@ichidao/ichi-vaults-sdk 0.1.42 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +61 -208
  2. package/dist/abis/types/AlgebraIntegralPool.d.ts +702 -793
  3. package/dist/abis/types/AlgebraPool.d.ts +693 -730
  4. package/dist/abis/types/ClPool.d.ts +789 -871
  5. package/dist/abis/types/DepositGuard.d.ts +193 -178
  6. package/dist/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
  7. package/dist/abis/types/ERC20.d.ts +120 -147
  8. package/dist/abis/types/ERC20Wrapper.d.ts +147 -155
  9. package/dist/abis/types/IchiVault.d.ts +598 -728
  10. package/dist/abis/types/MultiFeeDistributer.d.ts +314 -423
  11. package/dist/abis/types/Multicall.d.ts +58 -73
  12. package/dist/abis/types/UniswapV3Pool.d.ts +654 -693
  13. package/dist/abis/types/common.d.ts +40 -12
  14. package/dist/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
  15. package/dist/abis/types/factories/AlgebraIntegralPool__factory.js +10 -13
  16. package/dist/abis/types/factories/AlgebraIntegralPool__factory.js.map +1 -1
  17. package/dist/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
  18. package/dist/abis/types/factories/AlgebraPool__factory.js +10 -13
  19. package/dist/abis/types/factories/AlgebraPool__factory.js.map +1 -1
  20. package/dist/abis/types/factories/ClPool__factory.d.ts +2 -3
  21. package/dist/abis/types/factories/ClPool__factory.js +10 -13
  22. package/dist/abis/types/factories/ClPool__factory.js.map +1 -1
  23. package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
  24. package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js +10 -13
  25. package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js.map +1 -1
  26. package/dist/abis/types/factories/DepositGuard__factory.d.ts +2 -3
  27. package/dist/abis/types/factories/DepositGuard__factory.js +10 -13
  28. package/dist/abis/types/factories/DepositGuard__factory.js.map +1 -1
  29. package/dist/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
  30. package/dist/abis/types/factories/ERC20Wrapper__factory.js +10 -13
  31. package/dist/abis/types/factories/ERC20Wrapper__factory.js.map +1 -1
  32. package/dist/abis/types/factories/ERC20__factory.d.ts +2 -3
  33. package/dist/abis/types/factories/ERC20__factory.js +10 -13
  34. package/dist/abis/types/factories/ERC20__factory.js.map +1 -1
  35. package/dist/abis/types/factories/IchiVault__factory.d.ts +2 -3
  36. package/dist/abis/types/factories/IchiVault__factory.js +10 -13
  37. package/dist/abis/types/factories/IchiVault__factory.js.map +1 -1
  38. package/dist/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
  39. package/dist/abis/types/factories/MultiFeeDistributer__factory.js +10 -13
  40. package/dist/abis/types/factories/MultiFeeDistributer__factory.js.map +1 -1
  41. package/dist/abis/types/factories/Multicall__factory.d.ts +2 -3
  42. package/dist/abis/types/factories/Multicall__factory.js +10 -13
  43. package/dist/abis/types/factories/Multicall__factory.js.map +1 -1
  44. package/dist/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
  45. package/dist/abis/types/factories/UniswapV3Pool__factory.js +10 -13
  46. package/dist/abis/types/factories/UniswapV3Pool__factory.js.map +1 -1
  47. package/dist/src/__tests__/index.test.js +376 -700
  48. package/dist/src/__tests__/index.test.js.map +1 -1
  49. package/dist/src/abis/types/AlgebraIntegralPool.d.ts +702 -793
  50. package/dist/src/abis/types/AlgebraPool.d.ts +693 -730
  51. package/dist/src/abis/types/ClPool.d.ts +789 -871
  52. package/dist/src/abis/types/DepositGuard.d.ts +193 -178
  53. package/dist/src/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
  54. package/dist/src/abis/types/ERC20.d.ts +120 -147
  55. package/dist/src/abis/types/ERC20Wrapper.d.ts +147 -155
  56. package/dist/src/abis/types/IchiVault.d.ts +598 -728
  57. package/dist/src/abis/types/MultiFeeDistributer.d.ts +314 -423
  58. package/dist/src/abis/types/Multicall.d.ts +58 -73
  59. package/dist/src/abis/types/UniswapV3Pool.d.ts +654 -693
  60. package/dist/src/abis/types/common.d.ts +40 -12
  61. package/dist/src/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
  62. package/dist/src/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
  63. package/dist/src/abis/types/factories/ClPool__factory.d.ts +2 -3
  64. package/dist/src/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
  65. package/dist/src/abis/types/factories/DepositGuard__factory.d.ts +2 -3
  66. package/dist/src/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
  67. package/dist/src/abis/types/factories/ERC20__factory.d.ts +2 -3
  68. package/dist/src/abis/types/factories/IchiVault__factory.d.ts +2 -3
  69. package/dist/src/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
  70. package/dist/src/abis/types/factories/Multicall__factory.d.ts +2 -3
  71. package/dist/src/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
  72. package/dist/src/contracts/index.d.ts +1 -1
  73. package/dist/src/contracts/index.js +12 -12
  74. package/dist/src/contracts/index.js.map +1 -1
  75. package/dist/src/functions/_totalBalances.d.ts +2 -3
  76. package/dist/src/functions/_totalBalances.js +46 -117
  77. package/dist/src/functions/_totalBalances.js.map +1 -1
  78. package/dist/src/functions/_vaultEvents.js +347 -488
  79. package/dist/src/functions/_vaultEvents.js.map +1 -1
  80. package/dist/src/functions/_withdrawHelpers.d.ts +2 -3
  81. package/dist/src/functions/_withdrawHelpers.js +13 -62
  82. package/dist/src/functions/_withdrawHelpers.js.map +1 -1
  83. package/dist/src/functions/calculateApr.d.ts +1 -1
  84. package/dist/src/functions/calculateApr.js +77 -150
  85. package/dist/src/functions/calculateApr.js.map +1 -1
  86. package/dist/src/functions/calculateDtr.d.ts +1 -1
  87. package/dist/src/functions/calculateDtr.js +84 -169
  88. package/dist/src/functions/calculateDtr.js.map +1 -1
  89. package/dist/src/functions/calculateFees.d.ts +1 -1
  90. package/dist/src/functions/calculateFees.js +97 -172
  91. package/dist/src/functions/calculateFees.js.map +1 -1
  92. package/dist/src/functions/chains.js +6 -6
  93. package/dist/src/functions/chains.js.map +1 -1
  94. package/dist/src/functions/claimRewards.d.ts +3 -4
  95. package/dist/src/functions/claimRewards.js +29 -92
  96. package/dist/src/functions/claimRewards.js.map +1 -1
  97. package/dist/src/functions/deposit.d.ts +7 -9
  98. package/dist/src/functions/deposit.js +199 -364
  99. package/dist/src/functions/deposit.js.map +1 -1
  100. package/dist/src/functions/depositWithHtsWrapping.d.ts +4 -6
  101. package/dist/src/functions/depositWithHtsWrapping.js +109 -226
  102. package/dist/src/functions/depositWithHtsWrapping.js.map +1 -1
  103. package/dist/src/functions/getFeeAprs.d.ts +1 -1
  104. package/dist/src/functions/getFeeAprs.js +55 -111
  105. package/dist/src/functions/getFeeAprs.js.map +1 -1
  106. package/dist/src/functions/priceFromPool.d.ts +3 -4
  107. package/dist/src/functions/priceFromPool.js +99 -208
  108. package/dist/src/functions/priceFromPool.js.map +1 -1
  109. package/dist/src/functions/rewardInfo.js +79 -159
  110. package/dist/src/functions/rewardInfo.js.map +1 -1
  111. package/dist/src/functions/totalBalances.d.ts +2 -3
  112. package/dist/src/functions/totalBalances.js +14 -67
  113. package/dist/src/functions/totalBalances.js.map +1 -1
  114. package/dist/src/functions/userBalances.d.ts +2 -3
  115. package/dist/src/functions/userBalances.js +244 -368
  116. package/dist/src/functions/userBalances.js.map +1 -1
  117. package/dist/src/functions/userRewards.d.ts +1 -1
  118. package/dist/src/functions/userRewards.js +87 -145
  119. package/dist/src/functions/userRewards.js.map +1 -1
  120. package/dist/src/functions/vault.d.ts +1 -1
  121. package/dist/src/functions/vault.js +203 -383
  122. package/dist/src/functions/vault.js.map +1 -1
  123. package/dist/src/functions/vaultBasics.js +6 -7
  124. package/dist/src/functions/vaultBasics.js.map +1 -1
  125. package/dist/src/functions/vaultMetrics.d.ts +1 -1
  126. package/dist/src/functions/vaultMetrics.js +111 -189
  127. package/dist/src/functions/vaultMetrics.js.map +1 -1
  128. package/dist/src/functions/vaultPositions.d.ts +1 -1
  129. package/dist/src/functions/vaultPositions.js +69 -134
  130. package/dist/src/functions/vaultPositions.js.map +1 -1
  131. package/dist/src/functions/vaultTvl.d.ts +1 -1
  132. package/dist/src/functions/vaultTvl.js +80 -165
  133. package/dist/src/functions/vaultTvl.js.map +1 -1
  134. package/dist/src/functions/withdraw.d.ts +6 -8
  135. package/dist/src/functions/withdraw.js +165 -295
  136. package/dist/src/functions/withdraw.js.map +1 -1
  137. package/dist/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
  138. package/dist/src/functions/withdrawWithErc20Wrapping.js +59 -126
  139. package/dist/src/functions/withdrawWithErc20Wrapping.js.map +1 -1
  140. package/dist/src/graphql/constants.js +211 -212
  141. package/dist/src/graphql/constants.js.map +1 -1
  142. package/dist/src/graphql/functions.js +30 -102
  143. package/dist/src/graphql/functions.js.map +1 -1
  144. package/dist/src/graphql/queries.js +407 -42
  145. package/dist/src/graphql/queries.js.map +1 -1
  146. package/dist/src/index.cjs.js +3 -2
  147. package/dist/src/index.d.ts +1 -0
  148. package/dist/src/index.esm.js +3 -2
  149. package/dist/src/index.js +1 -0
  150. package/dist/src/index.js.map +1 -1
  151. package/dist/src/src/contracts/index.d.ts +1 -1
  152. package/dist/src/src/functions/_totalBalances.d.ts +2 -3
  153. package/dist/src/src/functions/_withdrawHelpers.d.ts +2 -3
  154. package/dist/src/src/functions/calculateApr.d.ts +1 -1
  155. package/dist/src/src/functions/calculateDtr.d.ts +1 -1
  156. package/dist/src/src/functions/calculateFees.d.ts +1 -1
  157. package/dist/src/src/functions/claimRewards.d.ts +3 -4
  158. package/dist/src/src/functions/deposit.d.ts +7 -9
  159. package/dist/src/src/functions/depositWithHtsWrapping.d.ts +4 -6
  160. package/dist/src/src/functions/getFeeAprs.d.ts +1 -1
  161. package/dist/src/src/functions/priceFromPool.d.ts +3 -4
  162. package/dist/src/src/functions/totalBalances.d.ts +2 -3
  163. package/dist/src/src/functions/userBalances.d.ts +2 -3
  164. package/dist/src/src/functions/userRewards.d.ts +1 -1
  165. package/dist/src/src/functions/vault.d.ts +1 -1
  166. package/dist/src/src/functions/vaultMetrics.d.ts +1 -1
  167. package/dist/src/src/functions/vaultPositions.d.ts +1 -1
  168. package/dist/src/src/functions/vaultTvl.d.ts +1 -1
  169. package/dist/src/src/functions/withdraw.d.ts +6 -8
  170. package/dist/src/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
  171. package/dist/src/src/index.d.ts +1 -0
  172. package/dist/src/src/types/calculateGasMargin.d.ts +1 -2
  173. package/dist/src/src/types/index.d.ts +11 -13
  174. package/dist/src/src/utils/amountWithSlippage.d.ts +1 -2
  175. package/dist/src/src/utils/config/addresses.d.ts +1 -1
  176. package/dist/src/src/utils/formatBigInt.d.ts +1 -2
  177. package/dist/src/src/utils/getConfigByFactory.d.ts +33 -0
  178. package/dist/src/src/utils/getPrice.d.ts +1 -2
  179. package/dist/src/src/utils/multicallUtils.d.ts +9 -10
  180. package/dist/src/src/utils/parseBigInt.d.ts +1 -2
  181. package/dist/src/types/calculateGasMargin.d.ts +1 -2
  182. package/dist/src/types/calculateGasMargin.js +4 -5
  183. package/dist/src/types/calculateGasMargin.js.map +1 -1
  184. package/dist/src/types/index.d.ts +11 -13
  185. package/dist/src/types/index.js.map +1 -1
  186. package/dist/src/utils/amountWithSlippage.d.ts +1 -2
  187. package/dist/src/utils/amountWithSlippage.js +1 -1
  188. package/dist/src/utils/amountWithSlippage.js.map +1 -1
  189. package/dist/src/utils/cache.js +2 -2
  190. package/dist/src/utils/cache.js.map +1 -1
  191. package/dist/src/utils/config/addresses.d.ts +1 -1
  192. package/dist/src/utils/config/addresses.js +267 -268
  193. package/dist/src/utils/config/addresses.js.map +1 -1
  194. package/dist/src/utils/formatBigInt.d.ts +1 -2
  195. package/dist/src/utils/formatBigInt.js +4 -5
  196. package/dist/src/utils/formatBigInt.js.map +1 -1
  197. package/dist/src/utils/getConfigByFactory.d.ts +33 -0
  198. package/dist/src/utils/getConfigByFactory.js +79 -0
  199. package/dist/src/utils/getConfigByFactory.js.map +1 -0
  200. package/dist/src/utils/getGraphUrls.js +8 -12
  201. package/dist/src/utils/getGraphUrls.js.map +1 -1
  202. package/dist/src/utils/getPrice.d.ts +1 -2
  203. package/dist/src/utils/getPrice.js +5 -6
  204. package/dist/src/utils/getPrice.js.map +1 -1
  205. package/dist/src/utils/isVelodrome.js +2 -3
  206. package/dist/src/utils/isVelodrome.js.map +1 -1
  207. package/dist/src/utils/multicallUtils.d.ts +9 -10
  208. package/dist/src/utils/multicallUtils.js +38 -93
  209. package/dist/src/utils/multicallUtils.js.map +1 -1
  210. package/dist/src/utils/parseBigInt.d.ts +1 -2
  211. package/dist/src/utils/parseBigInt.js +5 -7
  212. package/dist/src/utils/parseBigInt.js.map +1 -1
  213. package/dist/src/utils/positionKey.js +2 -4
  214. package/dist/src/utils/positionKey.js.map +1 -1
  215. package/package.json +5 -17
@@ -1,137 +1,70 @@
1
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
5
  Object.defineProperty(exports, "__esModule", { value: true });
53
6
  exports.withdrawWithErc20Wrapping = void 0;
54
- var ethers_1 = require("ethers");
55
- var contracts_1 = require("../contracts");
56
- var parseBigInt_1 = __importDefault(require("../utils/parseBigInt"));
57
- var types_1 = require("../types");
58
- var calculateGasMargin_1 = require("../types/calculateGasMargin");
7
+ const contracts_1 = require("../contracts");
8
+ const parseBigInt_1 = __importDefault(require("../utils/parseBigInt"));
9
+ const types_1 = require("../types");
10
+ const calculateGasMargin_1 = require("../types/calculateGasMargin");
59
11
  // eslint-disable-next-line import/no-cycle
60
- var vault_1 = require("./vault");
61
- var addresses_1 = require("../utils/config/addresses");
62
- var amountWithSlippage_1 = __importDefault(require("../utils/amountWithSlippage"));
63
- var userBalances_1 = require("./userBalances");
64
- var vaultBasics_1 = __importDefault(require("./vaultBasics"));
65
- var _withdrawHelpers_1 = require("./_withdrawHelpers");
66
- function withdrawWithErc20Wrapping(accountAddress, shares, vaultAddress, jsonProvider, dex, percentSlippage, overrides) {
67
- var _a, _b;
68
- if (percentSlippage === void 0) { percentSlippage = 1; }
69
- return __awaiter(this, void 0, void 0, function () {
70
- var _c, chainId, vault, signer, vaultDeployerAddress, userShares, withdrawShares, isApproved, depositGuardAddress, depositGuardContract, maxGasLimit, amounts, gasLimit, _d, _e, tx;
71
- return __generator(this, function (_f) {
72
- switch (_f.label) {
73
- case 0: return [4 /*yield*/, (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex)];
74
- case 1:
75
- _c = _f.sent(), chainId = _c.chainId, vault = _c.vault;
76
- // This function is only applicable for BONZO vaults on Hedera
77
- if (dex !== types_1.SupportedDex.Bonzo || chainId !== types_1.SupportedChainId.hedera) {
78
- throw new Error("withdrawWithErc20Wrapping is only supported for Bonzo vaults on Hedera. Got dex: ".concat(dex, ", chainId: ").concat(chainId));
79
- }
80
- signer = jsonProvider.getSigner(accountAddress);
81
- vaultDeployerAddress = (0, vaultBasics_1.default)(vaultAddress, chainId, dex);
82
- userShares = (0, userBalances_1.getUserBalance)(accountAddress, vaultAddress, jsonProvider, dex, true);
83
- withdrawShares = shares instanceof ethers_1.BigNumber ? shares : (0, parseBigInt_1.default)(shares, 18);
84
- return [4 /*yield*/, userShares];
85
- case 2:
86
- if ((_f.sent()).lt(withdrawShares)) {
87
- throw new Error("Withdraw amount exceeds user shares amount in vault ".concat(vaultAddress, " on chain ").concat(chainId, " and dex ").concat(dex));
88
- }
89
- return [4 /*yield*/, (0, _withdrawHelpers_1._isVaultTokenApproved)(accountAddress, withdrawShares, vault, chainId, jsonProvider, dex)];
90
- case 3:
91
- isApproved = _f.sent();
92
- if (!isApproved) {
93
- throw new Error("Vault token transfer is not approved for vault ".concat(vaultAddress, " on chain ").concat(chainId, " and dex ").concat(dex));
94
- }
95
- depositGuardAddress = (_a = addresses_1.addressConfig[chainId][dex]) === null || _a === void 0 ? void 0 : _a.depositGuard.address;
96
- if (!depositGuardAddress) {
97
- throw new Error("Deposit Guard for vault ".concat(vaultAddress, " not found on chain ").concat(chainId, " and dex ").concat(dex));
98
- }
99
- depositGuardContract = (0, contracts_1.getDepositGuardWithHtsWrappingContract)(depositGuardAddress, signer);
100
- maxGasLimit = (0, calculateGasMargin_1.getGasLimit)(chainId);
101
- return [4 /*yield*/, depositGuardContract.callStatic.withdrawFromICHIVaultAndTryUnwrapToERC20(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, ethers_1.BigNumber.from(0), ethers_1.BigNumber.from(0), {
102
- gasLimit: maxGasLimit,
103
- })];
104
- case 4:
105
- amounts = _f.sent();
106
- // reduce the estimated amounts by an acceptable slippage %, default - 1%
107
- if (percentSlippage < 0.01)
108
- throw new Error('Slippage parameter is less than 0.01%.');
109
- if (percentSlippage > 100)
110
- throw new Error('Slippage parameter is more than 100%.');
111
- amounts = {
112
- 0: (0, amountWithSlippage_1.default)(amounts[0], percentSlippage),
113
- 1: (0, amountWithSlippage_1.default)(amounts[1], percentSlippage),
114
- amount0: (0, amountWithSlippage_1.default)(amounts[0], percentSlippage),
115
- amount1: (0, amountWithSlippage_1.default)(amounts[1], percentSlippage),
116
- };
117
- if (!((_b = overrides === null || overrides === void 0 ? void 0 : overrides.gasLimit) !== null && _b !== void 0)) return [3 /*break*/, 5];
118
- _d = _b;
119
- return [3 /*break*/, 7];
120
- case 5:
121
- _e = calculateGasMargin_1.calculateGasMargin;
122
- return [4 /*yield*/, depositGuardContract.estimateGas.withdrawFromICHIVaultAndTryUnwrapToERC20(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, amounts[0], amounts[1])];
123
- case 6:
124
- _d = _e.apply(void 0, [_f.sent()]);
125
- _f.label = 7;
126
- case 7:
127
- gasLimit = _d;
128
- return [4 /*yield*/, depositGuardContract.withdrawFromICHIVaultAndTryUnwrapToERC20(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, amounts[0], amounts[1], __assign(__assign({}, overrides), { gasLimit: gasLimit }))];
129
- case 8:
130
- tx = _f.sent();
131
- return [2 /*return*/, tx];
132
- }
133
- });
12
+ const vault_1 = require("./vault");
13
+ const addresses_1 = require("../utils/config/addresses");
14
+ const amountWithSlippage_1 = __importDefault(require("../utils/amountWithSlippage"));
15
+ const userBalances_1 = require("./userBalances");
16
+ const vaultBasics_1 = __importDefault(require("./vaultBasics"));
17
+ const _withdrawHelpers_1 = require("./_withdrawHelpers");
18
+ async function withdrawWithErc20Wrapping(accountAddress, shares, vaultAddress, signer, dex, percentSlippage = 1, overrides) {
19
+ if (!signer.provider) {
20
+ throw new Error('Signer must be connected to a provider');
21
+ }
22
+ const jsonProvider = signer.provider;
23
+ const { chainId, vault } = await (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex);
24
+ // This function is only applicable for BONZO vaults on Hedera
25
+ if (dex !== types_1.SupportedDex.Bonzo || chainId !== types_1.SupportedChainId.hedera) {
26
+ throw new Error(`withdrawWithErc20Wrapping is only supported for Bonzo vaults on Hedera. Got dex: ${dex}, chainId: ${chainId}`);
27
+ }
28
+ const vaultDeployerAddress = (0, vaultBasics_1.default)(vaultAddress, chainId, dex);
29
+ const userShares = (0, userBalances_1.getUserBalance)(accountAddress, vaultAddress, jsonProvider, dex, true);
30
+ const withdrawShares = typeof shares === 'bigint' ? shares : (0, parseBigInt_1.default)(shares, 18);
31
+ if ((await userShares) < withdrawShares) {
32
+ throw new Error(`Withdraw amount exceeds user shares amount in vault ${vaultAddress} on chain ${chainId} and dex ${dex}`);
33
+ }
34
+ const isApproved = await (0, _withdrawHelpers_1._isVaultTokenApproved)(accountAddress, withdrawShares, vault, chainId, jsonProvider, dex);
35
+ if (!isApproved) {
36
+ throw new Error(`Vault token transfer is not approved for vault ${vaultAddress} on chain ${chainId} and dex ${dex}`);
37
+ }
38
+ // Obtain Deposit Guard with HTS Wrapping contract
39
+ const depositGuardAddress = addresses_1.addressConfig[chainId][dex]?.depositGuard.address;
40
+ if (!depositGuardAddress) {
41
+ throw new Error(`Deposit Guard for vault ${vaultAddress} not found on chain ${chainId} and dex ${dex}`);
42
+ }
43
+ const depositGuardContract = (0, contracts_1.getDepositGuardWithHtsWrappingContract)(depositGuardAddress, signer);
44
+ const maxGasLimit = (0, calculateGasMargin_1.getGasLimit)(chainId);
45
+ // the first call: get estimated amounts
46
+ let amounts = await depositGuardContract.withdrawFromICHIVaultAndTryUnwrapToERC20.staticCall(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, 0n, 0n, {
47
+ gasLimit: maxGasLimit,
48
+ });
49
+ // reduce the estimated amounts by an acceptable slippage %, default - 1%
50
+ if (percentSlippage < 0.01)
51
+ throw new Error('Slippage parameter is less than 0.01%.');
52
+ if (percentSlippage > 100)
53
+ throw new Error('Slippage parameter is more than 100%.');
54
+ amounts = {
55
+ 0: (0, amountWithSlippage_1.default)(amounts[0], percentSlippage),
56
+ 1: (0, amountWithSlippage_1.default)(amounts[1], percentSlippage),
57
+ amount0: (0, amountWithSlippage_1.default)(amounts[0], percentSlippage),
58
+ amount1: (0, amountWithSlippage_1.default)(amounts[1], percentSlippage),
59
+ };
60
+ const gasLimit = overrides?.gasLimit ??
61
+ (0, calculateGasMargin_1.calculateGasMargin)(await depositGuardContract.withdrawFromICHIVaultAndTryUnwrapToERC20.estimateGas(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, amounts[0], amounts[1]));
62
+ // the second call: actual withdraw transaction
63
+ const tx = await depositGuardContract.withdrawFromICHIVaultAndTryUnwrapToERC20(vaultAddress, vaultDeployerAddress, withdrawShares, accountAddress, amounts[0], amounts[1], {
64
+ ...overrides,
65
+ gasLimit,
134
66
  });
67
+ return tx;
135
68
  }
136
69
  exports.withdrawWithErc20Wrapping = withdrawWithErc20Wrapping;
137
70
  //# sourceMappingURL=withdrawWithErc20Wrapping.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withdrawWithErc20Wrapping.js","sourceRoot":"","sources":["../../../src/functions/withdrawWithErc20Wrapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iCAAmC;AACnC,0CAAsE;AACtE,qEAA+C;AAC/C,kCAA0D;AAC1D,kEAA8E;AAC9E,2CAA2C;AAC3C,iCAA4C;AAC5C,uDAA0D;AAC1D,mFAA6D;AAC7D,+CAAgD;AAChD,8DAA6C;AAC7C,uDAA2D;AAE3D,SAAsB,yBAAyB,CAC7C,cAAsB,EACtB,MAAmC,EACnC,YAAoB,EACpB,YAA6B,EAC7B,GAAiB,EACjB,eAAmB,EACnB,SAAqB;;IADrB,gCAAA,EAAA,mBAAmB;;;;;wBAGQ,qBAAM,IAAA,yBAAiB,EAAC,YAAY,EAAE,YAAY,EAAE,GAAG,CAAC,EAAA;;oBAA7E,KAAqB,SAAwD,EAA3E,OAAO,aAAA,EAAE,KAAK,WAAA;oBAEtB,8DAA8D;oBAC9D,IAAI,GAAG,KAAK,oBAAY,CAAC,KAAK,IAAI,OAAO,KAAK,wBAAgB,CAAC,MAAM,EAAE;wBACrE,MAAM,IAAI,KAAK,CACb,2FAAoF,GAAG,wBAAc,OAAO,CAAE,CAC/G,CAAC;qBACH;oBAEK,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;oBAEhD,oBAAoB,GAAG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