Skip to content

Commit

Permalink
[flexa-capacity-staking] Add Flexa Capacity staking strategy (snapsho…
Browse files Browse the repository at this point in the history
…t-labs#60)

* Add Flexa Capacity staking strategy

Allow for full stake + reward balances to be reflected in
voting power

* Update fetch call to use batched GET
  • Loading branch information
zkmoney authored Sep 17, 2021
1 parent 01022a6 commit ae2a18a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/strategies/flexa-capacity-staking/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"name": "Flexa Capacity staking example query",
"strategy": {
"name": "flexa-capacity-staking",
"params": {
"apiBase": "https://api.capacity.staging.flexa.network"
}
},
"network": "1",
"addresses": [
"0x4621E524e6F95A6280b7761BDE3d150101b290F8",
"0x3c4B8C52Ed4c29eE402D9c91FfAe1Db2BAdd228D",
"0xd649bACfF66f1C85618c5376ee4F38e43eE53b63",
"0x726022a9fe1322fA9590FB244b8164936bB00489",
"0xc6665eb39d2106fb1DBE54bf19190F82FD535c19",
"0x6ef2376fa6e12dabb3a3ed0fb44e4ff29847af68"
],
"snapshot": 11437846
}
]
40 changes: 40 additions & 0 deletions src/strategies/flexa-capacity-staking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fetch from 'cross-fetch';
import { getAddress } from '@ethersproject/address';
import { BigNumber } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';

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

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const apiUrl = `${options.apiBase}/accounts?addresses=${addresses.join(
','
)}&snapshot=${snapshot}`;

const response = await fetch(apiUrl, {
method: 'GET',
headers: {
Accept: 'application/vnd.flexa.capacity.v1+json'
}
});
const data = await response.json();

return Object.fromEntries(
data.map((value) => {
const { supplyTotal = 0, rewardTotal = 0 } = value;
return [
getAddress(value.address),
parseFloat(
formatUnits(BigNumber.from(supplyTotal).add(rewardTotal), 18)
)
];
})
);
}
6 changes: 4 additions & 2 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import * as snowswap from './snowswap';
import * as meebitsdao from './meebitsdao';
import * as crucibleERC20BalanceOf from './crucible-erc20-balance-of';
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';

Expand Down Expand Up @@ -289,9 +290,10 @@ const strategies = {
snowswap,
meebitsdao,
'crucible-erc20-balance-of': crucibleERC20BalanceOf,
'has-rock': hasrock,
'flexa-capacity-staking': flexaCapacityStaking,
'sunrisegaming-univ2-lp': sunriseGamingUniv2Lp,
'sunrisegaming-staking': sunriseGamingStaking,
'has-rock': hasrock
'sunrisegaming-staking': sunriseGamingStaking
};

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

0 comments on commit ae2a18a

Please sign in to comment.