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.
- package/lib/config/contracts/routers.js +24 -24
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +1 -1
- package/lib/onchain/account/onchainAccountLendingVault.js +1 -1
- package/lib/onchain/account/onchainAccountPoolToken.d.ts +1 -0
- package/lib/onchain/account/onchainAccountPoolToken.js +2 -1
- package/lib/onchain/onchain.d.ts +1 -0
- package/lib/onchain/onchain.js +1 -0
- package/lib/utils/lliquidity-math.js +3 -1
- package/package.json +1 -1
|
@@ -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]: '
|
|
10
|
+
[types_1.Factory.V2V1]: '0x6271c6D2Cf5072D769A16eD99C8D5F3272d44E4F'
|
|
11
11
|
},
|
|
12
12
|
[types_1.Networks.Polygon]: {
|
|
13
|
-
[types_1.Factory.V2V1_1]: '
|
|
14
|
-
[types_1.Factory.V2V2]: '
|
|
15
|
-
[types_1.Factory.SOLV2]: '
|
|
16
|
-
[types_1.Factory.SOL_STABLE]: '
|
|
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]: '
|
|
20
|
-
[types_1.Factory.V2V2]: '
|
|
21
|
-
[types_1.Factory.SOLV2]: '
|
|
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]: '
|
|
25
|
-
[types_1.Factory.V2V2]: '
|
|
26
|
-
[types_1.Factory.SOLV2]: '
|
|
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]: '
|
|
37
|
-
[types_1.Factory.SOLV2]: '
|
|
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]: '
|
|
40
|
+
[types_1.Factory.SOLV2]: '0x370D3eE40f1257fC432C33e387981CeDD15C7fac',
|
|
41
41
|
},
|
|
42
42
|
[types_1.Networks.ZksyncEra]: {
|
|
43
|
-
[types_1.Factory.SOLV2]: '
|
|
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]: '
|
|
52
|
-
[types_1.Networks.Polygon]: '
|
|
53
|
-
[types_1.Networks.Arbitrum]: '
|
|
54
|
-
[types_1.Networks.Avalanche]: '
|
|
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]: '
|
|
59
|
-
[types_1.Networks.Canto]: '
|
|
60
|
-
[types_1.Networks.ZksyncEra]: '
|
|
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())
|
|
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())
|
|
81
|
+
const availableCash = (yield this.poolToken.getTotalBalance()) * (1 - this.getLiquidityBuffer());
|
|
81
82
|
return Math.min(deposited, availableCash);
|
|
82
83
|
});
|
|
83
84
|
}
|
package/lib/onchain/onchain.d.ts
CHANGED
|
@@ -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;
|
package/lib/onchain/onchain.js
CHANGED
|
@@ -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 (
|
|
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));
|