Skip to content

Fix: deposit and stake ng only #415

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

Merged
merged 2 commits into from
Nov 20, 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
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.65.8",
"version": "2.65.9",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
50 changes: 50 additions & 0 deletions src/constants/abis/deposit_and_stake_ng_only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"stateMutability": "payable",
"type": "function",
"name": "deposit_and_stake",
"inputs": [
{
"name": "deposit",
"type": "address"
},
{
"name": "lp_token",
"type": "address"
},
{
"name": "gauge",
"type": "address"
},
{
"name": "n_coins",
"type": "uint256"
},
{
"name": "coins",
"type": "address[]"
},
{
"name": "amounts",
"type": "uint256[]"
},
{
"name": "min_mint_amount",
"type": "uint256"
},
{
"name": "use_dynarray",
"type": "bool"
},
{
"name": "pool",
"type": "address"
}
],
"outputs": []
},
{
"stateMutability": "payable",
"type": "fallback"
}
]
12 changes: 10 additions & 2 deletions src/curve.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import { getFactoryPoolData } from "./factory/factory.js";
import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
import { getCryptoFactoryPoolData } from "./factory/factory-crypto.js";
import { getTricryptoFactoryPoolData } from "./factory/factory-tricrypto.js";
import {IPoolData, IDict, ICurve, INetworkName, IChainId, IFactoryPoolType, Abi, INetworkConstants} from "./interfaces";
import {IPoolData, IDict, ICurve, IChainId, IFactoryPoolType, Abi, INetworkConstants} from "./interfaces";
import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
import cERC20Abi from './constants/abis/cERC20.json' assert { type: 'json' };
import yERC20Abi from './constants/abis/yERC20.json' assert { type: 'json' };
@@ -30,6 +30,7 @@ import feeDistributorABI from './constants/abis/fee_distributor.json' assert { t
import feeDistributorCrvUSDABI from './constants/abis/fee_distributor_crvusd.json' assert { type: 'json' };
import gaugeControllerABI from './constants/abis/gaugecontroller.json' assert { type: 'json' };
import depositAndStakeABI from './constants/abis/deposit_and_stake.json' assert { type: 'json' };
import depositAndStakeNgOnlyABI from './constants/abis/deposit_and_stake_ng_only.json' assert { type: 'json' };
import cryptoCalcZapABI from './constants/abis/crypto_calc.json' assert { type: 'json'};
import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type: 'json' };
import routerABI from './constants/abis/router.json' assert { type: 'json' };
@@ -56,6 +57,9 @@ import { L2Networks } from "./constants/L2Networks.js";
import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
import {getNetworkConstants} from "./utils.js";


export const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools

export const memoizedContract = (): (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract => {
const cache: Record<string, Contract> = {};
return (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer): Contract => {
@@ -369,7 +373,11 @@ class Curve implements ICurve {
this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
}

this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
if (OLD_CHAINS.includes(this.chainId)) {
this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
} else {
this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeNgOnlyABI);
}

this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);

86 changes: 59 additions & 27 deletions src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import {
PERIODS,
} from '../utils.js';
import {IDict, IProfit} from '../interfaces';
import { curve } from "../curve.js";
import { curve, OLD_CHAINS } from "../curve.js";
import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
import {CorePool} from "./subClasses/corePool.js";
import {StatsPool} from "./subClasses/statsPool.js";
@@ -1227,6 +1227,7 @@ export class PoolTemplate extends CorePool {

const contract = curve.contracts[curve.constants.ALIASES.deposit_and_stake].contract;
const useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && (!this.zap || this.id == 'avaxcrypto');
const useDynarray = (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg);
const _expectedLpTokenAmount = isUnderlying ?
curve.parseUnits(await this.depositAndStakeExpected(amounts)) :
curve.parseUnits(await this.depositAndStakeWrappedExpected(amounts));
@@ -1235,37 +1236,68 @@ export class PoolTemplate extends CorePool {
const ethIndex = getEthIndex(coinAddresses);
const value = _amounts[ethIndex] || curve.parseUnits("0");

const _gas = (await contract.deposit_and_stake.estimateGas(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useUnderlying,
(!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg),
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{ ...curve.constantOptions, value }
))
let _gas = BigInt(0)
if (OLD_CHAINS.includes(curve.chainId)) {
_gas = (await contract.deposit_and_stake.estimateGas(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useUnderlying, // <--- DIFFERENCE
useDynarray,
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{...curve.constantOptions, value}
))
} else {
_gas = (await contract.deposit_and_stake.estimateGas(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useDynarray,
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{...curve.constantOptions, value}
))
}

if (estimateGas) return smartNumber(_gas)

await curve.updateFeeData();
const gasLimit = DIGas(_gas) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
return (await contract.deposit_and_stake(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useUnderlying,
(!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg),
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{ ...curve.options, gasLimit, value }
)).hash
if (OLD_CHAINS.includes(curve.chainId)) {
return (await contract.deposit_and_stake(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useUnderlying, // <--- DIFFERENCE
useDynarray,
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{...curve.options, gasLimit, value}
)).hash
} else {
return (await contract.deposit_and_stake(
depositAddress,
this.lpToken,
this.gauge.address,
coins.length,
coinAddresses,
_amounts,
_minMintAmount,
useDynarray,
this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS,
{...curve.options, gasLimit, value}
)).hash
}
}

// ---------------- WITHDRAW ----------------
4 changes: 1 addition & 3 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import axios from "axios";
import memoize from "memoizee";
import BigNumber from "bignumber.js";
import {ethers} from "ethers";
import {curve} from "./curve.js";
import { curve, OLD_CHAINS } from "./curve.js";
import {IDict, IRoute, IRouteOutputAndCost, IRouteStep} from "./interfaces";
import {
_cutZeros,
@@ -35,8 +35,6 @@ import {IRouteGraphInput, routeGraphWorker, routeGraphWorkerCode} from "./route-
const MAX_STEPS = 5;
const ROUTE_LENGTH = (MAX_STEPS * 2) + 1;

const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools

const _getTVL = memoize(
async (poolId: string) => Number(await (getPool(poolId)).stats.totalLiquidity()),
{

Unchanged files with check annotations Beta

'0xdAD97F7713Ae9437fa9249920eC8507e5FbB23d3': 'atricrypto3',
});
export const basePoolIdZapDictEthereum: IDict<{ address: string, ABI: any }> = {

Check warning on line 18 in src/constants/factory/crypto.ts

GitHub Actions / test

Unexpected any. Specify a different type
'3pool': {
address: "0x97aDC08FA1D849D2C48C5dcC1DaB568B169b0267".toLowerCase(),
ABI: tripoolZapABI,
},
};
export const basePoolIdZapDictPolygon: IDict<{ address: string, ABI: any }> = {

Check warning on line 29 in src/constants/factory/crypto.ts

GitHub Actions / test

Unexpected any. Specify a different type
atricrypto3: {
address: "0x3d8EADb739D1Ef95dd53D718e4810721837c69c1".toLowerCase(),
ABI: atricrypto3ZapABI,
export const CRYPTO_FACTORY_CONSTANTS: { [index: number]: {
lpTokenBasePoolIdDict?: IDict<string>,
basePoolIdZapDict?: IDict<{ address: string, ABI: any }>,

Check warning on line 127 in src/constants/factory/crypto.ts

GitHub Actions / test

Unexpected any. Specify a different type
tricryptoDeployImplementations?: IDict<string | number>,
} } = {
1: { // ETH
import { lowerCaseKeys } from "../utils.js";
export const implementationABIDictEthereum: IDict<any> = lowerCaseKeys({

Check warning on line 44 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0x5F890841f657d90E081bAbdB532A05996Af79Fe6": factorySwapABI,
"0x213be373FDff327658139C7df330817DAD2d5bBE": MetaUSDABI,
"0xaD4753D045D3Aed5C1a6606dFb6a7D7AD67C1Ad7": Plain4OptimizedABI,
});
export const implementationABIDictPolygon: IDict<any> = lowerCaseKeys({

Check warning on line 90 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0x4fb93D7d320E8A263F22f62C2059dFC2A8bCbC4c": MetaUSDABI,
"0x39fE1824f98CD828050D7c51dA443E84121c7cf1": MetaUSDBalancesABI,
"0xAc273d5b4FC06625d8b1abA3BE8De15bDFb8E39f": Plain4OptimizedABI,
});
export const implementationABIDictFantom: IDict<any> = lowerCaseKeys({

Check warning on line 113 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0xfCE359115dFe1533a2458650123F86C454BC0213": MetaUSDABI,
"0x09C62ad0694e3f1ad8cF8876aaBe56138C586f5F": MetaUSDBalancesABI,
"0x65e38C41CcE6D9Bc202209Cc546B2f63985D4139": Plain6OptimizedABI,
});
export const implementationABIDictAvalanche: IDict<any> = lowerCaseKeys({

Check warning on line 146 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0xA237034249290De2B07988Ac64b96f22c0E76fE0": MetaUSDABI,
"0xc50C05Ca1f8C2346664bd0d4a1eb6aC1Da38414f": MetaUSDBalancesABI, // 0x7f90122BF0700F9E7e1F688fe926940E8839F353
"0xCE94D3E5b0D80565D7B713A687b39a3Dc81780BA": Plain4OptimizedABI,
});
export const implementationABIDictArbitrum: IDict<any> = lowerCaseKeys({

Check warning on line 169 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0x09672362833d8f703D5395ef3252D4Bfa51c15ca": MetaUSDABI,
"0xBE175115BF33E12348ff77CcfEE4726866A0Fbd5": MetaUSDBalancesABI,
"0x06e3C4da96fd076b97b7ca3Ae23527314b6140dF": Plain4OptimizedABI,
});
export const implementationABIDictOptimism: IDict<any> = lowerCaseKeys({

Check warning on line 197 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0x78CF256256C8089d68Cde634Cf7cDEFb39286470": MetaUSDABI,
"0xADf698e4d8Df08b3E2c79682891636eF00F6e205": MetaUSDBalancesABI,
"0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6": Plain4OptimizedABI,
})
export const implementationABIDictXDai: IDict<any> = lowerCaseKeys({

Check warning on line 222 in src/constants/factory/stable.ts

GitHub Actions / test

Unexpected any. Specify a different type
"0x4A5bF7Ab9A8202692051c19B102d3eDD62aaBAE6": MetaUSDABI,
"0x0B4dc7A945695D11FD83e40B2DfC2B896A02395F": MetaUSDBalancesABI,