impermax-sdk 1.0.1 → 1.0.2
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/esm/abis/ImpermaxABI.d.ts +2 -0
- package/lib/esm/abis/ImpermaxABI.js +3 -0
- package/lib/esm/abis/contracts/ClaimAggregator.json +2015 -0
- package/lib/esm/abis/contracts/IBorrowable.json +13207 -0
- package/lib/esm/abis/contracts/IClaimable.json +406 -0
- package/lib/esm/abis/contracts/ICollateral.json +8952 -0
- package/lib/esm/abis/contracts/IERC20.json +2376 -0
- package/lib/esm/abis/contracts/IFactory.json +3660 -0
- package/lib/esm/abis/contracts/IFarmingPool.json +3584 -0
- package/lib/esm/abis/contracts/IMerkleDistributor.json +1134 -0
- package/lib/esm/abis/contracts/IRouter02.json +7283 -0
- package/lib/esm/abis/contracts/ISimpleUniswapOracle.json +1469 -0
- package/lib/esm/abis/contracts/IStakedLPToken.json +7309 -0
- package/lib/esm/abis/contracts/IStakingRewards.json +1036 -0
- package/lib/esm/abis/contracts/IUniswapV2Factory.json +1690 -0
- package/lib/esm/abis/contracts/IUniswapV2Pair.json +6761 -0
- package/lib/esm/abis/contracts/ImpermaxChef.json +20945 -0
- package/lib/esm/config/amms.d.ts +25 -0
- package/lib/esm/config/amms.js +196 -0
- package/lib/esm/config/contracts/claim-aggregators.d.ts +2 -0
- package/lib/esm/config/contracts/claim-aggregators.js +18 -0
- package/lib/esm/config/contracts/impermax-chef.d.ts +2 -0
- package/lib/esm/config/contracts/impermax-chef.js +18 -0
- package/lib/esm/config/contracts/imxes.d.ts +2 -0
- package/lib/esm/config/contracts/imxes.js +18 -0
- package/lib/esm/config/contracts/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/contracts/merkle-distributors.js +13 -0
- package/lib/esm/config/contracts/routers.d.ts +2 -0
- package/lib/esm/config/contracts/routers.js +38 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.d.ts +2 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.js +35 -0
- package/lib/esm/config/contracts/weths.d.ts +2 -0
- package/lib/esm/config/contracts/weths.js +19 -0
- package/lib/esm/config/debank-ids.d.ts +2 -0
- package/lib/esm/config/debank-ids.js +17 -0
- package/lib/esm/config/endpoints/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/endpoints/merkle-distributors.js +13 -0
- package/lib/esm/config/eth.d.ts +3 -0
- package/lib/esm/config/eth.js +32 -0
- package/lib/esm/config/factories.d.ts +6 -0
- package/lib/esm/config/factories.js +24 -0
- package/lib/esm/config/farms.d.ts +59 -0
- package/lib/esm/config/farms.js +114 -0
- package/lib/esm/config/general.d.ts +3 -0
- package/lib/esm/config/general.js +8 -0
- package/lib/esm/config/subgraphs.d.ts +5 -0
- package/lib/esm/config/subgraphs.js +68 -0
- package/lib/esm/config/types.d.ts +67 -0
- package/lib/esm/config/types.js +54 -0
- package/lib/esm/impermax-router/Account.d.ts +31 -0
- package/lib/esm/impermax-router/Account.js +154 -0
- package/lib/esm/impermax-router/AccountBorrowable.d.ts +22 -0
- package/lib/esm/impermax-router/AccountBorrowable.js +141 -0
- package/lib/esm/impermax-router/AccountCollateral.d.ts +11 -0
- package/lib/esm/impermax-router/AccountCollateral.js +63 -0
- package/lib/esm/impermax-router/AccountLendingPool.d.ts +57 -0
- package/lib/esm/impermax-router/AccountLendingPool.js +266 -0
- package/lib/esm/impermax-router/AccountPoolToken.d.ts +29 -0
- package/lib/esm/impermax-router/AccountPoolToken.js +89 -0
- package/lib/esm/impermax-router/Borrowable.d.ts +27 -0
- package/lib/esm/impermax-router/Borrowable.js +128 -0
- package/lib/esm/impermax-router/Collateral.d.ts +9 -0
- package/lib/esm/impermax-router/Collateral.js +45 -0
- package/lib/esm/impermax-router/ContractsHelper.d.ts +28 -0
- package/lib/esm/impermax-router/ContractsHelper.js +50 -0
- package/lib/esm/impermax-router/ImpermaxFactory.d.ts +15 -0
- package/lib/esm/impermax-router/ImpermaxFactory.js +42 -0
- package/lib/esm/impermax-router/Interactions.d.ts +16 -0
- package/lib/esm/impermax-router/Interactions.js +105 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.d.ts +43 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.js +124 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.d.ts +23 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.js +194 -0
- package/lib/esm/impermax-router/LendingPool.d.ts +69 -0
- package/lib/esm/impermax-router/LendingPool.js +291 -0
- package/lib/esm/impermax-router/PoolToken.d.ts +36 -0
- package/lib/esm/impermax-router/PoolToken.js +140 -0
- package/lib/esm/impermax-router/index.d.ts +20 -0
- package/lib/esm/impermax-router/index.js +34 -0
- package/lib/esm/impermax-router/interfaces.d.ts +218 -0
- package/lib/esm/impermax-router/interfaces.js +15 -0
- package/{index.ts → lib/esm/index.d.ts} +1 -3
- package/lib/esm/index.js +10 -0
- package/lib/esm/subgraph/Account.d.ts +18 -0
- package/lib/esm/subgraph/Account.js +111 -0
- package/lib/esm/subgraph/AccountLendingPool.d.ts +19 -0
- package/lib/esm/subgraph/AccountLendingPool.js +71 -0
- package/lib/esm/subgraph/AccountPoolToken.d.ts +14 -0
- package/lib/esm/subgraph/AccountPoolToken.js +75 -0
- package/lib/esm/subgraph/LendingPool.d.ts +38 -0
- package/lib/esm/subgraph/LendingPool.js +204 -0
- package/lib/esm/subgraph/PoolToken.d.ts +64 -0
- package/lib/esm/subgraph/PoolToken.js +462 -0
- package/lib/esm/subgraph/PriceHelper.d.ts +21 -0
- package/lib/esm/subgraph/PriceHelper.js +166 -0
- package/lib/esm/subgraph/SolidexHelper.d.ts +16 -0
- package/lib/esm/subgraph/SolidexHelper.js +58 -0
- package/lib/esm/subgraph/index.d.ts +73 -0
- package/lib/esm/subgraph/index.js +185 -0
- package/lib/esm/subgraph/initializer.d.ts +34 -0
- package/lib/esm/subgraph/initializer.js +517 -0
- package/lib/esm/subgraph/query.d.ts +10 -0
- package/lib/esm/subgraph/query.js +229 -0
- package/lib/esm/utils/ether-utils.d.ts +5 -0
- package/lib/esm/utils/ether-utils.js +26 -0
- package/lib/esm/utils/index.d.ts +3 -0
- package/lib/esm/utils/index.js +16 -0
- package/package.json +9 -3
- package/.idea/impermax-sdk.iml +0 -12
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/workspace.xml +0 -642
- package/abis/ImpermaxABI.ts +0 -3
- package/abis/contracts/BAllowance.json +0 -4735
- package/abis/contracts/BDeployer.json +0 -1195
- package/abis/contracts/BInterestRateModel.json +0 -10796
- package/abis/contracts/BSetter.json +0 -6219
- package/abis/contracts/BStorage.json +0 -2613
- package/abis/contracts/Borrowable.json +0 -19937
- package/abis/contracts/CDeployer.json +0 -1104
- package/abis/contracts/CSetter.json +0 -5094
- package/abis/contracts/CStorage.json +0 -516
- package/abis/contracts/ClaimAggregator.json +0 -2015
- package/abis/contracts/Collateral.json +0 -21615
- package/abis/contracts/ERC20.json +0 -819
- package/abis/contracts/Factory.json +0 -21986
- package/abis/contracts/FarmingPool.json +0 -8601
- package/abis/contracts/IBDeployer.json +0 -351
- package/abis/contracts/IBorrowTracker.json +0 -346
- package/abis/contracts/IBorrowable.json +0 -13207
- package/abis/contracts/ICDeployer.json +0 -294
- package/abis/contracts/IClaimable.json +0 -406
- package/abis/contracts/ICollateral.json +0 -8952
- package/abis/contracts/IERC20.json +0 -2376
- package/abis/contracts/IFactory.json +0 -3660
- package/abis/contracts/IFarmingPool.json +0 -3584
- package/abis/contracts/IImpermaxCallee.json +0 -679
- package/abis/contracts/IMerkleDistributor.json +0 -1134
- package/abis/contracts/IPoolToken.json +0 -5343
- package/abis/contracts/IRouter01.json +0 -6891
- package/abis/contracts/IRouter02.json +0 -7283
- package/abis/contracts/ISimpleUniswapOracle.json +0 -1469
- package/abis/contracts/IStakedLPToken.json +0 -7309
- package/abis/contracts/IStakingRewards.json +0 -1036
- package/abis/contracts/IUniswapV2Callee.json +0 -403
- package/abis/contracts/IUniswapV2ERC20.json +0 -3155
- package/abis/contracts/IUniswapV2Factory.json +0 -1690
- package/abis/contracts/IUniswapV2Pair.json +0 -6761
- package/abis/contracts/IWETH.json +0 -561
- package/abis/contracts/ImpermaxChef.json +0 -20945
- package/abis/contracts/ImpermaxERC20.json +0 -12095
- package/abis/contracts/Math.json +0 -1966
- package/abis/contracts/MockERC20.json +0 -8884
- package/abis/contracts/PoolToken.json +0 -10784
- package/abis/contracts/Router01.json +0 -43963
- package/abis/contracts/SafeMath.json +0 -6828
- package/abis/contracts/SimpleUniswapOracle.json +0 -9640
- package/abis/contracts/TransferHelper.json +0 -4875
- package/abis/contracts/UQ112x112.json +0 -1201
- package/abis/contracts/UniswapV2ERC20.json +0 -10969
- package/abis/contracts/UniswapV2Factory.json +0 -5521
- package/abis/contracts/UniswapV2Library.json +0 -13789
- package/abis/contracts/UniswapV2Pair.json +0 -30782
- package/abis/contracts/WETH9.json +0 -6613
- package/config/amms.ts +0 -199
- package/config/contracts/claim-aggregators.ts +0 -16
- package/config/contracts/impermax-chef.ts +0 -16
- package/config/contracts/imxes.ts +0 -16
- package/config/contracts/merkle-distributors.ts +0 -13
- package/config/contracts/routers.ts +0 -36
- package/config/contracts/simple-uniswap-oracles.ts +0 -33
- package/config/contracts/weths.ts +0 -18
- package/config/debank-ids.ts +0 -15
- package/config/endpoints/merkle-distributors.ts +0 -13
- package/config/eth.ts +0 -32
- package/config/factories.ts +0 -26
- package/config/farms.ts +0 -119
- package/config/general.ts +0 -8
- package/config/subgraphs.ts +0 -69
- package/config/types.ts +0 -81
- package/impermax-router/Account.ts +0 -123
- package/impermax-router/AccountBorrowable.ts +0 -110
- package/impermax-router/AccountCollateral.ts +0 -40
- package/impermax-router/AccountLendingPool.ts +0 -231
- package/impermax-router/AccountPoolToken.ts +0 -76
- package/impermax-router/Borrowable.ts +0 -86
- package/impermax-router/Collateral.ts +0 -26
- package/impermax-router/ContractsHelper.ts +0 -64
- package/impermax-router/ImpermaxFactory.ts +0 -47
- package/impermax-router/Interactions.ts +0 -94
- package/impermax-router/InteractionsLendingPool.ts +0 -129
- package/impermax-router/InteractionsPoolToken.ts +0 -187
- package/impermax-router/LendingPool.ts +0 -256
- package/impermax-router/PoolToken.ts +0 -112
- package/impermax-router/index.ts +0 -49
- package/impermax-router/interfaces.ts +0 -233
- package/subgraph/Account.ts +0 -93
- package/subgraph/AccountLendingPool.ts +0 -60
- package/subgraph/AccountPoolToken.ts +0 -60
- package/subgraph/LendingPool.ts +0 -179
- package/subgraph/PoolToken.ts +0 -381
- package/subgraph/PriceHelper.ts +0 -150
- package/subgraph/SolidexHelper.ts +0 -54
- package/subgraph/index.ts +0 -166
- package/subgraph/initializer.ts +0 -509
- package/subgraph/query.ts +0 -224
- package/tsconfig.json +0 -16
- package/utils/ether-utils.ts +0 -22
- package/utils/index.ts +0 -12
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class SolidexHelper {
|
|
13
|
+
constructor(subgraph) {
|
|
14
|
+
this.subgraph = subgraph;
|
|
15
|
+
}
|
|
16
|
+
cleanCache() {
|
|
17
|
+
this.solidexLPDetails = null;
|
|
18
|
+
}
|
|
19
|
+
initializeSolidexLPDetails() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
const response = yield fetch("https://api.solidexfinance.com/api/getLPDetails?v=fantom");
|
|
23
|
+
if (response.status != 200)
|
|
24
|
+
return {};
|
|
25
|
+
const data = yield response.json();
|
|
26
|
+
if (!data || !data.success)
|
|
27
|
+
return {};
|
|
28
|
+
const solidexLPDetails = {};
|
|
29
|
+
for (const pool of data.data.poolDetailsAll) {
|
|
30
|
+
if (!pool.solidexTVL)
|
|
31
|
+
continue;
|
|
32
|
+
solidexLPDetails[pool.poolAddress.toLowerCase()] = [
|
|
33
|
+
{
|
|
34
|
+
APR: pool.solidexTVL.realsolidAPR / 100,
|
|
35
|
+
symbol: "SOLID",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
APR: pool.solidexTVL.realsexAPR / 100,
|
|
39
|
+
symbol: "SEX",
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
return solidexLPDetails;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getSolidexLPDetails() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!this.solidexLPDetails)
|
|
53
|
+
this.solidexLPDetails = this.initializeSolidexLPDetails();
|
|
54
|
+
return this.solidexLPDetails;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = SolidexHelper;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { LendingPoolData, TvlData, UserData, XimxData } from "../impermax-router/interfaces";
|
|
2
|
+
import * as initializer from "./initializer";
|
|
3
|
+
import LendingPool from "./LendingPool";
|
|
4
|
+
import PriceHelper from "./PriceHelper";
|
|
5
|
+
import SolidexHelper from "./SolidexHelper";
|
|
6
|
+
import Account from "./Account";
|
|
7
|
+
import { Address, Factory, FactoryIndex, LendingPoolIndex, Networks } from '../config/types';
|
|
8
|
+
export interface SubgraphCfg {
|
|
9
|
+
network: Networks;
|
|
10
|
+
chainId: number;
|
|
11
|
+
whitelistedPairs?: FactoryIndex<Address[]>;
|
|
12
|
+
}
|
|
13
|
+
export default class Subgraph {
|
|
14
|
+
network: Networks;
|
|
15
|
+
chainId: number;
|
|
16
|
+
whitelistedPairs?: FactoryIndex<Address[]>;
|
|
17
|
+
lendingPools: LendingPoolIndex<LendingPool>;
|
|
18
|
+
accounts: {
|
|
19
|
+
[key in Address]?: Account;
|
|
20
|
+
};
|
|
21
|
+
priceHelper: PriceHelper;
|
|
22
|
+
solidexHelper: SolidexHelper;
|
|
23
|
+
lendingPoolsData: Promise<LendingPoolIndex<LendingPoolData>>;
|
|
24
|
+
usersData: {
|
|
25
|
+
[key in Address]?: Promise<FactoryIndex<UserData>>;
|
|
26
|
+
};
|
|
27
|
+
tvlData: Promise<TvlData>;
|
|
28
|
+
ximxData: Promise<XimxData>;
|
|
29
|
+
constructor(cfg: SubgraphCfg);
|
|
30
|
+
cleanCache(): void;
|
|
31
|
+
getLendingPool(factory: Factory, pairAddress: Address): Promise<LendingPool>;
|
|
32
|
+
getAccount(account: Address): Account;
|
|
33
|
+
/**
|
|
34
|
+
* TODO
|
|
35
|
+
* Potrei organizzare in:
|
|
36
|
+
* - lendingPoolData
|
|
37
|
+
* - usersData
|
|
38
|
+
* - tvlData
|
|
39
|
+
* - ximxData
|
|
40
|
+
*/
|
|
41
|
+
apolloFetcher: typeof initializer.apolloFetcher;
|
|
42
|
+
fetchLendingPools: typeof initializer.fetchLendingPools;
|
|
43
|
+
fetchLendingPoolsPast: typeof initializer.fetchLendingPoolsPast;
|
|
44
|
+
fetchPastVolume: typeof initializer.fetchPastVolume;
|
|
45
|
+
fetchCurrentVolumeAndReserves: typeof initializer.fetchCurrentVolumeAndReserves;
|
|
46
|
+
fetchImpermaxChefRewardRates: typeof initializer.fetchImpermaxChefRewardRates;
|
|
47
|
+
fetchUniswapAPR: typeof initializer.fetchUniswapAPR;
|
|
48
|
+
fetchBlockByTimestamp: typeof initializer.fetchBlockByTimestamp;
|
|
49
|
+
initializeLendingPoolsData: typeof initializer.initializeLendingPoolsData;
|
|
50
|
+
getLendingPoolsData: typeof initializer.getLendingPoolsData;
|
|
51
|
+
getLendingPoolData: typeof initializer.getLendingPoolData;
|
|
52
|
+
initializeTvlData: typeof initializer.initializeTvlData;
|
|
53
|
+
getTvlData: typeof initializer.getTvlData;
|
|
54
|
+
fetchUserData: typeof initializer.fetchUserData;
|
|
55
|
+
initializeUserData: typeof initializer.initializeUserData;
|
|
56
|
+
getUserData: typeof initializer.getUserData;
|
|
57
|
+
initializeXimxData: typeof initializer.initializeXimxData;
|
|
58
|
+
getXimxData: typeof initializer.getXimxData;
|
|
59
|
+
/**
|
|
60
|
+
* DATA GETTERS
|
|
61
|
+
*/
|
|
62
|
+
getPairList(): Promise<any[]>;
|
|
63
|
+
private getPairData;
|
|
64
|
+
getPairListWithData(pairList: {
|
|
65
|
+
pairAddress: string;
|
|
66
|
+
factory: Factory;
|
|
67
|
+
}[]): Promise<any[]>;
|
|
68
|
+
getCrossChainTVL(): Promise<number>;
|
|
69
|
+
getTotalValueLocked(): Promise<number>;
|
|
70
|
+
getTotalValueSupplied(): Promise<number>;
|
|
71
|
+
getTotalValueBorrowed(): Promise<number>;
|
|
72
|
+
getXIMXAPY(): Promise<number>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const initializer = __importStar(require("./initializer"));
|
|
39
|
+
const PriceHelper_1 = __importDefault(require("./PriceHelper"));
|
|
40
|
+
const SolidexHelper_1 = __importDefault(require("./SolidexHelper"));
|
|
41
|
+
const Account_1 = __importDefault(require("./Account"));
|
|
42
|
+
class Subgraph {
|
|
43
|
+
constructor(cfg) {
|
|
44
|
+
/**
|
|
45
|
+
* TODO
|
|
46
|
+
* Potrei organizzare in:
|
|
47
|
+
* - lendingPoolData
|
|
48
|
+
* - usersData
|
|
49
|
+
* - tvlData
|
|
50
|
+
* - ximxData
|
|
51
|
+
*/
|
|
52
|
+
// Fetchers
|
|
53
|
+
this.apolloFetcher = initializer.apolloFetcher;
|
|
54
|
+
this.fetchLendingPools = initializer.fetchLendingPools;
|
|
55
|
+
this.fetchLendingPoolsPast = initializer.fetchLendingPoolsPast;
|
|
56
|
+
this.fetchPastVolume = initializer.fetchPastVolume;
|
|
57
|
+
this.fetchCurrentVolumeAndReserves = initializer.fetchCurrentVolumeAndReserves;
|
|
58
|
+
this.fetchImpermaxChefRewardRates = initializer.fetchImpermaxChefRewardRates;
|
|
59
|
+
this.fetchUniswapAPR = initializer.fetchUniswapAPR;
|
|
60
|
+
this.fetchBlockByTimestamp = initializer.fetchBlockByTimestamp;
|
|
61
|
+
this.initializeLendingPoolsData = initializer.initializeLendingPoolsData;
|
|
62
|
+
this.getLendingPoolsData = initializer.getLendingPoolsData;
|
|
63
|
+
this.getLendingPoolData = initializer.getLendingPoolData;
|
|
64
|
+
this.initializeTvlData = initializer.initializeTvlData;
|
|
65
|
+
this.getTvlData = initializer.getTvlData;
|
|
66
|
+
this.fetchUserData = initializer.fetchUserData;
|
|
67
|
+
this.initializeUserData = initializer.initializeUserData;
|
|
68
|
+
this.getUserData = initializer.getUserData;
|
|
69
|
+
this.initializeXimxData = initializer.initializeXimxData;
|
|
70
|
+
this.getXimxData = initializer.getXimxData;
|
|
71
|
+
this.network = cfg.network;
|
|
72
|
+
this.chainId = cfg.chainId;
|
|
73
|
+
this.whitelistedPairs = cfg.whitelistedPairs;
|
|
74
|
+
this.priceHelper = new PriceHelper_1.default(this);
|
|
75
|
+
this.solidexHelper = new SolidexHelper_1.default(this);
|
|
76
|
+
this.accounts = {};
|
|
77
|
+
this.usersData = {};
|
|
78
|
+
}
|
|
79
|
+
cleanCache() {
|
|
80
|
+
this.lendingPoolsData = null;
|
|
81
|
+
this.usersData = {};
|
|
82
|
+
this.tvlData = null;
|
|
83
|
+
this.ximxData = null;
|
|
84
|
+
this.priceHelper.cleanCache();
|
|
85
|
+
this.solidexHelper.cleanCache();
|
|
86
|
+
}
|
|
87
|
+
getLendingPool(factory, pairAddress) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
yield this.getLendingPoolsData(); // make sure that lending pools are initialized
|
|
90
|
+
return this.lendingPools[factory][pairAddress];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getAccount(account) {
|
|
94
|
+
if (!this.accounts[account])
|
|
95
|
+
this.accounts[account] = new Account_1.default(this, account);
|
|
96
|
+
return this.accounts[account];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* DATA GETTERS
|
|
100
|
+
*/
|
|
101
|
+
// Pair List
|
|
102
|
+
/*async getPairListOld() : Promise<FactoryIndex<Address[]>> {
|
|
103
|
+
const result: FactoryIndex<Address[]> = {};
|
|
104
|
+
const lendingPoolData = await this.getLendingPoolsData();
|
|
105
|
+
for (const factory of Object.keys(lendingPoolData) as Factory[]) {
|
|
106
|
+
result[factory] = Object.keys(lendingPoolData[factory]);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
async getPairListWithData() {
|
|
111
|
+
const pairList = await this.getPairList();
|
|
112
|
+
if (!pairList) return null;
|
|
113
|
+
const requests = [];
|
|
114
|
+
for (const factory of Object.keys(pairList) as Factory[]) {
|
|
115
|
+
for (const pairAddress of pairList[factory]) {
|
|
116
|
+
requests.push(this.getPairData(factory, pairAddress));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
console.log("length", requests.length)
|
|
120
|
+
return Promise.all(requests);
|
|
121
|
+
}*/
|
|
122
|
+
getPairList() {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const result = [];
|
|
125
|
+
const lendingPoolData = yield this.getLendingPoolsData();
|
|
126
|
+
for (const factory of Object.keys(lendingPoolData)) {
|
|
127
|
+
for (const pairAddress of Object.keys(lendingPoolData[factory])) {
|
|
128
|
+
result.push({ pairAddress, factory });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
getPairData(factory, pairAddress) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const lendingPool = yield this.getLendingPool(factory, pairAddress);
|
|
137
|
+
const totalBorrowsUSD = yield lendingPool.getTotalBorrowsUSD();
|
|
138
|
+
return { pairAddress, factory, totalBorrowsUSD };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
getPairListWithData(pairList) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const requests = [];
|
|
144
|
+
for (const pair of pairList) {
|
|
145
|
+
requests.push(this.getPairData(pair.factory, pair.pairAddress));
|
|
146
|
+
}
|
|
147
|
+
return Promise.all(requests);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// TVL Data
|
|
151
|
+
getCrossChainTVL() {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const tvlData = yield this.getTvlData();
|
|
154
|
+
return tvlData.crossChainTVLUSD;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
getTotalValueLocked() {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const tvlData = yield this.getTvlData();
|
|
160
|
+
return tvlData.totalBalanceUSD;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
getTotalValueSupplied() {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const tvlData = yield this.getTvlData();
|
|
166
|
+
return tvlData.totalSupplyUSD;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
getTotalValueBorrowed() {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const tvlData = yield this.getTvlData();
|
|
172
|
+
return tvlData.totalBorrowsUSD;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// IMX Staking
|
|
176
|
+
getXIMXAPY() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const ximxData = yield this.getXimxData();
|
|
179
|
+
if (!ximxData)
|
|
180
|
+
return 0;
|
|
181
|
+
return Math.pow(1 + parseFloat(ximxData.dailyAPR), 365) - 1;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.default = Subgraph;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LendingPoolData, TvlData, UserData, CollateralPosition, SupplyPosition, BorrowPosition, XimxData } from "../impermax-router/interfaces";
|
|
2
|
+
import Subgraph from "./index";
|
|
3
|
+
import { DocumentNode } from "graphql";
|
|
4
|
+
import { Address, AddressIndex, Amms, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
|
|
5
|
+
export declare function apolloFetcher(subgraphUrl: string, query: DocumentNode): Promise<import("apollo-client").ApolloQueryResult<any>>;
|
|
6
|
+
export declare function fetchBlockByTimestamp(this: Subgraph, timestamp: number): Promise<number>;
|
|
7
|
+
export declare function fetchLendingPools(this: Subgraph): Promise<FactoryIndex<LendingPoolData[]>>;
|
|
8
|
+
export declare function fetchLendingPoolsPast(this: Subgraph, seconds: number): Promise<FactoryIndex<any[]>>;
|
|
9
|
+
export declare function fetchImpermaxChefRewardRates(this: Subgraph): Promise<AddressIndex<Array<{
|
|
10
|
+
rewardToken: Address;
|
|
11
|
+
rewardRate: number;
|
|
12
|
+
}>>>;
|
|
13
|
+
export declare function fetchPastVolume(this: Subgraph, amm: Amms, lendingPools: LendingPoolData[], seconds: number): Promise<AddressIndex<number>>;
|
|
14
|
+
export declare function fetchCurrentVolumeAndReserves(this: Subgraph, amm: Amms, lendingPools: LendingPoolData[]): Promise<{
|
|
15
|
+
currentVolume: AddressIndex<number>;
|
|
16
|
+
currentReserve: AddressIndex<number>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function fetchUniswapAPR(this: Subgraph, lendingPoolsByAmm: {
|
|
19
|
+
[key in Amms]?: LendingPoolData[];
|
|
20
|
+
}, seconds?: number): Promise<AddressIndex<number>>;
|
|
21
|
+
export declare function initializeLendingPoolsData(this: Subgraph): Promise<LendingPoolIndex<LendingPoolData>>;
|
|
22
|
+
export declare function getLendingPoolsData(this: Subgraph): Promise<LendingPoolIndex<LendingPoolData>>;
|
|
23
|
+
export declare function getLendingPoolData(this: Subgraph, factory: Factory, uniswapV2PairAddress: Address): Promise<LendingPoolData>;
|
|
24
|
+
export declare function initializeTvlData(this: Subgraph): Promise<TvlData>;
|
|
25
|
+
export declare function getTvlData(this: Subgraph): Promise<TvlData>;
|
|
26
|
+
export declare function fetchUserData(this: Subgraph, account: Address): Promise<FactoryIndex<{
|
|
27
|
+
collateralPositions: CollateralPosition[];
|
|
28
|
+
supplyPositions: SupplyPosition[];
|
|
29
|
+
borrowPositions: BorrowPosition[];
|
|
30
|
+
}>>;
|
|
31
|
+
export declare function initializeUserData(this: Subgraph, account: Address): Promise<FactoryIndex<UserData>>;
|
|
32
|
+
export declare function getUserData(this: Subgraph, account: Address): Promise<FactoryIndex<UserData>>;
|
|
33
|
+
export declare function initializeXimxData(this: Subgraph): Promise<XimxData>;
|
|
34
|
+
export declare function getXimxData(this: Subgraph): Promise<XimxData>;
|