@symmetry-hq/temp-v3-sdk 0.0.33 → 0.0.35

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.
@@ -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,15 +84,21 @@ 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: {
92
+ keeper: string;
90
93
  intent: string;
91
- executor: string;
92
94
  }): Promise<TxPayloadBatchSequence>;
93
95
  cancelBasketIntentTx(params: {
96
+ keeper: string;
94
97
  intent: string;
95
- manager: string;
98
+ }): Promise<TxPayloadBatchSequence>;
99
+ cancelRebalanceIntentTx(params: {
100
+ keeper: string;
101
+ rebalance_intent: string;
96
102
  }): Promise<TxPayloadBatchSequence>;
97
103
  buyBasketTx(params: {
98
104
  buyer: 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 }),
@@ -467,7 +478,7 @@ class SymmetryCore {
467
478
  }
468
479
  executeBasketIntentTx(params) {
469
480
  return __awaiter(this, void 0, void 0, function* () {
470
- let keeper = new web3_js_1.PublicKey(params.executor);
481
+ let keeper = new web3_js_1.PublicKey(params.keeper);
471
482
  let intent = yield this.fetchIntent(params.intent);
472
483
  let basketMint;
473
484
  if (intent.taskType === intent_1.TaskType.EditMetadataSettings) {
@@ -499,10 +510,10 @@ class SymmetryCore {
499
510
  }
500
511
  cancelBasketIntentTx(params) {
501
512
  return __awaiter(this, void 0, void 0, function* () {
502
- let manager = new web3_js_1.PublicKey(params.manager);
513
+ let keeper = new web3_js_1.PublicKey(params.keeper);
503
514
  let intent = yield this.fetchIntent(params.intent);
504
515
  let ix = (0, edit_1.cancelIntentIx)({
505
- keeper: manager,
516
+ keeper: keeper,
506
517
  basket: intent.basket,
507
518
  intent: intent.ownAddress,
508
519
  editType: intent.taskType,
@@ -510,7 +521,30 @@ class SymmetryCore {
510
521
  bountyMint: intent.bounty.bountyMint,
511
522
  });
512
523
  let txBatchData = { batches: [[{
513
- payer: manager,
524
+ payer: keeper,
525
+ instructions: [
526
+ ix,
527
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
528
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
529
+ ],
530
+ lookupTables: [],
531
+ }]] };
532
+ let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
533
+ let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
534
+ return txPayloadBatchSequence;
535
+ });
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,
514
548
  instructions: [
515
549
  ix,
516
550
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
@@ -525,7 +559,7 @@ class SymmetryCore {
525
559
  }
526
560
  buyBasketTx(params) {
527
561
  return __awaiter(this, void 0, void 0, function* () {
528
- var _a, _b, _c, _d, _e, _f;
562
+ var _a, _b, _c, _d, _e, _f, _g, _h;
529
563
  let buyer = new web3_js_1.PublicKey(params.buyer);
530
564
  let contributions = params.contributions.map(contribution => ({
531
565
  mint: new web3_js_1.PublicKey(contribution.mint),
@@ -537,18 +571,31 @@ class SymmetryCore {
537
571
  let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
538
572
  let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
539
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);
540
586
  const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, buyer);
541
587
  let rentPayer = (0, pda_1.getRentPayerPda)();
542
588
  let renPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
543
589
  let rebalanceIntentRentPayer = buyer;
544
590
  // TODO: check actual lamports required for rent
545
- if ((_f = renPayerAi === null || renPayerAi === void 0 ? void 0 : renPayerAi.lamports) !== null && _f !== void 0 ? _f : 0 > 0)
591
+ if ((_h = renPayerAi === null || renPayerAi === void 0 ? void 0 : renPayerAi.lamports) !== null && _h !== void 0 ? _h : 0 > 0)
546
592
  rebalanceIntentRentPayer = rentPayer;
547
593
  let bountyMint = basket.settings.bountyMint;
548
594
  let txBatchData = { batches: [
549
595
  [{
550
596
  payer: buyer,
551
597
  instructions: [
598
+ ...wsolIxs,
552
599
  (0, rebalanceIntent_1.createRebalanceIntentIx)({
553
600
  signer: buyer,
554
601
  owner: buyer,
@@ -615,7 +662,7 @@ class SymmetryCore {
615
662
  }
616
663
  sellBasketTx(params) {
617
664
  return __awaiter(this, void 0, void 0, function* () {
618
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
665
+ var _a, _b, _c, _d, _e, _f;
619
666
  let seller = new web3_js_1.PublicKey(params.seller);
620
667
  let basketMint = new web3_js_1.PublicKey(params.basket_mint);
621
668
  let withdrawAmount = new anchor_1.BN(params.withdraw_amount);
@@ -625,32 +672,41 @@ class SymmetryCore {
625
672
  let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
626
673
  let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
627
674
  let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
628
- const basket = (0, pda_1.getBasketState)(basketMint);
629
- 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);
630
688
  let rentPayer = (0, pda_1.getRentPayerPda)();
631
- let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
689
+ let rentPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
632
690
  let rebalanceIntentRentPayer = seller;
633
691
  // TODO: check actual lamports required for rent
634
- 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)
635
693
  rebalanceIntentRentPayer = rentPayer;
636
- 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));
637
- let bountyMint = basketState.settings.bountyMint;
638
- ;
694
+ let bountyMint = basket.settings.bountyMint;
639
695
  let keepAllTokensFlag = 1;
640
- for (let i = 0; i < basketState.numTokens; i++) {
641
- 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())) {
642
698
  keepAllTokensFlag = 0;
643
699
  break;
644
700
  }
645
701
  }
646
- 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)
647
703
  .map(asset => asset.mint.toBase58()));
648
704
  let keepTokensBitmask = new anchor_1.BN(0);
649
705
  if (keepTokens && keepTokens.length > 0) {
650
706
  for (const mint of keepTokens) {
651
707
  let tokenIndex = -1;
652
- for (let i = 0; i < basketState.numTokens; i++) {
653
- if (basketState.composition[i].mint.toBase58() === mint) {
708
+ for (let i = 0; i < basket.numTokens; i++) {
709
+ if (basket.composition[i].mint.toBase58() === mint) {
654
710
  tokenIndex = i;
655
711
  break;
656
712
  }
@@ -661,23 +717,24 @@ class SymmetryCore {
661
717
  keepTokensBitmask = keepTokensBitmask.or(new anchor_1.BN(1).shln(tokenIndex));
662
718
  }
663
719
  }
664
- const basketRebalanceIntent = basketState.settings.activeRebalance > 0
665
- ? (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)
666
722
  : undefined;
667
723
  let txBatchData = { batches: [
668
724
  [{
669
725
  payer: seller,
670
726
  instructions: [
727
+ ...wsolIxs,
671
728
  (0, rebalanceIntent_1.createRebalanceIntentIx)({
672
729
  signer: seller,
673
730
  owner: seller,
674
- basket: basket,
731
+ basket: basket.ownAddress,
675
732
  }),
676
733
  (0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
677
734
  (0, rebalanceIntent_1.initRebalanceIntentIx)({
678
735
  signer: seller,
679
736
  owner: seller,
680
- basket,
737
+ basket: basket.ownAddress,
681
738
  basketTokenMint: basketMint,
682
739
  rebalanceIntentRentPayer: rebalanceIntentRentPayer,
683
740
  bountyMint: bountyMint,
@@ -703,7 +760,7 @@ class SymmetryCore {
703
760
  instructions: [
704
761
  executionStartTime == 0 ? (0, priceUpdate_1.startPriceUpdatesIx)({
705
762
  keeper: seller,
706
- basket: basket,
763
+ basket: basket.ownAddress,
707
764
  rebalanceIntent: rebalanceIntent,
708
765
  }) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
709
766
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
@@ -819,16 +876,20 @@ class SymmetryCore {
819
876
  };
820
877
  let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
821
878
  let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
822
- let ixs = [
879
+ let ixs = [];
880
+ ixs.concat([
823
881
  (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
824
882
  (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
825
- ixWithdraw,
826
- ];
883
+ ]);
884
+ if (params.jup_token_ledger_ix) {
885
+ ixs.push(params.jup_token_ledger_ix);
886
+ }
887
+ ixs.push(ixWithdraw);
827
888
  if (params.jup_swap_ix) {
828
889
  ixs.push(params.jup_swap_ix);
829
890
  }
891
+ ixs.push(ixDeposit);
830
892
  ixs = ixs.concat([
831
- ixDeposit,
832
893
  web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
833
894
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
834
895
  ]);
@@ -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 },
@@ -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;
@@ -1,56 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWithdrawStateIx = createWithdrawStateIx;
4
3
  exports.redeemTokensIx = redeemTokensIx;
5
4
  const constants_1 = require("../../constants");
6
5
  const spl_token_1 = require("@solana/spl-token");
7
- const anchor_1 = require("@coral-xyz/anchor");
8
6
  const pda_1 = require("../pda");
9
7
  const web3_js_1 = require("@solana/web3.js");
10
8
  const web3_js_2 = require("@solana/web3.js");
11
- const CREATE_WITHDRAW_STATE_DISCRIMINATOR = Buffer.from([161, 45, 253, 59, 110, 240, 65, 3]);
12
9
  const REDEEM_TOKENS_DISCRIMINATOR = Buffer.from([83, 49, 112, 2, 105, 193, 106, 126]);
13
- function createWithdrawStateIx(params) {
14
- const { seller, basket, basketTokenMint, withdrawAmount, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, bountyMint, } = params;
15
- let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, seller);
16
- let rentPayerPda = (0, pda_1.getRentPayerPda)();
17
- let globalConfig = (0, pda_1.getGlobalConfigPda)();
18
- let bountyVault = (0, pda_1.getBountyVaultPda)();
19
- let sellerBasketAta = (0, pda_1.getAta)(seller, basketTokenMint);
20
- let sellerBountyAta = (0, pda_1.getAta)(seller, bountyMint);
21
- let bountyVaultAta = (0, pda_1.getAta)(bountyVault, bountyMint);
22
- let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, basket);
23
- const data = Buffer.concat([
24
- CREATE_WITHDRAW_STATE_DISCRIMINATOR,
25
- Buffer.from(new anchor_1.BN(withdrawAmount).toArray("le", 8)),
26
- Buffer.from(new anchor_1.BN(rebalanceSlippageBps).toArray("le", 2)),
27
- Buffer.from(new anchor_1.BN(perTradeRebalanceSlippageBps).toArray("le", 2)),
28
- Buffer.from(new anchor_1.BN(executionStartTime).toArray("le", 8)),
29
- ]);
30
- const keys = [
31
- { pubkey: seller, isSigner: true, isWritable: true },
32
- { pubkey: basket, isSigner: false, isWritable: true },
33
- { pubkey: basketRebalanceIntent, isSigner: false, isWritable: true },
34
- { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
35
- { pubkey: rentPayerPda, isSigner: false, isWritable: true },
36
- { pubkey: basketTokenMint, isSigner: false, isWritable: false },
37
- { pubkey: sellerBasketAta, isSigner: false, isWritable: true },
38
- { pubkey: globalConfig, isSigner: false, isWritable: false },
39
- { pubkey: bountyMint, isSigner: false, isWritable: false },
40
- { pubkey: sellerBountyAta, isSigner: false, isWritable: true },
41
- { pubkey: bountyVault, isSigner: false, isWritable: true },
42
- { pubkey: bountyVaultAta, isSigner: false, isWritable: true },
43
- { pubkey: web3_js_2.SystemProgram.programId, isSigner: false, isWritable: false },
44
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
45
- { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
46
- { pubkey: rebalanceIntent, isSigner: false, isWritable: false } // remaining accounts
47
- ];
48
- return new web3_js_1.TransactionInstruction({
49
- keys,
50
- programId: constants_1.BASKETS_V3_PROGRAM_ID,
51
- data,
52
- });
53
- }
54
10
  function redeemTokensIx(params) {
55
11
  const { keeper, basket, owner, } = params;
56
12
  let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
@@ -1,5 +1,6 @@
1
1
  import { Connection, PublicKey } from "@solana/web3.js";
2
- import { RebalanceIntent } from "../../layouts/intents/rebalanceIntent";
2
+ import { RebalanceIntent, RebalanceType } from "../../layouts/intents/rebalanceIntent";
3
+ export declare function computeRebalanceIntentBountyAmount(rebalance_type: RebalanceType, num_tokens: number, bounty_bond: number, bounty_per_task: number, bounty_per_price_update_task_max: number): number;
3
4
  export declare function addFieldsToRebalanceIntent(rebalanceIntent: RebalanceIntent): RebalanceIntent;
4
5
  export declare function fetchRebalanceIntent(connection: Connection, rebalanceIntentAddress: PublicKey): Promise<RebalanceIntent>;
5
6
  export declare function fetchRebalanceIntentsMultiple(connection: Connection, rebalanceIntentAddresses: PublicKey[]): Promise<Map<string, RebalanceIntent>>;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.computeRebalanceIntentBountyAmount = computeRebalanceIntentBountyAmount;
12
13
  exports.addFieldsToRebalanceIntent = addFieldsToRebalanceIntent;
13
14
  exports.fetchRebalanceIntent = fetchRebalanceIntent;
14
15
  exports.fetchRebalanceIntentsMultiple = fetchRebalanceIntentsMultiple;
@@ -18,6 +19,28 @@ const rebalanceIntent_1 = require("../../layouts/intents/rebalanceIntent");
18
19
  const constants_1 = require("../../constants");
19
20
  const fraction_1 = require("../../layouts/fraction");
20
21
  const txUtils_1 = require("../../txUtils");
22
+ function computeRebalanceIntentBountyAmount(rebalance_type, num_tokens, bounty_bond, bounty_per_task, bounty_per_price_update_task_max) {
23
+ let num_tasks = 0;
24
+ num_tasks += 1; // StartPriceUpdates;
25
+ num_tasks += 1; // FinishPriceUpdates;
26
+ num_tasks += 1; // CancelRebalance;
27
+ if (rebalance_type == rebalanceIntent_1.RebalanceType.Deposit) {
28
+ num_tasks += 1; // MintBasket;
29
+ }
30
+ if (rebalance_type == rebalanceIntent_1.RebalanceType.Deposit || rebalance_type == rebalanceIntent_1.RebalanceType.Withdraw) {
31
+ num_tasks += num_tokens; // TokenSettlement;
32
+ }
33
+ else {
34
+ num_tasks += 1; // AuctionCreation;
35
+ }
36
+ let claim_bounty_tasks = (num_tasks + constants_1.MAX_TRANSFER_TOKENS - 1) / constants_1.MAX_TRANSFER_TOKENS;
37
+ let price_update_tasks = num_tokens;
38
+ let tasks = num_tasks + claim_bounty_tasks;
39
+ let bounty_total = bounty_per_price_update_task_max * price_update_tasks +
40
+ bounty_per_task * tasks +
41
+ bounty_bond;
42
+ return bounty_total;
43
+ }
21
44
  function addFieldsToRebalanceIntent(rebalanceIntent) {
22
45
  let numTokens = constants_1.MAX_SUPPORTED_TOKENS_PER_BASKET;
23
46
  while (numTokens > 0 && rebalanceIntent.tokens[numTokens - 1].mint.equals(web3_js_1.PublicKey.default))
@@ -808,9 +808,9 @@ class PythOracle {
808
808
  catch (error) {
809
809
  return new oracle_1.OraclePrice(new decimal_js_1.default(0), new decimal_js_1.default(0), 0);
810
810
  }
811
- let pr = new decimal_js_1.default(state.priceMessage.price.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent));
812
- let ema = new decimal_js_1.default(state.priceMessage.emaPrice.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent));
813
- let cf = new decimal_js_1.default(state.priceMessage.conf.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent));
811
+ let pr = new decimal_js_1.default(state.priceMessage.price.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent - oracleParams.tokenDecimals));
812
+ let ema = new decimal_js_1.default(state.priceMessage.emaPrice.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent - oracleParams.tokenDecimals));
813
+ let cf = new decimal_js_1.default(state.priceMessage.conf.toString()).mul(decimal_js_1.default.pow(10, state.priceMessage.exponent - oracleParams.tokenDecimals));
814
814
  const lastUpdateTimestamp = state.priceMessage.publishTime;
815
815
  // Validate primary price is not zero
816
816
  if (pr.lte(0)) {
@@ -1,5 +1,4 @@
1
- import { AccountInfo } from '@solana/web3.js';
2
- import { Transaction } from '@solana/web3.js';
1
+ import { AccountInfo, Transaction } from '@solana/web3.js';
3
2
  import { AddressLookupTableAccount, Connection, Keypair, PublicKey, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
4
3
  export declare const COMPUTE_UNITS = 1000000;
5
4
  type TransactionSignature = string;
@@ -10,6 +9,7 @@ export interface Wallet {
10
9
  /** Keypair of the configured payer (Node only) */
11
10
  payer?: Keypair;
12
11
  }
12
+ export declare function wrapWsolIxs(connection: Connection, wallet: PublicKey, amount: number): Promise<TransactionInstruction[]>;
13
13
  export interface TxData {
14
14
  payer: PublicKey;
15
15
  instructions: TransactionInstruction[];