@symmetry-hq/temp-v3-sdk 0.0.31 → 0.0.33
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/index.d.ts +28 -21
- package/dist/src/index.js +142 -48
- package/dist/src/instructions/automation/flashSwap.d.ts +21 -0
- package/dist/src/instructions/automation/flashSwap.js +74 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +1 -0
- package/dist/src/instructions/automation/priceUpdate.js +3 -0
- package/dist/src/instructions/user/deposit.d.ts +1 -0
- package/dist/src/instructions/user/deposit.js +2 -0
- package/dist/src/txUtils.js +6 -5
- package/dist/test.js +88 -13
- package/package.json +1 -1
- package/src/index.ts +170 -73
- package/src/instructions/automation/flashSwap.ts +104 -0
- package/src/instructions/automation/priceUpdate.ts +3 -0
- package/src/instructions/user/deposit.ts +2 -0
- package/src/txUtils.ts +5 -5
- package/test.ts +93 -13
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Connection, PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
3
2
|
import { Basket } from './layouts/basket';
|
|
4
3
|
import { FormattedGlobalConfig, GlobalConfig } from './layouts/config';
|
|
5
4
|
import { OracleInput, EditAddTokenSettings, EditAutomationSettings, EditCreatorSettings, EditCustomRebalanceSettings, EditDepositsSettings, EditFeeSettings, EditForceRebalanceSettings, EditLpSettings, EditMakeDirectSwapSettings, EditManagerSettings, EditMetadataSettings, EditScheduleSettings, EditUpdateWeightsSettings, Intent, MakeDirectSwapInput, Settings, TaskContext, TaskType, UpdateWeightsInput, FormattedIntentStatus, FormattedTaskType, FormattedIntent, FormattedBounty, FormattedBountySchedule, AddOrEditTokenInput } from './layouts/intents/intent';
|
|
@@ -80,11 +79,12 @@ export declare class SymmetryCore {
|
|
|
80
79
|
editSwapDelayTx(context: TaskContext, settings: EditMakeDirectSwapSettings): Promise<TxPayloadBatchSequence>;
|
|
81
80
|
addOrEditTokenTx(context: TaskContext, settings: AddOrEditTokenInput): Promise<TxPayloadBatchSequence>;
|
|
82
81
|
updateWeightsTx(context: TaskContext, settings: UpdateWeightsInput): Promise<TxPayloadBatchSequence>;
|
|
83
|
-
makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput): Promise<TxPayloadBatchSequence>;
|
|
82
|
+
makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput, jup_swap_ix?: TransactionInstruction): Promise<TxPayloadBatchSequence>;
|
|
84
83
|
openBasketIntentTx(params: {
|
|
85
84
|
context: TaskContext;
|
|
86
85
|
type: TaskType;
|
|
87
86
|
settings: Settings;
|
|
87
|
+
jup_swap_ix?: TransactionInstruction;
|
|
88
88
|
}): Promise<TxPayloadBatchSequence>;
|
|
89
89
|
executeBasketIntentTx(params: {
|
|
90
90
|
intent: string;
|
|
@@ -118,32 +118,39 @@ export declare class SymmetryCore {
|
|
|
118
118
|
min_bounty_amount?: number;
|
|
119
119
|
max_bounty_amount?: number;
|
|
120
120
|
}): Promise<TxPayloadBatchSequence>;
|
|
121
|
+
startPriceUpdatesTx(params: {
|
|
122
|
+
keeper: string;
|
|
123
|
+
basket: string;
|
|
124
|
+
rebalance_intent: string;
|
|
125
|
+
}): Promise<TxPayloadBatchSequence>;
|
|
121
126
|
updateTokenPricesTx(params: {
|
|
122
|
-
keeper:
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
keeper: string;
|
|
128
|
+
basket: string;
|
|
129
|
+
rebalance_intent: string;
|
|
125
130
|
}): Promise<TxPayloadBatchSequence>;
|
|
126
|
-
|
|
127
|
-
keeper:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
flashSwapTx(params: {
|
|
132
|
+
keeper: string;
|
|
133
|
+
basket: string;
|
|
134
|
+
rebalance_intent?: string;
|
|
135
|
+
intent?: string;
|
|
136
|
+
mint_in: string;
|
|
137
|
+
mint_out: string;
|
|
138
|
+
amount_in: number;
|
|
139
|
+
amount_out: number;
|
|
140
|
+
mode?: number;
|
|
141
|
+
jup_swap_ix?: TransactionInstruction;
|
|
134
142
|
}): Promise<TxPayloadBatchSequence>;
|
|
135
143
|
mintTx(params: {
|
|
136
|
-
keeper:
|
|
137
|
-
|
|
138
|
-
basket: PublicKey;
|
|
144
|
+
keeper: string;
|
|
145
|
+
rebalance_intent: string;
|
|
139
146
|
}): Promise<TxPayloadBatchSequence>;
|
|
140
147
|
redeemTokensTx(params: {
|
|
141
|
-
keeper:
|
|
142
|
-
|
|
148
|
+
keeper: string;
|
|
149
|
+
rebalance_intent: string;
|
|
143
150
|
}): Promise<TxPayloadBatchSequence>;
|
|
144
151
|
claimBountyTx(params: {
|
|
145
|
-
keeper:
|
|
146
|
-
|
|
152
|
+
keeper: string;
|
|
153
|
+
rebalance_intent: string;
|
|
147
154
|
}): Promise<TxPayloadBatchSequence>;
|
|
148
155
|
signAndSendVersionedTxs(params: {
|
|
149
156
|
versionedTxs: VersionedTxs;
|
package/dist/src/index.js
CHANGED
|
@@ -20,7 +20,6 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
20
20
|
const claimBounty_1 = require("./instructions/automation/claimBounty");
|
|
21
21
|
const priceUpdate_1 = require("./instructions/automation/priceUpdate");
|
|
22
22
|
const rebalanceIntent_1 = require("./instructions/automation/rebalanceIntent");
|
|
23
|
-
const rebalanceSwap_1 = require("./instructions/automation/rebalanceSwap");
|
|
24
23
|
const admin_1 = require("./instructions/management/admin");
|
|
25
24
|
const createBasket_1 = require("./instructions/management/createBasket");
|
|
26
25
|
const edit_1 = require("./instructions/management/edit");
|
|
@@ -37,6 +36,7 @@ const intent_2 = require("./states/intents/intent");
|
|
|
37
36
|
const rebalanceIntent_3 = require("./states/intents/rebalanceIntent");
|
|
38
37
|
const txUtils_1 = require("./txUtils");
|
|
39
38
|
const config_1 = require("./states/config");
|
|
39
|
+
const flashSwap_1 = require("./instructions/automation/flashSwap");
|
|
40
40
|
exports.COMPUTE_UNITS = 1000000;
|
|
41
41
|
exports.PRIORITY_FEE = 100000;
|
|
42
42
|
exports.JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
|
|
@@ -342,9 +342,9 @@ class SymmetryCore {
|
|
|
342
342
|
return this.openBasketIntentTx({ type: intent_1.TaskType.UpdateWeights, context, settings });
|
|
343
343
|
});
|
|
344
344
|
}
|
|
345
|
-
makeDirectSwapTx(context, settings) {
|
|
345
|
+
makeDirectSwapTx(context, settings, jup_swap_ix) {
|
|
346
346
|
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
-
return this.openBasketIntentTx({ type: intent_1.TaskType.MakeDirectSwap, context, settings });
|
|
347
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.MakeDirectSwap, context, settings, jup_swap_ix: jup_swap_ix });
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
350
|
openBasketIntentTx(params) {
|
|
@@ -394,7 +394,15 @@ class SymmetryCore {
|
|
|
394
394
|
editType: editType,
|
|
395
395
|
editData: editData,
|
|
396
396
|
});
|
|
397
|
-
|
|
397
|
+
let txBatchData = { batches: [[{
|
|
398
|
+
payer: manager,
|
|
399
|
+
instructions: [
|
|
400
|
+
openBasketIntentIx,
|
|
401
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
402
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
403
|
+
],
|
|
404
|
+
lookupTables: [],
|
|
405
|
+
}]] };
|
|
398
406
|
// Only execute in the same transaction when there is no delay and no scheduled activation.
|
|
399
407
|
if (modificationDelay.eq(new anchor_1.BN(0)) && activationTimestamp.eq(new anchor_1.BN(0))) {
|
|
400
408
|
let executeBasketIntentIx = (0, edit_1.executeEditBasketIntentIx)({
|
|
@@ -406,17 +414,52 @@ class SymmetryCore {
|
|
|
406
414
|
keeper: manager,
|
|
407
415
|
basketMint: basket.mint,
|
|
408
416
|
});
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
417
|
+
if (editType == intent_1.TaskType.MakeDirectSwap && params.jup_swap_ix) {
|
|
418
|
+
let flashParams = {
|
|
419
|
+
keeper: manager,
|
|
420
|
+
basket: basket.ownAddress,
|
|
421
|
+
rebalanceIntent: undefined,
|
|
422
|
+
intent: intent,
|
|
423
|
+
mintIn: new web3_js_1.PublicKey(editData.make_direct_swap.from_token_mint),
|
|
424
|
+
mintOut: new web3_js_1.PublicKey(editData.make_direct_swap.to_token_mint),
|
|
425
|
+
amountIn: new anchor_1.BN(editData.make_direct_swap.amount_from),
|
|
426
|
+
amountOut: new anchor_1.BN(editData.make_direct_swap.amount_to),
|
|
427
|
+
mode: undefined,
|
|
428
|
+
};
|
|
429
|
+
let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
|
|
430
|
+
let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
|
|
431
|
+
txBatchData.batches.push([{
|
|
412
432
|
payer: manager,
|
|
413
433
|
instructions: [
|
|
414
|
-
|
|
434
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintIn), manager, flashParams.mintIn),
|
|
435
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintOut), manager, flashParams.mintOut),
|
|
436
|
+
ixWithdraw,
|
|
437
|
+
params.jup_swap_ix,
|
|
438
|
+
ixDeposit,
|
|
415
439
|
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
416
440
|
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
417
441
|
],
|
|
418
442
|
lookupTables: [],
|
|
419
|
-
}]
|
|
443
|
+
}]);
|
|
444
|
+
txBatchData.batches.push([{
|
|
445
|
+
payer: manager,
|
|
446
|
+
instructions: [
|
|
447
|
+
executeBasketIntentIx,
|
|
448
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
449
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
450
|
+
],
|
|
451
|
+
lookupTables: [],
|
|
452
|
+
}]);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
txBatchData.batches[0][0].instructions = [
|
|
456
|
+
openBasketIntentIx,
|
|
457
|
+
executeBasketIntentIx,
|
|
458
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
459
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
460
|
+
];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
420
463
|
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
421
464
|
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
422
465
|
return txPayloadBatchSequence;
|
|
@@ -482,9 +525,8 @@ class SymmetryCore {
|
|
|
482
525
|
}
|
|
483
526
|
buyBasketTx(params) {
|
|
484
527
|
return __awaiter(this, void 0, void 0, function* () {
|
|
485
|
-
var _a, _b, _c, _d, _e, _f
|
|
528
|
+
var _a, _b, _c, _d, _e, _f;
|
|
486
529
|
let buyer = new web3_js_1.PublicKey(params.buyer);
|
|
487
|
-
let basketMint = new web3_js_1.PublicKey(params.basket_mint);
|
|
488
530
|
let contributions = params.contributions.map(contribution => ({
|
|
489
531
|
mint: new web3_js_1.PublicKey(contribution.mint),
|
|
490
532
|
amount: new anchor_1.BN(contribution.amount),
|
|
@@ -494,16 +536,15 @@ class SymmetryCore {
|
|
|
494
536
|
let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
|
|
495
537
|
let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
|
|
496
538
|
let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
497
|
-
const basket = (0, pda_1.getBasketState)(
|
|
498
|
-
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
|
|
539
|
+
const basket = yield this.fetchBasket((0, pda_1.getBasketState)(new web3_js_1.PublicKey(params.basket_mint)).toBase58());
|
|
540
|
+
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, buyer);
|
|
499
541
|
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
500
|
-
let
|
|
542
|
+
let renPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
|
|
501
543
|
let rebalanceIntentRentPayer = buyer;
|
|
502
544
|
// TODO: check actual lamports required for rent
|
|
503
|
-
if ((
|
|
545
|
+
if ((_f = renPayerAi === null || renPayerAi === void 0 ? void 0 : renPayerAi.lamports) !== null && _f !== void 0 ? _f : 0 > 0)
|
|
504
546
|
rebalanceIntentRentPayer = rentPayer;
|
|
505
|
-
let
|
|
506
|
-
let bountyMint = basketState.settings.bountyMint;
|
|
547
|
+
let bountyMint = basket.settings.bountyMint;
|
|
507
548
|
let txBatchData = { batches: [
|
|
508
549
|
[{
|
|
509
550
|
payer: buyer,
|
|
@@ -511,14 +552,14 @@ class SymmetryCore {
|
|
|
511
552
|
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
512
553
|
signer: buyer,
|
|
513
554
|
owner: buyer,
|
|
514
|
-
basket: basket,
|
|
555
|
+
basket: basket.ownAddress,
|
|
515
556
|
}),
|
|
516
557
|
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
517
558
|
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
518
559
|
signer: buyer,
|
|
519
560
|
owner: buyer,
|
|
520
|
-
basket,
|
|
521
|
-
basketTokenMint:
|
|
561
|
+
basket: basket.ownAddress,
|
|
562
|
+
basketTokenMint: basket.mint,
|
|
522
563
|
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
523
564
|
bountyMint: bountyMint,
|
|
524
565
|
rebalanceType: rebalanceIntent_2.RebalanceType.Deposit,
|
|
@@ -536,7 +577,7 @@ class SymmetryCore {
|
|
|
536
577
|
}],
|
|
537
578
|
(0, deposit_1.depositTokensIx)({
|
|
538
579
|
owner: buyer,
|
|
539
|
-
basket: basket,
|
|
580
|
+
basket: basket.ownAddress,
|
|
540
581
|
contributions: contributions,
|
|
541
582
|
}).map(ix => {
|
|
542
583
|
return {
|
|
@@ -554,11 +595,11 @@ class SymmetryCore {
|
|
|
554
595
|
instructions: [
|
|
555
596
|
(0, deposit_1.lockDepositsIx)({
|
|
556
597
|
owner: buyer,
|
|
557
|
-
basket: basket,
|
|
598
|
+
basket: basket.ownAddress,
|
|
558
599
|
}),
|
|
559
|
-
executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
|
|
600
|
+
executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
|
|
560
601
|
keeper: buyer,
|
|
561
|
-
basket: basket,
|
|
602
|
+
basket: basket.ownAddress,
|
|
562
603
|
rebalanceIntent: rebalanceIntent,
|
|
563
604
|
}) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
564
605
|
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
@@ -660,7 +701,7 @@ class SymmetryCore {
|
|
|
660
701
|
[{
|
|
661
702
|
payer: seller,
|
|
662
703
|
instructions: [
|
|
663
|
-
executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
|
|
704
|
+
executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
|
|
664
705
|
keeper: seller,
|
|
665
706
|
basket: basket,
|
|
666
707
|
rebalanceIntent: rebalanceIntent,
|
|
@@ -676,9 +717,35 @@ class SymmetryCore {
|
|
|
676
717
|
return txPayloadBatchSequence;
|
|
677
718
|
});
|
|
678
719
|
}
|
|
720
|
+
startPriceUpdatesTx(params) {
|
|
721
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
722
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
723
|
+
let basket = new web3_js_1.PublicKey(params.basket);
|
|
724
|
+
let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
|
|
725
|
+
let txBatchData = { batches: [[{
|
|
726
|
+
payer: keeper,
|
|
727
|
+
instructions: [
|
|
728
|
+
(0, priceUpdate_1.startPriceUpdatesIx)({
|
|
729
|
+
keeper: keeper,
|
|
730
|
+
basket: basket,
|
|
731
|
+
rebalanceIntent: rebalanceIntent,
|
|
732
|
+
}),
|
|
733
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
734
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
735
|
+
],
|
|
736
|
+
lookupTables: [],
|
|
737
|
+
}]] };
|
|
738
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
739
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
740
|
+
return txPayloadBatchSequence;
|
|
741
|
+
});
|
|
742
|
+
}
|
|
679
743
|
updateTokenPricesTx(params) {
|
|
680
744
|
return __awaiter(this, void 0, void 0, function* () {
|
|
681
|
-
let
|
|
745
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
746
|
+
let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
|
|
747
|
+
let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(new web3_js_1.PublicKey(params.basket), new web3_js_1.PublicKey(params.basket));
|
|
748
|
+
let basket = yield this.fetchBasket(params.basket);
|
|
682
749
|
let ixs = [];
|
|
683
750
|
let batchSize = 7;
|
|
684
751
|
for (let batchStart = 0; batchStart < basket.numTokens; batchStart += batchSize) {
|
|
@@ -702,14 +769,16 @@ class SymmetryCore {
|
|
|
702
769
|
}
|
|
703
770
|
while (tokenIndices.length < 20)
|
|
704
771
|
tokenIndices.push(0);
|
|
772
|
+
// TODO: in last instruction we should include performance fee accounts
|
|
705
773
|
ixs.push((0, priceUpdate_1.updateTokenPricesIx)({
|
|
706
774
|
keeper: keeper,
|
|
707
|
-
basket:
|
|
708
|
-
rebalanceIntent: rebalanceIntent
|
|
775
|
+
basket: basket.ownAddress,
|
|
776
|
+
rebalanceIntent: rebalanceIntent,
|
|
709
777
|
lookupTable0: basket.lookupTables.active[0],
|
|
710
778
|
lookupTable1: basket.lookupTables.active[1],
|
|
711
779
|
tokenIndices: tokenIndices,
|
|
712
780
|
additionalOracleAccounts: allKeys,
|
|
781
|
+
basketRebalanceIntent: basket.settings.activeRebalance.eq(new anchor_1.BN(0)) ? undefined : basketRebalanceIntent,
|
|
713
782
|
}));
|
|
714
783
|
}
|
|
715
784
|
let txBatchData = { batches: [ixs.map(ix => ({
|
|
@@ -726,25 +795,46 @@ class SymmetryCore {
|
|
|
726
795
|
return txPayloadBatchSequence;
|
|
727
796
|
});
|
|
728
797
|
}
|
|
729
|
-
|
|
798
|
+
flashSwapTx(params) {
|
|
730
799
|
return __awaiter(this, void 0, void 0, function* () {
|
|
731
|
-
let
|
|
732
|
-
let
|
|
800
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
801
|
+
let basket = new web3_js_1.PublicKey(params.basket);
|
|
802
|
+
let rebalanceIntent = params.rebalance_intent ? new web3_js_1.PublicKey(params.rebalance_intent) : undefined;
|
|
803
|
+
let intent = params.intent ? new web3_js_1.PublicKey(params.intent) : undefined;
|
|
804
|
+
let mintIn = new web3_js_1.PublicKey(params.mint_in);
|
|
805
|
+
let mintOut = new web3_js_1.PublicKey(params.mint_out);
|
|
806
|
+
let amountIn = new anchor_1.BN(params.amount_in);
|
|
807
|
+
let amountOut = new anchor_1.BN(params.amount_out);
|
|
808
|
+
let mode = params.mode ? params.mode : 0;
|
|
809
|
+
let flashParams = {
|
|
733
810
|
keeper: keeper,
|
|
734
|
-
basket:
|
|
735
|
-
|
|
736
|
-
|
|
811
|
+
basket: basket,
|
|
812
|
+
rebalanceIntent: rebalanceIntent,
|
|
813
|
+
intent: intent,
|
|
814
|
+
mintIn: mintIn,
|
|
815
|
+
mintOut: mintOut,
|
|
737
816
|
amountIn: amountIn,
|
|
738
817
|
amountOut: amountOut,
|
|
739
818
|
mode: mode,
|
|
740
|
-
}
|
|
819
|
+
};
|
|
820
|
+
let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
|
|
821
|
+
let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
|
|
822
|
+
let ixs = [
|
|
823
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
|
|
824
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
|
|
825
|
+
ixWithdraw,
|
|
826
|
+
];
|
|
827
|
+
if (params.jup_swap_ix) {
|
|
828
|
+
ixs.push(params.jup_swap_ix);
|
|
829
|
+
}
|
|
830
|
+
ixs = ixs.concat([
|
|
831
|
+
ixDeposit,
|
|
832
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
833
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
834
|
+
]);
|
|
741
835
|
let txBatchData = { batches: [[{
|
|
742
836
|
payer: keeper,
|
|
743
|
-
instructions:
|
|
744
|
-
ix,
|
|
745
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
746
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
747
|
-
],
|
|
837
|
+
instructions: ixs,
|
|
748
838
|
lookupTables: [],
|
|
749
839
|
}]] };
|
|
750
840
|
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
@@ -754,14 +844,16 @@ class SymmetryCore {
|
|
|
754
844
|
}
|
|
755
845
|
mintTx(params) {
|
|
756
846
|
return __awaiter(this, void 0, void 0, function* () {
|
|
757
|
-
let
|
|
758
|
-
|
|
759
|
-
let
|
|
847
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
848
|
+
let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
|
|
849
|
+
let basket = yield this.fetchBasket(rebalanceIntent.basket.toBase58());
|
|
850
|
+
let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, rebalanceIntent.owner);
|
|
760
851
|
let ix = (0, deposit_1.mintBasketIx)({
|
|
761
852
|
keeper: keeper,
|
|
762
|
-
basket: basket,
|
|
763
|
-
basketTokenMint: mint,
|
|
764
|
-
buyer:
|
|
853
|
+
basket: basket.ownAddress,
|
|
854
|
+
basketTokenMint: basket.mint,
|
|
855
|
+
buyer: rebalanceIntent.owner,
|
|
856
|
+
basketRebalanceIntent: basket.settings.activeRebalance.eq(new anchor_1.BN(0)) ? undefined : basketRebalanceIntent,
|
|
765
857
|
});
|
|
766
858
|
let txBatchData = { batches: [[{
|
|
767
859
|
payer: keeper,
|
|
@@ -779,7 +871,8 @@ class SymmetryCore {
|
|
|
779
871
|
}
|
|
780
872
|
redeemTokensTx(params) {
|
|
781
873
|
return __awaiter(this, void 0, void 0, function* () {
|
|
782
|
-
let
|
|
874
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
875
|
+
let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
|
|
783
876
|
let batchSize = 7;
|
|
784
877
|
let ixs = [];
|
|
785
878
|
for (let batchStart = 0; batchStart < rebalanceIntent.tokens.length; batchStart += batchSize) {
|
|
@@ -812,7 +905,8 @@ class SymmetryCore {
|
|
|
812
905
|
}
|
|
813
906
|
claimBountyTx(params) {
|
|
814
907
|
return __awaiter(this, void 0, void 0, function* () {
|
|
815
|
-
let
|
|
908
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
909
|
+
let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
|
|
816
910
|
let keepersArray = [];
|
|
817
911
|
if (!rebalanceIntent.startPriceUpdateTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
818
912
|
keepersArray.push(rebalanceIntent.startPriceUpdateTask.completedBy);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
+
export declare function flashWithdrawIx(params: {
|
|
4
|
+
keeper: PublicKey;
|
|
5
|
+
basket: PublicKey;
|
|
6
|
+
rebalanceIntent?: PublicKey;
|
|
7
|
+
intent?: PublicKey;
|
|
8
|
+
mintIn: PublicKey;
|
|
9
|
+
mintOut: PublicKey;
|
|
10
|
+
amountIn: BN;
|
|
11
|
+
amountOut: BN;
|
|
12
|
+
mode?: number;
|
|
13
|
+
}): TransactionInstruction;
|
|
14
|
+
export declare function flashDepositIx(params: {
|
|
15
|
+
keeper: PublicKey;
|
|
16
|
+
basket: PublicKey;
|
|
17
|
+
rebalanceIntent?: PublicKey;
|
|
18
|
+
intent?: PublicKey;
|
|
19
|
+
mintIn: PublicKey;
|
|
20
|
+
mintOut: PublicKey;
|
|
21
|
+
}): TransactionInstruction;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flashWithdrawIx = flashWithdrawIx;
|
|
4
|
+
exports.flashDepositIx = flashDepositIx;
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
const pda_1 = require("../pda");
|
|
9
|
+
const FLASH_WITHDRAW_DISCRIMINATOR = Buffer.from([164, 84, 46, 132, 94, 220, 214, 156]);
|
|
10
|
+
const FLASH_DEPOSIT_DISCRIMINATOR = Buffer.from([21, 4, 89, 84, 131, 84, 128, 21]);
|
|
11
|
+
function flashWithdrawIx(params) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { keeper, basket, mintIn, mintOut, amountIn, amountOut, mode } = params;
|
|
14
|
+
let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
|
|
15
|
+
let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
|
|
16
|
+
let basketInATA = (0, pda_1.getAta)(basket, mintIn);
|
|
17
|
+
let basketOutATA = (0, pda_1.getAta)(basket, mintOut);
|
|
18
|
+
const keys = [
|
|
19
|
+
{ pubkey: params.keeper, isWritable: true, isSigner: true },
|
|
20
|
+
{ pubkey: params.basket, isWritable: true, isSigner: false },
|
|
21
|
+
{ pubkey: (_a = params.rebalanceIntent) !== null && _a !== void 0 ? _a : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
|
|
22
|
+
{ pubkey: (_b = params.intent) !== null && _b !== void 0 ? _b : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
|
|
23
|
+
{ pubkey: params.mintIn, isWritable: false, isSigner: false },
|
|
24
|
+
{ pubkey: params.mintOut, isWritable: false, isSigner: false },
|
|
25
|
+
{ pubkey: keeperFromATA, isWritable: true, isSigner: false },
|
|
26
|
+
{ pubkey: keeperToATA, isWritable: true, isSigner: false },
|
|
27
|
+
{ pubkey: basketInATA, isWritable: true, isSigner: false },
|
|
28
|
+
{ pubkey: basketOutATA, isWritable: true, isSigner: false },
|
|
29
|
+
{ pubkey: (0, pda_1.getGlobalConfigPda)(), isWritable: false, isSigner: false },
|
|
30
|
+
{ pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
|
|
31
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
32
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
33
|
+
];
|
|
34
|
+
const discriminator = FLASH_WITHDRAW_DISCRIMINATOR;
|
|
35
|
+
const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
|
|
36
|
+
const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
|
|
37
|
+
const modeBuffer = Buffer.from([mode !== null && mode !== void 0 ? mode : 0]);
|
|
38
|
+
const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
|
|
39
|
+
return new web3_js_1.TransactionInstruction({
|
|
40
|
+
keys,
|
|
41
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
42
|
+
data,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function flashDepositIx(params) {
|
|
46
|
+
const { keeper, basket, mintIn, mintOut } = params;
|
|
47
|
+
let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
|
|
48
|
+
let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
|
|
49
|
+
let basketInATA = (0, pda_1.getAta)(basket, mintIn);
|
|
50
|
+
let basketOutATA = (0, pda_1.getAta)(basket, mintOut);
|
|
51
|
+
const keys = [
|
|
52
|
+
{ pubkey: params.keeper, isWritable: true, isSigner: true },
|
|
53
|
+
{ pubkey: params.basket, isWritable: true, isSigner: false },
|
|
54
|
+
{ pubkey: params.rebalanceIntent ? params.rebalanceIntent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
|
|
55
|
+
{ pubkey: params.intent ? params.intent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
|
|
56
|
+
{ pubkey: params.mintIn, isWritable: false, isSigner: false },
|
|
57
|
+
{ pubkey: params.mintOut, isWritable: false, isSigner: false },
|
|
58
|
+
{ pubkey: keeperFromATA, isWritable: true, isSigner: false },
|
|
59
|
+
{ pubkey: keeperToATA, isWritable: true, isSigner: false },
|
|
60
|
+
{ pubkey: basketInATA, isWritable: true, isSigner: false },
|
|
61
|
+
{ pubkey: basketOutATA, isWritable: true, isSigner: false },
|
|
62
|
+
{ pubkey: (0, pda_1.getGlobalConfigPda)(), isWritable: false, isSigner: false },
|
|
63
|
+
{ pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
|
|
64
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
65
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
66
|
+
];
|
|
67
|
+
const discriminator = FLASH_DEPOSIT_DISCRIMINATOR;
|
|
68
|
+
const data = Buffer.concat([discriminator]);
|
|
69
|
+
return new web3_js_1.TransactionInstruction({
|
|
70
|
+
keys,
|
|
71
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
72
|
+
data,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -16,6 +16,7 @@ function startPriceUpdatesIx(params) {
|
|
|
16
16
|
{ pubkey: params.keeper, isSigner: true, isWritable: true },
|
|
17
17
|
{ pubkey: params.basket, isSigner: false, isWritable: true },
|
|
18
18
|
{ pubkey: params.rebalanceIntent, isSigner: false, isWritable: true },
|
|
19
|
+
{ pubkey: (0, pda_1.getGlobalConfigPda)(), isSigner: false, isWritable: false },
|
|
19
20
|
];
|
|
20
21
|
const data = START_PRICE_UPDATES_DISCRIMINATOR;
|
|
21
22
|
return new web3_js_1.TransactionInstruction({
|
|
@@ -26,6 +27,7 @@ function startPriceUpdatesIx(params) {
|
|
|
26
27
|
}
|
|
27
28
|
;
|
|
28
29
|
function updateTokenPricesIx(params) {
|
|
30
|
+
var _a;
|
|
29
31
|
let globalConfig = (0, pda_1.getGlobalConfigPda)();
|
|
30
32
|
const tokenIndices = params.tokenIndices.slice(0, 20);
|
|
31
33
|
while (tokenIndices.length < 20) {
|
|
@@ -44,6 +46,7 @@ function updateTokenPricesIx(params) {
|
|
|
44
46
|
{ pubkey: constants_1.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT, isSigner: false, isWritable: true },
|
|
45
47
|
{ pubkey: params.lookupTable0, isSigner: false, isWritable: true },
|
|
46
48
|
{ pubkey: params.lookupTable1, isSigner: false, isWritable: true },
|
|
49
|
+
{ pubkey: (_a = params.basketRebalanceIntent) !== null && _a !== void 0 ? _a : constants_1.BASKETS_V3_PROGRAM_ID, isSigner: false, isWritable: params.basketRebalanceIntent ? true : false },
|
|
47
50
|
];
|
|
48
51
|
// remaining accounts
|
|
49
52
|
keys.push(...params.additionalOracleAccounts.map((pubkey) => ({ pubkey, isSigner: false, isWritable: false })));
|
|
@@ -64,6 +64,7 @@ function lockDepositsIx(params) {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
function mintBasketIx(params) {
|
|
67
|
+
var _a;
|
|
67
68
|
const { keeper, basket, basketTokenMint, buyer } = params;
|
|
68
69
|
let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
|
|
69
70
|
let basketFees = (0, pda_1.getBasketFeesPda)(basket);
|
|
@@ -80,6 +81,7 @@ function mintBasketIx(params) {
|
|
|
80
81
|
{ pubkey: globalConfig, isWritable: false, isSigner: false },
|
|
81
82
|
{ pubkey: basketFees, isWritable: true, isSigner: false },
|
|
82
83
|
{ pubkey: basketFeesAta, isWritable: true, isSigner: false },
|
|
84
|
+
{ pubkey: (_a = params.basketRebalanceIntent) !== null && _a !== void 0 ? _a : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.basketRebalanceIntent ? true : false, isSigner: false },
|
|
83
85
|
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
84
86
|
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
85
87
|
{ pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
package/dist/src/txUtils.js
CHANGED
|
@@ -166,14 +166,14 @@ function sendVersionedTransaction(connection, tx, blockhash, lastValidBlockHeigh
|
|
|
166
166
|
blockhash,
|
|
167
167
|
lastValidBlockHeight,
|
|
168
168
|
signature: txId,
|
|
169
|
-
}, "confirmed").then((res) => confirmation = res);
|
|
170
|
-
let iterations =
|
|
169
|
+
}, "confirmed").catch(() => null).then((res) => confirmation = res);
|
|
170
|
+
let iterations = 10;
|
|
171
171
|
while (confirmation === null && result === null && iterations > 0) {
|
|
172
|
-
yield delay(
|
|
172
|
+
yield delay(1000);
|
|
173
173
|
result = yield connection.getTransaction(txId, {
|
|
174
174
|
commitment: "confirmed",
|
|
175
175
|
maxSupportedTransactionVersion: 0,
|
|
176
|
-
});
|
|
176
|
+
}).catch(() => null);
|
|
177
177
|
if (result && result.meta && ((_a = result.meta) === null || _a === void 0 ? void 0 : _a.err)) {
|
|
178
178
|
console.log(result.meta.err);
|
|
179
179
|
throw new Error(txId);
|
|
@@ -262,6 +262,7 @@ function signTxPayloadBatchSequence(wallet, txPayloadBatchSequence) {
|
|
|
262
262
|
}
|
|
263
263
|
function sendTxPayloadBatchSequence(connection_1, txPayloadBatchSequence_1) {
|
|
264
264
|
return __awaiter(this, arguments, void 0, function* (connection, txPayloadBatchSequence, simulateTransactions = false) {
|
|
265
|
+
var _a, _b;
|
|
265
266
|
let txs = [];
|
|
266
267
|
for (const batch of txPayloadBatchSequence.batches) {
|
|
267
268
|
let batchTxs = [];
|
|
@@ -270,7 +271,7 @@ function sendTxPayloadBatchSequence(connection_1, txPayloadBatchSequence_1) {
|
|
|
270
271
|
txs.push(batchTxs);
|
|
271
272
|
}
|
|
272
273
|
return yield sendVersionedTxs(connection, {
|
|
273
|
-
blockhash: txPayloadBatchSequence.batches[0].transactions[0].recent_blockhash,
|
|
274
|
+
blockhash: (_b = (_a = txPayloadBatchSequence.batches[0].transactions[0]) === null || _a === void 0 ? void 0 : _a.recent_blockhash) !== null && _b !== void 0 ? _b : "",
|
|
274
275
|
lastValidBlockHeight: 0,
|
|
275
276
|
batches: txs,
|
|
276
277
|
}, simulateTransactions);
|