forked from Proof-Of-Humanity/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add synthetix-quadratic_2 and [synthetix-non-quadratic_2] strategies …
…/ fix previous README.md (snapshot-labs#496) * add new strategy * update existing strategy for upcoming election * update endpoints * add into index * revert synthetix back to original * introduce a new strategy * import in index * remove console log and ensure test work * refactor * add synthetix-non-quadratic_2 * fix synthetix-non-quadratic_1 readme * add synthetix-quadratic_2 strategy * fix other strategies readme * fix readme
- Loading branch information
Showing
10 changed files
with
395 additions
and
3 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
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 @@ | ||
# Non-Quadratic Debt Percentage Strategy | ||
|
||
Calculates the weighting of voters, based on their debt percentage in the previous fee period. | ||
|
||
## Examples | ||
|
||
Can be used instead of the erc20-balance-of strategy, the space config will look like this: | ||
|
||
```JSON | ||
{ | ||
"strategies": [ | ||
["synthetix-non-quadratic_2"] | ||
] | ||
} | ||
``` |
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,27 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "synthetix-non-quadratic_2", | ||
"params": { | ||
"address": "0x023c66b7e13d30a3c46aa433fd2829763d5817c5", | ||
"symbol": "WD", | ||
"totalL2Debt": 40201854, | ||
"lastDebtLedgerEntryL2": 10909822163955610660349890, | ||
"L2BlockNumber": 4750287 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x78b037B39704e88a82DD23CFBE1f57f6AeF8EBC5", | ||
"0x0bc3668d2AaFa53eD5E5134bA13ec74ea195D000", | ||
"0xcAc59F91E4536Bc0E79aB816a5cD54e89f10433C", | ||
"0x6dc88B231Cd04Dd1b1e525161162993F47140006", | ||
"0x935D2fD458fdf41B6F7B62471f593797866a3Ce6", | ||
"0x24e445fe7708Bf4bC2ae8d4df1694C98Af8BDE4F", | ||
"0x49be88f0fcc3a8393a59d3688480d7d253c37d2a", | ||
"0x27Cc4d6bc95b55a3a981BF1F1c7261CDa7bB0931" | ||
], | ||
"snapshot": 14443440 | ||
} | ||
] |
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,153 @@ | ||
import { getAddress } from '@ethersproject/address'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { Contract } from '@ethersproject/contracts'; | ||
import { Provider } from '@ethersproject/providers'; | ||
import { subgraphRequest } from '../../utils'; | ||
import { | ||
DebtCacheABI, | ||
debtL1, | ||
debtL2, | ||
returnGraphParams, | ||
SNXHoldersResult, | ||
SynthetixStateABI | ||
} from '../synthetix/helper'; | ||
|
||
export const author = 'andytcf'; | ||
export const version = '1.0.0'; | ||
|
||
const MED_PRECISE_UNIT = 1e18; | ||
|
||
// @TODO: check if most-up-to-date version (using https://contracts.synthetix.io/SynthetixState) | ||
const SynthetixStateContractAddress = | ||
'0x4b9Ca5607f1fF8019c1C6A3c2f0CC8de622D5B82'; | ||
// @TODO: check if most-up-to-date version (using http://contracts.synthetix.io/DebtCache) | ||
const DebtCacheContractAddress = '0x1620Aa736939597891C1940CF0d28b82566F9390'; | ||
|
||
const defaultGraphs = { | ||
'1': 'https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix', | ||
'10': 'https://api.thegraph.com/subgraphs/name/synthetixio-team/optimism-main' | ||
}; | ||
|
||
const loadLastDebtLedgerEntry = async ( | ||
provider: Provider, | ||
snapshot: number | string | ||
) => { | ||
const contract = new Contract( | ||
SynthetixStateContractAddress, | ||
SynthetixStateABI, | ||
provider | ||
); | ||
|
||
const lastDebtLedgerEntry = await contract.lastDebtLedgerEntry({ | ||
blockTag: snapshot | ||
}); | ||
|
||
return BigNumber.from(lastDebtLedgerEntry); | ||
}; | ||
|
||
const loadL1TotalDebt = async ( | ||
provider: Provider, | ||
snapshot: number | string | ||
) => { | ||
const contract = new Contract( | ||
DebtCacheContractAddress, | ||
DebtCacheABI, | ||
provider | ||
); | ||
|
||
const currentDebtObject = await contract.currentDebt({ | ||
blockTag: snapshot | ||
}); | ||
|
||
return Number(currentDebtObject.debt) / MED_PRECISE_UNIT; | ||
}; | ||
|
||
export async function strategy( | ||
_space, | ||
_network, | ||
_provider, | ||
_addresses, | ||
_options, | ||
snapshot | ||
) { | ||
const score = {}; | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
/* Global Constants */ | ||
|
||
const totalL1Debt = await loadL1TotalDebt(_provider, snapshot); // (high-precision 1e18) | ||
const lastDebtLedgerEntry = await loadLastDebtLedgerEntry( | ||
_provider, | ||
snapshot | ||
); | ||
|
||
/* EDIT THESE FOR OVM */ | ||
|
||
// @TODO update the currentDebt for the snapshot from (https://contracts.synthetix.io/ovm/DebtCache) | ||
// const totalL2Debt = 40201854; | ||
const totalL2Debt = _options.totalL2Debt; | ||
// @TODO update the lastDebtLedgerEntry from (https://contracts.synthetix.io/ovm/SynthetixState) | ||
// const lastDebtLedgerEntryL2 = 10909822163955610660349890; | ||
const lastDebtLedgerEntryL2 = _options.lastDebtLedgerEntryL2; | ||
// @TODO update the comparison between OVM:ETH c-ratios at the time of snapshot | ||
const normalisedL2CRatio = 500 / 400; | ||
// @TODO update the L2 block number to use | ||
// const L2BlockNumber = 4750287; | ||
const L2BlockNumber = _options.L2BlockNumber; | ||
|
||
const scaledTotalL2Debt = totalL2Debt * normalisedL2CRatio; | ||
|
||
/* --------------- */ | ||
|
||
/* Using the subgraph, we get the relevant L1 calculations */ | ||
|
||
const l1Results = (await subgraphRequest( | ||
defaultGraphs[1], | ||
returnGraphParams(blockTag, _addresses) | ||
)) as SNXHoldersResult; | ||
|
||
if (l1Results && l1Results.snxholders) { | ||
for (let i = 0; i < l1Results.snxholders.length; i++) { | ||
const holder = l1Results.snxholders[i]; | ||
const vote = await debtL1( | ||
holder.initialDebtOwnership, | ||
holder.debtEntryAtIndex, | ||
totalL1Debt, | ||
scaledTotalL2Debt, | ||
lastDebtLedgerEntry, | ||
false | ||
); | ||
score[getAddress(holder.id)] = vote; | ||
} | ||
} | ||
|
||
/* Using the subgraph, we get the relevant L2 calculations */ | ||
|
||
const l2Results = (await subgraphRequest( | ||
defaultGraphs[10], | ||
returnGraphParams(L2BlockNumber, _addresses) | ||
)) as SNXHoldersResult; | ||
|
||
if (l2Results && l2Results.snxholders) { | ||
for (let i = 0; i < l2Results.snxholders.length; i++) { | ||
const holder = l2Results.snxholders[i]; | ||
|
||
const vote = await debtL2( | ||
holder.initialDebtOwnership, | ||
holder.debtEntryAtIndex, | ||
totalL1Debt, | ||
scaledTotalL2Debt, | ||
lastDebtLedgerEntryL2, | ||
false | ||
); | ||
|
||
if (score[getAddress(holder.id)]) { | ||
score[getAddress(holder.id)] += vote; | ||
} else { | ||
score[getAddress(holder.id)] = vote; | ||
} | ||
} | ||
} | ||
|
||
return score || {}; | ||
} |
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,15 @@ | ||
# Quadratic Debt Percentage Strategy | ||
|
||
Calculates the quadratic weighting of voters, based on their debt percentage in the previous fee period. | ||
|
||
## Examples | ||
|
||
Can be used instead of the erc20-balance-of strategy, the space config will look like this: | ||
|
||
```JSON | ||
{ | ||
"strategies": [ | ||
["synthetix-quadratic_2"] | ||
] | ||
} | ||
``` |
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,27 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "synthetix-quadratic_2", | ||
"params": { | ||
"address": "0x023c66b7e13d30a3c46aa433fd2829763d5817c5", | ||
"symbol": "WD", | ||
"totalL2Debt": 40201854, | ||
"lastDebtLedgerEntryL2": 10909822163955610660349890, | ||
"L2BlockNumber": 4750287 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x78b037B39704e88a82DD23CFBE1f57f6AeF8EBC5", | ||
"0x0bc3668d2AaFa53eD5E5134bA13ec74ea195D000", | ||
"0xcAc59F91E4536Bc0E79aB816a5cD54e89f10433C", | ||
"0x6dc88B231Cd04Dd1b1e525161162993F47140006", | ||
"0x935D2fD458fdf41B6F7B62471f593797866a3Ce6", | ||
"0x24e445fe7708Bf4bC2ae8d4df1694C98Af8BDE4F", | ||
"0x49be88f0fcc3a8393a59d3688480d7d253c37d2a", | ||
"0x27Cc4d6bc95b55a3a981BF1F1c7261CDa7bB0931" | ||
], | ||
"snapshot": 14443440 | ||
} | ||
] |
Oops, something went wrong.