@hawksightco/hawk-sdk 1.1.44 → 1.1.46
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/classes/CreateTxMetadata.d.ts.map +1 -1
- package/dist/src/classes/CreateTxMetadata.js +16 -8
- package/dist/src/classes/General.d.ts +1 -2
- package/dist/src/classes/General.d.ts.map +1 -1
- package/dist/src/classes/Transactions.d.ts +19 -0
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +184 -26
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +6 -5
- package/dist/src/classes/TxGeneratorAutomations.d.ts +11 -0
- package/dist/src/classes/TxGeneratorAutomations.d.ts.map +1 -1
- package/dist/src/classes/TxGeneratorAutomations.js +36 -0
- package/dist/src/hsToMeteora.js +11 -11
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts +1 -1
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +22 -13
- package/dist/src/meteora.d.ts +139 -0
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +312 -1
- package/dist/src/types.d.ts +14 -6
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/src/classes/Transaction copy.d.ts +0 -162
- package/dist/src/classes/Transaction copy.d.ts.map +0 -1
- package/dist/src/classes/Transaction copy.js +0 -458
|
@@ -105,17 +105,23 @@ class MeteoraDlmmIxGenerator {
|
|
|
105
105
|
const userTokenY = (0, functions_1.generateAta)(userPda, tokenYMint);
|
|
106
106
|
const activeBinId = lbPairInfo.activeId;
|
|
107
107
|
const MAX_BIN_ARRAY_SIZE = new bn_js_1.default(anchor_1.Anchor.instance().meteoraProgram.idl.constants[1].value);
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
// Get min and max bin id values from checkRange threshold
|
|
109
|
+
const { minBinId, maxBinId } = checkRange;
|
|
110
|
+
let _checkRange = [minBinId, maxBinId];
|
|
111
|
+
// Find bin arrays from given range
|
|
112
|
+
const tickArrays = fn.findMeteoraTickArrays(lbPair, minBinId, maxBinId);
|
|
113
|
+
// comment out for reference
|
|
114
|
+
// const lowerBinArrayIndex = fn.binIdToBinArrayIndex(MAX_BIN_ARRAY_SIZE, new BN(activeBinId - relativeLowerBinId));
|
|
115
|
+
// const binArrayLower = fn.deriveBinArray(lbPair, lowerBinArrayIndex);
|
|
116
|
+
// const binArrayUpper = fn.deriveBinArray(lbPair, lowerBinArrayIndex.add(new BN(1)));
|
|
117
|
+
// comment out for reference
|
|
118
|
+
// let _checkRange: null | [number, number];
|
|
119
|
+
// if (!!checkRange) {
|
|
120
|
+
// const { minBinId, maxBinId } = checkRange;
|
|
121
|
+
// _checkRange = [minBinId, maxBinId];
|
|
122
|
+
// } else {
|
|
123
|
+
// _checkRange = null;
|
|
124
|
+
// }
|
|
119
125
|
// Generate instruction
|
|
120
126
|
return this.iyfMain.iyfExtensionExecute(connection, {
|
|
121
127
|
userWallet,
|
|
@@ -136,14 +142,17 @@ class MeteoraDlmmIxGenerator {
|
|
|
136
142
|
reserveY,
|
|
137
143
|
tokenXMint,
|
|
138
144
|
tokenYMint,
|
|
139
|
-
binArrayLower,
|
|
140
|
-
binArrayUpper,
|
|
145
|
+
// binArrayLower,
|
|
146
|
+
// binArrayUpper,
|
|
141
147
|
systemProgram: web3.SystemProgram.programId,
|
|
142
148
|
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
143
149
|
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
144
150
|
eventAuthority: METEORA_EVENT_AUTHORITY,
|
|
145
151
|
meteoraDlmmProgram: METEORA_DLMM_PROGRAM,
|
|
146
152
|
})
|
|
153
|
+
.remainingAccounts(tickArrays.map(pubkey => {
|
|
154
|
+
return { pubkey, isSigner: false, isWritable: true };
|
|
155
|
+
}))
|
|
147
156
|
.instruction(),
|
|
148
157
|
});
|
|
149
158
|
});
|
package/dist/src/meteora.d.ts
CHANGED
|
@@ -65,6 +65,40 @@ export declare class MeteoraDLMM {
|
|
|
65
65
|
slippage?: number;
|
|
66
66
|
skipInputTokenCheck?: boolean;
|
|
67
67
|
}, meteoraToHawksight: MeteoraToHawksightFn): Promise<InitializePositionAndAddLiquidityByStrategyBuilder>;
|
|
68
|
+
/**
|
|
69
|
+
* Initializes a position and adds liquidity to the specified strategy, with various steps including
|
|
70
|
+
* handling wrapped SOL tokens, depositing tokens, adding liquidity, and handling dust withdrawals.
|
|
71
|
+
*
|
|
72
|
+
* @param {web3.PublicKey} userWallet - The public key of the user's wallet executing the transaction.
|
|
73
|
+
* @param {web3.PublicKey} payer - The public key of the transaction payer.
|
|
74
|
+
* @param {Object} params - The parameters for initializing the position and adding liquidity.
|
|
75
|
+
* @param {web3.PublicKey} params.positionPubKey - The public key of the position to be initialized.
|
|
76
|
+
* @param {BN} params.totalXAmount - The total amount of X tokens to be used for liquidity.
|
|
77
|
+
* @param {BN} params.totalYAmount - The total amount of Y tokens to be used for liquidity.
|
|
78
|
+
* @param {Object} params.strategy - The strategy details for adding liquidity.
|
|
79
|
+
* @param {number} params.strategy.maxBinId - The maximum bin ID for the strategy.
|
|
80
|
+
* @param {number} params.strategy.minBinId - The minimum bin ID for the strategy.
|
|
81
|
+
* @param {StrategyType} params.strategy.strategyType - The type of strategy to be applied.
|
|
82
|
+
* @param {web3.PublicKey} params.user - The public key of the user executing the transaction.
|
|
83
|
+
* @param {number} [params.slippage] - Optional slippage tolerance for the transaction.
|
|
84
|
+
*
|
|
85
|
+
* @returns {Promise<web3.TransactionInstruction[]>} - A promise that resolves to an array of transaction instructions.
|
|
86
|
+
*
|
|
87
|
+
* @throws {Error} - Throws an error if input token(s) do not exist on the blockchain.
|
|
88
|
+
*/
|
|
89
|
+
initializePositionAndAddLiquidityByStrategyPda(userWallet: web3.PublicKey, payer: web3.PublicKey, params: {
|
|
90
|
+
positionPubKey: web3.PublicKey;
|
|
91
|
+
totalXAmount: BN;
|
|
92
|
+
totalYAmount: BN;
|
|
93
|
+
strategy: {
|
|
94
|
+
maxBinId: number;
|
|
95
|
+
minBinId: number;
|
|
96
|
+
strategyType: StrategyType;
|
|
97
|
+
};
|
|
98
|
+
user: web3.PublicKey;
|
|
99
|
+
slippage?: number;
|
|
100
|
+
skipInputTokenCheck?: boolean;
|
|
101
|
+
}, meteoraToHawksight: MeteoraToHawksightFn): Promise<InitializePositionAndAddLiquidityByStrategyPdaBuilder>;
|
|
68
102
|
/**
|
|
69
103
|
* Adds liquidity to an existing position according to a specified strategy.
|
|
70
104
|
*
|
|
@@ -126,6 +160,31 @@ export declare class MeteoraDLMM {
|
|
|
126
160
|
bps: BN;
|
|
127
161
|
shouldClaimAndClose?: boolean;
|
|
128
162
|
}, meteoraToHawksight: MeteoraToHawksightFn): Promise<RemoveLiquidityBuilder>;
|
|
163
|
+
/**
|
|
164
|
+
* Removes liquidity from an existing position to the user pda.
|
|
165
|
+
*
|
|
166
|
+
* This method communicates with the DLMM (Dynamic Liquidity Market Maker) to remove liquidity
|
|
167
|
+
* from a specified trading position. It filters the transaction instructions to include only those
|
|
168
|
+
* relevant to the Meteora DLMM program.
|
|
169
|
+
*
|
|
170
|
+
* @param {web3.PublicKey} userWallet - The public key of the user's wallet executing the transaction.
|
|
171
|
+
* @param {web3.PublicKey} payer - The public key of the transaction payer.
|
|
172
|
+
* @param {Object} params - The parameters for removing liquidity from the position.
|
|
173
|
+
* @param {web3.PublicKey} params.user - The public key of the user executing the transaction.
|
|
174
|
+
* @param {web3.PublicKey} params.position - The public key of the position from which liquidity is being removed.
|
|
175
|
+
* @param {number[]} params.binIds - An array of bin IDs indicating which bins to remove liquidity from.
|
|
176
|
+
* @param {BN} params.bps - The basis points (in BN) indicating the proportion of liquidity to remove.
|
|
177
|
+
* @param {boolean} [params.shouldClaimAndClose] - Optional flag to indicate whether the position should be claimed and closed after removing liquidity.
|
|
178
|
+
*
|
|
179
|
+
* @returns {Promise<web3.TransactionInstruction[]>} - A promise that resolves to an array of transaction instructions relevant to the Meteora DLMM program.
|
|
180
|
+
*/
|
|
181
|
+
removeLiquidityPda(userWallet: web3.PublicKey, payer: web3.PublicKey, params: {
|
|
182
|
+
user: web3.PublicKey;
|
|
183
|
+
position: web3.PublicKey;
|
|
184
|
+
binIds: number[];
|
|
185
|
+
bps: BN;
|
|
186
|
+
shouldClaimAndClose?: boolean;
|
|
187
|
+
}, meteoraToHawksight: MeteoraToHawksightFn): Promise<RemoveLiquidityPdaBuilder>;
|
|
129
188
|
/**
|
|
130
189
|
* Claims all rewards for a specified position.
|
|
131
190
|
*
|
|
@@ -210,6 +269,7 @@ export declare class MeteoraFunctions {
|
|
|
210
269
|
BIN_ARRAY_BITMAP_SIZE: BN;
|
|
211
270
|
EXTENSION_BINARRAY_BITMAP_SIZE: BN;
|
|
212
271
|
};
|
|
272
|
+
findMeteoraTickArrays(lbPair: web3.PublicKey, minBinId: number, maxBinId: number): web3.PublicKey[];
|
|
213
273
|
deriveReserve(token: web3.PublicKey, lbPair: web3.PublicKey): web3.PublicKey;
|
|
214
274
|
deriveBinArray(lbPair: web3.PublicKey, index: BN): web3.PublicKey;
|
|
215
275
|
binIdToBinArrayIndex(MAX_BIN_ARRAY_SIZE: BN, binId: BN): BN;
|
|
@@ -279,6 +339,14 @@ export declare class ClaimAllRewardsByPositionBuilder {
|
|
|
279
339
|
* @returns {web3.TransactionInstruction[]} - An array of transaction instructions in the required order.
|
|
280
340
|
*/
|
|
281
341
|
default(): web3.TransactionInstruction[];
|
|
342
|
+
/**
|
|
343
|
+
* Replaces claim fee token ixs into storage token account
|
|
344
|
+
*/
|
|
345
|
+
replaceClaimFeeTokenToSTA(): void;
|
|
346
|
+
/**
|
|
347
|
+
* Replaces reward token into storage token account
|
|
348
|
+
*/
|
|
349
|
+
replaceClaimRewardToSTA(): void;
|
|
282
350
|
}
|
|
283
351
|
/**
|
|
284
352
|
* A builder class for constructing transaction instructions to add liquidity according to a specified strategy.
|
|
@@ -367,6 +435,45 @@ export declare class RemoveLiquidityBuilder {
|
|
|
367
435
|
*/
|
|
368
436
|
replaceClaimRewardToATA(): void;
|
|
369
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* A builder class for constructing transaction instructions to remove liquidity from a position to the pda.
|
|
440
|
+
*
|
|
441
|
+
* This class provides a structured way to build the necessary transaction instructions for removing liquidity
|
|
442
|
+
* from a position, handling operations such as creating associated token accounts (ATAs), claiming rewards,
|
|
443
|
+
* withdrawing tokens, and managing wrapped SOL (wSOL) accounts.
|
|
444
|
+
*/
|
|
445
|
+
export declare class RemoveLiquidityPdaBuilder {
|
|
446
|
+
readonly createAtaIxs: web3.TransactionInstruction[];
|
|
447
|
+
readonly mainIxs: web3.TransactionInstruction[];
|
|
448
|
+
/**
|
|
449
|
+
* Constructs an instance of the RemoveLiquidityBuilder class.
|
|
450
|
+
*
|
|
451
|
+
* @param {web3.TransactionInstruction[]} createAtaIxs - Instructions to create associated token accounts (ATAs) prior to withdrawal.
|
|
452
|
+
* @param {web3.TransactionInstruction[]} mainIxs - Main instructions for claiming fees/rewards, removing liquidity, and possibly closing the position.
|
|
453
|
+
* @param {web3.TransactionInstruction[]} unwrapWsolIxs - Instructions to close wSOL accounts, if any.
|
|
454
|
+
*/
|
|
455
|
+
constructor(createAtaIxs: web3.TransactionInstruction[], mainIxs: web3.TransactionInstruction[]);
|
|
456
|
+
/**
|
|
457
|
+
* Builds the default sequence of transaction instructions for removing liquidity from a position.
|
|
458
|
+
*
|
|
459
|
+
* This method returns an array of transaction instructions that includes:
|
|
460
|
+
* - Initializing associated token accounts (ATAs) prior to withdrawal
|
|
461
|
+
* - Claiming fees and/or rewards, removing liquidity, and possibly closing the position
|
|
462
|
+
* - Withdrawing tokens to the user wallet
|
|
463
|
+
* - Closing wSOL accounts, if any
|
|
464
|
+
*
|
|
465
|
+
* @returns {web3.TransactionInstruction[]} - An array of transaction instructions in the required order.
|
|
466
|
+
*/
|
|
467
|
+
default(): web3.TransactionInstruction[];
|
|
468
|
+
/**
|
|
469
|
+
* Replaces claim fee token ixs into storage token account
|
|
470
|
+
*/
|
|
471
|
+
replaceClaimFeeTokenToSTA(): void;
|
|
472
|
+
/**
|
|
473
|
+
* Replaces reward token into storage token account
|
|
474
|
+
*/
|
|
475
|
+
replaceClaimRewardToSTA(): void;
|
|
476
|
+
}
|
|
370
477
|
/**
|
|
371
478
|
* A builder class for constructing transaction instructions to remove liquidity from a position.
|
|
372
479
|
*
|
|
@@ -403,4 +510,36 @@ export declare class InitializePositionAndAddLiquidityByStrategyBuilder {
|
|
|
403
510
|
*/
|
|
404
511
|
default(): web3.TransactionInstruction[];
|
|
405
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* A builder class for constructing transaction instructions to remove liquidity from a position.
|
|
515
|
+
*
|
|
516
|
+
* This class provides a structured way to build the necessary transaction instructions for removing liquidity
|
|
517
|
+
* from a position, handling operations such as creating associated token accounts (ATAs), claiming rewards,
|
|
518
|
+
* withdrawing tokens, and managing wrapped SOL (wSOL) accounts.
|
|
519
|
+
*/
|
|
520
|
+
export declare class InitializePositionAndAddLiquidityByStrategyPdaBuilder {
|
|
521
|
+
readonly mainIxs: web3.TransactionInstruction[];
|
|
522
|
+
/**
|
|
523
|
+
* Constructs an instance of the InitializePositionAndAddLiquidityByStrategyBuilder class.
|
|
524
|
+
*
|
|
525
|
+
* @param {web3.TransactionInstruction[]} wrapSolIxs - Instructions to wrap SOL to wSOL if needed.
|
|
526
|
+
* @param {web3.TransactionInstruction} depositToPdaIxs - Instruction to deposit X and Y tokens to the UserPDA.
|
|
527
|
+
* @param {web3.TransactionInstruction[]} mainIxs - Main instructions for adding liquidity by strategy.
|
|
528
|
+
* @param {web3.TransactionInstruction} refundDustIxs - Instruction to refund dust tokens to the user wallet.
|
|
529
|
+
* @param {web3.TransactionInstruction[]} unwrapWsolIxs - Instructions to unwrap wSOL to SOL if any.
|
|
530
|
+
*/
|
|
531
|
+
constructor(mainIxs: web3.TransactionInstruction[]);
|
|
532
|
+
/**
|
|
533
|
+
* Builds the default sequence of transaction instructions for removing liquidity from a position.
|
|
534
|
+
*
|
|
535
|
+
* This method returns an array of transaction instructions that includes:
|
|
536
|
+
* - Initializing associated token accounts (ATAs) prior to withdrawal
|
|
537
|
+
* - Claiming fees and/or rewards, removing liquidity, and possibly closing the position
|
|
538
|
+
* - Withdrawing tokens to the user wallet
|
|
539
|
+
* - Closing wSOL accounts, if any
|
|
540
|
+
*
|
|
541
|
+
* @returns {web3.TransactionInstruction[]} - An array of transaction instructions in the required order.
|
|
542
|
+
*/
|
|
543
|
+
default(): web3.TransactionInstruction[];
|
|
544
|
+
}
|
|
406
545
|
//# sourceMappingURL=meteora.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meteora.d.ts","sourceRoot":"","sources":["../../src/meteora.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,EAAE,EAAuF,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAiB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACjN,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAUxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAK/C,qBAAa,WAAW;aACc,IAAI,EAAE,IAAI;IAA9C,OAAO;IAEP,QAAQ,CAAC,MAAM,iBAAoB;IAEnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAc;IACtC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAiB;IAC5C,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkB;WAE/B,MAAM,CACjB,UAAU,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D,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAClD,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,sBAAsB;IACrD,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAC/C,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,sBAAsB;IACnD,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAdvD;;;;;;;;OAQG;gBAEQ,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE,EACzC,eAAe,EAAE,IAAI,CAAC,sBAAsB,EAC5C,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE,EACtC,aAAa,EAAE,IAAI,CAAC,sBAAsB,EAC1C,aAAa,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAGvD;;;;;;;;;;OAUG;IACH,OAAO,IAAI,IAAI,CAAC,sBAAsB,EAAE;CAkBzC;AAED;;;;;;GAMG;AACH,qBAAa,qDAAqD;IAY9D,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAVjD;;;;;;;;OAQG;gBAEQ,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE;IAGjD;;;;;;;;;;OAUG;IACH,OAAO,IAAI,IAAI,CAAC,sBAAsB,EAAE;CAkBzC"}
|
package/dist/src/meteora.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.InitializePositionAndAddLiquidityByStrategyBuilder = exports.RemoveLiquidityBuilder = exports.AddLiquidityByStrategyBuilder = exports.ClaimAllRewardsByPositionBuilder = exports.MeteoraFunctions = exports.MeteoraDLMM = void 0;
|
|
38
|
+
exports.InitializePositionAndAddLiquidityByStrategyPdaBuilder = exports.InitializePositionAndAddLiquidityByStrategyBuilder = exports.RemoveLiquidityPdaBuilder = exports.RemoveLiquidityBuilder = exports.AddLiquidityByStrategyBuilder = exports.ClaimAllRewardsByPositionBuilder = exports.MeteoraFunctions = exports.MeteoraDLMM = void 0;
|
|
39
39
|
const dlmm_1 = __importStar(require("@meteora-ag/dlmm"));
|
|
40
40
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
41
41
|
const web3 = __importStar(require("@solana/web3.js"));
|
|
@@ -188,6 +188,76 @@ class MeteoraDLMM {
|
|
|
188
188
|
(0, functions_1.unwrapSolIfMintIsWsol)(userWallet, mints));
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Initializes a position and adds liquidity to the specified strategy, with various steps including
|
|
193
|
+
* handling wrapped SOL tokens, depositing tokens, adding liquidity, and handling dust withdrawals.
|
|
194
|
+
*
|
|
195
|
+
* @param {web3.PublicKey} userWallet - The public key of the user's wallet executing the transaction.
|
|
196
|
+
* @param {web3.PublicKey} payer - The public key of the transaction payer.
|
|
197
|
+
* @param {Object} params - The parameters for initializing the position and adding liquidity.
|
|
198
|
+
* @param {web3.PublicKey} params.positionPubKey - The public key of the position to be initialized.
|
|
199
|
+
* @param {BN} params.totalXAmount - The total amount of X tokens to be used for liquidity.
|
|
200
|
+
* @param {BN} params.totalYAmount - The total amount of Y tokens to be used for liquidity.
|
|
201
|
+
* @param {Object} params.strategy - The strategy details for adding liquidity.
|
|
202
|
+
* @param {number} params.strategy.maxBinId - The maximum bin ID for the strategy.
|
|
203
|
+
* @param {number} params.strategy.minBinId - The minimum bin ID for the strategy.
|
|
204
|
+
* @param {StrategyType} params.strategy.strategyType - The type of strategy to be applied.
|
|
205
|
+
* @param {web3.PublicKey} params.user - The public key of the user executing the transaction.
|
|
206
|
+
* @param {number} [params.slippage] - Optional slippage tolerance for the transaction.
|
|
207
|
+
*
|
|
208
|
+
* @returns {Promise<web3.TransactionInstruction[]>} - A promise that resolves to an array of transaction instructions.
|
|
209
|
+
*
|
|
210
|
+
* @throws {Error} - Throws an error if input token(s) do not exist on the blockchain.
|
|
211
|
+
*/
|
|
212
|
+
initializePositionAndAddLiquidityByStrategyPda(userWallet, payer, params, meteoraToHawksight) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
if (!!!params.skipInputTokenCheck) {
|
|
215
|
+
// Throw error if input token(s) do not exist on blockchain
|
|
216
|
+
yield (0, functions_1.inputTokenExists)(anchor_1.Anchor.instance().connection, userWallet, [
|
|
217
|
+
this.dlmm.tokenX.publicKey,
|
|
218
|
+
this.dlmm.tokenY.publicKey,
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
// Generate InitializePosition and AddLiquidityByStrategy instruction from Meteora API
|
|
222
|
+
const txn = yield this.dlmm.initializePositionAndAddLiquidityByStrategy(params);
|
|
223
|
+
// Filter out non-meteora instructions
|
|
224
|
+
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
225
|
+
// Find mint from meteora instructions
|
|
226
|
+
const mints = (0, functions_1.getMintsFromInstruction)({
|
|
227
|
+
instructions: ixs,
|
|
228
|
+
find: {
|
|
229
|
+
AddLiquidityByStrategy: {
|
|
230
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
231
|
+
mintIndices: [7, 8],
|
|
232
|
+
},
|
|
233
|
+
AddLiquidityByStrategyOneSide: {
|
|
234
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
235
|
+
mintIndices: [5],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
return new InitializePositionAndAddLiquidityByStrategyPdaBuilder(
|
|
240
|
+
// // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
|
|
241
|
+
// wrapSolIfMintIsWsol(userWallet, payer, [
|
|
242
|
+
// { mint: this.dlmm.tokenX.publicKey, amount: params.totalXAmount },
|
|
243
|
+
// { mint: this.dlmm.tokenY.publicKey, amount: params.totalYAmount },
|
|
244
|
+
// ]),
|
|
245
|
+
// // Step 2: Deposit X and Y token to UserPDA
|
|
246
|
+
// await depositMultipleToken({
|
|
247
|
+
// payer: userWallet,
|
|
248
|
+
// deposit: [
|
|
249
|
+
// { mint: this.dlmm.tokenX.publicKey, amount: params.totalXAmount },
|
|
250
|
+
// { mint: this.dlmm.tokenY.publicKey, amount: params.totalYAmount },
|
|
251
|
+
// ],
|
|
252
|
+
// }),
|
|
253
|
+
// Step 3: Initialize position and add liquidity by strategy
|
|
254
|
+
yield meteoraToHawksight({
|
|
255
|
+
ixs,
|
|
256
|
+
userPda: params.user,
|
|
257
|
+
authority: userWallet,
|
|
258
|
+
}));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
191
261
|
/**
|
|
192
262
|
* Adds liquidity to an existing position according to a specified strategy.
|
|
193
263
|
*
|
|
@@ -339,6 +409,67 @@ class MeteoraDLMM {
|
|
|
339
409
|
(0, functions_1.unwrapSolIfMintIsWsol)(userWallet, mints));
|
|
340
410
|
});
|
|
341
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Removes liquidity from an existing position to the user pda.
|
|
414
|
+
*
|
|
415
|
+
* This method communicates with the DLMM (Dynamic Liquidity Market Maker) to remove liquidity
|
|
416
|
+
* from a specified trading position. It filters the transaction instructions to include only those
|
|
417
|
+
* relevant to the Meteora DLMM program.
|
|
418
|
+
*
|
|
419
|
+
* @param {web3.PublicKey} userWallet - The public key of the user's wallet executing the transaction.
|
|
420
|
+
* @param {web3.PublicKey} payer - The public key of the transaction payer.
|
|
421
|
+
* @param {Object} params - The parameters for removing liquidity from the position.
|
|
422
|
+
* @param {web3.PublicKey} params.user - The public key of the user executing the transaction.
|
|
423
|
+
* @param {web3.PublicKey} params.position - The public key of the position from which liquidity is being removed.
|
|
424
|
+
* @param {number[]} params.binIds - An array of bin IDs indicating which bins to remove liquidity from.
|
|
425
|
+
* @param {BN} params.bps - The basis points (in BN) indicating the proportion of liquidity to remove.
|
|
426
|
+
* @param {boolean} [params.shouldClaimAndClose] - Optional flag to indicate whether the position should be claimed and closed after removing liquidity.
|
|
427
|
+
*
|
|
428
|
+
* @returns {Promise<web3.TransactionInstruction[]>} - A promise that resolves to an array of transaction instructions relevant to the Meteora DLMM program.
|
|
429
|
+
*/
|
|
430
|
+
removeLiquidityPda(userWallet, payer, params, meteoraToHawksight) {
|
|
431
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
+
// Claim fees and/or rewards, remove liquidity, and possibly close position from Meteora API (if set)
|
|
433
|
+
const txn = yield this.dlmm.removeLiquidity(params);
|
|
434
|
+
// Filter out non-meteora instructions
|
|
435
|
+
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
436
|
+
// Find mint from meteora instructions
|
|
437
|
+
const mints = (0, functions_1.getMintsFromInstruction)({
|
|
438
|
+
instructions: ixs,
|
|
439
|
+
find: {
|
|
440
|
+
RemoveLiquidity: {
|
|
441
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
442
|
+
mintIndices: [7, 8],
|
|
443
|
+
},
|
|
444
|
+
RemoveLiquidityByRange: {
|
|
445
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
446
|
+
mintIndices: [7, 8],
|
|
447
|
+
},
|
|
448
|
+
ClaimFee: {
|
|
449
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
450
|
+
mintIndices: [9, 10],
|
|
451
|
+
},
|
|
452
|
+
ClaimReward: {
|
|
453
|
+
programId: addresses_1.METEORA_DLMM_PROGRAM.toBase58(),
|
|
454
|
+
mintIndices: [6],
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
return new RemoveLiquidityPdaBuilder(
|
|
459
|
+
// Step 1: Init ATA prior to withdrawal
|
|
460
|
+
(0, functions_1.createAtaIdempotentIxs)({
|
|
461
|
+
accounts: mints.map((mint) => {
|
|
462
|
+
return { owner: params.user, payer, mint };
|
|
463
|
+
}),
|
|
464
|
+
}),
|
|
465
|
+
// Step 2: Claim fees and/or rewards, remove liquidity, and possibly close position (if set)
|
|
466
|
+
yield meteoraToHawksight({
|
|
467
|
+
ixs,
|
|
468
|
+
userPda: params.user,
|
|
469
|
+
authority: userWallet,
|
|
470
|
+
}));
|
|
471
|
+
});
|
|
472
|
+
}
|
|
342
473
|
/**
|
|
343
474
|
* Claims all rewards for a specified position.
|
|
344
475
|
*
|
|
@@ -525,6 +656,19 @@ class MeteoraFunctions {
|
|
|
525
656
|
EXTENSION_BINARRAY_BITMAP_SIZE,
|
|
526
657
|
};
|
|
527
658
|
}
|
|
659
|
+
findMeteoraTickArrays(lbPair, minBinId, maxBinId) {
|
|
660
|
+
const MAX_BIN_ARRAY_SIZE = new bn_js_1.default(anchor_1.Anchor.instance().meteoraProgram.idl.constants[1].value);
|
|
661
|
+
const binIdStrings = {};
|
|
662
|
+
for (let binId = minBinId; binId <= maxBinId; binId++) {
|
|
663
|
+
binIdStrings[this.binIdToBinArrayIndex(MAX_BIN_ARRAY_SIZE, new bn_js_1.default(binId)).toString()] = 1;
|
|
664
|
+
}
|
|
665
|
+
const binIds = Object.keys(binIdStrings).map(v => new bn_js_1.default(v));
|
|
666
|
+
const tickArrays = binIds.map(binId => this.deriveBinArray(lbPair, binId));
|
|
667
|
+
const tickArrayUpperIndex = binIds[binIds.length - 1].add(new bn_js_1.default(1));
|
|
668
|
+
const tickArrayUpper = this.deriveBinArray(lbPair, tickArrayUpperIndex);
|
|
669
|
+
tickArrays.push(tickArrayUpper);
|
|
670
|
+
return tickArrays;
|
|
671
|
+
}
|
|
528
672
|
deriveReserve(token, lbPair) {
|
|
529
673
|
const [reserve] = web3.PublicKey.findProgramAddressSync([
|
|
530
674
|
lbPair.toBuffer(),
|
|
@@ -831,6 +975,45 @@ class ClaimAllRewardsByPositionBuilder {
|
|
|
831
975
|
...this.unwrapWsolIxs,
|
|
832
976
|
];
|
|
833
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* Replaces claim fee token ixs into storage token account
|
|
980
|
+
*/
|
|
981
|
+
replaceClaimFeeTokenToSTA() {
|
|
982
|
+
const index = this.mainIxs.findIndex(mainIx => {
|
|
983
|
+
const dataWithoutIyfExtensionExecute = mainIx.data.subarray(12);
|
|
984
|
+
return (0, functions_1.sighashMatch)(dataWithoutIyfExtensionExecute, "MeteoraDlmmClaimFeeAutomation");
|
|
985
|
+
});
|
|
986
|
+
// Should never be empty
|
|
987
|
+
if (index === -1) {
|
|
988
|
+
// Throw error instead?
|
|
989
|
+
console.warn(`Warn: claim fee instruction not found! This should not happen.`);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const userPda = this.mainIxs[index].keys[1].pubkey;
|
|
993
|
+
const tokenXMint = this.mainIxs[index].keys[14].pubkey;
|
|
994
|
+
const tokenYMint = this.mainIxs[index].keys[15].pubkey;
|
|
995
|
+
const staTokenX = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenXMint);
|
|
996
|
+
const staTokenY = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenYMint);
|
|
997
|
+
this.mainIxs[index].keys[12].pubkey = staTokenX;
|
|
998
|
+
this.mainIxs[index].keys[13].pubkey = staTokenY;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Replaces reward token into storage token account
|
|
1002
|
+
*/
|
|
1003
|
+
replaceClaimRewardToSTA() {
|
|
1004
|
+
const index = this.mainIxs.findIndex(mainIx => {
|
|
1005
|
+
const dataWithoutIyfExtensionExecute = mainIx.data.subarray(12);
|
|
1006
|
+
return (0, functions_1.sighashMatch)(dataWithoutIyfExtensionExecute, "MeteoraDlmmClaimRewardAutomation");
|
|
1007
|
+
});
|
|
1008
|
+
if (index === -1) {
|
|
1009
|
+
console.warn(`Warn: Reward instruction not found! This may happen if pool has no rewards`);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
const userPda = this.mainIxs[index].keys[1].pubkey;
|
|
1013
|
+
const tokenMint = this.mainIxs[index].keys[10].pubkey;
|
|
1014
|
+
const staToken = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenMint);
|
|
1015
|
+
this.mainIxs[index].keys[11].pubkey = staToken;
|
|
1016
|
+
}
|
|
834
1017
|
}
|
|
835
1018
|
exports.ClaimAllRewardsByPositionBuilder = ClaimAllRewardsByPositionBuilder;
|
|
836
1019
|
/**
|
|
@@ -1006,6 +1189,87 @@ class RemoveLiquidityBuilder {
|
|
|
1006
1189
|
}
|
|
1007
1190
|
}
|
|
1008
1191
|
exports.RemoveLiquidityBuilder = RemoveLiquidityBuilder;
|
|
1192
|
+
/**
|
|
1193
|
+
* A builder class for constructing transaction instructions to remove liquidity from a position to the pda.
|
|
1194
|
+
*
|
|
1195
|
+
* This class provides a structured way to build the necessary transaction instructions for removing liquidity
|
|
1196
|
+
* from a position, handling operations such as creating associated token accounts (ATAs), claiming rewards,
|
|
1197
|
+
* withdrawing tokens, and managing wrapped SOL (wSOL) accounts.
|
|
1198
|
+
*/
|
|
1199
|
+
class RemoveLiquidityPdaBuilder {
|
|
1200
|
+
/**
|
|
1201
|
+
* Constructs an instance of the RemoveLiquidityBuilder class.
|
|
1202
|
+
*
|
|
1203
|
+
* @param {web3.TransactionInstruction[]} createAtaIxs - Instructions to create associated token accounts (ATAs) prior to withdrawal.
|
|
1204
|
+
* @param {web3.TransactionInstruction[]} mainIxs - Main instructions for claiming fees/rewards, removing liquidity, and possibly closing the position.
|
|
1205
|
+
* @param {web3.TransactionInstruction[]} unwrapWsolIxs - Instructions to close wSOL accounts, if any.
|
|
1206
|
+
*/
|
|
1207
|
+
constructor(createAtaIxs, mainIxs) {
|
|
1208
|
+
this.createAtaIxs = createAtaIxs;
|
|
1209
|
+
this.mainIxs = mainIxs;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Builds the default sequence of transaction instructions for removing liquidity from a position.
|
|
1213
|
+
*
|
|
1214
|
+
* This method returns an array of transaction instructions that includes:
|
|
1215
|
+
* - Initializing associated token accounts (ATAs) prior to withdrawal
|
|
1216
|
+
* - Claiming fees and/or rewards, removing liquidity, and possibly closing the position
|
|
1217
|
+
* - Withdrawing tokens to the user wallet
|
|
1218
|
+
* - Closing wSOL accounts, if any
|
|
1219
|
+
*
|
|
1220
|
+
* @returns {web3.TransactionInstruction[]} - An array of transaction instructions in the required order.
|
|
1221
|
+
*/
|
|
1222
|
+
default() {
|
|
1223
|
+
return [
|
|
1224
|
+
// Step 1: Init ATA prior to withdrawal
|
|
1225
|
+
...this.createAtaIxs,
|
|
1226
|
+
// Step 2: Claim fees and/or rewards, remove liquidity, and possibly close position (if set)
|
|
1227
|
+
...this.mainIxs,
|
|
1228
|
+
// // Step 3: Withdraw tokens to user wallet
|
|
1229
|
+
// this.withdrawMultipleTokenIx,
|
|
1230
|
+
// // Step 4: Close wSOL account (if there's any)
|
|
1231
|
+
// ...this.unwrapWsolIxs,
|
|
1232
|
+
];
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Replaces claim fee token ixs into storage token account
|
|
1236
|
+
*/
|
|
1237
|
+
replaceClaimFeeTokenToSTA() {
|
|
1238
|
+
const index = this.mainIxs.findIndex(mainIx => {
|
|
1239
|
+
const dataWithoutIyfExtensionExecute = mainIx.data.subarray(12);
|
|
1240
|
+
return (0, functions_1.sighashMatch)(dataWithoutIyfExtensionExecute, "MeteoraDlmmClaimFeeAutomation");
|
|
1241
|
+
});
|
|
1242
|
+
if (index === -1) {
|
|
1243
|
+
console.warn(`Warn: claim fee instruction not found! This should not happen if \`shouldClaimAndClose\` is set to true.`);
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const userPda = this.mainIxs[index].keys[1].pubkey;
|
|
1247
|
+
const tokenXMint = this.mainIxs[index].keys[14].pubkey;
|
|
1248
|
+
const tokenYMint = this.mainIxs[index].keys[15].pubkey;
|
|
1249
|
+
const staTokenX = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenXMint);
|
|
1250
|
+
const staTokenY = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenYMint);
|
|
1251
|
+
this.mainIxs[index].keys[12].pubkey = staTokenX;
|
|
1252
|
+
this.mainIxs[index].keys[13].pubkey = staTokenY;
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Replaces reward token into storage token account
|
|
1256
|
+
*/
|
|
1257
|
+
replaceClaimRewardToSTA() {
|
|
1258
|
+
const index = this.mainIxs.findIndex(mainIx => {
|
|
1259
|
+
const dataWithoutIyfExtensionExecute = mainIx.data.subarray(12);
|
|
1260
|
+
return (0, functions_1.sighashMatch)(dataWithoutIyfExtensionExecute, "MeteoraDlmmClaimRewardAutomation");
|
|
1261
|
+
});
|
|
1262
|
+
if (index === -1) {
|
|
1263
|
+
console.warn(`Warn: Reward instruction not found! This may happen if pool has no rewards`);
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
const userPda = this.mainIxs[index].keys[1].pubkey;
|
|
1267
|
+
const tokenMint = this.mainIxs[index].keys[10].pubkey;
|
|
1268
|
+
const staToken = (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenMint);
|
|
1269
|
+
this.mainIxs[index].keys[11].pubkey = staToken;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
exports.RemoveLiquidityPdaBuilder = RemoveLiquidityPdaBuilder;
|
|
1009
1273
|
/**
|
|
1010
1274
|
* A builder class for constructing transaction instructions to remove liquidity from a position.
|
|
1011
1275
|
*
|
|
@@ -1057,3 +1321,50 @@ class InitializePositionAndAddLiquidityByStrategyBuilder {
|
|
|
1057
1321
|
}
|
|
1058
1322
|
}
|
|
1059
1323
|
exports.InitializePositionAndAddLiquidityByStrategyBuilder = InitializePositionAndAddLiquidityByStrategyBuilder;
|
|
1324
|
+
/**
|
|
1325
|
+
* A builder class for constructing transaction instructions to remove liquidity from a position.
|
|
1326
|
+
*
|
|
1327
|
+
* This class provides a structured way to build the necessary transaction instructions for removing liquidity
|
|
1328
|
+
* from a position, handling operations such as creating associated token accounts (ATAs), claiming rewards,
|
|
1329
|
+
* withdrawing tokens, and managing wrapped SOL (wSOL) accounts.
|
|
1330
|
+
*/
|
|
1331
|
+
class InitializePositionAndAddLiquidityByStrategyPdaBuilder {
|
|
1332
|
+
/**
|
|
1333
|
+
* Constructs an instance of the InitializePositionAndAddLiquidityByStrategyBuilder class.
|
|
1334
|
+
*
|
|
1335
|
+
* @param {web3.TransactionInstruction[]} wrapSolIxs - Instructions to wrap SOL to wSOL if needed.
|
|
1336
|
+
* @param {web3.TransactionInstruction} depositToPdaIxs - Instruction to deposit X and Y tokens to the UserPDA.
|
|
1337
|
+
* @param {web3.TransactionInstruction[]} mainIxs - Main instructions for adding liquidity by strategy.
|
|
1338
|
+
* @param {web3.TransactionInstruction} refundDustIxs - Instruction to refund dust tokens to the user wallet.
|
|
1339
|
+
* @param {web3.TransactionInstruction[]} unwrapWsolIxs - Instructions to unwrap wSOL to SOL if any.
|
|
1340
|
+
*/
|
|
1341
|
+
constructor(mainIxs) {
|
|
1342
|
+
this.mainIxs = mainIxs;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Builds the default sequence of transaction instructions for removing liquidity from a position.
|
|
1346
|
+
*
|
|
1347
|
+
* This method returns an array of transaction instructions that includes:
|
|
1348
|
+
* - Initializing associated token accounts (ATAs) prior to withdrawal
|
|
1349
|
+
* - Claiming fees and/or rewards, removing liquidity, and possibly closing the position
|
|
1350
|
+
* - Withdrawing tokens to the user wallet
|
|
1351
|
+
* - Closing wSOL accounts, if any
|
|
1352
|
+
*
|
|
1353
|
+
* @returns {web3.TransactionInstruction[]} - An array of transaction instructions in the required order.
|
|
1354
|
+
*/
|
|
1355
|
+
default() {
|
|
1356
|
+
return [
|
|
1357
|
+
// // Step 1: Init wSOL token account for user wallet (if X or Y token is wSOL)
|
|
1358
|
+
// ...this.wrapSolIxs,
|
|
1359
|
+
// // Step 2: Deposit X and Y token to UserPDA
|
|
1360
|
+
// this.depositToPdaIxs,
|
|
1361
|
+
// Step 3: Add liquidity by strategy
|
|
1362
|
+
...this.mainIxs,
|
|
1363
|
+
// // Step 4: Refund dust to user wallet
|
|
1364
|
+
// this.refundDustIxs,
|
|
1365
|
+
// // Step 5: Close wSOL account (if there's any)
|
|
1366
|
+
// ...this.unwrapWsolIxs,
|
|
1367
|
+
];
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
exports.InitializePositionAndAddLiquidityByStrategyPdaBuilder = InitializePositionAndAddLiquidityByStrategyPdaBuilder;
|