impermax-sdk 2.1.141 → 2.1.143
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/subgraphs.js +3 -0
- package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.js +29 -59
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +54 -80
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +3 -14
- package/lib/offchain/account/lendingPool/offchainAccountCollateralV2.js +10 -24
- package/lib/offchain/account/lendingPool/offchainAccountCollateralV3.js +2 -13
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +8 -23
- package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV2.js +25 -43
- package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.js +33 -54
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +55 -102
- package/lib/offchain/account/offchainAccount.js +94 -127
- package/lib/offchain/account/offchainAccountPoolToken.js +4 -15
- package/lib/offchain/account/offchainMultichainAccount.js +171 -199
- package/lib/offchain/account/vault/offchainAccountVault.js +32 -49
- package/lib/offchain/configManager/offchainConfigManager.js +7 -20
- package/lib/offchain/configManager/offchainConfigManagerInitializer.js +23 -40
- package/lib/offchain/configManager/offchainPairConfig.js +25 -48
- package/lib/offchain/configManager/offchainProposal.js +15 -32
- package/lib/offchain/initializer/apollo.js +11 -22
- package/lib/offchain/initializer/blocks.js +13 -24
- package/lib/offchain/initializer/farming.js +30 -41
- package/lib/offchain/initializer/lendingPools.js +154 -173
- package/lib/offchain/initializer/lendingPoolsPast.js +114 -132
- package/lib/offchain/initializer/staking.js +9 -22
- package/lib/offchain/initializer/tvl.js +89 -102
- package/lib/offchain/initializer/user/lendingPools.js +58 -74
- package/lib/offchain/initializer/user/positionsV2.js +24 -35
- package/lib/offchain/initializer/user/positionsV3.js +39 -45
- package/lib/offchain/initializer/user/vaults.js +44 -56
- package/lib/offchain/initializer/vaults.js +61 -76
- package/lib/offchain/initializer/whitelist.js +37 -54
- package/lib/offchain/lendingPool/nftlp/offchainNftlp.js +8 -21
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +23 -42
- package/lib/offchain/lendingPool/offchainBorrowable.js +304 -398
- package/lib/offchain/lendingPool/offchainCollateralV2.js +24 -52
- package/lib/offchain/lendingPool/offchainCollateralV3.js +20 -43
- package/lib/offchain/lendingPool/offchainLendingPool.js +208 -273
- package/lib/offchain/lendingPool/offchainLendingPoolV2.js +9 -20
- package/lib/offchain/offchain.d.ts +1 -3
- package/lib/offchain/offchain.js +92 -130
- package/lib/offchain/offchainAPRHelper.js +176 -223
- package/lib/offchain/offchainEndpointManager.d.ts +11 -6
- package/lib/offchain/offchainEndpointManager.js +59 -72
- package/lib/offchain/offchainMultichain.d.ts +3 -0
- package/lib/offchain/offchainMultichain.js +36 -44
- package/lib/offchain/offchainPoolToken.js +55 -88
- package/lib/offchain/offchainPriceHelper.js +237 -265
- package/lib/offchain/offchainSolidexHelper.js +30 -43
- package/lib/offchain/queries/apis/ponder/index.js +3 -3
- package/lib/offchain/queries/apis/thegraph/index.js +5 -6
- package/lib/offchain/queries/index.js +5 -2
- package/lib/offchain/vault/offchainHedgedVault.js +4 -17
- package/lib/offchain/vault/offchainLendingVault.js +46 -67
- package/lib/offchain/vault/offchainLeveragedVault.js +4 -17
- package/lib/offchain/vault/offchainVault.js +86 -131
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +35 -66
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +6 -17
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +79 -108
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +14 -29
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +3 -14
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +36 -61
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +5 -18
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +13 -26
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +169 -204
- package/lib/onchain/account/onchainAccount.js +53 -82
- package/lib/onchain/account/onchainAccountLendingVault.js +6 -19
- package/lib/onchain/account/onchainAccountPoolToken.js +37 -60
- package/lib/onchain/configManager/onchainPairConfig.js +30 -53
- package/lib/onchain/configManager/onchainProposal.js +16 -31
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +8 -21
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +54 -83
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +72 -112
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +8 -23
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +2 -13
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +4 -15
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +11 -31
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +10 -25
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +22 -43
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +206 -273
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +7 -18
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +14 -25
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +190 -209
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +26 -43
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +4 -15
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +14 -29
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +69 -90
- package/lib/onchain/interactions/onchainInteractions.js +21 -38
- package/lib/onchain/interactions/onchainInteractionsConfigManager.js +9 -24
- package/lib/onchain/interactions/onchainInteractionsPoolToken.js +92 -131
- package/lib/onchain/onchain.d.ts +2 -0
- package/lib/onchain/onchain.js +6 -0
- package/lib/onchain/onchainLendingVault.js +18 -39
- package/lib/onchain/onchainPermitHelper.js +84 -111
- package/lib/onchain/onchainPoolToken.js +68 -107
- package/lib/utils/ether-utils.js +1 -1
- package/lib/utils/lliquidity-math.js +4 -4
- package/lib/utils/nftlpMath/uniswapV3General.js +1 -1
- package/lib/utils/nftlpMath/uniswapV3Position.js +2 -2
- package/lib/utils/position/uniswapV3/index.js +2 -2
- package/package.json +4 -3
package/lib/config/subgraphs.js
CHANGED
|
@@ -27,12 +27,15 @@ exports.IMPERMAX_SUBGRAPH_URL = {
|
|
|
27
27
|
[types_1.Networks.Arbitrum]: {
|
|
28
28
|
[types_1.Factory.V2V1_1]: [
|
|
29
29
|
"https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/3PMyaq269mDMwhJ7E285RYD1r43x996b6xZmJSCGvtkm",
|
|
30
|
+
"https://arbitrum-factory-production.up.railway.app/"
|
|
30
31
|
],
|
|
31
32
|
[types_1.Factory.V2V2]: [
|
|
32
33
|
"https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/BkMRb8mR5zgCbjFSgau6s27pnANhR6k64RGVKUbWaZdY",
|
|
34
|
+
"https://arbitrum-factory-production.up.railway.app/"
|
|
33
35
|
],
|
|
34
36
|
[types_1.Factory.SOLV2]: [
|
|
35
37
|
"https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/AdLbcSfG6JnpZ7RDdHNHq3bJ21waGnRi7AJ5x3YFGYFo",
|
|
38
|
+
"https://arbitrum-factory-production.up.railway.app/"
|
|
36
39
|
],
|
|
37
40
|
},
|
|
38
41
|
[types_1.Networks.Avalanche]: {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -23,67 +14,46 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
|
|
|
23
14
|
this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
|
|
24
15
|
}
|
|
25
16
|
// Returns all positions by token ID
|
|
26
|
-
getTokenPositions() {
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
const positions = (_a = (yield this.getLendingPool().getLendingPoolPosition())) === null || _a === void 0 ? void 0 : _a.positions;
|
|
30
|
-
return positions;
|
|
31
|
-
});
|
|
17
|
+
async getTokenPositions() {
|
|
18
|
+
const positions = (await this.getLendingPool().getLendingPoolPosition())?.positions;
|
|
19
|
+
return positions;
|
|
32
20
|
}
|
|
33
21
|
// Returns single position data
|
|
34
|
-
getPositionData(tokenId) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return positions[tokenId].nftlp;
|
|
38
|
-
});
|
|
22
|
+
async getPositionData(tokenId) {
|
|
23
|
+
const positions = await this.getTokenPositions();
|
|
24
|
+
return positions[tokenId].nftlp;
|
|
39
25
|
}
|
|
40
26
|
// Mirrored from Onchain
|
|
41
|
-
getFee(tokenId) {
|
|
42
|
-
return
|
|
43
|
-
return (yield this.getPositionData(tokenId)).fee / 10000;
|
|
44
|
-
});
|
|
27
|
+
async getFee(tokenId) {
|
|
28
|
+
return (await this.getPositionData(tokenId)).fee / 10000;
|
|
45
29
|
}
|
|
46
|
-
getTickLower(tokenId) {
|
|
47
|
-
return
|
|
48
|
-
return (yield this.getPositionData(tokenId)).tickLower;
|
|
49
|
-
});
|
|
30
|
+
async getTickLower(tokenId) {
|
|
31
|
+
return (await this.getPositionData(tokenId)).tickLower;
|
|
50
32
|
}
|
|
51
|
-
getTickUpper(tokenId) {
|
|
52
|
-
return
|
|
53
|
-
return (yield this.getPositionData(tokenId)).tickUpper;
|
|
54
|
-
});
|
|
33
|
+
async getTickUpper(tokenId) {
|
|
34
|
+
return (await this.getPositionData(tokenId)).tickUpper;
|
|
55
35
|
}
|
|
56
|
-
getPriceA(tokenId) {
|
|
57
|
-
return
|
|
58
|
-
return this.getNftlp().tickToPrice(yield this.getTickLower(tokenId));
|
|
59
|
-
});
|
|
36
|
+
async getPriceA(tokenId) {
|
|
37
|
+
return this.getNftlp().tickToPrice(await this.getTickLower(tokenId));
|
|
60
38
|
}
|
|
61
|
-
getPriceB(tokenId) {
|
|
62
|
-
return
|
|
63
|
-
return this.getNftlp().tickToPrice(yield this.getTickUpper(tokenId));
|
|
64
|
-
});
|
|
39
|
+
async getPriceB(tokenId) {
|
|
40
|
+
return this.getNftlp().tickToPrice(await this.getTickUpper(tokenId));
|
|
65
41
|
}
|
|
66
|
-
getLiquidity(tokenId) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
|
|
72
|
-
});
|
|
42
|
+
async getLiquidity(tokenId) {
|
|
43
|
+
const decimalsA = await this.getNftlp().getLendingPool().getBorrowableA().getDecimals();
|
|
44
|
+
const decimalsB = await this.getNftlp().getLendingPool().getBorrowableB().getDecimals();
|
|
45
|
+
const liquidity = (await this.getPositionData(tokenId)).liquidity;
|
|
46
|
+
return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
|
|
73
47
|
}
|
|
74
|
-
createPositionObject(tokenId, lockStateChange = true) {
|
|
75
|
-
return
|
|
76
|
-
return new uniswapV3_1.default(yield this.getLiquidity(tokenId), yield this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), yield this.getLendingPool().getBorrowableB().getBorrowedAmount(tokenId), yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), yield this.getPriceA(tokenId), yield this.getPriceB(tokenId), yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
77
|
-
});
|
|
48
|
+
async createPositionObject(tokenId, lockStateChange = true) {
|
|
49
|
+
return new uniswapV3_1.default(await this.getLiquidity(tokenId), await this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), await this.getLendingPool().getBorrowableB().getBorrowedAmount(tokenId), await this.getNftlp().getMarketPrice(), await this.getNftlp().getOraclePrice(), await this.getPriceA(tokenId), await this.getPriceB(tokenId), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
78
50
|
}
|
|
79
|
-
getPositionObject(tokenId) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return this.cache.positionsObject[tokenId];
|
|
86
|
-
});
|
|
51
|
+
async getPositionObject(tokenId) {
|
|
52
|
+
if (!this.cache.positionsObject)
|
|
53
|
+
this.cache.positionsObject = {};
|
|
54
|
+
if (!this.cache.positionsObject[tokenId])
|
|
55
|
+
this.cache.positionsObject[tokenId] = this.createPositionObject(tokenId);
|
|
56
|
+
return this.cache.positionsObject[tokenId];
|
|
87
57
|
}
|
|
88
58
|
}
|
|
89
59
|
exports.default = OffchainAccountNftlpUniswapV3;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -26,91 +17,74 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
|
|
|
26
17
|
* Supply Positions *
|
|
27
18
|
*--------------------------------------------------------------------------*/
|
|
28
19
|
// Lending position //
|
|
29
|
-
getSupplyPosition() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return lendingPoolPosition[`borrowable${this.borrowable}`];
|
|
35
|
-
});
|
|
20
|
+
async getSupplyPosition() {
|
|
21
|
+
const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
|
|
22
|
+
if (!lendingPoolPosition)
|
|
23
|
+
return undefined;
|
|
24
|
+
return lendingPoolPosition[`borrowable${this.borrowable}`];
|
|
36
25
|
}
|
|
37
|
-
getAmount() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return supplyBalance * exchangeRate;
|
|
45
|
-
});
|
|
26
|
+
async getAmount() {
|
|
27
|
+
const supplyPosition = await this.getSupplyPosition();
|
|
28
|
+
if (!supplyPosition)
|
|
29
|
+
return 0;
|
|
30
|
+
const exchangeRate = await this.poolToken.getCurrentExchangeRate();
|
|
31
|
+
const supplyBalance = parseFloat(supplyPosition.balance);
|
|
32
|
+
return supplyBalance * exchangeRate;
|
|
46
33
|
}
|
|
47
|
-
getValue() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return borrowedAmount * tokenPrice;
|
|
52
|
-
});
|
|
34
|
+
async getValue() {
|
|
35
|
+
const tokenPrice = await this.poolToken.getTokenPriceAccurate();
|
|
36
|
+
const borrowedAmount = await this.getAmount();
|
|
37
|
+
return borrowedAmount * tokenPrice;
|
|
53
38
|
}
|
|
54
39
|
// Earnings //
|
|
55
40
|
// WARN: Not all networks support cumulativeEarnings for now, see the `userQuery` in
|
|
56
41
|
// queries/apis/thegraph/index.ts. atm only available on Blast
|
|
57
|
-
getEarnings() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return cumulativeEarnings + newEarnings;
|
|
70
|
-
});
|
|
42
|
+
async getEarnings() {
|
|
43
|
+
const supplyPosition = await this.getSupplyPosition();
|
|
44
|
+
if (!supplyPosition)
|
|
45
|
+
return 0;
|
|
46
|
+
const exchangeRate = await this.poolToken.getCurrentExchangeRate();
|
|
47
|
+
if (!supplyPosition.cumulativeEarnings)
|
|
48
|
+
return 0;
|
|
49
|
+
const cumulativeEarnings = parseFloat(supplyPosition.cumulativeEarnings);
|
|
50
|
+
const lastExchangeRate = parseFloat(supplyPosition.lastExchangeRate);
|
|
51
|
+
const tokenBalance = parseFloat(supplyPosition.balance);
|
|
52
|
+
const newEarnings = (exchangeRate - lastExchangeRate) * tokenBalance;
|
|
53
|
+
return cumulativeEarnings + newEarnings;
|
|
71
54
|
}
|
|
72
|
-
getEarningsUSD() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return earnings * tokenPrice;
|
|
77
|
-
});
|
|
55
|
+
async getEarningsUSD() {
|
|
56
|
+
const tokenPrice = await this.poolToken.getTokenPriceAccurate();
|
|
57
|
+
const earnings = await this.getEarnings();
|
|
58
|
+
return earnings * tokenPrice;
|
|
78
59
|
}
|
|
79
60
|
/*--------------------------------------------------------------------------*
|
|
80
61
|
* Borrow Positions *
|
|
81
62
|
*--------------------------------------------------------------------------*/
|
|
82
|
-
getBorrowPosition(tokenId) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const borrowableId = yield this.getPoolToken().getUnderlyingAddress();
|
|
93
|
-
return borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions.find(i => i.borrowable.underlying.id === borrowableId);
|
|
94
|
-
});
|
|
63
|
+
async getBorrowPosition(tokenId) {
|
|
64
|
+
const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
|
|
65
|
+
// For V2 borrow positions
|
|
66
|
+
if (tokenId === undefined)
|
|
67
|
+
return lendingPoolPosition?.borrowPositions?.[`borrowable${this.borrowable}`];
|
|
68
|
+
// For V3 borrow positions with tokenId
|
|
69
|
+
// Find the corresponding borrow position for this borrowable using underlying address
|
|
70
|
+
const borrowPositions = lendingPoolPosition?.positions?.[tokenId]?.borrowPositions;
|
|
71
|
+
const borrowableId = await this.getPoolToken().getUnderlyingAddress();
|
|
72
|
+
return borrowPositions?.find(i => i.borrowable.underlying.id === borrowableId);
|
|
95
73
|
}
|
|
96
74
|
// Borrowing position
|
|
97
|
-
getBorrowedAmount(tokenId) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return borrowBalance * borrowIndex / userBorrowIndex;
|
|
106
|
-
});
|
|
75
|
+
async getBorrowedAmount(tokenId) {
|
|
76
|
+
const borrowPosition = await this.getBorrowPosition(tokenId);
|
|
77
|
+
const borrowIndex = await this.poolToken.getBorrowIndex();
|
|
78
|
+
if (!borrowPosition)
|
|
79
|
+
return 0;
|
|
80
|
+
const borrowBalance = parseFloat(borrowPosition.borrowBalance);
|
|
81
|
+
const userBorrowIndex = parseFloat(borrowPosition.borrowIndex);
|
|
82
|
+
return borrowBalance * borrowIndex / userBorrowIndex;
|
|
107
83
|
}
|
|
108
|
-
getBorrowedValue(tokenId) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return borrowedAmount * tokenPrice;
|
|
113
|
-
});
|
|
84
|
+
async getBorrowedValue(tokenId) {
|
|
85
|
+
const tokenPrice = await this.poolToken.getTokenPriceAccurate();
|
|
86
|
+
const borrowedAmount = await this.getBorrowedAmount(tokenId);
|
|
87
|
+
return borrowedAmount * tokenPrice;
|
|
114
88
|
}
|
|
115
89
|
}
|
|
116
90
|
exports.default = OffchainAccountBorrowable;
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
class OffchainAccountCollateral {
|
|
13
4
|
constructor() {
|
|
14
5
|
//public abstract cleanCache();
|
|
15
6
|
this.getAccount = () => this.getLendingPool().getAccount();
|
|
16
7
|
}
|
|
17
|
-
getAmount() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return 0;
|
|
21
|
-
});
|
|
8
|
+
async getAmount() {
|
|
9
|
+
// TODO remove this class?
|
|
10
|
+
return 0;
|
|
22
11
|
}
|
|
23
12
|
}
|
|
24
13
|
exports.default = OffchainAccountCollateral;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -20,22 +11,17 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
|
|
|
20
11
|
this.getLendingPool = () => this.lendingPool;
|
|
21
12
|
this.lendingPool = lendingPool;
|
|
22
13
|
}
|
|
23
|
-
getCollateralPosition() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return undefined;
|
|
29
|
-
return (_a = lendingPoolPosition[`collateralPosition`]) === null || _a === void 0 ? void 0 : _a[0];
|
|
30
|
-
});
|
|
14
|
+
async getCollateralPosition() {
|
|
15
|
+
const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
|
|
16
|
+
if (!lendingPoolPosition)
|
|
17
|
+
return undefined;
|
|
18
|
+
return lendingPoolPosition[`collateralPosition`]?.[0];
|
|
31
19
|
}
|
|
32
|
-
getAmount() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return parseFloat(collateralPosition.balance);
|
|
38
|
-
});
|
|
20
|
+
async getAmount() {
|
|
21
|
+
const collateralPosition = await this.getCollateralPosition();
|
|
22
|
+
if (!collateralPosition)
|
|
23
|
+
return 0;
|
|
24
|
+
return parseFloat(collateralPosition.balance);
|
|
39
25
|
}
|
|
40
26
|
}
|
|
41
27
|
exports.default = OffchainAccountCollateralV2;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -31,10 +22,8 @@ class OffchainAccountCollateralV3 extends offchainAccountCollateral_1.default {
|
|
|
31
22
|
cleanCache() {
|
|
32
23
|
this.collateralCache = {};
|
|
33
24
|
}
|
|
34
|
-
getAmount() {
|
|
35
|
-
return
|
|
36
|
-
return 1;
|
|
37
|
-
});
|
|
25
|
+
async getAmount() {
|
|
26
|
+
return 1;
|
|
38
27
|
}
|
|
39
28
|
}
|
|
40
29
|
exports.default = OffchainAccountCollateralV3;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const types_1 = require("../../../config/types");
|
|
13
4
|
class OffchainAccountLendingPool {
|
|
@@ -21,8 +12,8 @@ class OffchainAccountLendingPool {
|
|
|
21
12
|
this.getCollateral = () => this.collateral;
|
|
22
13
|
this.getFactory = () => this.lendingPool.getFactory();
|
|
23
14
|
this.getId = () => this.getId();
|
|
24
|
-
this.getSafetyMargin = () =>
|
|
25
|
-
this.getLiquidationPenalty = () =>
|
|
15
|
+
this.getSafetyMargin = async () => await this.lendingPool.getSafetyMargin();
|
|
16
|
+
this.getLiquidationPenalty = async () => await this.lendingPool.getLiquidationPenalty();
|
|
26
17
|
this.account = account;
|
|
27
18
|
this.lendingPool = lendingPool;
|
|
28
19
|
this.collateral = this.getNewCollateralObject();
|
|
@@ -31,20 +22,14 @@ class OffchainAccountLendingPool {
|
|
|
31
22
|
[types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
|
|
32
23
|
};
|
|
33
24
|
}
|
|
34
|
-
getLeveragedPositions() {
|
|
35
|
-
return
|
|
36
|
-
return [];
|
|
37
|
-
});
|
|
25
|
+
async getLeveragedPositions() {
|
|
26
|
+
return [];
|
|
38
27
|
}
|
|
39
|
-
getLeveragedPositionsTotalBalanceUSD() {
|
|
40
|
-
return
|
|
41
|
-
return 1;
|
|
42
|
-
});
|
|
28
|
+
async getLeveragedPositionsTotalBalanceUSD() {
|
|
29
|
+
return 1;
|
|
43
30
|
}
|
|
44
|
-
getLeveragedPositionsNetAPR() {
|
|
45
|
-
return
|
|
46
|
-
return 1;
|
|
47
|
-
});
|
|
31
|
+
async getLeveragedPositionsNetAPR() {
|
|
32
|
+
return 1;
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
35
|
exports.default = OffchainAccountLendingPool;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -35,8 +26,8 @@ class OffchainAccountLendingPoolV2 extends offchainAccountLendingPool_1.default
|
|
|
35
26
|
this.getAccount = () => this.account;
|
|
36
27
|
this.getFactory = () => this.lendingPool.getFactory();
|
|
37
28
|
this.getId = () => this.getId();
|
|
38
|
-
this.getSafetyMargin = () =>
|
|
39
|
-
this.getLiquidationPenalty = () =>
|
|
29
|
+
this.getSafetyMargin = async () => await this.lendingPool.getSafetyMargin();
|
|
30
|
+
this.getLiquidationPenalty = async () => await this.lendingPool.getLiquidationPenalty();
|
|
40
31
|
this.account = account;
|
|
41
32
|
this.lendingPool = lendingPool;
|
|
42
33
|
this.collateral = this.getNewCollateralObject();
|
|
@@ -48,41 +39,32 @@ class OffchainAccountLendingPoolV2 extends offchainAccountLendingPool_1.default
|
|
|
48
39
|
/*--------------------------------------------------------------------------*
|
|
49
40
|
* User Lending Pool Data (PoolToken) *
|
|
50
41
|
*--------------------------------------------------------------------------*/
|
|
51
|
-
getLendingPoolPosition() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
});
|
|
42
|
+
async getLendingPoolPosition() {
|
|
43
|
+
const userData = await this.account.getUserData();
|
|
44
|
+
const userDataOfFactory = userData?.[this.lendingPool.getFactory()];
|
|
45
|
+
if (!userDataOfFactory)
|
|
46
|
+
return;
|
|
47
|
+
const pairAddress = this.lendingPool.getPairAddress();
|
|
48
|
+
const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
|
|
49
|
+
const borrowPositions = userDataOfFactory?.borrowPositions?.[pairAddress];
|
|
50
|
+
return {
|
|
51
|
+
borrowable0: supplyPositions?.[types_1.PoolTokenType.BorrowableA],
|
|
52
|
+
borrowable1: supplyPositions?.[types_1.PoolTokenType.BorrowableB],
|
|
53
|
+
collateralPosition: userDataOfFactory?.collateralPositions?.[pairAddress],
|
|
54
|
+
borrowPositions: {
|
|
55
|
+
borrowable0: borrowPositions?.[types_1.PoolTokenType.BorrowableA],
|
|
56
|
+
borrowable1: borrowPositions?.[types_1.PoolTokenType.BorrowableB]
|
|
57
|
+
},
|
|
58
|
+
};
|
|
71
59
|
}
|
|
72
|
-
getLeveragedPositions() {
|
|
73
|
-
return
|
|
74
|
-
return [];
|
|
75
|
-
});
|
|
60
|
+
async getLeveragedPositions() {
|
|
61
|
+
return [];
|
|
76
62
|
}
|
|
77
|
-
getLeveragedPositionsTotalBalanceUSD() {
|
|
78
|
-
return
|
|
79
|
-
return 1;
|
|
80
|
-
});
|
|
63
|
+
async getLeveragedPositionsTotalBalanceUSD() {
|
|
64
|
+
return 1;
|
|
81
65
|
}
|
|
82
|
-
getLeveragedPositionsNetAPR() {
|
|
83
|
-
return
|
|
84
|
-
return 1;
|
|
85
|
-
});
|
|
66
|
+
async getLeveragedPositionsNetAPR() {
|
|
67
|
+
return 1;
|
|
86
68
|
}
|
|
87
69
|
}
|
|
88
70
|
exports.default = OffchainAccountLendingPoolV2;
|