Skip to content

Commit f316a51

Browse files
authored
[contract-manager] Utility script to fetch fees on different contracts (#1026)
* Utility script to fetch fees on different contracts
1 parent 20d8eec commit f316a51

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import yargs from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import {
4+
AptosContract,
5+
CosmWasmContract,
6+
DefaultStore,
7+
EvmContract,
8+
} from "../src";
9+
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
10+
11+
const parser = yargs(hideBin(process.argv))
12+
.usage("Usage: $0")
13+
.options({
14+
testnet: {
15+
type: "boolean",
16+
default: false,
17+
desc: "Fetch testnet contract fees instead of mainnet",
18+
},
19+
});
20+
21+
async function main() {
22+
const argv = await parser.argv;
23+
for (const contract of Object.values(DefaultStore.contracts)) {
24+
if (contract.getChain().isMainnet() === argv.testnet) continue;
25+
if (
26+
contract instanceof AptosContract ||
27+
contract instanceof EvmContract ||
28+
contract instanceof CosmWasmContract
29+
) {
30+
console.log(`${contract.getId()} ${await contract.getTotalFee()}`);
31+
}
32+
}
33+
}
34+
35+
main();

contract_manager/src/contracts/aptos.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Contract, PriceFeed } from "../base";
22
import { AptosAccount, BCS, TxnBuilderTypes } from "aptos";
33
import { AptosChain, Chain } from "../chains";
44
import { DataSource } from "xc_admin_common";
5+
import { CoinClient } from "aptos";
56

67
export class AptosContract extends Contract {
78
static type: string = "AptosContract";
@@ -174,6 +175,11 @@ export class AptosContract extends Contract {
174175
return AptosContract.type;
175176
}
176177

178+
async getTotalFee(): Promise<bigint> {
179+
const client = new CoinClient(this.chain.getClient());
180+
return await client.checkBalance(this.stateId);
181+
}
182+
177183
async getValidTimePeriod() {
178184
const data = (await this.findResource("StalePriceThreshold")) as any;
179185
return Number(data.threshold_secs);

contract_manager/src/contracts/cosmwasm.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ export class CosmWasmContract extends Contract {
368368
return this.chain;
369369
}
370370

371+
async getTotalFee(): Promise<bigint> {
372+
const client = await CosmWasmClient.connect(this.chain.endpoint);
373+
const coin = await client.getBalance(
374+
this.address,
375+
this.getChain().feeDenom
376+
);
377+
return BigInt(coin.amount);
378+
}
379+
371380
async getValidTimePeriod() {
372381
let client = await CosmWasmClient.connect(this.chain.endpoint);
373382
let result = await client.queryContractSmart(

contract_manager/src/contracts/evm.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ export class EvmContract extends Contract {
346346
return Web3.utils.keccak256(strippedCode);
347347
}
348348

349+
async getTotalFee(): Promise<bigint> {
350+
const web3 = new Web3(this.chain.getRpcUrl());
351+
return BigInt(await web3.eth.getBalance(this.address));
352+
}
353+
349354
async getLastExecutedGovernanceSequence() {
350355
const pythContract = await this.getContract();
351356
return Number(

contract_manager/store/chains/CosmWasmChains.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
wormholeChainName: injective
44
mainnet: true
55
type: CosmWasmChain
6+
feeDenom: inj
67
- endpoint: https://rpc.atlantic-2.seinetwork.io/
78
id: sei_testnet_atlantic_2
89
wormholeChainName: sei_testnet_atlantic_2
@@ -23,6 +24,7 @@
2324
id: injective_testnet
2425
wormholeChainName: injective_testnet
2526
mainnet: false
27+
feeDenom: inj
2628
type: CosmWasmChain
2729
- endpoint: https://rpc-palvus.pion-1.ntrn.tech/
2830
id: neutron_testnet_pion_1

0 commit comments

Comments
 (0)