@symmetry-hq/temp-v3-sdk 0.0.5 → 0.0.7

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.
@@ -15,7 +15,7 @@ exports.WSOL_MINT = new web3_js_1.PublicKey("So111111111111111111111111111111111
15
15
  exports.USDC_MINT = new web3_js_1.PublicKey("USDCoctVLVnvTXBEuP9s8hntucdJokbo17RwHuNXemT");
16
16
  exports.PYTHNET_CUSTODY_PRICE_WSOL_ACCOUNT = new web3_js_1.PublicKey("7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE");
17
17
  exports.PYTHNET_CUSTODY_PRICE_USDC_ACCOUNT = new web3_js_1.PublicKey("Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX");
18
- exports.BOUNTY_MINT = new web3_js_1.PublicKey("49hY35FvJ8KimFrkGL1X89GSve1C1ZVoLPeQBUHXCouy");
18
+ exports.BOUNTY_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
19
19
  exports.INTENT_TASK_DATA_SIZE = 600;
20
20
  exports.MAX_MANAGERS_PER_BASKET = 10;
21
21
  exports.X64 = new decimal_js_1.default(2).pow(new decimal_js_1.default(64));
@@ -48,6 +48,43 @@ export declare class SymmetryCore {
48
48
  manager: PublicKey;
49
49
  editType: TaskType;
50
50
  }): Promise<VersionedTxs>;
51
+ depositTx(params: {
52
+ buyer: PublicKey;
53
+ basket: PublicKey;
54
+ contributions: {
55
+ mint: PublicKey;
56
+ amount: number;
57
+ }[];
58
+ rebalanceSlippageBps?: number;
59
+ perTradeRebalanceSlippageBps?: number;
60
+ executionStartTime?: number;
61
+ }): Promise<VersionedTxs>;
62
+ updateTokenPricesTx(params: {
63
+ keeper: PublicKey;
64
+ rebalanceIntent: RebalanceIntent;
65
+ basket: Basket;
66
+ }): Promise<VersionedTxs>;
67
+ executeSwap(params: {
68
+ keeper: PublicKey;
69
+ rebalanceIntent: RebalanceIntent;
70
+ mintFrom: PublicKey;
71
+ mintTo: PublicKey;
72
+ amount: number;
73
+ side: number;
74
+ }): Promise<VersionedTxs>;
75
+ mintTx(params: {
76
+ keeper: PublicKey;
77
+ buyer: PublicKey;
78
+ basket: PublicKey;
79
+ }): Promise<VersionedTxs>;
80
+ redeemTokensTx(params: {
81
+ keeper: PublicKey;
82
+ rebalanceIntent: RebalanceIntent;
83
+ }): Promise<VersionedTxs>;
84
+ claimBountyTx(params: {
85
+ keeper: PublicKey;
86
+ rebalanceIntent: RebalanceIntent;
87
+ }): Promise<VersionedTxs>;
51
88
  signAndSendVersionedTxs(params: {
52
89
  vtxs: VersionedTxs;
53
90
  wallet: Wallet;
package/dist/src/index.js CHANGED
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SymmetryCore = exports.MAX_JUPITER_ACCOUNTS = exports.JUPITER_API_KEY = exports.PRIORITY_FEE = exports.COMPUTE_UNITS = void 0;
16
16
  const anchor_1 = require("@coral-xyz/anchor");
17
17
  const web3_js_1 = require("@solana/web3.js");
18
+ const constants_1 = require("./constants");
18
19
  const createBasket_1 = require("./instructions/management/createBasket");
19
20
  const edit_1 = require("./instructions/management/edit");
20
21
  const pda_1 = require("./instructions/pda");
@@ -25,6 +26,11 @@ const intent_2 = require("./states/intents/intent");
25
26
  const rebalanceIntent_1 = require("./states/intents/rebalanceIntent");
26
27
  const txUtils_1 = require("./txUtils");
27
28
  const decimal_js_1 = __importDefault(require("decimal.js"));
29
+ const deposit_1 = require("./instructions/user/deposit");
30
+ const priceUpdate_1 = require("./instructions/automation/priceUpdate");
31
+ const rebalanceSwap_1 = require("./instructions/automation/rebalanceSwap");
32
+ const withdraw_1 = require("./instructions/user/withdraw");
33
+ const claimBounty_1 = require("./instructions/automation/claimBounty");
28
34
  exports.COMPUTE_UNITS = 1000000;
29
35
  exports.PRIORITY_FEE = 100000;
30
36
  exports.JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
@@ -164,6 +170,260 @@ class SymmetryCore {
164
170
  return vtxs;
165
171
  });
166
172
  }
173
+ depositTx(params) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ let { buyer, basket, contributions, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime } = params;
176
+ if (!rebalanceSlippageBps)
177
+ rebalanceSlippageBps = 100;
178
+ if (!perTradeRebalanceSlippageBps)
179
+ perTradeRebalanceSlippageBps = 100;
180
+ if (!executionStartTime)
181
+ executionStartTime = 0;
182
+ let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
183
+ let batchIxs = [
184
+ [
185
+ (0, deposit_1.createUserRebalanceIntentIx)({
186
+ user: params.buyer,
187
+ basket: params.basket,
188
+ }),
189
+ (0, deposit_1.resizeRebalanceIntentIx)(rebalanceIntent),
190
+ (0, deposit_1.depositStateIx)({
191
+ buyer,
192
+ basket,
193
+ bountyMint: constants_1.BOUNTY_MINT,
194
+ rebalanceIntentRentPayer: buyer,
195
+ rebalanceSlippageBps,
196
+ perTradeRebalanceSlippageBps,
197
+ executionStartTime: executionStartTime,
198
+ }),
199
+ ]
200
+ ];
201
+ let depositTokensIxs = (0, deposit_1.depositTokensIx)({
202
+ owner: buyer,
203
+ basket: basket,
204
+ contributions: contributions,
205
+ });
206
+ depositTokensIxs.forEach((ix) => {
207
+ batchIxs.push([ix]);
208
+ });
209
+ batchIxs.push([
210
+ (0, deposit_1.lockDepositsIx)({
211
+ owner: buyer,
212
+ basket: basket,
213
+ }),
214
+ (0, priceUpdate_1.startPriceUpdatesIx)({
215
+ keeper: buyer,
216
+ basket: basket,
217
+ rebalanceIntent: rebalanceIntent,
218
+ }),
219
+ ]);
220
+ // batchIxs = [batchIxs[batchIxs.length - 1]];
221
+ let signers = [];
222
+ let multipleLookupTableAddresses = [];
223
+ for (let i = 0; i < batchIxs.length; i++) {
224
+ signers.push([]);
225
+ multipleLookupTableAddresses.push([]);
226
+ }
227
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
228
+ connection: this.sdkParams.connection,
229
+ payer: buyer,
230
+ priorityFee: this.sdkParams.priorityFee,
231
+ multipleIxs: batchIxs,
232
+ multipleLookupTableAddresses: multipleLookupTableAddresses,
233
+ signers: signers,
234
+ batches: [1, depositTokensIxs.length, 1],
235
+ });
236
+ return vtxs;
237
+ });
238
+ }
239
+ updateTokenPricesTx(params) {
240
+ return __awaiter(this, void 0, void 0, function* () {
241
+ let { keeper, rebalanceIntent, basket } = params;
242
+ let ixs = [];
243
+ let signers = [];
244
+ let multipleLookupTableAddresses = [];
245
+ let batchSize = 7;
246
+ for (let batchStart = 0; batchStart < basket.numTokens; batchStart += batchSize) {
247
+ let allKeys = [];
248
+ let tokenIndices = [];
249
+ for (let i = batchStart; i < basket.numTokens && i < batchStart + batchSize; i++) {
250
+ tokenIndices.push(i);
251
+ let agg = basket.composition[i].oracleAggregator;
252
+ for (let i = 0; i < agg.numOracles; i++) {
253
+ const oracleData = agg.oracles[i];
254
+ for (let j = 0; j < oracleData.oracleSettings.numRequiredAccounts; j++) {
255
+ const lutId = oracleData.accountsToLoadLutIds[j];
256
+ const lutIdx = oracleData.accountsToLoadLutIndices[j];
257
+ if (lutId === 0 && lutIdx === 0)
258
+ continue;
259
+ if (!basket.lutPubkeys)
260
+ continue;
261
+ allKeys.push(basket.lutPubkeys[lutId].state.addresses[lutIdx]);
262
+ }
263
+ }
264
+ }
265
+ while (tokenIndices.length < 20)
266
+ tokenIndices.push(0);
267
+ ixs.push([
268
+ (0, priceUpdate_1.updateTokenPricesIx)({
269
+ keeper: keeper,
270
+ basket: rebalanceIntent.basket, //@ts-ignore
271
+ rebalanceIntent: rebalanceIntent.ownAddress,
272
+ lookupTable0: basket.lookupTables.active[0],
273
+ lookupTable1: basket.lookupTables.active[1],
274
+ tokenIndices: tokenIndices,
275
+ additionalOracleAccounts: allKeys,
276
+ }),
277
+ ]);
278
+ signers.push([]);
279
+ multipleLookupTableAddresses.push([basket.lookupTables.active[0], basket.lookupTables.active[1]]);
280
+ break;
281
+ }
282
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
283
+ connection: this.sdkParams.connection,
284
+ payer: keeper,
285
+ priorityFee: this.sdkParams.priorityFee,
286
+ multipleIxs: ixs,
287
+ multipleLookupTableAddresses: multipleLookupTableAddresses,
288
+ signers: signers,
289
+ batches: [ixs.length],
290
+ });
291
+ return vtxs;
292
+ });
293
+ }
294
+ executeSwap(params) {
295
+ return __awaiter(this, void 0, void 0, function* () {
296
+ let { keeper, rebalanceIntent, mintFrom, mintTo, amount, side } = params;
297
+ let ix = (0, rebalanceSwap_1.rebalanceSwapIx)({
298
+ keeper: keeper,
299
+ basket: rebalanceIntent.basket,
300
+ mintFrom: mintFrom,
301
+ mintTo: mintTo,
302
+ amount: amount,
303
+ side: side,
304
+ });
305
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
306
+ connection: this.sdkParams.connection,
307
+ payer: keeper,
308
+ priorityFee: this.sdkParams.priorityFee,
309
+ multipleIxs: [[ix]],
310
+ multipleLookupTableAddresses: [],
311
+ signers: [[]],
312
+ batches: [1],
313
+ });
314
+ return vtxs;
315
+ });
316
+ }
317
+ mintTx(params) {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ let { keeper, buyer, basket } = params;
320
+ let ix = (0, deposit_1.mintBasketIx)({
321
+ keeper: keeper,
322
+ basket: basket,
323
+ buyer: buyer,
324
+ });
325
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
326
+ connection: this.sdkParams.connection,
327
+ payer: keeper,
328
+ priorityFee: this.sdkParams.priorityFee,
329
+ multipleIxs: [[ix]],
330
+ multipleLookupTableAddresses: [],
331
+ signers: [[]],
332
+ batches: [1],
333
+ });
334
+ return vtxs;
335
+ });
336
+ }
337
+ redeemTokensTx(params) {
338
+ return __awaiter(this, void 0, void 0, function* () {
339
+ let { keeper, rebalanceIntent } = params;
340
+ let batchSize = 7;
341
+ let ixs = [];
342
+ let signers = [];
343
+ let multipleLookupTableAddresses = [];
344
+ for (let batchStart = 0; batchStart < rebalanceIntent.tokens.length; batchStart += batchSize) {
345
+ let tokenMints = [];
346
+ for (let i = batchStart; i < rebalanceIntent.tokens.length && i < batchStart + batchSize; i++)
347
+ if (rebalanceIntent.tokens[i].amount.gt(new anchor_1.BN(0)))
348
+ tokenMints.push(rebalanceIntent.tokens[i].mint);
349
+ if (tokenMints.length > 0) {
350
+ ixs.push([
351
+ (0, withdraw_1.redeemTokensIx)({
352
+ keeper: keeper,
353
+ basket: rebalanceIntent.basket,
354
+ owner: rebalanceIntent.owner,
355
+ tokenMints: tokenMints,
356
+ })
357
+ ]);
358
+ signers.push([]);
359
+ multipleLookupTableAddresses.push([]);
360
+ }
361
+ }
362
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
363
+ connection: this.sdkParams.connection,
364
+ payer: keeper,
365
+ priorityFee: this.sdkParams.priorityFee,
366
+ multipleIxs: ixs,
367
+ multipleLookupTableAddresses: multipleLookupTableAddresses,
368
+ signers: signers,
369
+ batches: [ixs.length],
370
+ });
371
+ return vtxs;
372
+ });
373
+ }
374
+ claimBountyTx(params) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ let { keeper, rebalanceIntent } = params;
377
+ let keepersArray = [];
378
+ if (!rebalanceIntent.startPriceUpdateTask.completedBy.equals(web3_js_1.PublicKey.default))
379
+ keepersArray.push(rebalanceIntent.startPriceUpdateTask.completedBy);
380
+ if (!rebalanceIntent.finishPriceUpdateTask.completedBy.equals(web3_js_1.PublicKey.default))
381
+ keepersArray.push(rebalanceIntent.finishPriceUpdateTask.completedBy);
382
+ if (!rebalanceIntent.mintBasketTask.completedBy.equals(web3_js_1.PublicKey.default))
383
+ keepersArray.push(rebalanceIntent.mintBasketTask.completedBy);
384
+ for (let i = 0; i < rebalanceIntent.priceUpdateTasks.length; i++)
385
+ if (!rebalanceIntent.priceUpdateTasks[i].completedBy.equals(web3_js_1.PublicKey.default))
386
+ keepersArray.push(rebalanceIntent.priceUpdateTasks[i].completedBy);
387
+ for (let i = 0; i < rebalanceIntent.tokenSettlementTasks.length; i++)
388
+ if (!rebalanceIntent.tokenSettlementTasks[i].completedBy.equals(web3_js_1.PublicKey.default))
389
+ keepersArray.push(rebalanceIntent.tokenSettlementTasks[i].completedBy);
390
+ keepersArray = Array.from(new Set(keepersArray));
391
+ let batchSize = 10;
392
+ let ixs = [];
393
+ let signers = [];
394
+ let multipleLookupTableAddresses = [];
395
+ for (let batchStart = 0; batchStart < keepersArray.length; batchStart += batchSize) {
396
+ let keepers = [];
397
+ for (let i = batchStart; i < keepersArray.length && i < batchStart + batchSize; i++)
398
+ keepers.push(keepersArray[i]);
399
+ if (keepers.length > 0) {
400
+ ixs.push([
401
+ (0, claimBounty_1.claimBountyIx)({
402
+ keeper: keeper,
403
+ basket: rebalanceIntent.basket, //@ts-ignore
404
+ intent: rebalanceIntent.ownAddress,
405
+ bountyMint: rebalanceIntent.bounty.bountyMint,
406
+ bountyDepositor: rebalanceIntent.bounty.bountyDepositor,
407
+ rentPayer: rebalanceIntent.rentPayer,
408
+ keepers: keepers,
409
+ })
410
+ ]);
411
+ signers.push([]);
412
+ multipleLookupTableAddresses.push([]);
413
+ }
414
+ }
415
+ let vtxs = yield (0, txUtils_1.prepareV0Transactions)({
416
+ connection: this.sdkParams.connection,
417
+ payer: keeper,
418
+ priorityFee: this.sdkParams.priorityFee,
419
+ multipleIxs: ixs,
420
+ multipleLookupTableAddresses: multipleLookupTableAddresses,
421
+ signers: signers,
422
+ batches: [ixs.length],
423
+ });
424
+ return vtxs;
425
+ });
426
+ }
167
427
  signAndSendVersionedTxs(params) {
168
428
  return __awaiter(this, void 0, void 0, function* () {
169
429
  let { vtxs, wallet } = params;
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.editPrivateBasketSettingsIx = editPrivateBasketSettingsIx;
4
4
  exports.createEditBasketIntentIx = createEditBasketIntentIx;
5
5
  exports.editBasketIx = editBasketIx;
6
- const intent_1 = require("../../layouts/intents/intent");
7
6
  const web3_js_1 = require("@solana/web3.js");
7
+ const intent_1 = require("../../layouts/intents/intent");
8
+ const web3_js_2 = require("@solana/web3.js");
8
9
  const constants_1 = require("../../constants");
9
10
  const pda_1 = require("../pda");
10
11
  const spl_token_1 = require("@solana/spl-token");
11
12
  const config_1 = require("../../layouts/config");
12
13
  const anchor_1 = require("@coral-xyz/anchor");
13
- const web3_js_2 = require("@solana/web3.js");
14
+ const web3_js_3 = require("@solana/web3.js");
14
15
  const oracle_1 = require("../../layouts/oracle");
15
16
  const EDIT_PRIVATE_BASKET_SETTINGS_DISCRIMINATOR = Buffer.from([202, 54, 138, 17, 3, 104, 128, 229]);
16
17
  const CREATE_EDIT_BASKET_INTENT_DISCRIMINATOR = Buffer.from([82, 150, 58, 227, 153, 129, 20, 30]);
@@ -53,7 +54,7 @@ function editPrivateBasketSettingsIx(params) {
53
54
  { pubkey: globalConfig, isSigner: false, isWritable: false },
54
55
  { pubkey: constants_1.METADATA_PROGRAM_ID, isSigner: false, isWritable: false }
55
56
  ];
56
- return new web3_js_1.TransactionInstruction({
57
+ return new web3_js_2.TransactionInstruction({
57
58
  keys,
58
59
  programId: constants_1.BASKETS_V3_PROGRAM_ID,
59
60
  data
@@ -79,6 +80,10 @@ function createEditBasketIntentIx(params) {
79
80
  break;
80
81
  case intent_1.TaskType.EditManagerSettings: // 3
81
82
  let startIndex = 0;
83
+ while (editData.managerSettings.managersWeightBps.length < config_1.MAX_MANAGERS_PER_BASKET) {
84
+ editData.managerSettings.managersWeightBps.push(0);
85
+ editData.managerSettings.managers.push(web3_js_1.PublicKey.default);
86
+ }
82
87
  for (let i = 0; i < config_1.MAX_MANAGERS_PER_BASKET; i++) {
83
88
  let managerWeight = editData.managerSettings.managersWeightBps[i];
84
89
  editDataBuf.writeUInt16LE(managerWeight, startIndex);
@@ -93,7 +98,9 @@ function createEditBasketIntentIx(params) {
93
98
  intent_1.AuthorityBitmasksLayout.encode(editData.authorityBitmasks, authorityBitmasksBuffer);
94
99
  editDataBuf.set(authorityBitmasksBuffer, startIndex);
95
100
  startIndex += intent_1.AuthorityBitmasksLayout.span;
96
- editDataBuf.writeBigUint64LE(editData.managerSettings.modificationDelay, startIndex);
101
+ let modificationDelayBN = editData.managerSettings.modificationDelay;
102
+ editDataBuf.writeBigUint64LE(BigInt(modificationDelayBN.toString()), startIndex);
103
+ startIndex += 8;
97
104
  break;
98
105
  case intent_1.TaskType.EditAutomationSettings: // 4
99
106
  config_1.AutomationSettingsLayout.encode(editData, editDataBuf);
@@ -111,7 +118,21 @@ function createEditBasketIntentIx(params) {
111
118
  intent_1.UpdateWeightsDelayLayout.encode(editData, editDataBuf);
112
119
  break;
113
120
  case intent_1.TaskType.AddToken: // 9
114
- oracle_1.OracleAggregatorLayout.encode(editData.oracleAggregator, editDataBuf);
121
+ let data = editData.oracleAggregator;
122
+ while (data.oracles.length < constants_1.MAX_ORACLES_PER_TOKEN) {
123
+ data.oracles.push({
124
+ oracleSettings: oracle_1.DEFAULT_ORACLE_SETTINGS,
125
+ accountsToLoadLutIds: [],
126
+ accountsToLoadLutIndices: [],
127
+ });
128
+ }
129
+ for (let i = 0; i < data.oracles.length; i++) {
130
+ while (data.oracles[i].accountsToLoadLutIds.length < oracle_1.MAX_ACCOUNTS_PER_ORACLE) {
131
+ data.oracles[i].accountsToLoadLutIds.push(0);
132
+ data.oracles[i].accountsToLoadLutIndices.push(0);
133
+ }
134
+ }
135
+ oracle_1.OracleAggregatorLayout.encode(data, editDataBuf);
115
136
  additionalAccounts.push({
116
137
  pubkey: editData.tokenMint,
117
138
  isWritable: false,
@@ -132,11 +153,13 @@ function createEditBasketIntentIx(params) {
132
153
  isWritable: true,
133
154
  isSigner: false
134
155
  });
135
- additionalAccounts.push({
136
- pubkey: editData.oracleAccount,
137
- isWritable: false,
138
- isSigner: false
139
- });
156
+ for (let i = 0; i < editData.oracleAccounts.length; i++) {
157
+ additionalAccounts.push({
158
+ pubkey: editData.oracleAccounts[i],
159
+ isWritable: false,
160
+ isSigner: false
161
+ });
162
+ }
140
163
  break;
141
164
  case intent_1.TaskType.UpdateWeights: // 10
142
165
  intent_1.UpdateWeightsLayout.encode(editData, editDataBuf);
@@ -162,13 +185,13 @@ function createEditBasketIntentIx(params) {
162
185
  { pubkey: managerBountyATA, isSigner: false, isWritable: true },
163
186
  { pubkey: bountyVault, isSigner: false, isWritable: true },
164
187
  { pubkey: bountyVaultATA, isSigner: false, isWritable: true },
165
- { pubkey: web3_js_2.SystemProgram.programId, isSigner: false, isWritable: false },
188
+ { pubkey: web3_js_3.SystemProgram.programId, isSigner: false, isWritable: false },
166
189
  { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
167
190
  { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
168
191
  { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
169
192
  ];
170
193
  keys.push(...additionalAccounts);
171
- return new web3_js_1.TransactionInstruction({
194
+ return new web3_js_2.TransactionInstruction({
172
195
  keys,
173
196
  programId: constants_1.BASKETS_V3_PROGRAM_ID,
174
197
  data,
@@ -198,7 +221,7 @@ function editBasketIx(params) {
198
221
  { pubkey: managerBountyATA, isSigner: false, isWritable: true },
199
222
  { pubkey: bountyVault, isSigner: false, isWritable: true },
200
223
  { pubkey: bountyVaultATA, isSigner: false, isWritable: true },
201
- { pubkey: web3_js_2.SystemProgram.programId, isSigner: false, isWritable: false },
224
+ { pubkey: web3_js_3.SystemProgram.programId, isSigner: false, isWritable: false },
202
225
  { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
203
226
  { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
204
227
  { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
@@ -210,7 +233,7 @@ function editBasketIx(params) {
210
233
  keys.push({ pubkey: constants_1.METADATA_PROGRAM_ID, isSigner: false, isWritable: false });
211
234
  }
212
235
  ;
213
- return new web3_js_1.TransactionInstruction({
236
+ return new web3_js_2.TransactionInstruction({
214
237
  keys,
215
238
  programId: constants_1.BASKETS_V3_PROGRAM_ID,
216
239
  data,
@@ -11,6 +11,7 @@ export declare function depositStateIx(params: {
11
11
  bountyMint: PublicKey;
12
12
  rebalanceIntentRentPayer: PublicKey;
13
13
  rebalanceSlippageBps: number;
14
+ perTradeRebalanceSlippageBps: number;
14
15
  executionStartTime: number;
15
16
  }): TransactionInstruction;
16
17
  export declare function depositTokensIx(params: {
@@ -20,7 +21,7 @@ export declare function depositTokensIx(params: {
20
21
  mint: PublicKey;
21
22
  amount: number;
22
23
  }[];
23
- }): TransactionInstruction;
24
+ }): TransactionInstruction[];
24
25
  export declare function lockDepositsIx(params: {
25
26
  owner: PublicKey;
26
27
  basket: PublicKey;
@@ -53,7 +53,7 @@ function resizeRebalanceIntentIx(rebalanceIntent) {
53
53
  });
54
54
  }
55
55
  function depositStateIx(params) {
56
- const { buyer, basket, bountyMint, rebalanceIntentRentPayer, rebalanceSlippageBps, executionStartTime, } = params;
56
+ const { buyer, basket, bountyMint, rebalanceIntentRentPayer, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, } = params;
57
57
  let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
58
58
  let basketTokenMint = (0, pda_1.getBasketTokenMintPda)(basket);
59
59
  let globalConfig = (0, pda_1.getGlobalConfigPda)();
@@ -64,11 +64,13 @@ function depositStateIx(params) {
64
64
  let buyerBasketAta = (0, pda_1.getAta)(buyer, basketTokenMint);
65
65
  const rebalanceIntentRentPayerBuf = rebalanceIntentRentPayer.toBuffer();
66
66
  const rebalanceSlippageBuf = Buffer.from(new anchor_1.BN(rebalanceSlippageBps).toArray("le", 2));
67
+ const perTradeRebalanceSlippageBuf = Buffer.from(new anchor_1.BN(perTradeRebalanceSlippageBps).toArray("le", 2));
67
68
  const executionStartBuf = Buffer.from(new anchor_1.BN(executionStartTime).toArray("le", 8));
68
69
  const data = Buffer.concat([
69
70
  CREATE_DEPOSIT_STATE_DISCRIMINATOR,
70
71
  rebalanceIntentRentPayerBuf,
71
72
  rebalanceSlippageBuf,
73
+ perTradeRebalanceSlippageBuf,
72
74
  executionStartBuf
73
75
  ]);
74
76
  const keys = [
@@ -98,31 +100,40 @@ function depositTokensIx(params) {
98
100
  const { owner, basket, contributions } = params;
99
101
  let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
100
102
  const discriminator = DEPOSIT_TOKENS_DISCRIMINATOR;
101
- const amountsBuffer = Buffer.concat(contributions.map((contribution) => Buffer.from(new anchor_1.BN(contribution.amount).toArray("le", 8))));
102
- const data = Buffer.concat([discriminator, amountsBuffer]);
103
- const keys = [
104
- { pubkey: owner, isSigner: true, isWritable: true },
105
- { pubkey: basket, isSigner: false, isWritable: true },
106
- { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
107
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
108
- { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
109
- { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
110
- { pubkey: web3_js_3.SystemProgram.programId, isSigner: false, isWritable: false },
111
- ];
112
- // remaining accounts
113
- contributions.forEach((contribution) => {
114
- let mint = contribution.mint;
115
- let ownerAta = (0, pda_1.getAta)(owner, mint);
116
- let basketAta = (0, pda_1.getAta)(basket, mint);
117
- keys.push({ pubkey: mint, isSigner: false, isWritable: false });
118
- keys.push({ pubkey: ownerAta, isSigner: false, isWritable: true });
119
- keys.push({ pubkey: basketAta, isSigner: false, isWritable: true });
120
- });
121
- return new web3_js_2.TransactionInstruction({
122
- keys,
123
- programId: constants_1.BASKETS_V3_PROGRAM_ID,
124
- data,
125
- });
103
+ let ixs = [];
104
+ let batch_size = 5;
105
+ for (let i = 0; i < contributions.length; i += batch_size) {
106
+ let batch_contributions = contributions.slice(i, i + batch_size);
107
+ let amounts = batch_contributions.map((contribution) => contribution.amount);
108
+ while (amounts.length < 10)
109
+ amounts.push(0);
110
+ const amountsBuffer = Buffer.concat(amounts.map((amount) => Buffer.from(new anchor_1.BN(amount).toArray("le", 8))));
111
+ const data = Buffer.concat([discriminator, amountsBuffer]);
112
+ const keys = [
113
+ { pubkey: owner, isSigner: true, isWritable: true },
114
+ { pubkey: basket, isSigner: false, isWritable: true },
115
+ { pubkey: rebalanceIntent, isSigner: false, isWritable: true },
116
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
117
+ { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
118
+ { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
119
+ { pubkey: web3_js_3.SystemProgram.programId, isSigner: false, isWritable: false },
120
+ ];
121
+ // remaining accounts
122
+ batch_contributions.forEach((contribution) => {
123
+ let mint = contribution.mint;
124
+ let ownerAta = (0, pda_1.getAta)(owner, mint);
125
+ let basketAta = (0, pda_1.getAta)(basket, mint);
126
+ keys.push({ pubkey: mint, isSigner: false, isWritable: false });
127
+ keys.push({ pubkey: ownerAta, isSigner: false, isWritable: true });
128
+ keys.push({ pubkey: basketAta, isSigner: false, isWritable: true });
129
+ });
130
+ ixs.push(new web3_js_2.TransactionInstruction({
131
+ keys,
132
+ programId: constants_1.BASKETS_V3_PROGRAM_ID,
133
+ data,
134
+ }));
135
+ }
136
+ return ixs;
126
137
  }
127
138
  function lockDepositsIx(params) {
128
139
  const { owner, basket } = params;
@@ -5,6 +5,7 @@ export declare function createWithdrawStateIx(params: {
5
5
  basket: PublicKey;
6
6
  withdrawAmount: number;
7
7
  rebalanceSlippageBps: number;
8
+ perTradeRebalanceSlippageBps: number;
8
9
  executionStartTime: number;
9
10
  bountyMint: PublicKey;
10
11
  }): TransactionInstruction;
@@ -11,7 +11,7 @@ const web3_js_2 = require("@solana/web3.js");
11
11
  const CREATE_WITHDRAW_STATE_DISCRIMINATOR = Buffer.from([161, 45, 253, 59, 110, 240, 65, 3]);
12
12
  const REDEEM_TOKENS_DISCRIMINATOR = Buffer.from([83, 49, 112, 2, 105, 193, 106, 126]);
13
13
  function createWithdrawStateIx(params) {
14
- const { seller, basket, withdrawAmount, rebalanceSlippageBps, executionStartTime, bountyMint, } = params;
14
+ const { seller, basket, withdrawAmount, rebalanceSlippageBps, perTradeRebalanceSlippageBps, executionStartTime, bountyMint, } = params;
15
15
  let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, seller);
16
16
  let rentPayerPda = (0, pda_1.getRentPayerPda)();
17
17
  let basketTokenMint = (0, pda_1.getBasketTokenMintPda)(basket);
@@ -25,6 +25,7 @@ function createWithdrawStateIx(params) {
25
25
  CREATE_WITHDRAW_STATE_DISCRIMINATOR,
26
26
  Buffer.from(new anchor_1.BN(withdrawAmount).toArray("le", 8)),
27
27
  Buffer.from(new anchor_1.BN(rebalanceSlippageBps).toArray("le", 2)),
28
+ Buffer.from(new anchor_1.BN(perTradeRebalanceSlippageBps).toArray("le", 2)),
28
29
  Buffer.from(new anchor_1.BN(executionStartTime).toArray("le", 8)),
29
30
  ]);
30
31
  const keys = [
@@ -67,10 +68,8 @@ function redeemTokensIx(params) {
67
68
  // remaining accounts
68
69
  params.tokenMints.forEach((mint) => {
69
70
  keys.push({ pubkey: mint, isWritable: false, isSigner: false });
70
- const ownerAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, owner);
71
- keys.push({ pubkey: ownerAta, isWritable: true, isSigner: false });
72
- const basketAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, basket);
73
- keys.push({ pubkey: basketAta, isWritable: true, isSigner: false });
71
+ keys.push({ pubkey: (0, pda_1.getAta)(owner, mint), isWritable: true, isSigner: false });
72
+ keys.push({ pubkey: (0, pda_1.getAta)(basket, mint), isWritable: true, isSigner: false });
74
73
  });
75
74
  const discriminator = REDEEM_TOKENS_DISCRIMINATOR;
76
75
  const data = discriminator;