Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BounebRayan authored Feb 12, 2025
2 parents 2d6f1f9 + 1b70d24 commit b2d43d9
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@ethersproject/strings": "^5.6.1",
"@ethersproject/units": "^5.6.1",
"@ethersproject/wallet": "^5.6.2",
"@snapshot-labs/snapshot.js": "^0.12.43",
"@snapshot-labs/snapshot.js": "^0.12.47",
"@spruceid/didkit-wasm-node": "^0.2.1",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/v3-sdk": "^3.9.0",
Expand Down
5 changes: 3 additions & 2 deletions src/strategies/aks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type VotingResponse = {
total: string;
};

const MINIUM_VOTING_POWER = 0.01;
const MINIMUM_VOTING_POWER = 0.01;
const SMART_CHEF_URL =
'https://api.thegraph.com/subgraphs/name/akshaysoam8/smartchef';
const VOTING_API_URL = 'https://voting-api.pancakeswap.info/api/power';
Expand Down Expand Up @@ -88,7 +88,8 @@ export async function strategy(

return {
...accum,
[address]: total <= MINIUM_VOTING_POWER ? MINIUM_VOTING_POWER : total
[address]:
total <= MINIMUM_VOTING_POWER ? MINIMUM_VOTING_POWER : total
};
},
{}
Expand Down
36 changes: 36 additions & 0 deletions src/strategies/dappcomposer-getvotingunits/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"name": "dAppComposer query",
"strategy": {
"name": "dappcomposer-getvotingunits",
"params": {
"address": "0xBcAA291f9b84A8B8dA02584F79587cCaEDfFE38a",
"decimals": 18
}
},
"network": "11155111",
"addresses": [
"0x890a8A5B2e0335a22DdB0a2Bd991f079591ff44C",
"0xC16A3fE7F94E8e55Dd50c8848380093fEA5aa714",
"0x6Fb67e33D101465065C87734a563731aB8c30bB1"
],
"snapshot": 7594600
},
{
"name": "dAppComposer query",
"strategy": {
"name": "dappcomposer-getvotingunits",
"params": {
"address": "0xBcAA291f9b84A8B8dA02584F79587cCaEDfFE38a",
"decimals": 18
}
},
"network": "11155111",
"addresses": [
"0x890a8A5B2e0335a22DdB0a2Bd991f079591ff44C",
"0xC16A3fE7F94E8e55Dd50c8848380093fEA5aa714",
"0x6Fb67e33D101465065C87734a563731aB8c30bB1"
],
"snapshot": 6456459
}
]
43 changes: 43 additions & 0 deletions src/strategies/dappcomposer-getvotingunits/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { Multicaller } from '../../utils';
import { formatUnits } from '@ethersproject/units';

export const author = 'tutellus';
export const version = '0.1.0';
export const name = 'dappcomposer-getvotingunits';

const veTokenABI = [
'function getVotingUnits(address account) public view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const blockTag = typeof snapshot === 'number' ? snapshot : undefined;

// Initialize Multicaller
const multi = new Multicaller(network, provider, veTokenABI, { blockTag });

// Third batch: Get voting power for each token
addresses.forEach((address) => {
multi.call(`${address}`, options.address, 'getVotingUnits', [address]);
});

const voteByTokenIds: Record<string, BigNumberish> = await multi.execute();

// Calculate final scores
const scores = {};
addresses.forEach((address) => {
let totalVotingPower = 0;
const power = voteByTokenIds[address];
totalVotingPower += Number(formatUnits(power, options.decimals || 18));
scores[address] = totalVotingPower;
});

return scores;
}
40 changes: 40 additions & 0 deletions src/strategies/erc1155-balance-of/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. UNI"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"tokenId": {
"type": "string",
"title": "Token ID",
"examples": ["e.g. 1, 0x8"],
"maxLength": 100
},
"decimals": {
"type": "number",
"title": "Decimals",
"examples": ["e.g. 18"],
"minimum": 0
}
},
"required": ["address", "tokenId", "decimals"],
"additionalProperties": false
}
}
}
11 changes: 11 additions & 0 deletions src/strategies/erc20-votes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# erc20-votes strategy

This strategy gets voting power from compound like contracts, it uses `getVotes` function to get the voting power of an address.

## Params

| Param | Type | Description |
| --- | --- | --- |
|`address`|`string`|The address of the contract to get the voting power from|
|`symbol`|`string`|The symbol of the token|
|`decimals`|`number`|The decimals of the token|
9 changes: 5 additions & 4 deletions src/strategies/erc20-votes/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"strategy": {
"name": "erc20-votes",
"params": {
"address": "0xc00e94cb662c3520282e6f5717214004a7f26888",
"address": "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
"symbol": "ENS"
}
},
"network": "1",
"addresses": [
"0x2B384212EDc04Ae8bB41738D05BA20E33277bf33",
"0xAC5720d6EE2d7872b88914C9c5Fa9BF38e72FaF6"
"0x552DF471a4c7Fea11Ea8d7a7b0Acc6989b902a95",
"0x89EdE5cBE53473A64d6C8DF14176a0d658dAAeDC",
"0x5BFCB4BE4d7B43437d5A0c57E908c048a4418390"
],
"snapshot": 12050071
"snapshot": 21791300
}
]
35 changes: 35 additions & 0 deletions src/strategies/erc20-votes/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$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. ENS"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"decimals": {
"type": "integer",
"title": "Decimals",
"examples": ["e.g. 18"],
"minimum": 0,
"maximum": 18
}
},
"required": ["address"],
"additionalProperties": false
}
}
}
2 changes: 1 addition & 1 deletion src/strategies/fountainhead/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function strategy(
const mCall2Result: Record<string, any> = await mCall2.execute();
const lockerByAddress = Object.fromEntries(
Object.entries(mCall2Result)
.filter(([_, { isCreated }]) => isCreated)
.filter(([, { isCreated }]) => isCreated)
.map(([addr, { lockerAddress }]) => [addr, lockerAddress])
);
const existingLockers = Object.values(lockerByAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const GIVETH_SUBGRAPH_API =
const XDAI_BLOCKS_API =
'https://subgrapher.snapshot.org/subgraph/arbitrum/HTGgWawRHBKr6tDe6umPoVNkYDoUpBEsJSGtX6A7N8MG';

const CIRUCLATING_SUPPLY_API = 'https://circulating.giveth.io/token-supply';
const CIRCULATING_SUPPLY_API = 'https://circulating.giveth.io/token-supply';
// "supplyField" : "circulating",

const blockParams = {
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function strategy(
);

const data = subgraphRequest(GIVETH_SUBGRAPH_API, params);
const supply = fetch(CIRUCLATING_SUPPLY_API, {
const supply = fetch(CIRCULATING_SUPPLY_API, {
method: 'GET',
headers: {
Accept: 'application/json',
Expand Down
6 changes: 4 additions & 2 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,9 @@ import * as morphoDelegation from './morpho-delegation';
import * as lizcoinStrategy2024 from './lizcoin-strategy-2024';
import * as realt from './realt';
import * as superfluidVesting from './superfluid-vesting';
import * as spookyLpSonic from './spooky-lp-sonic';
import * as spookyLpSonic from './spooky-lp-sonic';
import * as synapse from './synapse';
import * as dappcomposerGetVotingUnits from './dappcomposer-getvotingunits';

const strategies = {
'spooky-lp-sonic': spookyLpSonic,
Expand Down Expand Up @@ -958,7 +959,8 @@ const strategies = {
'lizcoin-strategy-2024': lizcoinStrategy2024,
realt,
'superfluid-vesting': superfluidVesting,
synapse
synapse,
'dappcomposer-getvotingunits': dappcomposerGetVotingUnits
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/meebitsdao-delegation/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# meebitsdao-delegation

This delegation strategy returns the balances of the voters for specific ERC20 [mVOX](https://polygonscan.com/address/0x7C1a4c36D9BDa5C568f0E4877CD8E27D74Ae66c6) and ERC721 [MFND](https://polygonscan.com/address/0xc34cbca32e355636c7f52dd8beab0af2396ebd79). The calcualation is as follows: users with MFND tokens can hold voting power and can be assigned as delegates, while users with mVOX tokens can delegate votes (to those who hold MFND tokens) but cannot hold actual vote themselves. This is different from the standard Snapshot voting strategy in that votes from delegators do not count themselves, if the votes are not delegated.
This delegation strategy returns the balances of the voters for specific ERC20 [mVOX](https://polygonscan.com/address/0x7C1a4c36D9BDa5C568f0E4877CD8E27D74Ae66c6) and ERC721 [MFND](https://polygonscan.com/address/0xc34cbca32e355636c7f52dd8beab0af2396ebd79). The calculation is as follows: users with MFND tokens can hold voting power and can be assigned as delegates, while users with mVOX tokens can delegate votes (to those who hold MFND tokens) but cannot hold actual vote themselves. This is different from the standard Snapshot voting strategy in that votes from delegators do not count themselves, if the votes are not delegated.

Here is an example of parameters:

Expand Down
7 changes: 2 additions & 5 deletions src/strategies/nedao/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const abi = [

function bytes32ToBool(bytes32) {
const hex = bytes32.startsWith('0x') ? bytes32.slice(2) : bytes32;
return (hex != 0) ? 1 : 0;
return hex != 0 ? 1 : 0;
}

export async function strategy(
Expand All @@ -34,9 +34,6 @@ export async function strategy(
const result: Record<string, BigNumber> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address, id]) => [
address,
bytes32ToBool(id),
])
Object.entries(result).map(([address, id]) => [address, bytes32ToBool(id)])
);
}
4 changes: 3 additions & 1 deletion src/strategies/nedao/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"typeValidation": {
"type": "string",
"title": "The keccak256 value of the bot",
"examples": ["e.g. 0xd36f63907c7fad13dd9dc69aa8b9af9c3296a3edad0b0b1eb50c10fd066fc910"],
"examples": [
"e.g. 0xd36f63907c7fad13dd9dc69aa8b9af9c3296a3edad0b0b1eb50c10fd066fc910"
],
"pattern": "^0x[a-fA-F0-9]{64}$",
"minLength": 66,
"maxLength": 66
Expand Down
12 changes: 6 additions & 6 deletions src/strategies/the-graph-balance/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export function getCuratorSignalledGRT(curator: Curator): number {
const signalAmount = parseFloat(deployment.signalAmount);
// we calculate the value of their signal based on the share they have
// of the total signal in the subgraph deployment
const deploymentSignalShareCoeficient = signalAmount
const deploymentSignalShareCoefficient = signalAmount
? signalledTokens / signalAmount
: 0;
result += deploymentSignalShareCoeficient * parsedSignal;
result += deploymentSignalShareCoefficient * parsedSignal;
}
// Get GRT of Curator for the name signal they have in each Deployment
for (const nameSignal of nameSignals) {
Expand All @@ -69,22 +69,22 @@ export function getCuratorSignalledGRT(curator: Curator): number {
const signalledTokens = parseFloat(deployment.signalledTokens);
const signal = parseFloat(nameSignal.signal);
const signalAmount = parseFloat(deployment.signalAmount);
const deploymentSignalShareCoeficient = signalAmount
const deploymentSignalShareCoefficient = signalAmount
? signalledTokens / signalAmount
: 0;

result += deploymentSignalShareCoeficient * signal;
result += deploymentSignalShareCoefficient * signal;
} else {
// edge case where curators didn't withdraw their signal from a deprecated subgraph
const subgraph = nameSignal.subgraph;
const withdrawableTokens = parseFloat(subgraph.withdrawableTokens);
const _nameSignal = parseFloat(nameSignal.nameSignal);
const nameSignalAmount = parseFloat(subgraph.nameSignalAmount);
const subgraphNameSignalShareCoeficient = nameSignalAmount
const subgraphNameSignalShareCoefficient = nameSignalAmount
? withdrawableTokens / nameSignalAmount
: 0;

result += subgraphNameSignalShareCoeficient * _nameSignal;
result += subgraphNameSignalShareCoefficient * _nameSignal;
}
}
// result is in wei, format it in GRT
Expand Down
9 changes: 5 additions & 4 deletions src/strategies/uniswap-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This strategy fetches the reserves of the user's positions in Uniswap V3.

## Params

|| **name** || **description** || **default** ||
|| tokenReserve || Token reserve to consider for scoring || ||
|| poolAddress || Pool address to fetch the positions from. || ||
|| subgraph || Subgraph URL to fetch the data from. || uniswap-v3 subgraph URL ||
| **name** | **description** | **default** |
| ---- | ---- | ---- |
| tokenReserve | Token reserve to consider for scoring | - |
| poolAddress | Pool address to fetch the positions from. | - |
| subgraph | Subgraph URL to fetch the data from. | uniswap-v3 subgraph URL |
4 changes: 3 additions & 1 deletion src/strategies/uniswap-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { subgraphRequest } from '../../utils';
import { getAllReserves } from './helper';

const UNISWAP_V3_SUBGRAPH_URL = {
'1': 'https://subgrapher.snapshot.org/subgraph/arbitrum/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV'
'1': 'https://subgrapher.snapshot.org/subgraph/arbitrum/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV',
'8453':
'https://subgrapher.snapshot.org/subgraph/arbitrum/43Hwfi3dJSoGpyas9VwNoDAv55yjgGrPpNSmbQZArzMG'
};

export const author = 'anassohail99';
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1239,10 +1239,10 @@
dependencies:
"@sinonjs/commons" "^2.0.0"

"@snapshot-labs/snapshot.js@^0.12.43":
version "0.12.43"
resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot.js/-/snapshot.js-0.12.43.tgz#576a97b6f96f0eaf18914b12d8d56fce9e11d70e"
integrity sha512-cZLj7wA/Hco9rFHxJcB56PzYU+VHJiPpdljoa3BHGZW9ojPjrxn3327oc6TZ8OInqUiwjbJKEHZRZpfNCDSR1Q==
"@snapshot-labs/snapshot.js@^0.12.47":
version "0.12.47"
resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot.js/-/snapshot.js-0.12.47.tgz#ad9a7ad01f876146a14e689a1e2e5eb0416eeec2"
integrity sha512-0Qt6qNyRzmC9SeyrtHzj/zx1F5cISWKi1dQ0dkmbTa/SSCVU7B5ke9V5cvPXYB6MfM+giCwf4/eksesPGJSNhA==
dependencies:
"@ensdomains/eth-ens-namehash" "^2.0.15"
"@ethersproject/abi" "^5.6.4"
Expand Down

0 comments on commit b2d43d9

Please sign in to comment.