Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:tetu-io/tetu-strategies-matic into d…
Browse files Browse the repository at this point in the history
…ev-ruby
  • Loading branch information
alexandersazonof committed Feb 19, 2024
2 parents b6d074d + bd919c7 commit 020ca33
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 58 deletions.
6 changes: 3 additions & 3 deletions scripts/utils/create-tetu-bal-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {Proposal} from "@snapshot-labs/snapshot.js/src/sign/types";
import {getBalancerGaugesData} from "./tools/voting-utils";

// !!!!!!!!!!!!!!!!!!!!!!!! CHANGE ME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const POLYGON_SNAPSHOT_BLOCK_NUMBER = 51571176; // use the-best-block-for-snapshot.ts script
const POLYGON_SNAPSHOT_BLOCK_NUMBER = 53164734; // use the-best-block-for-snapshot.ts script
const START_UNIX = Math.floor(Date.now() / 1000)
const END_UNIX = Math.floor((new Date('Jan 08 2024 20:00:00 UTC')).getTime() / 1000)
const TITLE = 'BRV-037: Gauge Weights for 11th January - 24th January 2024'
const END_UNIX = Math.floor((new Date('Feb 19 2024 20:00:00 UTC')).getTime() / 1000)
const TITLE = 'BRV-040: Gauge Weights for 22th February - 06th March 2024'
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// new tetubal gauge https://etherscan.io/address/0xF6A814eD60653Cb0e36DA247B01E6309318328d4#code
Expand Down
73 changes: 28 additions & 45 deletions scripts/utils/tetu-bal-vote.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios from "axios";
import {getBalancerGaugesData} from "./tools/voting-utils";

const FREE_VOTES = 19.1;
const OUR_VOTING_POWER = 172000;
const MIN_VALUE_PER_VOTE = 0.2;
const MIN_TOTAL_VALUE = 1000;
const FREE_VOTES = 43.64;
const OUR_VOTING_POWER = 237000;
const MIN_VALUE_PER_VOTE = 0.18;
const MIN_TOTAL_VALUE = 100;

// const VOTE_MARKET_HH_API = 'https://vm.crvusd.fi/bribes?name=hiddehand';
const HH_API = 'https://api.hiddenhand.finance/proposal/balancer';
Expand All @@ -26,7 +26,7 @@ async function main() {
const votes = totalFreeVotes * ratio;
const percent = votes / OUR_VOTING_POWER * 100;

console.log(bribe.proposalOption, percent.toFixed(2));
console.log(bribe.proposalOption + ';' + percent.toFixed(2));

totalUsedVotes += percent;
}
Expand All @@ -38,21 +38,24 @@ async function getBribesForVotes() {
const resp = await axios.get(HH_API)
// console.log(resp);
const result: BribeInfoHH2[] = resp.data.data;
const poolIdToGauges = await getProposalOptions();
// const poolIdToGauges = await getProposalOptions();

return result.filter(b =>
b.valuePerVote > MIN_VALUE_PER_VOTE
&& b.totalValue > MIN_TOTAL_VALUE
).map(b => {
const r: BribeInfoSimple = {
valuePerVote: b.valuePerVote,
title: b.title,
rewards: b.totalValue,
proposalOption: poolIdToGauges.get(b.poolId.toLowerCase()) ?? 'Unknown',
poolId: b.poolId.substring(0, 8)
}
return r;
}).filter(b => b.proposalOption !== 'Unknown')
return b.bribes.map(bribe => {
const r: BribeInfoSimple = {
valuePerVote: b.valuePerVote,
title: b.title,
rewards: bribe.value,
proposalOption: formatProposalOption(b.title, b.proposal),
poolId: b.poolId.substring(0, 8)
}
return r;
})
}).flatMap(b => b)
.filter(b => b.proposalOption !== 'Unknown')
.sort((a, b) => b.rewards - a.rewards)
}

Expand All @@ -64,41 +67,21 @@ async function getProposalOptions(): Promise<Map<string, string>> {
for (const d of resp) {
if (d.isKilled) continue

const truncatedAddr = d.gauge.address.substring(0, 8)
result.set(d.id.toLowerCase(), `${d.symbol.trim().substring(0, 23)} (${truncatedAddr})`);
const key = d.id.toLowerCase() + '_' + d.chain.toString();

if (result.has(key)) {
throw Error('duplicate ' + JSON.stringify(d));
}

result.set(key, formatProposalOption(d.symbol, d.gauge.address));
}

return result;
}

type BribeInfoHH = {
proposal: string,
proposalHash: string,
title: string,
proposalDeadline: number,
totalValue: number
maxTotalValue: number
voteCount: number
valuePerVote: number
maxValuePerVote: number
bribes: {
token: string,
symbol: string,
decimals: number
value: number
maxValue: number
amount: number
maxTokensPerVote: number
briber: string,
periodIndex: number,
chainId: number,
tokenImage: string
}[],
poolId: string,
totalReward: number,
apr: number,
totalVotes: number
};
function formatProposalOption(symbol: string, gauge: string) {
return `${symbol.trim().substring(0, 23)};${gauge.substring(0, 8)}`;
}

type BribeInfoHH2 = {
proposal: string,
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/the-best-block-for-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {getSnapshotData} from "./tools/voting-utils";
import {Misc} from "./tools/Misc";

// check here https://snapshot.org/#/tetubal.eth
const PREVIOUS_PROPOSAL = '0x45e8c0e3df0c4ae63a133570fa30653b1d86ec2d5da89147b50c77725d0f0a07';
const PREVIOUS_PROPOSAL = '0x4dc14ecac7137c2c4b186c562e7987a73627ad1ef83f71590c3685622cfbc45e';

async function main() {
const BALANCER_VAULT = '0xBA12222222228d8Ba445958a75a0704d566BF2C8';
Expand Down
23 changes: 14 additions & 9 deletions scripts/utils/xtetuBAL-airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { getUserBalanceByBlock } from '../graphql/graph-service';

// MAKE SURE YOUR LOCAL SNAPSHOT BLOCK IS ACTUAL!
// the last snapshot https://snapshot.org/#/tetubal.eth
const PROPOSAL_ID = '0x45e8c0e3df0c4ae63a133570fa30653b1d86ec2d5da89147b50c77725d0f0a07';
const PROPOSAL_ID = '0x4dc14ecac7137c2c4b186c562e7987a73627ad1ef83f71590c3685622cfbc45e';
// USDC amount received from all bribes
const USDC_AMOUNT = 64723;
const USDC_AMOUNT = 35602;
// % of USDC amount that will be transfer as TETU tokens. calc it depending on protocol pools bribes where we used TETU as bribes.
const TETU_RATIO = Number(1);

Expand Down Expand Up @@ -89,6 +89,7 @@ async function main() {
const tetuPrice = await tools.calculator.getPriceWithDefaultOutput(MaticAddresses.TETU_TOKEN, /*{blockTag: BLOCK}*/); // use actual price
const xtetuBalTVL = await ISmartVault__factory.connect(MaticAddresses.xtetuBAL_TOKEN, signer).underlyingBalanceWithInvestment({blockTag: BLOCK});
const xtetuBalTVLUSD = +formatUnits(xtetuBalPrice.mul(xtetuBalTVL), 36);
console.log('tetuPrice', +formatUnits(tetuPrice));

const distributor = XtetuBALDistributor__factory.connect(DISTRIBUTOR, signer);

Expand All @@ -108,10 +109,11 @@ async function main() {
console.log('X_TETU_BAL_STRATEGY power', +formatUnits(xtetuBALStrategyPower));


// const tetuBalReducing = +formatUnits(await power.tetuBalReducing({blockTag: BLOCK}));
const tetuBalReducing = 0;
const tetuBalReducing = +formatUnits(await power.tetuBalReducing({blockTag: BLOCK}));
console.log('tetuBalReducing power', tetuBalReducing);

expectedPawnshopPower = expectedPawnshopPower * (1 - tetuBalReducing);

const tetuBalTotalSupply = +formatUnits(await power.totalSupply({blockTag: BLOCK}));
console.log('tetuBalTotalSupply', tetuBalTotalSupply);

Expand All @@ -128,10 +130,6 @@ async function main() {
console.log('totalPureTetuBal', totalPureTetuBal);
console.log('extraFromTetuBalCut', extraFromTetuBalCut);

// todo when the cut will be not zero need to check additional logic
expect(extraFromTetuBalCut).eq(0);


const expectedStrategyRatio = (+votedPower - tetuBalInBalancer - tetuBalHolderPower - pawnshopPower - extraFromTetuBalCut) / votedPower;
console.log('expectedStrategyRatio', expectedStrategyRatio);

Expand Down Expand Up @@ -396,13 +394,16 @@ async function collectUsers(block: number) {
);

console.log('logs', logs.length);
const TARGET_FOR_CHECK = '0'.toLowerCase();

const balances = new Map<string, number>();

for (const log of logs) {
const transfer = IERC20__factory.createInterface().parseLog(log) as unknown as TransferEvent;

// console.log('transfer', transfer);
if (transfer.args.from.toLowerCase() === TARGET_FOR_CHECK || transfer.args.to.toLowerCase() === TARGET_FOR_CHECK) {
console.log('TARGET transfer', +formatUnits(transfer.args.value));
}

balances.set(transfer.args.from, (balances.get(transfer.args.from) ?? 0) - +formatUnits(transfer.args.value));
balances.set(transfer.args.to, (balances.get(transfer.args.to) ?? 0) + +formatUnits(transfer.args.value));
Expand All @@ -419,6 +420,10 @@ async function collectUsers(block: number) {
// console.error('actual balance', acc, balances.get(acc), '!==', +formatUnits(actualBalance));
}
result.set(acc, +formatUnits(actualBalance));

if (acc.toLowerCase() === TARGET_FOR_CHECK) {
console.log('TARGET balance', +formatUnits(actualBalance));
}
}

return result;
Expand Down

0 comments on commit 020ca33

Please sign in to comment.