Skip to content

Commit

Permalink
Merge pull request #233 from curvefi/fix/native-get_dx-calc_token_amo…
Browse files Browse the repository at this point in the history
…unt-for-stableNG

Fix: native get_dx and calc_token_amount for stable-ng
  • Loading branch information
Macket authored Nov 29, 2023
2 parents ae8460a + 471c5dc commit 6e3ce5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 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": "2.52.1",
"version": "2.52.2",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
37 changes: 24 additions & 13 deletions src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export class PoolTemplate {
try {
const contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;

if (curve.constants.ALIASES.stable_calc === curve.constants.ZERO_ADDRESS) {
if (curve.constants.ALIASES.stable_calc === curve.constants.ZERO_ADDRESS || this.id.startsWith("factory-stable-ng")) {
return await this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying);
} else if (this.isMeta) {
const basePool = new PoolTemplate(this.basePool);
Expand Down Expand Up @@ -1948,37 +1948,48 @@ export class PoolTemplate {
}

private async _swapRequired(i: number, j: number, _amount: bigint, isUnderlying: boolean): Promise<any> {
const poolAddress = this.address;

const contract = this.isCrypto ? curve.contracts[curve.constants.ALIASES.crypto_calc].contract : curve.contracts[curve.constants.ALIASES.stable_calc].contract;

if(this.isCrypto) {
const contract = curve.contracts[curve.constants.ALIASES.crypto_calc].contract;
if(this.isMeta && isUnderlying) {
const basePool = new PoolTemplate(this.basePool);
if(this.wrappedCoins.length === 3) {
return await contract.get_dx_tricrypto_meta_underlying(poolAddress,i,j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
return await contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
}
if(basePool.isFake) {
const secondPool = new PoolTemplate(basePool.basePool)
return await contract.get_dx_double_meta_underlying(poolAddress,i,j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, curve.constantOptions)
return await contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, curve.constantOptions)
}
return await contract.get_dx_meta_underlying(poolAddress,i,j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
return await contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
} else {
return await contract.get_dx(poolAddress,i,j, _amount, this.wrappedCoins.length, curve.constantOptions)
return await contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions)
}
} else {
if (this.id.startsWith("factory-stable-ng")) {
const contract = curve.contracts[this.address].contract;
if (this.isMeta) {
if (isUnderlying) {
return await contract.get_dx_underlying(i, j, _amount, curve.constantOptions);
} else {
return await contract.get_dx(i, j, _amount, curve.constantOptions);
}
} else {
return await contract.get_dx(i, j, _amount)
}
}

const contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
if(this.isMeta) {
const basePool = new PoolTemplate(this.basePool);
if(isUnderlying) {
return await contract.get_dx_meta_underlying(poolAddress,i,j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
return await contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions)
} else {
return await contract. get_dx_meta(poolAddress,i,j, _amount, this.wrappedCoins.length, basePool.address, curve.constantOptions)
return await contract. get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, curve.constantOptions)
}
} else {
if(isUnderlying && this.isLending) {
return await contract.get_dx_underlying(poolAddress,i,j, _amount, this.underlyingCoins.length, curve.constantOptions)
return await contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length, curve.constantOptions)
} else {
return await contract.get_dx(poolAddress,i,j, _amount, this.wrappedCoins.length, curve.constantOptions)
return await contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions)
}
}
}
Expand Down

0 comments on commit 6e3ce5e

Please sign in to comment.