Skip to content

Commit

Permalink
Merge branch 'snapshot-labs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina authored Sep 10, 2023
2 parents 60be5c9 + e978c32 commit 19a908e
Show file tree
Hide file tree
Showing 43 changed files with 1,156 additions and 278 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
allow:
# Allow updates for snapshot.js only
- dependency-name: "@snapshot-labs/snapshot.js"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@ethersproject/strings": "^5.6.1",
"@ethersproject/units": "^5.6.1",
"@ethersproject/wallet": "^5.6.2",
"@snapshot-labs/snapshot.js": "^0.4.109",
"@snapshot-labs/snapshot.js": "^0.5.8",
"@spruceid/didkit-wasm-node": "^0.2.1",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/v3-sdk": "^3.9.0",
Expand Down
13 changes: 6 additions & 7 deletions src/strategies/aave-governance-power/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Contract call strategy
# aave-governance-power strategy

Allows to get Voting power or Proposition power from an Aave GovernanceStrategy contract.

## Strategy Parameters
## Params

| Param | Type | Description | | |
| ------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------- | --- | --- |
| governanceStrategy | string | The Ethereum address of the GovernanceStrategy contract to measure voting or proposition power from an address at a block. | | |
| powerType | string | Use `vote` for Voting Power or `proposition` for Proposition Power | | |
| | | | | |
| Param | Type | Description |
| --- | --- | --- |
| governanceStrategy | string | The Ethereum address of the GovernanceStrategy contract to measure voting or proposition power from an address at a block. |
| powerType | string | Use `vote` for Voting Power or `proposition` for Proposition Power |
10 changes: 5 additions & 5 deletions src/strategies/aave-governance-power/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"strategy": {
"name": "aave-governance-power",
"params": {
"governanceStrategy": "0xb7e383ef9b1e9189fc0f71fb30af8aa14377429e",
"symbol": "AAVE+stkAAVE",
"decimals": 18,
"powerType": "vote",
"symbol": "Voting Power",
"decimals": 18
"governanceStrategy": "0xb7e383ef9b1e9189fc0f71fb30af8aa14377429e"
}
},
"network": "1",
"addresses": ["0x5BC928BF0DAb1e4A2ddd9e347b0F22e88026D76c"],
"snapshot": 12657715
"addresses": ["0x329c54289Ff5D6B7b7daE13592C6B1EDA1543eD4", "0x57ab7ee15cE5ECacB1aB84EE42D5A9d0d8112922", "0x0ab97008cad303a8C90ea630c282760284c19e93"],
"snapshot": 18054498
}
]
22 changes: 2 additions & 20 deletions src/strategies/aave-governance-power/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,8 @@ export const version = '0.1.0';
*/

const abi = [
{
inputs: [
{ internalType: 'address', name: 'user', type: 'address' },
{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }
],
name: 'getPropositionPowerAt',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
},
{
inputs: [
{ internalType: 'address', name: 'user', type: 'address' },
{ internalType: 'uint256', name: 'blockNumber', type: 'uint256' }
],
name: 'getVotingPowerAt',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function'
}
'function getPropositionPowerAt(address user, uint256 blockNumber) view returns (uint256)',
'function getVotingPowerAt(address user, uint256 blockNumber) view returns (uint256)'
];

const powerTypesToMethod = {
Expand Down
40 changes: 40 additions & 0 deletions src/strategies/aave-governance-power/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"symbol": {
"type": "string",
"title": "Symbol",
"examples": ["e.g. DOODLE"],
"maxLength": 16
},
"governanceStrategy": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"powerType": {
"type": "string",
"title": "Power type",
"enum": ["vote", "proposition"]
},
"decimals": {
"type": "integer",
"title": "Decimals",
"examples": ["e.g. 18"],
"minimum": 0,
"maximum": 18
}
},
"required": ["governanceStrategy", "powerType", "decimals"],
"additionalProperties": false
}
}
}
35 changes: 0 additions & 35 deletions src/strategies/deposit-in-sablier-stream/examples.json

This file was deleted.

17 changes: 17 additions & 0 deletions src/strategies/erc20-balance-of-top-holders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# erc20-balance-of-top-holders

Strategy, that accept votes only from top N token holders

Subgraph should be compatible with [OpenZeppelin ERC20 Subgraph](https://github.com/OpenZeppelin/openzeppelin-subgraphs)

Here is an example of parameters:

```json
{
"address": "0x8494Aee22e0DB34daA1e8D6829d85710357be9F7",
"symbol": "HANDZ",
"decimals": 18,
"subgraphUrl": "https://api.thegraph.com/subgraphs/name/kostyamospan/handz-token",
"topHolders": 5
}
```
30 changes: 30 additions & 0 deletions src/strategies/erc20-balance-of-top-holders/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"name": "Example query",
"strategy": {
"name": "erc20-balance-of-top-holders",
"params": {
"address": "0x8494Aee22e0DB34daA1e8D6829d85710357be9F7",
"symbol": "HANDZ",
"decimals": 18,
"subgraphUrl": "https://api.thegraph.com/subgraphs/name/kostyamospan/handz-token",
"topHolders": 5
}
},
"network": "1",
"addresses": [
"0xD87dec8eE5d941234d85a9d2636D077fE03B0660",
"0x54B9ca09248C49e9ed0968bfD0AA0bd13E85992A",
"0x254c8A6225CE32903D2657D0945701ACD6e42188",
"0xF59Dd6525529F77cF90Ec9A8205d52874af7a425",
"0x0a0A1669A7E3f16b3010dD78F53D3E22Dcf4b739",
"0x5b941eA7387190Ba6a0bF4B766c1F3eB0Ab30A25",
"0xc0D57b31F33Ce4f6627d353Ac51461fB7cDC1519",
"0xF5De2507726A312aD6f806A9972Ed438344022b2",
"0x33b5752C03495014A130f8f4A235f6280C58f266",
"0x6323b71f37a07642F8055E9847B58Ffc9FA44243",
"0xf5F730146D177Cf7Dd28AA39F81359DaE51D4379"
],
"snapshot": 18020926
}
]
73 changes: 73 additions & 0 deletions src/strategies/erc20-balance-of-top-holders/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { subgraphRequest } from '../../utils';
import { getAddress } from '@ethersproject/address';

export const author = 'RedDuck-Software';
export const version = '0.0.1';

async function getTopHoldersBalance(
url,
options,
snapshot
): Promise<Record<string, number>> {
const topHoldersAmount = +options.topHolders || 0;

const query = {
erc20Balances: {
__args: {
where: {
account_not: null,
contract: options.address
},
orderBy: 'valueExact',
orderDirection: 'desc',
first: topHoldersAmount
},
value: true,
contract: true,
account: {
id: true
}
}
};

if (snapshot !== 'latest') {
// @ts-ignore
query.erc20Balances.__args.block = { number: snapshot };
}

const topHolders: Record<string, number> = {};

const result = await subgraphRequest(url, query);

if (result && result.erc20Balances) {
result.erc20Balances.forEach((tokenBalance) => {
const address = getAddress(tokenBalance.account.id);
const balance = parseFloat(tokenBalance.value);
topHolders[address] = balance;
});
}

return topHolders;
}

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const topHoldersBalancesScores = await getTopHoldersBalance(
options.subgraphUrl,
options,
snapshot
);

return Object.fromEntries(
addresses.map((address) => [
address,
topHoldersBalancesScores[address] ? topHoldersBalancesScores[address] : 0
])
);
}
12 changes: 12 additions & 0 deletions src/strategies/friend-tech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# friend-tech

This strategy allocates voting power according to the number of keys (or shares) a voter possesses on friend.tech for a particular user.

Here is an example of parameters:

```json
{
"address": "0xe12a2f60b400e6c6971d5602df454e5da63edd78",
"symbol": "KEYS"
}
```
19 changes: 19 additions & 0 deletions src/strategies/friend-tech/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "Example query",
"strategy": {
"name": "friend-tech",
"params": {
"address": "0xe12A2f60B400E6c6971D5602DF454E5dA63eDD78",
"symbol": "KEYS"
}
},
"network": "8453",
"addresses": [
"0x81a9a7979f5EB27588b5AB9448398ad321Dba90C",
"0x3B7576DF0Ef2d6c1656245aE15Ad52DCf34FD04a",
"0x7C2FDC7de9F536560E47105257a57C8C8dF79372"
],
"snapshot": 2933820
}
]
33 changes: 33 additions & 0 deletions src/strategies/friend-tech/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'bonustrack';
export const version = '0.1.0';

const abi = ['function sharesBalance(address,address) view returns (uint256)'];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const contract = '0xcf205808ed36593aa40a44f10c7f7c2f67d4a4d4';

const multi = new Multicaller(network, provider, abi, { blockTag });
addresses.forEach((address) =>
multi.call(address, contract, 'sharesBalance', [options.address, address])
);
const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, 0))
])
);
}
28 changes: 28 additions & 0 deletions src/strategies/friend-tech/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"address": {
"type": "string",
"title": "User address",
"examples": ["e.g. 0xe12a2f60b400e6c6971d5602df454e5da63edd78"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"symbol": {
"type": "string",
"title": "Symbol",
"examples": ["e.g. KEYS"],
"maxLength": 16
}
},
"required": ["address"],
"additionalProperties": false
}
}
}
Loading

0 comments on commit 19a908e

Please sign in to comment.