Skip to content

Commit

Permalink
Chore(contract manager) add viem (#2438)
Browse files Browse the repository at this point in the history
* chore(pricefeed) Imporve scripts

* added tokens

* added ton
  • Loading branch information
aditya520 authored Mar 6, 2025
1 parent 101b0d8 commit a41471f
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 224 deletions.
4 changes: 2 additions & 2 deletions apps/api-reference/src/evm-networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const NETWORK_INFO = {
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
},
[1001]: {
name: "klaytn_testnet",
name: "kaia_testnet",
rpcUrl: "https://rpc.ankr.com/klaytn_testnet",
isMainnet: false,
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
Expand Down Expand Up @@ -420,7 +420,7 @@ export const NETWORK_INFO = {
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
},
[8217]: {
name: "klaytn",
name: "kaia",
rpcUrl: "https://rpc.ankr.com/klaytn",
isMainnet: true,
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
Expand Down
1 change: 1 addition & 0 deletions contract_manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"starknet": "^6.9.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"viem": "^2.23.5",
"web3": "^1.8.2",
"web3-eth-contract": "^1.8.2",
"yaml": "^2.1.1"
Expand Down
4 changes: 3 additions & 1 deletion contract_manager/scripts/fetch_fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CosmWasmPriceFeedContract,
DefaultStore,
EvmPriceFeedContract,
TonPriceFeedContract,
} from "../src";

const parser = yargs(hideBin(process.argv))
Expand Down Expand Up @@ -36,7 +37,8 @@ async function main() {
if (
contract instanceof AptosPriceFeedContract ||
contract instanceof EvmPriceFeedContract ||
contract instanceof CosmWasmPriceFeedContract
contract instanceof CosmWasmPriceFeedContract ||
contract instanceof TonPriceFeedContract
) {
try {
const fee = await contract.getTotalFee();
Expand Down
17 changes: 17 additions & 0 deletions contract_manager/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { keyPairFromSeed } from "@ton/crypto";
import { PythContract } from "@pythnetwork/pyth-ton-js";
import * as nearAPI from "near-api-js";
import * as bs58 from "bs58";
import * as chains from "viem/chains";

/**
* Returns the chain rpc url with any environment variables replaced or throws an error if any are missing
Expand Down Expand Up @@ -367,6 +368,13 @@ export class EvmChain extends Chain {

static fromJson(parsed: ChainConfig & { networkId: number }): EvmChain {
if (parsed.type !== EvmChain.type) throw new Error("Invalid type");
if (parsed.nativeToken === undefined) {
for (const chain of Object.values(chains)) {
if (chain.id === parsed.networkId) {
parsed.nativeToken = chain.nativeCurrency.symbol;
}
}
}
return new EvmChain(
parsed.id,
parsed.mainnet,
Expand All @@ -383,6 +391,15 @@ export class EvmChain extends Chain {
return new Web3(parseRpcUrl(this.rpcUrl));
}

getViemDefaultWeb3(): Web3 {
for (const chain of Object.values(chains)) {
if (chain.id === this.networkId) {
return new Web3(chain.rpcUrls.default.http[0]);
}
}
throw new Error(`Chain with id ${this.networkId} not found in Viem`);
}

/**
* Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
* @param address hex string of the 20 byte address of the contract to upgrade to without the 0x prefix
Expand Down
12 changes: 10 additions & 2 deletions contract_manager/src/contracts/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,16 @@ export class EvmPriceFeedContract extends PriceFeedContract {
}

async getTotalFee(): Promise<TokenQty> {
const web3 = this.chain.getWeb3();
const amount = BigInt(await web3.eth.getBalance(this.address));
let web3: Web3;
let amount = BigInt(0);
try {
web3 = this.chain.getViemDefaultWeb3();
amount = BigInt(await web3.eth.getBalance(this.address));
} catch (error) {
// Fallback to regular web3 if viem default web3 fails
web3 = this.chain.getWeb3();
amount = BigInt(await web3.eth.getBalance(this.address));
}
return {
amount,
denom: this.chain.getNativeToken(),
Expand Down
4 changes: 2 additions & 2 deletions contract_manager/store/chains/EvmChains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@
rpcUrl: https://node.mainnet.etherlink.com/
networkId: 42793
type: EvmChain
- id: klaytn
- id: kaia
mainnet: true
rpcUrl: https://rpc.ankr.com/klaytn
networkId: 8217
type: EvmChain
- id: klaytn_testnet
- id: kaia_testnet
mainnet: false
rpcUrl: https://rpc.ankr.com/klaytn_testnet
networkId: 1001
Expand Down
4 changes: 2 additions & 2 deletions contract_manager/store/contracts/EvmEntropyContracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
- chain: sei_evm_testnet
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
type: EvmEntropyContract
- chain: klaytn_testnet
- chain: kaia_testnet
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
type: EvmEntropyContract
- chain: klaytn
- chain: kaia
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
type: EvmEntropyContract
- chain: b3_testnet
Expand Down
4 changes: 2 additions & 2 deletions contract_manager/store/contracts/EvmPriceFeedContracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@
- chain: sei_evm_testnet
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
type: EvmPriceFeedContract
- chain: klaytn_testnet
- chain: kaia_testnet
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
type: EvmPriceFeedContract
- chain: klaytn
- chain: kaia
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
type: EvmPriceFeedContract
- chain: morph_holesky_testnet
Expand Down
4 changes: 2 additions & 2 deletions contract_manager/store/contracts/EvmWormholeContracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@
- chain: sei_evm_testnet
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
type: EvmWormholeContract
- chain: klaytn_testnet
- chain: kaia_testnet
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
type: EvmWormholeContract
- chain: klaytn
- chain: kaia
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
type: EvmWormholeContract
- chain: morph_holesky_testnet
Expand Down
108 changes: 108 additions & 0 deletions contract_manager/store/tokens/Tokens.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,111 @@
pythId: 097d687437374051c75160d648800f021086bc8edf469f11284491fda8192315
decimals: 18
type: token
- id: AVAX
pythId: 93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7
decimals: 18
type: token
- id: MATIC
pythId: ffd11c5a1cfd42f80afb2df4d9f264c15f956d68153335374ec10722edd70472
decimals: 18
type: token
- id: FIL
pythId: 150ac9b959aee0051e4091f0ef5216d941f590e1c5e7f91cf7635b5c11628c0e
decimals: 18
type: token
- id: CELO
pythId: 7d669ddcdd23d9ef1fa9a9cc022ba055ec900e91c4cb960f3c20429d4447a411
decimals: 18
type: token
- id: CRO
pythId: 23199c2bcb1303f667e733b9934db9eca5991e765b45f5ed18bc4b231415f2fe
decimals: 18
type: token
- id: INJ
pythId: 7a5bc1d2b56ad029048cd63964b3ad2776eadf812edc1a43a31406cb54bff592
decimals: 18
type: token
- id: SEI
pythId: 53614f1cb0c031d4af66c04cb9c756234adad0e1cee85303795091499a4084eb
decimals: 18
type: token
- id: BERA
pythId: 962088abcfdbdb6e30db2e340c8cf887d9efb311b1f2f17b155a63dbb6d40265
decimals: 18
type: token
- id: ZETA
pythId: b70656181007f487e392bf0d92e55358e9f0da5da6531c7c4ce7828aa11277fe
decimals: 18
type: token
- id: FLOW
pythId: 2fb245b9a84554a0f15aa123cbb5f64cd263b59e9a87d80148cbffab50c69f30
decimals: 18
type: token
- id: XTZ
pythId: 0affd4b8ad136a21d79bc82450a325ee12ff55a235abc242666e423b8bcffd03
decimals: 18
type: token
- id: KAVA
pythId: a6e905d4e85ab66046def2ef0ce66a7ea2a60871e68ae54aed50ec2fd96d8584
decimals: 18
type: token
- id: USDC
pythId: eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a
decimals: 6
type: token
- id: MOVE
pythId: 6bf748c908767baa762a1563d454ebec2d5108f8ee36d806aadacc8f0a075b6d
decimals: 8
type: token
- id: IP
pythId: b620ba83044577029da7e4ded7a2abccf8e6afc2a0d4d26d89ccdd39ec109025
decimals: 18
type: token
- id: S
pythId: f490b178d0c85683b7a0f2388b40af2e6f7c90cbe0f96b31f315f08d0e5a2d6d
decimals: 18
type: token
- id: KAIA
pythId: 452d40e01473f95aa9930911b4392197b3551b37ac92a049e87487b654b4ebbe
decimals: 18
type: token
- id: APE
pythId: 15add95022ae13563a11992e727c91bdb6b55bc183d9d747436c80a483d8c864
decimals: 18
type: token
- id: SMR
pythId: af5b9ac426ae79591fde6816bc3f043b5e06d5e442f52112f76249320df22449
decimals: 18
type: token
- id: CFX
pythId: 8879170230c9603342f3837cf9a8e76c61791198fb1271bb2552c9af7b33c933
decimals: 18
type: token
- id: CANTO
pythId: 972776d57490d31c32279c16054e5c01160bd9a2e6af8b58780c82052b053549
decimals: 18
type: token
- id: NEON
pythId: d82183dd487bef3208a227bb25d748930db58862c5121198e723ed0976eb92b7
decimals: 18
type: token
- id: MTR
pythId: 8cdc9b2118d2ce55a299f8f1d700d0127cf4036d1aa666a8cd51dcab4254284f
decimals: 18
type: token
- id: WEMIX
pythId: f63f008474fad630207a1cfa49207d59bca2593ea64fc0a6da9bf3337485791c
decimals: 18
type: token
- id: EOS
pythId: 06ade621dbc31ed0fc9255caaab984a468abe84164fb2ccc76f02a4636d97e31
decimals: 18
type: token
- id: RON
pythId: 97cfe19da9153ef7d647b011c5e355142280ddb16004378573e6494e499879f3
decimals: 18
type: token
- id: ZEN
pythId: d183ffe0155e8a55e7274155a14ea2e8b54059cef471f88fa3f7eb4b5d8dbc24
decimals: 18
type: token
4 changes: 2 additions & 2 deletions governance/xc_admin/packages/xc_admin_common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const RECEIVER_CHAINS = {
gravity: 60053,
polynomial: 60054,
etherlink: 60055,
klaytn: 60056,
kaia: 60056,
kinto: 60057,
b3_mainnet: 60058,
cronos_zkevm_mainnet: 60059,
Expand Down Expand Up @@ -201,7 +201,7 @@ export const RECEIVER_CHAINS = {
etherlink_testnet: 50083,
fuel_testnet: 50084,
sei_evm_testnet: 50085,
klaytn_testnet: 50086,
kaia_testnet: 50086,
morph_holesky_testnet: 50087,
tabi_testnet: 50088,
movement_suzuka_testnet: 50089,
Expand Down
Loading

0 comments on commit a41471f

Please sign in to comment.