@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.
Files changed (81) hide show
  1. package/lib/boosting.d.ts +33 -32
  2. package/lib/boosting.js +320 -252
  3. package/lib/cached.d.ts +4 -3
  4. package/lib/cached.js +63 -19
  5. package/lib/constants/utils.d.ts +14 -1
  6. package/lib/constants/utils.js +21 -6
  7. package/lib/curve.d.ts +5 -5
  8. package/lib/curve.js +21 -38
  9. package/lib/dao.d.ts +32 -31
  10. package/lib/dao.js +420 -350
  11. package/lib/external-api.d.ts +1 -1
  12. package/lib/external-api.js +2 -2
  13. package/lib/factory/common.d.ts +2 -1
  14. package/lib/factory/common.js +1 -1
  15. package/lib/factory/deploy.d.ts +46 -45
  16. package/lib/factory/deploy.js +630 -551
  17. package/lib/factory/factory-api.d.ts +3 -2
  18. package/lib/factory/factory-api.js +22 -23
  19. package/lib/factory/factory-crypto.d.ts +1 -1
  20. package/lib/factory/factory-crypto.js +12 -15
  21. package/lib/factory/factory-tricrypto.d.ts +1 -1
  22. package/lib/factory/factory-tricrypto.js +14 -15
  23. package/lib/factory/factory-twocrypto.d.ts +1 -1
  24. package/lib/factory/factory-twocrypto.js +12 -13
  25. package/lib/factory/factory.d.ts +4 -3
  26. package/lib/factory/factory.js +21 -24
  27. package/lib/index.d.ts +413 -104
  28. package/lib/index.js +253 -257
  29. package/lib/interfaces.d.ts +2 -0
  30. package/lib/pools/PoolTemplate.d.ts +13 -12
  31. package/lib/pools/PoolTemplate.js +279 -285
  32. package/lib/pools/mixins/common.js +2 -2
  33. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
  34. package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
  35. package/lib/pools/mixins/depositMixins.d.ts +25 -5
  36. package/lib/pools/mixins/depositMixins.js +38 -76
  37. package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
  38. package/lib/pools/mixins/depositWrappedMixins.js +17 -33
  39. package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
  40. package/lib/pools/mixins/poolBalancesMixin.js +3 -5
  41. package/lib/pools/mixins/swapMixins.d.ts +20 -4
  42. package/lib/pools/mixins/swapMixins.js +36 -70
  43. package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
  44. package/lib/pools/mixins/swapWrappedMixins.js +32 -60
  45. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
  46. package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
  47. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
  48. package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
  49. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
  50. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
  51. package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
  52. package/lib/pools/mixins/withdrawMixins.js +33 -67
  53. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
  54. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
  55. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
  56. package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
  57. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
  58. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
  59. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
  60. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
  61. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
  62. package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
  63. package/lib/pools/poolConstructor.d.ts +2 -1
  64. package/lib/pools/poolConstructor.js +27 -28
  65. package/lib/pools/subClasses/corePool.d.ts +4 -1
  66. package/lib/pools/subClasses/corePool.js +5 -7
  67. package/lib/pools/subClasses/gaugePool.d.ts +5 -3
  68. package/lib/pools/subClasses/gaugePool.js +19 -18
  69. package/lib/pools/subClasses/statsPool.d.ts +2 -0
  70. package/lib/pools/subClasses/statsPool.js +22 -10
  71. package/lib/pools/subClasses/walletPool.d.ts +2 -1
  72. package/lib/pools/subClasses/walletPool.js +6 -6
  73. package/lib/pools/utils.d.ts +7 -6
  74. package/lib/pools/utils.js +316 -297
  75. package/lib/route-graph.worker.d.ts +2 -2
  76. package/lib/route-graph.worker.js +4 -6
  77. package/lib/router.d.ts +12 -11
  78. package/lib/router.js +331 -295
  79. package/lib/utils.d.ts +34 -33
  80. package/lib/utils.js +481 -435
  81. package/package.json +1 -1
@@ -9,41 +9,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import memoize from "memoizee";
11
11
  import { _getAllGaugesFormatted } from '../external-api.js';
12
- import { _getCoinAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, findAbiFunction, PERIODS, } from '../utils.js';
13
- import { curve, OLD_CHAINS } from "../curve.js";
12
+ import { _cutZeros, _ensureAllowance, _get_price_impact, _get_small_x, _getAddress, _getCoinAddresses, _getRewardsFromApi, _getUsdRate, _setContracts, BN, checkNumber, DIGas, ensureAllowance, ensureAllowanceEstimateGas, findAbiFunction, fromBN, getEthIndex, hasAllowance, mulBy1_3, parseUnits, PERIODS, smartNumber, toBN, toStringFromBN, } from '../utils.js';
13
+ import { OLD_CHAINS } from "../curve.js";
14
14
  import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
15
15
  import { CorePool } from "./subClasses/corePool.js";
16
16
  import { StatsPool } from "./subClasses/statsPool.js";
17
17
  import { WalletPool } from "./subClasses/walletPool.js";
18
18
  import { checkVyperVulnerability } from "./utils.js";
19
19
  export class PoolTemplate extends CorePool {
20
- constructor(id) {
21
- super(id);
20
+ constructor(id, curve, poolData = curve.getPoolsData()[id]) {
21
+ super(id, poolData, curve);
22
22
  this._calcTokenApy = (...args_1) => __awaiter(this, [...args_1], void 0, function* (futureWorkingSupplyBN = null) {
23
23
  const totalLiquidityUSD = yield this.stats.totalLiquidity();
24
24
  if (Number(totalLiquidityUSD) === 0)
25
25
  return [0, 0];
26
26
  let inflationRateBN, workingSupplyBN, totalSupplyBN;
27
- if (curve.chainId !== 1) {
28
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
29
- const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
30
- const crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
27
+ if (this.curve.chainId !== 1) {
28
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
29
+ const lpTokenContract = this.curve.contracts[this.lpToken].multicallContract;
30
+ const crvContract = this.curve.contracts[this.curve.constants.ALIASES.crv].contract;
31
31
  const currentWeek = Math.floor(Date.now() / 1000 / PERIODS.WEEK);
32
- [inflationRateBN, workingSupplyBN, totalSupplyBN] = (yield curve.multicallProvider.all([
32
+ [inflationRateBN, workingSupplyBN, totalSupplyBN] = (yield this.curve.multicallProvider.all([
33
33
  gaugeContract.inflation_rate(currentWeek),
34
34
  gaugeContract.working_supply(),
35
35
  lpTokenContract.totalSupply(),
36
36
  ])).map((value) => toBN(value));
37
37
  if (inflationRateBN.eq(0)) {
38
- inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(PERIODS.WEEK);
38
+ inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, this.curve.constantOptions)).div(PERIODS.WEEK);
39
39
  }
40
40
  }
41
41
  else {
42
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
43
- const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
44
- const gaugeControllerContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
42
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
43
+ const lpTokenContract = this.curve.contracts[this.lpToken].multicallContract;
44
+ const gaugeControllerContract = this.curve.contracts[this.curve.constants.ALIASES.gauge_controller].multicallContract;
45
45
  let weightBN;
46
- [inflationRateBN, weightBN, workingSupplyBN, totalSupplyBN] = (yield curve.multicallProvider.all([
46
+ [inflationRateBN, weightBN, workingSupplyBN, totalSupplyBN] = (yield this.curve.multicallProvider.all([
47
47
  gaugeContract.inflation_rate(),
48
48
  gaugeControllerContract.gauge_relative_weight(this.gauge.address),
49
49
  gaugeContract.working_supply(),
@@ -58,7 +58,7 @@ export class PoolTemplate extends CorePool {
58
58
  // If you added 1$ value of LP it would be 0.4$ of working LP. So your annual reward per 1$ in USD is:
59
59
  // (annual reward per working liquidity in $) * (0.4$ of working LP)
60
60
  const rateBN = inflationRateBN.times(31536000).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)).times(0.4);
61
- const crvPrice = yield _getUsdRate(curve.constants.ALIASES.crv);
61
+ const crvPrice = yield _getUsdRate.call(this.curve, this.curve.constants.ALIASES.crv);
62
62
  const baseApyBN = rateBN.times(crvPrice);
63
63
  const boostedApyBN = baseApyBN.times(2.5);
64
64
  return [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()];
@@ -69,14 +69,14 @@ export class PoolTemplate extends CorePool {
69
69
  return yield this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying);
70
70
  }
71
71
  catch (e) { // Seeding
72
- const lpContract = curve.contracts[this.lpToken].contract;
73
- const _lpTotalSupply = yield lpContract.totalSupply(curve.constantOptions);
74
- if (_lpTotalSupply > curve.parseUnits("0"))
72
+ const lpContract = this.curve.contracts[this.lpToken].contract;
73
+ const _lpTotalSupply = yield lpContract.totalSupply(this.curve.constantOptions);
74
+ if (_lpTotalSupply > this.curve.parseUnits("0"))
75
75
  throw e; // Already seeded
76
76
  if (this.isMeta && useUnderlying)
77
77
  throw Error("Initial deposit for crypto meta pools must be in wrapped coins");
78
78
  const decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
79
- const amounts = _amounts.map((_a, i) => curve.formatUnits(_a, decimals[i]));
79
+ const amounts = _amounts.map((_a, i) => this.curve.formatUnits(_a, decimals[i]));
80
80
  const seedAmounts = yield this.getSeedAmounts(amounts[0]); // Checks N coins is 2 or 3 and amounts > 0
81
81
  amounts.forEach((a, i) => {
82
82
  if (!BN(a).eq(BN(seedAmounts[i])))
@@ -89,22 +89,22 @@ export class PoolTemplate extends CorePool {
89
89
  if (this.isNg)
90
90
  return yield this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying);
91
91
  if (this.isMeta) {
92
- const basePool = new PoolTemplate(this.basePool);
93
- return yield curve.contracts[curve.constants.ALIASES.stable_calc].contract.calc_token_amount_meta(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, basePool.address, basePool.lpToken, isDeposit, useUnderlying);
92
+ const basePool = new PoolTemplate(this.basePool, this.curve);
93
+ return yield this.curve.contracts[this.curve.constants.ALIASES.stable_calc].contract.calc_token_amount_meta(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(this.curve.parseUnits("0"))), _amounts.length, basePool.address, basePool.lpToken, isDeposit, useUnderlying);
94
94
  }
95
95
  else {
96
- return yield curve.contracts[curve.constants.ALIASES.stable_calc].contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending);
96
+ return yield this.curve.contracts[this.curve.constants.ALIASES.stable_calc].contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(this.curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending);
97
97
  }
98
98
  }
99
99
  catch (e) { // Seeding
100
100
  if (!isDeposit)
101
101
  throw e; // Seeding is only for deposit
102
- const lpContract = curve.contracts[this.lpToken].contract;
103
- const _lpTotalSupply = yield lpContract.totalSupply(curve.constantOptions);
104
- if (_lpTotalSupply > curve.parseUnits("0"))
102
+ const lpContract = this.curve.contracts[this.lpToken].contract;
103
+ const _lpTotalSupply = yield lpContract.totalSupply(this.curve.constantOptions);
104
+ if (_lpTotalSupply > this.curve.parseUnits("0"))
105
105
  throw e; // Already seeded
106
106
  const decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
107
- const amounts = _amounts.map((_a, i) => curve.formatUnits(_a, decimals[i]));
107
+ const amounts = _amounts.map((_a, i) => this.curve.formatUnits(_a, decimals[i]));
108
108
  const seedAmounts = yield this.getSeedAmounts(amounts[0]); // Checks N coins == 2 and amounts > 0
109
109
  amounts.forEach((a, i) => {
110
110
  if (!BN(a).eq(BN(seedAmounts[i])))
@@ -123,28 +123,28 @@ export class PoolTemplate extends CorePool {
123
123
  this.crvProfit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
124
124
  if (this.rewardsOnly())
125
125
  throw Error(`${this.name} has Rewards-Only Gauge. Use rewardsProfit instead`);
126
- address = address || curve.signerAddress;
126
+ address = address || this.curve.signerAddress;
127
127
  if (!address)
128
128
  throw Error("Need to connect wallet or pass address into args");
129
129
  let inflationRateBN, workingSupplyBN, workingBalanceBN;
130
- if (curve.chainId !== 1) {
131
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
132
- const crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
130
+ if (this.curve.chainId !== 1) {
131
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
132
+ const crvContract = this.curve.contracts[this.curve.constants.ALIASES.crv].contract;
133
133
  const currentWeek = Math.floor(Date.now() / 1000 / PERIODS.WEEK);
134
- [inflationRateBN, workingBalanceBN, workingSupplyBN] = (yield curve.multicallProvider.all([
134
+ [inflationRateBN, workingBalanceBN, workingSupplyBN] = (yield this.curve.multicallProvider.all([
135
135
  gaugeContract.inflation_rate(currentWeek),
136
136
  gaugeContract.working_balances(address),
137
137
  gaugeContract.working_supply(),
138
138
  ])).map((value) => toBN(value));
139
139
  if (inflationRateBN.eq(0)) {
140
- inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, curve.constantOptions)).div(PERIODS.WEEK);
140
+ inflationRateBN = toBN(yield crvContract.balanceOf(this.gauge.address, this.curve.constantOptions)).div(PERIODS.WEEK);
141
141
  }
142
142
  }
143
143
  else {
144
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
145
- const gaugeControllerContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
144
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
145
+ const gaugeControllerContract = this.curve.contracts[this.curve.constants.ALIASES.gauge_controller].multicallContract;
146
146
  let weightBN;
147
- [inflationRateBN, weightBN, workingBalanceBN, workingSupplyBN] = (yield curve.multicallProvider.all([
147
+ [inflationRateBN, weightBN, workingBalanceBN, workingSupplyBN] = (yield this.curve.multicallProvider.all([
148
148
  gaugeContract.inflation_rate(),
149
149
  gaugeControllerContract.gauge_relative_weight(this.gauge.address),
150
150
  gaugeContract.working_balances(address),
@@ -152,14 +152,14 @@ export class PoolTemplate extends CorePool {
152
152
  ])).map((value) => toBN(value));
153
153
  inflationRateBN = inflationRateBN.times(weightBN);
154
154
  }
155
- const crvPrice = yield _getUsdRate('CRV');
155
+ const crvPrice = yield _getUsdRate.call(this.curve, 'CRV');
156
156
  if (workingSupplyBN.eq(0))
157
157
  return {
158
158
  day: "0.0",
159
159
  week: "0.0",
160
160
  month: "0.0",
161
161
  year: "0.0",
162
- token: curve.constants.ALIASES.crv,
162
+ token: this.curve.constants.ALIASES.crv,
163
163
  symbol: 'CRV',
164
164
  price: crvPrice,
165
165
  };
@@ -172,19 +172,19 @@ export class PoolTemplate extends CorePool {
172
172
  week: weeklyIncome.toString(),
173
173
  month: monthlyIncome.toString(),
174
174
  year: annualIncome.toString(),
175
- token: curve.constants.ALIASES.crv,
175
+ token: this.curve.constants.ALIASES.crv,
176
176
  symbol: 'CRV',
177
177
  price: crvPrice,
178
178
  };
179
179
  });
180
180
  this.userBoost = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
181
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
181
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
182
182
  throw Error(`${this.name} doesn't have gauge`);
183
183
  if (this.rewardsOnly())
184
184
  throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
185
- address = _getAddress(address);
186
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
187
- const [workingBalanceBN, balanceBN] = (yield curve.multicallProvider.all([
185
+ address = _getAddress.call(this.curve, address);
186
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
187
+ const [workingBalanceBN, balanceBN] = (yield this.curve.multicallProvider.all([
188
188
  gaugeContract.working_balances(address),
189
189
  gaugeContract.balanceOf(address),
190
190
  ])).map((value) => toBN(value));
@@ -197,8 +197,8 @@ export class PoolTemplate extends CorePool {
197
197
  });
198
198
  this._userFutureBoostAndWorkingSupply = (address) => __awaiter(this, void 0, void 0, function* () {
199
199
  // Calc future working balance
200
- const veContractMulticall = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
201
- const gaugeContractMulticall = curve.contracts[this.gauge.address].multicallContract;
200
+ const veContractMulticall = this.curve.contracts[this.curve.constants.ALIASES.voting_escrow].multicallContract;
201
+ const gaugeContractMulticall = this.curve.contracts[this.gauge.address].multicallContract;
202
202
  const calls = [
203
203
  veContractMulticall.balanceOf(address),
204
204
  veContractMulticall.totalSupply(),
@@ -207,7 +207,7 @@ export class PoolTemplate extends CorePool {
207
207
  gaugeContractMulticall.working_balances(address),
208
208
  gaugeContractMulticall.working_supply(),
209
209
  ];
210
- const [_votingBalance, _votingTotal, _gaugeBalance, _gaugeTotal, _workingBalance, _workingSupply] = yield curve.multicallProvider.all(calls);
210
+ const [_votingBalance, _votingTotal, _gaugeBalance, _gaugeTotal, _workingBalance, _workingSupply] = yield this.curve.multicallProvider.all(calls);
211
211
  let _futureWorkingBalance = _gaugeBalance * BigInt(40) / BigInt(100);
212
212
  if (_votingTotal > BigInt(0)) {
213
213
  _futureWorkingBalance += _gaugeTotal * _votingBalance / _votingTotal * BigInt(60) / BigInt(100);
@@ -223,7 +223,7 @@ export class PoolTemplate extends CorePool {
223
223
  this.userFutureBoost = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
224
224
  if (this.rewardsOnly())
225
225
  throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
226
- address = _getAddress(address);
226
+ address = _getAddress.call(this.curve, address);
227
227
  const [boostBN] = yield this._userFutureBoostAndWorkingSupply(address);
228
228
  if (boostBN.lt(1))
229
229
  return '1.0';
@@ -234,7 +234,7 @@ export class PoolTemplate extends CorePool {
234
234
  this.userCrvApy = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
235
235
  if (this.rewardsOnly())
236
236
  throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
237
- address = _getAddress(address);
237
+ address = _getAddress.call(this.curve, address);
238
238
  const [minApy, maxApy] = yield this.stats.tokenApy();
239
239
  const boost = yield this.userBoost(address);
240
240
  if (boost == "2.5")
@@ -246,7 +246,7 @@ export class PoolTemplate extends CorePool {
246
246
  this.userFutureCrvApy = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
247
247
  if (this.rewardsOnly())
248
248
  throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
249
- address = _getAddress(address);
249
+ address = _getAddress.call(this.curve, address);
250
250
  const [boostBN, futureWorkingSupplyBN] = yield this._userFutureBoostAndWorkingSupply(address);
251
251
  const [minApy, maxApy] = yield this._calcTokenApy(futureWorkingSupplyBN);
252
252
  if (boostBN.lt(1))
@@ -256,21 +256,21 @@ export class PoolTemplate extends CorePool {
256
256
  return BN(minApy).times(boostBN).toNumber();
257
257
  });
258
258
  this.maxBoostedStake = (...addresses) => __awaiter(this, void 0, void 0, function* () {
259
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
259
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
260
260
  throw Error(`${this.name} doesn't have gauge`);
261
261
  if (addresses.length == 1 && Array.isArray(addresses[0]))
262
262
  addresses = addresses[0];
263
- if (addresses.length === 0 && curve.signerAddress !== '')
264
- addresses = [curve.signerAddress];
263
+ if (addresses.length === 0 && this.curve.signerAddress !== '')
264
+ addresses = [this.curve.signerAddress];
265
265
  if (addresses.length === 0)
266
266
  throw Error("Need to connect wallet or pass addresses into args");
267
- const votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
268
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
267
+ const votingEscrowContract = this.curve.contracts[this.curve.constants.ALIASES.voting_escrow].multicallContract;
268
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
269
269
  const contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
270
270
  addresses.forEach((account) => {
271
271
  contractCalls.push(votingEscrowContract.balanceOf(account));
272
272
  });
273
- const _response = yield curve.multicallProvider.all(contractCalls);
273
+ const _response = yield this.curve.multicallProvider.all(contractCalls);
274
274
  const responseBN = _response.map((value) => toBN(value));
275
275
  const [veTotalSupplyBN, gaugeTotalSupplyBN] = responseBN.splice(0, 2);
276
276
  const resultBN = {};
@@ -285,14 +285,15 @@ export class PoolTemplate extends CorePool {
285
285
  });
286
286
  // ---------------- REWARDS PROFIT, CLAIM ----------------
287
287
  this.rewardTokens = memoize((...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
288
+ const curve = this.curve;
288
289
  if (this.gauge.address === curve.constants.ZERO_ADDRESS)
289
290
  return [];
290
291
  if (useApi) {
291
- const rewards = yield _getRewardsFromApi();
292
+ const rewards = yield _getRewardsFromApi.call(curve);
292
293
  if (!rewards[this.gauge.address])
293
294
  return [];
294
295
  // Don't reset ABI if its already set, we might override an LP token ABI
295
- rewards[this.gauge.address].forEach((r) => !curve.contracts[r.tokenAddress] && _setContracts(r.tokenAddress, ERC20Abi));
296
+ rewards[this.gauge.address].forEach((r) => !curve.contracts[r.tokenAddress] && _setContracts.call(curve, r.tokenAddress, ERC20Abi));
296
297
  return rewards[this.gauge.address].map((r) => ({ token: r.tokenAddress, symbol: r.symbol, decimals: Number(r.decimals) }));
297
298
  }
298
299
  const gaugeContract = curve.contracts[this.gauge.address].contract;
@@ -313,7 +314,7 @@ export class PoolTemplate extends CorePool {
313
314
  const tokenInfoCalls = [];
314
315
  for (const token of tokens) {
315
316
  // Don't reset ABI if its already set, we might override an LP token ABI
316
- const { multicallContract } = curve.contracts[token] || _setContracts(token, ERC20Abi);
317
+ const { multicallContract } = curve.contracts[token] || _setContracts.call(curve, token, ERC20Abi);
317
318
  tokenInfoCalls.push(multicallContract.symbol(), multicallContract.decimals());
318
319
  }
319
320
  const tokenInfo = yield curve.multicallProvider.all(tokenInfoCalls);
@@ -326,7 +327,7 @@ export class PoolTemplate extends CorePool {
326
327
  const rewardContract = curve.contracts[this.sRewardContract].contract;
327
328
  const method = "snx()" in rewardContract ? "snx" : "rewardsToken"; // susd, tbtc : dusd, musd, rsv, sbtc
328
329
  const token = (yield rewardContract[method](curve.constantOptions)).toLowerCase();
329
- _setContracts(token, ERC20Abi);
330
+ _setContracts.call(curve, token, ERC20Abi);
330
331
  const tokenMulticallContract = curve.contracts[token].multicallContract;
331
332
  const res = yield curve.multicallProvider.all([
332
333
  tokenMulticallContract.symbol(),
@@ -342,27 +343,27 @@ export class PoolTemplate extends CorePool {
342
343
  maxAge: 30 * 60 * 1000, // 30m
343
344
  });
344
345
  this.rewardsProfit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (address = "") {
345
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
346
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
346
347
  throw Error(`${this.name} doesn't have gauge`);
347
- address = address || curve.signerAddress;
348
+ address = address || this.curve.signerAddress;
348
349
  if (!address)
349
350
  throw Error("Need to connect wallet or pass address into args");
350
351
  const rewardTokens = yield this.rewardTokens();
351
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
352
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
352
353
  const result = [];
353
- if ('reward_data(address)' in curve.contracts[this.gauge.address].contract) {
354
+ if ('reward_data(address)' in this.curve.contracts[this.gauge.address].contract) {
354
355
  const calls = [gaugeContract.balanceOf(address), gaugeContract.totalSupply()];
355
356
  for (const rewardToken of rewardTokens) {
356
357
  calls.push(gaugeContract.reward_data(rewardToken.token));
357
358
  }
358
- const res = yield curve.multicallProvider.all(calls);
359
+ const res = yield this.curve.multicallProvider.all(calls);
359
360
  const balanceBN = toBN(res.shift());
360
361
  const totalSupplyBN = toBN(res.shift());
361
362
  for (const rewardToken of rewardTokens) {
362
363
  const _rewardData = res.shift();
363
- const periodFinish = Number(curve.formatUnits(_rewardData.period_finish, 0)) * 1000;
364
+ const periodFinish = Number(this.curve.formatUnits(_rewardData.period_finish, 0)) * 1000;
364
365
  const inflationRateBN = periodFinish > Date.now() ? toBN(_rewardData.rate, rewardToken.decimals) : BN(0);
365
- const tokenPrice = yield _getUsdRate(rewardToken.token);
366
+ const tokenPrice = yield _getUsdRate.call(this.curve, rewardToken.token);
366
367
  result.push({
367
368
  day: inflationRateBN.times(PERIODS.DAY).times(balanceBN).div(totalSupplyBN).toString(),
368
369
  week: inflationRateBN.times(PERIODS.WEEK).times(balanceBN).div(totalSupplyBN).toString(),
@@ -374,10 +375,10 @@ export class PoolTemplate extends CorePool {
374
375
  });
375
376
  }
376
377
  }
377
- else if (this.sRewardContract && "rewardRate()" in curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1) {
378
+ else if (this.sRewardContract && "rewardRate()" in this.curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1) {
378
379
  const rewardToken = rewardTokens[0];
379
- const sRewardContract = curve.contracts[this.sRewardContract].multicallContract;
380
- const [_inflationRate, _periodFinish, _balance, _totalSupply] = yield curve.multicallProvider.all([
380
+ const sRewardContract = this.curve.contracts[this.sRewardContract].multicallContract;
381
+ const [_inflationRate, _periodFinish, _balance, _totalSupply] = yield this.curve.multicallProvider.all([
381
382
  sRewardContract.rewardRate(),
382
383
  sRewardContract.periodFinish(),
383
384
  gaugeContract.balanceOf(address),
@@ -387,7 +388,7 @@ export class PoolTemplate extends CorePool {
387
388
  const inflationRateBN = periodFinish > Date.now() ? toBN(_inflationRate, rewardToken.decimals) : BN(0);
388
389
  const balanceBN = toBN(_balance);
389
390
  const totalSupplyBN = toBN(_totalSupply);
390
- const tokenPrice = yield _getUsdRate(rewardToken.token);
391
+ const tokenPrice = yield _getUsdRate.call(this.curve, rewardToken.token);
391
392
  result.push({
392
393
  day: inflationRateBN.times(PERIODS.DAY).times(balanceBN).div(totalSupplyBN).toString(),
393
394
  week: inflationRateBN.times(PERIODS.WEEK).times(balanceBN).div(totalSupplyBN).toString(),
@@ -400,7 +401,7 @@ export class PoolTemplate extends CorePool {
400
401
  }
401
402
  else if (['aave', 'saave', 'ankreth'].includes(this.id)) {
402
403
  for (const rewardToken of rewardTokens) {
403
- const tokenPrice = yield _getUsdRate(rewardToken.token);
404
+ const tokenPrice = yield _getUsdRate.call(this.curve, rewardToken.token);
404
405
  result.push({
405
406
  day: "0",
406
407
  week: "0",
@@ -416,18 +417,18 @@ export class PoolTemplate extends CorePool {
416
417
  });
417
418
  // ---------------- ... ----------------
418
419
  this.gaugeOptimalDeposits = (...accounts) => __awaiter(this, void 0, void 0, function* () {
419
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
420
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
420
421
  throw Error(`${this.name} doesn't have gauge`);
421
422
  if (accounts.length == 1 && Array.isArray(accounts[0]))
422
423
  accounts = accounts[0];
423
- const votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
424
- const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
425
- const gaugeContract = curve.contracts[this.gauge.address].multicallContract;
424
+ const votingEscrowContract = this.curve.contracts[this.curve.constants.ALIASES.voting_escrow].multicallContract;
425
+ const lpTokenContract = this.curve.contracts[this.lpToken].multicallContract;
426
+ const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
426
427
  const contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
427
428
  accounts.forEach((account) => {
428
429
  contractCalls.push(votingEscrowContract.balanceOf(account), lpTokenContract.balanceOf(account), gaugeContract.balanceOf(account));
429
430
  });
430
- const _response = yield curve.multicallProvider.all(contractCalls);
431
+ const _response = yield this.curve.multicallProvider.all(contractCalls);
431
432
  const response = _response.map((value) => toBN(value));
432
433
  const [veTotalSupply, gaugeTotalSupply] = response.splice(0, 2);
433
434
  const votingPower = {};
@@ -438,7 +439,6 @@ export class PoolTemplate extends CorePool {
438
439
  response.splice(0, 3);
439
440
  }
440
441
  const totalPower = Object.values(votingPower).reduce((sum, item) => sum.plus(item));
441
- // @ts-ignore
442
442
  const optimalBN = Object.fromEntries(accounts.map((acc) => [acc, BN(0)]));
443
443
  if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
444
444
  for (const acct of accounts) {
@@ -481,7 +481,7 @@ export class PoolTemplate extends CorePool {
481
481
  }
482
482
  return idx;
483
483
  }
484
- const [coinAddress] = _getCoinAddresses(coin);
484
+ const [coinAddress] = _getCoinAddresses.call(this.curve, coin);
485
485
  const lowerCaseCoinAddresses = useUnderlying ?
486
486
  this.underlyingCoinAddresses.map((c) => c.toLowerCase()) :
487
487
  this.wrappedCoinAddresses.map((c) => c.toLowerCase());
@@ -498,17 +498,17 @@ export class PoolTemplate extends CorePool {
498
498
  const addr = this.wrappedCoinAddresses[i];
499
499
  if (this.useLending[i]) {
500
500
  if (['compound', 'usdt', 'ib'].includes(this.id)) {
501
- _rates.push(yield curve.contracts[addr].contract.exchangeRateStored());
501
+ _rates.push(yield this.curve.contracts[addr].contract.exchangeRateStored());
502
502
  }
503
503
  else if (['y', 'busd', 'pax'].includes(this.id)) {
504
- _rates.push(yield curve.contracts[addr].contract.getPricePerFullShare());
504
+ _rates.push(yield this.curve.contracts[addr].contract.getPricePerFullShare());
505
505
  }
506
506
  else {
507
- _rates.push(curve.parseUnits(String(Math.pow(10, 18)), 0)); // Aave ratio 1:1
507
+ _rates.push(this.curve.parseUnits(String(Math.pow(10, 18)), 0)); // Aave ratio 1:1
508
508
  }
509
509
  }
510
510
  else {
511
- _rates.push(curve.parseUnits(String(Math.pow(10, 18)), 0));
511
+ _rates.push(this.curve.parseUnits(String(Math.pow(10, 18)), 0));
512
512
  }
513
513
  }
514
514
  return _rates;
@@ -517,12 +517,12 @@ export class PoolTemplate extends CorePool {
517
517
  if (this.isMeta) {
518
518
  if (useUnderlying)
519
519
  return this.underlyingCoins.map(() => BN(1));
520
- const _vp = yield curve.contracts[curve.getPoolsData()[this.basePool].swap_address].contract.get_virtual_price();
520
+ const _vp = yield this.curve.contracts[this.curve.getPoolsData()[this.basePool].swap_address].contract.get_virtual_price();
521
521
  return [BN(1), toBN(_vp)];
522
522
  }
523
523
  //for crvusd and stable-ng implementations
524
- if (findAbiFunction(curve.contracts[this.address].abi, 'stored_rates').length > 0 && this.isPlain) {
525
- const _stored_rates = yield curve.contracts[this.address].contract.stored_rates();
524
+ if (findAbiFunction(this.curve.contracts[this.address].abi, 'stored_rates').length > 0 && this.isPlain) {
525
+ const _stored_rates = yield this.curve.contracts[this.address].contract.stored_rates();
526
526
  return _stored_rates.map((_r, i) => toBN(_r, 36 - this.wrappedDecimals[i]));
527
527
  }
528
528
  return this.wrappedCoins.map(() => BN(1));
@@ -530,7 +530,7 @@ export class PoolTemplate extends CorePool {
530
530
  this._underlyingPrices = () => __awaiter(this, void 0, void 0, function* () {
531
531
  const promises = [];
532
532
  for (const addr of this.underlyingCoinAddresses) {
533
- promises.push(_getUsdRate(addr));
533
+ promises.push(_getUsdRate.call(this.curve, addr));
534
534
  }
535
535
  return yield Promise.all(promises);
536
536
  });
@@ -538,7 +538,7 @@ export class PoolTemplate extends CorePool {
538
538
  this._wrappedPrices = () => __awaiter(this, void 0, void 0, function* () {
539
539
  const promises = [];
540
540
  for (const addr of this.wrappedCoinAddresses) {
541
- promises.push(_getUsdRate(addr));
541
+ promises.push(_getUsdRate.call(this.curve, addr));
542
542
  }
543
543
  return yield Promise.all(promises);
544
544
  });
@@ -576,31 +576,31 @@ export class PoolTemplate extends CorePool {
576
576
  };
577
577
  }
578
578
  hasVyperVulnerability() {
579
- return checkVyperVulnerability(curve.chainId, this.id, this.implementation);
579
+ return checkVyperVulnerability(this.curve.chainId, this.id, this.implementation);
580
580
  }
581
581
  rewardsOnly() {
582
- if (curve.chainId === 2222 || curve.chainId === 324)
582
+ if (this.curve.chainId === 2222 || this.curve.chainId === 324)
583
583
  return true; // TODO remove this for Kava and ZkSync
584
- if (this.gauge.address === curve.constants.ZERO_ADDRESS)
584
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
585
585
  throw Error(`${this.name} doesn't have gauge`);
586
- return !findAbiFunction(curve.contracts[this.gauge.address].abi, 'inflation_rate')
586
+ return !findAbiFunction(this.curve.contracts[this.gauge.address].abi, 'inflation_rate')
587
587
  .find((func) => ['', 'uint256'].includes(func.inputs.map((a) => `${a.type}`).join(',')));
588
588
  }
589
589
  _pureCalcLpTokenAmount(_amounts_1) {
590
590
  return __awaiter(this, arguments, void 0, function* (_amounts, isDeposit = true, useUnderlying = true) {
591
591
  const calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
592
592
  const N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
593
- const contract = curve.contracts[calcContractAddress].contract;
593
+ const contract = this.curve.contracts[calcContractAddress].contract;
594
594
  if (this.isMetaFactory && useUnderlying) {
595
595
  if (`calc_token_amount(address,uint256[${N_coins}],bool)` in contract) {
596
- return yield contract.calc_token_amount(this.address, _amounts, isDeposit, curve.constantOptions);
596
+ return yield contract.calc_token_amount(this.address, _amounts, isDeposit, this.curve.constantOptions);
597
597
  }
598
- return yield contract.calc_token_amount(this.address, _amounts, curve.constantOptions);
598
+ return yield contract.calc_token_amount(this.address, _amounts, this.curve.constantOptions);
599
599
  }
600
600
  if (`calc_token_amount(uint256[${N_coins}],bool)` in contract) {
601
- return yield contract.calc_token_amount(_amounts, isDeposit, curve.constantOptions);
601
+ return yield contract.calc_token_amount(_amounts, isDeposit, this.curve.constantOptions);
602
602
  }
603
- return yield contract.calc_token_amount(_amounts, curve.constantOptions);
603
+ return yield contract.calc_token_amount(_amounts, this.curve.constantOptions);
604
604
  });
605
605
  }
606
606
  calcLpTokenAmount(amounts_1) {
@@ -610,7 +610,7 @@ export class PoolTemplate extends CorePool {
610
610
  }
611
611
  const _underlyingAmounts = amounts.map((amount, i) => parseUnits(amount, this.underlyingDecimals[i]));
612
612
  const _expected = yield this._calcLpTokenAmount(_underlyingAmounts, isDeposit, true);
613
- return curve.formatUnits(_expected);
613
+ return this.curve.formatUnits(_expected);
614
614
  });
615
615
  }
616
616
  calcLpTokenAmountWrapped(amounts_1) {
@@ -623,7 +623,7 @@ export class PoolTemplate extends CorePool {
623
623
  }
624
624
  const _amounts = amounts.map((amount, i) => parseUnits(amount, this.wrappedDecimals[i]));
625
625
  const _expected = yield this._calcLpTokenAmount(_amounts, isDeposit, false);
626
- return curve.formatUnits(_expected);
626
+ return this.curve.formatUnits(_expected);
627
627
  });
628
628
  }
629
629
  // ---------------- DEPOSIT ----------------
@@ -635,13 +635,13 @@ export class PoolTemplate extends CorePool {
635
635
  if (this.isCrypto) {
636
636
  const decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
637
637
  if (decimals.length === 2) {
638
- const priceScaleBN = toBN(yield curve.contracts[this.address].contract.price_scale(curve.constantOptions));
638
+ const priceScaleBN = toBN(yield this.curve.contracts[this.address].contract.price_scale(this.curve.constantOptions));
639
639
  return [_cutZeros(amount1BN.toFixed(decimals[0])), _cutZeros(amount1BN.div(priceScaleBN).toFixed(decimals[1]))];
640
640
  }
641
641
  else if (decimals.length === 3) {
642
- const priceScaleBN = (yield curve.multicallProvider.all([
643
- curve.contracts[this.address].multicallContract.price_scale(0),
644
- curve.contracts[this.address].multicallContract.price_scale(1),
642
+ const priceScaleBN = (yield this.curve.multicallProvider.all([
643
+ this.curve.contracts[this.address].multicallContract.price_scale(0),
644
+ this.curve.contracts[this.address].multicallContract.price_scale(1),
645
645
  ])).map((_p) => toBN(_p));
646
646
  return [
647
647
  _cutZeros(amount1BN.toFixed(decimals[0])),
@@ -654,7 +654,7 @@ export class PoolTemplate extends CorePool {
654
654
  else {
655
655
  const amounts = [_cutZeros(amount1BN.toFixed(this.wrappedDecimals[0]))];
656
656
  if (this.isMeta && useUnderlying) {
657
- const basePool = new PoolTemplate(this.basePool);
657
+ const basePool = new PoolTemplate(this.basePool, this.curve);
658
658
  const basePoolBalancesBN = (yield basePool.stats.underlyingBalances()).map(BN);
659
659
  const totalBN = basePoolBalancesBN.reduce((a, b) => a.plus(b));
660
660
  for (let i = 1; i < this.underlyingDecimals.length; i++) {
@@ -707,18 +707,18 @@ export class PoolTemplate extends CorePool {
707
707
  depositBonus(amounts) {
708
708
  return __awaiter(this, void 0, void 0, function* () {
709
709
  const amountsBN = amounts.map(BN);
710
- let pricesBN = [];
711
- const multicallContract = curve.contracts[this.address].multicallContract;
710
+ let pricesBN;
711
+ const multicallContract = this.curve.contracts[this.address].multicallContract;
712
712
  if (this.isCrypto || this.id === 'wsteth') {
713
- if (curve.isLiteChain) {
713
+ if (this.curve.isLiteChain) {
714
714
  const prices = this.id.includes('twocrypto')
715
715
  ? [
716
716
  1,
717
- Number(yield curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
717
+ Number(yield this.curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
718
718
  ]
719
719
  : [
720
720
  1,
721
- ...(yield curve.multicallProvider.all([
721
+ ...(yield this.curve.multicallProvider.all([
722
722
  multicallContract.price_oracle(0),
723
723
  multicallContract.price_oracle(1),
724
724
  ])).map((value) => Number(value) / (Math.pow(10, 18))),
@@ -741,17 +741,17 @@ export class PoolTemplate extends CorePool {
741
741
  }
742
742
  depositIsApproved(amounts) {
743
743
  return __awaiter(this, void 0, void 0, function* () {
744
- return yield hasAllowance(this.underlyingCoinAddresses, amounts, curve.signerAddress, this.zap || this.address);
744
+ return yield hasAllowance.call(this.curve, this.underlyingCoinAddresses, amounts, this.curve.signerAddress, this.zap || this.address);
745
745
  });
746
746
  }
747
747
  depositApproveEstimateGas(amounts) {
748
748
  return __awaiter(this, void 0, void 0, function* () {
749
- return yield ensureAllowanceEstimateGas(this.underlyingCoinAddresses, amounts, this.zap || this.address);
749
+ return yield ensureAllowanceEstimateGas.call(this.curve, this.underlyingCoinAddresses, amounts, this.zap || this.address);
750
750
  });
751
751
  }
752
752
  depositApprove(amounts_1) {
753
753
  return __awaiter(this, arguments, void 0, function* (amounts, isMax = true) {
754
- return yield ensureAllowance(this.underlyingCoinAddresses, amounts, this.zap || this.address, isMax);
754
+ return yield ensureAllowance.call(this.curve, this.underlyingCoinAddresses, amounts, this.zap || this.address, isMax);
755
755
  });
756
756
  }
757
757
  // OVERRIDE
@@ -796,7 +796,7 @@ export class PoolTemplate extends CorePool {
796
796
  if (this.isFake) {
797
797
  throw Error(`depositWrappedIsApproved method doesn't exist for pool ${this.name} (id: ${this.name})`);
798
798
  }
799
- return yield hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, this.address);
799
+ return yield hasAllowance.call(this.curve, this.wrappedCoinAddresses, amounts, this.curve.signerAddress, this.address);
800
800
  });
801
801
  }
802
802
  depositWrappedApproveEstimateGas(amounts) {
@@ -804,7 +804,7 @@ export class PoolTemplate extends CorePool {
804
804
  if (this.isFake) {
805
805
  throw Error(`depositWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
806
806
  }
807
- return yield ensureAllowanceEstimateGas(this.wrappedCoinAddresses, amounts, this.address);
807
+ return yield ensureAllowanceEstimateGas.call(this.curve, this.wrappedCoinAddresses, amounts, this.address);
808
808
  });
809
809
  }
810
810
  depositWrappedApprove(amounts) {
@@ -812,7 +812,7 @@ export class PoolTemplate extends CorePool {
812
812
  if (this.isFake) {
813
813
  throw Error(`depositWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
814
814
  }
815
- return yield ensureAllowance(this.wrappedCoinAddresses, amounts, this.address);
815
+ return yield ensureAllowance.call(this.curve, this.wrappedCoinAddresses, amounts, this.address);
816
816
  });
817
817
  }
818
818
  // OVERRIDE
@@ -830,77 +830,77 @@ export class PoolTemplate extends CorePool {
830
830
  // ---------------- STAKING ----------------
831
831
  stakeIsApproved(lpTokenAmount) {
832
832
  return __awaiter(this, void 0, void 0, function* () {
833
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
833
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
834
834
  throw Error(`stakeIsApproved method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
835
835
  }
836
- return yield hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.gauge.address);
836
+ return yield hasAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.curve.signerAddress, this.gauge.address);
837
837
  });
838
838
  }
839
839
  stakeApproveEstimateGas(lpTokenAmount) {
840
840
  return __awaiter(this, void 0, void 0, function* () {
841
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
841
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
842
842
  throw Error(`stakeApproveEstimateGas method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
843
843
  }
844
- return yield ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.gauge.address);
844
+ return yield ensureAllowanceEstimateGas.call(this.curve, [this.lpToken], [lpTokenAmount], this.gauge.address);
845
845
  });
846
846
  }
847
847
  stakeApprove(lpTokenAmount) {
848
848
  return __awaiter(this, void 0, void 0, function* () {
849
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
849
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
850
850
  throw Error(`stakeApprove method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
851
851
  }
852
- return yield ensureAllowance([this.lpToken], [lpTokenAmount], this.gauge.address);
852
+ return yield ensureAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.gauge.address);
853
853
  });
854
854
  }
855
855
  stakeEstimateGas(lpTokenAmount) {
856
856
  return __awaiter(this, void 0, void 0, function* () {
857
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
857
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
858
858
  throw Error(`stakeEstimateGas method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
859
859
  }
860
860
  const _lpTokenAmount = parseUnits(lpTokenAmount);
861
- return smartNumber(yield curve.contracts[this.gauge.address].contract.deposit.estimateGas(_lpTokenAmount, curve.constantOptions));
861
+ return smartNumber(yield this.curve.contracts[this.gauge.address].contract.deposit.estimateGas(_lpTokenAmount, this.curve.constantOptions));
862
862
  });
863
863
  }
864
864
  stake(lpTokenAmount) {
865
865
  return __awaiter(this, void 0, void 0, function* () {
866
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
866
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
867
867
  throw Error(`stake method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
868
868
  }
869
869
  const _lpTokenAmount = parseUnits(lpTokenAmount);
870
- yield _ensureAllowance([this.lpToken], [_lpTokenAmount], this.gauge.address);
871
- yield curve.updateFeeData();
872
- const gasLimit = mulBy1_3(DIGas(yield curve.contracts[this.gauge.address].contract.deposit.estimateGas(_lpTokenAmount, curve.constantOptions)));
873
- return (yield curve.contracts[this.gauge.address].contract.deposit(_lpTokenAmount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
870
+ yield _ensureAllowance.call(this.curve, [this.lpToken], [_lpTokenAmount], this.gauge.address);
871
+ yield this.curve.updateFeeData();
872
+ const gasLimit = mulBy1_3(DIGas(yield this.curve.contracts[this.gauge.address].contract.deposit.estimateGas(_lpTokenAmount, this.curve.constantOptions)));
873
+ return (yield this.curve.contracts[this.gauge.address].contract.deposit(_lpTokenAmount, Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
874
874
  });
875
875
  }
876
876
  unstakeEstimateGas(lpTokenAmount) {
877
877
  return __awaiter(this, void 0, void 0, function* () {
878
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
878
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
879
879
  throw Error(`unstakeEstimateGas method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
880
880
  }
881
881
  const _lpTokenAmount = parseUnits(lpTokenAmount);
882
- return smartNumber(yield curve.contracts[this.gauge.address].contract.withdraw.estimateGas(_lpTokenAmount, curve.constantOptions));
882
+ return smartNumber(yield this.curve.contracts[this.gauge.address].contract.withdraw.estimateGas(_lpTokenAmount, this.curve.constantOptions));
883
883
  });
884
884
  }
885
885
  unstake(lpTokenAmount) {
886
886
  return __awaiter(this, void 0, void 0, function* () {
887
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
887
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
888
888
  throw Error(`unstake method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
889
889
  }
890
890
  const _lpTokenAmount = parseUnits(lpTokenAmount);
891
- yield curve.updateFeeData();
892
- const gasLimit = DIGas((yield curve.contracts[this.gauge.address].contract.withdraw.estimateGas(_lpTokenAmount, curve.constantOptions))) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
893
- return (yield curve.contracts[this.gauge.address].contract.withdraw(_lpTokenAmount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
891
+ yield this.curve.updateFeeData();
892
+ const gasLimit = DIGas((yield this.curve.contracts[this.gauge.address].contract.withdraw.estimateGas(_lpTokenAmount, this.curve.constantOptions))) * this.curve.parseUnits("200", 0) / this.curve.parseUnits("100", 0);
893
+ return (yield this.curve.contracts[this.gauge.address].contract.withdraw(_lpTokenAmount, Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
894
894
  });
895
895
  }
896
896
  claimableCrv() {
897
897
  return __awaiter(this, arguments, void 0, function* (address = "") {
898
898
  if (this.rewardsOnly())
899
899
  throw Error(`${this.name} has Rewards-Only Gauge. Use claimableRewards instead`);
900
- address = address || curve.signerAddress;
900
+ address = address || this.curve.signerAddress;
901
901
  if (!address)
902
902
  throw Error("Need to connect wallet or pass address into args");
903
- return curve.formatUnits(yield curve.contracts[this.gauge.address].contract.claimable_tokens(address, curve.constantOptions));
903
+ return this.curve.formatUnits(yield this.curve.contracts[this.gauge.address].contract.claimable_tokens(address, this.curve.constantOptions));
904
904
  });
905
905
  }
906
906
  claimCrvEstimateGas() {
@@ -909,9 +909,9 @@ export class PoolTemplate extends CorePool {
909
909
  throw Error(`${this.name} has Rewards-Only Gauge. Use claimRewards instead`);
910
910
  let isOldFactory = false;
911
911
  let contract;
912
- if (curve.chainId !== 1) {
913
- if (curve.constants.ALIASES.child_gauge_factory_old && curve.constants.ALIASES.child_gauge_factory_old !== curve.constants.ZERO_ADDRESS) {
914
- const oldFactoryContract = curve.contracts[curve.constants.ALIASES.child_gauge_factory_old].contract;
912
+ if (this.curve.chainId !== 1) {
913
+ if (this.curve.constants.ALIASES.child_gauge_factory_old && this.curve.constants.ALIASES.child_gauge_factory_old !== this.curve.constants.ZERO_ADDRESS) {
914
+ const oldFactoryContract = this.curve.contracts[this.curve.constants.ALIASES.child_gauge_factory_old].contract;
915
915
  const gaugeAddress = yield oldFactoryContract.get_gauge_from_lp_token(this.lpToken);
916
916
  isOldFactory = gaugeAddress.toLowerCase() === this.gauge.address.toLowerCase();
917
917
  if (isOldFactory) {
@@ -920,18 +920,18 @@ export class PoolTemplate extends CorePool {
920
920
  }
921
921
  }
922
922
  if (!isOldFactory) {
923
- contract = curve.chainId === 1 ?
924
- curve.contracts[curve.constants.ALIASES.minter].contract :
925
- curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;
923
+ contract = this.curve.chainId === 1 ?
924
+ this.curve.contracts[this.curve.constants.ALIASES.minter].contract :
925
+ this.curve.contracts[this.curve.constants.ALIASES.child_gauge_factory].contract;
926
926
  }
927
927
  if (!contract) {
928
928
  throw new Error("Failed to find the correct contract for estimating gas");
929
929
  }
930
- if (curve.chainId === 1) {
931
- return Number(yield contract.mint.estimateGas(this.gauge.address, curve.constantOptions));
930
+ if (this.curve.chainId === 1) {
931
+ return Number(yield contract.mint.estimateGas(this.gauge.address, this.curve.constantOptions));
932
932
  }
933
933
  else {
934
- return smartNumber(yield contract.mint.estimateGas(this.gauge.address, curve.constantOptions));
934
+ return smartNumber(yield contract.mint.estimateGas(this.gauge.address, this.curve.constantOptions));
935
935
  }
936
936
  });
937
937
  }
@@ -941,9 +941,9 @@ export class PoolTemplate extends CorePool {
941
941
  throw Error(`${this.name} has Rewards-Only Gauge. Use claimRewards instead`);
942
942
  let isOldFactory = false;
943
943
  let contract;
944
- if (curve.chainId !== 1) {
945
- if (curve.constants.ALIASES.child_gauge_factory_old && curve.constants.ALIASES.child_gauge_factory_old !== curve.constants.ZERO_ADDRESS) {
946
- const oldFactoryContract = curve.contracts[curve.constants.ALIASES.child_gauge_factory_old].contract;
944
+ if (this.curve.chainId !== 1) {
945
+ if (this.curve.constants.ALIASES.child_gauge_factory_old && this.curve.constants.ALIASES.child_gauge_factory_old !== this.curve.constants.ZERO_ADDRESS) {
946
+ const oldFactoryContract = this.curve.contracts[this.curve.constants.ALIASES.child_gauge_factory_old].contract;
947
947
  const gaugeAddress = yield oldFactoryContract.get_gauge_from_lp_token(this.lpToken);
948
948
  isOldFactory = gaugeAddress.toLowerCase() === this.gauge.address.toLowerCase();
949
949
  if (isOldFactory) {
@@ -952,48 +952,48 @@ export class PoolTemplate extends CorePool {
952
952
  }
953
953
  }
954
954
  if (!isOldFactory) {
955
- contract = curve.chainId === 1 ?
956
- curve.contracts[curve.constants.ALIASES.minter].contract :
957
- curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;
955
+ contract = this.curve.chainId === 1 ?
956
+ this.curve.contracts[this.curve.constants.ALIASES.minter].contract :
957
+ this.curve.contracts[this.curve.constants.ALIASES.child_gauge_factory].contract;
958
958
  }
959
959
  if (!contract) {
960
960
  throw new Error("Failed to find the correct contract for minting");
961
961
  }
962
- yield curve.updateFeeData();
963
- const gasLimit = mulBy1_3(DIGas(yield contract.mint.estimateGas(this.gauge.address, curve.constantOptions)));
964
- return (yield contract.mint(this.gauge.address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
962
+ yield this.curve.updateFeeData();
963
+ const gasLimit = mulBy1_3(DIGas(yield contract.mint.estimateGas(this.gauge.address, this.curve.constantOptions)));
964
+ return (yield contract.mint(this.gauge.address, Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
965
965
  });
966
966
  }
967
967
  // TODO 1. Fix aave and saave error
968
968
  claimableRewards() {
969
969
  return __awaiter(this, arguments, void 0, function* (address = "") {
970
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
970
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
971
971
  throw Error(`claimableRewards method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
972
972
  }
973
- address = address || curve.signerAddress;
973
+ address = address || this.curve.signerAddress;
974
974
  if (!address)
975
975
  throw Error("Need to connect wallet or pass address into args");
976
- const gaugeContract = curve.contracts[this.gauge.address].contract;
976
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
977
977
  const rewardTokens = yield this.rewardTokens();
978
978
  const rewards = [];
979
979
  if ('claimable_reward(address,address)' in gaugeContract) {
980
980
  for (const rewardToken of rewardTokens) {
981
- const _amount = yield gaugeContract.claimable_reward(address, rewardToken.token, curve.constantOptions);
981
+ const _amount = yield gaugeContract.claimable_reward(address, rewardToken.token, this.curve.constantOptions);
982
982
  rewards.push({
983
983
  token: rewardToken.token,
984
984
  symbol: rewardToken.symbol,
985
- amount: curve.formatUnits(_amount, rewardToken.decimals),
985
+ amount: this.curve.formatUnits(_amount, rewardToken.decimals),
986
986
  });
987
987
  }
988
988
  }
989
989
  else if ('claimable_reward(address)' in gaugeContract && rewardTokens.length > 0) { // Synthetix Gauge
990
990
  const rewardToken = rewardTokens[0];
991
- const _totalAmount = yield gaugeContract.claimable_reward(address, curve.constantOptions);
992
- const _claimedAmount = yield gaugeContract.claimed_rewards_for(address, curve.constantOptions);
991
+ const _totalAmount = yield gaugeContract.claimable_reward(address, this.curve.constantOptions);
992
+ const _claimedAmount = yield gaugeContract.claimed_rewards_for(address, this.curve.constantOptions);
993
993
  rewards.push({
994
994
  token: rewardToken.token,
995
995
  symbol: rewardToken.symbol,
996
- amount: curve.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
996
+ amount: this.curve.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
997
997
  });
998
998
  }
999
999
  return rewards;
@@ -1001,32 +1001,32 @@ export class PoolTemplate extends CorePool {
1001
1001
  }
1002
1002
  claimRewardsEstimateGas() {
1003
1003
  return __awaiter(this, void 0, void 0, function* () {
1004
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1004
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1005
1005
  throw Error(`claimRewards method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1006
1006
  }
1007
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1007
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1008
1008
  if (!("claim_rewards()" in gaugeContract))
1009
1009
  throw Error(`${this.name} pool doesn't have such method`);
1010
- return smartNumber(yield gaugeContract.claim_rewards.estimateGas(curve.constantOptions));
1010
+ return smartNumber(yield gaugeContract.claim_rewards.estimateGas(this.curve.constantOptions));
1011
1011
  });
1012
1012
  }
1013
1013
  claimRewards() {
1014
1014
  return __awaiter(this, void 0, void 0, function* () {
1015
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1015
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1016
1016
  throw Error(`claimRewards method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1017
1017
  }
1018
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1018
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1019
1019
  if (!("claim_rewards()" in gaugeContract))
1020
1020
  throw Error(`${this.name} pool doesn't have such method`);
1021
- yield curve.updateFeeData();
1022
- const gasLimit = mulBy1_3(DIGas(yield gaugeContract.claim_rewards.estimateGas(curve.constantOptions)));
1023
- return (yield gaugeContract.claim_rewards(Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
1021
+ yield this.curve.updateFeeData();
1022
+ const gasLimit = mulBy1_3(DIGas(yield gaugeContract.claim_rewards.estimateGas(this.curve.constantOptions)));
1023
+ return (yield gaugeContract.claim_rewards(Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
1024
1024
  });
1025
1025
  }
1026
1026
  // ---------------- DEPOSIT & STAKE ----------------
1027
1027
  depositAndStakeExpected(amounts) {
1028
1028
  return __awaiter(this, void 0, void 0, function* () {
1029
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1029
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1030
1030
  throw Error(`depositAndStakeExpected method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1031
1031
  }
1032
1032
  return yield this.depositExpected(amounts);
@@ -1034,7 +1034,7 @@ export class PoolTemplate extends CorePool {
1034
1034
  }
1035
1035
  depositAndStakeBonus(amounts) {
1036
1036
  return __awaiter(this, void 0, void 0, function* () {
1037
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1037
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1038
1038
  throw Error(`depositAndStakeBonus method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1039
1039
  }
1040
1040
  return yield this.depositBonus(amounts);
@@ -1042,13 +1042,13 @@ export class PoolTemplate extends CorePool {
1042
1042
  }
1043
1043
  depositAndStakeIsApproved(amounts) {
1044
1044
  return __awaiter(this, void 0, void 0, function* () {
1045
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1045
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1046
1046
  throw Error(`depositAndStakeIsApproved method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1047
1047
  }
1048
- const coinsAllowance = yield hasAllowance(this.underlyingCoinAddresses, amounts, curve.signerAddress, curve.constants.ALIASES.deposit_and_stake);
1049
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1048
+ const coinsAllowance = yield hasAllowance.call(this.curve, this.underlyingCoinAddresses, amounts, this.curve.signerAddress, this.curve.constants.ALIASES.deposit_and_stake);
1049
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1050
1050
  if ('approved_to_deposit' in gaugeContract) {
1051
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1051
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1052
1052
  return coinsAllowance && gaugeAllowance;
1053
1053
  }
1054
1054
  return coinsAllowance;
@@ -1056,15 +1056,15 @@ export class PoolTemplate extends CorePool {
1056
1056
  }
1057
1057
  depositAndStakeApproveEstimateGas(amounts) {
1058
1058
  return __awaiter(this, void 0, void 0, function* () {
1059
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1059
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1060
1060
  throw Error(`depositAndStakeApprove method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1061
1061
  }
1062
- const approveCoinsGas = yield ensureAllowanceEstimateGas(this.underlyingCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake);
1063
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1062
+ const approveCoinsGas = yield ensureAllowanceEstimateGas.call(this.curve, this.underlyingCoinAddresses, amounts, this.curve.constants.ALIASES.deposit_and_stake);
1063
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1064
1064
  if ('approved_to_deposit' in gaugeContract) {
1065
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1065
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1066
1066
  if (!gaugeAllowance) {
1067
- const approveGaugeGas = smartNumber(yield gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions));
1067
+ const approveGaugeGas = smartNumber(yield gaugeContract.set_approve_deposit.estimateGas(this.curve.constants.ALIASES.deposit_and_stake, true, this.curve.constantOptions));
1068
1068
  if (Array.isArray(approveCoinsGas) && Array.isArray(approveGaugeGas)) {
1069
1069
  return [approveCoinsGas[0] + approveGaugeGas[0], approveCoinsGas[1] + approveGaugeGas[1]];
1070
1070
  }
@@ -1078,16 +1078,16 @@ export class PoolTemplate extends CorePool {
1078
1078
  }
1079
1079
  depositAndStakeApprove(amounts) {
1080
1080
  return __awaiter(this, void 0, void 0, function* () {
1081
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1081
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1082
1082
  throw Error(`depositAndStakeApprove method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1083
1083
  }
1084
- const approveCoinsTx = yield ensureAllowance(this.underlyingCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake);
1085
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1084
+ const approveCoinsTx = yield ensureAllowance.call(this.curve, this.underlyingCoinAddresses, amounts, this.curve.constants.ALIASES.deposit_and_stake);
1085
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1086
1086
  if ('approved_to_deposit' in gaugeContract) {
1087
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1087
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1088
1088
  if (!gaugeAllowance) {
1089
- const gasLimit = mulBy1_3(yield gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions));
1090
- const approveGaugeTx = (yield gaugeContract.set_approve_deposit(curve.constants.ALIASES.deposit_and_stake, true, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
1089
+ const gasLimit = mulBy1_3(yield gaugeContract.set_approve_deposit.estimateGas(this.curve.constants.ALIASES.deposit_and_stake, true, this.curve.constantOptions));
1090
+ const approveGaugeTx = (yield gaugeContract.set_approve_deposit(this.curve.constants.ALIASES.deposit_and_stake, true, Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
1091
1091
  return [...approveCoinsTx, approveGaugeTx];
1092
1092
  }
1093
1093
  }
@@ -1096,7 +1096,7 @@ export class PoolTemplate extends CorePool {
1096
1096
  }
1097
1097
  depositAndStakeEstimateGas(amounts) {
1098
1098
  return __awaiter(this, void 0, void 0, function* () {
1099
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1099
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1100
1100
  throw Error(`depositAndStake method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1101
1101
  }
1102
1102
  return yield this._depositAndStake(amounts, 1, true, true);
@@ -1104,7 +1104,7 @@ export class PoolTemplate extends CorePool {
1104
1104
  }
1105
1105
  depositAndStake(amounts_1) {
1106
1106
  return __awaiter(this, arguments, void 0, function* (amounts, slippage = 0.1) {
1107
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1107
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1108
1108
  throw Error(`depositAndStake method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1109
1109
  }
1110
1110
  return yield this._depositAndStake(amounts, slippage, true, false);
@@ -1113,7 +1113,7 @@ export class PoolTemplate extends CorePool {
1113
1113
  // ---------------- DEPOSIT & STAKE WRAPPED ----------------
1114
1114
  depositAndStakeWrappedExpected(amounts) {
1115
1115
  return __awaiter(this, void 0, void 0, function* () {
1116
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1116
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1117
1117
  throw Error(`depositAndStakeWrappedExpected method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1118
1118
  }
1119
1119
  if (this.isPlain || this.isFake)
@@ -1123,7 +1123,7 @@ export class PoolTemplate extends CorePool {
1123
1123
  }
1124
1124
  depositAndStakeWrappedBonus(amounts) {
1125
1125
  return __awaiter(this, void 0, void 0, function* () {
1126
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1126
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1127
1127
  throw Error(`depositAndStakeWrappedBonus method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1128
1128
  }
1129
1129
  if (this.isPlain || this.isFake)
@@ -1133,15 +1133,15 @@ export class PoolTemplate extends CorePool {
1133
1133
  }
1134
1134
  depositAndStakeWrappedIsApproved(amounts) {
1135
1135
  return __awaiter(this, void 0, void 0, function* () {
1136
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1136
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1137
1137
  throw Error(`depositAndStakeWrappedIsApproved method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1138
1138
  }
1139
1139
  if (this.isPlain || this.isFake)
1140
1140
  throw Error(`depositAndStakeWrappedIsApproved method doesn't exist for pool ${this.name} (id: ${this.name})`);
1141
- const coinsAllowance = yield hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, curve.constants.ALIASES.deposit_and_stake);
1142
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1141
+ const coinsAllowance = yield hasAllowance.call(this.curve, this.wrappedCoinAddresses, amounts, this.curve.signerAddress, this.curve.constants.ALIASES.deposit_and_stake);
1142
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1143
1143
  if ('approved_to_deposit' in gaugeContract) {
1144
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1144
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1145
1145
  return coinsAllowance && gaugeAllowance;
1146
1146
  }
1147
1147
  return coinsAllowance;
@@ -1149,17 +1149,17 @@ export class PoolTemplate extends CorePool {
1149
1149
  }
1150
1150
  depositAndStakeWrappedApproveEstimateGas(amounts) {
1151
1151
  return __awaiter(this, void 0, void 0, function* () {
1152
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1152
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1153
1153
  throw Error(`depositAndStakeWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1154
1154
  }
1155
1155
  if (this.isPlain || this.isFake)
1156
1156
  throw Error(`depositAndStakeWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
1157
- const approveCoinsGas = yield ensureAllowanceEstimateGas(this.wrappedCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake);
1158
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1157
+ const approveCoinsGas = yield ensureAllowanceEstimateGas.call(this.curve, this.wrappedCoinAddresses, amounts, this.curve.constants.ALIASES.deposit_and_stake);
1158
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1159
1159
  if ('approved_to_deposit' in gaugeContract) {
1160
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1160
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1161
1161
  if (!gaugeAllowance) {
1162
- const approveGaugeGas = Number(yield gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions));
1162
+ const approveGaugeGas = Number(yield gaugeContract.set_approve_deposit.estimateGas(this.curve.constants.ALIASES.deposit_and_stake, true, this.curve.constantOptions));
1163
1163
  if (Array.isArray(approveCoinsGas) && Array.isArray(approveGaugeGas)) {
1164
1164
  return [approveCoinsGas[0] + approveGaugeGas[0], approveCoinsGas[1] + approveGaugeGas[1]];
1165
1165
  }
@@ -1173,18 +1173,18 @@ export class PoolTemplate extends CorePool {
1173
1173
  }
1174
1174
  depositAndStakeWrappedApprove(amounts) {
1175
1175
  return __awaiter(this, void 0, void 0, function* () {
1176
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1176
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1177
1177
  throw Error(`depositAndStakeWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1178
1178
  }
1179
1179
  if (this.isPlain || this.isFake)
1180
1180
  throw Error(`depositAndStakeWrappedApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
1181
- const approveCoinsTx = yield ensureAllowance(this.wrappedCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake);
1182
- const gaugeContract = curve.contracts[this.gauge.address].contract;
1181
+ const approveCoinsTx = yield ensureAllowance.call(this.curve, this.wrappedCoinAddresses, amounts, this.curve.constants.ALIASES.deposit_and_stake);
1182
+ const gaugeContract = this.curve.contracts[this.gauge.address].contract;
1183
1183
  if ('approved_to_deposit' in gaugeContract) {
1184
- const gaugeAllowance = yield gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions);
1184
+ const gaugeAllowance = yield gaugeContract.approved_to_deposit(this.curve.constants.ALIASES.deposit_and_stake, this.curve.signerAddress, this.curve.constantOptions);
1185
1185
  if (!gaugeAllowance) {
1186
- const gasLimit = mulBy1_3(yield gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions));
1187
- const approveGaugeTx = (yield gaugeContract.set_approve_deposit(curve.constants.ALIASES.deposit_and_stake, true, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
1186
+ const gasLimit = mulBy1_3(yield gaugeContract.set_approve_deposit.estimateGas(this.curve.constants.ALIASES.deposit_and_stake, true, this.curve.constantOptions));
1187
+ const approveGaugeTx = (yield gaugeContract.set_approve_deposit(this.curve.constants.ALIASES.deposit_and_stake, true, Object.assign(Object.assign({}, this.curve.options), { gasLimit }))).hash;
1188
1188
  return [...approveCoinsTx, approveGaugeTx];
1189
1189
  }
1190
1190
  }
@@ -1193,7 +1193,7 @@ export class PoolTemplate extends CorePool {
1193
1193
  }
1194
1194
  depositAndStakeWrappedEstimateGas(amounts) {
1195
1195
  return __awaiter(this, void 0, void 0, function* () {
1196
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1196
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1197
1197
  throw Error(`depositAndStakeWrapped method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1198
1198
  }
1199
1199
  if (this.isPlain || this.isFake)
@@ -1203,7 +1203,7 @@ export class PoolTemplate extends CorePool {
1203
1203
  }
1204
1204
  depositAndStakeWrapped(amounts_1) {
1205
1205
  return __awaiter(this, arguments, void 0, function* (amounts, slippage = 0.1) {
1206
- if (this.gauge.address === curve.constants.ZERO_ADDRESS) {
1206
+ if (this.gauge.address === this.curve.constants.ZERO_ADDRESS) {
1207
1207
  throw Error(`depositAndStakeWrapped method doesn't exist for pool ${this.name} (id: ${this.name}). There is no gauge`);
1208
1208
  }
1209
1209
  if (this.isPlain || this.isFake)
@@ -1239,34 +1239,28 @@ export class PoolTemplate extends CorePool {
1239
1239
  }
1240
1240
  }
1241
1241
  const _amounts = amounts.map((amount, i) => parseUnits(amount, decimals[i]));
1242
- const contract = curve.contracts[curve.constants.ALIASES.deposit_and_stake].contract;
1242
+ const contract = this.curve.contracts[this.curve.constants.ALIASES.deposit_and_stake].contract;
1243
1243
  const useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && (!this.zap || this.id == 'avaxcrypto');
1244
- const useDynarray = (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg);
1244
+ const useDynarray = (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool, this.curve)).isNg);
1245
1245
  const _expectedLpTokenAmount = isUnderlying ?
1246
- curve.parseUnits(yield this.depositAndStakeExpected(amounts)) :
1247
- curve.parseUnits(yield this.depositAndStakeWrappedExpected(amounts));
1246
+ this.curve.parseUnits(yield this.depositAndStakeExpected(amounts)) :
1247
+ this.curve.parseUnits(yield this.depositAndStakeWrappedExpected(amounts));
1248
1248
  const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
1249
1249
  const _minMintAmount = fromBN(minAmountBN);
1250
1250
  const ethIndex = getEthIndex(coinAddresses);
1251
- const value = _amounts[ethIndex] || curve.parseUnits("0");
1252
- let _gas = BigInt(0);
1253
- if (OLD_CHAINS.includes(curve.chainId)) {
1254
- _gas = (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
1255
- useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.constantOptions), { value })));
1256
- }
1257
- else {
1258
- _gas = (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.constantOptions), { value })));
1259
- }
1251
+ const value = _amounts[ethIndex] || this.curve.parseUnits("0");
1252
+ const _gas = OLD_CHAINS.includes(this.curve.chainId) ? (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
1253
+ useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.constantOptions), { value }))) : (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.constantOptions), { value })));
1260
1254
  if (estimateGas)
1261
1255
  return smartNumber(_gas);
1262
- yield curve.updateFeeData();
1263
- const gasLimit = DIGas(_gas) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
1264
- if (OLD_CHAINS.includes(curve.chainId)) {
1256
+ yield this.curve.updateFeeData();
1257
+ const gasLimit = DIGas(_gas) * this.curve.parseUnits("200", 0) / this.curve.parseUnits("100", 0);
1258
+ if (OLD_CHAINS.includes(this.curve.chainId)) {
1265
1259
  return (yield contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
1266
- useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
1260
+ useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.options), { gasLimit, value }))).hash;
1267
1261
  }
1268
1262
  else {
1269
- return (yield contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
1263
+ return (yield contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.options), { gasLimit, value }))).hash;
1270
1264
  }
1271
1265
  });
1272
1266
  }
@@ -1281,21 +1275,21 @@ export class PoolTemplate extends CorePool {
1281
1275
  return __awaiter(this, void 0, void 0, function* () {
1282
1276
  if (!this.zap)
1283
1277
  return true;
1284
- return yield hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.zap);
1278
+ return yield hasAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.curve.signerAddress, this.zap);
1285
1279
  });
1286
1280
  }
1287
1281
  withdrawApproveEstimateGas(lpTokenAmount) {
1288
1282
  return __awaiter(this, void 0, void 0, function* () {
1289
1283
  if (!this.zap)
1290
1284
  return 0;
1291
- return yield ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.zap);
1285
+ return yield ensureAllowanceEstimateGas.call(this.curve, [this.lpToken], [lpTokenAmount], this.zap);
1292
1286
  });
1293
1287
  }
1294
1288
  withdrawApprove(lpTokenAmount) {
1295
1289
  return __awaiter(this, void 0, void 0, function* () {
1296
1290
  if (!this.zap)
1297
1291
  return [];
1298
- return yield ensureAllowance([this.lpToken], [lpTokenAmount], this.zap);
1292
+ return yield ensureAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.zap);
1299
1293
  });
1300
1294
  }
1301
1295
  // OVERRIDE
@@ -1340,17 +1334,17 @@ export class PoolTemplate extends CorePool {
1340
1334
  withdrawImbalanceBonus(amounts) {
1341
1335
  return __awaiter(this, void 0, void 0, function* () {
1342
1336
  let pricesBN = [];
1343
- const multicallContract = curve.contracts[this.address].multicallContract;
1337
+ const multicallContract = this.curve.contracts[this.address].multicallContract;
1344
1338
  if (this.isCrypto || this.id === 'wsteth') {
1345
- if (curve.isLiteChain) {
1339
+ if (this.curve.isLiteChain) {
1346
1340
  const prices = this.id.includes('twocrypto')
1347
1341
  ? [
1348
1342
  1,
1349
- Number(yield curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
1343
+ Number(yield this.curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
1350
1344
  ]
1351
1345
  : [
1352
1346
  1,
1353
- ...(yield curve.multicallProvider.all([
1347
+ ...(yield this.curve.multicallProvider.all([
1354
1348
  multicallContract.price_oracle(0),
1355
1349
  multicallContract.price_oracle(1),
1356
1350
  ])).map((value) => Number(value) / (Math.pow(10, 18))),
@@ -1377,8 +1371,8 @@ export class PoolTemplate extends CorePool {
1377
1371
  throw Error(`withdrawImbalanceIsApproved method doesn't exist for pool ${this.name} (id: ${this.name})`);
1378
1372
  if (this.zap) {
1379
1373
  const _amounts = amounts.map((amount, i) => parseUnits(amount, this.underlyingDecimals[i]));
1380
- const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
1381
- return yield hasAllowance([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], curve.signerAddress, this.zap);
1374
+ const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * this.curve.parseUnits("101", 0) / this.curve.parseUnits("100", 0);
1375
+ return yield hasAllowance.call(this.curve, [this.lpToken], [this.curve.formatUnits(_maxBurnAmount, 18)], this.curve.signerAddress, this.zap);
1382
1376
  }
1383
1377
  return true;
1384
1378
  });
@@ -1389,8 +1383,8 @@ export class PoolTemplate extends CorePool {
1389
1383
  throw Error(`withdrawImbalanceApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
1390
1384
  if (this.zap) {
1391
1385
  const _amounts = amounts.map((amount, i) => parseUnits(amount, this.underlyingDecimals[i]));
1392
- const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
1393
- return yield ensureAllowanceEstimateGas([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], this.zap);
1386
+ const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * this.curve.parseUnits("101", 0) / this.curve.parseUnits("100", 0);
1387
+ return yield ensureAllowanceEstimateGas.call(this.curve, [this.lpToken], [this.curve.formatUnits(_maxBurnAmount, 18)], this.zap);
1394
1388
  }
1395
1389
  return 0;
1396
1390
  });
@@ -1401,8 +1395,8 @@ export class PoolTemplate extends CorePool {
1401
1395
  throw Error(`withdrawImbalanceApprove method doesn't exist for pool ${this.name} (id: ${this.name})`);
1402
1396
  if (this.zap) {
1403
1397
  const _amounts = amounts.map((amount, i) => parseUnits(amount, this.underlyingDecimals[i]));
1404
- const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
1405
- return yield ensureAllowance([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], this.zap);
1398
+ const _maxBurnAmount = (yield this._calcLpTokenAmount(_amounts, false)) * this.curve.parseUnits("101", 0) / this.curve.parseUnits("100", 0);
1399
+ return yield ensureAllowance.call(this.curve, [this.lpToken], [this.curve.formatUnits(_maxBurnAmount, 18)], this.zap);
1406
1400
  }
1407
1401
  return [];
1408
1402
  });
@@ -1461,23 +1455,23 @@ export class PoolTemplate extends CorePool {
1461
1455
  const i = this._getCoinIdx(coin);
1462
1456
  const _lpTokenAmount = parseUnits(lpTokenAmount);
1463
1457
  const _expected = yield this._withdrawOneCoinExpected(_lpTokenAmount, i);
1464
- return curve.formatUnits(_expected, this.underlyingDecimals[i]);
1458
+ return this.curve.formatUnits(_expected, this.underlyingDecimals[i]);
1465
1459
  });
1466
1460
  }
1467
1461
  withdrawOneCoinBonus(lpTokenAmount, coin) {
1468
1462
  return __awaiter(this, void 0, void 0, function* () {
1469
1463
  let pricesBN = [];
1470
- const multicallContract = curve.contracts[this.address].multicallContract;
1464
+ const multicallContract = this.curve.contracts[this.address].multicallContract;
1471
1465
  if (this.isCrypto || this.id === 'wsteth') {
1472
- if (curve.isLiteChain) {
1466
+ if (this.curve.isLiteChain) {
1473
1467
  const prices = this.id.includes('twocrypto')
1474
1468
  ? [
1475
1469
  1,
1476
- Number(yield curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
1470
+ Number(yield this.curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
1477
1471
  ]
1478
1472
  : [
1479
1473
  1,
1480
- ...(yield curve.multicallProvider.all([
1474
+ ...(yield this.curve.multicallProvider.all([
1481
1475
  multicallContract.price_oracle(0),
1482
1476
  multicallContract.price_oracle(1),
1483
1477
  ])).map((value) => Number(value) / (Math.pow(10, 18))),
@@ -1503,21 +1497,21 @@ export class PoolTemplate extends CorePool {
1503
1497
  return __awaiter(this, void 0, void 0, function* () {
1504
1498
  if (!this.zap)
1505
1499
  return true;
1506
- return yield hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.zap);
1500
+ return yield hasAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.curve.signerAddress, this.zap);
1507
1501
  });
1508
1502
  }
1509
1503
  withdrawOneCoinApproveEstimateGas(lpTokenAmount) {
1510
1504
  return __awaiter(this, void 0, void 0, function* () {
1511
1505
  if (!this.zap)
1512
1506
  return 0;
1513
- return yield ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.zap);
1507
+ return yield ensureAllowanceEstimateGas.call(this.curve, [this.lpToken], [lpTokenAmount], this.zap);
1514
1508
  });
1515
1509
  }
1516
1510
  withdrawOneCoinApprove(lpTokenAmount) {
1517
1511
  return __awaiter(this, void 0, void 0, function* () {
1518
1512
  if (!this.zap)
1519
1513
  return [];
1520
- return yield ensureAllowance([this.lpToken], [lpTokenAmount], this.zap);
1514
+ return yield ensureAllowance.call(this.curve, [this.lpToken], [lpTokenAmount], this.zap);
1521
1515
  });
1522
1516
  }
1523
1517
  // OVERRIDE
@@ -1544,7 +1538,7 @@ export class PoolTemplate extends CorePool {
1544
1538
  const i = this._getCoinIdx(coin, false);
1545
1539
  const _lpTokenAmount = parseUnits(lpTokenAmount);
1546
1540
  const _expected = yield this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i);
1547
- return curve.formatUnits(_expected, this.wrappedDecimals[i]);
1541
+ return this.curve.formatUnits(_expected, this.wrappedDecimals[i]);
1548
1542
  });
1549
1543
  }
1550
1544
  withdrawOneCoinWrappedBonus(lpTokenAmount, coin) {
@@ -1582,7 +1576,7 @@ export class PoolTemplate extends CorePool {
1582
1576
  }
1583
1577
  userBalances() {
1584
1578
  return __awaiter(this, arguments, void 0, function* (address = "") {
1585
- address = address || curve.signerAddress;
1579
+ address = address || this.curve.signerAddress;
1586
1580
  if (!address)
1587
1581
  throw Error("Need to connect wallet or pass address into args");
1588
1582
  const lpTotalBalanceBN = yield this._userLpTotalBalance(address);
@@ -1593,7 +1587,7 @@ export class PoolTemplate extends CorePool {
1593
1587
  }
1594
1588
  userWrappedBalances() {
1595
1589
  return __awaiter(this, arguments, void 0, function* (address = "") {
1596
- address = address || curve.signerAddress;
1590
+ address = address || this.curve.signerAddress;
1597
1591
  if (!address)
1598
1592
  throw Error("Need to connect wallet or pass address into args");
1599
1593
  const lpTotalBalanceBN = yield this._userLpTotalBalance(address);
@@ -1605,7 +1599,7 @@ export class PoolTemplate extends CorePool {
1605
1599
  userLiquidityUSD() {
1606
1600
  return __awaiter(this, arguments, void 0, function* (address = "") {
1607
1601
  const lpBalanceBN = yield this._userLpTotalBalance(address);
1608
- const lpPrice = yield _getUsdRate(this.lpToken);
1602
+ const lpPrice = yield _getUsdRate.call(this.curve, this.lpToken);
1609
1603
  return lpBalanceBN.times(lpPrice).toFixed(8);
1610
1604
  });
1611
1605
  }
@@ -1630,8 +1624,8 @@ export class PoolTemplate extends CorePool {
1630
1624
  }
1631
1625
  userShare() {
1632
1626
  return __awaiter(this, arguments, void 0, function* (address = "") {
1633
- const withGauge = this.gauge.address !== curve.constants.ZERO_ADDRESS;
1634
- address = address || curve.signerAddress;
1627
+ const withGauge = this.gauge.address !== this.curve.constants.ZERO_ADDRESS;
1628
+ address = address || this.curve.signerAddress;
1635
1629
  if (!address)
1636
1630
  throw Error("Need to connect wallet or pass address into args");
1637
1631
  const userLpBalance = yield this.wallet.lpTokenBalances(address);
@@ -1640,13 +1634,13 @@ export class PoolTemplate extends CorePool {
1640
1634
  userLpTotalBalanceBN = userLpTotalBalanceBN.plus(BN(userLpBalance.gauge));
1641
1635
  let totalLp, gaugeLp;
1642
1636
  if (withGauge) {
1643
- [totalLp, gaugeLp] = (yield curve.multicallProvider.all([
1644
- curve.contracts[this.lpToken].multicallContract.totalSupply(),
1645
- curve.contracts[this.gauge.address].multicallContract.totalSupply(),
1646
- ])).map((_supply) => curve.formatUnits(_supply));
1637
+ [totalLp, gaugeLp] = (yield this.curve.multicallProvider.all([
1638
+ this.curve.contracts[this.lpToken].multicallContract.totalSupply(),
1639
+ this.curve.contracts[this.gauge.address].multicallContract.totalSupply(),
1640
+ ])).map((_supply) => this.curve.formatUnits(_supply));
1647
1641
  }
1648
1642
  else {
1649
- totalLp = curve.formatUnits(yield curve.contracts[this.lpToken].contract.totalSupply(curve.constantOptions));
1643
+ totalLp = this.curve.formatUnits(yield this.curve.contracts[this.lpToken].contract.totalSupply(this.curve.constantOptions));
1650
1644
  }
1651
1645
  return {
1652
1646
  lpUser: userLpTotalBalanceBN.toString(),
@@ -1662,15 +1656,15 @@ export class PoolTemplate extends CorePool {
1662
1656
  _swapExpected(i, j, _amount) {
1663
1657
  return __awaiter(this, void 0, void 0, function* () {
1664
1658
  const contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
1665
- const contract = curve.contracts[contractAddress].contract;
1659
+ const contract = this.curve.contracts[contractAddress].contract;
1666
1660
  if ('get_dy_underlying' in contract) {
1667
- return yield contract.get_dy_underlying(i, j, _amount, curve.constantOptions);
1661
+ return yield contract.get_dy_underlying(i, j, _amount, this.curve.constantOptions);
1668
1662
  }
1669
1663
  else {
1670
1664
  if ('get_dy(address,uint256,uint256,uint256)' in contract) { // atricrypto3 based metapools
1671
- return yield contract.get_dy(this.address, i, j, _amount, curve.constantOptions);
1665
+ return yield contract.get_dy(this.address, i, j, _amount, this.curve.constantOptions);
1672
1666
  }
1673
- return yield contract.get_dy(i, j, _amount, curve.constantOptions);
1667
+ return yield contract.get_dy(i, j, _amount, this.curve.constantOptions);
1674
1668
  }
1675
1669
  });
1676
1670
  }
@@ -1680,61 +1674,61 @@ export class PoolTemplate extends CorePool {
1680
1674
  const j = this._getCoinIdx(outputCoin);
1681
1675
  const _amount = parseUnits(amount, this.underlyingDecimals[i]);
1682
1676
  const _expected = yield this._swapExpected(i, j, _amount);
1683
- return curve.formatUnits(_expected, this.underlyingDecimals[j]);
1677
+ return this.curve.formatUnits(_expected, this.underlyingDecimals[j]);
1684
1678
  });
1685
1679
  }
1686
1680
  _swapRequired(i, j, _amount, isUnderlying) {
1687
1681
  return __awaiter(this, void 0, void 0, function* () {
1688
1682
  if (this.isCrypto) {
1689
1683
  if (this.isNg)
1690
- return yield curve.contracts[this.address].contract.get_dx(i, j, _amount, curve.constantOptions);
1691
- const contract = curve.contracts[curve.constants.ALIASES.crypto_calc].contract;
1684
+ return yield this.curve.contracts[this.address].contract.get_dx(i, j, _amount, this.curve.constantOptions);
1685
+ const contract = this.curve.contracts[this.curve.constants.ALIASES.crypto_calc].contract;
1692
1686
  if (this.isMeta && isUnderlying) {
1693
- const basePool = new PoolTemplate(this.basePool);
1687
+ const basePool = new PoolTemplate(this.basePool, this.curve);
1694
1688
  if (this.wrappedCoins.length === 3) {
1695
- return yield contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, curve.constantOptions);
1689
+ return yield contract.get_dx_tricrypto_meta_underlying(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1696
1690
  }
1697
1691
  if (basePool.isFake) {
1698
- const secondPool = new PoolTemplate(basePool.basePool);
1699
- return yield contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, curve.constantOptions);
1692
+ const secondPool = new PoolTemplate(basePool.basePool, this.curve);
1693
+ return yield contract.get_dx_double_meta_underlying(this.address, i, j, _amount, basePool.address, basePool.zap, secondPool.address, secondPool.lpToken, this.curve.constantOptions);
1700
1694
  }
1701
- return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions);
1695
+ return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1702
1696
  }
1703
1697
  else {
1704
- return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions);
1698
+ return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, this.curve.constantOptions);
1705
1699
  }
1706
1700
  }
1707
1701
  else {
1708
1702
  if (this.isNg) {
1709
- const contract = curve.contracts[this.address].contract;
1703
+ const contract = this.curve.contracts[this.address].contract;
1710
1704
  if (this.isMeta) {
1711
1705
  if (isUnderlying) {
1712
- return yield contract.get_dx_underlying(i, j, _amount, curve.constantOptions);
1706
+ return yield contract.get_dx_underlying(i, j, _amount, this.curve.constantOptions);
1713
1707
  }
1714
1708
  else {
1715
- return yield contract.get_dx(i, j, _amount, curve.constantOptions);
1709
+ return yield contract.get_dx(i, j, _amount, this.curve.constantOptions);
1716
1710
  }
1717
1711
  }
1718
1712
  else {
1719
- return yield contract.get_dx(i, j, _amount, curve.constantOptions);
1713
+ return yield contract.get_dx(i, j, _amount, this.curve.constantOptions);
1720
1714
  }
1721
1715
  }
1722
- const contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
1716
+ const contract = this.curve.contracts[this.curve.constants.ALIASES.stable_calc].contract;
1723
1717
  if (this.isMeta) {
1724
- const basePool = new PoolTemplate(this.basePool);
1718
+ const basePool = new PoolTemplate(this.basePool, this.curve);
1725
1719
  if (isUnderlying) {
1726
- return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, curve.constantOptions);
1720
+ return yield contract.get_dx_meta_underlying(this.address, i, j, _amount, this.underlyingCoins.length, basePool.address, basePool.lpToken, this.curve.constantOptions);
1727
1721
  }
1728
1722
  else {
1729
- return yield contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, curve.constantOptions);
1723
+ return yield contract.get_dx_meta(this.address, i, j, _amount, this.wrappedCoins.length, basePool.address, this.curve.constantOptions);
1730
1724
  }
1731
1725
  }
1732
1726
  else {
1733
1727
  if (isUnderlying && this.isLending) {
1734
- return yield contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length, curve.constantOptions);
1728
+ return yield contract.get_dx_underlying(this.address, i, j, _amount, this.underlyingCoins.length, this.curve.constantOptions);
1735
1729
  }
1736
1730
  else {
1737
- return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, curve.constantOptions);
1731
+ return yield contract.get_dx(this.address, i, j, _amount, this.wrappedCoins.length, this.curve.constantOptions);
1738
1732
  }
1739
1733
  }
1740
1734
  }
@@ -1746,7 +1740,7 @@ export class PoolTemplate extends CorePool {
1746
1740
  const j = this._getCoinIdx(outputCoin);
1747
1741
  const _amount = parseUnits(amount, this.underlyingDecimals[j]);
1748
1742
  const _required = yield this._swapRequired(i, j, _amount, true);
1749
- return curve.formatUnits(_required, this.underlyingDecimals[i]);
1743
+ return this.curve.formatUnits(_required, this.underlyingDecimals[i]);
1750
1744
  });
1751
1745
  }
1752
1746
  // OVERRIDE
@@ -1773,27 +1767,27 @@ export class PoolTemplate extends CorePool {
1773
1767
  });
1774
1768
  }
1775
1769
  _swapContractAddress() {
1776
- return (this.isCrypto && this.isMeta) || (this.isMetaFactory && (new PoolTemplate(this.basePool).isLending)) ? this.zap : this.address;
1770
+ return (this.isCrypto && this.isMeta) || (this.isMetaFactory && (new PoolTemplate(this.basePool, this.curve).isLending)) ? this.zap : this.address;
1777
1771
  }
1778
1772
  swapIsApproved(inputCoin, amount) {
1779
1773
  return __awaiter(this, void 0, void 0, function* () {
1780
1774
  const contractAddress = this._swapContractAddress();
1781
1775
  const i = this._getCoinIdx(inputCoin);
1782
- return yield hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress);
1776
+ return yield hasAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [amount], this.curve.signerAddress, contractAddress);
1783
1777
  });
1784
1778
  }
1785
1779
  swapApproveEstimateGas(inputCoin, amount) {
1786
1780
  return __awaiter(this, void 0, void 0, function* () {
1787
1781
  const contractAddress = this._swapContractAddress();
1788
1782
  const i = this._getCoinIdx(inputCoin);
1789
- return yield ensureAllowanceEstimateGas([this.underlyingCoinAddresses[i]], [amount], contractAddress);
1783
+ return yield ensureAllowanceEstimateGas.call(this.curve, [this.underlyingCoinAddresses[i]], [amount], contractAddress);
1790
1784
  });
1791
1785
  }
1792
1786
  swapApprove(inputCoin, amount) {
1793
1787
  return __awaiter(this, void 0, void 0, function* () {
1794
1788
  const contractAddress = this._swapContractAddress();
1795
1789
  const i = this._getCoinIdx(inputCoin);
1796
- return yield ensureAllowance([this.underlyingCoinAddresses[i]], [amount], contractAddress);
1790
+ return yield ensureAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [amount], contractAddress);
1797
1791
  });
1798
1792
  }
1799
1793
  // OVERRIDE
@@ -1811,7 +1805,7 @@ export class PoolTemplate extends CorePool {
1811
1805
  // ---------------- SWAP WRAPPED ----------------
1812
1806
  _swapWrappedExpected(i, j, _amount) {
1813
1807
  return __awaiter(this, void 0, void 0, function* () {
1814
- return yield curve.contracts[this.address].contract.get_dy(i, j, _amount, curve.constantOptions);
1808
+ return yield this.curve.contracts[this.address].contract.get_dy(i, j, _amount, this.curve.constantOptions);
1815
1809
  });
1816
1810
  }
1817
1811
  // OVERRIDE