forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[single-staking-pools-balanceof] New Strategy for Single Staking Pools (
snapshot-labs#68) * New Strategy for Single Staking Pools Implements new strategy to fetch Staked token amount in single staking pool * Update src/strategies/single-staking-pools-balanceof/index.ts * Update src/strategies/single-staking-pools-balanceof/index.ts * Update src/strategies/single-staking-pools-balanceof/index.ts * Update src/strategies/single-staking-pools-balanceof/README.md * Update src/strategies/single-staking-pools-balanceof/examples.json Co-authored-by: Chaitanya <[email protected]>
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# single-staking-pools-balanceof | ||
|
||
Used for fetching the staked token balance in a single staking pool | ||
|
||
Here is an example of parameters: | ||
|
||
```json | ||
{ | ||
"stakingPoolAddress": [ | ||
"0x081Ffa6Fa76e738531B3717301F4B636efAe1F1e" | ||
], | ||
"decimals": 18 | ||
} | ||
``` |
20 changes: 20 additions & 0 deletions
20
src/strategies/single-staking-pools-balanceof/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,20 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "single-staking-pools-balanceof", | ||
"params": { | ||
"stakingPoolAddresses": [ | ||
"0x081Ffa6Fa76e738531B3717301F4B636efAe1F1e" | ||
], | ||
"symbol": "DAI", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "43114", | ||
"addresses": [ | ||
"0xa598710E9EdA808dF224E14748f6eba374043715" | ||
], | ||
"snapshot": 4565540 | ||
} | ||
] |
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,39 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'PolySwift'; | ||
export const version = '0.1.0'; | ||
|
||
|
||
const singleStakingPoolAbi = [ | ||
'function userInfo(address) view returns (uint256 amount, uint256 rewardDebt)' | ||
]; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
const multi = new Multicaller(network, provider, singleStakingPoolAbi, { blockTag }); | ||
|
||
options.stakingPoolAddresses.forEach(stakingPoolAddress => { | ||
addresses.forEach((address) => | ||
multi.call(address, stakingPoolAddress, 'userInfo', [address]) | ||
); | ||
}) | ||
|
||
const result: Record<string, any> = await multi.execute(); | ||
|
||
return Object.fromEntries( | ||
Object.entries(result).map(([address, userInfo]) => [ | ||
address, | ||
parseFloat(formatUnits(userInfo.amount, options.decimals)) | ||
]) | ||
); | ||
} |