impermax-sdk 1.0.3 → 1.0.4

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 (108) hide show
  1. package/lib/abis/ImpermaxABI.d.ts +2 -0
  2. package/lib/abis/ImpermaxABI.js +3 -0
  3. package/lib/abis/contracts/ClaimAggregator.json +2015 -0
  4. package/lib/abis/contracts/IBorrowable.json +13207 -0
  5. package/lib/abis/contracts/IClaimable.json +406 -0
  6. package/lib/abis/contracts/ICollateral.json +8952 -0
  7. package/lib/abis/contracts/IERC20.json +2376 -0
  8. package/lib/abis/contracts/IFactory.json +3660 -0
  9. package/lib/abis/contracts/IFarmingPool.json +3584 -0
  10. package/lib/abis/contracts/IMerkleDistributor.json +1134 -0
  11. package/lib/abis/contracts/IRouter02.json +7283 -0
  12. package/lib/abis/contracts/ISimpleUniswapOracle.json +1469 -0
  13. package/lib/abis/contracts/IStakedLPToken.json +7309 -0
  14. package/lib/abis/contracts/IStakingRewards.json +1036 -0
  15. package/lib/abis/contracts/IUniswapV2Factory.json +1690 -0
  16. package/lib/abis/contracts/IUniswapV2Pair.json +6761 -0
  17. package/lib/abis/contracts/ImpermaxChef.json +20945 -0
  18. package/lib/config/amms.d.ts +25 -0
  19. package/lib/config/amms.js +196 -0
  20. package/lib/config/contracts/claim-aggregators.d.ts +2 -0
  21. package/lib/config/contracts/claim-aggregators.js +18 -0
  22. package/lib/config/contracts/impermax-chef.d.ts +2 -0
  23. package/lib/config/contracts/impermax-chef.js +18 -0
  24. package/lib/config/contracts/imxes.d.ts +2 -0
  25. package/lib/config/contracts/imxes.js +18 -0
  26. package/lib/config/contracts/merkle-distributors.d.ts +4 -0
  27. package/lib/config/contracts/merkle-distributors.js +13 -0
  28. package/lib/config/contracts/routers.d.ts +2 -0
  29. package/lib/config/contracts/routers.js +38 -0
  30. package/lib/config/contracts/simple-uniswap-oracles.d.ts +2 -0
  31. package/lib/config/contracts/simple-uniswap-oracles.js +35 -0
  32. package/lib/config/contracts/weths.d.ts +2 -0
  33. package/lib/config/contracts/weths.js +19 -0
  34. package/lib/config/debank-ids.d.ts +2 -0
  35. package/lib/config/debank-ids.js +17 -0
  36. package/lib/config/endpoints/merkle-distributors.d.ts +4 -0
  37. package/lib/config/endpoints/merkle-distributors.js +13 -0
  38. package/lib/config/eth.d.ts +3 -0
  39. package/lib/config/eth.js +32 -0
  40. package/lib/config/factories.d.ts +6 -0
  41. package/lib/config/factories.js +24 -0
  42. package/lib/config/farms.d.ts +59 -0
  43. package/lib/config/farms.js +114 -0
  44. package/lib/config/general.d.ts +3 -0
  45. package/lib/config/general.js +8 -0
  46. package/lib/config/subgraphs.d.ts +5 -0
  47. package/lib/config/subgraphs.js +68 -0
  48. package/lib/config/types.d.ts +67 -0
  49. package/lib/config/types.js +54 -0
  50. package/lib/impermax-router/Account.d.ts +31 -0
  51. package/lib/impermax-router/Account.js +154 -0
  52. package/lib/impermax-router/AccountBorrowable.d.ts +22 -0
  53. package/lib/impermax-router/AccountBorrowable.js +141 -0
  54. package/lib/impermax-router/AccountCollateral.d.ts +11 -0
  55. package/lib/impermax-router/AccountCollateral.js +63 -0
  56. package/lib/impermax-router/AccountLendingPool.d.ts +57 -0
  57. package/lib/impermax-router/AccountLendingPool.js +266 -0
  58. package/lib/impermax-router/AccountPoolToken.d.ts +29 -0
  59. package/lib/impermax-router/AccountPoolToken.js +89 -0
  60. package/lib/impermax-router/Borrowable.d.ts +27 -0
  61. package/lib/impermax-router/Borrowable.js +128 -0
  62. package/lib/impermax-router/Collateral.d.ts +9 -0
  63. package/lib/impermax-router/Collateral.js +45 -0
  64. package/lib/impermax-router/ContractsHelper.d.ts +28 -0
  65. package/lib/impermax-router/ContractsHelper.js +50 -0
  66. package/lib/impermax-router/ImpermaxFactory.d.ts +15 -0
  67. package/lib/impermax-router/ImpermaxFactory.js +42 -0
  68. package/lib/impermax-router/Interactions.d.ts +16 -0
  69. package/lib/impermax-router/Interactions.js +105 -0
  70. package/lib/impermax-router/InteractionsLendingPool.d.ts +43 -0
  71. package/lib/impermax-router/InteractionsLendingPool.js +124 -0
  72. package/lib/impermax-router/InteractionsPoolToken.d.ts +23 -0
  73. package/lib/impermax-router/InteractionsPoolToken.js +194 -0
  74. package/lib/impermax-router/LendingPool.d.ts +69 -0
  75. package/lib/impermax-router/LendingPool.js +291 -0
  76. package/lib/impermax-router/PoolToken.d.ts +36 -0
  77. package/lib/impermax-router/PoolToken.js +140 -0
  78. package/lib/impermax-router/index.d.ts +20 -0
  79. package/lib/impermax-router/index.js +34 -0
  80. package/lib/impermax-router/interfaces.d.ts +218 -0
  81. package/lib/impermax-router/interfaces.js +15 -0
  82. package/lib/index.d.ts +3 -0
  83. package/lib/index.js +10 -0
  84. package/lib/subgraph/Account.d.ts +18 -0
  85. package/lib/subgraph/Account.js +111 -0
  86. package/lib/subgraph/AccountLendingPool.d.ts +19 -0
  87. package/lib/subgraph/AccountLendingPool.js +71 -0
  88. package/lib/subgraph/AccountPoolToken.d.ts +14 -0
  89. package/lib/subgraph/AccountPoolToken.js +75 -0
  90. package/lib/subgraph/LendingPool.d.ts +38 -0
  91. package/lib/subgraph/LendingPool.js +204 -0
  92. package/lib/subgraph/PoolToken.d.ts +64 -0
  93. package/lib/subgraph/PoolToken.js +462 -0
  94. package/lib/subgraph/PriceHelper.d.ts +21 -0
  95. package/lib/subgraph/PriceHelper.js +166 -0
  96. package/lib/subgraph/SolidexHelper.d.ts +16 -0
  97. package/lib/subgraph/SolidexHelper.js +58 -0
  98. package/lib/subgraph/index.d.ts +73 -0
  99. package/lib/subgraph/index.js +185 -0
  100. package/lib/subgraph/initializer.d.ts +34 -0
  101. package/lib/subgraph/initializer.js +517 -0
  102. package/lib/subgraph/query.d.ts +10 -0
  103. package/lib/subgraph/query.js +229 -0
  104. package/lib/utils/ether-utils.d.ts +5 -0
  105. package/lib/utils/ether-utils.js +26 -0
  106. package/lib/utils/index.d.ts +3 -0
  107. package/lib/utils/index.js +16 -0
  108. package/package.json +2 -2
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ximxQuery = exports.userQuery = exports.tvlQuery = exports.currentVolumeAndReservesQuery = exports.pastVolumeQuery = exports.impermaxChefQuery = exports.lendingPoolsPastQuery = exports.lendingPoolsQuery = exports.blockQuery = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const factories_1 = require("../config/factories");
9
+ function blockQuery(timestamp) {
10
+ return (0, graphql_tag_1.default) `{
11
+ blocks (first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${timestamp + 600} }) {
12
+ number
13
+ }
14
+ _meta {
15
+ block {
16
+ number
17
+ }
18
+ }
19
+ }`;
20
+ }
21
+ exports.blockQuery = blockQuery;
22
+ function lendingPoolsQuery(factory, addressesFilter) {
23
+ const tokenStr = `{
24
+ id
25
+ symbol
26
+ name
27
+ decimals
28
+ derivedUSD
29
+ }`;
30
+ const distributorStr = `{
31
+ id
32
+ }`;
33
+ const farmingPoolStr = `{
34
+ epochAmount
35
+ epochBegin
36
+ segmentLength
37
+ vestingBegin
38
+ sharePercentage
39
+ distributor ${distributorStr}
40
+ }`;
41
+ const borrowableStr = `{
42
+ id
43
+ underlying ${tokenStr}
44
+ totalBalance
45
+ totalBorrows
46
+ borrowRate
47
+ reserveFactor
48
+ kinkBorrowRate
49
+ kinkUtilizationRate
50
+ borrowIndex
51
+ accrualTimestamp
52
+ exchangeRate
53
+ totalBalanceUSD
54
+ totalSupplyUSD
55
+ totalBorrowsUSD
56
+ farmingPool ${farmingPoolStr}
57
+ }`;
58
+ const collateralStr = `{
59
+ id
60
+ totalBalance
61
+ totalBalanceUSD
62
+ safetyMargin
63
+ liquidationIncentive
64
+ ${factories_1.LIQUIDATION_FEE_FACTORIES.includes(factory) ? "liquidationFee" : ""}
65
+ exchangeRate
66
+ }`;
67
+ const pairStr = `{
68
+ factory
69
+ reserve0
70
+ reserve1
71
+ totalSupply
72
+ reserveUSD
73
+ token0Price
74
+ token1Price
75
+ derivedUSD
76
+ uniswapV2PairAddress
77
+ uniswapV2Factory
78
+ isStakedLPToken
79
+ exchangeRate
80
+ stakingRewards
81
+ masterChef
82
+ pid
83
+ stakedTotalSupply
84
+ rewards {
85
+ id
86
+ rewardRate
87
+ rewardsToken ${tokenStr}
88
+ periodFinish
89
+ }
90
+ }`;
91
+ const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
92
+ return (0, graphql_tag_1.default) `{
93
+ lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc ${id_in_string}) {
94
+ id
95
+ borrowable0 ${borrowableStr}
96
+ borrowable1 ${borrowableStr}
97
+ collateral ${collateralStr}
98
+ pair ${pairStr}
99
+ }
100
+ _meta {
101
+ block {
102
+ number
103
+ }
104
+ hasIndexingErrors
105
+ }
106
+ }`;
107
+ }
108
+ exports.lendingPoolsQuery = lendingPoolsQuery;
109
+ function lendingPoolsPastQuery(blockNumber, addressesFilter) {
110
+ const borrowablePastStr = `{
111
+ borrowIndex
112
+ accrualTimestamp
113
+ exchangeRate
114
+ }`;
115
+ const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
116
+ return (0, graphql_tag_1.default) `{
117
+ lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc, block: {number: ${blockNumber}} ${id_in_string}) {
118
+ id
119
+ borrowable0 ${borrowablePastStr}
120
+ borrowable1 ${borrowablePastStr}
121
+ }
122
+ }`;
123
+ }
124
+ exports.lendingPoolsPastQuery = lendingPoolsPastQuery;
125
+ function impermaxChefQuery() {
126
+ return (0, graphql_tag_1.default) `{
127
+ impermaxChefs(first: 1) {
128
+ id
129
+ rewardToken
130
+ rewardPerSec
131
+ totalAllocPoint
132
+ }
133
+ pools(first: 1000) {
134
+ id
135
+ allocPoint
136
+ rewarder {id}
137
+ }
138
+ impermaxRewarders(first: 1000) {
139
+ rewardToken
140
+ rewardPerSec
141
+ totalAllocPoint
142
+ pools(first: 1000) {
143
+ borrowable
144
+ allocPoint
145
+ }
146
+ }
147
+ }`;
148
+ }
149
+ exports.impermaxChefQuery = impermaxChefQuery;
150
+ function pastVolumeQuery(blockNumber, addressesFilter) {
151
+ const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
152
+ return (0, graphql_tag_1.default) `{
153
+ pairs (block: {number: ${blockNumber}} ${id_in_string}) {
154
+ id
155
+ volumeUSD
156
+ }
157
+ }`;
158
+ }
159
+ exports.pastVolumeQuery = pastVolumeQuery;
160
+ function currentVolumeAndReservesQuery(addressesFilter) {
161
+ const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
162
+ return (0, graphql_tag_1.default) `{
163
+ pairs (${id_in_string}) {
164
+ id
165
+ reserveUSD
166
+ volumeUSD
167
+ }
168
+ }`;
169
+ }
170
+ exports.currentVolumeAndReservesQuery = currentVolumeAndReservesQuery;
171
+ function tvlQuery() {
172
+ return (0, graphql_tag_1.default) `{
173
+ impermaxFactories(first: 1) {
174
+ totalBalanceUSD
175
+ totalSupplyUSD
176
+ totalBorrowsUSD
177
+ }
178
+ }`;
179
+ }
180
+ exports.tvlQuery = tvlQuery;
181
+ function userQuery(account) {
182
+ return (0, graphql_tag_1.default) `{
183
+ user(id: "${account.toLowerCase()}") {
184
+ collateralPositions(first:1000) {
185
+ balance
186
+ collateral {
187
+ lendingPool {
188
+ id
189
+ }
190
+ }
191
+ }
192
+ supplyPositions(first:1000) {
193
+ balance
194
+ borrowable {
195
+ underlying {
196
+ id
197
+ }
198
+ lendingPool {
199
+ id
200
+ }
201
+ }
202
+ }
203
+ borrowPositions(first:1000) {
204
+ borrowBalance
205
+ borrowIndex
206
+ borrowable {
207
+ underlying {
208
+ id
209
+ }
210
+ lendingPool {
211
+ id
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }`;
217
+ }
218
+ exports.userQuery = userQuery;
219
+ function ximxQuery() {
220
+ return (0, graphql_tag_1.default) `{
221
+ ximxes(first: 1) {
222
+ totalSupply
223
+ totalBalance
224
+ exchangeRate
225
+ dailyAPR
226
+ }
227
+ }`;
228
+ }
229
+ exports.ximxQuery = ximxQuery;
@@ -0,0 +1,5 @@
1
+ import { BigNumber } from 'ethers';
2
+ export declare function balanceToDecimal(s: string): string;
3
+ export declare function formatToDecimals(n: number, decimals?: number): string;
4
+ export declare function decimalToBalance(d: string | number, decimals?: number): BigNumber;
5
+ export declare function address(n: number): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.address = exports.decimalToBalance = exports.formatToDecimals = exports.balanceToDecimal = void 0;
4
+ const utils_1 = require("ethers/lib/utils");
5
+ function balanceToDecimal(s) {
6
+ return (0, utils_1.formatUnits)(s);
7
+ }
8
+ exports.balanceToDecimal = balanceToDecimal;
9
+ function formatToDecimals(n, decimals = 2) {
10
+ if (n === null || n === undefined || isNaN(n))
11
+ return "-";
12
+ if (n == Infinity)
13
+ return "Infinity"; //return "∞";
14
+ return (Math.round(n * (Math.pow(10, decimals))) / (Math.pow(10, decimals))).toFixed(decimals);
15
+ }
16
+ exports.formatToDecimals = formatToDecimals;
17
+ function decimalToBalance(d, decimals = 18) {
18
+ const n = parseFloat(d.toString());
19
+ const s = formatToDecimals(Math.max(n, 0), decimals);
20
+ return (0, utils_1.parseUnits)(s, decimals);
21
+ }
22
+ exports.decimalToBalance = decimalToBalance;
23
+ function address(n) {
24
+ return `0x${n.toString(16).padStart(40, '0')}`;
25
+ }
26
+ exports.address = address;
@@ -0,0 +1,3 @@
1
+ export declare function toAPR(n: number): number;
2
+ export declare function impermanentLoss(priceSwing: number): number;
3
+ export declare function isValidNumber(n: number): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidNumber = exports.impermanentLoss = exports.toAPR = void 0;
4
+ function toAPR(n) {
5
+ const SECONDS_IN_YEAR = 365 * 24 * 3600;
6
+ return n * SECONDS_IN_YEAR;
7
+ }
8
+ exports.toAPR = toAPR;
9
+ function impermanentLoss(priceSwing) {
10
+ return Math.sqrt(priceSwing) / (priceSwing + 1) * 2;
11
+ }
12
+ exports.impermanentLoss = impermanentLoss;
13
+ function isValidNumber(n) {
14
+ return !(n === null || n === undefined || isNaN(n));
15
+ }
16
+ exports.isValidNumber = isValidNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "tsc": "tsc -p tsconfig.json",
13
- "prepublish": "npm run tsc"
13
+ "prepublishOnly": "npm run tsc"
14
14
  },
15
15
  "author": "",
16
16
  "license": "ISC",