@curvefi/llamalend-api 1.0.2

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 (125) hide show
  1. package/.eslintrc.json +40 -0
  2. package/.github/workflows/lint.yml +15 -0
  3. package/.github/workflows/publish.yml +55 -0
  4. package/LICENSE +21 -0
  5. package/README.md +1976 -0
  6. package/lib/cache/index.d.ts +14 -0
  7. package/lib/cache/index.js +31 -0
  8. package/lib/constants/L2Networks.d.ts +1 -0
  9. package/lib/constants/L2Networks.js +1 -0
  10. package/lib/constants/abis/Controller.json +1027 -0
  11. package/lib/constants/abis/ERC20.json +222 -0
  12. package/lib/constants/abis/ERC4626.json +1674 -0
  13. package/lib/constants/abis/GaugeController.json +794 -0
  14. package/lib/constants/abis/GaugeFactoryMainnet.json +1 -0
  15. package/lib/constants/abis/GaugeFactorySidechain.json +475 -0
  16. package/lib/constants/abis/GaugeV5.json +958 -0
  17. package/lib/constants/abis/LeverageZap.json +35 -0
  18. package/lib/constants/abis/Llamma.json +984 -0
  19. package/lib/constants/abis/Minter.json +1 -0
  20. package/lib/constants/abis/MonetaryPolicy.json +221 -0
  21. package/lib/constants/abis/OneWayLendingFactoryABI.json +899 -0
  22. package/lib/constants/abis/SidechainGauge.json +939 -0
  23. package/lib/constants/abis/Vault.json +721 -0
  24. package/lib/constants/abis/crvUSD/DeleverageZap.json +248 -0
  25. package/lib/constants/abis/crvUSD/Factory.json +514 -0
  26. package/lib/constants/abis/crvUSD/HealthCalculatorZap.json +54 -0
  27. package/lib/constants/abis/crvUSD/LeverageZap.json +312 -0
  28. package/lib/constants/abis/crvUSD/MonetaryPolicy.json +294 -0
  29. package/lib/constants/abis/crvUSD/MonetaryPolicy2.json +299 -0
  30. package/lib/constants/abis/crvUSD/PegKeeper.json +411 -0
  31. package/lib/constants/abis/crvUSD/controller.json +991 -0
  32. package/lib/constants/abis/crvUSD/llamma.json +984 -0
  33. package/lib/constants/abis/gas_oracle_optimism.json +149 -0
  34. package/lib/constants/abis/gas_oracle_optimism_blob.json +203 -0
  35. package/lib/constants/aliases.d.ts +16 -0
  36. package/lib/constants/aliases.js +124 -0
  37. package/lib/constants/coins.d.ts +16 -0
  38. package/lib/constants/coins.js +24 -0
  39. package/lib/constants/llammas.d.ts +2 -0
  40. package/lib/constants/llammas.js +96 -0
  41. package/lib/constants/utils.d.ts +4 -0
  42. package/lib/constants/utils.js +27 -0
  43. package/lib/external-api.d.ts +13 -0
  44. package/lib/external-api.js +436 -0
  45. package/lib/index.d.ts +104 -0
  46. package/lib/index.js +123 -0
  47. package/lib/interfaces.d.ts +228 -0
  48. package/lib/interfaces.js +1 -0
  49. package/lib/lendMarkets/LendMarketTemplate.d.ts +510 -0
  50. package/lib/lendMarkets/LendMarketTemplate.js +4682 -0
  51. package/lib/lendMarkets/index.d.ts +3 -0
  52. package/lib/lendMarkets/index.js +3 -0
  53. package/lib/lendMarkets/lendMarketConstructor.d.ts +2 -0
  54. package/lib/lendMarkets/lendMarketConstructor.js +6 -0
  55. package/lib/llamalend.d.ts +80 -0
  56. package/lib/llamalend.js +878 -0
  57. package/lib/mintMarkets/MintMarketTemplate.d.ts +308 -0
  58. package/lib/mintMarkets/MintMarketTemplate.js +2998 -0
  59. package/lib/mintMarkets/index.d.ts +3 -0
  60. package/lib/mintMarkets/index.js +3 -0
  61. package/lib/mintMarkets/mintMarketConstructor.d.ts +2 -0
  62. package/lib/mintMarkets/mintMarketConstructor.js +4 -0
  63. package/lib/st-crvUSD.d.ts +35 -0
  64. package/lib/st-crvUSD.js +505 -0
  65. package/lib/utils.d.ts +58 -0
  66. package/lib/utils.js +661 -0
  67. package/package.json +42 -0
  68. package/src/cache/index.ts +41 -0
  69. package/src/constants/L2Networks.ts +1 -0
  70. package/src/constants/abis/Controller.json +1027 -0
  71. package/src/constants/abis/ERC20.json +222 -0
  72. package/src/constants/abis/ERC4626.json +1674 -0
  73. package/src/constants/abis/GaugeController.json +794 -0
  74. package/src/constants/abis/GaugeFactoryMainnet.json +1 -0
  75. package/src/constants/abis/GaugeFactorySidechain.json +475 -0
  76. package/src/constants/abis/GaugeV5.json +958 -0
  77. package/src/constants/abis/LeverageZap.json +35 -0
  78. package/src/constants/abis/Llamma.json +984 -0
  79. package/src/constants/abis/Minter.json +1 -0
  80. package/src/constants/abis/MonetaryPolicy.json +221 -0
  81. package/src/constants/abis/OneWayLendingFactoryABI.json +899 -0
  82. package/src/constants/abis/SidechainGauge.json +939 -0
  83. package/src/constants/abis/Vault.json +721 -0
  84. package/src/constants/abis/crvUSD/DeleverageZap.json +248 -0
  85. package/src/constants/abis/crvUSD/ERC20.json +222 -0
  86. package/src/constants/abis/crvUSD/Factory.json +514 -0
  87. package/src/constants/abis/crvUSD/HealthCalculatorZap.json +54 -0
  88. package/src/constants/abis/crvUSD/LeverageZap.json +312 -0
  89. package/src/constants/abis/crvUSD/MonetaryPolicy.json +294 -0
  90. package/src/constants/abis/crvUSD/MonetaryPolicy2.json +299 -0
  91. package/src/constants/abis/crvUSD/PegKeeper.json +411 -0
  92. package/src/constants/abis/crvUSD/controller.json +991 -0
  93. package/src/constants/abis/crvUSD/llamma.json +984 -0
  94. package/src/constants/abis/gas_oracle_optimism.json +149 -0
  95. package/src/constants/abis/gas_oracle_optimism_blob.json +203 -0
  96. package/src/constants/aliases.ts +141 -0
  97. package/src/constants/coins.ts +41 -0
  98. package/src/constants/llammas.ts +99 -0
  99. package/src/constants/utils.ts +33 -0
  100. package/src/external-api.ts +325 -0
  101. package/src/index.ts +128 -0
  102. package/src/interfaces.ts +237 -0
  103. package/src/lendMarkets/LendMarketTemplate.ts +3022 -0
  104. package/src/lendMarkets/index.ts +7 -0
  105. package/src/lendMarkets/lendMarketConstructor.ts +7 -0
  106. package/src/llamalend.ts +785 -0
  107. package/src/mintMarkets/MintMarketTemplate.ts +1781 -0
  108. package/src/mintMarkets/index.ts +7 -0
  109. package/src/mintMarkets/mintMarketConstructor.ts +5 -0
  110. package/src/st-crvUSD.ts +244 -0
  111. package/src/utils.ts +497 -0
  112. package/test/fetch.test.ts +152 -0
  113. package/test/general.test.ts +216 -0
  114. package/test/leverageBorrowMore.test.ts +245 -0
  115. package/test/leverageCreateLoan.test.ts +236 -0
  116. package/test/leverageRepay.test.ts +240 -0
  117. package/test/readme.test.ts +475 -0
  118. package/test/selfLiquidate.test.ts +57 -0
  119. package/test/selfLiquidateCrvUSD.test.ts +54 -0
  120. package/test/st_crvUSD.test.ts +68 -0
  121. package/test/swap.test.ts +62 -0
  122. package/test/swapCrvUSD.test.ts +56 -0
  123. package/test/vault.test.ts +112 -0
  124. package/tsconfig.build.json +10 -0
  125. package/tsconfig.json +72 -0
@@ -0,0 +1,13 @@
1
+ import memoize from "memoizee";
2
+ import { INetworkName, I1inchSwapData, IDict, IMarketData, IQuoteOdos } from "./interfaces";
3
+ export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
4
+ export declare const _getUserCollateral: ((network: INetworkName, controller: string, user: string) => Promise<Record<string, any>>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<Record<string, any>>>;
5
+ export declare const _getUserCollateralCrvUsd: ((network: INetworkName, controller: string, user: string) => Promise<string>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<string>>;
6
+ export declare const _getMarketsData: ((network: INetworkName) => Promise<IMarketData>) & memoize.Memoized<(network: INetworkName) => Promise<IMarketData>>;
7
+ export declare const _getQuoteOdos: (fromToken: string, toToken: string, _amount: bigint, blacklist: string, pathVizImage: boolean, slippage?: number) => Promise<IQuoteOdos>;
8
+ export declare const _getExpectedOdos: (fromToken: string, toToken: string, _amount: bigint, blacklist: string) => Promise<string>;
9
+ export declare const _assembleTxOdos: ((pathId: string) => Promise<string>) & memoize.Memoized<(pathId: string) => Promise<string>>;
10
+ export declare const _getSpotPriceOdos: ((fromToken: string, toToken: string) => Promise<string | undefined>) & memoize.Memoized<(fromToken: string, toToken: string) => Promise<string | undefined>>;
11
+ export declare const _getExpected1inch: ((fromToken: string, toToken: string, _amount: bigint) => Promise<string>) & memoize.Memoized<(fromToken: string, toToken: string, _amount: bigint) => Promise<string>>;
12
+ export declare const _getSwapData1inch: ((fromToken: string, toToken: string, _amount: bigint, slippage: number) => Promise<I1inchSwapData>) & memoize.Memoized<(fromToken: string, toToken: string, _amount: bigint, slippage: number) => Promise<I1inchSwapData>>;
13
+ export declare const _getSpotPrice1inch: ((fromToken: string, toToken: string) => Promise<string | undefined>) & memoize.Memoized<(fromToken: string, toToken: string) => Promise<string | undefined>>;
@@ -0,0 +1,436 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import axios from "axios";
49
+ import { ethers } from "ethers";
50
+ import memoize from "memoizee";
51
+ import BigNumber from 'bignumber.js';
52
+ import { llamalend } from "./llamalend.js";
53
+ var _getPoolsFromApi = memoize(function (network, poolFactory) { return __awaiter(void 0, void 0, void 0, function () {
54
+ var url, response;
55
+ var _a;
56
+ return __generator(this, function (_b) {
57
+ switch (_b.label) {
58
+ case 0:
59
+ url = "https://api.curve.fi/api/getPools/".concat(network, "/").concat(poolFactory);
60
+ return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
61
+ case 1:
62
+ response = _b.sent();
63
+ return [2 /*return*/, (_a = response.data.data) !== null && _a !== void 0 ? _a : { poolData: [], tvl: 0, tvlAll: 0 }];
64
+ }
65
+ });
66
+ }); }, {
67
+ promise: true,
68
+ maxAge: 5 * 60 * 1000, // 5m
69
+ });
70
+ var _getAllPoolsFromApi = function (network) { return __awaiter(void 0, void 0, void 0, function () {
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4 /*yield*/, Promise.all([
74
+ _getPoolsFromApi(network, "main"),
75
+ _getPoolsFromApi(network, "crypto"),
76
+ _getPoolsFromApi(network, "factory"),
77
+ _getPoolsFromApi(network, "factory-crvusd"),
78
+ _getPoolsFromApi(network, "factory-crypto"),
79
+ _getPoolsFromApi(network, "factory-twocrypto"),
80
+ _getPoolsFromApi(network, "factory-tricrypto"),
81
+ _getPoolsFromApi(network, "factory-stable-ng"),
82
+ ])];
83
+ case 1: return [2 /*return*/, _a.sent()];
84
+ }
85
+ });
86
+ }); };
87
+ export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
88
+ var network, allTypesExtendedPoolData, priceDict, priceDictByMaxTvl, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, lpTokenAddress, totalSupply, _c, _d, coin, _e, _f, coin, address, maxTvlItem;
89
+ var _g, _h;
90
+ return __generator(this, function (_j) {
91
+ switch (_j.label) {
92
+ case 0:
93
+ network = llamalend.constants.NETWORK_NAME;
94
+ return [4 /*yield*/, _getAllPoolsFromApi(network)];
95
+ case 1:
96
+ allTypesExtendedPoolData = _j.sent();
97
+ priceDict = {};
98
+ priceDictByMaxTvl = {};
99
+ for (_i = 0, allTypesExtendedPoolData_1 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_1.length; _i++) {
100
+ extendedPoolData = allTypesExtendedPoolData_1[_i];
101
+ for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
102
+ pool = _b[_a];
103
+ lpTokenAddress = (_g = pool.lpTokenAddress) !== null && _g !== void 0 ? _g : pool.address;
104
+ totalSupply = pool.totalSupply / (Math.pow(10, 18));
105
+ if (lpTokenAddress.toLowerCase() in priceDict) {
106
+ priceDict[lpTokenAddress.toLowerCase()].push({
107
+ price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
108
+ tvl: pool.usdTotal,
109
+ });
110
+ }
111
+ else {
112
+ priceDict[lpTokenAddress.toLowerCase()] = [];
113
+ priceDict[lpTokenAddress.toLowerCase()].push({
114
+ price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
115
+ tvl: pool.usdTotal,
116
+ });
117
+ }
118
+ for (_c = 0, _d = pool.coins; _c < _d.length; _c++) {
119
+ coin = _d[_c];
120
+ if (typeof coin.usdPrice === "number") {
121
+ if (coin.address.toLowerCase() in priceDict) {
122
+ priceDict[coin.address.toLowerCase()].push({
123
+ price: coin.usdPrice,
124
+ tvl: pool.usdTotal,
125
+ });
126
+ }
127
+ else {
128
+ priceDict[coin.address.toLowerCase()] = [];
129
+ priceDict[coin.address.toLowerCase()].push({
130
+ price: coin.usdPrice,
131
+ tvl: pool.usdTotal,
132
+ });
133
+ }
134
+ }
135
+ }
136
+ for (_e = 0, _f = (_h = pool.gaugeRewards) !== null && _h !== void 0 ? _h : []; _e < _f.length; _e++) {
137
+ coin = _f[_e];
138
+ if (typeof coin.tokenPrice === "number") {
139
+ if (coin.tokenAddress.toLowerCase() in priceDict) {
140
+ priceDict[coin.tokenAddress.toLowerCase()].push({
141
+ price: coin.tokenPrice,
142
+ tvl: pool.usdTotal,
143
+ });
144
+ }
145
+ else {
146
+ priceDict[coin.tokenAddress.toLowerCase()] = [];
147
+ priceDict[coin.tokenAddress.toLowerCase()].push({
148
+ price: coin.tokenPrice,
149
+ tvl: pool.usdTotal,
150
+ });
151
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+ for (address in priceDict) {
157
+ if (priceDict[address].length > 0) {
158
+ maxTvlItem = priceDict[address].reduce(function (prev, current) {
159
+ if (+current.tvl > +prev.tvl) {
160
+ return current;
161
+ }
162
+ else {
163
+ return prev;
164
+ }
165
+ });
166
+ priceDictByMaxTvl[address] = maxTvlItem.price;
167
+ }
168
+ else {
169
+ priceDictByMaxTvl[address] = 0;
170
+ }
171
+ }
172
+ return [2 /*return*/, priceDictByMaxTvl];
173
+ }
174
+ });
175
+ }); };
176
+ export var _getUserCollateral = memoize(function (network, controller, user) { return __awaiter(void 0, void 0, void 0, function () {
177
+ var url, response;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ url = "https://prices.curve.fi/v1/lending/collateral_events/".concat(network, "/").concat(controller, "/").concat(user);
182
+ return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
183
+ case 1:
184
+ response = _a.sent();
185
+ return [2 /*return*/, {
186
+ total_deposit_precise: response.data.total_deposit_precise,
187
+ total_deposit_from_user: response.data.total_deposit_from_user,
188
+ total_deposit_usd_value: response.data.total_deposit_usd_value,
189
+ }];
190
+ }
191
+ });
192
+ }); }, {
193
+ promise: true,
194
+ maxAge: 60 * 1000, // 1m
195
+ });
196
+ export var _getUserCollateralCrvUsd = memoize(function (network, controller, user) { return __awaiter(void 0, void 0, void 0, function () {
197
+ var url, response;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ url = "https://prices.curve.fi/v1/crvusd/collateral_events/".concat(network, "/").concat(controller, "/").concat(user);
202
+ return [4 /*yield*/, axios.get(url, { validateStatus: function () { return true; } })];
203
+ case 1:
204
+ response = _a.sent();
205
+ return [2 /*return*/, response.data.total_deposit];
206
+ }
207
+ });
208
+ }); }, {
209
+ promise: true,
210
+ maxAge: 60 * 1000, // 1m
211
+ });
212
+ export var _getMarketsData = memoize(function (network) { return __awaiter(void 0, void 0, void 0, function () {
213
+ var url, response;
214
+ return __generator(this, function (_a) {
215
+ switch (_a.label) {
216
+ case 0:
217
+ url = "https://api.curve.fi/api/getLendingVaults/".concat(network, "/oneway");
218
+ return [4 /*yield*/, axios.get(url, {
219
+ headers: { "accept": "application/json" },
220
+ validateStatus: function () { return true; },
221
+ })];
222
+ case 1:
223
+ response = _a.sent();
224
+ if (response.status !== 200) {
225
+ throw Error("Fetch error: ".concat(response.status, " ").concat(response.statusText));
226
+ }
227
+ return [2 /*return*/, response.data.data];
228
+ }
229
+ });
230
+ }); }, {
231
+ promise: true,
232
+ maxAge: 10 * 1000, // 10s
233
+ });
234
+ // --- ODOS ---
235
+ export var _getQuoteOdos = function (fromToken, toToken, _amount, blacklist, pathVizImage, slippage) {
236
+ if (slippage === void 0) { slippage = 0.5; }
237
+ return __awaiter(void 0, void 0, void 0, function () {
238
+ var url, response;
239
+ return __generator(this, function (_a) {
240
+ switch (_a.label) {
241
+ case 0:
242
+ if (_amount === BigInt(0))
243
+ return [2 /*return*/, { outAmounts: ["0.0"], pathId: '', pathVizImage: '', priceImpact: 0, slippage: slippage }];
244
+ if (ethers.getAddress(fromToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE")
245
+ fromToken = "0x0000000000000000000000000000000000000000";
246
+ if (ethers.getAddress(toToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE")
247
+ toToken = "0x0000000000000000000000000000000000000000";
248
+ url = "https://prices.curve.fi/odos/quote?chain_id=".concat(llamalend.chainId, "&from_address=").concat(ethers.getAddress(fromToken)) +
249
+ "&to_address=".concat(ethers.getAddress(toToken), "&amount=").concat(_amount.toString(), "&slippage=").concat(slippage, "&pathVizImage=").concat(pathVizImage) +
250
+ "&caller_address=".concat(ethers.getAddress(llamalend.constants.ALIASES.leverage_zap), "&blacklist=").concat(ethers.getAddress(blacklist));
251
+ return [4 /*yield*/, axios.get(url, {
252
+ headers: { "accept": "application/json" },
253
+ validateStatus: function () { return true; },
254
+ })];
255
+ case 1:
256
+ response = _a.sent();
257
+ if (response.status !== 200) {
258
+ throw Error("Odos quote error - ".concat(response.status, " ").concat(response.statusText));
259
+ }
260
+ return [2 /*return*/, __assign(__assign({}, response.data), { slippage: slippage })];
261
+ }
262
+ });
263
+ });
264
+ };
265
+ export var _getExpectedOdos = function (fromToken, toToken, _amount, blacklist) { return __awaiter(void 0, void 0, void 0, function () {
266
+ return __generator(this, function (_a) {
267
+ switch (_a.label) {
268
+ case 0: return [4 /*yield*/, _getQuoteOdos(fromToken, toToken, _amount, blacklist, false)];
269
+ case 1: return [2 /*return*/, (_a.sent()).outAmounts[0]];
270
+ }
271
+ });
272
+ }); };
273
+ export var _assembleTxOdos = memoize(function (pathId) { return __awaiter(void 0, void 0, void 0, function () {
274
+ var url, response;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ url = "https://prices.curve.fi/odos/assemble?user=".concat(ethers.getAddress(llamalend.constants.ALIASES.leverage_zap), "&path_id=").concat(pathId);
279
+ return [4 /*yield*/, axios.get(url, {
280
+ headers: { 'Content-Type': 'application/json' },
281
+ validateStatus: function () { return true; },
282
+ })];
283
+ case 1:
284
+ response = _a.sent();
285
+ if (response.status !== 200) {
286
+ throw Error("Odos assemble error - ".concat(response.status, " ").concat(response.statusText));
287
+ }
288
+ return [2 /*return*/, response.data['transaction']['data']];
289
+ }
290
+ });
291
+ }); }, {
292
+ promise: true,
293
+ maxAge: 10 * 1000, // 10s
294
+ });
295
+ export var _getSpotPriceOdos = memoize(function (fromToken, toToken) { return __awaiter(void 0, void 0, void 0, function () {
296
+ var url, response, pricesFromOdos, pricesFromApi, _i, _a, coin, _pricesFromApi, prices;
297
+ return __generator(this, function (_b) {
298
+ switch (_b.label) {
299
+ case 0:
300
+ fromToken = ethers.getAddress(fromToken);
301
+ toToken = ethers.getAddress(toToken);
302
+ url = "https://prices.curve.fi/odos/prices?chain_id=".concat(llamalend.chainId, "&tokens=").concat(fromToken, ",").concat(toToken);
303
+ return [4 /*yield*/, axios.get(url, {
304
+ headers: { "accept": "application/json" },
305
+ validateStatus: function () { return true; },
306
+ })];
307
+ case 1:
308
+ response = _b.sent();
309
+ if (response.status !== 200) {
310
+ throw Error("Odos spot prices error - ".concat(response.status, " ").concat(response.statusText));
311
+ }
312
+ pricesFromOdos = response.data.tokenPrices;
313
+ pricesFromApi = {};
314
+ _i = 0, _a = [fromToken, toToken];
315
+ _b.label = 2;
316
+ case 2:
317
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
318
+ coin = _a[_i];
319
+ if (pricesFromOdos[coin] !== 0)
320
+ return [3 /*break*/, 4];
321
+ return [4 /*yield*/, _getUsdPricesFromApi()];
322
+ case 3:
323
+ _pricesFromApi = _b.sent();
324
+ pricesFromApi[coin] = String(_pricesFromApi[coin] || 0);
325
+ _b.label = 4;
326
+ case 4:
327
+ _i++;
328
+ return [3 /*break*/, 2];
329
+ case 5:
330
+ prices = __assign(__assign({}, pricesFromOdos), pricesFromApi);
331
+ if (BigNumber(prices[fromToken]).eq(0) || BigNumber(prices[toToken]).eq(0))
332
+ return [2 /*return*/, undefined];
333
+ return [2 /*return*/, (new BigNumber(prices[toToken])).div(prices[fromToken]).toString()];
334
+ }
335
+ });
336
+ }); }, {
337
+ promise: true,
338
+ maxAge: 10 * 1000, // 10s
339
+ });
340
+ // --- 1INCH ---
341
+ export var _getExpected1inch = memoize(function (fromToken, toToken, _amount) { return __awaiter(void 0, void 0, void 0, function () {
342
+ var url, response;
343
+ return __generator(this, function (_a) {
344
+ switch (_a.label) {
345
+ case 0:
346
+ if (_amount === BigInt(0))
347
+ return [2 /*return*/, "0.0"];
348
+ url = "https://prices.curve.fi/1inch/swap/v6.0/".concat(llamalend.chainId, "/quote?src=").concat(fromToken, "&dst=").concat(toToken, "&amount=").concat(_amount, "&excludedProtocols=").concat(llamalend.constants.EXCLUDED_PROTOCOLS_1INCH, "&includeTokensInfo=true&includeProtocols=true");
349
+ return [4 /*yield*/, axios.get(url, {
350
+ headers: { "accept": "application/json" },
351
+ validateStatus: function () { return true; },
352
+ })];
353
+ case 1:
354
+ response = _a.sent();
355
+ if (response.status !== 200) {
356
+ throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
357
+ }
358
+ return [2 /*return*/, response.data.dstAmount];
359
+ }
360
+ });
361
+ }); }, {
362
+ promise: true,
363
+ maxAge: 10 * 1000, // 10s
364
+ });
365
+ export var _getSwapData1inch = memoize(function (fromToken, toToken, _amount, slippage) { return __awaiter(void 0, void 0, void 0, function () {
366
+ var url, response;
367
+ return __generator(this, function (_a) {
368
+ switch (_a.label) {
369
+ case 0:
370
+ if (_amount === BigInt(0))
371
+ throw Error("Amount must be > 0");
372
+ url = "https://prices.curve.fi/1inch/swap/v6.0/".concat(llamalend.chainId, "/swap?src=").concat(fromToken, "&dst=").concat(toToken, "&amount=").concat(_amount, "&from_=").concat(llamalend.constants.ALIASES.leverage_zap, "&slippage=").concat(slippage, "&excludedProtocols=").concat(llamalend.constants.EXCLUDED_PROTOCOLS_1INCH, "&includeTokensInfo=true&includeProtocols=true&disableEstimate=true");
373
+ return [4 /*yield*/, axios.get(url, {
374
+ headers: { "accept": "application/json" },
375
+ validateStatus: function () { return true; },
376
+ })];
377
+ case 1:
378
+ response = _a.sent();
379
+ if (response.status !== 200) {
380
+ throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
381
+ }
382
+ return [2 /*return*/, response.data];
383
+ }
384
+ });
385
+ }); }, {
386
+ promise: true,
387
+ maxAge: 10 * 1000, // 10s
388
+ });
389
+ export var _getSpotPrice1inch = memoize(function (fromToken, toToken) { return __awaiter(void 0, void 0, void 0, function () {
390
+ var url, response, pricesFromApi, _a, _b, _c, _i, coin, _pricesFromApi, prices;
391
+ return __generator(this, function (_d) {
392
+ switch (_d.label) {
393
+ case 0:
394
+ url = "https://prices.curve.fi/1inch/price/v1.1/".concat(llamalend.chainId, "?tokens=").concat(fromToken, ",").concat(toToken, "&currency=USD");
395
+ return [4 /*yield*/, axios.get(url, {
396
+ headers: { "accept": "application/json" },
397
+ validateStatus: function () { return true; },
398
+ })];
399
+ case 1:
400
+ response = _d.sent();
401
+ if (response.status !== 200) {
402
+ throw Error("1inch error: ".concat(response.status, " ").concat(response.statusText));
403
+ }
404
+ pricesFromApi = {};
405
+ _a = response.data;
406
+ _b = [];
407
+ for (_c in _a)
408
+ _b.push(_c);
409
+ _i = 0;
410
+ _d.label = 2;
411
+ case 2:
412
+ if (!(_i < _b.length)) return [3 /*break*/, 5];
413
+ _c = _b[_i];
414
+ if (!(_c in _a)) return [3 /*break*/, 4];
415
+ coin = _c;
416
+ if (response.data[coin] !== "0")
417
+ return [3 /*break*/, 4];
418
+ return [4 /*yield*/, _getUsdPricesFromApi()];
419
+ case 3:
420
+ _pricesFromApi = _d.sent();
421
+ pricesFromApi[coin] = String(_pricesFromApi[coin] || 0);
422
+ _d.label = 4;
423
+ case 4:
424
+ _i++;
425
+ return [3 /*break*/, 2];
426
+ case 5:
427
+ prices = __assign(__assign({}, response.data), pricesFromApi);
428
+ if (prices[fromToken] === '0' || prices[toToken] === '0')
429
+ return [2 /*return*/, undefined];
430
+ return [2 /*return*/, (new BigNumber(prices[toToken])).div(prices[fromToken]).toString()];
431
+ }
432
+ });
433
+ }); }, {
434
+ promise: true,
435
+ maxAge: 10 * 1000, // 10s
436
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ /// <reference types="memoizee" />
2
+ import { ethers, Networkish } from "ethers";
3
+ import { LendMarketTemplate } from "./lendMarkets/index.js";
4
+ import { MintMarketTemplate } from "./mintMarkets/index.js";
5
+ declare function init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', providerSettings: {
6
+ url?: string;
7
+ privateKey?: string;
8
+ batchMaxCount?: number;
9
+ } | {
10
+ externalProvider: ethers.Eip1193Provider;
11
+ } | {
12
+ network?: Networkish;
13
+ apiKey?: string;
14
+ }, options?: {
15
+ gasPrice?: number;
16
+ maxFeePerGas?: number;
17
+ maxPriorityFeePerGas?: number;
18
+ chainId?: number;
19
+ }): Promise<void>;
20
+ declare function setCustomFeeData(customFeeData: {
21
+ gasPrice?: number;
22
+ maxFeePerGas?: number;
23
+ maxPriorityFeePerGas?: number;
24
+ }): void;
25
+ declare const llamalend: {
26
+ init: typeof init;
27
+ chainId: number;
28
+ signerAddress: string;
29
+ LendMarketTemplate: typeof LendMarketTemplate;
30
+ getLendMarket: (lendMarketId: string) => LendMarketTemplate;
31
+ MintMarketTemplate: typeof MintMarketTemplate;
32
+ getMintMarket: (mintMarketId: string) => MintMarketTemplate;
33
+ totalSupply: () => Promise<{
34
+ total: string;
35
+ minted: string;
36
+ pegKeepersDebt: string;
37
+ }>;
38
+ getLsdApy: ((name: "sfrxETH" | "wstETH") => Promise<{
39
+ apy: number;
40
+ baseApy: number;
41
+ apyMean30d: number;
42
+ }>) & import("memoizee").Memoized<(name: "sfrxETH" | "wstETH") => Promise<{
43
+ apy: number;
44
+ baseApy: number;
45
+ apyMean30d: number;
46
+ }>>;
47
+ setCustomFeeData: typeof setCustomFeeData;
48
+ getBalances: (coins: string[], address?: string) => Promise<string[]>;
49
+ getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
50
+ hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
51
+ ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<string[]>;
52
+ getUsdRate: (coin: string) => Promise<number>;
53
+ getGasPriceFromL1: () => Promise<number>;
54
+ getGasPriceFromL2: () => Promise<number>;
55
+ getGasInfoForL2: () => Promise<Record<string, number>>;
56
+ fetchStats: (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[]) => Promise<void>;
57
+ getLlammaList: () => string[];
58
+ lendMarkets: {
59
+ fetchMarkets: (useAPI?: boolean) => Promise<void>;
60
+ getMarketList: () => string[];
61
+ };
62
+ estimateGas: {
63
+ ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<import("./interfaces.js").TGas>;
64
+ };
65
+ st_crvUSD: {
66
+ convertToAssets: (shares: import("./interfaces.js").TAmount) => Promise<string>;
67
+ convertToShares: (assets: import("./interfaces.js").TAmount) => Promise<string>;
68
+ userBalances: (address?: string) => Promise<{
69
+ crvUSD: string;
70
+ st_crvUSD: string;
71
+ }>;
72
+ totalSupplyAndCrvUSDLocked: () => Promise<{
73
+ crvUSD: string;
74
+ st_crvUSD: string;
75
+ }>;
76
+ maxDeposit: (address?: string) => Promise<string>;
77
+ previewDeposit: (assets: import("./interfaces.js").TAmount) => Promise<string>;
78
+ depositIsApproved: (assets: import("./interfaces.js").TAmount) => Promise<boolean>;
79
+ depositAllowance: () => Promise<string[]>;
80
+ depositApprove: (assets: import("./interfaces.js").TAmount, isMax?: boolean) => Promise<string[]>;
81
+ deposit: (assets: import("./interfaces.js").TAmount) => Promise<string>;
82
+ maxMint: (address?: string) => Promise<string>;
83
+ previewMint: (shares: import("./interfaces.js").TAmount) => Promise<string>;
84
+ mintIsApproved: (shares: import("./interfaces.js").TAmount) => Promise<boolean>;
85
+ mintAllowance: () => Promise<string[]>;
86
+ mintApprove: (shares: import("./interfaces.js").TAmount, isMax?: boolean) => Promise<string[]>;
87
+ mint: (shares: import("./interfaces.js").TAmount) => Promise<string>;
88
+ maxWithdraw: (address?: string) => Promise<string>;
89
+ previewWithdraw: (assets: import("./interfaces.js").TAmount) => Promise<string>;
90
+ withdraw: (assets: import("./interfaces.js").TAmount) => Promise<string>;
91
+ maxRedeem: (address?: string) => Promise<string>;
92
+ previewRedeem: (shares: import("./interfaces.js").TAmount) => Promise<string>;
93
+ redeem: (shares: import("./interfaces.js").TAmount) => Promise<string>;
94
+ estimateGas: {
95
+ depositApprove: (assets: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
96
+ deposit: (assets: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
97
+ mintApprove: (shares: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
98
+ mint: (shares: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
99
+ withdraw: (assets: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
100
+ redeem: (shares: import("./interfaces.js").TAmount) => Promise<import("./interfaces.js").TGas>;
101
+ };
102
+ };
103
+ };
104
+ export default llamalend;