Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getWrappedAssetAddress function #94

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
);
}
};
Loading