Skip to content

Commit

Permalink
[single-staking-pools-balanceof] New Strategy for Single Staking Pools (
Browse files Browse the repository at this point in the history
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
PolySwift and ChaituVR authored Sep 20, 2021
1 parent 9d748a7 commit f74ff85
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import * as hasrock from './has-rock';
import * as flexaCapacityStaking from './flexa-capacity-staking';
import * as sunriseGamingUniv2Lp from './sunrisegaming-univ2-lp';
import * as sunriseGamingStaking from './sunrisegaming-staking';
import * as singleStakingPoolsBalanceOf from './single-staking-pools-balanceof'

const strategies = {
coordinape,
Expand Down Expand Up @@ -297,7 +298,8 @@ const strategies = {
'has-rock': hasrock,
'flexa-capacity-staking': flexaCapacityStaking,
'sunrisegaming-univ2-lp': sunriseGamingUniv2Lp,
'sunrisegaming-staking': sunriseGamingStaking
'sunrisegaming-staking': sunriseGamingStaking,
'single-staking-pools-balanceof': singleStakingPoolsBalanceOf
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
14 changes: 14 additions & 0 deletions src/strategies/single-staking-pools-balanceof/README.md
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 src/strategies/single-staking-pools-balanceof/examples.json
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
}
]
39 changes: 39 additions & 0 deletions src/strategies/single-staking-pools-balanceof/index.ts
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))
])
);
}

0 comments on commit f74ff85

Please sign in to comment.