@hawksightco/hawk-sdk 0.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.
- package/README.md +3 -0
- package/jest.config.js +5 -0
- package/package.json +37 -0
- package/src/index.ts +382 -0
- package/src/types.ts +248 -0
- package/test/index.spec.ts +213 -0
- package/tsconfig.json +109 -0
package/README.md
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hawksightco/hawk-sdk",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Hawksight v2 SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": "https://github.com/ghabxph/hawk-api-client.git",
|
|
7
|
+
"homepage": "https://hawksight.co/",
|
|
8
|
+
"author": "Hawksight",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/bn.js": "^5.1.5",
|
|
12
|
+
"@types/jest": "^29.5.11",
|
|
13
|
+
"@types/lodash": "^4.14.202",
|
|
14
|
+
"@types/node": "^20.11.5",
|
|
15
|
+
"eslint": "^8.56.0",
|
|
16
|
+
"jest": "^29.7.0",
|
|
17
|
+
"nodemon": "^3.0.3",
|
|
18
|
+
"ts-jest": "^29.1.2",
|
|
19
|
+
"typescript": "^5.4.5"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@solana/web3.js": "^1.89.1",
|
|
23
|
+
"@hawksightco/swagger-client": "0.0.3",
|
|
24
|
+
"axios": "^1.6.5",
|
|
25
|
+
"bn.js": "^5.2.1",
|
|
26
|
+
"bs58": "^5.0.0",
|
|
27
|
+
"fp-ts": "^2.16.5",
|
|
28
|
+
"io-ts": "^2.2.21",
|
|
29
|
+
"io-ts-types": "^0.5.19",
|
|
30
|
+
"lodash": "^4.17.21",
|
|
31
|
+
"zod": "^3.22.4"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"start": "npx ts-node src/index.ts",
|
|
35
|
+
"test": "npx jest"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import * as client from "@hawksightco/swagger-client";
|
|
3
|
+
import { HealthResponse, MeteoraDlmmActiveBin, ResponseWithStatus, TransactionMetadata, TransactionMetadataResponse, UserPortfolioOut } from "./types";
|
|
4
|
+
|
|
5
|
+
class Client {
|
|
6
|
+
public readonly config: client.Configuration;
|
|
7
|
+
public readonly healthCheck: client.HealthCheckApi;
|
|
8
|
+
public readonly generalEndpoints: client.GeneralEndpointsApi;
|
|
9
|
+
public readonly meteoraDLMMUtilityFunctionsApi: client.MeteoraDLMMUtilityFunctionsApi;
|
|
10
|
+
public readonly meteoraDLMMInstructionsApi: client.MeteoraDLMMInstructionsApi;
|
|
11
|
+
public readonly meteoraDLMMAutomationInstructionsApi: client.MeteoraDLMMAutomationInstructionsApi;
|
|
12
|
+
public readonly orcaUtilityFunctionsApi: client.OrcaUtilityFunctionsApi;
|
|
13
|
+
public readonly orcaCLMMInstructionsApi: client.OrcaCLMMInstructionsApi;
|
|
14
|
+
constructor(
|
|
15
|
+
public readonly url: string = "https://api2.hawksight.co",
|
|
16
|
+
) {
|
|
17
|
+
this.config = new client.Configuration({
|
|
18
|
+
basePath: url
|
|
19
|
+
});
|
|
20
|
+
this.healthCheck = new client.HealthCheckApi(this.config);
|
|
21
|
+
this.generalEndpoints = new client.GeneralEndpointsApi(this.config);
|
|
22
|
+
this.meteoraDLMMUtilityFunctionsApi = new client.MeteoraDLMMUtilityFunctionsApi(this.config);
|
|
23
|
+
this.meteoraDLMMInstructionsApi = new client.MeteoraDLMMInstructionsApi(this.config);
|
|
24
|
+
this.meteoraDLMMAutomationInstructionsApi = new client.MeteoraDLMMAutomationInstructionsApi(this.config);
|
|
25
|
+
this.orcaUtilityFunctionsApi = new client.OrcaUtilityFunctionsApi(this.config);
|
|
26
|
+
this.orcaCLMMInstructionsApi = new client.OrcaCLMMInstructionsApi(this.config);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class Health {
|
|
31
|
+
constructor(
|
|
32
|
+
private readonly client: Client,
|
|
33
|
+
) {}
|
|
34
|
+
async health(): Promise<ResponseWithStatus<HealthResponse>> {
|
|
35
|
+
const result = await this.client.healthCheck.healthGet().catch(e => e.response);
|
|
36
|
+
return {
|
|
37
|
+
status: result.status,
|
|
38
|
+
data: result.data,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class General {
|
|
44
|
+
constructor(
|
|
45
|
+
private readonly client: Client,
|
|
46
|
+
) {}
|
|
47
|
+
|
|
48
|
+
async portfolio(
|
|
49
|
+
params: {
|
|
50
|
+
wallet: string,
|
|
51
|
+
pool?: string,
|
|
52
|
+
}
|
|
53
|
+
): Promise<ResponseWithStatus<UserPortfolioOut>> {
|
|
54
|
+
const result = await this.client.generalEndpoints.portfolioGet(params.wallet, params.pool).catch(e => e.response);
|
|
55
|
+
return {
|
|
56
|
+
status: result.status,
|
|
57
|
+
data: result.data,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async pools(): Promise<ResponseWithStatus<client.InlineResponse2002[]>> {
|
|
61
|
+
const result = await this.client.generalEndpoints.poolsGet().catch(e => e.response);
|
|
62
|
+
return {
|
|
63
|
+
status: result.status,
|
|
64
|
+
data: result.data,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async tokens(): Promise<ResponseWithStatus<client.InlineResponse2003[]>> {
|
|
69
|
+
const result = await this.client.generalEndpoints.tokensGet().catch(e => e.response);
|
|
70
|
+
return {
|
|
71
|
+
status: result.status,
|
|
72
|
+
data: result.data,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async register(connection: web3.Connection, payer: string, params: client.RegisterBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
77
|
+
const result = await this.client.generalEndpoints.registerPost(params).catch(e => e.response);
|
|
78
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
79
|
+
{
|
|
80
|
+
status: result.status,
|
|
81
|
+
data: result.data,
|
|
82
|
+
},
|
|
83
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class Util {
|
|
89
|
+
constructor(
|
|
90
|
+
private readonly client: Client,
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
async meteoraDlmmPools(): Promise<ResponseWithStatus<client.InlineResponse2005[]>> {
|
|
94
|
+
const result = await this.client.meteoraDLMMUtilityFunctionsApi.meteoraDlmmUtilPoolsGet().catch(e => e.response);
|
|
95
|
+
return {
|
|
96
|
+
status: result.status,
|
|
97
|
+
data: result.data,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async meteoraDlmmPositions(
|
|
102
|
+
params: {
|
|
103
|
+
wallet: string,
|
|
104
|
+
pool?: string,
|
|
105
|
+
}
|
|
106
|
+
): Promise<ResponseWithStatus<any>> {
|
|
107
|
+
const result = await this.client.meteoraDLMMUtilityFunctionsApi.meteoraDlmmUtilPositionsGet(params.wallet, params.pool).catch(e => e.response);
|
|
108
|
+
return {
|
|
109
|
+
status: result.status,
|
|
110
|
+
data: result.data,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async meteoraDlmmActiveBin(params: client.UtilActiveBinBody): Promise<ResponseWithStatus<MeteoraDlmmActiveBin>> {
|
|
115
|
+
const result = await this.client.meteoraDLMMUtilityFunctionsApi.meteoraDlmmUtilActiveBinPost(params).catch(e => e.response);
|
|
116
|
+
return {
|
|
117
|
+
status: result.status,
|
|
118
|
+
data: result.data,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async orcaClmmPools(): Promise<ResponseWithStatus<any>> {
|
|
123
|
+
const result = await this.client.orcaUtilityFunctionsApi.orcaUtilPoolsGet().catch(e => e.response);
|
|
124
|
+
return {
|
|
125
|
+
status: result.status,
|
|
126
|
+
data: result.data,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async orcaPositions(
|
|
131
|
+
params: {
|
|
132
|
+
wallet: string,
|
|
133
|
+
pool?: string,
|
|
134
|
+
}
|
|
135
|
+
): Promise<ResponseWithStatus<any>> {
|
|
136
|
+
const result = await this.client.orcaUtilityFunctionsApi.orcaUtilPositionsGet(params.wallet, params.pool).catch(e => e.response);
|
|
137
|
+
return {
|
|
138
|
+
status: result.status,
|
|
139
|
+
data: result.data,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async orcaGetPositionMint(
|
|
144
|
+
params: {
|
|
145
|
+
position: string,
|
|
146
|
+
}
|
|
147
|
+
): Promise<ResponseWithStatus<any>> {
|
|
148
|
+
const result = await this.client.orcaUtilityFunctionsApi.orcaUtilGetPositionMintGet(params.position).catch(e => e.response);
|
|
149
|
+
return {
|
|
150
|
+
status: result.status,
|
|
151
|
+
data: result.data,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class TxGenerator {
|
|
157
|
+
constructor(
|
|
158
|
+
private readonly client: Client,
|
|
159
|
+
) {}
|
|
160
|
+
|
|
161
|
+
async meteoraCreatePositionAndDeposit(connection: web3.Connection, payer: string, params: client.TxCreatePositionAndDepositBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
162
|
+
const result = await this.client.meteoraDLMMInstructionsApi.meteoraDlmmTxCreatePositionAndDepositPost(params).catch(e => e.response);
|
|
163
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
164
|
+
{
|
|
165
|
+
status: result.status,
|
|
166
|
+
data: result.data,
|
|
167
|
+
},
|
|
168
|
+
async (data) => await createTxMetadata(connection, payer, data)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async meteoraDeposit(connection: web3.Connection, payer: string, params: client.TxDepositBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
173
|
+
const result = await this.client.meteoraDLMMInstructionsApi.meteoraDlmmTxDepositPost(params).catch(e => e.response);
|
|
174
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
175
|
+
{
|
|
176
|
+
status: result.status,
|
|
177
|
+
data: result.data,
|
|
178
|
+
},
|
|
179
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async meteoraWithdraw(connection: web3.Connection, payer: string, params: client.TxWithdrawBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
184
|
+
const result = await this.client.meteoraDLMMInstructionsApi.meteoraDlmmTxWithdrawPost(params).catch(e => e.response);
|
|
185
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
186
|
+
{
|
|
187
|
+
status: result.status,
|
|
188
|
+
data: result.data,
|
|
189
|
+
},
|
|
190
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async meteoraClaim(connection: web3.Connection, payer: string, params: client.TxClaimBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
195
|
+
const result = await this.client.meteoraDLMMInstructionsApi.meteoraDlmmTxClaimPost(params).catch(e => e.response);
|
|
196
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
197
|
+
{
|
|
198
|
+
status: result.status,
|
|
199
|
+
data: result.data,
|
|
200
|
+
},
|
|
201
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async meteoraClosePosition(connection: web3.Connection, payer: string, params: client.TxClosePositionBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
206
|
+
const result = await this.client.meteoraDLMMInstructionsApi.meteoraDlmmTxClosePositionPost(params).catch(e => e.response);
|
|
207
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
208
|
+
{
|
|
209
|
+
status: result.status,
|
|
210
|
+
data: result.data,
|
|
211
|
+
},
|
|
212
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async orcaOpenPosition(connection: web3.Connection, payer: string, params: client.TxOpenPositionBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
217
|
+
const result = await this.client.orcaCLMMInstructionsApi.orcaTxOpenPositionPost(params).catch(e => e.response);
|
|
218
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
219
|
+
{
|
|
220
|
+
status: result.status,
|
|
221
|
+
data: result.data,
|
|
222
|
+
},
|
|
223
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async orcaClosePosition(connection: web3.Connection, payer: string, params: client.TxClosePositionBody1): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
228
|
+
const result = await this.client.orcaCLMMInstructionsApi.orcaTxClosePositionPost(params).catch(e => e.response);
|
|
229
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
230
|
+
{
|
|
231
|
+
status: result.status,
|
|
232
|
+
data: result.data,
|
|
233
|
+
},
|
|
234
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async orcaDeposit(connection: web3.Connection, payer: string, params: client.TxDepositBody1): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
239
|
+
const result = await this.client.orcaCLMMInstructionsApi.orcaTxDepositPost(params).catch(e => e.response);
|
|
240
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
241
|
+
{
|
|
242
|
+
status: result.status,
|
|
243
|
+
data: result.data,
|
|
244
|
+
},
|
|
245
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async orcaWithdraw(connection: web3.Connection, payer: string, params: client.TxWithdrawBody1): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
250
|
+
const result = await this.client.orcaCLMMInstructionsApi.orcaTxWithdrawPost(params).catch(e => e.response);
|
|
251
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
252
|
+
{
|
|
253
|
+
status: result.status,
|
|
254
|
+
data: result.data,
|
|
255
|
+
},
|
|
256
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async orcaClaimRewards(connection: web3.Connection, payer: string, params: client.TxClaimRewardsBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
261
|
+
const result = await this.client.orcaCLMMInstructionsApi.orcaTxClaimRewardsPost(params).catch(e => e.response);
|
|
262
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
263
|
+
{
|
|
264
|
+
status: result.status,
|
|
265
|
+
data: result.data,
|
|
266
|
+
},
|
|
267
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
class TxGeneratorAutomations {
|
|
273
|
+
constructor(
|
|
274
|
+
private readonly client: Client,
|
|
275
|
+
) {}
|
|
276
|
+
|
|
277
|
+
async meteoraClaimFeeAndRewards(connection: web3.Connection, payer: string, params: client.AutomationClaimFeeAndRewardsAutomationIxBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
278
|
+
const result = await this.client.meteoraDLMMAutomationInstructionsApi.meteoraDlmmAutomationClaimFeeAndRewardsAutomationIxPost(params).catch(e => e.response);
|
|
279
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
280
|
+
{
|
|
281
|
+
status: result.status,
|
|
282
|
+
data: result.data,
|
|
283
|
+
},
|
|
284
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async meteoraFullWithdrawalAndClosePosition(connection: web3.Connection, payer: string, params: client.AutomationFullWithdrawAndClosePositionAutomationIxBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
289
|
+
const result = await this.client.meteoraDLMMAutomationInstructionsApi.meteoraDlmmAutomationFullWithdrawAndClosePositionAutomationIxPost(params).catch(e => e.response);
|
|
290
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
291
|
+
{
|
|
292
|
+
status: result.status,
|
|
293
|
+
data: result.data,
|
|
294
|
+
},
|
|
295
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async meteoraCreatePositionAndDeposit(connection: web3.Connection, payer: string, params: client.AutomationCreatePositionAndDepositAutomationIxBody): Promise<ResponseWithStatus<TransactionMetadataResponse> | ResponseWithStatus<TransactionMetadata>> {
|
|
300
|
+
const result = await this.client.meteoraDLMMAutomationInstructionsApi.meteoraDlmmAutomationCreatePositionAndDepositAutomationIxPost(params).catch(e => e.response);
|
|
301
|
+
return resultOrError<TransactionMetadataResponse, TransactionMetadata>(
|
|
302
|
+
{
|
|
303
|
+
status: result.status,
|
|
304
|
+
data: result.data,
|
|
305
|
+
},
|
|
306
|
+
async (data) => await createTxMetadata(connection, payer, data),
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
class HawkAPI {
|
|
312
|
+
public readonly health: Health;
|
|
313
|
+
public readonly general: General;
|
|
314
|
+
public readonly util: Util;
|
|
315
|
+
public readonly txGenerator: TxGenerator;
|
|
316
|
+
public readonly txGeneratorAutomation: TxGeneratorAutomations;
|
|
317
|
+
constructor(
|
|
318
|
+
protected readonly url: string = "https://api2.hawksight.co",
|
|
319
|
+
) {
|
|
320
|
+
const client = new Client(url);
|
|
321
|
+
this.health = new Health(client);
|
|
322
|
+
this.general = new General(client);
|
|
323
|
+
this.util = new Util(client);
|
|
324
|
+
this.txGenerator = new TxGenerator(client);
|
|
325
|
+
this.txGeneratorAutomation = new TxGeneratorAutomations(client);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export default HawkAPI;
|
|
330
|
+
|
|
331
|
+
async function createTxMetadata(connection: web3.Connection, payer: string, data: TransactionMetadataResponse): Promise<TransactionMetadata> {
|
|
332
|
+
const alts: web3.AddressLookupTableAccount[] = [];
|
|
333
|
+
for (const alt of data.addressLookupTableAddresses) {
|
|
334
|
+
alts.push(
|
|
335
|
+
(await connection.getAddressLookupTable(new web3.PublicKey(alt))).value as web3.AddressLookupTableAccount
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
const computeIxs = data.computeBudgetInstructions.map(ix => {
|
|
339
|
+
return new web3.TransactionInstruction({
|
|
340
|
+
keys: ix.accounts.map(meta => {
|
|
341
|
+
return { pubkey: new web3.PublicKey(meta.pubkey), isSigner: meta.isSigner, isWritable: meta.isWritable };
|
|
342
|
+
}),
|
|
343
|
+
programId: new web3.PublicKey(ix.programId),
|
|
344
|
+
data: Buffer.from(ix.data, 'base64'),
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
const mainIxs = data.computeBudgetInstructions.map(ix => {
|
|
348
|
+
return new web3.TransactionInstruction({
|
|
349
|
+
keys: ix.accounts.map(meta => {
|
|
350
|
+
return { pubkey: new web3.PublicKey(meta.pubkey), isSigner: meta.isSigner, isWritable: meta.isWritable };
|
|
351
|
+
}),
|
|
352
|
+
programId: new web3.PublicKey(ix.programId),
|
|
353
|
+
data: Buffer.from(ix.data, 'base64'),
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
const { blockhash: recentBlockhash } = await connection.getLatestBlockhash();
|
|
357
|
+
const txMessage = new web3.TransactionMessage({
|
|
358
|
+
payerKey: new web3.PublicKey(payer),
|
|
359
|
+
instructions: [...computeIxs, ...mainIxs],
|
|
360
|
+
recentBlockhash,
|
|
361
|
+
});
|
|
362
|
+
const tx = new web3.VersionedTransaction(txMessage.compileToV0Message(alts));
|
|
363
|
+
return {
|
|
364
|
+
description: data.description,
|
|
365
|
+
estimatedFeeInSOL: data.estimatedFeeInSOL,
|
|
366
|
+
transaction: tx.serialize(),
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function resultOrError<Response, Out>(result: { status: number, data: Response }, successFn: (data: Response) => Promise<Out>): Promise<ResponseWithStatus<Out> | ResponseWithStatus<Response>> {
|
|
371
|
+
if (result.status === 200) {
|
|
372
|
+
return {
|
|
373
|
+
status: result.status,
|
|
374
|
+
data: await successFn(result.data),
|
|
375
|
+
};
|
|
376
|
+
} else {
|
|
377
|
+
return {
|
|
378
|
+
status: result.status,
|
|
379
|
+
data: result.data,
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
|
|
4
|
+
export type AccountMeta = {
|
|
5
|
+
isSigner: boolean,
|
|
6
|
+
isWritable: boolean,
|
|
7
|
+
pubkey: string,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type TransactionInstruction = {
|
|
11
|
+
programId: string,
|
|
12
|
+
keys: AccountMeta[],
|
|
13
|
+
data: string
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type Transaction = TransactionInstruction[];
|
|
17
|
+
|
|
18
|
+
export type Web3Transaction = web3.TransactionInstruction[];
|
|
19
|
+
|
|
20
|
+
export type BinRange = {
|
|
21
|
+
lowerRange: number,
|
|
22
|
+
upperRange: number,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type Distribution = "SPOT" | "CURVE" | "BID-ASK";
|
|
26
|
+
|
|
27
|
+
export type MeteoraCreatePositionAndDeposit = {
|
|
28
|
+
position: web3.PublicKey,
|
|
29
|
+
pool: string,
|
|
30
|
+
userWallet: web3.PublicKey,
|
|
31
|
+
totalXAmount: BN,
|
|
32
|
+
totalYAmount: BN,
|
|
33
|
+
binRange: BinRange,
|
|
34
|
+
distribution: Distribution,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type MeteoraDeposit = {
|
|
38
|
+
position: web3.PublicKey,
|
|
39
|
+
pool: string,
|
|
40
|
+
userWallet: web3.PublicKey,
|
|
41
|
+
totalXAmount: BN,
|
|
42
|
+
totalYAmount: BN,
|
|
43
|
+
distribution: Distribution,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type MeteoraPoolInfo = {
|
|
47
|
+
address: string,
|
|
48
|
+
name: string,
|
|
49
|
+
mint_x: string,
|
|
50
|
+
mint_y: string,
|
|
51
|
+
reserve_x: string,
|
|
52
|
+
reserve_y: string,
|
|
53
|
+
reserve_x_amount: number,
|
|
54
|
+
reserve_y_amount: number,
|
|
55
|
+
bin_step: number,
|
|
56
|
+
base_fee_percentage: string,
|
|
57
|
+
max_fee_percentage: string,
|
|
58
|
+
protocol_fee_percentage: string,
|
|
59
|
+
liquidity: string,
|
|
60
|
+
reward_mint_x: string,
|
|
61
|
+
reward_mint_y: string,
|
|
62
|
+
fees_24h: number,
|
|
63
|
+
today_fees: number,
|
|
64
|
+
trade_volume_24h: number,
|
|
65
|
+
cumulative_trade_volume: string,
|
|
66
|
+
cumulative_fee_volume: string,
|
|
67
|
+
current_price: number,
|
|
68
|
+
apr: number,
|
|
69
|
+
apy: number,
|
|
70
|
+
hide: boolean
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export enum Tags {
|
|
74
|
+
Stable = "stable",
|
|
75
|
+
Volatile = "volatile",
|
|
76
|
+
LiquidStaking = "liquid_staking",
|
|
77
|
+
Stablecoin = "stablecoins",
|
|
78
|
+
Deprecated = "deprecated",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export enum Protocol {
|
|
82
|
+
Saber = "saber",
|
|
83
|
+
Orca = "orca",
|
|
84
|
+
Meteora = "meteora",
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface BasePool {
|
|
88
|
+
id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
url: string;
|
|
91
|
+
tags: Tags[];
|
|
92
|
+
hidden: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type Pool =
|
|
96
|
+
| (BasePool & {
|
|
97
|
+
protocol: Protocol.Saber;
|
|
98
|
+
config: SaberPoolConfig; // contains all the related accounts to this strategy
|
|
99
|
+
})
|
|
100
|
+
| (BasePool & {
|
|
101
|
+
protocol: Protocol.Orca;
|
|
102
|
+
config: OrcaPoolConfig; // contains all the related accounts to this strategy
|
|
103
|
+
})
|
|
104
|
+
| (BasePool & {
|
|
105
|
+
protocol: Protocol.Meteora;
|
|
106
|
+
config: MeteoraPoolConfig; // contains all the related accounts to this strategy
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export type SaberPoolConfig = {};
|
|
110
|
+
export type OrcaPoolConfig = OrcaPoolInfo;
|
|
111
|
+
export type MeteoraPoolConfig = {
|
|
112
|
+
address: string,
|
|
113
|
+
name: string,
|
|
114
|
+
mint_x: string,
|
|
115
|
+
mint_y: string,
|
|
116
|
+
reserve_x: string,
|
|
117
|
+
reserve_y: string,
|
|
118
|
+
reward_mint_x: string,
|
|
119
|
+
reward_mint_y: string,
|
|
120
|
+
bin_step: number,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type Token = {
|
|
124
|
+
address: string;
|
|
125
|
+
name: string;
|
|
126
|
+
symbol: string;
|
|
127
|
+
decimals: number;
|
|
128
|
+
logo: string;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// This should be serializable to web3.TransactionInstruction
|
|
132
|
+
export type Instruction = {
|
|
133
|
+
accounts: {
|
|
134
|
+
isSigner: boolean;
|
|
135
|
+
isWritable: boolean;
|
|
136
|
+
pubkey: string;
|
|
137
|
+
}[];
|
|
138
|
+
data: string;
|
|
139
|
+
programId: string;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type TransactionPriority = "Default" | "Low" | "Medium" | "High" | "VeryHigh" | "UnsafeMax" | "None";
|
|
143
|
+
|
|
144
|
+
export type Balance = {
|
|
145
|
+
amount: string;
|
|
146
|
+
mint: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export type UserPositionBalances = {
|
|
150
|
+
balances: Balance[],
|
|
151
|
+
fees: Balance[],
|
|
152
|
+
rewards: Balance[],
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type PoolOut = UserPositionBalances & {
|
|
156
|
+
positionAddress: string,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export type UserPortfolioOut = {
|
|
160
|
+
wallet: string,
|
|
161
|
+
userPda: string,
|
|
162
|
+
pools: Record<string, PoolOut[]>,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type OrcaPoolInfo = {
|
|
166
|
+
address: string,
|
|
167
|
+
feeApr: {
|
|
168
|
+
day: number,
|
|
169
|
+
month: number,
|
|
170
|
+
week: number,
|
|
171
|
+
}
|
|
172
|
+
lpFeeRate: number,
|
|
173
|
+
modifiedTimeMs: number,
|
|
174
|
+
price: number,
|
|
175
|
+
priceRange: {
|
|
176
|
+
day: { min: number, max: number },
|
|
177
|
+
month: { min: number, max: number },
|
|
178
|
+
week: { min: number, max: number },
|
|
179
|
+
},
|
|
180
|
+
protocolFeeRate: number,
|
|
181
|
+
reward0Apr: { day: number, week: number, month: number },
|
|
182
|
+
reward1Apr: { day: number, week: number, month: number },
|
|
183
|
+
reward2Apr: { day: number, week: number, month: number },
|
|
184
|
+
tickSpacing: number,
|
|
185
|
+
tokenA: {
|
|
186
|
+
coingeckoId: string,
|
|
187
|
+
decimals: number,
|
|
188
|
+
logoURI: string,
|
|
189
|
+
mint: string,
|
|
190
|
+
name: string,
|
|
191
|
+
poolToken: boolean,
|
|
192
|
+
symbol: string,
|
|
193
|
+
whitelisted: boolean,
|
|
194
|
+
}
|
|
195
|
+
tokenB: {
|
|
196
|
+
coingeckoId: string,
|
|
197
|
+
decimals: number,
|
|
198
|
+
logoURI: string,
|
|
199
|
+
mint: string,
|
|
200
|
+
name: string,
|
|
201
|
+
poolToken: boolean,
|
|
202
|
+
symbol: string,
|
|
203
|
+
whitelisted: boolean,
|
|
204
|
+
},
|
|
205
|
+
totalApr: { day: number, week: number, month: number },
|
|
206
|
+
tvl: number,
|
|
207
|
+
volume: { day: number, week: number, month: number },
|
|
208
|
+
volumeDenominatedA: { day: number, week: number, month: number },
|
|
209
|
+
volumeDemonimatedB: { day: number, week: number, month: number },
|
|
210
|
+
whirlpoolsConfig: string,
|
|
211
|
+
whitelisted: boolean,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export type OrcaPoolResponse = {
|
|
215
|
+
whirlpools: OrcaPoolInfo[],
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type OrcaPoolInfoIndexed = Record<string, OrcaPoolInfo>;
|
|
219
|
+
|
|
220
|
+
export type TokenAccountInfo = {
|
|
221
|
+
address: web3.PublicKey,
|
|
222
|
+
owner: web3.PublicKey,
|
|
223
|
+
mint: web3.PublicKey,
|
|
224
|
+
amount: BN,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export type ResponseWithStatus<T> = {
|
|
228
|
+
status: number,
|
|
229
|
+
data: T
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type HealthResponse = Record<string, "OK" | "NOT OK">;
|
|
233
|
+
|
|
234
|
+
export type MeteoraDlmmActiveBin = Record<string, number>;
|
|
235
|
+
|
|
236
|
+
export type TransactionMetadataResponse = {
|
|
237
|
+
description: string;
|
|
238
|
+
estimatedFeeInSOL: string,
|
|
239
|
+
addressLookupTableAddresses: string[]; // "alts" is confusing, copied jup's naming
|
|
240
|
+
computeBudgetInstructions: Instruction[]; // this enables for ease of access while also making them optional
|
|
241
|
+
mainInstructions: Instruction[];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export type TransactionMetadata = {
|
|
245
|
+
description: string,
|
|
246
|
+
estimatedFeeInSOL: string,
|
|
247
|
+
transaction: Uint8Array,
|
|
248
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
import HawkAPI from "../src";
|
|
4
|
+
import { ResponseWithStatus } from "../src/types";
|
|
5
|
+
|
|
6
|
+
const client = new HawkAPI('http://localhost:5001');
|
|
7
|
+
const TIMEOUT = 30_000;
|
|
8
|
+
const testWallet = 'Ga5jNBh26JHh9zyJcdm7vpyVWRgtKS2cLpNgEc5zBv8G';
|
|
9
|
+
const hawkWallet = 'dche7M2764e8AxNihBdn7uffVzZvTBNeL8x4LZg5E2c';
|
|
10
|
+
const connection = new web3.Connection('https://mainnet-beta.solana.com'); // change this to private rpc
|
|
11
|
+
const testPool = 'ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq';
|
|
12
|
+
const testPosition = '7kbNjgL5SUtcwqpTRbjxkmSDHeYTnPUgEGUQwm1ETdDp';
|
|
13
|
+
let activeBin: number;
|
|
14
|
+
|
|
15
|
+
describe('Health Endpoints', () => {
|
|
16
|
+
it ('GET /health', async () => {
|
|
17
|
+
const result: any = await client.health.health();
|
|
18
|
+
expect(result.status).toBe(200);
|
|
19
|
+
for (const key in result.services) {
|
|
20
|
+
expect(result.services[key]).toBe('OK');
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('General Endpoints', () => {
|
|
26
|
+
it ('GET /portfolio', async () => {
|
|
27
|
+
const result = await client.general.portfolio({ wallet: 'Ga5jNBh26JHh9zyJcdm7vpyVWRgtKS2cLpNgEc5zBv8G' });
|
|
28
|
+
expect(result.status).toBe(200);
|
|
29
|
+
for (const poolId in result.data.pools) {
|
|
30
|
+
if (result.data.pools[poolId] !== undefined) {
|
|
31
|
+
for (const position of result.data.pools[poolId]) {
|
|
32
|
+
expect(isPublicKey(position.positionAddress)).toBe(true); // Must be a valid public key
|
|
33
|
+
expect(position.balances.length >= 0).toBe(true); // Must be a valid array
|
|
34
|
+
expect(position.fees.length >= 0).toBe(true); // Must be a valid array
|
|
35
|
+
expect(position.rewards.length >= 0).toBe(true); // Must be a valid array
|
|
36
|
+
for (const balance of position.balances) {
|
|
37
|
+
expect(isInteger(balance.amount)).toBe(true);
|
|
38
|
+
expect(isPublicKey(balance.mint)).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
for (const balance of position.fees) {
|
|
41
|
+
expect(isInteger(balance.amount)).toBe(true);
|
|
42
|
+
expect(isPublicKey(balance.mint)).toBe(true);
|
|
43
|
+
}
|
|
44
|
+
for (const balance of position.rewards) {
|
|
45
|
+
expect(isInteger(balance.amount)).toBe(true);
|
|
46
|
+
expect(isPublicKey(balance.mint)).toBe(true);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, TIMEOUT);
|
|
52
|
+
|
|
53
|
+
it ('GET /pools', async () => {
|
|
54
|
+
const result = await client.general.pools();
|
|
55
|
+
expect(result.status).toBe(200);
|
|
56
|
+
expect(result.data.length >= 0).toBe(true);
|
|
57
|
+
}, TIMEOUT);
|
|
58
|
+
|
|
59
|
+
it ('POST /register', async () => {
|
|
60
|
+
const result = await client.general.register(connection, hawkWallet, { userWallet: hawkWallet });
|
|
61
|
+
logIfNot200(result);
|
|
62
|
+
expect(result.status).toBe(200);
|
|
63
|
+
}, TIMEOUT);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('Meteora Endpoints', () => {
|
|
67
|
+
it ('POST /meteora/dlmm/util/activeBin', async () => {
|
|
68
|
+
const result = await client.util.meteoraDlmmActiveBin(
|
|
69
|
+
{
|
|
70
|
+
pools: [testPool],
|
|
71
|
+
commitment: 'confirmed',
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
logIfNot200(result);
|
|
75
|
+
expect(result.status).toBe(200);
|
|
76
|
+
activeBin = result.data[testPool];
|
|
77
|
+
}, TIMEOUT);
|
|
78
|
+
it ('POST /meteora/dlmm/tx/createPositionAndDeposit', async () => {
|
|
79
|
+
const result = await client.txGenerator.meteoraCreatePositionAndDeposit(
|
|
80
|
+
connection,
|
|
81
|
+
hawkWallet,
|
|
82
|
+
{
|
|
83
|
+
position: web3.Keypair.generate().publicKey.toString(),
|
|
84
|
+
pool: testPool,
|
|
85
|
+
userWallet: testWallet,
|
|
86
|
+
totalXAmount: 10_000,
|
|
87
|
+
totalYAmount: 10_000,
|
|
88
|
+
lowerBinRange: activeBin - 20,
|
|
89
|
+
upperBinRange: activeBin + 20,
|
|
90
|
+
distribution: 'CURVE',
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
logIfNot200(result);
|
|
94
|
+
expect(result.status).toBe(200);
|
|
95
|
+
}, TIMEOUT);
|
|
96
|
+
it ('POST /meteora/dlmm/tx/deposit', async () => {
|
|
97
|
+
const result = await client.txGenerator.meteoraDeposit(
|
|
98
|
+
connection,
|
|
99
|
+
hawkWallet,
|
|
100
|
+
{
|
|
101
|
+
position: testPosition,
|
|
102
|
+
userWallet: testWallet,
|
|
103
|
+
totalXAmount: 10_000,
|
|
104
|
+
totalYAmount: 10_000,
|
|
105
|
+
distribution: 'CURVE',
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
logIfNot200(result);
|
|
109
|
+
expect(result.status).toBe(200);
|
|
110
|
+
}, TIMEOUT);
|
|
111
|
+
it ('POST /meteora/dlmm/tx/claim', async () => {
|
|
112
|
+
const result = await client.txGenerator.meteoraClaim(
|
|
113
|
+
connection,
|
|
114
|
+
hawkWallet,
|
|
115
|
+
{
|
|
116
|
+
position: testPosition,
|
|
117
|
+
userWallet: testWallet,
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
logIfNot200(result);
|
|
121
|
+
expect(result.status).toBe(200);
|
|
122
|
+
}, TIMEOUT);
|
|
123
|
+
it ('POST /meteora/dlmm/tx/withdraw', async () => {
|
|
124
|
+
const result = await client.txGenerator.meteoraWithdraw(
|
|
125
|
+
connection,
|
|
126
|
+
hawkWallet,
|
|
127
|
+
{
|
|
128
|
+
position: testPosition,
|
|
129
|
+
userWallet: testWallet,
|
|
130
|
+
amountBps: 10_000,
|
|
131
|
+
shouldClaimAndClose: true,
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
logIfNot200(result);
|
|
135
|
+
expect(result.status).toBe(200);
|
|
136
|
+
}, TIMEOUT);
|
|
137
|
+
it ('POST /meteora/dlmm/tx/closePosition', async () => { // will not work because position is not empty.
|
|
138
|
+
const result = await client.txGenerator.meteoraClosePosition(
|
|
139
|
+
connection,
|
|
140
|
+
hawkWallet,
|
|
141
|
+
{
|
|
142
|
+
position: testPosition,
|
|
143
|
+
userWallet: testWallet,
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
logIfNot200(result);
|
|
147
|
+
expect(result.status).toBe(200);
|
|
148
|
+
}, TIMEOUT);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('Meteora Automation Endpoints', () => {
|
|
152
|
+
it ('POST /meteora/dlmm/automation/claimFeeAndRewardsAutomationIx', async () => {
|
|
153
|
+
const result = await client.txGeneratorAutomation.meteoraClaimFeeAndRewards(
|
|
154
|
+
connection,
|
|
155
|
+
hawkWallet,
|
|
156
|
+
{
|
|
157
|
+
userWallet: testWallet,
|
|
158
|
+
position: testPosition,
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
logIfNot200(result);
|
|
162
|
+
expect(result.status).toBe(200);
|
|
163
|
+
}, TIMEOUT);
|
|
164
|
+
it ('POST /meteora/dlmm/automation/fullWithdrawAndClosePositionAutomationIx', async () => {
|
|
165
|
+
const result = await client.txGeneratorAutomation.meteoraFullWithdrawalAndClosePosition(
|
|
166
|
+
connection,
|
|
167
|
+
hawkWallet,
|
|
168
|
+
{
|
|
169
|
+
userWallet: testWallet,
|
|
170
|
+
position: testPosition,
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
logIfNot200(result);
|
|
174
|
+
expect(result.status).toBe(200);
|
|
175
|
+
}, TIMEOUT);
|
|
176
|
+
it ('POST /meteora/dlmm/automation/createPositionAndDepositAutomationIx', async () => { // can't test...
|
|
177
|
+
const result = await client.txGeneratorAutomation.meteoraCreatePositionAndDeposit(
|
|
178
|
+
connection,
|
|
179
|
+
hawkWallet,
|
|
180
|
+
{
|
|
181
|
+
position: web3.Keypair.generate().publicKey.toString(),
|
|
182
|
+
pool: testPool,
|
|
183
|
+
userWallet: testWallet,
|
|
184
|
+
lowerBinRange: activeBin - 20,
|
|
185
|
+
upperBinRange: activeBin + 20,
|
|
186
|
+
distribution: 'CURVE',
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
logIfNot200(result);
|
|
190
|
+
expect(result.status).toBe(200);
|
|
191
|
+
}, TIMEOUT);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('Orca Endpoints', () => {});
|
|
195
|
+
|
|
196
|
+
function isPublicKey(address: string): boolean {
|
|
197
|
+
try {
|
|
198
|
+
new web3.PublicKey(address);
|
|
199
|
+
return true;
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function isInteger(value: string): boolean {
|
|
206
|
+
return String(parseInt(value)) === value;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function logIfNot200(result: ResponseWithStatus<any>) {
|
|
210
|
+
if (result.status !== 200) {
|
|
211
|
+
console.log(result.data);
|
|
212
|
+
}
|
|
213
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
+
|
|
46
|
+
/* JavaScript Support */
|
|
47
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
+
|
|
51
|
+
/* Emit */
|
|
52
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
59
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
63
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
74
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
|
+
|
|
76
|
+
/* Interop Constraints */
|
|
77
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
81
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
83
|
+
|
|
84
|
+
/* Type Checking */
|
|
85
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
86
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
94
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
95
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
96
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
97
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
98
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
99
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
100
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
101
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
102
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
103
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
104
|
+
|
|
105
|
+
/* Completeness */
|
|
106
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
+
}
|
|
109
|
+
}
|