Skip to content

Commit a41471f

Browse files
authored
Chore(contract manager) add viem (#2438)
* chore(pricefeed) Imporve scripts * added tokens * added ton
1 parent 101b0d8 commit a41471f

File tree

13 files changed

+323
-224
lines changed

13 files changed

+323
-224
lines changed

apps/api-reference/src/evm-networks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const NETWORK_INFO = {
198198
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
199199
},
200200
[1001]: {
201-
name: "klaytn_testnet",
201+
name: "kaia_testnet",
202202
rpcUrl: "https://rpc.ankr.com/klaytn_testnet",
203203
isMainnet: false,
204204
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
@@ -420,7 +420,7 @@ export const NETWORK_INFO = {
420420
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",
421421
},
422422
[8217]: {
423-
name: "klaytn",
423+
name: "kaia",
424424
rpcUrl: "https://rpc.ankr.com/klaytn",
425425
isMainnet: true,
426426
contractAddress: "0x2880aB155794e7179c9eE2e38200202908C17B43",

contract_manager/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"starknet": "^6.9.0",
5858
"ts-node": "^10.9.1",
5959
"typescript": "^5.3.3",
60+
"viem": "^2.23.5",
6061
"web3": "^1.8.2",
6162
"web3-eth-contract": "^1.8.2",
6263
"yaml": "^2.1.1"

contract_manager/scripts/fetch_fees.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CosmWasmPriceFeedContract,
66
DefaultStore,
77
EvmPriceFeedContract,
8+
TonPriceFeedContract,
89
} from "../src";
910

1011
const parser = yargs(hideBin(process.argv))
@@ -36,7 +37,8 @@ async function main() {
3637
if (
3738
contract instanceof AptosPriceFeedContract ||
3839
contract instanceof EvmPriceFeedContract ||
39-
contract instanceof CosmWasmPriceFeedContract
40+
contract instanceof CosmWasmPriceFeedContract ||
41+
contract instanceof TonPriceFeedContract
4042
) {
4143
try {
4244
const fee = await contract.getTotalFee();

contract_manager/src/chains.ts

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { keyPairFromSeed } from "@ton/crypto";
3838
import { PythContract } from "@pythnetwork/pyth-ton-js";
3939
import * as nearAPI from "near-api-js";
4040
import * as bs58 from "bs58";
41+
import * as chains from "viem/chains";
4142

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

368369
static fromJson(parsed: ChainConfig & { networkId: number }): EvmChain {
369370
if (parsed.type !== EvmChain.type) throw new Error("Invalid type");
371+
if (parsed.nativeToken === undefined) {
372+
for (const chain of Object.values(chains)) {
373+
if (chain.id === parsed.networkId) {
374+
parsed.nativeToken = chain.nativeCurrency.symbol;
375+
}
376+
}
377+
}
370378
return new EvmChain(
371379
parsed.id,
372380
parsed.mainnet,
@@ -383,6 +391,15 @@ export class EvmChain extends Chain {
383391
return new Web3(parseRpcUrl(this.rpcUrl));
384392
}
385393

394+
getViemDefaultWeb3(): Web3 {
395+
for (const chain of Object.values(chains)) {
396+
if (chain.id === this.networkId) {
397+
return new Web3(chain.rpcUrls.default.http[0]);
398+
}
399+
}
400+
throw new Error(`Chain with id ${this.networkId} not found in Viem`);
401+
}
402+
386403
/**
387404
* Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
388405
* @param address hex string of the 20 byte address of the contract to upgrade to without the 0x prefix

contract_manager/src/contracts/evm.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,16 @@ export class EvmPriceFeedContract extends PriceFeedContract {
621621
}
622622

623623
async getTotalFee(): Promise<TokenQty> {
624-
const web3 = this.chain.getWeb3();
625-
const amount = BigInt(await web3.eth.getBalance(this.address));
624+
let web3: Web3;
625+
let amount = BigInt(0);
626+
try {
627+
web3 = this.chain.getViemDefaultWeb3();
628+
amount = BigInt(await web3.eth.getBalance(this.address));
629+
} catch (error) {
630+
// Fallback to regular web3 if viem default web3 fails
631+
web3 = this.chain.getWeb3();
632+
amount = BigInt(await web3.eth.getBalance(this.address));
633+
}
626634
return {
627635
amount,
628636
denom: this.chain.getNativeToken(),

contract_manager/store/chains/EvmChains.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,12 @@
634634
rpcUrl: https://node.mainnet.etherlink.com/
635635
networkId: 42793
636636
type: EvmChain
637-
- id: klaytn
637+
- id: kaia
638638
mainnet: true
639639
rpcUrl: https://rpc.ankr.com/klaytn
640640
networkId: 8217
641641
type: EvmChain
642-
- id: klaytn_testnet
642+
- id: kaia_testnet
643643
mainnet: false
644644
rpcUrl: https://rpc.ankr.com/klaytn_testnet
645645
networkId: 1001

contract_manager/store/contracts/EvmEntropyContracts.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@
8282
- chain: sei_evm_testnet
8383
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
8484
type: EvmEntropyContract
85-
- chain: klaytn_testnet
85+
- chain: kaia_testnet
8686
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
8787
type: EvmEntropyContract
88-
- chain: klaytn
88+
- chain: kaia
8989
address: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320"
9090
type: EvmEntropyContract
9191
- chain: b3_testnet

contract_manager/store/contracts/EvmPriceFeedContracts.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@
349349
- chain: sei_evm_testnet
350350
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
351351
type: EvmPriceFeedContract
352-
- chain: klaytn_testnet
352+
- chain: kaia_testnet
353353
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
354354
type: EvmPriceFeedContract
355-
- chain: klaytn
355+
- chain: kaia
356356
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
357357
type: EvmPriceFeedContract
358358
- chain: morph_holesky_testnet

contract_manager/store/contracts/EvmWormholeContracts.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@
331331
- chain: sei_evm_testnet
332332
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
333333
type: EvmWormholeContract
334-
- chain: klaytn_testnet
334+
- chain: kaia_testnet
335335
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
336336
type: EvmWormholeContract
337-
- chain: klaytn
337+
- chain: kaia
338338
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
339339
type: EvmWormholeContract
340340
- chain: morph_holesky_testnet

contract_manager/store/tokens/Tokens.yaml

+108
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,111 @@
5050
pythId: 097d687437374051c75160d648800f021086bc8edf469f11284491fda8192315
5151
decimals: 18
5252
type: token
53+
- id: AVAX
54+
pythId: 93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7
55+
decimals: 18
56+
type: token
57+
- id: MATIC
58+
pythId: ffd11c5a1cfd42f80afb2df4d9f264c15f956d68153335374ec10722edd70472
59+
decimals: 18
60+
type: token
61+
- id: FIL
62+
pythId: 150ac9b959aee0051e4091f0ef5216d941f590e1c5e7f91cf7635b5c11628c0e
63+
decimals: 18
64+
type: token
65+
- id: CELO
66+
pythId: 7d669ddcdd23d9ef1fa9a9cc022ba055ec900e91c4cb960f3c20429d4447a411
67+
decimals: 18
68+
type: token
69+
- id: CRO
70+
pythId: 23199c2bcb1303f667e733b9934db9eca5991e765b45f5ed18bc4b231415f2fe
71+
decimals: 18
72+
type: token
73+
- id: INJ
74+
pythId: 7a5bc1d2b56ad029048cd63964b3ad2776eadf812edc1a43a31406cb54bff592
75+
decimals: 18
76+
type: token
77+
- id: SEI
78+
pythId: 53614f1cb0c031d4af66c04cb9c756234adad0e1cee85303795091499a4084eb
79+
decimals: 18
80+
type: token
81+
- id: BERA
82+
pythId: 962088abcfdbdb6e30db2e340c8cf887d9efb311b1f2f17b155a63dbb6d40265
83+
decimals: 18
84+
type: token
85+
- id: ZETA
86+
pythId: b70656181007f487e392bf0d92e55358e9f0da5da6531c7c4ce7828aa11277fe
87+
decimals: 18
88+
type: token
89+
- id: FLOW
90+
pythId: 2fb245b9a84554a0f15aa123cbb5f64cd263b59e9a87d80148cbffab50c69f30
91+
decimals: 18
92+
type: token
93+
- id: XTZ
94+
pythId: 0affd4b8ad136a21d79bc82450a325ee12ff55a235abc242666e423b8bcffd03
95+
decimals: 18
96+
type: token
97+
- id: KAVA
98+
pythId: a6e905d4e85ab66046def2ef0ce66a7ea2a60871e68ae54aed50ec2fd96d8584
99+
decimals: 18
100+
type: token
101+
- id: USDC
102+
pythId: eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a
103+
decimals: 6
104+
type: token
105+
- id: MOVE
106+
pythId: 6bf748c908767baa762a1563d454ebec2d5108f8ee36d806aadacc8f0a075b6d
107+
decimals: 8
108+
type: token
109+
- id: IP
110+
pythId: b620ba83044577029da7e4ded7a2abccf8e6afc2a0d4d26d89ccdd39ec109025
111+
decimals: 18
112+
type: token
113+
- id: S
114+
pythId: f490b178d0c85683b7a0f2388b40af2e6f7c90cbe0f96b31f315f08d0e5a2d6d
115+
decimals: 18
116+
type: token
117+
- id: KAIA
118+
pythId: 452d40e01473f95aa9930911b4392197b3551b37ac92a049e87487b654b4ebbe
119+
decimals: 18
120+
type: token
121+
- id: APE
122+
pythId: 15add95022ae13563a11992e727c91bdb6b55bc183d9d747436c80a483d8c864
123+
decimals: 18
124+
type: token
125+
- id: SMR
126+
pythId: af5b9ac426ae79591fde6816bc3f043b5e06d5e442f52112f76249320df22449
127+
decimals: 18
128+
type: token
129+
- id: CFX
130+
pythId: 8879170230c9603342f3837cf9a8e76c61791198fb1271bb2552c9af7b33c933
131+
decimals: 18
132+
type: token
133+
- id: CANTO
134+
pythId: 972776d57490d31c32279c16054e5c01160bd9a2e6af8b58780c82052b053549
135+
decimals: 18
136+
type: token
137+
- id: NEON
138+
pythId: d82183dd487bef3208a227bb25d748930db58862c5121198e723ed0976eb92b7
139+
decimals: 18
140+
type: token
141+
- id: MTR
142+
pythId: 8cdc9b2118d2ce55a299f8f1d700d0127cf4036d1aa666a8cd51dcab4254284f
143+
decimals: 18
144+
type: token
145+
- id: WEMIX
146+
pythId: f63f008474fad630207a1cfa49207d59bca2593ea64fc0a6da9bf3337485791c
147+
decimals: 18
148+
type: token
149+
- id: EOS
150+
pythId: 06ade621dbc31ed0fc9255caaab984a468abe84164fb2ccc76f02a4636d97e31
151+
decimals: 18
152+
type: token
153+
- id: RON
154+
pythId: 97cfe19da9153ef7d647b011c5e355142280ddb16004378573e6494e499879f3
155+
decimals: 18
156+
type: token
157+
- id: ZEN
158+
pythId: d183ffe0155e8a55e7274155a14ea2e8b54059cef471f88fa3f7eb4b5d8dbc24
159+
decimals: 18
160+
type: token

governance/xc_admin/packages/xc_admin_common/src/chains.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const RECEIVER_CHAINS = {
8383
gravity: 60053,
8484
polynomial: 60054,
8585
etherlink: 60055,
86-
klaytn: 60056,
86+
kaia: 60056,
8787
kinto: 60057,
8888
b3_mainnet: 60058,
8989
cronos_zkevm_mainnet: 60059,
@@ -201,7 +201,7 @@ export const RECEIVER_CHAINS = {
201201
etherlink_testnet: 50083,
202202
fuel_testnet: 50084,
203203
sei_evm_testnet: 50085,
204-
klaytn_testnet: 50086,
204+
kaia_testnet: 50086,
205205
morph_holesky_testnet: 50087,
206206
tabi_testnet: 50088,
207207
movement_suzuka_testnet: 50089,

0 commit comments

Comments
 (0)