@hawksightco/hawk-sdk 1.3.102 → 1.3.104
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/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +107 -159
- package/dist/src/errors.d.ts +10 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +91 -1
- package/dist/src/functions.js +3 -3
- package/dist/src/hsToMeteora.js +5 -13
- package/dist/src/idl/iyf-extension-idl.d.ts +0 -112
- package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-extension-idl.js +1 -113
- package/dist/src/idl/iyf-main-idl.d.ts +1 -0
- package/dist/src/idl/iyf-main-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-main-idl.js +1 -0
- package/dist/src/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/IyfExtensionIxGenerator.js +0 -12
- package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/IyfMainIxGenerator.js +0 -2
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +9 -30
- package/dist/src/ixGenerator/RaydiumIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/RaydiumIxGenerator.js +0 -5
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +3 -3
- package/package.json +4 -2
- package/test/logs/.gitignore +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAoBxC,OAAO,EACL,Y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AAC;IAuB3E;;;;;;OAMG;IACG,wBAAwB,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAmG/E;;;;;;OAMG;IACG,wBAAwB,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAmFhF;AAED,eAAO,MAAM,KAAK,cAA6B,CAAC"}
|
|
@@ -46,6 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.txgen = exports.Transactions = void 0;
|
|
49
|
+
const errors_1 = require("../errors");
|
|
49
50
|
const dlmm_1 = require("@meteora-ag/dlmm");
|
|
50
51
|
const web3 = __importStar(require("@solana/web3.js"));
|
|
51
52
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -881,21 +882,11 @@ class Transactions {
|
|
|
881
882
|
checkRange: params.checkRange,
|
|
882
883
|
useAta: params.useAta
|
|
883
884
|
}, null, 2));
|
|
884
|
-
console.log('Step 1: Fetching position data...');
|
|
885
885
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
886
886
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
887
|
-
console.log('Position data:', {
|
|
888
|
-
lbPair: position.lbPair.toString(),
|
|
889
|
-
lowerBinId: position.lowerBinId,
|
|
890
|
-
upperBinId: position.upperBinId,
|
|
891
|
-
owner: position.owner.toString()
|
|
892
|
-
});
|
|
893
|
-
console.log('Step 2: Creating DLMM pool...');
|
|
894
887
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
895
888
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
896
|
-
console.log('User PDA:', userPda.toString());
|
|
897
889
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
898
|
-
console.log('Step 3: Getting user positions...');
|
|
899
890
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
900
891
|
console.log('Found user positions:', userPositions.length);
|
|
901
892
|
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.equals(params.currentPosition));
|
|
@@ -903,7 +894,6 @@ class Transactions {
|
|
|
903
894
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
904
895
|
}
|
|
905
896
|
console.log('User position found:', userPosition.publicKey.toString());
|
|
906
|
-
console.log('Step 4: Creating remove liquidity builder...');
|
|
907
897
|
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
908
898
|
user: userPda,
|
|
909
899
|
position: params.currentPosition,
|
|
@@ -912,22 +902,16 @@ class Transactions {
|
|
|
912
902
|
bps: new bn_js_1.default(10000),
|
|
913
903
|
shouldClaimAndClose: true,
|
|
914
904
|
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
915
|
-
console.log('Remove liquidity builder created successfully');
|
|
916
|
-
console.log('Step 5: Replacing claim tokens...');
|
|
917
905
|
if (!!params.useAta) {
|
|
918
906
|
removeLiquidityBuilder.replaceClaimFeeTokenToATA();
|
|
919
|
-
console.log('Replaced claim fee token to ATA');
|
|
920
907
|
removeLiquidityBuilder.replaceClaimRewardToATA();
|
|
921
|
-
console.log('Replaced claim reward token to STA');
|
|
922
908
|
}
|
|
923
909
|
else {
|
|
924
910
|
removeLiquidityBuilder.replaceClaimFeeTokenToSTA();
|
|
925
911
|
removeLiquidityBuilder.replaceClaimRewardToSTA();
|
|
926
|
-
console.log('Replaced both claim tokens to STA');
|
|
927
912
|
}
|
|
928
913
|
// Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
|
|
929
914
|
const { userWallet, newPosition, relativeBinRange, distribution, checkRange, } = params;
|
|
930
|
-
console.log('Step 6: Preparing redeposit parameters...');
|
|
931
915
|
const redepositParams = {
|
|
932
916
|
userWallet,
|
|
933
917
|
lbPair: position.lbPair,
|
|
@@ -940,11 +924,7 @@ class Transactions {
|
|
|
940
924
|
maxBinId: checkRange.upperRange,
|
|
941
925
|
},
|
|
942
926
|
};
|
|
943
|
-
console.log('Redeposit params:', JSON.stringify(Object.assign(Object.assign({}, redepositParams), { userWallet: redepositParams.userWallet.toString(), lbPair: redepositParams.lbPair.toString(), position: redepositParams.position.toString(), strategyType: redepositParams.strategyType }), null, 2));
|
|
944
|
-
console.log('Step 7: Calling redepositAutomation2...');
|
|
945
927
|
const redepositIx = yield this.ix.meteoraDlmm.redepositAutomation2(connection, redepositParams);
|
|
946
|
-
console.log('Redeposit instruction created successfully');
|
|
947
|
-
console.log('Step 8: Building final instructions...');
|
|
948
928
|
const mainInstructions = [
|
|
949
929
|
// Initialize required ATA
|
|
950
930
|
...removeLiquidityBuilder.createAtaIxs,
|
|
@@ -953,8 +933,6 @@ class Transactions {
|
|
|
953
933
|
// Re-deposit liquidity
|
|
954
934
|
redepositIx,
|
|
955
935
|
];
|
|
956
|
-
console.log('Final instruction count:', mainInstructions.length);
|
|
957
|
-
console.log('=== REBALANCE AUTOMATION IX2 SUCCESS ===');
|
|
958
936
|
return (0, functions_1.createTransactionMeta)({
|
|
959
937
|
payer: params.userWallet,
|
|
960
938
|
description: "Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)",
|
|
@@ -1119,49 +1097,14 @@ class Transactions {
|
|
|
1119
1097
|
limitCloseAutomationIx(_a) {
|
|
1120
1098
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
1121
1099
|
try {
|
|
1122
|
-
console.log('=== LIMIT CLOSE AUTOMATION IX START ===');
|
|
1123
|
-
console.log('Params:', JSON.stringify({
|
|
1124
|
-
userWallet: params.userWallet.toString(),
|
|
1125
|
-
position: params.position.toString(),
|
|
1126
|
-
minBinId: params.minBinId,
|
|
1127
|
-
maxBinId: params.maxBinId,
|
|
1128
|
-
pdaTokenType: params.pdaTokenType
|
|
1129
|
-
}, null, 2));
|
|
1130
|
-
console.log('Step 1: Fetching position data...');
|
|
1131
1100
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
1132
1101
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
1133
|
-
console.log('Position data:', {
|
|
1134
|
-
lbPair: position.lbPair.toString(),
|
|
1135
|
-
lowerBinId: position.lowerBinId,
|
|
1136
|
-
upperBinId: position.upperBinId,
|
|
1137
|
-
owner: position.owner.toString()
|
|
1138
|
-
});
|
|
1139
|
-
console.log('Step 2: Creating DLMM pool...');
|
|
1140
1102
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
1141
|
-
console.log('DLMM pool created successfully');
|
|
1142
1103
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
1143
|
-
console.log('User PDA generated:', userPda.toString());
|
|
1144
|
-
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
1145
|
-
// const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair(
|
|
1146
|
-
// userPda
|
|
1147
|
-
// );
|
|
1148
|
-
// const binIdsToRemove = userPositions[0].positionData.positionBinData.map(
|
|
1149
|
-
// (bin) => bin.binId
|
|
1150
|
-
// );
|
|
1151
1104
|
const binIdsToRemove = [];
|
|
1152
1105
|
for (let i = position.lowerBinId; i <= position.upperBinId; i++) {
|
|
1153
1106
|
binIdsToRemove.push(i);
|
|
1154
1107
|
}
|
|
1155
|
-
console.log('Bin IDs to remove:', binIdsToRemove);
|
|
1156
|
-
console.log('Step 3: Calling removeLiquidity...');
|
|
1157
|
-
console.log('removeLiquidity params:', {
|
|
1158
|
-
user: userPda.toString(),
|
|
1159
|
-
position: params.position.toString(),
|
|
1160
|
-
fromBinId: position.lowerBinId,
|
|
1161
|
-
toBinId: position.upperBinId,
|
|
1162
|
-
bps: 10000,
|
|
1163
|
-
shouldClaimAndClose: true
|
|
1164
|
-
});
|
|
1165
1108
|
// Claim fees and/or rewards, remove liquidity, and possibly close position from Meteora API (if set)
|
|
1166
1109
|
const txn = yield dlmmPool.dlmm.removeLiquidity({
|
|
1167
1110
|
user: userPda,
|
|
@@ -1171,13 +1114,8 @@ class Transactions {
|
|
|
1171
1114
|
bps: new bn_js_1.default(10000),
|
|
1172
1115
|
shouldClaimAndClose: true,
|
|
1173
1116
|
});
|
|
1174
|
-
console.log('removeLiquidity completed successfully');
|
|
1175
|
-
console.log('Transaction array length:', txn.length);
|
|
1176
|
-
console.log('Total instructions across all transactions:', txn.reduce((total, tx) => total + tx.instructions.length, 0));
|
|
1177
|
-
console.log('Step 4: Filtering Meteora instructions...');
|
|
1178
1117
|
// Filter out non-meteora instructions
|
|
1179
1118
|
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1180
|
-
console.log('Filtered Meteora instructions count:', ixs.length);
|
|
1181
1119
|
const farm = addresses_1.USDC_FARM;
|
|
1182
1120
|
const authority = params.userWallet;
|
|
1183
1121
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1248,12 +1186,10 @@ class Transactions {
|
|
|
1248
1186
|
ix: limitCloseAutomationIx,
|
|
1249
1187
|
});
|
|
1250
1188
|
}
|
|
1251
|
-
console.log('Step 7: Creating transaction metadata...');
|
|
1252
1189
|
const mainInstructions = [
|
|
1253
1190
|
// Limit Close Automation Instruction (Hawksight CPI)
|
|
1254
1191
|
ix,
|
|
1255
1192
|
];
|
|
1256
|
-
console.log('=== LIMIT CLOSE AUTOMATION IX SUCCESS ===');
|
|
1257
1193
|
return (0, functions_1.createTransactionMeta)({
|
|
1258
1194
|
payer: params.userWallet,
|
|
1259
1195
|
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
@@ -1274,101 +1210,113 @@ class Transactions {
|
|
|
1274
1210
|
}
|
|
1275
1211
|
limitCloseAutomationIx2(_a) {
|
|
1276
1212
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1213
|
+
return errors_1.UniversalErrorHandler.catchErrorsAsync(`limitCloseAutomationIx2`, () => __awaiter(this, void 0, void 0, function* () {
|
|
1214
|
+
const program = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield meteora_1.MeteoraDLMM.program(connection); }));
|
|
1215
|
+
const position = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield program.account.positionV2.fetch(params.position); }));
|
|
1216
|
+
const dlmmPool = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () { return yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix); }));
|
|
1217
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
1218
|
+
// Claim fees and/or rewards, remove liquidity, and possibly close position from Meteora API (if set)
|
|
1219
|
+
const txn = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
1220
|
+
return yield dlmmPool.dlmm.removeLiquidity({
|
|
1221
|
+
user: userPda,
|
|
1222
|
+
position: params.position,
|
|
1223
|
+
fromBinId: position.lowerBinId,
|
|
1224
|
+
toBinId: position.upperBinId,
|
|
1225
|
+
bps: new bn_js_1.default(10000),
|
|
1226
|
+
shouldClaimAndClose: true,
|
|
1227
|
+
});
|
|
1228
|
+
}));
|
|
1229
|
+
// Filter out non-meteora instructions
|
|
1230
|
+
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1231
|
+
const farm = addresses_1.USDC_FARM;
|
|
1232
|
+
const authority = params.userWallet;
|
|
1233
|
+
const iyfProgram = addresses_1.IYF_MAIN;
|
|
1234
|
+
const hawksightAuthority = addresses_1.HS_AUTHORITY;
|
|
1235
|
+
const { params: _params, data } = this.removeLiquidityByRange2Info(ixs);
|
|
1236
|
+
let { position: _position, lbPair, binArrayBitmapExtension, reserveX, reserveY, tokenXMint, tokenYMint, sender, tokenXProgram, tokenYProgram, memoProgram, eventAuthority, program: meteoraDlmmProgram, binArrays, } = _params;
|
|
1237
|
+
let ix;
|
|
1238
|
+
if (params.isLimitOrder) {
|
|
1239
|
+
const limitTokenX = (0, functions_1.generateLimitToken)(userPda, tokenXMint.pubkey);
|
|
1240
|
+
const limitTokenY = (0, functions_1.generateLimitToken)(userPda, tokenYMint.pubkey);
|
|
1241
|
+
const authorityTokenX = (0, functions_1.generateAta)(hawksightAuthority, tokenXMint.pubkey);
|
|
1242
|
+
const authorityTokenY = (0, functions_1.generateAta)(hawksightAuthority, tokenYMint.pubkey);
|
|
1243
|
+
// Use MeteoraDlmmIxGenerator for limitOrderCloseV2
|
|
1244
|
+
const limitCloseAutomationIx = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
1245
|
+
return yield this.ix.meteoraDlmm.limitOrderCloseV2({
|
|
1246
|
+
connection,
|
|
1247
|
+
userWallet: params.userWallet,
|
|
1248
|
+
position: _position.pubkey,
|
|
1249
|
+
lbPair: lbPair.pubkey,
|
|
1250
|
+
tokenXMint: tokenXMint.pubkey,
|
|
1251
|
+
tokenYMint: tokenYMint.pubkey,
|
|
1252
|
+
reserveX: reserveX.pubkey,
|
|
1253
|
+
reserveY: reserveY.pubkey,
|
|
1254
|
+
tokenXProgram: tokenXProgram.pubkey,
|
|
1255
|
+
tokenYProgram: tokenYProgram.pubkey,
|
|
1256
|
+
useFuelAccount: false,
|
|
1257
|
+
param: data,
|
|
1258
|
+
minBinId: params.minBinId,
|
|
1259
|
+
maxBinId: params.maxBinId,
|
|
1260
|
+
binArrays: binArrays,
|
|
1261
|
+
});
|
|
1262
|
+
}));
|
|
1263
|
+
// Instruction via main hawksight contract
|
|
1264
|
+
// @ts-ignore
|
|
1265
|
+
ix = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
1266
|
+
return yield anchor_1.Anchor.instance()
|
|
1267
|
+
.iyfMain.methods.iyfExtensionExecuteV2(limitCloseAutomationIx.data)
|
|
1268
|
+
.accounts({
|
|
1269
|
+
userPda,
|
|
1270
|
+
authority,
|
|
1271
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1272
|
+
})
|
|
1273
|
+
.remainingAccounts([...limitCloseAutomationIx.keys.slice(2)])
|
|
1274
|
+
.instruction();
|
|
1275
|
+
}));
|
|
1276
|
+
}
|
|
1277
|
+
else {
|
|
1278
|
+
// @ts-ignore
|
|
1279
|
+
const limitCloseAutomationIx = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
1280
|
+
return yield this.ix.meteoraDlmm.meteoraDlmmLimitCloseAutomationV2({
|
|
1281
|
+
connection,
|
|
1282
|
+
userWallet: params.userWallet,
|
|
1283
|
+
position: _position.pubkey,
|
|
1284
|
+
lbPair: lbPair.pubkey,
|
|
1285
|
+
tokenXMint: tokenXMint.pubkey,
|
|
1286
|
+
tokenYMint: tokenYMint.pubkey,
|
|
1287
|
+
reserveX: reserveX.pubkey,
|
|
1288
|
+
reserveY: reserveY.pubkey,
|
|
1289
|
+
tokenXProgram: tokenXProgram.pubkey,
|
|
1290
|
+
tokenYProgram: tokenYProgram.pubkey,
|
|
1291
|
+
pdaTokenType: params.pdaTokenType,
|
|
1292
|
+
useFuelAccount: false,
|
|
1293
|
+
param: data,
|
|
1294
|
+
minBinId: params.minBinId,
|
|
1295
|
+
maxBinId: params.maxBinId,
|
|
1296
|
+
isHawkRefund: params.isHawkRefund,
|
|
1297
|
+
binArrays: binArrays,
|
|
1298
|
+
});
|
|
1299
|
+
}));
|
|
1300
|
+
// Instruction via main hawksight contract using iyfExtensionExecuteV2
|
|
1301
|
+
ix = yield errors_1.AppError.handleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
1302
|
+
return yield this.ix.iyfMain.iyfExtensionExecuteV2(connection, {
|
|
1303
|
+
userPda,
|
|
1304
|
+
authority: hawksightAuthority,
|
|
1305
|
+
ix: limitCloseAutomationIx,
|
|
1306
|
+
});
|
|
1307
|
+
}));
|
|
1308
|
+
}
|
|
1309
|
+
const mainInstructions = [
|
|
1310
|
+
// Limit Close Automation Instruction (Hawksight CPI)
|
|
1311
|
+
ix,
|
|
1312
|
+
];
|
|
1313
|
+
return (0, functions_1.createTransactionMeta)({
|
|
1314
|
+
payer: params.userWallet,
|
|
1315
|
+
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
1316
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1317
|
+
mainInstructions,
|
|
1360
1318
|
});
|
|
1361
|
-
}
|
|
1362
|
-
const mainInstructions = [
|
|
1363
|
-
// Limit Close Automation Instruction (Hawksight CPI)
|
|
1364
|
-
ix,
|
|
1365
|
-
];
|
|
1366
|
-
return (0, functions_1.createTransactionMeta)({
|
|
1367
|
-
payer: params.userWallet,
|
|
1368
|
-
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
1369
|
-
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1370
|
-
mainInstructions,
|
|
1371
|
-
});
|
|
1319
|
+
}));
|
|
1372
1320
|
});
|
|
1373
1321
|
}
|
|
1374
1322
|
removeLiquidityByRangeInfo(ixs) {
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export declare class AppError extends Error {
|
|
2
|
+
readonly isErrorHandled: boolean;
|
|
3
|
+
readonly stackTrace: string[];
|
|
4
|
+
readonly errorMsg: string;
|
|
5
|
+
constructor(message: string, _module: string, stackTrace?: string);
|
|
6
|
+
static handleErrorAsync<T>(fn: () => Promise<T>): Promise<T>;
|
|
7
|
+
static handleErrorSync<T>(fn: () => T): T;
|
|
8
|
+
}
|
|
9
|
+
export declare class UniversalErrorHandler {
|
|
10
|
+
static catchErrorsAsync<T>(moduleName: string, fn: () => Promise<T>): Promise<T>;
|
|
11
|
+
static catchErrorsSync<T>(moduleName: string, fn: () => T): T;
|
|
2
12
|
}
|
|
3
13
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/src/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAS,SAAQ,KAAK;IAEjC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAQ;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;WAgCpD,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IASlE,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;CAQ1C;AAGD,qBAAa,qBAAqB;WACnB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAatF,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;CAY9D"}
|
package/dist/src/errors.js
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppError = void 0;
|
|
12
|
+
exports.UniversalErrorHandler = exports.AppError = void 0;
|
|
13
|
+
const os_1 = require("os");
|
|
4
14
|
class AppError extends Error {
|
|
15
|
+
constructor(message, _module, stackTrace) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
super(message);
|
|
18
|
+
this.isErrorHandled = true;
|
|
19
|
+
this.name = _module;
|
|
20
|
+
if (stackTrace) {
|
|
21
|
+
this.stack = stackTrace;
|
|
22
|
+
}
|
|
23
|
+
// Record a stacktrace with fallback in case stackTrace is undefined.
|
|
24
|
+
const _stackTrace = new Error().stack;
|
|
25
|
+
this.stackTrace = ((_a = this.stack) !== null && _a !== void 0 ? _a : _stackTrace).split(os_1.EOL);
|
|
26
|
+
// Store message to another variable (for serialization purposes by global error handler handled by node / typescript)
|
|
27
|
+
this.errorMsg = message;
|
|
28
|
+
console.error(``);
|
|
29
|
+
console.error(``);
|
|
30
|
+
console.error(`Error in module: ${_module}`);
|
|
31
|
+
console.error(`----------------------------------------------------------------------------`);
|
|
32
|
+
console.error(`Error message:`);
|
|
33
|
+
this.message.split(os_1.EOL).forEach(line => {
|
|
34
|
+
console.error(` ${line}`);
|
|
35
|
+
});
|
|
36
|
+
console.error(`Stack trace:`);
|
|
37
|
+
((_b = this.stack) !== null && _b !== void 0 ? _b : '').split(os_1.EOL).forEach(line => {
|
|
38
|
+
console.error(` ${line}`);
|
|
39
|
+
});
|
|
40
|
+
console.error(`----------------------------------------------------------------------------`);
|
|
41
|
+
console.error(``);
|
|
42
|
+
console.error(``);
|
|
43
|
+
}
|
|
44
|
+
static handleErrorAsync(fn) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const stackTrace = new Error().stack;
|
|
47
|
+
try {
|
|
48
|
+
return yield fn();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new AppError(`${error}`, fn.name, stackTrace);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static handleErrorSync(fn) {
|
|
56
|
+
const stackTrace = new Error().stack;
|
|
57
|
+
try {
|
|
58
|
+
return fn();
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new AppError(`${error}`, fn.name, stackTrace);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
5
64
|
}
|
|
6
65
|
exports.AppError = AppError;
|
|
66
|
+
class UniversalErrorHandler {
|
|
67
|
+
static catchErrorsAsync(moduleName, fn) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
try {
|
|
70
|
+
return yield fn();
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
if (e instanceof AppError && e.isErrorHandled) {
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
console.error('Unhandled exception detected. Please analyze the error and kindly handle the error.');
|
|
77
|
+
console.error('Use AppError.handleErrorAsync() or AppError.handleErrorSync() to handle the error so that we would not see this error again.');
|
|
78
|
+
throw new AppError(`Unhandled exception: ${e}`, moduleName);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static catchErrorsSync(moduleName, fn) {
|
|
83
|
+
try {
|
|
84
|
+
return fn();
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (e instanceof AppError && e.isErrorHandled) {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
console.error('Unhandled exception detected. Please analyze the error and kindly handle the error.');
|
|
91
|
+
console.error('Use AppError.handleErrorAsync() or AppError.handleErrorSync() to handle the error so that we would not see this error again.');
|
|
92
|
+
throw new AppError(`Unhandled exception: ${e}`, moduleName);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.UniversalErrorHandler = UniversalErrorHandler;
|
package/dist/src/functions.js
CHANGED
|
@@ -388,10 +388,10 @@ function sighashMatch(data, compareTo, prefix, noSnakeCase, skipDataLengthCheck)
|
|
|
388
388
|
if (skipDataLengthCheck) {
|
|
389
389
|
return false;
|
|
390
390
|
}
|
|
391
|
-
throw new errors_1.AppError(`Data is not an anchor instruction`);
|
|
391
|
+
throw new errors_1.AppError(`Data is not an anchor instruction`, `sighashMatch`);
|
|
392
392
|
}
|
|
393
393
|
if (compareTo.length < 8) {
|
|
394
|
-
throw new errors_1.AppError(`compareTo is not a valid sighash`);
|
|
394
|
+
throw new errors_1.AppError(`compareTo is not a valid sighash`, `sighashMatch`);
|
|
395
395
|
}
|
|
396
396
|
for (let i = 0; i < 8; i++) {
|
|
397
397
|
if (data[i] !== compareTo[i]) {
|
|
@@ -1222,7 +1222,7 @@ function getMeteoraStrategyType(strategyType, totalXAmount, totalYAmount) {
|
|
|
1222
1222
|
singleSidedX = false;
|
|
1223
1223
|
}
|
|
1224
1224
|
else {
|
|
1225
|
-
throw new errors_1.AppError("Total X or Y amount must be greater than 0 when adding liquidity one-sided");
|
|
1225
|
+
throw new errors_1.AppError("Total X or Y amount must be greater than 0 when adding liquidity one-sided", `getMeteoraStrategyType`);
|
|
1226
1226
|
}
|
|
1227
1227
|
}
|
|
1228
1228
|
return [_strategyType, singleSidedX];
|
package/dist/src/hsToMeteora.js
CHANGED
|
@@ -2351,10 +2351,7 @@ class ClosePositionIfEmptyAutomation extends HawksightMeteoraAutomationCpi {
|
|
|
2351
2351
|
const closePositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
2352
2352
|
.meteoraDlmmClosePositionAutomationV2()
|
|
2353
2353
|
.accounts({
|
|
2354
|
-
farm,
|
|
2355
2354
|
userPda,
|
|
2356
|
-
authority,
|
|
2357
|
-
iyfProgram,
|
|
2358
2355
|
hawksightAuthority,
|
|
2359
2356
|
position: this.ix.keys[0].pubkey,
|
|
2360
2357
|
lbPair: lbPair,
|
|
@@ -2364,17 +2361,12 @@ class ClosePositionIfEmptyAutomation extends HawksightMeteoraAutomationCpi {
|
|
|
2364
2361
|
}).instruction();
|
|
2365
2362
|
// Instruction via main hawksight contract
|
|
2366
2363
|
// @ts-ignore
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2369
|
-
.accounts({
|
|
2370
|
-
farm,
|
|
2364
|
+
const ixGen = new SimpleIxGenerator_1.SimpleIxGenerator();
|
|
2365
|
+
const ix = yield ixGen.iyfMain.iyfExtensionExecuteV2(anchor_1.Anchor.instance().connection, {
|
|
2371
2366
|
userPda,
|
|
2372
|
-
authority,
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
})
|
|
2376
|
-
.remainingAccounts(closePositionIx.keys.slice(4))
|
|
2377
|
-
.instruction();
|
|
2367
|
+
authority: hawksightAuthority,
|
|
2368
|
+
ix: closePositionIx
|
|
2369
|
+
});
|
|
2378
2370
|
// Override the instruction
|
|
2379
2371
|
this._ix = ix;
|
|
2380
2372
|
});
|