Skip to content

Commit 43a3013

Browse files
committed
chore(contract-manager) Entropy Dao Fees
1 parent 011c398 commit 43a3013

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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 mainnetResults = results.filter((r) => r.isMainnet);
87+
const testnetResults = results.filter((r) => !r.isMainnet);
88+
89+
if (mainnetResults.length > 0) {
90+
console.log("MAINNET CHAINS:");
91+
console.log("─".repeat(80));
92+
for (const result of mainnetResults) {
93+
if (result.error) {
94+
console.log(`${result.chainId.padEnd(20)} | ERROR: ${result.error}`);
95+
} else {
96+
const feesDisplay =
97+
showEth && result.accruedFeesEth
98+
? `${result.accruedFees.padStart(20)} Wei (${result.accruedFeesEth} ETH)`
99+
: `${result.accruedFees.padStart(20)} Wei`;
100+
console.log(`${result.chainId.padEnd(20)} | ${feesDisplay}`);
101+
}
102+
}
103+
console.log("");
104+
}
105+
106+
if (testnetResults.length > 0) {
107+
console.log("TESTNET CHAINS:");
108+
console.log("─".repeat(80));
109+
for (const result of testnetResults) {
110+
if (result.error) {
111+
console.log(`${result.chainId.padEnd(20)} | ERROR: ${result.error}`);
112+
} else {
113+
const feesDisplay =
114+
showEth && result.accruedFeesEth
115+
? `${result.accruedFees.padStart(20)} Wei (${result.accruedFeesEth} ETH)`
116+
: `${result.accruedFees.padStart(20)} Wei`;
117+
console.log(`${result.chainId.padEnd(20)} | ${feesDisplay}`);
118+
}
119+
}
120+
console.log("");
121+
}
122+
123+
// Summary statistics
124+
const successfulResults = results.filter((r) => !r.error);
125+
126+
console.log("SUMMARY:");
127+
console.log("─".repeat(40));
128+
console.log(`Total Chains Checked: ${results.length}`);
129+
console.log(`Successful Queries: ${successfulResults.length}`);
130+
console.log(
131+
`Failed Queries: ${results.length - successfulResults.length}`,
132+
);
133+
console.log("");
134+
}
135+
136+
async function main() {
137+
const argv = await parser.argv;
138+
const results: FeeResult[] = [];
139+
140+
console.log("Fetching accrued entropy DAO fees from entropy contracts...\n");
141+
142+
if (argv.chain) {
143+
// Fetch fees for a specific chain
144+
try {
145+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
146+
const contract = findEntropyContract(chain);
147+
console.log(`Fetching fees for ${argv.chain}...`);
148+
const result = await fetchAccruedFees(contract, argv.showEth);
149+
results.push(result);
150+
} catch (error) {
151+
console.error(
152+
`Error fetching fees for ${argv.chain}:`,
153+
error instanceof Error ? error.message : error,
154+
);
155+
process.exit(1);
156+
}
157+
} else if (argv["all-chains"]) {
158+
// Fetch fees for all chains based on network type
159+
const contracts = Object.values(DefaultStore.entropy_contracts);
160+
161+
if (contracts.length === 0) {
162+
console.log("No entropy contracts found in the store.");
163+
return;
164+
}
165+
166+
console.log(`Found ${contracts.length} entropy contract(s) in the store.`);
167+
168+
for (const contract of contracts) {
169+
const chainId = contract.getChain().getId();
170+
const isMainnet = contract.getChain().isMainnet();
171+
172+
// Filter based on network type
173+
if (argv["all-chains"] === "mainnet" && !isMainnet) continue;
174+
if (argv["all-chains"] === "testnet" && isMainnet) continue;
175+
// If "all", we include both mainnet and testnet
176+
177+
console.log(`Fetching fees for ${chainId}...`);
178+
const result = await fetchAccruedFees(contract, argv.showEth);
179+
results.push(result);
180+
}
181+
}
182+
183+
if (results.length === 0) {
184+
console.log("No matching contracts found for the specified criteria.");
185+
return;
186+
}
187+
188+
formatResults(results, argv.showEth);
189+
}
190+
191+
main().catch((error) => {
192+
console.error(
193+
"Script failed:",
194+
error instanceof Error ? error.message : error,
195+
);
196+
process.exit(1);
197+
});

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)