Skip to content

Commit

Permalink
add gysr staking balance strategy (snapshot-labs#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinaconley authored Feb 15, 2022
1 parent 263f8dd commit fbe3893
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/strategies/gysr-staking-balance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GYSR staking balance

This strategy returns the staking balance for each user in a specified GYSR pool.

Here is an example of parameters:

```json
{
"pool": "0x30C0f65D9b27EBE2CC2A49Cbcb4133230b3fb381",
"symbol": "GYSR",
"decimals": 18
}
```
68 changes: 68 additions & 0 deletions src/strategies/gysr-staking-balance/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"name": "Example GYSR staking balance query",
"strategy": {
"name": "gysr-staking-balance",
"params": {
"pool": "0x30C0f65D9b27EBE2CC2A49Cbcb4133230b3fb381",
"symbol": "GYSR",
"decimals": 18
}
},
"network": 1,
"addresses": [
"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11",
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7",
"0x1E1A51E25f2816335cA436D65e9Af7694BE232ad",
"0x1F717Ce8ff07597ee7c408b5623dF40AaAf1787C",
"0x1c7a9275F2BD5a260A9c31069F77d53473b8ae2e",
"0x1d5E65a087eBc3d03a294412E46CE5D6882969f4",
"0x1f254336E5c46639A851b9CfC165697150a6c327",
"0x2ec3F80BeDA63Ede96BA20375032CDD3aAfb3030",
"0x4AcBcA6BE2f8D2540bBF4CA77E45dA0A4a095Fa2",
"0x4F3D348a6D09837Ae7961B1E0cEe2cc118cec777",
"0x6D7f23A509E212Ba7773EC1b2505d1A134f54fbe",
"0x07a1f6fc89223c5ebD4e4ddaE89Ac97629856A0f",
"0x8d5F05270da470e015b67Ab5042BDbE2D2FEFB48",
"0xa0ffbF245095dBFbB3A76d86C18Cda009b96aD8B",
"0x126bC064dBd1d0205fC608C3178a60C9706b482C",
"0xC643B5B1d3912C52f9498E8C6E8BF321C94F28E9",
"0x39cf6E97046cc8454fE0aaD04B05524Ae34025Cb",
"0xA80481E3f9098602954B2E5cf306e6dEE053EF3E"
],
"snapshot": 14200000
},
{
"name": "Example GYSR NFT staking balance query on Polygon",
"strategy": {
"name": "gysr-staking-balance",
"params": {
"pool": "0xc8D2A357178b9466Ad0f153CD2c950226F612934",
"symbol": "NFT",
"decimals": 0
}
},
"network": 137,
"addresses": [
"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11",
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7",
"0x1E1A51E25f2816335cA436D65e9Af7694BE232ad",
"0x1F717Ce8ff07597ee7c408b5623dF40AaAf1787C",
"0x1c7a9275F2BD5a260A9c31069F77d53473b8ae2e",
"0x1d5E65a087eBc3d03a294412E46CE5D6882969f4",
"0x1f254336E5c46639A851b9CfC165697150a6c327",
"0x2ec3F80BeDA63Ede96BA20375032CDD3aAfb3030",
"0x4AcBcA6BE2f8D2540bBF4CA77E45dA0A4a095Fa2",
"0x4F3D348a6D09837Ae7961B1E0cEe2cc118cec777",
"0x6D7f23A509E212Ba7773EC1b2505d1A134f54fbe",
"0x07a1f6fc89223c5ebD4e4ddaE89Ac97629856A0f",
"0x8d5F05270da470e015b67Ab5042BDbE2D2FEFB48",
"0x1Fd05325d3236D4e07963195538b75636ABDE75C",
"0xa15226cAB1A266958f881Ec18035741D047aA47F",
"0x97A8C2e0E1f17296e8C109eD136Fe9C75d745092",
"0xdab44c6D2e0691856016B4412D70ecDE86b0d0b1",
"0xA80481E3f9098602954B2E5cf306e6dEE053EF3E"
],
"snapshot": 24976000
}
]
34 changes: 34 additions & 0 deletions src/strategies/gysr-staking-balance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'devinaconley';
export const version = '0.0.1';

const abi = [
'function stakingBalances(address user) external view returns (uint256[])'
];

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, abi, { blockTag });
addresses.forEach((address) =>
multi.call(address, options.pool, 'stakingBalances', [address])
);
const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, balances]) => [
address,
parseFloat(formatUnits(balances[0], options.decimals))
])
);
}
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ import * as chubbykaijudao from './chubbykaijudao';
import * as landDaoTiers from './landdao-token-tiers';
import * as defiplaza from './defiplaza';
import * as stakingClaimedUnclaimed from './staking-claimed-unclaimed';
import * as gysrStakingBalance from './gysr-staking-balance';

const strategies = {
'landdao-token-tiers': landDaoTiers,
Expand Down Expand Up @@ -516,7 +517,8 @@ const strategies = {
've-balance-of-at': veBalanceOfAt,
chubbykaijudao: chubbykaijudao,
revest: revest,
'staking-claimed-unclaimed': stakingClaimedUnclaimed
'staking-claimed-unclaimed': stakingClaimedUnclaimed,
'gysr-staking-balance': gysrStakingBalance
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down

0 comments on commit fbe3893

Please sign in to comment.