forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'snapshot-labs:master' into master
- Loading branch information
Showing
10 changed files
with
206 additions
and
46 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
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
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
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
[ | ||
{ | ||
"name": "Example query Moonbase", | ||
"strategy": { | ||
"name": "moonbase", | ||
"params": { | ||
"address": "0xc97c478Fc35d75b51549C39974053a679A5C67E1", | ||
"masterChef": "0x830304d6C669d33738c7E4c1F2310CC1E530Df63", | ||
"moonbaseLPs": [ | ||
{ | ||
"address": "0x230C64C42886A1F6b91eD8C11B59a2D45865d38F", | ||
"pid": 7 | ||
} | ||
], | ||
"symbol": "MBG", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "84531", | ||
"addresses": [ | ||
"0xe32C26Be24232ba92cd89d116985F81f94Dd26a8", | ||
"0x7DC90A11489C384dc72234120B0f84C3932d94Ce", | ||
"0xf704872349a62ceBb40F841B635de268b2F7B9Fb" | ||
], | ||
"snapshot": 9182354 | ||
} | ||
] | ||
{ | ||
"name": "Example query Moonbase", | ||
"strategy": { | ||
"name": "moonbase", | ||
"params": { | ||
"address": "0xc97c478Fc35d75b51549C39974053a679A5C67E1", | ||
"masterChef": "0x830304d6C669d33738c7E4c1F2310CC1E530Df63", | ||
"moonbaseLPs": [ | ||
{ | ||
"address": "0x230C64C42886A1F6b91eD8C11B59a2D45865d38F", | ||
"pid": 7 | ||
} | ||
], | ||
"symbol": "MBG", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "84531", | ||
"addresses": [ | ||
"0xe32C26Be24232ba92cd89d116985F81f94Dd26a8", | ||
"0x7DC90A11489C384dc72234120B0f84C3932d94Ce", | ||
"0xf704872349a62ceBb40F841B635de268b2F7B9Fb" | ||
], | ||
"snapshot": 9182354 | ||
} | ||
] |
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
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-v3 | ||
|
||
This is a strategy for staking node operators, it returns the half square rooted node effective stake balance given 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,34 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "rocketpool-node-operator-v3", | ||
"params": { | ||
"address": "0xD33526068D116cE69F19A9ee46F0bd304F21A51f", | ||
"symbol": "RPL", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x17Fa597cEc16Ab63A7ca00Fb351eb4B29Ffa6f46", | ||
"0xca317A4ecCbe0Dd5832dE2A7407e3c03F88b2CdD", | ||
"0x327260c50634136551bfE4e4eB082281555AAfAE", | ||
"0x5d8172792a9e649053c07366E3a7C24a37F0C534", | ||
"0x701F4dcEAD1049FA01F321d49F6dca525cF4A5A5", | ||
"0xb8ed9ea221bf33d37360A76DDD52bA7b1E66AA5C", | ||
"0xbfaf9BFa09F26EF8104A6d5FF09afdCC9300E5bc", | ||
"0x174E0b45C03318B0C9bc03573028605B26764931", | ||
"0x5f4cB66c9B1Ed8A4758A059FDB10E0F72C307D8A", | ||
"0x24609303B67051eF77735E34D671e2A13E3Da35d", | ||
"0xE35854CdE18A3cC4706134b4850Dd861a55B9A30", | ||
"0x53938f795AB6c57070AAd32905a70A2E5961A887", | ||
"0xD6527Bd3d62f1Da520E6f74B89EBD8F8cD04564f", | ||
"0xf8bFf17a1C9dfC632F6C905d12C404AfE451B16c", | ||
"0x689C6853f3deBac91b72f32BafA83200eeC9613C", | ||
"0xaEbb400542598E6ee58b2FDF2E7425c07E8Ba68D", | ||
"0xa016344b2D4dfBf370766F24d196171DeC86544A" | ||
], | ||
"snapshot": 17761214 | ||
} | ||
] |
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,112 @@ | ||
import { BigNumberish, BigNumber } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'rocket-pool'; | ||
export const version = '0.1.3'; | ||
|
||
const rocketNetworkPricesAddress = '0xd3f500F550F46e504A4D2153127B47e007e11166'; | ||
const rocketNetworkPricesContractAbi = [ | ||
'function getRPLPrice() external view returns (uint256)' | ||
]; | ||
const rocketNodeStakingAddress = '0x0d8D8f8541B12A0e1194B7CC4b6D954b90AB82ec'; | ||
const rocketNodeStakingContractAbi = [ | ||
'function getNodeEffectiveRPLStake(address _nodeAddress) external view returns (uint256)', | ||
'function getNodeRPLStake(address _nodeAddress) external view returns (uint256)', | ||
'function getNodeETHProvided(address _nodeAddress) external view returns (uint256)' | ||
]; | ||
|
||
function minBN(a, b) { | ||
return a.lt(b) ? a : b; | ||
} | ||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
const nodeRPLStake = new Multicaller( | ||
network, | ||
provider, | ||
rocketNodeStakingContractAbi, | ||
{ blockTag } | ||
); | ||
|
||
const nodeETHProvided = new Multicaller( | ||
network, | ||
provider, | ||
rocketNodeStakingContractAbi, | ||
{ blockTag } | ||
); | ||
|
||
const RPLPrice = new Multicaller( | ||
network, | ||
provider, | ||
rocketNetworkPricesContractAbi, | ||
{ blockTag } | ||
); | ||
|
||
addresses.forEach((address) => { | ||
nodeRPLStake.call(address, rocketNodeStakingAddress, 'getNodeRPLStake', [ | ||
address | ||
]); | ||
nodeETHProvided.call( | ||
address, | ||
rocketNodeStakingAddress, | ||
'getNodeETHProvided', | ||
[address] | ||
); | ||
RPLPrice.call(address, rocketNetworkPricesAddress, 'getRPLPrice'); | ||
}); | ||
|
||
const nodeRPLStakeResponse: Record<string, BigNumberish> = | ||
await nodeRPLStake.execute(); | ||
|
||
const nodeETHProvidedResponse: Record<string, BigNumberish> = | ||
await nodeETHProvided.execute(); | ||
|
||
const RPLPriceResponse: Record<string, BigNumberish> = | ||
await RPLPrice.execute(); | ||
|
||
const merged = addresses.map((address) => { | ||
const nodeRPLStake = nodeRPLStakeResponse[address]; | ||
const nodeETHProvided = nodeETHProvidedResponse[address]; | ||
const RPLPrice = RPLPriceResponse[address]; | ||
|
||
return { | ||
address: address, | ||
nodeRPLStake: nodeRPLStake, | ||
nodeETHProvided: nodeETHProvided, | ||
RPLPrice: RPLPrice | ||
}; | ||
}); | ||
|
||
const data = merged.map((item) => { | ||
const multiplier = BigNumber.from('15').mul(BigNumber.from('10').pow(17)); | ||
const numerator = item.nodeETHProvided.mul(multiplier); | ||
const denominator = item.RPLPrice; | ||
const maxEffectiveStake = numerator.div(denominator); | ||
const effectiveStake = minBN(item.nodeRPLStake, maxEffectiveStake); | ||
|
||
return { | ||
address: item.address, | ||
effectiveStake: effectiveStake | ||
}; | ||
}); | ||
|
||
const reduced: Record<string, BigNumberish> = data.reduce((acc, obj) => { | ||
acc[obj.address] = obj.effectiveStake; | ||
return acc; | ||
}, {}); | ||
|
||
return Object.fromEntries( | ||
Object.entries(reduced).map(([address, balance]) => [ | ||
address, | ||
Math.sqrt(parseFloat(formatUnits(balance, options.decimals))) / 2 | ||
]) | ||
); | ||
} |
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
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