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

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.
Files changed (32) hide show
  1. package/dist/src/constants.d.ts +1 -0
  2. package/dist/src/constants.js +2 -1
  3. package/dist/src/index.d.ts +7 -0
  4. package/dist/src/index.js +122 -53
  5. package/dist/src/instructions/automation/flashSwap.js +4 -3
  6. package/dist/src/instructions/automation/priceUpdate.d.ts +1 -0
  7. package/dist/src/instructions/automation/priceUpdate.js +3 -0
  8. package/dist/src/instructions/automation/rebalanceIntent.d.ts +1 -1
  9. package/dist/src/instructions/automation/rebalanceIntent.js +2 -3
  10. package/dist/src/instructions/user/deposit.d.ts +1 -0
  11. package/dist/src/instructions/user/deposit.js +2 -0
  12. package/dist/src/instructions/user/withdraw.d.ts +0 -10
  13. package/dist/src/instructions/user/withdraw.js +0 -44
  14. package/dist/src/states/intents/rebalanceIntent.d.ts +2 -1
  15. package/dist/src/states/intents/rebalanceIntent.js +23 -0
  16. package/dist/src/txUtils.d.ts +2 -2
  17. package/dist/src/txUtils.js +44 -13
  18. package/dist/test.js +99 -16
  19. package/package.json +1 -1
  20. package/src/constants.ts +1 -0
  21. package/src/index.ts +151 -49
  22. package/src/instructions/automation/flashSwap.ts +3 -3
  23. package/src/instructions/automation/priceUpdate.ts +3 -0
  24. package/src/instructions/automation/rebalanceIntent.ts +3 -4
  25. package/src/instructions/user/deposit.ts +2 -0
  26. package/src/instructions/user/withdraw.ts +2 -75
  27. package/src/states/intents/rebalanceIntent.ts +36 -2
  28. package/src/txUtils.ts +44 -7
  29. package/test.ts +105 -16
  30. package/dist/src/instructions/automation/rebalanceSwap.d.ts +0 -11
  31. package/dist/src/instructions/automation/rebalanceSwap.js +0 -42
  32. package/src/instructions/automation/rebalanceSwap.ts +0 -62
@@ -9,6 +9,7 @@ export declare const PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT: PublicKey;
9
9
  export declare const PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT: PublicKey;
10
10
  export declare const INTENT_TASK_DATA_SIZE = 600;
11
11
  export declare const MAX_MANAGERS_PER_BASKET = 10;
12
+ export declare const MAX_TRANSFER_TOKENS = 10;
12
13
  export declare const X64: Decimal;
13
14
  export declare const HUNDRED_PERCENT_BPS = 10000;
14
15
  export declare const WSOL_DECIMALS = 9;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MAX_EXTRA_DATA_PER_ORACLE = exports.MAX_ORACLES_PER_TOKEN = exports.MAX_SUPPORTED_TOKENS_PER_BASKET = exports.USDC_DECIMALS = exports.WSOL_DECIMALS = exports.HUNDRED_PERCENT_BPS = exports.X64 = exports.MAX_MANAGERS_PER_BASKET = exports.INTENT_TASK_DATA_SIZE = exports.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT = exports.PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT = exports.MINTS = exports.RENT_SYSVAR_ID = exports.ADDRESS_LOOKUP_TABLE_PROGRAM_ID = exports.METADATA_PROGRAM_ID = exports.BASKETS_V3_PROGRAM_ID = void 0;
6
+ exports.MAX_EXTRA_DATA_PER_ORACLE = exports.MAX_ORACLES_PER_TOKEN = exports.MAX_SUPPORTED_TOKENS_PER_BASKET = exports.USDC_DECIMALS = exports.WSOL_DECIMALS = exports.HUNDRED_PERCENT_BPS = exports.X64 = exports.MAX_TRANSFER_TOKENS = exports.MAX_MANAGERS_PER_BASKET = exports.INTENT_TASK_DATA_SIZE = exports.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT = exports.PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT = exports.MINTS = exports.RENT_SYSVAR_ID = exports.ADDRESS_LOOKUP_TABLE_PROGRAM_ID = exports.METADATA_PROGRAM_ID = exports.BASKETS_V3_PROGRAM_ID = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
8
  const decimal_js_1 = __importDefault(require("decimal.js"));
9
9
  exports.BASKETS_V3_PROGRAM_ID = new web3_js_1.PublicKey("BASKT7aKd8n7ibpUbwLP3Wiyxyi3yoiXsxBk4Hpumate");
@@ -24,6 +24,7 @@ exports.PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT = new web3_js_1.PublicKey("7UVimffxr9
24
24
  exports.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT = new web3_js_1.PublicKey("Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX");
25
25
  exports.INTENT_TASK_DATA_SIZE = 600;
26
26
  exports.MAX_MANAGERS_PER_BASKET = 10;
27
+ exports.MAX_TRANSFER_TOKENS = 10;
27
28
  exports.X64 = new decimal_js_1.default(2).pow(new decimal_js_1.default(64));
28
29
  exports.HUNDRED_PERCENT_BPS = 10000;
29
30
  exports.WSOL_DECIMALS = 9;
@@ -84,6 +84,8 @@ export declare class SymmetryCore {
84
84
  context: TaskContext;
85
85
  type: TaskType;
86
86
  settings: Settings;
87
+ min_bounty_per_task?: number;
88
+ max_bounty_per_task?: number;
87
89
  jup_swap_ix?: TransactionInstruction;
88
90
  }): Promise<TxPayloadBatchSequence>;
89
91
  executeBasketIntentTx(params: {
@@ -94,6 +96,10 @@ export declare class SymmetryCore {
94
96
  intent: string;
95
97
  manager: string;
96
98
  }): Promise<TxPayloadBatchSequence>;
99
+ cancelRebalanceIntentTx(params: {
100
+ keeper: string;
101
+ rebalance_intent: string;
102
+ }): Promise<TxPayloadBatchSequence>;
97
103
  buyBasketTx(params: {
98
104
  buyer: string;
99
105
  basket_mint: string;
@@ -138,6 +144,7 @@ export declare class SymmetryCore {
138
144
  amount_in: number;
139
145
  amount_out: number;
140
146
  mode?: number;
147
+ jup_token_ledger_ix?: TransactionInstruction;
141
148
  jup_swap_ix?: TransactionInstruction;
142
149
  }): Promise<TxPayloadBatchSequence>;
143
150
  mintTx(params: {
package/dist/src/index.js CHANGED
@@ -26,17 +26,17 @@ const edit_1 = require("./instructions/management/edit");
26
26
  const pda_1 = require("./instructions/pda");
27
27
  const deposit_1 = require("./instructions/user/deposit");
28
28
  const withdraw_1 = require("./instructions/user/withdraw");
29
- const basket_1 = require("./layouts/basket");
30
29
  const fraction_1 = require("./layouts/fraction");
31
30
  const intent_1 = require("./layouts/intents/intent");
32
31
  Object.defineProperty(exports, "TaskType", { enumerable: true, get: function () { return intent_1.TaskType; } });
33
32
  const rebalanceIntent_2 = require("./layouts/intents/rebalanceIntent");
34
- const basket_2 = require("./states/basket");
33
+ const basket_1 = require("./states/basket");
35
34
  const intent_2 = require("./states/intents/intent");
36
35
  const rebalanceIntent_3 = require("./states/intents/rebalanceIntent");
37
36
  const txUtils_1 = require("./txUtils");
38
37
  const config_1 = require("./states/config");
39
38
  const flashSwap_1 = require("./instructions/automation/flashSwap");
39
+ const constants_1 = require("./constants");
40
40
  exports.COMPUTE_UNITS = 1000000;
41
41
  exports.PRIORITY_FEE = 100000;
42
42
  exports.JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
@@ -63,32 +63,32 @@ class SymmetryCore {
63
63
  }
64
64
  fetchBasket(basketPubkey) {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
- return yield (0, basket_2.fetchBasket)(this.sdkParams.connection, new web3_js_1.PublicKey(basketPubkey));
66
+ return yield (0, basket_1.fetchBasket)(this.sdkParams.connection, new web3_js_1.PublicKey(basketPubkey));
67
67
  });
68
68
  }
69
69
  fetchMultipleBaskets(basketPubkeys) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
- return yield (0, basket_2.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeys.map(key => new web3_js_1.PublicKey(key)));
71
+ return yield (0, basket_1.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeys.map(key => new web3_js_1.PublicKey(key)));
72
72
  });
73
73
  }
74
74
  fetchAllBaskets(basketFilter) {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
- return yield (0, basket_2.fetchBaskets)(this.sdkParams.connection, basketFilter);
76
+ return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, basketFilter);
77
77
  });
78
78
  }
79
79
  fetchCreatedBaskets(creatorPubkey) {
80
80
  return __awaiter(this, void 0, void 0, function* () {
81
- return yield (0, basket_2.fetchBaskets)(this.sdkParams.connection, { type: "creator", pubkey: creatorPubkey });
81
+ return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "creator", pubkey: creatorPubkey });
82
82
  });
83
83
  }
84
84
  fetchHostedBaskets(hostPubkey) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
- return yield (0, basket_2.fetchBaskets)(this.sdkParams.connection, { type: "host", pubkey: hostPubkey });
86
+ return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "host", pubkey: hostPubkey });
87
87
  });
88
88
  }
89
89
  fetchManagedBaskets(managerPubkey) {
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
- return yield (0, basket_2.fetchBaskets)(this.sdkParams.connection, { type: "manager", pubkey: managerPubkey });
91
+ return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "manager", pubkey: managerPubkey });
92
92
  });
93
93
  }
94
94
  deriveBasketsByMints(mints) {
@@ -115,7 +115,7 @@ class SymmetryCore {
115
115
  }
116
116
  return res;
117
117
  }).filter(mint => mint !== null);
118
- const basketsMap = yield (0, basket_2.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeys);
118
+ const basketsMap = yield (0, basket_1.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeys);
119
119
  let mintsMap = new Map();
120
120
  for (let basket of basketsMap.values()) {
121
121
  mintsMap.set(basket.mint.toBase58(), basket);
@@ -125,7 +125,7 @@ class SymmetryCore {
125
125
  }
126
126
  loadBasketPrice(basket) {
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
- return yield (0, basket_2.loadBasketPrice)(basket, this.sdkParams.connection);
128
+ return yield (0, basket_1.loadBasketPrice)(basket, this.sdkParams.connection);
129
129
  });
130
130
  }
131
131
  fetchIntent(intentPubkey) {
@@ -349,7 +349,7 @@ class SymmetryCore {
349
349
  }
350
350
  openBasketIntentTx(params) {
351
351
  return __awaiter(this, void 0, void 0, function* () {
352
- var _a;
352
+ var _a, _b, _c;
353
353
  let basket = yield this.fetchBasket(params.context.basket);
354
354
  let manager = new web3_js_1.PublicKey(params.context.manager);
355
355
  let useBounty = params.context.use_bounty == false ? false : true;
@@ -377,13 +377,22 @@ class SymmetryCore {
377
377
  default: return new anchor_1.BN(0);
378
378
  }
379
379
  })();
380
+ let globalConfig = yield this.fetchGlobalConfig();
381
+ let bountyWsolAmount = 0;
382
+ if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
383
+ let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
384
+ let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
385
+ if ((_b = params === null || params === void 0 ? void 0 : params.max_bounty_per_task) !== null && _b !== void 0 ? _b : 0 > maxBountyPerTask)
386
+ maxBountyPerTask = (_c = params === null || params === void 0 ? void 0 : params.max_bounty_per_task) !== null && _c !== void 0 ? _c : 0;
387
+ bountyWsolAmount = maxBountyPerTask + boundBounty;
388
+ }
389
+ let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, manager, bountyWsolAmount);
380
390
  let intentSeedArray = web3_js_1.Keypair.generate().publicKey.toBytes();
381
391
  if (editType === intent_1.TaskType.AddToken) {
382
392
  let tokenMint = new web3_js_1.PublicKey(editData.token_mint);
383
393
  intentSeedArray = tokenMint.toBytes();
384
394
  }
385
395
  let intent = (0, pda_1.getIntentPda)(basket.ownAddress, intentSeedArray, editType);
386
- let ixs = [];
387
396
  let openBasketIntentIx = (0, edit_1.createEditBasketIntentIx)({
388
397
  manager: manager,
389
398
  basket: basket,
@@ -397,6 +406,7 @@ class SymmetryCore {
397
406
  let txBatchData = { batches: [[{
398
407
  payer: manager,
399
408
  instructions: [
409
+ ...wsolIxs,
400
410
  openBasketIntentIx,
401
411
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
402
412
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
@@ -453,6 +463,7 @@ class SymmetryCore {
453
463
  }
454
464
  else {
455
465
  txBatchData.batches[0][0].instructions = [
466
+ ...wsolIxs,
456
467
  openBasketIntentIx,
457
468
  executeBasketIntentIx,
458
469
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
@@ -523,11 +534,33 @@ class SymmetryCore {
523
534
  return txPayloadBatchSequence;
524
535
  });
525
536
  }
537
+ cancelRebalanceIntentTx(params) {
538
+ return __awaiter(this, void 0, void 0, function* () {
539
+ let keeper = new web3_js_1.PublicKey(params.keeper);
540
+ let intent = yield this.fetchRebalanceIntent(params.rebalance_intent);
541
+ let ix = (0, rebalanceIntent_1.cancelRebalanceIx)({
542
+ keeper: keeper,
543
+ basket: intent.basket,
544
+ rebalanceIntent: intent.ownAddress,
545
+ });
546
+ let txBatchData = { batches: [[{
547
+ payer: keeper,
548
+ instructions: [
549
+ ix,
550
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
551
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
552
+ ],
553
+ lookupTables: [],
554
+ }]] };
555
+ let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
556
+ let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
557
+ return txPayloadBatchSequence;
558
+ });
559
+ }
526
560
  buyBasketTx(params) {
527
561
  return __awaiter(this, void 0, void 0, function* () {
528
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
562
+ var _a, _b, _c, _d, _e, _f, _g, _h;
529
563
  let buyer = new web3_js_1.PublicKey(params.buyer);
530
- let basketMint = new web3_js_1.PublicKey(params.basket_mint);
531
564
  let contributions = params.contributions.map(contribution => ({
532
565
  mint: new web3_js_1.PublicKey(contribution.mint),
533
566
  amount: new anchor_1.BN(contribution.amount),
@@ -537,31 +570,43 @@ class SymmetryCore {
537
570
  let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
538
571
  let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
539
572
  let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
540
- const basket = (0, pda_1.getBasketState)(basketMint);
541
- const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
573
+ const basket = yield this.fetchBasket((0, pda_1.getBasketState)(new web3_js_1.PublicKey(params.basket_mint)).toBase58());
574
+ let globalConfig = yield this.fetchGlobalConfig();
575
+ let bountyWsolAmount = 0;
576
+ if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
577
+ let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
578
+ let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
579
+ let bountyPerPriceUpdateTaskDivisor = parseInt(globalConfig.bountyPerPriceUpdateTaskDivisor.toString());
580
+ if (maxBountyAmount > maxBountyPerTask)
581
+ maxBountyPerTask = maxBountyAmount;
582
+ bountyWsolAmount = (0, rebalanceIntent_3.computeRebalanceIntentBountyAmount)(rebalanceIntent_2.RebalanceType.Deposit, basket.numTokens, boundBounty, maxBountyPerTask, Math.floor(maxBountyPerTask / bountyPerPriceUpdateTaskDivisor));
583
+ }
584
+ let wsolContributionAmount = (_g = (_f = params.contributions.find(contribution => contribution.mint === constants_1.MINTS["mainnet"].WSOL.toBase58())) === null || _f === void 0 ? void 0 : _f.amount) !== null && _g !== void 0 ? _g : 0;
585
+ let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, buyer, bountyWsolAmount + wsolContributionAmount);
586
+ const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, buyer);
542
587
  let rentPayer = (0, pda_1.getRentPayerPda)();
543
- let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
588
+ let renPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
544
589
  let rebalanceIntentRentPayer = buyer;
545
590
  // TODO: check actual lamports required for rent
546
- if (((_g = (_f = accountInfos.get(rentPayer.toBase58())) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : 0) > 0)
591
+ if ((_h = renPayerAi === null || renPayerAi === void 0 ? void 0 : renPayerAi.lamports) !== null && _h !== void 0 ? _h : 0 > 0)
547
592
  rebalanceIntentRentPayer = rentPayer;
548
- let basketState = basket_1.BasketLayout.decode((_j = (_h = accountInfos.get(basket.toBase58())) === null || _h === void 0 ? void 0 : _h.data.slice(8)) !== null && _j !== void 0 ? _j : Buffer.alloc(0));
549
- let bountyMint = basketState.settings.bountyMint;
593
+ let bountyMint = basket.settings.bountyMint;
550
594
  let txBatchData = { batches: [
551
595
  [{
552
596
  payer: buyer,
553
597
  instructions: [
598
+ ...wsolIxs,
554
599
  (0, rebalanceIntent_1.createRebalanceIntentIx)({
555
600
  signer: buyer,
556
601
  owner: buyer,
557
- basket: basket,
602
+ basket: basket.ownAddress,
558
603
  }),
559
604
  (0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
560
605
  (0, rebalanceIntent_1.initRebalanceIntentIx)({
561
606
  signer: buyer,
562
607
  owner: buyer,
563
- basket,
564
- basketTokenMint: basketMint,
608
+ basket: basket.ownAddress,
609
+ basketTokenMint: basket.mint,
565
610
  rebalanceIntentRentPayer: rebalanceIntentRentPayer,
566
611
  bountyMint: bountyMint,
567
612
  rebalanceType: rebalanceIntent_2.RebalanceType.Deposit,
@@ -579,7 +624,7 @@ class SymmetryCore {
579
624
  }],
580
625
  (0, deposit_1.depositTokensIx)({
581
626
  owner: buyer,
582
- basket: basket,
627
+ basket: basket.ownAddress,
583
628
  contributions: contributions,
584
629
  }).map(ix => {
585
630
  return {
@@ -597,11 +642,11 @@ class SymmetryCore {
597
642
  instructions: [
598
643
  (0, deposit_1.lockDepositsIx)({
599
644
  owner: buyer,
600
- basket: basket,
645
+ basket: basket.ownAddress,
601
646
  }),
602
647
  executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
603
648
  keeper: buyer,
604
- basket: basket,
649
+ basket: basket.ownAddress,
605
650
  rebalanceIntent: rebalanceIntent,
606
651
  }) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
607
652
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
@@ -617,7 +662,7 @@ class SymmetryCore {
617
662
  }
618
663
  sellBasketTx(params) {
619
664
  return __awaiter(this, void 0, void 0, function* () {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
665
+ var _a, _b, _c, _d, _e, _f;
621
666
  let seller = new web3_js_1.PublicKey(params.seller);
622
667
  let basketMint = new web3_js_1.PublicKey(params.basket_mint);
623
668
  let withdrawAmount = new anchor_1.BN(params.withdraw_amount);
@@ -627,32 +672,41 @@ class SymmetryCore {
627
672
  let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
628
673
  let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
629
674
  let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
630
- const basket = (0, pda_1.getBasketState)(basketMint);
631
- const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, seller);
675
+ const basket = yield this.fetchBasket((0, pda_1.getBasketState)(basketMint).toBase58());
676
+ let globalConfig = yield this.fetchGlobalConfig();
677
+ let bountyWsolAmount = 0;
678
+ if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
679
+ let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
680
+ let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
681
+ let bountyPerPriceUpdateTaskDivisor = parseInt(globalConfig.bountyPerPriceUpdateTaskDivisor.toString());
682
+ if (maxBountyAmount > maxBountyPerTask)
683
+ maxBountyPerTask = maxBountyAmount;
684
+ bountyWsolAmount = (0, rebalanceIntent_3.computeRebalanceIntentBountyAmount)(rebalanceIntent_2.RebalanceType.Deposit, basket.numTokens, boundBounty, maxBountyPerTask, Math.floor(maxBountyPerTask / bountyPerPriceUpdateTaskDivisor));
685
+ }
686
+ let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, seller, bountyWsolAmount);
687
+ const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, seller);
632
688
  let rentPayer = (0, pda_1.getRentPayerPda)();
633
- let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
689
+ let rentPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
634
690
  let rebalanceIntentRentPayer = seller;
635
691
  // TODO: check actual lamports required for rent
636
- if (((_g = (_f = accountInfos.get(rentPayer.toBase58())) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : 0) > 0)
692
+ if ((_f = rentPayerAi === null || rentPayerAi === void 0 ? void 0 : rentPayerAi.lamports) !== null && _f !== void 0 ? _f : 0 > 0)
637
693
  rebalanceIntentRentPayer = rentPayer;
638
- let basketState = basket_1.BasketLayout.decode((_j = (_h = accountInfos.get(basket.toBase58())) === null || _h === void 0 ? void 0 : _h.data.slice(8)) !== null && _j !== void 0 ? _j : Buffer.alloc(0));
639
- let bountyMint = basketState.settings.bountyMint;
640
- ;
694
+ let bountyMint = basket.settings.bountyMint;
641
695
  let keepAllTokensFlag = 1;
642
- for (let i = 0; i < basketState.numTokens; i++) {
643
- if (!keepTokens.includes(basketState.composition[i].mint.toBase58())) {
696
+ for (let i = 0; i < basket.numTokens; i++) {
697
+ if (!keepTokens.includes(basket.composition[i].mint.toBase58())) {
644
698
  keepAllTokensFlag = 0;
645
699
  break;
646
700
  }
647
701
  }
648
- let tokenMintsHash = (0, basket_2.computeTokenMintsHash)(basketState.composition.slice(0, basketState.numTokens)
702
+ let tokenMintsHash = (0, basket_1.computeTokenMintsHash)(basket.composition.slice(0, basket.numTokens)
649
703
  .map(asset => asset.mint.toBase58()));
650
704
  let keepTokensBitmask = new anchor_1.BN(0);
651
705
  if (keepTokens && keepTokens.length > 0) {
652
706
  for (const mint of keepTokens) {
653
707
  let tokenIndex = -1;
654
- for (let i = 0; i < basketState.numTokens; i++) {
655
- if (basketState.composition[i].mint.toBase58() === mint) {
708
+ for (let i = 0; i < basket.numTokens; i++) {
709
+ if (basket.composition[i].mint.toBase58() === mint) {
656
710
  tokenIndex = i;
657
711
  break;
658
712
  }
@@ -663,23 +717,24 @@ class SymmetryCore {
663
717
  keepTokensBitmask = keepTokensBitmask.or(new anchor_1.BN(1).shln(tokenIndex));
664
718
  }
665
719
  }
666
- const basketRebalanceIntent = basketState.settings.activeRebalance > 0
667
- ? (0, pda_1.getRebalanceIntentPda)(basket, basket)
720
+ const basketRebalanceIntent = basket.settings.activeRebalance.gt(new anchor_1.BN(0))
721
+ ? (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, basket.ownAddress)
668
722
  : undefined;
669
723
  let txBatchData = { batches: [
670
724
  [{
671
725
  payer: seller,
672
726
  instructions: [
727
+ ...wsolIxs,
673
728
  (0, rebalanceIntent_1.createRebalanceIntentIx)({
674
729
  signer: seller,
675
730
  owner: seller,
676
- basket: basket,
731
+ basket: basket.ownAddress,
677
732
  }),
678
733
  (0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
679
734
  (0, rebalanceIntent_1.initRebalanceIntentIx)({
680
735
  signer: seller,
681
736
  owner: seller,
682
- basket,
737
+ basket: basket.ownAddress,
683
738
  basketTokenMint: basketMint,
684
739
  rebalanceIntentRentPayer: rebalanceIntentRentPayer,
685
740
  bountyMint: bountyMint,
@@ -705,7 +760,7 @@ class SymmetryCore {
705
760
  instructions: [
706
761
  executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
707
762
  keeper: seller,
708
- basket: basket,
763
+ basket: basket.ownAddress,
709
764
  rebalanceIntent: rebalanceIntent,
710
765
  }) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
711
766
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
@@ -746,6 +801,7 @@ class SymmetryCore {
746
801
  return __awaiter(this, void 0, void 0, function* () {
747
802
  let keeper = new web3_js_1.PublicKey(params.keeper);
748
803
  let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
804
+ let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(new web3_js_1.PublicKey(params.basket), new web3_js_1.PublicKey(params.basket));
749
805
  let basket = yield this.fetchBasket(params.basket);
750
806
  let ixs = [];
751
807
  let batchSize = 7;
@@ -770,6 +826,7 @@ class SymmetryCore {
770
826
  }
771
827
  while (tokenIndices.length < 20)
772
828
  tokenIndices.push(0);
829
+ // TODO: in last instruction we should include performance fee accounts
773
830
  ixs.push((0, priceUpdate_1.updateTokenPricesIx)({
774
831
  keeper: keeper,
775
832
  basket: basket.ownAddress,
@@ -778,6 +835,7 @@ class SymmetryCore {
778
835
  lookupTable1: basket.lookupTables.active[1],
779
836
  tokenIndices: tokenIndices,
780
837
  additionalOracleAccounts: allKeys,
838
+ basketRebalanceIntent: basket.settings.activeRebalance.eq(new anchor_1.BN(0)) ? undefined : basketRebalanceIntent,
781
839
  }));
782
840
  }
783
841
  let txBatchData = { batches: [ixs.map(ix => ({
@@ -818,17 +876,26 @@ class SymmetryCore {
818
876
  };
819
877
  let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
820
878
  let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
879
+ let ixs = [];
880
+ ixs.concat([
881
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
882
+ (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
883
+ ]);
884
+ if (params.jup_token_ledger_ix) {
885
+ ixs.push(params.jup_token_ledger_ix);
886
+ }
887
+ ixs.push(ixWithdraw);
888
+ if (params.jup_swap_ix) {
889
+ ixs.push(params.jup_swap_ix);
890
+ }
891
+ ixs.push(ixDeposit);
892
+ ixs = ixs.concat([
893
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
894
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
895
+ ]);
821
896
  let txBatchData = { batches: [[{
822
897
  payer: keeper,
823
- instructions: [
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,
829
- web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
830
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
831
- ],
898
+ instructions: ixs,
832
899
  lookupTables: [],
833
900
  }]] };
834
901
  let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
@@ -841,11 +908,13 @@ class SymmetryCore {
841
908
  let keeper = new web3_js_1.PublicKey(params.keeper);
842
909
  let rebalanceIntent = yield this.fetchRebalanceIntent(params.rebalance_intent);
843
910
  let basket = yield this.fetchBasket(rebalanceIntent.basket.toBase58());
911
+ let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, rebalanceIntent.owner);
844
912
  let ix = (0, deposit_1.mintBasketIx)({
845
913
  keeper: keeper,
846
914
  basket: basket.ownAddress,
847
915
  basketTokenMint: basket.mint,
848
916
  buyer: rebalanceIntent.owner,
917
+ basketRebalanceIntent: basket.settings.activeRebalance.eq(new anchor_1.BN(0)) ? undefined : basketRebalanceIntent,
849
918
  });
850
919
  let txBatchData = { batches: [[{
851
920
  payer: keeper,
@@ -9,6 +9,7 @@ const pda_1 = require("../pda");
9
9
  const FLASH_WITHDRAW_DISCRIMINATOR = Buffer.from([164, 84, 46, 132, 94, 220, 214, 156]);
10
10
  const FLASH_DEPOSIT_DISCRIMINATOR = Buffer.from([21, 4, 89, 84, 131, 84, 128, 21]);
11
11
  function flashWithdrawIx(params) {
12
+ var _a, _b;
12
13
  const { keeper, basket, mintIn, mintOut, amountIn, amountOut, mode } = params;
13
14
  let keeperFromATA = (0, pda_1.getAta)(keeper, mintIn);
14
15
  let keeperToATA = (0, pda_1.getAta)(keeper, mintOut);
@@ -17,8 +18,8 @@ function flashWithdrawIx(params) {
17
18
  const keys = [
18
19
  { pubkey: params.keeper, isWritable: true, isSigner: true },
19
20
  { 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 },
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 },
22
23
  { pubkey: params.mintIn, isWritable: false, isSigner: false },
23
24
  { pubkey: params.mintOut, isWritable: false, isSigner: false },
24
25
  { pubkey: keeperFromATA, isWritable: true, isSigner: false },
@@ -33,7 +34,7 @@ function flashWithdrawIx(params) {
33
34
  const discriminator = FLASH_WITHDRAW_DISCRIMINATOR;
34
35
  const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
35
36
  const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
36
- const modeBuffer = mode ? Buffer.from([mode]) : Buffer.from([]);
37
+ const modeBuffer = Buffer.from([mode !== null && mode !== void 0 ? mode : 0]);
37
38
  const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
38
39
  return new web3_js_1.TransactionInstruction({
39
40
  keys,
@@ -9,6 +9,7 @@ export declare function updateTokenPricesIx(params: {
9
9
  keeper: PublicKey;
10
10
  basket: PublicKey;
11
11
  rebalanceIntent: PublicKey;
12
+ basketRebalanceIntent?: PublicKey;
12
13
  lookupTable0: PublicKey;
13
14
  lookupTable1: PublicKey;
14
15
  tokenIndices: number[];
@@ -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 })));
@@ -28,5 +28,5 @@ export declare function initRebalanceIntentIx(params: {
28
28
  export declare function cancelRebalanceIx(params: {
29
29
  keeper: PublicKey;
30
30
  basket: PublicKey;
31
- owner: PublicKey;
31
+ rebalanceIntent: PublicKey;
32
32
  }): TransactionInstruction;
@@ -77,7 +77,7 @@ function initRebalanceIntentIx(params) {
77
77
  { pubkey: basket, isSigner: false, isWritable: true },
78
78
  { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
79
79
  { pubkey: rentPayerPda, isSigner: false, isWritable: true },
80
- { pubkey: basketTokenMint, isSigner: false, isWritable: false },
80
+ { pubkey: basketTokenMint, isSigner: false, isWritable: true },
81
81
  { pubkey: signerBasketAta, isSigner: false, isWritable: true },
82
82
  { pubkey: globalConfig, isSigner: false, isWritable: false },
83
83
  { pubkey: bountyMint, isSigner: false, isWritable: false },
@@ -98,8 +98,7 @@ function initRebalanceIntentIx(params) {
98
98
  });
99
99
  }
100
100
  function cancelRebalanceIx(params) {
101
- const { keeper, basket, owner } = params;
102
- const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
101
+ const { keeper, basket, rebalanceIntent } = params;
103
102
  const globalConfig = (0, pda_1.getGlobalConfigPda)();
104
103
  const keys = [
105
104
  { pubkey: keeper, isSigner: true, isWritable: true },
@@ -16,4 +16,5 @@ export declare function mintBasketIx(params: {
16
16
  basket: PublicKey;
17
17
  basketTokenMint: PublicKey;
18
18
  buyer: PublicKey;
19
+ basketRebalanceIntent?: PublicKey;
19
20
  }): TransactionInstruction;
@@ -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 },
@@ -1,15 +1,5 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { TransactionInstruction } from "@solana/web3.js";
3
- export declare function createWithdrawStateIx(params: {
4
- seller: PublicKey;
5
- basket: PublicKey;
6
- basketTokenMint: PublicKey;
7
- withdrawAmount: number;
8
- rebalanceSlippageBps: number;
9
- perTradeRebalanceSlippageBps: number;
10
- executionStartTime: number;
11
- bountyMint: PublicKey;
12
- }): TransactionInstruction;
13
3
  export declare function redeemTokensIx(params: {
14
4
  keeper: PublicKey;
15
5
  basket: PublicKey;