impermax-sdk 1.2.11 → 1.2.13

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.
@@ -7,40 +7,40 @@ exports.ROUTER = {
7
7
  [types_1.Factory.V2V1]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632'
8
8
  },
9
9
  [types_1.Networks.Mainnet]: {
10
- [types_1.Factory.V2V1]: '0x5e169082fff23cee6766062b96051a78c543127d'
10
+ [types_1.Factory.V2V1]: '0x6271c6D2Cf5072D769A16eD99C8D5F3272d44E4F'
11
11
  },
12
12
  [types_1.Networks.Polygon]: {
13
- [types_1.Factory.V2V1_1]: '0x7C79A1c2152665273ebD50e9E88d92A887a83BA0',
14
- [types_1.Factory.V2V2]: '0x4e69Cf49FF3aF82eFe304a3C723556efB7434736',
15
- [types_1.Factory.SOLV2]: '0x4aE11dC7D7e70eE16d7eaE32851302e55f6CA85e',
16
- [types_1.Factory.SOL_STABLE]: '0x509f26e44F5D8814879ABB27a9eB72159FA92F53',
13
+ [types_1.Factory.V2V1_1]: '0x69767394c72240275A7a6CCeD1f1a7960Aa06333',
14
+ [types_1.Factory.V2V2]: '0xF117a35038cdcfFAAeA6f953438E048D9440A9c2',
15
+ [types_1.Factory.SOLV2]: '0xD7F63a4F2d317b51e84e64cb0d1eDB9F70956Ac9',
16
+ [types_1.Factory.SOL_STABLE]: '0xe564D3d09863D81ACa176abE58de027389a186aA',
17
17
  },
18
18
  [types_1.Networks.Arbitrum]: {
19
- [types_1.Factory.V2V1_1]: '0xd0543EA38f433Dd3Dc87B8e784aE715bD7154BD8',
20
- [types_1.Factory.V2V2]: '0x6e6a0c7131f273c6BdC4860a7C4610A1F5978869',
21
- [types_1.Factory.SOLV2]: '0x0B13BeC190E71DaCB101bC02f8f4d28A376Ff623',
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
- [types_1.Factory.V2V1_2]: '0x3039C26F9126833bAca8EdBF61c761CD909F461f',
25
- [types_1.Factory.V2V2]: '0xaf82ee9246a608484e8567fadbef64ac1b8a87ab',
26
- [types_1.Factory.SOLV2]: '0x8B07b0d9F4470635546Ef39CD3C5D00673864D0a',
24
+ [types_1.Factory.V2V1_2]: '0xA8567d1229cCaB63E3a834Cd29066a063911E4cf',
25
+ [types_1.Factory.V2V2]: '0xfB48b69fcba9218f86a437121198E46b2b88Ad63',
26
+ [types_1.Factory.SOLV2]: '0xD18d2B8BaAd0078593a3C020cc3c6c5CD2F5B8b8',
27
27
  },
28
28
  [types_1.Networks.Moonriver]: {
29
- [types_1.Factory.V2V1_2]: '0x3271cc175577465691e48196955e09d638fa05d5',
29
+ [types_1.Factory.V2V1_2]: '0x3271cc175577465691e48196955e09d638fa05d5', // OLD ROUTER
30
30
  },
31
31
  [types_1.Networks.Aurora]: {
32
- [types_1.Factory.V2V1_2]: '0xBB92270716C8c424849F17cCc12F4F24AD4064D6',
32
+ [types_1.Factory.V2V1_2]: '0xBB92270716C8c424849F17cCc12F4F24AD4064D6', // OLD ROUTER
33
33
  },
34
34
  [types_1.Networks.Cronos]: {},
35
35
  [types_1.Networks.Fantom]: {
36
- [types_1.Factory.SOLV1_2]: '0xB9f3413e206F1D658D4DaFB233873dDe56cf94Fc',
37
- [types_1.Factory.SOLV2]: '0xc75094b5cE53C050816A446701B0D69101c40937',
36
+ [types_1.Factory.SOLV1_2]: '0xF655C8567E0f213e6C634CD2A68d992152161dC6',
37
+ [types_1.Factory.SOLV2]: '0xd9eA4A62C46Cb221F74314C21979Cfb2E020de87',
38
38
  },
39
39
  [types_1.Networks.Canto]: {
40
- [types_1.Factory.SOLV2]: '0xf6f32Ddb73d103895228Aa603c252690fC95727d',
40
+ [types_1.Factory.SOLV2]: '0x370D3eE40f1257fC432C33e387981CeDD15C7fac',
41
41
  },
42
42
  [types_1.Networks.ZksyncEra]: {
43
- [types_1.Factory.SOLV2]: '0x0463cdFc586c36CCD0E2510acECE24bdac354324',
43
+ [types_1.Factory.SOLV2]: '0xDC9eb03D753D552A3eE286d272F37d49de2783D3',
44
44
  },
45
45
  [types_1.Networks.Harmony]: {},
46
46
  [types_1.Networks.Moonbeam]: {},
@@ -48,16 +48,16 @@ exports.ROUTER = {
48
48
  };
49
49
  exports.DEFAULT_ROUTER = {
50
50
  [types_1.Networks.Ropsten]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632',
51
- [types_1.Networks.Mainnet]: '0x5e169082fff23cee6766062b96051a78c543127d',
52
- [types_1.Networks.Polygon]: '0x4e69Cf49FF3aF82eFe304a3C723556efB7434736',
53
- [types_1.Networks.Arbitrum]: '0x6e6a0c7131f273c6BdC4860a7C4610A1F5978869',
54
- [types_1.Networks.Avalanche]: '0xaf82ee9246a608484e8567fadbef64ac1b8a87ab',
51
+ [types_1.Networks.Mainnet]: '0x6271c6D2Cf5072D769A16eD99C8D5F3272d44E4F',
52
+ [types_1.Networks.Polygon]: '0xF117a35038cdcfFAAeA6f953438E048D9440A9c2',
53
+ [types_1.Networks.Arbitrum]: '0x58d966725Ee8fcd93CAF7C98C0c8F9b34ef076D3',
54
+ [types_1.Networks.Avalanche]: '0xfB48b69fcba9218f86a437121198E46b2b88Ad63',
55
55
  [types_1.Networks.Moonriver]: '0x3271cc175577465691e48196955e09d638fa05d5',
56
56
  [types_1.Networks.Aurora]: '0xBB92270716C8c424849F17cCc12F4F24AD4064D6',
57
57
  [types_1.Networks.Cronos]: '',
58
- [types_1.Networks.Fantom]: '0xB9f3413e206F1D658D4DaFB233873dDe56cf94Fc',
59
- [types_1.Networks.Canto]: '0xf6f32Ddb73d103895228Aa603c252690fC95727d',
60
- [types_1.Networks.ZksyncEra]: '0x0463cdFc586c36CCD0E2510acECE24bdac354324',
58
+ [types_1.Networks.Fantom]: '0xF655C8567E0f213e6C634CD2A68d992152161dC6',
59
+ [types_1.Networks.Canto]: '0x370D3eE40f1257fC432C33e387981CeDD15C7fac',
60
+ [types_1.Networks.ZksyncEra]: '0xDC9eb03D753D552A3eE286d272F37d49de2783D3',
61
61
  [types_1.Networks.Harmony]: '',
62
62
  [types_1.Networks.Moonbeam]: '',
63
63
  [types_1.Networks.Sxnetwork]: '',
@@ -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;
@@ -40,7 +40,7 @@ class OnchainAccountLendingVault extends onchainAccountPoolToken_1.default {
40
40
  getMaxWithdrawable() {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  const deposited = (yield this.getDeposited()) * this.getDust();
43
- const availableCash = (yield this.poolToken.getAvailableLiquidity()) / this.getDust();
43
+ const availableCash = (yield this.poolToken.getAvailableLiquidity()) * (1 - this.getLiquidityBuffer());
44
44
  return Math.min(deposited, availableCash);
45
45
  });
46
46
  }
@@ -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
  }
@@ -77,7 +78,7 @@ class OnchainAccountPoolToken {
77
78
  getMaxWithdrawable() {
78
79
  return __awaiter(this, void 0, void 0, function* () {
79
80
  const deposited = (yield this.getDeposited()) * this.getDust();
80
- const availableCash = (yield this.poolToken.getTotalBalance()) / 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,6 +19,7 @@ class Onchain {
19
19
  this.web3 = cfg.web3;
20
20
  this.chainId = cfg.chainId;
21
21
  this.uiMargin = 1.1;
22
+ this.liquidityBuffer = 0.0001; // always leave 0.01% liquidity to avoid failures due to exchangeRate increase
22
23
  this.dust = 1.00000001;
23
24
  this.priceInverted = cfg.priceInverted ? cfg.priceInverted : false;
24
25
  this.contractsHelper = new onchainContractsHelper_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.11",
3
+ "version": "1.2.13",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",