-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rocketpool-node-operator-delegate-v7] Added the rocket-pool-node-ope…
…rator-delegate-v7 strategy (#1533) * added the rocket-pool-node-operator-delegate-v7 strategy * added faster lookup method to fix more than 500 address test
- Loading branch information
1 parent
def4606
commit 66d50fd
Showing
4 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/strategies/rocketpool-node-operator-delegate-v7/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# rocketpool-node-operator-delegate-v7 | ||
|
||
This is a strategy for delegate node operators, it returns the delegated vote power for a node address given a signalling address. | ||
|
||
Here is an example of parameters: | ||
|
||
```json | ||
{ | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
``` |
47 changes: 47 additions & 0 deletions
47
src/strategies/rocketpool-node-operator-delegate-v7/examples.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "rocketpool-node-operator-delegate-v7", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18, | ||
"strategies": [ | ||
{ | ||
"name": "rocketpool-node-operator-v7", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x6212Ee7822265cE44B56C943bFd4bCcc03AeC42A", | ||
"0x291BFc5E578aEdFBE4b4A86d6188E99391BC30Fa", | ||
"0x27108a00Aa686c79fB15c79Fca4B312030cEFb24", | ||
"0xB0De8cB8Dcc8c5382c4b7F3E978b491140B2bC55", | ||
"0x439B5eEa6dD4745d575ADa1ED7d682c723829b7D", | ||
"0x9Be85faBd144bCa1aCdF2b5E074cFbFBEB2855a3", | ||
"0x166C58AC1907e2c4b24717DD52683A88E7123AbA", | ||
"0xf8bFf17a1C9dfC632F6C905d12C404AfE451B16c", | ||
"0x2600846F4401aE10CA760604036A891bb896649E", | ||
"0x38857Ed3a8fC5951289E58e20fB56A00e88f0BBD", | ||
"0xd0Fa32A950fb860501E8e3C0712B9fF847AD6f71", | ||
"0x8de90ADBd431Dfdae0cd81937fc1156031D50f19", | ||
"0xBb2b1CA23afCB616837F2966eb26C4C50ec8D080", | ||
"0x5061845415d2B9f279016Ba819510f2F44908086", | ||
"0x71c1B6562556B2b7fC9929cB1D4c949248036320", | ||
"0xaC643357BBdA44E46896Dcfb195A09cb8C6AE279", | ||
"0x220576274Cd2561a1cc396B023A36631862604f0", | ||
"0x0226e3174a45F3d97d853B8f3fe5DAd1006B9294", | ||
"0xD16dbc40479D572e19da7B671bb6C230aF41643d", | ||
"0x16d9de20adfb6ed1790a2e618063e5b3d1d07ba6" | ||
], | ||
"snapshot": 20309057 | ||
} | ||
] |
89 changes: 89 additions & 0 deletions
89
src/strategies/rocketpool-node-operator-delegate-v7/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import fetch from 'cross-fetch'; | ||
import { getAddress } from '@ethersproject/address'; | ||
import { getScoresDirect, Multicaller } from '../../utils'; | ||
|
||
export const author = 'rocket-pool'; | ||
export const version = '0.1.7'; | ||
|
||
const signerRegistryContractAddress = | ||
'0xc1062617d10Ae99E09D941b60746182A87eAB38F'; | ||
const signerRegistryAbi = [ | ||
'function signerToNode(address) external view returns (address)' | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = | ||
typeof snapshot === 'number' ? snapshot : await provider.getBlockNumber(); | ||
|
||
const req = await fetch( | ||
'https://api.rocketpool.net/mainnet/delegates/block/' + blockTag | ||
); | ||
const resp = await req.json(); | ||
|
||
const signerRegistry = new Multicaller(network, provider, signerRegistryAbi, { | ||
blockTag | ||
}); | ||
|
||
addresses.forEach((address) => { | ||
signerRegistry.call( | ||
address, | ||
signerRegistryContractAddress, | ||
'signerToNode', | ||
[address] | ||
); | ||
}); | ||
|
||
const signerRegistryResponse: Record<string, string> = | ||
await signerRegistry.execute(); | ||
|
||
const addressMap: Map<any, any> = new Map(resp.map(obj => [getAddress(obj.address), obj])); | ||
|
||
const nodeData = addresses.map((address) => { | ||
const nodeAddress = getAddress(signerRegistryResponse[address]); | ||
const node = addressMap.get(nodeAddress); | ||
return { | ||
signallingAddress: address, | ||
nodeAddress: nodeAddress, | ||
delegators: node && node.delegators.length > 0 ? node.delegators.map((d) => getAddress(d.address)) : [nodeAddress], | ||
Check failure on line 54 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts GitHub Actions / lint / Lint
|
||
} | ||
}); | ||
|
||
const delegations: Record<string, string[]> = Object.fromEntries( | ||
nodeData.map((node) => [node.nodeAddress, node.delegators]) | ||
); | ||
|
||
const scores = ( | ||
await getScoresDirect( | ||
space, | ||
options.strategies, | ||
network, | ||
provider, | ||
Object.values(delegations).reduce((a: string[], b: string[]) => | ||
a.concat(b) | ||
), | ||
snapshot | ||
) | ||
).filter((score) => Object.keys(score).length !== 0); | ||
|
||
return Object.fromEntries( | ||
addresses.map((address) => { | ||
const addressData = nodeData.find((node) => node.signallingAddress === address); | ||
if (addressData.nodeAddress === "0x0000000000000000000000000000000000000000") { | ||
Check failure on line 78 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts GitHub Actions / lint / Lint
|
||
return [address, 0]; | ||
} | ||
const delegators = addressData.delegators; | ||
const addressScore = delegators.reduce( | ||
(a, b) => a + scores.reduce((x, y) => (y[b] ? x + y[b] : x), 0), | ||
0 | ||
); | ||
return [address, addressScore]; | ||
}) | ||
); | ||
} |