Skip to content

Commit

Permalink
refactor: shortened approve methods for straight exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
Makeev Ivan committed Oct 27, 2021
1 parent 337a741 commit efbf7ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "1.6.1",
"version": "1.7.0",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"scripts": {
Expand Down
30 changes: 6 additions & 24 deletions src/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1718,36 +1718,18 @@ export const exchangeExpected = async (inputCoin: string, outputCoin: string, am
}

export const exchangeIsApproved = async (inputCoin: string, outputCoin: string, amount: string): Promise<boolean> => {
const [poolName, i, , isUnderlying] = await _getExchangeData(inputCoin, outputCoin, amount);
const pool = new Pool(poolName);

if (isUnderlying) {
return await pool.exchangeIsApproved(i, amount);
} else {
return await pool.exchangeWrappedIsApproved(i, amount);
}
const { poolAddress } = await getBestPoolAndOutput(inputCoin, outputCoin, amount);
return await hasAllowance([inputCoin], [amount], curve.signerAddress, poolAddress);
}

export const exchangeApproveEstimateGas = async (inputCoin: string, outputCoin: string, amount: string): Promise<number> => {
const [poolName, i, , isUnderlying] = await _getExchangeData(inputCoin, outputCoin, amount);
const pool = new Pool(poolName);

if (isUnderlying) {
return await pool.estimateGas.exchangeApprove(i, amount);
} else {
return await pool.estimateGas.exchangeWrappedApprove(i, amount);
}
const { poolAddress } = await getBestPoolAndOutput(inputCoin, outputCoin, amount);
return await ensureAllowanceEstimateGas([inputCoin], [amount], poolAddress);
}

export const exchangeApprove = async (inputCoin: string, outputCoin: string, amount: string): Promise<string[]> => {
const [poolName, i, , isUnderlying] = await _getExchangeData(inputCoin, outputCoin, amount);
const pool = new Pool(poolName);

if (isUnderlying) {
return await pool.exchangeApprove(i, amount);
} else {
return await pool.exchangeWrappedApprove(i, amount);
}
const { poolAddress } = await getBestPoolAndOutput(inputCoin, outputCoin, amount);
return await ensureAllowance([inputCoin], [amount], poolAddress);
}

export const exchangeEstimateGas = async (inputCoin: string, outputCoin: string, amount: string, maxSlippage = 0.01): Promise<number> => {
Expand Down

0 comments on commit efbf7ee

Please sign in to comment.