impermax-sdk 2.1.47 → 2.1.49

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.
@@ -277,6 +277,21 @@
277
277
  "stateMutability": "view",
278
278
  "type": "function"
279
279
  },
280
+ {
281
+ "constant": true,
282
+ "inputs": [],
283
+ "name": "version",
284
+ "outputs": [
285
+ {
286
+ "internalType": "string",
287
+ "name": "",
288
+ "type": "string"
289
+ }
290
+ ],
291
+ "payable": false,
292
+ "stateMutability": "view",
293
+ "type": "function"
294
+ },
280
295
  {
281
296
  "constant": true,
282
297
  "inputs": [],
@@ -54,7 +54,7 @@ export default class OffchainLendingPool {
54
54
  isBlacklisted(): Promise<boolean>;
55
55
  isLowTVL(): Promise<boolean>;
56
56
  isHighTVL(): Promise<boolean>;
57
- isStable(): boolean;
57
+ isStable(): Promise<boolean>;
58
58
  getLendingPoolVersion(): LendingPoolVersion;
59
59
  getTotalBorrowsUSD(): Promise<number>;
60
60
  getUniswapV2PairAddress(): Promise<Address>;
@@ -185,7 +185,7 @@ class OffchainLendingPool {
185
185
  getAmm() {
186
186
  var _a, _b, _c;
187
187
  return __awaiter(this, void 0, void 0, function* () {
188
- const lendingPoolData = yield this.getLendingPoolData();
188
+ const lendingPoolData = (yield this.getLendingPoolData());
189
189
  // TODO: this properly
190
190
  const pairFactory = (_b = (_a = lendingPoolData.pair) === null || _a === void 0 ? void 0 : _a.uniswapV2Factory) !== null && _b !== void 0 ? _b : (_c = lendingPoolData.nftlp) === null || _c === void 0 ? void 0 : _c.dexFactory;
191
191
  return (0, amms_1.getAmmByFactory)(this.offchain.network, pairFactory);
@@ -252,7 +252,7 @@ class OffchainLendingPool {
252
252
  const [supply0USD, supply1USD, totalBalanceUSD] = yield Promise.all([
253
253
  this.getBorrowableA().getTotalBalanceUSD(),
254
254
  this.getBorrowableB().getTotalBalanceUSD(),
255
- this.getCollateral().getTotalBalanceUSD()
255
+ this.getCollateral().getTotalBalanceUSD(),
256
256
  ]);
257
257
  if (supply0USD && supply1USD && totalBalanceUSD)
258
258
  return supply0USD + supply1USD + totalBalanceUSD;
@@ -280,12 +280,21 @@ class OffchainLendingPool {
280
280
  return false;
281
281
  });
282
282
  }
283
- // WARN: If V3 supports multiple pool types, then need more robust way to check if is stable or not
283
+ // Stable is defined if any following condition is met:
284
+ // - Both tokens are stables
285
+ // - factory type is "7" (ie. SOL_STABLE)
284
286
  isStable() {
285
- const factoryType = Number(this.factory);
286
- if (factoryType === 7)
287
- return true;
288
- return false;
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ const [stables, token0, token1] = yield Promise.all([
289
+ this.getOffchain().getAPRHelper().getAllStablecoins(),
290
+ this.getBorrowableA().getSymbol(),
291
+ this.getBorrowableB().getSymbol(),
292
+ ]);
293
+ const bothStable = stables.includes(token0) && stables.includes(token1);
294
+ if (bothStable || this.factory === "7")
295
+ return true;
296
+ return false;
297
+ });
289
298
  }
290
299
  // Versions Specfics
291
300
  getLendingPoolVersion() {
@@ -13,14 +13,16 @@ export type LlamaChainChart = {
13
13
  }[];
14
14
  }[];
15
15
  export default class OffchainAPRHelper {
16
- private llamaAllPools;
17
16
  private initialized;
18
- private chainTvls;
17
+ private llamaAllPools;
18
+ private chainTvlCharts;
19
+ private protocolTvlChart;
19
20
  private tvlInitialized;
21
+ private chainTvls;
20
22
  private chainsTotalSupplied;
21
23
  private totalSuppliedInitialized;
22
- private chainTvlCharts;
23
- private protocolTvlChart;
24
+ private stablecoins;
25
+ private stablecoinsInitialized;
24
26
  private readonly blacklistedProjects;
25
27
  offchainMultichain: OffchainMultichain;
26
28
  constructor(offchainMultichain: OffchainMultichain);
@@ -43,4 +45,6 @@ export default class OffchainAPRHelper {
43
45
  getImpermaxTotalSupplied(): Promise<number>;
44
46
  getProtocolTvlChart(): Promise<LlamaTvlChart>;
45
47
  getChainTvlChart(chain: Networks): Promise<LlamaTvlChart>;
48
+ private initializeStablecoins;
49
+ getAllStablecoins(): Promise<string[]>;
46
50
  }
@@ -35,18 +35,24 @@ const LlamaChains = {
35
35
  // Class to get the APR from DefiLlama directly, only makes 1 call to api and caches all pools
36
36
  class OffchainAPRHelper {
37
37
  constructor(offchainMultichain) {
38
- this.llamaAllPools = {};
38
+ // Llama Yields
39
39
  this.initialized = null;
40
- this.chainTvls = {};
40
+ this.llamaAllPools = {};
41
+ // Chain Charts
42
+ this.chainTvlCharts = {};
43
+ this.protocolTvlChart = [];
44
+ // Chain TVLs
41
45
  this.tvlInitialized = null;
46
+ this.chainTvls = {};
47
+ // Chain Total Supplied
42
48
  this.chainsTotalSupplied = {};
43
49
  this.totalSuppliedInitialized = null;
44
- // Charts
45
- this.chainTvlCharts = {};
46
- this.protocolTvlChart = [];
50
+ // Misc.
51
+ this.stablecoins = [];
52
+ this.stablecoinsInitialized = null;
47
53
  this.blacklistedProjects = new Set([
48
54
  "extra-finance",
49
- "beefy"
55
+ "beefy",
50
56
  ]);
51
57
  this.offchainMultichain = offchainMultichain;
52
58
  }
@@ -57,6 +63,8 @@ class OffchainAPRHelper {
57
63
  this.tvlInitialized = null;
58
64
  this.chainsTotalSupplied = {};
59
65
  this.totalSuppliedInitialized = null;
66
+ this.stablecoins = [];
67
+ this.stablecoinsInitialized = null;
60
68
  }
61
69
  // Blacklist certain projects which might report same pool as dex (aggregators, etc.)
62
70
  // Reason we need this is that we want the DEX APR and not the APR of other projects
@@ -123,9 +131,10 @@ class OffchainAPRHelper {
123
131
  return __awaiter(this, void 0, void 0, function* () {
124
132
  try {
125
133
  const response = yield fetch("https://yields.llama.fi/poolsBorrow").then((i) => i.json());
126
- const impermaxPools = response.data.filter((i) => i.project === 'impermax-finance');
134
+ const impermaxPools = response.data.filter((i) => i.project === "impermax-finance");
127
135
  this.chainsTotalSupplied = impermaxPools.reduce((acc, pool) => {
128
- acc[pool.chain.toLowerCase()] = (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
136
+ acc[pool.chain.toLowerCase()] =
137
+ (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
129
138
  return acc;
130
139
  }, {});
131
140
  }
@@ -191,7 +200,7 @@ class OffchainAPRHelper {
191
200
  // Get or initialize the tvl for all chains
192
201
  const [llamaTvls, totalSuppliedYields] = yield Promise.all([
193
202
  this.getLlamaTvls(),
194
- this.getChainsTotalSupplied()
203
+ this.getChainsTotalSupplied(),
195
204
  ]);
196
205
  const llamaChain = LlamaChains[chain];
197
206
  if (!llamaChain)
@@ -249,5 +258,26 @@ class OffchainAPRHelper {
249
258
  return this.chainTvlCharts[llamaChain];
250
259
  });
251
260
  }
261
+ initializeStablecoins() {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ try {
264
+ const response = yield fetch("https://stablecoins.llama.fi/stablecoins").then((i) => i.json());
265
+ this.stablecoins = response.peggedAssets.map((i) => i.symbol);
266
+ }
267
+ catch (err) {
268
+ console.log("Error getting stablecoins data: ", err);
269
+ }
270
+ });
271
+ }
272
+ // Other helpful defillama functions
273
+ // Get a list of stablecoins
274
+ getAllStablecoins() {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ if (!this.stablecoinsInitialized)
277
+ this.stablecoinsInitialized = this.initializeStablecoins();
278
+ yield this.stablecoinsInitialized;
279
+ return this.stablecoins;
280
+ });
281
+ }
252
282
  }
253
283
  exports.default = OffchainAPRHelper;
@@ -116,7 +116,12 @@ class OnchainInteractionsPoolToken {
116
116
  const token = yield this.poolToken.getToken();
117
117
  // experimental feature: check if the token supports permit by getting the DOMAIN_SEPARATOR
118
118
  const domain = yield token.methods.DOMAIN_SEPARATOR().call();
119
- return this.getPermitHelper().getTokenPermit(token, owner, spender, amount, domain);
119
+ let version = null;
120
+ try {
121
+ version = yield token.methods.version().call();
122
+ }
123
+ catch (_a) { }
124
+ return this.getPermitHelper().getTokenPermit(token, owner, spender, amount, version);
120
125
  });
121
126
  }
122
127
  permit2Underlying(amount) {
@@ -15,7 +15,7 @@ export default class OnchainPermitHelper {
15
15
  private getNftPermitJSONData;
16
16
  private getPermit2SingleJSONData;
17
17
  private getSignature;
18
- getTokenPermit(token: Contract, owner: Address, spender: Address, value: BigNumber, overrideDomain?: null): Promise<Permit>;
18
+ getTokenPermit(token: Contract, owner: Address, spender: Address, value: BigNumber, version?: null): Promise<Permit>;
19
19
  getNftPermit(token: Contract, owner: Address, spender: Address, tokenId: BigNumber): Promise<Permit>;
20
20
  getPermit2Single(token: Contract, owner: Address, spender: Address, value: BigNumber): Promise<Permit>;
21
21
  }
@@ -68,10 +68,10 @@ class OnchainPermitHelper {
68
68
  // TODO crate new router for V2 otherwise borrowPermit will stop working
69
69
  constructor(onchain) {
70
70
  this.deadline = general_1.DEADLINE.toString();
71
- this.getDomainPermit1 = (contract) => __awaiter(this, void 0, void 0, function* () {
71
+ this.getDomainPermit1 = (contract, version = null) => __awaiter(this, void 0, void 0, function* () {
72
72
  return ({
73
73
  name: yield contract.methods.name().call(),
74
- version: "1",
74
+ version: version ? version : "1",
75
75
  chainId: this.onchain.chainId,
76
76
  verifyingContract: contract._address,
77
77
  });
@@ -89,11 +89,10 @@ class OnchainPermitHelper {
89
89
  permits = [];
90
90
  return ethers_1.ethers.utils.defaultAbiCoder.encode(['tuple(uint256 permitType, bytes permitData, bytes signature)[]'], [permits]);
91
91
  }
92
- getTokenPermitJSONData(contract, message, overrideDomain = null) {
92
+ getTokenPermitJSONData(contract, message, version = null) {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
- console.log("overrideDomain", overrideDomain);
95
- console.log("domain", yield this.getDomainPermit1(contract));
96
- const domain = !overrideDomain ? overrideDomain : yield this.getDomainPermit1(contract);
94
+ const domain = yield this.getDomainPermit1(contract, version);
95
+ console.log(domain);
97
96
  const primaryType = "Permit";
98
97
  return JSON.stringify({ types: TOKEN_PERMIT_TYPES, domain, primaryType, message });
99
98
  });
@@ -138,7 +137,7 @@ class OnchainPermitHelper {
138
137
  });
139
138
  });
140
139
  }
141
- getTokenPermit(token, owner, spender, value, overrideDomain = null) {
140
+ getTokenPermit(token, owner, spender, value, version = null) {
142
141
  return __awaiter(this, void 0, void 0, function* () {
143
142
  const nonce = yield token.methods.nonces(owner).call();
144
143
  const jsonData = yield this.getTokenPermitJSONData(token, {
@@ -147,7 +146,7 @@ class OnchainPermitHelper {
147
146
  value: value.toString(),
148
147
  nonce: ethers_1.BigNumber.from(nonce).toHexString(),
149
148
  deadline: this.deadline,
150
- }, overrideDomain);
149
+ }, version);
151
150
  return {
152
151
  permitType: onchainTypes_1.PermitType.PERMIT1,
153
152
  permitData: ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'uint256'], [token._address, value.toString(), this.deadline]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.47",
3
+ "version": "2.1.49",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",