@symmetry-hq/temp-v3-sdk 0.0.30 → 0.0.32

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.
@@ -1,5 +1,4 @@
1
- import { BN } from '@coral-xyz/anchor';
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: PublicKey;
123
- rebalanceIntent: RebalanceIntent;
124
- basket: Basket;
127
+ keeper: string;
128
+ basket: string;
129
+ rebalance_intent: string;
125
130
  }): Promise<TxPayloadBatchSequence>;
126
- executeSwap(params: {
127
- keeper: PublicKey;
128
- rebalanceIntent: RebalanceIntent;
129
- mintFrom: PublicKey;
130
- mintTo: PublicKey;
131
- amountIn: BN;
132
- amountOut: BN;
133
- mode: number;
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: PublicKey;
137
- buyer: PublicKey;
138
- basket: PublicKey;
144
+ keeper: string;
145
+ rebalance_intent: string;
139
146
  }): Promise<TxPayloadBatchSequence>;
140
147
  redeemTokensTx(params: {
141
- keeper: PublicKey;
142
- rebalanceIntent: RebalanceIntent;
148
+ keeper: string;
149
+ rebalance_intent: string;
143
150
  }): Promise<TxPayloadBatchSequence>;
144
151
  claimBountyTx(params: {
145
- keeper: PublicKey;
146
- rebalanceIntent: RebalanceIntent;
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
- ixs.push(openBasketIntentIx);
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
- ixs.push(executeBasketIntentIx);
410
- }
411
- let txBatchData = { batches: [[{
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
- ...ixs,
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;
@@ -556,7 +599,7 @@ class SymmetryCore {
556
599
  owner: buyer,
557
600
  basket: basket,
558
601
  }),
559
- executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
602
+ executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
560
603
  keeper: buyer,
561
604
  basket: basket,
562
605
  rebalanceIntent: rebalanceIntent,
@@ -660,7 +703,7 @@ class SymmetryCore {
660
703
  [{
661
704
  payer: seller,
662
705
  instructions: [
663
- executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
706
+ executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
664
707
  keeper: seller,
665
708
  basket: basket,
666
709
  rebalanceIntent: rebalanceIntent,
@@ -676,9 +719,34 @@ class SymmetryCore {
676
719
  return txPayloadBatchSequence;
677
720
  });
678
721
  }
722
+ startPriceUpdatesTx(params) {
723
+ return __awaiter(this, void 0, void 0, function* () {
724
+ let keeper = new web3_js_1.PublicKey(params.keeper);
725
+ let basket = new web3_js_1.PublicKey(params.basket);
726
+ let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
727
+ let txBatchData = { batches: [[{
728
+ payer: keeper,
729
+ instructions: [
730
+ (0, priceUpdate_1.startPriceUpdatesIx)({
731
+ keeper: keeper,
732
+ basket: basket,
733
+ rebalanceIntent: rebalanceIntent,
734
+ }),
735
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
736
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
737
+ ],
738
+ lookupTables: [],
739
+ }]] };
740
+ let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
741
+ let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
742
+ return txPayloadBatchSequence;
743
+ });
744
+ }
679
745
  updateTokenPricesTx(params) {
680
746
  return __awaiter(this, void 0, void 0, function* () {
681
- let { keeper, rebalanceIntent, basket } = params;
747
+ let keeper = new web3_js_1.PublicKey(params.keeper);
748
+ let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
749
+ let basket = yield this.fetchBasket(params.basket);
682
750
  let ixs = [];
683
751
  let batchSize = 7;
684
752
  for (let batchStart = 0; batchStart < basket.numTokens; batchStart += batchSize) {
@@ -704,8 +772,8 @@ class SymmetryCore {
704
772
  tokenIndices.push(0);
705
773
  ixs.push((0, priceUpdate_1.updateTokenPricesIx)({
706
774
  keeper: keeper,
707
- basket: rebalanceIntent.basket, //@ts-ignore
708
- rebalanceIntent: rebalanceIntent.ownAddress,
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,
@@ -726,22 +794,38 @@ class SymmetryCore {
726
794
  return txPayloadBatchSequence;
727
795
  });
728
796
  }
729
- executeSwap(params) {
797
+ flashSwapTx(params) {
730
798
  return __awaiter(this, void 0, void 0, function* () {
731
- let { keeper, rebalanceIntent, mintFrom, mintTo, amountIn, amountOut, mode } = params;
732
- let ix = (0, rebalanceSwap_1.rebalanceSwapIx)({
799
+ let keeper = new web3_js_1.PublicKey(params.keeper);
800
+ let basket = new web3_js_1.PublicKey(params.basket);
801
+ let rebalanceIntent = params.rebalance_intent ? new web3_js_1.PublicKey(params.rebalance_intent) : undefined;
802
+ let intent = params.intent ? new web3_js_1.PublicKey(params.intent) : undefined;
803
+ let mintIn = new web3_js_1.PublicKey(params.mint_in);
804
+ let mintOut = new web3_js_1.PublicKey(params.mint_out);
805
+ let amountIn = new anchor_1.BN(params.amount_in);
806
+ let amountOut = new anchor_1.BN(params.amount_out);
807
+ let mode = params.mode ? params.mode : 0;
808
+ let flashParams = {
733
809
  keeper: keeper,
734
- basket: rebalanceIntent.basket,
735
- mintFrom: mintFrom,
736
- mintTo: mintTo,
810
+ basket: basket,
811
+ rebalanceIntent: rebalanceIntent,
812
+ intent: intent,
813
+ mintIn: mintIn,
814
+ mintOut: mintOut,
737
815
  amountIn: amountIn,
738
816
  amountOut: amountOut,
739
817
  mode: mode,
740
- });
818
+ };
819
+ let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
820
+ let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
741
821
  let txBatchData = { batches: [[{
742
822
  payer: keeper,
743
823
  instructions: [
744
- ix,
824
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
825
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
826
+ ixWithdraw,
827
+ params.jup_swap_ix ? params.jup_swap_ix : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
828
+ ixDeposit,
745
829
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
746
830
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
747
831
  ],
@@ -754,14 +838,14 @@ class SymmetryCore {
754
838
  }
755
839
  mintTx(params) {
756
840
  return __awaiter(this, void 0, void 0, function* () {
757
- let { keeper, buyer, basket } = params;
758
- const basketAi = yield this.sdkParams.connection.getAccountInfo(basket);
759
- let mint = basket_1.BasketLayout.decode(basketAi === null || basketAi === void 0 ? void 0 : basketAi.data.slice(8)).mint;
841
+ let keeper = new web3_js_1.PublicKey(params.keeper);
842
+ let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
843
+ let basket = yield this.fetchBasket(rebalanceIntent.basket.toBase58());
760
844
  let ix = (0, deposit_1.mintBasketIx)({
761
845
  keeper: keeper,
762
- basket: basket,
763
- basketTokenMint: mint,
764
- buyer: buyer,
846
+ basket: basket.ownAddress,
847
+ basketTokenMint: basket.mint,
848
+ buyer: rebalanceIntent.owner,
765
849
  });
766
850
  let txBatchData = { batches: [[{
767
851
  payer: keeper,
@@ -779,7 +863,8 @@ class SymmetryCore {
779
863
  }
780
864
  redeemTokensTx(params) {
781
865
  return __awaiter(this, void 0, void 0, function* () {
782
- let { keeper, rebalanceIntent } = params;
866
+ let keeper = new web3_js_1.PublicKey(params.keeper);
867
+ let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
783
868
  let batchSize = 7;
784
869
  let ixs = [];
785
870
  for (let batchStart = 0; batchStart < rebalanceIntent.tokens.length; batchStart += batchSize) {
@@ -812,7 +897,8 @@ class SymmetryCore {
812
897
  }
813
898
  claimBountyTx(params) {
814
899
  return __awaiter(this, void 0, void 0, function* () {
815
- let { keeper, rebalanceIntent } = params;
900
+ let keeper = new web3_js_1.PublicKey(params.keeper);
901
+ let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
816
902
  let keepersArray = [];
817
903
  if (!rebalanceIntent.startPriceUpdateTask.completedBy.equals(web3_js_1.PublicKey.default))
818
904
  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,73 @@
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
+ const { keeper, basket, mintIn, mintOut, amountIn, amountOut, mode } = params;
13
+ let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
14
+ let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
15
+ let basketInATA = (0, pda_1.getAta)(basket, mintIn);
16
+ let basketOutATA = (0, pda_1.getAta)(basket, mintOut);
17
+ const keys = [
18
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
19
+ { pubkey: params.basket, isWritable: true, isSigner: false },
20
+ { pubkey: params.rebalanceIntent ? params.rebalanceIntent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
21
+ { pubkey: params.intent ? params.intent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
22
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
23
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
24
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
25
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
26
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
27
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
28
+ { pubkey: (0, pda_1.getGlobalConfigPda)(), isWritable: false, isSigner: false },
29
+ { pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
30
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
31
+ { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
32
+ ];
33
+ const discriminator = FLASH_WITHDRAW_DISCRIMINATOR;
34
+ const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
35
+ const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
36
+ const modeBuffer = mode ? Buffer.from([mode]) : Buffer.from([]);
37
+ const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
38
+ return new web3_js_1.TransactionInstruction({
39
+ keys,
40
+ programId: constants_1.BASKETS_V3_PROGRAM_ID,
41
+ data,
42
+ });
43
+ }
44
+ function flashDepositIx(params) {
45
+ const { keeper, basket, mintIn, mintOut } = params;
46
+ let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
47
+ let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
48
+ let basketInATA = (0, pda_1.getAta)(basket, mintIn);
49
+ let basketOutATA = (0, pda_1.getAta)(basket, mintOut);
50
+ const keys = [
51
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
52
+ { pubkey: params.basket, isWritable: true, isSigner: false },
53
+ { pubkey: params.rebalanceIntent ? params.rebalanceIntent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
54
+ { pubkey: params.intent ? params.intent : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
55
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
56
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
57
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
58
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
59
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
60
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
61
+ { pubkey: (0, pda_1.getGlobalConfigPda)(), isWritable: false, isSigner: false },
62
+ { pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
63
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
64
+ { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
65
+ ];
66
+ const discriminator = FLASH_DEPOSIT_DISCRIMINATOR;
67
+ const data = Buffer.concat([discriminator]);
68
+ return new web3_js_1.TransactionInstruction({
69
+ keys,
70
+ programId: constants_1.BASKETS_V3_PROGRAM_ID,
71
+ data,
72
+ });
73
+ }
@@ -165,6 +165,8 @@ export interface EditMakeDirectSwapSettings {
165
165
  }
166
166
  export interface OracleInput {
167
167
  oracle_type: FormattedOracleType;
168
+ account_lut_id: number;
169
+ account_lut_index: number;
168
170
  account: string;
169
171
  num_required_accounts: number;
170
172
  weight: number;
@@ -60,12 +60,12 @@ function taskTypeFromU8(value) {
60
60
  case 8: return TaskType.EditDepositsSettings;
61
61
  case 9: return TaskType.EditForceRebalanceSettings;
62
62
  case 10: return TaskType.EditCustomRebalanceSettings;
63
- case 11: return TaskType.EditAddTokenDelay;
64
- case 12: return TaskType.EditUpdateWeightsDelay;
65
- case 13: return TaskType.EditMakeDirectSwapDelay;
66
- case 14: return TaskType.AddToken;
67
- case 15: return TaskType.UpdateWeights;
68
- case 16: return TaskType.MakeDirectSwap;
63
+ case 101: return TaskType.EditAddTokenDelay;
64
+ case 102: return TaskType.EditUpdateWeightsDelay;
65
+ case 103: return TaskType.EditMakeDirectSwapDelay;
66
+ case 201: return TaskType.AddToken;
67
+ case 202: return TaskType.UpdateWeights;
68
+ case 203: return TaskType.MakeDirectSwap;
69
69
  default: return TaskType.Unknown;
70
70
  }
71
71
  }
@@ -220,6 +220,8 @@ function addFieldsToBasket(basket) {
220
220
  oracles: asset.oracleAggregator.oracles.map(oracle => ({
221
221
  oracle_settings: {
222
222
  oracle_type: oracle_1.ORACLE_TYPES_STRINGS[oracle.oracleSettings.oracleType],
223
+ account_lut_id: oracle.accountsToLoadLutIds[0],
224
+ account_lut_index: oracle.accountsToLoadLutIndices[0],
223
225
  account: lookup_tables.active[oracle.accountsToLoadLutIds[0]].contents[oracle.accountsToLoadLutIndices[0]],
224
226
  num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
225
227
  weight: oracle.oracleSettings.weight,
@@ -185,6 +185,8 @@ function decodeTaskDataForType(intent) {
185
185
  conf_multiplier: (0, fraction_1.fractionToDecimal)(oracleAggregator.confMultiplier).toNumber(),
186
186
  oracles: oracleAggregator.oracles.slice(0, oracleAggregator.numOracles).map(oracle => ({
187
187
  oracle_type: oracle_1.ORACLE_TYPES_STRINGS[oracle.oracleSettings.oracleType],
188
+ account_lut_id: oracle.accountsToLoadLutIds[0],
189
+ account_lut_index: oracle.accountsToLoadLutIndices[0],
188
190
  account: "",
189
191
  num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
190
192
  weight: oracle.oracleSettings.weight,
package/dist/test.js CHANGED
@@ -12,11 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const web3_js_1 = require("@solana/web3.js");
13
13
  const anchor_1 = require("@coral-xyz/anchor");
14
14
  const src_1 = require("./src");
15
+ let kp = Array.from(web3_js_1.Keypair.generate().secretKey);
15
16
  let connection = new web3_js_1.Connection("https://api.devnet.solana.com");
16
17
  function testStates() {
17
18
  return __awaiter(this, void 0, void 0, function* () {
18
19
  return;
19
- let kp = Array.from(web3_js_1.Keypair.generate().secretKey);
20
20
  let wallet = new anchor_1.Wallet(web3_js_1.Keypair.fromSecretKey(new Uint8Array(kp)));
21
21
  console.log(wallet.publicKey.toBase58());
22
22
  let sdk = new src_1.SymmetryCore({
@@ -248,6 +248,8 @@ function testStates() {
248
248
  oracles: [
249
249
  {
250
250
  oracle_type: "pyth",
251
+ account_lut_id: 0,
252
+ account_lut_index: 0,
251
253
  account: "So11111111111111111111111111111111111111112",
252
254
  num_required_accounts: 1,
253
255
  weight: 100,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmetry-hq/temp-v3-sdk",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "Symmetry Baskets V3 SDK",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import Decimal from 'decimal.js';
2
2
 
3
3
  import { BN } from '@coral-xyz/anchor';
4
- import { createAssociatedTokenAccountInstruction } from '@solana/spl-token';
4
+ import { createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction } from '@solana/spl-token';
5
5
  import {
6
6
  ComputeBudgetProgram, Connection, Keypair, PublicKey, TransactionInstruction,
7
7
  TransactionSignature
@@ -65,6 +65,8 @@ import {
65
65
  } from './txUtils';
66
66
  import { FormattedOracleType } from './layouts/oracle';
67
67
  import { fetchGlobalConfig } from './states/config';
68
+ import { flashDepositIx, flashWithdrawIx } from './instructions/automation/flashSwap';
69
+
68
70
  export const COMPUTE_UNITS = 1_000_000;
69
71
  export const PRIORITY_FEE = 100_000;
70
72
  export const JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
@@ -366,14 +368,15 @@ export class SymmetryCore {
366
368
  async updateWeightsTx(context: TaskContext, settings: UpdateWeightsInput): Promise<TxPayloadBatchSequence> {
367
369
  return this.openBasketIntentTx({ type: TaskType.UpdateWeights, context, settings });
368
370
  }
369
- async makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput): Promise<TxPayloadBatchSequence> {
370
- return this.openBasketIntentTx({ type: TaskType.MakeDirectSwap, context, settings });
371
+ async makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput, jup_swap_ix?: TransactionInstruction): Promise<TxPayloadBatchSequence> {
372
+ return this.openBasketIntentTx({ type: TaskType.MakeDirectSwap, context, settings, jup_swap_ix: jup_swap_ix });
371
373
  }
372
374
 
373
375
  async openBasketIntentTx(params: {
374
376
  context: TaskContext,
375
377
  type: TaskType,
376
378
  settings: Settings,
379
+ jup_swap_ix?: TransactionInstruction,
377
380
  }): Promise<TxPayloadBatchSequence> {
378
381
  let basket = await this.fetchBasket(params.context.basket);
379
382
  let manager = new PublicKey(params.context.manager);
@@ -421,7 +424,15 @@ export class SymmetryCore {
421
424
  editType: editType,
422
425
  editData: editData,
423
426
  });
424
- ixs.push(openBasketIntentIx);
427
+ let txBatchData: TxBatchData = {batches: [[{
428
+ payer: manager,
429
+ instructions: [
430
+ openBasketIntentIx,
431
+ ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
432
+ ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
433
+ ],
434
+ lookupTables: [],
435
+ }]]};
425
436
 
426
437
  // Only execute in the same transaction when there is no delay and no scheduled activation.
427
438
  if (modificationDelay.eq(new BN(0)) && activationTimestamp.eq(new BN(0))) {
@@ -434,18 +445,52 @@ export class SymmetryCore {
434
445
  keeper: manager,
435
446
  basketMint: basket.mint,
436
447
  });
437
- ixs.push(executeBasketIntentIx);
448
+ if (editType == TaskType.MakeDirectSwap && params.jup_swap_ix) {
449
+ let flashParams = {
450
+ keeper: manager,
451
+ basket: basket.ownAddress,
452
+ rebalanceIntent: undefined,
453
+ intent: intent,
454
+ mintIn: new PublicKey((editData as MakeDirectSwapInput).make_direct_swap.from_token_mint),
455
+ mintOut: new PublicKey((editData as MakeDirectSwapInput).make_direct_swap.to_token_mint),
456
+ amountIn: new BN((editData as MakeDirectSwapInput).make_direct_swap.amount_from),
457
+ amountOut: new BN((editData as MakeDirectSwapInput).make_direct_swap.amount_to),
458
+ mode: undefined,
459
+ }
460
+ let ixWithdraw = flashWithdrawIx(flashParams);
461
+ let ixDeposit = flashDepositIx(flashParams);
462
+ txBatchData.batches.push([{
463
+ payer: manager,
464
+ instructions: [
465
+ createAssociatedTokenAccountIdempotentInstruction(manager, getAta(manager, flashParams.mintIn), manager, flashParams.mintIn),
466
+ createAssociatedTokenAccountIdempotentInstruction(manager, getAta(manager, flashParams.mintOut), manager, flashParams.mintOut),
467
+ ixWithdraw,
468
+ params.jup_swap_ix,
469
+ ixDeposit,
470
+ ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
471
+ ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
472
+ ],
473
+ lookupTables: [],
474
+ }]);
475
+ txBatchData.batches.push([{
476
+ payer: manager,
477
+ instructions: [
478
+ executeBasketIntentIx,
479
+ ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
480
+ ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
481
+ ],
482
+ lookupTables: [],
483
+ }]);
484
+ } else {
485
+ txBatchData.batches[0][0].instructions = [
486
+ openBasketIntentIx,
487
+ executeBasketIntentIx,
488
+ ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
489
+ ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
490
+ ];
491
+ }
438
492
  }
439
493
 
440
- let txBatchData: TxBatchData = {batches: [[{
441
- payer: manager,
442
- instructions: [
443
- ...ixs,
444
- ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
445
- ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
446
- ],
447
- lookupTables: [],
448
- }]]};
449
494
  let versionedTxs = await prepareVersionedTxs(this.sdkParams.connection, txBatchData);
450
495
  let txPayloadBatchSequence = prepareTxPayloadBatchSequence(txBatchData, versionedTxs);
451
496
  return txPayloadBatchSequence;
@@ -606,7 +651,7 @@ export class SymmetryCore {
606
651
  owner: buyer,
607
652
  basket: basket,
608
653
  }),
609
- executionStartTime ? startPriceUpdatesIx({
654
+ executionStartTime == 0 ? startPriceUpdatesIx({
610
655
  keeper: buyer,
611
656
  basket: basket,
612
657
  rebalanceIntent: rebalanceIntent,
@@ -732,7 +777,7 @@ export class SymmetryCore {
732
777
  [{
733
778
  payer: seller,
734
779
  instructions: [
735
- executionStartTime ? startPriceUpdatesIx({
780
+ executionStartTime == 0 ? startPriceUpdatesIx({
736
781
  keeper: seller,
737
782
  basket: basket,
738
783
  rebalanceIntent: rebalanceIntent,
@@ -748,14 +793,41 @@ export class SymmetryCore {
748
793
  let txPayloadBatchSequence = prepareTxPayloadBatchSequence(txBatchData, versionedTxs);
749
794
  return txPayloadBatchSequence;
750
795
  }
751
-
796
+
797
+ async startPriceUpdatesTx(params: {
798
+ keeper: string,
799
+ basket: string,
800
+ rebalance_intent: string,
801
+ }): Promise<TxPayloadBatchSequence> {
802
+ let keeper = new PublicKey(params.keeper);
803
+ let basket = new PublicKey(params.basket);
804
+ let rebalanceIntent = new PublicKey(params.rebalance_intent);
805
+ let txBatchData: TxBatchData = {batches: [[{
806
+ payer: keeper,
807
+ instructions: [
808
+ startPriceUpdatesIx({
809
+ keeper: keeper,
810
+ basket: basket,
811
+ rebalanceIntent: rebalanceIntent,
812
+ }),
813
+ ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
814
+ ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
815
+ ],
816
+ lookupTables: [],
817
+ }]]};
818
+ let versionedTxs = await prepareVersionedTxs(this.sdkParams.connection, txBatchData);
819
+ let txPayloadBatchSequence = prepareTxPayloadBatchSequence(txBatchData, versionedTxs);
820
+ return txPayloadBatchSequence;
821
+ }
752
822
 
753
823
  async updateTokenPricesTx(params: {
754
- keeper: PublicKey,
755
- rebalanceIntent: RebalanceIntent,
756
- basket: Basket,
824
+ keeper: string,
825
+ basket: string,
826
+ rebalance_intent: string,
757
827
  }): Promise<TxPayloadBatchSequence> {
758
- let { keeper, rebalanceIntent, basket } = params;
828
+ let keeper = new PublicKey(params.keeper);
829
+ let rebalanceIntent = new PublicKey(params.rebalance_intent);
830
+ let basket = await this.fetchBasket(params.basket);
759
831
  let ixs: TransactionInstruction[] = [];
760
832
  let batchSize = 7;
761
833
  for (let batchStart = 0; batchStart < basket.numTokens; batchStart += batchSize) {
@@ -779,8 +851,8 @@ export class SymmetryCore {
779
851
  ixs.push(
780
852
  updateTokenPricesIx({
781
853
  keeper: keeper,
782
- basket: rebalanceIntent.basket, //@ts-ignore
783
- rebalanceIntent: rebalanceIntent.ownAddress,
854
+ basket: basket.ownAddress,
855
+ rebalanceIntent: rebalanceIntent,
784
856
  lookupTable0: basket.lookupTables.active[0],
785
857
  lookupTable1: basket.lookupTables.active[1],
786
858
  tokenIndices: tokenIndices,
@@ -802,29 +874,48 @@ export class SymmetryCore {
802
874
  return txPayloadBatchSequence;
803
875
  }
804
876
 
805
- async executeSwap(params: {
806
- keeper: PublicKey,
807
- rebalanceIntent: RebalanceIntent,
808
- mintFrom: PublicKey,
809
- mintTo: PublicKey,
810
- amountIn: BN,
811
- amountOut: BN,
812
- mode: number,
877
+ async flashSwapTx(params: {
878
+ keeper: string,
879
+ basket: string,
880
+ rebalance_intent?: string,
881
+ intent?: string,
882
+ mint_in: string,
883
+ mint_out: string,
884
+ amount_in: number,
885
+ amount_out: number,
886
+ mode?: number,
887
+ jup_swap_ix?: TransactionInstruction,
813
888
  }): Promise<TxPayloadBatchSequence> {
814
- let { keeper, rebalanceIntent, mintFrom, mintTo, amountIn, amountOut, mode } = params;
815
- let ix = rebalanceSwapIx({
889
+ let keeper = new PublicKey(params.keeper);
890
+ let basket = new PublicKey(params.basket);
891
+ let rebalanceIntent = params.rebalance_intent ? new PublicKey(params.rebalance_intent) : undefined;
892
+ let intent = params.intent ? new PublicKey(params.intent) : undefined;
893
+ let mintIn = new PublicKey(params.mint_in);
894
+ let mintOut = new PublicKey(params.mint_out);
895
+ let amountIn = new BN(params.amount_in);
896
+ let amountOut = new BN(params.amount_out);
897
+ let mode = params.mode ? params.mode : 0;
898
+ let flashParams = {
816
899
  keeper: keeper,
817
- basket: rebalanceIntent.basket,
818
- mintFrom: mintFrom,
819
- mintTo: mintTo,
900
+ basket: basket,
901
+ rebalanceIntent: rebalanceIntent,
902
+ intent: intent,
903
+ mintIn: mintIn,
904
+ mintOut: mintOut,
820
905
  amountIn: amountIn,
821
906
  amountOut: amountOut,
822
907
  mode: mode,
823
- });
908
+ };
909
+ let ixWithdraw = flashWithdrawIx(flashParams);
910
+ let ixDeposit = flashDepositIx(flashParams);
824
911
  let txBatchData: TxBatchData = {batches: [[{
825
912
  payer: keeper,
826
913
  instructions: [
827
- ix,
914
+ createAssociatedTokenAccountIdempotentInstruction(keeper, getAta(keeper, mintIn), keeper, mintIn),
915
+ createAssociatedTokenAccountIdempotentInstruction(keeper, getAta(keeper, mintOut), keeper, mintOut),
916
+ ixWithdraw,
917
+ params.jup_swap_ix ? params.jup_swap_ix : ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
918
+ ixDeposit,
828
919
  ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
829
920
  ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
830
921
  ],
@@ -836,18 +927,17 @@ export class SymmetryCore {
836
927
  }
837
928
 
838
929
  async mintTx(params: {
839
- keeper: PublicKey,
840
- buyer: PublicKey,
841
- basket: PublicKey,
930
+ keeper: string,
931
+ rebalance_intent: string,
842
932
  }): Promise<TxPayloadBatchSequence> {
843
- let { keeper, buyer, basket } = params;
844
- const basketAi = await this.sdkParams.connection.getAccountInfo(basket);
845
- let mint = BasketLayout.decode(basketAi?.data.slice(8)).mint;
933
+ let keeper = new PublicKey(params.keeper);
934
+ let rebalanceIntent = await this.fetchRebalanceIntent(params.rebalance_intent);
935
+ let basket = await this.fetchBasket(rebalanceIntent.basket.toBase58());
846
936
  let ix = mintBasketIx({
847
937
  keeper: keeper,
848
- basket: basket,
849
- basketTokenMint: mint,
850
- buyer: buyer,
938
+ basket: basket.ownAddress,
939
+ basketTokenMint: basket.mint,
940
+ buyer: rebalanceIntent.owner,
851
941
  });
852
942
  let txBatchData: TxBatchData = {batches: [[{
853
943
  payer: keeper,
@@ -864,10 +954,11 @@ export class SymmetryCore {
864
954
  }
865
955
 
866
956
  async redeemTokensTx(params: {
867
- keeper: PublicKey,
868
- rebalanceIntent: RebalanceIntent,
957
+ keeper: string,
958
+ rebalance_intent: string,
869
959
  }): Promise<TxPayloadBatchSequence> {
870
- let { keeper, rebalanceIntent } = params;
960
+ let keeper = new PublicKey(params.keeper);
961
+ let rebalanceIntent = await this.fetchRebalanceIntent(params.rebalance_intent);
871
962
  let batchSize = 7;
872
963
  let ixs: TransactionInstruction[] = [];
873
964
  for (let batchStart = 0; batchStart < rebalanceIntent.tokens.length; batchStart += batchSize) {
@@ -901,10 +992,11 @@ export class SymmetryCore {
901
992
  }
902
993
 
903
994
  async claimBountyTx(params: {
904
- keeper: PublicKey,
905
- rebalanceIntent: RebalanceIntent,
995
+ keeper: string,
996
+ rebalance_intent: string,
906
997
  }): Promise<TxPayloadBatchSequence> {
907
- let { keeper, rebalanceIntent } = params;
998
+ let keeper = new PublicKey(params.keeper);
999
+ let rebalanceIntent = await this.fetchRebalanceIntent(params.rebalance_intent);
908
1000
  let keepersArray: PublicKey[] = [];
909
1001
  if (!rebalanceIntent.startPriceUpdateTask.completedBy.equals(PublicKey.default))
910
1002
  keepersArray.push(rebalanceIntent.startPriceUpdateTask.completedBy);
@@ -0,0 +1,104 @@
1
+ import { BN } from '@coral-xyz/anchor';
2
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token';
3
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, TransactionInstruction } from '@solana/web3.js';
4
+
5
+ import { BASKETS_V3_PROGRAM_ID } from '../../constants';
6
+ import { getAta, getGlobalConfigPda } from '../pda';
7
+
8
+ const FLASH_WITHDRAW_DISCRIMINATOR = Buffer.from([164, 84, 46, 132, 94, 220, 214, 156]);
9
+ const FLASH_DEPOSIT_DISCRIMINATOR = Buffer.from([21, 4, 89, 84, 131, 84, 128, 21]);
10
+
11
+ export function flashWithdrawIx(params: {
12
+ keeper: PublicKey;
13
+ basket: PublicKey;
14
+ rebalanceIntent?: PublicKey;
15
+ intent?: PublicKey;
16
+ mintIn: PublicKey;
17
+ mintOut: PublicKey;
18
+ amountIn: BN;
19
+ amountOut: BN;
20
+ mode?: number;
21
+ }): TransactionInstruction {
22
+
23
+ const { keeper, basket, mintIn, mintOut, amountIn, amountOut, mode } = params;
24
+
25
+ let keeperFromATA = getAta(keeper, mintIn);
26
+ let keeperToATA = getAta(keeper, mintOut);
27
+ let basketInATA = getAta(basket, mintIn);
28
+ let basketOutATA = getAta(basket, mintOut);
29
+
30
+ const keys = [
31
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
32
+ { pubkey: params.basket, isWritable: true, isSigner: false },
33
+ { pubkey: params.rebalanceIntent ? params.rebalanceIntent : BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
34
+ { pubkey: params.intent ? params.intent : BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
35
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
36
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
37
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
38
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
39
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
40
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
41
+ { pubkey: getGlobalConfigPda(), isWritable: false, isSigner: false },
42
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
43
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
44
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
45
+ ];
46
+
47
+ const discriminator = FLASH_WITHDRAW_DISCRIMINATOR;
48
+
49
+ const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
50
+ const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
51
+ const modeBuffer = mode ? Buffer.from([mode]) : Buffer.from([]);
52
+
53
+ const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
54
+
55
+ return new TransactionInstruction({
56
+ keys,
57
+ programId: BASKETS_V3_PROGRAM_ID,
58
+ data,
59
+ });
60
+ }
61
+
62
+ export function flashDepositIx(params: {
63
+ keeper: PublicKey;
64
+ basket: PublicKey;
65
+ rebalanceIntent?: PublicKey;
66
+ intent?: PublicKey;
67
+ mintIn: PublicKey;
68
+ mintOut: PublicKey;
69
+ }): TransactionInstruction {
70
+ const { keeper, basket, mintIn, mintOut } = params;
71
+
72
+ let keeperFromATA = getAta(keeper, mintIn);
73
+ let keeperToATA = getAta(keeper, mintOut);
74
+ let basketInATA = getAta(basket, mintIn);
75
+ let basketOutATA = getAta(basket, mintOut);
76
+
77
+ const keys = [
78
+ { pubkey: params.keeper, isWritable: true, isSigner: true },
79
+ { pubkey: params.basket, isWritable: true, isSigner: false },
80
+ { pubkey: params.rebalanceIntent ? params.rebalanceIntent : BASKETS_V3_PROGRAM_ID, isWritable: params.rebalanceIntent ? true : false, isSigner: false },
81
+ { pubkey: params.intent ? params.intent : BASKETS_V3_PROGRAM_ID, isWritable: params.intent ? true : false, isSigner: false },
82
+ { pubkey: params.mintIn, isWritable: false, isSigner: false },
83
+ { pubkey: params.mintOut, isWritable: false, isSigner: false },
84
+ { pubkey: keeperFromATA, isWritable: true, isSigner: false },
85
+ { pubkey: keeperToATA, isWritable: true, isSigner: false },
86
+ { pubkey: basketInATA, isWritable: true, isSigner: false },
87
+ { pubkey: basketOutATA, isWritable: true, isSigner: false },
88
+ { pubkey: getGlobalConfigPda(), isWritable: false, isSigner: false },
89
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isWritable: false, isSigner: false },
90
+ { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
91
+ { pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
92
+ ];
93
+
94
+ const discriminator = FLASH_DEPOSIT_DISCRIMINATOR;
95
+
96
+
97
+ const data = Buffer.concat([discriminator]);
98
+
99
+ return new TransactionInstruction({
100
+ keys,
101
+ programId: BASKETS_V3_PROGRAM_ID,
102
+ data,
103
+ });
104
+ }
@@ -106,13 +106,13 @@ export enum TaskType {
106
106
  case 9: return TaskType.EditForceRebalanceSettings;
107
107
  case 10: return TaskType.EditCustomRebalanceSettings;
108
108
 
109
- case 11: return TaskType.EditAddTokenDelay;
110
- case 12: return TaskType.EditUpdateWeightsDelay;
111
- case 13: return TaskType.EditMakeDirectSwapDelay;
109
+ case 101: return TaskType.EditAddTokenDelay;
110
+ case 102: return TaskType.EditUpdateWeightsDelay;
111
+ case 103: return TaskType.EditMakeDirectSwapDelay;
112
112
 
113
- case 14: return TaskType.AddToken;
114
- case 15: return TaskType.UpdateWeights;
115
- case 16: return TaskType.MakeDirectSwap;
113
+ case 201: return TaskType.AddToken;
114
+ case 202: return TaskType.UpdateWeights;
115
+ case 203: return TaskType.MakeDirectSwap;
116
116
 
117
117
  default: return TaskType.Unknown;
118
118
  }
@@ -233,6 +233,8 @@ export interface EditMakeDirectSwapSettings {
233
233
 
234
234
  export interface OracleInput {
235
235
  oracle_type: FormattedOracleType,
236
+ account_lut_id: number,
237
+ account_lut_index: number,
236
238
  account: string,
237
239
  num_required_accounts: number,
238
240
  weight: number,
@@ -219,7 +219,7 @@ export function addFieldsToBasket(basket: Basket): Basket {
219
219
  },
220
220
  ],
221
221
  };
222
- let composition: FormattedAsset[] =basket.composition.map(asset => ({
222
+ let composition: FormattedAsset[] = basket.composition.map(asset => ({
223
223
  mint: asset.mint.toBase58(),
224
224
  amount: parseInt(asset.amount.toString()),
225
225
  weight: asset.weight,
@@ -230,6 +230,8 @@ export function addFieldsToBasket(basket: Basket): Basket {
230
230
  oracles: asset.oracleAggregator.oracles.map(oracle => ({
231
231
  oracle_settings: {
232
232
  oracle_type: ORACLE_TYPES_STRINGS[oracle.oracleSettings.oracleType],
233
+ account_lut_id: oracle.accountsToLoadLutIds[0],
234
+ account_lut_index: oracle.accountsToLoadLutIndices[0],
233
235
  account: lookup_tables.active[oracle.accountsToLoadLutIds[0]].contents[oracle.accountsToLoadLutIndices[0]],
234
236
  num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
235
237
  weight: oracle.oracleSettings.weight,
@@ -8,7 +8,7 @@ import {
8
8
  import { BASKETS_V3_PROGRAM_ID, MAX_MANAGERS_PER_BASKET } from '../../constants';
9
9
  import { AddOrEditTokenInput, EditAddTokenSettings, EditAutomationSettings, EditCreatorSettings, EditCustomRebalanceSettings, EditDepositsSettings, EditFeeSettings, EditForceRebalanceSettings, EditLpSettings, EditMakeDirectSwapSettings, EditManagerSettings, EditMetadataSettings, EditScheduleSettings, EditUpdateWeightsSettings, FormattedIntent, Intent, INTENT_STATUS_STRINGS, IntentLayout, IntentStatus, MakeDirectSwapInput, Settings, TASK_TYPE_STRINGS, TaskType, taskTypeFromU8, UpdateWeightsInput } from '../../layouts/intents/intent';
10
10
  import { getMultipleAccountsInfoBatched } from '../../txUtils';
11
- import { AuthorityBitmasks, AuthorityBitmasksLayout, AutomationSettings, AutomationSettingsLayout, EditAddTokenDelay, EditAddTokenDelayLayout, EditCreator, EditCreatorLayout, EditMakeDirectSwapDelay, EditMakeDirectSwapDelayLayout, EditUpdateWeightsDelay, EditUpdateWeightsDelayLayout, FeeSettings, FeeSettingsLayout, LpSettings, LpSettingsLayout, MakeDirectSwap, MakeDirectSwapLayout, MetadataSettings, MetadataSettingsLayout, ScheduleSettings, ScheduleSettingsLayout, UpdateWeights, UpdateWeightsLayout } from '../../layouts/config';
11
+ import { AuthorityBitmasks, AuthorityBitmasksLayout, AutomationSettings, AutomationSettingsLayout, EditAddTokenDelay, EditAddTokenDelayLayout, EditCreator, EditCreatorLayout, EditMakeDirectSwapDelay, EditMakeDirectSwapDelayLayout, EditUpdateWeightsDelay, EditUpdateWeightsDelayLayout, FeeSettings, FeeSettingsLayout, LpSettings, LpSettingsLayout, MakeDirectSwap, MakeDirectSwapLayout, ManagerSettings, ManagerSettingsLayout, MetadataSettings, MetadataSettingsLayout, ScheduleSettings, ScheduleSettingsLayout, UpdateWeights, UpdateWeightsLayout } from '../../layouts/config';
12
12
  import { BN } from '@coral-xyz/anchor';
13
13
  import { ORACLE_TYPES_STRINGS, OracleAggregator, OracleAggregatorLayout } from '../../layouts/oracle';
14
14
  import { fractionToDecimal } from '../../layouts/fraction';
@@ -177,6 +177,8 @@ function decodeTaskDataForType(intent: Intent): Settings {
177
177
  conf_multiplier: fractionToDecimal(oracleAggregator.confMultiplier).toNumber(),
178
178
  oracles: oracleAggregator.oracles.slice(0, oracleAggregator.numOracles).map(oracle => ({
179
179
  oracle_type: ORACLE_TYPES_STRINGS[oracle.oracleSettings.oracleType],
180
+ account_lut_id: oracle.accountsToLoadLutIds[0],
181
+ account_lut_index: oracle.accountsToLoadLutIndices[0],
180
182
  account: "",
181
183
  num_required_accounts: oracle.oracleSettings.numRequiredAccounts,
182
184
  weight: oracle.oracleSettings.weight,
package/test.ts CHANGED
@@ -6,11 +6,13 @@ import { AddOrEditTokenInput, UpdateWeightsInput, MakeDirectSwapInput } from "./
6
6
  import { EditCreatorSettings, EditManagerSettings, EditFeeSettings, EditScheduleSettings, EditAutomationSettings, EditLpSettings, EditMetadataSettings, EditDepositsSettings, EditForceRebalanceSettings, EditCustomRebalanceSettings, EditAddTokenSettings, EditUpdateWeightsSettings, EditMakeDirectSwapSettings } from "./src";
7
7
 
8
8
 
9
+ let kp = Array.from(Keypair.generate().secretKey);
10
+
9
11
  let connection = new Connection("https://api.devnet.solana.com");
10
12
 
13
+
11
14
  async function testStates() {
12
15
  return;
13
- let kp = Array.from(Keypair.generate().secretKey);
14
16
  let wallet = new Wallet(Keypair.fromSecretKey(new Uint8Array(kp)));
15
17
  console.log(wallet.publicKey.toBase58());
16
18
 
@@ -273,6 +275,8 @@ async function testStates() {
273
275
  oracles: [
274
276
  {
275
277
  oracle_type: "pyth",
278
+ account_lut_id: 0,
279
+ account_lut_index: 0,
276
280
  account: "So11111111111111111111111111111111111111112",
277
281
  num_required_accounts: 1,
278
282
  weight: 100,