Skip to content

Commit

Permalink
[rocketpool-node-operator-delegate-v7] Added the rocket-pool-node-ope…
Browse files Browse the repository at this point in the history
…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
nickdoherty authored Jul 16, 2024
1 parent def4606 commit 66d50fd
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ import * as rocketpoolNodeOperatorv7 from './rocketpool-node-operator-v7';
import * as rocketpoolNodeOperatorDelegatev4 from './rocketpool-node-operator-delegate-v4';
import * as rocketpoolNodeOperatorDelegatev5 from './rocketpool-node-operator-delegate-v5';
import * as rocketpoolNodeOperatorDelegatev6 from './rocketpool-node-operator-delegate-v6';
import * as rocketpoolNodeOperatorDelegatev7 from './rocketpool-node-operator-delegate-v7';
import * as earthfundChildDaoStakingBalance from './earthfund-child-dao-staking-balance';
import * as unipilotVaultPilotBalance from './unipilot-vault-pilot-balance';
import * as sdBoostTWAVP from './sd-boost-twavp';
Expand Down Expand Up @@ -747,6 +748,7 @@ const strategies = {
'rocketpool-node-operator-delegate-v4': rocketpoolNodeOperatorDelegatev4,
'rocketpool-node-operator-delegate-v5': rocketpoolNodeOperatorDelegatev5,
'rocketpool-node-operator-delegate-v6': rocketpoolNodeOperatorDelegatev6,
'rocketpool-node-operator-delegate-v7': rocketpoolNodeOperatorDelegatev7,
'earthfund-child-dao-staking-balance': earthfundChildDaoStakingBalance,
'sd-boost-twavp': sdBoostTWAVP,
'unipilot-vault-pilot-balance': unipilotVaultPilotBalance,
Expand Down
13 changes: 13 additions & 0 deletions src/strategies/rocketpool-node-operator-delegate-v7/README.md
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 src/strategies/rocketpool-node-operator-delegate-v7/examples.json
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 src/strategies/rocketpool-node-operator-delegate-v7/index.ts
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]));

Check failure on line 46 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `resp.map(obj·=>·[getAddress(obj.address),·obj])` with `⏎····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

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `·node·&&·node.delegators.length·>·0·?·node.delegators.map((d)·=>·getAddress(d.address))·:·[nodeAddress],` with `⏎········node·&&·node.delegators.length·>·0⏎··········?·node.delegators.map((d)·=>·getAddress(d.address))⏎··········:·[nodeAddress]`
}

Check failure on line 55 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Insert `;`
});

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);

Check failure on line 77 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `(node)·=>·node.signallingAddress·===·address` with `⏎········(node)·=>·node.signallingAddress·===·address⏎······`
if (addressData.nodeAddress === "0x0000000000000000000000000000000000000000") {

Check failure on line 78 in src/strategies/rocketpool-node-operator-delegate-v7/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `addressData.nodeAddress·===·"0x0000000000000000000000000000000000000000"` with `⏎········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];
})
);
}

0 comments on commit 66d50fd

Please sign in to comment.