Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IntegralDAO strategy [integral-dao] #1122

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ import * as rnbwBalance from './rnbw-balance';
import * as celerSgnDelegation from './celer-sgn-delegation';
import * as balancerDelegation from './balancer-delegation';
import * as infinityProtocolPools from './infinityprotocol-liquidity-pools';
import * as IntegralDAO from './integral-dao';
import * as aaveGovernancePower from './aave-governance-power';
import * as cake from './cake';
import * as aks from './aks';
Expand Down Expand Up @@ -620,6 +621,7 @@ const strategies = {
'celer-sgn-delegation': celerSgnDelegation,
'balancer-delegation': balancerDelegation,
'infinityprotocol-liquidity-pools': infinityProtocolPools,
'integral-dao': IntegralDAO,
'aave-governance-power': aaveGovernancePower,
cake,
aks,
Expand Down
35 changes: 35 additions & 0 deletions src/strategies/integral-dao/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"name": "Integral vote weighting strategy",
"strategy": {
"name": "integral-dao",
"params": {
"symbol": "ITGR",
"contractAddresses": [
"0xd502f487e1841fdc805130e13eae80c61186bc98",
"0x36bD665392236b20bd42e161f02Bf0ae1d9441Ff",
"0xFFc0EAC1a1aE79C697607229Aca43Ef422625a40"
],
"decimals": 18,
"pageSize": 100
}
},
"network": "1",
"addresses": [
"0x39C6F54b47c1CCB896221EB5e4e24765108Cf145",
"0x013f107eb48401b1a58607d7bb37127ce075002c",
"0x6b174b2f42dae970fed64cfa61cd0b993d59ef66",
"0x02b2d6a3298a4b20aa4f7a0a57e920e9fc9ad864",
"0xD222674ee29F588Fad1633E850b513b64b0350a9",
"0x384f28360caabd007e27c872b95e63302bf2492f",
"0x6b879dd45cf492b0950e4ac94f2657d811341169",
"0x671e53a32573ab447796bbc6b98b9c166f960fe8",
"0xaef031994435202aa92e1c1f3289d07a89b8ae54",
"0x5bbe5c40af27dbe17adb4cf24a4793d4dbff5614",
"0x430a5965bcee916b7629353be63f0ba9f9fdb18b",
"0xc16f2313e360c53803f728bbd3a798048f656c52",
"0x8f49f0eb2b30ef269dc22b44bdead34c81887e7b"
],
"snapshot": 13569183
}
]
58 changes: 58 additions & 0 deletions src/strategies/integral-dao/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

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

const abi = [
'function getCurrentVotes(address account) external view returns (uint96)'
];

async function getVotes(
multi: any,
addresses: string[],
contractAddress: string,
decimals: number
) {
addresses.forEach((address) => {
multi.call(address, contractAddress, 'getCurrentVotes', [address]);
});
const result: Record<string, BigNumberish> = await multi.execute();
return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, decimals))
])
);
}

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const results = await Promise.all(
options.contractAddresses.map((contractAddress) =>
getVotes(
new Multicaller(network, provider, abi, { blockTag }),
addresses,
contractAddress,
options.decimals
)
)
);
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved

return results.slice(1).reduce((acc, result) => {
Object.keys(result).forEach((address) => {
if (acc[address]) {
acc[address] += result[address];
}
});
return acc;
}, results[0]);
}