Skip to content

Commit

Permalink
feat: remove ethers imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix committed Jun 4, 2024
1 parent 425fe03 commit 2915a6f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 261 deletions.
9 changes: 3 additions & 6 deletions packages/bridge/src/axelar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ import {
Address,
createPublicClient,
encodeFunctionData,
erc20Abi,
http,
toHex,
} from "viem";

import { BridgeError, BridgeQuoteError } from "../errors";
import {
Erc20Abi,
EthereumChainInfo,
NativeEVMTokenConstantAddress,
} from "../ethereum";
import { EthereumChainInfo, NativeEVMTokenConstantAddress } from "../ethereum";
import {
BridgeAsset,
BridgeCoin,
Expand Down Expand Up @@ -370,7 +367,7 @@ export class AxelarBridgeProvider implements BridgeProvider {
type: "evm",
to: fromAsset.address as Address, // ERC20 token address
data: encodeFunctionData({
abi: Erc20Abi,
abi: erc20Abi,
functionName: "transfer",
args: [depositAddress as `0x${string}`, BigInt(fromAmount)],
}),
Expand Down
224 changes: 0 additions & 224 deletions packages/bridge/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,227 +132,3 @@ export const EthereumChainInfo = createEthereumChainInfo({
*/
export const NativeEVMTokenConstantAddress =
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";

/** ABI spec for interfacing with ERC20 token contracts on EVM chains. */
export const Erc20Abi = [
{
constant: true,
inputs: [],
name: "name",
outputs: [
{
name: "",
type: "string",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{
name: "_spender",
type: "address",
},
{
name: "_value",
type: "uint256",
},
],
name: "approve",
outputs: [
{
name: "",
type: "bool",
},
],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "totalSupply",
outputs: [
{
name: "",
type: "uint256",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{
name: "_from",
type: "address",
},
{
name: "_to",
type: "address",
},
{
name: "_value",
type: "uint256",
},
],
name: "transferFrom",
outputs: [
{
name: "",
type: "bool",
},
],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "decimals",
outputs: [
{
name: "",
type: "uint8",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address",
},
],
name: "balanceOf", // balanceOf
outputs: [
{
name: "balance",
type: "uint256",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "symbol",
outputs: [
{
name: "",
type: "string",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{
name: "_to",
type: "address",
},
{
name: "_value",
type: "uint256",
},
],
name: "transfer",
outputs: [
{
name: "",
type: "bool",
},
],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address",
},
{
name: "_spender",
type: "address",
},
],
name: "allowance",
outputs: [
{
name: "",
type: "uint256",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
payable: true,
stateMutability: "payable",
type: "fallback",
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: "owner",
type: "address",
},
{
indexed: true,
name: "spender",
type: "address",
},
{
indexed: false,
name: "value",
type: "uint256",
},
],
name: "Approval",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: "from",
type: "address",
},
{
indexed: true,
name: "to",
type: "address",
},
{
indexed: false,
name: "value",
type: "uint256",
},
],
name: "Transfer",
type: "event",
},
] as const;
17 changes: 9 additions & 8 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fromBech32, toBech32 } from "@cosmjs/encoding";
import { CoinPretty } from "@keplr-wallet/unit";
import { isNil } from "@osmosis-labs/utils";
import cachified from "cachified";
import {
Address,
Expand Down Expand Up @@ -291,7 +292,7 @@ export class SkipBridgeProvider implements BridgeProvider {
};
}

private getEthersProvider(chainID: string) {
private getViemProvider(chainID: string) {
const evmChain = Object.values(EthereumChainInfo).find(
(chain) => chain.id.toString() === chainID
);
Expand Down Expand Up @@ -321,7 +322,7 @@ export class SkipBridgeProvider implements BridgeProvider {
}
| undefined
> {
const provider = this.getEthersProvider(chainID);
const provider = this.getViemProvider(chainID);

const allowance = await provider.readContract({
abi: erc20Abi,
Expand Down Expand Up @@ -545,10 +546,10 @@ export class SkipBridgeProvider implements BridgeProvider {
try {
if (!txData.approvalTransactionRequest) {
const estimatedGas = await provider.estimateGas({
from: params.fromAddress,
account: params.fromAddress as Address,
to: txData.to,
data: txData.data,
value: txData.value,
value: !isNil(txData.value) ? BigInt(txData.value) : undefined,
});

return BigInt(estimatedGas);
Expand Down Expand Up @@ -585,10 +586,10 @@ export class SkipBridgeProvider implements BridgeProvider {
};

// Call with no state overrides
const callResult = await provider.send("eth_estimateGas", [
...callParams,
stateDiff,
]);
const callResult = await provider.request({
method: "eth_estimateGas",
params: [...callParams, stateDiff],
});

return BigInt(callResult);
} catch (err) {
Expand Down
Loading

0 comments on commit 2915a6f

Please sign in to comment.