@curvefi/api 1.25.2 → 2.0.0

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 (213) hide show
  1. package/README.md +775 -589
  2. package/docs/v1/README.md +916 -0
  3. package/lib/boosting.d.ts +12 -12
  4. package/lib/boosting.js +23 -23
  5. package/lib/constants/abis/{json/2pool → 2pool}/swap.json +0 -0
  6. package/lib/constants/abis/{json/3pool → 3pool}/swap.json +0 -0
  7. package/lib/constants/abis/{json/4pool → 4pool}/swap.json +0 -0
  8. package/lib/constants/abis/{json/ERC20.json → ERC20.json} +0 -0
  9. package/lib/constants/abis/{json/aave → aave}/rewards.json +0 -0
  10. package/lib/constants/abis/{json/aave → aave}/swap.json +0 -0
  11. package/lib/constants/abis/{json/address_provider.json → address_provider.json} +0 -0
  12. package/lib/constants/abis/{json/ankreth → ankreth}/sCurveRewards.json +0 -0
  13. package/lib/constants/abis/{json/ankreth → ankreth}/swap.json +0 -0
  14. package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/swap.json +0 -0
  15. package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/zap.json +0 -0
  16. package/lib/constants/abis/{json/bbtc → bbtc}/deposit.json +0 -0
  17. package/lib/constants/abis/{json/bbtc → bbtc}/swap.json +0 -0
  18. package/lib/constants/abis/{json/busd → busd}/deposit.json +0 -0
  19. package/lib/constants/abis/{json/busd → busd}/swap.json +0 -0
  20. package/lib/constants/abis/{json/cERC20.json → cERC20.json} +0 -0
  21. package/lib/constants/abis/{json/compound → compound}/deposit.json +0 -0
  22. package/lib/constants/abis/{json/compound → compound}/swap.json +0 -0
  23. package/lib/constants/abis/{json/crveth → crveth}/swap.json +0 -0
  24. package/lib/constants/abis/{json/deposit_and_stake.json → deposit_and_stake.json} +0 -0
  25. package/lib/constants/abis/{json/dusd → dusd}/deposit.json +0 -0
  26. package/lib/constants/abis/{json/dusd → dusd}/sCurveRewards.json +0 -0
  27. package/lib/constants/abis/{json/dusd → dusd}/swap.json +0 -0
  28. package/lib/constants/abis/{json/eurs → eurs}/sCurveRewards.json +0 -0
  29. package/lib/constants/abis/{json/eurs → eurs}/swap.json +0 -0
  30. package/lib/constants/abis/{json/eursusd → eursusd}/swap.json +0 -0
  31. package/lib/constants/abis/{json/eurt → eurt}/swap.json +0 -0
  32. package/lib/constants/abis/{json/eurtusd → eurtusd}/deposit.json +0 -0
  33. package/lib/constants/abis/{json/eurtusd → eurtusd}/swap.json +0 -0
  34. package/lib/constants/abis/{json/factory-crypto → factory-crypto}/factory-crypto-pool-2.json +0 -0
  35. package/lib/constants/abis/{json/factory-crypto.json → factory-crypto.json} +0 -0
  36. package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaBtcPolygon.json +0 -0
  37. package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaUsdPolygon.json +0 -0
  38. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTC.json +0 -0
  39. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalances.json +0 -0
  40. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalancesRen.json +0 -0
  41. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCRen.json +0 -0
  42. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSD.json +0 -0
  43. package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSDBalances.json +0 -0
  44. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Balances.json +0 -0
  45. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Basic.json +0 -0
  46. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2ETH.json +0 -0
  47. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Optimized.json +0 -0
  48. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Balances.json +0 -0
  49. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Basic.json +0 -0
  50. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3ETH.json +0 -0
  51. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Optimized.json +0 -0
  52. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Balances.json +0 -0
  53. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Basic.json +0 -0
  54. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4ETH.json +0 -0
  55. package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Optimized.json +0 -0
  56. package/lib/constants/abis/{json/factory.json → factory.json} +0 -0
  57. package/lib/constants/abis/{json/factoryPools → factoryPools}/deposit.json +0 -0
  58. package/lib/constants/abis/{json/factoryPools → factoryPools}/rewards.json +0 -0
  59. package/lib/constants/abis/{json/factoryPools → factoryPools}/swap.json +0 -0
  60. package/lib/constants/abis/{json/gauge.json → gauge.json} +0 -0
  61. package/lib/constants/abis/{json/gauge_factory.json → gauge_factory.json} +0 -0
  62. package/lib/constants/abis/{json/gauge_rewards_only.json → gauge_rewards_only.json} +0 -0
  63. package/lib/constants/abis/{json/gauge_synthetix.json → gauge_synthetix.json} +0 -0
  64. package/lib/constants/abis/{json/gauge_v2.json → gauge_v2.json} +0 -0
  65. package/lib/constants/abis/{json/gauge_v3.json → gauge_v3.json} +0 -0
  66. package/lib/constants/abis/{json/gauge_v4.json → gauge_v4.json} +0 -0
  67. package/lib/constants/abis/{json/gauge_v5.json → gauge_v5.json} +0 -0
  68. package/lib/constants/abis/{json/gaugecontroller.json → gaugecontroller.json} +0 -0
  69. package/lib/constants/abis/{json/gusd → gusd}/deposit.json +0 -0
  70. package/lib/constants/abis/{json/gusd → gusd}/swap.json +0 -0
  71. package/lib/constants/abis/{json/hbtc → hbtc}/swap.json +0 -0
  72. package/lib/constants/abis/{json/husd → husd}/deposit.json +0 -0
  73. package/lib/constants/abis/{json/husd → husd}/swap.json +0 -0
  74. package/lib/constants/abis/{json/ib → ib}/swap.json +0 -0
  75. package/lib/constants/abis/{json/iearn → iearn}/deposit.json +0 -0
  76. package/lib/constants/abis/{json/iearn → iearn}/sCurveRewards.json +0 -0
  77. package/lib/constants/abis/{json/iearn → iearn}/swap.json +0 -0
  78. package/lib/constants/abis/{json/link → link}/swap.json +0 -0
  79. package/lib/constants/abis/{json/minter.json → minter.json} +0 -0
  80. package/lib/constants/abis/{json/musd → musd}/deposit.json +0 -0
  81. package/lib/constants/abis/{json/musd → musd}/sCurveRewards.json +0 -0
  82. package/lib/constants/abis/{json/musd → musd}/swap.json +0 -0
  83. package/lib/constants/abis/{json/obtc → obtc}/deposit.json +0 -0
  84. package/lib/constants/abis/{json/obtc → obtc}/sCurveRewards.json +0 -0
  85. package/lib/constants/abis/{json/obtc → obtc}/swap.json +0 -0
  86. package/lib/constants/abis/{json/paave → paave}/rewards.json +0 -0
  87. package/lib/constants/abis/{json/pax → pax}/deposit.json +0 -0
  88. package/lib/constants/abis/{json/pax → pax}/swap.json +0 -0
  89. package/lib/constants/abis/{json/pbtc → pbtc}/deposit.json +0 -0
  90. package/lib/constants/abis/{json/pbtc → pbtc}/sCurveRewards.json +0 -0
  91. package/lib/constants/abis/{json/pbtc → pbtc}/swap.json +0 -0
  92. package/lib/constants/abis/{json/rai → rai}/deposit.json +0 -0
  93. package/lib/constants/abis/{json/rai → rai}/swap.json +0 -0
  94. package/lib/constants/abis/{json/registry_exchange.json → registry_exchange.json} +0 -0
  95. package/lib/constants/abis/{json/ren → ren}/swap.json +0 -0
  96. package/lib/constants/abis/{json/ren-polygon → ren-polygon}/swap.json +0 -0
  97. package/lib/constants/abis/{json/reth → reth}/swap.json +0 -0
  98. package/lib/constants/abis/{json/router.json → router.json} +0 -0
  99. package/lib/constants/abis/{json/rsv → rsv}/deposit.json +0 -0
  100. package/lib/constants/abis/{json/rsv → rsv}/sCurveRewards.json +0 -0
  101. package/lib/constants/abis/{json/rsv → rsv}/swap.json +0 -0
  102. package/lib/constants/abis/{json/saave → saave}/swap.json +0 -0
  103. package/lib/constants/abis/{json/sbtc → sbtc}/sCurveRewards.json +0 -0
  104. package/lib/constants/abis/{json/sbtc → sbtc}/swap.json +0 -0
  105. package/lib/constants/abis/{json/seth → seth}/swap.json +0 -0
  106. package/lib/constants/abis/{json/steth → steth}/sCurveRewards.json +0 -0
  107. package/lib/constants/abis/{json/steth → steth}/swap.json +0 -0
  108. package/lib/constants/abis/{json/streamer.json → streamer.json} +0 -0
  109. package/lib/constants/abis/{json/susdv2 → susdv2}/deposit.json +0 -0
  110. package/lib/constants/abis/{json/susdv2 → susdv2}/sCurveRewards.json +0 -0
  111. package/lib/constants/abis/{json/susdv2 → susdv2}/swap.json +0 -0
  112. package/lib/constants/abis/{json/tbtc → tbtc}/deposit.json +0 -0
  113. package/lib/constants/abis/{json/tbtc → tbtc}/sCurveRewards.json +0 -0
  114. package/lib/constants/abis/{json/tbtc → tbtc}/swap.json +0 -0
  115. package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/deposit.json +0 -0
  116. package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/swap.json +0 -0
  117. package/lib/constants/abis/{json/usdk → usdk}/deposit.json +0 -0
  118. package/lib/constants/abis/{json/usdk → usdk}/swap.json +0 -0
  119. package/lib/constants/abis/{json/usdn → usdn}/deposit.json +0 -0
  120. package/lib/constants/abis/{json/usdn → usdn}/swap.json +0 -0
  121. package/lib/constants/abis/{json/usdp → usdp}/deposit.json +0 -0
  122. package/lib/constants/abis/{json/usdp → usdp}/swap.json +0 -0
  123. package/lib/constants/abis/{json/usdt → usdt}/deposit.json +0 -0
  124. package/lib/constants/abis/{json/usdt → usdt}/swap.json +0 -0
  125. package/lib/constants/abis/{json/ust → ust}/deposit.json +0 -0
  126. package/lib/constants/abis/{json/ust → ust}/swap.json +0 -0
  127. package/lib/constants/abis/{json/votingescrow.json → votingescrow.json} +0 -0
  128. package/lib/constants/abis/{json/yERC20.json → yERC20.json} +0 -0
  129. package/lib/constants/aliases.d.ts +2 -24
  130. package/lib/constants/aliases.js +5 -4
  131. package/lib/constants/{coins-ethereum.d.ts → coins/ethereum.d.ts} +0 -9
  132. package/lib/constants/{coins-ethereum.js → coins/ethereum.js} +12 -23
  133. package/lib/constants/{coins-polygon.d.ts → coins/polygon.d.ts} +0 -12
  134. package/lib/constants/{coins-polygon.js → coins/polygon.js} +8 -20
  135. package/lib/constants/pools/ethereum.d.ts +2 -0
  136. package/lib/constants/{abis/abis-ethereum.js → pools/ethereum.js} +517 -1012
  137. package/lib/constants/pools/index.d.ts +3 -0
  138. package/lib/constants/pools/index.js +7 -0
  139. package/lib/constants/pools/polygon.d.ts +4 -0
  140. package/lib/constants/{abis/abis-polygon.js → pools/polygon.js} +52 -80
  141. package/lib/constants/utils.d.ts +5 -0
  142. package/lib/constants/utils.js +69 -0
  143. package/lib/curve.d.ts +10 -32
  144. package/lib/curve.js +188 -232
  145. package/lib/external-api.d.ts +3 -2
  146. package/lib/external-api.js +18 -1
  147. package/lib/factory/constants.d.ts +15 -15
  148. package/lib/factory/constants.js +19 -19
  149. package/lib/factory/factory-api.d.ts +2 -2
  150. package/lib/factory/factory-api.js +34 -49
  151. package/lib/factory/factory-crypto.d.ts +2 -2
  152. package/lib/factory/factory-crypto.js +23 -31
  153. package/lib/factory/factory.d.ts +2 -2
  154. package/lib/factory/factory.js +53 -66
  155. package/lib/index.d.ts +36 -53
  156. package/lib/index.js +27 -35
  157. package/lib/interfaces.d.ts +25 -67
  158. package/lib/pools/PoolTemplate.d.ts +210 -0
  159. package/lib/pools/PoolTemplate.js +2292 -0
  160. package/lib/pools/index.d.ts +3 -0
  161. package/lib/pools/index.js +7 -0
  162. package/lib/pools/mixins/common.d.ts +3 -0
  163. package/lib/pools/mixins/common.js +77 -0
  164. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +5 -0
  165. package/lib/pools/mixins/depositBalancedAmountsMixins.js +145 -0
  166. package/lib/pools/mixins/depositBonusMixins.d.ts +5 -0
  167. package/lib/pools/mixins/depositBonusMixins.js +164 -0
  168. package/lib/pools/mixins/depositMixins.d.ts +5 -0
  169. package/lib/pools/mixins/depositMixins.js +373 -0
  170. package/lib/pools/mixins/depositWrappedMixins.d.ts +3 -0
  171. package/lib/pools/mixins/depositWrappedMixins.js +243 -0
  172. package/lib/pools/mixins/poolBalancesMixin.d.ts +4 -0
  173. package/lib/pools/mixins/poolBalancesMixin.js +129 -0
  174. package/lib/pools/mixins/swapMixins.d.ts +4 -0
  175. package/lib/pools/mixins/swapMixins.js +313 -0
  176. package/lib/pools/mixins/swapWrappedMixins.d.ts +4 -0
  177. package/lib/pools/mixins/swapWrappedMixins.js +297 -0
  178. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +6 -0
  179. package/lib/pools/mixins/withdrawExpectedMixins.js +164 -0
  180. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +5 -0
  181. package/lib/pools/mixins/withdrawImbalanceMixins.js +348 -0
  182. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +3 -0
  183. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +207 -0
  184. package/lib/pools/mixins/withdrawMixins.d.ts +5 -0
  185. package/lib/pools/mixins/withdrawMixins.js +347 -0
  186. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +5 -0
  187. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +104 -0
  188. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +5 -0
  189. package/lib/pools/mixins/withdrawOneCoinMixins.js +347 -0
  190. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +3 -0
  191. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +72 -0
  192. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +3 -0
  193. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +205 -0
  194. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +3 -0
  195. package/lib/pools/mixins/withdrawWrappedMixins.js +206 -0
  196. package/lib/pools/poolConstructor.d.ts +2 -0
  197. package/lib/pools/poolConstructor.js +228 -0
  198. package/lib/pools/utils.d.ts +4 -0
  199. package/lib/pools/utils.js +85 -0
  200. package/lib/router.d.ts +12 -0
  201. package/lib/router.js +624 -0
  202. package/lib/utils.d.ts +10 -16
  203. package/lib/utils.js +33 -126
  204. package/package.json +1 -1
  205. package/lib/constants/abis/abis-ethereum.d.ts +0 -4
  206. package/lib/constants/abis/abis-polygon.d.ts +0 -4
  207. package/lib/constants/abis/json/aRewards.json +0 -1
  208. package/lib/constants/abis/json/compound/migration.json +0 -57
  209. package/lib/constants/abis/json/compound/oldSwap.json +0 -688
  210. package/lib/constants/abis/json/ren/adapter.json +0 -1
  211. package/lib/constants/abis/json/sbtc/adapter.json +0 -1
  212. package/lib/pools.d.ts +0 -267
  213. package/lib/pools.js +0 -4752
@@ -0,0 +1,2292 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.PoolTemplate = void 0;
60
+ var ethers_1 = require("ethers");
61
+ var external_api_1 = require("../external-api");
62
+ var utils_1 = require("../utils");
63
+ var curve_1 = require("../curve");
64
+ var PoolTemplate = /** @class */ (function () {
65
+ function PoolTemplate(id) {
66
+ var _this = this;
67
+ this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
68
+ var multicallContract, calls, additionalCalls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
69
+ return __generator(this, function (_f) {
70
+ switch (_f.label) {
71
+ case 0:
72
+ multicallContract = curve_1.curve.contracts[this.address].multicallContract;
73
+ calls = [
74
+ multicallContract.get_virtual_price(),
75
+ multicallContract.fee(),
76
+ multicallContract.admin_fee(),
77
+ multicallContract.A(),
78
+ ];
79
+ if (this.isCrypto)
80
+ calls.push(multicallContract.gamma());
81
+ additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
82
+ if ('initial_A' in multicallContract) {
83
+ additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
84
+ }
85
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
86
+ case 1:
87
+ _a = _f.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
88
+ _c = [
89
+ ethers_1.ethers.utils.formatUnits(_virtualPrice),
90
+ ethers_1.ethers.utils.formatUnits(_fee, 8),
91
+ ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
92
+ ethers_1.ethers.utils.formatUnits(_A, 0),
93
+ _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
94
+ ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
95
+ A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
96
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
97
+ case 2:
98
+ _d = _f.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
99
+ _e = [
100
+ _future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
101
+ _initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
102
+ _future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
103
+ _initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
104
+ ], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
105
+ return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
106
+ }
107
+ });
108
+ }); };
109
+ this.statsTotalLiquidity = function (useApi) {
110
+ if (useApi === void 0) { useApi = true; }
111
+ return __awaiter(_this, void 0, void 0, function () {
112
+ var network, poolType, poolsData, totalLiquidity_1, balances, promises, _i, _a, addr, prices, totalLiquidity;
113
+ var _this = this;
114
+ return __generator(this, function (_c) {
115
+ switch (_c.label) {
116
+ case 0:
117
+ if (!useApi) return [3 /*break*/, 2];
118
+ network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
119
+ poolType = !this.isFactory && !this.isCrypto ? "main" :
120
+ !this.isFactory ? "crypto" :
121
+ !(this.isCrypto && this.isFactory) ? "factory" :
122
+ "factory-crypto";
123
+ return [4 /*yield*/, (0, external_api_1._getPoolsFromApi)(network, poolType)];
124
+ case 1:
125
+ poolsData = (_c.sent()).poolData;
126
+ try {
127
+ totalLiquidity_1 = poolsData.filter(function (data) { return data.address.toLowerCase() === _this.address.toLowerCase(); })[0].usdTotal;
128
+ return [2 /*return*/, String(totalLiquidity_1)];
129
+ }
130
+ catch (err) {
131
+ console.log(err.message);
132
+ }
133
+ _c.label = 2;
134
+ case 2: return [4 /*yield*/, this.statsUnderlyingBalances()];
135
+ case 3:
136
+ balances = _c.sent();
137
+ promises = [];
138
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
139
+ addr = _a[_i];
140
+ promises.push((0, utils_1._getUsdRate)(addr));
141
+ }
142
+ return [4 /*yield*/, Promise.all(promises)];
143
+ case 4:
144
+ prices = _c.sent();
145
+ totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
146
+ return [2 /*return*/, totalLiquidity.toFixed(8)];
147
+ }
148
+ });
149
+ });
150
+ };
151
+ this.statsVolume = function () { return __awaiter(_this, void 0, void 0, function () {
152
+ var network, poolsData, poolData;
153
+ var _this = this;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
158
+ return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
159
+ case 1:
160
+ poolsData = (_a.sent());
161
+ poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
162
+ if (!poolData)
163
+ throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
164
+ return [2 /*return*/, poolData.volumeUSD.toString()];
165
+ }
166
+ });
167
+ }); };
168
+ this.statsBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
169
+ var network, poolsData, poolData;
170
+ var _this = this;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
175
+ return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
176
+ case 1:
177
+ poolsData = (_a.sent());
178
+ poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
179
+ if (!poolData)
180
+ throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
181
+ return [2 /*return*/, {
182
+ day: poolData.latestDailyApy.toString(),
183
+ week: poolData.latestWeeklyApy.toString(),
184
+ }];
185
+ }
186
+ });
187
+ }); };
188
+ this.statsTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
189
+ var gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _a, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
190
+ return __generator(this, function (_c) {
191
+ switch (_c.label) {
192
+ case 0:
193
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
194
+ throw Error("".concat(this.name, " doesn't have gauge"));
195
+ if (curve_1.curve.chainId === 137)
196
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
197
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
198
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
199
+ gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
200
+ return [4 /*yield*/, this.statsTotalLiquidity()];
201
+ case 1:
202
+ totalLiquidityUSD = _c.sent();
203
+ if (Number(totalLiquidityUSD) === 0)
204
+ return [2 /*return*/, ["0", "0"]];
205
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
206
+ gaugeContract.inflation_rate(),
207
+ gaugeControllerContract.gauge_relative_weight(this.gauge),
208
+ gaugeContract.working_supply(),
209
+ lpTokenContract.totalSupply(),
210
+ ])];
211
+ case 2:
212
+ _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
213
+ if (Number(workingSupply) === 0)
214
+ return [2 /*return*/, ["0", "0"]];
215
+ rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
216
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
217
+ case 3:
218
+ crvRate = _c.sent();
219
+ baseApy = rate.times(crvRate);
220
+ boostedApy = baseApy.times(2.5);
221
+ return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
222
+ }
223
+ });
224
+ }); };
225
+ this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
226
+ var apy, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, network, promises, _d, mainPoolsRewards, allTypesExtendedPoolData, rewards, _e, _f, extendedPoolData, _g, _h, pool;
227
+ var _j;
228
+ return __generator(this, function (_k) {
229
+ switch (_k.label) {
230
+ case 0:
231
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
232
+ apy = [];
233
+ _i = 0, _a = this.rewardTokens;
234
+ _k.label = 1;
235
+ case 1:
236
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
237
+ rewardToken = _a[_i];
238
+ rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
239
+ return [4 /*yield*/, this.statsTotalLiquidity()];
240
+ case 2:
241
+ totalLiquidityUSD = _k.sent();
242
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
243
+ case 3:
244
+ crvRate = _k.sent();
245
+ _c = utils_1.toBN;
246
+ return [4 /*yield*/, rewardContract.reward_data(curve_1.curve.constants.ALIASES.crv, curve_1.curve.constantOptions)];
247
+ case 4:
248
+ inflation = _c.apply(void 0, [(_k.sent()).rate]);
249
+ baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
250
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
251
+ return [4 /*yield*/, rewardTokenContract.symbol()];
252
+ case 5:
253
+ symbol = _k.sent();
254
+ apy.push({
255
+ gaugeAddress: this.gauge.toLowerCase(),
256
+ tokenAddress: rewardToken,
257
+ symbol: symbol,
258
+ apy: Number(baseApy.times(100).toFixed(4)),
259
+ });
260
+ _k.label = 6;
261
+ case 6:
262
+ _i++;
263
+ return [3 /*break*/, 1];
264
+ case 7: return [2 /*return*/, apy];
265
+ case 8:
266
+ network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
267
+ promises = [
268
+ (0, external_api_1._getMainPoolsGaugeRewards)(),
269
+ (0, external_api_1._getPoolsFromApi)(network, "main"),
270
+ (0, external_api_1._getPoolsFromApi)(network, "crypto"),
271
+ (0, external_api_1._getPoolsFromApi)(network, "factory"),
272
+ (0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
273
+ ];
274
+ return [4 /*yield*/, Promise.all(promises)];
275
+ case 9:
276
+ _d = _k.sent(), mainPoolsRewards = _d[0], allTypesExtendedPoolData = _d.slice(1);
277
+ rewards = mainPoolsRewards;
278
+ for (_e = 0, _f = allTypesExtendedPoolData; _e < _f.length; _e++) {
279
+ extendedPoolData = _f[_e];
280
+ for (_g = 0, _h = extendedPoolData.poolData; _g < _h.length; _g++) {
281
+ pool = _h[_g];
282
+ if (pool.gaugeAddress && pool.gaugeRewards) {
283
+ rewards[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
284
+ }
285
+ }
286
+ }
287
+ return [2 /*return*/, (_j = rewards[this.gauge.toLowerCase()]) !== null && _j !== void 0 ? _j : []];
288
+ }
289
+ });
290
+ }); };
291
+ // ---------------- ... ----------------
292
+ this.gaugeMaxBoostedDeposit = function () {
293
+ var addresses = [];
294
+ for (var _i = 0; _i < arguments.length; _i++) {
295
+ addresses[_i] = arguments[_i];
296
+ }
297
+ return __awaiter(_this, void 0, void 0, function () {
298
+ var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _a, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _c, _d, entry;
299
+ return __generator(this, function (_e) {
300
+ switch (_e.label) {
301
+ case 0:
302
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
303
+ throw Error("".concat(this.name, " doesn't have gauge"));
304
+ if (addresses.length == 1 && Array.isArray(addresses[0]))
305
+ addresses = addresses[0];
306
+ votingEscrowContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.voting_escrow].multicallContract;
307
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
308
+ contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
309
+ addresses.forEach(function (account) {
310
+ contractCalls.push(votingEscrowContract.balanceOf(account));
311
+ });
312
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
313
+ case 1:
314
+ _response = _e.sent();
315
+ responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
316
+ _a = responseBN.splice(0, 2), veTotalSupplyBN = _a[0], gaugeTotalSupplyBN = _a[1];
317
+ resultBN = {};
318
+ addresses.forEach(function (acct, i) {
319
+ resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
320
+ });
321
+ result = {};
322
+ for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
323
+ entry = _d[_c];
324
+ result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
325
+ }
326
+ return [2 /*return*/, result];
327
+ }
328
+ });
329
+ });
330
+ };
331
+ this.gaugeOptimalDeposits = function () {
332
+ var accounts = [];
333
+ for (var _i = 0; _i < arguments.length; _i++) {
334
+ accounts[_i] = arguments[_i];
335
+ }
336
+ return __awaiter(_this, void 0, void 0, function () {
337
+ var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, response, _a, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _c, accounts_1, acct, totalPower, optimalBN, _d, accounts_2, acct, amount, _e, accounts_3, acct, optimal, _f, _g, entry;
338
+ return __generator(this, function (_h) {
339
+ switch (_h.label) {
340
+ case 0:
341
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
342
+ throw Error("".concat(this.name, " doesn't have gauge"));
343
+ if (accounts.length == 1 && Array.isArray(accounts[0]))
344
+ accounts = accounts[0];
345
+ votingEscrowContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.voting_escrow].multicallContract;
346
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
347
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
348
+ contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
349
+ accounts.forEach(function (account) {
350
+ contractCalls.push(votingEscrowContract.balanceOf(account), lpTokenContract.balanceOf(account), gaugeContract.balanceOf(account));
351
+ });
352
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
353
+ case 1:
354
+ _response = _h.sent();
355
+ response = _response.map(function (value) { return (0, utils_1.toBN)(value); });
356
+ _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
357
+ votingPower = {};
358
+ totalBalance = (0, utils_1.BN)(0);
359
+ for (_c = 0, accounts_1 = accounts; _c < accounts_1.length; _c++) {
360
+ acct = accounts_1[_c];
361
+ votingPower[acct] = response[0];
362
+ totalBalance = totalBalance.plus(response[1]).plus(response[2]);
363
+ response.splice(0, 3);
364
+ }
365
+ totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
366
+ optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
367
+ if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
368
+ for (_d = 0, accounts_2 = accounts; _d < accounts_2.length; _d++) {
369
+ acct = accounts_2[_d];
370
+ amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
371
+ gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
372
+ optimalBN[acct] = amount;
373
+ totalBalance = totalBalance.minus(amount);
374
+ if (totalBalance.lte(0)) {
375
+ break;
376
+ }
377
+ }
378
+ }
379
+ else {
380
+ if (totalPower.lt(0)) {
381
+ for (_e = 0, accounts_3 = accounts; _e < accounts_3.length; _e++) {
382
+ acct = accounts_3[_e];
383
+ optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
384
+ }
385
+ }
386
+ optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
387
+ }
388
+ optimal = {};
389
+ for (_f = 0, _g = Object.entries(optimalBN); _f < _g.length; _f++) {
390
+ entry = _g[_f];
391
+ optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
392
+ }
393
+ return [2 /*return*/, optimal];
394
+ }
395
+ });
396
+ });
397
+ };
398
+ this.boost = function (address) { return __awaiter(_this, void 0, void 0, function () {
399
+ var gaugeContract, _a, workingBalance, balance, boost;
400
+ return __generator(this, function (_c) {
401
+ switch (_c.label) {
402
+ case 0:
403
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
404
+ throw Error("".concat(this.name, " doesn't have gauge"));
405
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
406
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
407
+ gaugeContract.working_balances(address),
408
+ gaugeContract.balanceOf(address),
409
+ ])];
410
+ case 1:
411
+ _a = (_c.sent()).map(function (value) { return Number(ethers_1.ethers.utils.formatUnits(value)); }), workingBalance = _a[0], balance = _a[1];
412
+ boost = workingBalance / (0.4 * balance);
413
+ return [2 /*return*/, boost.toFixed(4).replace(/([0-9])0+$/, '$1')];
414
+ }
415
+ });
416
+ }); };
417
+ this._getCoinIdx = function (coin, useUnderlying) {
418
+ if (useUnderlying === void 0) { useUnderlying = true; }
419
+ if (typeof coin === 'number') {
420
+ var coins_N = useUnderlying ? _this.underlyingCoins.length : _this.wrappedCoins.length;
421
+ var idx_1 = coin;
422
+ if (!Number.isInteger(idx_1)) {
423
+ throw Error('Index must be integer');
424
+ }
425
+ if (idx_1 < 0) {
426
+ throw Error('Index must be >= 0');
427
+ }
428
+ if (idx_1 > coins_N - 1) {
429
+ throw Error("Index must be < ".concat(coins_N));
430
+ }
431
+ return idx_1;
432
+ }
433
+ var coinAddress = (0, utils_1._getCoinAddresses)(coin)[0];
434
+ var lowerCaseCoinAddresses = useUnderlying ?
435
+ _this.underlyingCoinAddresses.map(function (c) { return c.toLowerCase(); }) :
436
+ _this.wrappedCoinAddresses.map(function (c) { return c.toLowerCase(); });
437
+ var idx = lowerCaseCoinAddresses.indexOf(coinAddress.toLowerCase());
438
+ if (idx === -1) {
439
+ throw Error("There is no ".concat(coin, " in ").concat(_this.name, " pool")); // TODO add wrapped or underlying
440
+ }
441
+ return idx;
442
+ };
443
+ this._getRates = function () { return __awaiter(_this, void 0, void 0, function () {
444
+ var _rates, i, addr, _a, _c, _d, _e;
445
+ return __generator(this, function (_f) {
446
+ switch (_f.label) {
447
+ case 0:
448
+ _rates = [];
449
+ i = 0;
450
+ _f.label = 1;
451
+ case 1:
452
+ if (!(i < this.wrappedCoinAddresses.length)) return [3 /*break*/, 9];
453
+ addr = this.wrappedCoinAddresses[i];
454
+ if (!this.useLending[i]) return [3 /*break*/, 7];
455
+ if (!['compound', 'usdt', 'ib'].includes(this.id)) return [3 /*break*/, 3];
456
+ _c = (_a = _rates).push;
457
+ return [4 /*yield*/, curve_1.curve.contracts[addr].contract.exchangeRateStored()];
458
+ case 2:
459
+ _c.apply(_a, [_f.sent()]);
460
+ return [3 /*break*/, 6];
461
+ case 3:
462
+ if (!['y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 5];
463
+ _e = (_d = _rates).push;
464
+ return [4 /*yield*/, curve_1.curve.contracts[addr].contract.getPricePerFullShare()];
465
+ case 4:
466
+ _e.apply(_d, [_f.sent()]);
467
+ return [3 /*break*/, 6];
468
+ case 5:
469
+ _rates.push(ethers_1.ethers.BigNumber.from(10).pow(18)); // Aave ratio 1:1
470
+ _f.label = 6;
471
+ case 6: return [3 /*break*/, 8];
472
+ case 7:
473
+ _rates.push(ethers_1.ethers.BigNumber.from(10).pow(18));
474
+ _f.label = 8;
475
+ case 8:
476
+ i++;
477
+ return [3 /*break*/, 1];
478
+ case 9: return [2 /*return*/, _rates];
479
+ }
480
+ });
481
+ }); };
482
+ this._balances = function (rawCoinNames, rawCoinAddresses) {
483
+ var addresses = [];
484
+ for (var _i = 2; _i < arguments.length; _i++) {
485
+ addresses[_i - 2] = arguments[_i];
486
+ }
487
+ return __awaiter(_this, void 0, void 0, function () {
488
+ var coinNames, coinAddresses, i, rawBalances, balances, _a, addresses_1, address, _c, coinNames_1, coinName;
489
+ return __generator(this, function (_d) {
490
+ switch (_d.label) {
491
+ case 0:
492
+ coinNames = [];
493
+ coinAddresses = [];
494
+ // removing duplicates
495
+ for (i = 0; i < rawCoinAddresses.length; i++) {
496
+ if (!coinAddresses.includes(rawCoinAddresses[i])) {
497
+ coinNames.push(rawCoinNames[i]);
498
+ coinAddresses.push(rawCoinAddresses[i]);
499
+ }
500
+ }
501
+ addresses = (0, utils_1._prepareAddresses)(addresses);
502
+ return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
503
+ case 1:
504
+ rawBalances = _d.sent();
505
+ balances = {};
506
+ for (_a = 0, addresses_1 = addresses; _a < addresses_1.length; _a++) {
507
+ address = addresses_1[_a];
508
+ balances[address] = {};
509
+ for (_c = 0, coinNames_1 = coinNames; _c < coinNames_1.length; _c++) {
510
+ coinName = coinNames_1[_c];
511
+ balances[address][coinName] = rawBalances[address].shift();
512
+ }
513
+ }
514
+ return [2 /*return*/, addresses.length === 1 ? balances[addresses[0]] : balances];
515
+ }
516
+ });
517
+ });
518
+ };
519
+ this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
520
+ var promises, _i, _a, addr;
521
+ return __generator(this, function (_c) {
522
+ switch (_c.label) {
523
+ case 0:
524
+ promises = [];
525
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
526
+ addr = _a[_i];
527
+ promises.push((0, utils_1._getUsdRate)(addr));
528
+ }
529
+ return [4 /*yield*/, Promise.all(promises)];
530
+ case 1: return [2 /*return*/, _c.sent()];
531
+ }
532
+ });
533
+ }); };
534
+ // NOTE! It may crash!
535
+ this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
536
+ var promises, _i, _a, addr;
537
+ return __generator(this, function (_c) {
538
+ switch (_c.label) {
539
+ case 0:
540
+ promises = [];
541
+ for (_i = 0, _a = this.wrappedCoinAddresses; _i < _a.length; _i++) {
542
+ addr = _a[_i];
543
+ promises.push((0, utils_1._getUsdRate)(addr));
544
+ }
545
+ return [4 /*yield*/, Promise.all(promises)];
546
+ case 1: return [2 /*return*/, _c.sent()];
547
+ }
548
+ });
549
+ }); };
550
+ this._withdrawCryptoBonus = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
551
+ if (useUnderlying === void 0) { useUnderlying = true; }
552
+ return __awaiter(_this, void 0, void 0, function () {
553
+ var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
554
+ return __generator(this, function (_d) {
555
+ switch (_d.label) {
556
+ case 0:
557
+ if (!useUnderlying) return [3 /*break*/, 2];
558
+ return [4 /*yield*/, this._underlyingPrices()];
559
+ case 1:
560
+ _a = _d.sent();
561
+ return [3 /*break*/, 4];
562
+ case 2: return [4 /*yield*/, this._wrappedPrices()];
563
+ case 3:
564
+ _a = _d.sent();
565
+ _d.label = 4;
566
+ case 4:
567
+ prices = _a;
568
+ if (!useUnderlying) return [3 /*break*/, 6];
569
+ return [4 /*yield*/, this.withdrawExpected(String(lpTokenAmount))];
570
+ case 5:
571
+ _c = _d.sent();
572
+ return [3 /*break*/, 8];
573
+ case 6: return [4 /*yield*/, this.withdrawWrappedExpected(String(lpTokenAmount))];
574
+ case 7:
575
+ _c = _d.sent();
576
+ _d.label = 8;
577
+ case 8:
578
+ balancedAmounts = _c;
579
+ balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
580
+ return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / totalAmountUSD * 100)];
581
+ }
582
+ });
583
+ });
584
+ };
585
+ // TODO make the same as _withdrawCryptoBonus
586
+ this._withdrawBonus = function (totalAmount, expected, useUnderlying) {
587
+ if (useUnderlying === void 0) { useUnderlying = true; }
588
+ return __awaiter(_this, void 0, void 0, function () {
589
+ var poolBalances, _a, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _c, _d, _e;
590
+ return __generator(this, function (_f) {
591
+ switch (_f.label) {
592
+ case 0:
593
+ if (!useUnderlying) return [3 /*break*/, 2];
594
+ return [4 /*yield*/, this.stats.underlyingBalances()];
595
+ case 1:
596
+ _a = (_f.sent()).map(Number);
597
+ return [3 /*break*/, 4];
598
+ case 2: return [4 /*yield*/, this.stats.wrappedBalances()];
599
+ case 3:
600
+ _a = (_f.sent()).map(Number);
601
+ _f.label = 4;
602
+ case 4:
603
+ poolBalances = _a;
604
+ poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
605
+ poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
606
+ balancedAmounts = poolBalancesRatios.map(function (r) { return String(r * totalAmount); });
607
+ if (!useUnderlying) return [3 /*break*/, 6];
608
+ _d = Number;
609
+ return [4 /*yield*/, this.withdrawImbalanceExpected(balancedAmounts)];
610
+ case 5:
611
+ _c = _d.apply(void 0, [_f.sent()]);
612
+ return [3 /*break*/, 8];
613
+ case 6:
614
+ _e = Number;
615
+ return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(balancedAmounts)];
616
+ case 7:
617
+ _c = _e.apply(void 0, [_f.sent()]);
618
+ _f.label = 8;
619
+ case 8:
620
+ balancedExpected = _c;
621
+ return [2 /*return*/, String((balancedExpected - expected) / balancedExpected * 100)];
622
+ }
623
+ });
624
+ });
625
+ };
626
+ var poolData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA)[id];
627
+ this.id = id;
628
+ this.name = poolData.name;
629
+ this.fullName = poolData.full_name;
630
+ this.symbol = poolData.symbol;
631
+ this.referenceAsset = poolData.reference_asset;
632
+ this.address = poolData.swap_address;
633
+ this.lpToken = poolData.token_address;
634
+ this.gauge = poolData.gauge_address;
635
+ this.zap = poolData.deposit_address || null;
636
+ this.rewardContract = poolData.reward_contract || null;
637
+ this.isPlain = poolData.is_plain || false;
638
+ this.isLending = poolData.is_lending || false;
639
+ this.isMeta = poolData.is_meta || false;
640
+ this.isCrypto = poolData.is_crypto || false;
641
+ this.isFake = poolData.is_fake || false;
642
+ this.isFactory = poolData.is_factory || false;
643
+ this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
644
+ this.basePool = poolData.base_pool || '';
645
+ this.underlyingCoins = poolData.underlying_coins;
646
+ this.wrappedCoins = poolData.wrapped_coins;
647
+ this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
648
+ this.wrappedCoinAddresses = poolData.wrapped_coin_addresses;
649
+ this.underlyingDecimals = poolData.underlying_decimals;
650
+ this.wrappedDecimals = poolData.wrapped_decimals;
651
+ this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(function () { return false; });
652
+ this.rewardTokens = poolData.reward_tokens || [];
653
+ this.estimateGas = {
654
+ depositApprove: this.depositApproveEstimateGas.bind(this),
655
+ deposit: this.depositEstimateGas.bind(this),
656
+ depositWrappedApprove: this.depositWrappedApproveEstimateGas.bind(this),
657
+ depositWrapped: this.depositWrappedEstimateGas.bind(this),
658
+ stakeApprove: this.stakeApproveEstimateGas.bind(this),
659
+ stake: this.stakeEstimateGas.bind(this),
660
+ unstake: this.unstakeEstimateGas.bind(this),
661
+ claimCrv: this.claimCrvEstimateGas.bind(this),
662
+ claimRewards: this.claimRewardsEstimateGas.bind(this),
663
+ depositAndStakeApprove: this.depositAndStakeApproveEstimateGas.bind(this),
664
+ depositAndStake: this.depositAndStakeEstimateGas.bind(this),
665
+ depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas.bind(this),
666
+ depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas.bind(this),
667
+ withdrawApprove: this.withdrawApproveEstimateGas.bind(this),
668
+ withdraw: this.withdrawEstimateGas.bind(this),
669
+ withdrawWrapped: this.withdrawWrappedEstimateGas.bind(this),
670
+ withdrawImbalanceApprove: this.withdrawImbalanceApproveEstimateGas.bind(this),
671
+ withdrawImbalance: this.withdrawImbalanceEstimateGas.bind(this),
672
+ withdrawImbalanceWrapped: this.withdrawImbalanceWrappedEstimateGas.bind(this),
673
+ withdrawOneCoinApprove: this.withdrawOneCoinApproveEstimateGas.bind(this),
674
+ withdrawOneCoin: this.withdrawOneCoinEstimateGas.bind(this),
675
+ withdrawOneCoinWrapped: this.withdrawOneCoinWrappedEstimateGas.bind(this),
676
+ swapApprove: this.swapApproveEstimateGas.bind(this),
677
+ swap: this.swapEstimateGas.bind(this),
678
+ swapWrappedApprove: this.swapWrappedApproveEstimateGas.bind(this),
679
+ swapWrapped: this.swapWrappedEstimateGas.bind(this),
680
+ };
681
+ this.stats = {
682
+ parameters: this.statsParameters.bind(this),
683
+ underlyingBalances: this.statsUnderlyingBalances.bind(this),
684
+ wrappedBalances: this.statsWrappedBalances.bind(this),
685
+ totalLiquidity: this.statsTotalLiquidity.bind(this),
686
+ volume: this.statsVolume.bind(this),
687
+ baseApy: this.statsBaseApy.bind(this),
688
+ tokenApy: this.statsTokenApy.bind(this),
689
+ rewardsApy: this.statsRewardsApy.bind(this),
690
+ };
691
+ this.wallet = {
692
+ balances: this.walletBalances.bind(this),
693
+ lpTokenBalances: this.walletLpTokenBalances.bind(this),
694
+ underlyingCoinBalances: this.walletUnderlyingCoinBalances.bind(this),
695
+ wrappedCoinBalances: this.walletWrappedCoinBalances.bind(this),
696
+ allCoinBalances: this.walletAllCoinBalances.bind(this),
697
+ };
698
+ }
699
+ PoolTemplate.prototype.statsWrappedBalances = function () {
700
+ return __awaiter(this, void 0, void 0, function () {
701
+ var swapContract, contractCalls, _wrappedBalances;
702
+ var _this = this;
703
+ return __generator(this, function (_a) {
704
+ switch (_a.label) {
705
+ case 0:
706
+ swapContract = curve_1.curve.contracts[this.address].multicallContract;
707
+ contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
708
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
709
+ case 1:
710
+ _wrappedBalances = _a.sent();
711
+ return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.wrappedDecimals[i]); })];
712
+ }
713
+ });
714
+ });
715
+ };
716
+ // OVERRIDE
717
+ PoolTemplate.prototype.statsUnderlyingBalances = function () {
718
+ return __awaiter(this, void 0, void 0, function () {
719
+ return __generator(this, function (_a) {
720
+ switch (_a.label) {
721
+ case 0: return [4 /*yield*/, this.statsWrappedBalances()];
722
+ case 1: return [2 /*return*/, _a.sent()];
723
+ }
724
+ });
725
+ });
726
+ };
727
+ PoolTemplate.prototype._calcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
728
+ if (isDeposit === void 0) { isDeposit = true; }
729
+ if (useUnderlying === void 0) { useUnderlying = true; }
730
+ return __awaiter(this, void 0, void 0, function () {
731
+ var _rates_1, contractAddress, contract;
732
+ return __generator(this, function (_a) {
733
+ switch (_a.label) {
734
+ case 0:
735
+ if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
736
+ return [4 /*yield*/, this._getRates()];
737
+ case 1:
738
+ _rates_1 = _a.sent();
739
+ _amounts = _amounts.map(function (_amount, i) {
740
+ return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
741
+ });
742
+ _a.label = 2;
743
+ case 2:
744
+ contractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
745
+ contract = curve_1.curve.contracts[contractAddress].contract;
746
+ if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
747
+ return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
748
+ case 3: return [2 /*return*/, _a.sent()];
749
+ case 4:
750
+ if (!contract["calc_token_amount(uint256[".concat(_amounts.length, "],bool)")]) return [3 /*break*/, 6];
751
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
752
+ case 5: return [2 /*return*/, _a.sent()];
753
+ case 6: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
754
+ case 7: return [2 /*return*/, _a.sent()];
755
+ }
756
+ });
757
+ });
758
+ };
759
+ PoolTemplate.prototype.calcLpTokenAmount = function (amounts, isDeposit) {
760
+ if (isDeposit === void 0) { isDeposit = true; }
761
+ return __awaiter(this, void 0, void 0, function () {
762
+ var _underlyingAmounts, _expected;
763
+ var _this = this;
764
+ return __generator(this, function (_a) {
765
+ switch (_a.label) {
766
+ case 0:
767
+ if (amounts.length !== this.underlyingCoinAddresses.length) {
768
+ throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
769
+ }
770
+ _underlyingAmounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
771
+ return [4 /*yield*/, this._calcLpTokenAmount(_underlyingAmounts, isDeposit, true)];
772
+ case 1:
773
+ _expected = _a.sent();
774
+ return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
775
+ }
776
+ });
777
+ });
778
+ };
779
+ PoolTemplate.prototype.calcLpTokenAmountWrapped = function (amounts, isDeposit) {
780
+ if (isDeposit === void 0) { isDeposit = true; }
781
+ return __awaiter(this, void 0, void 0, function () {
782
+ var _amounts, _expected;
783
+ var _this = this;
784
+ return __generator(this, function (_a) {
785
+ switch (_a.label) {
786
+ case 0:
787
+ if (amounts.length !== this.wrappedCoinAddresses.length) {
788
+ throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
789
+ }
790
+ if (this.isFake) {
791
+ throw Error("".concat(this.name, " pool doesn't have this method"));
792
+ }
793
+ _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.wrappedDecimals[i]); });
794
+ return [4 /*yield*/, this._calcLpTokenAmount(_amounts, isDeposit, false)];
795
+ case 1:
796
+ _expected = _a.sent();
797
+ return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected)];
798
+ }
799
+ });
800
+ });
801
+ };
802
+ // ---------------- DEPOSIT ----------------
803
+ PoolTemplate.prototype.depositBalancedAmounts = function () {
804
+ return __awaiter(this, void 0, void 0, function () {
805
+ return __generator(this, function (_a) {
806
+ throw Error("depositBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
807
+ });
808
+ });
809
+ };
810
+ PoolTemplate.prototype.depositExpected = function (amounts) {
811
+ return __awaiter(this, void 0, void 0, function () {
812
+ return __generator(this, function (_a) {
813
+ switch (_a.label) {
814
+ case 0: return [4 /*yield*/, this.calcLpTokenAmount(amounts)];
815
+ case 1: return [2 /*return*/, _a.sent()];
816
+ }
817
+ });
818
+ });
819
+ };
820
+ // OVERRIDE
821
+ PoolTemplate.prototype.depositBonus = function (amounts) {
822
+ return __awaiter(this, void 0, void 0, function () {
823
+ return __generator(this, function (_a) {
824
+ throw Error("depositBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
825
+ });
826
+ });
827
+ };
828
+ PoolTemplate.prototype.depositIsApproved = function (amounts) {
829
+ return __awaiter(this, void 0, void 0, function () {
830
+ return __generator(this, function (_a) {
831
+ switch (_a.label) {
832
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.address)];
833
+ case 1: return [2 /*return*/, _a.sent()];
834
+ }
835
+ });
836
+ });
837
+ };
838
+ PoolTemplate.prototype.depositApproveEstimateGas = function (amounts) {
839
+ return __awaiter(this, void 0, void 0, function () {
840
+ return __generator(this, function (_a) {
841
+ switch (_a.label) {
842
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
843
+ case 1: return [2 /*return*/, _a.sent()];
844
+ }
845
+ });
846
+ });
847
+ };
848
+ PoolTemplate.prototype.depositApprove = function (amounts) {
849
+ return __awaiter(this, void 0, void 0, function () {
850
+ return __generator(this, function (_a) {
851
+ switch (_a.label) {
852
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
853
+ case 1: return [2 /*return*/, _a.sent()];
854
+ }
855
+ });
856
+ });
857
+ };
858
+ // OVERRIDE
859
+ PoolTemplate.prototype.depositEstimateGas = function (amounts) {
860
+ return __awaiter(this, void 0, void 0, function () {
861
+ return __generator(this, function (_a) {
862
+ throw Error("depositEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
863
+ });
864
+ });
865
+ };
866
+ // OVERRIDE
867
+ PoolTemplate.prototype.deposit = function (amounts, slippage) {
868
+ if (slippage === void 0) { slippage = 0.5; }
869
+ return __awaiter(this, void 0, void 0, function () {
870
+ return __generator(this, function (_a) {
871
+ throw Error("deposit method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
872
+ });
873
+ });
874
+ };
875
+ // ---------------- DEPOSIT WRAPPED ----------------
876
+ PoolTemplate.prototype.depositWrappedBalancedAmounts = function () {
877
+ return __awaiter(this, void 0, void 0, function () {
878
+ return __generator(this, function (_a) {
879
+ throw Error("depositWrappedBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
880
+ });
881
+ });
882
+ };
883
+ PoolTemplate.prototype.depositWrappedExpected = function (amounts) {
884
+ return __awaiter(this, void 0, void 0, function () {
885
+ return __generator(this, function (_a) {
886
+ switch (_a.label) {
887
+ case 0:
888
+ if (this.isFake) {
889
+ throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
890
+ }
891
+ return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
892
+ case 1: return [2 /*return*/, _a.sent()];
893
+ }
894
+ });
895
+ });
896
+ };
897
+ // OVERRIDE
898
+ PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
899
+ return __awaiter(this, void 0, void 0, function () {
900
+ return __generator(this, function (_a) {
901
+ throw Error("depositWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
902
+ });
903
+ });
904
+ };
905
+ PoolTemplate.prototype.depositWrappedIsApproved = function (amounts) {
906
+ return __awaiter(this, void 0, void 0, function () {
907
+ return __generator(this, function (_a) {
908
+ switch (_a.label) {
909
+ case 0:
910
+ if (this.isFake) {
911
+ throw Error("depositWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
912
+ }
913
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, this.address)];
914
+ case 1: return [2 /*return*/, _a.sent()];
915
+ }
916
+ });
917
+ });
918
+ };
919
+ PoolTemplate.prototype.depositWrappedApproveEstimateGas = function (amounts) {
920
+ return __awaiter(this, void 0, void 0, function () {
921
+ return __generator(this, function (_a) {
922
+ switch (_a.label) {
923
+ case 0:
924
+ if (this.isFake) {
925
+ throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
926
+ }
927
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, this.address)];
928
+ case 1: return [2 /*return*/, _a.sent()];
929
+ }
930
+ });
931
+ });
932
+ };
933
+ PoolTemplate.prototype.depositWrappedApprove = function (amounts) {
934
+ return __awaiter(this, void 0, void 0, function () {
935
+ return __generator(this, function (_a) {
936
+ switch (_a.label) {
937
+ case 0:
938
+ if (this.isFake) {
939
+ throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
940
+ }
941
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, this.address)];
942
+ case 1: return [2 /*return*/, _a.sent()];
943
+ }
944
+ });
945
+ });
946
+ };
947
+ // OVERRIDE
948
+ PoolTemplate.prototype.depositWrappedEstimateGas = function (amounts) {
949
+ return __awaiter(this, void 0, void 0, function () {
950
+ return __generator(this, function (_a) {
951
+ throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
952
+ });
953
+ });
954
+ };
955
+ // OVERRIDE
956
+ PoolTemplate.prototype.depositWrapped = function (amounts, slippage) {
957
+ if (slippage === void 0) { slippage = 0.5; }
958
+ return __awaiter(this, void 0, void 0, function () {
959
+ return __generator(this, function (_a) {
960
+ throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
961
+ });
962
+ });
963
+ };
964
+ // ---------------- STAKING ----------------
965
+ PoolTemplate.prototype.stakeIsApproved = function (lpTokenAmount) {
966
+ return __awaiter(this, void 0, void 0, function () {
967
+ return __generator(this, function (_a) {
968
+ switch (_a.label) {
969
+ case 0:
970
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
971
+ throw Error("stakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
972
+ }
973
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
974
+ case 1: return [2 /*return*/, _a.sent()];
975
+ }
976
+ });
977
+ });
978
+ };
979
+ PoolTemplate.prototype.stakeApproveEstimateGas = function (lpTokenAmount) {
980
+ return __awaiter(this, void 0, void 0, function () {
981
+ return __generator(this, function (_a) {
982
+ switch (_a.label) {
983
+ case 0:
984
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
985
+ throw Error("stakeApproveEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
986
+ }
987
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
988
+ case 1: return [2 /*return*/, _a.sent()];
989
+ }
990
+ });
991
+ });
992
+ };
993
+ PoolTemplate.prototype.stakeApprove = function (lpTokenAmount) {
994
+ return __awaiter(this, void 0, void 0, function () {
995
+ return __generator(this, function (_a) {
996
+ switch (_a.label) {
997
+ case 0:
998
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
999
+ throw Error("stakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1000
+ }
1001
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
1002
+ case 1: return [2 /*return*/, _a.sent()];
1003
+ }
1004
+ });
1005
+ });
1006
+ };
1007
+ PoolTemplate.prototype.stakeEstimateGas = function (lpTokenAmount) {
1008
+ return __awaiter(this, void 0, void 0, function () {
1009
+ var _lpTokenAmount;
1010
+ return __generator(this, function (_a) {
1011
+ switch (_a.label) {
1012
+ case 0:
1013
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1014
+ throw Error("stakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1015
+ }
1016
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
1017
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1018
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1019
+ }
1020
+ });
1021
+ });
1022
+ };
1023
+ PoolTemplate.prototype.stake = function (lpTokenAmount) {
1024
+ return __awaiter(this, void 0, void 0, function () {
1025
+ var _lpTokenAmount, gasLimit;
1026
+ return __generator(this, function (_a) {
1027
+ switch (_a.label) {
1028
+ case 0:
1029
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1030
+ throw Error("stake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1031
+ }
1032
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
1033
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
1034
+ case 1:
1035
+ _a.sent();
1036
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1037
+ case 2:
1038
+ gasLimit = (_a.sent()).mul(150).div(100);
1039
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1040
+ case 3: return [2 /*return*/, (_a.sent()).hash];
1041
+ }
1042
+ });
1043
+ });
1044
+ };
1045
+ PoolTemplate.prototype.unstakeEstimateGas = function (lpTokenAmount) {
1046
+ return __awaiter(this, void 0, void 0, function () {
1047
+ var _lpTokenAmount;
1048
+ return __generator(this, function (_a) {
1049
+ switch (_a.label) {
1050
+ case 0:
1051
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1052
+ throw Error("unstakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1053
+ }
1054
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
1055
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1056
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1057
+ }
1058
+ });
1059
+ });
1060
+ };
1061
+ PoolTemplate.prototype.unstake = function (lpTokenAmount) {
1062
+ return __awaiter(this, void 0, void 0, function () {
1063
+ var _lpTokenAmount, gasLimit;
1064
+ return __generator(this, function (_a) {
1065
+ switch (_a.label) {
1066
+ case 0:
1067
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1068
+ throw Error("unstake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1069
+ }
1070
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
1071
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1072
+ case 1:
1073
+ gasLimit = (_a.sent()).mul(200).div(100);
1074
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1075
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1076
+ }
1077
+ });
1078
+ });
1079
+ };
1080
+ PoolTemplate.prototype.claimableCrv = function (address) {
1081
+ if (address === void 0) { address = ""; }
1082
+ return __awaiter(this, void 0, void 0, function () {
1083
+ var _a, _c;
1084
+ return __generator(this, function (_d) {
1085
+ switch (_d.label) {
1086
+ case 0:
1087
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1088
+ throw Error("claimableCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1089
+ }
1090
+ if (curve_1.curve.chainId !== 1)
1091
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimableRewards instead"));
1092
+ address = address || curve_1.curve.signerAddress;
1093
+ if (!address)
1094
+ throw Error("Need to connect wallet or pass address into args");
1095
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1096
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
1097
+ case 1: return [2 /*return*/, _c.apply(_a, [_d.sent()])];
1098
+ }
1099
+ });
1100
+ });
1101
+ };
1102
+ PoolTemplate.prototype.claimCrvEstimateGas = function () {
1103
+ return __awaiter(this, void 0, void 0, function () {
1104
+ return __generator(this, function (_a) {
1105
+ switch (_a.label) {
1106
+ case 0:
1107
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1108
+ throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1109
+ }
1110
+ if (curve_1.curve.chainId !== 1)
1111
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimRewards instead"));
1112
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1113
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1114
+ }
1115
+ });
1116
+ });
1117
+ };
1118
+ PoolTemplate.prototype.claimCrv = function () {
1119
+ return __awaiter(this, void 0, void 0, function () {
1120
+ var gasLimit;
1121
+ return __generator(this, function (_a) {
1122
+ switch (_a.label) {
1123
+ case 0:
1124
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1125
+ throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1126
+ }
1127
+ if (curve_1.curve.chainId !== 1)
1128
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimRewards instead"));
1129
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1130
+ case 1:
1131
+ gasLimit = (_a.sent()).mul(130).div(100);
1132
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1133
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1134
+ }
1135
+ });
1136
+ });
1137
+ };
1138
+ // TODO 1. Fix aave and saave error
1139
+ // TODO 2. Figure out Synthetix cumulative results
1140
+ PoolTemplate.prototype.claimableRewards = function (address) {
1141
+ if (address === void 0) { address = ""; }
1142
+ return __awaiter(this, void 0, void 0, function () {
1143
+ var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1144
+ return __generator(this, function (_g) {
1145
+ switch (_g.label) {
1146
+ case 0:
1147
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1148
+ throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1149
+ }
1150
+ address = address || curve_1.curve.signerAddress;
1151
+ if (!address)
1152
+ throw Error("Need to connect wallet or pass address into args");
1153
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1154
+ rewards = [];
1155
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1156
+ _i = 0, _a = this.rewardTokens;
1157
+ _g.label = 1;
1158
+ case 1:
1159
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
1160
+ rewardToken = _a[_i];
1161
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1162
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1163
+ case 2:
1164
+ symbol = _g.sent();
1165
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1166
+ case 3:
1167
+ decimals = _g.sent();
1168
+ method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1169
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
1170
+ return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1171
+ case 4:
1172
+ amount = _d.apply(_c, [_g.sent(), decimals]);
1173
+ rewards.push({
1174
+ token: rewardToken,
1175
+ symbol: symbol,
1176
+ amount: amount,
1177
+ });
1178
+ _g.label = 5;
1179
+ case 5:
1180
+ _i++;
1181
+ return [3 /*break*/, 1];
1182
+ case 6: return [3 /*break*/, 11];
1183
+ case 7:
1184
+ if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1185
+ rewardToken = this.rewardTokens[0];
1186
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1187
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1188
+ case 8:
1189
+ symbol = _g.sent();
1190
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1191
+ case 9:
1192
+ decimals = _g.sent();
1193
+ _f = (_e = ethers_1.ethers.utils).formatUnits;
1194
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1195
+ case 10:
1196
+ amount = _f.apply(_e, [_g.sent(), decimals]);
1197
+ rewards.push({
1198
+ token: rewardToken,
1199
+ symbol: symbol,
1200
+ amount: amount,
1201
+ });
1202
+ _g.label = 11;
1203
+ case 11: return [2 /*return*/, rewards];
1204
+ }
1205
+ });
1206
+ });
1207
+ };
1208
+ PoolTemplate.prototype.claimRewardsEstimateGas = function () {
1209
+ return __awaiter(this, void 0, void 0, function () {
1210
+ var gaugeContract;
1211
+ return __generator(this, function (_a) {
1212
+ switch (_a.label) {
1213
+ case 0:
1214
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1215
+ throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1216
+ }
1217
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1218
+ if (!("claim_rewards()" in gaugeContract))
1219
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1220
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1221
+ case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1222
+ }
1223
+ });
1224
+ });
1225
+ };
1226
+ PoolTemplate.prototype.claimRewards = function () {
1227
+ return __awaiter(this, void 0, void 0, function () {
1228
+ var gaugeContract, gasLimit;
1229
+ return __generator(this, function (_a) {
1230
+ switch (_a.label) {
1231
+ case 0:
1232
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1233
+ throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1234
+ }
1235
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1236
+ if (!("claim_rewards()" in gaugeContract))
1237
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1238
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1239
+ case 1:
1240
+ gasLimit = (_a.sent()).mul(130).div(100);
1241
+ return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1242
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1243
+ }
1244
+ });
1245
+ });
1246
+ };
1247
+ // ---------------- DEPOSIT & STAKE ----------------
1248
+ PoolTemplate.prototype.depositAndStakeExpected = function (amounts) {
1249
+ return __awaiter(this, void 0, void 0, function () {
1250
+ return __generator(this, function (_a) {
1251
+ switch (_a.label) {
1252
+ case 0:
1253
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1254
+ throw Error("depositAndStakeExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1255
+ }
1256
+ return [4 /*yield*/, this.depositExpected(amounts)];
1257
+ case 1: return [2 /*return*/, _a.sent()];
1258
+ }
1259
+ });
1260
+ });
1261
+ };
1262
+ PoolTemplate.prototype.depositAndStakeBonus = function (amounts) {
1263
+ return __awaiter(this, void 0, void 0, function () {
1264
+ return __generator(this, function (_a) {
1265
+ switch (_a.label) {
1266
+ case 0:
1267
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1268
+ throw Error("depositAndStakeBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1269
+ }
1270
+ return [4 /*yield*/, this.depositBonus(amounts)];
1271
+ case 1: return [2 /*return*/, _a.sent()];
1272
+ }
1273
+ });
1274
+ });
1275
+ };
1276
+ PoolTemplate.prototype.depositAndStakeIsApproved = function (amounts) {
1277
+ return __awaiter(this, void 0, void 0, function () {
1278
+ var coinsAllowance, gaugeContract, gaugeAllowance;
1279
+ return __generator(this, function (_a) {
1280
+ switch (_a.label) {
1281
+ case 0:
1282
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1283
+ throw Error("depositAndStakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1284
+ }
1285
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1286
+ case 1:
1287
+ coinsAllowance = _a.sent();
1288
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1289
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
1290
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1291
+ case 2:
1292
+ gaugeAllowance = _a.sent();
1293
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
1294
+ case 3: return [2 /*return*/, coinsAllowance];
1295
+ }
1296
+ });
1297
+ });
1298
+ };
1299
+ PoolTemplate.prototype.depositAndStakeApproveEstimateGas = function (amounts) {
1300
+ return __awaiter(this, void 0, void 0, function () {
1301
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
1302
+ return __generator(this, function (_a) {
1303
+ switch (_a.label) {
1304
+ case 0:
1305
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1306
+ throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1307
+ }
1308
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1309
+ case 1:
1310
+ approveCoinsGas = _a.sent();
1311
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1312
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
1313
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1314
+ case 2:
1315
+ gaugeAllowance = _a.sent();
1316
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
1317
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
1318
+ case 3:
1319
+ approveGaugeGas = (_a.sent()).toNumber();
1320
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
1321
+ case 4: return [2 /*return*/, approveCoinsGas];
1322
+ }
1323
+ });
1324
+ });
1325
+ };
1326
+ PoolTemplate.prototype.depositAndStakeApprove = function (amounts) {
1327
+ return __awaiter(this, void 0, void 0, function () {
1328
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
1329
+ return __generator(this, function (_a) {
1330
+ switch (_a.label) {
1331
+ case 0:
1332
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1333
+ throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1334
+ }
1335
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1336
+ case 1:
1337
+ approveCoinsTx = _a.sent();
1338
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1339
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
1340
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1341
+ case 2:
1342
+ gaugeAllowance = _a.sent();
1343
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
1344
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
1345
+ case 3:
1346
+ gasLimit = (_a.sent()).mul(130).div(100);
1347
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1348
+ case 4:
1349
+ approveGaugeTx = (_a.sent()).hash;
1350
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
1351
+ case 5: return [2 /*return*/, approveCoinsTx];
1352
+ }
1353
+ });
1354
+ });
1355
+ };
1356
+ PoolTemplate.prototype.depositAndStakeEstimateGas = function (amounts) {
1357
+ return __awaiter(this, void 0, void 0, function () {
1358
+ return __generator(this, function (_a) {
1359
+ switch (_a.label) {
1360
+ case 0:
1361
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1362
+ throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1363
+ }
1364
+ return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
1365
+ case 1: return [2 /*return*/, _a.sent()];
1366
+ }
1367
+ });
1368
+ });
1369
+ };
1370
+ PoolTemplate.prototype.depositAndStake = function (amounts) {
1371
+ return __awaiter(this, void 0, void 0, function () {
1372
+ return __generator(this, function (_a) {
1373
+ switch (_a.label) {
1374
+ case 0:
1375
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1376
+ throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1377
+ }
1378
+ return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
1379
+ case 1: return [2 /*return*/, _a.sent()];
1380
+ }
1381
+ });
1382
+ });
1383
+ };
1384
+ // ---------------- DEPOSIT & STAKE WRAPPED ----------------
1385
+ PoolTemplate.prototype.depositAndStakeWrappedExpected = function (amounts) {
1386
+ return __awaiter(this, void 0, void 0, function () {
1387
+ return __generator(this, function (_a) {
1388
+ switch (_a.label) {
1389
+ case 0:
1390
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1391
+ throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1392
+ }
1393
+ if (this.isFake)
1394
+ throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1395
+ return [4 /*yield*/, this.depositWrappedExpected(amounts)];
1396
+ case 1: return [2 /*return*/, _a.sent()];
1397
+ }
1398
+ });
1399
+ });
1400
+ };
1401
+ PoolTemplate.prototype.depositAndStakeWrappedBonus = function (amounts) {
1402
+ return __awaiter(this, void 0, void 0, function () {
1403
+ return __generator(this, function (_a) {
1404
+ switch (_a.label) {
1405
+ case 0:
1406
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1407
+ throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1408
+ }
1409
+ if (this.isFake)
1410
+ throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1411
+ return [4 /*yield*/, this.depositWrappedBonus(amounts)];
1412
+ case 1: return [2 /*return*/, _a.sent()];
1413
+ }
1414
+ });
1415
+ });
1416
+ };
1417
+ PoolTemplate.prototype.depositAndStakeWrappedIsApproved = function (amounts) {
1418
+ return __awaiter(this, void 0, void 0, function () {
1419
+ var coinsAllowance, gaugeContract, gaugeAllowance;
1420
+ return __generator(this, function (_a) {
1421
+ switch (_a.label) {
1422
+ case 0:
1423
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1424
+ throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1425
+ }
1426
+ if (this.isFake)
1427
+ throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1428
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1429
+ case 1:
1430
+ coinsAllowance = _a.sent();
1431
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1432
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
1433
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1434
+ case 2:
1435
+ gaugeAllowance = _a.sent();
1436
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
1437
+ case 3: return [2 /*return*/, coinsAllowance];
1438
+ }
1439
+ });
1440
+ });
1441
+ };
1442
+ PoolTemplate.prototype.depositAndStakeWrappedApproveEstimateGas = function (amounts) {
1443
+ return __awaiter(this, void 0, void 0, function () {
1444
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
1445
+ return __generator(this, function (_a) {
1446
+ switch (_a.label) {
1447
+ case 0:
1448
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1449
+ throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1450
+ }
1451
+ if (this.isFake)
1452
+ throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1453
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1454
+ case 1:
1455
+ approveCoinsGas = _a.sent();
1456
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1457
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
1458
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1459
+ case 2:
1460
+ gaugeAllowance = _a.sent();
1461
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
1462
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
1463
+ case 3:
1464
+ approveGaugeGas = (_a.sent()).toNumber();
1465
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
1466
+ case 4: return [2 /*return*/, approveCoinsGas];
1467
+ }
1468
+ });
1469
+ });
1470
+ };
1471
+ PoolTemplate.prototype.depositAndStakeWrappedApprove = function (amounts) {
1472
+ return __awaiter(this, void 0, void 0, function () {
1473
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
1474
+ return __generator(this, function (_a) {
1475
+ switch (_a.label) {
1476
+ case 0:
1477
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1478
+ throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1479
+ }
1480
+ if (this.isFake)
1481
+ throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1482
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1483
+ case 1:
1484
+ approveCoinsTx = _a.sent();
1485
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1486
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
1487
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, curve_1.curve.signerAddress, curve_1.curve.constantOptions)];
1488
+ case 2:
1489
+ gaugeAllowance = _a.sent();
1490
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
1491
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
1492
+ case 3:
1493
+ gasLimit = (_a.sent()).mul(130).div(100);
1494
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1495
+ case 4:
1496
+ approveGaugeTx = (_a.sent()).hash;
1497
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
1498
+ case 5: return [2 /*return*/, approveCoinsTx];
1499
+ }
1500
+ });
1501
+ });
1502
+ };
1503
+ PoolTemplate.prototype.depositAndStakeWrappedEstimateGas = function (amounts) {
1504
+ return __awaiter(this, void 0, void 0, function () {
1505
+ return __generator(this, function (_a) {
1506
+ switch (_a.label) {
1507
+ case 0:
1508
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1509
+ throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1510
+ }
1511
+ if (this.isFake)
1512
+ throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1513
+ return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1514
+ case 1: return [2 /*return*/, _a.sent()];
1515
+ }
1516
+ });
1517
+ });
1518
+ };
1519
+ PoolTemplate.prototype.depositAndStakeWrapped = function (amounts) {
1520
+ return __awaiter(this, void 0, void 0, function () {
1521
+ return __generator(this, function (_a) {
1522
+ switch (_a.label) {
1523
+ case 0:
1524
+ if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1525
+ throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1526
+ }
1527
+ if (this.isFake)
1528
+ throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1529
+ return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1530
+ case 1: return [2 /*return*/, _a.sent()];
1531
+ }
1532
+ });
1533
+ });
1534
+ };
1535
+ PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
1536
+ return __awaiter(this, void 0, void 0, function () {
1537
+ var coinAddresses, coins, decimals, depositAddress, balances, _a, _c, _d, _e, _f, i, allowance, _g, _amounts, contract, useUnderlying, _minMintAmount, _h, _j, _k, _l, _m, ethIndex, value, i, _gas, gasLimit;
1538
+ return __generator(this, function (_o) {
1539
+ switch (_o.label) {
1540
+ case 0:
1541
+ coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
1542
+ coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
1543
+ decimals = isUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
1544
+ depositAddress = isUnderlying ? this.zap || this.address : this.address;
1545
+ if (amounts.length !== coinAddresses.length) {
1546
+ throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
1547
+ }
1548
+ if (!isUnderlying) return [3 /*break*/, 2];
1549
+ _d = (_c = Object).values;
1550
+ return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
1551
+ case 1:
1552
+ _a = _d.apply(_c, [_o.sent()]);
1553
+ return [3 /*break*/, 4];
1554
+ case 2:
1555
+ _f = (_e = Object).values;
1556
+ return [4 /*yield*/, this.walletWrappedCoinBalances()];
1557
+ case 3:
1558
+ _a = _f.apply(_e, [_o.sent()]);
1559
+ _o.label = 4;
1560
+ case 4:
1561
+ balances = _a;
1562
+ for (i = 0; i < balances.length; i++) {
1563
+ if (Number(balances[i]) < Number(amounts[i])) {
1564
+ throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
1565
+ }
1566
+ }
1567
+ if (!isUnderlying) return [3 /*break*/, 6];
1568
+ return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
1569
+ case 5:
1570
+ _g = _o.sent();
1571
+ return [3 /*break*/, 8];
1572
+ case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
1573
+ case 7:
1574
+ _g = _o.sent();
1575
+ _o.label = 8;
1576
+ case 8:
1577
+ allowance = _g;
1578
+ if (estimateGas && !allowance) {
1579
+ throw Error("Token allowance is needed to estimate gas");
1580
+ }
1581
+ if (!!estimateGas) return [3 /*break*/, 12];
1582
+ if (!isUnderlying) return [3 /*break*/, 10];
1583
+ return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
1584
+ case 9:
1585
+ _o.sent();
1586
+ return [3 /*break*/, 12];
1587
+ case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
1588
+ case 11:
1589
+ _o.sent();
1590
+ _o.label = 12;
1591
+ case 12:
1592
+ _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
1593
+ contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
1594
+ useUnderlying = isUnderlying && (this.isLending || this.isCrypto) && !this.zap;
1595
+ if (!isUnderlying) return [3 /*break*/, 14];
1596
+ _k = (_j = ethers_1.ethers.utils).parseUnits;
1597
+ return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
1598
+ case 13:
1599
+ _h = _k.apply(_j, [_o.sent()]).mul(99).div(100);
1600
+ return [3 /*break*/, 16];
1601
+ case 14:
1602
+ _m = (_l = ethers_1.ethers.utils).parseUnits;
1603
+ return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
1604
+ case 15:
1605
+ _h = _m.apply(_l, [_o.sent()]).mul(99).div(100);
1606
+ _o.label = 16;
1607
+ case 16:
1608
+ _minMintAmount = _h;
1609
+ ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
1610
+ value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
1611
+ for (i = 0; i < 5; i++) {
1612
+ coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
1613
+ _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
1614
+ }
1615
+ return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1616
+ case 17:
1617
+ _gas = (_o.sent());
1618
+ if (estimateGas)
1619
+ return [2 /*return*/, _gas.toNumber()];
1620
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
1621
+ case 18:
1622
+ _o.sent();
1623
+ gasLimit = _gas.mul(200).div(100);
1624
+ return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
1625
+ case 19: return [2 /*return*/, (_o.sent()).hash];
1626
+ }
1627
+ });
1628
+ });
1629
+ };
1630
+ // ---------------- WITHDRAW ----------------
1631
+ // OVERRIDE
1632
+ PoolTemplate.prototype.withdrawExpected = function (lpTokenAmount) {
1633
+ return __awaiter(this, void 0, void 0, function () {
1634
+ return __generator(this, function (_a) {
1635
+ throw Error("withdrawExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1636
+ });
1637
+ });
1638
+ };
1639
+ PoolTemplate.prototype.withdrawIsApproved = function (lpTokenAmount) {
1640
+ return __awaiter(this, void 0, void 0, function () {
1641
+ return __generator(this, function (_a) {
1642
+ switch (_a.label) {
1643
+ case 0:
1644
+ if (!this.zap)
1645
+ return [2 /*return*/, true];
1646
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
1647
+ case 1: return [2 /*return*/, _a.sent()];
1648
+ }
1649
+ });
1650
+ });
1651
+ };
1652
+ PoolTemplate.prototype.withdrawApproveEstimateGas = function (lpTokenAmount) {
1653
+ return __awaiter(this, void 0, void 0, function () {
1654
+ return __generator(this, function (_a) {
1655
+ switch (_a.label) {
1656
+ case 0:
1657
+ if (!this.zap)
1658
+ return [2 /*return*/, 0];
1659
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
1660
+ case 1: return [2 /*return*/, _a.sent()];
1661
+ }
1662
+ });
1663
+ });
1664
+ };
1665
+ PoolTemplate.prototype.withdrawApprove = function (lpTokenAmount) {
1666
+ return __awaiter(this, void 0, void 0, function () {
1667
+ return __generator(this, function (_a) {
1668
+ switch (_a.label) {
1669
+ case 0:
1670
+ if (!this.zap)
1671
+ return [2 /*return*/, []];
1672
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
1673
+ case 1: return [2 /*return*/, _a.sent()];
1674
+ }
1675
+ });
1676
+ });
1677
+ };
1678
+ // OVERRIDE
1679
+ PoolTemplate.prototype.withdrawEstimateGas = function (lpTokenAmount) {
1680
+ return __awaiter(this, void 0, void 0, function () {
1681
+ return __generator(this, function (_a) {
1682
+ throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1683
+ });
1684
+ });
1685
+ };
1686
+ // OVERRIDE
1687
+ PoolTemplate.prototype.withdraw = function (lpTokenAmount, slippage) {
1688
+ if (slippage === void 0) { slippage = 0.5; }
1689
+ return __awaiter(this, void 0, void 0, function () {
1690
+ return __generator(this, function (_a) {
1691
+ throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1692
+ });
1693
+ });
1694
+ };
1695
+ // ---------------- WITHDRAW WRAPPED ----------------
1696
+ // OVERRIDE
1697
+ PoolTemplate.prototype.withdrawWrappedExpected = function (lpTokenAmount) {
1698
+ return __awaiter(this, void 0, void 0, function () {
1699
+ return __generator(this, function (_a) {
1700
+ throw Error("withdrawWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1701
+ });
1702
+ });
1703
+ };
1704
+ // OVERRIDE
1705
+ PoolTemplate.prototype.withdrawWrappedEstimateGas = function (lpTokenAmount) {
1706
+ return __awaiter(this, void 0, void 0, function () {
1707
+ return __generator(this, function (_a) {
1708
+ throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1709
+ });
1710
+ });
1711
+ };
1712
+ // OVERRIDE
1713
+ PoolTemplate.prototype.withdrawWrapped = function (lpTokenAmount, slippage) {
1714
+ if (slippage === void 0) { slippage = 0.5; }
1715
+ return __awaiter(this, void 0, void 0, function () {
1716
+ return __generator(this, function (_a) {
1717
+ throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1718
+ });
1719
+ });
1720
+ };
1721
+ // ---------------- WITHDRAW IMBALANCE ----------------
1722
+ PoolTemplate.prototype.withdrawImbalanceExpected = function (amounts) {
1723
+ return __awaiter(this, void 0, void 0, function () {
1724
+ return __generator(this, function (_a) {
1725
+ switch (_a.label) {
1726
+ case 0:
1727
+ if (this.isCrypto)
1728
+ throw Error("withdrawImbalanceExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1729
+ return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
1730
+ case 1: return [2 /*return*/, _a.sent()];
1731
+ }
1732
+ });
1733
+ });
1734
+ };
1735
+ PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
1736
+ return __awaiter(this, void 0, void 0, function () {
1737
+ var totalAmount, expected, _a;
1738
+ return __generator(this, function (_c) {
1739
+ switch (_c.label) {
1740
+ case 0:
1741
+ if (this.isCrypto)
1742
+ throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1743
+ totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
1744
+ _a = Number;
1745
+ return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
1746
+ case 1:
1747
+ expected = _a.apply(void 0, [_c.sent()]);
1748
+ return [4 /*yield*/, this._withdrawBonus(totalAmount, expected)];
1749
+ case 2: return [2 /*return*/, _c.sent()];
1750
+ }
1751
+ });
1752
+ });
1753
+ };
1754
+ PoolTemplate.prototype.withdrawImbalanceIsApproved = function (amounts) {
1755
+ return __awaiter(this, void 0, void 0, function () {
1756
+ var _amounts, _maxBurnAmount;
1757
+ var _this = this;
1758
+ return __generator(this, function (_a) {
1759
+ switch (_a.label) {
1760
+ case 0:
1761
+ if (this.isCrypto)
1762
+ throw Error("withdrawImbalanceIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1763
+ if (!this.zap) return [3 /*break*/, 3];
1764
+ _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
1765
+ return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
1766
+ case 1:
1767
+ _maxBurnAmount = (_a.sent()).mul(101).div(100);
1768
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], curve_1.curve.signerAddress, this.zap)];
1769
+ case 2: return [2 /*return*/, _a.sent()];
1770
+ case 3: return [2 /*return*/, true];
1771
+ }
1772
+ });
1773
+ });
1774
+ };
1775
+ PoolTemplate.prototype.withdrawImbalanceApproveEstimateGas = function (amounts) {
1776
+ return __awaiter(this, void 0, void 0, function () {
1777
+ var _amounts, _maxBurnAmount;
1778
+ var _this = this;
1779
+ return __generator(this, function (_a) {
1780
+ switch (_a.label) {
1781
+ case 0:
1782
+ if (this.isCrypto)
1783
+ throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1784
+ if (!this.zap) return [3 /*break*/, 3];
1785
+ _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
1786
+ return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
1787
+ case 1:
1788
+ _maxBurnAmount = (_a.sent()).mul(101).div(100);
1789
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
1790
+ case 2: return [2 /*return*/, _a.sent()];
1791
+ case 3: return [2 /*return*/, 0];
1792
+ }
1793
+ });
1794
+ });
1795
+ };
1796
+ PoolTemplate.prototype.withdrawImbalanceApprove = function (amounts) {
1797
+ return __awaiter(this, void 0, void 0, function () {
1798
+ var _amounts, _maxBurnAmount;
1799
+ var _this = this;
1800
+ return __generator(this, function (_a) {
1801
+ switch (_a.label) {
1802
+ case 0:
1803
+ if (this.isCrypto)
1804
+ throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1805
+ if (!this.zap) return [3 /*break*/, 3];
1806
+ _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, _this.underlyingDecimals[i]); });
1807
+ return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
1808
+ case 1:
1809
+ _maxBurnAmount = (_a.sent()).mul(101).div(100);
1810
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [ethers_1.ethers.utils.formatUnits(_maxBurnAmount, 18)], this.zap)];
1811
+ case 2: return [2 /*return*/, _a.sent()];
1812
+ case 3: return [2 /*return*/, []];
1813
+ }
1814
+ });
1815
+ });
1816
+ };
1817
+ // OVERRIDE
1818
+ PoolTemplate.prototype.withdrawImbalanceEstimateGas = function (amounts) {
1819
+ return __awaiter(this, void 0, void 0, function () {
1820
+ return __generator(this, function (_a) {
1821
+ throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1822
+ });
1823
+ });
1824
+ };
1825
+ // OVERRIDE
1826
+ PoolTemplate.prototype.withdrawImbalance = function (amounts, slippage) {
1827
+ if (slippage === void 0) { slippage = 0.5; }
1828
+ return __awaiter(this, void 0, void 0, function () {
1829
+ return __generator(this, function (_a) {
1830
+ throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1831
+ });
1832
+ });
1833
+ };
1834
+ // ---------------- WITHDRAW IMBALANCE WRAPPED ----------------
1835
+ PoolTemplate.prototype.withdrawImbalanceWrappedExpected = function (amounts) {
1836
+ return __awaiter(this, void 0, void 0, function () {
1837
+ return __generator(this, function (_a) {
1838
+ switch (_a.label) {
1839
+ case 0:
1840
+ if (this.isCrypto)
1841
+ throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1842
+ return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
1843
+ case 1: return [2 /*return*/, _a.sent()];
1844
+ }
1845
+ });
1846
+ });
1847
+ };
1848
+ PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
1849
+ return __awaiter(this, void 0, void 0, function () {
1850
+ var totalAmount, expected, _a;
1851
+ return __generator(this, function (_c) {
1852
+ switch (_c.label) {
1853
+ case 0:
1854
+ if (this.isCrypto)
1855
+ throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1856
+ totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
1857
+ _a = Number;
1858
+ return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
1859
+ case 1:
1860
+ expected = _a.apply(void 0, [_c.sent()]);
1861
+ return [4 /*yield*/, this._withdrawBonus(totalAmount, expected, false)];
1862
+ case 2: return [2 /*return*/, _c.sent()];
1863
+ }
1864
+ });
1865
+ });
1866
+ };
1867
+ // OVERRIDE
1868
+ PoolTemplate.prototype.withdrawImbalanceWrappedEstimateGas = function (amounts) {
1869
+ return __awaiter(this, void 0, void 0, function () {
1870
+ return __generator(this, function (_a) {
1871
+ throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1872
+ });
1873
+ });
1874
+ };
1875
+ // OVERRIDE
1876
+ PoolTemplate.prototype.withdrawImbalanceWrapped = function (amounts, slippage) {
1877
+ if (slippage === void 0) { slippage = 0.5; }
1878
+ return __awaiter(this, void 0, void 0, function () {
1879
+ return __generator(this, function (_a) {
1880
+ throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1881
+ });
1882
+ });
1883
+ };
1884
+ // ---------------- WITHDRAW ONE COIN ----------------
1885
+ // OVERRIDE
1886
+ PoolTemplate.prototype._withdrawOneCoinExpected = function (_lpTokenAmount, i) {
1887
+ return __awaiter(this, void 0, void 0, function () {
1888
+ return __generator(this, function (_a) {
1889
+ throw Error("withdrawOneCoinExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1890
+ });
1891
+ });
1892
+ };
1893
+ PoolTemplate.prototype.withdrawOneCoinExpected = function (lpTokenAmount, coin) {
1894
+ return __awaiter(this, void 0, void 0, function () {
1895
+ var i, _lpTokenAmount, _expected;
1896
+ return __generator(this, function (_a) {
1897
+ switch (_a.label) {
1898
+ case 0:
1899
+ i = this._getCoinIdx(coin);
1900
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
1901
+ return [4 /*yield*/, this._withdrawOneCoinExpected(_lpTokenAmount, i)];
1902
+ case 1:
1903
+ _expected = _a.sent();
1904
+ return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[i])];
1905
+ }
1906
+ });
1907
+ });
1908
+ };
1909
+ PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
1910
+ return __awaiter(this, void 0, void 0, function () {
1911
+ var totalAmount, _a, coinPrice;
1912
+ return __generator(this, function (_c) {
1913
+ switch (_c.label) {
1914
+ case 0:
1915
+ _a = Number;
1916
+ return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
1917
+ case 1:
1918
+ totalAmount = _a.apply(void 0, [_c.sent()]);
1919
+ if (!this.isCrypto) return [3 /*break*/, 4];
1920
+ return [4 /*yield*/, this._underlyingPrices()];
1921
+ case 2:
1922
+ coinPrice = (_c.sent())[this._getCoinIdx(coin)];
1923
+ return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
1924
+ case 3: return [2 /*return*/, _c.sent()];
1925
+ case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount))];
1926
+ case 5: return [2 /*return*/, _c.sent()];
1927
+ }
1928
+ });
1929
+ });
1930
+ };
1931
+ PoolTemplate.prototype.withdrawOneCoinIsApproved = function (lpTokenAmount) {
1932
+ return __awaiter(this, void 0, void 0, function () {
1933
+ return __generator(this, function (_a) {
1934
+ switch (_a.label) {
1935
+ case 0:
1936
+ if (!this.zap)
1937
+ return [2 /*return*/, true];
1938
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
1939
+ case 1: return [2 /*return*/, _a.sent()];
1940
+ }
1941
+ });
1942
+ });
1943
+ };
1944
+ PoolTemplate.prototype.withdrawOneCoinApproveEstimateGas = function (lpTokenAmount) {
1945
+ return __awaiter(this, void 0, void 0, function () {
1946
+ return __generator(this, function (_a) {
1947
+ switch (_a.label) {
1948
+ case 0:
1949
+ if (!this.zap)
1950
+ return [2 /*return*/, 0];
1951
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
1952
+ case 1: return [2 /*return*/, _a.sent()];
1953
+ }
1954
+ });
1955
+ });
1956
+ };
1957
+ PoolTemplate.prototype.withdrawOneCoinApprove = function (lpTokenAmount) {
1958
+ return __awaiter(this, void 0, void 0, function () {
1959
+ return __generator(this, function (_a) {
1960
+ switch (_a.label) {
1961
+ case 0:
1962
+ if (!this.zap)
1963
+ return [2 /*return*/, []];
1964
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
1965
+ case 1: return [2 /*return*/, _a.sent()];
1966
+ }
1967
+ });
1968
+ });
1969
+ };
1970
+ // OVERRIDE
1971
+ PoolTemplate.prototype.withdrawOneCoinEstimateGas = function (lpTokenAmount, coin) {
1972
+ return __awaiter(this, void 0, void 0, function () {
1973
+ return __generator(this, function (_a) {
1974
+ throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1975
+ });
1976
+ });
1977
+ };
1978
+ // OVERRIDE
1979
+ PoolTemplate.prototype.withdrawOneCoin = function (lpTokenAmount, coin, slippage) {
1980
+ if (slippage === void 0) { slippage = 0.5; }
1981
+ return __awaiter(this, void 0, void 0, function () {
1982
+ return __generator(this, function (_a) {
1983
+ throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1984
+ });
1985
+ });
1986
+ };
1987
+ // ---------------- WITHDRAW ONE COIN WRAPPED ----------------
1988
+ // OVERRIDE
1989
+ PoolTemplate.prototype._withdrawOneCoinWrappedExpected = function (_lpTokenAmount, i) {
1990
+ return __awaiter(this, void 0, void 0, function () {
1991
+ return __generator(this, function (_a) {
1992
+ throw Error("withdrawOneCoinWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1993
+ });
1994
+ });
1995
+ };
1996
+ PoolTemplate.prototype.withdrawOneCoinWrappedExpected = function (lpTokenAmount, coin) {
1997
+ return __awaiter(this, void 0, void 0, function () {
1998
+ var i, _lpTokenAmount, _expected;
1999
+ return __generator(this, function (_a) {
2000
+ switch (_a.label) {
2001
+ case 0:
2002
+ i = this._getCoinIdx(coin, false);
2003
+ _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
2004
+ return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
2005
+ case 1:
2006
+ _expected = _a.sent();
2007
+ return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.wrappedDecimals[i])];
2008
+ }
2009
+ });
2010
+ });
2011
+ };
2012
+ PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
2013
+ return __awaiter(this, void 0, void 0, function () {
2014
+ var totalAmount, _a, coinPrice;
2015
+ return __generator(this, function (_c) {
2016
+ switch (_c.label) {
2017
+ case 0:
2018
+ if (this.isFake) {
2019
+ throw Error("".concat(this.name, " pool doesn't have this method"));
2020
+ }
2021
+ _a = Number;
2022
+ return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
2023
+ case 1:
2024
+ totalAmount = _a.apply(void 0, [_c.sent()]);
2025
+ if (!this.isCrypto) return [3 /*break*/, 4];
2026
+ return [4 /*yield*/, this._underlyingPrices()];
2027
+ case 2:
2028
+ coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
2029
+ return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
2030
+ case 3: return [2 /*return*/, _c.sent()];
2031
+ case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount), false)];
2032
+ case 5: return [2 /*return*/, _c.sent()];
2033
+ }
2034
+ });
2035
+ });
2036
+ };
2037
+ // OVERRIDE
2038
+ PoolTemplate.prototype.withdrawOneCoinWrappedEstimateGas = function (lpTokenAmount, coin) {
2039
+ return __awaiter(this, void 0, void 0, function () {
2040
+ return __generator(this, function (_a) {
2041
+ throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2042
+ });
2043
+ });
2044
+ };
2045
+ // OVERRIDE
2046
+ PoolTemplate.prototype.withdrawOneCoinWrapped = function (lpTokenAmount, coin, slippage) {
2047
+ if (slippage === void 0) { slippage = 0.5; }
2048
+ return __awaiter(this, void 0, void 0, function () {
2049
+ return __generator(this, function (_a) {
2050
+ throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2051
+ });
2052
+ });
2053
+ };
2054
+ // ---------------- WALLET BALANCES ----------------
2055
+ PoolTemplate.prototype.walletBalances = function () {
2056
+ var addresses = [];
2057
+ for (var _i = 0; _i < arguments.length; _i++) {
2058
+ addresses[_i] = arguments[_i];
2059
+ }
2060
+ return __awaiter(this, void 0, void 0, function () {
2061
+ return __generator(this, function (_a) {
2062
+ switch (_a.label) {
2063
+ case 0:
2064
+ if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
2065
+ return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
2066
+ case 1: return [2 /*return*/, _a.sent()];
2067
+ case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
2068
+ case 3: return [2 /*return*/, _a.sent()];
2069
+ }
2070
+ });
2071
+ });
2072
+ };
2073
+ PoolTemplate.prototype.walletLpTokenBalances = function () {
2074
+ var addresses = [];
2075
+ for (var _i = 0; _i < arguments.length; _i++) {
2076
+ addresses[_i] = arguments[_i];
2077
+ }
2078
+ return __awaiter(this, void 0, void 0, function () {
2079
+ return __generator(this, function (_a) {
2080
+ switch (_a.label) {
2081
+ case 0:
2082
+ if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
2083
+ return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
2084
+ case 1: return [2 /*return*/, _a.sent()];
2085
+ case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
2086
+ case 3: return [2 /*return*/, _a.sent()];
2087
+ }
2088
+ });
2089
+ });
2090
+ };
2091
+ PoolTemplate.prototype.walletUnderlyingCoinBalances = function () {
2092
+ var addresses = [];
2093
+ for (var _i = 0; _i < arguments.length; _i++) {
2094
+ addresses[_i] = arguments[_i];
2095
+ }
2096
+ return __awaiter(this, void 0, void 0, function () {
2097
+ return __generator(this, function (_a) {
2098
+ switch (_a.label) {
2099
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoinAddresses, this.underlyingCoinAddresses], addresses, false))];
2100
+ case 1: return [2 /*return*/, _a.sent()];
2101
+ }
2102
+ });
2103
+ });
2104
+ };
2105
+ PoolTemplate.prototype.walletWrappedCoinBalances = function () {
2106
+ var addresses = [];
2107
+ for (var _i = 0; _i < arguments.length; _i++) {
2108
+ addresses[_i] = arguments[_i];
2109
+ }
2110
+ return __awaiter(this, void 0, void 0, function () {
2111
+ return __generator(this, function (_a) {
2112
+ switch (_a.label) {
2113
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.wrappedCoinAddresses, this.wrappedCoinAddresses], addresses, false))];
2114
+ case 1: return [2 /*return*/, _a.sent()];
2115
+ }
2116
+ });
2117
+ });
2118
+ };
2119
+ PoolTemplate.prototype.walletAllCoinBalances = function () {
2120
+ var addresses = [];
2121
+ for (var _i = 0; _i < arguments.length; _i++) {
2122
+ addresses[_i] = arguments[_i];
2123
+ }
2124
+ return __awaiter(this, void 0, void 0, function () {
2125
+ return __generator(this, function (_a) {
2126
+ switch (_a.label) {
2127
+ case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
2128
+ case 1: return [2 /*return*/, _a.sent()];
2129
+ }
2130
+ });
2131
+ });
2132
+ };
2133
+ // ---------------- SWAP ----------------
2134
+ PoolTemplate.prototype._swapExpected = function (i, j, _amount) {
2135
+ return __awaiter(this, void 0, void 0, function () {
2136
+ var contractAddress, contract;
2137
+ return __generator(this, function (_a) {
2138
+ switch (_a.label) {
2139
+ case 0:
2140
+ contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
2141
+ contract = curve_1.curve.contracts[contractAddress].contract;
2142
+ if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2143
+ return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
2144
+ case 1: return [2 /*return*/, _a.sent()];
2145
+ case 2: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
2146
+ case 3: return [2 /*return*/, _a.sent()];
2147
+ }
2148
+ });
2149
+ });
2150
+ };
2151
+ PoolTemplate.prototype.swapExpected = function (inputCoin, outputCoin, amount) {
2152
+ return __awaiter(this, void 0, void 0, function () {
2153
+ var i, j, _amount, _expected;
2154
+ return __generator(this, function (_a) {
2155
+ switch (_a.label) {
2156
+ case 0:
2157
+ i = this._getCoinIdx(inputCoin);
2158
+ j = this._getCoinIdx(outputCoin);
2159
+ _amount = (0, utils_1.parseUnits)(amount, this.underlyingDecimals[i]);
2160
+ return [4 /*yield*/, this._swapExpected(i, j, _amount)];
2161
+ case 1:
2162
+ _expected = _a.sent();
2163
+ return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.underlyingDecimals[j])];
2164
+ }
2165
+ });
2166
+ });
2167
+ };
2168
+ PoolTemplate.prototype._swapContractAddress = function () {
2169
+ return (this.isCrypto && this.isMeta) || (curve_1.curve.chainId === 137 && this.isMetaFactory) ? this.zap : this.address;
2170
+ };
2171
+ PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
2172
+ return __awaiter(this, void 0, void 0, function () {
2173
+ var contractAddress, i;
2174
+ return __generator(this, function (_a) {
2175
+ switch (_a.label) {
2176
+ case 0:
2177
+ contractAddress = this._swapContractAddress();
2178
+ i = this._getCoinIdx(inputCoin);
2179
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
2180
+ case 1: return [2 /*return*/, _a.sent()];
2181
+ }
2182
+ });
2183
+ });
2184
+ };
2185
+ PoolTemplate.prototype.swapApproveEstimateGas = function (inputCoin, amount) {
2186
+ return __awaiter(this, void 0, void 0, function () {
2187
+ var contractAddress, i;
2188
+ return __generator(this, function (_a) {
2189
+ switch (_a.label) {
2190
+ case 0:
2191
+ contractAddress = this._swapContractAddress();
2192
+ i = this._getCoinIdx(inputCoin);
2193
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
2194
+ case 1: return [2 /*return*/, _a.sent()];
2195
+ }
2196
+ });
2197
+ });
2198
+ };
2199
+ PoolTemplate.prototype.swapApprove = function (inputCoin, amount) {
2200
+ return __awaiter(this, void 0, void 0, function () {
2201
+ var contractAddress, i;
2202
+ return __generator(this, function (_a) {
2203
+ switch (_a.label) {
2204
+ case 0:
2205
+ contractAddress = this._swapContractAddress();
2206
+ i = this._getCoinIdx(inputCoin);
2207
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
2208
+ case 1: return [2 /*return*/, _a.sent()];
2209
+ }
2210
+ });
2211
+ });
2212
+ };
2213
+ // OVERRIDE
2214
+ PoolTemplate.prototype.swapEstimateGas = function (inputCoin, outputCoin, amount) {
2215
+ return __awaiter(this, void 0, void 0, function () {
2216
+ return __generator(this, function (_a) {
2217
+ throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2218
+ });
2219
+ });
2220
+ };
2221
+ // OVERRIDE
2222
+ PoolTemplate.prototype.swap = function (inputCoin, outputCoin, amount, slippage) {
2223
+ if (slippage === void 0) { slippage = 0.5; }
2224
+ return __awaiter(this, void 0, void 0, function () {
2225
+ return __generator(this, function (_a) {
2226
+ throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2227
+ });
2228
+ });
2229
+ };
2230
+ // ---------------- SWAP WRAPPED ----------------
2231
+ PoolTemplate.prototype._swapWrappedExpected = function (i, j, _amount) {
2232
+ return __awaiter(this, void 0, void 0, function () {
2233
+ return __generator(this, function (_a) {
2234
+ switch (_a.label) {
2235
+ case 0: return [4 /*yield*/, curve_1.curve.contracts[this.address].contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
2236
+ case 1: return [2 /*return*/, _a.sent()];
2237
+ }
2238
+ });
2239
+ });
2240
+ };
2241
+ // OVERRIDE
2242
+ PoolTemplate.prototype.swapWrappedExpected = function (inputCoin, outputCoin, amount) {
2243
+ return __awaiter(this, void 0, void 0, function () {
2244
+ return __generator(this, function (_a) {
2245
+ throw Error("swapWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2246
+ });
2247
+ });
2248
+ };
2249
+ // OVERRIDE
2250
+ PoolTemplate.prototype.swapWrappedIsApproved = function (inputCoin, amount) {
2251
+ return __awaiter(this, void 0, void 0, function () {
2252
+ return __generator(this, function (_a) {
2253
+ throw Error("swapWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2254
+ });
2255
+ });
2256
+ };
2257
+ // OVERRIDE
2258
+ PoolTemplate.prototype.swapWrappedApproveEstimateGas = function (inputCoin, amount) {
2259
+ return __awaiter(this, void 0, void 0, function () {
2260
+ return __generator(this, function (_a) {
2261
+ throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2262
+ });
2263
+ });
2264
+ };
2265
+ // OVERRIDE
2266
+ PoolTemplate.prototype.swapWrappedApprove = function (inputCoin, amount) {
2267
+ return __awaiter(this, void 0, void 0, function () {
2268
+ return __generator(this, function (_a) {
2269
+ throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2270
+ });
2271
+ });
2272
+ };
2273
+ // OVERRIDE
2274
+ PoolTemplate.prototype.swapWrappedEstimateGas = function (inputCoin, outputCoin, amount) {
2275
+ return __awaiter(this, void 0, void 0, function () {
2276
+ return __generator(this, function (_a) {
2277
+ throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2278
+ });
2279
+ });
2280
+ };
2281
+ // OVERRIDE
2282
+ PoolTemplate.prototype.swapWrapped = function (inputCoin, outputCoin, amount, slippage) {
2283
+ if (slippage === void 0) { slippage = 0.5; }
2284
+ return __awaiter(this, void 0, void 0, function () {
2285
+ return __generator(this, function (_a) {
2286
+ throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2287
+ });
2288
+ });
2289
+ };
2290
+ return PoolTemplate;
2291
+ }());
2292
+ exports.PoolTemplate = PoolTemplate;