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

[sd-reverse-delegation] new strategy: sd reverse delegation #1341

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ import * as gelatoStaking from './gelato-staking';
import * as erc4626AssetsOf from './erc4626-assets-of';
import * as sdVoteBoostTWAVPV2 from './sd-vote-boost-twavp-v2';
import * as sdVoteBoostTWAVPV3 from './sd-vote-boost-twavp-v3';
import * as sdReverseDelegation from './sd-reverse-delegation';
import * as friendTech from './friend-tech';
import * as moonbase from './moonbase';
import * as dssVestUnpaid from './dss-vest-unpaid';
Expand Down Expand Up @@ -946,6 +947,7 @@ const strategies = {
'friend-tech': friendTech,
'sd-vote-boost-twavp-v2': sdVoteBoostTWAVPV2,
'sd-vote-boost-twavp-v3': sdVoteBoostTWAVPV3,
'sd-reverse-delegation': sdReverseDelegation,
moonbase: moonbase,
'dss-vest-unpaid': dssVestUnpaid,
'dss-vest-balance-and-unpaid': dssVestBalanceAndUnpaid,
Expand Down
49 changes: 49 additions & 0 deletions src/strategies/sd-reverse-delegation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# reverse delegation

The reserve delegation allow the delegation address to receive automatically all the voting power, even if an user didn't delegate to the delegation address.
Each user can still delegate to the delegation address, it will change nothing.
If an user delegate to another address then the delegation address, the delegation address will not receive his voting power.

Here is an example of parameters:

```json
[
{
"name": "Stake DAO reverse delegation",
"strategy": {
"name": "sd-reverse-delegation",
"params": {
"strategies": [
{
"name": "sd-vote-boost-twavp",
"params": {
"veToken": "0x0C462Dbb9EC8cD1630f1728B2CFD2769d09f0dd5",
"liquidLocker": "0xD13F8C25CceD32cdfA79EB5eD654Ce3e484dCAF5",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5",
"symbol": "sdToken",
"decimals": 18,
"sampleSize": 30,
"sampleStep": 5,
"avgBlockTime": 12.0
}
}
],
"delegationSpace": "sdangle.eth",
"delegationAddress": "0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5"
}
},
"network": "1",
"addresses": [
"0x12d3D411d010891a88BFf2401bD73FA41fb1316e",
"0xDdB50FfDbA4D89354E1088e4EA402de895562173",
"0x1A162A5FdaEbb0113f7B83Ed87A43BCF0B6a4D1E",
"0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"0xF930EBBd05eF8b25B1797b9b2109DDC9B0d43063",
"0xb0e83C2D71A991017e0116d58c5765Abc57384af"
],
"snapshot": 18430677
}
]

```
38 changes: 38 additions & 0 deletions src/strategies/sd-reverse-delegation/examples-sdangle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "Stake DAO reverse delegation",
"strategy": {
"name": "sd-reverse-delegation",
"params": {
"strategies": [
{
"name": "sd-vote-boost-twavp",
"params": {
"veToken": "0x0C462Dbb9EC8cD1630f1728B2CFD2769d09f0dd5",
"liquidLocker": "0xD13F8C25CceD32cdfA79EB5eD654Ce3e484dCAF5",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5",
"symbol": "sdToken",
"decimals": 18,
"sampleSize": 30,
"sampleStep": 5,
"avgBlockTime": 12.0
}
}
],
"delegationSpace": "sdangle.eth",
"delegationAddress": "0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5"
}
},
"network": "1",
"addresses": [
"0x12d3D411d010891a88BFf2401bD73FA41fb1316e",
"0xDdB50FfDbA4D89354E1088e4EA402de895562173",
"0x1A162A5FdaEbb0113f7B83Ed87A43BCF0B6a4D1E",
"0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"0xF930EBBd05eF8b25B1797b9b2109DDC9B0d43063",
"0xb0e83C2D71A991017e0116d58c5765Abc57384af"
],
"snapshot": 18430677
}
]
35 changes: 35 additions & 0 deletions src/strategies/sd-reverse-delegation/examples-sdcrv-gov.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"name": "Stake DAO reverse delegation",
"strategy": {
"name": "sd-reverse-delegation",
"params": {
"strategies": [
{
"name": "sd-vote-boost-twavp",
"params": {
"symbol": "sdCRV",
"veToken": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
"decimals": 18,
"sampleSize": 30,
"sampleStep": 5,
"avgBlockTime": 12,
"liquidLocker": "0x52f541764E6e90eeBc5c21Ff570De0e2D63766B6",
"sdTokenGauge": "0x7f50786A0b15723D741727882ee99a0BF34e3466"
}
}
],
"delegationSpace": "sdcrv-gov.eth",
"delegationAddress": "0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"sdTokenGauge": "0x7f50786A0b15723D741727882ee99a0BF34e3466"
}
},
"network": "1",
"addresses": [
"0xb0e83C2D71A991017e0116d58c5765Abc57384af",
"0xb957DccaA1CCFB1eB78B495B499801D591d8a403",
"0x52ea58f4FC3CEd48fa18E909226c1f8A0EF887DC"
],
"snapshot": 18481919
}
]
45 changes: 45 additions & 0 deletions src/strategies/sd-reverse-delegation/examples-sdcrv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"name": "Stake DAO reverse delegation",
"strategy": {
"name": "sd-reverse-delegation",
"params": {
"strategies": [
{
"name": "sd-vote-boost-twavp-v3",
"params": {
"pools": [
"0xca0253a98d16e9c1e3614cafda19318ee69772d0"
],
"symbol": "sdToken",
"sdToken": "0xD1b5651E55D4CeeD36251c61c50C889B36F6abB5",
"veToken": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
"decimals": 18,
"botAddress": "0xb4542526afee2fda1d584213d1521272a398b42a",
"sampleSize": 10,
"sampleStep": 5,
"liquidLocker": "0x52f541764E6e90eeBc5c21Ff570De0e2D63766B6",
"sdTokenGauge": "0x7f50786A0b15723D741727882ee99a0BF34e3466",
"whiteListedAddress": [
"0x1c0D72a330F2768dAF718DEf8A19BAb019EEAd09"
]
}
}
],
"delegationSpace": "sdcrv.eth",
"delegationAddress": "0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"sdTokenGauge": "0x7f50786A0b15723D741727882ee99a0BF34e3466"
}
},
"network": "1",
"addresses": [
"0xb0e83C2D71A991017e0116d58c5765Abc57384af",
"0xb4542526AfeE2FdA1D584213D1521272a398B42a",
"0x578a4af5cbc3009487a89be88bc560157200795b",
"0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"0xF930EBBd05eF8b25B1797b9b2109DDC9B0d43063",
"0xf872703F1C8f93fA186869Bac83BAC5A0c87C3c8"
],
"snapshot": 18430677
}
]
38 changes: 38 additions & 0 deletions src/strategies/sd-reverse-delegation/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "Stake DAO reverse delegation",
"strategy": {
"name": "sd-reverse-delegation",
"params": {
"strategies": [
{
"name": "sd-vote-boost-twavp",
"params": {
"veToken": "0x0C462Dbb9EC8cD1630f1728B2CFD2769d09f0dd5",
"liquidLocker": "0xD13F8C25CceD32cdfA79EB5eD654Ce3e484dCAF5",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5",
"symbol": "sdToken",
"decimals": 18,
"sampleSize": 30,
"sampleStep": 5,
"avgBlockTime": 12.0
}
}
],
"delegationSpace": "sdangle.eth",
"delegationAddress": "0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"sdTokenGauge": "0xE55843a90672f7d8218285e51EE8fF8E233F35d5"
}
},
"network": "1",
"addresses": [
"0x12d3D411d010891a88BFf2401bD73FA41fb1316e",
"0xDdB50FfDbA4D89354E1088e4EA402de895562173",
"0x1A162A5FdaEbb0113f7B83Ed87A43BCF0B6a4D1E",
"0x52ea58f4fc3ced48fa18e909226c1f8a0ef887dc",
"0xF930EBBd05eF8b25B1797b9b2109DDC9B0d43063",
"0xb0e83C2D71A991017e0116d58c5765Abc57384af"
],
"snapshot": 18530676
}
]
138 changes: 138 additions & 0 deletions src/strategies/sd-reverse-delegation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { getDelegations } from '../../utils/delegation';
import { getScoresDirect } from '../../utils';
import { multicall } from '../../utils';
import { formatUnits } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { getAddress } from '@ethersproject/address';

export const author = 'pierremarsotlyon1';
export const version = '0.1.0';
export const dependOnOtherAddress = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pierremarsotlyon1 Right now we are not accepting strategies that depend on other addresses to calculate voting power. these types of strategies are usually not scalable, you see some other way to handle this without depending on other voters

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@pierremarsotlyon1 pierremarsotlyon1 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ChaituVR
I didn't really understand the issue here
I'm just calculating the voting power of each voters to calculate the voting power of another voter
Which is basically like calculate the voting power of each voters like all the other strategies

For example, if we have these voters : [0x1, 0x2, 0x3] and the strategy will want to calculate the voting power of 0x3 (based on strategy parameters), I will calculate the voting power of 0x1 and 0x2 to assign the voting power of 0x3

What's the issue here ?

and you already have few strategies with dependOnOtherAddress set at true like 'src/strategies/delegation/index.ts'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do have other 15 old strategies that depend on other addresses, but we stopped accepting new ones as they are not scalable and causing lot of trouble, one alternative way is running seperate server to return the voting power of addresses and using the strategy api-v2-override

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is something that i don't understand
Currently, with your current default delegation strategy, how you reduce the delegation address voting power if there are some voters who delegated to the delegation address ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, with your current default delegation strategy, how you reduce the delegation address voting power if there are some voters who delegated to the delegation address?

We calculate voting power for all addresses again (that's the pain problem 🙈 ), and then we will just ignore the voting power of the delegator who voted from the delegate's voting power

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to calculate in a external server the voting power of each user and then compute the delegation address voting power in the strategy ?

the delegation address voting power will still be based on the voter addresses but at least the user voting power will be compute externally
So basically, the strategy will just fetch voting powers with an endpoint and then do plus/minus stuff

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your strategy can do anything within limits mentioned here https:/snapshot-labs/snapshot-strategies#code just that depending on other addresses is not scalable for us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we're blocked with what we want to achieve and your requirements.
Is it really not possible to push this strat ?

Otherwise, is it possible to use your delegation strategy (like currently we have) but use a custom delegation contract address by the strategy settings ?
Or is it possible to add this logic on your side ?

Basically, our "custom" delegation contract will be the same as yours but with new functions


// Used ABI
const abi = [
'function totalSupply() external view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {

const delegationSpace = options.delegationSpace || space;

// Fetch totalSupply + delegations data
const calls: any[] = [
multicall(network, provider, abi, [[options.sdTokenGauge, 'totalSupply']], { blockTag: snapshot }),
getDelegations(
delegationSpace,
network,
addresses,
snapshot
)
];

// If we have an delegation address, fetch VP for users who voted (to minus them after)
let delegationAddressLc = "";
let haveDelegationAddress = false;
if (options.delegationAddress) {

delegationAddressLc = options.delegationAddress.toLowerCase();
haveDelegationAddress = addresses.find((addr: string) => addr.toLowerCase() === delegationAddressLc);

if (haveDelegationAddress) {
// Fetch vp from users who voted
const otherAddresses = addresses.filter((addr: string) => addr.toLowerCase() !== delegationAddressLc);
calls.push(getScoresDirect(
space,
options.strategies,
network,
provider,
otherAddresses,
snapshot
));
}
}

// Fetch
let [callTotalSupply, delegations, ...userScores] = await Promise.all(calls);

// Compute the total supply
const totalSupply = parseFloat(formatUnits(BigNumber.from(callTotalSupply.shift()[0]), 18));

if (Object.keys(delegations).length === 0) return {};

// Just to avoid type error
const delegationValues = Object.values(delegations) as string[][];

// Fetch the VP for each delegates
const scores = (
await getScoresDirect(
space,
options.strategies,
network,
provider,
delegationValues.reduce((a: string[], b: string[]) =>
a.concat(b)
),
snapshot
)
).filter((score) => Object.keys(score).length !== 0);

// Sum the VP for all delegators
// ie : VP delegator = SUM(vp delegates)
// Here we should have something like :
// {'0x1': 100, '0x2': 300}
const delegationSum = Object.fromEntries(
addresses.map((address) => {
const addressScore = delegations[address]
? delegations[address].reduce(
(a, b) => a + scores.reduce((x, y) => (y[b] ? x + y[b] : x), 0),
0
)
: 0;
return [address.toLowerCase(), addressScore];
})
);

// If we have a delegation address set in the parameters, we assign it the whole VP
// Then we reduce the VP from users who voted + VP from other delegators
if (haveDelegationAddress) {

// Fetch vp from users who voted
userScores = userScores.filter((score) => Object.keys(score).length !== 0);

// Assign the whole VP
delegationSum[delegationAddressLc] = totalSupply;

// Compute and remove VP from users who voted
for (const userScore of userScores) {
for (const obj of userScore) {
for (const addr of Object.keys(obj)) {
delegationSum[delegationAddressLc] -= obj[addr];
}
}
}

// Remove VP from other delegators
for (const addr of Object.keys(delegationSum)) {
if (addr.toLowerCase() === delegationAddressLc) {
continue;
}

delegationSum[delegationAddressLc] -= delegationSum[addr];
}
}

// Checksum addresses
const checksumAddresses: any = {};
for (const addr of Object.keys(delegationSum)) {
checksumAddresses[getAddress(addr)] = delegationSum[addr];
}

return checksumAddresses;
}
Loading