forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flexa-capacity-staking] Add Flexa Capacity staking strategy (snapsho…
…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
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
]; | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters