impermax-sdk 1.2.102 → 1.2.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/subgraphs.d.ts +1 -1
- package/lib/config/subgraphs.js +40 -28
- package/lib/offchain/configManager/offchainConfigManagerInitializer.js +3 -24
- package/lib/offchain/offchain.d.ts +2 -0
- package/lib/offchain/offchain.js +2 -0
- package/lib/offchain/offchainEndpointManager.d.ts +25 -0
- package/lib/offchain/offchainEndpointManager.js +125 -0
- package/lib/offchain/offchainInitializer.js +61 -50
- package/lib/offchain/queries/apis/ponder/index.d.ts +14 -0
- package/lib/offchain/queries/apis/ponder/index.js +278 -0
- package/lib/offchain/queries/apis/thegraph/index.d.ts +19 -0
- package/lib/offchain/queries/apis/thegraph/index.js +349 -0
- package/lib/offchain/queries/index.d.ts +16 -0
- package/lib/offchain/queries/index.js +44 -0
- package/lib/offchain/queries/interfaces/query-builder.d.ts +19 -0
- package/lib/offchain/queries/interfaces/query-builder.js +2 -0
- package/lib/offchain/queries/interfaces/transformers.d.ts +0 -0
- package/lib/offchain/queries/interfaces/transformers.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,278 @@
|
|
|
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.PonderQueryBuilder = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const factories_1 = require("../../../../config/factories");
|
|
9
|
+
const impermax_factories_1 = require("../../../../config/contracts/impermax-factories");
|
|
10
|
+
class PonderQueryBuilder {
|
|
11
|
+
/*-----------------------------*
|
|
12
|
+
* 1. API Health
|
|
13
|
+
*-----------------------------*/
|
|
14
|
+
// Add queries here for metadata, health, etc.
|
|
15
|
+
blockQuery() {
|
|
16
|
+
return (0, graphql_tag_1.default) `{
|
|
17
|
+
_meta {
|
|
18
|
+
status
|
|
19
|
+
}
|
|
20
|
+
}`;
|
|
21
|
+
}
|
|
22
|
+
getBlockNumber(response, network) {
|
|
23
|
+
return response.data._meta.status[network].block.number || 0;
|
|
24
|
+
}
|
|
25
|
+
/*-----------------------------*
|
|
26
|
+
* 2. Lending pools
|
|
27
|
+
*-----------------------------*/
|
|
28
|
+
lendingPoolsQuery(factory, addressesFilter, network) {
|
|
29
|
+
const tokenStr = `{
|
|
30
|
+
id
|
|
31
|
+
symbol
|
|
32
|
+
name
|
|
33
|
+
decimals
|
|
34
|
+
derivedUSD
|
|
35
|
+
}`;
|
|
36
|
+
const distributorStr = `{
|
|
37
|
+
id
|
|
38
|
+
}`;
|
|
39
|
+
const farmingPoolStr = `{
|
|
40
|
+
epochAmount
|
|
41
|
+
epochBegin
|
|
42
|
+
segmentLength
|
|
43
|
+
vestingBegin
|
|
44
|
+
sharePercentage
|
|
45
|
+
distributor ${distributorStr}
|
|
46
|
+
}`;
|
|
47
|
+
const borrowableStr = `{
|
|
48
|
+
id
|
|
49
|
+
underlying ${tokenStr}
|
|
50
|
+
totalBalance
|
|
51
|
+
totalBorrows
|
|
52
|
+
borrowRate
|
|
53
|
+
reserveFactor
|
|
54
|
+
kinkBorrowRate
|
|
55
|
+
kinkUtilizationRate
|
|
56
|
+
adjustSpeed
|
|
57
|
+
borrowIndex
|
|
58
|
+
accrualTimestamp
|
|
59
|
+
exchangeRate
|
|
60
|
+
borrowTracker
|
|
61
|
+
farmingPool ${farmingPoolStr}
|
|
62
|
+
}`;
|
|
63
|
+
const collateralStr = `{
|
|
64
|
+
id
|
|
65
|
+
totalBalance
|
|
66
|
+
safetyMargin
|
|
67
|
+
liquidationIncentive
|
|
68
|
+
${factories_1.LIQUIDATION_FEE_FACTORIES.includes(factory) ? "liquidationFee" : ""}
|
|
69
|
+
exchangeRate
|
|
70
|
+
}`;
|
|
71
|
+
const pairStr = `{
|
|
72
|
+
factory
|
|
73
|
+
reserve0
|
|
74
|
+
reserve1
|
|
75
|
+
totalSupply
|
|
76
|
+
reserveUSD
|
|
77
|
+
token0Price
|
|
78
|
+
token1Price
|
|
79
|
+
derivedUSD
|
|
80
|
+
uniswapV2PairAddress
|
|
81
|
+
uniswapV2Factory
|
|
82
|
+
isStakedLPToken
|
|
83
|
+
exchangeRate
|
|
84
|
+
stakingRewards
|
|
85
|
+
masterChef
|
|
86
|
+
pid
|
|
87
|
+
stakedTotalSupply
|
|
88
|
+
rewards {
|
|
89
|
+
items {
|
|
90
|
+
id
|
|
91
|
+
rewardRate
|
|
92
|
+
rewardsToken ${tokenStr}
|
|
93
|
+
periodFinish
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}`;
|
|
97
|
+
const id_in_string = addressesFilter.length > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
98
|
+
return (0, graphql_tag_1.default) `{
|
|
99
|
+
lendingPools(
|
|
100
|
+
limit: 1000
|
|
101
|
+
orderBy: "totalBorrowsUSD"
|
|
102
|
+
where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}", ${id_in_string}}
|
|
103
|
+
) {
|
|
104
|
+
items {
|
|
105
|
+
id
|
|
106
|
+
borrowable0 ${borrowableStr}
|
|
107
|
+
borrowable1 ${borrowableStr}
|
|
108
|
+
collateral ${collateralStr}
|
|
109
|
+
pair ${pairStr}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
_meta {
|
|
113
|
+
status
|
|
114
|
+
}
|
|
115
|
+
}`;
|
|
116
|
+
}
|
|
117
|
+
userQuery(account, network, factory) {
|
|
118
|
+
return (0, graphql_tag_1.default) `{
|
|
119
|
+
user(id: "${account.toLowerCase()}") {
|
|
120
|
+
collateralPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}"}) {
|
|
121
|
+
items {
|
|
122
|
+
balance
|
|
123
|
+
collateral {
|
|
124
|
+
lendingPool {
|
|
125
|
+
id
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
supplyPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}"}) {
|
|
131
|
+
items {
|
|
132
|
+
balance
|
|
133
|
+
borrowable {
|
|
134
|
+
underlying {
|
|
135
|
+
id
|
|
136
|
+
}
|
|
137
|
+
lendingPool {
|
|
138
|
+
id
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
borrowPositions(limit:1000, where: { factoryId: "${impermax_factories_1.IMPERMAX_FACTORY[network][factory]}"}) {
|
|
144
|
+
items {
|
|
145
|
+
borrowBalance
|
|
146
|
+
borrowIndex
|
|
147
|
+
borrowable {
|
|
148
|
+
underlying {
|
|
149
|
+
id
|
|
150
|
+
}
|
|
151
|
+
lendingPool {
|
|
152
|
+
id
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_meta {
|
|
159
|
+
status
|
|
160
|
+
}
|
|
161
|
+
}`;
|
|
162
|
+
}
|
|
163
|
+
tvlQuery() {
|
|
164
|
+
return (0, graphql_tag_1.default) `
|
|
165
|
+
{
|
|
166
|
+
impermaxFactorys(limit: 1) {
|
|
167
|
+
items {
|
|
168
|
+
id
|
|
169
|
+
totalBalanceUSD
|
|
170
|
+
totalSupplyUSD
|
|
171
|
+
totalBorrowsUSD
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
/*-----------------------------*
|
|
178
|
+
* Lending vaults
|
|
179
|
+
*-----------------------------*/
|
|
180
|
+
lendingVaultsUserQuery(account) {
|
|
181
|
+
return (0, graphql_tag_1.default) `{
|
|
182
|
+
user(id: "${account.toLowerCase()}") {
|
|
183
|
+
positions(first:1000) {
|
|
184
|
+
tokenBalance
|
|
185
|
+
lastExchangeRate
|
|
186
|
+
cumulativeEarnings
|
|
187
|
+
lendingVault {
|
|
188
|
+
id
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}`;
|
|
193
|
+
}
|
|
194
|
+
lendingVaultsQuery(addressesFilter) {
|
|
195
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
196
|
+
return (0, graphql_tag_1.default) `{
|
|
197
|
+
lendingVaults(first: 1000 ${id_in_string}) {
|
|
198
|
+
id
|
|
199
|
+
underlying {
|
|
200
|
+
id
|
|
201
|
+
symbol
|
|
202
|
+
name
|
|
203
|
+
decimals
|
|
204
|
+
}
|
|
205
|
+
totalBalance
|
|
206
|
+
totalSupply
|
|
207
|
+
supplyRate
|
|
208
|
+
reserveFactor
|
|
209
|
+
exchangeRate
|
|
210
|
+
availableLiquidity
|
|
211
|
+
lastUpdate
|
|
212
|
+
}
|
|
213
|
+
_meta {
|
|
214
|
+
block {
|
|
215
|
+
number
|
|
216
|
+
}
|
|
217
|
+
hasIndexingErrors
|
|
218
|
+
}
|
|
219
|
+
}`;
|
|
220
|
+
}
|
|
221
|
+
/*-----------------------------*
|
|
222
|
+
* Config Manager
|
|
223
|
+
*-----------------------------*/
|
|
224
|
+
// TODO: Add config manager ponder
|
|
225
|
+
proposalsMetaQuery(rangeBegin, rangeLength, descending) {
|
|
226
|
+
return (0, graphql_tag_1.default) `{
|
|
227
|
+
proposals(
|
|
228
|
+
orderBy: idInt,
|
|
229
|
+
orderDirection: ${descending ? "desc" : "asc"},
|
|
230
|
+
first: ${rangeLength},
|
|
231
|
+
skip: ${rangeBegin}
|
|
232
|
+
) {
|
|
233
|
+
id
|
|
234
|
+
state
|
|
235
|
+
}
|
|
236
|
+
}`;
|
|
237
|
+
}
|
|
238
|
+
proposalQuery(id) {
|
|
239
|
+
return (0, graphql_tag_1.default) `{
|
|
240
|
+
proposal(id:${id}) {
|
|
241
|
+
id
|
|
242
|
+
state
|
|
243
|
+
pairConfig {
|
|
244
|
+
factory
|
|
245
|
+
pair
|
|
246
|
+
safetyMarginSqrt
|
|
247
|
+
liquidationIncentive
|
|
248
|
+
liquidationFee
|
|
249
|
+
reserveFactor0
|
|
250
|
+
reserveFactor1
|
|
251
|
+
kinkUtilizationRate0
|
|
252
|
+
kinkUtilizationRate1
|
|
253
|
+
adjustSpeed0
|
|
254
|
+
adjustSpeed1
|
|
255
|
+
borrowTracker0
|
|
256
|
+
borrowTracker1
|
|
257
|
+
whiteListState
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}`;
|
|
261
|
+
}
|
|
262
|
+
/*-----------------------------*
|
|
263
|
+
* IBEX
|
|
264
|
+
*-----------------------------*/
|
|
265
|
+
// TODO: Add IBEX ponder idk what this is
|
|
266
|
+
ximxQuery() {
|
|
267
|
+
return (0, graphql_tag_1.default) `{
|
|
268
|
+
ximxes(first: 1) {
|
|
269
|
+
totalSupply
|
|
270
|
+
totalBalance
|
|
271
|
+
exchangeRate
|
|
272
|
+
dailyAPR
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.PonderQueryBuilder = PonderQueryBuilder;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Address, Factory, Networks } from "../../../../config/types";
|
|
2
|
+
import { IQueryBuilder } from "../../interfaces/query-builder";
|
|
3
|
+
export declare class TheGraphQueryBuilder implements IQueryBuilder {
|
|
4
|
+
blockQuery(timestamp: number): import("graphql").DocumentNode;
|
|
5
|
+
getBlockNumber(response: any, network: Networks): number;
|
|
6
|
+
lendingPoolsQuery(factory: Factory, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
7
|
+
userQuery(account: Address, network: Networks, factory: Factory): import("graphql").DocumentNode;
|
|
8
|
+
tvlQuery(): import("graphql").DocumentNode;
|
|
9
|
+
lendingVaultsQuery(addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
10
|
+
lendingVaultsUserQuery(account: Address): import("graphql").DocumentNode;
|
|
11
|
+
proposalsMetaQuery(rangeBegin: any, rangeLength: any, descending: any): import("graphql").DocumentNode;
|
|
12
|
+
proposalQuery(id: number): import("graphql").DocumentNode;
|
|
13
|
+
ximxQuery(): import("graphql").DocumentNode;
|
|
14
|
+
lendingPoolsPastQuery(blockNumber: number, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
15
|
+
impermaxChefQuery(): import("graphql").DocumentNode;
|
|
16
|
+
pastVolumeQuery(blockNumber: number, addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
17
|
+
currentVolumeAndReservesQuery(addressesFilter: Address[]): import("graphql").DocumentNode;
|
|
18
|
+
whitelistQuery(): import("graphql").DocumentNode;
|
|
19
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
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.TheGraphQueryBuilder = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const factories_1 = require("../../../../config/factories");
|
|
9
|
+
class TheGraphQueryBuilder {
|
|
10
|
+
/*-----------------------------*
|
|
11
|
+
* 1. API Health
|
|
12
|
+
*-----------------------------*/
|
|
13
|
+
// Add queries here for metadata, health, etc.
|
|
14
|
+
blockQuery(timestamp) {
|
|
15
|
+
return (0, graphql_tag_1.default) `{
|
|
16
|
+
blocks (first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${timestamp + 600} }) {
|
|
17
|
+
number
|
|
18
|
+
}
|
|
19
|
+
_meta {
|
|
20
|
+
block {
|
|
21
|
+
number
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}`;
|
|
25
|
+
}
|
|
26
|
+
getBlockNumber(response, network) {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
// Keep compatible to interface, shh
|
|
29
|
+
network;
|
|
30
|
+
return ((_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.block) === null || _c === void 0 ? void 0 : _c.number) || 0;
|
|
31
|
+
}
|
|
32
|
+
/*-----------------------------*
|
|
33
|
+
* 2. Lending pools
|
|
34
|
+
*-----------------------------*/
|
|
35
|
+
lendingPoolsQuery(factory, addressesFilter) {
|
|
36
|
+
const tokenStr = `{
|
|
37
|
+
id
|
|
38
|
+
symbol
|
|
39
|
+
name
|
|
40
|
+
decimals
|
|
41
|
+
derivedUSD
|
|
42
|
+
}`;
|
|
43
|
+
const distributorStr = `{
|
|
44
|
+
id
|
|
45
|
+
}`;
|
|
46
|
+
const farmingPoolStr = `{
|
|
47
|
+
epochAmount
|
|
48
|
+
epochBegin
|
|
49
|
+
segmentLength
|
|
50
|
+
vestingBegin
|
|
51
|
+
sharePercentage
|
|
52
|
+
distributor ${distributorStr}
|
|
53
|
+
}`;
|
|
54
|
+
const borrowableStr = `{
|
|
55
|
+
id
|
|
56
|
+
underlying ${tokenStr}
|
|
57
|
+
totalBalance
|
|
58
|
+
totalBorrows
|
|
59
|
+
borrowRate
|
|
60
|
+
reserveFactor
|
|
61
|
+
kinkBorrowRate
|
|
62
|
+
kinkUtilizationRate
|
|
63
|
+
adjustSpeed
|
|
64
|
+
borrowIndex
|
|
65
|
+
accrualTimestamp
|
|
66
|
+
exchangeRate
|
|
67
|
+
totalBalanceUSD
|
|
68
|
+
totalSupplyUSD
|
|
69
|
+
totalBorrowsUSD
|
|
70
|
+
borrowTracker
|
|
71
|
+
farmingPool ${farmingPoolStr}
|
|
72
|
+
}`;
|
|
73
|
+
const collateralStr = `{
|
|
74
|
+
id
|
|
75
|
+
totalBalance
|
|
76
|
+
totalBalanceUSD
|
|
77
|
+
safetyMargin
|
|
78
|
+
liquidationIncentive
|
|
79
|
+
${factories_1.LIQUIDATION_FEE_FACTORIES.includes(factory) ? "liquidationFee" : ""}
|
|
80
|
+
exchangeRate
|
|
81
|
+
}`;
|
|
82
|
+
const pairStr = `{
|
|
83
|
+
factory
|
|
84
|
+
reserve0
|
|
85
|
+
reserve1
|
|
86
|
+
totalSupply
|
|
87
|
+
reserveUSD
|
|
88
|
+
token0Price
|
|
89
|
+
token1Price
|
|
90
|
+
derivedUSD
|
|
91
|
+
uniswapV2PairAddress
|
|
92
|
+
uniswapV2Factory
|
|
93
|
+
isStakedLPToken
|
|
94
|
+
exchangeRate
|
|
95
|
+
stakingRewards
|
|
96
|
+
masterChef
|
|
97
|
+
pid
|
|
98
|
+
stakedTotalSupply
|
|
99
|
+
rewards {
|
|
100
|
+
id
|
|
101
|
+
rewardRate
|
|
102
|
+
rewardsToken ${tokenStr}
|
|
103
|
+
periodFinish
|
|
104
|
+
}
|
|
105
|
+
}`;
|
|
106
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
107
|
+
return (0, graphql_tag_1.default) `{
|
|
108
|
+
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc ${id_in_string}) {
|
|
109
|
+
id
|
|
110
|
+
borrowable0 ${borrowableStr}
|
|
111
|
+
borrowable1 ${borrowableStr}
|
|
112
|
+
collateral ${collateralStr}
|
|
113
|
+
pair ${pairStr}
|
|
114
|
+
}
|
|
115
|
+
_meta {
|
|
116
|
+
block {
|
|
117
|
+
number
|
|
118
|
+
}
|
|
119
|
+
hasIndexingErrors
|
|
120
|
+
}
|
|
121
|
+
}`;
|
|
122
|
+
}
|
|
123
|
+
userQuery(account, network, factory) {
|
|
124
|
+
// Shh
|
|
125
|
+
network;
|
|
126
|
+
factory;
|
|
127
|
+
return (0, graphql_tag_1.default) `{
|
|
128
|
+
user(id: "${account.toLowerCase()}") {
|
|
129
|
+
collateralPositions(first:1000) {
|
|
130
|
+
balance
|
|
131
|
+
collateral {
|
|
132
|
+
lendingPool {
|
|
133
|
+
id
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
supplyPositions(first:1000) {
|
|
138
|
+
balance
|
|
139
|
+
borrowable {
|
|
140
|
+
underlying {
|
|
141
|
+
id
|
|
142
|
+
}
|
|
143
|
+
lendingPool {
|
|
144
|
+
id
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
borrowPositions(first:1000) {
|
|
149
|
+
borrowBalance
|
|
150
|
+
borrowIndex
|
|
151
|
+
borrowable {
|
|
152
|
+
underlying {
|
|
153
|
+
id
|
|
154
|
+
}
|
|
155
|
+
lendingPool {
|
|
156
|
+
id
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_meta {
|
|
162
|
+
block {
|
|
163
|
+
number
|
|
164
|
+
}
|
|
165
|
+
hasIndexingErrors
|
|
166
|
+
}
|
|
167
|
+
}`;
|
|
168
|
+
}
|
|
169
|
+
tvlQuery() {
|
|
170
|
+
return (0, graphql_tag_1.default) `{
|
|
171
|
+
impermaxFactories(first: 1) {
|
|
172
|
+
totalBalanceUSD
|
|
173
|
+
totalSupplyUSD
|
|
174
|
+
totalBorrowsUSD
|
|
175
|
+
}
|
|
176
|
+
}`;
|
|
177
|
+
}
|
|
178
|
+
/*-----------------------------*
|
|
179
|
+
* Lending vaults
|
|
180
|
+
*-----------------------------*/
|
|
181
|
+
lendingVaultsQuery(addressesFilter) {
|
|
182
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
183
|
+
return (0, graphql_tag_1.default) `{
|
|
184
|
+
lendingVaults(first: 1000 ${id_in_string}) {
|
|
185
|
+
id
|
|
186
|
+
underlying {
|
|
187
|
+
id
|
|
188
|
+
symbol
|
|
189
|
+
name
|
|
190
|
+
decimals
|
|
191
|
+
}
|
|
192
|
+
totalBalance
|
|
193
|
+
totalSupply
|
|
194
|
+
supplyRate
|
|
195
|
+
reserveFactor
|
|
196
|
+
exchangeRate
|
|
197
|
+
availableLiquidity
|
|
198
|
+
lastUpdate
|
|
199
|
+
}
|
|
200
|
+
_meta {
|
|
201
|
+
block {
|
|
202
|
+
number
|
|
203
|
+
}
|
|
204
|
+
hasIndexingErrors
|
|
205
|
+
}
|
|
206
|
+
}`;
|
|
207
|
+
}
|
|
208
|
+
lendingVaultsUserQuery(account) {
|
|
209
|
+
return (0, graphql_tag_1.default) `{
|
|
210
|
+
user(id: "${account.toLowerCase()}") {
|
|
211
|
+
positions(first:1000) {
|
|
212
|
+
tokenBalance
|
|
213
|
+
lastExchangeRate
|
|
214
|
+
cumulativeEarnings
|
|
215
|
+
lendingVault {
|
|
216
|
+
id
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}`;
|
|
221
|
+
}
|
|
222
|
+
/*-----------------------------*
|
|
223
|
+
* Config Manager
|
|
224
|
+
*-----------------------------*/
|
|
225
|
+
proposalsMetaQuery(rangeBegin, rangeLength, descending) {
|
|
226
|
+
return (0, graphql_tag_1.default) `{
|
|
227
|
+
proposals(
|
|
228
|
+
orderBy: idInt,
|
|
229
|
+
orderDirection: ${descending ? "desc" : "asc"},
|
|
230
|
+
first: ${rangeLength},
|
|
231
|
+
skip: ${rangeBegin}
|
|
232
|
+
) {
|
|
233
|
+
id
|
|
234
|
+
state
|
|
235
|
+
}
|
|
236
|
+
}`;
|
|
237
|
+
}
|
|
238
|
+
proposalQuery(id) {
|
|
239
|
+
return (0, graphql_tag_1.default) `{
|
|
240
|
+
proposal(id:${id}) {
|
|
241
|
+
id
|
|
242
|
+
state
|
|
243
|
+
pairConfig {
|
|
244
|
+
factory
|
|
245
|
+
pair
|
|
246
|
+
safetyMarginSqrt
|
|
247
|
+
liquidationIncentive
|
|
248
|
+
liquidationFee
|
|
249
|
+
reserveFactor0
|
|
250
|
+
reserveFactor1
|
|
251
|
+
kinkUtilizationRate0
|
|
252
|
+
kinkUtilizationRate1
|
|
253
|
+
adjustSpeed0
|
|
254
|
+
adjustSpeed1
|
|
255
|
+
borrowTracker0
|
|
256
|
+
borrowTracker1
|
|
257
|
+
whiteListState
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}`;
|
|
261
|
+
}
|
|
262
|
+
/*-----------------------------*
|
|
263
|
+
* IBEX
|
|
264
|
+
*-----------------------------*/
|
|
265
|
+
ximxQuery() {
|
|
266
|
+
return (0, graphql_tag_1.default) `{
|
|
267
|
+
ximxes(first: 1) {
|
|
268
|
+
totalSupply
|
|
269
|
+
totalBalance
|
|
270
|
+
exchangeRate
|
|
271
|
+
dailyAPR
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
}
|
|
276
|
+
/*-----------------------------*
|
|
277
|
+
* Optionals
|
|
278
|
+
*-----------------------------*/
|
|
279
|
+
lendingPoolsPastQuery(blockNumber, addressesFilter) {
|
|
280
|
+
const borrowablePastStr = `{
|
|
281
|
+
borrowIndex
|
|
282
|
+
accrualTimestamp
|
|
283
|
+
exchangeRate
|
|
284
|
+
}`;
|
|
285
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
286
|
+
return (0, graphql_tag_1.default) `{
|
|
287
|
+
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc, block: {number: ${blockNumber}} ${id_in_string}) {
|
|
288
|
+
id
|
|
289
|
+
borrowable0 ${borrowablePastStr}
|
|
290
|
+
borrowable1 ${borrowablePastStr}
|
|
291
|
+
}
|
|
292
|
+
}`;
|
|
293
|
+
}
|
|
294
|
+
impermaxChefQuery() {
|
|
295
|
+
return (0, graphql_tag_1.default) `{
|
|
296
|
+
impermaxChefs(first: 1) {
|
|
297
|
+
id
|
|
298
|
+
rewardToken
|
|
299
|
+
rewardPerSec
|
|
300
|
+
totalAllocPoint
|
|
301
|
+
}
|
|
302
|
+
pools(first: 1000) {
|
|
303
|
+
id
|
|
304
|
+
allocPoint
|
|
305
|
+
rewarder {
|
|
306
|
+
id
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
impermaxRewarders(first: 1000) {
|
|
310
|
+
rewardToken
|
|
311
|
+
rewardPerSec
|
|
312
|
+
totalAllocPoint
|
|
313
|
+
pools(first: 1000) {
|
|
314
|
+
borrowable
|
|
315
|
+
allocPoint
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}`;
|
|
319
|
+
}
|
|
320
|
+
pastVolumeQuery(blockNumber, addressesFilter) {
|
|
321
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
322
|
+
return (0, graphql_tag_1.default) `{
|
|
323
|
+
pairs (block: {number: ${blockNumber}} ${id_in_string}) {
|
|
324
|
+
id
|
|
325
|
+
volumeUSD
|
|
326
|
+
}
|
|
327
|
+
}`;
|
|
328
|
+
}
|
|
329
|
+
currentVolumeAndReservesQuery(addressesFilter) {
|
|
330
|
+
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
331
|
+
return (0, graphql_tag_1.default) `{
|
|
332
|
+
pairs (${id_in_string}) {
|
|
333
|
+
id
|
|
334
|
+
reserveUSD
|
|
335
|
+
volumeUSD
|
|
336
|
+
}
|
|
337
|
+
}`;
|
|
338
|
+
}
|
|
339
|
+
whitelistQuery() {
|
|
340
|
+
return (0, graphql_tag_1.default) `{
|
|
341
|
+
whitelistStates(first: 1000) {
|
|
342
|
+
factory
|
|
343
|
+
pair
|
|
344
|
+
state
|
|
345
|
+
}
|
|
346
|
+
}`;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
exports.TheGraphQueryBuilder = TheGraphQueryBuilder;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IQueryBuilder } from "./interfaces/query-builder";
|
|
2
|
+
import { ApolloQueryResult } from "apollo-client";
|
|
3
|
+
/**
|
|
4
|
+
* Pure utility class to create query builders and transform data
|
|
5
|
+
*/
|
|
6
|
+
export declare class QueryBuilderFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Gets an API's query builder given an endpoint
|
|
9
|
+
*/
|
|
10
|
+
static getQuery(endpoint: string): IQueryBuilder;
|
|
11
|
+
/**
|
|
12
|
+
* Helper to transform nested query results from various apis during apollo fetch.
|
|
13
|
+
* Mainly used for Ponder as the graphql schema is different to thegraph due to pagination.
|
|
14
|
+
*/
|
|
15
|
+
static transformData(input: ApolloQueryResult<any>): ApolloQueryResult<any>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryBuilderFactory = void 0;
|
|
4
|
+
const ponder_1 = require("./apis/ponder");
|
|
5
|
+
const thegraph_1 = require("./apis/thegraph");
|
|
6
|
+
/**
|
|
7
|
+
* Pure utility class to create query builders and transform data
|
|
8
|
+
*/
|
|
9
|
+
class QueryBuilderFactory {
|
|
10
|
+
/**
|
|
11
|
+
* Gets an API's query builder given an endpoint
|
|
12
|
+
*/
|
|
13
|
+
static getQuery(endpoint) {
|
|
14
|
+
if (endpoint.includes("thegraph"))
|
|
15
|
+
return new thegraph_1.TheGraphQueryBuilder();
|
|
16
|
+
// if (endpoint.includes("goldsky")) return new GoldskyBuilder(), etc.;
|
|
17
|
+
// Default to ponder (ie. includes('railway')) but helps local test
|
|
18
|
+
return new ponder_1.PonderQueryBuilder();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Helper to transform nested query results from various apis during apollo fetch.
|
|
22
|
+
* Mainly used for Ponder as the graphql schema is different to thegraph due to pagination.
|
|
23
|
+
*/
|
|
24
|
+
static transformData(input) {
|
|
25
|
+
const transformValue = (value) => {
|
|
26
|
+
if (!value)
|
|
27
|
+
return value;
|
|
28
|
+
if (Array.isArray(value))
|
|
29
|
+
return value.map(transformValue);
|
|
30
|
+
if (typeof value === "object") {
|
|
31
|
+
const transformed = {};
|
|
32
|
+
for (const [key, val] of Object.entries(value)) {
|
|
33
|
+
if (key === "items" && Array.isArray(val))
|
|
34
|
+
return val.map(transformValue);
|
|
35
|
+
transformed[key] = transformValue(val);
|
|
36
|
+
}
|
|
37
|
+
return transformed;
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
return Object.assign(Object.assign({}, input), { data: transformValue(input.data) });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.QueryBuilderFactory = QueryBuilderFactory;
|