impermax-sdk 1.2.5 → 1.2.6

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.
@@ -20,3 +20,19 @@ export declare const CONFIG_MANAGER_SUBGRAPH_URL: {
20
20
  moonbeam: string;
21
21
  sxnetwork: string;
22
22
  };
23
+ export declare const WHITELIST_SUBGRAPH_URL: {
24
+ ropsten: string;
25
+ mainnet: string;
26
+ polygon: string;
27
+ arbitrum: string;
28
+ avalanche: string;
29
+ moonriver: string;
30
+ aurora: string;
31
+ cronos: string;
32
+ fantom: string;
33
+ canto: string;
34
+ "zksync-era": string;
35
+ harmony: string;
36
+ moonbeam: string;
37
+ sxnetwork: string;
38
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG_MANAGER_SUBGRAPH_URL = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.LENDING_VAULT_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = void 0;
3
+ exports.WHITELIST_SUBGRAPH_URL = exports.CONFIG_MANAGER_SUBGRAPH_URL = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.LENDING_VAULT_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = void 0;
4
4
  const types_1 = require("./types");
5
5
  exports.IMPERMAX_SUBGRAPH_URL = {
6
6
  [types_1.Networks.Ropsten]: {
@@ -113,3 +113,19 @@ exports.CONFIG_MANAGER_SUBGRAPH_URL = {
113
113
  [types_1.Networks.Moonbeam]: '',
114
114
  [types_1.Networks.Sxnetwork]: '',
115
115
  };
116
+ exports.WHITELIST_SUBGRAPH_URL = {
117
+ [types_1.Networks.Ropsten]: '',
118
+ [types_1.Networks.Mainnet]: '',
119
+ [types_1.Networks.Polygon]: 'https://api.thegraph.com/subgraphs/name/impermax-finance/impermax-whitelist-polygon',
120
+ [types_1.Networks.Arbitrum]: '',
121
+ [types_1.Networks.Avalanche]: '',
122
+ [types_1.Networks.Moonriver]: '',
123
+ [types_1.Networks.Aurora]: '',
124
+ [types_1.Networks.Cronos]: '',
125
+ [types_1.Networks.Fantom]: '',
126
+ [types_1.Networks.Canto]: '',
127
+ [types_1.Networks.ZksyncEra]: '',
128
+ [types_1.Networks.Harmony]: '',
129
+ [types_1.Networks.Moonbeam]: '',
130
+ [types_1.Networks.Sxnetwork]: '',
131
+ };
@@ -1,6 +1,6 @@
1
1
  import { PairConfigData } from '../offchainTypes';
2
2
  import OffchainLendingPool from '../lendingPool';
3
- import { Address, Factory, PoolTokenType } from '../../config/types';
3
+ import { Address, Factory, PoolTokenType, WhitelistState } from '../../config/types';
4
4
  import OffchainProposal from './offchainProposal';
5
5
  export default class OffchainPairConfig {
6
6
  private readonly proposal;
@@ -18,7 +18,7 @@ export default class OffchainPairConfig {
18
18
  getSafetyMargin(): Promise<number>;
19
19
  getLiquidationIncentive(): Promise<number>;
20
20
  getLiquidationFee(): Promise<number>;
21
- getWhitelisted(): Promise<boolean>;
21
+ getWhitelistState(): Promise<WhitelistState>;
22
22
  getBorrowableConfig(poolTokenType: PoolTokenType): {
23
23
  getReserveFactor: () => Promise<number>;
24
24
  getKinkUtilizationRate: () => Promise<number>;
@@ -60,9 +60,9 @@ class OffchainPairConfig {
60
60
  return this.getProposalParamFloat("liquidationFee");
61
61
  });
62
62
  }
63
- getWhitelisted() {
63
+ getWhitelistState() {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
- return this.pairConfigData["whiteListState"] > 0;
65
+ return this.pairConfigData["whiteListState"];
66
66
  });
67
67
  }
68
68
  getBorrowableConfig(poolTokenType) {
@@ -1,5 +1,5 @@
1
1
  import Offchain from '../index';
2
- import { Address, Factory, PoolTokenType } from '../../config/types';
2
+ import { Address, Factory, PoolTokenType, WhitelistState } from '../../config/types';
3
3
  import OffchainCollateral from './offchainCollateral';
4
4
  import OffchainBorrowable from './offchainBorrowable';
5
5
  import OffchainPoolToken from '../offchainPoolToken';
@@ -20,6 +20,7 @@ export default class OffchainLendingPool {
20
20
  getBorrowableB: () => OffchainBorrowable;
21
21
  getCollateral: () => OffchainCollateral;
22
22
  getLendingPoolData(): Promise<LendingPoolData>;
23
+ getWhitelistState(): Promise<WhitelistState>;
23
24
  getSafetyMargin(): Promise<number>;
24
25
  getLiquidationIncentive(): Promise<number>;
25
26
  getLiquidationFee(): Promise<number>;
@@ -46,6 +46,12 @@ class OffchainLendingPool {
46
46
  return this.offchain.getLendingPoolData(this.factory, this.pairAddress);
47
47
  });
48
48
  }
49
+ // Whitelist State
50
+ getWhitelistState() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return this.offchain.getWhitelistState(this.factory, this.pairAddress);
53
+ });
54
+ }
49
55
  // Safety Margin
50
56
  getSafetyMargin() {
51
57
  return __awaiter(this, void 0, void 0, function* () {
@@ -3,7 +3,7 @@ import OffchainLendingPool from "./lendingPool";
3
3
  import OffchainPriceHelper from "./offchainPriceHelper";
4
4
  import OffchainSolidexHelper from "./offchainSolidexHelper";
5
5
  import OffchainAccount from "./account";
6
- import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks } from '../config/types';
6
+ import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Networks, WhitelistState } from '../config/types';
7
7
  import { LendingPoolData, LendingVaultData, LendingVaultPosition, TvlData, UserData, XimxData } from './offchainTypes';
8
8
  import OffchainLendingVault from './offchainLendingVault';
9
9
  import OffchainConfigManager from './configManager';
@@ -32,6 +32,7 @@ export default class Offchain {
32
32
  };
33
33
  protected tvlData: Promise<TvlData> | null;
34
34
  protected ximxData: Promise<XimxData> | null;
35
+ protected whitelistData: Promise<LendingPoolIndex<WhitelistState>> | null;
35
36
  constructor(cfg: OffchainCfg);
36
37
  cleanCache(): void;
37
38
  getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
@@ -74,6 +75,10 @@ export default class Offchain {
74
75
  protected fetchLendingVaultsUserData: typeof initializer.fetchLendingVaultsUserData;
75
76
  protected initializeLendingVaultsUserData: typeof initializer.initializeLendingVaultsUserData;
76
77
  getLendingVaultsUserData: typeof initializer.getLendingVaultsUserData;
78
+ protected fetchWhitelist: typeof initializer.fetchWhitelist;
79
+ protected initializeWhitelistData: typeof initializer.initializeWhitelistData;
80
+ getWhitelistData: typeof initializer.getWhitelistData;
81
+ getWhitelistState: typeof initializer.getWhitelistState;
77
82
  /**
78
83
  * DATA GETTERS
79
84
  */
@@ -81,6 +81,10 @@ class Offchain {
81
81
  this.fetchLendingVaultsUserData = initializer.fetchLendingVaultsUserData;
82
82
  this.initializeLendingVaultsUserData = initializer.initializeLendingVaultsUserData;
83
83
  this.getLendingVaultsUserData = initializer.getLendingVaultsUserData;
84
+ this.fetchWhitelist = initializer.fetchWhitelist;
85
+ this.initializeWhitelistData = initializer.initializeWhitelistData;
86
+ this.getWhitelistData = initializer.getWhitelistData;
87
+ this.getWhitelistState = initializer.getWhitelistState;
84
88
  this.network = cfg.network;
85
89
  this.chainId = cfg.chainId;
86
90
  this.whitelistedPairs = cfg.whitelistedPairs ? cfg.whitelistedPairs : {};
@@ -98,6 +102,7 @@ class Offchain {
98
102
  this.lendingVaultsUsersData = {};
99
103
  this.tvlData = null;
100
104
  this.ximxData = null;
105
+ this.whitelistData = null;
101
106
  this.priceHelper.cleanCache();
102
107
  this.solidexHelper.cleanCache();
103
108
  this.configManager.cleanCache();
@@ -1,8 +1,8 @@
1
1
  import { ApolloQueryResult } from "apollo-client";
2
2
  import { DocumentNode } from "graphql";
3
- import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex } from '../config/types';
3
+ import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, WhitelistState } from '../config/types';
4
4
  import { Amms } from '../config/amms';
5
- import { LendingPoolData, LendingVaultData, LendingVaultPosition, RawUserData, TvlData, UserData, XimxData } from './offchainTypes';
5
+ import { LendingPoolData, LendingVaultData, LendingVaultPosition, RawUserData, TvlData, UserData, WhitelistData, XimxData } from './offchainTypes';
6
6
  import Offchain from './offchain';
7
7
  export declare function apolloFetcher(subgraphUrl: string, query: DocumentNode): Promise<ApolloQueryResult<any>>;
8
8
  export declare function fetchBlockByTimestamp(this: Offchain, timestamp: number): Promise<number | null>;
@@ -37,6 +37,16 @@ export declare function fetchLendingVaults(this: Offchain): Promise<LendingVault
37
37
  export declare function initializeLendingVaultsData(this: Offchain): Promise<AddressIndex<LendingVaultData>>;
38
38
  export declare function getLendingVaultsData(this: Offchain): Promise<AddressIndex<LendingVaultData>>;
39
39
  export declare function getLendingVaultData(this: Offchain, lendingVaultAddress: Address): Promise<LendingVaultData>;
40
+ /**
41
+ * Whitelist
42
+ */
43
+ export declare function fetchWhitelist(this: Offchain): Promise<WhitelistData[]>;
44
+ export declare function initializeWhitelistData(this: Offchain): Promise<LendingPoolIndex<WhitelistState>>;
45
+ export declare function getWhitelistData(this: Offchain): Promise<LendingPoolIndex<WhitelistState>>;
46
+ export declare function getWhitelistState(this: Offchain, factory: Factory, pair: Address): Promise<WhitelistState>;
47
+ /**
48
+ * User Data
49
+ */
40
50
  export declare function fetchLendingVaultsUserData(this: Offchain, account: Address): Promise<LendingVaultPosition[] | null>;
41
51
  export declare function initializeLendingVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<LendingVaultPosition> | null>;
42
52
  export declare function getLendingVaultsUserData(this: Offchain, account: Address): Promise<AddressIndex<LendingVaultPosition> | null>;
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.getLendingVaultsUserData = exports.initializeLendingVaultsUserData = exports.fetchLendingVaultsUserData = exports.getLendingVaultData = exports.getLendingVaultsData = exports.initializeLendingVaultsData = exports.fetchLendingVaults = exports.getXimxData = exports.initializeXimxData = exports.getUserData = exports.initializeUserData = exports.fetchUserData = exports.getTvlData = exports.initializeTvlData = exports.getLendingPoolData = exports.getLendingPoolsData = exports.initializeLendingPoolsData = exports.fetchUniswapAPR = exports.fetchCurrentVolumeAndReserves = exports.fetchPastVolume = exports.fetchImpermaxChefRewardRates = exports.fetchLendingPoolsPast = exports.fetchLendingPools = exports.fetchBlockByTimestamp = exports.apolloFetcher = void 0;
38
+ exports.getLendingVaultsUserData = exports.initializeLendingVaultsUserData = exports.fetchLendingVaultsUserData = exports.getWhitelistState = exports.getWhitelistData = exports.initializeWhitelistData = exports.fetchWhitelist = exports.getLendingVaultData = exports.getLendingVaultsData = exports.initializeLendingVaultsData = exports.fetchLendingVaults = exports.getXimxData = exports.initializeXimxData = exports.getUserData = exports.initializeUserData = exports.fetchUserData = exports.getTvlData = exports.initializeTvlData = exports.getLendingPoolData = exports.getLendingPoolsData = exports.initializeLendingPoolsData = exports.fetchUniswapAPR = exports.fetchCurrentVolumeAndReserves = exports.fetchPastVolume = exports.fetchImpermaxChefRewardRates = exports.fetchLendingPoolsPast = exports.fetchLendingPools = exports.fetchBlockByTimestamp = exports.apolloFetcher = void 0;
39
39
  const apollo_client_1 = __importDefault(require("apollo-client"));
40
40
  const apollo_link_http_1 = require("apollo-link-http");
41
41
  const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
@@ -45,6 +45,7 @@ const subgraphs_1 = require("../config/subgraphs");
45
45
  const types_1 = require("../config/types");
46
46
  const amms_1 = require("../config/amms");
47
47
  const offchainLendingVault_1 = __importDefault(require("./offchainLendingVault"));
48
+ const impermax_factories_1 = require("../config/contracts/impermax-factories");
48
49
  const SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
49
50
  function apolloFetcher(subgraphUrl, query) {
50
51
  return __awaiter(this, void 0, void 0, function* () {
@@ -670,7 +671,62 @@ function getLendingVaultData(lendingVaultAddress) {
670
671
  });
671
672
  }
672
673
  exports.getLendingVaultData = getLendingVaultData;
673
- // User Data
674
+ /**
675
+ * Whitelist
676
+ */
677
+ function fetchWhitelist() {
678
+ return __awaiter(this, void 0, void 0, function* () {
679
+ const subgraph = subgraphs_1.WHITELIST_SUBGRAPH_URL[this.network];
680
+ if (!subgraph)
681
+ return [];
682
+ const result = yield this.apolloFetcher(subgraph, query.whitelistQuery());
683
+ if (!result || !result.data.whitelistState)
684
+ return [];
685
+ return result.data.whitelistState;
686
+ });
687
+ }
688
+ exports.fetchWhitelist = fetchWhitelist;
689
+ function initializeWhitelistData() {
690
+ return __awaiter(this, void 0, void 0, function* () {
691
+ const whitelistData = {};
692
+ const whitelistPairsData = yield this.fetchWhitelist();
693
+ // Organize lending vaults data
694
+ for (const whitelistPairData of whitelistPairsData) {
695
+ const factory = (0, impermax_factories_1.getFactoryByAddress)(this.network, whitelistPairData.factory);
696
+ if (!factory)
697
+ continue;
698
+ if (!whitelistData[factory])
699
+ whitelistData[factory] = {};
700
+ const whitelistDataOfFactory = whitelistData[factory];
701
+ whitelistDataOfFactory[whitelistPairData.pair] = whitelistPairData.state;
702
+ }
703
+ return whitelistData;
704
+ });
705
+ }
706
+ exports.initializeWhitelistData = initializeWhitelistData;
707
+ function getWhitelistData() {
708
+ return __awaiter(this, void 0, void 0, function* () {
709
+ if (!this.whitelistData)
710
+ this.whitelistData = this.initializeWhitelistData();
711
+ return this.whitelistData;
712
+ });
713
+ }
714
+ exports.getWhitelistData = getWhitelistData;
715
+ function getWhitelistState(factory, pair) {
716
+ return __awaiter(this, void 0, void 0, function* () {
717
+ const whitelistData = yield this.getWhitelistData();
718
+ const whitelistDataOfFactory = whitelistData[factory];
719
+ if (!whitelistDataOfFactory)
720
+ return types_1.WhitelistState.Unlisted;
721
+ if (!whitelistDataOfFactory[pair.toLowerCase()])
722
+ return types_1.WhitelistState.Unlisted;
723
+ return whitelistDataOfFactory[pair.toLowerCase()];
724
+ });
725
+ }
726
+ exports.getWhitelistState = getWhitelistState;
727
+ /**
728
+ * User Data
729
+ */
674
730
  function fetchLendingVaultsUserData(account) {
675
731
  return __awaiter(this, void 0, void 0, function* () {
676
732
  const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
@@ -200,3 +200,11 @@ export interface ProposalMetadata {
200
200
  id: number;
201
201
  state: ProposalState;
202
202
  }
203
+ /**
204
+ * Whitelist
205
+ */
206
+ export interface WhitelistData {
207
+ factory: string;
208
+ pair: string;
209
+ state: WhitelistState;
210
+ }
@@ -12,3 +12,4 @@ export declare function lendingVaultsQuery(addressesFilter: Address[]): import("
12
12
  export declare function lendingVaultsUserQuery(account: Address): import("graphql").DocumentNode;
13
13
  export declare function proposalsMetaQuery(rangeBegin: any, rangeLength: any, descending: any): import("graphql").DocumentNode;
14
14
  export declare function proposalQuery(id: number): import("graphql").DocumentNode;
15
+ export declare function whitelistQuery(): import("graphql").DocumentNode;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.proposalQuery = exports.proposalsMetaQuery = exports.lendingVaultsUserQuery = exports.lendingVaultsQuery = exports.ximxQuery = exports.userQuery = exports.tvlQuery = exports.currentVolumeAndReservesQuery = exports.pastVolumeQuery = exports.impermaxChefQuery = exports.lendingPoolsPastQuery = exports.lendingPoolsQuery = exports.blockQuery = void 0;
6
+ exports.whitelistQuery = exports.proposalQuery = exports.proposalsMetaQuery = exports.lendingVaultsUserQuery = exports.lendingVaultsQuery = exports.ximxQuery = exports.userQuery = exports.tvlQuery = exports.currentVolumeAndReservesQuery = exports.pastVolumeQuery = exports.impermaxChefQuery = exports.lendingPoolsPastQuery = exports.lendingPoolsQuery = exports.blockQuery = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const factories_1 = require("../config/factories");
9
9
  function blockQuery(timestamp) {
@@ -308,3 +308,13 @@ function proposalQuery(id) {
308
308
  }`;
309
309
  }
310
310
  exports.proposalQuery = proposalQuery;
311
+ function whitelistQuery() {
312
+ return (0, graphql_tag_1.default) `{
313
+ whitelistStates(first:1000) {
314
+ factory
315
+ pair
316
+ state
317
+ }
318
+ }`;
319
+ }
320
+ exports.whitelistQuery = whitelistQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",