impermax-sdk 1.1.36 → 1.1.37
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/offchain/account/index.js +1 -5
- package/lib/offchain/index.d.ts +1 -3
- package/lib/offchain/initializer.d.ts +2 -6
- package/lib/offchain/initializer.js +7 -18
- package/lib/offchain/priceHelper.js +0 -2
- package/lib/offchain/types.d.ts +5 -0
- package/lib/onchain/account/index.d.ts +2 -0
- package/lib/onchain/account/index.js +5 -1
- package/lib/onchain/account/interactions/index.d.ts +1 -0
- package/lib/onchain/account/interactions/index.js +5 -0
- package/lib/onchain/account/interactions/lendingPool/index.js +0 -3
- package/lib/onchain/impermaxFactory/index.d.ts +1 -1
- package/lib/onchain/impermaxFactory/index.js +5 -5
- package/lib/onchain/impermaxFactory/lendingPool/borrowable.js +1 -1
- package/lib/onchain/impermaxFactory/lendingPool/collateral.js +1 -1
- package/lib/onchain/impermaxFactory/lendingPool/index.js +7 -7
- package/lib/onchain/index.d.ts +2 -0
- package/lib/onchain/index.js +10 -4
- package/package.json +1 -1
|
@@ -44,7 +44,6 @@ const poolToken_1 = __importDefault(require("./poolToken"));
|
|
|
44
44
|
exports.PoolToken = poolToken_1.default;
|
|
45
45
|
const lendingVault_1 = __importDefault(require("./lendingVault"));
|
|
46
46
|
exports.LendingVault = lendingVault_1.default;
|
|
47
|
-
const assert = require("assert");
|
|
48
47
|
class Account {
|
|
49
48
|
constructor(offchain, account) {
|
|
50
49
|
this.offchain = offchain;
|
|
@@ -63,12 +62,9 @@ class Account {
|
|
|
63
62
|
if (!this.accountLLPs[factory])
|
|
64
63
|
this.accountLLPs[factory] = {};
|
|
65
64
|
const accountLLPsOfFactory = this.accountLLPs[factory];
|
|
66
|
-
assert(accountLLPsOfFactory);
|
|
67
65
|
if (!accountLLPsOfFactory[pair])
|
|
68
66
|
accountLLPsOfFactory[pair] = this.initializeAccountLendingPool(factory, pair);
|
|
69
|
-
|
|
70
|
-
assert(accountLendingPool);
|
|
71
|
-
return accountLendingPool;
|
|
67
|
+
return accountLLPsOfFactory[pair];
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
70
|
initializeAccountLendingVault(vaultAddress) {
|
package/lib/offchain/index.d.ts
CHANGED
|
@@ -21,9 +21,7 @@ export default class Offchain {
|
|
|
21
21
|
whitelistedPairs: FactoryIndex<Address[]>;
|
|
22
22
|
lendingPools: LendingPoolIndex<LendingPool>;
|
|
23
23
|
lendingVaults: AddressIndex<LendingVault>;
|
|
24
|
-
accounts:
|
|
25
|
-
[key in Address]: Account;
|
|
26
|
-
};
|
|
24
|
+
accounts: AddressIndex<Account>;
|
|
27
25
|
priceHelper: PriceHelper;
|
|
28
26
|
solidexHelper: SolidexHelper;
|
|
29
27
|
lendingPoolsData: Promise<LendingPoolIndex<LendingPoolData>> | null;
|
|
@@ -3,7 +3,7 @@ import Offchain from "./index";
|
|
|
3
3
|
import { DocumentNode } from "graphql";
|
|
4
4
|
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
5
5
|
import { Amms } from '../config/amms';
|
|
6
|
-
import {
|
|
6
|
+
import { LendingPoolData, RawUserData, TvlData, UserData, XimxData } from './types';
|
|
7
7
|
export declare function apolloFetcher(subgraphUrl: string, query: DocumentNode): Promise<ApolloQueryResult<any>>;
|
|
8
8
|
export declare function fetchBlockByTimestamp(this: Offchain, timestamp: number): Promise<number | null>;
|
|
9
9
|
export declare function fetchLendingPools(this: Offchain): Promise<FactoryIndex<LendingPoolData[]>>;
|
|
@@ -25,11 +25,7 @@ export declare function getLendingPoolsData(this: Offchain): Promise<LendingPool
|
|
|
25
25
|
export declare function getLendingPoolData(this: Offchain, factory: Factory, uniswapV2PairAddress: Address): Promise<LendingPoolData>;
|
|
26
26
|
export declare function initializeTvlData(this: Offchain): Promise<TvlData>;
|
|
27
27
|
export declare function getTvlData(this: Offchain): Promise<TvlData>;
|
|
28
|
-
export declare function fetchUserData(this: Offchain, account: Address): Promise<FactoryIndex<
|
|
29
|
-
collateralPositions: CollateralPosition[];
|
|
30
|
-
supplyPositions: SupplyPosition[];
|
|
31
|
-
borrowPositions: BorrowPosition[];
|
|
32
|
-
}>>;
|
|
28
|
+
export declare function fetchUserData(this: Offchain, account: Address): Promise<FactoryIndex<RawUserData>>;
|
|
33
29
|
export declare function initializeUserData(this: Offchain, account: Address): Promise<FactoryIndex<UserData> | null>;
|
|
34
30
|
export declare function getUserData(this: Offchain, account: Address): Promise<FactoryIndex<UserData> | null>;
|
|
35
31
|
export declare function initializeXimxData(this: Offchain): Promise<XimxData>;
|
|
@@ -44,7 +44,6 @@ const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
|
44
44
|
const subgraphs_1 = require("../config/subgraphs");
|
|
45
45
|
const types_1 = require("../config/types");
|
|
46
46
|
const amms_1 = require("../config/amms");
|
|
47
|
-
const assert = require("assert");
|
|
48
47
|
const SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
|
49
48
|
function apolloFetcher(subgraphUrl, query) {
|
|
50
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -262,7 +261,6 @@ function initializeLendingPoolsData() {
|
|
|
262
261
|
if (!lendingPoolsByAmm[amm])
|
|
263
262
|
lendingPoolsByAmm[amm] = [];
|
|
264
263
|
const lendingPoolsOfAmm = lendingPoolsByAmm[amm];
|
|
265
|
-
assert(lendingPoolsOfAmm !== undefined);
|
|
266
264
|
lendingPoolsOfAmm.push(lendingPool);
|
|
267
265
|
}
|
|
268
266
|
}
|
|
@@ -447,9 +445,8 @@ function getLendingPoolsData() {
|
|
|
447
445
|
exports.getLendingPoolsData = getLendingPoolsData;
|
|
448
446
|
function getLendingPoolData(factory, uniswapV2PairAddress) {
|
|
449
447
|
return __awaiter(this, void 0, void 0, function* () {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
return lendingPoolsDataOfFactory[uniswapV2PairAddress.toLowerCase()];
|
|
448
|
+
const lendingPoolsData = (yield this.getLendingPoolsData())[factory];
|
|
449
|
+
return lendingPoolsData[uniswapV2PairAddress.toLowerCase()];
|
|
453
450
|
});
|
|
454
451
|
}
|
|
455
452
|
exports.getLendingPoolData = getLendingPoolData;
|
|
@@ -572,35 +569,29 @@ function initializeUserData(account) {
|
|
|
572
569
|
supplyPositions: {},
|
|
573
570
|
borrowPositions: {},
|
|
574
571
|
};
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
for (const collateralPosition of data.collateralPositions) {
|
|
572
|
+
const rawUserData = userData[factory];
|
|
573
|
+
for (const collateralPosition of rawUserData.collateralPositions) {
|
|
578
574
|
const resultOfFactory = result[factory];
|
|
579
|
-
assert(resultOfFactory);
|
|
580
575
|
resultOfFactory.collateralPositions[collateralPosition.collateral.lendingPool.id] = collateralPosition;
|
|
581
576
|
}
|
|
582
|
-
for (const supplyPositions of
|
|
577
|
+
for (const supplyPositions of rawUserData.supplyPositions) {
|
|
583
578
|
const uniswapV2PairAddress = supplyPositions.borrowable.lendingPool.id;
|
|
584
579
|
const underlyingAddress = supplyPositions.borrowable.underlying.id;
|
|
585
580
|
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).poolTokens[types_1.PoolTokenType.BorrowableA];
|
|
586
|
-
assert(borrowableA);
|
|
587
581
|
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
588
582
|
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
589
583
|
const resultOfFactory = result[factory];
|
|
590
|
-
assert(resultOfFactory);
|
|
591
584
|
if (!(uniswapV2PairAddress in resultOfFactory.supplyPositions))
|
|
592
585
|
resultOfFactory.supplyPositions[uniswapV2PairAddress] = {};
|
|
593
586
|
resultOfFactory.supplyPositions[uniswapV2PairAddress][poolTokenType] = supplyPositions;
|
|
594
587
|
}
|
|
595
|
-
for (const borrowPositions of
|
|
588
|
+
for (const borrowPositions of rawUserData.borrowPositions) {
|
|
596
589
|
const uniswapV2PairAddress = borrowPositions.borrowable.lendingPool.id;
|
|
597
590
|
const underlyingAddress = borrowPositions.borrowable.underlying.id;
|
|
598
591
|
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).poolTokens[types_1.PoolTokenType.BorrowableA];
|
|
599
|
-
assert(borrowableA);
|
|
600
592
|
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
601
593
|
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
602
594
|
const resultOfFactory = result[factory];
|
|
603
|
-
assert(resultOfFactory);
|
|
604
595
|
if (!(uniswapV2PairAddress in resultOfFactory.borrowPositions))
|
|
605
596
|
resultOfFactory.borrowPositions[uniswapV2PairAddress] = {};
|
|
606
597
|
resultOfFactory.borrowPositions[uniswapV2PairAddress][poolTokenType] = borrowPositions;
|
|
@@ -614,9 +605,7 @@ function getUserData(account) {
|
|
|
614
605
|
return __awaiter(this, void 0, void 0, function* () {
|
|
615
606
|
if (!(account in this.usersData))
|
|
616
607
|
this.usersData[account] = this.initializeUserData(account);
|
|
617
|
-
|
|
618
|
-
assert(userData !== undefined);
|
|
619
|
-
return userData;
|
|
608
|
+
return this.usersData[account];
|
|
620
609
|
});
|
|
621
610
|
}
|
|
622
611
|
exports.getUserData = getUserData;
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const debank_ids_1 = require("../config/debank-ids");
|
|
13
|
-
const assert = require("assert");
|
|
14
13
|
// coingecko has priority over debank for initialized tokens
|
|
15
14
|
const coingecko_ids = {
|
|
16
15
|
// Arbitrum
|
|
@@ -164,7 +163,6 @@ class PriceHelper {
|
|
|
164
163
|
if (!this.debankTokensPrice[tokenAddress])
|
|
165
164
|
this.debankTokensPrice[tokenAddress] = this.initializeDebankTokenPrice(tokenAddress);
|
|
166
165
|
const tokenPrice = yield this.debankTokensPrice[tokenAddress];
|
|
167
|
-
assert(tokenPrice !== undefined);
|
|
168
166
|
if (tokenPrice === 0) {
|
|
169
167
|
//manual fallback
|
|
170
168
|
if (tokenAddress.toLowerCase() === '0xaaa6c1e32c55a7bfa8066a6fae9b42650f262418') { // fix for RAM
|
package/lib/offchain/types.d.ts
CHANGED
|
@@ -116,6 +116,11 @@ export interface BorrowPosition {
|
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
+
export interface RawUserData {
|
|
120
|
+
collateralPositions: CollateralPosition[];
|
|
121
|
+
supplyPositions: SupplyPosition[];
|
|
122
|
+
borrowPositions: BorrowPosition[];
|
|
123
|
+
}
|
|
119
124
|
export interface UserData {
|
|
120
125
|
collateralPositions: {
|
|
121
126
|
[key in Address]: CollateralPosition;
|
|
@@ -11,6 +11,7 @@ export { lendingPool, interactions, LendingPool, Interactions, PoolToken, Lendin
|
|
|
11
11
|
export default class Account {
|
|
12
12
|
router: OnChain;
|
|
13
13
|
account: Address;
|
|
14
|
+
interactions: Interactions;
|
|
14
15
|
accountLLPs: LendingPoolIndex<Promise<LendingPool>>;
|
|
15
16
|
accountLVs: AddressIndex<Promise<LendingVault>>;
|
|
16
17
|
cache: {
|
|
@@ -23,6 +24,7 @@ export default class Account {
|
|
|
23
24
|
};
|
|
24
25
|
constructor(router: OnChain, account: Address);
|
|
25
26
|
cleanCache(): Promise<void>;
|
|
27
|
+
getInteractions(): Interactions;
|
|
26
28
|
private initializeAccountLendingPool;
|
|
27
29
|
getAccountLendingPool(factory: Factory, pair: Address): Promise<LendingPool>;
|
|
28
30
|
private initializeAccountLendingVault;
|
|
@@ -55,6 +55,7 @@ class Account {
|
|
|
55
55
|
this.cache = { airdropData: {}, claimableIBEX: {} };
|
|
56
56
|
this.router = router;
|
|
57
57
|
this.account = account;
|
|
58
|
+
this.interactions = new interactions_1.default(this);
|
|
58
59
|
this.accountLLPs = {};
|
|
59
60
|
this.accountLVs = {};
|
|
60
61
|
}
|
|
@@ -69,11 +70,14 @@ class Account {
|
|
|
69
70
|
for (const vaultAddress in this.accountLVs) {
|
|
70
71
|
(yield this.accountLVs[vaultAddress]).cleanCache();
|
|
71
72
|
}
|
|
73
|
+
this.interactions.cleanCache();
|
|
72
74
|
});
|
|
73
75
|
}
|
|
76
|
+
getInteractions() {
|
|
77
|
+
return this.interactions;
|
|
78
|
+
}
|
|
74
79
|
initializeAccountLendingPool(factory, pair) {
|
|
75
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
const facto = this.router.getFactory(factory);
|
|
77
81
|
const lendingPool = yield this.router.getFactory(factory).getLendingPool(pair);
|
|
78
82
|
return new lendingPool_1.default(this, lendingPool);
|
|
79
83
|
});
|
|
@@ -15,6 +15,7 @@ export default class Interactions {
|
|
|
15
15
|
defaultRouterContract?: Contract;
|
|
16
16
|
};
|
|
17
17
|
constructor(account: Account);
|
|
18
|
+
cleanCache(): Promise<void>;
|
|
18
19
|
private initializeInteractionsLendingPool;
|
|
19
20
|
getInteractionsLendingPool(factory: Factory, pair: Address): Promise<LendingPool>;
|
|
20
21
|
private initializeInteractionsLendingVault;
|
|
@@ -55,6 +55,11 @@ class Interactions {
|
|
|
55
55
|
this.interactionsLLPs = {};
|
|
56
56
|
this.interactionsLVs = {};
|
|
57
57
|
}
|
|
58
|
+
cleanCache() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
this.cache = {};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
58
63
|
initializeInteractionsLendingPool(factory, pair) {
|
|
59
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
65
|
const lendingPool = yield this.account.getAccountLendingPool(factory, pair);
|
|
@@ -20,7 +20,6 @@ const collateral_1 = __importDefault(require("./collateral"));
|
|
|
20
20
|
exports.Collateral = collateral_1.default;
|
|
21
21
|
const borrowable_1 = __importDefault(require("./borrowable"));
|
|
22
22
|
exports.Borrowable = borrowable_1.default;
|
|
23
|
-
const assert = require("assert");
|
|
24
23
|
class LendingPool {
|
|
25
24
|
constructor(interactions, accountLendingPool) {
|
|
26
25
|
this.getRouterLendingPool = () => this.accountLendingPool.lendingPool;
|
|
@@ -113,9 +112,7 @@ class LendingPool {
|
|
|
113
112
|
}
|
|
114
113
|
reinvest(onTransactionHash) {
|
|
115
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const account = this.accountLendingPool.account.account;
|
|
117
115
|
const stakedLPToken = yield this.getRouterLendingPool().getStakedLPToken();
|
|
118
|
-
assert(stakedLPToken);
|
|
119
116
|
return this.send(stakedLPToken.methods.reinvest(), onTransactionHash);
|
|
120
117
|
});
|
|
121
118
|
}
|
|
@@ -5,7 +5,7 @@ import { Address, Factory } from '../../config/types';
|
|
|
5
5
|
import { Contract } from '../types';
|
|
6
6
|
export { lendingPool, LendingPool, };
|
|
7
7
|
export default class ImpermaxFactory {
|
|
8
|
-
|
|
8
|
+
onchain: OnChain;
|
|
9
9
|
factory: Factory;
|
|
10
10
|
lendingPools: {
|
|
11
11
|
[key in Address]: LendingPool;
|
|
@@ -36,7 +36,7 @@ const routers_1 = require("../../config/contracts/routers");
|
|
|
36
36
|
class ImpermaxFactory {
|
|
37
37
|
constructor(router, factory) {
|
|
38
38
|
this.cache = {};
|
|
39
|
-
this.
|
|
39
|
+
this.onchain = router;
|
|
40
40
|
this.factory = factory;
|
|
41
41
|
this.lendingPools = {};
|
|
42
42
|
}
|
|
@@ -48,23 +48,23 @@ class ImpermaxFactory {
|
|
|
48
48
|
}
|
|
49
49
|
getSimpleUniswapOracle() {
|
|
50
50
|
if (!this.cache.simpleUniswapOracleContract) {
|
|
51
|
-
const address = simple_uniswap_oracles_1.SIMPLE_UNISWAP_ORACLE[this.
|
|
51
|
+
const address = simple_uniswap_oracles_1.SIMPLE_UNISWAP_ORACLE[this.onchain.network][this.factory];
|
|
52
52
|
if (!address) {
|
|
53
53
|
console.error("SimpleUniswapOracle address not found");
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
|
-
this.cache.simpleUniswapOracleContract = this.
|
|
56
|
+
this.cache.simpleUniswapOracleContract = this.onchain.contractsHelper.newSimpleUniswapOracle(address);
|
|
57
57
|
}
|
|
58
58
|
return this.cache.simpleUniswapOracleContract;
|
|
59
59
|
}
|
|
60
60
|
getRouter() {
|
|
61
61
|
if (!this.cache.routerContract) {
|
|
62
|
-
const address = routers_1.ROUTER[this.
|
|
62
|
+
const address = routers_1.ROUTER[this.onchain.network][this.factory];
|
|
63
63
|
if (!address) {
|
|
64
64
|
console.error("SimpleUniswapOracle address not found");
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
|
-
this.cache.routerContract = this.
|
|
67
|
+
this.cache.routerContract = this.onchain.contractsHelper.newRouter(address);
|
|
68
68
|
}
|
|
69
69
|
return this.cache.routerContract;
|
|
70
70
|
}
|
|
@@ -18,7 +18,7 @@ class Borrowable extends poolToken_1.default {
|
|
|
18
18
|
constructor(lendingPool, poolTokenType) {
|
|
19
19
|
super();
|
|
20
20
|
this.borrowableCache = {};
|
|
21
|
-
this.getContractHelper = () => this.lendingPool.factory.
|
|
21
|
+
this.getContractHelper = () => this.lendingPool.factory.onchain.contractsHelper;
|
|
22
22
|
// Impermax Chef
|
|
23
23
|
this.getImpermaxChef = () => this.getContractHelper().impermaxChef;
|
|
24
24
|
this.lendingPool = lendingPool;
|
|
@@ -17,7 +17,7 @@ class Collateral extends poolToken_1.default {
|
|
|
17
17
|
constructor(lendingPool, poolTokenType) {
|
|
18
18
|
super();
|
|
19
19
|
this.collateralCache = {};
|
|
20
|
-
this.getContractHelper = () => this.lendingPool.factory.
|
|
20
|
+
this.getContractHelper = () => this.lendingPool.factory.onchain.contractsHelper;
|
|
21
21
|
this.lendingPool = lendingPool;
|
|
22
22
|
this.poolTokenType = poolTokenType;
|
|
23
23
|
}
|
|
@@ -45,7 +45,7 @@ class LendingPool {
|
|
|
45
45
|
}
|
|
46
46
|
getOffchainLendingPool() {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
return this.factory.
|
|
48
|
+
return this.factory.onchain.offchain.getLendingPool(this.factory.factory, this.pairAddress);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
initializePoolTokenAddresses() {
|
|
@@ -86,7 +86,7 @@ class LendingPool {
|
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
if (!(yield this.getIsStakedLPToken()))
|
|
88
88
|
return null;
|
|
89
|
-
return this.factory.
|
|
89
|
+
return this.factory.onchain.contractsHelper.newStakedLPToken(this.pairAddress);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
getStakedLPToken() {
|
|
@@ -99,7 +99,7 @@ class LendingPool {
|
|
|
99
99
|
initializeUniswapV2Pair() {
|
|
100
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
101
|
const stakedLPToken = yield this.getStakedLPToken();
|
|
102
|
-
return this.factory.
|
|
102
|
+
return this.factory.onchain.contractsHelper.newUniswapV2Pair(stakedLPToken
|
|
103
103
|
? yield (stakedLPToken.methods.underlying().call())
|
|
104
104
|
: this.pairAddress);
|
|
105
105
|
});
|
|
@@ -179,7 +179,7 @@ class LendingPool {
|
|
|
179
179
|
getMarketPrice() {
|
|
180
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
181
|
const [reserve0, reserve1] = yield this.getReserves();
|
|
182
|
-
return this.factory.
|
|
182
|
+
return this.factory.onchain.priceInverted ? 1 * reserve0 / reserve1 : 1 * reserve1 / reserve0;
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
// TWAP Price
|
|
@@ -208,7 +208,7 @@ class LendingPool {
|
|
|
208
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
209
|
if (!this.cache.TWAPPrice)
|
|
210
210
|
this.cache.TWAPPrice = this.initializeTWAPPrice();
|
|
211
|
-
return !this.factory.
|
|
211
|
+
return !this.factory.onchain.priceInverted ? (yield this.cache.TWAPPrice) : 1 / (yield this.cache.TWAPPrice);
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
214
|
// Exchange rate
|
|
@@ -234,7 +234,7 @@ class LendingPool {
|
|
|
234
234
|
if (!stakedLPToken)
|
|
235
235
|
return null;
|
|
236
236
|
const rewardTokenAddress = yield stakedLPToken.methods.rewardsToken().call();
|
|
237
|
-
const rewardToken = this.factory.
|
|
237
|
+
const rewardToken = this.factory.onchain.contractsHelper.newERC20(rewardTokenAddress);
|
|
238
238
|
const decimals = yield rewardToken.methods.decimals().call();
|
|
239
239
|
let result = {
|
|
240
240
|
amount: 0,
|
|
@@ -247,7 +247,7 @@ class LendingPool {
|
|
|
247
247
|
catch (_a) {
|
|
248
248
|
try {
|
|
249
249
|
const stakingRewardsAddress = yield stakedLPToken.methods.stakingRewards().call();
|
|
250
|
-
const stakingRewards = this.factory.
|
|
250
|
+
const stakingRewards = this.factory.onchain.contractsHelper.newStakingRewards(stakingRewardsAddress);
|
|
251
251
|
const earned = yield stakingRewards.methods.earned(stakedLPToken._address).call();
|
|
252
252
|
result.amount = earned / Math.pow(10, decimals);
|
|
253
253
|
}
|
package/lib/onchain/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export default class Onchain {
|
|
|
17
17
|
contractsHelper: ContractsHelper;
|
|
18
18
|
factories: FactoryIndex<ImpermaxFactory>;
|
|
19
19
|
lendingVaults: AddressIndex<LendingVault>;
|
|
20
|
+
accounts: AddressIndex<Account>;
|
|
20
21
|
uiMargin: number;
|
|
21
22
|
dust: number;
|
|
22
23
|
priceInverted: boolean;
|
|
@@ -25,4 +26,5 @@ export default class Onchain {
|
|
|
25
26
|
setPriceInverted(priceInverted: boolean): void;
|
|
26
27
|
getFactory(factory: Factory): ImpermaxFactory;
|
|
27
28
|
getLendingVault(vaultAddress: Address): LendingVault;
|
|
29
|
+
getAccount(accountAddress: Address): Account;
|
|
28
30
|
}
|
package/lib/onchain/index.js
CHANGED
|
@@ -41,7 +41,6 @@ const lendingVault_1 = __importDefault(require("./lendingVault"));
|
|
|
41
41
|
exports.LendingVault = lendingVault_1.default;
|
|
42
42
|
const poolToken_1 = __importDefault(require("./poolToken"));
|
|
43
43
|
exports.PoolToken = poolToken_1.default;
|
|
44
|
-
const assert = require("assert");
|
|
45
44
|
class Onchain {
|
|
46
45
|
constructor(cfg) {
|
|
47
46
|
this.network = cfg.network;
|
|
@@ -53,6 +52,7 @@ class Onchain {
|
|
|
53
52
|
this.priceInverted = cfg.priceInverted ? cfg.priceInverted : false;
|
|
54
53
|
this.contractsHelper = new contractsHelper_1.default(this);
|
|
55
54
|
this.factories = {};
|
|
55
|
+
this.accounts = {};
|
|
56
56
|
}
|
|
57
57
|
cleanCache() {
|
|
58
58
|
for (const factory in this.factories) {
|
|
@@ -61,6 +61,9 @@ class Onchain {
|
|
|
61
61
|
for (const vaultAddress in this.lendingVaults) {
|
|
62
62
|
this.lendingVaults[vaultAddress].cleanCache();
|
|
63
63
|
}
|
|
64
|
+
for (const accountAddress in this.accounts) {
|
|
65
|
+
this.accounts[accountAddress].cleanCache();
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
setPriceInverted(priceInverted) {
|
|
66
69
|
this.priceInverted = priceInverted;
|
|
@@ -68,14 +71,17 @@ class Onchain {
|
|
|
68
71
|
getFactory(factory) {
|
|
69
72
|
if (!this.factories[factory])
|
|
70
73
|
this.factories[factory] = new impermaxFactory_1.default(this, factory);
|
|
71
|
-
|
|
72
|
-
assert(impermaxFactory);
|
|
73
|
-
return impermaxFactory;
|
|
74
|
+
return this.factories[factory];
|
|
74
75
|
}
|
|
75
76
|
getLendingVault(vaultAddress) {
|
|
76
77
|
if (!this.lendingVaults[vaultAddress])
|
|
77
78
|
this.lendingVaults[vaultAddress] = new lendingVault_1.default(this, vaultAddress);
|
|
78
79
|
return this.lendingVaults[vaultAddress];
|
|
79
80
|
}
|
|
81
|
+
getAccount(accountAddress) {
|
|
82
|
+
if (!this.accounts[accountAddress])
|
|
83
|
+
this.accounts[accountAddress] = new account_1.default(this, accountAddress);
|
|
84
|
+
return this.accounts[accountAddress];
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
exports.default = Onchain;
|