impermax-sdk 2.1.114 → 2.1.116

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.
Files changed (44) hide show
  1. package/lib/config/subgraphs.js +1 -1
  2. package/lib/index.d.ts +2 -1
  3. package/lib/index.js +4 -1
  4. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.d.ts +4 -3
  5. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.js +18 -3
  6. package/lib/offchain/account/offchainAccount.js +1 -3
  7. package/lib/offchain/account/offchainMultichainAccount.js +0 -1
  8. package/lib/offchain/initializer/apollo.d.ts +7 -0
  9. package/lib/offchain/initializer/apollo.js +40 -0
  10. package/lib/offchain/initializer/blocks.d.ts +2 -0
  11. package/lib/offchain/initializer/blocks.js +33 -0
  12. package/lib/offchain/initializer/farming.d.ts +9 -0
  13. package/lib/offchain/initializer/farming.js +55 -0
  14. package/lib/offchain/initializer/index.d.ts +10 -0
  15. package/lib/offchain/initializer/index.js +26 -0
  16. package/lib/offchain/initializer/lendingPools.d.ts +7 -0
  17. package/lib/offchain/initializer/lendingPools.js +219 -0
  18. package/lib/offchain/initializer/lendingPoolsPast.d.ts +13 -0
  19. package/lib/offchain/initializer/lendingPoolsPast.js +154 -0
  20. package/lib/offchain/initializer/staking.d.ts +4 -0
  21. package/lib/offchain/initializer/staking.js +31 -0
  22. package/lib/offchain/initializer/tvl.d.ts +4 -0
  23. package/lib/offchain/initializer/tvl.js +119 -0
  24. package/lib/offchain/initializer/user/index.d.ts +2 -0
  25. package/lib/offchain/initializer/user/index.js +18 -0
  26. package/lib/offchain/initializer/user/lendingPools.d.ts +6 -0
  27. package/lib/offchain/initializer/user/lendingPools.js +89 -0
  28. package/lib/offchain/initializer/user/positions.d.ts +12 -0
  29. package/lib/offchain/initializer/user/positions.js +63 -0
  30. package/lib/offchain/initializer/user/vaults.d.ts +9 -0
  31. package/lib/offchain/initializer/user/vaults.js +71 -0
  32. package/lib/offchain/initializer/vaults.d.ts +7 -0
  33. package/lib/offchain/initializer/vaults.js +103 -0
  34. package/lib/offchain/initializer/whitelist.d.ts +7 -0
  35. package/lib/offchain/initializer/whitelist.js +69 -0
  36. package/lib/offchain/offchain.d.ts +6 -6
  37. package/lib/offchain/offchain.js +1 -1
  38. package/lib/offchain/offchainEndpointManager.js +1 -0
  39. package/lib/offchain/offchainTypes.d.ts +58 -48
  40. package/lib/offchain/offchainTypes.js +4 -0
  41. package/lib/offchain/queries/apis/ponder/index.js +35 -27
  42. package/package.json +1 -1
  43. package/lib/offchain/offchainInitializer.d.ts +0 -52
  44. package/lib/offchain/offchainInitializer.js +0 -839
@@ -104,7 +104,7 @@ exports.IMPERMAX_SUBGRAPH_URL = {
104
104
  "https://base-factory-production.up.railway.app/",
105
105
  ],
106
106
  [types_1.Factory.V3]: [
107
- "https://impermax-indexer-production.up.railway.app/",
107
+ "https://new-factory-v3-production.up.railway.app/",
108
108
  ],
109
109
  },
110
110
  [types_1.Networks.Scroll]: {
package/lib/index.d.ts CHANGED
@@ -38,4 +38,5 @@ import { VaultRisk } from "./offchain/vault/offchainVault";
38
38
  import { LendingPoolVersion } from "./offchain/lendingPool/offchainLendingPool";
39
39
  import { PositionType, AccountPosition } from "./offchain/account/offchainMultichainAccount";
40
40
  import { OnchainInteractionsNftlpUniswapV3 } from './onchain/interactions/lendingPool/nftlp';
41
- 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, getFactoryByAddress, 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, Extension, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable, OnchainInteractionsLendingPoolV3, OnchainInteractionsNftlpUniswapV3 };
41
+ import { decimalToBalance } from './utils/ether-utils';
42
+ 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, getFactoryByAddress, 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, Extension, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable, OnchainInteractionsLendingPoolV3, OnchainInteractionsNftlpUniswapV3, decimalToBalance };
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.Amms = exports.PoolTokenType = exports.Extension = 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.getFactoryByAddress = exports.getNetworkFactories = exports.IMPERMAX_FACTORY = exports.IMX = exports.IMPERMAX_CHEF = exports.CLAIM_AGGREGATOR = exports.NO_CHANGES = exports.ApprovalType = exports.OnchainInteractionsConfigManager = void 0;
28
- exports.OnchainInteractionsNftlpUniswapV3 = exports.OnchainInteractionsLendingPoolV3 = exports.Borrowable = exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = void 0;
28
+ exports.decimalToBalance = exports.OnchainInteractionsNftlpUniswapV3 = exports.OnchainInteractionsLendingPoolV3 = exports.Borrowable = exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = 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; } });
@@ -178,3 +178,6 @@ Object.defineProperty(exports, "PositionType", { enumerable: true, get: function
178
178
  // Nftlp
179
179
  const nftlp_1 = require("./onchain/interactions/lendingPool/nftlp");
180
180
  Object.defineProperty(exports, "OnchainInteractionsNftlpUniswapV3", { enumerable: true, get: function () { return nftlp_1.OnchainInteractionsNftlpUniswapV3; } });
181
+ // Utils
182
+ const ether_utils_1 = require("./utils/ether-utils");
183
+ Object.defineProperty(exports, "decimalToBalance", { enumerable: true, get: function () { return ether_utils_1.decimalToBalance; } });
@@ -17,15 +17,15 @@ export default class OffchainAccountLendingPoolV3 extends OffchainAccountLending
17
17
  };
18
18
  protected getNewCollateralObject(): OffchainAccountCollateralV3;
19
19
  protected getNewBorrowableObject(borrowable: Borrowable): OffchainAccountBorrowableV3;
20
+ protected getId: () => any;
21
+ protected getFactory: () => import("../../../config/types").Factory;
22
+ constructor(account: OffchainAccount, lendingPool: OffchainLendingPool);
20
23
  getLendingPool: () => OffchainLendingPoolV3;
21
24
  getBorrowable: (borrowable: Borrowable) => OffchainAccountBorrowableV3;
22
25
  getBorrowableA: () => OffchainAccountBorrowableV3;
23
26
  getBorrowableB: () => OffchainAccountBorrowableV3;
24
27
  getCollateral: () => OffchainAccountCollateralV3;
25
- constructor(account: OffchainAccount, lendingPool: OffchainLendingPool);
26
28
  getAccount: () => OffchainAccount;
27
- protected getFactory: () => import("../../../config/types").Factory;
28
- protected getId: () => any;
29
29
  getSafetyMargin: () => Promise<number>;
30
30
  getLiquidationPenalty: () => Promise<number>;
31
31
  getNftlp: () => import("./nftlp/offchainAccountNftlp").default;
@@ -36,4 +36,5 @@ export default class OffchainAccountLendingPoolV3 extends OffchainAccountLending
36
36
  getLeveragedPositions(): Promise<Array<OffchainLeveragedPosition>>;
37
37
  getLeveragedPositionsTotalBalanceUSD(): Promise<number>;
38
38
  getLeveragedPositionsNetAPR(): Promise<number>;
39
+ getTokenIds(): Promise<(string | undefined)[]>;
39
40
  }
@@ -26,15 +26,15 @@ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default
26
26
  constructor(account, lendingPool) {
27
27
  super(account, lendingPool);
28
28
  // Shortcuts
29
+ this.getId = () => this.getId();
30
+ this.getFactory = () => this.lendingPool.getFactory();
31
+ // Shortcuts
29
32
  this.getLendingPool = () => this.lendingPool;
30
33
  this.getBorrowable = (borrowable) => this.borrowables[borrowable];
31
34
  this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
32
35
  this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
33
36
  this.getCollateral = () => this.collateral;
34
- // Shortcuts
35
37
  this.getAccount = () => this.account;
36
- this.getFactory = () => this.lendingPool.getFactory();
37
- this.getId = () => this.getId();
38
38
  this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getSafetyMargin(); });
39
39
  this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getLiquidationPenalty(); });
40
40
  this.getNftlp = () => this.collateral.getNftlp();
@@ -60,6 +60,9 @@ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default
60
60
  };
61
61
  });
62
62
  }
63
+ // Gets the token ids for a user
64
+ //public async getTotalBorrowsUSD(): Promise<number> {
65
+ //}
63
66
  getLeveragedPositions() {
64
67
  return __awaiter(this, void 0, void 0, function* () {
65
68
  return [];
@@ -75,5 +78,17 @@ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default
75
78
  return 1;
76
79
  });
77
80
  }
81
+ getTokenIds() {
82
+ var _a, _b;
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const userData = yield this.account.getUserData();
85
+ if (!userData)
86
+ return [];
87
+ const factory = this.getLendingPool().getFactory();
88
+ const pairAddress = this.getLendingPool().getPairAddress();
89
+ const positions = ((_b = (_a = userData[factory]) === null || _a === void 0 ? void 0 : _a.positions) === null || _b === void 0 ? void 0 : _b[pairAddress]) || [];
90
+ return positions.map(pos => pos.tokenId);
91
+ });
92
+ }
78
93
  }
79
94
  exports.default = OffchainAccountLendingPoolV3;
@@ -70,10 +70,8 @@ class OffchainAccount {
70
70
  for (const factory in userData) {
71
71
  result[factory] = [];
72
72
  const collateralPositions = userData[factory].collateralPositions;
73
- // 1-to-many relationship between lending pool and borrow positions
74
73
  for (const lendingPool in collateralPositions) {
75
- const positions = collateralPositions[lendingPool];
76
- positions.forEach(() => result[factory].push(lendingPool));
74
+ result[factory].push(lendingPool);
77
75
  }
78
76
  }
79
77
  return result;
@@ -79,7 +79,6 @@ class OffchainMultichainAccount {
79
79
  return results.flat();
80
80
  });
81
81
  }
82
- // NOTE: Should this return OffchainCollateral?
83
82
  getBorrowPositions(params = {}, orderBy = BorrowPositionsOrderBy.TVL) {
84
83
  var _a;
85
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,7 @@
1
+ import { DocumentNode } from "graphql";
2
+ /**
3
+ * Apollo client to fetch queries. In case where data endpoints return different
4
+ * data structures (for example with ponder endpoints) then it transforms the data
5
+ * if needed.
6
+ */
7
+ export declare function apolloFetcher(subgraphUrl: string, query: DocumentNode): Promise<import("apollo-client").ApolloQueryResult<any>>;
@@ -0,0 +1,40 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.apolloFetcher = void 0;
16
+ const apollo_client_1 = __importDefault(require("apollo-client"));
17
+ const apollo_link_http_1 = require("apollo-link-http");
18
+ const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
19
+ const queries_1 = require("../queries");
20
+ /**
21
+ * Apollo client to fetch queries. In case where data endpoints return different
22
+ * data structures (for example with ponder endpoints) then it transforms the data
23
+ * if needed.
24
+ */
25
+ function apolloFetcher(subgraphUrl, query) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const client = new apollo_client_1.default({
28
+ link: new apollo_link_http_1.HttpLink({
29
+ uri: subgraphUrl
30
+ }),
31
+ cache: new apollo_cache_inmemory_1.InMemoryCache(),
32
+ });
33
+ const result = yield client.query({
34
+ query: query,
35
+ fetchPolicy: "cache-first",
36
+ });
37
+ return queries_1.QueryBuilderFactory.transformData(result);
38
+ });
39
+ }
40
+ exports.apolloFetcher = apolloFetcher;
@@ -0,0 +1,2 @@
1
+ import Offchain from "../offchain";
2
+ export declare function fetchBlockByTimestamp(this: Offchain, timestamp: number): Promise<number | null>;
@@ -0,0 +1,33 @@
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
+ exports.fetchBlockByTimestamp = void 0;
13
+ const queries_1 = require("../queries");
14
+ const subgraphs_1 = require("../../config/subgraphs");
15
+ // TODO: Deprecate this?
16
+ function fetchBlockByTimestamp(timestamp) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ if (subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network].length == 0)
20
+ return null;
21
+ const subgraph = subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network];
22
+ const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
23
+ const result = yield this.apolloFetcher(subgraph, query.blockQuery(timestamp));
24
+ if (!result.data.blocks[0])
25
+ return null;
26
+ return result.data.blocks[0].number;
27
+ }
28
+ catch (e) {
29
+ return null;
30
+ }
31
+ });
32
+ }
33
+ exports.fetchBlockByTimestamp = fetchBlockByTimestamp;
@@ -0,0 +1,9 @@
1
+ import { Address, AddressIndex } from "../../config/types";
2
+ import Offchain from "../offchain";
3
+ /**
4
+ * Impermax Chef rewards
5
+ */
6
+ export declare function fetchImpermaxChefRewardRates(this: Offchain): Promise<AddressIndex<Array<{
7
+ rewardToken: Address;
8
+ rewardRate: number;
9
+ }>> | null>;
@@ -0,0 +1,55 @@
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
+ exports.fetchImpermaxChefRewardRates = void 0;
13
+ const queries_1 = require("../queries");
14
+ const subgraphs_1 = require("../../config/subgraphs");
15
+ /**
16
+ * Impermax Chef rewards
17
+ */
18
+ function fetchImpermaxChefRewardRates() {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const subgraph = subgraphs_1.IMPERMAX_CHEF_SUBGRAPH_URL[this.network];
21
+ const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
22
+ // `impermaxChefQuery` is optional, see `offchain/queries/interfaces/query-builder.ts`
23
+ // Since it's not part of core, one endpoint should suffice
24
+ if (!subgraph || !query.impermaxChefQuery)
25
+ return null;
26
+ const result = yield this.apolloFetcher(subgraph, query.impermaxChefQuery());
27
+ const rewards = {};
28
+ let rewardToken = result.data.impermaxChefs[0].rewardToken;
29
+ let rewardPerSec = parseFloat(result.data.impermaxChefs[0].rewardPerSec);
30
+ let totalAllocPoint = parseFloat(result.data.impermaxChefs[0].totalAllocPoint);
31
+ const impermaxRewarders = result.data.impermaxRewarders;
32
+ for (const pool of result.data.pools) {
33
+ rewards[pool.id] = [];
34
+ rewards[pool.id].push({
35
+ rewardToken,
36
+ rewardRate: (parseFloat(pool.allocPoint) / totalAllocPoint) * rewardPerSec,
37
+ });
38
+ }
39
+ for (const impermaxRewarder of impermaxRewarders) {
40
+ rewardToken = impermaxRewarder.rewardToken;
41
+ rewardPerSec = parseFloat(impermaxRewarder.rewardPerSec);
42
+ totalAllocPoint = parseFloat(impermaxRewarder.totalAllocPoint);
43
+ for (const pool of impermaxRewarder.pools) {
44
+ if (!(pool.borrowable in rewards))
45
+ rewards[pool.borrowable] = [];
46
+ rewards[pool.borrowable].push({
47
+ rewardToken,
48
+ rewardRate: (parseFloat(pool.allocPoint) / totalAllocPoint) * rewardPerSec,
49
+ });
50
+ }
51
+ }
52
+ return rewards;
53
+ });
54
+ }
55
+ exports.fetchImpermaxChefRewardRates = fetchImpermaxChefRewardRates;
@@ -0,0 +1,10 @@
1
+ export * from './apollo';
2
+ export * from './blocks';
3
+ export * from './lendingPools';
4
+ export * from './lendingPoolsPast';
5
+ export * from './vaults';
6
+ export * from './user';
7
+ export * from './whitelist';
8
+ export * from './staking';
9
+ export * from './farming';
10
+ export * from './tvl';
@@ -0,0 +1,26 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./apollo"), exports);
18
+ __exportStar(require("./blocks"), exports);
19
+ __exportStar(require("./lendingPools"), exports);
20
+ __exportStar(require("./lendingPoolsPast"), exports);
21
+ __exportStar(require("./vaults"), exports);
22
+ __exportStar(require("./user"), exports);
23
+ __exportStar(require("./whitelist"), exports);
24
+ __exportStar(require("./staking"), exports);
25
+ __exportStar(require("./farming"), exports);
26
+ __exportStar(require("./tvl"), exports);
@@ -0,0 +1,7 @@
1
+ import { LendingPoolData } from "../offchainTypes";
2
+ import { Factory, LendingPoolIndex, FactoryIndex, Address } from "../../config/types";
3
+ import Offchain from "../offchain";
4
+ export declare function getLendingPoolsData(this: Offchain): Promise<LendingPoolIndex<LendingPoolData>>;
5
+ export declare function getLendingPoolData(this: Offchain, factory: Factory, uniswapV2PairAddress: Address): Promise<LendingPoolData>;
6
+ export declare function initializeLendingPoolsData(this: Offchain): Promise<LendingPoolIndex<LendingPoolData>>;
7
+ export declare function fetchLendingPools(this: Offchain): Promise<FactoryIndex<LendingPoolData[]>>;
@@ -0,0 +1,219 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchLendingPools = exports.initializeLendingPoolsData = exports.getLendingPoolData = exports.getLendingPoolsData = void 0;
16
+ const amms_1 = require("../../config/amms");
17
+ const offchainTypes_1 = require("../offchainTypes");
18
+ const subgraphs_1 = require("../../config/subgraphs");
19
+ const types_1 = require("../../config/types");
20
+ const offchainLendingPoolV2_1 = __importDefault(require("../lendingPool/offchainLendingPoolV2"));
21
+ const offchainLendingPoolV3_1 = __importDefault(require("../lendingPool/offchainLendingPoolV3"));
22
+ /*--------------------------------------------------------------------------*
23
+ * Getters *
24
+ *--------------------------------------------------------------------------*/
25
+ function getLendingPoolsData() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ if (!this.lendingPoolsData)
28
+ this.lendingPoolsData = this.initializeLendingPoolsData();
29
+ return this.lendingPoolsData;
30
+ });
31
+ }
32
+ exports.getLendingPoolsData = getLendingPoolsData;
33
+ function getLendingPoolData(factory, uniswapV2PairAddress) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const lendingPoolsData = (yield this.getLendingPoolsData())[factory];
36
+ return lendingPoolsData[uniswapV2PairAddress.toLowerCase()];
37
+ });
38
+ }
39
+ exports.getLendingPoolData = getLendingPoolData;
40
+ /*--------------------------------------------------------------------------*
41
+ * Initializers *
42
+ *--------------------------------------------------------------------------*/
43
+ // OffchainLendingPool Data
44
+ function initializeLendingPoolsData() {
45
+ var _a, _b, _c;
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const lendingPoolsData = {};
48
+ // Get raw data
49
+ const [lendingPools, lendingPoolsPast24h, lendingPoolsPast7d, impermaxChefRewardRates,] = yield Promise.all([
50
+ this.fetchLendingPools(),
51
+ this.fetchLendingPoolsPast(24 * 3600),
52
+ this.fetchLendingPoolsPast(7 * 24 * 3600),
53
+ this.fetchImpermaxChefRewardRates(),
54
+ ]);
55
+ // Get Uniswap APR
56
+ const lendingPoolsByAmm = {};
57
+ for (const factory in lendingPools) {
58
+ for (const lendingPool of lendingPools[factory]) {
59
+ const amm = (0, amms_1.getAmmByFactory)(this.network,
60
+ // WARN: Quick temporary fix, to be removed after
61
+ (_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);
62
+ if (!amm)
63
+ continue;
64
+ if (!lendingPoolsByAmm[amm])
65
+ lendingPoolsByAmm[amm] = [];
66
+ const lendingPoolsOfAmm = lendingPoolsByAmm[amm];
67
+ lendingPoolsOfAmm.push(lendingPool);
68
+ }
69
+ }
70
+ // const uniswapAPR = await this.fetchUniswapAPR(lendingPoolsByAmm);
71
+ // Organize lending pools data
72
+ for (const factory in lendingPools) {
73
+ for (const lendingPool of lendingPools[factory]) {
74
+ // WARN: Quick temporary fix, to be removed after
75
+ if ((0, offchainTypes_1.isV3)(factory))
76
+ lendingPool["pair"] = lendingPool["nftlp"];
77
+ lendingPool.pair.uniswapAPR = 0;
78
+ if (impermaxChefRewardRates) {
79
+ lendingPool.borrowable0.rewards =
80
+ impermaxChefRewardRates[lendingPool.borrowable0.id];
81
+ lendingPool.borrowable1.rewards =
82
+ impermaxChefRewardRates[lendingPool.borrowable1.id];
83
+ }
84
+ // If one of the price of the 2 tokens is 0, fix the collateral price by doubling it
85
+ if (parseFloat(lendingPool.borrowable0.underlying.derivedUSD) === 0 ||
86
+ parseFloat(lendingPool.borrowable1.underlying.derivedUSD) === 0) {
87
+ lendingPool.pair.derivedUSD = (parseFloat(lendingPool.pair.derivedUSD) * 2).toString();
88
+ }
89
+ if (!lendingPoolsData[factory])
90
+ lendingPoolsData[factory] = {};
91
+ lendingPoolsData[factory][lendingPool.id] = lendingPool;
92
+ }
93
+ // Add past data
94
+ if (lendingPoolsPast24h) {
95
+ const lendingPoolsPast24hOfFactory = lendingPoolsPast24h[factory];
96
+ if (lendingPoolsPast24hOfFactory) {
97
+ for (const lendingPool of lendingPoolsPast24hOfFactory) {
98
+ lendingPoolsData[factory][lendingPool.id].past24h = lendingPool;
99
+ }
100
+ }
101
+ }
102
+ if (lendingPoolsPast7d) {
103
+ const lendingPoolsPast7dhOfFactory = lendingPoolsPast7d[factory];
104
+ if (lendingPoolsPast7dhOfFactory) {
105
+ for (const lendingPool of lendingPoolsPast7dhOfFactory) {
106
+ lendingPoolsData[factory][lendingPool.id].past7d = lendingPool;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ // Initialize OffchainLendingPool objects
112
+ this.lendingPools = {};
113
+ for (const factory in lendingPools) {
114
+ this.lendingPools[factory] = {};
115
+ for (const lendingPool of lendingPools[factory]) {
116
+ const isV2 = Number(factory) < 8;
117
+ this.lendingPools[factory][lendingPool.id] = isV2 ?
118
+ new offchainLendingPoolV2_1.default(this, factory, lendingPool.id)
119
+ : new offchainLendingPoolV3_1.default(this, factory, lendingPool.id);
120
+ }
121
+ }
122
+ // Quickfix for MIM and SPELL
123
+ if (this.network === types_1.Networks.Arbitrum) {
124
+ // const ETH_MIM = '0xa6e69dd0c36f3b59539e2c7afd274ef91b5c70f9';
125
+ // const ETH_SPELL = '0x35b44b303eacb71114aa62fe8dae6f9c5de0f680';
126
+ const ETH_gGOHM = "0x6d94f7e67c6ae0b0257c35754e059fdfb249d998";
127
+ const ETH_MAGIC = "0x88a0b00bbe918ee00e3482f71962070dc052984b";
128
+ const ETH_RDNT = "0xfb468ad210d427d65c9a765a480649d5754ca325";
129
+ // const LIZ_LIZ_ETH = '0x699c5e23357ab1bf658bd0b38070d746e37671f3';
130
+ // const LIZ_ETH_USDC = '0x1229aac120ae75301ab1c3a2a04ec14183493584';
131
+ // const LIZ_ETH_BTC = '0xce009c44e1645bc6d19c90ba440c618a42ae581d';
132
+ // const LIZ_LIZ_USDC = '0x463ec151258370a07431068bb3bdc98b5a6ba18f';
133
+ const lendingPoolsDataV2V1_1 = lendingPoolsData[types_1.Factory.V2V1_1];
134
+ if (lendingPoolsDataV2V1_1) {
135
+ if (lendingPoolsDataV2V1_1[ETH_gGOHM]) {
136
+ //lendingPoolsData[Factory.V2V1_1][ETH_SPELL].pair.rewards[0].rewardRate = '8.44';
137
+ //lendingPoolsData[Factory.V2V1_1][ETH_MIM].pair.rewards[0].rewardRate = '30.64';
138
+ //lendingPoolsData[Factory.V2V1_1][ETH_gGOHM].pair.rewards[0].rewardRate = '0.000009129';
139
+ lendingPoolsDataV2V1_1[ETH_MAGIC].pair.rewards[0].rewardRate = "0.135";
140
+ }
141
+ }
142
+ const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
143
+ if (lendingPoolsDataV2V2) {
144
+ if (lendingPoolsDataV2V2[ETH_RDNT]) {
145
+ lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate = (parseFloat(lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate) / 2).toString();
146
+ }
147
+ }
148
+ }
149
+ if (this.network === types_1.Networks.Polygon) {
150
+ const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
151
+ if (lendingPoolsDataV2V2) {
152
+ const GNS_DAI = "0xf9221c5edc736d26ffc4ddccddfa15a4b958862e";
153
+ if (lendingPoolsDataV2V2[GNS_DAI]) {
154
+ const GNS = lendingPoolsDataV2V2[GNS_DAI].borrowable1.underlying;
155
+ lendingPoolsDataV2V2[GNS_DAI].pair.rewards[0] = {
156
+ id: "",
157
+ rewardsToken: GNS,
158
+ rewardRate: "0.00608",
159
+ periodFinish: "0",
160
+ };
161
+ lendingPoolsDataV2V2[GNS_DAI].pair.stakedTotalSupply = "1640000";
162
+ }
163
+ }
164
+ }
165
+ if (this.network === types_1.Networks.Avalanche) {
166
+ const lendingPoolsDataV2V1_2 = lendingPoolsData[types_1.Factory.V2V1_2];
167
+ if (lendingPoolsDataV2V1_2) {
168
+ const QI_AVAX = "0x3e2a4dcd46e0e339aec603080d90bd939a163062";
169
+ if (lendingPoolsDataV2V1_2[QI_AVAX]) {
170
+ const QI = lendingPoolsDataV2V1_2[QI_AVAX].borrowable0.underlying;
171
+ lendingPoolsDataV2V1_2[QI_AVAX].pair.rewards[0] = {
172
+ id: "",
173
+ rewardsToken: QI,
174
+ rewardRate: "4.54",
175
+ periodFinish: "0",
176
+ };
177
+ // TODO -> this is wrong
178
+ lendingPoolsDataV2V1_2[QI_AVAX].pair.stakedTotalSupply =
179
+ "0.000000992210460243"; //https://snowtrace.io/token/0xe530dc2095ef5653205cf5ea79f8979a7028065c?a=0x784da19e61cf348a8c54547531795ecfee2affd1
180
+ }
181
+ }
182
+ }
183
+ return lendingPoolsData;
184
+ });
185
+ }
186
+ exports.initializeLendingPoolsData = initializeLendingPoolsData;
187
+ /*--------------------------------------------------------------------------*
188
+ * Fetchers *
189
+ *--------------------------------------------------------------------------*/
190
+ function fetchLendingPools() {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const calls = [];
193
+ const factories = [];
194
+ let factory;
195
+ for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
196
+ const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
197
+ calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, this.whitelistedPairs[factory], this.network)));
198
+ factories.push(factory);
199
+ }
200
+ const results = yield Promise.all(calls);
201
+ const lendingPools = {};
202
+ results.forEach((result, index) => {
203
+ var _a;
204
+ // `offchainEndpointManager` returns null when using filters and cant find subgraph with filter
205
+ if (!result)
206
+ return;
207
+ // Get the factory for this result
208
+ const factory = factories[index];
209
+ // Get pools data
210
+ const poolsForFactory = (_a = result.data) === null || _a === void 0 ? void 0 : _a.lendingPools;
211
+ if (!poolsForFactory)
212
+ return;
213
+ // Add all pools for this factory
214
+ lendingPools[factory] = poolsForFactory;
215
+ });
216
+ return lendingPools;
217
+ });
218
+ }
219
+ exports.fetchLendingPools = fetchLendingPools;
@@ -0,0 +1,13 @@
1
+ import { Amms } from "../../config/amms";
2
+ import { LendingPoolData } from "../offchainTypes";
3
+ import Offchain from "../offchain";
4
+ import { FactoryIndex, AddressIndex } from "../../config/types";
5
+ export declare function fetchPastVolume(this: Offchain, amm: Amms, lendingPools: LendingPoolData[], seconds: number): Promise<AddressIndex<number>>;
6
+ export declare function fetchCurrentVolumeAndReserves(this: Offchain, amm: Amms, lendingPools: LendingPoolData[]): Promise<{
7
+ currentVolume: AddressIndex<number>;
8
+ currentReserve: AddressIndex<number>;
9
+ }>;
10
+ export declare function fetchUniswapAPR(this: Offchain, lendingPoolsByAmm: {
11
+ [key in Amms]?: LendingPoolData[];
12
+ }, seconds?: number): Promise<AddressIndex<number>>;
13
+ export declare function fetchLendingPoolsPast(this: Offchain, seconds: number): Promise<FactoryIndex<any[]> | null>;