@hawksightco/hawk-sdk 1.3.10 → 1.3.12
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/CHANGELOG.md +135 -0
- package/README.md +306 -10
- package/dist/src/addresses.d.ts +3 -0
- package/dist/src/addresses.d.ts.map +1 -1
- package/dist/src/addresses.js +21 -8
- package/dist/src/anchor.d.ts +1 -0
- package/dist/src/anchor.d.ts.map +1 -1
- package/dist/src/anchor.js +17 -7
- package/dist/src/classes/Atomicity.d.ts.map +1 -1
- package/dist/src/classes/Client.js +17 -7
- package/dist/src/classes/CombineTransactions.js +17 -7
- package/dist/src/classes/CreateTxMetadata.js +17 -7
- package/dist/src/classes/General.js +17 -7
- package/dist/src/classes/HawkAPI.d.ts.map +1 -1
- package/dist/src/classes/JupiterAlts.js +17 -7
- package/dist/src/classes/Logging.js +2 -3
- package/dist/src/classes/MultiTransaction.js +19 -9
- package/dist/src/classes/RaydiumSDK.js +3 -3
- package/dist/src/classes/SimpleIxGenerator.d.ts.map +1 -1
- package/dist/src/classes/SimpleIxGenerator.js +1 -1
- package/dist/src/classes/Transaction.js +17 -7
- package/dist/src/classes/Transaction2.js +17 -7
- package/dist/src/classes/Transaction3.js +17 -7
- package/dist/src/classes/TransactionBatchExecute.d.ts.map +1 -1
- package/dist/src/classes/TransactionBatchExecute.js +17 -7
- package/dist/src/classes/TransactionBatchExecute2.js +17 -7
- package/dist/src/classes/Transactions.d.ts +4 -0
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +54 -33
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +20 -7
- package/dist/src/classes/TxGeneratorAutomations.js +17 -7
- package/dist/src/classes/account-cache/AccountCache.d.ts +0 -1
- package/dist/src/classes/account-cache/AccountCache.d.ts.map +1 -1
- package/dist/src/classes/account-cache/AccountCache.js +17 -7
- package/dist/src/functions.d.ts +5 -6
- package/dist/src/functions.d.ts.map +1 -1
- package/dist/src/functions.js +76 -72
- package/dist/src/hawksight.js +24 -15
- package/dist/src/hsToMeteora.js +429 -13
- package/dist/src/idl/iyf-extension-idl.d.ts +1582 -571
- package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-extension-idl.js +1582 -571
- package/dist/src/idl/iyf-main-idl.d.ts +121 -0
- package/dist/src/idl/iyf-main-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-main-idl.js +121 -0
- package/dist/src/idl/jupiter-idl.d.ts +58 -5
- package/dist/src/idl/jupiter-idl.d.ts.map +1 -1
- package/dist/src/idl/jupiter-idl.js +58 -5
- package/dist/src/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/IyfExtensionIxGenerator.js +17 -7
- package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts +7 -1
- package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/IyfMainIxGenerator.js +40 -7
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +17 -7
- package/dist/src/ixGenerator/OrcaIxGenerator.d.ts +67 -2
- package/dist/src/ixGenerator/OrcaIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/OrcaIxGenerator.js +232 -10
- package/dist/src/ixGenerator/RaydiumIxGenerator.js +20 -10
- package/dist/src/meteora.d.ts +1 -1
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +32 -7
- package/dist/src/orca.js +23 -13
- package/dist/src/pdaGenerator/HawksightPdaGenerator.js +17 -7
- package/dist/src/pdaGenerator/OrcaPdaGenerator.d.ts +8 -0
- package/dist/src/pdaGenerator/OrcaPdaGenerator.d.ts.map +1 -1
- package/dist/src/pdaGenerator/OrcaPdaGenerator.js +30 -7
- package/dist/src/pdaGenerator/RaydiumPdaGenerator.js +17 -7
- package/dist/src/pdaGenerator/UtilPdaGenerator.js +17 -7
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +20 -3
package/dist/src/hsToMeteora.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,7 +45,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
46
|
};
|
|
37
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
48
|
+
exports.meteoraToHawksight = meteoraToHawksight;
|
|
49
|
+
exports.meteoraToHawksightAutomationIxs = meteoraToHawksightAutomationIxs;
|
|
50
|
+
exports.meteoraToHawksightPdaIxs = meteoraToHawksightPdaIxs;
|
|
39
51
|
const web3 = __importStar(require("@solana/web3.js"));
|
|
40
52
|
const types_1 = require("./types");
|
|
41
53
|
const addresses_1 = require("./addresses");
|
|
@@ -64,7 +76,6 @@ function meteoraToHawksight(_a) {
|
|
|
64
76
|
return _ixs;
|
|
65
77
|
});
|
|
66
78
|
}
|
|
67
|
-
exports.meteoraToHawksight = meteoraToHawksight;
|
|
68
79
|
/**
|
|
69
80
|
* Convert listed meteora instruction to hawksight meteora automation cpi
|
|
70
81
|
*
|
|
@@ -84,7 +95,6 @@ function meteoraToHawksightAutomationIxs(_a) {
|
|
|
84
95
|
return _ixs;
|
|
85
96
|
});
|
|
86
97
|
}
|
|
87
|
-
exports.meteoraToHawksightAutomationIxs = meteoraToHawksightAutomationIxs;
|
|
88
98
|
/**
|
|
89
99
|
* Convert listed meteora instruction to hawksight meteora automation cpi
|
|
90
100
|
*
|
|
@@ -104,7 +114,6 @@ function meteoraToHawksightPdaIxs(_a) {
|
|
|
104
114
|
return _ixs;
|
|
105
115
|
});
|
|
106
116
|
}
|
|
107
|
-
exports.meteoraToHawksightPdaIxs = meteoraToHawksightPdaIxs;
|
|
108
117
|
/**
|
|
109
118
|
* Abstract base class `HawksightMeteoraCpi` for handling and chaining transaction instructions.
|
|
110
119
|
* This class provides a framework for creating and linking complex transaction processes in a blockchain environment.
|
|
@@ -172,7 +181,8 @@ class HawksightMeteoraCpi {
|
|
|
172
181
|
.next(new ClaimReward2(ix, userPda, authority, opt))
|
|
173
182
|
.next(new ClosePosition(ix, userPda, authority, opt))
|
|
174
183
|
.next(new ClosePosition2(ix, userPda, authority, opt))
|
|
175
|
-
.next(new ClosePositionIfEmpty(ix, userPda, authority, opt))
|
|
184
|
+
.next(new ClosePositionIfEmpty(ix, userPda, authority, opt))
|
|
185
|
+
.next(new MeteoraDlmmDeposit2(ix, userPda, authority, opt));
|
|
176
186
|
return chain;
|
|
177
187
|
}
|
|
178
188
|
/**
|
|
@@ -1172,7 +1182,10 @@ class HawksightMeteoraAutomationCpi {
|
|
|
1172
1182
|
.next(new RemoveLiquidityByRangeAutomation(ix, userPda, authority, opt))
|
|
1173
1183
|
.next(new ClaimFeeAutomation(ix, userPda, authority, opt))
|
|
1174
1184
|
.next(new ClaimRewardAutomation(ix, userPda, authority, opt))
|
|
1175
|
-
.next(new ClosePositionAutomation(ix, userPda, authority, opt))
|
|
1185
|
+
.next(new ClosePositionAutomation(ix, userPda, authority, opt))
|
|
1186
|
+
.next(new MeteoraDlmmClaimFee2Automation(ix, userPda, authority, opt))
|
|
1187
|
+
.next(new MeteoraDlmmDeposit2Automation(ix, userPda, authority, opt))
|
|
1188
|
+
.next(new MeteoraDlmmWithdraw2Automation(ix, userPda, authority, opt));
|
|
1176
1189
|
return chain;
|
|
1177
1190
|
}
|
|
1178
1191
|
/**
|
|
@@ -2113,6 +2126,308 @@ class ClosePositionAutomation extends HawksightMeteoraAutomationCpi {
|
|
|
2113
2126
|
});
|
|
2114
2127
|
}
|
|
2115
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Handles Meteora DLMM Claim Fee v2 Automation instruction.
|
|
2131
|
+
*/
|
|
2132
|
+
class MeteoraDlmmClaimFee2Automation extends HawksightMeteoraAutomationCpi {
|
|
2133
|
+
/**
|
|
2134
|
+
* Constructs an instance of MeteoraDlmmClaimFee2Automation with the necessary transaction parameters.
|
|
2135
|
+
*
|
|
2136
|
+
* @param ix The core transaction instruction.
|
|
2137
|
+
* @param userPda The user's program-derived address (PDA) as a public key.
|
|
2138
|
+
* @param authority The authority public key that has signing capabilities over the transaction.
|
|
2139
|
+
*/
|
|
2140
|
+
constructor(ix, userPda, authority, opt) {
|
|
2141
|
+
super(ix, userPda, authority, Buffer.from([165, 106, 93, 125, 144, 8, 104, 62]), opt);
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* Modifies transaction keys for the purpose of claiming transaction fees.
|
|
2145
|
+
*/
|
|
2146
|
+
replace() {
|
|
2147
|
+
this._ix.keys[1].pubkey = this.userPda;
|
|
2148
|
+
this._ix.keys[1].isSigner = false;
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
* Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
|
|
2152
|
+
*/
|
|
2153
|
+
replaceCpi() {
|
|
2154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2155
|
+
var _a;
|
|
2156
|
+
// Common parameters
|
|
2157
|
+
const userPda = this.userPda;
|
|
2158
|
+
const authority = this.authority;
|
|
2159
|
+
// Get token mints X and Y
|
|
2160
|
+
const tokenXMint = this.ix.keys[9].pubkey;
|
|
2161
|
+
const tokenYMint = this.ix.keys[10].pubkey;
|
|
2162
|
+
const tokenXMintInfo = AccountCache_1.AccountCache.get(tokenXMint);
|
|
2163
|
+
const tokenYMintInfo = AccountCache_1.AccountCache.get(tokenYMint);
|
|
2164
|
+
if (!(!!tokenXMintInfo && !!tokenYMintInfo)) {
|
|
2165
|
+
throw new Error("Unexpected error: Mint X or Y not found in cache.");
|
|
2166
|
+
}
|
|
2167
|
+
// Generate owner fee X and Y ATA
|
|
2168
|
+
const ownerFeeX = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenXMint, tokenXMintInfo.info.owner);
|
|
2169
|
+
const ownerFeeY = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenYMint, tokenYMintInfo.info.owner);
|
|
2170
|
+
// Adjust by token type
|
|
2171
|
+
const pdaTokenType = (_a = this.opt) === null || _a === void 0 ? void 0 : _a.pdaTokenType;
|
|
2172
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
2173
|
+
this.ix.keys[7].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[9].pubkey);
|
|
2174
|
+
this.ix.keys[8].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[10].pubkey);
|
|
2175
|
+
}
|
|
2176
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
2177
|
+
this.ix.keys[7].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[9].pubkey);
|
|
2178
|
+
this.ix.keys[8].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[10].pubkey);
|
|
2179
|
+
}
|
|
2180
|
+
else {
|
|
2181
|
+
this.ix.keys[7].pubkey = util.generateAta(this.userPda, this.ix.keys[9].pubkey, tokenXMintInfo.info.owner);
|
|
2182
|
+
this.ix.keys[8].pubkey = util.generateAta(this.userPda, this.ix.keys[10].pubkey, tokenYMintInfo.info.owner);
|
|
2183
|
+
}
|
|
2184
|
+
// Generate IX via extension contract
|
|
2185
|
+
// @ts-ignore
|
|
2186
|
+
const claimFeeIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
2187
|
+
.meteoraDlmmClaimFee2Automation()
|
|
2188
|
+
.accounts({
|
|
2189
|
+
userPda,
|
|
2190
|
+
authority,
|
|
2191
|
+
hawksightAuthority: this.ix.keys[2].pubkey,
|
|
2192
|
+
lbPair: this.ix.keys[3].pubkey,
|
|
2193
|
+
position: this.ix.keys[4].pubkey,
|
|
2194
|
+
reserveX: this.ix.keys[5].pubkey,
|
|
2195
|
+
reserveY: this.ix.keys[6].pubkey,
|
|
2196
|
+
userTokenX: this.ix.keys[7].pubkey,
|
|
2197
|
+
userTokenY: this.ix.keys[8].pubkey,
|
|
2198
|
+
tokenXMint: this.ix.keys[9].pubkey,
|
|
2199
|
+
tokenYMint: this.ix.keys[10].pubkey,
|
|
2200
|
+
tokenProgramX: this.ix.keys[11].pubkey,
|
|
2201
|
+
tokenProgramY: this.ix.keys[12].pubkey,
|
|
2202
|
+
memoProgram: this.ix.keys[13].pubkey,
|
|
2203
|
+
eventAuthority: this.ix.keys[14].pubkey,
|
|
2204
|
+
meteoraDlmmProgram: this.ix.keys[15].pubkey,
|
|
2205
|
+
ownerFeeX,
|
|
2206
|
+
ownerFeeY,
|
|
2207
|
+
}).instruction();
|
|
2208
|
+
const sighash = util.sighash("meteora_dlmm_claim_fee_2_automation");
|
|
2209
|
+
claimFeeIx.data.set(sighash, 0);
|
|
2210
|
+
// Instruction via main hawksight contract
|
|
2211
|
+
// @ts-ignore
|
|
2212
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
2213
|
+
.iyfExtensionExecuteV2(claimFeeIx.data)
|
|
2214
|
+
.accounts({
|
|
2215
|
+
userPda,
|
|
2216
|
+
authority,
|
|
2217
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
2218
|
+
})
|
|
2219
|
+
.remainingAccounts(claimFeeIx.keys.slice(2))
|
|
2220
|
+
.instruction();
|
|
2221
|
+
// Override the instruction
|
|
2222
|
+
this._ix = ix;
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Handles Meteora DLMM Deposit v2 Automation instruction.
|
|
2228
|
+
*/
|
|
2229
|
+
class MeteoraDlmmDeposit2Automation extends HawksightMeteoraAutomationCpi {
|
|
2230
|
+
/**
|
|
2231
|
+
* Constructs an instance of MeteoraDlmmDeposit2Automation with the necessary transaction parameters.
|
|
2232
|
+
*
|
|
2233
|
+
* @param ix The core transaction instruction.
|
|
2234
|
+
* @param userPda The user's program-derived address (PDA) as a public key.
|
|
2235
|
+
* @param authority The authority public key that has signing capabilities over the transaction.
|
|
2236
|
+
*/
|
|
2237
|
+
constructor(ix, userPda, authority, opt) {
|
|
2238
|
+
super(ix, userPda, authority, Buffer.from([180, 169, 127, 243, 205, 255, 102, 164]), opt);
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Modifies transaction keys for the purpose of depositing liquidity.
|
|
2242
|
+
*/
|
|
2243
|
+
replace() {
|
|
2244
|
+
this._ix.keys[1].pubkey = this.userPda;
|
|
2245
|
+
this._ix.keys[1].isSigner = false;
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
|
|
2249
|
+
*/
|
|
2250
|
+
replaceCpi() {
|
|
2251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2252
|
+
var _a;
|
|
2253
|
+
// Common parameters
|
|
2254
|
+
const farm = addresses_1.USDC_FARM;
|
|
2255
|
+
const userPda = this.userPda;
|
|
2256
|
+
const authority = this.authority;
|
|
2257
|
+
const iyfProgram = addresses_1.IYF_MAIN;
|
|
2258
|
+
const hawksightAuthority = addresses_1.HS_AUTHORITY;
|
|
2259
|
+
// Get token mints X and Y
|
|
2260
|
+
const tokenXMint = this.ix.keys[9].pubkey;
|
|
2261
|
+
const tokenYMint = this.ix.keys[10].pubkey;
|
|
2262
|
+
// Generate IX via extension contract
|
|
2263
|
+
const data = this.ix.data.subarray(8);
|
|
2264
|
+
const activeId = data.subarray(16, 20).readInt32LE();
|
|
2265
|
+
const maxActiveBinSlippage = data.subarray(20, 24).readInt32LE();
|
|
2266
|
+
const strategyParametersMinBinId = data.subarray(24, 28).readInt32LE();
|
|
2267
|
+
const strategyParametersMaxBinId = data.subarray(28, 32).readInt32LE();
|
|
2268
|
+
const strategyParametersStrategyType = data[32];
|
|
2269
|
+
const strategyParametersParameters = Array.from(data.subarray(33));
|
|
2270
|
+
const tokenXMintInfo = AccountCache_1.AccountCache.get(tokenXMint);
|
|
2271
|
+
const tokenYMintInfo = AccountCache_1.AccountCache.get(tokenYMint);
|
|
2272
|
+
if (!(!!tokenXMintInfo && !!tokenYMintInfo)) {
|
|
2273
|
+
throw new Error("Unexpected error: Mint X or Y not found in cache.");
|
|
2274
|
+
}
|
|
2275
|
+
// Adjust by token type
|
|
2276
|
+
const pdaTokenType = (_a = this.opt) === null || _a === void 0 ? void 0 : _a.pdaTokenType;
|
|
2277
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
2278
|
+
this.ix.keys[5].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[9].pubkey);
|
|
2279
|
+
this.ix.keys[6].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[10].pubkey);
|
|
2280
|
+
}
|
|
2281
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
2282
|
+
this.ix.keys[5].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[9].pubkey);
|
|
2283
|
+
this.ix.keys[6].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[10].pubkey);
|
|
2284
|
+
}
|
|
2285
|
+
else {
|
|
2286
|
+
this.ix.keys[5].pubkey = util.generateAta(this.userPda, this.ix.keys[9].pubkey, tokenXMintInfo.info.owner);
|
|
2287
|
+
this.ix.keys[6].pubkey = util.generateAta(this.userPda, this.ix.keys[10].pubkey, tokenYMintInfo.info.owner);
|
|
2288
|
+
}
|
|
2289
|
+
// @ts-ignore
|
|
2290
|
+
const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
2291
|
+
.meteoraDlmmDeposit2Automation(activeId, maxActiveBinSlippage, strategyParametersMinBinId, strategyParametersMaxBinId, strategyParametersStrategyType, strategyParametersParameters)
|
|
2292
|
+
.accounts({
|
|
2293
|
+
farm,
|
|
2294
|
+
userPda,
|
|
2295
|
+
authority,
|
|
2296
|
+
iyfProgram,
|
|
2297
|
+
hawksightAuthority,
|
|
2298
|
+
position: this.ix.keys[2].pubkey,
|
|
2299
|
+
lbPair: this.ix.keys[3].pubkey,
|
|
2300
|
+
binArrayBitmapExtension: this.ix.keys[4].pubkey,
|
|
2301
|
+
userTokenX: this.ix.keys[5].pubkey,
|
|
2302
|
+
userTokenY: this.ix.keys[6].pubkey,
|
|
2303
|
+
reserveX: this.ix.keys[7].pubkey,
|
|
2304
|
+
reserveY: this.ix.keys[8].pubkey,
|
|
2305
|
+
tokenXMint: this.ix.keys[9].pubkey,
|
|
2306
|
+
tokenYMint: this.ix.keys[10].pubkey,
|
|
2307
|
+
tokenXProgram: this.ix.keys[11].pubkey,
|
|
2308
|
+
tokenYProgram: this.ix.keys[12].pubkey,
|
|
2309
|
+
eventAuthority: this.ix.keys[13].pubkey,
|
|
2310
|
+
meteoraDlmmProgram: this.ix.keys[14].pubkey,
|
|
2311
|
+
}).instruction();
|
|
2312
|
+
const sighash = util.sighash("meteora_dlmm_deposit_2_automation");
|
|
2313
|
+
depositIx.data.set(sighash, 0);
|
|
2314
|
+
// Instruction via main hawksight contract
|
|
2315
|
+
// @ts-ignore
|
|
2316
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
2317
|
+
.iyfExtensionExecuteV2(depositIx.data)
|
|
2318
|
+
.accounts({
|
|
2319
|
+
farm,
|
|
2320
|
+
userPda,
|
|
2321
|
+
authority,
|
|
2322
|
+
iyfProgram,
|
|
2323
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
2324
|
+
})
|
|
2325
|
+
.remainingAccounts(depositIx.keys.slice(4))
|
|
2326
|
+
.instruction();
|
|
2327
|
+
// Override the instruction
|
|
2328
|
+
this._ix = ix;
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Handles Meteora DLMM Withdraw v2 Automation instruction.
|
|
2334
|
+
*/
|
|
2335
|
+
class MeteoraDlmmWithdraw2Automation extends HawksightMeteoraAutomationCpi {
|
|
2336
|
+
/**
|
|
2337
|
+
* Constructs an instance of MeteoraDlmmWithdraw2Automation with the necessary transaction parameters.
|
|
2338
|
+
*
|
|
2339
|
+
* @param ix The core transaction instruction.
|
|
2340
|
+
* @param userPda The user's program-derived address (PDA) as a public key.
|
|
2341
|
+
* @param authority The authority public key that has signing capabilities over the transaction.
|
|
2342
|
+
*/
|
|
2343
|
+
constructor(ix, userPda, authority, opt) {
|
|
2344
|
+
super(ix, userPda, authority, Buffer.from([54, 152, 149, 59, 20, 177, 13, 212]), opt);
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Modifies transaction keys for the purpose of withdrawing liquidity.
|
|
2348
|
+
*/
|
|
2349
|
+
replace() {
|
|
2350
|
+
this._ix.keys[1].pubkey = this.userPda;
|
|
2351
|
+
this._ix.keys[1].isSigner = false;
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
|
|
2355
|
+
*/
|
|
2356
|
+
replaceCpi() {
|
|
2357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2358
|
+
var _a;
|
|
2359
|
+
// Common parameters
|
|
2360
|
+
const farm = addresses_1.USDC_FARM;
|
|
2361
|
+
const userPda = this.userPda;
|
|
2362
|
+
const authority = this.authority;
|
|
2363
|
+
const iyfProgram = addresses_1.IYF_MAIN;
|
|
2364
|
+
const hawksightAuthority = addresses_1.HS_AUTHORITY;
|
|
2365
|
+
// Get token mints X and Y
|
|
2366
|
+
const tokenXMint = this.ix.keys[9].pubkey;
|
|
2367
|
+
const tokenYMint = this.ix.keys[10].pubkey;
|
|
2368
|
+
const tokenXMintInfo = AccountCache_1.AccountCache.get(tokenXMint);
|
|
2369
|
+
const tokenYMintInfo = AccountCache_1.AccountCache.get(tokenYMint);
|
|
2370
|
+
if (!(!!tokenXMintInfo && !!tokenYMintInfo)) {
|
|
2371
|
+
throw new Error("Unexpected error: Mint X or Y not found in cache.");
|
|
2372
|
+
}
|
|
2373
|
+
// Adjust by token type
|
|
2374
|
+
const pdaTokenType = (_a = this.opt) === null || _a === void 0 ? void 0 : _a.pdaTokenType;
|
|
2375
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
2376
|
+
this.ix.keys[5].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[9].pubkey);
|
|
2377
|
+
this.ix.keys[6].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[10].pubkey);
|
|
2378
|
+
}
|
|
2379
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
2380
|
+
this.ix.keys[5].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[9].pubkey);
|
|
2381
|
+
this.ix.keys[6].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[10].pubkey);
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
this.ix.keys[5].pubkey = util.generateAta(this.userPda, this.ix.keys[9].pubkey, tokenXMintInfo.info.owner);
|
|
2385
|
+
this.ix.keys[6].pubkey = util.generateAta(this.userPda, this.ix.keys[10].pubkey, tokenYMintInfo.info.owner);
|
|
2386
|
+
}
|
|
2387
|
+
// Generate IX via extension contract
|
|
2388
|
+
// @ts-ignore
|
|
2389
|
+
const withdrawIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
2390
|
+
.meteoraDlmmWithdraw2Automation(this.ix.data)
|
|
2391
|
+
.accounts({
|
|
2392
|
+
farm,
|
|
2393
|
+
userPda,
|
|
2394
|
+
authority,
|
|
2395
|
+
iyfProgram,
|
|
2396
|
+
hawksightAuthority,
|
|
2397
|
+
position: this.ix.keys[2].pubkey,
|
|
2398
|
+
lbPair: this.ix.keys[3].pubkey,
|
|
2399
|
+
binArrayBitmapExtension: this.ix.keys[4].pubkey,
|
|
2400
|
+
userTokenX: this.ix.keys[5].pubkey,
|
|
2401
|
+
userTokenY: this.ix.keys[6].pubkey,
|
|
2402
|
+
reserveX: this.ix.keys[7].pubkey,
|
|
2403
|
+
reserveY: this.ix.keys[8].pubkey,
|
|
2404
|
+
tokenXMint: this.ix.keys[9].pubkey,
|
|
2405
|
+
tokenYMint: this.ix.keys[10].pubkey,
|
|
2406
|
+
tokenXProgram: this.ix.keys[11].pubkey,
|
|
2407
|
+
tokenYProgram: this.ix.keys[12].pubkey,
|
|
2408
|
+
eventAuthority: this.ix.keys[13].pubkey,
|
|
2409
|
+
meteoraDlmmProgram: this.ix.keys[14].pubkey,
|
|
2410
|
+
}).instruction();
|
|
2411
|
+
const sighash = util.sighash("meteora_dlmm_withdraw_2_automation");
|
|
2412
|
+
withdrawIx.data.set(sighash, 0);
|
|
2413
|
+
// Instruction via main hawksight contract
|
|
2414
|
+
// @ts-ignore
|
|
2415
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
2416
|
+
.iyfExtensionExecuteV2(withdrawIx.data)
|
|
2417
|
+
.accounts({
|
|
2418
|
+
farm,
|
|
2419
|
+
userPda,
|
|
2420
|
+
authority,
|
|
2421
|
+
iyfProgram,
|
|
2422
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
2423
|
+
})
|
|
2424
|
+
.remainingAccounts(withdrawIx.keys.slice(4))
|
|
2425
|
+
.instruction();
|
|
2426
|
+
// Override the instruction
|
|
2427
|
+
this._ix = ix;
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2116
2431
|
/**
|
|
2117
2432
|
* Abstract base class `HawksightMeteoraCpi` for handling and chaining transaction instructions.
|
|
2118
2433
|
* This class provides a framework for creating and linking complex transaction processes in a blockchain environment.
|
|
@@ -2517,3 +2832,104 @@ class AddLiquidityByStrategyOneSidePda extends HawksightMeteoraPdaCpi {
|
|
|
2517
2832
|
});
|
|
2518
2833
|
}
|
|
2519
2834
|
}
|
|
2835
|
+
/**
|
|
2836
|
+
* Handles Meteora DLMM Deposit v2 instruction (non-automation version).
|
|
2837
|
+
*/
|
|
2838
|
+
class MeteoraDlmmDeposit2 extends HawksightMeteoraCpi {
|
|
2839
|
+
/**
|
|
2840
|
+
* Constructs an instance of MeteoraDlmmDeposit2 with the necessary transaction parameters.
|
|
2841
|
+
*
|
|
2842
|
+
* @param ix The core transaction instruction.
|
|
2843
|
+
* @param userPda The user's program-derived address (PDA) as a public key.
|
|
2844
|
+
* @param authority The authority public key that has signing capabilities over the transaction.
|
|
2845
|
+
*/
|
|
2846
|
+
constructor(ix, userPda, authority, opt) {
|
|
2847
|
+
super(ix, userPda, authority, Buffer.from([202, 49, 107, 181, 87, 156, 173, 94]), opt);
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Modifies transaction keys for the purpose of depositing liquidity.
|
|
2851
|
+
*/
|
|
2852
|
+
replace() {
|
|
2853
|
+
this.ix.keys[1].pubkey = this.userPda;
|
|
2854
|
+
this.ix.keys[1].isSigner = false;
|
|
2855
|
+
}
|
|
2856
|
+
/**
|
|
2857
|
+
* Overrides default add hawksight cpi to use meteoraDlmmDeposit2 instead of meteoraDynamicCpi
|
|
2858
|
+
*/
|
|
2859
|
+
addHawksightCpi() {
|
|
2860
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2861
|
+
var _a;
|
|
2862
|
+
// Common parameters
|
|
2863
|
+
const userPda = this.userPda;
|
|
2864
|
+
const authority = this.authority;
|
|
2865
|
+
// Get token mints X and Y
|
|
2866
|
+
const tokenXMint = this.ix.keys[9].pubkey;
|
|
2867
|
+
const tokenYMint = this.ix.keys[10].pubkey;
|
|
2868
|
+
// Generate IX via extension contract
|
|
2869
|
+
const data = this.ix.data.subarray(8);
|
|
2870
|
+
const activeId = data.subarray(0, 4).readInt32LE();
|
|
2871
|
+
const maxActiveBinSlippage = data.subarray(4, 8).readInt32LE();
|
|
2872
|
+
const strategyParametersMinBinId = data.subarray(8, 12).readInt32LE();
|
|
2873
|
+
const strategyParametersMaxBinId = data.subarray(12, 16).readInt32LE();
|
|
2874
|
+
const strategyParametersStrategyType = data[16];
|
|
2875
|
+
const strategyParametersParameters = Array.from(data.subarray(17));
|
|
2876
|
+
const tokenXMintInfo = AccountCache_1.AccountCache.get(tokenXMint);
|
|
2877
|
+
const tokenYMintInfo = AccountCache_1.AccountCache.get(tokenYMint);
|
|
2878
|
+
if (!(!!tokenXMintInfo && !!tokenYMintInfo)) {
|
|
2879
|
+
throw new Error("Unexpected error: Mint X or Y not found in cache.");
|
|
2880
|
+
}
|
|
2881
|
+
// Adjust by token type
|
|
2882
|
+
const pdaTokenType = (_a = this.opt) === null || _a === void 0 ? void 0 : _a.pdaTokenType;
|
|
2883
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
2884
|
+
this.ix.keys[5].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[9].pubkey);
|
|
2885
|
+
this.ix.keys[6].pubkey = util.generateLimitToken(this.userPda, this.ix.keys[10].pubkey);
|
|
2886
|
+
}
|
|
2887
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
2888
|
+
this.ix.keys[5].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[9].pubkey);
|
|
2889
|
+
this.ix.keys[6].pubkey = util.generateUserPdaStorageAccount(this.userPda, this.ix.keys[10].pubkey);
|
|
2890
|
+
}
|
|
2891
|
+
else {
|
|
2892
|
+
this.ix.keys[5].pubkey = util.generateAta(this.userPda, this.ix.keys[9].pubkey, tokenXMintInfo.info.owner);
|
|
2893
|
+
this.ix.keys[6].pubkey = util.generateAta(this.userPda, this.ix.keys[10].pubkey, tokenYMintInfo.info.owner);
|
|
2894
|
+
}
|
|
2895
|
+
// Generate IX via extension contract
|
|
2896
|
+
// @ts-ignore
|
|
2897
|
+
const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
2898
|
+
.meteoraDlmmDeposit2(activeId, maxActiveBinSlippage, strategyParametersMinBinId, strategyParametersMaxBinId, strategyParametersStrategyType, strategyParametersParameters)
|
|
2899
|
+
.accounts({
|
|
2900
|
+
userPda,
|
|
2901
|
+
authority,
|
|
2902
|
+
position: this.ix.keys[2].pubkey,
|
|
2903
|
+
lbPair: this.ix.keys[3].pubkey,
|
|
2904
|
+
binArrayBitmapExtension: this.ix.keys[4].pubkey,
|
|
2905
|
+
userTokenX: this.ix.keys[5].pubkey,
|
|
2906
|
+
userTokenY: this.ix.keys[6].pubkey,
|
|
2907
|
+
reserveX: this.ix.keys[7].pubkey,
|
|
2908
|
+
reserveY: this.ix.keys[8].pubkey,
|
|
2909
|
+
tokenXMint: this.ix.keys[9].pubkey,
|
|
2910
|
+
tokenYMint: this.ix.keys[10].pubkey,
|
|
2911
|
+
tokenXProgram: this.ix.keys[11].pubkey,
|
|
2912
|
+
tokenYProgram: this.ix.keys[12].pubkey,
|
|
2913
|
+
eventAuthority: this.ix.keys[13].pubkey,
|
|
2914
|
+
meteoraDlmmProgram: this.ix.keys[14].pubkey,
|
|
2915
|
+
}).instruction();
|
|
2916
|
+
const sighash = util.sighash("meteora_dlmm_deposit_2");
|
|
2917
|
+
depositIx.data.set(sighash, 0);
|
|
2918
|
+
// Instruction via main hawksight contract
|
|
2919
|
+
// @ts-ignore
|
|
2920
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
2921
|
+
.iyfExtensionExecuteV2(depositIx.data)
|
|
2922
|
+
.accounts({
|
|
2923
|
+
userPda,
|
|
2924
|
+
authority,
|
|
2925
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
2926
|
+
})
|
|
2927
|
+
.remainingAccounts(depositIx.keys.slice(2))
|
|
2928
|
+
.instruction();
|
|
2929
|
+
// Override the instruction
|
|
2930
|
+
this.ix.programId = ix.programId;
|
|
2931
|
+
this.ix.data = ix.data;
|
|
2932
|
+
this.ix.keys = ix.keys;
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
}
|