@hawksightco/hawk-sdk 1.0.0 → 1.0.2
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/src/anchor.d.ts +2 -0
- package/dist/src/anchor.d.ts.map +1 -1
- package/dist/src/anchor.js +2 -3
- package/dist/src/classes/Transactions.d.ts +28 -1
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +363 -39
- package/dist/src/classes/TxGenerator.d.ts +45 -0
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +191 -0
- package/dist/src/orca.d.ts +42 -0
- package/dist/src/orca.d.ts.map +1 -0
- package/dist/src/orca.js +85 -0
- package/package.json +5 -3
package/dist/src/anchor.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import * as web3 from "@solana/web3.js";
|
|
|
3
3
|
import * as anchor from "@coral-xyz/anchor";
|
|
4
4
|
import { IndexYieldFarming } from "./idl/iyf-main-idl";
|
|
5
5
|
import { IyfExtension } from "./idl/iyf-extension-idl";
|
|
6
|
+
import { WhirlpoolContext } from "@orca-so/whirlpools-sdk";
|
|
6
7
|
export declare class Anchor {
|
|
7
8
|
connection: web3.Connection;
|
|
8
9
|
private static _instance;
|
|
9
10
|
provider: anchor.AnchorProvider;
|
|
10
11
|
iyfMain: anchor.Program<IndexYieldFarming>;
|
|
11
12
|
iyfExtension: anchor.Program<IyfExtension>;
|
|
13
|
+
whirlpoolCtx: WhirlpoolContext;
|
|
12
14
|
private constructor();
|
|
13
15
|
static initialize(connection: web3.Connection): void;
|
|
14
16
|
static instance(): Anchor;
|
package/dist/src/anchor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../src/anchor.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAwB,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../src/anchor.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAwB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAO7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qBAAa,MAAM;IASR,UAAU,EAAE,IAAI,CAAC,UAAU;IAPpC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IACjC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3C,YAAY,EAAE,gBAAgB,CAAA;IAE9B,OAAO;IASP,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IAI7C,MAAM,CAAC,QAAQ,IAAI,MAAM;CAO1B"}
|
package/dist/src/anchor.js
CHANGED
|
@@ -33,15 +33,14 @@ const iyf_main_idl_1 = require("./idl/iyf-main-idl");
|
|
|
33
33
|
const iyf_extension_idl_1 = require("./idl/iyf-extension-idl");
|
|
34
34
|
const nodewallet_1 = __importDefault(require("@coral-xyz/anchor/dist/cjs/nodewallet"));
|
|
35
35
|
const addresses_1 = require("./addresses");
|
|
36
|
-
|
|
36
|
+
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
37
37
|
class Anchor {
|
|
38
|
-
// whirlpoolCtx:
|
|
39
38
|
constructor(connection) {
|
|
40
39
|
this.connection = connection;
|
|
41
40
|
this.provider = new anchor.AnchorProvider(connection, new nodewallet_1.default(web3.Keypair.generate()), {});
|
|
42
41
|
this.iyfMain = new anchor.Program(iyf_main_idl_1.IDL, addresses_1.IYF_MAIN, this.provider);
|
|
43
42
|
this.iyfExtension = new anchor.Program(iyf_extension_idl_1.IDL, addresses_1.IYF_EXTENSION, this.provider);
|
|
44
|
-
|
|
43
|
+
this.whirlpoolCtx = whirlpools_sdk_1.WhirlpoolContext.withProvider(this.provider, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
45
44
|
}
|
|
46
45
|
static initialize(connection) {
|
|
47
46
|
Anchor._instance = new Anchor(connection);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
2
|
import * as web3 from "@solana/web3.js";
|
|
3
|
-
import { MeteoraClaim, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, OrcaOpenPosition, OrcaClosePosition, TransactionMetadataResponse } from '../types';
|
|
3
|
+
import { MeteoraClaim, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, OrcaOpenPosition, OrcaClosePosition, OrcaDeposit, OrcaWithdraw, OrcaClaimRewards, TransactionMetadataResponse } from '../types';
|
|
4
4
|
export declare class Transactions {
|
|
5
5
|
/**
|
|
6
6
|
* Generate UserPDA
|
|
@@ -103,6 +103,33 @@ export declare class Transactions {
|
|
|
103
103
|
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
104
104
|
*/
|
|
105
105
|
orcaClosePosition({ connection, params }: TxgenParams<OrcaClosePosition>): Promise<TransactionMetadataResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Creates orca instruction that deposits to a position
|
|
108
|
+
*
|
|
109
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
110
|
+
* @param payer The public key of the payer for transaction fees.
|
|
111
|
+
* @param params Parameters required
|
|
112
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
113
|
+
*/
|
|
114
|
+
orcaDeposit({ connection, params }: TxgenParams<OrcaDeposit>): Promise<TransactionMetadataResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Creates orca instruction that withdraws from a position
|
|
117
|
+
*
|
|
118
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
119
|
+
* @param payer The public key of the payer for transaction fees.
|
|
120
|
+
* @param params Parameters required
|
|
121
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
122
|
+
*/
|
|
123
|
+
orcaWithdraw({ connection, params }: TxgenParams<OrcaWithdraw>): Promise<TransactionMetadataResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates orca instruction that claims fees and rewards
|
|
126
|
+
*
|
|
127
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
128
|
+
* @param payer The public key of the payer for transaction fees.
|
|
129
|
+
* @param params Parameters required
|
|
130
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
131
|
+
*/
|
|
132
|
+
orcaClaimRewards({ connection, params }: TxgenParams<OrcaClaimRewards>): Promise<TransactionMetadataResponse>;
|
|
106
133
|
}
|
|
107
134
|
export declare const txgen: Transactions;
|
|
108
135
|
//# sourceMappingURL=Transactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes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,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAoGpH;AAED,eAAO,MAAM,KAAK,cAAqB,CAAC"}
|
|
@@ -40,12 +40,13 @@ const dlmm_1 = require("@meteora-ag/dlmm");
|
|
|
40
40
|
const web3 = __importStar(require("@solana/web3.js"));
|
|
41
41
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
42
42
|
const addresses_1 = require("../addresses");
|
|
43
|
-
const functions_1 = require("../functions");
|
|
44
43
|
const types_1 = require("../types");
|
|
45
|
-
const
|
|
44
|
+
const functions_1 = require("../functions");
|
|
45
|
+
const orca_1 = require("../orca");
|
|
46
46
|
const hsToMeteora_1 = require("../hsToMeteora");
|
|
47
47
|
const meteora_1 = require("../meteora");
|
|
48
48
|
const anchor_1 = require("../anchor");
|
|
49
|
+
const hawksight_1 = require("../hawksight");
|
|
49
50
|
const types_2 = require("../types");
|
|
50
51
|
class Transactions {
|
|
51
52
|
/**
|
|
@@ -56,7 +57,7 @@ class Transactions {
|
|
|
56
57
|
* @returns
|
|
57
58
|
*/
|
|
58
59
|
generateUserPda(userWallet, farm = addresses_1.USDC_FARM) {
|
|
59
|
-
return (0,
|
|
60
|
+
return (0, functions_1.generateUserPda)(userWallet, farm);
|
|
60
61
|
}
|
|
61
62
|
/**s
|
|
62
63
|
* Registers a new entity or user with the necessary parameters, handling transaction creation and response.
|
|
@@ -69,7 +70,7 @@ class Transactions {
|
|
|
69
70
|
register(_a) {
|
|
70
71
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
71
72
|
const farm = addresses_1.USDC_FARM;
|
|
72
|
-
const user = (0,
|
|
73
|
+
const user = (0, functions_1.generateUserPda)(params.authority, farm);
|
|
73
74
|
const [stableToken] = web3.PublicKey.findProgramAddressSync([
|
|
74
75
|
Buffer.from("index-token", "utf-8"),
|
|
75
76
|
addresses_1.STABLEMINT_1.toBuffer(),
|
|
@@ -88,7 +89,7 @@ class Transactions {
|
|
|
88
89
|
throw new Error(`User PDA for wallet: ${params.authority} is already registered.`);
|
|
89
90
|
}
|
|
90
91
|
catch (_b) {
|
|
91
|
-
return (0,
|
|
92
|
+
return (0, functions_1.createTransactionMeta)({
|
|
92
93
|
payer: params.authority,
|
|
93
94
|
description: "Register User",
|
|
94
95
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -124,7 +125,7 @@ class Transactions {
|
|
|
124
125
|
meteoraCreatePositionAndDeposit(_a) {
|
|
125
126
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
126
127
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool));
|
|
127
|
-
const userPda = (0,
|
|
128
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
128
129
|
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
129
130
|
positionPubKey: params.position,
|
|
130
131
|
user: userPda,
|
|
@@ -138,7 +139,7 @@ class Transactions {
|
|
|
138
139
|
slippage: params.slippage,
|
|
139
140
|
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
140
141
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
141
|
-
return (0,
|
|
142
|
+
return (0, functions_1.createTransactionMeta)({
|
|
142
143
|
payer: params.userWallet,
|
|
143
144
|
description: "Create position and deposit to Meteora DLMM",
|
|
144
145
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -160,7 +161,7 @@ class Transactions {
|
|
|
160
161
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress);
|
|
161
162
|
const binArraysRequired = yield (0, dlmm_1.getBinArraysRequiredByPositionRange)(poolAddress, new bn_js_1.default(params.minBinId), new bn_js_1.default(params.maxBinId), dlmmPool.dlmm.program.programId);
|
|
162
163
|
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map((b) => b.index), new web3.PublicKey(params.userWallet));
|
|
163
|
-
return (0,
|
|
164
|
+
return (0, functions_1.createTransactionMeta)({
|
|
164
165
|
payer: params.userWallet,
|
|
165
166
|
description: "Initialize bin arrays for Meteora DLMM pool",
|
|
166
167
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -192,7 +193,7 @@ class Transactions {
|
|
|
192
193
|
minBinId = position.lowerBinId;
|
|
193
194
|
}
|
|
194
195
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(lbPair));
|
|
195
|
-
const userPda = (0,
|
|
196
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
196
197
|
const mainInstructions = (yield dlmmPool.addLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
197
198
|
positionPubKey: params.position,
|
|
198
199
|
user: userPda,
|
|
@@ -206,7 +207,7 @@ class Transactions {
|
|
|
206
207
|
slippage: params.slippage,
|
|
207
208
|
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
208
209
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
209
|
-
return (0,
|
|
210
|
+
return (0, functions_1.createTransactionMeta)({
|
|
210
211
|
payer: params.userWallet,
|
|
211
212
|
description: "Deposit to existing position in Meteora DLMM",
|
|
212
213
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -224,7 +225,7 @@ class Transactions {
|
|
|
224
225
|
*/
|
|
225
226
|
meteoraWithdraw(_a) {
|
|
226
227
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
227
|
-
const userPda = (0,
|
|
228
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
228
229
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
229
230
|
let lbPair, binIdsToRemove;
|
|
230
231
|
if (params.fastGeneration !== undefined) {
|
|
@@ -268,7 +269,7 @@ class Transactions {
|
|
|
268
269
|
else {
|
|
269
270
|
description = "Partial position withdrawal from Meteora DLMM";
|
|
270
271
|
}
|
|
271
|
-
return (0,
|
|
272
|
+
return (0, functions_1.createTransactionMeta)({
|
|
272
273
|
payer: params.userWallet,
|
|
273
274
|
description,
|
|
274
275
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -296,14 +297,14 @@ class Transactions {
|
|
|
296
297
|
lbPair = position.lbPair;
|
|
297
298
|
}
|
|
298
299
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
299
|
-
const userPda = (0,
|
|
300
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
300
301
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
301
302
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
302
303
|
const mainInstructions = (yield dlmmPool.claimAllRewardsByPosition(params.userWallet, params.userWallet, {
|
|
303
304
|
owner: userPda,
|
|
304
305
|
position: userPositions[index],
|
|
305
306
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
306
|
-
return (0,
|
|
307
|
+
return (0, functions_1.createTransactionMeta)({
|
|
307
308
|
payer: params.userWallet,
|
|
308
309
|
description: "Claim fees / rewards from Meteora DLMM Position",
|
|
309
310
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -324,7 +325,7 @@ class Transactions {
|
|
|
324
325
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
325
326
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
326
327
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
327
|
-
const userPda = (0,
|
|
328
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
328
329
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
329
330
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
330
331
|
yield dlmmPool.getActiveBin();
|
|
@@ -332,7 +333,7 @@ class Transactions {
|
|
|
332
333
|
owner: userPda,
|
|
333
334
|
position: userPositions[index],
|
|
334
335
|
}, hsToMeteora_1.meteoraToHawksight);
|
|
335
|
-
return (0,
|
|
336
|
+
return (0, functions_1.createTransactionMeta)({
|
|
336
337
|
payer: params.userWallet,
|
|
337
338
|
description: "Close Meteora DLMM Position",
|
|
338
339
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -345,7 +346,7 @@ class Transactions {
|
|
|
345
346
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
346
347
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
347
348
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
348
|
-
const userPda = (0,
|
|
349
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
349
350
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
350
351
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
351
352
|
// Claim fee and claim reward ixs
|
|
@@ -374,7 +375,7 @@ class Transactions {
|
|
|
374
375
|
// Step 3: Re-deposit fees
|
|
375
376
|
...addLiquidityBuilder.mainIxs,
|
|
376
377
|
];
|
|
377
|
-
return (0,
|
|
378
|
+
return (0, functions_1.createTransactionMeta)({
|
|
378
379
|
payer: params.userWallet,
|
|
379
380
|
description: "Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)",
|
|
380
381
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -387,7 +388,7 @@ class Transactions {
|
|
|
387
388
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
388
389
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
389
390
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
390
|
-
const userPda = (0,
|
|
391
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
391
392
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
392
393
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
393
394
|
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
@@ -433,7 +434,7 @@ class Transactions {
|
|
|
433
434
|
// Sweep dust
|
|
434
435
|
...sweepLiquidityBuilder.mainIxs,
|
|
435
436
|
];
|
|
436
|
-
return (0,
|
|
437
|
+
return (0, functions_1.createTransactionMeta)({
|
|
437
438
|
payer: params.userWallet,
|
|
438
439
|
description: "Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)",
|
|
439
440
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -452,7 +453,7 @@ class Transactions {
|
|
|
452
453
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
453
454
|
const activePoolRewards = [];
|
|
454
455
|
const mainInstructions = [];
|
|
455
|
-
const userPda = (0,
|
|
456
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
456
457
|
if (params.protocol === types_2.Protocol.Meteora && params.pool) {
|
|
457
458
|
const poolInfo = yield (0, functions_1.getMeteoraPool)(params.pool);
|
|
458
459
|
if (poolInfo.reward_mint_x !== "11111111111111111111111111111111") {
|
|
@@ -464,7 +465,7 @@ class Transactions {
|
|
|
464
465
|
}
|
|
465
466
|
const combinedMints = [...params.mints, ...activePoolRewards];
|
|
466
467
|
const filteredMints = combinedMints.filter((m, i) => combinedMints.findIndex((mint) => mint.equals(m)) === i);
|
|
467
|
-
const storageAddresses = filteredMints.map((mint) => (0,
|
|
468
|
+
const storageAddresses = filteredMints.map((mint) => (0, functions_1.generateUserPdaStorageAccount)(userPda, mint));
|
|
468
469
|
const accountsData = yield connection.getMultipleAccountsInfo(storageAddresses, "processed");
|
|
469
470
|
for (let i = 0; i < accountsData.length; i++) {
|
|
470
471
|
if (!accountsData[i]) {
|
|
@@ -484,7 +485,7 @@ class Transactions {
|
|
|
484
485
|
}
|
|
485
486
|
}
|
|
486
487
|
if (mainInstructions.length) {
|
|
487
|
-
return (0,
|
|
488
|
+
return (0, functions_1.createTransactionMeta)({
|
|
488
489
|
payer: params.userWallet,
|
|
489
490
|
description: "Initialize STAs",
|
|
490
491
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -499,7 +500,7 @@ class Transactions {
|
|
|
499
500
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
500
501
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
501
502
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
502
|
-
const userPda = (0,
|
|
503
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
503
504
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
504
505
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
505
506
|
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
@@ -512,7 +513,7 @@ class Transactions {
|
|
|
512
513
|
shouldClaimAndClose: true,
|
|
513
514
|
});
|
|
514
515
|
// Filter out non-meteora instructions
|
|
515
|
-
const ixs = (0,
|
|
516
|
+
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
516
517
|
const farm = addresses_1.USDC_FARM;
|
|
517
518
|
const authority = params.userWallet;
|
|
518
519
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -530,8 +531,8 @@ class Transactions {
|
|
|
530
531
|
position: _position.pubkey,
|
|
531
532
|
lbPair: lbPair.pubkey,
|
|
532
533
|
binArrayBitmapExtension: binArrayBitmapExtension.pubkey,
|
|
533
|
-
userTokenX: (0,
|
|
534
|
-
userTokenY: (0,
|
|
534
|
+
userTokenX: (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenXMint.pubkey),
|
|
535
|
+
userTokenY: (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenYMint.pubkey),
|
|
535
536
|
reserveX: reserveX.pubkey,
|
|
536
537
|
reserveY: reserveY.pubkey,
|
|
537
538
|
tokenXMint: tokenXMint.pubkey,
|
|
@@ -542,8 +543,8 @@ class Transactions {
|
|
|
542
543
|
binArrayUpper: binArrayUpper.pubkey,
|
|
543
544
|
eventAuthority: eventAuthority.pubkey,
|
|
544
545
|
meteoraDlmmProgram: meteoraDlmmProgram.pubkey,
|
|
545
|
-
ownerFeeX: (0,
|
|
546
|
-
ownerFeeY: (0,
|
|
546
|
+
ownerFeeX: (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, tokenXMint.pubkey),
|
|
547
|
+
ownerFeeY: (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, tokenYMint.pubkey),
|
|
547
548
|
})
|
|
548
549
|
.instruction();
|
|
549
550
|
// Instruction via main hawksight contract
|
|
@@ -581,7 +582,7 @@ class Transactions {
|
|
|
581
582
|
// Limit Close Automation Instruction (Hawksight CPI)
|
|
582
583
|
ix,
|
|
583
584
|
];
|
|
584
|
-
return (0,
|
|
585
|
+
return (0, functions_1.createTransactionMeta)({
|
|
585
586
|
payer: params.userWallet,
|
|
586
587
|
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
587
588
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -592,7 +593,7 @@ class Transactions {
|
|
|
592
593
|
removeLiquidityByRangeInfo(ixs) {
|
|
593
594
|
for (const ix of ixs) {
|
|
594
595
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
595
|
-
const _sighashMatch = (0,
|
|
596
|
+
const _sighashMatch = (0, functions_1.sighashMatch)(ix.data, "RemoveLiquidityByRange");
|
|
596
597
|
if (programIdMatch && _sighashMatch) {
|
|
597
598
|
return {
|
|
598
599
|
data: ix.data,
|
|
@@ -630,9 +631,9 @@ class Transactions {
|
|
|
630
631
|
orcaOpenPosition(_a) {
|
|
631
632
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
632
633
|
const farm = addresses_1.USDC_FARM;
|
|
633
|
-
const userPda = (0,
|
|
634
|
-
const position = (0,
|
|
635
|
-
const positionTokenAccount = (0,
|
|
634
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
635
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
636
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
636
637
|
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
637
638
|
.orcaOpenPosition(params.tickLowerIndex, params.tickUpperIndex)
|
|
638
639
|
.accounts({
|
|
@@ -673,7 +674,7 @@ class Transactions {
|
|
|
673
674
|
])
|
|
674
675
|
.instruction();
|
|
675
676
|
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
676
|
-
return (0,
|
|
677
|
+
return (0, functions_1.createTransactionMeta)({
|
|
677
678
|
payer: params.userWallet,
|
|
678
679
|
description: "Create new Orca Position",
|
|
679
680
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -692,9 +693,9 @@ class Transactions {
|
|
|
692
693
|
orcaClosePosition(_a) {
|
|
693
694
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
694
695
|
const farm = addresses_1.USDC_FARM;
|
|
695
|
-
const userPda = (0,
|
|
696
|
-
const position = (0,
|
|
697
|
-
const positionTokenAccount = (0,
|
|
696
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
697
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
698
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
698
699
|
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
699
700
|
.orcaClosePosition()
|
|
700
701
|
.accounts({
|
|
@@ -729,7 +730,7 @@ class Transactions {
|
|
|
729
730
|
])
|
|
730
731
|
.instruction();
|
|
731
732
|
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
732
|
-
return (0,
|
|
733
|
+
return (0, functions_1.createTransactionMeta)({
|
|
733
734
|
payer: params.userWallet,
|
|
734
735
|
description: "Close Orca Position",
|
|
735
736
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -737,6 +738,329 @@ class Transactions {
|
|
|
737
738
|
});
|
|
738
739
|
});
|
|
739
740
|
}
|
|
741
|
+
/**
|
|
742
|
+
* Creates orca instruction that deposits to a position
|
|
743
|
+
*
|
|
744
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
745
|
+
* @param payer The public key of the payer for transaction fees.
|
|
746
|
+
* @param params Parameters required
|
|
747
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
748
|
+
*/
|
|
749
|
+
orcaDeposit(_a) {
|
|
750
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
751
|
+
const farm = addresses_1.USDC_FARM;
|
|
752
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
753
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
754
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
755
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
756
|
+
if (positionData === null) {
|
|
757
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
758
|
+
}
|
|
759
|
+
const whirlpool = positionData.whirlpool;
|
|
760
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
761
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
762
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
763
|
+
const tokenSeeds = [
|
|
764
|
+
{ owner: params.userWallet, mint: mintA },
|
|
765
|
+
{ owner: params.userWallet, mint: mintB },
|
|
766
|
+
];
|
|
767
|
+
const resultMap = yield (0, functions_1.tokenAccountExists)(connection, tokenSeeds);
|
|
768
|
+
resultMap.map((result, index) => {
|
|
769
|
+
const tokenKey = result.tokenKey;
|
|
770
|
+
const token = tokenSeeds[index];
|
|
771
|
+
if (!result.exists) {
|
|
772
|
+
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
776
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
777
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
778
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
779
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
780
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
781
|
+
const depositIx = yield (0, hawksight_1.depositMultipleToken)({
|
|
782
|
+
payer: params.userWallet,
|
|
783
|
+
deposit: [
|
|
784
|
+
{
|
|
785
|
+
mint: mintA,
|
|
786
|
+
amount: params.totalXAmount,
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
mint: mintB,
|
|
790
|
+
amount: params.totalYAmount,
|
|
791
|
+
},
|
|
792
|
+
]
|
|
793
|
+
});
|
|
794
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
795
|
+
.orcaDeposit()
|
|
796
|
+
.accounts({
|
|
797
|
+
farm,
|
|
798
|
+
userPda,
|
|
799
|
+
authority: params.userWallet,
|
|
800
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
801
|
+
positionMint: params.positionMint,
|
|
802
|
+
whirlpool,
|
|
803
|
+
position,
|
|
804
|
+
positionTokenAccount,
|
|
805
|
+
tokenOwnerAccountA,
|
|
806
|
+
tokenOwnerAccountB,
|
|
807
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
808
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
809
|
+
tickArrayLower,
|
|
810
|
+
tickArrayUpper,
|
|
811
|
+
ownerFeeA,
|
|
812
|
+
ownerFeeB,
|
|
813
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
814
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
815
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
816
|
+
})
|
|
817
|
+
.instruction();
|
|
818
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
819
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
820
|
+
.accounts({
|
|
821
|
+
farm,
|
|
822
|
+
userPda,
|
|
823
|
+
authority: params.userWallet,
|
|
824
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
825
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
826
|
+
})
|
|
827
|
+
.remainingAccounts([
|
|
828
|
+
orcaOpenPositionIx.keys[4],
|
|
829
|
+
orcaOpenPositionIx.keys[5],
|
|
830
|
+
orcaOpenPositionIx.keys[6],
|
|
831
|
+
orcaOpenPositionIx.keys[7],
|
|
832
|
+
orcaOpenPositionIx.keys[8],
|
|
833
|
+
orcaOpenPositionIx.keys[9],
|
|
834
|
+
orcaOpenPositionIx.keys[10],
|
|
835
|
+
orcaOpenPositionIx.keys[11],
|
|
836
|
+
orcaOpenPositionIx.keys[12],
|
|
837
|
+
orcaOpenPositionIx.keys[13],
|
|
838
|
+
orcaOpenPositionIx.keys[14],
|
|
839
|
+
orcaOpenPositionIx.keys[15],
|
|
840
|
+
orcaOpenPositionIx.keys[16],
|
|
841
|
+
orcaOpenPositionIx.keys[17],
|
|
842
|
+
orcaOpenPositionIx.keys[18],
|
|
843
|
+
])
|
|
844
|
+
.instruction();
|
|
845
|
+
const clearRemainingTokensIxs = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
846
|
+
payer: params.userWallet,
|
|
847
|
+
withdraw: [
|
|
848
|
+
{ mint: mintA },
|
|
849
|
+
{ mint: mintB },
|
|
850
|
+
],
|
|
851
|
+
});
|
|
852
|
+
const mainInstructions = [depositIx, orcaOpenPositionIxViaMain, clearRemainingTokensIxs];
|
|
853
|
+
return (0, functions_1.createTransactionMeta)({
|
|
854
|
+
payer: params.userWallet,
|
|
855
|
+
description: `Deposit to Orca Position: ${position}`,
|
|
856
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
857
|
+
mainInstructions,
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Creates orca instruction that withdraws from a position
|
|
863
|
+
*
|
|
864
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
865
|
+
* @param payer The public key of the payer for transaction fees.
|
|
866
|
+
* @param params Parameters required
|
|
867
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
868
|
+
*/
|
|
869
|
+
orcaWithdraw(_a) {
|
|
870
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
871
|
+
const farm = addresses_1.USDC_FARM;
|
|
872
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
873
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
874
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
875
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
876
|
+
if (positionData === null) {
|
|
877
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
878
|
+
}
|
|
879
|
+
const whirlpool = positionData.whirlpool;
|
|
880
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
881
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
882
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
883
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
884
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
885
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
886
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
887
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
888
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
889
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
890
|
+
.orcaWithdraw(params.liquidityAmount)
|
|
891
|
+
.accounts({
|
|
892
|
+
farm,
|
|
893
|
+
userPda,
|
|
894
|
+
authority: params.userWallet,
|
|
895
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
896
|
+
positionMint: params.positionMint,
|
|
897
|
+
whirlpool,
|
|
898
|
+
position,
|
|
899
|
+
positionTokenAccount,
|
|
900
|
+
tokenOwnerAccountA,
|
|
901
|
+
tokenOwnerAccountB,
|
|
902
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
903
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
904
|
+
tickArrayLower,
|
|
905
|
+
tickArrayUpper,
|
|
906
|
+
ownerFeeA,
|
|
907
|
+
ownerFeeB,
|
|
908
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
909
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
910
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
911
|
+
})
|
|
912
|
+
.instruction();
|
|
913
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
914
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
915
|
+
.accounts({
|
|
916
|
+
farm,
|
|
917
|
+
userPda,
|
|
918
|
+
authority: params.userWallet,
|
|
919
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
920
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
921
|
+
})
|
|
922
|
+
.remainingAccounts([
|
|
923
|
+
orcaOpenPositionIx.keys[4],
|
|
924
|
+
orcaOpenPositionIx.keys[5],
|
|
925
|
+
orcaOpenPositionIx.keys[6],
|
|
926
|
+
orcaOpenPositionIx.keys[7],
|
|
927
|
+
orcaOpenPositionIx.keys[8],
|
|
928
|
+
orcaOpenPositionIx.keys[9],
|
|
929
|
+
orcaOpenPositionIx.keys[10],
|
|
930
|
+
orcaOpenPositionIx.keys[11],
|
|
931
|
+
orcaOpenPositionIx.keys[12],
|
|
932
|
+
orcaOpenPositionIx.keys[13],
|
|
933
|
+
orcaOpenPositionIx.keys[14],
|
|
934
|
+
orcaOpenPositionIx.keys[15],
|
|
935
|
+
orcaOpenPositionIx.keys[16],
|
|
936
|
+
orcaOpenPositionIx.keys[17],
|
|
937
|
+
orcaOpenPositionIx.keys[18],
|
|
938
|
+
])
|
|
939
|
+
.instruction();
|
|
940
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
941
|
+
payer: params.userWallet,
|
|
942
|
+
withdraw: [
|
|
943
|
+
{ mint: mintA },
|
|
944
|
+
{ mint: mintB },
|
|
945
|
+
],
|
|
946
|
+
});
|
|
947
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
948
|
+
return (0, functions_1.createTransactionMeta)({
|
|
949
|
+
payer: params.userWallet,
|
|
950
|
+
description: `Withdraw deposits from Orca Position: ${position}`,
|
|
951
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
952
|
+
mainInstructions,
|
|
953
|
+
});
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Creates orca instruction that claims fees and rewards
|
|
958
|
+
*
|
|
959
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
960
|
+
* @param payer The public key of the payer for transaction fees.
|
|
961
|
+
* @param params Parameters required
|
|
962
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
963
|
+
*/
|
|
964
|
+
orcaClaimRewards(_a) {
|
|
965
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
966
|
+
const farm = addresses_1.USDC_FARM;
|
|
967
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
968
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
969
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
970
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
971
|
+
if (positionData === null) {
|
|
972
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
973
|
+
}
|
|
974
|
+
const whirlpool = positionData.whirlpool;
|
|
975
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
976
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
977
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
978
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
979
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
980
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
981
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
982
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
983
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
984
|
+
const remainingAccounts = [];
|
|
985
|
+
for (const rewardInfo of whirlpoolData.rewardInfos) {
|
|
986
|
+
if (rewardInfo.mint.toString() !== web3.SystemProgram.programId.toString()) {
|
|
987
|
+
const rewardOwnerAccount = (0, functions_1.generateAta)(userPda, rewardInfo.mint);
|
|
988
|
+
const rewardVault = rewardInfo.vault;
|
|
989
|
+
const rewardFee = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, rewardInfo.mint);
|
|
990
|
+
remainingAccounts.push({ pubkey: rewardOwnerAccount, isSigner: false, isWritable: true });
|
|
991
|
+
remainingAccounts.push({ pubkey: rewardVault, isSigner: false, isWritable: true });
|
|
992
|
+
remainingAccounts.push({ pubkey: rewardFee, isSigner: false, isWritable: true });
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
whirlpoolData.rewardInfos[0].mint;
|
|
996
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
997
|
+
.orcaClaimRewards()
|
|
998
|
+
.accounts({
|
|
999
|
+
farm,
|
|
1000
|
+
userPda,
|
|
1001
|
+
authority: params.userWallet,
|
|
1002
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1003
|
+
whirlpool,
|
|
1004
|
+
positionMint: params.positionMint,
|
|
1005
|
+
position,
|
|
1006
|
+
tickArrayLower,
|
|
1007
|
+
tickArrayUpper,
|
|
1008
|
+
positionTokenAccount,
|
|
1009
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
1010
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
1011
|
+
tokenOwnerAccountA,
|
|
1012
|
+
tokenOwnerAccountB,
|
|
1013
|
+
ownerFeeA,
|
|
1014
|
+
ownerFeeB,
|
|
1015
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
1016
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1017
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
1018
|
+
})
|
|
1019
|
+
.remainingAccounts(remainingAccounts)
|
|
1020
|
+
.instruction();
|
|
1021
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1022
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
1023
|
+
.accounts({
|
|
1024
|
+
farm,
|
|
1025
|
+
userPda,
|
|
1026
|
+
authority: params.userWallet,
|
|
1027
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1028
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1029
|
+
})
|
|
1030
|
+
.remainingAccounts([
|
|
1031
|
+
orcaOpenPositionIx.keys[4],
|
|
1032
|
+
orcaOpenPositionIx.keys[5],
|
|
1033
|
+
orcaOpenPositionIx.keys[6],
|
|
1034
|
+
orcaOpenPositionIx.keys[7],
|
|
1035
|
+
orcaOpenPositionIx.keys[8],
|
|
1036
|
+
orcaOpenPositionIx.keys[9],
|
|
1037
|
+
orcaOpenPositionIx.keys[10],
|
|
1038
|
+
orcaOpenPositionIx.keys[11],
|
|
1039
|
+
orcaOpenPositionIx.keys[12],
|
|
1040
|
+
orcaOpenPositionIx.keys[13],
|
|
1041
|
+
orcaOpenPositionIx.keys[14],
|
|
1042
|
+
orcaOpenPositionIx.keys[15],
|
|
1043
|
+
orcaOpenPositionIx.keys[16],
|
|
1044
|
+
orcaOpenPositionIx.keys[17],
|
|
1045
|
+
orcaOpenPositionIx.keys[18],
|
|
1046
|
+
])
|
|
1047
|
+
.instruction();
|
|
1048
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
1049
|
+
payer: params.userWallet,
|
|
1050
|
+
withdraw: [
|
|
1051
|
+
{ mint: mintA },
|
|
1052
|
+
{ mint: mintB },
|
|
1053
|
+
],
|
|
1054
|
+
});
|
|
1055
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
1056
|
+
return (0, functions_1.createTransactionMeta)({
|
|
1057
|
+
payer: params.userWallet,
|
|
1058
|
+
description: `Claim rewards from Orca Position: ${position}`,
|
|
1059
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1060
|
+
mainInstructions,
|
|
1061
|
+
});
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
740
1064
|
}
|
|
741
1065
|
exports.Transactions = Transactions;
|
|
742
1066
|
exports.txgen = new Transactions();
|
|
@@ -72,5 +72,50 @@ export declare class TxGenerator {
|
|
|
72
72
|
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
73
73
|
*/
|
|
74
74
|
meteoraInitializeBinArrays(connection: web3.Connection, payer: string, params: _client.TxInitializeBinArraysBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates orca instruction that opens new position
|
|
77
|
+
*
|
|
78
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
79
|
+
* @param payer The public key of the payer for transaction fees.
|
|
80
|
+
* @param params Parameters required
|
|
81
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
82
|
+
*/
|
|
83
|
+
orcaOpenPosition(connection: web3.Connection, payer: string, params: _client.TxOpenPositionBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
84
|
+
/**
|
|
85
|
+
* Creates orca instruction that closes position
|
|
86
|
+
*
|
|
87
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
88
|
+
* @param payer The public key of the payer for transaction fees.
|
|
89
|
+
* @param params Parameters required
|
|
90
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
91
|
+
*/
|
|
92
|
+
orcaClosePosition(connection: web3.Connection, payer: string, params: _client.TxClosePositionBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
93
|
+
/**
|
|
94
|
+
* Creates orca instruction that deposits to a position
|
|
95
|
+
*
|
|
96
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
97
|
+
* @param payer The public key of the payer for transaction fees.
|
|
98
|
+
* @param params Parameters required
|
|
99
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
100
|
+
*/
|
|
101
|
+
orcaDeposit(connection: web3.Connection, payer: string, params: _client.TxDepositBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates orca instruction that withdraws from a position
|
|
104
|
+
*
|
|
105
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
106
|
+
* @param payer The public key of the payer for transaction fees.
|
|
107
|
+
* @param params Parameters required
|
|
108
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
109
|
+
*/
|
|
110
|
+
orcaWithdraw(connection: web3.Connection, payer: string, params: _client.TxWithdrawBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
111
|
+
/**
|
|
112
|
+
* Creates orca instruction that claims fees and rewards
|
|
113
|
+
*
|
|
114
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
115
|
+
* @param payer The public key of the payer for transaction fees.
|
|
116
|
+
* @param params Parameters required
|
|
117
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
118
|
+
*/
|
|
119
|
+
orcaClaimRewards(connection: web3.Connection, payer: string, params: _client.TxClaimRewardsBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
75
120
|
}
|
|
76
121
|
//# sourceMappingURL=TxGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TxGenerator.d.ts","sourceRoot":"","sources":["../../../src/classes/TxGenerator.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAkE,MAAM,UAAU,CAAC;AACnI,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;GAIG;AACH,qBAAa,WAAW;IAQpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc;IAPnD;;;;OAIG;gBAEgB,MAAM,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc;IAGnD;;;;;;;OAOG;IACG,+BAA+B,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,8BAA8B,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAqCnL;;;;;;;OAOG;IACG,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IA2CjJ;;;;;;;OAOG;IACG,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,kBAA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,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAgC3J;;;;;;;OAOG;IACG,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAkC/I;;;;;;;OAOG;IACG,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAiCjJ;;;;;;;OAOG;IACG,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CA+BzJ"}
|
|
@@ -309,5 +309,196 @@ class TxGenerator {
|
|
|
309
309
|
}
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Creates orca instruction that opens new position
|
|
314
|
+
*
|
|
315
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
316
|
+
* @param payer The public key of the payer for transaction fees.
|
|
317
|
+
* @param params Parameters required
|
|
318
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
319
|
+
*/
|
|
320
|
+
orcaOpenPosition(connection, payer, params) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
// Initialize anchor
|
|
323
|
+
anchor_1.Anchor.initialize(connection);
|
|
324
|
+
try {
|
|
325
|
+
const result = yield Transactions_1.txgen.orcaOpenPosition({
|
|
326
|
+
connection,
|
|
327
|
+
params: {
|
|
328
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
329
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
330
|
+
whirlpool: new web3.PublicKey(params.whirlpool),
|
|
331
|
+
tickLowerIndex: parseInt(params.tickLowerIndex),
|
|
332
|
+
tickUpperIndex: parseInt(params.tickUpperIndex),
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
status: 200,
|
|
337
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
catch (e) {
|
|
341
|
+
return {
|
|
342
|
+
status: 400,
|
|
343
|
+
data: {
|
|
344
|
+
code: "custom",
|
|
345
|
+
message: e,
|
|
346
|
+
path: [],
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Creates orca instruction that closes position
|
|
354
|
+
*
|
|
355
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
356
|
+
* @param payer The public key of the payer for transaction fees.
|
|
357
|
+
* @param params Parameters required
|
|
358
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
359
|
+
*/
|
|
360
|
+
orcaClosePosition(connection, payer, params) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
// Initialize anchor
|
|
363
|
+
anchor_1.Anchor.initialize(connection);
|
|
364
|
+
try {
|
|
365
|
+
const result = yield Transactions_1.txgen.orcaClosePosition({
|
|
366
|
+
connection,
|
|
367
|
+
params: {
|
|
368
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
369
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
status: 200,
|
|
374
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
return {
|
|
379
|
+
status: 400,
|
|
380
|
+
data: {
|
|
381
|
+
code: "custom",
|
|
382
|
+
message: e,
|
|
383
|
+
path: [],
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Creates orca instruction that deposits to a position
|
|
391
|
+
*
|
|
392
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
393
|
+
* @param payer The public key of the payer for transaction fees.
|
|
394
|
+
* @param params Parameters required
|
|
395
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
396
|
+
*/
|
|
397
|
+
orcaDeposit(connection, payer, params) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
// Initialize anchor
|
|
400
|
+
anchor_1.Anchor.initialize(connection);
|
|
401
|
+
try {
|
|
402
|
+
const result = yield Transactions_1.txgen.orcaDeposit({
|
|
403
|
+
connection,
|
|
404
|
+
params: {
|
|
405
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
406
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
407
|
+
totalXAmount: new bn_js_1.BN(params.totalXAmount),
|
|
408
|
+
totalYAmount: new bn_js_1.BN(params.totalYAmount),
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return {
|
|
412
|
+
status: 200,
|
|
413
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
return {
|
|
418
|
+
status: 400,
|
|
419
|
+
data: {
|
|
420
|
+
code: "custom",
|
|
421
|
+
message: e,
|
|
422
|
+
path: [],
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Creates orca instruction that withdraws from a position
|
|
430
|
+
*
|
|
431
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
432
|
+
* @param payer The public key of the payer for transaction fees.
|
|
433
|
+
* @param params Parameters required
|
|
434
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
435
|
+
*/
|
|
436
|
+
orcaWithdraw(connection, payer, params) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
438
|
+
// Initialize anchor
|
|
439
|
+
anchor_1.Anchor.initialize(connection);
|
|
440
|
+
try {
|
|
441
|
+
const result = yield Transactions_1.txgen.orcaWithdraw({
|
|
442
|
+
connection,
|
|
443
|
+
params: {
|
|
444
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
445
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
446
|
+
liquidityAmount: new bn_js_1.BN(params.liquidityAmount),
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
return {
|
|
450
|
+
status: 200,
|
|
451
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
catch (e) {
|
|
455
|
+
return {
|
|
456
|
+
status: 400,
|
|
457
|
+
data: {
|
|
458
|
+
code: "custom",
|
|
459
|
+
message: e,
|
|
460
|
+
path: [],
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Creates orca instruction that claims fees and rewards
|
|
468
|
+
*
|
|
469
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
470
|
+
* @param payer The public key of the payer for transaction fees.
|
|
471
|
+
* @param params Parameters required
|
|
472
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
473
|
+
*/
|
|
474
|
+
orcaClaimRewards(connection, payer, params) {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
+
// Initialize anchor
|
|
477
|
+
anchor_1.Anchor.initialize(connection);
|
|
478
|
+
try {
|
|
479
|
+
const result = yield Transactions_1.txgen.orcaClaimRewards({
|
|
480
|
+
connection,
|
|
481
|
+
params: {
|
|
482
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
483
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return {
|
|
487
|
+
status: 200,
|
|
488
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
catch (e) {
|
|
492
|
+
return {
|
|
493
|
+
status: 400,
|
|
494
|
+
data: {
|
|
495
|
+
code: "custom",
|
|
496
|
+
message: e,
|
|
497
|
+
path: [],
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
312
503
|
}
|
|
313
504
|
exports.TxGenerator = TxGenerator;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
|
+
import * as web3 from "@solana/web3.js";
|
|
3
|
+
export declare const TICK_ARRAY_SIZE = 88;
|
|
4
|
+
export declare const MIN_TICK_INDEX = -443636;
|
|
5
|
+
export declare const MAX_TICK_INDEX = 443636;
|
|
6
|
+
export declare const PDA_TICK_ARRAY_SEED = "tick_array";
|
|
7
|
+
/**
|
|
8
|
+
* Get the PDA of the tick array containing tickIndex.
|
|
9
|
+
* tickArrayOffset can be used to get neighboring tick arrays.
|
|
10
|
+
*
|
|
11
|
+
* @param tickIndex
|
|
12
|
+
* @param tickSpacing
|
|
13
|
+
* @param whirlpool
|
|
14
|
+
* @param programId
|
|
15
|
+
* @param tickArrayOffset
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTickArrayFromTickIndex(tickIndex: number, tickSpacing: number, whirlpool: web3.PublicKey, programId: web3.PublicKey, tickArrayOffset?: number): {
|
|
19
|
+
bump: number;
|
|
20
|
+
publicKey: web3.PublicKey;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get the startIndex of the tick array containing tickIndex.
|
|
24
|
+
*
|
|
25
|
+
* @param tickIndex
|
|
26
|
+
* @param tickSpacing
|
|
27
|
+
* @param offset can be used to get neighboring tick array startIndex.
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function getStartTickIndex(tickIndex: number, tickSpacing: number, offset?: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* @category Program Derived Addresses
|
|
33
|
+
* @param programId
|
|
34
|
+
* @param whirlpoolAddress
|
|
35
|
+
* @param startTick
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare function getTickArray(programId: web3.PublicKey, whirlpoolAddress: web3.PublicKey, startTick: number): {
|
|
39
|
+
bump: number;
|
|
40
|
+
publicKey: web3.PublicKey;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=orca.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orca.d.ts","sourceRoot":"","sources":["../../src/orca.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAGxC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,eAAe,GAAE,MAAU;;;EAGlK;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,UAQ3F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM;;;EAO1G"}
|
package/dist/src/orca.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getTickArray = exports.getStartTickIndex = exports.getTickArrayFromTickIndex = exports.PDA_TICK_ARRAY_SEED = exports.MAX_TICK_INDEX = exports.MIN_TICK_INDEX = exports.TICK_ARRAY_SIZE = void 0;
|
|
30
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
31
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
32
|
+
exports.TICK_ARRAY_SIZE = 88;
|
|
33
|
+
exports.MIN_TICK_INDEX = -443636;
|
|
34
|
+
exports.MAX_TICK_INDEX = 443636;
|
|
35
|
+
exports.PDA_TICK_ARRAY_SEED = "tick_array";
|
|
36
|
+
/**
|
|
37
|
+
* Get the PDA of the tick array containing tickIndex.
|
|
38
|
+
* tickArrayOffset can be used to get neighboring tick arrays.
|
|
39
|
+
*
|
|
40
|
+
* @param tickIndex
|
|
41
|
+
* @param tickSpacing
|
|
42
|
+
* @param whirlpool
|
|
43
|
+
* @param programId
|
|
44
|
+
* @param tickArrayOffset
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
function getTickArrayFromTickIndex(tickIndex, tickSpacing, whirlpool, programId, tickArrayOffset = 0) {
|
|
48
|
+
const startIndex = getStartTickIndex(tickIndex, tickSpacing, tickArrayOffset);
|
|
49
|
+
return getTickArray(programId, whirlpool, startIndex);
|
|
50
|
+
}
|
|
51
|
+
exports.getTickArrayFromTickIndex = getTickArrayFromTickIndex;
|
|
52
|
+
/**
|
|
53
|
+
* Get the startIndex of the tick array containing tickIndex.
|
|
54
|
+
*
|
|
55
|
+
* @param tickIndex
|
|
56
|
+
* @param tickSpacing
|
|
57
|
+
* @param offset can be used to get neighboring tick array startIndex.
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
function getStartTickIndex(tickIndex, tickSpacing, offset = 0) {
|
|
61
|
+
const realIndex = Math.floor(tickIndex / tickSpacing / exports.TICK_ARRAY_SIZE);
|
|
62
|
+
const startTickIndex = (realIndex + offset) * tickSpacing * exports.TICK_ARRAY_SIZE;
|
|
63
|
+
const ticksInArray = exports.TICK_ARRAY_SIZE * tickSpacing;
|
|
64
|
+
const minTickIndex = exports.MIN_TICK_INDEX - ((exports.MIN_TICK_INDEX % ticksInArray) + ticksInArray);
|
|
65
|
+
(0, tiny_invariant_1.default)(startTickIndex >= minTickIndex, `startTickIndex is too small - - ${startTickIndex}`);
|
|
66
|
+
(0, tiny_invariant_1.default)(startTickIndex <= exports.MAX_TICK_INDEX, `startTickIndex is too large - ${startTickIndex}`);
|
|
67
|
+
return startTickIndex;
|
|
68
|
+
}
|
|
69
|
+
exports.getStartTickIndex = getStartTickIndex;
|
|
70
|
+
/**
|
|
71
|
+
* @category Program Derived Addresses
|
|
72
|
+
* @param programId
|
|
73
|
+
* @param whirlpoolAddress
|
|
74
|
+
* @param startTick
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
function getTickArray(programId, whirlpoolAddress, startTick) {
|
|
78
|
+
const [publicKey, bump] = web3.PublicKey.findProgramAddressSync([
|
|
79
|
+
Buffer.from(exports.PDA_TICK_ARRAY_SEED),
|
|
80
|
+
whirlpoolAddress.toBuffer(),
|
|
81
|
+
Buffer.from(startTick.toString()),
|
|
82
|
+
], programId);
|
|
83
|
+
return { bump, publicKey };
|
|
84
|
+
}
|
|
85
|
+
exports.getTickArray = getTickArray;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hawksightco/hawk-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Hawksight v2 SDK",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"repository": "https://github.com/ghabxph/hawk-api-client.git",
|
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
"@coral-xyz/anchor": "^0.28.0",
|
|
25
25
|
"@hawksightco/swagger-client": "^0.0.29",
|
|
26
26
|
"@meteora-ag/dlmm": "^1.0.51",
|
|
27
|
-
"@
|
|
27
|
+
"@orca-so/whirlpools-sdk": "^0.13.3",
|
|
28
28
|
"@solana/spl-token": "^0.4.6",
|
|
29
|
+
"@solana/web3.js": "^1.89.1",
|
|
29
30
|
"bn.js": "^5.2.1",
|
|
30
|
-
"lodash": "^4.17.21"
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"tiny-invariant": "^1.3.1"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
35
|
"start": "npx ts-node src/index.ts",
|