Skip to content

Commit cd7cb92

Browse files
committed
Update calculatedFees and add boosting to pondo bot
1 parent affe920 commit cd7cb92

File tree

6 files changed

+83519
-0
lines changed

6 files changed

+83519
-0
lines changed

pondo-bot/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const PONDO_ORACLE_PROGRAM_CODE = pondoProgramToCode[PONDO_ORACLE_PROGRAM
9999
export const MANUAL_DEPLOY = process.env.MANUAL_DEPLOY === 'true' || false;
100100
export const INITIALIZATION_AMOUNT = process.env.INITIALIZATION_AMOUNT || '101_000_000u64';
101101
export const BOT_DELAY = process.env.BOT_DELAY ? parseInt(process.env.BOT_DELAY) : 15_000;
102+
export const VALIDATOR_TO_BOOST = process.env.VALIDATOR_TO_BOOST || '';
103+
export const BOOST_AMOUNT = process.env.BOOST_AMOUNT || '100_000';
102104

103105
// Non .env constants
104106
export const CREDITS_PROGRAM = 'credits.aleo';
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { getMappingValue, isTransactionAccepted } from "../aleo/client";
2+
import { resolveImports } from '../aleo/deploy';
3+
import { submitTransaction } from "../aleo/execute";
4+
import { pondoDependencyTree } from "../compiledPrograms";
5+
import { BOOST_AMOUNT, NETWORK, PONDO_ORACLE_PROGRAM, PONDO_ORACLE_PROGRAM_CODE, PRIVATE_KEY } from "../constants";
6+
import { formatAleoString } from "../util";
7+
8+
9+
const hasValidatorBoostedInEpoch = async (address: string, epoch: bigint): Promise<boolean> => {
10+
const validatorBoostMappingValue = await getMappingValue(address, PONDO_ORACLE_PROGRAM, 'validator_boosting');
11+
console.log(`Validator boost mapping value: ${validatorBoostMappingValue}`);
12+
if (!validatorBoostMappingValue) {
13+
return false;
14+
}
15+
const validatorBoost = JSON.parse(formatAleoString(validatorBoostMappingValue));
16+
const boostEpoch = BigInt(validatorBoost.epoch.slice(0, -3));
17+
console.log(`Validator: ${address} has boosted in epoch: ${boostEpoch} by ${validatorBoost.boost_amount}`);
18+
19+
if (epoch < boostEpoch) {
20+
return false;
21+
}
22+
23+
return true;
24+
}
25+
26+
export const boostValidator = async (validatorAddress: string, epoch: bigint): Promise<void> => {
27+
const hasValidatorBoosted = await hasValidatorBoostedInEpoch(validatorAddress, epoch);
28+
if (hasValidatorBoosted) {
29+
console.log(`Validator: ${validatorAddress} already boosted in this epoch`);
30+
return;
31+
}
32+
33+
console.log(`Boosting validator: ${validatorAddress} in epoch: ${epoch} by ${BOOST_AMOUNT}`);
34+
// Submit the boost transaction
35+
let imports = pondoDependencyTree[PONDO_ORACLE_PROGRAM!];
36+
let resolvedImports = await resolveImports(imports);
37+
38+
const txResult = await submitTransaction(
39+
NETWORK!,
40+
PRIVATE_KEY!,
41+
PONDO_ORACLE_PROGRAM_CODE,
42+
'boost_validator',
43+
[
44+
validatorAddress,
45+
`${BOOST_AMOUNT}u64`,
46+
],
47+
0.085602,
48+
undefined,
49+
resolvedImports
50+
);
51+
52+
const transactionAccepted = await isTransactionAccepted(txResult);
53+
console.log(`Boost transaction accepted: ${transactionAccepted}`);
54+
}

pondo-bot/src/protocol/calculatedFees.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const calculatedFees: CalculatedFees = {
1515
initialize: "238840",
1616
add_delegator: "169508",
1717
update_data: "1222149",
18+
boost_validator: "85601"
1819
},
1920
"pondo_staked_aleo_tokenv1.aleo": {},
2021
"pondo_tokenv1.aleo": {},
@@ -52,4 +53,48 @@ export const calculatedFees: CalculatedFees = {
5253
set_oracle_tvl: "293434",
5354
},
5455
"reference_delegatorgizgkl.aleo": { initialize: "543166" },
56+
"multi_token_support_program.aleo": { initialize: "48650" },
57+
"mtsp_credits.aleo": {},
58+
"pondo_oracle.aleo": {
59+
initialize: "238840",
60+
add_delegator: "169508",
61+
update_data: "1222149",
62+
boost_validator: "85601"
63+
},
64+
"pondo_staked_aleo_token.aleo": {},
65+
"pondo_token.aleo": {},
66+
"pondo_delegator1.aleo": {
67+
bond: "217640", // Manually set to lower value
68+
unbond: "426138", // Manually set to lower value
69+
terminal_state: "69096",
70+
},
71+
"pondo_delegator2.aleo": {
72+
bond: "217640", // Manually set to lower value
73+
unbond: "426138", // Manually set to lower value
74+
terminal_state: "69096",
75+
},
76+
"pondo_delegator3.aleo": {
77+
bond: "217640", // Manually set to lower value
78+
unbond: "426138", // Manually set to lower value
79+
terminal_state: "69096",
80+
},
81+
"pondo_delegator4.aleo": {
82+
bond: "217640", // Manually set to lower value
83+
unbond: "426138", // Manually set to lower value
84+
terminal_state: "69096",
85+
},
86+
"pondo_delegator5.aleo": {},
87+
"pondo_core_protocol.aleo": {
88+
initialize: "1032812",
89+
prep_rebalance: "355766", // Manually set to lower value
90+
deposit_public_as_signer: "487534", // Manually set to lower value
91+
distribute_deposits: "346768", // Manually set to lower value
92+
instant_withdraw_public: "556319", // Manually set to lower value
93+
withdraw_public: "532935", // Manually set to lower value
94+
claim_withdrawal_public: "126015", // Manually set to lower value
95+
rebalance_retrieve_credits: "732545", // Manually set to lower value
96+
rebalance_redistribute: "677000", // Manually set to lower value
97+
set_oracle_tvl: "293434",
98+
},
99+
"reference_delegator.aleo": { initialize: "543166" },
55100
};

pondo-bot/src/protocol/runProtocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
pondoProgramToCode,
1616
pondoPrograms,
1717
} from '../compiledPrograms';
18+
import { boostValidator } from './boostValidator';
1819
import {
1920
CREDITS_PROGRAM,
2021
EPOCH_BLOCKS,
2122
NETWORK,
2223
ORACLE_UPDATE_BLOCKS,
2324
PRIVATE_KEY,
2425
REBALANCE_BLOCKS,
26+
VALIDATOR_TO_BOOST,
2527
VERSION,
2628
ZERO_ADDRESS,
2729
} from '../constants';
@@ -401,6 +403,8 @@ export const runProtocol = async (): Promise<void> => {
401403
} else {
402404
// Set the oracle TVL if it's changed by more than 50%
403405
await setOracleTVL();
406+
// Boost the validator if necessary
407+
await boostValidator(VALIDATOR_TO_BOOST, BigInt(blockHeight) / BigInt(EPOCH_BLOCKS));
404408
}
405409

406410
// Can be run in any epoch period

pondo-bot/utils/analyze-data.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const fs = require('fs');
2+
3+
// Function to load data from the JSON file
4+
function loadData(filePath) {
5+
try {
6+
const data = fs.readFileSync(filePath, 'utf8');
7+
const jsonData = JSON.parse(data);
8+
return jsonData;
9+
} catch (err) {
10+
console.error('Error reading or parsing file:', err);
11+
}
12+
}
13+
14+
// Call the function with the path to your JSON file
15+
const filePath = './mainnet-data.json'; // Adjust the file path as needed
16+
const data = loadData(filePath);
17+
18+
function analyzeData(data) {
19+
const snapshots = data.result;
20+
const totalSnapshots = snapshots.length;
21+
console.log('Total snapshots:', totalSnapshots);
22+
let previousRatio = 0;
23+
for (let i = 0; i < totalSnapshots; i++) {
24+
const snapshot = snapshots[i];
25+
const ratio = Number(snapshot.pondoTVL) / Number(snapshot.paleoSupply);
26+
const change = ratio - previousRatio;
27+
console.log(`Snapshot ${i + 1}: ${ratio}`);
28+
if (change < 0) {
29+
console.log('Ratio decreased from the previous snapshot');
30+
console.log(snapshot);
31+
console.log(snapshots[i - 1]);
32+
}
33+
previousRatio = ratio;
34+
}
35+
}
36+
37+
// Call the analyzeData function with the pondo data
38+
analyzeData(data);

0 commit comments

Comments
 (0)