diff --git a/src/strategies/index.ts b/src/strategies/index.ts index 4a0714c48..74521137b 100644 --- a/src/strategies/index.ts +++ b/src/strategies/index.ts @@ -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, @@ -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) { diff --git a/src/strategies/single-staking-pools-balanceof/README.md b/src/strategies/single-staking-pools-balanceof/README.md new file mode 100644 index 000000000..94bda2f1f --- /dev/null +++ b/src/strategies/single-staking-pools-balanceof/README.md @@ -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 +} +``` diff --git a/src/strategies/single-staking-pools-balanceof/examples.json b/src/strategies/single-staking-pools-balanceof/examples.json new file mode 100644 index 000000000..98c2ddbdf --- /dev/null +++ b/src/strategies/single-staking-pools-balanceof/examples.json @@ -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 + } +] diff --git a/src/strategies/single-staking-pools-balanceof/index.ts b/src/strategies/single-staking-pools-balanceof/index.ts new file mode 100644 index 000000000..0a3907445 --- /dev/null +++ b/src/strategies/single-staking-pools-balanceof/index.ts @@ -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> { + 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 = await multi.execute(); + + return Object.fromEntries( + Object.entries(result).map(([address, userInfo]) => [ + address, + parseFloat(formatUnits(userInfo.amount, options.decimals)) + ]) + ); +}