@curvefi/llamalend-api 1.1.10 → 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 (138) hide show
  1. package/docs/MIGRATION.md +325 -0
  2. package/docs/SUPPORT_LLv2.md +409 -0
  3. package/lib/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
  4. package/lib/constants/aliases.d.ts +0 -11
  5. package/lib/constants/aliases.js +1 -86
  6. package/lib/constants/coins.d.ts +0 -11
  7. package/lib/constants/coins.js +0 -14
  8. package/lib/constants/utils.d.ts +2 -0
  9. package/lib/constants/utils.js +2 -0
  10. package/lib/index.d.ts +10 -4
  11. package/lib/interfaces.d.ts +3 -2
  12. package/lib/lendMarkets/LendMarketTemplate.d.ts +13 -502
  13. package/lib/lendMarkets/LendMarketTemplate.js +237 -2860
  14. package/lib/lendMarkets/fetch/fetchFactoryData.d.ts +13 -0
  15. package/lib/lendMarkets/fetch/fetchFactoryData.js +101 -0
  16. package/lib/lendMarkets/fetch/fetchLendMarkets.d.ts +3 -0
  17. package/lib/lendMarkets/fetch/fetchLendMarkets.js +94 -0
  18. package/lib/lendMarkets/interfaces/common/amm.d.ts +10 -0
  19. package/lib/lendMarkets/interfaces/common/amm.js +1 -0
  20. package/lib/lendMarkets/interfaces/common/index.d.ts +5 -0
  21. package/lib/lendMarkets/interfaces/common/index.js +5 -0
  22. package/lib/lendMarkets/interfaces/common/prices.d.ts +13 -0
  23. package/lib/lendMarkets/interfaces/common/prices.js +1 -0
  24. package/lib/lendMarkets/interfaces/common/userPosition.d.ts +39 -0
  25. package/lib/lendMarkets/interfaces/common/userPosition.js +1 -0
  26. package/lib/lendMarkets/interfaces/common/vault.d.ts +55 -0
  27. package/lib/lendMarkets/interfaces/common/vault.js +1 -0
  28. package/lib/lendMarkets/interfaces/common/wallet.d.ts +8 -0
  29. package/lib/lendMarkets/interfaces/common/wallet.js +1 -0
  30. package/lib/lendMarkets/interfaces/v1/index.d.ts +4 -0
  31. package/lib/lendMarkets/interfaces/v1/index.js +4 -0
  32. package/lib/lendMarkets/interfaces/v1/leverageV1.d.ts +90 -0
  33. package/lib/lendMarkets/interfaces/v1/leverageV1.js +1 -0
  34. package/lib/lendMarkets/interfaces/v1/loanV1.d.ts +73 -0
  35. package/lib/lendMarkets/interfaces/v1/loanV1.js +1 -0
  36. package/lib/lendMarkets/interfaces/v1/statsV1.d.ts +49 -0
  37. package/lib/lendMarkets/interfaces/v1/statsV1.js +1 -0
  38. package/lib/lendMarkets/interfaces/v2/index.d.ts +3 -0
  39. package/lib/lendMarkets/interfaces/v2/index.js +3 -0
  40. package/lib/lendMarkets/interfaces/v2/leverageV2.d.ts +90 -0
  41. package/lib/lendMarkets/interfaces/v2/leverageV2.js +1 -0
  42. package/lib/lendMarkets/interfaces/v2/loanV2.d.ts +73 -0
  43. package/lib/lendMarkets/interfaces/v2/loanV2.js +1 -0
  44. package/lib/lendMarkets/interfaces/v2/statsV2.d.ts +49 -0
  45. package/lib/lendMarkets/interfaces/v2/statsV2.js +1 -0
  46. package/lib/lendMarkets/lendMarketConstructor.js +1 -1
  47. package/lib/lendMarkets/modules/common/amm.d.ts +19 -0
  48. package/lib/lendMarkets/modules/common/amm.js +137 -0
  49. package/lib/lendMarkets/modules/common/index.d.ts +9 -0
  50. package/lib/lendMarkets/modules/common/index.js +9 -0
  51. package/lib/lendMarkets/modules/common/leverageZapV1Base.d.ts +118 -0
  52. package/lib/lendMarkets/modules/common/leverageZapV1Base.js +770 -0
  53. package/lib/lendMarkets/modules/{leverageZapV2.d.ts → common/leverageZapV2Base.d.ts} +10 -5
  54. package/lib/lendMarkets/modules/{leverageZapV2.js → common/leverageZapV2Base.js} +36 -32
  55. package/lib/lendMarkets/modules/common/loanBase.d.ts +115 -0
  56. package/lib/lendMarkets/modules/common/loanBase.js +793 -0
  57. package/lib/lendMarkets/modules/common/prices.d.ts +19 -0
  58. package/lib/lendMarkets/modules/common/prices.js +104 -0
  59. package/lib/lendMarkets/modules/common/statsBase.d.ts +69 -0
  60. package/lib/lendMarkets/modules/common/statsBase.js +291 -0
  61. package/lib/lendMarkets/modules/common/userPosition.d.ts +46 -0
  62. package/lib/lendMarkets/modules/common/userPosition.js +223 -0
  63. package/lib/lendMarkets/modules/common/vault.d.ts +69 -0
  64. package/lib/lendMarkets/modules/common/vault.js +535 -0
  65. package/lib/lendMarkets/modules/common/wallet.d.ts +13 -0
  66. package/lib/lendMarkets/modules/common/wallet.js +28 -0
  67. package/lib/lendMarkets/modules/index.d.ts +1 -1
  68. package/lib/lendMarkets/modules/index.js +1 -1
  69. package/lib/lendMarkets/modules/v1/index.d.ts +4 -0
  70. package/lib/lendMarkets/modules/v1/index.js +4 -0
  71. package/lib/lendMarkets/modules/v1/leverageV1ZapV1.d.ts +3 -0
  72. package/lib/lendMarkets/modules/v1/leverageV1ZapV1.js +3 -0
  73. package/lib/lendMarkets/modules/v1/leverageV1ZapV2.d.ts +3 -0
  74. package/lib/lendMarkets/modules/v1/leverageV1ZapV2.js +3 -0
  75. package/lib/lendMarkets/modules/v1/loanV1.d.ts +4 -0
  76. package/lib/lendMarkets/modules/v1/loanV1.js +3 -0
  77. package/lib/lendMarkets/modules/v1/statsV1.d.ts +3 -0
  78. package/lib/lendMarkets/modules/v1/statsV1.js +3 -0
  79. package/lib/lendMarkets/modules/v2/index.d.ts +4 -0
  80. package/lib/lendMarkets/modules/v2/index.js +4 -0
  81. package/lib/lendMarkets/modules/v2/leverageV2ZapV1.d.ts +3 -0
  82. package/lib/lendMarkets/modules/v2/leverageV2ZapV1.js +3 -0
  83. package/lib/lendMarkets/modules/v2/leverageV2ZapV2.d.ts +3 -0
  84. package/lib/lendMarkets/modules/v2/leverageV2ZapV2.js +3 -0
  85. package/lib/lendMarkets/modules/v2/loanV2.d.ts +4 -0
  86. package/lib/lendMarkets/modules/v2/loanV2.js +3 -0
  87. package/lib/lendMarkets/modules/v2/statsV2.d.ts +3 -0
  88. package/lib/lendMarkets/modules/v2/statsV2.js +3 -0
  89. package/lib/llamalend.d.ts +6 -6
  90. package/lib/llamalend.js +46 -210
  91. package/lib/utils.js +2 -33
  92. package/package.json +1 -1
  93. package/src/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
  94. package/src/constants/aliases.ts +1 -97
  95. package/src/constants/coins.ts +0 -25
  96. package/src/constants/utils.ts +4 -0
  97. package/src/interfaces.ts +3 -2
  98. package/src/lendMarkets/LendMarketTemplate.ts +318 -3222
  99. package/src/lendMarkets/fetch/fetchFactoryData.ts +113 -0
  100. package/src/lendMarkets/fetch/fetchLendMarkets.ts +108 -0
  101. package/src/lendMarkets/interfaces/common/amm.ts +11 -0
  102. package/src/lendMarkets/interfaces/common/index.ts +5 -0
  103. package/src/lendMarkets/interfaces/common/prices.ts +13 -0
  104. package/src/lendMarkets/interfaces/common/userPosition.ts +24 -0
  105. package/src/lendMarkets/interfaces/common/vault.ts +48 -0
  106. package/src/lendMarkets/interfaces/common/wallet.ts +3 -0
  107. package/src/lendMarkets/interfaces/v1/index.ts +4 -0
  108. package/src/lendMarkets/interfaces/v1/leverageV1.ts +84 -0
  109. package/src/lendMarkets/interfaces/v1/loanV1.ts +77 -0
  110. package/src/lendMarkets/interfaces/v1/statsV1.ts +21 -0
  111. package/src/lendMarkets/interfaces/v2/index.ts +3 -0
  112. package/src/lendMarkets/interfaces/v2/leverageV2.ts +84 -0
  113. package/src/lendMarkets/interfaces/v2/loanV2.ts +77 -0
  114. package/src/lendMarkets/interfaces/v2/statsV2.ts +21 -0
  115. package/src/lendMarkets/lendMarketConstructor.ts +1 -1
  116. package/src/lendMarkets/modules/common/amm.ts +132 -0
  117. package/src/lendMarkets/modules/common/index.ts +9 -0
  118. package/src/lendMarkets/modules/common/leverageZapV1Base.ts +912 -0
  119. package/src/lendMarkets/modules/{leverageZapV2.ts → common/leverageZapV2Base.ts} +41 -37
  120. package/src/lendMarkets/modules/common/loanBase.ts +773 -0
  121. package/src/lendMarkets/modules/common/prices.ts +111 -0
  122. package/src/lendMarkets/modules/common/statsBase.ts +313 -0
  123. package/src/lendMarkets/modules/common/userPosition.ts +243 -0
  124. package/src/lendMarkets/modules/common/vault.ts +551 -0
  125. package/src/lendMarkets/modules/common/wallet.ts +29 -0
  126. package/src/lendMarkets/modules/index.ts +1 -1
  127. package/src/lendMarkets/modules/v1/index.ts +4 -0
  128. package/src/lendMarkets/modules/v1/leverageV1ZapV1.ts +3 -0
  129. package/src/lendMarkets/modules/v1/leverageV1ZapV2.ts +3 -0
  130. package/src/lendMarkets/modules/v1/loanV1.ts +4 -0
  131. package/src/lendMarkets/modules/v1/statsV1.ts +3 -0
  132. package/src/lendMarkets/modules/v2/index.ts +4 -0
  133. package/src/lendMarkets/modules/v2/leverageV2ZapV1.ts +3 -0
  134. package/src/lendMarkets/modules/v2/leverageV2ZapV2.ts +3 -0
  135. package/src/lendMarkets/modules/v2/loanV2.ts +4 -0
  136. package/src/lendMarkets/modules/v2/statsV2.ts +3 -0
  137. package/src/llamalend.ts +47 -244
  138. package/src/utils.ts +2 -35
@@ -0,0 +1,3 @@
1
+ import { LeverageZapV1BaseModule } from "../common/leverageZapV1Base.js";
2
+ export declare class LeverageV2ZapV1Module extends LeverageZapV1BaseModule {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { LeverageZapV1BaseModule } from "../common/leverageZapV1Base.js";
2
+ export class LeverageV2ZapV1Module extends LeverageZapV1BaseModule {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { LeverageZapV2BaseModule } from "../common/leverageZapV2Base.js";
2
+ export declare class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { LeverageZapV2BaseModule } from "../common/leverageZapV2Base.js";
2
+ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
3
+ }
@@ -0,0 +1,4 @@
1
+ import { LoanBaseModule } from "../common/loanBase.js";
2
+ import { ILoanV2 } from "../../interfaces/v2";
3
+ export declare class LoanV2Module extends LoanBaseModule implements ILoanV2 {
4
+ }
@@ -0,0 +1,3 @@
1
+ import { LoanBaseModule } from "../common/loanBase.js";
2
+ export class LoanV2Module extends LoanBaseModule {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { StatsBaseModule } from "../common/statsBase.js";
2
+ export declare class StatsV2Module extends StatsBaseModule {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { StatsBaseModule } from "../common/statsBase.js";
2
+ export class StatsV2Module extends StatsBaseModule {
3
+ }
@@ -39,6 +39,7 @@ declare class Llamalend implements ILlamalend {
39
39
  L1WeightedGasPrice?: number;
40
40
  constants: {
41
41
  ONE_WAY_MARKETS: IDict<IOneWayMarket>;
42
+ ONE_WAY_MARKETS_V2: IDict<IOneWayMarket>;
42
43
  DECIMALS: IDict<number>;
43
44
  NETWORK_NAME: INetworkName;
44
45
  ALIASES: Record<string, string>;
@@ -75,13 +76,12 @@ declare class Llamalend implements ILlamalend {
75
76
  _filterHiddenMarkets(markets: IDict<IOneWayMarket>): Promise<IDict<IOneWayMarket>>;
76
77
  getLendMarketList: () => string[];
77
78
  getMintMarketList: () => string[];
78
- getFactoryMarketData: () => Promise<Record<string, any>>;
79
- getFactoryMarketDataByAPI: () => Promise<Record<string, string[]>>;
79
+ fetchLendMarkets: ({ useApi, version }?: {
80
+ useApi?: boolean;
81
+ version?: "v1" | "v2";
82
+ }) => Promise<void>;
80
83
  getCoins: (collateral_tokens: string[], borrowed_tokens: string[], useApi?: boolean) => Promise<IDict<ICoin>>;
81
- fetchStats: (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[]) => Promise<void>;
82
- fetchLendMarkets: (useAPI?: boolean) => Promise<void>;
83
- _fetchOneWayMarketsByBlockchain: () => Promise<void>;
84
- _fetchOneWayMarketsByAPI: () => Promise<void>;
84
+ fetchStats: (amms: string[], controllers: string[], vaults: string[], borrowed_tokens: string[], collateral_tokens: string[], version?: "v1" | "v2") => Promise<void>;
85
85
  formatUnits(value: BigNumberish, unit?: string | Numeric): string;
86
86
  parseUnits(value: string, unit?: string | Numeric): bigint;
87
87
  updateFeeData(): Promise<void>;
package/lib/llamalend.js CHANGED
@@ -11,14 +11,9 @@ import { ethers, Contract, AbstractProvider } from "ethers";
11
11
  import { Provider as MulticallProvider, Contract as MulticallContract } from '@curvefi/ethcall';
12
12
  // OneWayMarket ABIs
13
13
  import OneWayLendingFactoryABI from "./constants/abis/OneWayLendingFactoryABI.json" with { type: 'json' };
14
+ import OneWayLendingFactoryV2ABI from "./constants/abis/OneWayLendingFactoryV2ABI.json" with { type: 'json' };
14
15
  import ERC20ABI from './constants/abis/ERC20.json' with { type: 'json' };
15
16
  import ERC4626ABI from './constants/abis/ERC4626.json' with { type: 'json' };
16
- import LlammaABI from './constants/abis/Llamma.json' with { type: 'json' };
17
- import ControllerABI from './constants/abis/Controller.json' with { type: 'json' };
18
- import MonetaryPolicyABI from './constants/abis/MonetaryPolicy.json' with { type: 'json' };
19
- import VaultABI from './constants/abis/Vault.json' with { type: 'json' };
20
- import GaugeABI from './constants/abis/GaugeV5.json' with { type: 'json' };
21
- import SidechainGaugeABI from './constants/abis/SidechainGauge.json' with { type: 'json' };
22
17
  import GaugeControllerABI from './constants/abis/GaugeController.json' with { type: 'json' };
23
18
  import GaugeFactoryMainnetABI from './constants/abis/GaugeFactoryMainnet.json' with { type: 'json' };
24
19
  import GaugeFactorySidechainABI from './constants/abis/GaugeFactorySidechain.json' with { type: 'json' };
@@ -36,14 +31,15 @@ import MonetaryPolicy2ABI from "./constants/abis/crvUSD/MonetaryPolicy2.json" wi
36
31
  import HealthCalculatorZapABI from "./constants/abis/crvUSD/HealthCalculatorZap.json" with { type: 'json' };
37
32
  import LeverageZapCrvUSDABI from "./constants/abis/crvUSD/LeverageZap.json" with { type: 'json' };
38
33
  import DeleverageZapABI from "./constants/abis/crvUSD/DeleverageZap.json" with { type: 'json' };
39
- import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_POLYGON, ALIASES_FANTOM, ALIASES_AVALANCHE, ALIASES_ARBITRUM, ALIASES_XDAI, ALIASES_MOONBEAM, ALIASES_AURORA, ALIASES_KAVA, ALIASES_CELO, ALIASES_ZKSYNC, ALIASES_BASE, ALIASES_BSC, ALIASES_FRAXTAL, ALIASES_SONIC, } from "./constants/aliases.js";
40
- import { COINS_ETHEREUM, COINS_OPTIMISM, COINS_POLYGON, COINS_FANTOM, COINS_AVALANCHE, COINS_ARBITRUM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_SONIC, } from "./constants/coins.js";
34
+ import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_ARBITRUM, ALIASES_FRAXTAL, ALIASES_SONIC, } from "./constants/aliases.js";
35
+ import { COINS_ETHEREUM, COINS_OPTIMISM, COINS_ARBITRUM, COINS_FRAXTAL, COINS_SONIC, } from "./constants/coins.js";
41
36
  import { LLAMMAS } from "./constants/llammas.js";
42
37
  import { L2Networks } from "./constants/L2Networks.js";
43
38
  import { createCall, handleMultiCallResponse } from "./utils.js";
44
39
  import { cacheKey, cacheStats } from "./cache/index.js";
45
40
  import { _getMarketsData, _getHiddenPools } from "./external-api.js";
46
41
  import { extractDecimals } from "./constants/utils.js";
42
+ import { fetchOneWayMarketsByBlockchain, fetchOneWayMarketsByAPI } from "./lendMarkets/fetch/fetchLendMarkets.js";
47
43
  export const NETWORK_CONSTANTS = {
48
44
  1: {
49
45
  NAME: 'ethereum',
@@ -56,120 +52,37 @@ export const NETWORK_CONSTANTS = {
56
52
  ALIASES: ALIASES_OPTIMISM,
57
53
  COINS: COINS_OPTIMISM,
58
54
  },
59
- 56: {
60
- NAME: 'bsc',
61
- ALIASES: ALIASES_BSC,
62
- COINS: COINS_BSC,
63
- },
64
- 100: {
65
- NAME: 'xdai',
66
- ALIASES: ALIASES_XDAI,
67
- COINS: COINS_XDAI,
68
- },
69
- 137: {
70
- NAME: 'polygon',
71
- ALIASES: ALIASES_POLYGON,
72
- COINS: COINS_POLYGON,
73
- },
74
55
  146: {
75
56
  NAME: 'sonic',
76
57
  ALIASES: ALIASES_SONIC,
77
58
  COINS: COINS_SONIC,
78
59
  },
79
- 250: {
80
- NAME: 'fantom',
81
- ALIASES: ALIASES_FANTOM,
82
- COINS: COINS_FANTOM,
83
- },
84
60
  252: {
85
61
  NAME: 'fraxtal',
86
62
  ALIASES: ALIASES_FRAXTAL,
87
63
  COINS: COINS_FRAXTAL,
88
64
  },
89
- 324: {
90
- NAME: 'zksync',
91
- ALIASES: ALIASES_ZKSYNC,
92
- COINS: COINS_ZKSYNC,
93
- },
94
- 1284: {
95
- NAME: 'moonbeam',
96
- ALIASES: ALIASES_MOONBEAM,
97
- COINS: COINS_MOONBEAM,
98
- },
99
- 2222: {
100
- NAME: 'kava',
101
- ALIASES: ALIASES_KAVA,
102
- COINS: COINS_KAVA,
103
- },
104
- 8453: {
105
- NAME: 'base',
106
- ALIASES: ALIASES_BASE,
107
- COINS: COINS_BASE,
108
- },
109
65
  42161: {
110
66
  NAME: 'arbitrum',
111
67
  ALIASES: ALIASES_ARBITRUM,
112
68
  COINS: COINS_ARBITRUM,
113
69
  EXCLUDED_PROTOCOLS_1INCH: "",
114
70
  },
115
- 42220: {
116
- NAME: 'celo',
117
- ALIASES: ALIASES_CELO,
118
- COINS: COINS_CELO,
119
- },
120
- 43114: {
121
- NAME: 'avalanche',
122
- ALIASES: ALIASES_AVALANCHE,
123
- COINS: COINS_AVALANCHE,
124
- },
125
- 1313161554: {
126
- NAME: 'aurora',
127
- ALIASES: ALIASES_AURORA,
128
- COINS: COINS_AURORA,
129
- },
130
71
  };
131
72
  class Llamalend {
132
73
  constructor() {
133
- this.getLendMarketList = () => Object.keys(this.constants.ONE_WAY_MARKETS);
74
+ this.getLendMarketList = () => Object.keys(Object.assign(Object.assign({}, this.constants.ONE_WAY_MARKETS), this.constants.ONE_WAY_MARKETS_V2));
134
75
  this.getMintMarketList = () => Object.keys(this.constants.LLAMMAS);
135
- this.getFactoryMarketData = () => __awaiter(this, void 0, void 0, function* () {
136
- const factory = this.contracts[this.constants.ALIASES['one_way_factory']];
137
- const factoryContract = this.contracts[this.constants.ALIASES['one_way_factory']].contract;
138
- const markets_count = yield factoryContract.market_count();
139
- const callsMap = ['names', 'amms', 'controllers', 'borrowed_tokens', 'collateral_tokens', 'monetary_policies', 'vaults', 'gauges'];
140
- const calls = [];
141
- for (let i = 0; i < markets_count; i++) {
142
- callsMap.forEach((item) => {
143
- calls.push(createCall(factory, item, [i]));
144
- });
76
+ this.fetchLendMarkets = (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ useApi = true, version = 'v1' } = {}) {
77
+ if (version === 'v2' && useApi) {
78
+ throw new Error('API fetch is not supported for v2 markets yet. Please use fetchMarkets({ useApi: false, version: "v2" }) to fetch from blockchain.');
79
+ }
80
+ if (useApi) {
81
+ yield fetchOneWayMarketsByAPI(this, version);
82
+ }
83
+ else {
84
+ yield fetchOneWayMarketsByBlockchain(this, version);
145
85
  }
146
- const res = (yield this.multicallProvider.all(calls)).map((addr) => addr.toLowerCase());
147
- return handleMultiCallResponse(callsMap, res);
148
- });
149
- this.getFactoryMarketDataByAPI = () => __awaiter(this, void 0, void 0, function* () {
150
- const apiData = (yield _getMarketsData(this.constants.NETWORK_NAME)).lendingVaultData;
151
- const result = {
152
- names: [],
153
- amms: [],
154
- controllers: [],
155
- borrowed_tokens: [],
156
- collateral_tokens: [],
157
- monetary_policies: [],
158
- vaults: [],
159
- gauges: [],
160
- };
161
- apiData.forEach((market) => {
162
- var _a;
163
- result.names.push(market.name);
164
- result.amms.push(market.ammAddress.toLowerCase());
165
- result.controllers.push(market.controllerAddress.toLowerCase());
166
- result.borrowed_tokens.push(market.assets.borrowed.address.toLowerCase());
167
- result.collateral_tokens.push(market.assets.collateral.address.toLowerCase());
168
- result.monetary_policies.push(market.monetaryPolicyAddress.toLowerCase());
169
- result.vaults.push(market.address.toLowerCase());
170
- result.gauges.push(((_a = market.gaugeAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || this.constants.ZERO_ADDRESS);
171
- });
172
- return result;
173
86
  });
174
87
  this.getCoins = (collateral_tokens_1, borrowed_tokens_1, ...args_1) => __awaiter(this, [collateral_tokens_1, borrowed_tokens_1, ...args_1], void 0, function* (collateral_tokens, borrowed_tokens, useApi = false) {
175
88
  const coins = new Set([...collateral_tokens, ...borrowed_tokens]);
@@ -221,128 +134,46 @@ class Llamalend {
221
134
  }
222
135
  return COINS_DATA;
223
136
  });
224
- this.fetchStats = (amms, controllers, vaults, borrowed_tokens, collateral_tokens) => __awaiter(this, void 0, void 0, function* () {
137
+ this.fetchStats = (amms_1, controllers_1, vaults_1, borrowed_tokens_1, collateral_tokens_1, ...args_1) => __awaiter(this, [amms_1, controllers_1, vaults_1, borrowed_tokens_1, collateral_tokens_1, ...args_1], void 0, function* (amms, controllers, vaults, borrowed_tokens, collateral_tokens, version = 'v1') {
225
138
  cacheStats.clear();
226
139
  const marketCount = controllers.length;
140
+ console.log(controllers.length);
227
141
  const calls = [];
228
142
  for (let i = 0; i < marketCount; i++) {
229
143
  calls.push(createCall(this.contracts[controllers[i]], 'total_debt', []));
230
- calls.push(createCall(this.contracts[vaults[i]], 'totalAssets', [controllers[i]]));
144
+ calls.push(createCall(this.contracts[vaults[i]], 'totalAssets', []));
231
145
  calls.push(createCall(this.contracts[borrowed_tokens[i]], 'balanceOf', [controllers[i]]));
232
146
  calls.push(createCall(this.contracts[amms[i]], 'rate', []));
233
147
  calls.push(createCall(this.contracts[borrowed_tokens[i]], 'balanceOf', [amms[i]]));
234
- calls.push(createCall(this.contracts[amms[i]], 'admin_fees_x', []));
235
- calls.push(createCall(this.contracts[amms[i]], 'admin_fees_y', []));
148
+ if (version === 'v1') {
149
+ calls.push(createCall(this.contracts[amms[i]], 'admin_fees_x', []));
150
+ calls.push(createCall(this.contracts[amms[i]], 'admin_fees_y', []));
151
+ }
236
152
  calls.push(createCall(this.contracts[collateral_tokens[i]], 'balanceOf', [amms[i]]));
237
153
  }
238
154
  const res = yield this.multicallProvider.all(calls);
239
155
  for (let i = 0; i < marketCount; i++) {
240
- cacheStats.set(cacheKey(controllers[i], 'total_debt'), res[(i * 8) + 0]);
241
- cacheStats.set(cacheKey(vaults[i], 'totalAssets', controllers[i]), res[(i * 8) + 1]);
242
- cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', controllers[i]), res[(i * 8) + 2]);
243
- cacheStats.set(cacheKey(amms[i], 'rate'), res[(i * 8) + 3]);
244
- cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 4]);
245
- cacheStats.set(cacheKey(amms[i], 'admin_fees_x'), res[(i * 8) + 5]);
246
- cacheStats.set(cacheKey(amms[i], 'admin_fees_y'), res[(i * 8) + 6]);
247
- cacheStats.set(cacheKey(collateral_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 7]);
248
- }
249
- });
250
- this.fetchLendMarkets = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useAPI = true) {
251
- if (useAPI) {
252
- yield this._fetchOneWayMarketsByAPI();
253
- }
254
- else {
255
- yield this._fetchOneWayMarketsByBlockchain();
256
- }
257
- });
258
- this._fetchOneWayMarketsByBlockchain = () => __awaiter(this, void 0, void 0, function* () {
259
- const { names, amms, controllers, borrowed_tokens, collateral_tokens, monetary_policies, vaults, gauges } = yield this.getFactoryMarketData();
260
- const COIN_DATA = yield this.getCoins(collateral_tokens, borrowed_tokens);
261
- for (const c in COIN_DATA) {
262
- this.constants.DECIMALS[c] = COIN_DATA[c].decimals;
263
- }
264
- amms.forEach((amm, index) => {
265
- this.setContract(amm, LlammaABI);
266
- this.setContract(controllers[index], ControllerABI);
267
- this.setContract(monetary_policies[index], MonetaryPolicyABI);
268
- this.setContract(vaults[index], VaultABI);
269
- this.setContract(gauges[index], this.chainId === 1 ? GaugeABI : SidechainGaugeABI);
270
- COIN_DATA[vaults[index]] = {
271
- address: vaults[index],
272
- decimals: 18,
273
- name: "Curve Vault for " + COIN_DATA[borrowed_tokens[index]].name,
274
- symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol,
275
- };
276
- COIN_DATA[gauges[index]] = {
277
- address: gauges[index],
278
- decimals: 18,
279
- name: "curve.finance " + COIN_DATA[borrowed_tokens[index]].name + " Gauge Deposit",
280
- symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol + "-gauge",
281
- };
282
- this.constants.DECIMALS[vaults[index]] = 18;
283
- this.constants.DECIMALS[gauges[index]] = 18;
284
- this.constants.ONE_WAY_MARKETS[`one-way-market-${index}`] = {
285
- name: names[index],
286
- addresses: {
287
- amm: amms[index],
288
- controller: controllers[index],
289
- borrowed_token: borrowed_tokens[index],
290
- collateral_token: collateral_tokens[index],
291
- monetary_policy: monetary_policies[index],
292
- vault: vaults[index],
293
- gauge: gauges[index],
294
- },
295
- borrowed_token: COIN_DATA[borrowed_tokens[index]],
296
- collateral_token: COIN_DATA[collateral_tokens[index]],
297
- };
298
- });
299
- this.constants.ONE_WAY_MARKETS = yield this._filterHiddenMarkets(this.constants.ONE_WAY_MARKETS);
300
- yield this.fetchStats(amms, controllers, vaults, borrowed_tokens, collateral_tokens);
301
- });
302
- this._fetchOneWayMarketsByAPI = () => __awaiter(this, void 0, void 0, function* () {
303
- const { names, amms, controllers, borrowed_tokens, collateral_tokens, monetary_policies, vaults, gauges } = yield this.getFactoryMarketDataByAPI();
304
- const COIN_DATA = yield this.getCoins(collateral_tokens, borrowed_tokens, true);
305
- for (const c in COIN_DATA) {
306
- this.constants.DECIMALS[c] = COIN_DATA[c].decimals;
307
- }
308
- amms.forEach((amm, index) => {
309
- this.setContract(amms[index], LlammaABI);
310
- this.setContract(controllers[index], ControllerABI);
311
- this.setContract(monetary_policies[index], MonetaryPolicyABI);
312
- this.setContract(vaults[index], VaultABI);
313
- if (gauges[index]) {
314
- this.setContract(gauges[index], this.chainId === 1 ? GaugeABI : SidechainGaugeABI);
156
+ if (version === 'v1') {
157
+ cacheStats.set(cacheKey(controllers[i], 'total_debt'), res[(i * 8) + 0]);
158
+ cacheStats.set(cacheKey(vaults[i], 'totalAssets', controllers[i]), res[(i * 8) + 1]);
159
+ cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', controllers[i]), res[(i * 8) + 2]);
160
+ cacheStats.set(cacheKey(amms[i], 'rate'), res[(i * 8) + 3]);
161
+ cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 4]);
162
+ cacheStats.set(cacheKey(amms[i], 'admin_fees_x'), res[(i * 8) + 5]);
163
+ cacheStats.set(cacheKey(amms[i], 'admin_fees_y'), res[(i * 8) + 6]);
164
+ cacheStats.set(cacheKey(collateral_tokens[i], 'balanceOf', amms[i]), res[(i * 8) + 7]);
315
165
  }
316
- COIN_DATA[vaults[index]] = {
317
- address: vaults[index],
318
- decimals: 18,
319
- name: "Curve Vault for " + COIN_DATA[borrowed_tokens[index]].name,
320
- symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol,
321
- };
322
- COIN_DATA[gauges[index]] = {
323
- address: gauges[index],
324
- decimals: 18,
325
- name: "curve.finance " + COIN_DATA[borrowed_tokens[index]].name + " Gauge Deposit",
326
- symbol: "cv" + COIN_DATA[borrowed_tokens[index]].symbol + "-gauge",
327
- };
328
- this.constants.DECIMALS[vaults[index]] = 18;
329
- this.constants.DECIMALS[gauges[index]] = 18;
330
- this.constants.ONE_WAY_MARKETS[`one-way-market-${index}`] = {
331
- name: names[index],
332
- addresses: {
333
- amm: amms[index],
334
- controller: controllers[index],
335
- borrowed_token: borrowed_tokens[index],
336
- collateral_token: collateral_tokens[index],
337
- monetary_policy: monetary_policies[index],
338
- vault: vaults[index],
339
- gauge: gauges[index],
340
- },
341
- borrowed_token: COIN_DATA[borrowed_tokens[index]],
342
- collateral_token: COIN_DATA[collateral_tokens[index]],
343
- };
344
- });
345
- this.constants.ONE_WAY_MARKETS = yield this._filterHiddenMarkets(this.constants.ONE_WAY_MARKETS);
166
+ else {
167
+ cacheStats.set(cacheKey(controllers[i], 'total_debt'), res[(i * 6) + 0]);
168
+ cacheStats.set(cacheKey(vaults[i], 'totalAssets', controllers[i]), res[(i * 6) + 1]);
169
+ cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', controllers[i]), res[(i * 6) + 2]);
170
+ cacheStats.set(cacheKey(amms[i], 'rate'), res[(i * 6) + 3]);
171
+ cacheStats.set(cacheKey(borrowed_tokens[i], 'balanceOf', amms[i]), res[(i * 6) + 4]);
172
+ cacheStats.set(cacheKey(amms[i], 'admin_fees_x'), BigInt(0)); // Always 0 for v2
173
+ cacheStats.set(cacheKey(amms[i], 'admin_fees_y'), BigInt(0)); // Always 0 for v2
174
+ cacheStats.set(cacheKey(collateral_tokens[i], 'balanceOf', amms[i]), res[(i * 6) + 5]);
175
+ }
176
+ }
346
177
  });
347
178
  this.address = '00000';
348
179
  this.crvUsdAddress = COINS_ETHEREUM.crvusd;
@@ -359,6 +190,7 @@ class Llamalend {
359
190
  this.options = {};
360
191
  this.constants = {
361
192
  ONE_WAY_MARKETS: {},
193
+ ONE_WAY_MARKETS_V2: {},
362
194
  LLAMMAS: {},
363
195
  COINS: {},
364
196
  DECIMALS: {},
@@ -392,6 +224,7 @@ class Llamalend {
392
224
  this.options = {};
393
225
  this.constants = {
394
226
  ONE_WAY_MARKETS: {},
227
+ ONE_WAY_MARKETS_V2: {},
395
228
  LLAMMAS: Object.assign({}, LLAMMAS),
396
229
  COINS: {},
397
230
  DECIMALS: {},
@@ -486,6 +319,9 @@ class Llamalend {
486
319
  yield this.updateFeeData();
487
320
  // oneWayMarkets contracts
488
321
  this.setContract(this.constants.ALIASES['one_way_factory'], OneWayLendingFactoryABI);
322
+ if (this.constants.ALIASES['one_way_factory_v2'] && this.constants.ALIASES['one_way_factory_v2'] !== this.constants.ZERO_ADDRESS) {
323
+ this.setContract(this.constants.ALIASES['one_way_factory_v2'], OneWayLendingFactoryV2ABI);
324
+ }
489
325
  this.setContract(this.constants.ALIASES['gauge_controller'], GaugeControllerABI);
490
326
  this.setContract(this.constants.ALIASES['leverage_zap'], LeverageZapABI);
491
327
  this.setContract(this.constants.ALIASES['leverage_zap_v2'], LeverageZapABI);
package/lib/utils.js CHANGED
@@ -267,47 +267,21 @@ export const _getUsdRate = function (assetId) {
267
267
  const pricesFromApi = yield _getUsdPricesFromApi(this.constants.NETWORK_NAME);
268
268
  if (assetId.toLowerCase() in pricesFromApi)
269
269
  return pricesFromApi[assetId.toLowerCase()];
270
- if (assetId === 'USD' || (this.chainId === 137 && (assetId.toLowerCase() === this.constants.COINS.am3crv.toLowerCase())))
270
+ if (assetId === 'USD' || (assetId.toLowerCase() === this.constants.COINS.am3crv.toLowerCase()))
271
271
  return 1;
272
- let chainName = {
272
+ const chainName = {
273
273
  1: 'ethereum',
274
274
  10: 'optimistic-ethereum',
275
- 56: "binance-smart-chain",
276
- 100: 'xdai',
277
- 137: 'polygon-pos',
278
275
  146: 'sonic',
279
- 196: 'x-layer',
280
- 250: 'fantom',
281
276
  252: 'fraxtal',
282
- 324: 'zksync',
283
- 1284: 'moonbeam',
284
- 2222: 'kava',
285
- 5000: 'mantle',
286
- 8453: 'base',
287
- 42220: 'celo',
288
- 43114: 'avalanche',
289
277
  42161: 'arbitrum-one',
290
- 1313161554: 'aurora',
291
278
  }[this.chainId];
292
279
  const nativeTokenName = {
293
280
  1: 'ethereum',
294
281
  10: 'ethereum',
295
- 56: 'binancecoin',
296
- 100: 'xdai',
297
- 137: 'matic-network',
298
282
  146: 'sonic-3',
299
- 196: 'okb',
300
- 250: 'fantom',
301
283
  252: 'frax-ether',
302
- 324: 'ethereum',
303
- 1284: 'moonbeam',
304
- 2222: 'kava',
305
- 5000: 'mantle',
306
- 8453: 'ethereum',
307
- 42220: 'celo',
308
- 43114: 'avalanche-2',
309
284
  42161: 'ethereum',
310
- 1313161554: 'ethereum',
311
285
  }[this.chainId];
312
286
  if (chainName === undefined) {
313
287
  throw Error('curve object is not initialized');
@@ -320,11 +294,6 @@ export const _getUsdRate = function (assetId) {
320
294
  'LINK': 'link',
321
295
  }[assetId.toUpperCase()] || assetId;
322
296
  assetId = isEth(assetId) ? nativeTokenName : assetId.toLowerCase();
323
- // No EURT on Coingecko Polygon
324
- if (this.chainId === 137 && assetId.toLowerCase() === this.constants.COINS.eurt) {
325
- chainName = 'ethereum';
326
- assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
327
- }
328
297
  // CRV
329
298
  if (assetId.toLowerCase() === this.constants.ALIASES.crv) {
330
299
  assetId = 'curve-dao-token';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.1.10",
3
+ "version": "2.0.0",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",