@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
package/lib/index.js ADDED
@@ -0,0 +1,123 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { LendMarketTemplate, getLendMarket } from "./lendMarkets/index.js";
38
+ import { MintMarketTemplate, getMintMarket } from "./mintMarkets/index.js";
39
+ import { llamalend as _llamalend } from "./llamalend.js";
40
+ import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL2, getGasInfoForL2, getGasPriceFromL1, totalSupply, getLsdApy, } from "./utils.js";
41
+ import { convertToAssets, convertToShares, userBalances, totalSupplyAndCrvUSDLocked, maxDeposit, previewDeposit, depositIsApproved, depositAllowance, depositApproveEstimateGas, depositApprove, depositEstimateGas, deposit, maxMint, previewMint, mintIsApproved, mintAllowance, mintApproveEstimateGas, mintApprove, mintEstimateGas, mint, maxWithdraw, previewWithdraw, withdrawEstimateGas, withdraw, maxRedeem, previewRedeem, redeemEstimateGas, redeem, } from "./st-crvUSD.js";
42
+ function init(providerType, providerSettings, options) {
43
+ if (options === void 0) { options = {}; }
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, _llamalend.init(providerType, providerSettings, options)];
48
+ case 1:
49
+ _a.sent();
50
+ // @ts-ignore
51
+ this.signerAddress = _llamalend.signerAddress;
52
+ // @ts-ignore
53
+ this.chainId = _llamalend.chainId;
54
+ return [2 /*return*/];
55
+ }
56
+ });
57
+ });
58
+ }
59
+ function setCustomFeeData(customFeeData) {
60
+ _llamalend.setCustomFeeData(customFeeData);
61
+ }
62
+ var llamalend = {
63
+ init: init,
64
+ chainId: 0,
65
+ signerAddress: '',
66
+ LendMarketTemplate: LendMarketTemplate,
67
+ getLendMarket: getLendMarket,
68
+ MintMarketTemplate: MintMarketTemplate,
69
+ getMintMarket: getMintMarket,
70
+ totalSupply: totalSupply,
71
+ getLsdApy: getLsdApy,
72
+ setCustomFeeData: setCustomFeeData,
73
+ getBalances: getBalances,
74
+ getAllowance: getAllowance,
75
+ hasAllowance: hasAllowance,
76
+ ensureAllowance: ensureAllowance,
77
+ getUsdRate: getUsdRate,
78
+ getGasPriceFromL1: getGasPriceFromL1,
79
+ getGasPriceFromL2: getGasPriceFromL2,
80
+ getGasInfoForL2: getGasInfoForL2,
81
+ fetchStats: _llamalend.fetchStats,
82
+ getLlammaList: _llamalend.getMintMarketList,
83
+ lendMarkets: {
84
+ fetchMarkets: _llamalend.fetchLendMarkets,
85
+ getMarketList: _llamalend.getLendMarketList,
86
+ },
87
+ estimateGas: {
88
+ ensureAllowance: ensureAllowanceEstimateGas,
89
+ },
90
+ st_crvUSD: {
91
+ convertToAssets: convertToAssets,
92
+ convertToShares: convertToShares,
93
+ userBalances: userBalances,
94
+ totalSupplyAndCrvUSDLocked: totalSupplyAndCrvUSDLocked,
95
+ maxDeposit: maxDeposit,
96
+ previewDeposit: previewDeposit,
97
+ depositIsApproved: depositIsApproved,
98
+ depositAllowance: depositAllowance,
99
+ depositApprove: depositApprove,
100
+ deposit: deposit,
101
+ maxMint: maxMint,
102
+ previewMint: previewMint,
103
+ mintIsApproved: mintIsApproved,
104
+ mintAllowance: mintAllowance,
105
+ mintApprove: mintApprove,
106
+ mint: mint,
107
+ maxWithdraw: maxWithdraw,
108
+ previewWithdraw: previewWithdraw,
109
+ withdraw: withdraw,
110
+ maxRedeem: maxRedeem,
111
+ previewRedeem: previewRedeem,
112
+ redeem: redeem,
113
+ estimateGas: {
114
+ depositApprove: depositApproveEstimateGas,
115
+ deposit: depositEstimateGas,
116
+ mintApprove: mintApproveEstimateGas,
117
+ mint: mintEstimateGas,
118
+ withdraw: withdrawEstimateGas,
119
+ redeem: redeemEstimateGas,
120
+ },
121
+ },
122
+ };
123
+ export default llamalend;
@@ -0,0 +1,228 @@
1
+ import { Contract, ethers } from "ethers";
2
+ import { Contract as MulticallContract, Provider as MulticallProvider } from "@curvefi/ethcall";
3
+ export interface IDict<T> {
4
+ [index: string]: T;
5
+ }
6
+ export type INetworkName = "ethereum" | "optimism" | "bsc" | "xdai" | "polygon" | "x-layer" | "fantom" | "fraxtal" | "zksync" | "moonbeam" | "kava" | "mantle" | "base" | "arbitrum" | "celo" | "avalanche" | "aurora";
7
+ export type IChainId = 1 | 10 | 56 | 100 | 137 | 196 | 250 | 252 | 324 | 1284 | 2222 | 5000 | 8453 | 42161 | 42220 | 43114 | 1313161554;
8
+ export type IPoolFactory = "main" | "crypto" | "factory" | "factory-crvusd" | "factory-crypto" | "factory-twocrypto" | "factory-tricrypto" | "factory-stable-ng";
9
+ export interface ICurveContract {
10
+ contract: Contract;
11
+ multicallContract: MulticallContract;
12
+ abi: any;
13
+ address: string;
14
+ }
15
+ export type TAmount = number | string;
16
+ export type TGas = number | number[];
17
+ export interface ILlamma {
18
+ amm_address: string;
19
+ controller_address: string;
20
+ monetary_policy_address: string;
21
+ collateral_address: string;
22
+ leverage_zap: string;
23
+ deleverage_zap: string;
24
+ health_calculator_zap?: string;
25
+ collateral_symbol: string;
26
+ collateral_decimals: number;
27
+ min_bands: number;
28
+ max_bands: number;
29
+ default_bands: number;
30
+ A: number;
31
+ monetary_policy_abi: any;
32
+ }
33
+ export interface ICoin {
34
+ address: string;
35
+ name: string;
36
+ symbol: string;
37
+ decimals: number;
38
+ }
39
+ export interface IOneWayMarket {
40
+ name: string;
41
+ addresses: {
42
+ amm: string;
43
+ controller: string;
44
+ borrowed_token: string;
45
+ collateral_token: string;
46
+ monetary_policy: string;
47
+ vault: string;
48
+ gauge: string;
49
+ };
50
+ borrowed_token: ICoin;
51
+ collateral_token: ICoin;
52
+ }
53
+ export interface ILlamalend {
54
+ provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
55
+ multicallProvider: MulticallProvider;
56
+ signer: ethers.Signer | null;
57
+ signerAddress: string;
58
+ contracts: {
59
+ [index: string]: {
60
+ contract: Contract;
61
+ multicallContract: MulticallContract;
62
+ };
63
+ };
64
+ feeData: {
65
+ gasPrice?: number;
66
+ maxFeePerGas?: number;
67
+ maxPriorityFeePerGas?: number;
68
+ };
69
+ constantOptions: {
70
+ gasLimit: number;
71
+ };
72
+ options: {
73
+ gasPrice?: number | bigint;
74
+ maxFeePerGas?: number | bigint;
75
+ maxPriorityFeePerGas?: number | bigint;
76
+ };
77
+ constants: {
78
+ ONE_WAY_MARKETS: IDict<IOneWayMarket>;
79
+ DECIMALS: IDict<number>;
80
+ NETWORK_NAME: INetworkName;
81
+ ALIASES: Record<string, string>;
82
+ COINS: Record<string, string>;
83
+ ZERO_ADDRESS: string;
84
+ };
85
+ }
86
+ export interface ICoinFromPoolDataApi {
87
+ address: string;
88
+ symbol: string;
89
+ decimals: string;
90
+ usdPrice: number | string;
91
+ }
92
+ export interface IReward {
93
+ gaugeAddress: string;
94
+ tokenAddress: string;
95
+ tokenPrice?: number;
96
+ name?: string;
97
+ symbol: string;
98
+ decimals?: number;
99
+ apy: number;
100
+ }
101
+ export interface IPoolDataFromApi {
102
+ id: string;
103
+ name: string;
104
+ symbol: string;
105
+ assetTypeName: string;
106
+ address: string;
107
+ lpTokenAddress?: string;
108
+ gaugeAddress?: string;
109
+ implementation: string;
110
+ implementationAddress: string;
111
+ coins: ICoinFromPoolDataApi[];
112
+ gaugeRewards?: IReward[];
113
+ usdTotal: number;
114
+ totalSupply: number;
115
+ amplificationCoefficient: string;
116
+ }
117
+ export interface IExtendedPoolDataFromApi {
118
+ poolData: IPoolDataFromApi[];
119
+ tvl?: number;
120
+ tvlAll: number;
121
+ }
122
+ export interface IReward {
123
+ gaugeAddress: string;
124
+ tokenAddress: string;
125
+ symbol: string;
126
+ apy: number;
127
+ }
128
+ export type T1inchRouteStep = {
129
+ name: string;
130
+ part: number;
131
+ fromTokenAddress: string;
132
+ toTokenAddress: string;
133
+ }[];
134
+ export interface I1inchRoute {
135
+ part: number;
136
+ hops: T1inchRouteStep[];
137
+ }
138
+ export interface I1inchSwapData {
139
+ tx: {
140
+ data: string;
141
+ };
142
+ dstAmount: string;
143
+ protocols: I1inchRoute[];
144
+ slippage: number;
145
+ }
146
+ interface Rates {
147
+ borrowApr: number;
148
+ borrowApy: number;
149
+ borrowApyPcent: number;
150
+ lendApr: number;
151
+ lendApy: number;
152
+ lendApyPcent: number;
153
+ }
154
+ interface AssetDetail {
155
+ symbol: string;
156
+ decimals: number;
157
+ address: string;
158
+ blockchainId: string;
159
+ usdPrice: number;
160
+ }
161
+ interface Assets {
162
+ borrowed: AssetDetail;
163
+ collateral: AssetDetail;
164
+ }
165
+ interface VaultShares {
166
+ pricePerShare: number;
167
+ totalShares: number;
168
+ }
169
+ interface Total {
170
+ total: number;
171
+ usdTotal: number;
172
+ }
173
+ interface LendingVaultUrls {
174
+ deposit: string;
175
+ withdraw: string;
176
+ }
177
+ interface AmmBalances {
178
+ ammBalanceBorrowed: number;
179
+ ammBalanceBorrowedUsd: number;
180
+ ammBalanceCollateral: number;
181
+ ammBalanceCollateralUsd: number;
182
+ }
183
+ export interface IMarketDataAPI {
184
+ id: string;
185
+ name: string;
186
+ address: string;
187
+ controllerAddress: string;
188
+ ammAddress: string;
189
+ monetaryPolicyAddress: string;
190
+ rates: Rates;
191
+ gaugeAddress: string;
192
+ gaugeRewards: any[];
193
+ assets: Assets;
194
+ vaultShares: VaultShares;
195
+ totalSupplied: Total;
196
+ borrowed: Total;
197
+ availableToBorrow: Total;
198
+ lendingVaultUrls: LendingVaultUrls;
199
+ usdTotal: number;
200
+ ammBalances: AmmBalances;
201
+ }
202
+ export interface IMarketData {
203
+ lendingVaultData: IMarketDataAPI[];
204
+ }
205
+ export interface IQuoteOdos {
206
+ outAmounts: string[];
207
+ priceImpact: number;
208
+ pathId: string | null;
209
+ pathVizImage: string;
210
+ slippage: number;
211
+ }
212
+ export interface ILlamma {
213
+ amm_address: string;
214
+ controller_address: string;
215
+ monetary_policy_address: string;
216
+ collateral_address: string;
217
+ leverage_zap: string;
218
+ deleverage_zap: string;
219
+ health_calculator_zap?: string;
220
+ collateral_symbol: string;
221
+ collateral_decimals: number;
222
+ min_bands: number;
223
+ max_bands: number;
224
+ default_bands: number;
225
+ A: number;
226
+ monetary_policy_abi: any;
227
+ }
228
+ export {};
@@ -0,0 +1 @@
1
+ export {};