forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'snapshot-labs:master' into master
- Loading branch information
Showing
12 changed files
with
260 additions
and
24 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
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,15 @@ | ||
# AdmiralDao Staked Sail | ||
|
||
This strategy returns the voting power of an address that has staked sail in the vesail staking contract [VeSail](https://etherscan.io/token/0x26fe2f89a1fef1bc90b8a89d8ad18a1891166ff5). | ||
The voting power is calculated as: | ||
- The amount of vesail held in their address. | ||
- The result is then used to interract with the tosail method in the contract to get the sail equivalent. | ||
- Lastly it will take the equivalent sail amount and apply a square root operation. | ||
|
||
```JSON | ||
{ | ||
"strategies": [ | ||
["clipper-staked-sail"] | ||
] | ||
} | ||
``` |
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 @@ | ||
[ | ||
{ | ||
"name": "Example of clipper-staked-sail Strategy", | ||
"strategy": { | ||
"name": "clipper-staked-sail" | ||
}, | ||
"network": "1", | ||
"decimals": 18, | ||
"addresses": [ | ||
"0x3334829670F9e8D309C9D9F318C4E6876755eDe2", | ||
"0x8e70Ca936a2f2d81cBbF1Dc84Aabe4213C87b8E9", | ||
"0x314C0695273Ba259Bb60074f2C92c67AC7ae6D40", | ||
"0x2c2e209465D5312e6dF0cd5F7D1066f1aff9a953", | ||
"0x4d768cFDb6E0077aD0a971678fa84DBcac32CE62", | ||
"0x26f8435Bf2a7B8b4771F0D5317beb09fB1F197C3" | ||
], | ||
"snapshot": 18558302 | ||
} | ||
] |
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,90 @@ | ||
import { multicall } from '../../utils'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
|
||
const vesailTokenAddress = '0x26fE2f89a1FEf1bC90b8a89D8AD18a1891166ff5'; | ||
const decimals = 18; | ||
|
||
export const author = 'cryptotrades20'; | ||
export const version = '0.1.0'; | ||
|
||
//read vesail balance | ||
const vesailBalanceOfABI = [ | ||
'function balanceOf(address account) view returns (uint256)' | ||
]; | ||
|
||
//vesail to sail conversion | ||
const toSAILABI = [ | ||
'function toSAIL(uint256 sailAmount) view returns (uint256)' | ||
]; | ||
|
||
/** | ||
* Voting power is calculated as the conversion of their vesail balance to sail | ||
* Then take that sail amount and apply square root operation to it | ||
*/ | ||
async function getVesailBalance(network, provider, snapshot, addresses) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
const response = await multicall( | ||
network, | ||
provider, | ||
vesailBalanceOfABI, | ||
addresses.map((address) => [vesailTokenAddress, 'balanceOf', [address]]), | ||
{ blockTag } | ||
); | ||
return response.map((result) => result[0]); | ||
} | ||
|
||
//read vesail to sail balance | ||
async function readToSail( | ||
network, | ||
provider, | ||
snapshot, | ||
addresses, | ||
vesailBalances | ||
) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
const response = await multicall( | ||
network, | ||
provider, | ||
toSAILABI, | ||
addresses.map((address, index) => [ | ||
vesailTokenAddress, | ||
'toSAIL', | ||
[vesailBalances[index]] | ||
]), | ||
{ blockTag } | ||
); | ||
return response.map((result) => result[0]); | ||
} | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
) { | ||
const vesailBalances = await getVesailBalance( | ||
network, | ||
provider, | ||
snapshot, | ||
addresses | ||
); | ||
const sailAmounts = await readToSail( | ||
network, | ||
provider, | ||
snapshot, | ||
addresses, | ||
vesailBalances | ||
); | ||
|
||
return Object.fromEntries( | ||
addresses.map((address, index) => [ | ||
address, | ||
//square root the resulting vesail to sail amount | ||
Math.sqrt( | ||
Number(BigNumber.from(sailAmounts[index].toString())) / 10 ** decimals | ||
) | ||
]) | ||
); | ||
} |
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
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,16 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "snote", | ||
"params": { "symbol": "sNOTE" } | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0xCece1920D4dBb96BAf88705ce0A6Eb3203ed2eB1", | ||
"0x4E8014fF5bacE498DAB1a9E2B5c3f4240bC059B6", | ||
"0x741AA7CFB2c7bF2A1E7D4dA2e3Df6a56cA4131F3" | ||
], | ||
"snapshot": 18629000 | ||
} | ||
] |
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,80 @@ | ||
import { BigNumberish } from '@ethersproject/bignumber'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'kaiserpy'; | ||
export const version = '0.1.0'; | ||
|
||
const abi = [ | ||
'function getVotes(address account) external view returns (uint256)', | ||
'function votingPowerWithoutDelegation(address account) external view returns (uint256)', | ||
'function delegates(address account) external view returns (address)' | ||
]; | ||
|
||
const STAKED_NOTE_CONTRACT_ADDRESS = | ||
'0x38de42f4ba8a35056b33a746a6b45be9b1c3b9d2'; | ||
|
||
interface VotingInfo { | ||
[address: string]: BigNumberish; | ||
} | ||
|
||
export async function strategy( | ||
space: any, | ||
network: string, | ||
provider: any, | ||
addresses: string[], | ||
options: any, | ||
snapshot: number | string | ||
) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
// Helper function to fetch data using multicall | ||
async function fetchMulticallData(method: string) { | ||
const multi = new Multicaller(network, provider, abi, { blockTag }); | ||
addresses.forEach((address) => | ||
multi.call(address, STAKED_NOTE_CONTRACT_ADDRESS, method, [address]) | ||
); | ||
return await multi.execute(); | ||
} | ||
|
||
// Fetch delegate votes, non-delegated votes, and delegation information | ||
const delegatedVotes: VotingInfo = await fetchMulticallData('getVotes'); | ||
const nonDelegatedVotes: VotingInfo = await fetchMulticallData( | ||
'votingPowerWithoutDelegation' | ||
); | ||
const delegationInfo: Record<string, boolean> = await fetchMulticallData( | ||
'delegates' | ||
).then((result2: Record<string, string>) => | ||
Object.fromEntries( | ||
Object.entries(result2).map(([address, delegate]) => [ | ||
address, | ||
delegate.toLowerCase() === '0x0000000000000000000000000000000000000000' | ||
]) | ||
) | ||
); | ||
|
||
// Process and filter the data | ||
const delegateVotingPowers = Object.fromEntries( | ||
Object.entries(delegatedVotes).map(([address, balance]) => [ | ||
address, | ||
parseFloat(formatUnits(balance, 8)) | ||
]) | ||
); | ||
const votingPowers = Object.fromEntries( | ||
Object.entries(nonDelegatedVotes).map(([address, balance]) => [ | ||
address, | ||
parseFloat(formatUnits(balance, 8)) | ||
]) | ||
); | ||
|
||
const filteredBalances: Record<string, number> = {}; | ||
addresses.forEach((address) => { | ||
if (delegationInfo[address]) { | ||
const delegateVotingPower = delegateVotingPowers[address] || 0; | ||
const votingPower = votingPowers[address] || 0; | ||
filteredBalances[address] = delegateVotingPower + votingPower; | ||
} | ||
}); | ||
|
||
return filteredBalances; | ||
} |
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
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