@curvefi/api 2.57.1 → 2.57.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/curve.js CHANGED
@@ -54,8 +54,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
54
  }
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
- import { ethers, Contract, AbstractProvider } from "ethers";
58
- import { Provider as MulticallProvider, Contract as MulticallContract } from 'ethcall';
57
+ import { ethers, AbstractProvider, } from "ethers";
58
+ import { Provider as MulticallProvider } from 'ethcall';
59
59
  import { getFactoryPoolData } from "./factory/factory.js";
60
60
  import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
61
61
  import { getCryptoFactoryPoolData } from "./factory/factory-crypto.js";
@@ -111,6 +111,7 @@ import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./co
111
111
  import { _getAllGauges, _getHiddenPools } from "./external-api.js";
112
112
  import { L2Networks } from "./constants/L2Networks.js";
113
113
  import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto";
114
+ import { initContract, initMulticallContract } from "./utils.js";
114
115
  var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
115
116
  var gaugeData, isKilled, gaugeStatuses, poolId;
116
117
  return __generator(this, function (_a) {
@@ -1179,10 +1180,26 @@ var Curve = /** @class */ (function () {
1179
1180
  });
1180
1181
  };
1181
1182
  Curve.prototype.setContract = function (address, abi) {
1182
- this.contracts[address] = {
1183
- contract: new Contract(address, abi, this.signer || this.provider),
1184
- multicallContract: new MulticallContract(address, abi),
1183
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1184
+ var curveInstance = this;
1185
+ var proxyHandler = {
1186
+ get: function (target, name) {
1187
+ if (name === 'contract') {
1188
+ return initContract(target['address'], target['abi'], curveInstance.signer || curveInstance.provider);
1189
+ }
1190
+ else if (name === 'multicallContract') {
1191
+ return initMulticallContract(target['address'], target['abi']);
1192
+ }
1193
+ else {
1194
+ return target[name];
1195
+ }
1196
+ },
1197
+ };
1198
+ var coreContract = {
1199
+ address: address,
1200
+ abi: abi,
1185
1201
  };
1202
+ this.contracts[address] = new Proxy(coreContract, proxyHandler);
1186
1203
  };
1187
1204
  Curve.prototype._filterHiddenPools = function (pools) {
1188
1205
  return __awaiter(this, void 0, void 0, function () {
package/lib/index.d.ts CHANGED
@@ -38,7 +38,7 @@ declare const curve: {
38
38
  price: number;
39
39
  }[][]>;
40
40
  PoolTemplate: typeof PoolTemplate;
41
- getBasePools: () => import("./interfaces.js").IBasePoolShortItem[];
41
+ getBasePools: () => Promise<import("./interfaces.js").IBasePoolShortItem[]>;
42
42
  getPool: (poolId: string) => PoolTemplate;
43
43
  getUsdRate: (coin: string) => Promise<number>;
44
44
  getGasPriceFromL1: () => Promise<number>;
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Contract } from 'ethers';
1
+ import { BrowserProvider, Contract, JsonRpcProvider, Signer } from 'ethers';
2
+ import { Contract as MulticallContract } from "ethcall";
2
3
  import BigNumber from 'bignumber.js';
3
4
  import { IBasePoolShortItem, IChainId, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
4
5
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
@@ -64,4 +65,6 @@ export declare const isMethodExist: (contract: Contract, methodName: string) =>
64
65
  export declare const getPoolName: (name: string) => string;
65
66
  export declare const isStableNgPool: (name: string) => boolean;
66
67
  export declare const assetTypeNameHandler: (assetTypeName: string) => REFERENCE_ASSET;
67
- export declare const getBasePools: () => IBasePoolShortItem[];
68
+ export declare const getBasePools: () => Promise<IBasePoolShortItem[]>;
69
+ export declare const initContract: (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
70
+ export declare const initMulticallContract: (address: string, abi: any) => MulticallContract;
package/lib/utils.js CHANGED
@@ -970,15 +970,65 @@ export var assetTypeNameHandler = function (assetTypeName) {
970
970
  return assetTypeName.toUpperCase();
971
971
  }
972
972
  };
973
- export var getBasePools = function () {
974
- return Object.keys(curve.constants.BASE_POOLS).map(function (poolId) {
975
- var pool = getPool(poolId);
976
- return {
977
- id: poolId,
978
- name: pool.name,
979
- pool: pool.address,
980
- token: pool.lpToken,
981
- coins: pool.underlyingCoinAddresses,
982
- };
973
+ export var getBasePools = function () { return __awaiter(void 0, void 0, void 0, function () {
974
+ var factoryContract, factoryMulticallContract, basePoolCount, _a, _b, _c, calls, i, basePoolList, pools, basePoolIds;
975
+ return __generator(this, function (_d) {
976
+ switch (_d.label) {
977
+ case 0:
978
+ factoryContract = curve.contracts[curve.constants.ALIASES['stable_ng_factory']].contract;
979
+ factoryMulticallContract = curve.contracts[curve.constants.ALIASES['stable_ng_factory']].multicallContract;
980
+ _a = Number;
981
+ _c = (_b = curve).formatUnits;
982
+ return [4 /*yield*/, factoryContract.base_pool_count(curve.constantOptions)];
983
+ case 1:
984
+ basePoolCount = _a.apply(void 0, [_c.apply(_b, [_d.sent(), 0])]);
985
+ calls = [];
986
+ for (i = 0; i < basePoolCount; i++) {
987
+ calls.push(factoryMulticallContract.base_pool_list(i));
988
+ }
989
+ return [4 /*yield*/, curve.multicallProvider.all(calls)];
990
+ case 2:
991
+ basePoolList = (_d.sent()).map(function (item) { return item.toLowerCase(); });
992
+ pools = __assign(__assign(__assign({}, curve.constants.STABLE_NG_FACTORY_POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.POOLS_DATA);
993
+ basePoolIds = Object.keys(pools).filter(function (item) { return basePoolList.includes(pools[item].swap_address); });
994
+ return [2 /*return*/, basePoolIds.map(function (poolId) {
995
+ var pool = getPool(poolId);
996
+ return {
997
+ id: poolId,
998
+ name: pool.name,
999
+ pool: pool.address,
1000
+ token: pool.lpToken,
1001
+ coins: pool.underlyingCoinAddresses,
1002
+ };
1003
+ })];
1004
+ }
983
1005
  });
1006
+ }); };
1007
+ var memoizedContract = function () {
1008
+ var cache = {};
1009
+ return function (address, abi, provider) {
1010
+ if (address in cache) {
1011
+ return cache[address];
1012
+ }
1013
+ else {
1014
+ var result = new Contract(address, abi, provider);
1015
+ cache[address] = result;
1016
+ return result;
1017
+ }
1018
+ };
1019
+ };
1020
+ var memoizedulticallContract = function () {
1021
+ var cache = {};
1022
+ return function (address, abi) {
1023
+ if (address in cache) {
1024
+ return cache[address];
1025
+ }
1026
+ else {
1027
+ var result = new MulticallContract(address, abi);
1028
+ cache[address] = result;
1029
+ return result;
1030
+ }
1031
+ };
984
1032
  };
1033
+ export var initContract = memoizedContract();
1034
+ export var initMulticallContract = memoizedulticallContract();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.57.1",
3
+ "version": "2.57.3",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",