impermax-sdk 1.1.27 → 1.1.28
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/impermax-router/LendingPool.js +1 -1
- package/lib/impermax-router/LendingVault.js +1 -1
- package/lib/impermax-router/index.js +1 -1
- package/lib/offchain/Account.d.ts +2 -2
- package/lib/offchain/Account.js +5 -5
- package/lib/offchain/Borrowable.d.ts +1 -1
- package/lib/offchain/Borrowable.js +5 -5
- package/lib/offchain/Collateral.d.ts +1 -1
- package/lib/offchain/Collateral.js +1 -1
- package/lib/offchain/LendingPool.d.ts +2 -2
- package/lib/offchain/LendingPool.js +7 -7
- package/lib/offchain/LendingVault.d.ts +3 -3
- package/lib/offchain/LendingVault.js +3 -3
- package/lib/offchain/PoolToken.d.ts +1 -1
- package/lib/offchain/PoolToken.js +4 -4
- package/lib/offchain/PriceHelper.d.ts +3 -3
- package/lib/offchain/PriceHelper.js +24 -24
- package/lib/offchain/SolidexHelper.d.ts +2 -2
- package/lib/offchain/SolidexHelper.js +2 -2
- package/lib/on-chain/LendingPool.js +1 -1
- package/lib/on-chain/LendingVault.js +1 -1
- package/lib/on-chain/index.js +1 -1
- package/lib/onchain/AccountBorrowable.js +3 -3
- package/lib/onchain/AccountLendingPool.js +2 -2
- package/lib/onchain/AccountPoolToken.js +1 -1
- package/lib/onchain/Borrowable.d.ts +2 -2
- package/lib/onchain/Borrowable.js +2 -2
- package/lib/onchain/Collateral.d.ts +2 -2
- package/lib/onchain/Collateral.js +2 -2
- package/lib/onchain/LendingPool.d.ts +1 -1
- package/lib/onchain/LendingPool.js +2 -2
- package/lib/onchain/LendingVault.d.ts +1 -1
- package/lib/onchain/LendingVault.js +2 -2
- package/lib/onchain/PoolToken.d.ts +2 -2
- package/lib/onchain/PoolToken.js +4 -4
- package/lib/onchain/index.d.ts +1 -1
- package/lib/onchain/index.js +1 -1
- package/lib/onchain/types.d.ts +1 -1
- package/lib/subgraph/Account.js +3 -3
- package/lib/subgraph/Borrowable.js +4 -4
- package/lib/subgraph/LendingPool.js +5 -5
- package/lib/subgraph/PriceHelper.js +4 -4
- package/package.json +1 -1
|
@@ -42,7 +42,7 @@ class LendingPool {
|
|
|
42
42
|
}
|
|
43
43
|
getSubgraphLendingPool() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return this.factory.router.
|
|
45
|
+
return this.factory.router.offchain.getLendingPool(this.factory.factory, this.pairAddress);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
initializePoolTokenAddresses() {
|
|
@@ -32,7 +32,7 @@ class LendingVault extends PoolToken_1.default {
|
|
|
32
32
|
}
|
|
33
33
|
getSubgraphPoolToken() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
return yield this.router.
|
|
35
|
+
return yield this.router.offchain.getLendingVault(this.vaultAddress);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
initializePoolToken() {
|
|
@@ -9,7 +9,7 @@ const LendingVault_1 = __importDefault(require("./LendingVault"));
|
|
|
9
9
|
class ImpermaxRouter {
|
|
10
10
|
constructor(cfg) {
|
|
11
11
|
this.network = cfg.network;
|
|
12
|
-
this.subgraph = cfg.
|
|
12
|
+
this.subgraph = cfg.offchain;
|
|
13
13
|
this.web3 = cfg.web3;
|
|
14
14
|
this.chainId = cfg.chainId;
|
|
15
15
|
this.uiMargin = 1.1;
|
|
@@ -4,11 +4,11 @@ import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '
|
|
|
4
4
|
import { UserData } from './types';
|
|
5
5
|
import AccountLendingVault from './AccountLendingVault';
|
|
6
6
|
export default class Account {
|
|
7
|
-
|
|
7
|
+
offchain: Offchain;
|
|
8
8
|
account: Address;
|
|
9
9
|
accountLLPs: LendingPoolIndex<Promise<AccountLendingPool>>;
|
|
10
10
|
accountLVs: AddressIndex<Promise<AccountLendingVault>>;
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(offchain: Offchain, account: Address);
|
|
12
12
|
private initializeAccountLendingPool;
|
|
13
13
|
getAccountLendingPool(factory: Factory, pair: Address): Promise<AccountLendingPool>;
|
|
14
14
|
private initializeAccountLendingVault;
|
package/lib/offchain/Account.js
CHANGED
|
@@ -15,15 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const AccountLendingPool_1 = __importDefault(require("./AccountLendingPool"));
|
|
16
16
|
const AccountLendingVault_1 = __importDefault(require("./AccountLendingVault"));
|
|
17
17
|
class Account {
|
|
18
|
-
constructor(
|
|
19
|
-
this.
|
|
18
|
+
constructor(offchain, account) {
|
|
19
|
+
this.offchain = offchain;
|
|
20
20
|
this.account = account;
|
|
21
21
|
this.accountLLPs = {};
|
|
22
22
|
this.accountLVs = {};
|
|
23
23
|
}
|
|
24
24
|
initializeAccountLendingPool(factory, pair) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const lendingPool = yield this.
|
|
26
|
+
const lendingPool = yield this.offchain.getLendingPool(factory, pair);
|
|
27
27
|
return new AccountLendingPool_1.default(this, lendingPool);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -38,7 +38,7 @@ class Account {
|
|
|
38
38
|
}
|
|
39
39
|
initializeAccountLendingVault(vaultAddress) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const lendingVault = yield this.
|
|
41
|
+
const lendingVault = yield this.offchain.getLendingVault(vaultAddress);
|
|
42
42
|
return new AccountLendingVault_1.default(this, lendingVault);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -51,7 +51,7 @@ class Account {
|
|
|
51
51
|
}
|
|
52
52
|
getUserData() {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return this.
|
|
54
|
+
return this.offchain.getUserData(this.account);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
getBorrowPositions() {
|
|
@@ -6,7 +6,7 @@ export default class Borrowable extends PoolToken {
|
|
|
6
6
|
lendingPool: LendingPool;
|
|
7
7
|
poolTokenType: PoolTokenType;
|
|
8
8
|
constructor(lendingPool: LendingPool, poolTokenType: PoolTokenType);
|
|
9
|
-
|
|
9
|
+
getOffchain: () => import(".").default;
|
|
10
10
|
getPoolTokenData(): Promise<PoolTokenData>;
|
|
11
11
|
getReserveFactor(): Promise<number>;
|
|
12
12
|
getKinkBorrowRate(): Promise<number>;
|
|
@@ -18,7 +18,7 @@ const imxes_1 = require("../config/contracts/imxes");
|
|
|
18
18
|
class Borrowable extends PoolToken_1.default {
|
|
19
19
|
constructor(lendingPool, poolTokenType) {
|
|
20
20
|
super();
|
|
21
|
-
this.
|
|
21
|
+
this.getOffchain = () => this.lendingPool.offchain;
|
|
22
22
|
this.lendingPool = lendingPool;
|
|
23
23
|
this.poolTokenType = poolTokenType;
|
|
24
24
|
}
|
|
@@ -199,7 +199,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
199
199
|
return [];
|
|
200
200
|
}
|
|
201
201
|
return [{
|
|
202
|
-
rewardToken: imxes_1.IMX[this.lendingPool.
|
|
202
|
+
rewardToken: imxes_1.IMX[this.lendingPool.offchain.network],
|
|
203
203
|
rewardRate: epochAmount / segmentLength
|
|
204
204
|
}];
|
|
205
205
|
});
|
|
@@ -221,7 +221,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
221
221
|
return [];
|
|
222
222
|
const rewards = [];
|
|
223
223
|
for (const reward of farmingRewards) {
|
|
224
|
-
const rewardPrice = yield this.lendingPool.
|
|
224
|
+
const rewardPrice = yield this.lendingPool.offchain.priceHelper.getDebankTokenPrice(reward.rewardToken);
|
|
225
225
|
rewards.push({
|
|
226
226
|
APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
|
|
227
227
|
symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
|
|
@@ -334,7 +334,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
334
334
|
});
|
|
335
335
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
336
|
let tokenAddress = yield this.getUnderlyingAddress();
|
|
337
|
-
let tokenPrices = yield this.lendingPool.
|
|
337
|
+
let tokenPrices = yield this.lendingPool.offchain.priceHelper.getSubgraphTokenPrice();
|
|
338
338
|
let tokenPrice = tokenPrices[tokenAddress];
|
|
339
339
|
if (tokenPrice > 0)
|
|
340
340
|
return tokenPrice;
|
|
@@ -344,7 +344,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
344
344
|
getTokenPriceAccurate() {
|
|
345
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
346
346
|
let tokenAddress = yield this.getUnderlyingAddress();
|
|
347
|
-
return this.lendingPool.
|
|
347
|
+
return this.lendingPool.offchain.priceHelper.getDebankTokenPrice(tokenAddress);
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
}
|
|
@@ -6,7 +6,7 @@ export default class Collateral extends PoolToken {
|
|
|
6
6
|
lendingPool: LendingPool;
|
|
7
7
|
poolTokenType: PoolTokenType;
|
|
8
8
|
constructor(lendingPool: LendingPool, poolTokenType: PoolTokenType);
|
|
9
|
-
|
|
9
|
+
getOffchain: () => import(".").default;
|
|
10
10
|
getPoolTokenData(): Promise<PoolTokenData>;
|
|
11
11
|
getName(): Promise<string>;
|
|
12
12
|
getSymbol(): Promise<string>;
|
|
@@ -17,7 +17,7 @@ const types_1 = require("../config/types");
|
|
|
17
17
|
class Collateral extends PoolToken_1.default {
|
|
18
18
|
constructor(lendingPool, poolTokenType) {
|
|
19
19
|
super();
|
|
20
|
-
this.
|
|
20
|
+
this.getOffchain = () => this.lendingPool.offchain;
|
|
21
21
|
this.lendingPool = lendingPool;
|
|
22
22
|
this.poolTokenType = poolTokenType;
|
|
23
23
|
}
|
|
@@ -7,7 +7,7 @@ import { LendingPoolData, LendingPoolPastData } from './types';
|
|
|
7
7
|
import Collateral from './Collateral';
|
|
8
8
|
import Borrowable from './Borrowable';
|
|
9
9
|
export default class LendingPool {
|
|
10
|
-
|
|
10
|
+
offchain: Offchain;
|
|
11
11
|
factory: Factory;
|
|
12
12
|
pairAddress: Address;
|
|
13
13
|
poolTokens: {
|
|
@@ -15,7 +15,7 @@ export default class LendingPool {
|
|
|
15
15
|
[PoolTokenType.BorrowableA]?: Borrowable;
|
|
16
16
|
[PoolTokenType.BorrowableB]?: Borrowable;
|
|
17
17
|
};
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(offchain: Offchain, factory: Factory, pairAddress: Address);
|
|
19
19
|
getPoolToken(poolTokenType: PoolTokenType): PoolToken;
|
|
20
20
|
getLendingPoolData(): Promise<LendingPoolData>;
|
|
21
21
|
getSafetyMargin(): Promise<number>;
|
|
@@ -20,8 +20,8 @@ const farms_1 = require("../config/farms");
|
|
|
20
20
|
const Collateral_1 = __importDefault(require("./Collateral"));
|
|
21
21
|
const Borrowable_1 = __importDefault(require("./Borrowable"));
|
|
22
22
|
class LendingPool {
|
|
23
|
-
constructor(
|
|
24
|
-
this.
|
|
23
|
+
constructor(offchain, factory, pairAddress) {
|
|
24
|
+
this.offchain = offchain;
|
|
25
25
|
this.factory = factory;
|
|
26
26
|
this.pairAddress = pairAddress;
|
|
27
27
|
this.poolTokens = {};
|
|
@@ -35,7 +35,7 @@ class LendingPool {
|
|
|
35
35
|
// Offchain calls
|
|
36
36
|
getLendingPoolData() {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
return this.
|
|
38
|
+
return this.offchain.getLendingPoolData(this.factory, this.pairAddress);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
// Safety Margin
|
|
@@ -89,7 +89,7 @@ class LendingPool {
|
|
|
89
89
|
const farm = yield this.getFarm();
|
|
90
90
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
91
91
|
if (farm === farms_1.Farms.solidex || farm === farms_1.Farms.solidexB || farm === farms_1.Farms.solidexUSDC || farm === farms_1.Farms.solidexUSDCB) {
|
|
92
|
-
const solidexLPDetails = yield this.
|
|
92
|
+
const solidexLPDetails = yield this.offchain.solidexHelper.getSolidexLPDetails();
|
|
93
93
|
const result = solidexLPDetails[lendingPoolData.pair.uniswapV2PairAddress];
|
|
94
94
|
if (result)
|
|
95
95
|
return result;
|
|
@@ -106,7 +106,7 @@ class LendingPool {
|
|
|
106
106
|
let rewardRate = parseFloat(reward.rewardRate);
|
|
107
107
|
if (farm == farms_1.Farms.traderJoeV4)
|
|
108
108
|
rewardRate = rewardRate * 0.45;
|
|
109
|
-
const rewardPrice = yield this.
|
|
109
|
+
const rewardPrice = yield this.offchain.priceHelper.getDebankTokenPrice(reward.rewardsToken.id);
|
|
110
110
|
rewards.push({
|
|
111
111
|
APR: (0, utils_1.toAPR)((rewardPrice * rewardRate) / (stakedTotalSupply * underlyingLPPrice) * multiplier),
|
|
112
112
|
symbol: reward.rewardsToken.symbol,
|
|
@@ -153,13 +153,13 @@ class LendingPool {
|
|
|
153
153
|
getAmm() {
|
|
154
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
155
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
156
|
-
return (0, amms_1.getAmmByFactory)(this.
|
|
156
|
+
return (0, amms_1.getAmmByFactory)(this.offchain.network, lendingPoolData.pair.uniswapV2Factory);
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
getFarm() {
|
|
160
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
161
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
162
|
-
return (0, farms_1.getFarmByStakedLPFactory)(this.
|
|
162
|
+
return (0, farms_1.getFarmByStakedLPFactory)(this.offchain.network, lendingPoolData.pair.factory);
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
// getCollateralPrice -> returns the price of the collateral, not necessarily of the underlying LP
|
|
@@ -3,10 +3,10 @@ import { Address } from '../config/types';
|
|
|
3
3
|
import PoolToken from './PoolToken';
|
|
4
4
|
import { PoolTokenData } from './types';
|
|
5
5
|
export default class LendingVault extends PoolToken {
|
|
6
|
-
|
|
6
|
+
offchain: Offchain;
|
|
7
7
|
vaultAddress: Address;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
8
|
+
constructor(offchain: Offchain, vaultAddress: Address);
|
|
9
|
+
getOffchain: () => Offchain;
|
|
10
10
|
getPoolTokenData(): Promise<PoolTokenData>;
|
|
11
11
|
getAccrualTimestamp(): Promise<number>;
|
|
12
12
|
getVaultSupply(): Promise<number>;
|
|
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const PoolToken_1 = __importDefault(require("./PoolToken"));
|
|
16
16
|
class LendingVault extends PoolToken_1.default {
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(offchain, vaultAddress) {
|
|
18
18
|
super();
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
19
|
+
this.getOffchain = () => this.offchain;
|
|
20
|
+
this.offchain = offchain;
|
|
21
21
|
this.vaultAddress = vaultAddress;
|
|
22
22
|
}
|
|
23
23
|
getPoolTokenData() {
|
|
@@ -2,7 +2,7 @@ import { Address } from '../config/types';
|
|
|
2
2
|
import { PoolTokenData } from './types';
|
|
3
3
|
import Offchain from './index';
|
|
4
4
|
export default abstract class PoolToken {
|
|
5
|
-
abstract
|
|
5
|
+
abstract getOffchain(): Offchain;
|
|
6
6
|
abstract getPoolTokenData(): Promise<PoolTokenData>;
|
|
7
7
|
protected getPoolTokenParam(param: string): Promise<string>;
|
|
8
8
|
protected getPoolTokenParamFloat(param: string): Promise<number>;
|
|
@@ -34,8 +34,8 @@ class PoolToken {
|
|
|
34
34
|
getName() {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
const underlying = yield this.getUnderlyingAddress();
|
|
37
|
-
if (underlying.toLowerCase() === weths_1.WETH[this.
|
|
38
|
-
return eth_1.ETH_NAME[this.
|
|
37
|
+
if (underlying.toLowerCase() === weths_1.WETH[this.getOffchain().network].toLowerCase())
|
|
38
|
+
return eth_1.ETH_NAME[this.getOffchain().network];
|
|
39
39
|
if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
|
|
40
40
|
return "MIMATIC";
|
|
41
41
|
if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
|
|
@@ -47,8 +47,8 @@ class PoolToken {
|
|
|
47
47
|
getSymbol() {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
49
|
const underlying = yield this.getUnderlyingAddress();
|
|
50
|
-
if (underlying.toLowerCase() === weths_1.WETH[this.
|
|
51
|
-
return eth_1.ETH_SYMBOL[this.
|
|
50
|
+
if (underlying.toLowerCase() === weths_1.WETH[this.getOffchain().network].toLowerCase())
|
|
51
|
+
return eth_1.ETH_SYMBOL[this.getOffchain().network];
|
|
52
52
|
if (underlying.toLowerCase() === "0xa3fa99a148fa48d14ed51d610c367c61876997f1")
|
|
53
53
|
return "MAI";
|
|
54
54
|
if (underlying.toLowerCase() === "0x2e9a6df78e42a30712c10a9dc4b1c8656f8f2879")
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Offchain from "./index";
|
|
2
2
|
import { Address } from '../config/types';
|
|
3
3
|
export default class PriceHelper {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
offchain: Offchain;
|
|
5
|
+
offchainTokenPrice: Promise<{
|
|
6
6
|
[key in Address]?: number;
|
|
7
7
|
}>;
|
|
8
8
|
debankTokenPrice: {
|
|
9
9
|
[key in Address]?: Promise<number>;
|
|
10
10
|
};
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(offchain: Offchain);
|
|
12
12
|
cleanCache(): void;
|
|
13
13
|
private addPriceIfMissing;
|
|
14
14
|
private initializeSubgraphTokenPrice;
|
|
@@ -30,49 +30,49 @@ const coingecko_ids = {
|
|
|
30
30
|
"0x5756a28e2aae01f600fc2c01358395f5c1f8ad3a": "vesync",
|
|
31
31
|
};
|
|
32
32
|
class PriceHelper {
|
|
33
|
-
constructor(
|
|
34
|
-
this.
|
|
33
|
+
constructor(offchain) {
|
|
34
|
+
this.offchain = offchain;
|
|
35
35
|
this.debankTokenPrice = {};
|
|
36
36
|
}
|
|
37
37
|
cleanCache() {
|
|
38
|
-
this.
|
|
38
|
+
this.offchainTokenPrice = null;
|
|
39
39
|
this.debankTokenPrice = {};
|
|
40
40
|
}
|
|
41
41
|
// First source of token price: Offchain (less accurate, faster)
|
|
42
|
-
addPriceIfMissing(
|
|
43
|
-
if (
|
|
42
|
+
addPriceIfMissing(offchainTokenPrice, token) {
|
|
43
|
+
if (offchainTokenPrice[token.id])
|
|
44
44
|
return;
|
|
45
|
-
|
|
45
|
+
offchainTokenPrice[token.id] = parseFloat(token.derivedUSD);
|
|
46
46
|
}
|
|
47
47
|
initializeSubgraphTokenPrice() {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const lendingPoolsData = yield this.
|
|
50
|
-
const
|
|
49
|
+
const lendingPoolsData = yield this.offchain.getLendingPoolsData();
|
|
50
|
+
const offchainTokenPrice = {};
|
|
51
51
|
for (const factory of Object.keys(lendingPoolsData)) {
|
|
52
52
|
for (const id of Object.keys(lendingPoolsData[factory])) {
|
|
53
53
|
const lendingPool = lendingPoolsData[factory][id];
|
|
54
|
-
this.addPriceIfMissing(
|
|
55
|
-
this.addPriceIfMissing(
|
|
54
|
+
this.addPriceIfMissing(offchainTokenPrice, lendingPool.borrowable0.underlying);
|
|
55
|
+
this.addPriceIfMissing(offchainTokenPrice, lendingPool.borrowable1.underlying);
|
|
56
56
|
for (const reward of lendingPool.pair.rewards) {
|
|
57
|
-
this.addPriceIfMissing(
|
|
57
|
+
this.addPriceIfMissing(offchainTokenPrice, reward.rewardsToken);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
//fix for IMX
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
62
|
+
offchainTokenPrice["0x9c67ee39e3c4954396b9142010653f17257dd39c"] = 0;
|
|
63
|
+
offchainTokenPrice["0x7b35ce522cb72e4077baeb96cb923a5529764a00"] = 0;
|
|
64
|
+
offchainTokenPrice["0xea6887e4a9cda1b77e70129e5fba830cdb5cddef"] = 0;
|
|
65
|
+
offchainTokenPrice["0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05"] = 0;
|
|
66
|
+
offchainTokenPrice["0x900f1ec5819fa087d368877cd03b265bf1802667"] = 0;
|
|
67
|
+
offchainTokenPrice["0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2"] = 0;
|
|
68
|
+
return offchainTokenPrice;
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
getSubgraphTokenPrice() {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
if (!this.
|
|
74
|
-
this.
|
|
75
|
-
return this.
|
|
73
|
+
if (!this.offchainTokenPrice)
|
|
74
|
+
this.offchainTokenPrice = this.initializeSubgraphTokenPrice();
|
|
75
|
+
return this.offchainTokenPrice;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
// Second source of token price: Debank (more accurate, slower)
|
|
@@ -101,9 +101,9 @@ class PriceHelper {
|
|
|
101
101
|
return result;
|
|
102
102
|
}
|
|
103
103
|
try {
|
|
104
|
-
const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.
|
|
104
|
+
const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.offchain.network] + "&id=" + tokenAddress);
|
|
105
105
|
/*const response = await fetch(
|
|
106
|
-
"https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.
|
|
106
|
+
"https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.offchain.network] + "&id=" + tokenAddress,
|
|
107
107
|
{headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
|
|
108
108
|
);*/
|
|
109
109
|
if (response.status != 200)
|
|
@@ -183,7 +183,7 @@ class PriceHelper {
|
|
|
183
183
|
if (tokenAddress.toLowerCase() === '0x1c28edf9e0d66f3124f141a3cf3ef1217f7019c4') { // fix for SLNA
|
|
184
184
|
return 0.00045;
|
|
185
185
|
}
|
|
186
|
-
// try fallback on
|
|
186
|
+
// try fallback on offchain
|
|
187
187
|
const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
|
|
188
188
|
return subgraphTokenPrice[tokenAddress] ? subgraphTokenPrice[tokenAddress] : 0;
|
|
189
189
|
}
|
|
@@ -7,9 +7,9 @@ export type SolidexLPDetails = {
|
|
|
7
7
|
}>;
|
|
8
8
|
};
|
|
9
9
|
export default class SolidexHelper {
|
|
10
|
-
|
|
10
|
+
offchain: Offchain;
|
|
11
11
|
solidexLPDetails: Promise<SolidexLPDetails>;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(offchain: Offchain);
|
|
13
13
|
cleanCache(): void;
|
|
14
14
|
private initializeSolidexLPDetails;
|
|
15
15
|
getSolidexLPDetails(): Promise<SolidexLPDetails>;
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
class SolidexHelper {
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
13
|
+
constructor(offchain) {
|
|
14
|
+
this.offchain = offchain;
|
|
15
15
|
}
|
|
16
16
|
cleanCache() {
|
|
17
17
|
this.solidexLPDetails = null;
|
|
@@ -42,7 +42,7 @@ class LendingPool {
|
|
|
42
42
|
}
|
|
43
43
|
getSubgraphLendingPool() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return this.factory.router.
|
|
45
|
+
return this.factory.router.offchain.getLendingPool(this.factory.factory, this.pairAddress);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
initializePoolTokenAddresses() {
|
|
@@ -32,7 +32,7 @@ class LendingVault extends PoolToken_1.default {
|
|
|
32
32
|
}
|
|
33
33
|
getSubgraphPoolToken() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
return yield this.router.
|
|
35
|
+
return yield this.router.offchain.getLendingVault(this.vaultAddress);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
initializePoolToken() {
|
package/lib/on-chain/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const LendingVault_1 = __importDefault(require("./LendingVault"));
|
|
|
9
9
|
class OnChain {
|
|
10
10
|
constructor(cfg) {
|
|
11
11
|
this.network = cfg.network;
|
|
12
|
-
this.subgraph = cfg.
|
|
12
|
+
this.subgraph = cfg.offchain;
|
|
13
13
|
this.web3 = cfg.web3;
|
|
14
14
|
this.chainId = cfg.chainId;
|
|
15
15
|
this.uiMargin = 1.1;
|
|
@@ -20,9 +20,9 @@ class AccountBorrowable extends AccountPoolToken_1.default {
|
|
|
20
20
|
super();
|
|
21
21
|
this.borrowableCache = {};
|
|
22
22
|
// Shortcuts
|
|
23
|
-
this.getSupplyAPR = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.
|
|
24
|
-
this.getBorrowRate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.
|
|
25
|
-
this.getAccrualTimestamp = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.
|
|
23
|
+
this.getSupplyAPR = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getOffchainPoolToken()).getSupplyAPR(); });
|
|
24
|
+
this.getBorrowRate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getOffchainPoolToken()).getBorrowRate(); });
|
|
25
|
+
this.getAccrualTimestamp = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getOffchainPoolToken()).getAccrualTimestamp(); });
|
|
26
26
|
this.accountLendingPool = accountLendingPool;
|
|
27
27
|
this.account = accountLendingPool.account;
|
|
28
28
|
this.poolToken = accountLendingPool.lendingPool.poolTokens[poolTokenType];
|
|
@@ -23,8 +23,8 @@ class AccountLendingPool {
|
|
|
23
23
|
this.pta = () => this.accountPoolTokens[types_2.PoolTokenType.BorrowableA];
|
|
24
24
|
this.ptb = () => this.accountPoolTokens[types_2.PoolTokenType.BorrowableB];
|
|
25
25
|
this.ptc = () => this.accountPoolTokens[types_2.PoolTokenType.Collateral];
|
|
26
|
-
this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.
|
|
27
|
-
this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.
|
|
26
|
+
this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getOffchainLendingPool()).getSafetyMargin(); });
|
|
27
|
+
this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getOffchainLendingPool()).getLiquidationPenalty(); });
|
|
28
28
|
this.getUiMargin = () => this.account.router.uiMargin;
|
|
29
29
|
this.account = account;
|
|
30
30
|
this.lendingPool = lendingPool;
|
|
@@ -19,7 +19,7 @@ class AccountPoolToken {
|
|
|
19
19
|
this.getEth = () => this.account.router.web3.eth;
|
|
20
20
|
this.getDust = () => this.account.router.dust;
|
|
21
21
|
this.getUiMargin = () => this.account.router.uiMargin;
|
|
22
|
-
this.getTokenPriceAccurate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.
|
|
22
|
+
this.getTokenPriceAccurate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getOffchainPoolToken()).getTokenPriceAccurate(); });
|
|
23
23
|
}
|
|
24
24
|
cleanCache() {
|
|
25
25
|
this.cache = {};
|
|
@@ -2,7 +2,7 @@ import { Contract } from "./types";
|
|
|
2
2
|
import PoolToken from "./PoolToken";
|
|
3
3
|
import { Address, PoolTokenType } from '../config/types';
|
|
4
4
|
import LendingPool from './LendingPool';
|
|
5
|
-
import
|
|
5
|
+
import OffchainBorrowable from '../offchain/Borrowable';
|
|
6
6
|
export default class Borrowable extends PoolToken {
|
|
7
7
|
lendingPool: LendingPool;
|
|
8
8
|
borrowableCache: {
|
|
@@ -16,7 +16,7 @@ export default class Borrowable extends PoolToken {
|
|
|
16
16
|
cleanCache(): void;
|
|
17
17
|
getContractHelper: () => import("./ContractsHelper").default;
|
|
18
18
|
getPoolTokenAddress(): Promise<Address>;
|
|
19
|
-
|
|
19
|
+
getOffchainPoolToken(): Promise<OffchainBorrowable>;
|
|
20
20
|
initializePoolToken(): Promise<Contract>;
|
|
21
21
|
initializeToken(): Promise<Contract>;
|
|
22
22
|
getPriceDenomLP(): Promise<number>;
|
|
@@ -33,9 +33,9 @@ class Borrowable extends PoolToken_1.default {
|
|
|
33
33
|
return (yield this.lendingPool.getPoolTokenAddresses())[this.poolTokenType];
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
getOffchainPoolToken() {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const lendingPool = yield this.lendingPool.
|
|
38
|
+
const lendingPool = yield this.lendingPool.getOffchainLendingPool();
|
|
39
39
|
return lendingPool.poolTokens[this.poolTokenType];
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -2,7 +2,7 @@ import { Contract } from "./types";
|
|
|
2
2
|
import PoolToken from "./PoolToken";
|
|
3
3
|
import LendingPool from './LendingPool';
|
|
4
4
|
import { Address, PoolTokenType } from '../config/types';
|
|
5
|
-
import
|
|
5
|
+
import OffchainCollateral from '../offchain/Collateral';
|
|
6
6
|
export default class Collateral extends PoolToken {
|
|
7
7
|
lendingPool: LendingPool;
|
|
8
8
|
collateralCache: {};
|
|
@@ -10,7 +10,7 @@ export default class Collateral extends PoolToken {
|
|
|
10
10
|
cleanCache(): void;
|
|
11
11
|
getContractHelper: () => import("./ContractsHelper").default;
|
|
12
12
|
getPoolTokenAddress(): Promise<Address>;
|
|
13
|
-
|
|
13
|
+
getOffchainPoolToken(): Promise<OffchainCollateral>;
|
|
14
14
|
initializePoolToken(): Promise<Contract>;
|
|
15
15
|
initializeToken(): Promise<Contract>;
|
|
16
16
|
protected initializeExchangeRate(): Promise<number>;
|
|
@@ -30,9 +30,9 @@ class Collateral extends PoolToken_1.default {
|
|
|
30
30
|
return (yield this.lendingPool.getPoolTokenAddresses())[this.poolTokenType];
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
getOffchainPoolToken() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const lendingPool = yield this.lendingPool.
|
|
35
|
+
const lendingPool = yield this.lendingPool.getOffchainLendingPool();
|
|
36
36
|
return lendingPool.poolTokens[this.poolTokenType];
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -35,7 +35,7 @@ export default class LendingPool {
|
|
|
35
35
|
ptb: () => Borrowable;
|
|
36
36
|
ptc: () => Collateral;
|
|
37
37
|
getPoolToken(poolTokenType: PoolTokenType): PoolToken;
|
|
38
|
-
|
|
38
|
+
getOffchainLendingPool(): Promise<import("..").OffchainLendingPool>;
|
|
39
39
|
private initializePoolTokenAddresses;
|
|
40
40
|
getPoolTokenAddresses(): Promise<{
|
|
41
41
|
collateral: string;
|
|
@@ -40,9 +40,9 @@ class LendingPool {
|
|
|
40
40
|
getPoolToken(poolTokenType) {
|
|
41
41
|
return this.poolTokens[poolTokenType];
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
getOffchainLendingPool() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return this.factory.router.
|
|
45
|
+
return this.factory.router.offchain.getLendingPool(this.factory.factory, this.pairAddress);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
initializePoolTokenAddresses() {
|
|
@@ -10,7 +10,7 @@ export default class LendingVault extends PoolToken {
|
|
|
10
10
|
cleanCache(): void;
|
|
11
11
|
getContractHelper: () => import("./ContractsHelper").default;
|
|
12
12
|
getPoolTokenAddress(): Promise<Address>;
|
|
13
|
-
|
|
13
|
+
getOffchainPoolToken(): Promise<import("..").OffchainLendingVault>;
|
|
14
14
|
initializePoolToken(): Promise<Contract>;
|
|
15
15
|
initializeToken(): Promise<Contract>;
|
|
16
16
|
getAvailableLiquidity(): Promise<number>;
|
|
@@ -30,9 +30,9 @@ class LendingVault extends PoolToken_1.default {
|
|
|
30
30
|
return this.vaultAddress;
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
getOffchainPoolToken() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
return yield this.router.
|
|
35
|
+
return yield this.router.offchain.getLendingVault(this.vaultAddress);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
initializePoolToken() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
import { Contract } from "./types";
|
|
3
3
|
import { Address, PoolTokenType } from '../config/types';
|
|
4
|
-
import
|
|
4
|
+
import OffchainPoolToken from '../offchain/PoolToken';
|
|
5
5
|
export default abstract class PoolToken {
|
|
6
6
|
poolTokenType: PoolTokenType;
|
|
7
7
|
cache: {
|
|
@@ -11,7 +11,7 @@ export default abstract class PoolToken {
|
|
|
11
11
|
totalBalance?: Promise<number>;
|
|
12
12
|
};
|
|
13
13
|
cleanCache(): void;
|
|
14
|
-
abstract
|
|
14
|
+
abstract getOffchainPoolToken(): Promise<OffchainPoolToken>;
|
|
15
15
|
abstract getPoolTokenAddress(): Promise<Address>;
|
|
16
16
|
abstract initializePoolToken(): Promise<Contract>;
|
|
17
17
|
getPoolToken(): Promise<any>;
|
package/lib/onchain/PoolToken.js
CHANGED
|
@@ -39,8 +39,8 @@ class PoolToken {
|
|
|
39
39
|
}
|
|
40
40
|
getDecimals() {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const
|
|
43
|
-
return yield
|
|
42
|
+
const offchainPoolToken = yield this.getOffchainPoolToken();
|
|
43
|
+
return yield offchainPoolToken.getDecimals();
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
// Utilities
|
|
@@ -97,8 +97,8 @@ class PoolToken {
|
|
|
97
97
|
getTotalBalanceUSD() {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
99
|
const totalBalance = yield this.getTotalBalance();
|
|
100
|
-
const
|
|
101
|
-
const tokenPrice = yield
|
|
100
|
+
const offchainPoolToken = yield this.getOffchainPoolToken();
|
|
101
|
+
const tokenPrice = yield offchainPoolToken.getTokenPriceFast();
|
|
102
102
|
return totalBalance * tokenPrice;
|
|
103
103
|
});
|
|
104
104
|
}
|
package/lib/onchain/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Address, AddressIndex, Factory, FactoryIndex, Networks } from '../confi
|
|
|
6
6
|
import LendingVault from './LendingVault';
|
|
7
7
|
export default class Onchain {
|
|
8
8
|
network: Networks;
|
|
9
|
-
|
|
9
|
+
offchain: Offchain;
|
|
10
10
|
web3: any;
|
|
11
11
|
chainId: number;
|
|
12
12
|
contractsHelper: ContractsHelper;
|
package/lib/onchain/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const LendingVault_1 = __importDefault(require("./LendingVault"));
|
|
|
9
9
|
class Onchain {
|
|
10
10
|
constructor(cfg) {
|
|
11
11
|
this.network = cfg.network;
|
|
12
|
-
this.
|
|
12
|
+
this.offchain = cfg.offchain;
|
|
13
13
|
this.web3 = cfg.web3;
|
|
14
14
|
this.chainId = cfg.chainId;
|
|
15
15
|
this.uiMargin = 1.1;
|
package/lib/onchain/types.d.ts
CHANGED
package/lib/subgraph/Account.js
CHANGED
|
@@ -23,7 +23,7 @@ class Account {
|
|
|
23
23
|
}
|
|
24
24
|
initializeAccountLendingPool(factory, pair) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const lendingPool = yield this.
|
|
26
|
+
const lendingPool = yield this.offchain.getLendingPool(factory, pair);
|
|
27
27
|
return new AccountLendingPool_1.default(this, lendingPool);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -38,7 +38,7 @@ class Account {
|
|
|
38
38
|
}
|
|
39
39
|
initializeAccountLendingVault(vaultAddress) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const lendingVault = yield this.
|
|
41
|
+
const lendingVault = yield this.offchain.getLendingVault(vaultAddress);
|
|
42
42
|
return new AccountLendingVault_1.default(this, lendingVault);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -51,7 +51,7 @@ class Account {
|
|
|
51
51
|
}
|
|
52
52
|
getUserData() {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return this.
|
|
54
|
+
return this.offchain.getUserData(this.account);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
getBorrowPositions() {
|
|
@@ -199,7 +199,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
199
199
|
return [];
|
|
200
200
|
}
|
|
201
201
|
return [{
|
|
202
|
-
rewardToken: imxes_1.IMX[this.lendingPool.
|
|
202
|
+
rewardToken: imxes_1.IMX[this.lendingPool.offchain.network],
|
|
203
203
|
rewardRate: epochAmount / segmentLength
|
|
204
204
|
}];
|
|
205
205
|
});
|
|
@@ -221,7 +221,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
221
221
|
return [];
|
|
222
222
|
const rewards = [];
|
|
223
223
|
for (const reward of farmingRewards) {
|
|
224
|
-
const rewardPrice = yield this.lendingPool.
|
|
224
|
+
const rewardPrice = yield this.lendingPool.offchain.priceHelper.getDebankTokenPrice(reward.rewardToken);
|
|
225
225
|
rewards.push({
|
|
226
226
|
APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
|
|
227
227
|
symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
|
|
@@ -334,7 +334,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
334
334
|
});
|
|
335
335
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
336
|
let tokenAddress = yield this.getUnderlyingAddress();
|
|
337
|
-
let tokenPrices = yield this.lendingPool.
|
|
337
|
+
let tokenPrices = yield this.lendingPool.offchain.priceHelper.getSubgraphTokenPrice();
|
|
338
338
|
let tokenPrice = tokenPrices[tokenAddress];
|
|
339
339
|
if (tokenPrice > 0)
|
|
340
340
|
return tokenPrice;
|
|
@@ -344,7 +344,7 @@ class Borrowable extends PoolToken_1.default {
|
|
|
344
344
|
getTokenPriceAccurate() {
|
|
345
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
346
346
|
let tokenAddress = yield this.getUnderlyingAddress();
|
|
347
|
-
return this.lendingPool.
|
|
347
|
+
return this.lendingPool.offchain.priceHelper.getDebankTokenPrice(tokenAddress);
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
}
|
|
@@ -35,7 +35,7 @@ class LendingPool {
|
|
|
35
35
|
// Offchain calls
|
|
36
36
|
getLendingPoolData() {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
return this.
|
|
38
|
+
return this.offchain.getLendingPoolData(this.factory, this.pairAddress);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
// Safety Margin
|
|
@@ -89,7 +89,7 @@ class LendingPool {
|
|
|
89
89
|
const farm = yield this.getFarm();
|
|
90
90
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
91
91
|
if (farm === farms_1.Farms.solidex || farm === farms_1.Farms.solidexB || farm === farms_1.Farms.solidexUSDC || farm === farms_1.Farms.solidexUSDCB) {
|
|
92
|
-
const solidexLPDetails = yield this.
|
|
92
|
+
const solidexLPDetails = yield this.offchain.solidexHelper.getSolidexLPDetails();
|
|
93
93
|
const result = solidexLPDetails[lendingPoolData.pair.uniswapV2PairAddress];
|
|
94
94
|
if (result)
|
|
95
95
|
return result;
|
|
@@ -106,7 +106,7 @@ class LendingPool {
|
|
|
106
106
|
let rewardRate = parseFloat(reward.rewardRate);
|
|
107
107
|
if (farm == farms_1.Farms.traderJoeV4)
|
|
108
108
|
rewardRate = rewardRate * 0.45;
|
|
109
|
-
const rewardPrice = yield this.
|
|
109
|
+
const rewardPrice = yield this.offchain.priceHelper.getDebankTokenPrice(reward.rewardsToken.id);
|
|
110
110
|
rewards.push({
|
|
111
111
|
APR: (0, utils_1.toAPR)((rewardPrice * rewardRate) / (stakedTotalSupply * underlyingLPPrice) * multiplier),
|
|
112
112
|
symbol: reward.rewardsToken.symbol,
|
|
@@ -153,13 +153,13 @@ class LendingPool {
|
|
|
153
153
|
getAmm() {
|
|
154
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
155
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
156
|
-
return (0, amms_1.getAmmByFactory)(this.
|
|
156
|
+
return (0, amms_1.getAmmByFactory)(this.offchain.network, lendingPoolData.pair.uniswapV2Factory);
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
getFarm() {
|
|
160
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
161
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
162
|
-
return (0, farms_1.getFarmByStakedLPFactory)(this.
|
|
162
|
+
return (0, farms_1.getFarmByStakedLPFactory)(this.offchain.network, lendingPoolData.pair.factory);
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
// getCollateralPrice -> returns the price of the collateral, not necessarily of the underlying LP
|
|
@@ -46,7 +46,7 @@ class PriceHelper {
|
|
|
46
46
|
}
|
|
47
47
|
initializeSubgraphTokenPrice() {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const lendingPoolsData = yield this.
|
|
49
|
+
const lendingPoolsData = yield this.offchain.getLendingPoolsData();
|
|
50
50
|
const subgraphTokenPrice = {};
|
|
51
51
|
for (const factory of Object.keys(lendingPoolsData)) {
|
|
52
52
|
for (const id of Object.keys(lendingPoolsData[factory])) {
|
|
@@ -101,9 +101,9 @@ class PriceHelper {
|
|
|
101
101
|
return result;
|
|
102
102
|
}
|
|
103
103
|
try {
|
|
104
|
-
const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.
|
|
104
|
+
const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.offchain.network] + "&id=" + tokenAddress);
|
|
105
105
|
/*const response = await fetch(
|
|
106
|
-
"https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.
|
|
106
|
+
"https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.offchain.network] + "&id=" + tokenAddress,
|
|
107
107
|
{headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
|
|
108
108
|
);*/
|
|
109
109
|
if (response.status != 200)
|
|
@@ -183,7 +183,7 @@ class PriceHelper {
|
|
|
183
183
|
if (tokenAddress.toLowerCase() === '0x1c28edf9e0d66f3124f141a3cf3ef1217f7019c4') { // fix for SLNA
|
|
184
184
|
return 0.00045;
|
|
185
185
|
}
|
|
186
|
-
// try fallback on
|
|
186
|
+
// try fallback on offchain
|
|
187
187
|
const subgraphTokenPrice = yield this.getSubgraphTokenPrice();
|
|
188
188
|
return subgraphTokenPrice[tokenAddress] ? subgraphTokenPrice[tokenAddress] : 0;
|
|
189
189
|
}
|