-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(apps/price_pusher): Use viem instead of web3 for evm pusher (#…
…1829) Web3 library is not very widely used anymore due to its complex and magical internal design. Some users were reporting issues like strange timeouts or unsupported RPC calls via web3 (and the deprecated HDWalletProvider by truffle that we use). This change refactors the code to use Viem. The experience with Viem is nice: it has strong types and good utilities. The error handling is also very well designed. The downside is that it has a steep learning curve to get it right. This change refactors the code based on the PR reviews to make it simpler as well. Lastly the version is bumped as a major release because the behaviour and logs have changed and it might affect production environments. It also signals the users to test it out properly before using it which is good because all the failure cases might not be handled.
- xc-admin-v0.6.13
- xc-admin-v0.6.12
- xc-admin-v0.6.11
- xc-admin-v0.6.10
- xc-admin-v0.6.9
- xc-admin-v0.6.8
- xc-admin-v0.6.7
- xc-admin-v0.6.6
- xc-admin-v0.6.5
- rust-pyth-lazer-solana-contract-v0.3.0
- rust-pyth-lazer-solana-contract-v0.2.0
- rust-pyth-lazer-solana-contract-v0.1.0
- rust-pyth-lazer-sdk-v0.1.0
- rust-pyth-lazer-protocol-v0.6.2
- rust-pyth-lazer-protocol-v0.6.1
- rust-pyth-lazer-protocol-v0.6.0
- rust-pyth-lazer-protocol-v0.5.1
- rust-pyth-lazer-protocol-v0.5.0
- rust-pyth-lazer-protocol-v0.4.2
- rust-pyth-lazer-protocol-v0.4.1
- rust-pyth-lazer-protocol-v0.4.0
- rust-pyth-lazer-protocol-v0.3.3
- rust-pyth-lazer-protocol-v0.3.2
- rust-pyth-lazer-protocol-v0.3.1
- rust-pyth-lazer-protocol-v0.3.0
- rust-pyth-lazer-protocol-v0.2.6
- rust-pyth-lazer-protocol-v0.2.5
- rust-pyth-lazer-protocol-v0.2.4
- rust-pyth-lazer-protocol-v0.2.3
- rust-pyth-lazer-protocol-v0.2.2
- rust-pyth-lazer-protocol-v0.2.1
- rust-pyth-lazer-protocol-v0.2.0
- rust-pyth-lazer-protocol-v0.1.3
- rust-pyth-lazer-protocol-v0.1.2
- rust-pyth-lazer-protocol-v0.1.1
- rust-pyth-lazer-protocol-v0.1.0
- rust-pyth-lazer-client-v0.1.2
- rust-pyth-lazer-client-v0.1.1
- python-v0.12.2
- python-v0.10.1
- python-v0.10.0
- python-v0.9.0
- pythnet-sdk-v2.3.1
- pyth-solana-receiver-sdk-v0.5.0
- pyth-solana-receiver-sdk-v0.4.0
- pyth-solana-receiver-sdk-v0.3.2
- pyth-price-store-v0.1.0
- pyth-price-pusher-v9.1.0
- pyth-price-pusher-v9.0.1
- pyth-price-pusher-v9.0.0
- pyth-price-pusher-v8.3.3
- pyth-price-pusher-v8.3.2
- pyth-price-pusher-v8.3.0
- pyth-price-pusher-v8.2.0
- pyth-price-pusher-v8.1.0
- pyth-price-pusher-v8.0.4
- pyth-price-pusher-v8.0.3
- pyth-price-pusher-v8.0.2
- pyth-price-pusher-v8.0.0
- pyth-price-pusher-v8.0.0-alpha
- pyth-js-v117
- pyth-js-v116
- pyth-js-v115
- pyth-js-v114
- pyth-js-v113
- pyth-js-v112
- pyth-js-v111
- pyth-js-v110
- pyth-js-v109
- pyth-js-v108
- pyth-js-v107
- pyth-js-v106
- pyth-js-v105
- pyth-js-v104
- pyth-js-v103
- pyth-js-v102
- pyth-js-v101
- pyth-js-v100
- pyth-js-v99
- pyth-js-v98
- pyth-js-v97
- pyth-js-v96
- pyth-js-v95
- pyth-js-v94
- pyth-js-v93
- pyth-js-v92
- pyth-js-v91
- pyth-js-v90
- pyth-js-v89
- pyth-js-v88
- pyth-js-v87
- pyth-js-v86
- pyth-js-v85
- pyth-js-v84
- pyth-js-v83
- pyth-js-v82
- pyth-js-v81
- pyth-js-v80
- pyth-js-v79
- pyth-js-v78
- pyth-js-v77
- pyth-js-v76
- pyth-fuel-contract-v0.6.0
- hermes-v0.8.2
- hermes-v0.8.1
- hermes-v0.7.2
- hermes-v0.7.1
- hermes-v0.7.0
- hermes-v0.6.1
- hermes-v0.6.0
- hermes-v0.5.17
- hermes-v0.5.16
- fortuna-v7.4.4
- fortuna-v7.4.1
- fortuna-v7.4.0
- fortuna-v7.3.0
- fortuna-v7.2.0
- fortuna-v7.1.0
- fortuna-v7.0.0
- fortuna-v6.8.1
- fortuna-v6.7.2
- fortuna-v6.7.1
- fortuna-v6.7.0
- fortuna-v6.6.0
- fortuna-v6.5.5
- fortuna-v6.5.4
- fortuna-v6.5.3
1 parent
7fddbd6
commit 5c3be6a
Showing
9 changed files
with
1,064 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getContract, Address, GetContractReturnType } from "viem"; | ||
import { PythAbi } from "./pyth-abi"; | ||
import { SuperWalletClient } from "./super-wallet"; | ||
|
||
export type PythContract = GetContractReturnType< | ||
typeof PythAbi, | ||
SuperWalletClient | ||
>; | ||
|
||
export const createPythContract = ( | ||
client: SuperWalletClient, | ||
address: Address | ||
): PythContract => | ||
getContract({ | ||
client, | ||
abi: PythAbi, | ||
address, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
createPublicClient, | ||
createWalletClient, | ||
defineChain, | ||
http, | ||
webSocket, | ||
Account, | ||
Chain, | ||
publicActions, | ||
Client, | ||
RpcSchema, | ||
WalletActions, | ||
PublicActions, | ||
WebSocketTransport, | ||
HttpTransport, | ||
Transport, | ||
} from "viem"; | ||
import { mnemonicToAccount } from "viem/accounts"; | ||
import * as chains from "viem/chains"; | ||
import { isWsEndpoint } from "../utils"; | ||
|
||
const UNKNOWN_CHAIN_CONFIG = { | ||
name: "Unknown", | ||
nativeCurrency: { | ||
name: "Unknown", | ||
symbol: "Unknown", | ||
decimals: 18, | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [], | ||
}, | ||
}, | ||
}; | ||
|
||
export type SuperWalletClient = Client< | ||
Transport, | ||
Chain, | ||
Account, | ||
RpcSchema, | ||
PublicActions<Transport, Chain, Account> & WalletActions<Chain, Account> | ||
>; | ||
|
||
// Get the transport based on the endpoint | ||
const getTransport = (endpoint: string): WebSocketTransport | HttpTransport => | ||
isWsEndpoint(endpoint) ? webSocket(endpoint) : http(endpoint); | ||
|
||
// Get the chain corresponding to the chainId. If the chain is not found, it will return | ||
// an unknown chain which should work fine in most of the cases. We might need to update | ||
// the viem package to support new chains if they don't work as expected with the unknown | ||
// chain. | ||
const getChainById = (chainId: number): Chain => | ||
Object.values(chains).find((chain) => chain.id === chainId) || | ||
defineChain({ id: chainId, ...UNKNOWN_CHAIN_CONFIG }); | ||
|
||
export const createClient = async ( | ||
endpoint: string, | ||
mnemonic: string | ||
): Promise<SuperWalletClient> => { | ||
const transport = getTransport(endpoint); | ||
|
||
const chainId = await createPublicClient({ | ||
transport, | ||
}).getChainId(); | ||
|
||
return createWalletClient({ | ||
transport, | ||
account: mnemonicToAccount(mnemonic), | ||
chain: getChainById(chainId), | ||
}).extend(publicActions); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.