Skip to content

Commit

Permalink
perf: replace snapshot.js sdk with an axios request (#5483)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture authored Oct 18, 2023
1 parent 27d9378 commit bd68920
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 55 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"@shapeshiftoss/hdwallet-xdefi": "^1.52.2",
"@shapeshiftoss/types": "workspace:^",
"@shapeshiftoss/unchained-client": "workspace:^",
"@snapshot-labs/snapshot.js": "^0.6.1",
"@sniptt/monads": "^0.5.10",
"@types/bip21": "^2.0.0",
"@types/react-plotly.js": "^2.6.0",
Expand Down
34 changes: 34 additions & 0 deletions src/state/apis/snapshot/getVotingPower.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from 'axios'

import type { Strategy } from './validators'

export const getVotingPower = async (
address: string,
network: string,
strategies: Strategy[],
snapshot: number | 'latest',
space: string,
delegation: boolean,
) => {
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
}
const body = {
jsonrpc: '2.0',
method: 'get_vp',
params: {
address,
network,
strategies,
snapshot,
space,
delegation,
},
}

const { data } = await axios.post('https://score.snapshot.org', body, {
headers,
})
return data.result
}
5 changes: 2 additions & 3 deletions src/state/apis/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createApi } from '@reduxjs/toolkit/dist/query/react'
import { type AccountId, fromAccountId } from '@shapeshiftoss/caip'
import { isEvmChainId } from '@shapeshiftoss/chain-adapters'
import snapshot from '@snapshot-labs/snapshot.js'
import axios from 'axios'
import { BigNumber, bn, bnOrZero } from 'lib/bignumber/bignumber'
import { findClosestFoxDiscountDelayBlockNumber } from 'lib/fees/utils'

import { BASE_RTK_CREATE_API_CONFIG } from '../const'
import { getVotingPower } from './getVotingPower'
import type { Strategy } from './validators'
import { SnapshotSchema, VotingPowerSchema } from './validators'

Expand Down Expand Up @@ -67,8 +67,7 @@ export const snapshotApi = createApi({
const delegation = false // don't let people delegate for discounts - ambiguous in spec
const votingPowerResults = await Promise.all(
evmAddresses.map(async address => {
// https://docs.snapshot.org/tools/snapshot.js#getvp
const votingPowerUnvalidated = await snapshot.utils.getVp(
const votingPowerUnvalidated = await getVotingPower(
address,
'1',
strategies,
Expand Down
58 changes: 7 additions & 51 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5997,13 +5997,6 @@ __metadata:
languageName: node
linkType: hard

"@ensdomains/eth-ens-namehash@npm:^2.0.15":
version: 2.0.15
resolution: "@ensdomains/eth-ens-namehash@npm:2.0.15"
checksum: 56e2d4275f30b701e7328e488b7107b5ee793b57653342232f01396f769a51b812e73f9475faf894198ffc8ea97eead3809c1431e0955b9377400f503b4da970
languageName: node
linkType: hard

"@epnsproject/sdk-restapi@npm:^0.1.20":
version: 0.1.20
resolution: "@epnsproject/sdk-restapi@npm:0.1.20"
Expand Down Expand Up @@ -6175,7 +6168,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/abi@npm:5.7.0, @ethersproject/abi@npm:^5.0.1, @ethersproject/abi@npm:^5.5.0, @ethersproject/abi@npm:^5.6.3, @ethersproject/abi@npm:^5.6.4, @ethersproject/abi@npm:^5.7.0":
"@ethersproject/abi@npm:5.7.0, @ethersproject/abi@npm:^5.0.1, @ethersproject/abi@npm:^5.5.0, @ethersproject/abi@npm:^5.6.3, @ethersproject/abi@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/abi@npm:5.7.0"
dependencies:
Expand Down Expand Up @@ -6220,7 +6213,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/address@npm:5.7.0, @ethersproject/address@npm:^5.0.4, @ethersproject/address@npm:^5.6.1, @ethersproject/address@npm:^5.7.0":
"@ethersproject/address@npm:5.7.0, @ethersproject/address@npm:^5.0.4, @ethersproject/address@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/address@npm:5.7.0"
dependencies:
Expand Down Expand Up @@ -6263,7 +6256,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/bytes@npm:5.7.0, @ethersproject/bytes@npm:^5.0.4, @ethersproject/bytes@npm:^5.6.1, @ethersproject/bytes@npm:^5.7.0":
"@ethersproject/bytes@npm:5.7.0, @ethersproject/bytes@npm:^5.0.4, @ethersproject/bytes@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/bytes@npm:5.7.0"
dependencies:
Expand All @@ -6281,7 +6274,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/contracts@npm:5.7.0, @ethersproject/contracts@npm:^5.6.2, @ethersproject/contracts@npm:^5.7.0":
"@ethersproject/contracts@npm:5.7.0, @ethersproject/contracts@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/contracts@npm:5.7.0"
dependencies:
Expand Down Expand Up @@ -6402,7 +6395,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/providers@npm:5.7.2, @ethersproject/providers@npm:^5.6.8, @ethersproject/providers@npm:^5.7.0, @ethersproject/providers@npm:^5.7.2":
"@ethersproject/providers@npm:5.7.2, @ethersproject/providers@npm:^5.7.0, @ethersproject/providers@npm:^5.7.2":
version: 5.7.2
resolution: "@ethersproject/providers@npm:5.7.2"
dependencies:
Expand Down Expand Up @@ -6528,7 +6521,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/wallet@npm:5.7.0, @ethersproject/wallet@npm:^5.6.2, @ethersproject/wallet@npm:^5.7.0":
"@ethersproject/wallet@npm:5.7.0, @ethersproject/wallet@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/wallet@npm:5.7.0"
dependencies:
Expand Down Expand Up @@ -9783,7 +9776,6 @@ __metadata:
"@shapeshiftoss/hdwallet-xdefi": ^1.52.2
"@shapeshiftoss/types": "workspace:^"
"@shapeshiftoss/unchained-client": "workspace:^"
"@snapshot-labs/snapshot.js": ^0.6.1
"@sniptt/monads": ^0.5.10
"@testing-library/jest-dom": ^5.16.4
"@testing-library/react": ^13.3.0
Expand Down Expand Up @@ -9988,28 +9980,6 @@ __metadata:
languageName: node
linkType: hard

"@snapshot-labs/snapshot.js@npm:^0.6.1":
version: 0.6.1
resolution: "@snapshot-labs/snapshot.js@npm:0.6.1"
dependencies:
"@ensdomains/eth-ens-namehash": ^2.0.15
"@ethersproject/abi": ^5.6.4
"@ethersproject/address": ^5.6.1
"@ethersproject/bytes": ^5.6.1
"@ethersproject/contracts": ^5.6.2
"@ethersproject/hash": ^5.7.0
"@ethersproject/providers": ^5.6.8
"@ethersproject/units": ^5.7.0
"@ethersproject/wallet": ^5.6.2
ajv: ^8.11.0
ajv-formats: ^2.1.1
cross-fetch: ^3.1.6
json-to-graphql-query: ^2.2.4
lodash.set: ^4.3.2
checksum: 7c52f5b6282c2ba4251aace51dca854650d9a70d0ef96d77b618392ef8041d6f5a55b0e4fb41c5bd3cd230c5e9b0f06c033f02caaa4db4e189580a26993f77e1
languageName: node
linkType: hard

"@sniptt/monads@npm:^0.5.10":
version: 0.5.10
resolution: "@sniptt/monads@npm:0.5.10"
Expand Down Expand Up @@ -17877,7 +17847,7 @@ __metadata:
languageName: node
linkType: hard

"cross-fetch@npm:^3.0.6, cross-fetch@npm:^3.1.6":
"cross-fetch@npm:^3.0.6":
version: 3.1.8
resolution: "cross-fetch@npm:3.1.8"
dependencies:
Expand Down Expand Up @@ -25303,13 +25273,6 @@ __metadata:
languageName: node
linkType: hard

"json-to-graphql-query@npm:^2.2.4":
version: 2.2.5
resolution: "json-to-graphql-query@npm:2.2.5"
checksum: f35e8a7ecf1d2e567b0b17ddd67ccf3b3cd4739034272a8a1745b5bdad9ecd3fcf4078a18517fdd15b5dd0c877784a99001d443685510ea0fbed5ed5e028d706
languageName: node
linkType: hard

"json5@npm:2.x, json5@npm:^2.2.2, json5@npm:^2.2.3":
version: 2.2.3
resolution: "json5@npm:2.2.3"
Expand Down Expand Up @@ -26050,13 +26013,6 @@ __metadata:
languageName: node
linkType: hard

"lodash.set@npm:^4.3.2":
version: 4.3.2
resolution: "lodash.set@npm:4.3.2"
checksum: a9122f49eef9f2d0fc9061a33d87f8e5b8c6b23d46e8b9e9ce1529d3588d79741bd1145a3abdfa3b13082703e65af27ff18d8a07bfc22b9be32f3fc36f763f70
languageName: node
linkType: hard

"lodash.snakecase@npm:^4.1.1":
version: 4.1.1
resolution: "lodash.snakecase@npm:4.1.1"
Expand Down

0 comments on commit bd68920

Please sign in to comment.