impermax-sdk 1.2.59 → 1.2.60
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/index.d.ts +2 -1
- package/lib/offchain/index.js +3 -1
- package/lib/offchain/lendingPool/offchainLendingPool.js +8 -5
- package/lib/offchain/offchain.d.ts +3 -0
- package/lib/offchain/offchain.js +4 -0
- package/lib/offchain/offchainAPRHelper.d.ts +12 -4
- package/lib/offchain/offchainAPRHelper.js +80 -36
- package/lib/offchain/offchainPriceHelper.js +1 -0
- package/package.json +1 -1
package/lib/offchain/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import OffchainLendingPool from "./lendingPool";
|
|
2
2
|
import * as lendingPool from './lendingPool';
|
|
3
3
|
import OffchainPriceHelper from "./offchainPriceHelper";
|
|
4
|
+
import OffchainAPRHelper from "./offchainAPRHelper";
|
|
4
5
|
import OffchainSolidexHelper from "./offchainSolidexHelper";
|
|
5
6
|
import OffchainAccount from "./account";
|
|
6
7
|
import * as account from "./account";
|
|
@@ -9,5 +10,5 @@ import OffchainLendingVault from './offchainLendingVault';
|
|
|
9
10
|
import OffchainPoolToken from "./offchainPoolToken";
|
|
10
11
|
import Offchain from './offchain';
|
|
11
12
|
import OffchainConfigManager from "./configManager";
|
|
12
|
-
export { account, lendingPool, configManager, OffchainAccount, OffchainLendingPool, OffchainConfigManager, OffchainPoolToken, OffchainLendingVault, OffchainSolidexHelper, OffchainPriceHelper, };
|
|
13
|
+
export { account, lendingPool, configManager, OffchainAccount, OffchainLendingPool, OffchainConfigManager, OffchainPoolToken, OffchainLendingVault, OffchainSolidexHelper, OffchainPriceHelper, OffchainAPRHelper };
|
|
13
14
|
export default Offchain;
|
package/lib/offchain/index.js
CHANGED
|
@@ -26,13 +26,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.OffchainPriceHelper = exports.OffchainSolidexHelper = exports.OffchainLendingVault = exports.OffchainPoolToken = exports.OffchainConfigManager = exports.OffchainLendingPool = exports.OffchainAccount = exports.configManager = exports.lendingPool = exports.account = void 0;
|
|
29
|
+
exports.OffchainAPRHelper = exports.OffchainPriceHelper = exports.OffchainSolidexHelper = exports.OffchainLendingVault = exports.OffchainPoolToken = exports.OffchainConfigManager = exports.OffchainLendingPool = exports.OffchainAccount = exports.configManager = exports.lendingPool = exports.account = void 0;
|
|
30
30
|
const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
31
31
|
exports.OffchainLendingPool = lendingPool_1.default;
|
|
32
32
|
const lendingPool = __importStar(require("./lendingPool"));
|
|
33
33
|
exports.lendingPool = lendingPool;
|
|
34
34
|
const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
|
|
35
35
|
exports.OffchainPriceHelper = offchainPriceHelper_1.default;
|
|
36
|
+
const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
|
|
37
|
+
exports.OffchainAPRHelper = offchainAPRHelper_1.default;
|
|
36
38
|
const offchainSolidexHelper_1 = __importDefault(require("./offchainSolidexHelper"));
|
|
37
39
|
exports.OffchainSolidexHelper = offchainSolidexHelper_1.default;
|
|
38
40
|
const account_1 = __importDefault(require("./account"));
|
|
@@ -19,7 +19,6 @@ const farms_1 = require("../../config/farms");
|
|
|
19
19
|
const utils_1 = require("../../utils");
|
|
20
20
|
const amms_1 = require("../../config/amms");
|
|
21
21
|
const factories_1 = require("../../config/factories");
|
|
22
|
-
const offchainAPRHelper_1 = require("../offchainAPRHelper");
|
|
23
22
|
class OffchainLendingPool {
|
|
24
23
|
constructor(offchain, factory, pairAddress) {
|
|
25
24
|
this.getOffchain = () => this.offchain;
|
|
@@ -216,12 +215,16 @@ class OffchainLendingPool {
|
|
|
216
215
|
return totalBorrowsUSDA + totalBorrowsUSDB;
|
|
217
216
|
});
|
|
218
217
|
}
|
|
219
|
-
// Try get APR from defillama
|
|
218
|
+
// Try get APR from defillama if the uniswapv2 pair is listed on `offchainAPRHelper`
|
|
220
219
|
getTotalAPR() {
|
|
221
220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
const uniswapV2Pair = (yield this.getLendingPoolData()).pair.uniswapV2PairAddress
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
const uniswapV2Pair = (yield this.getLendingPoolData()).pair.uniswapV2PairAddress;
|
|
222
|
+
// Remove this condition for all chains
|
|
223
|
+
if (this.offchain.network == types_1.Networks.Fantom) {
|
|
224
|
+
// If llama fails/apr is 0 we get the uniswapAPR and stakingAPR through subgraph
|
|
225
|
+
const apr = yield this.offchain.getAPRHelper().getLlamaAPR(uniswapV2Pair, this.offchain.network);
|
|
226
|
+
if (apr > 0)
|
|
227
|
+
return apr;
|
|
225
228
|
}
|
|
226
229
|
const [uniswapAPR, stakingAPR] = yield Promise.all([this.getUniswapAPR(), this.getStakingAPR()]);
|
|
227
230
|
return uniswapAPR + stakingAPR;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as initializer from "./offchainInitializer";
|
|
2
2
|
import OffchainLendingPool from "./lendingPool";
|
|
3
3
|
import OffchainPriceHelper from "./offchainPriceHelper";
|
|
4
|
+
import OffchainAPRHelper from "./offchainAPRHelper";
|
|
4
5
|
import OffchainSolidexHelper from "./offchainSolidexHelper";
|
|
5
6
|
import OffchainAccount from "./account";
|
|
6
7
|
import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState } from '../config/types';
|
|
@@ -20,6 +21,7 @@ export default class Offchain {
|
|
|
20
21
|
protected lendingVaults: AddressIndex<OffchainLendingVault>;
|
|
21
22
|
protected accounts: AddressIndex<OffchainAccount>;
|
|
22
23
|
protected priceHelper: OffchainPriceHelper;
|
|
24
|
+
protected aprHelper: OffchainAPRHelper;
|
|
23
25
|
protected solidexHelper: OffchainSolidexHelper;
|
|
24
26
|
protected configManager: OffchainConfigManager;
|
|
25
27
|
protected lendingPoolsData: Promise<LendingPoolIndex<LendingPoolData>> | null;
|
|
@@ -41,6 +43,7 @@ export default class Offchain {
|
|
|
41
43
|
getPriceHelper: () => OffchainPriceHelper;
|
|
42
44
|
getSolidexHelper: () => OffchainSolidexHelper;
|
|
43
45
|
getConfigManager: () => OffchainConfigManager;
|
|
46
|
+
getAPRHelper: () => OffchainAPRHelper;
|
|
44
47
|
/**
|
|
45
48
|
* TODO
|
|
46
49
|
* Potrei organizzare in:
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const initializer = __importStar(require("./offchainInitializer"));
|
|
39
39
|
const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
|
|
40
|
+
const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
|
|
40
41
|
const offchainSolidexHelper_1 = __importDefault(require("./offchainSolidexHelper"));
|
|
41
42
|
const account_1 = __importDefault(require("./account"));
|
|
42
43
|
const offchainLendingVault_1 = __importDefault(require("./offchainLendingVault"));
|
|
@@ -46,6 +47,7 @@ class Offchain {
|
|
|
46
47
|
this.getPriceHelper = () => this.priceHelper;
|
|
47
48
|
this.getSolidexHelper = () => this.solidexHelper;
|
|
48
49
|
this.getConfigManager = () => this.configManager;
|
|
50
|
+
this.getAPRHelper = () => this.aprHelper;
|
|
49
51
|
/**
|
|
50
52
|
* TODO
|
|
51
53
|
* Potrei organizzare in:
|
|
@@ -92,6 +94,7 @@ class Offchain {
|
|
|
92
94
|
this.priceHelper = new offchainPriceHelper_1.default(this);
|
|
93
95
|
this.solidexHelper = new offchainSolidexHelper_1.default(this);
|
|
94
96
|
this.configManager = new configManager_1.default(this);
|
|
97
|
+
this.aprHelper = new offchainAPRHelper_1.default(this);
|
|
95
98
|
this.accounts = {};
|
|
96
99
|
this.usersData = {};
|
|
97
100
|
this.lendingVaultsUsersData = {};
|
|
@@ -107,6 +110,7 @@ class Offchain {
|
|
|
107
110
|
this.priceHelper.cleanCache();
|
|
108
111
|
this.solidexHelper.cleanCache();
|
|
109
112
|
this.configManager.cleanCache();
|
|
113
|
+
this.aprHelper.cleanCache();
|
|
110
114
|
}
|
|
111
115
|
getLendingPool(factory, pairAddress) {
|
|
112
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Address, Networks } from '../config/types';
|
|
2
|
+
import Offchain from "./index";
|
|
3
|
+
export default class OffchainAPRHelper {
|
|
4
|
+
private llamaAllPools;
|
|
5
|
+
private initialized;
|
|
6
|
+
offchain: Offchain;
|
|
7
|
+
constructor(offchain: Offchain);
|
|
8
|
+
cleanCache(): void;
|
|
9
|
+
private initializeLlamaAllPools;
|
|
10
|
+
private getLlamaPools;
|
|
11
|
+
getLlamaAPR(pool: Address, chain: Networks): Promise<number>;
|
|
12
|
+
}
|
|
@@ -9,42 +9,86 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"0x68ca64CABbB3d40dBB0de37101A8C0b701f66fD6": "e0d0bad2-1664-49c0-9a67-345b25ec03f8",
|
|
12
|
+
const types_1 = require("../config/types");
|
|
13
|
+
// Map of OUR chains to the chain names used by llama in their `poolsOld`
|
|
14
|
+
const LlamaChains = {
|
|
15
|
+
[types_1.Networks.Ropsten]: 'ropsten',
|
|
16
|
+
[types_1.Networks.Mainnet]: 'ethereum',
|
|
17
|
+
[types_1.Networks.Polygon]: 'polygon',
|
|
18
|
+
[types_1.Networks.Arbitrum]: 'arbitrum',
|
|
19
|
+
[types_1.Networks.Avalanche]: 'avalanche',
|
|
20
|
+
[types_1.Networks.Moonriver]: 'moonriver',
|
|
21
|
+
[types_1.Networks.Aurora]: 'aurora',
|
|
22
|
+
[types_1.Networks.Cronos]: 'cronos',
|
|
23
|
+
[types_1.Networks.Fantom]: 'fantom',
|
|
24
|
+
[types_1.Networks.Harmony]: 'harmony',
|
|
25
|
+
[types_1.Networks.Moonbeam]: 'moonbeam',
|
|
26
|
+
[types_1.Networks.Sxnetwork]: 'sxnetwork',
|
|
27
|
+
[types_1.Networks.Canto]: 'canto',
|
|
28
|
+
[types_1.Networks.ZksyncEra]: 'zksync era',
|
|
29
|
+
[types_1.Networks.Base]: 'base',
|
|
30
|
+
[types_1.Networks.Mantle]: 'mantle',
|
|
31
|
+
[types_1.Networks.Scroll]: 'scroll'
|
|
33
32
|
};
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const res = yield fetch(`https://yields.llama.fi/chart/${poolId}`).then(i => i.json());
|
|
42
|
-
apy = res.data[res.data.length - 1].apy;
|
|
33
|
+
// Class to get the APR from DefiLlama directly, only makes 1 call to api and caches all pools
|
|
34
|
+
class OffchainAPRHelper {
|
|
35
|
+
constructor(offchain) {
|
|
36
|
+
this.llamaAllPools = {};
|
|
37
|
+
this.initialized = null;
|
|
38
|
+
this.offchain = offchain;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
cleanCache() {
|
|
41
|
+
this.llamaAllPools = {};
|
|
42
|
+
this.initialized = null;
|
|
46
43
|
}
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
// Initializes all llama pools
|
|
45
|
+
initializeLlamaAllPools() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
try {
|
|
48
|
+
const response = yield fetch('https://yields.llama.fi/poolsOld').then(i => i.json());
|
|
49
|
+
const pools = response.data;
|
|
50
|
+
// `i.pool_old` is the pool address with sometimes `-{chain}` separator if contracts exists on diff chains
|
|
51
|
+
this.llamaAllPools = pools.reduce((acc, i) => {
|
|
52
|
+
const pool = i.pool_old.split("-")[0];
|
|
53
|
+
const llamaChain = i.chain;
|
|
54
|
+
const llamaId = pool.toLowerCase() + "-" + llamaChain.toLowerCase();
|
|
55
|
+
acc[llamaId] = i;
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.warn("The llamas are down?");
|
|
61
|
+
this.llamaAllPools = {};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
getLlamaPools() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
// First call initializes
|
|
68
|
+
if (!this.initialized)
|
|
69
|
+
this.initialized = this.initializeLlamaAllPools();
|
|
70
|
+
// async mutex to only call llama api once
|
|
71
|
+
yield this.initialized;
|
|
72
|
+
return this.llamaAllPools;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Given a DefiLlama ID get the latest APR
|
|
76
|
+
getLlamaAPR(pool, chain) {
|
|
77
|
+
var _a;
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
// Get or initialize the pools
|
|
80
|
+
const llamaAllPools = yield this.getLlamaPools();
|
|
81
|
+
// Map to llama chain names, if not supported, then fetch native way
|
|
82
|
+
const llamaChain = LlamaChains[chain];
|
|
83
|
+
if (!llamaChain)
|
|
84
|
+
return 0;
|
|
85
|
+
// Make pool unique ({poolAddress}-{chain})
|
|
86
|
+
const llamaId = pool.toLowerCase() + "-" + llamaChain.toLowerCase();
|
|
87
|
+
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
88
|
+
const apy = ((_a = llamaAllPools[llamaId]) === null || _a === void 0 ? void 0 : _a.apy) / 100;
|
|
89
|
+
// If 0 then should fetch native way to make sure
|
|
90
|
+
return apy || 0;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.default = OffchainAPRHelper;
|
|
@@ -125,6 +125,7 @@ class OffchainPriceHelper {
|
|
|
125
125
|
offchainTokenPrice["0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2"] = 0;
|
|
126
126
|
offchainTokenPrice["0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83"] = 0;
|
|
127
127
|
offchainTokenPrice["0xc19669a405067927865b40ea045a2baabbbe57f5"] = 0;
|
|
128
|
+
offchainTokenPrice["0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6"] = 0;
|
|
128
129
|
return offchainTokenPrice;
|
|
129
130
|
});
|
|
130
131
|
}
|