@curvefi/api 2.66.30 → 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
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { curve } from "../curve.js";
|
|
2
1
|
import { PoolTemplate } from "./PoolTemplate.js";
|
|
3
|
-
import {
|
|
4
|
-
import { depositBalancedAmountsMixin,
|
|
5
|
-
import {
|
|
2
|
+
import { poolBalancesLendingMixin, poolBalancesMetaMixin } from "./mixins/poolBalancesMixin.js";
|
|
3
|
+
import { depositBalancedAmountsCryptoMixin, depositBalancedAmountsMixin, depositWrappedBalancedAmountsCryptoMixin, depositWrappedBalancedAmountsMixin, } from "./mixins/depositBalancedAmountsMixins.js";
|
|
4
|
+
import { depositCryptoMetaFactoryMixin, depositLendingOrCryptoMixin, depositMetaFactoryMixin, depositPlainMixin, depositZapMixin, } from "./mixins/depositMixins.js";
|
|
6
5
|
import { depositWrapped2argsMixin, depositWrapped3argsMixin } from "./mixins/depositWrappedMixins.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { withdrawExpectedLendingOrCryptoMixin, withdrawExpectedMetaMixin, withdrawExpectedMixin, withdrawWrappedExpectedMixin, } from "./mixins/withdrawExpectedMixins.js";
|
|
7
|
+
import { withdrawCryptoMetaFactoryMixin, withdrawLendingOrCryptoMixin, withdrawMetaFactoryMixin, withdrawPlainMixin, withdrawZapMixin, } from "./mixins/withdrawMixins.js";
|
|
9
8
|
import { withdrawWrapped2argsMixin, withdrawWrapped3argsMixin } from "./mixins/withdrawWrappedMixins.js";
|
|
10
|
-
import { withdrawImbalanceMetaFactoryMixin,
|
|
11
|
-
import { withdrawImbalanceWrapped2argsMixin, withdrawImbalanceWrapped3argsMixin } from "./mixins/withdrawImbalanceWrappedMixins.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpected3argsMixin } from "./mixins/withdrawOneCoinWrappedExpectedMixins.js";
|
|
15
|
-
import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin } from "./mixins/withdrawOneCoinWrappedMixins.js";
|
|
16
|
-
import {
|
|
17
|
-
import { swapWrappedExpectedAndApproveMixin,
|
|
18
|
-
import {
|
|
9
|
+
import { withdrawImbalanceLendingMixin, withdrawImbalanceMetaFactoryMixin, withdrawImbalancePlainMixin, withdrawImbalanceZapMixin, } from "./mixins/withdrawImbalanceMixins.js";
|
|
10
|
+
import { withdrawImbalanceWrapped2argsMixin, withdrawImbalanceWrapped3argsMixin, } from "./mixins/withdrawImbalanceWrappedMixins.js";
|
|
11
|
+
import { withdrawOneCoinExpected2argsMixin, withdrawOneCoinExpected3argsMixin, withdrawOneCoinExpectedMetaFactoryMixin, withdrawOneCoinExpectedZapMixin, } from "./mixins/withdrawOneCoinExpectedMixins.js";
|
|
12
|
+
import { withdrawOneCoinCryptoMetaFactoryMixin, withdrawOneCoinLendingOrCryptoMixin, withdrawOneCoinMetaFactoryMixin, withdrawOneCoinPlainMixin, withdrawOneCoinZapMixin, } from "./mixins/withdrawOneCoinMixins.js";
|
|
13
|
+
import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpected3argsMixin, } from "./mixins/withdrawOneCoinWrappedExpectedMixins.js";
|
|
14
|
+
import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin, } from "./mixins/withdrawOneCoinWrappedMixins.js";
|
|
15
|
+
import { swapCryptoMetaFactoryMixin, swapMetaFactoryMixin, swapMixin, swapTricrypto2Mixin } from "./mixins/swapMixins.js";
|
|
16
|
+
import { swapWrappedExpectedAndApproveMixin, swapWrappedMixin, swapWrappedRequiredMixin, swapWrappedTricrypto2Mixin, } from "./mixins/swapWrappedMixins.js";
|
|
17
|
+
import { findAbiSignature, getCountArgsOfMethodByAbi } from "../utils.js";
|
|
19
18
|
import { StatsPool } from "./subClasses/statsPool.js";
|
|
20
|
-
export
|
|
21
|
-
const poolDummy = new PoolTemplate(poolId);
|
|
19
|
+
export function getPool(poolId) {
|
|
20
|
+
const poolDummy = new PoolTemplate(poolId, this);
|
|
22
21
|
class Pool extends PoolTemplate {
|
|
23
|
-
constructor(poolId) {
|
|
24
|
-
super(poolId);
|
|
22
|
+
constructor(poolId, curve) {
|
|
23
|
+
super(poolId, curve);
|
|
25
24
|
this.stats = new StatsPool(this);
|
|
26
25
|
this.configureStats(poolDummy);
|
|
27
26
|
}
|
|
@@ -62,7 +61,7 @@ export const getPool = (poolId) => {
|
|
|
62
61
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
63
62
|
Object.assign(Pool.prototype, depositZapMixin);
|
|
64
63
|
}
|
|
65
|
-
else if (getCountArgsOfMethodByAbi(
|
|
64
|
+
else if (getCountArgsOfMethodByAbi(this.contracts[poolDummy.address].abi, 'add_liquidity') > 2) {
|
|
66
65
|
Object.assign(Pool.prototype, depositLendingOrCryptoMixin);
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
@@ -99,7 +98,7 @@ export const getPool = (poolId) => {
|
|
|
99
98
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
100
99
|
Object.assign(Pool.prototype, withdrawZapMixin);
|
|
101
100
|
}
|
|
102
|
-
else if (getCountArgsOfMethodByAbi(
|
|
101
|
+
else if (getCountArgsOfMethodByAbi(this.contracts[poolDummy.address].abi, 'remove_liquidity') > 2) {
|
|
103
102
|
Object.assign(Pool.prototype, withdrawLendingOrCryptoMixin);
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
@@ -165,7 +164,7 @@ export const getPool = (poolId) => {
|
|
|
165
164
|
else if (poolDummy.zap) { // including susd
|
|
166
165
|
Object.assign(Pool.prototype, withdrawOneCoinZapMixin);
|
|
167
166
|
}
|
|
168
|
-
else if (getCountArgsOfMethodByAbi(
|
|
167
|
+
else if (getCountArgsOfMethodByAbi(this.contracts[poolDummy.address].abi, 'remove_liquidity_one_coin') > 3) {
|
|
169
168
|
Object.assign(Pool.prototype, withdrawOneCoinLendingOrCryptoMixin);
|
|
170
169
|
}
|
|
171
170
|
else {
|
|
@@ -190,11 +189,11 @@ export const getPool = (poolId) => {
|
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
// swap and swapEstimateGas
|
|
193
|
-
if (findAbiSignature(
|
|
194
|
-
!(
|
|
192
|
+
if (findAbiSignature(this.contracts[poolDummy.address].abi, 'exchange', 'uint256,uint256,uint256,uint256,bool') &&
|
|
193
|
+
!(this.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum), avaxcrypto (avalanche); 100 is xDAI
|
|
195
194
|
Object.assign(Pool.prototype, swapTricrypto2Mixin);
|
|
196
195
|
}
|
|
197
|
-
else if (poolDummy.isMetaFactory && (getPool(poolDummy.basePool).isLending || getPool(poolDummy.basePool).isFake || poolDummy.isCrypto)) {
|
|
196
|
+
else if (poolDummy.isMetaFactory && (getPool.call(this, poolDummy.basePool).isLending || getPool.call(this, poolDummy.basePool).isFake || poolDummy.isCrypto)) {
|
|
198
197
|
if (poolDummy.isCrypto) {
|
|
199
198
|
Object.assign(Pool.prototype, swapCryptoMetaFactoryMixin);
|
|
200
199
|
}
|
|
@@ -209,12 +208,12 @@ export const getPool = (poolId) => {
|
|
|
209
208
|
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
210
209
|
Object.assign(Pool.prototype, swapWrappedExpectedAndApproveMixin);
|
|
211
210
|
Object.assign(Pool.prototype, swapWrappedRequiredMixin);
|
|
212
|
-
if (findAbiSignature(
|
|
211
|
+
if (findAbiSignature(this.contracts[poolDummy.address].abi, 'exchange', 'uint256,uint256,uint256,uint256,bool')) { // tricrypto2 (eth), tricrypto (arbitrum)
|
|
213
212
|
Object.assign(Pool.prototype, swapWrappedTricrypto2Mixin);
|
|
214
213
|
}
|
|
215
214
|
else {
|
|
216
215
|
Object.assign(Pool.prototype, swapWrappedMixin);
|
|
217
216
|
}
|
|
218
217
|
}
|
|
219
|
-
return new Pool(poolId);
|
|
220
|
-
}
|
|
218
|
+
return new Pool(poolId, this);
|
|
219
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type Curve } from "../../curve.js";
|
|
1
2
|
import { IGaugePool } from "./gaugePool.js";
|
|
3
|
+
import { IPoolData } from "../../interfaces";
|
|
2
4
|
export interface ICorePool {
|
|
3
5
|
id: string;
|
|
4
6
|
name: string;
|
|
@@ -33,6 +35,7 @@ export interface ICorePool {
|
|
|
33
35
|
inApi: boolean;
|
|
34
36
|
}
|
|
35
37
|
export declare class CorePool implements ICorePool {
|
|
38
|
+
readonly curve: Curve;
|
|
36
39
|
id: string;
|
|
37
40
|
name: string;
|
|
38
41
|
fullName: string;
|
|
@@ -64,5 +67,5 @@ export declare class CorePool implements ICorePool {
|
|
|
64
67
|
wrappedDecimals: number[];
|
|
65
68
|
useLending: boolean[];
|
|
66
69
|
inApi: boolean;
|
|
67
|
-
constructor(id: string);
|
|
70
|
+
constructor(id: string, poolData: IPoolData, curve: Curve);
|
|
68
71
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { curve } from "../../curve.js";
|
|
2
1
|
import { GaugePool } from "./gaugePool.js";
|
|
3
2
|
export class CorePool {
|
|
4
|
-
constructor(id) {
|
|
3
|
+
constructor(id, poolData, curve) {
|
|
5
4
|
var _a, _b;
|
|
6
|
-
|
|
7
|
-
if (!
|
|
8
|
-
throw new Error(`Pool
|
|
5
|
+
this.curve = curve;
|
|
6
|
+
if (!poolData) {
|
|
7
|
+
throw new Error(`Pool data is required for pool ${id}`);
|
|
9
8
|
}
|
|
10
|
-
const poolData = poolsData[id];
|
|
11
9
|
this.id = id;
|
|
12
10
|
this.name = poolData.name;
|
|
13
11
|
this.fullName = poolData.full_name;
|
|
@@ -15,7 +13,7 @@ export class CorePool {
|
|
|
15
13
|
this.referenceAsset = poolData.reference_asset;
|
|
16
14
|
this.address = poolData.swap_address;
|
|
17
15
|
this.lpToken = poolData.token_address;
|
|
18
|
-
this.gauge = new GaugePool(poolData.gauge_address, poolData.name);
|
|
16
|
+
this.gauge = new GaugePool(poolData.gauge_address, poolData.name, curve);
|
|
19
17
|
this.zap = poolData.deposit_address || null;
|
|
20
18
|
this.sRewardContract = poolData.sCurveRewards_address || null;
|
|
21
19
|
this.rewardContract = poolData.reward_contract || null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IDict } from '../../interfaces.js';
|
|
2
|
+
import { type Curve } from "../../curve.js";
|
|
2
3
|
export interface IGaugePool {
|
|
3
4
|
address: string;
|
|
4
5
|
poolName: string;
|
|
@@ -17,14 +18,15 @@ export interface IGaugePool {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
export declare class GaugePool implements IGaugePool {
|
|
20
|
-
address: string;
|
|
21
|
-
poolName: string;
|
|
21
|
+
readonly address: string;
|
|
22
|
+
readonly poolName: string;
|
|
23
|
+
readonly curve: Curve;
|
|
22
24
|
estimateGas: {
|
|
23
25
|
addReward: (rewardToken: string, distributor: string) => Promise<number | number[]>;
|
|
24
26
|
depositRewardApprove: (rewardToken: string, amount: number | string) => Promise<number | number[]>;
|
|
25
27
|
depositReward: (rewardToken: string, amount: string | number, epoch: string | number) => Promise<number | number[]>;
|
|
26
28
|
};
|
|
27
|
-
constructor(address: string, poolName: string);
|
|
29
|
+
constructor(address: string, poolName: string, curve: Curve);
|
|
28
30
|
gaugeManager(): Promise<string>;
|
|
29
31
|
gaugeDistributors(): Promise<IDict<string>>;
|
|
30
32
|
gaugeVersion(): Promise<string | null>;
|
|
@@ -7,10 +7,12 @@ 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 { curve } from "../../curve.js";
|
|
11
10
|
import { DIGas, ensureAllowance, ensureAllowanceEstimateGas, getCoinsData, hasAllowance, mulBy1_3, parseUnits, smartNumber, } from "../../utils.js";
|
|
12
11
|
export class GaugePool {
|
|
13
|
-
constructor(address, poolName) {
|
|
12
|
+
constructor(address, poolName, curve) {
|
|
13
|
+
this.address = address;
|
|
14
|
+
this.poolName = poolName;
|
|
15
|
+
this.curve = curve;
|
|
14
16
|
this.address = address;
|
|
15
17
|
this.poolName = poolName;
|
|
16
18
|
this.estimateGas = {
|
|
@@ -21,6 +23,7 @@ export class GaugePool {
|
|
|
21
23
|
}
|
|
22
24
|
gaugeManager() {
|
|
23
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const curve = this.curve;
|
|
24
27
|
if (!this.address || this.address === curve.constants.ZERO_ADDRESS) {
|
|
25
28
|
return curve.constants.ZERO_ADDRESS;
|
|
26
29
|
}
|
|
@@ -28,7 +31,7 @@ export class GaugePool {
|
|
|
28
31
|
try {
|
|
29
32
|
return yield curve.contracts[this.address].contract.manager();
|
|
30
33
|
}
|
|
31
|
-
catch (
|
|
34
|
+
catch (_a) {
|
|
32
35
|
return curve.constants.ZERO_ADDRESS;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -36,19 +39,18 @@ export class GaugePool {
|
|
|
36
39
|
}
|
|
37
40
|
gaugeDistributors() {
|
|
38
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const gaugeContract =
|
|
40
|
-
const
|
|
41
|
-
const rewardCount = Number(curve.formatUnits(yield gaugeContract.reward_count(curve.constantOptions), 0));
|
|
42
|
+
const { contract: gaugeContract, multicallContract: gaugeMulticallContract } = this.curve.contracts[this.address];
|
|
43
|
+
const rewardCount = Number(this.curve.formatUnits(yield gaugeContract.reward_count(this.curve.constantOptions), 0));
|
|
42
44
|
let calls = [];
|
|
43
45
|
for (let i = 0; i < rewardCount; i++) {
|
|
44
46
|
calls.push(gaugeMulticallContract.reward_tokens(i));
|
|
45
47
|
}
|
|
46
|
-
const rewardTokens = yield curve.multicallProvider.all(calls);
|
|
48
|
+
const rewardTokens = yield this.curve.multicallProvider.all(calls);
|
|
47
49
|
calls = [];
|
|
48
50
|
for (let i = 0; i < rewardCount; i++) {
|
|
49
51
|
calls.push(gaugeMulticallContract.reward_data(rewardTokens[i]));
|
|
50
52
|
}
|
|
51
|
-
const rewardData = yield curve.multicallProvider.all(calls);
|
|
53
|
+
const rewardData = yield this.curve.multicallProvider.all(calls);
|
|
52
54
|
const gaugeDistributors = {};
|
|
53
55
|
for (let i = 0; i < rewardCount; i++) {
|
|
54
56
|
gaugeDistributors[rewardTokens[i]] = rewardData[i].distributor;
|
|
@@ -58,6 +60,7 @@ export class GaugePool {
|
|
|
58
60
|
}
|
|
59
61
|
gaugeVersion() {
|
|
60
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const curve = this.curve;
|
|
61
64
|
if (!this.address || this.address === curve.constants.ZERO_ADDRESS) {
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
@@ -65,7 +68,7 @@ export class GaugePool {
|
|
|
65
68
|
try {
|
|
66
69
|
return yield curve.contracts[this.address].contract.version();
|
|
67
70
|
}
|
|
68
|
-
catch (
|
|
71
|
+
catch (_a) {
|
|
69
72
|
return null;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -73,6 +76,7 @@ export class GaugePool {
|
|
|
73
76
|
}
|
|
74
77
|
_addReward(_reward_token_1, _distributor_1) {
|
|
75
78
|
return __awaiter(this, arguments, void 0, function* (_reward_token, _distributor, estimateGas = false) {
|
|
79
|
+
const curve = this.curve;
|
|
76
80
|
if (this.address !== curve.constants.ZERO_ADDRESS && this.address) {
|
|
77
81
|
const gas = yield curve.contracts[this.address].contract.add_reward.estimateGas(_reward_token, _distributor, Object.assign({}, curve.constantOptions));
|
|
78
82
|
if (estimateGas)
|
|
@@ -85,13 +89,11 @@ export class GaugePool {
|
|
|
85
89
|
}
|
|
86
90
|
addRewardEstimateGas(rewardToken, distributor) {
|
|
87
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
// @ts-ignore
|
|
89
92
|
return yield this._addReward(rewardToken, distributor, true);
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
addReward(rewardToken, distributor) {
|
|
93
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
// @ts-ignore
|
|
95
97
|
return yield this._addReward(rewardToken, distributor);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
@@ -104,25 +106,26 @@ export class GaugePool {
|
|
|
104
106
|
}
|
|
105
107
|
depositRewardIsApproved(rewardToken, amount) {
|
|
106
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
return yield hasAllowance([rewardToken], [amount], curve.signerAddress, this.address);
|
|
109
|
+
return yield hasAllowance.call(this.curve, [rewardToken], [amount], this.curve.signerAddress, this.address);
|
|
108
110
|
});
|
|
109
111
|
}
|
|
110
112
|
depositRewardApproveEstimateGas(rewardToken, amount) {
|
|
111
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
return yield ensureAllowanceEstimateGas([rewardToken], [amount], this.address);
|
|
114
|
+
return yield ensureAllowanceEstimateGas.call(this.curve, [rewardToken], [amount], this.address);
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
depositRewardApprove(rewardToken, amount) {
|
|
116
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
return yield ensureAllowance([rewardToken], [amount], this.address);
|
|
119
|
+
return yield ensureAllowance.call(this.curve, [rewardToken], [amount], this.address);
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
_depositReward(rewardToken_1, amount_1, epoch_1) {
|
|
121
123
|
return __awaiter(this, arguments, void 0, function* (rewardToken, amount, epoch, estimateGas = false) {
|
|
124
|
+
const curve = this.curve;
|
|
122
125
|
if (!estimateGas)
|
|
123
|
-
yield ensureAllowance([rewardToken], [amount], this.address);
|
|
126
|
+
yield ensureAllowance.call(curve, [rewardToken], [amount], this.address);
|
|
124
127
|
const contract = curve.contracts[this.address].contract;
|
|
125
|
-
const decimals = (yield getCoinsData(rewardToken))[0].decimals;
|
|
128
|
+
const decimals = (yield getCoinsData.call(curve, rewardToken))[0].decimals;
|
|
126
129
|
const _amount = parseUnits(amount, decimals);
|
|
127
130
|
const gas = yield contract.deposit_reward_token.estimateGas(rewardToken, _amount, epoch, Object.assign({}, curve.constantOptions));
|
|
128
131
|
if (estimateGas)
|
|
@@ -133,13 +136,11 @@ export class GaugePool {
|
|
|
133
136
|
}
|
|
134
137
|
depositRewardEstimateGas(rewardToken, amount, epoch) {
|
|
135
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
// @ts-ignore
|
|
137
139
|
return yield this._depositReward(rewardToken, amount, epoch, true);
|
|
138
140
|
});
|
|
139
141
|
}
|
|
140
142
|
depositReward(rewardToken, amount, epoch) {
|
|
141
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
// @ts-ignore
|
|
143
144
|
return yield this._depositReward(rewardToken, amount, epoch);
|
|
144
145
|
});
|
|
145
146
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IReward } from '../../interfaces.js';
|
|
2
2
|
import { PoolTemplate } from "../PoolTemplate.js";
|
|
3
|
+
import memoize from "memoizee";
|
|
3
4
|
export interface IStatsParameters {
|
|
4
5
|
lpTokenSupply: string;
|
|
5
6
|
virtualPrice: string;
|
|
@@ -35,6 +36,7 @@ export declare class StatsPool implements IStatsPool {
|
|
|
35
36
|
wrappedBalances(): Promise<string[]>;
|
|
36
37
|
underlyingBalances(): Promise<string[]>;
|
|
37
38
|
totalLiquidity: (useApi?: boolean) => Promise<string>;
|
|
39
|
+
totalLiquidityMemoized: ((useApi?: boolean) => Promise<string>) & memoize.Memoized<(useApi?: boolean) => Promise<string>>;
|
|
38
40
|
volume: () => Promise<string>;
|
|
39
41
|
baseApy: () => Promise<{
|
|
40
42
|
day: string;
|
|
@@ -7,12 +7,13 @@ 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 { curve } from "../../curve.js";
|
|
11
10
|
import { _getPoolsFromApi, _getCrvApyFromApi } from '../../cached.js';
|
|
12
11
|
import { _getUsdRate, BN, toBN, _getRewardsFromApi, getVolumeApiController, } from '../../utils.js';
|
|
12
|
+
import memoize from "memoizee";
|
|
13
13
|
export class StatsPool {
|
|
14
14
|
constructor(pool) {
|
|
15
15
|
this.parameters = () => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const curve = this.pool.curve;
|
|
16
17
|
const multicallContract = curve.contracts[this.pool.address].multicallContract;
|
|
17
18
|
const lpMulticallContract = curve.contracts[this.pool.lpToken].multicallContract;
|
|
18
19
|
const calls = [
|
|
@@ -45,7 +46,8 @@ export class StatsPool {
|
|
|
45
46
|
try {
|
|
46
47
|
[_virtualPrice, _fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
|
|
47
48
|
}
|
|
48
|
-
catch (
|
|
49
|
+
catch ( // Empty pool
|
|
50
|
+
_a) { // Empty pool
|
|
49
51
|
calls.shift();
|
|
50
52
|
if (this.pool.isCrypto) {
|
|
51
53
|
calls.shift();
|
|
@@ -84,6 +86,7 @@ export class StatsPool {
|
|
|
84
86
|
return { lpTokenSupply, virtualPrice, fee, adminFee, A, future_A, initial_A, future_A_time, initial_A_time, gamma, priceOracle, priceScale };
|
|
85
87
|
});
|
|
86
88
|
this.totalLiquidity = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
89
|
+
const curve = this.pool.curve;
|
|
87
90
|
if (curve.chainId === 1 && this.pool.id === "crveth")
|
|
88
91
|
return "0";
|
|
89
92
|
if (this.pool.isLlamma) {
|
|
@@ -96,7 +99,7 @@ export class StatsPool {
|
|
|
96
99
|
collateralContract.balanceOf(this.pool.address),
|
|
97
100
|
ammContract.admin_fees_y(),
|
|
98
101
|
]);
|
|
99
|
-
const collateralRate = yield _getUsdRate(this.pool.underlyingCoinAddresses[1]);
|
|
102
|
+
const collateralRate = yield _getUsdRate.call(curve, this.pool.underlyingCoinAddresses[1]);
|
|
100
103
|
const stablecoinTvlBN = toBN(_balance_x).minus(toBN(_fee_x));
|
|
101
104
|
const collateralTvlBN = toBN(_balance_y).minus(toBN(_fee_y)).times(collateralRate);
|
|
102
105
|
return stablecoinTvlBN.plus(collateralTvlBN).toString();
|
|
@@ -108,7 +111,7 @@ export class StatsPool {
|
|
|
108
111
|
poolType = this.pool.id.replace(/-\d+$/, '');
|
|
109
112
|
poolType = poolType.replace(/-v2$/, '');
|
|
110
113
|
}
|
|
111
|
-
const poolsData = (yield _getPoolsFromApi(network, poolType, curve.isLiteChain)).poolData;
|
|
114
|
+
const poolsData = (yield _getPoolsFromApi.call(curve, network, poolType, curve.isLiteChain)).poolData;
|
|
112
115
|
try {
|
|
113
116
|
const totalLiquidity = poolsData.filter((data) => data.address.toLowerCase() === this.pool.address.toLowerCase())[0].usdTotal;
|
|
114
117
|
return String(totalLiquidity);
|
|
@@ -120,18 +123,23 @@ export class StatsPool {
|
|
|
120
123
|
const balances = yield this.underlyingBalances();
|
|
121
124
|
const promises = [];
|
|
122
125
|
for (const addr of this.pool.underlyingCoinAddresses) {
|
|
123
|
-
promises.push(_getUsdRate(addr));
|
|
126
|
+
promises.push(_getUsdRate.call(curve, addr));
|
|
124
127
|
}
|
|
125
128
|
const prices = yield Promise.all(promises);
|
|
126
129
|
const totalLiquidity = balances.reduce((liquidity, b, i) => liquidity + (Number(b) * prices[i]), 0);
|
|
127
130
|
return totalLiquidity.toFixed(8);
|
|
128
131
|
});
|
|
132
|
+
this.totalLiquidityMemoized = memoize(this.totalLiquidity.bind(this), {
|
|
133
|
+
promise: true,
|
|
134
|
+
maxAge: 5 * 60 * 1000, // 5m
|
|
135
|
+
});
|
|
129
136
|
this.volume = () => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const curve = this.pool.curve;
|
|
130
138
|
if (curve.isLiteChain && curve.chainId !== 146) {
|
|
131
139
|
throw Error('This method is not supported for the lite version');
|
|
132
140
|
}
|
|
133
141
|
const network = curve.constants.NETWORK_NAME;
|
|
134
|
-
const { poolsData } = yield getVolumeApiController(network);
|
|
142
|
+
const { poolsData } = yield getVolumeApiController.call(curve, network);
|
|
135
143
|
const poolData = poolsData.find((d) => d.address.toLowerCase() === this.pool.address);
|
|
136
144
|
if (poolData) {
|
|
137
145
|
return poolData.volumeUSD.toString();
|
|
@@ -139,11 +147,12 @@ export class StatsPool {
|
|
|
139
147
|
throw Error(`Can't get Volume for ${this.pool.name} (id: ${this.pool.id})`);
|
|
140
148
|
});
|
|
141
149
|
this.baseApy = () => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const curve = this.pool.curve;
|
|
142
151
|
if (curve.isLiteChain && curve.chainId !== 146) {
|
|
143
152
|
throw Error('baseApy is not supported for the lite version');
|
|
144
153
|
}
|
|
145
154
|
const network = curve.constants.NETWORK_NAME;
|
|
146
|
-
const { poolsData } = yield getVolumeApiController(network);
|
|
155
|
+
const { poolsData } = yield getVolumeApiController.call(curve, network);
|
|
147
156
|
const poolData = poolsData.find((d) => d.address.toLowerCase() === this.pool.address);
|
|
148
157
|
if (poolData) {
|
|
149
158
|
return {
|
|
@@ -155,6 +164,7 @@ export class StatsPool {
|
|
|
155
164
|
});
|
|
156
165
|
this.tokenApy = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
157
166
|
var _a;
|
|
167
|
+
const curve = this.pool.curve;
|
|
158
168
|
if (curve.isLiteChain && curve.chainId !== 146) {
|
|
159
169
|
throw Error('tokenApy is not supported for the lite version');
|
|
160
170
|
}
|
|
@@ -162,18 +172,19 @@ export class StatsPool {
|
|
|
162
172
|
throw Error(`${this.pool.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
|
|
163
173
|
const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
|
|
164
174
|
if (useApi && !isDisabledChain) {
|
|
165
|
-
const crvAPYs = yield _getCrvApyFromApi();
|
|
175
|
+
const crvAPYs = yield _getCrvApyFromApi(curve.constants.NETWORK_NAME, curve.isLiteChain);
|
|
166
176
|
const poolCrvApy = (_a = crvAPYs[this.pool.gauge.address]) !== null && _a !== void 0 ? _a : [0, 0]; // new pools might be missing
|
|
167
177
|
return [poolCrvApy[0], poolCrvApy[1]];
|
|
168
178
|
}
|
|
169
179
|
return yield this.pool._calcTokenApy();
|
|
170
180
|
});
|
|
171
181
|
this.rewardsApy = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
182
|
+
const curve = this.pool.curve;
|
|
172
183
|
if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS)
|
|
173
184
|
return [];
|
|
174
185
|
const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
|
|
175
186
|
if (useApi && !isDisabledChain) {
|
|
176
|
-
const rewards = yield _getRewardsFromApi();
|
|
187
|
+
const rewards = yield _getRewardsFromApi.call(curve);
|
|
177
188
|
if (!rewards[this.pool.gauge.address])
|
|
178
189
|
return [];
|
|
179
190
|
return rewards[this.pool.gauge.address].map((r) => ({ gaugeAddress: r.gaugeAddress, tokenAddress: r.tokenAddress, symbol: r.symbol, apy: r.apy }));
|
|
@@ -185,7 +196,7 @@ export class StatsPool {
|
|
|
185
196
|
const lpTokenContract = curve.contracts[this.pool.lpToken].multicallContract;
|
|
186
197
|
const rewardContract = curve.contracts[this.pool.sRewardContract || this.pool.gauge.address].multicallContract;
|
|
187
198
|
const totalLiquidityUSD = yield this.totalLiquidity();
|
|
188
|
-
const rewardRate = yield _getUsdRate(rewardToken.token);
|
|
199
|
+
const rewardRate = yield _getUsdRate.call(curve, rewardToken.token);
|
|
189
200
|
const [rewardData, _stakedSupply, _totalSupply] = yield curve.multicallProvider.all([
|
|
190
201
|
rewardContract.reward_data(rewardToken.token),
|
|
191
202
|
gaugeContract.totalSupply(),
|
|
@@ -211,6 +222,7 @@ export class StatsPool {
|
|
|
211
222
|
}
|
|
212
223
|
wrappedBalances() {
|
|
213
224
|
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
const curve = this.pool.curve;
|
|
214
226
|
const contract = curve.contracts[this.pool.address].multicallContract;
|
|
215
227
|
const calls = [];
|
|
216
228
|
for (let i = 0; i < this.pool.wrappedCoins.length; i++)
|
|
@@ -8,8 +8,9 @@ export interface IWalletPool {
|
|
|
8
8
|
allCoinBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
|
|
9
9
|
}
|
|
10
10
|
export declare class WalletPool implements IWalletPool {
|
|
11
|
+
readonly curve: import("../../curve").Curve;
|
|
11
12
|
private pool;
|
|
12
|
-
constructor(pool: PoolTemplate);
|
|
13
|
+
constructor(pool: PoolTemplate, curve?: import("../../curve").Curve);
|
|
13
14
|
private _balances;
|
|
14
15
|
balances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
|
|
15
16
|
lpTokenBalances(...addresses: string[] | string[][]): Promise<IDict<IDict<string>> | IDict<string>>;
|
|
@@ -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 { curve } from "../../curve.js";
|
|
11
10
|
import { _prepareAddresses, _getBalances, } from '../../utils.js';
|
|
12
11
|
export class WalletPool {
|
|
13
|
-
constructor(pool) {
|
|
12
|
+
constructor(pool, curve = pool.curve) {
|
|
13
|
+
this.curve = curve;
|
|
14
14
|
this._balances = (rawCoinNames, rawCoinAddresses, ...addresses) => __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const coinNames = [];
|
|
16
16
|
const coinAddresses = [];
|
|
@@ -21,8 +21,8 @@ export class WalletPool {
|
|
|
21
21
|
coinAddresses.push(rawCoinAddresses[i]);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
addresses = _prepareAddresses(addresses);
|
|
25
|
-
const rawBalances = yield _getBalances(coinAddresses, addresses);
|
|
24
|
+
addresses = _prepareAddresses.call(this.curve, addresses);
|
|
25
|
+
const rawBalances = yield _getBalances.call(this.curve, coinAddresses, addresses);
|
|
26
26
|
const balances = {};
|
|
27
27
|
for (const address of addresses) {
|
|
28
28
|
balances[address] = {};
|
|
@@ -36,7 +36,7 @@ export class WalletPool {
|
|
|
36
36
|
}
|
|
37
37
|
balances(...addresses) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS) {
|
|
39
|
+
if (this.pool.gauge.address === this.curve.constants.ZERO_ADDRESS) {
|
|
40
40
|
return yield this._balances(['lpToken', ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], [this.pool.lpToken, ...this.pool.underlyingCoinAddresses, ...this.pool.wrappedCoinAddresses], ...addresses);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
@@ -46,7 +46,7 @@ export class WalletPool {
|
|
|
46
46
|
}
|
|
47
47
|
lpTokenBalances(...addresses) {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
if (this.pool.gauge.address === curve.constants.ZERO_ADDRESS) {
|
|
49
|
+
if (this.pool.gauge.address === this.curve.constants.ZERO_ADDRESS) {
|
|
50
50
|
return yield this._balances(['lpToken'], [this.pool.lpToken], ...addresses);
|
|
51
51
|
}
|
|
52
52
|
else {
|
package/lib/pools/utils.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { IDict } from "../interfaces";
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
2
|
+
import { type Curve } from "../curve.js";
|
|
3
|
+
export declare function getUserPoolListByLiquidity(this: Curve, address?: string): Promise<string[]>;
|
|
4
|
+
export declare function getUserLiquidityUSD(this: Curve, pools: string[], address?: string): Promise<string[]>;
|
|
5
|
+
export declare function getUserPoolListByClaimable(this: Curve, address?: string): Promise<string[]>;
|
|
6
|
+
export declare function getUserClaimable(this: Curve, pools: string[], address?: string): Promise<{
|
|
6
7
|
token: string;
|
|
7
8
|
symbol: string;
|
|
8
9
|
amount: string;
|
|
9
10
|
price: number;
|
|
10
11
|
}[][]>;
|
|
11
|
-
export declare
|
|
12
|
-
export declare
|
|
12
|
+
export declare function getUserPoolList(this: Curve, address?: string, useApi?: boolean): Promise<string[]>;
|
|
13
|
+
export declare function _getAmplificationCoefficientsFromApi(this: Curve): Promise<IDict<number>>;
|
|
13
14
|
export declare const checkVyperVulnerability: (chainId: number, poolId: string, implementation: string | null) => boolean;
|