Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Mar 14, 2024
2 parents 17520c2 + 58bbd0f commit cb6825b
Show file tree
Hide file tree
Showing 20 changed files with 756 additions and 22 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.11.6",
"@snapshot-labs/snapshot.js": "^0.11.8",
"@spruceid/didkit-wasm-node": "^0.2.1",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/v3-sdk": "^3.9.0",
Expand Down
3 changes: 3 additions & 0 deletions src/strategies/giveth-balances-supply-weighted/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Giveth Balances Supply Weighted

This strategy is used to get the balance of tokens a user holds + the amount they have staked in GIVpower. It gets the sum of those balances, divides it by the circulating supply of the GIV token from an API endpoint then applies a weight to it.
28 changes: 28 additions & 0 deletions src/strategies/giveth-balances-supply-weighted/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "Example query",
"strategy": {
"name": "giveth-balances-supply-weighted",
"params": {
"tokenAddress": "0x528CDc92eAB044E1E39FE43B9514bfdAB4412B98",
"stakedAddress": "0x301C739CF6bfb6B47A74878BdEB13f92F13Ae5E7",
"supplyApi": "https://circulating.giveth.io/token-supply",
"supplyField": "circulating",
"weight": 0.5,
"symbol": "GIV",
"decimals": 18,
"methodABI": {
"method" : "function depositTokenBalance(address) public view returns (uint256)",
"name": "depositTokenBalance"
}
}
},
"network": "10",
"addresses": [
"0x826976d7C600d45FB8287CA1d7c76FC8eb732030",
"0x839395e20bbB182fa440d08F850E6c7A8f6F0780",
"0x960A16c9070A9BbbB03e1bFd418982636D56D77d"
],
"snapshot": 117386958
}
]
70 changes: 70 additions & 0 deletions src/strategies/giveth-balances-supply-weighted/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';
import { BigNumber } from '@ethersproject/bignumber';

export const author = 'divine-comedian';
export const version = '0.1.0';

const abi = [
'function balanceOf(address account) external 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 supply = fetch(options.supplyApi, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
}).then((response) => response.json());

const tokenMulti = new Multicaller(network, provider, abi, { blockTag });
const stakedMulti = new Multicaller(
network,
provider,
[options.methodABI.method] as string[],
{
blockTag
}
);
addresses.forEach((address) => {
tokenMulti.call(address, options.tokenAddress, 'balanceOf', [address]),
stakedMulti.call(address, options.stakedAddress, options.methodABI.name, [
address
]);
});
const tokenBalance = tokenMulti.execute();
const stakedBalance = stakedMulti.execute();

const [supplyResult, tokenResult, stakedResult]: [
any,
Record<string, BigNumber>,
Record<string, BigNumber>
] = await Promise.all([supply, tokenBalance, stakedBalance]);

const circulatingSupply = parseFloat(
formatUnits(supplyResult[options.supplyField], options.decimals)
);

return Object.fromEntries(
Object.entries(tokenResult).map(([address, tokenBalance]) => {
const stakedBalance = stakedResult[address];
const totalBalance = tokenBalance.add(stakedBalance);
return [
address,
(parseFloat(formatUnits(totalBalance, options.decimals)) /
circulatingSupply) *
options.weight
];
})
);
}
12 changes: 12 additions & 0 deletions src/strategies/giveth-gnosis-balance-supply-weighted-v3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Giveth Gnosis balance

This strategy sums up all the GIV on xDai, including the ones that are staked in Honeyswap pools, Sushiswap pools, single staked on GIV pool and GIVpower. This version divide the balance by the circulating supply of GIV and multiplies it by a weight.

Here is an example of parameters:

```json
{
"symbol": "GIV",
"decimals": 18
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "Example query",
"strategy": {
"name": "giveth-gnosis-balance-supply-weighted-v3",
"params": {
"symbol": "GIV",
"decimals": 18,
"weight": 0.5
}
},
"network": "100",
"addresses": [
"0x839395e20bbb182fa440d08f850e6c7a8f6f0780",
"0x960a16c9070a9bbbb03e1bfd418982636d56d77d",
"0x826976d7C600d45FB8287CA1d7c76FC8eb732030"
],
"snapshot": 32900726
}
]
103 changes: 103 additions & 0 deletions src/strategies/giveth-gnosis-balance-supply-weighted-v3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { subgraphRequest } from '../../utils';
import { getAddress } from '@ethersproject/address';
import { formatUnits } from '@ethersproject/units';

export const author = 'divine-comedian';
export const version = '0.1.0';

const GIVETH_SUBGRAPH_API =
'https://api.thegraph.com/subgraphs/name/giveth/giveth-economy-second-xdai';
const XDAI_BLOCKS_API =
'https://api.thegraph.com/subgraphs/name/elkfinance/xdai-blocks';

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

const blockParams = {
blocks: {
__args: {
first: 1,
orderBy: 'timestamp',
orderDirection: 'desc',
where: {
timestamp_lte: ''
}
},
number: true
}
};

const pairParams = {
pair: {
__args: {
id: ''
},
reserve0: true,
totalSupply: true
}
};

const params = {
tokenBalances: {
__args: {
orderBy: 'id',
orderDirection: 'asc',
where: {
user_in: []
}
},
id: true,
balance: true,
token: true
}
};

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const block = await provider.getBlock(blockTag);
blockParams.blocks.__args.where.timestamp_lte = block.timestamp;
const xDaiBlock = await subgraphRequest(XDAI_BLOCKS_API, blockParams);
const blockNumber = Number(xDaiBlock.blocks[0].number);
// @ts-ignore
params.tokenBalances.__args.block = { number: blockNumber };
if (snapshot !== 'latest') {
// @ts-ignore
pairParams.pair.__args.block = { number: blockNumber };
}

params.tokenBalances.__args.where.user_in = addresses.map((address) =>
address.toLowerCase()
);

const data = subgraphRequest(GIVETH_SUBGRAPH_API, params);
const supply = fetch(CIRUCLATING_SUPPLY_API, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
const [supplyData, balanceData] = await Promise.all([supply, data]);
const supplyJSON = await supplyData.json();
const circulatingSupply = parseFloat(
formatUnits(supplyJSON.circulating, options.decimals)
);
const score = {};
balanceData.tokenBalances.map((addressBalance) => {
const id = addressBalance.id.split('-')[1];
const prevScore = score[getAddress(id)] ? score[getAddress(id)] : 0;
score[getAddress(id)] =
prevScore +
(parseFloat(formatUnits(addressBalance.balance, options.decimals)) /
circulatingSupply) *
options.weight;
});
return score;
}
11 changes: 10 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,15 @@ import * as vendorV2BorrowerCollateralBalanceOf from './vendor-v2-borrower-colla
import * as voltVotingPower from './volt-voting-power';
import * as xdaiStakersAndHolders from './xdai-stakers-and-holders';
import * as minimeBalanceVsSupplyWeighted from './minime-balance-vs-supply-weighted';
import * as vestingBalanceOf from './vesting-balance-of';
import * as givethBalancesSupplyWeighted from './giveth-balances-supply-weighted';
import * as givethGnosisBalanceSupplyWeightedV3 from './giveth-gnosis-balance-supply-weighted-v3';
import * as stakeMineLiquidHelios from './stake-mine-liquid-helios';

const strategies = {
'giveth-balances-supply-weighted': givethBalancesSupplyWeighted,
'giveth-gnosis-balance-supply-weighted-v3':
givethGnosisBalanceSupplyWeightedV3,
'minime-balance-vs-supply-weighted': minimeBalanceVsSupplyWeighted,
'cap-voting-power': capVotingPower,
'izumi-veizi': izumiVeiZi,
Expand Down Expand Up @@ -833,7 +840,9 @@ const strategies = {
vendorV2BorrowerCollateralBalanceOf,
'volt-voting-power': voltVotingPower,
'xdai-stakers-and-holders': xdaiStakersAndHolders,
'urbit-galaxies': urbitGalaxies
'urbit-galaxies': urbitGalaxies,
'vesting-balance-of': vestingBalanceOf,
'stake-mine-liquid-helios' : stakeMineLiquidHelios,
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
8 changes: 5 additions & 3 deletions src/strategies/push-voting-power/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

This strategy weighs the vote using:
- Amount of `$PUSH` delegated to user
- Amount of `$PUSH` staked in Push staking pool
- Amount of `$PUSH-LP` staked in LP staking pool
- Amount of `$PUSH` staked in Push V1 and V2 staking pool
- Amount of `$PUSH-LP` staked in LP staking pool V1 and V2

The voting power is calculated in terms of `$PUSH`, so `$PUSH-LP` tokens are converted to `$PUSH` using on chain data from Uniswap-V2 Router, WETH and USDT token contracts.

Expand All @@ -18,7 +18,9 @@ The voting power is calculated in terms of `$PUSH`, so `$PUSH-LP` tokens are con
"uniswapV2Router02": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"WETHAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"USDTAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",


"pushUniStakingV2":"0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2",
"pushStakingInfoCoreV2": "0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE",
"decimals": 18
}
```
8 changes: 6 additions & 2 deletions src/strategies/push-voting-power/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"WETHAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"USDTAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",

"pushUniStakingV2":"0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2",
"pushStakingInfoCoreV2": "0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE",
"decimals": 18
}
},
Expand All @@ -24,8 +26,10 @@
"0x5913760160d245d0C9A05a8a956012694281bEE3",
"0x4b9D53246eD18db31f26Fc59b6e47a9efC3C1213",
"0x89c1151cA988ca5372b569A30d24964A94Ad05FD",
"0xE08fcc423566BF10B53e32E05d24C0429F91111A"
"0xE08fcc423566BF10B53e32E05d24C0429F91111A",
"0xD66f2F1d86C0c5477aA1612cA92f03297A5477B0",
"0xaB8a67743325347Aa53bCC66850f8F13df87e3AF"
],
"snapshot": 13626267
"snapshot": 19381155
}
]
Loading

0 comments on commit cb6825b

Please sign in to comment.