Skip to content

Commit

Permalink
Merge branch 'master' into fix-1256
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Oct 15, 2023
2 parents 9974d58 + d31c3b5 commit 0902088
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ jobs:
run: |
yarn install --frozen-lockfile
yarn build
yarn lint
28 changes: 28 additions & 0 deletions .github/workflows/fix-lint.yml
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
28 changes: 4 additions & 24 deletions .github/workflows/lint.yml
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"prepublishOnly": "npm run build",
"postinstall": "npm run build",
"postbuild": "copyfiles -u 1 \"src/**/*.md\" dist/ && copyfiles -u 1 \"src/**/*.json\" dist/",
"lint": "eslint src/ test/ --ext .ts,.json --fix"
"typecheck": "tsc --noEmit",
"lint": "eslint src/ test/ --ext .ts,.json",
"lint:fix": "yarn lint --fix"
},
"dependencies": {
"@ethersproject/abi": "^5.6.4",
Expand Down
49 changes: 29 additions & 20 deletions src/strategies/sd-vote-boost-twavp-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export async function strategy(
if (options.whiteListedAddress.length > 20) {
throw new Error('maximum of 20 whitelisted address');
}

// Maximum of 500 pools address
if (options.pools.length > 500) {
throw new Error('maximum of 500 pools');
}

const calls: any[] = [];
for(const pool of options.pools) {
for (const pool of options.pools) {
calls.push([options.sdToken, 'balanceOf', [pool]]);
}
calls.push([options.veToken, 'balanceOf', [options.liquidLocker]]);
Expand All @@ -51,7 +51,7 @@ export async function strategy(
} else {
blockTag = await provider.getBlockNumber();
}

// Create block list
const blockList = getPreviousBlocks(
blockTag,
Expand Down Expand Up @@ -81,19 +81,12 @@ export async function strategy(
loopCalls.push([options.sdTokenGauge, 'totalSupply']);
loopCalls.push(...workingBalanceQuery);
loopCalls.push(...calls);

} else {
loopCalls.push(...workingBalanceQuery);
}

response.push(
await multicall(
network,
provider,
abi,
loopCalls,
{ blockTag }
)
await multicall(network, provider, abi, loopCalls, { blockTag })
);
}

Expand All @@ -104,9 +97,18 @@ export async function strategy(
const sdTokenGaugeTotalSupply = response[response.length - 1].shift()[0]; // Last response, latest block

const votingPowerLiquidLocker = response[response.length - 1].pop()[0];
const poolsBalances = options.pools.map(() => response[response.length - 1].pop());
const sumPoolsBalance = poolsBalances.reduce((acc, balance) => acc.add(balance[0]), BigNumber.from(0));
const total = sumPoolsBalance.mul(4).div(10).mul(votingPowerLiquidLocker).div(sdTokenGaugeTotalSupply);
const poolsBalances = options.pools.map(() =>
response[response.length - 1].pop()
);
const sumPoolsBalance = poolsBalances.reduce(
(acc, balance) => acc.add(balance[0]),
BigNumber.from(0)
);
const total = sumPoolsBalance
.mul(4)
.div(10)
.mul(votingPowerLiquidLocker)
.div(sdTokenGaugeTotalSupply);

return Object.fromEntries(
Array(addresses.length)
Expand All @@ -121,7 +123,10 @@ export async function strategy(
}

if (addresses[i].toLowerCase() === options.botAddress.toLowerCase()) {
return [addresses[i], Number(parseFloat(formatUnits(total, options.decimals)))];
return [
addresses[i],
Number(parseFloat(formatUnits(total, options.decimals)))
];
} else {
// Get average working balance.
const averageWorkingBalance = average(
Expand All @@ -130,20 +135,24 @@ export async function strategy(
options.whiteListedAddress
);

const averageWorkingBalanceF = parseFloat(formatUnits(averageWorkingBalance, 18));
const sdTokenGaugeTotalSupplyF = parseFloat(formatUnits(sdTokenGaugeTotalSupply, 18));
const averageWorkingBalanceF = parseFloat(
formatUnits(averageWorkingBalance, 18)
);
const sdTokenGaugeTotalSupplyF = parseFloat(
formatUnits(sdTokenGaugeTotalSupply, 18)
);
const workingSupplyF = parseFloat(formatUnits(workingSupply, 18));

// Calculate voting power.
const votingPower =
workingSupply != 0
? averageWorkingBalanceF * sdTokenGaugeTotalSupplyF / workingSupplyF
? (averageWorkingBalanceF * sdTokenGaugeTotalSupplyF) /
workingSupplyF
: 0;

// Return address and voting power
return [addresses[i], Number(votingPower)];
}

})
);
}
Expand Down

0 comments on commit 0902088

Please sign in to comment.