impermax-sdk 2.1.8 → 2.1.10
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/amms.d.ts +3 -1
- package/lib/config/amms.js +5 -2
- package/lib/config/contracts/impermax-factories.js +1 -0
- package/lib/config/subgraphs.js +4 -0
- package/lib/config/types.d.ts +3 -4
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5 -2
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +14 -14
- package/lib/offchain/lendingPool/offchainLendingPool.js +69 -36
- package/lib/offchain/offchain.d.ts +1 -1
- package/lib/offchain/offchain.js +2 -2
- package/lib/offchain/offchainAPRHelper.js +16 -11
- package/lib/offchain/offchainInitializer.js +42 -77
- package/lib/offchain/offchainMultichain.d.ts +4 -4
- package/lib/offchain/offchainMultichain.js +37 -26
- package/lib/offchain/queries/apis/ponder/index.d.ts +1 -0
- package/lib/offchain/queries/apis/ponder/index.js +83 -2
- package/lib/offchain/queries/apis/thegraph/index.d.ts +1 -0
- package/lib/offchain/queries/apis/thegraph/index.js +11 -5
- package/lib/offchain/queries/interfaces/query-builder.d.ts +2 -1
- package/package.json +1 -1
package/lib/config/amms.d.ts
CHANGED
|
@@ -45,10 +45,12 @@ export declare enum Amms {
|
|
|
45
45
|
equalizer = "equalizer",
|
|
46
46
|
wigoswap = "wigoswap",
|
|
47
47
|
velodrome = "velodrome",
|
|
48
|
-
alien = "alien"
|
|
48
|
+
alien = "alien",
|
|
49
|
+
uniswapv3 = "uniswapv3"
|
|
49
50
|
}
|
|
50
51
|
export declare const hrAmms: {
|
|
51
52
|
uniswap: string;
|
|
53
|
+
uniswapv3: string;
|
|
52
54
|
quickswap: string;
|
|
53
55
|
satin: string;
|
|
54
56
|
pearl: string;
|
package/lib/config/amms.js
CHANGED
|
@@ -50,9 +50,11 @@ var Amms;
|
|
|
50
50
|
Amms["wigoswap"] = "wigoswap";
|
|
51
51
|
Amms["velodrome"] = "velodrome";
|
|
52
52
|
Amms["alien"] = "alien";
|
|
53
|
+
Amms["uniswapv3"] = "uniswapv3";
|
|
53
54
|
})(Amms = exports.Amms || (exports.Amms = {}));
|
|
54
55
|
exports.hrAmms = {
|
|
55
|
-
[Amms.uniswap]: '
|
|
56
|
+
[Amms.uniswap]: 'UniswapV2',
|
|
57
|
+
[Amms.uniswapv3]: 'UniswapV3',
|
|
56
58
|
[Amms.quickswap]: 'QuickSwap',
|
|
57
59
|
[Amms.satin]: 'Satin',
|
|
58
60
|
[Amms.pearl]: 'Pearl',
|
|
@@ -173,7 +175,8 @@ exports.AMM_FACTORY = {
|
|
|
173
175
|
[Amms.aeroStable1]: '0x9111b8D7Cc1a676A70015BEA3A3a9968A44C52c3',
|
|
174
176
|
[Amms.scale]: '0xEd8db60aCc29e14bC867a497D94ca6e3CeB5eC04',
|
|
175
177
|
[Amms.uniswap]: '0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6',
|
|
176
|
-
[Amms.alien]: '0x3E84D913803b02A4a7f027165E8cA42C14C0FdE7'
|
|
178
|
+
[Amms.alien]: '0x3E84D913803b02A4a7f027165E8cA42C14C0FdE7',
|
|
179
|
+
[Amms.uniswapv3]: '0x33128a8fc17869897dce68ed026d694621f6fdfd'
|
|
177
180
|
},
|
|
178
181
|
[types_1.Networks.Scroll]: {
|
|
179
182
|
[Amms.tokan]: '0x074568F090e93194289c2C2BF285eE7f60b485a9',
|
|
@@ -50,6 +50,7 @@ exports.IMPERMAX_FACTORY = {
|
|
|
50
50
|
[types_1.Factory.SOLV2]: '0x66ca66E002a9CEE8dEfE25dB6f0c6225117C2d9f',
|
|
51
51
|
[types_1.Factory.SOL_STABLE]: '0x8aDc5F73e63b3Af3fd0648281fE451738D8B9D86',
|
|
52
52
|
[types_1.Factory.V2V2]: '0x47183bB55AD0F891887E099Cec3570d3C667cD00',
|
|
53
|
+
[types_1.Factory.V3]: '0xfa13d3fda783824949bef75f5e95bb546cfddf6f',
|
|
53
54
|
},
|
|
54
55
|
[types_1.Networks.Scroll]: {
|
|
55
56
|
[types_1.Factory.SOLV2]: '0x02Ff7B4d96EeBF8c9B34Fae0418E591e11da3099',
|
package/lib/config/subgraphs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WHITELIST_SUBGRAPH_URL = exports.CONFIG_MANAGER_SUBGRAPH_URL = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.VAULT_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
exports.IMPERMAX_SUBGRAPH_URL = {
|
|
6
7
|
[types_1.Networks.Ropsten]: {},
|
|
7
8
|
[types_1.Networks.Mainnet]: {
|
|
@@ -102,6 +103,9 @@ exports.IMPERMAX_SUBGRAPH_URL = {
|
|
|
102
103
|
"https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/B7xsBeef3FohKaFPcsAsviyLKaWXTqcSELjAsPj2B7iW",
|
|
103
104
|
"https://base-start-production.up.railway.app/",
|
|
104
105
|
],
|
|
106
|
+
[types_1.Factory.V3]: [
|
|
107
|
+
"https://impermax-indexer-production.up.railway.app/",
|
|
108
|
+
],
|
|
105
109
|
},
|
|
106
110
|
[types_1.Networks.Scroll]: {
|
|
107
111
|
[types_1.Factory.SOLV2]: [
|
package/lib/config/types.d.ts
CHANGED
|
@@ -88,8 +88,7 @@ export declare enum VaultType {
|
|
|
88
88
|
HEDGED = "Hedged",
|
|
89
89
|
LEVERAGED = "Leverage"
|
|
90
90
|
}
|
|
91
|
-
export type
|
|
92
|
-
[key in
|
|
93
|
-
[key in VaultType]?: Type;
|
|
94
|
-
};
|
|
91
|
+
export type VaultTypeIndex<Type> = {
|
|
92
|
+
[key in VaultType]?: Type;
|
|
95
93
|
};
|
|
94
|
+
export type NetworkVaultTypeIndex<Type> = NetworkIndex<VaultTypeIndex<Type>>;
|
package/lib/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { OnchainInteractionsLendingPool, OnchainInteractionsLendingVault, Onchai
|
|
|
33
33
|
import { OnchainInteractionsBorrowable, OnchainInteractionsCollateral } from './onchain/interactions/lendingPool';
|
|
34
34
|
import { LENDING_VAULT_WATCHER } from './config/contracts/lending-vault-watcher';
|
|
35
35
|
import OffchainVault, { OffchainLendingVault, OffchainLeveragedVault, OffchainHedgedVault } from './offchain/vault';
|
|
36
|
-
import { SortDirection,
|
|
36
|
+
import { SortDirection, VaultListOrderBy, VaultListParams, LendingPoolListParams, LendingPoolListOrderBy } from "./offchain/offchainMultichain";
|
|
37
37
|
import { VaultRisk } from "./offchain/vault/offchainVault";
|
|
38
|
-
|
|
38
|
+
import { LendingPoolVersion } from "./offchain/lendingPool/offchainLendingPool";
|
|
39
|
+
export { offchain, OffchainMultichain, Offchain, OffchainLendingPool, OffchainPoolToken, OffchainCollateral, OffchainBorrowable, OffchainVault, OffchainLeveragedVault, OffchainLendingVault, OffchainHedgedVault, OffchainConfigManager, OffchainPairConfig, OffchainProposal, OffchainMultichainAccount, OffchainAccount, OffchainAccountLendingPool, OffchainAccountPoolToken, OffchainAccountCollateral, OffchainAccountBorrowable, OffchainLeveragedPosition, OffchainAccountVault, OffchainPriceHelper, OffchainSolidexHelper, PoolTokenData, BorrowableData, CollateralData, BorrowablePastData, TokenData, RewardData, PairData, FarmingPoolData, LendingPoolPastData, LendingPoolData, CollateralPosition, SupplyPosition, BorrowPosition, UserData, TvlData, XimxData, LendingVaultData, VaultPosition, PairConfigData, ProposalData, ProposalMetadata, VaultRisk, VaultType, onchain, Onchain, OnchainLendingPool, OnchainPoolToken, OnchainBorrowable, OnchainCollateral, OnchainLendingVault, OnchainConfigManager, OnchainProposal, OnchainPairConfig, OnchainAccount, OnchainAccountLendingPool, OnchainAccountPoolToken, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingVault, OnchainContractsHelper, OnchainImpermaxFactory, OnchainInteractions, OnchainInteractionsLendingPool, OnchainInteractionsPoolToken, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingVault, OnchainInteractionsConfigManager, Contract, ApprovalType, PermitData, OnchainConfig, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, CollateralConfig, BorrowableConfig, PairConfig, CLAIM_AGGREGATOR, IMPERMAX_CHEF, IMX, IMPERMAX_FACTORY, getNetworkFactories, LENDING_VAULT_WATCHER, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2, MERKLE_DISTRIBUTOR_ETH, ROUTER, SIMPLE_UNISWAP_ORACLE, WETH, MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2, hrAmms, AMM_FACTORY, getAmmByFactory, AMM_SUBGRAPH_URLS, ADD_LIQUIDITY_URLS, AMM_LP_FEE, DEBANK_IDS, ETH_SYMBOL, ETH_NAME, SOLIDEX_FACTORIES, BORROW_FEE_FACTORIES, OLD_KINK_MULTIPLIER_FACTORIES, LIQUIDATION_FEE_FACTORIES, V2_FACTORIES, Farms, hrFarms, FarmIndex, STAKED_LP_FACTORY, getFarmByStakedLPFactory, NOT_SYNCED, DEADLINE, ZERO, APPROVE_AMOUNT, IMPERMAX_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, BLOCKS_SUBGRAPH_URL, XIMX_SUBGRAPH_URL, Networks, Factory, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion };
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.OnchainInteractionsLendingVault = exports.OnchainInteractionsBorrowable = exports.OnchainInteractionsCollateral = exports.OnchainInteractionsPoolToken = exports.OnchainInteractionsLendingPool = exports.OnchainInteractions = exports.OnchainImpermaxFactory = exports.OnchainContractsHelper = exports.OnchainAccountLendingVault = exports.OnchainAccountCollateral = exports.OnchainAccountBorrowable = exports.OnchainAccountPoolToken = exports.OnchainAccountLendingPool = exports.OnchainAccount = exports.OnchainPairConfig = exports.OnchainProposal = exports.OnchainConfigManager = exports.OnchainLendingVault = exports.OnchainCollateral = exports.OnchainBorrowable = exports.OnchainPoolToken = exports.OnchainLendingPool = exports.Onchain = exports.onchain = exports.VaultType = exports.VaultRisk = exports.OffchainSolidexHelper = exports.OffchainPriceHelper = exports.OffchainAccountVault = exports.OffchainLeveragedPosition = exports.OffchainAccountBorrowable = exports.OffchainAccountCollateral = exports.OffchainAccountPoolToken = exports.OffchainAccountLendingPool = exports.OffchainAccount = exports.OffchainMultichainAccount = exports.OffchainProposal = exports.OffchainPairConfig = exports.OffchainConfigManager = exports.OffchainHedgedVault = exports.OffchainLendingVault = exports.OffchainLeveragedVault = exports.OffchainVault = exports.OffchainBorrowable = exports.OffchainCollateral = exports.OffchainPoolToken = exports.OffchainLendingPool = exports.Offchain = exports.OffchainMultichain = exports.offchain = void 0;
|
|
27
27
|
exports.WhitelistState = exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Factory = exports.Networks = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = exports.APPROVE_AMOUNT = exports.ZERO = exports.DEADLINE = exports.NOT_SYNCED = exports.getFarmByStakedLPFactory = exports.STAKED_LP_FACTORY = exports.hrFarms = exports.Farms = exports.V2_FACTORIES = exports.LIQUIDATION_FEE_FACTORIES = exports.OLD_KINK_MULTIPLIER_FACTORIES = exports.BORROW_FEE_FACTORIES = exports.SOLIDEX_FACTORIES = exports.ETH_NAME = exports.ETH_SYMBOL = exports.DEBANK_IDS = exports.AMM_LP_FEE = exports.ADD_LIQUIDITY_URLS = exports.AMM_SUBGRAPH_URLS = exports.getAmmByFactory = exports.AMM_FACTORY = exports.hrAmms = exports.MERKLE_URL_IBEX_2 = exports.MERKLE_URL_IBEX = exports.MERKLE_URL_ETH = exports.WETH = exports.SIMPLE_UNISWAP_ORACLE = exports.ROUTER = exports.MERKLE_DISTRIBUTOR_ETH = exports.MERKLE_DISTRIBUTOR_IBEX_2 = exports.MERKLE_DISTRIBUTOR_IBEX = exports.LENDING_VAULT_WATCHER = exports.getNetworkFactories = exports.IMPERMAX_FACTORY = exports.IMX = exports.IMPERMAX_CHEF = exports.CLAIM_AGGREGATOR = exports.NO_CHANGES = exports.ApprovalType = exports.OnchainInteractionsConfigManager = void 0;
|
|
28
|
-
exports.SortDirection = exports.
|
|
28
|
+
exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = void 0;
|
|
29
29
|
const offchain_1 = __importStar(require("./offchain"));
|
|
30
30
|
exports.Offchain = offchain_1.default;
|
|
31
31
|
Object.defineProperty(exports, "OffchainAccount", { enumerable: true, get: function () { return offchain_1.OffchainAccount; } });
|
|
@@ -162,6 +162,9 @@ Object.defineProperty(exports, "OffchainHedgedVault", { enumerable: true, get: f
|
|
|
162
162
|
// Data helpers (sort, filter)
|
|
163
163
|
const offchainMultichain_1 = require("./offchain/offchainMultichain");
|
|
164
164
|
Object.defineProperty(exports, "SortDirection", { enumerable: true, get: function () { return offchainMultichain_1.SortDirection; } });
|
|
165
|
-
Object.defineProperty(exports, "
|
|
165
|
+
Object.defineProperty(exports, "VaultListOrderBy", { enumerable: true, get: function () { return offchainMultichain_1.VaultListOrderBy; } });
|
|
166
|
+
Object.defineProperty(exports, "LendingPoolListOrderBy", { enumerable: true, get: function () { return offchainMultichain_1.LendingPoolListOrderBy; } });
|
|
166
167
|
const offchainVault_1 = require("./offchain/vault/offchainVault");
|
|
167
168
|
Object.defineProperty(exports, "VaultRisk", { enumerable: true, get: function () { return offchainVault_1.VaultRisk; } });
|
|
169
|
+
const offchainLendingPool_1 = require("./offchain/lendingPool/offchainLendingPool");
|
|
170
|
+
Object.defineProperty(exports, "LendingPoolVersion", { enumerable: true, get: function () { return offchainLendingPool_1.LendingPoolVersion; } });
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import Offchain from
|
|
2
|
-
import { Address, Borrowable, Factory, PoolTokenType, WhitelistState } from
|
|
3
|
-
import OffchainCollateral from
|
|
4
|
-
import OffchainBorrowable from
|
|
5
|
-
import OffchainPoolToken from
|
|
6
|
-
import { LendingPoolData, LendingPoolPastData } from
|
|
7
|
-
import { Farms } from
|
|
8
|
-
import { Amms } from
|
|
1
|
+
import Offchain from "../index";
|
|
2
|
+
import { Address, Borrowable, Factory, PoolTokenType, WhitelistState } from "../../config/types";
|
|
3
|
+
import OffchainCollateral from "./offchainCollateral";
|
|
4
|
+
import OffchainBorrowable from "./offchainBorrowable";
|
|
5
|
+
import OffchainPoolToken from "../offchainPoolToken";
|
|
6
|
+
import { LendingPoolData, LendingPoolPastData } from "../offchainTypes";
|
|
7
|
+
import { Farms } from "../../config/farms";
|
|
8
|
+
import { Amms } from "../../config/amms";
|
|
9
9
|
export declare enum LendingPoolVersion {
|
|
10
|
-
V1 =
|
|
11
|
-
V2 =
|
|
12
|
-
V3 =
|
|
10
|
+
V1 = "V1",
|
|
11
|
+
V2 = "V2",
|
|
12
|
+
V3 = "V3"
|
|
13
13
|
}
|
|
14
14
|
export default class OffchainLendingPool {
|
|
15
15
|
private readonly offchain;
|
|
@@ -48,13 +48,13 @@ export default class OffchainLendingPool {
|
|
|
48
48
|
getCollateralPrice(fast?: boolean): Promise<number>;
|
|
49
49
|
getUnderlyingLPPrice(fast?: boolean): Promise<number>;
|
|
50
50
|
getKinkMultiplier(): 2 | 5;
|
|
51
|
-
getTotalBorrowsUSD(): Promise<number>;
|
|
52
51
|
getTotalAPR(): Promise<number>;
|
|
53
52
|
getTVL(): Promise<number>;
|
|
54
53
|
isDeprecated(): Promise<boolean>;
|
|
55
54
|
isBlacklisted(): Promise<boolean>;
|
|
56
|
-
isStable(): Promise<boolean>;
|
|
57
55
|
isLowTVL(): Promise<boolean>;
|
|
58
56
|
isHighTVL(): Promise<boolean>;
|
|
59
|
-
|
|
57
|
+
isStable(): boolean;
|
|
58
|
+
getLendingPoolVersion(): LendingPoolVersion;
|
|
59
|
+
getTotalBorrowsUSD(): Promise<number>;
|
|
60
60
|
}
|
|
@@ -22,9 +22,9 @@ const amms_1 = require("../../config/amms");
|
|
|
22
22
|
const factories_1 = require("../../config/factories");
|
|
23
23
|
var LendingPoolVersion;
|
|
24
24
|
(function (LendingPoolVersion) {
|
|
25
|
-
LendingPoolVersion[
|
|
26
|
-
LendingPoolVersion[
|
|
27
|
-
LendingPoolVersion[
|
|
25
|
+
LendingPoolVersion["V1"] = "V1";
|
|
26
|
+
LendingPoolVersion["V2"] = "V2";
|
|
27
|
+
LendingPoolVersion["V3"] = "V3";
|
|
28
28
|
})(LendingPoolVersion = exports.LendingPoolVersion || (exports.LendingPoolVersion = {}));
|
|
29
29
|
class OffchainLendingPool {
|
|
30
30
|
constructor(offchain, factory, pairAddress) {
|
|
@@ -83,7 +83,7 @@ class OffchainLendingPool {
|
|
|
83
83
|
}
|
|
84
84
|
getLiquidationPenalty() {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
return (yield this.getLiquidationIncentive()) + (yield this.getLiquidationFee());
|
|
86
|
+
return ((yield this.getLiquidationIncentive()) + (yield this.getLiquidationFee()));
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
// Uniswap APR
|
|
@@ -110,8 +110,13 @@ class OffchainLendingPool {
|
|
|
110
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
111
|
const farm = yield this.getFarm();
|
|
112
112
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
113
|
-
if (farm === farms_1.Farms.solidex ||
|
|
114
|
-
|
|
113
|
+
if (farm === farms_1.Farms.solidex ||
|
|
114
|
+
farm === farms_1.Farms.solidexB ||
|
|
115
|
+
farm === farms_1.Farms.solidexUSDC ||
|
|
116
|
+
farm === farms_1.Farms.solidexUSDCB) {
|
|
117
|
+
const solidexLPDetails = yield this.offchain
|
|
118
|
+
.getSolidexHelper()
|
|
119
|
+
.getSolidexLPDetails();
|
|
115
120
|
const result = solidexLPDetails[lendingPoolData.pair.uniswapV2PairAddress];
|
|
116
121
|
if (result)
|
|
117
122
|
return result;
|
|
@@ -123,14 +128,19 @@ class OffchainLendingPool {
|
|
|
123
128
|
for (const reward of lendingPoolData.pair.rewards) {
|
|
124
129
|
const multiplier = farm === farms_1.Farms.traderJoeV2 ? 0.5 : 1;
|
|
125
130
|
const periodFinish = parseInt(reward.periodFinish);
|
|
126
|
-
if (
|
|
131
|
+
if (new Date().getTime() / 1000 - FINISH_DELAY > periodFinish &&
|
|
132
|
+
periodFinish !== 0)
|
|
127
133
|
continue;
|
|
128
134
|
let rewardRate = parseFloat(reward.rewardRate);
|
|
129
135
|
if (farm == farms_1.Farms.traderJoeV4)
|
|
130
136
|
rewardRate = rewardRate * 0.45;
|
|
131
|
-
const rewardPrice = yield this.offchain
|
|
137
|
+
const rewardPrice = yield this.offchain
|
|
138
|
+
.getPriceHelper()
|
|
139
|
+
.getDebankTokenPrice(reward.rewardsToken.id);
|
|
132
140
|
rewards.push({
|
|
133
|
-
APR: (0, utils_1.toAPR)((rewardPrice * rewardRate) /
|
|
141
|
+
APR: (0, utils_1.toAPR)(((rewardPrice * rewardRate) /
|
|
142
|
+
(stakedTotalSupply * underlyingLPPrice)) *
|
|
143
|
+
multiplier),
|
|
134
144
|
symbol: reward.rewardsToken.symbol,
|
|
135
145
|
});
|
|
136
146
|
}
|
|
@@ -173,9 +183,12 @@ class OffchainLendingPool {
|
|
|
173
183
|
}
|
|
174
184
|
// Amms and farms
|
|
175
185
|
getAmm() {
|
|
186
|
+
var _a, _b, _c;
|
|
176
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
188
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
178
|
-
|
|
189
|
+
// TODO: this properly
|
|
190
|
+
const pairFactory = (_b = (_a = lendingPoolData.pair) === null || _a === void 0 ? void 0 : _a.uniswapV2Factory) !== null && _b !== void 0 ? _b : (_c = lendingPoolData.nftlp) === null || _c === void 0 ? void 0 : _c.dexFactory;
|
|
191
|
+
return (0, amms_1.getAmmByFactory)(this.offchain.network, pairFactory);
|
|
179
192
|
});
|
|
180
193
|
}
|
|
181
194
|
getFarm() {
|
|
@@ -197,16 +210,17 @@ class OffchainLendingPool {
|
|
|
197
210
|
getCollateralPrice(fast = true) {
|
|
198
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
212
|
const lendingPoolData = yield this.getLendingPoolData();
|
|
200
|
-
return this.calculateCollateralPrice(parseFloat(lendingPoolData.pair.reserve0), parseFloat(lendingPoolData.pair.reserve1), parseFloat(lendingPoolData.pair.totalSupply), fast
|
|
201
|
-
yield this.getBorrowableA().getTokenPriceFast()
|
|
202
|
-
yield this.getBorrowableA().getTokenPriceAccurate(), fast
|
|
203
|
-
yield this.getBorrowableB().getTokenPriceFast()
|
|
204
|
-
yield this.getBorrowableB().getTokenPriceAccurate());
|
|
213
|
+
return this.calculateCollateralPrice(parseFloat(lendingPoolData.pair.reserve0), parseFloat(lendingPoolData.pair.reserve1), parseFloat(lendingPoolData.pair.totalSupply), fast
|
|
214
|
+
? yield this.getBorrowableA().getTokenPriceFast()
|
|
215
|
+
: yield this.getBorrowableA().getTokenPriceAccurate(), fast
|
|
216
|
+
? yield this.getBorrowableB().getTokenPriceFast()
|
|
217
|
+
: yield this.getBorrowableB().getTokenPriceAccurate());
|
|
205
218
|
});
|
|
206
219
|
}
|
|
207
220
|
getUnderlyingLPPrice(fast = true) {
|
|
208
221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
return (yield this.getCollateralPrice(fast)) /
|
|
222
|
+
return ((yield this.getCollateralPrice(fast)) /
|
|
223
|
+
(yield this.getStakedLPExchangeRate()));
|
|
210
224
|
});
|
|
211
225
|
}
|
|
212
226
|
// Kink Multiplier
|
|
@@ -215,29 +229,33 @@ class OffchainLendingPool {
|
|
|
215
229
|
return 5;
|
|
216
230
|
return 2;
|
|
217
231
|
}
|
|
218
|
-
// Stats
|
|
219
|
-
getTotalBorrowsUSD() {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
const totalBorrowsUSDA = yield this.getBorrowableA().getTotalBorrowsUSD();
|
|
222
|
-
const totalBorrowsUSDB = yield this.getBorrowableB().getTotalBorrowsUSD();
|
|
223
|
-
return totalBorrowsUSDA + totalBorrowsUSDB;
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
232
|
getTotalAPR() {
|
|
227
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
const uniswapV2Pair = (yield this.getLendingPoolData()).pair
|
|
234
|
+
const uniswapV2Pair = (yield this.getLendingPoolData()).pair
|
|
235
|
+
.uniswapV2PairAddress;
|
|
229
236
|
// If llama fails/apr is 0 we get the uniswapAPR and stakingAPR through subgraph
|
|
230
|
-
const apr = yield this.offchain
|
|
237
|
+
const apr = yield this.offchain
|
|
238
|
+
.getAPRHelper()
|
|
239
|
+
.getLlamaAPR(uniswapV2Pair, this.offchain.network);
|
|
231
240
|
if (apr > 0)
|
|
232
241
|
return apr;
|
|
233
|
-
const [uniswapAPR, stakingAPR] = yield Promise.all([
|
|
242
|
+
const [uniswapAPR, stakingAPR] = yield Promise.all([
|
|
243
|
+
this.getUniswapAPR(),
|
|
244
|
+
this.getStakingAPR(),
|
|
245
|
+
]);
|
|
234
246
|
return uniswapAPR + stakingAPR;
|
|
235
247
|
});
|
|
236
248
|
}
|
|
249
|
+
// NOTE: Should this also include collateral totalBalanceUSD ?
|
|
237
250
|
getTVL() {
|
|
238
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
|
|
240
|
-
|
|
252
|
+
const [supply0USD, supply1USD] = yield Promise.all([
|
|
253
|
+
this.getBorrowableA().getSupplyUSD(),
|
|
254
|
+
this.getBorrowableB().getSupplyUSD(),
|
|
255
|
+
]);
|
|
256
|
+
if (supply0USD && supply1USD)
|
|
257
|
+
return supply0USD + supply1USD;
|
|
258
|
+
return 0;
|
|
241
259
|
});
|
|
242
260
|
}
|
|
243
261
|
// Flags
|
|
@@ -251,11 +269,6 @@ class OffchainLendingPool {
|
|
|
251
269
|
return false;
|
|
252
270
|
});
|
|
253
271
|
}
|
|
254
|
-
isStable() {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
return false;
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
272
|
isLowTVL() {
|
|
260
273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
261
274
|
return false;
|
|
@@ -266,11 +279,31 @@ class OffchainLendingPool {
|
|
|
266
279
|
return false;
|
|
267
280
|
});
|
|
268
281
|
}
|
|
282
|
+
// WARN: If V3 supports multiple pool types, then need more robust way to check if is stable or not
|
|
283
|
+
isStable() {
|
|
284
|
+
const factoryType = Number(this.factory);
|
|
285
|
+
if (factoryType === 7)
|
|
286
|
+
return true;
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
269
289
|
// Versions Specfics
|
|
270
290
|
getLendingPoolVersion() {
|
|
271
|
-
|
|
272
|
-
|
|
291
|
+
const factoryType = Number(this.factory);
|
|
292
|
+
if (factoryType < 4)
|
|
293
|
+
return LendingPoolVersion.V1;
|
|
294
|
+
if (factoryType < 8)
|
|
273
295
|
return LendingPoolVersion.V2;
|
|
296
|
+
return LendingPoolVersion.V3;
|
|
297
|
+
}
|
|
298
|
+
getTotalBorrowsUSD() {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
const [borrows0USD, borrows1USD] = yield Promise.all([
|
|
301
|
+
this.getBorrowableA().getTotalBorrowsUSD(),
|
|
302
|
+
this.getBorrowableB().getTotalBorrowsUSD(),
|
|
303
|
+
]);
|
|
304
|
+
if (borrows0USD && borrows1USD)
|
|
305
|
+
return borrows0USD + borrows1USD;
|
|
306
|
+
return 0;
|
|
274
307
|
});
|
|
275
308
|
}
|
|
276
309
|
}
|
|
@@ -43,7 +43,7 @@ export default class Offchain {
|
|
|
43
43
|
protected vaultsUsersData: {
|
|
44
44
|
[key in Address]?: Promise<AddressIndex<AddressIndex<VaultPosition>>>;
|
|
45
45
|
};
|
|
46
|
-
constructor(offchainMultichain: OffchainMultichain, network: Networks);
|
|
46
|
+
constructor(offchainMultichain: OffchainMultichain, network: Networks, whitelist?: FactoryIndex<Address[]>);
|
|
47
47
|
cleanCache(): void;
|
|
48
48
|
getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
|
|
49
49
|
getVault(vaultAddress: Address): Promise<OffchainVault>;
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -45,7 +45,7 @@ const offchainVault_1 = __importDefault(require("./vault/offchainVault"));
|
|
|
45
45
|
const configManager_1 = __importDefault(require("./configManager"));
|
|
46
46
|
const chainId_1 = require("../config/chainId");
|
|
47
47
|
class Offchain {
|
|
48
|
-
constructor(offchainMultichain, network) {
|
|
48
|
+
constructor(offchainMultichain, network, whitelist) {
|
|
49
49
|
this.whitelistedPairs = {};
|
|
50
50
|
this.getPriceHelper = () => this.priceHelper;
|
|
51
51
|
this.getSolidexHelper = () => this.solidexHelper;
|
|
@@ -91,7 +91,7 @@ class Offchain {
|
|
|
91
91
|
// TODO fix conflicting lines (commented)
|
|
92
92
|
//this.network = cfg.network;
|
|
93
93
|
//this.chainId = cfg.chainId;
|
|
94
|
-
|
|
94
|
+
this.whitelistedPairs = whitelist !== null && whitelist !== void 0 ? whitelist : {};
|
|
95
95
|
this.offchainMultichain = offchainMultichain;
|
|
96
96
|
this.network = network;
|
|
97
97
|
this.chainId = chainId_1.CHAIN_IDS[network];
|
|
@@ -167,18 +167,23 @@ class OffchainAPRHelper {
|
|
|
167
167
|
getLlamaAPR(pool, chain) {
|
|
168
168
|
var _a;
|
|
169
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
try {
|
|
171
|
+
// Get or initialize the pools
|
|
172
|
+
const llamaAllPools = yield this.getLlamaYields();
|
|
173
|
+
// Map to llama chain names, if not supported, then fetch native way
|
|
174
|
+
const llamaChain = LlamaChains[chain];
|
|
175
|
+
if (!llamaChain)
|
|
176
|
+
return 0;
|
|
177
|
+
// Make pool unique ({poolAddress}-{chain})
|
|
178
|
+
const llamaId = pool.concat("-", llamaChain).toLowerCase();
|
|
179
|
+
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
180
|
+
const apy = ((_a = llamaAllPools[llamaId]) === null || _a === void 0 ? void 0 : _a.apy) / 100;
|
|
181
|
+
// If 0 then should fetch native way to make sure
|
|
182
|
+
return apy || 0;
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
175
185
|
return 0;
|
|
176
|
-
|
|
177
|
-
const llamaId = pool.concat("-", llamaChain).toLowerCase();
|
|
178
|
-
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
179
|
-
const apy = ((_a = llamaAllPools[llamaId]) === null || _a === void 0 ? void 0 : _a.apy) / 100;
|
|
180
|
-
// If 0 then should fetch native way to make sure
|
|
181
|
-
return apy || 0;
|
|
186
|
+
}
|
|
182
187
|
});
|
|
183
188
|
}
|
|
184
189
|
getLlamaTvlAndBorrows(chain) {
|
|
@@ -99,18 +99,29 @@ exports.fetchVaults = fetchVaults;
|
|
|
99
99
|
function fetchLendingPools() {
|
|
100
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
101
|
const calls = [];
|
|
102
|
+
const factories = [];
|
|
102
103
|
let factory;
|
|
103
104
|
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
104
|
-
// Multiple endpoints
|
|
105
105
|
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
106
|
-
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, [], this.network)));
|
|
106
|
+
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, this.whitelistedPairs[factory], this.network)));
|
|
107
|
+
factories.push(factory);
|
|
107
108
|
}
|
|
108
109
|
const results = yield Promise.all(calls);
|
|
109
110
|
const lendingPools = {};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
results.forEach((result, index) => {
|
|
112
|
+
var _a;
|
|
113
|
+
// `offchainEndpointManager` returns null when using filters and cant find subgraph with filter
|
|
114
|
+
if (!result)
|
|
115
|
+
return;
|
|
116
|
+
// Get the factory for this result
|
|
117
|
+
const factory = factories[index];
|
|
118
|
+
// Get pools data
|
|
119
|
+
const poolsForFactory = (_a = result.data) === null || _a === void 0 ? void 0 : _a.lendingPools;
|
|
120
|
+
if (!poolsForFactory)
|
|
121
|
+
return;
|
|
122
|
+
// Add all pools for this factory
|
|
123
|
+
lendingPools[factory] = poolsForFactory;
|
|
124
|
+
});
|
|
114
125
|
return lendingPools;
|
|
115
126
|
});
|
|
116
127
|
}
|
|
@@ -123,6 +134,7 @@ function fetchLendingPoolsPast(seconds) {
|
|
|
123
134
|
return null;
|
|
124
135
|
try {
|
|
125
136
|
const calls = [];
|
|
137
|
+
const factories = [];
|
|
126
138
|
let factory;
|
|
127
139
|
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
128
140
|
const endpoints = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
@@ -131,15 +143,25 @@ function fetchLendingPoolsPast(seconds) {
|
|
|
131
143
|
// Skip if no endpoints support past queries for this factory
|
|
132
144
|
if (supportedEndpoints.length === 0)
|
|
133
145
|
continue;
|
|
134
|
-
// Query only from supported endpoints
|
|
135
146
|
calls.push(this.endpointManager.fetch(supportedEndpoints, this.network, (queryBuilder) => queryBuilder.lendingPoolsPastQuery(blockNumber, this.whitelistedPairs[factory])));
|
|
147
|
+
factories.push(factory);
|
|
136
148
|
}
|
|
137
149
|
const results = yield Promise.all(calls);
|
|
138
150
|
const lendingPools = {};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
results.forEach((result, index) => {
|
|
152
|
+
var _a;
|
|
153
|
+
// `offchainEndpointManager` returns null when using filters and cant find subgraph with filter
|
|
154
|
+
if (!result)
|
|
155
|
+
return;
|
|
156
|
+
// Get the factory for this result
|
|
157
|
+
const factory = factories[index];
|
|
158
|
+
// Get pools data
|
|
159
|
+
const poolsForFactory = (_a = result.data) === null || _a === void 0 ? void 0 : _a.lendingPools;
|
|
160
|
+
if (!poolsForFactory)
|
|
161
|
+
return;
|
|
162
|
+
// Add all pools for this factory
|
|
163
|
+
lendingPools[factory] = poolsForFactory;
|
|
164
|
+
});
|
|
143
165
|
return lendingPools;
|
|
144
166
|
}
|
|
145
167
|
catch (_a) {
|
|
@@ -284,6 +306,7 @@ function fetchUniswapAPR(lendingPoolsByAmm, seconds = 60 * 60 * 24 * 7) {
|
|
|
284
306
|
exports.fetchUniswapAPR = fetchUniswapAPR;
|
|
285
307
|
// OffchainLendingPool Data
|
|
286
308
|
function initializeLendingPoolsData() {
|
|
309
|
+
var _a, _b, _c;
|
|
287
310
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
311
|
const lendingPoolsData = {};
|
|
289
312
|
// Get raw data
|
|
@@ -297,7 +320,9 @@ function initializeLendingPoolsData() {
|
|
|
297
320
|
const lendingPoolsByAmm = {};
|
|
298
321
|
for (const factory in lendingPools) {
|
|
299
322
|
for (const lendingPool of lendingPools[factory]) {
|
|
300
|
-
const amm = (0, amms_1.getAmmByFactory)(this.network,
|
|
323
|
+
const amm = (0, amms_1.getAmmByFactory)(this.network,
|
|
324
|
+
// WARN: Quick temporary fix, to be removed after
|
|
325
|
+
(_b = (_a = lendingPool === null || lendingPool === void 0 ? void 0 : lendingPool.pair) === null || _a === void 0 ? void 0 : _a.uniswapV2Factory) !== null && _b !== void 0 ? _b : (_c = lendingPool === null || lendingPool === void 0 ? void 0 : lendingPool.nftlp) === null || _c === void 0 ? void 0 : _c.dexFactory);
|
|
301
326
|
if (!amm)
|
|
302
327
|
continue;
|
|
303
328
|
if (!lendingPoolsByAmm[amm])
|
|
@@ -306,11 +331,14 @@ function initializeLendingPoolsData() {
|
|
|
306
331
|
lendingPoolsOfAmm.push(lendingPool);
|
|
307
332
|
}
|
|
308
333
|
}
|
|
309
|
-
const uniswapAPR =
|
|
334
|
+
// const uniswapAPR = await this.fetchUniswapAPR(lendingPoolsByAmm);
|
|
310
335
|
// Organize lending pools data
|
|
311
336
|
for (const factory in lendingPools) {
|
|
312
337
|
for (const lendingPool of lendingPools[factory]) {
|
|
313
|
-
|
|
338
|
+
// WARN: Quick temporary fix, to be removed after
|
|
339
|
+
if (factory === "8")
|
|
340
|
+
lendingPool["pair"] = lendingPool["nftlp"];
|
|
341
|
+
lendingPool.pair.uniswapAPR = 0;
|
|
314
342
|
if (impermaxChefRewardRates) {
|
|
315
343
|
lendingPool.borrowable0.rewards =
|
|
316
344
|
impermaxChefRewardRates[lendingPool.borrowable0.id];
|
|
@@ -378,37 +406,6 @@ function initializeLendingPoolsData() {
|
|
|
378
406
|
lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate = (parseFloat(lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate) / 2).toString();
|
|
379
407
|
}
|
|
380
408
|
}
|
|
381
|
-
/*if (lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH]) {
|
|
382
|
-
const LIZ = lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].borrowable0.underlying;
|
|
383
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.rewards = [{
|
|
384
|
-
id: '',
|
|
385
|
-
rewardsToken: LIZ,
|
|
386
|
-
rewardRate: '3.724',
|
|
387
|
-
periodFinish: '0',
|
|
388
|
-
}];
|
|
389
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.stakedTotalSupply = '40131.19426';
|
|
390
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.rewards = [{
|
|
391
|
-
id: '',
|
|
392
|
-
rewardsToken: LIZ,
|
|
393
|
-
rewardRate: '1.284',
|
|
394
|
-
periodFinish: '0',
|
|
395
|
-
}];
|
|
396
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.stakedTotalSupply = '0.182614';
|
|
397
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.rewards = [{
|
|
398
|
-
id: '',
|
|
399
|
-
rewardsToken: LIZ,
|
|
400
|
-
rewardRate: '0.159',
|
|
401
|
-
periodFinish: '0',
|
|
402
|
-
}];
|
|
403
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.stakedTotalSupply = '0.002468';
|
|
404
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.rewards = [{
|
|
405
|
-
id: '',
|
|
406
|
-
rewardsToken: LIZ,
|
|
407
|
-
rewardRate: '1.566',
|
|
408
|
-
periodFinish: '0',
|
|
409
|
-
}];
|
|
410
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.stakedTotalSupply = '0.568227';
|
|
411
|
-
}*/
|
|
412
409
|
}
|
|
413
410
|
if (this.network === types_1.Networks.Polygon) {
|
|
414
411
|
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
@@ -443,38 +440,6 @@ function initializeLendingPoolsData() {
|
|
|
443
440
|
"0.000000992210460243"; //https://snowtrace.io/token/0xe530dc2095ef5653205cf5ea79f8979a7028065c?a=0x784da19e61cf348a8c54547531795ecfee2affd1
|
|
444
441
|
}
|
|
445
442
|
}
|
|
446
|
-
/*REWARD STOPPED const sAVAX_AVAX = '0x5b588f4481035b0f765393fc9f4752615a6d0498';
|
|
447
|
-
if (lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX]) {
|
|
448
|
-
const QI = lendingPoolsData[Factory.V2V1_2][QI_AVAX].borrowable0.underlying;
|
|
449
|
-
lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX].pair.rewards[1] = {
|
|
450
|
-
id: '',
|
|
451
|
-
rewardsToken: QI,
|
|
452
|
-
rewardRate: '1.74',
|
|
453
|
-
periodFinish: '0',
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
const UST_AVAX = '0xc6e68d77d0f4fa925a1cf2611dab6b10900eaf2b';
|
|
457
|
-
if (lendingPoolsData[Factory.V2V1_2][UST_AVAX]) {
|
|
458
|
-
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
459
|
-
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[0].rewardRate = '0.000099';
|
|
460
|
-
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[2] = {
|
|
461
|
-
id: '',
|
|
462
|
-
rewardsToken: AVAX,
|
|
463
|
-
rewardRate: '0.00047',
|
|
464
|
-
periodFinish: '0',
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
const UST_USDC = '0x69c1c44e8742b66d892294a7eeb9aac51891b0eb';
|
|
468
|
-
if (lendingPoolsData[Factory.V2V1_2][UST_USDC]) {
|
|
469
|
-
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
470
|
-
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[0].rewardRate = '0.000099';
|
|
471
|
-
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[2] = {
|
|
472
|
-
id: '',
|
|
473
|
-
rewardsToken: AVAX,
|
|
474
|
-
rewardRate: '0.00047',
|
|
475
|
-
periodFinish: '0',
|
|
476
|
-
};
|
|
477
|
-
}*/
|
|
478
443
|
}
|
|
479
444
|
return lendingPoolsData;
|
|
480
445
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NetworkIndex, Networks, VaultType } from "../config/types";
|
|
1
|
+
import { NetworkIndex, Networks, VaultType, Address, FactoryIndex } from "../config/types";
|
|
2
2
|
import Offchain from "./offchain";
|
|
3
3
|
import OffchainVault from "./vault/offchainVault";
|
|
4
4
|
import { Amms } from "../config/amms";
|
|
@@ -10,7 +10,7 @@ export declare enum SortDirection {
|
|
|
10
10
|
ASC = "asc",
|
|
11
11
|
DESC = "desc"
|
|
12
12
|
}
|
|
13
|
-
export declare enum
|
|
13
|
+
export declare enum VaultListOrderBy {
|
|
14
14
|
TVL = 0,
|
|
15
15
|
APR = 1,
|
|
16
16
|
DEPOSITED = 2
|
|
@@ -48,8 +48,8 @@ export default class OffchainMultichain {
|
|
|
48
48
|
protected offchains: NetworkIndex<Offchain>;
|
|
49
49
|
private constructor();
|
|
50
50
|
static get instance(): OffchainMultichain;
|
|
51
|
-
getOffchain(network: Networks): Offchain;
|
|
51
|
+
getOffchain(network: Networks, whitelist?: FactoryIndex<Address[]>): Offchain;
|
|
52
52
|
getVaultList(params?: VaultListParams): Promise<Array<OffchainVault>>;
|
|
53
53
|
networkHasVault(network: Networks): boolean;
|
|
54
|
-
getLendingPoolList(params?: LendingPoolListParams
|
|
54
|
+
getLendingPoolList(params?: LendingPoolListParams): Promise<Array<OffchainLendingPool>>;
|
|
55
55
|
}
|
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
var _a, _OffchainMultichain_instance;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.LendingPoolListOrderBy = exports.
|
|
27
|
+
exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.SortDirection = void 0;
|
|
28
28
|
const types_1 = require("../config/types");
|
|
29
29
|
const offchain_1 = __importDefault(require("./offchain"));
|
|
30
30
|
const subgraphs_1 = require("../config/subgraphs");
|
|
@@ -34,12 +34,12 @@ var SortDirection;
|
|
|
34
34
|
SortDirection["ASC"] = "asc";
|
|
35
35
|
SortDirection["DESC"] = "desc";
|
|
36
36
|
})(SortDirection = exports.SortDirection || (exports.SortDirection = {}));
|
|
37
|
-
var
|
|
38
|
-
(function (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})(
|
|
37
|
+
var VaultListOrderBy;
|
|
38
|
+
(function (VaultListOrderBy) {
|
|
39
|
+
VaultListOrderBy[VaultListOrderBy["TVL"] = 0] = "TVL";
|
|
40
|
+
VaultListOrderBy[VaultListOrderBy["APR"] = 1] = "APR";
|
|
41
|
+
VaultListOrderBy[VaultListOrderBy["DEPOSITED"] = 2] = "DEPOSITED";
|
|
42
|
+
})(VaultListOrderBy = exports.VaultListOrderBy || (exports.VaultListOrderBy = {}));
|
|
43
43
|
// Pools //
|
|
44
44
|
var LendingPoolListOrderBy;
|
|
45
45
|
(function (LendingPoolListOrderBy) {
|
|
@@ -61,9 +61,9 @@ class OffchainMultichain {
|
|
|
61
61
|
}
|
|
62
62
|
return __classPrivateFieldGet(OffchainMultichain, _a, "f", _OffchainMultichain_instance);
|
|
63
63
|
}
|
|
64
|
-
getOffchain(network) {
|
|
64
|
+
getOffchain(network, whitelist) {
|
|
65
65
|
if (!this.offchains[network])
|
|
66
|
-
this.offchains[network] = new offchain_1.default(this, network);
|
|
66
|
+
this.offchains[network] = new offchain_1.default(this, network, whitelist);
|
|
67
67
|
return this.offchains[network];
|
|
68
68
|
}
|
|
69
69
|
/*--------------------------------------------------------*
|
|
@@ -71,24 +71,20 @@ class OffchainMultichain {
|
|
|
71
71
|
*--------------------------------------------------------*/
|
|
72
72
|
getVaultList(params = {}) {
|
|
73
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
|
|
74
|
+
console.time("Vaults");
|
|
75
75
|
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
76
|
-
// Filter out networks without vaults
|
|
77
76
|
const networksWithVaults = allNetworks.filter((network) => this.networkHasVault(network));
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
for (const network of networksWithVaults) {
|
|
77
|
+
// Networks
|
|
78
|
+
const networkPromises = networksWithVaults.map((network) => __awaiter(this, void 0, void 0, function* () {
|
|
81
79
|
const offchain = this.getOffchain(network);
|
|
82
80
|
const vaultsData = yield offchain.getVaultsData();
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
return allVaults;
|
|
81
|
+
// VaultTypes
|
|
82
|
+
const vaultPromises = Object.keys(vaultsData).map((address) => offchain.getVault(address));
|
|
83
|
+
return Promise.all(vaultPromises);
|
|
84
|
+
}));
|
|
85
|
+
const results = yield Promise.all(networkPromises);
|
|
86
|
+
console.timeEnd("Vaults");
|
|
87
|
+
return results.flat();
|
|
92
88
|
});
|
|
93
89
|
}
|
|
94
90
|
// Helpful for frontend UI thing
|
|
@@ -99,10 +95,25 @@ class OffchainMultichain {
|
|
|
99
95
|
* Lending Pools
|
|
100
96
|
*--------------------------------------------------------*/
|
|
101
97
|
// private async getVaultSortValue( vault: OffchainVault, orderBy: VaultOrderBy,): Promise<number> { }
|
|
102
|
-
getLendingPoolList(params = {}
|
|
98
|
+
getLendingPoolList(params = {}) {
|
|
103
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
console.time("Lending Pools");
|
|
101
|
+
const allNetworks = params.networks || Object.values(types_1.Networks);
|
|
102
|
+
// Networks
|
|
103
|
+
const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const offchain = this.getOffchain(network);
|
|
105
|
+
const lendingPoolsData = yield offchain.getLendingPoolsData();
|
|
106
|
+
// Factories
|
|
107
|
+
const factoryPromises = Object.entries(lendingPoolsData).map(([factory, pools]) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const poolPromises = Object.keys(pools).map((poolId) => offchain.getLendingPool(factory, poolId));
|
|
109
|
+
return Promise.all(poolPromises);
|
|
110
|
+
}));
|
|
111
|
+
const factoryResults = yield Promise.all(factoryPromises);
|
|
112
|
+
return factoryResults.flat();
|
|
113
|
+
}));
|
|
114
|
+
const results = yield Promise.all(networkPromises);
|
|
115
|
+
console.timeEnd("Lending Pools");
|
|
116
|
+
return results.flat();
|
|
106
117
|
});
|
|
107
118
|
}
|
|
108
119
|
}
|
|
@@ -3,6 +3,7 @@ import { IQueryBuilder } from "../../interfaces/query-builder";
|
|
|
3
3
|
export declare class PonderQueryBuilder implements IQueryBuilder {
|
|
4
4
|
blockQuery(): import("graphql").DocumentNode;
|
|
5
5
|
getBlockNumber(response: any, network: Networks): number;
|
|
6
|
+
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): import("graphql").DocumentNode;
|
|
6
7
|
lendingPoolsQuery(factory: Factory, addressesFilter: Address[], network: Networks): import("graphql").DocumentNode;
|
|
7
8
|
userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
8
9
|
tvlQuery(): import("graphql").DocumentNode;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PonderQueryBuilder = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const types_1 = require("../../../../config/types");
|
|
8
9
|
const factories_1 = require("../../../../config/factories");
|
|
9
10
|
const impermax_factories_1 = require("../../../../config/contracts/impermax-factories");
|
|
10
11
|
// TODO: Might need to separate Vaults query based on vault type, maybe not.
|
|
@@ -23,10 +24,90 @@ class PonderQueryBuilder {
|
|
|
23
24
|
getBlockNumber(response, network) {
|
|
24
25
|
return response.data._meta.status[network].block.number || 0;
|
|
25
26
|
}
|
|
27
|
+
/*-----------------------------*
|
|
28
|
+
* 2. Lending pools V3
|
|
29
|
+
*-----------------------------*/
|
|
30
|
+
lendingPoolsV3Query(factory, addressesFilter, network) {
|
|
31
|
+
const tokenStr = `{
|
|
32
|
+
id
|
|
33
|
+
symbol
|
|
34
|
+
name
|
|
35
|
+
decimals
|
|
36
|
+
derivedUSD
|
|
37
|
+
}`;
|
|
38
|
+
const distributorStr = `{
|
|
39
|
+
id
|
|
40
|
+
}`;
|
|
41
|
+
const farmingPoolStr = `{
|
|
42
|
+
epochAmount
|
|
43
|
+
epochBegin
|
|
44
|
+
segmentLength
|
|
45
|
+
vestingBegin
|
|
46
|
+
sharePercentage
|
|
47
|
+
distributor ${distributorStr}
|
|
48
|
+
}`;
|
|
49
|
+
const borrowableStr = `{
|
|
50
|
+
id
|
|
51
|
+
underlying ${tokenStr}
|
|
52
|
+
totalBalance
|
|
53
|
+
totalBorrows
|
|
54
|
+
borrowRate
|
|
55
|
+
reserveFactor
|
|
56
|
+
kinkBorrowRate
|
|
57
|
+
kinkUtilizationRate
|
|
58
|
+
adjustSpeed
|
|
59
|
+
borrowIndex
|
|
60
|
+
accrualTimestamp
|
|
61
|
+
exchangeRate
|
|
62
|
+
borrowTracker
|
|
63
|
+
farmingPool ${farmingPoolStr}
|
|
64
|
+
}`;
|
|
65
|
+
const collateralStr = `{
|
|
66
|
+
id
|
|
67
|
+
safetyMargin
|
|
68
|
+
liquidationIncentive
|
|
69
|
+
liquidationFee
|
|
70
|
+
}`;
|
|
71
|
+
const nftlpStr = `{
|
|
72
|
+
id
|
|
73
|
+
factory
|
|
74
|
+
dexFactory
|
|
75
|
+
token1Price
|
|
76
|
+
token0Price
|
|
77
|
+
rewards {
|
|
78
|
+
items {
|
|
79
|
+
id
|
|
80
|
+
rewardRate
|
|
81
|
+
rewardsToken ${tokenStr}
|
|
82
|
+
periodFinish
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}`;
|
|
86
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]` : "";
|
|
87
|
+
return (0, graphql_tag_1.default) `{
|
|
88
|
+
lendingPools(
|
|
89
|
+
limit: 1000
|
|
90
|
+
where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", ${id_in_string}}
|
|
91
|
+
) {
|
|
92
|
+
items {
|
|
93
|
+
id
|
|
94
|
+
borrowable0 ${borrowableStr}
|
|
95
|
+
borrowable1 ${borrowableStr}
|
|
96
|
+
collateral ${collateralStr}
|
|
97
|
+
nftlp ${nftlpStr}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_meta {
|
|
101
|
+
status
|
|
102
|
+
}
|
|
103
|
+
}`;
|
|
104
|
+
}
|
|
26
105
|
/*-----------------------------*
|
|
27
106
|
* 2. Lending pools
|
|
28
107
|
*-----------------------------*/
|
|
29
108
|
lendingPoolsQuery(factory, addressesFilter, network) {
|
|
109
|
+
if (factory == types_1.Factory.V3)
|
|
110
|
+
return this.lendingPoolsV3Query(factory, addressesFilter, network);
|
|
30
111
|
const tokenStr = `{
|
|
31
112
|
id
|
|
32
113
|
symbol
|
|
@@ -95,7 +176,7 @@ class PonderQueryBuilder {
|
|
|
95
176
|
}
|
|
96
177
|
}
|
|
97
178
|
}`;
|
|
98
|
-
const id_in_string = addressesFilter.length > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]
|
|
179
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]` : "";
|
|
99
180
|
return (0, graphql_tag_1.default) `{
|
|
100
181
|
lendingPools(
|
|
101
182
|
limit: 1000
|
|
@@ -183,7 +264,7 @@ class PonderQueryBuilder {
|
|
|
183
264
|
*-----------------------------*/
|
|
184
265
|
vaultsQuery(vaultType, addressesFilter) {
|
|
185
266
|
// do something here for difference kind of vault type, currently only lending
|
|
186
|
-
const id_in_string = addressesFilter.length > 0 ? `
|
|
267
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]` : "";
|
|
187
268
|
return (0, graphql_tag_1.default) `{
|
|
188
269
|
lendingVaults(limit: 1000, ${id_in_string}) {
|
|
189
270
|
items {
|
|
@@ -3,6 +3,7 @@ import { IQueryBuilder } from "../../interfaces/query-builder";
|
|
|
3
3
|
export declare class TheGraphQueryBuilder implements IQueryBuilder {
|
|
4
4
|
blockQuery(timestamp: number): import("graphql").DocumentNode;
|
|
5
5
|
getBlockNumber(response: any, network: Networks): number;
|
|
6
|
+
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
6
7
|
lendingPoolsQuery(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
7
8
|
userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
8
9
|
tvlQuery(): import("graphql").DocumentNode;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TheGraphQueryBuilder = void 0;
|
|
7
7
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const types_1 = require("../../../../config/types");
|
|
8
9
|
const factories_1 = require("../../../../config/factories");
|
|
9
10
|
// TODO: Might need to separate Vaults query based on vault type, maybe not.
|
|
10
11
|
class TheGraphQueryBuilder {
|
|
@@ -33,7 +34,12 @@ class TheGraphQueryBuilder {
|
|
|
33
34
|
/*-----------------------------*
|
|
34
35
|
* 2. Lending pools
|
|
35
36
|
*-----------------------------*/
|
|
37
|
+
lendingPoolsV3Query(factory, addressesFilter) {
|
|
38
|
+
return (0, graphql_tag_1.default) `{}`;
|
|
39
|
+
}
|
|
36
40
|
lendingPoolsQuery(factory, addressesFilter) {
|
|
41
|
+
if (factory == types_1.Factory.V3)
|
|
42
|
+
return this.lendingPoolsV3Query(factory, addressesFilter);
|
|
37
43
|
const tokenStr = `{
|
|
38
44
|
id
|
|
39
45
|
symbol
|
|
@@ -104,7 +110,7 @@ class TheGraphQueryBuilder {
|
|
|
104
110
|
periodFinish
|
|
105
111
|
}
|
|
106
112
|
}`;
|
|
107
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
113
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
108
114
|
return (0, graphql_tag_1.default) `{
|
|
109
115
|
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc ${id_in_string}) {
|
|
110
116
|
id
|
|
@@ -187,7 +193,7 @@ class TheGraphQueryBuilder {
|
|
|
187
193
|
*-----------------------------*/
|
|
188
194
|
vaultsQuery(vaultType, addressesFilter) {
|
|
189
195
|
// do something here for difference kind of vault type, currently only lending
|
|
190
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
196
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
191
197
|
return (0, graphql_tag_1.default) `{
|
|
192
198
|
lendingVaults(first: 1000 ${id_in_string}) {
|
|
193
199
|
id
|
|
@@ -290,7 +296,7 @@ class TheGraphQueryBuilder {
|
|
|
290
296
|
accrualTimestamp
|
|
291
297
|
exchangeRate
|
|
292
298
|
}`;
|
|
293
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
299
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
294
300
|
return (0, graphql_tag_1.default) `{
|
|
295
301
|
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc, block: {number: ${blockNumber}} ${id_in_string}) {
|
|
296
302
|
id
|
|
@@ -326,7 +332,7 @@ class TheGraphQueryBuilder {
|
|
|
326
332
|
}`;
|
|
327
333
|
}
|
|
328
334
|
pastVolumeQuery(blockNumber, addressesFilter) {
|
|
329
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
335
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
330
336
|
return (0, graphql_tag_1.default) `{
|
|
331
337
|
pairs (block: {number: ${blockNumber}} ${id_in_string}) {
|
|
332
338
|
id
|
|
@@ -335,7 +341,7 @@ class TheGraphQueryBuilder {
|
|
|
335
341
|
}`;
|
|
336
342
|
}
|
|
337
343
|
currentVolumeAndReservesQuery(addressesFilter) {
|
|
338
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
344
|
+
const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
339
345
|
return (0, graphql_tag_1.default) `{
|
|
340
346
|
pairs (${id_in_string}) {
|
|
341
347
|
id
|
|
@@ -3,7 +3,8 @@ import { Address, Factory, Networks, VaultType } from '../../../config/types';
|
|
|
3
3
|
export interface IQueryBuilder {
|
|
4
4
|
blockQuery(timestamp: number): DocumentNode;
|
|
5
5
|
getBlockNumber: (response: any, network: Networks) => number;
|
|
6
|
-
|
|
6
|
+
lendingPoolsV3Query(factory: Factory, addressesFilter: Address[], network: Networks): DocumentNode;
|
|
7
|
+
lendingPoolsQuery(factory: Factory, addressesFilter: Address[] | undefined, network: Networks): DocumentNode;
|
|
7
8
|
userQuery(account: Address, network: Networks, factory: Factory): DocumentNode;
|
|
8
9
|
tvlQuery(): DocumentNode;
|
|
9
10
|
vaultsQuery(vaultType: VaultType, addressesFilter: Address[]): DocumentNode;
|