Skip to content

Commit

Permalink
fix: don't use hardcoded wrapped asset addresses (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
welps authored Dec 9, 2024
1 parent f61d6a9 commit 89fdf6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
17 changes: 0 additions & 17 deletions sdk/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@ export type MultiChainAsset = {
[key: string]: EthereumAddress;
};

/**
* @deprecated: Should not use this anymore to reduce friction for new network support
*/
export const WRAPPED_ASSET: MultiChainAsset = {
[`${ChainId.mainnet}`]: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
[`${ChainId.optimism}`]: '0x4200000000000000000000000000000000000006',
[`${ChainId.polygon}`]: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
[`${ChainId.arbitrum}`]: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
[`${ChainId.bsc}`]: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
[`${ChainId.zora}`]: '0x4200000000000000000000000000000000000006',
[`${ChainId.base}`]: '0x4200000000000000000000000000000000000006',
[`${ChainId.avalanche}`]: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
[`${ChainId.blast}`]: '0x4300000000000000000000000000000000000004',
[`${ChainId.degen}`]: '0xeb54dacb4c2ccb64f8074eceea33b5ebb38e5387',
[`${ChainId.apechain}`]: '0x8643a49363e80c7a15790703b915d1b0b6b71d56',
};

export const DAI: MultiChainAsset = {
[`${ChainId.mainnet}`]: '0x6b175474e89094c44da98b954eedeac495271d0f',
};
Expand Down
18 changes: 10 additions & 8 deletions sdk/src/wrappedAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { Contract } from '@ethersproject/contracts';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Transaction } from '@ethersproject/transactions';
import { default as WethAbi } from './abi/Weth.json';
import { ChainId, TransactionOptions } from './types';
import { WRAPPED_ASSET } from './utils/constants';
import { EthereumAddress, TransactionOptions } from './types';

/**
* Function to wrap a specific amount of the native asset
* for the specified wallet from its ERC20 version
* @param {BigNumberish} amount
* @param {Signer} wallet
* @param {EthereumAddress} wrappedAssetAddress
* @returns {Promise<Transaction>}
*/
export const wrapNativeAsset = async (
amount: BigNumberish,
wallet: Signer,
chainId: ChainId = ChainId.mainnet,
wrappedAssetAddress: EthereumAddress,
transactionOptions: TransactionOptions = {}
): Promise<Transaction> => {
const instance = new Contract(
WRAPPED_ASSET[chainId],
wrappedAssetAddress,
JSON.stringify(WethAbi),
wallet
);
Expand All @@ -37,16 +37,17 @@ export const wrapNativeAsset = async (
* for the specified wallet from its ERC20 version
* @param {BigNumberish} amount
* @param {Signer} wallet
* @param {EthereumAddress} wrappedAssetAddress
* @returns {Promise<Transaction>}
*/
export const unwrapNativeAsset = async (
amount: BigNumberish,
wallet: Signer,
chainId: ChainId = ChainId.mainnet,
wrappedAssetAddress: EthereumAddress,
transactionOptions: TransactionOptions = {}
): Promise<Transaction> => {
const instance = new Contract(
WRAPPED_ASSET[chainId],
wrappedAssetAddress,
JSON.stringify(WethAbi),
wallet
);
Expand All @@ -59,15 +60,16 @@ export const unwrapNativeAsset = async (
* function that wraps or unwraps, to be used by estimateGas calls
* @param {string} name
* @param {StaticJsonRpcProvider} provider
* @param {EthereumAddress} wrappedAssetAddress
* @returns {Promise<Transaction>}
*/
export const getWrappedAssetMethod = (
name: string,
provider: StaticJsonRpcProvider,
chainId: ChainId = ChainId.mainnet
wrappedAssetAddress: EthereumAddress
): any => {
const instance = new Contract(
WRAPPED_ASSET[chainId],
wrappedAssetAddress,
JSON.stringify(WethAbi),
provider
);
Expand Down

0 comments on commit 89fdf6e

Please sign in to comment.