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.
[mstable] Add mStable strategy (snapshot-labs#93)
* Add mStable strategy - Combines balances of both stkMTA & stkBPT * Remove decimals from params * Add README * Update src/strategies/mstable/README.md * Update src/strategies/mstable/examples.json * Update src/strategies/mstable/index.ts Co-authored-by: Chaitanya <[email protected]>
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
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
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,19 @@ | ||
# mstable | ||
|
||
Calls getVotes() on both the stkMTA and stkBPT contracts, these balances are then summed to generate a users vMTA balance. | ||
|
||
## Examples | ||
|
||
```JSON | ||
{ | ||
"strategies": [ | ||
{ | ||
"name": "mstable", | ||
"params": { | ||
"stkBPT": "0xefbe22085d9f29863cfb77eed16d3cc0d927b011", | ||
"stkMTA": "0x8f2326316eC696F6d023E37A9931c2b2C177a3D7", | ||
} | ||
} | ||
] | ||
} | ||
``` |
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,18 @@ | ||
[ | ||
{ | ||
"name": "mstable", | ||
"strategy": { | ||
"name": "mstable", | ||
"params": { | ||
"stkBPT": "0xefbe22085d9f29863cfb77eed16d3cc0d927b011", | ||
"stkMTA": "0x8f2326316eC696F6d023E37A9931c2b2C177a3D7" | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x2ee8670d2b936985d5fb1ee968810c155d3bb9ca", | ||
"0x19f12c947d25ff8a3b748829d8001ca09a28d46d" | ||
], | ||
"snapshot": 13236086 | ||
} | ||
] |
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,61 @@ | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { multicall } from '../../utils'; | ||
|
||
export const author = 'chrisjgf'; | ||
export const version = '0.0.1'; | ||
|
||
const abi = [ 'function getVotes(address account) view returns (uint256)' ]; | ||
|
||
const chunk = (arr, size) => | ||
Array.from({ length: Math.ceil(arr.length / size) }, (v, i) => | ||
arr.slice(i * size, i * size + size) | ||
); | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
const stkMTAQuery = addresses.map((address: any) => [ | ||
options.stkMTA, | ||
'getVotes', | ||
[address] | ||
]); | ||
|
||
const stkBPTQuery = addresses.map((address: any) => [ | ||
options.stkBPT, | ||
'getVotes', | ||
[address] | ||
]); | ||
|
||
const response = await multicall( | ||
network, | ||
provider, | ||
abi, | ||
[...stkMTAQuery, ...stkBPTQuery], | ||
{ blockTag } | ||
); | ||
|
||
const chunks = chunk(response, addresses.length); | ||
const stkMTABalances = chunks[0]; | ||
const stkBPTBalances = chunks[1]; | ||
|
||
return Object.fromEntries( | ||
Array(addresses.length) | ||
.fill('x') | ||
.map((_, i) => [ | ||
addresses[i], | ||
parseFloat( | ||
formatUnits( | ||
stkMTABalances[i][0].add(stkBPTBalances[i][0]).toString(), | ||
18 | ||
) | ||
) | ||
]) | ||
); | ||
} |