@hawksightco/hawk-sdk 0.0.5 → 0.0.7
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/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +358 -0
- package/dist/types.d.ts +253 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/package.json +7 -3
- package/jest.config.js +0 -5
- package/src/index.ts +0 -382
- package/src/types.ts +0 -248
- package/test/index.spec.ts +0 -213
- package/tsconfig.json +0 -109
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
export type AccountMeta = {
|
|
4
|
+
isSigner: boolean;
|
|
5
|
+
isWritable: boolean;
|
|
6
|
+
pubkey: string;
|
|
7
|
+
};
|
|
8
|
+
export type TransactionInstruction = {
|
|
9
|
+
programId: string;
|
|
10
|
+
keys: AccountMeta[];
|
|
11
|
+
data: string;
|
|
12
|
+
};
|
|
13
|
+
export type Transaction = TransactionInstruction[];
|
|
14
|
+
export type Web3Transaction = web3.TransactionInstruction[];
|
|
15
|
+
export type BinRange = {
|
|
16
|
+
lowerRange: number;
|
|
17
|
+
upperRange: number;
|
|
18
|
+
};
|
|
19
|
+
export type Distribution = "SPOT" | "CURVE" | "BID-ASK";
|
|
20
|
+
export type MeteoraCreatePositionAndDeposit = {
|
|
21
|
+
position: web3.PublicKey;
|
|
22
|
+
pool: string;
|
|
23
|
+
userWallet: web3.PublicKey;
|
|
24
|
+
totalXAmount: BN;
|
|
25
|
+
totalYAmount: BN;
|
|
26
|
+
binRange: BinRange;
|
|
27
|
+
distribution: Distribution;
|
|
28
|
+
};
|
|
29
|
+
export type MeteoraDeposit = {
|
|
30
|
+
position: web3.PublicKey;
|
|
31
|
+
pool: string;
|
|
32
|
+
userWallet: web3.PublicKey;
|
|
33
|
+
totalXAmount: BN;
|
|
34
|
+
totalYAmount: BN;
|
|
35
|
+
distribution: Distribution;
|
|
36
|
+
};
|
|
37
|
+
export type MeteoraPoolInfo = {
|
|
38
|
+
address: string;
|
|
39
|
+
name: string;
|
|
40
|
+
mint_x: string;
|
|
41
|
+
mint_y: string;
|
|
42
|
+
reserve_x: string;
|
|
43
|
+
reserve_y: string;
|
|
44
|
+
reserve_x_amount: number;
|
|
45
|
+
reserve_y_amount: number;
|
|
46
|
+
bin_step: number;
|
|
47
|
+
base_fee_percentage: string;
|
|
48
|
+
max_fee_percentage: string;
|
|
49
|
+
protocol_fee_percentage: string;
|
|
50
|
+
liquidity: string;
|
|
51
|
+
reward_mint_x: string;
|
|
52
|
+
reward_mint_y: string;
|
|
53
|
+
fees_24h: number;
|
|
54
|
+
today_fees: number;
|
|
55
|
+
trade_volume_24h: number;
|
|
56
|
+
cumulative_trade_volume: string;
|
|
57
|
+
cumulative_fee_volume: string;
|
|
58
|
+
current_price: number;
|
|
59
|
+
apr: number;
|
|
60
|
+
apy: number;
|
|
61
|
+
hide: boolean;
|
|
62
|
+
};
|
|
63
|
+
export declare enum Tags {
|
|
64
|
+
Stable = "stable",
|
|
65
|
+
Volatile = "volatile",
|
|
66
|
+
LiquidStaking = "liquid_staking",
|
|
67
|
+
Stablecoin = "stablecoins",
|
|
68
|
+
Deprecated = "deprecated"
|
|
69
|
+
}
|
|
70
|
+
export declare enum Protocol {
|
|
71
|
+
Saber = "saber",
|
|
72
|
+
Orca = "orca",
|
|
73
|
+
Meteora = "meteora"
|
|
74
|
+
}
|
|
75
|
+
interface BasePool {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
url: string;
|
|
79
|
+
tags: Tags[];
|
|
80
|
+
hidden: boolean;
|
|
81
|
+
}
|
|
82
|
+
export type Pool = (BasePool & {
|
|
83
|
+
protocol: Protocol.Saber;
|
|
84
|
+
config: SaberPoolConfig;
|
|
85
|
+
}) | (BasePool & {
|
|
86
|
+
protocol: Protocol.Orca;
|
|
87
|
+
config: OrcaPoolConfig;
|
|
88
|
+
}) | (BasePool & {
|
|
89
|
+
protocol: Protocol.Meteora;
|
|
90
|
+
config: MeteoraPoolConfig;
|
|
91
|
+
});
|
|
92
|
+
export type SaberPoolConfig = {};
|
|
93
|
+
export type OrcaPoolConfig = OrcaPoolInfo;
|
|
94
|
+
export type MeteoraPoolConfig = {
|
|
95
|
+
address: string;
|
|
96
|
+
name: string;
|
|
97
|
+
mint_x: string;
|
|
98
|
+
mint_y: string;
|
|
99
|
+
reserve_x: string;
|
|
100
|
+
reserve_y: string;
|
|
101
|
+
reward_mint_x: string;
|
|
102
|
+
reward_mint_y: string;
|
|
103
|
+
bin_step: number;
|
|
104
|
+
};
|
|
105
|
+
export type Token = {
|
|
106
|
+
address: string;
|
|
107
|
+
name: string;
|
|
108
|
+
symbol: string;
|
|
109
|
+
decimals: number;
|
|
110
|
+
logo: string;
|
|
111
|
+
};
|
|
112
|
+
export type Instruction = {
|
|
113
|
+
accounts: {
|
|
114
|
+
isSigner: boolean;
|
|
115
|
+
isWritable: boolean;
|
|
116
|
+
pubkey: string;
|
|
117
|
+
}[];
|
|
118
|
+
data: string;
|
|
119
|
+
programId: string;
|
|
120
|
+
};
|
|
121
|
+
export type TransactionPriority = "Default" | "Low" | "Medium" | "High" | "VeryHigh" | "UnsafeMax" | "None";
|
|
122
|
+
export type Balance = {
|
|
123
|
+
amount: string;
|
|
124
|
+
mint: string;
|
|
125
|
+
};
|
|
126
|
+
export type UserPositionBalances = {
|
|
127
|
+
balances: Balance[];
|
|
128
|
+
fees: Balance[];
|
|
129
|
+
rewards: Balance[];
|
|
130
|
+
};
|
|
131
|
+
export type PoolOut = UserPositionBalances & {
|
|
132
|
+
positionAddress: string;
|
|
133
|
+
};
|
|
134
|
+
export type UserPortfolioOut = {
|
|
135
|
+
wallet: string;
|
|
136
|
+
userPda: string;
|
|
137
|
+
pools: Record<string, PoolOut[]>;
|
|
138
|
+
};
|
|
139
|
+
export type OrcaPoolInfo = {
|
|
140
|
+
address: string;
|
|
141
|
+
feeApr: {
|
|
142
|
+
day: number;
|
|
143
|
+
month: number;
|
|
144
|
+
week: number;
|
|
145
|
+
};
|
|
146
|
+
lpFeeRate: number;
|
|
147
|
+
modifiedTimeMs: number;
|
|
148
|
+
price: number;
|
|
149
|
+
priceRange: {
|
|
150
|
+
day: {
|
|
151
|
+
min: number;
|
|
152
|
+
max: number;
|
|
153
|
+
};
|
|
154
|
+
month: {
|
|
155
|
+
min: number;
|
|
156
|
+
max: number;
|
|
157
|
+
};
|
|
158
|
+
week: {
|
|
159
|
+
min: number;
|
|
160
|
+
max: number;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
protocolFeeRate: number;
|
|
164
|
+
reward0Apr: {
|
|
165
|
+
day: number;
|
|
166
|
+
week: number;
|
|
167
|
+
month: number;
|
|
168
|
+
};
|
|
169
|
+
reward1Apr: {
|
|
170
|
+
day: number;
|
|
171
|
+
week: number;
|
|
172
|
+
month: number;
|
|
173
|
+
};
|
|
174
|
+
reward2Apr: {
|
|
175
|
+
day: number;
|
|
176
|
+
week: number;
|
|
177
|
+
month: number;
|
|
178
|
+
};
|
|
179
|
+
tickSpacing: number;
|
|
180
|
+
tokenA: {
|
|
181
|
+
coingeckoId: string;
|
|
182
|
+
decimals: number;
|
|
183
|
+
logoURI: string;
|
|
184
|
+
mint: string;
|
|
185
|
+
name: string;
|
|
186
|
+
poolToken: boolean;
|
|
187
|
+
symbol: string;
|
|
188
|
+
whitelisted: boolean;
|
|
189
|
+
};
|
|
190
|
+
tokenB: {
|
|
191
|
+
coingeckoId: string;
|
|
192
|
+
decimals: number;
|
|
193
|
+
logoURI: string;
|
|
194
|
+
mint: string;
|
|
195
|
+
name: string;
|
|
196
|
+
poolToken: boolean;
|
|
197
|
+
symbol: string;
|
|
198
|
+
whitelisted: boolean;
|
|
199
|
+
};
|
|
200
|
+
totalApr: {
|
|
201
|
+
day: number;
|
|
202
|
+
week: number;
|
|
203
|
+
month: number;
|
|
204
|
+
};
|
|
205
|
+
tvl: number;
|
|
206
|
+
volume: {
|
|
207
|
+
day: number;
|
|
208
|
+
week: number;
|
|
209
|
+
month: number;
|
|
210
|
+
};
|
|
211
|
+
volumeDenominatedA: {
|
|
212
|
+
day: number;
|
|
213
|
+
week: number;
|
|
214
|
+
month: number;
|
|
215
|
+
};
|
|
216
|
+
volumeDemonimatedB: {
|
|
217
|
+
day: number;
|
|
218
|
+
week: number;
|
|
219
|
+
month: number;
|
|
220
|
+
};
|
|
221
|
+
whirlpoolsConfig: string;
|
|
222
|
+
whitelisted: boolean;
|
|
223
|
+
};
|
|
224
|
+
export type OrcaPoolResponse = {
|
|
225
|
+
whirlpools: OrcaPoolInfo[];
|
|
226
|
+
};
|
|
227
|
+
export type OrcaPoolInfoIndexed = Record<string, OrcaPoolInfo>;
|
|
228
|
+
export type TokenAccountInfo = {
|
|
229
|
+
address: web3.PublicKey;
|
|
230
|
+
owner: web3.PublicKey;
|
|
231
|
+
mint: web3.PublicKey;
|
|
232
|
+
amount: BN;
|
|
233
|
+
};
|
|
234
|
+
export type ResponseWithStatus<T> = {
|
|
235
|
+
status: number;
|
|
236
|
+
data: T;
|
|
237
|
+
};
|
|
238
|
+
export type HealthResponse = Record<string, "OK" | "NOT OK">;
|
|
239
|
+
export type MeteoraDlmmActiveBin = Record<string, number>;
|
|
240
|
+
export type TransactionMetadataResponse = {
|
|
241
|
+
description: string;
|
|
242
|
+
estimatedFeeInSOL: string;
|
|
243
|
+
addressLookupTableAddresses: string[];
|
|
244
|
+
computeBudgetInstructions: Instruction[];
|
|
245
|
+
mainInstructions: Instruction[];
|
|
246
|
+
};
|
|
247
|
+
export type TransactionMetadata = {
|
|
248
|
+
description: string;
|
|
249
|
+
estimatedFeeInSOL: string;
|
|
250
|
+
transaction: Uint8Array;
|
|
251
|
+
};
|
|
252
|
+
export {};
|
|
253
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Protocol = exports.Tags = void 0;
|
|
4
|
+
var Tags;
|
|
5
|
+
(function (Tags) {
|
|
6
|
+
Tags["Stable"] = "stable";
|
|
7
|
+
Tags["Volatile"] = "volatile";
|
|
8
|
+
Tags["LiquidStaking"] = "liquid_staking";
|
|
9
|
+
Tags["Stablecoin"] = "stablecoins";
|
|
10
|
+
Tags["Deprecated"] = "deprecated";
|
|
11
|
+
})(Tags || (exports.Tags = Tags = {}));
|
|
12
|
+
var Protocol;
|
|
13
|
+
(function (Protocol) {
|
|
14
|
+
Protocol["Saber"] = "saber";
|
|
15
|
+
Protocol["Orca"] = "orca";
|
|
16
|
+
Protocol["Meteora"] = "meteora";
|
|
17
|
+
})(Protocol || (exports.Protocol = Protocol = {}));
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hawksightco/hawk-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Hawksight v2 SDK",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://github.com/ghabxph/hawk-api-client.git",
|
|
7
7
|
"homepage": "https://hawksight.co/",
|
|
8
8
|
"author": "Hawksight",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
10
13
|
"devDependencies": {
|
|
11
14
|
"@types/bn.js": "^5.1.5",
|
|
12
15
|
"@types/jest": "^29.5.11",
|
|
@@ -32,6 +35,7 @@
|
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
37
|
"start": "npx ts-node src/index.ts",
|
|
35
|
-
"test": "npx jest"
|
|
38
|
+
"test": "npx jest",
|
|
39
|
+
"build": "tsc --outDir dist/"
|
|
36
40
|
}
|
|
37
41
|
}
|
package/jest.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
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
|
-
}
|