@hawksightco/hawk-sdk 0.0.71 → 1.0.1
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/addresses.d.ts +18 -0
- package/dist/src/addresses.d.ts.map +1 -0
- package/dist/src/addresses.js +54 -0
- package/dist/src/anchor.d.ts +18 -0
- package/dist/src/anchor.d.ts.map +1 -0
- package/dist/src/anchor.js +57 -0
- package/dist/src/classes/CreateTxMetadata.d.ts +1 -0
- package/dist/src/classes/CreateTxMetadata.d.ts.map +1 -1
- package/dist/src/classes/General.d.ts +1 -0
- package/dist/src/classes/General.d.ts.map +1 -1
- package/dist/src/classes/HawkAPI.d.ts.map +1 -1
- package/dist/src/classes/Transaction.d.ts +1 -0
- package/dist/src/classes/Transaction.d.ts.map +1 -1
- package/dist/src/classes/Transactions.d.ts +135 -0
- package/dist/src/classes/Transactions.d.ts.map +1 -0
- package/dist/src/classes/Transactions.js +1068 -0
- package/dist/src/classes/TxGenerator.d.ts +1 -0
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +342 -55
- package/dist/src/classes/TxGeneratorAutomations.d.ts +1 -0
- package/dist/src/classes/TxGeneratorAutomations.d.ts.map +1 -1
- package/dist/src/classes/TxGeneratorAutomations.js +7 -0
- package/dist/src/errors.d.ts +3 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +6 -0
- package/dist/src/functions.d.ts +203 -1
- package/dist/src/functions.d.ts.map +1 -1
- package/dist/src/functions.js +411 -1
- package/dist/src/hawksight.d.ts +17 -0
- package/dist/src/hawksight.d.ts.map +1 -0
- package/dist/src/hawksight.js +128 -0
- package/dist/src/hsToMeteora.d.ts +18 -0
- package/dist/src/hsToMeteora.d.ts.map +1 -0
- package/dist/src/hsToMeteora.js +1142 -0
- package/dist/src/idl/iyf-extension-idl.d.ts +7483 -0
- package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -0
- package/dist/src/idl/iyf-extension-idl.js +7484 -0
- package/dist/src/idl/iyf-main-idl.d.ts +6840 -0
- package/dist/src/idl/iyf-main-idl.d.ts.map +1 -0
- package/dist/src/idl/iyf-main-idl.js +6841 -0
- package/dist/src/meteora.d.ts +304 -0
- package/dist/src/meteora.d.ts.map +1 -0
- package/dist/src/meteora.js +615 -0
- package/dist/src/types.d.ts +138 -18
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +11 -1
- package/package.json +8 -2
|
@@ -0,0 +1,1068 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.txgen = exports.Transactions = void 0;
|
|
39
|
+
const dlmm_1 = require("@meteora-ag/dlmm");
|
|
40
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
41
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
42
|
+
const addresses_1 = require("../addresses");
|
|
43
|
+
const functions_1 = require("../functions");
|
|
44
|
+
const types_1 = require("../types");
|
|
45
|
+
const functions_2 = require("../functions");
|
|
46
|
+
const hsToMeteora_1 = require("../hsToMeteora");
|
|
47
|
+
const meteora_1 = require("../meteora");
|
|
48
|
+
const anchor_1 = require("../anchor");
|
|
49
|
+
// import { PDAUtil } from "@orca-so/whirlpools-sdk";
|
|
50
|
+
const hawksight_1 = require("../hawksight");
|
|
51
|
+
const types_2 = require("../types");
|
|
52
|
+
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
53
|
+
class Transactions {
|
|
54
|
+
/**
|
|
55
|
+
* Generate UserPDA
|
|
56
|
+
*
|
|
57
|
+
* @param userWallet
|
|
58
|
+
* @param farm
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
generateUserPda(userWallet, farm = addresses_1.USDC_FARM) {
|
|
62
|
+
return (0, functions_2.generateUserPda)(userWallet, farm);
|
|
63
|
+
}
|
|
64
|
+
/**s
|
|
65
|
+
* Registers a new entity or user with the necessary parameters, handling transaction creation and response.
|
|
66
|
+
*
|
|
67
|
+
* @param connection A Solana web3 connection for interacting with the blockchain.
|
|
68
|
+
* @param payer The public key of the payer, responsible for transaction fees.
|
|
69
|
+
* @param params Registration parameters required by the API.
|
|
70
|
+
* @returns A Promise resolving to the transaction metadata or an error response, depending on the outcome of the registration.
|
|
71
|
+
*/
|
|
72
|
+
register(_a) {
|
|
73
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
74
|
+
const farm = addresses_1.USDC_FARM;
|
|
75
|
+
const user = (0, functions_2.generateUserPda)(params.authority, farm);
|
|
76
|
+
const [stableToken] = web3.PublicKey.findProgramAddressSync([
|
|
77
|
+
Buffer.from("index-token", "utf-8"),
|
|
78
|
+
addresses_1.STABLEMINT_1.toBuffer(),
|
|
79
|
+
farm.toBuffer(),
|
|
80
|
+
user.toBuffer(),
|
|
81
|
+
], anchor_1.Anchor.instance().iyfMain.programId);
|
|
82
|
+
const [stableToken2] = web3.PublicKey.findProgramAddressSync([
|
|
83
|
+
Buffer.from("index-token", "utf-8"),
|
|
84
|
+
addresses_1.STABLEMINT_2.toBuffer(),
|
|
85
|
+
farm.toBuffer(),
|
|
86
|
+
user.toBuffer(),
|
|
87
|
+
], anchor_1.Anchor.instance().iyfMain.programId);
|
|
88
|
+
// check if user pda is already registered:
|
|
89
|
+
try {
|
|
90
|
+
yield anchor_1.Anchor.instance().iyfMain.account.userAccountMulti.fetch(user, "confirmed");
|
|
91
|
+
throw new Error(`User PDA for wallet: ${params.authority} is already registered.`);
|
|
92
|
+
}
|
|
93
|
+
catch (_b) {
|
|
94
|
+
return (0, functions_2.createTransactionMeta)({
|
|
95
|
+
payer: params.authority,
|
|
96
|
+
description: "Register User",
|
|
97
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
98
|
+
mainInstructions: [
|
|
99
|
+
yield anchor_1.Anchor.instance().iyfMain.methods
|
|
100
|
+
.newUser()
|
|
101
|
+
.accounts({
|
|
102
|
+
farm,
|
|
103
|
+
user,
|
|
104
|
+
authority: params.authority,
|
|
105
|
+
stableToken: stableToken,
|
|
106
|
+
stableMint: addresses_1.STABLEMINT_1,
|
|
107
|
+
stableToken2: stableToken2,
|
|
108
|
+
stableMint2: addresses_1.STABLEMINT_2,
|
|
109
|
+
systemProgram: web3.SystemProgram.programId,
|
|
110
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
111
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
112
|
+
})
|
|
113
|
+
.instruction(),
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates meteora instruction that creates new position and deposit.
|
|
121
|
+
*
|
|
122
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
123
|
+
* @param payer The public key of the payer for transaction fees.
|
|
124
|
+
* @param params Parameters required
|
|
125
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
126
|
+
*/
|
|
127
|
+
meteoraCreatePositionAndDeposit(_a) {
|
|
128
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
129
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool));
|
|
130
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
131
|
+
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
132
|
+
positionPubKey: params.position,
|
|
133
|
+
user: userPda,
|
|
134
|
+
totalXAmount: params.totalXAmount,
|
|
135
|
+
totalYAmount: params.totalYAmount,
|
|
136
|
+
strategy: {
|
|
137
|
+
maxBinId: params.binRange.upperRange,
|
|
138
|
+
minBinId: params.binRange.lowerRange,
|
|
139
|
+
strategyType: types_1.StrategyTypeMap[params.distribution],
|
|
140
|
+
},
|
|
141
|
+
slippage: params.slippage,
|
|
142
|
+
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
143
|
+
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
144
|
+
return (0, functions_2.createTransactionMeta)({
|
|
145
|
+
payer: params.userWallet,
|
|
146
|
+
description: "Create position and deposit to Meteora DLMM",
|
|
147
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
148
|
+
mainInstructions,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates meteora instruction that initializes bin arrays.
|
|
154
|
+
*
|
|
155
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
156
|
+
* @param payer The public key of the payer for transaction fees.
|
|
157
|
+
* @param params Parameters required
|
|
158
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
159
|
+
*/
|
|
160
|
+
meteoraInitializeBinArrays(_a) {
|
|
161
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
162
|
+
const poolAddress = new web3.PublicKey(params.pool);
|
|
163
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress);
|
|
164
|
+
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);
|
|
165
|
+
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map((b) => b.index), new web3.PublicKey(params.userWallet));
|
|
166
|
+
return (0, functions_2.createTransactionMeta)({
|
|
167
|
+
payer: params.userWallet,
|
|
168
|
+
description: "Initialize bin arrays for Meteora DLMM pool",
|
|
169
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
170
|
+
mainInstructions,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Creates meteora instruction that deposits to position.
|
|
176
|
+
*
|
|
177
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
178
|
+
* @param payer The public key of the payer for transaction fees.
|
|
179
|
+
* @param params Parameters required
|
|
180
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
181
|
+
*/
|
|
182
|
+
meteoraDeposit(_a) {
|
|
183
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
184
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
185
|
+
let lbPair, maxBinId, minBinId;
|
|
186
|
+
if (params.fastGeneration !== undefined) {
|
|
187
|
+
lbPair = params.fastGeneration.pool;
|
|
188
|
+
maxBinId = params.fastGeneration.upperBinId;
|
|
189
|
+
minBinId = params.fastGeneration.lowerBinId;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
193
|
+
lbPair = position.lbPair;
|
|
194
|
+
maxBinId = position.upperBinId;
|
|
195
|
+
minBinId = position.lowerBinId;
|
|
196
|
+
}
|
|
197
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(lbPair));
|
|
198
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
199
|
+
const mainInstructions = (yield dlmmPool.addLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
200
|
+
positionPubKey: params.position,
|
|
201
|
+
user: userPda,
|
|
202
|
+
totalXAmount: params.totalXAmount,
|
|
203
|
+
totalYAmount: params.totalYAmount,
|
|
204
|
+
strategy: {
|
|
205
|
+
maxBinId,
|
|
206
|
+
minBinId,
|
|
207
|
+
strategyType: types_1.StrategyTypeMap[params.distribution],
|
|
208
|
+
},
|
|
209
|
+
slippage: params.slippage,
|
|
210
|
+
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
211
|
+
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
212
|
+
return (0, functions_2.createTransactionMeta)({
|
|
213
|
+
payer: params.userWallet,
|
|
214
|
+
description: "Deposit to existing position in Meteora DLMM",
|
|
215
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
216
|
+
mainInstructions,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Creates meteora instruction withdraws from a position.
|
|
222
|
+
*
|
|
223
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
224
|
+
* @param payer The public key of the payer for transaction fees.
|
|
225
|
+
* @param params Parameters required
|
|
226
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
227
|
+
*/
|
|
228
|
+
meteoraWithdraw(_a) {
|
|
229
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
230
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
231
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
232
|
+
let lbPair, binIdsToRemove;
|
|
233
|
+
if (params.fastGeneration !== undefined) {
|
|
234
|
+
lbPair = params.fastGeneration.pool;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
238
|
+
lbPair = position.lbPair;
|
|
239
|
+
}
|
|
240
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
241
|
+
if (params.fastGeneration === undefined) {
|
|
242
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
243
|
+
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.toString() === params.position.toString());
|
|
244
|
+
if (userPosition === undefined) {
|
|
245
|
+
throw new Error("Position does not exist."); // this error should not happen...
|
|
246
|
+
}
|
|
247
|
+
binIdsToRemove = userPosition.positionData.positionBinData.map((bin) => bin.binId);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
binIdsToRemove = params.fastGeneration.binIdsToRemove;
|
|
251
|
+
}
|
|
252
|
+
const amountBps = params.shouldClaimAndClose
|
|
253
|
+
? new bn_js_1.default(10000)
|
|
254
|
+
: params.amountBps;
|
|
255
|
+
const mainInstructions = (yield dlmmPool.removeLiquidity(params.userWallet, params.userWallet, {
|
|
256
|
+
user: userPda,
|
|
257
|
+
position: params.position,
|
|
258
|
+
binIds: binIdsToRemove,
|
|
259
|
+
bps: amountBps,
|
|
260
|
+
shouldClaimAndClose: params.shouldClaimAndClose,
|
|
261
|
+
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
262
|
+
let description;
|
|
263
|
+
if (params.shouldClaimAndClose) {
|
|
264
|
+
description =
|
|
265
|
+
"Full position withdrawal with claim and close instructisons from Meteora DLMM";
|
|
266
|
+
}
|
|
267
|
+
else if (amountBps.eq(new bn_js_1.default(10000))) {
|
|
268
|
+
description =
|
|
269
|
+
"Full position withdrawal without claim and close instructions from Meteora DLMM";
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
description = "Partial position withdrawal from Meteora DLMM";
|
|
273
|
+
}
|
|
274
|
+
return (0, functions_2.createTransactionMeta)({
|
|
275
|
+
payer: params.userWallet,
|
|
276
|
+
description,
|
|
277
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
278
|
+
mainInstructions,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Creates meteora instruction that claims fees and rewards.
|
|
284
|
+
*
|
|
285
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
286
|
+
* @param payer The public key of the payer for transaction fees.
|
|
287
|
+
* @param params Parameters required
|
|
288
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
289
|
+
*/
|
|
290
|
+
meteoraClaim(_a) {
|
|
291
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
292
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
293
|
+
let lbPair;
|
|
294
|
+
if (params.fastGeneration !== undefined) {
|
|
295
|
+
lbPair = params.fastGeneration.pool;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
299
|
+
lbPair = position.lbPair;
|
|
300
|
+
}
|
|
301
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
302
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
303
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
304
|
+
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
305
|
+
const mainInstructions = (yield dlmmPool.claimAllRewardsByPosition(params.userWallet, params.userWallet, {
|
|
306
|
+
owner: userPda,
|
|
307
|
+
position: userPositions[index],
|
|
308
|
+
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
309
|
+
return (0, functions_2.createTransactionMeta)({
|
|
310
|
+
payer: params.userWallet,
|
|
311
|
+
description: "Claim fees / rewards from Meteora DLMM Position",
|
|
312
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
313
|
+
mainInstructions,
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates meteora instruction that closes position.
|
|
319
|
+
*
|
|
320
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
321
|
+
* @param payer The public key of the payer for transaction fees.
|
|
322
|
+
* @param params Parameters required
|
|
323
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
324
|
+
*/
|
|
325
|
+
meteoraClosePosition(_a) {
|
|
326
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
327
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
328
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
329
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
330
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
331
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
332
|
+
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
333
|
+
yield dlmmPool.getActiveBin();
|
|
334
|
+
const mainInstructions = yield dlmmPool.closePosition(params.userWallet, {
|
|
335
|
+
owner: userPda,
|
|
336
|
+
position: userPositions[index],
|
|
337
|
+
}, hsToMeteora_1.meteoraToHawksight);
|
|
338
|
+
return (0, functions_2.createTransactionMeta)({
|
|
339
|
+
payer: params.userWallet,
|
|
340
|
+
description: "Close Meteora DLMM Position",
|
|
341
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
342
|
+
mainInstructions,
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
compoundAutomationIx(_a) {
|
|
347
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
348
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
349
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
350
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
351
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
352
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
353
|
+
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
354
|
+
// Claim fee and claim reward ixs
|
|
355
|
+
const claimBuilder = yield dlmmPool.claimAllRewardsByPosition(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
356
|
+
owner: userPda,
|
|
357
|
+
position: userPositions[index],
|
|
358
|
+
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
359
|
+
// Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
|
|
360
|
+
const addLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
361
|
+
positionPubKey: params.position,
|
|
362
|
+
user: userPda,
|
|
363
|
+
totalXAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
364
|
+
totalYAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
365
|
+
strategy: {
|
|
366
|
+
maxBinId: position.upperBinId,
|
|
367
|
+
minBinId: position.lowerBinId,
|
|
368
|
+
strategyType: types_1.StrategyTypeMap["SPOT-IMBALANCED"], // TODO: how to get the right distribution from chain??
|
|
369
|
+
},
|
|
370
|
+
skipInputTokenCheck: true,
|
|
371
|
+
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
372
|
+
const mainInstructions = [
|
|
373
|
+
// Step 1: Initialize ATA
|
|
374
|
+
...claimBuilder.createAtaIxs,
|
|
375
|
+
// Step 2: Claim rewards and fees
|
|
376
|
+
...claimBuilder.mainIxs,
|
|
377
|
+
// Step 3: Re-deposit fees
|
|
378
|
+
...addLiquidityBuilder.mainIxs,
|
|
379
|
+
];
|
|
380
|
+
return (0, functions_2.createTransactionMeta)({
|
|
381
|
+
payer: params.userWallet,
|
|
382
|
+
description: "Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)",
|
|
383
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
384
|
+
mainInstructions,
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
rebalanceAutomationIx(_a) {
|
|
389
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
390
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
391
|
+
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
392
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
393
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
394
|
+
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
395
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
396
|
+
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
397
|
+
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
398
|
+
user: userPda,
|
|
399
|
+
position: params.currentPosition,
|
|
400
|
+
binIds: binIdsToRemove,
|
|
401
|
+
bps: new bn_js_1.default(10000),
|
|
402
|
+
shouldClaimAndClose: true,
|
|
403
|
+
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
404
|
+
// Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
|
|
405
|
+
const initPositionAndAddLiquidityBuilder = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
406
|
+
positionPubKey: params.newPosition,
|
|
407
|
+
user: userPda,
|
|
408
|
+
totalXAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
409
|
+
totalYAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
410
|
+
strategy: {
|
|
411
|
+
maxBinId: params.binRange.upperRange,
|
|
412
|
+
minBinId: params.binRange.lowerRange,
|
|
413
|
+
strategyType: types_1.StrategyTypeMap[params.distribution],
|
|
414
|
+
},
|
|
415
|
+
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
416
|
+
// Sweep dust
|
|
417
|
+
const sweepLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
418
|
+
positionPubKey: params.newPosition,
|
|
419
|
+
user: userPda,
|
|
420
|
+
totalXAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
421
|
+
totalYAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
422
|
+
strategy: {
|
|
423
|
+
maxBinId: params.binRange.upperRange,
|
|
424
|
+
minBinId: params.binRange.lowerRange,
|
|
425
|
+
strategyType: types_1.StrategyTypeMap["SPOT-IMBALANCED"],
|
|
426
|
+
},
|
|
427
|
+
skipInputTokenCheck: true,
|
|
428
|
+
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
429
|
+
const mainInstructions = [
|
|
430
|
+
// Initialize required ATA
|
|
431
|
+
...removeLiquidityBuilder.createAtaIxs,
|
|
432
|
+
// Remove liquidity
|
|
433
|
+
...removeLiquidityBuilder.mainIxs,
|
|
434
|
+
// Re-deposit liquidity
|
|
435
|
+
...initPositionAndAddLiquidityBuilder.mainIxs,
|
|
436
|
+
// Sweep dust
|
|
437
|
+
...sweepLiquidityBuilder.mainIxs,
|
|
438
|
+
];
|
|
439
|
+
return (0, functions_2.createTransactionMeta)({
|
|
440
|
+
payer: params.userWallet,
|
|
441
|
+
description: "Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)",
|
|
442
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
443
|
+
mainInstructions,
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Creates instructions to initialize storage token accounts
|
|
449
|
+
*
|
|
450
|
+
* @param connection A Solana web3 connection for interacting with the blockchain.
|
|
451
|
+
* @param params Parameters required.
|
|
452
|
+
* @returns A Promise resolving to the transaction metadata or an error response, depending on the outcome of the registration.
|
|
453
|
+
*/
|
|
454
|
+
initializeStorageTokenAccounts(_a) {
|
|
455
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
456
|
+
const activePoolRewards = [];
|
|
457
|
+
const mainInstructions = [];
|
|
458
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
459
|
+
if (params.protocol === types_2.Protocol.Meteora && params.pool) {
|
|
460
|
+
const poolInfo = yield (0, functions_1.getMeteoraPool)(params.pool);
|
|
461
|
+
if (poolInfo.reward_mint_x !== "11111111111111111111111111111111") {
|
|
462
|
+
activePoolRewards.push(new web3.PublicKey(poolInfo.reward_mint_x));
|
|
463
|
+
}
|
|
464
|
+
if (poolInfo.reward_mint_y !== "11111111111111111111111111111111") {
|
|
465
|
+
activePoolRewards.push(new web3.PublicKey(poolInfo.reward_mint_y));
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const combinedMints = [...params.mints, ...activePoolRewards];
|
|
469
|
+
const filteredMints = combinedMints.filter((m, i) => combinedMints.findIndex((mint) => mint.equals(m)) === i);
|
|
470
|
+
const storageAddresses = filteredMints.map((mint) => (0, functions_2.generateUserPdaStorageAccount)(userPda, mint));
|
|
471
|
+
const accountsData = yield connection.getMultipleAccountsInfo(storageAddresses, "processed");
|
|
472
|
+
for (let i = 0; i < accountsData.length; i++) {
|
|
473
|
+
if (!accountsData[i]) {
|
|
474
|
+
console.log(`initializing STA: ${filteredMints[i].toBase58()}`);
|
|
475
|
+
mainInstructions.push(yield anchor_1.Anchor.instance().iyfMain.methods
|
|
476
|
+
.initializeStorageTokenAccountAutomation()
|
|
477
|
+
.accounts({
|
|
478
|
+
userPda: userPda,
|
|
479
|
+
payer: params.userWallet,
|
|
480
|
+
mint: filteredMints[i],
|
|
481
|
+
storageTokenAccount: storageAddresses[i],
|
|
482
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
483
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
484
|
+
systemProgram: web3.SystemProgram.programId,
|
|
485
|
+
})
|
|
486
|
+
.instruction());
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (mainInstructions.length) {
|
|
490
|
+
return (0, functions_2.createTransactionMeta)({
|
|
491
|
+
payer: params.userWallet,
|
|
492
|
+
description: "Initialize STAs",
|
|
493
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
494
|
+
mainInstructions,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return [];
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
limitCloseAutomationIx(_a) {
|
|
501
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
502
|
+
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
503
|
+
const position = yield program.account.positionV2.fetch(params.position);
|
|
504
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
505
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet);
|
|
506
|
+
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
507
|
+
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
508
|
+
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
509
|
+
// Claim fees and/or rewards, remove liquidity, and possibly close position from Meteora API (if set)
|
|
510
|
+
const txn = yield dlmmPool.dlmm.removeLiquidity({
|
|
511
|
+
user: userPda,
|
|
512
|
+
position: params.position,
|
|
513
|
+
binIds: binIdsToRemove,
|
|
514
|
+
bps: new bn_js_1.default(10000),
|
|
515
|
+
shouldClaimAndClose: true,
|
|
516
|
+
});
|
|
517
|
+
// Filter out non-meteora instructions
|
|
518
|
+
const ixs = (0, functions_2.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
519
|
+
const farm = addresses_1.USDC_FARM;
|
|
520
|
+
const authority = params.userWallet;
|
|
521
|
+
const iyfProgram = addresses_1.IYF_MAIN;
|
|
522
|
+
const hawksightAuthority = addresses_1.HS_AUTHORITY;
|
|
523
|
+
const { params: _params, data } = this.removeLiquidityByRangeInfo(ixs);
|
|
524
|
+
const { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, tokenXProgram, tokenYProgram, binArrayLower, binArrayUpper, eventAuthority, program: meteoraDlmmProgram, } = _params;
|
|
525
|
+
const limitCloseAutomationIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
526
|
+
.meteoraDlmmLimitCloseAutomation(data, params.minBinId, params.maxBinId)
|
|
527
|
+
.accounts({
|
|
528
|
+
farm,
|
|
529
|
+
userPda,
|
|
530
|
+
authority,
|
|
531
|
+
iyfProgram,
|
|
532
|
+
hawksightAuthority,
|
|
533
|
+
position: _position.pubkey,
|
|
534
|
+
lbPair: lbPair.pubkey,
|
|
535
|
+
binArrayBitmapExtension: binArrayBitmapExtension.pubkey,
|
|
536
|
+
userTokenX: (0, functions_2.generateUserPdaStorageAccount)(userPda, tokenXMint.pubkey),
|
|
537
|
+
userTokenY: (0, functions_2.generateUserPdaStorageAccount)(userPda, tokenYMint.pubkey),
|
|
538
|
+
reserveX: reserveX.pubkey,
|
|
539
|
+
reserveY: reserveY.pubkey,
|
|
540
|
+
tokenXMint: tokenXMint.pubkey,
|
|
541
|
+
tokenYMint: tokenYMint.pubkey,
|
|
542
|
+
tokenXProgram: tokenXProgram.pubkey,
|
|
543
|
+
tokenYProgram: tokenYProgram.pubkey,
|
|
544
|
+
binArrayLower: binArrayLower.pubkey,
|
|
545
|
+
binArrayUpper: binArrayUpper.pubkey,
|
|
546
|
+
eventAuthority: eventAuthority.pubkey,
|
|
547
|
+
meteoraDlmmProgram: meteoraDlmmProgram.pubkey,
|
|
548
|
+
ownerFeeX: (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, tokenXMint.pubkey),
|
|
549
|
+
ownerFeeY: (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, tokenYMint.pubkey),
|
|
550
|
+
})
|
|
551
|
+
.instruction();
|
|
552
|
+
// Instruction via main hawksight contract
|
|
553
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
554
|
+
.iyfExtensionExecute(limitCloseAutomationIx.data)
|
|
555
|
+
.accounts({
|
|
556
|
+
farm,
|
|
557
|
+
userPda,
|
|
558
|
+
authority,
|
|
559
|
+
iyfProgram,
|
|
560
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
561
|
+
})
|
|
562
|
+
.remainingAccounts([
|
|
563
|
+
limitCloseAutomationIx.keys[4],
|
|
564
|
+
limitCloseAutomationIx.keys[5],
|
|
565
|
+
limitCloseAutomationIx.keys[6],
|
|
566
|
+
limitCloseAutomationIx.keys[7],
|
|
567
|
+
limitCloseAutomationIx.keys[8],
|
|
568
|
+
limitCloseAutomationIx.keys[9],
|
|
569
|
+
limitCloseAutomationIx.keys[10],
|
|
570
|
+
limitCloseAutomationIx.keys[11],
|
|
571
|
+
limitCloseAutomationIx.keys[12],
|
|
572
|
+
limitCloseAutomationIx.keys[13],
|
|
573
|
+
limitCloseAutomationIx.keys[14],
|
|
574
|
+
limitCloseAutomationIx.keys[15],
|
|
575
|
+
limitCloseAutomationIx.keys[16],
|
|
576
|
+
limitCloseAutomationIx.keys[17],
|
|
577
|
+
limitCloseAutomationIx.keys[18],
|
|
578
|
+
limitCloseAutomationIx.keys[19],
|
|
579
|
+
limitCloseAutomationIx.keys[20],
|
|
580
|
+
limitCloseAutomationIx.keys[21],
|
|
581
|
+
])
|
|
582
|
+
.instruction();
|
|
583
|
+
const mainInstructions = [
|
|
584
|
+
// Limit Close Automation Instruction (Hawksight CPI)
|
|
585
|
+
ix,
|
|
586
|
+
];
|
|
587
|
+
return (0, functions_2.createTransactionMeta)({
|
|
588
|
+
payer: params.userWallet,
|
|
589
|
+
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
590
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
591
|
+
mainInstructions,
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
removeLiquidityByRangeInfo(ixs) {
|
|
596
|
+
for (const ix of ixs) {
|
|
597
|
+
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
598
|
+
const _sighashMatch = (0, functions_2.sighashMatch)(ix.data, "RemoveLiquidityByRange");
|
|
599
|
+
if (programIdMatch && _sighashMatch) {
|
|
600
|
+
return {
|
|
601
|
+
data: ix.data,
|
|
602
|
+
params: {
|
|
603
|
+
position: ix.keys[0],
|
|
604
|
+
lbPair: ix.keys[1],
|
|
605
|
+
binArrayBitmapExtension: ix.keys[2],
|
|
606
|
+
userTokenX: ix.keys[3],
|
|
607
|
+
userTokenY: ix.keys[4],
|
|
608
|
+
reserveX: ix.keys[5],
|
|
609
|
+
reserveY: ix.keys[6],
|
|
610
|
+
tokenXMint: ix.keys[7],
|
|
611
|
+
tokenYMint: ix.keys[8],
|
|
612
|
+
binArrayLower: ix.keys[9],
|
|
613
|
+
binArrayUpper: ix.keys[10],
|
|
614
|
+
sender: ix.keys[11],
|
|
615
|
+
tokenXProgram: ix.keys[12],
|
|
616
|
+
tokenYProgram: ix.keys[13],
|
|
617
|
+
eventAuthority: ix.keys[14],
|
|
618
|
+
program: ix.keys[15],
|
|
619
|
+
},
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
throw new Error(`Unexpected error: Cannot find "RemoveLiquidityByRange" instruction from instructions`);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Creates orca instruction that opens new position
|
|
627
|
+
*
|
|
628
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
629
|
+
* @param payer The public key of the payer for transaction fees.
|
|
630
|
+
* @param params Parameters required
|
|
631
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
632
|
+
*/
|
|
633
|
+
orcaOpenPosition(_a) {
|
|
634
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
635
|
+
const farm = addresses_1.USDC_FARM;
|
|
636
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
637
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
638
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
639
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
640
|
+
.orcaOpenPosition(params.tickLowerIndex, params.tickUpperIndex)
|
|
641
|
+
.accounts({
|
|
642
|
+
farm,
|
|
643
|
+
userPda,
|
|
644
|
+
authority: params.userWallet,
|
|
645
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
646
|
+
position,
|
|
647
|
+
positionMint: params.positionMint,
|
|
648
|
+
positionTokenAccount,
|
|
649
|
+
whirlpool: params.whirlpool,
|
|
650
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
651
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
652
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
653
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
654
|
+
systemProgram: web3.SystemProgram.programId,
|
|
655
|
+
})
|
|
656
|
+
.instruction();
|
|
657
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
658
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
659
|
+
.accounts({
|
|
660
|
+
farm,
|
|
661
|
+
userPda,
|
|
662
|
+
authority: params.userWallet,
|
|
663
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
664
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
665
|
+
})
|
|
666
|
+
.remainingAccounts([
|
|
667
|
+
orcaOpenPositionIx.keys[4],
|
|
668
|
+
orcaOpenPositionIx.keys[5],
|
|
669
|
+
orcaOpenPositionIx.keys[6],
|
|
670
|
+
orcaOpenPositionIx.keys[7],
|
|
671
|
+
orcaOpenPositionIx.keys[8],
|
|
672
|
+
orcaOpenPositionIx.keys[9],
|
|
673
|
+
orcaOpenPositionIx.keys[10],
|
|
674
|
+
orcaOpenPositionIx.keys[11],
|
|
675
|
+
orcaOpenPositionIx.keys[12],
|
|
676
|
+
])
|
|
677
|
+
.instruction();
|
|
678
|
+
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
679
|
+
return (0, functions_2.createTransactionMeta)({
|
|
680
|
+
payer: params.userWallet,
|
|
681
|
+
description: "Create new Orca Position",
|
|
682
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
683
|
+
mainInstructions,
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Creates orca instruction that closes position
|
|
689
|
+
*
|
|
690
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
691
|
+
* @param payer The public key of the payer for transaction fees.
|
|
692
|
+
* @param params Parameters required
|
|
693
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
694
|
+
*/
|
|
695
|
+
orcaClosePosition(_a) {
|
|
696
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
697
|
+
const farm = addresses_1.USDC_FARM;
|
|
698
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
699
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
700
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
701
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
702
|
+
.orcaClosePosition()
|
|
703
|
+
.accounts({
|
|
704
|
+
farm,
|
|
705
|
+
userPda,
|
|
706
|
+
authority: params.userWallet,
|
|
707
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
708
|
+
positionMint: params.positionMint,
|
|
709
|
+
position,
|
|
710
|
+
positionTokenAccount,
|
|
711
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
712
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
713
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
714
|
+
})
|
|
715
|
+
.instruction();
|
|
716
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
717
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
718
|
+
.accounts({
|
|
719
|
+
farm,
|
|
720
|
+
userPda,
|
|
721
|
+
authority: params.userWallet,
|
|
722
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
723
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
724
|
+
})
|
|
725
|
+
.remainingAccounts([
|
|
726
|
+
orcaOpenPositionIx.keys[4],
|
|
727
|
+
orcaOpenPositionIx.keys[5],
|
|
728
|
+
orcaOpenPositionIx.keys[6],
|
|
729
|
+
orcaOpenPositionIx.keys[7],
|
|
730
|
+
orcaOpenPositionIx.keys[8],
|
|
731
|
+
orcaOpenPositionIx.keys[9],
|
|
732
|
+
])
|
|
733
|
+
.instruction();
|
|
734
|
+
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
735
|
+
return (0, functions_2.createTransactionMeta)({
|
|
736
|
+
payer: params.userWallet,
|
|
737
|
+
description: "Close Orca Position",
|
|
738
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
739
|
+
mainInstructions,
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Creates orca instruction that deposits to a position
|
|
745
|
+
*
|
|
746
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
747
|
+
* @param payer The public key of the payer for transaction fees.
|
|
748
|
+
* @param params Parameters required
|
|
749
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
750
|
+
*/
|
|
751
|
+
orcaDeposit(_a) {
|
|
752
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
753
|
+
const farm = addresses_1.USDC_FARM;
|
|
754
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
755
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
756
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
757
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
758
|
+
if (positionData === null) {
|
|
759
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
760
|
+
}
|
|
761
|
+
const whirlpool = positionData.whirlpool;
|
|
762
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
763
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
764
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
765
|
+
const tokenSeeds = [
|
|
766
|
+
{ owner: params.userWallet, mint: mintA },
|
|
767
|
+
{ owner: params.userWallet, mint: mintB },
|
|
768
|
+
];
|
|
769
|
+
const resultMap = yield (0, functions_2.tokenAccountExists)(connection, tokenSeeds);
|
|
770
|
+
resultMap.map((result, index) => {
|
|
771
|
+
const tokenKey = result.tokenKey;
|
|
772
|
+
const token = tokenSeeds[index];
|
|
773
|
+
if (!result.exists) {
|
|
774
|
+
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
778
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
779
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
780
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
781
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
782
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
783
|
+
const depositIx = yield (0, hawksight_1.depositMultipleToken)({
|
|
784
|
+
payer: params.userWallet,
|
|
785
|
+
deposit: [
|
|
786
|
+
{
|
|
787
|
+
mint: mintA,
|
|
788
|
+
amount: params.totalXAmount,
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
mint: mintB,
|
|
792
|
+
amount: params.totalYAmount,
|
|
793
|
+
},
|
|
794
|
+
]
|
|
795
|
+
});
|
|
796
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
797
|
+
.orcaDeposit()
|
|
798
|
+
.accounts({
|
|
799
|
+
farm,
|
|
800
|
+
userPda,
|
|
801
|
+
authority: params.userWallet,
|
|
802
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
803
|
+
positionMint: params.positionMint,
|
|
804
|
+
whirlpool,
|
|
805
|
+
position,
|
|
806
|
+
positionTokenAccount,
|
|
807
|
+
tokenOwnerAccountA,
|
|
808
|
+
tokenOwnerAccountB,
|
|
809
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
810
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
811
|
+
tickArrayLower,
|
|
812
|
+
tickArrayUpper,
|
|
813
|
+
ownerFeeA,
|
|
814
|
+
ownerFeeB,
|
|
815
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
816
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
817
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
818
|
+
})
|
|
819
|
+
.instruction();
|
|
820
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
821
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
822
|
+
.accounts({
|
|
823
|
+
farm,
|
|
824
|
+
userPda,
|
|
825
|
+
authority: params.userWallet,
|
|
826
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
827
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
828
|
+
})
|
|
829
|
+
.remainingAccounts([
|
|
830
|
+
orcaOpenPositionIx.keys[4],
|
|
831
|
+
orcaOpenPositionIx.keys[5],
|
|
832
|
+
orcaOpenPositionIx.keys[6],
|
|
833
|
+
orcaOpenPositionIx.keys[7],
|
|
834
|
+
orcaOpenPositionIx.keys[8],
|
|
835
|
+
orcaOpenPositionIx.keys[9],
|
|
836
|
+
orcaOpenPositionIx.keys[10],
|
|
837
|
+
orcaOpenPositionIx.keys[11],
|
|
838
|
+
orcaOpenPositionIx.keys[12],
|
|
839
|
+
orcaOpenPositionIx.keys[13],
|
|
840
|
+
orcaOpenPositionIx.keys[14],
|
|
841
|
+
orcaOpenPositionIx.keys[15],
|
|
842
|
+
orcaOpenPositionIx.keys[16],
|
|
843
|
+
orcaOpenPositionIx.keys[17],
|
|
844
|
+
orcaOpenPositionIx.keys[18],
|
|
845
|
+
])
|
|
846
|
+
.instruction();
|
|
847
|
+
const clearRemainingTokensIxs = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
848
|
+
payer: params.userWallet,
|
|
849
|
+
withdraw: [
|
|
850
|
+
{ mint: mintA },
|
|
851
|
+
{ mint: mintB },
|
|
852
|
+
],
|
|
853
|
+
});
|
|
854
|
+
const mainInstructions = [depositIx, orcaOpenPositionIxViaMain, clearRemainingTokensIxs];
|
|
855
|
+
return (0, functions_2.createTransactionMeta)({
|
|
856
|
+
payer: params.userWallet,
|
|
857
|
+
description: `Deposit to Orca Position: ${position}`,
|
|
858
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
859
|
+
mainInstructions,
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Creates orca instruction that withdraws from a position
|
|
865
|
+
*
|
|
866
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
867
|
+
* @param payer The public key of the payer for transaction fees.
|
|
868
|
+
* @param params Parameters required
|
|
869
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
870
|
+
*/
|
|
871
|
+
orcaWithdraw(_a) {
|
|
872
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
873
|
+
const farm = addresses_1.USDC_FARM;
|
|
874
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
875
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
876
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
877
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
878
|
+
if (positionData === null) {
|
|
879
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
880
|
+
}
|
|
881
|
+
const whirlpool = positionData.whirlpool;
|
|
882
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
883
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
884
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
885
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
886
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
887
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
888
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
889
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
890
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
891
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
892
|
+
.orcaWithdraw(params.liquidityAmount)
|
|
893
|
+
.accounts({
|
|
894
|
+
farm,
|
|
895
|
+
userPda,
|
|
896
|
+
authority: params.userWallet,
|
|
897
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
898
|
+
positionMint: params.positionMint,
|
|
899
|
+
whirlpool,
|
|
900
|
+
position,
|
|
901
|
+
positionTokenAccount,
|
|
902
|
+
tokenOwnerAccountA,
|
|
903
|
+
tokenOwnerAccountB,
|
|
904
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
905
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
906
|
+
tickArrayLower,
|
|
907
|
+
tickArrayUpper,
|
|
908
|
+
ownerFeeA,
|
|
909
|
+
ownerFeeB,
|
|
910
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
911
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
912
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
913
|
+
})
|
|
914
|
+
.instruction();
|
|
915
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
916
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
917
|
+
.accounts({
|
|
918
|
+
farm,
|
|
919
|
+
userPda,
|
|
920
|
+
authority: params.userWallet,
|
|
921
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
922
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
923
|
+
})
|
|
924
|
+
.remainingAccounts([
|
|
925
|
+
orcaOpenPositionIx.keys[4],
|
|
926
|
+
orcaOpenPositionIx.keys[5],
|
|
927
|
+
orcaOpenPositionIx.keys[6],
|
|
928
|
+
orcaOpenPositionIx.keys[7],
|
|
929
|
+
orcaOpenPositionIx.keys[8],
|
|
930
|
+
orcaOpenPositionIx.keys[9],
|
|
931
|
+
orcaOpenPositionIx.keys[10],
|
|
932
|
+
orcaOpenPositionIx.keys[11],
|
|
933
|
+
orcaOpenPositionIx.keys[12],
|
|
934
|
+
orcaOpenPositionIx.keys[13],
|
|
935
|
+
orcaOpenPositionIx.keys[14],
|
|
936
|
+
orcaOpenPositionIx.keys[15],
|
|
937
|
+
orcaOpenPositionIx.keys[16],
|
|
938
|
+
orcaOpenPositionIx.keys[17],
|
|
939
|
+
orcaOpenPositionIx.keys[18],
|
|
940
|
+
])
|
|
941
|
+
.instruction();
|
|
942
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
943
|
+
payer: params.userWallet,
|
|
944
|
+
withdraw: [
|
|
945
|
+
{ mint: mintA },
|
|
946
|
+
{ mint: mintB },
|
|
947
|
+
],
|
|
948
|
+
});
|
|
949
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
950
|
+
return (0, functions_2.createTransactionMeta)({
|
|
951
|
+
payer: params.userWallet,
|
|
952
|
+
description: `Withdraw deposits from Orca Position: ${position}`,
|
|
953
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
954
|
+
mainInstructions,
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Creates orca instruction that claims fees and rewards
|
|
960
|
+
*
|
|
961
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
962
|
+
* @param payer The public key of the payer for transaction fees.
|
|
963
|
+
* @param params Parameters required
|
|
964
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
965
|
+
*/
|
|
966
|
+
orcaClaimRewards(_a) {
|
|
967
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
968
|
+
const farm = addresses_1.USDC_FARM;
|
|
969
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
970
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
971
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
972
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
973
|
+
if (positionData === null) {
|
|
974
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
975
|
+
}
|
|
976
|
+
const whirlpool = positionData.whirlpool;
|
|
977
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
978
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
979
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
980
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
981
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
982
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
983
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
984
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
985
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
986
|
+
const remainingAccounts = [];
|
|
987
|
+
for (const rewardInfo of whirlpoolData.rewardInfos) {
|
|
988
|
+
if (rewardInfo.mint.toString() !== web3.SystemProgram.programId.toString()) {
|
|
989
|
+
const rewardOwnerAccount = (0, functions_2.generateAta)(userPda, rewardInfo.mint);
|
|
990
|
+
const rewardVault = rewardInfo.vault;
|
|
991
|
+
const rewardFee = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, rewardInfo.mint);
|
|
992
|
+
remainingAccounts.push({ pubkey: rewardOwnerAccount, isSigner: false, isWritable: true });
|
|
993
|
+
remainingAccounts.push({ pubkey: rewardVault, isSigner: false, isWritable: true });
|
|
994
|
+
remainingAccounts.push({ pubkey: rewardFee, isSigner: false, isWritable: true });
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
whirlpoolData.rewardInfos[0].mint;
|
|
998
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
999
|
+
.orcaClaimRewards()
|
|
1000
|
+
.accounts({
|
|
1001
|
+
farm,
|
|
1002
|
+
userPda,
|
|
1003
|
+
authority: params.userWallet,
|
|
1004
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1005
|
+
whirlpool,
|
|
1006
|
+
positionMint: params.positionMint,
|
|
1007
|
+
position,
|
|
1008
|
+
tickArrayLower,
|
|
1009
|
+
tickArrayUpper,
|
|
1010
|
+
positionTokenAccount,
|
|
1011
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
1012
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
1013
|
+
tokenOwnerAccountA,
|
|
1014
|
+
tokenOwnerAccountB,
|
|
1015
|
+
ownerFeeA,
|
|
1016
|
+
ownerFeeB,
|
|
1017
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
1018
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1019
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
1020
|
+
})
|
|
1021
|
+
.remainingAccounts(remainingAccounts)
|
|
1022
|
+
.instruction();
|
|
1023
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1024
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
1025
|
+
.accounts({
|
|
1026
|
+
farm,
|
|
1027
|
+
userPda,
|
|
1028
|
+
authority: params.userWallet,
|
|
1029
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1030
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1031
|
+
})
|
|
1032
|
+
.remainingAccounts([
|
|
1033
|
+
orcaOpenPositionIx.keys[4],
|
|
1034
|
+
orcaOpenPositionIx.keys[5],
|
|
1035
|
+
orcaOpenPositionIx.keys[6],
|
|
1036
|
+
orcaOpenPositionIx.keys[7],
|
|
1037
|
+
orcaOpenPositionIx.keys[8],
|
|
1038
|
+
orcaOpenPositionIx.keys[9],
|
|
1039
|
+
orcaOpenPositionIx.keys[10],
|
|
1040
|
+
orcaOpenPositionIx.keys[11],
|
|
1041
|
+
orcaOpenPositionIx.keys[12],
|
|
1042
|
+
orcaOpenPositionIx.keys[13],
|
|
1043
|
+
orcaOpenPositionIx.keys[14],
|
|
1044
|
+
orcaOpenPositionIx.keys[15],
|
|
1045
|
+
orcaOpenPositionIx.keys[16],
|
|
1046
|
+
orcaOpenPositionIx.keys[17],
|
|
1047
|
+
orcaOpenPositionIx.keys[18],
|
|
1048
|
+
])
|
|
1049
|
+
.instruction();
|
|
1050
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
1051
|
+
payer: params.userWallet,
|
|
1052
|
+
withdraw: [
|
|
1053
|
+
{ mint: mintA },
|
|
1054
|
+
{ mint: mintB },
|
|
1055
|
+
],
|
|
1056
|
+
});
|
|
1057
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
1058
|
+
return (0, functions_2.createTransactionMeta)({
|
|
1059
|
+
payer: params.userWallet,
|
|
1060
|
+
description: `Claim rewards from Orca Position: ${position}`,
|
|
1061
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1062
|
+
mainInstructions,
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
exports.Transactions = Transactions;
|
|
1068
|
+
exports.txgen = new Transactions();
|