Skip to content

Commit

Permalink
Merge pull request #231 from curvefi/feat/add-deploy-for-stable-ng-fa…
Browse files Browse the repository at this point in the history
…ctory

feat: add fetchRecentlyDeployedStableNgFactoryPool
  • Loading branch information
fedorovdg authored Nov 24, 2023
2 parents 04fa9a0 + 49d5d6c commit ae8460a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 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.0",
"version": "2.52.1",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
10 changes: 10 additions & 0 deletions src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,16 @@ class Curve implements ICurve {
return Object.keys(poolData)[0] // id
}

fetchRecentlyDeployedStableNgFactoryPool = async (poolAddress: string): Promise<string> => {
if (this.chainId === 1313161554) return '';

const poolData = lowerCasePoolDataAddresses(await getFactoryPoolData.call(this, 0, poolAddress, this.constants.ALIASES.stable_ng_factory));
this.constants.STABLE_NG_FACTORY_POOLS_DATA = { ...this.constants.STABLE_NG_FACTORY_POOLS_DATA, ...poolData };
this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);

return Object.keys(poolData)[0] // id
}

fetchRecentlyDeployedCryptoFactoryPool = async (poolAddress: string): Promise<string> => {
if (![1, 56, 137, 250, 8453].includes(this.chainId)) return '';
const poolData = lowerCasePoolDataAddresses(await getCryptoFactoryPoolData.call(this, 0, poolAddress));
Expand Down
1 change: 0 additions & 1 deletion src/factory/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const _deployStableNgPlainPool = async (
if (symbol.length > 10) throw Error("Max symbol length = 10");
if (coins.length < 1) throw Error("Invalid number of coins. Must be more than 1");
if (coins.length > 9) throw Error("Invalid number of coins. Must be less than 9");
if (BN(fee).lt(0.04)) throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
if (BN(fee).gt(1)) throw Error(`fee must be <= 1%. Passed fee = ${fee}`);

let _oracleAddresses: string[];
Expand Down
10 changes: 6 additions & 4 deletions src/factory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ export async function getBasePoolIds(this: ICurve, factoryAddress: string, rawSw
return basePoolIds;
}

async function getRecentlyCreatedPoolId(this: ICurve, swapAddress: string): Promise<string> {
const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
async function getRecentlyCreatedPoolId(this: ICurve, swapAddress: string, factoryAddress: string): Promise<string> {
const factoryContract = this.contracts[factoryAddress].contract;

const prefix = factoryAddress === this.constants.ALIASES.factory? 'factory-v2' : 'factory-stable-ng'

const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
for (let i = 1; i <= poolCount; i++) {
const address: string = await factoryContract.pool_list(poolCount - i);
if (address.toLowerCase() === swapAddress.toLowerCase()) return `factory-v2-${poolCount - i}`
if (address.toLowerCase() === swapAddress.toLowerCase()) return `${prefix}-${poolCount - i}`
}

throw Error("Unknown pool")
Expand Down Expand Up @@ -241,7 +243,7 @@ async function getCoinsData(

export async function getFactoryPoolData(this: ICurve, fromIdx = 0, swapAddress?: string, factoryAddress = curve.constants.ALIASES.factory): Promise<IDict<IPoolData>> {
const [rawPoolIds, rawSwapAddresses] = swapAddress ?
[[await getRecentlyCreatedPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
[[await getRecentlyCreatedPoolId.call(this, swapAddress, factoryAddress)], [swapAddress.toLowerCase()]]
: await getFactoryIdsAndSwapAddresses.call(this, fromIdx, factoryAddress);
if (rawPoolIds.length === 0) return {};

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const curve = {
deployMetaPool: deployStableNgMetaPool,
getDeployedPlainPoolAddress: getDeployedStablePlainPoolAddress,
getDeployedMetaPoolAddress: getDeployedStableMetaPoolAddress,
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedStableNgFactoryPool,
estimateGas: {
deployPlainPool: deployStableNgPlainPoolEstimateGas,
deployMetaPool: deployStableNgMetaPoolEstimateGas,
Expand Down

0 comments on commit ae8460a

Please sign in to comment.