@curvefi/api 2.68.26 → 2.68.27
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.d.ts +1 -0
- package/lib/curve.js +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/pools/poolConstructor.d.ts +1 -1
- package/lib/pools/poolConstructor.js +17 -2
- package/lib/utils.js +18 -5
- package/package.json +1 -1
package/lib/curve.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class Curve implements ICurve {
|
|
|
36
36
|
L1WeightedGasPrice?: number;
|
|
37
37
|
constants: INetworkConstants;
|
|
38
38
|
nativeTokenAddress: string;
|
|
39
|
+
poolAddressMapCache: IDict<string> | null;
|
|
39
40
|
constructor();
|
|
40
41
|
init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' | 'NoRPC', providerSettings: {
|
|
41
42
|
url?: string;
|
package/lib/curve.js
CHANGED
|
@@ -341,6 +341,7 @@ export class Curve {
|
|
|
341
341
|
this.constantOptions = { gasLimit: 12000000 };
|
|
342
342
|
this.options = {};
|
|
343
343
|
this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
|
|
344
|
+
this.poolAddressMapCache = null;
|
|
344
345
|
this.constants = {
|
|
345
346
|
NATIVE_TOKEN: NETWORK_CONSTANTS[1].NATIVE_COIN,
|
|
346
347
|
NETWORK_NAME: 'ethereum',
|
package/lib/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare const createCurve: () => {
|
|
|
40
40
|
}[][]>;
|
|
41
41
|
PoolTemplate: typeof PoolTemplate;
|
|
42
42
|
getBasePools: () => Promise<import("./interfaces.js").IBasePoolShortItem[]>;
|
|
43
|
-
getPool: (
|
|
43
|
+
getPool: (poolIdOrAddress: string) => PoolTemplate;
|
|
44
44
|
getUsdRate: (coin: string) => Promise<number>;
|
|
45
45
|
getGasPriceFromL1: () => Promise<number>;
|
|
46
46
|
getGasPriceFromL2: () => Promise<number>;
|
|
@@ -353,7 +353,7 @@ declare const _default: {
|
|
|
353
353
|
}[][]>;
|
|
354
354
|
PoolTemplate: typeof PoolTemplate;
|
|
355
355
|
getBasePools: () => Promise<import("./interfaces.js").IBasePoolShortItem[]>;
|
|
356
|
-
getPool: (
|
|
356
|
+
getPool: (poolIdOrAddress: string) => PoolTemplate;
|
|
357
357
|
getUsdRate: (coin: string) => Promise<number>;
|
|
358
358
|
getGasPriceFromL1: () => Promise<number>;
|
|
359
359
|
getGasPriceFromL2: () => Promise<number>;
|
|
@@ -14,9 +14,24 @@ import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpecte
|
|
|
14
14
|
import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin, } from "./mixins/withdrawOneCoinWrappedMixins.js";
|
|
15
15
|
import { swapCryptoMetaFactoryMixin, swapMetaFactoryMixin, swapMixin, swapTricrypto2Mixin } from "./mixins/swapMixins.js";
|
|
16
16
|
import { swapWrappedExpectedAndApproveMixin, swapWrappedMixin, swapWrappedRequiredMixin, swapWrappedTricrypto2Mixin, } from "./mixins/swapWrappedMixins.js";
|
|
17
|
-
import { findAbiSignature, getCountArgsOfMethodByAbi } from "../utils.js";
|
|
17
|
+
import { findAbiSignature, getCountArgsOfMethodByAbi, getPoolIdBySwapAddress } from "../utils.js";
|
|
18
18
|
import { StatsPool } from "./subClasses/statsPool.js";
|
|
19
|
-
export function getPool(
|
|
19
|
+
export function getPool(poolIdOrAddress) {
|
|
20
|
+
let poolId;
|
|
21
|
+
const _poolIdOrAddress = poolIdOrAddress.toLowerCase();
|
|
22
|
+
if (_poolIdOrAddress.startsWith('0x')) {
|
|
23
|
+
poolId = getPoolIdBySwapAddress.call(this, _poolIdOrAddress);
|
|
24
|
+
if (!poolId || !this.getPoolsData()[poolId]) {
|
|
25
|
+
throw new Error(`Pool with address ${_poolIdOrAddress} not found`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
poolId = _poolIdOrAddress;
|
|
30
|
+
const poolsData = this.getPoolsData();
|
|
31
|
+
if (!poolsData[poolId]) {
|
|
32
|
+
throw new Error(`Pool with id ${_poolIdOrAddress} not found`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
20
35
|
const poolDummy = new PoolTemplate(poolId, this);
|
|
21
36
|
class Pool extends PoolTemplate {
|
|
22
37
|
constructor(poolId, curve) {
|
package/lib/utils.js
CHANGED
|
@@ -291,11 +291,24 @@ export function populateApprove(coins_1, amounts_1, spender_1) {
|
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
export function getPoolIdBySwapAddress(swapAddress) {
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
var _a;
|
|
295
|
+
const _swapAddress = swapAddress.toLowerCase();
|
|
296
|
+
const buildCache = () => {
|
|
297
|
+
const poolsData = this.getPoolsData();
|
|
298
|
+
this.poolAddressMapCache = Object.entries(poolsData).reduce((acc, [poolId, poolData]) => {
|
|
299
|
+
acc[poolData.swap_address.toLowerCase()] = poolId;
|
|
300
|
+
return acc;
|
|
301
|
+
}, {});
|
|
302
|
+
};
|
|
303
|
+
if (this.poolAddressMapCache === null) {
|
|
304
|
+
buildCache();
|
|
305
|
+
}
|
|
306
|
+
if (this.poolAddressMapCache[_swapAddress]) {
|
|
307
|
+
return this.poolAddressMapCache[_swapAddress];
|
|
308
|
+
}
|
|
309
|
+
// Retry - cache update (if new pools were added through fetchFactoryPools and etc.)
|
|
310
|
+
buildCache();
|
|
311
|
+
return (_a = this.poolAddressMapCache[_swapAddress]) !== null && _a !== void 0 ? _a : "";
|
|
299
312
|
}
|
|
300
313
|
export function _getRewardsFromApi() {
|
|
301
314
|
return __awaiter(this, void 0, void 0, function* () {
|