Skip to content

Commit

Permalink
feat: add getWrappedAssetAddress function (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
welps authored Dec 11, 2024
1 parent a346220 commit e926a2f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sdk/src/wrappedAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
);
}
};

0 comments on commit e926a2f

Please sign in to comment.