-
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.
- Loading branch information
Showing
7 changed files
with
253 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], | ||
} | ||
}); | ||
|
||
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") { | ||
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]; | ||
}) | ||
); | ||
} |
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 node operators, it returns the vote power for a node address. | ||
|
||
Here is an example of parameters: | ||
|
||
```json | ||
{ | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
``` |
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,27 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "rocketpool-node-operator-v7", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xc942B5aA63A3410a13358a7a3aEdF33d9e9D3AC3", | ||
"0x9Fe9FfbfD57ab78D4d01973482258bfC4BB70bE3", | ||
"0x57767D8000859535431Fbc57EBFEc43FD0515902", | ||
"0x8fBfD009C4B6a99EDD7a1b9561e696A98b6E48dC", | ||
"0xDe506279b3704064Ee5ED2Fcf5515b7629eDAB1D", | ||
"0x48ee0aBAe316499E6d9375671c4B6AE406bd288B", | ||
"0x07f771B6C79b3F86E12585580654A946448A9020", | ||
"0xF912051684b910FFA7972aDa6E8c1EC46CBBE075", | ||
"0x0e973A3757ed841EfbBE4139a7d52a5EebDa03DB", | ||
"0x427d42983CC65d27e83A2Df5815b46F1F55e6445" | ||
], | ||
"snapshot": 20309057 | ||
} | ||
] |
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,60 @@ | ||
import { Multicaller } from '../../utils'; | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
|
||
export const author = 'rocket-pool'; | ||
export const version = '0.1.7'; | ||
|
||
const rocketNetworkVoting = '0xA9d27E1952f742d659143a544d3e535fFf3Eebe1'; | ||
const rocketNetworkVotingAbi = [ | ||
'function getVotingPower(address _nodeAddress, uint32 _block) external view returns (uint256)' | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = | ||
typeof snapshot === 'number' ? snapshot : await provider.getBlockNumber(); | ||
|
||
const nodeVotingPower = new Multicaller( | ||
network, | ||
provider, | ||
rocketNetworkVotingAbi, | ||
{ blockTag } | ||
); | ||
|
||
addresses.forEach((address) => { | ||
nodeVotingPower.call(address, rocketNetworkVoting, 'getVotingPower', [ | ||
address, | ||
blockTag | ||
]); | ||
}); | ||
|
||
const nodeVotingPowerResponse: Record<string, BigNumberish> = | ||
await nodeVotingPower.execute(); | ||
|
||
const merged = addresses.map((address) => { | ||
const votePower = nodeVotingPowerResponse[address]; | ||
return { | ||
address: address, | ||
votePower: votePower | ||
}; | ||
}); | ||
|
||
const reduced: Record<string, BigNumberish> = merged.reduce((acc, obj) => { | ||
acc[obj.address] = obj.votePower; | ||
return acc; | ||
}, {}); | ||
|
||
return Object.fromEntries( | ||
Object.entries(reduced).map(([address, votePower]) => [ | ||
address, | ||
parseFloat(formatUnits(votePower, options.decimals)) | ||
]) | ||
); | ||
} |