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
86 changed files
with
3,802 additions
and
804 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SNAPSHOT_API_STRATEGY_SALT=12345 # Salt for the snapshot API strategy to send a key in header (optional) | ||
PASSPORT_API_KEY= # API key for the passport API (optional for other strategies) | ||
PASSPORT_SCORER_ID= # Scorer ID for the passport API (optional for other strategies) |
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 |
---|---|---|
|
@@ -20,4 +20,3 @@ jobs: | |
run: | | ||
yarn install --frozen-lockfile | ||
yarn build | ||
yarn lint |
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,28 @@ | ||
name: Fix lint | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 0 10 * * 0 | ||
|
||
jobs: | ||
fix-lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '16.10.x' | ||
- name: Run lint script | ||
run: | | ||
yarn install --frozen-lockfile | ||
yarn lint:fix | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
commit-message: Automated lint | ||
title: Automated lint | ||
body: | | ||
- Changes from lint script | ||
Auto-generated by Github Actions | ||
branch: automated-lint |
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 |
---|---|---|
@@ -1,28 +1,8 @@ | ||
name: Lint | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 0 10 * * 0 | ||
|
||
on: [push] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '16.10.x' | ||
- name: Run lint script | ||
run: | | ||
yarn install --frozen-lockfile | ||
yarn lint | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
commit-message: Automated lint | ||
title: Automated lint | ||
body: | | ||
- Changes from lint script | ||
Auto-generated by Github Actions | ||
branch: automated-lint | ||
uses: snapshot-labs/actions/.github/workflows/lint.yml@main | ||
secrets: inherit |
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
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
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,11 @@ | ||
# Delegate Registry v2 | ||
|
||
A general-purpose delegate registry. | ||
|
||
In order to utilize this, the 'Strategy Zero Gated' validation strategy is necessary. This is to prevent the delegator from also using the votes that have been delegated. | ||
|
||
This strategy: | ||
|
||
- returns a score of 0 for addresses that are delegating to other addresses (PS: addresses that return a score of 0 should not be allowed to vote), | ||
- returns a score greater than 0 for addresses that are delegated to and are not delegating (PS: only the amount delegated to the address is returned; this needs to be merged with the scores from other strategies in the space to get the addresses total score), | ||
- returns nothing for addresses that are not delegating to other addresses or delegated to. |
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,45 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "delegate-registry-v2", | ||
"params": { | ||
"backendUrl": "https://delegate-registry-backend.vercel.app", | ||
"strategies": [ | ||
{ | ||
"name": "erc20-balance-of", | ||
"params": { | ||
"address": "0x6b175474e89094c44da98b954eedeac495271d0f", | ||
"symbol": "DAI", | ||
"decimals": 18 | ||
} | ||
}, | ||
{ | ||
"name": "gno", | ||
"params": { | ||
"symbol": "GNO", | ||
"decimals": 18, | ||
"SUBGRAPH_URL": "https://api.thegraph.com/subgraphs/id/QmduKVUHCPjR5tmNEgooXHBMGKqDJWrUPdp6dEMeJM6Kqa" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x000e37ed92d86a7667f520c53b73b01ff5c206eb", | ||
"0x000dbf2733da51135c1b21c8ef71a3d474383f0d", | ||
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7", | ||
"0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", | ||
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7", | ||
"0x1E1A51E25f2816335cA436D65e9Af7694BE232ad", | ||
"0x1F717Ce8ff07597ee7c408b5623dF40AaAf1787C", | ||
"0x1c7a9275F2BD5a260A9c31069F77d53473b8ae2e", | ||
"0x1d5E65a087eBc3d03a294412E46CE5D6882969f4", | ||
"0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11", | ||
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7", | ||
"0x1E1A51E25f2816335cA436D65e9Af7694BE232ad" | ||
], | ||
"snapshot": 17463998 | ||
} | ||
] |
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,109 @@ | ||
import fetch from 'cross-fetch'; | ||
import { StaticJsonRpcProvider } from '@ethersproject/providers'; | ||
import { Strategy } from '@snapshot-labs/snapshot.js/dist/voting/types'; | ||
import { getScoresDirect } from '../../utils'; | ||
import { getAddress } from '@ethersproject/address'; | ||
|
||
export const author = 'gnosis'; | ||
export const version = '0.0.1'; | ||
|
||
const DEFAULT_BACKEND_URL = 'https://delegate-registry-backend.vercel.app'; | ||
|
||
type Params = { | ||
backendUrl: string; | ||
strategies: Strategy[]; | ||
}; | ||
|
||
/* | ||
This strategy: | ||
- returns a score of 0 for addresses that are delegating to other addresses (PS: addresses that returns a score of 0, should not be allowed to vote), | ||
- returns a score greater than 0, for addresses that are delegated to (PS: only the amount delegated to the address us returned, this needs to be merged with the scores from other strategies in the space), | ||
- returns nothing for addresses that are not delegating to other addresses or delegated to. | ||
*/ | ||
export async function strategy( | ||
space: string, | ||
network: string, | ||
provider: StaticJsonRpcProvider, | ||
addresses: string[], | ||
options: Params = { backendUrl: DEFAULT_BACKEND_URL, strategies: [] }, | ||
snapshot: string | number | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
if (options.strategies.length > 8) | ||
throw new Error('Maximum 8 strategies allowed'); | ||
|
||
const response = await fetch( | ||
`${options.backendUrl}/api/${space}/snapshot/${blockTag}/strategy-formatted-vote-weights`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
addresses: addresses, | ||
strategies: options.strategies | ||
}) | ||
} | ||
); | ||
|
||
const delegationScores = (await response.json()) as [ | ||
address: string, | ||
voteWeight: string | ||
][]; | ||
|
||
// gets an array of all addresses that are in the addresses array, but not present in the response | ||
const addressesNotDelegatingOrDelegatedTo = addresses.filter( | ||
(address) => !delegationScores.find((score) => score[0] === address) | ||
); | ||
|
||
const addressesDelegating = delegationScores.filter( | ||
(score) => score[1] === '0' | ||
); | ||
|
||
const addressesDelegatedTo = delegationScores.filter( | ||
(score) => score[1] !== '0' | ||
); | ||
|
||
const addressesOwnScore = await getScoresDirect( | ||
space, | ||
options.strategies, | ||
network, | ||
provider, | ||
[ | ||
...addressesNotDelegatingOrDelegatedTo, | ||
...addressesDelegatedTo.map(([address]) => address) | ||
], | ||
snapshot | ||
); | ||
|
||
const delegationObject = addressesDelegatedTo.reduce( | ||
(pre, [address, score]) => { | ||
pre[getAddress(address)] = score; | ||
return pre; | ||
}, | ||
{} | ||
); | ||
|
||
const addressesScores = addressesOwnScore.reduce((pre, address) => { | ||
const addressKeys = Object.keys(address); | ||
const addressValues = Object.values(address); | ||
addressKeys.forEach((key, index) => { | ||
if (pre.hasOwnProperty(key)) { | ||
pre[getAddress(key)] = pre[getAddress(key)] + addressValues[index]; | ||
} else { | ||
pre[getAddress(key)] = addressValues[index]; | ||
} | ||
}); | ||
return pre; | ||
}, delegationObject); | ||
|
||
// add a 0 score for all addressesDelegating | ||
const finalScores = addressesDelegating.reduce((pre, [address]) => { | ||
pre[getAddress(address)] = 0; | ||
return pre; | ||
}, addressesScores); | ||
|
||
return finalScores; | ||
} |
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,3 @@ | ||
# dss-vest-balance-and-unpaid | ||
|
||
For an ERC20 token with a [DssVest](https://github.com/makerdao/dss-vest) token vesting contract, this strategy returns the sum of the voters' token balance and the vested but yet unclaimed tokens of the voters. |
Oops, something went wrong.