@symmetry-hq/sdk 1.0.10 → 1.0.11

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.
package/dist/src/index.js CHANGED
@@ -1538,7 +1538,7 @@ class SymmetryCore {
1538
1538
  payer: keeper,
1539
1539
  instructions: [
1540
1540
  ix,
1541
- web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
1541
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }),
1542
1542
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
1543
1543
  ],
1544
1544
  lookupTables: [vault.lookupTables.active[0], vault.lookupTables.active[1]],
@@ -0,0 +1,32 @@
1
+ import { Connection, PublicKey } from "@solana/web3.js";
2
+ import { Wallet } from "./txUtils";
3
+ import { Basket, UIRebalanceIntent } from ".";
4
+ export declare class RebalanceHandler {
5
+ private params;
6
+ private intent;
7
+ private basket;
8
+ constructor(params: {
9
+ intent: UIRebalanceIntent;
10
+ basket: Basket;
11
+ wallet: Wallet;
12
+ connection: Connection;
13
+ network: "devnet" | "mainnet";
14
+ jupiterApiKey: string;
15
+ maxAllowedAccounts: number;
16
+ priorityFee?: number;
17
+ simulateTransactions?: boolean;
18
+ });
19
+ delay: (ms: number) => Promise<unknown>;
20
+ refresh(): Promise<void>;
21
+ static run(params: {
22
+ intentPubkey: PublicKey;
23
+ wallet: Wallet;
24
+ connection: Connection;
25
+ network: "devnet" | "mainnet";
26
+ jupiterApiKey: string;
27
+ maxAllowedAccounts: number;
28
+ priorityFee?: number;
29
+ simulateTransactions?: boolean;
30
+ }): Promise<void>;
31
+ private execute;
32
+ }
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RebalanceHandler = void 0;
13
+ const web3_js_1 = require("@solana/web3.js");
14
+ const _1 = require(".");
15
+ const rebalanceIntent_1 = require("./states/intents/rebalanceIntent");
16
+ const constants_1 = require("./constants");
17
+ class RebalanceHandler {
18
+ constructor(params) {
19
+ var _a, _b;
20
+ this.delay = (ms) => __awaiter(this, void 0, void 0, function* () { return new Promise(resolve => setTimeout(resolve, ms)); });
21
+ this.params = {
22
+ wallet: params.wallet,
23
+ connection: params.connection,
24
+ symmetryCore: new _1.SymmetryCore({
25
+ connection: params.connection,
26
+ network: params.network,
27
+ priorityFee: (_a = params.priorityFee) !== null && _a !== void 0 ? _a : constants_1.PRIORITY_FEE,
28
+ }),
29
+ network: params.network,
30
+ jupiterApiKey: params.jupiterApiKey,
31
+ maxAllowedAccounts: params.maxAllowedAccounts,
32
+ simulateTransactions: (_b = params.simulateTransactions) !== null && _b !== void 0 ? _b : false,
33
+ };
34
+ this.intent = params.intent;
35
+ this.basket = params.basket;
36
+ }
37
+ refresh() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ this.intent = yield this.params.symmetryCore.fetchRebalanceIntent(this.intent.formatted_data.pubkey);
40
+ this.basket = yield this.params.symmetryCore.fetchBasket(this.intent.formatted_data.basket);
41
+ });
42
+ }
43
+ static run(params) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ var _a;
46
+ let symmetryCore = new _1.SymmetryCore({
47
+ connection: params.connection,
48
+ network: params.network,
49
+ priorityFee: (_a = params.priorityFee) !== null && _a !== void 0 ? _a : constants_1.PRIORITY_FEE,
50
+ });
51
+ let intent = yield symmetryCore.fetchRebalanceIntent(params.intentPubkey.toBase58());
52
+ let basket = yield symmetryCore.fetchBasket(intent.formatted_data.basket);
53
+ let handler = new RebalanceHandler({
54
+ intent, basket,
55
+ wallet: params.wallet,
56
+ connection: params.connection,
57
+ network: params.network,
58
+ jupiterApiKey: params.jupiterApiKey,
59
+ maxAllowedAccounts: params.maxAllowedAccounts,
60
+ simulateTransactions: params.simulateTransactions,
61
+ });
62
+ handler.execute();
63
+ for (let i = 0; i < 20; i++) {
64
+ yield handler.delay(15 * 1000);
65
+ try {
66
+ yield handler.refresh();
67
+ }
68
+ catch (e) {
69
+ break;
70
+ }
71
+ }
72
+ });
73
+ }
74
+ execute() {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ var _a, _b;
77
+ console.log("Starting rebalance handler for intent:", this.intent.formatted_data.pubkey);
78
+ let nextCheckTime = 0;
79
+ let numTriesUpdatePrices = 0;
80
+ let numTriesMint = 0;
81
+ let numTriesRedeemTokens = 0;
82
+ let numTriesClaimBounty = 0;
83
+ let rebalancePairs = [];
84
+ let lastJupQuotesUpdate = 0;
85
+ let jupQuotes = [];
86
+ while (true) {
87
+ if (!this.intent)
88
+ break;
89
+ let intent = this.intent.formatted_data;
90
+ let chainData = this.intent.chain_data;
91
+ let now = Date.now() / 1000;
92
+ if (now < nextCheckTime) {
93
+ yield this.delay(Math.min(30 * 1000, Math.max(0, nextCheckTime - now + 0.2) * 1000));
94
+ continue;
95
+ }
96
+ nextCheckTime = now + 35;
97
+ if (intent.current_action == "not_active") {
98
+ console.log("Intent not active, stopping");
99
+ break;
100
+ }
101
+ if (intent.current_action == "deposit_tokens") {
102
+ console.log("Waiting for deposit...");
103
+ continue;
104
+ }
105
+ if (intent.current_action == "update_prices" && intent.last_action_timestamp > now) {
106
+ nextCheckTime = intent.last_action_timestamp;
107
+ continue;
108
+ }
109
+ if (intent.current_action == "update_prices") {
110
+ if (numTriesUpdatePrices >= 3) {
111
+ console.log("Max retries for update_prices");
112
+ break;
113
+ }
114
+ numTriesUpdatePrices += 1;
115
+ try {
116
+ let tx = yield this.params.symmetryCore.updateTokenPricesTx({
117
+ keeper: this.params.wallet.publicKey.toBase58(),
118
+ basket: intent.basket,
119
+ rebalance_intent: intent.pubkey,
120
+ });
121
+ let res = yield this.params.symmetryCore.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet: this.params.wallet, simulateTransactions: this.params.simulateTransactions });
122
+ console.log("Update Prices:", res);
123
+ }
124
+ catch (e) {
125
+ if (numTriesUpdatePrices == 3) {
126
+ console.log("Stop - update prices failed:", e);
127
+ }
128
+ }
129
+ continue;
130
+ }
131
+ if (intent.auctions[2].end_time > now) {
132
+ let auction0StartTime = intent.auctions[0].start_time;
133
+ let auction0EndTime = intent.auctions[0].end_time;
134
+ let auction1StartTime = intent.auctions[1].start_time;
135
+ let auction1EndTime = intent.auctions[1].end_time;
136
+ let auction2StartTime = intent.auctions[2].start_time;
137
+ let auction2EndTime = intent.auctions[2].end_time;
138
+ rebalancePairs = (0, rebalanceIntent_1.getSwapPairs)(chainData, this.basket);
139
+ if (Date.now() / 1000 > lastJupQuotesUpdate + 60) {
140
+ let usedValue = new Map();
141
+ jupQuotes = [];
142
+ for (let pair of rebalancePairs) {
143
+ let inValue = (_a = usedValue.get(pair.inMint)) !== null && _a !== void 0 ? _a : 0;
144
+ let outValue = (_b = usedValue.get(pair.outMint)) !== null && _b !== void 0 ? _b : 0;
145
+ let swapValue = Math.min(pair.value - inValue, pair.value - outValue);
146
+ if (swapValue < 0.005) {
147
+ jupQuotes.push(undefined);
148
+ continue;
149
+ }
150
+ usedValue.set(pair.inMint, inValue + swapValue);
151
+ usedValue.set(pair.outMint, outValue + swapValue);
152
+ let res = undefined;
153
+ if (this.params.network == "mainnet")
154
+ try {
155
+ res = Object.assign(Object.assign({}, (yield (0, _1.getJupTokenLedgerAndSwapInstructions)({
156
+ keeper: this.params.wallet.publicKey,
157
+ basketMintIn: new web3_js_1.PublicKey(pair.inMint),
158
+ basketMintOut: new web3_js_1.PublicKey(pair.outMint),
159
+ basketAmountIn: pair.inAmount,
160
+ basketAmountOut: pair.outAmount,
161
+ swapMode: "ioc",
162
+ apiKey: this.params.jupiterApiKey,
163
+ maxJupAccounts: this.params.maxAllowedAccounts,
164
+ }))), { inMint: pair.inMint, outMint: pair.outMint });
165
+ }
166
+ catch (_c) { }
167
+ ;
168
+ jupQuotes.push(res);
169
+ }
170
+ }
171
+ for (let index = 0; index < rebalancePairs.length; index++)
172
+ try {
173
+ let pair = rebalancePairs[index];
174
+ let quote = jupQuotes.find(q => q && q.inMint == pair.inMint && q.outMint == pair.outMint);
175
+ if (!quote)
176
+ continue;
177
+ if (pair.value < 0.005)
178
+ continue;
179
+ let { tokenLedgerInstruction, swapInstruction, addressLookupTableAddresses, quoteResponse } = quote;
180
+ if (!quoteResponse)
181
+ continue;
182
+ console.log(pair, "Jup Quote:", parseFloat(quoteResponse.outAmount), "Requested In:", pair.inAmount);
183
+ if (parseFloat(quoteResponse.outAmount) <= pair.inAmount && this.params.network == "mainnet")
184
+ continue;
185
+ try {
186
+ let tx = yield this.params.symmetryCore.flashSwapTx({
187
+ keeper: this.params.wallet.publicKey.toBase58(),
188
+ basket: this.basket.ownAddress.toBase58(),
189
+ rebalance_intent: intent.pubkey,
190
+ mint_in: pair.inMint,
191
+ mint_out: pair.outMint,
192
+ amount_in: pair.inAmount,
193
+ amount_out: pair.outAmount,
194
+ mode: 2,
195
+ jup_token_ledger_ix: tokenLedgerInstruction,
196
+ jup_swap_ix: swapInstruction,
197
+ jup_address_lookup_table_addresses: addressLookupTableAddresses,
198
+ });
199
+ let res = yield this.params.symmetryCore.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet: this.params.wallet, simulateTransactions: this.params.simulateTransactions });
200
+ console.log("Flash Swap:", res);
201
+ rebalancePairs = rebalancePairs.splice(index, 1);
202
+ index -= 1;
203
+ }
204
+ catch (_d) { }
205
+ }
206
+ catch (_e) { }
207
+ nextCheckTime = (Date.now() / 1000) + 10;
208
+ continue;
209
+ }
210
+ if (intent.rebalance_type == "deposit") {
211
+ lastJupQuotesUpdate = 0;
212
+ if (numTriesMint >= 3) {
213
+ console.log("Max retries for mint");
214
+ break;
215
+ }
216
+ numTriesMint += 1;
217
+ try {
218
+ let tx = yield this.params.symmetryCore.mintTx({
219
+ keeper: this.params.wallet.publicKey.toBase58(),
220
+ rebalance_intent: intent.pubkey,
221
+ });
222
+ let res = yield this.params.symmetryCore.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet: this.params.wallet, simulateTransactions: this.params.simulateTransactions });
223
+ console.log("Mint:", res);
224
+ }
225
+ catch (e) {
226
+ if (numTriesMint == 3) {
227
+ console.log("Stop - mint failed:", e);
228
+ }
229
+ }
230
+ continue;
231
+ }
232
+ let hasTokens = intent.tokens.find((token) => token.amount > 0);
233
+ if (hasTokens && intent.rebalance_type == "withdraw") {
234
+ if (numTriesRedeemTokens >= 3) {
235
+ console.log("Max retries for redeem");
236
+ break;
237
+ }
238
+ numTriesRedeemTokens += 1;
239
+ try {
240
+ let tx = yield this.params.symmetryCore.redeemTokensTx({
241
+ keeper: this.params.wallet.publicKey.toBase58(),
242
+ rebalance_intent: intent.pubkey,
243
+ });
244
+ let res = yield this.params.symmetryCore.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet: this.params.wallet, simulateTransactions: this.params.simulateTransactions });
245
+ console.log("Redeem Tokens:", res);
246
+ }
247
+ catch (e) {
248
+ if (numTriesRedeemTokens == 3) {
249
+ console.log("Stop - redeem failed:", e);
250
+ }
251
+ }
252
+ continue;
253
+ }
254
+ if (numTriesClaimBounty >= 3) {
255
+ console.log("Max retries for claim bounty");
256
+ break;
257
+ }
258
+ numTriesClaimBounty += 1;
259
+ try {
260
+ let tx = yield this.params.symmetryCore.claimBountyTx({
261
+ keeper: this.params.wallet.publicKey.toBase58(),
262
+ rebalance_intent: intent.pubkey,
263
+ });
264
+ let res = yield this.params.symmetryCore.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet: this.params.wallet, simulateTransactions: this.params.simulateTransactions });
265
+ console.log("Claim Bounty:", res);
266
+ nextCheckTime = now + 60;
267
+ }
268
+ catch (e) {
269
+ if (numTriesClaimBounty == 3) {
270
+ console.log("Stop - claim bounty failed:", e);
271
+ }
272
+ }
273
+ }
274
+ console.log("Rebalance handler finished for intent:", this.intent.formatted_data.pubkey);
275
+ });
276
+ }
277
+ }
278
+ exports.RebalanceHandler = RebalanceHandler;
package/dist/test.js CHANGED
@@ -51,6 +51,8 @@ function testStates() {
51
51
  console.log("Total withdraw vault fees: ", (yield sdk.fetchAllWithdrawVaultFees()).length);
52
52
  let vault = yield sdk.fetchVault("C2SpNsmPB91ne4JdQRYZZdTJXkMLWyHfMSaZCS9nB33J");
53
53
  vault = yield sdk.loadVaultPrice(vault);
54
+ // console.log((await sdk.fetchAllVaults()).map(v => v.ownAddress.toBase58()));
55
+ // return;
54
56
  // let ri =(await sdk.fetchAllRebalanceIntents())[0];
55
57
  // ri = await sdk.fetchRebalanceIntent(ri.formatted_data.pubkey);
56
58
  // console.log(ri.deposit_data);
@@ -70,7 +72,7 @@ function testStates() {
70
72
  editGlobalConfig: false, // TESTED
71
73
  createVault: false, // TESTED
72
74
  editPrivateVaultSettings: false, // NOT TESTED
73
- addBounty: false, // TESTED
75
+ addBounty: true, // TESTED
74
76
  editCreator: false, // TESTED
75
77
  editManagerSettings: false, // TESTED
76
78
  editFeeSettings: false, // TESTED
@@ -124,7 +126,7 @@ function testStates() {
124
126
  let tx = yield sdk.addBountyTx({
125
127
  keeper: wallet.publicKey.toBase58(),
126
128
  vault: vault.ownAddress.toBase58(),
127
- amount: 250 * 10 ** 6,
129
+ amount: 15 * 10 ** 6,
128
130
  });
129
131
  let res = yield sdk.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet });
130
132
  console.log(res);
@@ -349,8 +351,8 @@ function testStates() {
349
351
  buyer: wallet.publicKey.toBase58(),
350
352
  vault_mint: vault.mint.toBase58(),
351
353
  contributions: [
352
- // {mint: "So11111111111111111111111111111111111111112", amount: 1000000000},
353
- { mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 2000000 },
354
+ { mint: "So11111111111111111111111111111111111111112", amount: 10000000 },
355
+ // {mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 2000000},
354
356
  ],
355
357
  });
356
358
  let res = yield sdk.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet });
@@ -504,8 +506,8 @@ function testStates() {
504
506
  allowWithdraws: 1,
505
507
  maxDepositFeeBps: 1000,
506
508
  maxWithdrawFeeBps: 1000,
507
- maxManagementFeeBps: 2000,
508
- maxPerformanceFeeBps: 2000,
509
+ maxManagementFeeBps: 0,
510
+ maxPerformanceFeeBps: 0,
509
511
  symmetryFeeCollector: new web3_js_1.PublicKey("9A5V7smsUMRNNzvrawbDx3ZexZR3LY1bcEUXUiMJ2bxk"),
510
512
  symmetryDepositFeeBps: 0,
511
513
  symmetryDepositFeeShareBps: 0,
@@ -522,12 +524,12 @@ function testStates() {
522
524
  minBountyForVaultAutomation: new anchor_1.BN(200 * 50 * 10 ** 3),
523
525
  bountyBondAmount: new anchor_1.BN(5 * 50 * 10 ** 3),
524
526
  bountyPerTask: {
525
- minBounty: new anchor_1.BN(1 * 50 * 10 ** 3),
526
- maxBounty: new anchor_1.BN(2 * 50 * 10 ** 3),
527
+ minBounty: new anchor_1.BN(10 * 50 * 10 ** 3),
528
+ maxBounty: new anchor_1.BN(20 * 50 * 10 ** 3),
527
529
  minBountyUntil: new anchor_1.BN(1),
528
530
  maxBountyAfter: new anchor_1.BN(101),
529
531
  },
530
- bountyPerPriceUpdateTaskDivisor: new anchor_1.BN(5),
532
+ bountyPerPriceUpdateTaskDivisor: new anchor_1.BN(3),
531
533
  minRemainingValue: { high: new anchor_1.BN(0), low: new anchor_1.BN("1844674407370955161") },
532
534
  minMintRatio: { high: new anchor_1.BN(0), low: new anchor_1.BN("18444899399302180660") },
533
535
  aprBpsPerYear: 3334,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmetry-hq/sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Symmetry V3 SDK",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
package/src/index.ts CHANGED
@@ -1717,7 +1717,7 @@ export class SymmetryCore {
1717
1717
  payer: keeper,
1718
1718
  instructions: [
1719
1719
  ix,
1720
- ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
1720
+ ComputeBudgetProgram.setComputeUnitLimit({units: 1_400_000}),
1721
1721
  ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
1722
1722
  ],
1723
1723
  lookupTables: [vault.lookupTables.active[0], vault.lookupTables.active[1]],
package/test.ts CHANGED
@@ -49,6 +49,8 @@ async function testStates() {
49
49
 
50
50
  let vault = await sdk.fetchVault("C2SpNsmPB91ne4JdQRYZZdTJXkMLWyHfMSaZCS9nB33J");
51
51
  vault = await sdk.loadVaultPrice(vault);
52
+ // console.log((await sdk.fetchAllVaults()).map(v => v.ownAddress.toBase58()));
53
+ // return;
52
54
  // let ri =(await sdk.fetchAllRebalanceIntents())[0];
53
55
  // ri = await sdk.fetchRebalanceIntent(ri.formatted_data.pubkey);
54
56
  // console.log(ri.deposit_data);
@@ -71,7 +73,7 @@ async function testStates() {
71
73
 
72
74
  createVault: false, // TESTED
73
75
  editPrivateVaultSettings: false, // NOT TESTED
74
- addBounty: false, // TESTED
76
+ addBounty: true, // TESTED
75
77
 
76
78
  editCreator: false, // TESTED
77
79
  editManagerSettings: false, // TESTED
@@ -138,7 +140,7 @@ async function testStates() {
138
140
  let tx = await sdk.addBountyTx({
139
141
  keeper: wallet.publicKey.toBase58(),
140
142
  vault: vault.ownAddress.toBase58(),
141
- amount: 250 * 10 ** 6,
143
+ amount: 15 * 10 ** 6,
142
144
  });
143
145
  let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
144
146
  console.log(res);
@@ -381,8 +383,8 @@ async function testStates() {
381
383
  buyer: wallet.publicKey.toBase58(),
382
384
  vault_mint: vault.mint.toBase58(),
383
385
  contributions: [
384
- // {mint: "So11111111111111111111111111111111111111112", amount: 1000000000},
385
- {mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 2000000},
386
+ {mint: "So11111111111111111111111111111111111111112", amount: 10000000},
387
+ // {mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 2000000},
386
388
  ],
387
389
  });
388
390
  let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
@@ -546,8 +548,8 @@ async function testStates() {
546
548
 
547
549
  maxDepositFeeBps: 1000,
548
550
  maxWithdrawFeeBps: 1000,
549
- maxManagementFeeBps: 2000,
550
- maxPerformanceFeeBps: 2000,
551
+ maxManagementFeeBps: 0,
552
+ maxPerformanceFeeBps: 0,
551
553
 
552
554
  symmetryFeeCollector: new PublicKey("9A5V7smsUMRNNzvrawbDx3ZexZR3LY1bcEUXUiMJ2bxk"),
553
555
  symmetryDepositFeeBps: 0,
@@ -566,12 +568,12 @@ async function testStates() {
566
568
  minBountyForVaultAutomation: new BN(200 * 50 * 10 ** 3),
567
569
  bountyBondAmount: new BN(5 * 50 * 10 ** 3),
568
570
  bountyPerTask: {
569
- minBounty: new BN(1 * 50 * 10 ** 3),
570
- maxBounty: new BN(2 * 50 * 10 ** 3),
571
+ minBounty: new BN(10 * 50 * 10 ** 3),
572
+ maxBounty: new BN(20 * 50 * 10 ** 3),
571
573
  minBountyUntil: new BN(1),
572
574
  maxBountyAfter: new BN(101),
573
575
  },
574
- bountyPerPriceUpdateTaskDivisor: new BN(5),
576
+ bountyPerPriceUpdateTaskDivisor: new BN(3),
575
577
  minRemainingValue: {high: new BN(0), low: new BN("1844674407370955161")},
576
578
  minMintRatio: {high: new BN(0), low: new BN("18444899399302180660")},
577
579
 
@@ -1,11 +0,0 @@
1
- import { BN } from '@coral-xyz/anchor';
2
- import { PublicKey, TransactionInstruction } from '@solana/web3.js';
3
- export declare function rebalanceSwapIx(params: {
4
- keeper: PublicKey;
5
- basket: PublicKey;
6
- mintFrom: PublicKey;
7
- mintTo: PublicKey;
8
- amountIn: BN;
9
- amountOut: BN;
10
- mode: number;
11
- }): TransactionInstruction;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rebalanceSwapIx = rebalanceSwapIx;
4
- const spl_token_1 = require("@solana/spl-token");
5
- const web3_js_1 = require("@solana/web3.js");
6
- const constants_1 = require("../../constants");
7
- const pda_1 = require("../pda");
8
- const REBALANCE_SWAP_DISCRIMINATOR = Buffer.from([101, 122, 61, 201, 21, 165, 177, 213]);
9
- function rebalanceSwapIx(params) {
10
- const { keeper, basket, mintFrom, mintTo, amountIn, amountOut, mode } = params;
11
- let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, keeper); // TODO: incorrect. Pass intent as func param
12
- let keeperFromATA = (0, pda_1.getAta)(keeper, mintFrom);
13
- let keeperToATA = (0, pda_1.getAta)(keeper, mintTo);
14
- let basketFromATA = (0, pda_1.getAta)(basket, mintFrom);
15
- let basketToATA = (0, pda_1.getAta)(basket, mintTo);
16
- const keys = [
17
- { pubkey: params.keeper, isWritable: true, isSigner: true },
18
- { pubkey: params.basket, isWritable: true, isSigner: false },
19
- { pubkey: rebalanceIntent, isWritable: true, isSigner: false },
20
- { pubkey: params.mintFrom, isWritable: false, isSigner: false },
21
- { pubkey: params.mintTo, isWritable: false, isSigner: false },
22
- { pubkey: keeperFromATA, isWritable: true, isSigner: false },
23
- { pubkey: keeperToATA, isWritable: true, isSigner: false },
24
- { pubkey: basketFromATA, isWritable: true, isSigner: false },
25
- { pubkey: basketToATA, isWritable: true, isSigner: false },
26
- { pubkey: (0, pda_1.getGlobalConfigPda)(), isWritable: false, isSigner: false },
27
- { pubkey: web3_js_1.SystemProgram.programId, isWritable: false, isSigner: false },
28
- { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
29
- { pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
30
- { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
31
- ];
32
- const discriminator = REBALANCE_SWAP_DISCRIMINATOR;
33
- const amountInBuffer = Buffer.from(amountIn.toArray("le", 8));
34
- const amountOutBuffer = Buffer.from(amountOut.toArray("le", 8));
35
- const modeBuffer = Buffer.from([mode]);
36
- const data = Buffer.concat([discriminator, amountInBuffer, amountOutBuffer, modeBuffer]);
37
- return new web3_js_1.TransactionInstruction({
38
- keys,
39
- programId: constants_1.BASKETS_V3_PROGRAM_ID,
40
- data,
41
- });
42
- }