Skip to content

Commit ab26746

Browse files
authored
chore(contract-manager) Script to fetch Entropy Dao Fees (#3007)
* chore(contract-manager) Entropy Dao Fees * update
1 parent 91fecfa commit ab26746

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import yargs from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import { DefaultStore } from "../src/node/utils/store";
4+
import { EvmChain } from "../src/core/chains";
5+
import { EvmEntropyContract } from "../src/core/contracts";
6+
import { findEntropyContract } from "./common";
7+
8+
const parser = yargs(hideBin(process.argv))
9+
.usage(
10+
"Fetches the accrued Pyth DAO fees for entropy contracts across chains.\n" +
11+
"Usage: $0 --chain <chain-id> | --all-chains <testnet|mainnet|all>",
12+
)
13+
.options({
14+
chain: {
15+
type: "string",
16+
desc: "Fetch accrued fees for the entropy contract on this specific chain",
17+
conflicts: "all-chains",
18+
},
19+
"all-chains": {
20+
type: "string",
21+
conflicts: "chain",
22+
choices: ["testnet", "mainnet", "all"],
23+
desc: "Fetch accrued fees for all entropy contracts deployed on specified network type",
24+
},
25+
"show-eth": {
26+
type: "boolean",
27+
default: false,
28+
desc: "Show fees in ETH in addition to Wei",
29+
},
30+
})
31+
.check((argv) => {
32+
if (!argv.chain && !argv["all-chains"]) {
33+
throw new Error("Must specify either --chain or --all-chains");
34+
}
35+
return true;
36+
});
37+
38+
interface FeeResult {
39+
chainId: string;
40+
contractAddress: string;
41+
accruedFees: string;
42+
accruedFeesEth?: string;
43+
isMainnet: boolean;
44+
error?: string;
45+
}
46+
47+
async function fetchAccruedFees(
48+
contract: EvmEntropyContract,
49+
showEth: boolean,
50+
): Promise<FeeResult> {
51+
const chainId = contract.getChain().getId();
52+
const contractAddress = contract.address;
53+
const isMainnet = contract.getChain().isMainnet();
54+
55+
try {
56+
const accruedFeesWei = await contract.getAccruedPythFees();
57+
let accruedFeesEth: string | undefined;
58+
59+
if (showEth) {
60+
const web3 = contract.getChain().getWeb3();
61+
accruedFeesEth = web3.utils.fromWei(accruedFeesWei, "ether");
62+
}
63+
64+
return {
65+
chainId,
66+
contractAddress,
67+
accruedFees: accruedFeesWei,
68+
accruedFeesEth,
69+
isMainnet,
70+
};
71+
} catch (error) {
72+
return {
73+
chainId,
74+
contractAddress,
75+
accruedFees: "0",
76+
accruedFeesEth: showEth ? "0" : undefined,
77+
isMainnet,
78+
error: error instanceof Error ? error.message : "Unknown error",
79+
};
80+
}
81+
}
82+
83+
function formatResults(results: FeeResult[], showEth: boolean): void {
84+
console.log("\n=== Accrued Entropy DAO Fees Summary ===\n");
85+
86+
const successfulResults = results.filter((r) => !r.error);
87+
const failedResults = results.filter((r) => r.error);
88+
89+
// Summary statistics
90+
console.log("SUMMARY:");
91+
console.log("─".repeat(40));
92+
console.log(`Total Chains Checked: ${results.length}`);
93+
console.log(`Successful Queries: ${successfulResults.length}`);
94+
console.log(`Failed Queries: ${failedResults.length}`);
95+
console.log("");
96+
97+
if (successfulResults.length > 0) {
98+
console.log("Successful Queries:");
99+
console.table(
100+
successfulResults.map((r) => {
101+
const baseData = {
102+
Chain: r.chainId,
103+
Network: r.isMainnet ? "Mainnet" : "Testnet",
104+
"Fees (Wei)": r.accruedFees,
105+
};
106+
107+
if (showEth && r.accruedFeesEth) {
108+
return {
109+
...baseData,
110+
"Fees (ETH)": r.accruedFeesEth,
111+
};
112+
}
113+
114+
return baseData;
115+
}),
116+
);
117+
}
118+
119+
if (failedResults.length > 0) {
120+
console.log("\nFailed Queries:");
121+
console.table(
122+
failedResults.map((r) => ({
123+
Chain: r.chainId,
124+
Network: r.isMainnet ? "Mainnet" : "Testnet",
125+
Error: r.error,
126+
})),
127+
);
128+
}
129+
}
130+
131+
async function main() {
132+
const argv = await parser.argv;
133+
const results: FeeResult[] = [];
134+
135+
console.log("Fetching accrued entropy DAO fees from entropy contracts...\n");
136+
137+
if (argv.chain) {
138+
// Fetch fees for a specific chain
139+
try {
140+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
141+
const contract = findEntropyContract(chain);
142+
console.log(`Fetching fees for ${argv.chain}...`);
143+
const result = await fetchAccruedFees(contract, argv.showEth);
144+
results.push(result);
145+
} catch (error) {
146+
console.error(
147+
`Error fetching fees for ${argv.chain}:`,
148+
error instanceof Error ? error.message : error,
149+
);
150+
process.exit(1);
151+
}
152+
} else if (argv["all-chains"]) {
153+
// Fetch fees for all chains based on network type
154+
const contracts = Object.values(DefaultStore.entropy_contracts);
155+
156+
if (contracts.length === 0) {
157+
console.log("No entropy contracts found in the store.");
158+
return;
159+
}
160+
161+
console.log(`Found ${contracts.length} entropy contract(s) in the store.`);
162+
163+
for (const contract of contracts) {
164+
const chainId = contract.getChain().getId();
165+
const isMainnet = contract.getChain().isMainnet();
166+
167+
// Filter based on network type
168+
if (argv["all-chains"] === "mainnet" && !isMainnet) continue;
169+
if (argv["all-chains"] === "testnet" && isMainnet) continue;
170+
// If "all", we include both mainnet and testnet
171+
172+
console.log(`Fetching fees for ${chainId}...`);
173+
const result = await fetchAccruedFees(contract, argv.showEth);
174+
results.push(result);
175+
}
176+
}
177+
178+
if (results.length === 0) {
179+
console.log("No matching contracts found for the specified criteria.");
180+
return;
181+
}
182+
183+
formatResults(results, argv.showEth);
184+
}
185+
186+
main().catch((error) => {
187+
console.error(
188+
"Script failed:",
189+
error instanceof Error ? error.message : error,
190+
);
191+
process.exit(1);
192+
});

contract_manager/src/core/contracts/evm.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ export class EvmEntropyContract extends Storable {
411411
from: address,
412412
});
413413
}
414+
415+
async getAccruedPythFees(): Promise<string> {
416+
const contract = this.getContract();
417+
return await contract.methods.getAccruedPythFees().call();
418+
}
414419
}
415420

416421
export class EvmExecutorContract extends Storable {

0 commit comments

Comments
 (0)