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