Skip to content

Commit

Permalink
[occ-stake-of] New strategy for OCC token stake balance (snapshot-lab…
Browse files Browse the repository at this point in the history
…s#72)

* Addition of OCC stake balance strategy

* Field name consistency
  • Loading branch information
edeava authored Sep 21, 2021
1 parent ceb1aa4 commit 7289330
Show file tree
Hide file tree
Showing 4 changed files with 82 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 @@ -150,6 +150,7 @@ 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'
import * as occStakeOf from './occ-stake-of'

const strategies = {
coordinape,
Expand Down Expand Up @@ -301,7 +302,8 @@ const strategies = {
'flexa-capacity-staking': flexaCapacityStaking,
'sunrisegaming-univ2-lp': sunriseGamingUniv2Lp,
'sunrisegaming-staking': sunriseGamingStaking,
'single-staking-pools-balanceof': singleStakingPoolsBalanceOf
'single-staking-pools-balanceof': singleStakingPoolsBalanceOf,
'occ-stake-of': occStakeOf
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
15 changes: 15 additions & 0 deletions src/strategies/occ-stake-of/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# occ-stake-of

This is the OCC staking strategy, it returns the OCC staking balances of the voters.

Here is an example of parameters:

```json
{
"stakingContractAddress": [
"0xeBC86Fb12ab0fFaC6CBcaFCe2f049BfE7eFAda0D"
],
"symbol": "OCC",
"decimals": 18
}
```
28 changes: 28 additions & 0 deletions src/strategies/occ-stake-of/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "Example query",
"strategy": {
"name": "occ-stake-of",
"params": {
"stakingContractAddress": [
"0xeBC86Fb12ab0fFaC6CBcaFCe2f049BfE7eFAda0D"
],
"symbol": "OCC",
"decimals": 18
}
},
"network": "1",
"addresses": [
"0xa95f8f54dc55281852b5c972e4874264c7b5d3de",
"0x77752aE2Cb765BDd09568E69B740a2276187F052",
"0xd3aecf9e0856822bd320873e905ae9f78a2977e7",
"0x2C2ADD1C863551A0644876be227604C8E458dD7e",
"0x8af630f68dd02c589b9449158455735814b452a3",
"0x252e2e0e4cc5bd7391acb47634fb6bb382d08586",
"0x4bf455074e67848dc7e1c55b45a32aafca2e9c9c",
"0xb623964e5761C1b04A4a46b9aE8D1809dEFa7efB"
],
"snapshot": 12381658
}
]

36 changes: 36 additions & 0 deletions src/strategies/occ-stake-of/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'OccamFi';
export const version = '0.1.0';

const abi = [
'function getStake(address user) public view returns (uint stake)'
];

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.stakingContractAddress[0], 'getStake', [address])
);

const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, stake]) => [
address,
parseFloat(formatUnits(stake, options.decimals))
])
);
}

0 comments on commit 7289330

Please sign in to comment.