Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clipper-staked-sail] add clipper-staked-sail strategy #1355

Merged
merged 10 commits into from
Nov 22, 2023
15 changes: 15 additions & 0 deletions src/strategies/clipper-staked-sail/README.md
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"]
]
}
```
20 changes: 20 additions & 0 deletions src/strategies/clipper-staked-sail/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"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
}
]

69 changes: 69 additions & 0 deletions src/strategies/clipper-staked-sail/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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),
])
);
}
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ import * as floki from './floki';
import * as hatsProtocolHatId from './hats-protocol-hat-id';
import * as hatsProtocolHatIds from './hats-protocol-hat-ids';
import * as bubblegumKids from './bubblegum-kids';
import * as clipperStakedSail from './clipper-staked-sail';

const strategies = {
'cap-voting-power': capVotingPower,
Expand Down Expand Up @@ -958,7 +959,8 @@ const strategies = {
floki,
'hats-protocol-hat-id': hatsProtocolHatId,
'hats-protocol-hat-ids': hatsProtocolHatIds,
'bubblegum-kids': bubblegumKids
'bubblegum-kids': bubblegumKids,
'clipper-staked-sail' : clipperStakedSail
};

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