Skip to content

Commit

Permalink
feat: approve methods for cross-asset exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
Makeev Ivan committed Oct 27, 2021
1 parent 85c25e8 commit 337a741
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
crossAssetExchangeAvailable,
crossAssetExchangeOutputAndSlippage,
crossAssetExchangeExpected,
crossAssetExchangeIsApproved,
crossAssetExchangeApproveEstimateGas,
crossAssetExchangeApprove,
crossAssetExchangeEstimateGas,
crossAssetExchange,
} from "./pools";
Expand Down Expand Up @@ -59,18 +62,21 @@ const curve = {
hasAllowance,
ensureAllowance,
getBestPoolAndOutput,
exchangeExpected,
exchangeIsApproved,
exchangeApprove,
exchangeExpected,
exchange,
crossAssetExchangeAvailable,
crossAssetExchangeOutputAndSlippage,
crossAssetExchangeExpected,
crossAssetExchangeIsApproved,
crossAssetExchangeApprove,
crossAssetExchange,
estimateGas: {
ensureAllowance: ensureAllowanceEstimateGas,
exchangeApprove: exchangeApproveEstimateGas,
exchange: exchangeEstimateGas,
crossAssetExchangeApprove: crossAssetExchangeApproveEstimateGas,
crossAssetExchange: crossAssetExchangeEstimateGas,
},
boosting: {
Expand Down
12 changes: 12 additions & 0 deletions src/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,18 @@ export const crossAssetExchangeExpected = async (inputCoin: string, outputCoin:
return ethers.utils.formatUnits(_expected, outputCoinDecimals)
}

export const crossAssetExchangeIsApproved = async (inputCoin: string, amount: string): Promise<boolean> => {
return await hasAllowance([inputCoin], [amount], curve.signerAddress, ALIASES.router);
}

export const crossAssetExchangeApproveEstimateGas = async (inputCoin: string, amount: string): Promise<number> => {
return await ensureAllowanceEstimateGas([inputCoin], [amount], ALIASES.router);
}

export const crossAssetExchangeApprove = async (inputCoin: string, amount: string): Promise<string[]> => {
return await ensureAllowance([inputCoin], [amount], ALIASES.router);
}

export const crossAssetExchangeEstimateGas = async (inputCoin: string, outputCoin: string, amount: string, maxSlippage = 0.02): Promise<number> => {
if (!(await crossAssetExchangeAvailable(inputCoin, outputCoin))) throw Error("Such exchange is not available");

Expand Down

0 comments on commit 337a741

Please sign in to comment.