Skip to content

Commit

Permalink
Merge pull request #227 from curvefi/feat/add-stable-ng-factory
Browse files Browse the repository at this point in the history
fix: fixed totalLiquidity and ABI for factory-stable-ng
  • Loading branch information
fedorovdg authored Nov 13, 2023
2 parents 9ad53ed + ded463d commit 990287d
Show file tree
Hide file tree
Showing 8 changed files with 2,344 additions and 12 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.51.0",
"version": "2.51.1",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
997 changes: 996 additions & 1 deletion src/constants/abis/factory-stable-ng.json

Large diffs are not rendered by default.

1,332 changes: 1,331 additions & 1 deletion src/constants/abis/factory-stable-ng/plain-stableswap-ng.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class Curve implements ICurve {
} else {
this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.stable_ng_factory));
}
console.log(this.constants.STABLE_NG_FACTORY_POOLS_DATA)

this.constants.STABLE_NG_FACTORY_POOLS_DATA = await this._filterHiddenPools(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
this._updateDecimalsAndGauges(this.constants.STABLE_NG_FACTORY_POOLS_DATA);

Expand Down
6 changes: 3 additions & 3 deletions src/factory/factory-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FACTORY_CONSTANTS } from "./constants.js";
import { CRYPTO_FACTORY_CONSTANTS } from "./constants-crypto.js";
import { setFactoryZapContracts } from "./common.js";
import { _getPoolsFromApi } from "../external-api.js";
import { getPoolName } from "../utils.js";
import { assetTypeNameHandler, getPoolName } from "../utils.js";

export const lowerCasePoolDataAddresses = (poolsData: IPoolDataFromApi[]): IPoolDataFromApi[] => {
for (const poolData of poolsData) {
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
name: getPoolName(pool.name),
full_name: pool.name,
symbol: pool.symbol,
reference_asset: pool.assetTypeName.toUpperCase() as REFERENCE_ASSET,
reference_asset: assetTypeNameHandler(pool.assetTypeName),
swap_address: pool.address,
token_address: pool.address,
gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
Expand All @@ -211,7 +211,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
name: getPoolName(pool.name),
full_name: pool.name,
symbol: pool.symbol,
reference_asset: pool.assetTypeName.toUpperCase() as REFERENCE_ASSET,
reference_asset: assetTypeNameHandler(pool.assetTypeName),
swap_address: pool.address,
token_address: pool.address,
gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
Expand Down
5 changes: 2 additions & 3 deletions src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,8 @@ export class PoolTemplate {
const network = curve.constants.NETWORK_NAME;
let poolType = this.isCrypto ? "crypto" : "main";
if (this.id.startsWith("factory")) {
poolType = "factory";
const factoryType = this.id.split("-")[1];
if (factoryType !== "v2") poolType += "-" + factoryType;
poolType = this.id.replace(/-\d+$/, '');
poolType = poolType.replace(/-v2$/, '');
}
const poolsData = (await _getPoolsFromApi(network, poolType as IPoolType)).poolData;

Expand Down
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { Contract } from 'ethers';
import { Contract as MulticallContract } from "ethcall";
import BigNumber from 'bignumber.js';
import { IChainId, IDict, INetworkName, IRewardFromApi } from './interfaces';
import {IChainId, IDict, INetworkName, IRewardFromApi, REFERENCE_ASSET} from './interfaces';
import { curve, NETWORK_CONSTANTS } from "./curve.js";
import { _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes, _getAllPoolsFromApi, _getSubgraphData } from "./external-api.js";
import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
Expand Down Expand Up @@ -655,4 +655,12 @@ export const getPoolName = (name: string): string => {
} else {
return separatedName[0].trim()
}
}

export const assetTypeNameHandler = (assetTypeName: string): REFERENCE_ASSET => {
if (assetTypeName.toUpperCase() === 'UNKNOWN') {
return 'OTHER';
} else {
return assetTypeName.toUpperCase() as REFERENCE_ASSET;
}
}
2 changes: 1 addition & 1 deletion test/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const FACTORY_POOLS_COUNT_POLYGON = 263;
const MAIN_POOLS_AVALANCHE = [ 'aave', 'ren', 'atricrypto'];
const FACTORY_POOLS_COUNT_AVALANCHE = 81;

const MAIN_POOLS_FANTOM = ['2pool', 'fusdt', 'ren', 'tricrypto', 'ib', 'geist'];;
const MAIN_POOLS_FANTOM = ['2pool', 'fusdt', 'ren', 'tricrypto', 'ib', 'geist'];
const FACTORY_POOLS_COUNT_FANTOM = 110;
const CRYPTO_FACTORY_POOLS_COUNT_FANTOM = 6;

Expand Down

0 comments on commit 990287d

Please sign in to comment.