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

Dev ruby #35

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 19 additions & 2 deletions scripts/utils/tools/veTETU-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import fetch from 'node-fetch';
import { ethers } from 'hardhat';
import { IVeTetu__factory } from '../../../typechain/factories/contracts/tools/VeTETUVotingPower.sol';
import { IERC721__factory } from '../../../typechain';
import { IERC20__factory, IERC721__factory } from '../../../typechain';
import { formatUnits } from 'ethers/lib/utils';
import { Misc } from './Misc';
import {BigNumber} from "ethers";
import { DeployerUtilsLocal } from '../../deploy/DeployerUtilsLocal';
import { BalancerConstants } from '../../deploy/strategies/balancer/BalancerConstants';
import { PriceCalculatorUtils } from '../../../test/PriceCalculatorUtils';

const VE_TETU = '0x6FB29DD17fa6E27BD112Bc3A2D0b8dae597AeDA4'.toLowerCase();
const GRAPHQL_ENDPOINT = 'https://api.thegraph.com/subgraphs/name/tetu-io/tetu-v2'
Expand Down Expand Up @@ -101,11 +104,25 @@ export function convertToRewardPercent(balances: Record<string, number[]>, minVa
rewards[key] = totalBalance;
total += totalBalance;
}
console.log(rewards);
for (const [key, value] of Object.entries(rewards)) {
rewardsInPercent[key] = value / total * 100;
}
return rewardsInPercent;
}

export async function getVeTetuTVL(block: number | string = 'latest'): Promise<number> {
const tetu = IERC20__factory.connect((await DeployerUtilsLocal.getCoreAddresses()).rewardToken, ethers.provider);
const vaultUsdcTetu = IERC20__factory.connect(BalancerConstants.BALANCER_VAULT_USDC_TETU, ethers.provider);

const tetuBalance = await tetu.balanceOf(VE_TETU, {
blockTag: block
});
const vaultBalance = await vaultUsdcTetu.balanceOf(VE_TETU,{
blockTag: block
});

const tetuPrice = await PriceCalculatorUtils.getPriceCached(tetu.address, null, block);
const vaultPrice = await PriceCalculatorUtils.getPriceCached(vaultUsdcTetu.address, null, block);

return (+formatUnits(tetuBalance) * +formatUnits(tetuPrice)) + (+formatUnits(vaultBalance) * +formatUnits(vaultPrice));
}
5 changes: 3 additions & 2 deletions scripts/utils/xtetuBAL-airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {getPawnshopData, getSnapshotVoters} from "./tools/voting-utils";
import {expect} from "chai";
import {TransferEvent} from "../../typechain/contracts/third_party/IERC20Extended";
import {getAllUserByBlock} from './users/users-balances';
import {collectUserBalance, convertToRewardPercent, getTokenIdByBlock} from './tools/veTETU-utils';
import { collectUserBalance, convertToRewardPercent, getTokenIdByBlock, getVeTetuTVL } from './tools/veTETU-utils';

// After airdrop receiving from all sources you need to liquidate all tokens to USDC
// USDC should be on the dedicated msig - send it to BRIBER address
Expand Down Expand Up @@ -371,7 +371,8 @@ async function distributeBribes(
);
}

const veTetuTvl = 0; // TODO get veTETU TVL via subgraph like it made on UI
const veTetuTvl = await getVeTetuTVL(block);
console.log('veTetuTvl', veTetuTvl);

const tokenId = await getTokenIdByBlock(block);
console.log('last token Id', tokenId);
Expand Down
6 changes: 4 additions & 2 deletions test/PriceCalculatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PriceCalculatorUtils {
}

// keep this method for possible implement caches
public static async getPriceCached(token: string, calculator: IPriceCalculator | null = null): Promise<BigNumber> {
public static async getPriceCached(token: string, calculator: IPriceCalculator | null = null, block: number | string = 'latest'): Promise<BigNumber> {
console.log('get price for', token);
// todo remove
if (token.toLowerCase() === '0xdcb8f34a3ceb48782c9f3f98df6c12119c8d168a'.toLowerCase()) {
Expand Down Expand Up @@ -59,7 +59,9 @@ export class PriceCalculatorUtils {
calculator = IPriceCalculator__factory.connect(tools.calculator, ethers.provider);
}
if (net.chainId === 137 || net.chainId === 250 || net.chainId === 1) {
return calculator.getPriceWithDefaultOutput(token);
return calculator.getPriceWithDefaultOutput(token, {
blockTag: block
});
} else {
throw Error('No config for ' + net.chainId);
}
Expand Down
Loading