@symmetry-hq/temp-v3-sdk 0.0.15 → 0.0.17

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.
@@ -2,7 +2,8 @@ import { BN } from '@coral-xyz/anchor';
2
2
  import { Connection, PublicKey, TransactionSignature } from '@solana/web3.js';
3
3
  import { Basket } from './layouts/basket';
4
4
  import { GlobalConfig } from './layouts/config';
5
- import { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings, TaskContext, Settings, AddTokenInput, UpdateWeightsInput, MakeDirectSwapInput, TaskType, Intent } from './layouts/intents/intent';
5
+ import { AddTokenInput, OracleInput, EditAddTokenSettings, EditAutomationSettings, EditCreatorSettings, EditCustomRebalanceSettings, EditDepositsSettings, EditFeeSettings, EditForceRebalanceSettings, EditLpSettings, EditMakeDirectSwapSettings, EditManagerSettings, EditMetadataSettings, EditScheduleSettings, EditUpdateWeightsSettings, Intent, MakeDirectSwapInput, Settings, TaskContext, TaskType, UpdateWeightsInput } from './layouts/intents/intent';
6
+ import { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings, FormattedAccumulatedFees, FormattedLookupTables, FormattedAsset, FormattedOracleSettings, FormattedOracleAggregator, FormattedOracle, FormattedBasket } from './layouts/basket';
6
7
  import { RebalanceIntent } from './layouts/intents/rebalanceIntent';
7
8
  import { BasketFilter } from './states/basket';
8
9
  import { IntentFilter } from './states/intents/intent';
@@ -45,26 +46,27 @@ export declare class SymmetryCore {
45
46
  name: string;
46
47
  symbol: string;
47
48
  metadata_uri: string;
48
- host_pubkey: string;
49
- host_deposit_fee_bps: number;
50
- host_withdraw_fee_bps: number;
51
- host_management_fee_bps: number;
52
- host_performance_fee_bps: number;
53
- priority_fee_lamports: number;
49
+ host_platform_params?: {
50
+ host_pubkey: string;
51
+ host_deposit_fee_bps: number;
52
+ host_withdraw_fee_bps: number;
53
+ host_management_fee_bps: number;
54
+ host_performance_fee_bps: number;
55
+ };
54
56
  }): Promise<TxPayloadBatchSequence>;
55
- editCreatorTx(context: TaskContext, settings: FormattedCreatorSettings): Promise<TxPayloadBatchSequence>;
56
- editManagersTx(context: TaskContext, settings: FormattedManagersSettings): Promise<TxPayloadBatchSequence>;
57
- editScheduleTx(context: TaskContext, settings: FormattedScheduleSettings): Promise<TxPayloadBatchSequence>;
58
- editFeesTx(context: TaskContext, settings: FormattedFeeSettings): Promise<TxPayloadBatchSequence>;
59
- editAutomationTx(context: TaskContext, settings: FormattedAutomationSettings): Promise<TxPayloadBatchSequence>;
60
- editLpTx(context: TaskContext, settings: FormattedLpSettings): Promise<TxPayloadBatchSequence>;
61
- editMetadataTx(context: TaskContext, settings: FormattedMetadataSettings): Promise<TxPayloadBatchSequence>;
62
- editDepositsTx(context: TaskContext, settings: FormattedDepositsSettings): Promise<TxPayloadBatchSequence>;
63
- editForceRebalanceTx(context: TaskContext, settings: FormattedForceRebalanceSettings): Promise<TxPayloadBatchSequence>;
64
- editCustomRebalanceTx(context: TaskContext, settings: FormattedCustomRebalanceSettings): Promise<TxPayloadBatchSequence>;
65
- editAddTokenDelayTx(context: TaskContext, settings: FormattedAddTokenSettings): Promise<TxPayloadBatchSequence>;
66
- editUpdateWeightsDelayTx(context: TaskContext, settings: FormattedUpdateWeightsSettings): Promise<TxPayloadBatchSequence>;
67
- editSwapDelayTx(context: TaskContext, settings: FormattedMakeDirectSwapSettings): Promise<TxPayloadBatchSequence>;
57
+ editCreatorTx(context: TaskContext, settings: EditCreatorSettings): Promise<TxPayloadBatchSequence>;
58
+ editManagersTx(context: TaskContext, settings: EditManagerSettings): Promise<TxPayloadBatchSequence>;
59
+ editScheduleTx(context: TaskContext, settings: EditScheduleSettings): Promise<TxPayloadBatchSequence>;
60
+ editFeesTx(context: TaskContext, settings: EditFeeSettings): Promise<TxPayloadBatchSequence>;
61
+ editAutomationTx(context: TaskContext, settings: EditAutomationSettings): Promise<TxPayloadBatchSequence>;
62
+ editLpTx(context: TaskContext, settings: EditLpSettings): Promise<TxPayloadBatchSequence>;
63
+ editMetadataTx(context: TaskContext, settings: EditMetadataSettings): Promise<TxPayloadBatchSequence>;
64
+ editDepositsTx(context: TaskContext, settings: EditDepositsSettings): Promise<TxPayloadBatchSequence>;
65
+ editForceRebalanceTx(context: TaskContext, settings: EditForceRebalanceSettings): Promise<TxPayloadBatchSequence>;
66
+ editCustomRebalanceTx(context: TaskContext, settings: EditCustomRebalanceSettings): Promise<TxPayloadBatchSequence>;
67
+ editAddTokenDelayTx(context: TaskContext, settings: EditAddTokenSettings): Promise<TxPayloadBatchSequence>;
68
+ editUpdateWeightsDelayTx(context: TaskContext, settings: EditUpdateWeightsSettings): Promise<TxPayloadBatchSequence>;
69
+ editSwapDelayTx(context: TaskContext, settings: EditMakeDirectSwapSettings): Promise<TxPayloadBatchSequence>;
68
70
  addTokenTx(context: TaskContext, settings: AddTokenInput): Promise<TxPayloadBatchSequence>;
69
71
  updateWeightsTx(context: TaskContext, settings: UpdateWeightsInput): Promise<TxPayloadBatchSequence>;
70
72
  makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput): Promise<TxPayloadBatchSequence>;
@@ -78,18 +80,28 @@ export declare class SymmetryCore {
78
80
  keeper: PublicKey;
79
81
  }): Promise<TxPayloadBatchSequence>;
80
82
  buyBasketTx(params: {
81
- buyer: PublicKey;
82
- basketMint: PublicKey;
83
+ buyer: string;
84
+ basket_mint: string;
83
85
  contributions: {
84
- mint: PublicKey;
86
+ mint: string;
85
87
  amount: number;
86
88
  }[];
87
- rebalanceSlippageBps?: number;
88
- perTradeRebalanceSlippageBps?: number;
89
- executionStartTime?: number;
90
- minBountyAmount?: number;
91
- maxBountyAmount?: number;
92
- priorityFee?: number;
89
+ rebalance_slippage_bps?: number;
90
+ per_trade_rebalance_slippage_bps?: number;
91
+ execution_start_time?: number;
92
+ min_bounty_amount?: number;
93
+ max_bounty_amount?: number;
94
+ }): Promise<TxPayloadBatchSequence>;
95
+ sellBasketTx(params: {
96
+ seller: string;
97
+ basket_mint: string;
98
+ withdraw_amount: number;
99
+ keep_tokens: string[];
100
+ rebalance_slippage_bps?: number;
101
+ per_trade_rebalance_slippage_bps?: number;
102
+ execution_start_time?: number;
103
+ min_bounty_amount?: number;
104
+ max_bounty_amount?: number;
93
105
  }): Promise<TxPayloadBatchSequence>;
94
106
  updateTokenPricesTx(params: {
95
107
  keeper: PublicKey;
@@ -128,4 +140,5 @@ export declare class SymmetryCore {
128
140
  }): Promise<TransactionSignature[][]>;
129
141
  }
130
142
  export { Basket, BasketFilter, Intent, IntentFilter, RebalanceIntent, RebalanceIntentFilter };
131
- export { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings, AddTokenInput, UpdateWeightsInput, MakeDirectSwapInput, Settings, TaskContext, TaskType, };
143
+ export { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings, FormattedAccumulatedFees, FormattedLookupTables, FormattedAsset, FormattedOracleSettings, FormattedOracleAggregator, FormattedOracle, FormattedBasket, };
144
+ export { EditCreatorSettings, EditManagerSettings, EditFeeSettings, EditScheduleSettings, EditAutomationSettings, EditLpSettings, EditMetadataSettings, EditDepositsSettings, EditForceRebalanceSettings, EditCustomRebalanceSettings, EditAddTokenSettings, EditUpdateWeightsSettings, EditMakeDirectSwapSettings, AddTokenInput, OracleInput, UpdateWeightsInput, MakeDirectSwapInput, Settings, TaskContext, TaskType, };
package/dist/src/index.js CHANGED
@@ -13,11 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TaskType = exports.SymmetryCore = exports.MAX_JUPITER_ACCOUNTS = exports.JUPITER_API_KEY = exports.PRIORITY_FEE = exports.COMPUTE_UNITS = void 0;
16
+ const crypto_1 = require("crypto");
16
17
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
18
  const anchor_1 = require("@coral-xyz/anchor");
19
+ const spl_token_1 = require("@solana/spl-token");
18
20
  const web3_js_1 = require("@solana/web3.js");
19
21
  const claimBounty_1 = require("./instructions/automation/claimBounty");
20
22
  const priceUpdate_1 = require("./instructions/automation/priceUpdate");
23
+ const rebalanceIntent_1 = require("./instructions/automation/rebalanceIntent");
21
24
  const rebalanceSwap_1 = require("./instructions/automation/rebalanceSwap");
22
25
  const admin_1 = require("./instructions/management/admin");
23
26
  const createBasket_1 = require("./instructions/management/createBasket");
@@ -30,13 +33,11 @@ const config_1 = require("./layouts/config");
30
33
  const fraction_1 = require("./layouts/fraction");
31
34
  const intent_1 = require("./layouts/intents/intent");
32
35
  Object.defineProperty(exports, "TaskType", { enumerable: true, get: function () { return intent_1.TaskType; } });
33
- const rebalanceIntent_1 = require("./layouts/intents/rebalanceIntent");
36
+ const rebalanceIntent_2 = require("./layouts/intents/rebalanceIntent");
34
37
  const basket_2 = require("./states/basket");
35
38
  const intent_2 = require("./states/intents/intent");
36
- const rebalanceIntent_2 = require("./states/intents/rebalanceIntent");
39
+ const rebalanceIntent_3 = require("./states/intents/rebalanceIntent");
37
40
  const txUtils_1 = require("./txUtils");
38
- const spl_token_1 = require("@solana/spl-token");
39
- const rebalanceIntent_3 = require("./instructions/automation/rebalanceIntent");
40
41
  exports.COMPUTE_UNITS = 1000000;
41
42
  exports.PRIORITY_FEE = 100000;
42
43
  exports.JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
@@ -134,7 +135,7 @@ class SymmetryCore {
134
135
  }
135
136
  fetchAllRebalanceIntents(filters) {
136
137
  return __awaiter(this, void 0, void 0, function* () {
137
- const rebalanceIntents = yield (0, rebalanceIntent_2.fetchRebalanceIntents)(this.sdkParams.connection, filters);
138
+ const rebalanceIntents = yield (0, rebalanceIntent_3.fetchRebalanceIntents)(this.sdkParams.connection, filters);
138
139
  return rebalanceIntents;
139
140
  });
140
141
  }
@@ -174,14 +175,14 @@ class SymmetryCore {
174
175
  }
175
176
  createBasketTx(params) {
176
177
  return __awaiter(this, void 0, void 0, function* () {
177
- var _a;
178
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
178
179
  const creator = new web3_js_1.PublicKey(params.creator);
179
- const host = new web3_js_1.PublicKey(params.host_pubkey);
180
+ const host = new web3_js_1.PublicKey((_b = (_a = params.host_platform_params) === null || _a === void 0 ? void 0 : _a.host_pubkey) !== null && _b !== void 0 ? _b : params.creator);
180
181
  const hostFees = {
181
- hostDepositFeeBps: params.host_deposit_fee_bps,
182
- hostWithdrawalFeeBps: params.host_withdraw_fee_bps,
183
- hostManagementFeeBps: params.host_management_fee_bps,
184
- hostPerformanceFeeBps: params.host_performance_fee_bps,
182
+ hostDepositFeeBps: (_d = (_c = params.host_platform_params) === null || _c === void 0 ? void 0 : _c.host_deposit_fee_bps) !== null && _d !== void 0 ? _d : 0,
183
+ hostWithdrawalFeeBps: (_f = (_e = params.host_platform_params) === null || _e === void 0 ? void 0 : _e.host_withdraw_fee_bps) !== null && _f !== void 0 ? _f : 0,
184
+ hostManagementFeeBps: (_h = (_g = params.host_platform_params) === null || _g === void 0 ? void 0 : _g.host_management_fee_bps) !== null && _h !== void 0 ? _h : 0,
185
+ hostPerformanceFeeBps: (_k = (_j = params.host_platform_params) === null || _j === void 0 ? void 0 : _j.host_performance_fee_bps) !== null && _k !== void 0 ? _k : 0,
185
186
  };
186
187
  const metadataParams = {
187
188
  name: params.name,
@@ -190,7 +191,7 @@ class SymmetryCore {
190
191
  };
191
192
  const startPrice = (0, fraction_1.decimalToFraction)(new decimal_js_1.default(parseFloat(params.start_price) / 10 ** 6));
192
193
  let globalConfigData = yield this.sdkParams.connection.getAccountInfo((0, pda_1.getGlobalConfigPda)());
193
- let globalConfig = config_1.GlobalConfigLayout.decode((_a = globalConfigData === null || globalConfigData === void 0 ? void 0 : globalConfigData.data.slice(8)) !== null && _a !== void 0 ? _a : Buffer.alloc(0));
194
+ let globalConfig = config_1.GlobalConfigLayout.decode((_l = globalConfigData === null || globalConfigData === void 0 ? void 0 : globalConfigData.data.slice(8)) !== null && _l !== void 0 ? _l : Buffer.alloc(0));
194
195
  let basketId = parseInt(globalConfig.totalNumberOfBaskets.toString());
195
196
  let mint = (0, pda_1.getBasketTokenMintPda)(basketId);
196
197
  let basket = (0, pda_1.getBasketState)(mint);
@@ -414,48 +415,46 @@ class SymmetryCore {
414
415
  }
415
416
  buyBasketTx(params) {
416
417
  return __awaiter(this, void 0, void 0, function* () {
417
- var _a, _b, _c, _d;
418
- let { buyer, basketMint, contributions, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, minBountyAmount, maxBountyAmount, priorityFee, } = params;
419
- if (!rebalanceSlippageBps)
420
- rebalanceSlippageBps = 100;
421
- if (!perTradeRebalanceSlippageBps)
422
- perTradeRebalanceSlippageBps = 100;
423
- if (!executionStartTime)
424
- executionStartTime = 0;
425
- if (!minBountyAmount)
426
- minBountyAmount = 0;
427
- if (!maxBountyAmount)
428
- maxBountyAmount = 0;
429
- if (!priorityFee)
430
- priorityFee = this.sdkParams.priorityFee;
418
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
419
+ let buyer = new web3_js_1.PublicKey(params.buyer);
420
+ let basketMint = new web3_js_1.PublicKey(params.basket_mint);
421
+ let contributions = params.contributions.map(contribution => ({
422
+ mint: new web3_js_1.PublicKey(contribution.mint),
423
+ amount: new anchor_1.BN(contribution.amount),
424
+ }));
425
+ let rebalanceSlippageBps = (_a = params.rebalance_slippage_bps) !== null && _a !== void 0 ? _a : 100;
426
+ let perTradeRebalanceSlippageBps = (_b = params.per_trade_rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
427
+ let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
428
+ let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
429
+ let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
431
430
  const basket = (0, pda_1.getBasketState)(basketMint);
432
431
  const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
433
432
  let rentPayer = (0, pda_1.getRentPayerPda)();
434
433
  let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
435
434
  let rebalanceIntentRentPayer = buyer;
436
435
  // TODO: check actual lamports required for rent
437
- if (((_b = (_a = accountInfos.get(rentPayer.toBase58())) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0)
436
+ if (((_g = (_f = accountInfos.get(rentPayer.toBase58())) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : 0) > 0)
438
437
  rebalanceIntentRentPayer = rentPayer;
439
- let basketState = basket_1.BasketLayout.decode((_d = (_c = accountInfos.get(basket.toBase58())) === null || _c === void 0 ? void 0 : _c.data.slice(8)) !== null && _d !== void 0 ? _d : Buffer.alloc(0));
438
+ 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));
440
439
  let bountyMint = basketState.bountyMint;
441
440
  let txBatchData = { batches: [
442
441
  [{
443
442
  payer: buyer,
444
443
  instructions: [
445
- (0, rebalanceIntent_3.createRebalanceIntentIx)({
444
+ (0, rebalanceIntent_1.createRebalanceIntentIx)({
446
445
  signer: buyer,
447
446
  owner: buyer,
448
447
  basket: basket,
449
448
  }),
450
- (0, rebalanceIntent_3.resizeRebalanceIntentIx)(rebalanceIntent),
451
- (0, rebalanceIntent_3.initRebalanceIntentIx)({
449
+ (0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
450
+ (0, rebalanceIntent_1.initRebalanceIntentIx)({
452
451
  signer: buyer,
453
452
  owner: buyer,
454
453
  basket,
455
454
  basketTokenMint: basketMint,
456
455
  rebalanceIntentRentPayer: rebalanceIntentRentPayer,
457
456
  bountyMint: bountyMint,
458
- rebalanceType: rebalanceIntent_1.RebalanceType.Deposit,
457
+ rebalanceType: rebalanceIntent_2.RebalanceType.Deposit,
459
458
  basketRebalanceIntent: undefined,
460
459
  rebalanceSlippageBps: rebalanceSlippageBps,
461
460
  perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
@@ -506,6 +505,113 @@ class SymmetryCore {
506
505
  return txPayloadBatchSequence;
507
506
  });
508
507
  }
508
+ sellBasketTx(params) {
509
+ return __awaiter(this, void 0, void 0, function* () {
510
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
511
+ let seller = new web3_js_1.PublicKey(params.seller);
512
+ let basketMint = new web3_js_1.PublicKey(params.basket_mint);
513
+ let withdrawAmount = new anchor_1.BN(params.withdraw_amount);
514
+ let keepTokens = (_a = params.keep_tokens) === null || _a === void 0 ? void 0 : _a.map(mint => new web3_js_1.PublicKey(mint));
515
+ let rebalanceSlippageBps = (_b = params.rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
516
+ let perTradeRebalanceSlippageBps = (_c = params.per_trade_rebalance_slippage_bps) !== null && _c !== void 0 ? _c : 100;
517
+ let executionStartTime = (_d = params.execution_start_time) !== null && _d !== void 0 ? _d : 0;
518
+ let minBountyAmount = (_e = params.min_bounty_amount) !== null && _e !== void 0 ? _e : 0;
519
+ let maxBountyAmount = (_f = params.max_bounty_amount) !== null && _f !== void 0 ? _f : 0;
520
+ const basket = (0, pda_1.getBasketState)(basketMint);
521
+ const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, seller);
522
+ let rentPayer = (0, pda_1.getRentPayerPda)();
523
+ let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
524
+ let rebalanceIntentRentPayer = seller;
525
+ // TODO: check actual lamports required for rent
526
+ if (((_h = (_g = accountInfos.get(rentPayer.toBase58())) === null || _g === void 0 ? void 0 : _g.lamports) !== null && _h !== void 0 ? _h : 0) > 0)
527
+ rebalanceIntentRentPayer = rentPayer;
528
+ let basketState = basket_1.BasketLayout.decode((_k = (_j = accountInfos.get(basket.toBase58())) === null || _j === void 0 ? void 0 : _j.data.slice(8)) !== null && _k !== void 0 ? _k : Buffer.alloc(0));
529
+ let bountyMint = basketState.bountyMint;
530
+ let keepAllTokensFlag = 1;
531
+ for (let i = 0; i < basketState.numTokens; i++) {
532
+ if (!keepTokens.includes(basketState.composition[i].mint.toBase58())) {
533
+ keepAllTokensFlag = 0;
534
+ break;
535
+ }
536
+ }
537
+ let tokenMintsHash = Buffer.alloc(32);
538
+ for (let i = 0; i < basketState.numTokens; i++) {
539
+ tokenMintsHash = (0, crypto_1.createHash)('sha256')
540
+ .update(Buffer.concat([tokenMintsHash, basketState.composition[i].mint.toBuffer()]))
541
+ .digest();
542
+ }
543
+ let keepTokensBitmask = new anchor_1.BN(0);
544
+ if (keepTokens && keepTokens.length > 0) {
545
+ for (const mint of keepTokens) {
546
+ let tokenIndex = -1;
547
+ for (let i = 0; i < basketState.numTokens; i++) {
548
+ if (basketState.composition[i].mint.equals(mint)) {
549
+ tokenIndex = i;
550
+ break;
551
+ }
552
+ }
553
+ if (tokenIndex === -1) {
554
+ throw new Error(`Token mint not in basket: ${mint.toBase58()}`);
555
+ }
556
+ keepTokensBitmask = keepTokensBitmask.or(new anchor_1.BN(1).shln(tokenIndex));
557
+ }
558
+ }
559
+ const basketRebalanceIntent = basketState.settings.activeRebalance > 0
560
+ ? (0, pda_1.getRebalanceIntentPda)(basket, basket)
561
+ : undefined;
562
+ let txBatchData = { batches: [
563
+ [{
564
+ payer: seller,
565
+ instructions: [
566
+ (0, rebalanceIntent_1.createRebalanceIntentIx)({
567
+ signer: seller,
568
+ owner: seller,
569
+ basket: basket,
570
+ }),
571
+ (0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
572
+ (0, rebalanceIntent_1.initRebalanceIntentIx)({
573
+ signer: seller,
574
+ owner: seller,
575
+ basket,
576
+ basketTokenMint: basketMint,
577
+ rebalanceIntentRentPayer: rebalanceIntentRentPayer,
578
+ bountyMint: bountyMint,
579
+ rebalanceType: rebalanceIntent_2.RebalanceType.Withdraw,
580
+ basketRebalanceIntent: basketRebalanceIntent,
581
+ rebalanceSlippageBps: rebalanceSlippageBps,
582
+ perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
583
+ executionStartTime: executionStartTime,
584
+ minBountyAmount: minBountyAmount,
585
+ maxBountyAmount: maxBountyAmount,
586
+ withdrawParamsBurnAmount: withdrawAmount,
587
+ withdrawParamsTokenMintsHash: Array.from(tokenMintsHash),
588
+ withdrawParamsKeepTokensBitmask: keepTokensBitmask,
589
+ withdrawParamsKeepAllTokens: keepAllTokensFlag,
590
+ }),
591
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
592
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
593
+ ],
594
+ lookupTables: [],
595
+ }],
596
+ [{
597
+ payer: seller,
598
+ instructions: [
599
+ executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
600
+ keeper: seller,
601
+ basket: basket,
602
+ rebalanceIntent: rebalanceIntent,
603
+ }) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
604
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
605
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
606
+ ],
607
+ lookupTables: [],
608
+ }]
609
+ ] };
610
+ let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
611
+ let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
612
+ return txPayloadBatchSequence;
613
+ });
614
+ }
509
615
  updateTokenPricesTx(params) {
510
616
  return __awaiter(this, void 0, void 0, function* () {
511
617
  let { keeper, rebalanceIntent, basket } = params;
@@ -1,3 +1,4 @@
1
+ import { BN } from '@coral-xyz/anchor';
1
2
  import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
3
  export declare function createRebalanceIntentIx(params: {
3
4
  signer: PublicKey;
@@ -21,7 +22,7 @@ export declare function initRebalanceIntentIx(params: {
21
22
  maxBountyAmount: number;
22
23
  withdrawParamsBurnAmount?: number;
23
24
  withdrawParamsTokenMintsHash?: number[];
24
- withdrawParamsKeepTokensBitmask?: number;
25
+ withdrawParamsKeepTokensBitmask?: BN;
25
26
  withdrawParamsKeepAllTokens?: number;
26
27
  }): TransactionInstruction;
27
28
  export declare function cancelRebalanceIx(params: {
@@ -47,7 +47,7 @@ function resizeRebalanceIntentIx(rebalanceIntent) {
47
47
  });
48
48
  }
49
49
  function initRebalanceIntentIx(params) {
50
- const { signer, owner, basket, basketTokenMint, rebalanceIntentRentPayer, bountyMint, rebalanceType, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, minBountyAmount, maxBountyAmount, withdrawParamsBurnAmount = 0, withdrawParamsTokenMintsHash = new Array(32).fill(0), withdrawParamsKeepTokensBitmask = 0, withdrawParamsKeepAllTokens = 0, basketRebalanceIntent, } = params;
50
+ const { signer, owner, basket, basketTokenMint, rebalanceIntentRentPayer, bountyMint, rebalanceType, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, minBountyAmount, maxBountyAmount, withdrawParamsBurnAmount = 0, withdrawParamsTokenMintsHash = new Array(32).fill(0), withdrawParamsKeepTokensBitmask = new anchor_1.BN(0), withdrawParamsKeepAllTokens = 0, basketRebalanceIntent, } = params;
51
51
  const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
52
52
  const rentPayerPda = (0, pda_1.getRentPayerPda)();
53
53
  const globalConfig = (0, pda_1.getGlobalConfigPda)();
@@ -68,7 +68,7 @@ function initRebalanceIntentIx(params) {
68
68
  Buffer.from(new anchor_1.BN(maxBountyAmount).toArray("le", 8)),
69
69
  Buffer.from(new anchor_1.BN(withdrawParamsBurnAmount).toArray("le", 8)),
70
70
  Buffer.from(withdrawParamsTokenMintsHash),
71
- Buffer.from(new anchor_1.BN(withdrawParamsKeepTokensBitmask).toArray("le", 16)),
71
+ Buffer.from(withdrawParamsKeepTokensBitmask.toArray("le", 16)),
72
72
  Buffer.from([withdrawParamsKeepAllTokens]),
73
73
  ]);
74
74
  const keys = [
@@ -272,7 +272,7 @@ function createEditBasketIntentIx(params) {
272
272
  for (let i = 0; i < addTokenData.oracles.length; i++) {
273
273
  let oracleData = {
274
274
  oracleSettings: {
275
- oracleType: addTokenData.oracles[i].oracle_type,
275
+ oracleType: oracle_1.ORACLE_TYPES.indexOf(addTokenData.oracles[i].oracle_type),
276
276
  numRequiredAccounts: addTokenData.oracles[i].num_required_accounts,
277
277
  weight: addTokenData.oracles[i].weight,
278
278
  isRequired: addTokenData.oracles[i].is_required ? 1 : 0,
@@ -322,9 +322,9 @@ function createEditBasketIntentIx(params) {
322
322
  isWritable: true,
323
323
  isSigner: false
324
324
  });
325
- for (let i = 0; i < addTokenData.oracle_accounts.length; i++) {
325
+ for (let i = 0; i < addTokenData.oracles.length; i++) {
326
326
  additionalAccounts.push({
327
- pubkey: new web3_js_1.PublicKey(addTokenData.oracle_accounts[i]),
327
+ pubkey: new web3_js_1.PublicKey(addTokenData.oracles[i].account),
328
328
  isWritable: false,
329
329
  isSigner: false
330
330
  });
@@ -4,7 +4,88 @@ import { OracleAggregator } from './oracle';
4
4
  import { OraclePrice } from '../states/oracles/oracle';
5
5
  import Decimal from 'decimal.js';
6
6
  import { BasketSettings } from './config';
7
- import { FormattedAddTokenSettings, FormattedAutomationSettings, FormattedCreatorSettings, FormattedCustomRebalanceSettings, FormattedDepositsSettings, FormattedFeeSettings, FormattedForceRebalanceSettings, FormattedLpSettings, FormattedMakeDirectSwapSettings, FormattedManagersSettings, FormattedMetadataSettings, FormattedScheduleSettings, FormattedUpdateWeightsSettings } from './intents/intent';
7
+ import { EditAddTokenSettings, EditAutomationSettings, EditCreatorSettings, EditCustomRebalanceSettings, EditDepositsSettings, EditFeeSettings, EditForceRebalanceSettings, EditLpSettings, EditMakeDirectSwapSettings, EditManagerSettings, EditMetadataSettings, EditScheduleSettings, EditUpdateWeightsSettings, OracleInput } from './intents/intent';
8
+ export interface FormattedAccumulatedFees {
9
+ symmetry_fees: number;
10
+ creator_fees: number;
11
+ host_fees: number;
12
+ managers_fees: number;
13
+ }
14
+ export interface FormattedLookupTables {
15
+ active: {
16
+ pubkey: string;
17
+ contents: string[];
18
+ }[];
19
+ temp: {
20
+ pubkey: string;
21
+ contents: string[];
22
+ }[];
23
+ }
24
+ export interface FormattedOracleSettings extends OracleInput {
25
+ quote: string;
26
+ side: string;
27
+ }
28
+ export interface FormattedOracle {
29
+ oracle_settings: FormattedOracleSettings;
30
+ accounts_to_load_lut_ids: number[];
31
+ accounts_to_load_lut_indices: number[];
32
+ }
33
+ export interface FormattedOracleAggregator {
34
+ num_oracles: number;
35
+ min_oracles_thresh: number;
36
+ oracles: FormattedOracle[];
37
+ min_conf_bps: number;
38
+ conf_thresh_bps: number;
39
+ conf_multiplier: number;
40
+ }
41
+ export interface FormattedAsset {
42
+ mint: string;
43
+ amount: number;
44
+ weight: number;
45
+ active: boolean;
46
+ oracle_aggregator: FormattedOracleAggregator;
47
+ }
48
+ export interface FormattedCreatorSettings extends EditCreatorSettings {
49
+ }
50
+ export interface FormattedManagersSettings extends EditManagerSettings {
51
+ updated_at: number;
52
+ }
53
+ export interface FormattedFeeSettings extends EditFeeSettings {
54
+ host_deposit_fee_bps: number;
55
+ host_withdraw_fee_bps: number;
56
+ host_management_fee_bps: number;
57
+ host_performance_fee_bps: number;
58
+ updated_at: number;
59
+ }
60
+ export interface FormattedScheduleSettings extends EditScheduleSettings {
61
+ updated_at: number;
62
+ }
63
+ export interface FormattedAutomationSettings extends EditAutomationSettings {
64
+ updated_at: number;
65
+ }
66
+ export interface FormattedLpSettings extends EditLpSettings {
67
+ updated_at: number;
68
+ }
69
+ export interface FormattedMetadataSettings extends EditMetadataSettings {
70
+ updated_at: number;
71
+ }
72
+ export interface FormattedDepositsSettings extends EditDepositsSettings {
73
+ }
74
+ export interface FormattedForceRebalanceSettings extends EditForceRebalanceSettings {
75
+ updated_at: number;
76
+ }
77
+ export interface FormattedCustomRebalanceSettings extends EditCustomRebalanceSettings {
78
+ updated_at: number;
79
+ }
80
+ export interface FormattedAddTokenSettings extends EditAddTokenSettings {
81
+ updated_at: number;
82
+ }
83
+ export interface FormattedUpdateWeightsSettings extends EditUpdateWeightsSettings {
84
+ updated_at: number;
85
+ }
86
+ export interface FormattedMakeDirectSwapSettings extends EditMakeDirectSwapSettings {
87
+ updated_at: number;
88
+ }
8
89
  export interface FormattedBasket {
9
90
  pubkey: string;
10
91
  name: string;
@@ -26,90 +107,21 @@ export interface FormattedBasket {
26
107
  active_managements: number;
27
108
  last_automation_execution_timestamp: number;
28
109
  creator_settings: FormattedCreatorSettings;
29
- manager_settings: FormattedManagersSettings & {
30
- updated_at: number;
31
- };
32
- fee_settings: FormattedFeeSettings & {
33
- updated_at: number;
34
- };
35
- schedule_settings: FormattedScheduleSettings & {
36
- updated_at: number;
37
- };
38
- automation_settings: FormattedAutomationSettings & {
39
- updated_at: number;
40
- };
41
- lp_settings: FormattedLpSettings & {
42
- updated_at: number;
43
- };
44
- metadata_settings: FormattedMetadataSettings & {
45
- updated_at: number;
46
- };
110
+ manager_settings: FormattedManagersSettings;
111
+ fee_settings: FormattedFeeSettings;
112
+ schedule_settings: FormattedScheduleSettings;
113
+ automation_settings: FormattedAutomationSettings;
114
+ lp_settings: FormattedLpSettings;
115
+ metadata_settings: FormattedMetadataSettings;
47
116
  deposits_settings: FormattedDepositsSettings;
48
- force_rebalance_settings: FormattedForceRebalanceSettings & {
49
- updated_at: number;
50
- };
51
- custom_rebalance_settings: FormattedCustomRebalanceSettings & {
52
- updated_at: number;
53
- };
54
- add_token_settings: FormattedAddTokenSettings & {
55
- updated_at: number;
56
- };
57
- update_weights_settings: FormattedUpdateWeightsSettings & {
58
- updated_at: number;
59
- };
60
- make_direct_swap_settings: FormattedMakeDirectSwapSettings & {
61
- updated_at: number;
62
- };
63
- accumulated_fees: {
64
- symmetry_fees: number;
65
- creator_fees: number;
66
- host_fees: number;
67
- managers_fees: number;
68
- };
69
- lookup_tables: {
70
- active: {
71
- pubkey: string;
72
- contents: string[];
73
- }[];
74
- temp: {
75
- pubkey: string;
76
- contents: string[];
77
- }[];
78
- };
79
- composition: {
80
- mint: string;
81
- amount: number;
82
- weight: number;
83
- active: boolean;
84
- oracle_aggregator: {
85
- num_oracles: number;
86
- min_oracles_thresh: number;
87
- oracles: {
88
- oracle_settings: {
89
- oracle_type: string;
90
- num_required_accounts: number;
91
- weight: number;
92
- is_required: boolean;
93
- conf_thresh_bps: number;
94
- volatility_thresh_bps: number;
95
- max_slippage_bps: number;
96
- min_liquidity: number;
97
- staleness_thresh: number;
98
- staleness_conf_rate_bps: number;
99
- token_decimals: number;
100
- twap_seconds_ago: number;
101
- twap_secondary_seconds_ago: number;
102
- quote: string;
103
- side: string;
104
- };
105
- accounts_to_load_lut_ids: number[];
106
- accounts_to_load_lut_indices: number[];
107
- }[];
108
- min_conf_bps: number;
109
- conf_thresh_bps: number;
110
- conf_multiplier: number;
111
- };
112
- }[];
117
+ force_rebalance_settings: FormattedForceRebalanceSettings;
118
+ custom_rebalance_settings: FormattedCustomRebalanceSettings;
119
+ add_token_settings: FormattedAddTokenSettings;
120
+ update_weights_settings: FormattedUpdateWeightsSettings;
121
+ make_direct_swap_settings: FormattedMakeDirectSwapSettings;
122
+ accumulated_fees: FormattedAccumulatedFees;
123
+ lookup_tables: FormattedLookupTables;
124
+ composition: FormattedAsset[];
113
125
  }
114
126
  export interface BasketFees {
115
127
  symmetryFees: BN;