From e926a2fad776da6b0ea635794274224dfcef9be0 Mon Sep 17 00:00:00 2001 From: Wayne Cheng <677680+welps@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:25:27 -0500 Subject: [PATCH] feat: add getWrappedAssetAddress function (#94) --- sdk/src/wrappedAsset.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sdk/src/wrappedAsset.ts b/sdk/src/wrappedAsset.ts index be8f52e..67f69a2 100644 --- a/sdk/src/wrappedAsset.ts +++ b/sdk/src/wrappedAsset.ts @@ -4,7 +4,7 @@ import { Contract } from '@ethersproject/contracts'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { Transaction } from '@ethersproject/transactions'; import { default as WethAbi } from './abi/Weth.json'; -import { EthereumAddress, TransactionOptions } from './types'; +import {EthereumAddress, Quote, SwapType, TransactionOptions} from './types'; /** * Function to wrap a specific amount of the native asset @@ -75,3 +75,21 @@ export const getWrappedAssetMethod = ( ); return instance.estimateGas[name]; }; + +/** + * Get the wrapped asset address from a quote on a wrap/unwrap + * @param quote + * @returns {EthereumAddress} + */ +export const getWrappedAssetAddress = (quote: Quote): EthereumAddress => { + switch (quote.swapType) { + case SwapType.wrap: + return quote.buyTokenAddress as EthereumAddress; + case SwapType.unwrap: + return quote.sellTokenAddress as EthereumAddress; + default: + throw new Error( + `Getting wrapped asset address on a ${quote.swapType} swap is not supported` + ); + } +};