@curvefi/api 2.66.29 → 2.66.31
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/boosting.d.ts +33 -32
- package/lib/boosting.js +320 -252
- package/lib/cached.d.ts +4 -3
- package/lib/cached.js +63 -19
- package/lib/constants/utils.d.ts +14 -1
- package/lib/constants/utils.js +21 -6
- package/lib/curve.d.ts +5 -5
- package/lib/curve.js +21 -38
- package/lib/dao.d.ts +32 -31
- package/lib/dao.js +420 -350
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +2 -2
- package/lib/factory/common.d.ts +2 -1
- package/lib/factory/common.js +1 -1
- package/lib/factory/deploy.d.ts +46 -45
- package/lib/factory/deploy.js +630 -551
- package/lib/factory/factory-api.d.ts +3 -2
- package/lib/factory/factory-api.js +22 -23
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +12 -15
- package/lib/factory/factory-tricrypto.d.ts +1 -1
- package/lib/factory/factory-tricrypto.js +14 -15
- package/lib/factory/factory-twocrypto.d.ts +1 -1
- package/lib/factory/factory-twocrypto.js +12 -13
- package/lib/factory/factory.d.ts +4 -3
- package/lib/factory/factory.js +21 -24
- package/lib/index.d.ts +413 -104
- package/lib/index.js +253 -257
- package/lib/interfaces.d.ts +2 -0
- package/lib/pools/PoolTemplate.d.ts +13 -12
- package/lib/pools/PoolTemplate.js +279 -285
- package/lib/pools/mixins/common.js +2 -2
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
- package/lib/pools/mixins/depositMixins.d.ts +25 -5
- package/lib/pools/mixins/depositMixins.js +38 -76
- package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/depositWrappedMixins.js +17 -33
- package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
- package/lib/pools/mixins/poolBalancesMixin.js +3 -5
- package/lib/pools/mixins/swapMixins.d.ts +20 -4
- package/lib/pools/mixins/swapMixins.js +36 -70
- package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
- package/lib/pools/mixins/swapWrappedMixins.js +32 -60
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
- package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
- package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawMixins.js +33 -67
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
- package/lib/pools/poolConstructor.d.ts +2 -1
- package/lib/pools/poolConstructor.js +27 -28
- package/lib/pools/subClasses/corePool.d.ts +4 -1
- package/lib/pools/subClasses/corePool.js +5 -7
- package/lib/pools/subClasses/gaugePool.d.ts +5 -3
- package/lib/pools/subClasses/gaugePool.js +19 -18
- package/lib/pools/subClasses/statsPool.d.ts +2 -0
- package/lib/pools/subClasses/statsPool.js +22 -10
- package/lib/pools/subClasses/walletPool.d.ts +2 -1
- package/lib/pools/subClasses/walletPool.js +6 -6
- package/lib/pools/utils.d.ts +7 -6
- package/lib/pools/utils.js +316 -297
- package/lib/route-graph.worker.d.ts +2 -2
- package/lib/route-graph.worker.js +4 -6
- package/lib/router.d.ts +12 -11
- package/lib/router.js +331 -295
- package/lib/utils.d.ts +34 -33
- package/lib/utils.js +481 -435
- package/package.json +1 -1
package/lib/cached.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDict, IExtendedPoolDataFromApi, INetworkName, IPoolType } from "./interfaces.js";
|
|
2
2
|
export declare const _getPoolsFromApi: (network: INetworkName, poolType: IPoolType, isLiteChain?: boolean) => Promise<IExtendedPoolDataFromApi>;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
3
|
+
export declare const _setPoolsFromApi: (network: INetworkName, isLiteChain: boolean, data: Record<IPoolType, IExtendedPoolDataFromApi>) => void;
|
|
4
|
+
export declare const _getAllPoolsFromApi: (network: INetworkName, isLiteChain: boolean) => Promise<IExtendedPoolDataFromApi[]>;
|
|
5
|
+
export declare const _getUsdPricesFromApi: (network: INetworkName, isLiteChain: boolean) => Promise<IDict<number>>;
|
|
6
|
+
export declare const _getCrvApyFromApi: (network: INetworkName, isLiteChain: boolean) => Promise<IDict<[number, number]>>;
|
package/lib/cached.js
CHANGED
|
@@ -7,39 +7,83 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
11
|
-
import { uncached_getAllPoolsFromApi, createCrvApyDict, createUsdPricesDict } from './external-api.js';
|
|
12
|
-
import { curve } from "./curve";
|
|
10
|
+
import { createCrvApyDict, createUsdPricesDict, uncached_getAllPoolsFromApi } from './external-api.js';
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* Memoizes a function that returns a promise.
|
|
13
|
+
* Custom function instead of `memoizee` because we want to be able to set the cache manually based on server data.
|
|
14
|
+
* @param fn The function that returns a promise and will be memoized
|
|
15
|
+
* @param maxAge The maximum age of the cache in milliseconds
|
|
16
|
+
* @param createKey A function that creates a key for the cache based on the arguments passed to the function
|
|
17
|
+
* @returns A memoized `fn` function that includes a `set` method to set the cache manually
|
|
16
18
|
*/
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
+
const memoize = (fn, { maxAge, createKey = (list) => list.toString(), }) => {
|
|
20
|
+
const cache = {};
|
|
21
|
+
const timeouts = {};
|
|
22
|
+
const setCache = (key, promise) => {
|
|
23
|
+
if (promise) {
|
|
24
|
+
cache[key] = promise;
|
|
25
|
+
}
|
|
26
|
+
else if (key in cache) {
|
|
27
|
+
delete cache[key];
|
|
28
|
+
}
|
|
29
|
+
if (key in timeouts) {
|
|
30
|
+
clearTimeout(timeouts[key]);
|
|
31
|
+
delete timeouts[key];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const scheduleCleanup = (key) => timeouts[key] = setTimeout(() => {
|
|
35
|
+
delete timeouts[key];
|
|
36
|
+
delete cache[key];
|
|
37
|
+
}, maxAge);
|
|
38
|
+
const cachedFn = (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const key = createKey(args);
|
|
40
|
+
if (key in cache) {
|
|
41
|
+
return cache[key];
|
|
42
|
+
}
|
|
43
|
+
const promise = fn(...args);
|
|
44
|
+
setCache(key, promise);
|
|
45
|
+
try {
|
|
46
|
+
const result = yield promise;
|
|
47
|
+
scheduleCleanup(key);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
delete cache[key];
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
cachedFn.set = (result, ...args) => {
|
|
56
|
+
const key = createKey(args);
|
|
57
|
+
setCache(key, Promise.resolve(result));
|
|
58
|
+
scheduleCleanup(key);
|
|
59
|
+
};
|
|
60
|
+
return cachedFn;
|
|
61
|
+
};
|
|
62
|
+
const createCache = (poolsDict) => {
|
|
19
63
|
const poolLists = Object.values(poolsDict);
|
|
20
64
|
const usdPrices = createUsdPricesDict(poolLists);
|
|
21
65
|
const crvApy = createCrvApyDict(poolLists);
|
|
22
66
|
return { poolsDict, poolLists, usdPrices, crvApy };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* This function is used to cache the data fetched from the API and the data derived from it.
|
|
70
|
+
* Note: do not expose this function to the outside world, instead encapsulate it in a function that returns the data you need.
|
|
71
|
+
*/
|
|
72
|
+
const _getCachedData = memoize((network, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () { return createCache(yield uncached_getAllPoolsFromApi(network, isLiteChain)); }), { maxAge: 1000 * 60 * 5 /* 5 minutes */ });
|
|
28
73
|
export const _getPoolsFromApi = (network_1, poolType_1, ...args_1) => __awaiter(void 0, [network_1, poolType_1, ...args_1], void 0, function* (network, poolType, isLiteChain = false) {
|
|
29
74
|
const { poolsDict } = yield _getCachedData(network, isLiteChain);
|
|
30
75
|
return poolsDict[poolType];
|
|
31
76
|
});
|
|
32
|
-
export const
|
|
77
|
+
export const _setPoolsFromApi = (network, isLiteChain, data) => _getCachedData.set(createCache(data), network, isLiteChain);
|
|
78
|
+
export const _getAllPoolsFromApi = (network, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
79
|
const { poolLists } = yield _getCachedData(network, isLiteChain);
|
|
34
80
|
return poolLists;
|
|
35
81
|
});
|
|
36
|
-
export const _getUsdPricesFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
const
|
|
38
|
-
const { usdPrices } = yield _getCachedData(network, false);
|
|
82
|
+
export const _getUsdPricesFromApi = (network, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const { usdPrices } = yield _getCachedData(network, isLiteChain);
|
|
39
84
|
return usdPrices;
|
|
40
85
|
});
|
|
41
|
-
export const _getCrvApyFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const
|
|
43
|
-
const { crvApy } = yield _getCachedData(network, false);
|
|
86
|
+
export const _getCrvApyFromApi = (network, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const { crvApy } = yield _getCachedData(network, isLiteChain);
|
|
44
88
|
return crvApy;
|
|
45
89
|
});
|
package/lib/constants/utils.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { IDict, IPoolData } from "../interfaces.js";
|
|
2
|
+
import { BigNumberish, Numeric } from "ethers";
|
|
3
|
+
import { Curve } from "../curve";
|
|
4
|
+
export declare const formatUnits: (value: BigNumberish, unit?: string | Numeric) => string;
|
|
5
|
+
export declare const parseUnits: (value: string, unit?: string | Numeric) => bigint;
|
|
2
6
|
export declare const lowerCasePoolDataAddresses: (poolsData: IDict<IPoolData>) => IDict<IPoolData>;
|
|
3
7
|
export declare const extractDecimals: (poolsData: IDict<IPoolData>) => IDict<number>;
|
|
4
|
-
export declare
|
|
8
|
+
export declare function extractGauges(this: Curve, poolsData: IDict<IPoolData>): string[];
|
|
5
9
|
export declare const lowerCaseValues: (dict: IDict<string>) => IDict<string>;
|
|
6
10
|
export declare const lowerCaseKeys: (dict: IDict<any>) => IDict<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Memoizes a method of an object by binding it to this when needed.
|
|
13
|
+
* The memoized method will cache the result for 5 minutes.
|
|
14
|
+
* @param obj The object to which the method belongs.
|
|
15
|
+
* @param name The name of the method to memoize. It must be unique within the object.
|
|
16
|
+
* @param method The method to memoize. It must be a function that returns a Promise.
|
|
17
|
+
* @returns The memoized method.
|
|
18
|
+
*/
|
|
19
|
+
export declare const memoizeMethod: <Obj extends object, Method extends (this: Obj, ...params: any[]) => Promise<unknown>>(obj: Obj, name: string, method: Method) => Method;
|
package/lib/constants/utils.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import memoize from "memoizee";
|
|
3
|
+
export const formatUnits = (value, unit) => ethers.formatUnits(value, unit);
|
|
4
|
+
export const parseUnits = (value, unit) => ethers.parseUnits(value, unit);
|
|
2
5
|
export const lowerCasePoolDataAddresses = (poolsData) => {
|
|
3
6
|
for (const poolId in poolsData) {
|
|
4
7
|
if (!Object.prototype.hasOwnProperty.call(poolsData, poolId))
|
|
@@ -37,20 +40,32 @@ export const extractDecimals = (poolsData) => {
|
|
|
37
40
|
}
|
|
38
41
|
return DECIMALS;
|
|
39
42
|
};
|
|
40
|
-
export
|
|
43
|
+
export function extractGauges(poolsData) {
|
|
41
44
|
const GAUGES = [];
|
|
42
45
|
for (const poolData of Object.values(poolsData)) {
|
|
43
|
-
if (poolData.gauge_address ===
|
|
46
|
+
if (poolData.gauge_address === this.constants.ZERO_ADDRESS)
|
|
44
47
|
continue;
|
|
45
48
|
GAUGES.push(poolData.gauge_address);
|
|
46
49
|
}
|
|
47
50
|
return GAUGES;
|
|
48
|
-
}
|
|
51
|
+
}
|
|
49
52
|
export const lowerCaseValues = (dict) => {
|
|
50
|
-
// @ts-ignore
|
|
51
53
|
return Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()]));
|
|
52
54
|
};
|
|
53
55
|
export const lowerCaseKeys = (dict) => {
|
|
54
|
-
// @ts-ignore
|
|
55
56
|
return Object.fromEntries(Object.entries(dict).map((entry) => [entry[0].toLowerCase(), entry[1]]));
|
|
56
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Memoizes a method of an object by binding it to this when needed.
|
|
60
|
+
* The memoized method will cache the result for 5 minutes.
|
|
61
|
+
* @param obj The object to which the method belongs.
|
|
62
|
+
* @param name The name of the method to memoize. It must be unique within the object.
|
|
63
|
+
* @param method The method to memoize. It must be a function that returns a Promise.
|
|
64
|
+
* @returns The memoized method.
|
|
65
|
+
*/
|
|
66
|
+
export const memoizeMethod = (obj, name, method) => {
|
|
67
|
+
if (!(name in obj)) {
|
|
68
|
+
obj[name] = memoize(method.bind(obj), { promise: true, maxAge: 5 * 60 * 1000 /* 5m */ });
|
|
69
|
+
}
|
|
70
|
+
return obj[name];
|
|
71
|
+
};
|
package/lib/curve.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { IPoolData, IDict, ICurve, IChainId, IFactoryPoolType, Abi, INetworkConstants } from "./interfaces";
|
|
1
|
+
import { BigNumberish, BrowserProvider, Contract, ethers, JsonRpcProvider, Networkish, Numeric, Signer } from "ethers";
|
|
2
|
+
import { Contract as MulticallContract, Provider as MulticallProvider } from "@curvefi/ethcall";
|
|
3
|
+
import { IPoolData, IDict, ICurve, IChainId, IFactoryPoolType, Abi, INetworkConstants, IPoolType, IExtendedPoolDataFromApi } from "./interfaces";
|
|
4
4
|
export declare const OLD_CHAINS: number[];
|
|
5
5
|
export declare const memoizedContract: () => (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
|
|
6
6
|
export declare const memoizedMulticallContract: () => (address: string, abi: any) => MulticallContract;
|
|
@@ -9,7 +9,7 @@ export type ContractItem = {
|
|
|
9
9
|
multicallContract: MulticallContract;
|
|
10
10
|
abi: Abi;
|
|
11
11
|
};
|
|
12
|
-
declare class Curve implements ICurve {
|
|
12
|
+
export declare class Curve implements ICurve {
|
|
13
13
|
provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
|
|
14
14
|
isNoRPC: boolean;
|
|
15
15
|
multicallProvider: MulticallProvider;
|
|
@@ -50,6 +50,7 @@ declare class Curve implements ICurve {
|
|
|
50
50
|
maxFeePerGas?: number;
|
|
51
51
|
maxPriorityFeePerGas?: number;
|
|
52
52
|
chainId?: number;
|
|
53
|
+
poolsData?: Record<IPoolType, IExtendedPoolDataFromApi>;
|
|
53
54
|
}): Promise<void>;
|
|
54
55
|
initContract: (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
|
|
55
56
|
initMulticallContract: (address: string, abi: any) => MulticallContract;
|
|
@@ -96,4 +97,3 @@ declare class Curve implements ICurve {
|
|
|
96
97
|
getIsLiteChain: () => boolean;
|
|
97
98
|
}
|
|
98
99
|
export declare const curve: Curve;
|
|
99
|
-
export {};
|
package/lib/curve.js
CHANGED
|
@@ -7,10 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { AbstractProvider, Contract, ethers, } from "ethers";
|
|
11
|
+
import { Contract as MulticallContract, Provider as MulticallProvider } from "@curvefi/ethcall";
|
|
12
12
|
import { NETWORK_CONSTANTS } from "./constants/network_constants.js";
|
|
13
|
-
import {
|
|
13
|
+
import { CRYPTO_FACTORY_CONSTANTS, STABLE_FACTORY_CONSTANTS } from "./constants/factory/index.js";
|
|
14
14
|
import { getFactoryPoolData } from "./factory/factory.js";
|
|
15
15
|
import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
|
|
16
16
|
import { getCryptoFactoryPoolData } from "./factory/factory-crypto.js";
|
|
@@ -47,12 +47,13 @@ import gasOracleABI from './constants/abis/gas_oracle_optimism.json' with { type
|
|
|
47
47
|
import gasOracleBlobABI from './constants/abis/gas_oracle_optimism_blob.json' with { type: 'json' };
|
|
48
48
|
import votingProposalABI from './constants/abis/voting_proposal.json' with { type: 'json' };
|
|
49
49
|
import circulatingSupplyABI from './constants/abis/circulating_supply.json' with { type: 'json' };
|
|
50
|
-
import rootGaugeFactoryABI from "./constants/abis/gauge_factory/root_gauge_factory.json" with { type:
|
|
51
|
-
import { lowerCasePoolDataAddresses,
|
|
50
|
+
import rootGaugeFactoryABI from "./constants/abis/gauge_factory/root_gauge_factory.json" with { type: "json" };
|
|
51
|
+
import { extractDecimals, extractGauges, formatUnits, lowerCasePoolDataAddresses, parseUnits, } from "./constants/utils.js";
|
|
52
52
|
import { _getHiddenPools } from "./external-api.js";
|
|
53
53
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
54
54
|
import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
|
|
55
55
|
import { getNetworkConstants } from "./utils.js";
|
|
56
|
+
import { _setPoolsFromApi } from "./cached";
|
|
56
57
|
export const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
|
|
57
58
|
export const memoizedContract = () => {
|
|
58
59
|
const cache = {};
|
|
@@ -80,7 +81,7 @@ export const memoizedMulticallContract = () => {
|
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
};
|
|
83
|
-
class Curve {
|
|
84
|
+
export class Curve {
|
|
84
85
|
constructor() {
|
|
85
86
|
this.initContract = memoizedContract();
|
|
86
87
|
this.initMulticallContract = memoizedMulticallContract();
|
|
@@ -322,15 +323,12 @@ class Curve {
|
|
|
322
323
|
this.getIsLiteChain = () => {
|
|
323
324
|
return this.isLiteChain;
|
|
324
325
|
};
|
|
325
|
-
// @ts-ignore
|
|
326
326
|
this.provider = null;
|
|
327
|
-
// @ts-ignore
|
|
328
327
|
this.signer = null;
|
|
329
328
|
this.isNoRPC = false;
|
|
330
329
|
this.signerAddress = '';
|
|
331
330
|
this.chainId = 1;
|
|
332
331
|
this.isLiteChain = false;
|
|
333
|
-
// @ts-ignore
|
|
334
332
|
this.multicallProvider = null;
|
|
335
333
|
this.contracts = {};
|
|
336
334
|
this.feeData = {};
|
|
@@ -363,14 +361,11 @@ class Curve {
|
|
|
363
361
|
return __awaiter(this, arguments, void 0, function* (providerType, providerSettings, options = {} // gasPrice in Gwei
|
|
364
362
|
) {
|
|
365
363
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
366
|
-
// @ts-ignore
|
|
367
364
|
this.provider = null;
|
|
368
|
-
// @ts-ignore
|
|
369
365
|
this.signer = null;
|
|
370
366
|
this.isNoRPC = false;
|
|
371
367
|
this.signerAddress = '';
|
|
372
368
|
this.chainId = 1;
|
|
373
|
-
// @ts-ignore
|
|
374
369
|
this.multicallProvider = null;
|
|
375
370
|
this.contracts = {};
|
|
376
371
|
this.feeData = {};
|
|
@@ -422,7 +417,7 @@ class Curve {
|
|
|
422
417
|
try {
|
|
423
418
|
this.signer = yield this.provider.getSigner();
|
|
424
419
|
}
|
|
425
|
-
catch (
|
|
420
|
+
catch (_l) {
|
|
426
421
|
this.signer = null;
|
|
427
422
|
}
|
|
428
423
|
}
|
|
@@ -459,7 +454,7 @@ class Curve {
|
|
|
459
454
|
console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
|
|
460
455
|
this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
|
|
461
456
|
this.isLiteChain = !(this.chainId in NETWORK_CONSTANTS);
|
|
462
|
-
const network_constants = yield getNetworkConstants(this.chainId);
|
|
457
|
+
const network_constants = yield getNetworkConstants.call(this, this.chainId);
|
|
463
458
|
this.constants.NATIVE_TOKEN = network_constants.NATIVE_COIN;
|
|
464
459
|
this.constants.NETWORK_NAME = network_constants.NAME;
|
|
465
460
|
this.constants.ALIASES = network_constants.ALIASES;
|
|
@@ -473,7 +468,7 @@ class Curve {
|
|
|
473
468
|
this.constants.DECIMALS = extractDecimals(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA));
|
|
474
469
|
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
|
|
475
470
|
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
|
|
476
|
-
this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
|
|
471
|
+
this.constants.GAUGES = extractGauges.call(this, this.constants.POOLS_DATA);
|
|
477
472
|
if (this.isLiteChain) {
|
|
478
473
|
this.constants.API_CONSTANTS = network_constants.API_CONSTANTS;
|
|
479
474
|
}
|
|
@@ -499,7 +494,7 @@ class Curve {
|
|
|
499
494
|
try {
|
|
500
495
|
this.signerAddress = yield this.signer.getAddress();
|
|
501
496
|
}
|
|
502
|
-
catch (
|
|
497
|
+
catch (_m) {
|
|
503
498
|
this.signer = null;
|
|
504
499
|
}
|
|
505
500
|
}
|
|
@@ -507,6 +502,9 @@ class Curve {
|
|
|
507
502
|
this.signerAddress = '';
|
|
508
503
|
}
|
|
509
504
|
this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
|
|
505
|
+
if (options.poolsData) {
|
|
506
|
+
_setPoolsFromApi(this.constants.NETWORK_NAME, this.isLiteChain, options.poolsData);
|
|
507
|
+
}
|
|
510
508
|
yield this.updateFeeData();
|
|
511
509
|
for (const pool of Object.values(Object.assign(Object.assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA))) {
|
|
512
510
|
this.setContract(pool.swap_address, pool.swap_abi);
|
|
@@ -619,25 +617,15 @@ class Curve {
|
|
|
619
617
|
const curveInstance = this;
|
|
620
618
|
curveInstance.setContract(curveInstance.constants.ALIASES.gas_oracle, gasOracleABI);
|
|
621
619
|
curveInstance.setContract(curveInstance.constants.ALIASES.gas_oracle_blob, gasOracleBlobABI);
|
|
622
|
-
|
|
623
|
-
if (AbstractProvider.prototype.originalEstimate) {
|
|
624
|
-
// @ts-ignore
|
|
620
|
+
if ('originalEstimate' in AbstractProvider.prototype) {
|
|
625
621
|
AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
|
|
626
622
|
}
|
|
627
623
|
const originalEstimate = AbstractProvider.prototype.estimateGas;
|
|
628
|
-
const oldEstimate =
|
|
629
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
630
|
-
// @ts-ignore
|
|
631
|
-
const originalEstimateFunc = originalEstimate.bind(this);
|
|
632
|
-
const gas = yield originalEstimateFunc(arg);
|
|
633
|
-
return gas;
|
|
634
|
-
});
|
|
635
|
-
};
|
|
624
|
+
const oldEstimate = originalEstimate.bind(this);
|
|
636
625
|
//Override
|
|
637
626
|
const newEstimate = function (arg) {
|
|
638
627
|
return __awaiter(this, void 0, void 0, function* () {
|
|
639
|
-
|
|
640
|
-
const L2EstimateGas = originalEstimate.bind(this);
|
|
628
|
+
const L2EstimateGas = oldEstimate;
|
|
641
629
|
const L1GasUsed = yield curveInstance.contracts[curveInstance.constants.ALIASES.gas_oracle_blob].contract.getL1GasUsed(arg.data);
|
|
642
630
|
const L1Fee = yield curveInstance.contracts[curveInstance.constants.ALIASES.gas_oracle_blob].contract.getL1Fee(arg.data);
|
|
643
631
|
curveInstance.L1WeightedGasPrice = Number(L1Fee) / Number(L1GasUsed);
|
|
@@ -645,15 +633,11 @@ class Curve {
|
|
|
645
633
|
return [L2GasUsed, L1GasUsed];
|
|
646
634
|
});
|
|
647
635
|
};
|
|
648
|
-
// @ts-ignore
|
|
649
636
|
AbstractProvider.prototype.estimateGas = newEstimate;
|
|
650
|
-
// @ts-ignore
|
|
651
637
|
AbstractProvider.prototype.originalEstimate = oldEstimate;
|
|
652
638
|
}
|
|
653
639
|
else {
|
|
654
|
-
|
|
655
|
-
if (AbstractProvider.prototype.originalEstimate) {
|
|
656
|
-
// @ts-ignore
|
|
640
|
+
if ('originalEstimate' in AbstractProvider.prototype) {
|
|
657
641
|
AbstractProvider.prototype.estimateGas = AbstractProvider.prototype.originalEstimate;
|
|
658
642
|
}
|
|
659
643
|
}
|
|
@@ -686,22 +670,21 @@ class Curve {
|
|
|
686
670
|
_filterHiddenPools(pools) {
|
|
687
671
|
return __awaiter(this, void 0, void 0, function* () {
|
|
688
672
|
const hiddenPools = (yield _getHiddenPools())[this.constants.NETWORK_NAME] || [];
|
|
689
|
-
// @ts-ignore
|
|
690
673
|
return Object.fromEntries(Object.entries(pools).filter(([id]) => !hiddenPools.includes(id)));
|
|
691
674
|
});
|
|
692
675
|
}
|
|
693
676
|
_updateDecimalsAndGauges(pools) {
|
|
694
677
|
this.constants.DECIMALS = Object.assign(Object.assign({}, this.constants.DECIMALS), extractDecimals(pools));
|
|
695
|
-
this.constants.GAUGES = [...this.constants.GAUGES, ...extractGauges(pools)];
|
|
678
|
+
this.constants.GAUGES = [...this.constants.GAUGES, ...extractGauges.call(this, pools)];
|
|
696
679
|
}
|
|
697
680
|
setCustomFeeData(customFeeData) {
|
|
698
681
|
this.feeData = Object.assign(Object.assign({}, this.feeData), customFeeData);
|
|
699
682
|
}
|
|
700
683
|
formatUnits(value, unit) {
|
|
701
|
-
return
|
|
684
|
+
return formatUnits(value, unit);
|
|
702
685
|
}
|
|
703
686
|
parseUnits(value, unit) {
|
|
704
|
-
return
|
|
687
|
+
return parseUnits(value, unit);
|
|
705
688
|
}
|
|
706
689
|
updateFeeData() {
|
|
707
690
|
return __awaiter(this, void 0, void 0, function* () {
|
package/lib/dao.d.ts
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { type Curve } from "./curve.js";
|
|
2
|
+
import { IDaoProposal, IDaoProposalListItem, IDaoProposalUserListItem, IGaugeUserVote, IVotingGauge, TVoteType } from './interfaces';
|
|
3
|
+
export declare function crvSupplyStats(this: Curve): Promise<{
|
|
3
4
|
circulating: string;
|
|
4
5
|
locked: string;
|
|
5
6
|
total: string;
|
|
6
7
|
veCrv: string;
|
|
7
8
|
averageLockTime: string;
|
|
8
9
|
}>;
|
|
9
|
-
export declare
|
|
10
|
-
export declare
|
|
10
|
+
export declare function userCrv(this: Curve, address?: string): Promise<string>;
|
|
11
|
+
export declare function userVeCrv(this: Curve, address?: string): Promise<{
|
|
11
12
|
veCrv: string;
|
|
12
13
|
veCrvPct: string;
|
|
13
14
|
lockedCrv: string;
|
|
14
15
|
unlockTime: number;
|
|
15
16
|
}>;
|
|
16
|
-
export declare
|
|
17
|
-
export declare
|
|
18
|
-
export declare
|
|
17
|
+
export declare function crvLockIsApproved(this: Curve, amount: number | string): Promise<boolean>;
|
|
18
|
+
export declare function crvLockApproveEstimateGas(this: Curve, amount: number | string): Promise<number | number[]>;
|
|
19
|
+
export declare function crvLockApprove(this: Curve, amount: number | string): Promise<string[]>;
|
|
19
20
|
export declare const calcCrvUnlockTime: (days: number | string, start?: number | string) => number;
|
|
20
|
-
export declare
|
|
21
|
-
export declare
|
|
22
|
-
export declare
|
|
23
|
-
export declare
|
|
24
|
-
export declare
|
|
25
|
-
export declare
|
|
26
|
-
export declare
|
|
27
|
-
export declare
|
|
28
|
-
export declare
|
|
29
|
-
export declare
|
|
30
|
-
export declare
|
|
31
|
-
export declare
|
|
32
|
-
export declare
|
|
21
|
+
export declare function createCrvLockEstimateGas(this: Curve, amount: number | string, days: number | string): Promise<number | number[]>;
|
|
22
|
+
export declare function createCrvLock(this: Curve, amount: number | string, days: number | string): Promise<string>;
|
|
23
|
+
export declare function increaseCrvLockedAmountEstimateGas(this: Curve, amount: number | string): Promise<number | number[]>;
|
|
24
|
+
export declare function increaseCrvLockedAmount(this: Curve, amount: number | string): Promise<string>;
|
|
25
|
+
export declare function increaseCrvUnlockTimeEstimateGas(this: Curve, days: number | string): Promise<number | number[]>;
|
|
26
|
+
export declare function increaseCrvUnlockTime(this: Curve, days: number | string): Promise<string>;
|
|
27
|
+
export declare function withdrawLockedCrvEstimateGas(this: Curve): Promise<number | number[]>;
|
|
28
|
+
export declare function withdrawLockedCrv(this: Curve): Promise<string>;
|
|
29
|
+
export declare function claimableFees(this: Curve, address?: string): Promise<string>;
|
|
30
|
+
export declare function claimFeesEstimateGas(this: Curve, address?: string): Promise<number | number[]>;
|
|
31
|
+
export declare function claimFees(this: Curve, address?: string): Promise<string>;
|
|
32
|
+
export declare function getVotingGaugeList(this: Curve): Promise<IVotingGauge[]>;
|
|
33
|
+
export declare function userGaugeVotes(this: Curve, address?: string): Promise<{
|
|
33
34
|
gauges: IGaugeUserVote[];
|
|
34
35
|
powerUsed: string;
|
|
35
36
|
veCrvUsed: string;
|
|
36
37
|
}>;
|
|
37
|
-
export declare
|
|
38
|
-
export declare
|
|
39
|
-
export declare
|
|
40
|
-
export declare
|
|
41
|
-
export declare
|
|
42
|
-
export declare
|
|
43
|
-
export declare
|
|
44
|
-
export declare
|
|
45
|
-
export declare
|
|
46
|
-
export declare
|
|
47
|
-
export declare
|
|
38
|
+
export declare function voteForGaugeNextTime(this: Curve, gauge: string): Promise<number>;
|
|
39
|
+
export declare function voteForGaugeEstimateGas(this: Curve, gauge: string, power: number | string): Promise<number | number[]>;
|
|
40
|
+
export declare function voteForGauge(this: Curve, gauge: string, power: number | string): Promise<string>;
|
|
41
|
+
export declare function getProposalList(this: Curve): Promise<IDaoProposalListItem[]>;
|
|
42
|
+
export declare function getProposal(this: Curve, type: "PARAMETER" | "OWNERSHIP", id: number): Promise<IDaoProposal>;
|
|
43
|
+
export declare function userProposalVotes(this: Curve, address?: string): Promise<IDaoProposalUserListItem[]>;
|
|
44
|
+
export declare function voteForProposalEstimateGas(this: Curve, type: TVoteType, id: number, support: boolean): Promise<number | number[]>;
|
|
45
|
+
export declare function voteForProposal(this: Curve, type: TVoteType, id: number, support: boolean): Promise<string>;
|
|
46
|
+
export declare function executeVoteEstimateGas(this: Curve, type: TVoteType, id: number): Promise<number | number[]>;
|
|
47
|
+
export declare function executeVote(this: Curve, type: TVoteType, id: number): Promise<string>;
|
|
48
|
+
export declare function isCanVoteExecute(this: Curve, type: TVoteType, id: number): Promise<boolean>;
|