impermax-sdk 1.2.10 → 1.2.12

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.
@@ -16,9 +16,9 @@ exports.ROUTER = {
16
16
  [types_1.Factory.SOL_STABLE]: '0x509f26e44F5D8814879ABB27a9eB72159FA92F53',
17
17
  },
18
18
  [types_1.Networks.Arbitrum]: {
19
- [types_1.Factory.V2V1_1]: '0x5475aEd9d11BeaA822e122C36ACDfa0dA2eb086f',
20
- [types_1.Factory.V2V2]: '0xaf82ee9246a608484e8567fadbef64ac1b8a87ab',
21
- [types_1.Factory.SOLV2]: '0xFB8Bd40C0a13D141b26eE190Ca87991Ec54932E9',
19
+ [types_1.Factory.V2V1_1]: '0x9655C5a1ADB30EC5a3a7AD5d06AbeDe8468B60B7',
20
+ [types_1.Factory.V2V2]: '0x58d966725Ee8fcd93CAF7C98C0c8F9b34ef076D3',
21
+ [types_1.Factory.SOLV2]: '0x3b03681d1a46B473F0074cd2C4D27f086497DD56',
22
22
  },
23
23
  [types_1.Networks.Avalanche]: {
24
24
  [types_1.Factory.V2V1_2]: '0x3039C26F9126833bAca8EdBF61c761CD909F461f',
@@ -50,7 +50,7 @@ exports.DEFAULT_ROUTER = {
50
50
  [types_1.Networks.Ropsten]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632',
51
51
  [types_1.Networks.Mainnet]: '0x5e169082fff23cee6766062b96051a78c543127d',
52
52
  [types_1.Networks.Polygon]: '0x4e69Cf49FF3aF82eFe304a3C723556efB7434736',
53
- [types_1.Networks.Arbitrum]: '0xaf82ee9246a608484e8567fadbef64ac1b8a87ab',
53
+ [types_1.Networks.Arbitrum]: '0x58d966725Ee8fcd93CAF7C98C0c8F9b34ef076D3',
54
54
  [types_1.Networks.Avalanche]: '0xaf82ee9246a608484e8567fadbef64ac1b8a87ab',
55
55
  [types_1.Networks.Moonriver]: '0x3271cc175577465691e48196955e09d638fa05d5',
56
56
  [types_1.Networks.Aurora]: '0xBB92270716C8c424849F17cCc12F4F24AD4064D6',
@@ -109,7 +109,7 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
109
109
  borrowAmount += jump;
110
110
  }
111
111
  }
112
- return bestAmount / this.getDust();
112
+ return bestAmount;
113
113
  });
114
114
  }
115
115
  // Farming Shares
@@ -102,7 +102,7 @@ class OnchainAccountCollateral extends onchainAccountPoolToken_1.default {
102
102
  break;
103
103
  }
104
104
  }
105
- return bestAmount / this.getDust();
105
+ return bestAmount * this.getDust();
106
106
  });
107
107
  }
108
108
  }
@@ -293,7 +293,7 @@ class OnchainAccountLendingPool {
293
293
  const collateralValueA = valueCollateral * reservesWeight0;
294
294
  const collateralValueB = valueCollateral * reservesWeight1;
295
295
  if (collateralValueA >= valueA && collateralValueB >= valueB) {
296
- return this.getCollateral().getDeposited();
296
+ return (yield this.getCollateral().getDeposited()) * this.account.getOnchain().dust;
297
297
  }
298
298
  if (valueCollateral < valueA + valueB) {
299
299
  return 0;
@@ -39,7 +39,9 @@ class OnchainAccountLendingVault extends onchainAccountPoolToken_1.default {
39
39
  // OnchainInteractions
40
40
  getMaxWithdrawable() {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
- return Math.min(yield this.getDeposited(), (yield this.poolToken.getAvailableLiquidity()) / this.getDust());
42
+ const deposited = (yield this.getDeposited()) * this.getDust();
43
+ const availableCash = (yield this.poolToken.getAvailableLiquidity()) * (1 - this.getLiquidityBuffer());
44
+ return Math.min(deposited, availableCash);
43
45
  });
44
46
  }
45
47
  }
@@ -17,6 +17,7 @@ export default abstract class OnchainAccountPoolToken {
17
17
  getNetwork: () => import("../..").Networks;
18
18
  getEth: () => any;
19
19
  getDust: () => number;
20
+ getLiquidityBuffer: () => number;
20
21
  getUiMargin: () => number;
21
22
  getTokenPriceAccurate: () => Promise<number>;
22
23
  private initializeAvailableBalance;
@@ -19,6 +19,7 @@ class OnchainAccountPoolToken {
19
19
  this.getNetwork = () => this.getAccount().getOnchain().network;
20
20
  this.getEth = () => this.getAccount().getOnchain().web3.eth;
21
21
  this.getDust = () => this.getAccount().getOnchain().dust;
22
+ this.getLiquidityBuffer = () => this.getAccount().getOnchain().liquidityBuffer;
22
23
  this.getUiMargin = () => this.getAccount().getOnchain().uiMargin;
23
24
  this.getTokenPriceAccurate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getOffchainPoolToken()).getTokenPriceAccurate(); });
24
25
  }
@@ -30,10 +31,10 @@ class OnchainAccountPoolToken {
30
31
  return __awaiter(this, void 0, void 0, function* () {
31
32
  const token = yield this.poolToken.getToken();
32
33
  if (token._address.toLowerCase() == weths_1.WETH[this.getNetwork()].toLowerCase()) {
33
- return (yield this.getEth().getBalance(this.getAccountAddress())) / 1e18 / this.getDust();
34
+ return (yield this.getEth().getBalance(this.getAccountAddress())) / 1e18;
34
35
  }
35
36
  const balance = yield token.methods.balanceOf(this.getAccountAddress()).call();
36
- return (yield this.poolToken.normalize(balance)) / this.getDust();
37
+ return (yield this.poolToken.normalize(balance));
37
38
  });
38
39
  }
39
40
  getAvailableBalance() {
@@ -76,8 +77,8 @@ class OnchainAccountPoolToken {
76
77
  // Max Withdrawable
77
78
  getMaxWithdrawable() {
78
79
  return __awaiter(this, void 0, void 0, function* () {
79
- const deposited = yield this.getDeposited();
80
- const availableCash = (yield this.poolToken.getTotalBalance()) / this.getDust();
80
+ const deposited = (yield this.getDeposited()) * this.getDust();
81
+ const availableCash = (yield this.poolToken.getTotalBalance()) * (1 - this.getLiquidityBuffer());
81
82
  return Math.min(deposited, availableCash);
82
83
  });
83
84
  }
@@ -14,6 +14,7 @@ export default class Onchain {
14
14
  readonly chainId: number;
15
15
  readonly uiMargin: number;
16
16
  readonly dust: number;
17
+ readonly liquidityBuffer: number;
17
18
  priceInverted: boolean;
18
19
  protected contractsHelper: OnchainContractsHelper;
19
20
  protected configManager: OnchainConfigManager;
@@ -19,7 +19,8 @@ class Onchain {
19
19
  this.web3 = cfg.web3;
20
20
  this.chainId = cfg.chainId;
21
21
  this.uiMargin = 1.1;
22
- this.dust = 1.000001;
22
+ this.liquidityBuffer = 0.0001; // always leave 0.01% liquidity to avoid failures due to exchangeRate increase
23
+ this.dust = 1.00000001;
23
24
  this.priceInverted = cfg.priceInverted ? cfg.priceInverted : false;
24
25
  this.contractsHelper = new onchainContractsHelper_1.default(this);
25
26
  this.configManager = new configManager_1.default(this);
@@ -16,7 +16,9 @@ exports.uniswapV2_getPriceFromReserves = uniswapV2_getPriceFromReserves;
16
16
  * - 1 meaning it is liquidatable
17
17
  */
18
18
  function uniswapV2_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
19
- if ((x0 == 0 || y0 == 0) && (debtX > 0 || debtY > 0))
19
+ if (debtX == 0 && debtY == 0)
20
+ return 0;
21
+ if (x0 == 0 || y0 == 0)
20
22
  return 1;
21
23
  const k = x0 * y0;
22
24
  const x = k / debtY * (1 + Math.sqrt(1 - debtY * debtX / k));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",