@symmetry-hq/temp-v3-sdk 0.0.61 → 0.0.62
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/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +5 -5
- package/dist/src/instructions/management/edit.js +2 -2
- package/dist/src/layouts/intents/intent.d.ts +9 -21
- package/dist/src/layouts/intents/intent.js +0 -1
- package/dist/src/states/intents/intent.js +9 -17
- package/dist/src/states/intents/rebalanceIntent.js +3 -3
- package/dist/src/txUtils.d.ts +1 -1
- package/dist/src/txUtils.js +9 -28
- package/dist/test.js +13 -21
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/index.ts +5 -5
- package/src/instructions/management/edit.ts +2 -2
- package/src/layouts/intents/intent.ts +10 -22
- package/src/states/intents/intent.ts +9 -17
- package/src/states/intents/rebalanceIntent.ts +3 -3
- package/src/txUtils.ts +18 -41
- package/test.ts +13 -21
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +0 -11
- package/dist/src/instructions/automation/rebalanceSwap.js +0 -42
package/dist/src/constants.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
export declare const COMPUTE_UNITS = 1000000;
|
|
4
|
-
export declare const PRIORITY_FEE =
|
|
4
|
+
export declare const PRIORITY_FEE = 25000;
|
|
5
5
|
export declare const BASKETS_V3_PROGRAM_ID: PublicKey;
|
|
6
6
|
export declare const METADATA_PROGRAM_ID: PublicKey;
|
|
7
7
|
export declare const ADDRESS_LOOKUP_TABLE_PROGRAM_ID: PublicKey;
|
package/dist/src/constants.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.UPDATE_TOKEN_PRICES_MAX_ACCOUNTS = exports.LUT_EXTEND_BATCH_SIZE = expor
|
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
9
|
exports.COMPUTE_UNITS = 1000000;
|
|
10
|
-
exports.PRIORITY_FEE =
|
|
10
|
+
exports.PRIORITY_FEE = 25000;
|
|
11
11
|
exports.BASKETS_V3_PROGRAM_ID = new web3_js_1.PublicKey("BASKT7aKd8n7ibpUbwLP3Wiyxyi3yoiXsxBk4Hpumate");
|
|
12
12
|
exports.METADATA_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
13
13
|
exports.ADDRESS_LOOKUP_TABLE_PROGRAM_ID = new web3_js_1.PublicKey("AddressLookupTab1e1111111111111111111111111");
|
package/dist/src/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class SymmetryCore {
|
|
|
17
17
|
* @param params {connection: Connection, network: "devnet" | "mainnet", priorityFee?: number} - The parameters for the SDK.
|
|
18
18
|
* @param params.connection - The connection to the Solana network.
|
|
19
19
|
* @param params.network - The network to use (devnet or mainnet).
|
|
20
|
-
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (
|
|
20
|
+
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (25_000).
|
|
21
21
|
*/
|
|
22
22
|
constructor(params: {
|
|
23
23
|
connection: Connection;
|
package/dist/src/index.js
CHANGED
|
@@ -51,7 +51,7 @@ class SymmetryCore {
|
|
|
51
51
|
* @param params {connection: Connection, network: "devnet" | "mainnet", priorityFee?: number} - The parameters for the SDK.
|
|
52
52
|
* @param params.connection - The connection to the Solana network.
|
|
53
53
|
* @param params.network - The network to use (devnet or mainnet).
|
|
54
|
-
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (
|
|
54
|
+
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (25_000).
|
|
55
55
|
*/
|
|
56
56
|
constructor(params) {
|
|
57
57
|
var _a;
|
|
@@ -772,10 +772,10 @@ class SymmetryCore {
|
|
|
772
772
|
basket: basket.ownAddress,
|
|
773
773
|
rebalanceIntent: undefined,
|
|
774
774
|
intent: intent,
|
|
775
|
-
mintIn: new web3_js_1.PublicKey(editData.
|
|
776
|
-
mintOut: new web3_js_1.PublicKey(editData.
|
|
777
|
-
amountIn: new bn_js_1.default(editData.
|
|
778
|
-
amountOut: new bn_js_1.default(editData.
|
|
775
|
+
mintIn: new web3_js_1.PublicKey(editData.from_token_mint),
|
|
776
|
+
mintOut: new web3_js_1.PublicKey(editData.to_token_mint),
|
|
777
|
+
amountIn: new bn_js_1.default(editData.amount_from),
|
|
778
|
+
amountOut: new bn_js_1.default(editData.amount_to),
|
|
779
779
|
mode: undefined,
|
|
780
780
|
};
|
|
781
781
|
let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
|
|
@@ -338,7 +338,7 @@ function createEditBasketIntentIx(params) {
|
|
|
338
338
|
});
|
|
339
339
|
break;
|
|
340
340
|
case intent_1.TaskType.UpdateWeights: { // 15 - 202
|
|
341
|
-
const updateWeightsData = editData
|
|
341
|
+
const updateWeightsData = editData;
|
|
342
342
|
const weights = updateWeightsData.token_weights.slice(0, constants_1.MAX_SUPPORTED_TOKENS_PER_BASKET);
|
|
343
343
|
while (weights.length < constants_1.MAX_SUPPORTED_TOKENS_PER_BASKET)
|
|
344
344
|
weights.push({ mint: '', weight_bps: 0 });
|
|
@@ -353,7 +353,7 @@ function createEditBasketIntentIx(params) {
|
|
|
353
353
|
break;
|
|
354
354
|
}
|
|
355
355
|
case intent_1.TaskType.MakeDirectSwap: // 16 - 203
|
|
356
|
-
let makeDirectSwapData = editData
|
|
356
|
+
let makeDirectSwapData = editData;
|
|
357
357
|
let makeDirectSwap = {
|
|
358
358
|
fromTokenMint: new web3_js_1.PublicKey(makeDirectSwapData.from_token_mint),
|
|
359
359
|
toTokenMint: new web3_js_1.PublicKey(makeDirectSwapData.to_token_mint),
|
|
@@ -194,28 +194,16 @@ export interface AddOrEditTokenInput {
|
|
|
194
194
|
oracles: OracleInput[];
|
|
195
195
|
}
|
|
196
196
|
export interface UpdateWeightsInput {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
token_weights: {
|
|
203
|
-
mint: string;
|
|
204
|
-
weight_bps: number;
|
|
205
|
-
}[];
|
|
206
|
-
token_mints_hash?: number[];
|
|
207
|
-
};
|
|
197
|
+
token_weights: {
|
|
198
|
+
mint: string;
|
|
199
|
+
weight_bps: number;
|
|
200
|
+
}[];
|
|
201
|
+
token_mints_hash?: number[];
|
|
208
202
|
}
|
|
209
203
|
export interface MakeDirectSwapInput {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
make_direct_swap: {
|
|
215
|
-
from_token_mint: string;
|
|
216
|
-
to_token_mint: string;
|
|
217
|
-
amount_from: number;
|
|
218
|
-
amount_to: number;
|
|
219
|
-
};
|
|
204
|
+
from_token_mint: string;
|
|
205
|
+
to_token_mint: string;
|
|
206
|
+
amount_from: number;
|
|
207
|
+
amount_to: number;
|
|
220
208
|
}
|
|
221
209
|
export type Settings = EditCreatorSettings | EditManagerSettings | EditFeeSettings | EditScheduleSettings | EditAutomationSettings | EditLpSettings | EditMetadataSettings | EditDepositsSettings | EditForceRebalanceSettings | EditCustomRebalanceSettings | EditAddTokenSettings | EditUpdateWeightsSettings | EditMakeDirectSwapSettings | AddOrEditTokenInput | UpdateWeightsInput | MakeDirectSwapInput;
|
|
@@ -201,28 +201,20 @@ function decodeTaskDataForType(intent) {
|
|
|
201
201
|
case intent_1.TaskType.UpdateWeights:
|
|
202
202
|
let updateWeights = config_1.UpdateWeightsLayout.decode(Buffer.from(taskData.slice(0, config_1.UpdateWeightsLayout.getSpan())));
|
|
203
203
|
let update_weights_input = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
weight_bps: weight,
|
|
210
|
-
})),
|
|
211
|
-
token_mints_hash: updateWeights.tokenMintsHash,
|
|
212
|
-
},
|
|
204
|
+
token_weights: updateWeights.tokenWeights.map(weight => ({
|
|
205
|
+
mint: "",
|
|
206
|
+
weight_bps: weight,
|
|
207
|
+
})),
|
|
208
|
+
token_mints_hash: updateWeights.tokenMintsHash,
|
|
213
209
|
};
|
|
214
210
|
return update_weights_input;
|
|
215
211
|
case intent_1.TaskType.MakeDirectSwap:
|
|
216
212
|
let makeDirectSwap = config_1.MakeDirectSwapLayout.decode(Buffer.from(taskData.slice(0, config_1.MakeDirectSwapLayout.getSpan())));
|
|
217
213
|
let make_direct_swap_input = {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
223
|
-
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
224
|
-
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
225
|
-
},
|
|
214
|
+
from_token_mint: makeDirectSwap.fromTokenMint.toBase58(),
|
|
215
|
+
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
216
|
+
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
217
|
+
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
226
218
|
};
|
|
227
219
|
return make_direct_swap_input;
|
|
228
220
|
default:
|
|
@@ -91,9 +91,9 @@ function formatRebalanceIntent(rebalanceIntent, basket) {
|
|
|
91
91
|
completed_time: parseInt(rebalanceIntent.mintBasketTask.completedTime.toString()),
|
|
92
92
|
};
|
|
93
93
|
let cancelRebalanceTask = {
|
|
94
|
-
completed_by: rebalanceIntent.
|
|
95
|
-
completed_bounty: parseInt(rebalanceIntent.
|
|
96
|
-
completed_time: parseInt(rebalanceIntent.
|
|
94
|
+
completed_by: rebalanceIntent.cancelRebalanceTask.completedBy.toBase58(),
|
|
95
|
+
completed_bounty: parseInt(rebalanceIntent.cancelRebalanceTask.completedBounty.toString()),
|
|
96
|
+
completed_time: parseInt(rebalanceIntent.cancelRebalanceTask.completedTime.toString()),
|
|
97
97
|
};
|
|
98
98
|
let tasks = [
|
|
99
99
|
placeholderTask,
|
package/dist/src/txUtils.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare function getAddressLookupTableAccounts(connection: Connection, ke
|
|
|
57
57
|
export declare function getMultipleAddressLookupTableAccounts(connection: Connection, batches: PublicKey[][][]): Promise<AddressLookupTableAccount[][][]>;
|
|
58
58
|
export declare function compileVersionedTransaction(blockhash: string, addressLookupTableAccounts: AddressLookupTableAccount[], payerPubkey: PublicKey, ixs: TransactionInstruction[]): VersionedTransaction;
|
|
59
59
|
export declare function sendVersionedTransaction(connection: Connection, tx: VersionedTransaction, blockhash: string, lastValidBlockHeight: number, simulateTransactions: boolean): Promise<TransactionSignature>;
|
|
60
|
-
export declare function prepareVersionedTxs(connection: Connection, txBatchData: TxBatchData
|
|
60
|
+
export declare function prepareVersionedTxs(connection: Connection, txBatchData: TxBatchData): Promise<VersionedTxs>;
|
|
61
61
|
export declare function sendVersionedTxs(connection: Connection, versionedTxs: VersionedTxs, simulateTransactions?: boolean): Promise<TransactionSignature[][]>;
|
|
62
62
|
export declare function signVersionedTxs(wallet: Wallet, versionedTxs: VersionedTxs): Promise<VersionedTxs>;
|
|
63
63
|
export declare function signTxPayloadBatchSequence(wallet: Wallet, txPayloadBatchSequence: TxPayloadBatchSequence): Promise<TxPayloadBatchSequence>;
|
package/dist/src/txUtils.js
CHANGED
|
@@ -175,10 +175,16 @@ function sendVersionedTransaction(connection, tx, blockhash, lastValidBlockHeigh
|
|
|
175
175
|
console.log(e.message);
|
|
176
176
|
throw new Error("Simulation failed");
|
|
177
177
|
});
|
|
178
|
+
for (let i = 0; i < 4; i++) {
|
|
179
|
+
yield delay(3000).then(() => connection.sendRawTransaction(serializedTx, { preflightCommitment: "confirmed", maxRetries: 0 }).catch(() => { }));
|
|
180
|
+
}
|
|
178
181
|
console.log("Simulation txId:", txId);
|
|
179
182
|
}
|
|
180
183
|
else {
|
|
181
184
|
txId = yield connection.sendRawTransaction(serializedTx, { skipPreflight: true, maxRetries: 0 });
|
|
185
|
+
for (let i = 0; i < 4; i++) {
|
|
186
|
+
yield delay(3000).then(() => connection.sendRawTransaction(serializedTx, { preflightCommitment: "confirmed", maxRetries: 0 }).catch(() => { }));
|
|
187
|
+
}
|
|
182
188
|
console.log("Sending tx:", txId);
|
|
183
189
|
}
|
|
184
190
|
let confirmation = null;
|
|
@@ -212,32 +218,8 @@ function sendVersionedTransaction(connection, tx, blockhash, lastValidBlockHeigh
|
|
|
212
218
|
return txId;
|
|
213
219
|
});
|
|
214
220
|
}
|
|
215
|
-
|
|
216
|
-
function
|
|
217
|
-
return ix.programId.equals(web3_js_2.ComputeBudgetProgram.programId);
|
|
218
|
-
}
|
|
219
|
-
function isSetComputeUnitPriceInstruction(ix) {
|
|
220
|
-
return ix.data.length > 0 && ix.data[0] === COMPUTE_BUDGET_SET_COMPUTE_UNIT_PRICE_INSTRUCTION;
|
|
221
|
-
}
|
|
222
|
-
function normalizeComputeBudgetInstructions(instructions, priorityFeeMicroLamports) {
|
|
223
|
-
const computeBudgetInstructions = [];
|
|
224
|
-
const regularInstructions = [];
|
|
225
|
-
for (const instruction of instructions) {
|
|
226
|
-
if (isComputeBudgetInstruction(instruction)) {
|
|
227
|
-
computeBudgetInstructions.push(instruction);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
regularInstructions.push(instruction);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!computeBudgetInstructions.some(isSetComputeUnitPriceInstruction)) {
|
|
234
|
-
computeBudgetInstructions.push(web3_js_2.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFeeMicroLamports }));
|
|
235
|
-
}
|
|
236
|
-
// Best practice: put compute budget instructions first.
|
|
237
|
-
return [...computeBudgetInstructions, ...regularInstructions];
|
|
238
|
-
}
|
|
239
|
-
function prepareVersionedTxs(connection_1, txBatchData_1) {
|
|
240
|
-
return __awaiter(this, arguments, void 0, function* (connection, txBatchData, priorityFeeMicroLamports = constants_1.PRIORITY_FEE) {
|
|
221
|
+
function prepareVersionedTxs(connection, txBatchData) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
223
|
const { batches } = txBatchData;
|
|
242
224
|
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash("confirmed");
|
|
243
225
|
let multipleLookupTableAddresses = batches.map(batch => batch.map(txData => txData.lookupTables));
|
|
@@ -246,8 +228,7 @@ function prepareVersionedTxs(connection_1, txBatchData_1) {
|
|
|
246
228
|
const txs = batch.map((txData, txIndex) => {
|
|
247
229
|
let tx = null;
|
|
248
230
|
try {
|
|
249
|
-
|
|
250
|
-
tx = compileVersionedTransaction(blockhash, multipleAddressLookupTableAccounts[batchIndex][txIndex], txData.payer, normalizedInstructions);
|
|
231
|
+
tx = compileVersionedTransaction(blockhash, multipleAddressLookupTableAccounts[batchIndex][txIndex], txData.payer, txData.instructions);
|
|
251
232
|
}
|
|
252
233
|
catch (e) {
|
|
253
234
|
console.log("Error signing tx:", e.message);
|
package/dist/test.js
CHANGED
|
@@ -315,19 +315,15 @@ function testStates() {
|
|
|
315
315
|
}
|
|
316
316
|
if (tests.updateWeights) {
|
|
317
317
|
let update_weights = {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
token_mints_hash: [
|
|
328
|
-
0, 0, 0, 0,
|
|
329
|
-
],
|
|
330
|
-
},
|
|
318
|
+
token_weights: [
|
|
319
|
+
{
|
|
320
|
+
mint: "So11111111111111111111111111111111111111112",
|
|
321
|
+
weight_bps: 100,
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
token_mints_hash: [
|
|
325
|
+
0, 0, 0, 0,
|
|
326
|
+
],
|
|
331
327
|
};
|
|
332
328
|
let tx = yield sdk.updateWeightsTx(task_context, update_weights);
|
|
333
329
|
let res = yield sdk.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet });
|
|
@@ -335,14 +331,10 @@ function testStates() {
|
|
|
335
331
|
}
|
|
336
332
|
if (tests.makeDirectSwap) {
|
|
337
333
|
let make_direct_swap = {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
to_token_mint: "So11111111111111111111111111111111111111112",
|
|
343
|
-
amount_from: 100,
|
|
344
|
-
amount_to: 100,
|
|
345
|
-
},
|
|
334
|
+
from_token_mint: "So11111111111111111111111111111111111111112",
|
|
335
|
+
to_token_mint: "So11111111111111111111111111111111111111112",
|
|
336
|
+
amount_from: 100,
|
|
337
|
+
amount_to: 100,
|
|
346
338
|
};
|
|
347
339
|
let tx = yield sdk.makeDirectSwapTx(task_context, make_direct_swap);
|
|
348
340
|
let res = yield sdk.signAndSendTxPayloadBatchSequence({ txPayloadBatchSequence: tx, wallet });
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { PublicKey } from '@solana/web3.js';
|
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
|
|
4
4
|
export const COMPUTE_UNITS = 1_000_000;
|
|
5
|
-
export const PRIORITY_FEE =
|
|
5
|
+
export const PRIORITY_FEE = 25_000;
|
|
6
6
|
|
|
7
7
|
export const BASKETS_V3_PROGRAM_ID = new PublicKey("BASKT7aKd8n7ibpUbwLP3Wiyxyi3yoiXsxBk4Hpumate");
|
|
8
8
|
|
package/src/index.ts
CHANGED
|
@@ -105,7 +105,7 @@ export class SymmetryCore {
|
|
|
105
105
|
* @param params {connection: Connection, network: "devnet" | "mainnet", priorityFee?: number} - The parameters for the SDK.
|
|
106
106
|
* @param params.connection - The connection to the Solana network.
|
|
107
107
|
* @param params.network - The network to use (devnet or mainnet).
|
|
108
|
-
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (
|
|
108
|
+
* @param params.priorityFee - Optional. Compute unit price in micro-lamports. Defaults to PRIORITY_FEE (25_000).
|
|
109
109
|
*/
|
|
110
110
|
constructor(params: {
|
|
111
111
|
connection: Connection,
|
|
@@ -816,10 +816,10 @@ export class SymmetryCore {
|
|
|
816
816
|
basket: basket.ownAddress,
|
|
817
817
|
rebalanceIntent: undefined,
|
|
818
818
|
intent: intent,
|
|
819
|
-
mintIn: new PublicKey((editData as MakeDirectSwapInput).
|
|
820
|
-
mintOut: new PublicKey((editData as MakeDirectSwapInput).
|
|
821
|
-
amountIn: new BN((editData as MakeDirectSwapInput).
|
|
822
|
-
amountOut: new BN((editData as MakeDirectSwapInput).
|
|
819
|
+
mintIn: new PublicKey((editData as MakeDirectSwapInput).from_token_mint),
|
|
820
|
+
mintOut: new PublicKey((editData as MakeDirectSwapInput).to_token_mint),
|
|
821
|
+
amountIn: new BN((editData as MakeDirectSwapInput).amount_from),
|
|
822
|
+
amountOut: new BN((editData as MakeDirectSwapInput).amount_to),
|
|
823
823
|
mode: undefined,
|
|
824
824
|
}
|
|
825
825
|
let ixWithdraw = flashWithdrawIx(flashParams);
|
|
@@ -420,7 +420,7 @@ export function createEditBasketIntentIx(params: {
|
|
|
420
420
|
break;
|
|
421
421
|
|
|
422
422
|
case TaskType.UpdateWeights: { // 15 - 202
|
|
423
|
-
const updateWeightsData = (editData as UpdateWeightsInput)
|
|
423
|
+
const updateWeightsData = (editData as UpdateWeightsInput);
|
|
424
424
|
const weights = updateWeightsData.token_weights.slice(0, MAX_SUPPORTED_TOKENS_PER_BASKET);
|
|
425
425
|
while (weights.length < MAX_SUPPORTED_TOKENS_PER_BASKET) weights.push({ mint: '', weight_bps: 0 });
|
|
426
426
|
|
|
@@ -438,7 +438,7 @@ export function createEditBasketIntentIx(params: {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
case TaskType.MakeDirectSwap: // 16 - 203
|
|
441
|
-
let makeDirectSwapData = (editData as MakeDirectSwapInput)
|
|
441
|
+
let makeDirectSwapData = (editData as MakeDirectSwapInput);
|
|
442
442
|
let makeDirectSwap: MakeDirectSwap = {
|
|
443
443
|
fromTokenMint: new PublicKey(makeDirectSwapData.from_token_mint),
|
|
444
444
|
toTokenMint: new PublicKey(makeDirectSwapData.to_token_mint),
|
|
@@ -289,31 +289,19 @@ export interface AddOrEditTokenInput {
|
|
|
289
289
|
};
|
|
290
290
|
|
|
291
291
|
export interface UpdateWeightsInput {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
token_weights: {
|
|
298
|
-
mint: string,
|
|
299
|
-
weight_bps: number,
|
|
300
|
-
}[],
|
|
301
|
-
token_mints_hash?: number[],
|
|
302
|
-
},
|
|
292
|
+
token_weights: {
|
|
293
|
+
mint: string,
|
|
294
|
+
weight_bps: number,
|
|
295
|
+
}[],
|
|
296
|
+
token_mints_hash?: number[],
|
|
303
297
|
}
|
|
304
298
|
|
|
305
299
|
export interface MakeDirectSwapInput {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
from_token_mint: string,
|
|
312
|
-
to_token_mint: string,
|
|
313
|
-
amount_from: number,
|
|
314
|
-
amount_to: number,
|
|
315
|
-
}
|
|
316
|
-
};
|
|
300
|
+
from_token_mint: string,
|
|
301
|
+
to_token_mint: string,
|
|
302
|
+
amount_from: number,
|
|
303
|
+
amount_to: number,
|
|
304
|
+
}
|
|
317
305
|
|
|
318
306
|
export type Settings =
|
|
319
307
|
EditCreatorSettings |
|
|
@@ -187,28 +187,20 @@ function decodeTaskDataForType(intent: Intent): Settings {
|
|
|
187
187
|
case TaskType.UpdateWeights:
|
|
188
188
|
let updateWeights: UpdateWeights = UpdateWeightsLayout.decode(Buffer.from(taskData.slice(0, UpdateWeightsLayout.getSpan())));
|
|
189
189
|
let update_weights_input: UpdateWeightsInput = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
weight_bps: weight,
|
|
196
|
-
})),
|
|
197
|
-
token_mints_hash: updateWeights.tokenMintsHash,
|
|
198
|
-
},
|
|
190
|
+
token_weights: updateWeights.tokenWeights.map(weight => ({
|
|
191
|
+
mint: "",
|
|
192
|
+
weight_bps: weight,
|
|
193
|
+
})),
|
|
194
|
+
token_mints_hash: updateWeights.tokenMintsHash,
|
|
199
195
|
}
|
|
200
196
|
return update_weights_input;
|
|
201
197
|
case TaskType.MakeDirectSwap:
|
|
202
198
|
let makeDirectSwap: MakeDirectSwap = MakeDirectSwapLayout.decode(Buffer.from(taskData.slice(0, MakeDirectSwapLayout.getSpan())));
|
|
203
199
|
let make_direct_swap_input: MakeDirectSwapInput = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
209
|
-
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
210
|
-
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
211
|
-
},
|
|
200
|
+
from_token_mint: makeDirectSwap.fromTokenMint.toBase58(),
|
|
201
|
+
to_token_mint: makeDirectSwap.toTokenMint.toBase58(),
|
|
202
|
+
amount_from: parseInt(makeDirectSwap.amountFrom.toString()),
|
|
203
|
+
amount_to: parseInt(makeDirectSwap.amountTo.toString()),
|
|
212
204
|
}
|
|
213
205
|
return make_direct_swap_input;
|
|
214
206
|
default:
|
|
@@ -86,9 +86,9 @@ export function formatRebalanceIntent(rebalanceIntent: RebalanceIntent, basket?:
|
|
|
86
86
|
completed_time: parseInt(rebalanceIntent.mintBasketTask.completedTime.toString()),
|
|
87
87
|
};
|
|
88
88
|
let cancelRebalanceTask = {
|
|
89
|
-
completed_by: rebalanceIntent.
|
|
90
|
-
completed_bounty: parseInt(rebalanceIntent.
|
|
91
|
-
completed_time: parseInt(rebalanceIntent.
|
|
89
|
+
completed_by: rebalanceIntent.cancelRebalanceTask.completedBy.toBase58(),
|
|
90
|
+
completed_bounty: parseInt(rebalanceIntent.cancelRebalanceTask.completedBounty.toString()),
|
|
91
|
+
completed_time: parseInt(rebalanceIntent.cancelRebalanceTask.completedTime.toString()),
|
|
92
92
|
};
|
|
93
93
|
let tasks = [
|
|
94
94
|
placeholderTask,
|
package/src/txUtils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
TransactionInstruction, TransactionMessage, VersionedTransaction
|
|
5
5
|
} from '@solana/web3.js';
|
|
6
6
|
import { getAta } from './instructions/pda';
|
|
7
|
-
import { MINTS
|
|
7
|
+
import { MINTS } from './constants';
|
|
8
8
|
import { createAssociatedTokenAccountIdempotentInstruction, createSyncNativeInstruction } from '@solana/spl-token';
|
|
9
9
|
|
|
10
10
|
type TransactionSignature = string;
|
|
@@ -245,12 +245,28 @@ export async function sendVersionedTransaction(
|
|
|
245
245
|
console.log(e.message);
|
|
246
246
|
throw new Error("Simulation failed");
|
|
247
247
|
});
|
|
248
|
+
for (let i = 0; i < 4; i++) {
|
|
249
|
+
await delay(3000).then(() =>
|
|
250
|
+
connection.sendRawTransaction(
|
|
251
|
+
serializedTx,
|
|
252
|
+
{preflightCommitment: "confirmed", maxRetries: 0}
|
|
253
|
+
).catch(() => {})
|
|
254
|
+
);
|
|
255
|
+
}
|
|
248
256
|
console.log("Simulation txId:", txId);
|
|
249
257
|
} else {
|
|
250
258
|
txId = await connection.sendRawTransaction(
|
|
251
259
|
serializedTx,
|
|
252
260
|
{ skipPreflight: true, maxRetries: 0 }
|
|
253
261
|
);
|
|
262
|
+
for (let i = 0; i < 4; i++) {
|
|
263
|
+
await delay(3000).then(() =>
|
|
264
|
+
connection.sendRawTransaction(
|
|
265
|
+
serializedTx,
|
|
266
|
+
{preflightCommitment: "confirmed", maxRetries: 0}
|
|
267
|
+
).catch(() => {})
|
|
268
|
+
);
|
|
269
|
+
}
|
|
254
270
|
console.log("Sending tx:", txId);
|
|
255
271
|
}
|
|
256
272
|
|
|
@@ -289,44 +305,9 @@ export async function sendVersionedTransaction(
|
|
|
289
305
|
return txId;
|
|
290
306
|
}
|
|
291
307
|
|
|
292
|
-
const COMPUTE_BUDGET_SET_COMPUTE_UNIT_PRICE_INSTRUCTION = 3;
|
|
293
|
-
|
|
294
|
-
function isComputeBudgetInstruction(ix: TransactionInstruction): boolean {
|
|
295
|
-
return ix.programId.equals(ComputeBudgetProgram.programId);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function isSetComputeUnitPriceInstruction(ix: TransactionInstruction): boolean {
|
|
299
|
-
return ix.data.length > 0 && ix.data[0] === COMPUTE_BUDGET_SET_COMPUTE_UNIT_PRICE_INSTRUCTION;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function normalizeComputeBudgetInstructions(
|
|
303
|
-
instructions: TransactionInstruction[],
|
|
304
|
-
priorityFeeMicroLamports: number,
|
|
305
|
-
): TransactionInstruction[] {
|
|
306
|
-
const computeBudgetInstructions: TransactionInstruction[] = [];
|
|
307
|
-
const regularInstructions: TransactionInstruction[] = [];
|
|
308
|
-
for (const instruction of instructions) {
|
|
309
|
-
if (isComputeBudgetInstruction(instruction)) {
|
|
310
|
-
computeBudgetInstructions.push(instruction);
|
|
311
|
-
} else {
|
|
312
|
-
regularInstructions.push(instruction);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (!computeBudgetInstructions.some(isSetComputeUnitPriceInstruction)) {
|
|
317
|
-
computeBudgetInstructions.push(
|
|
318
|
-
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFeeMicroLamports })
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Best practice: put compute budget instructions first.
|
|
323
|
-
return [...computeBudgetInstructions, ...regularInstructions];
|
|
324
|
-
}
|
|
325
|
-
|
|
326
308
|
export async function prepareVersionedTxs(
|
|
327
309
|
connection: Connection,
|
|
328
310
|
txBatchData: TxBatchData,
|
|
329
|
-
priorityFeeMicroLamports: number = PRIORITY_FEE,
|
|
330
311
|
): Promise<VersionedTxs> {
|
|
331
312
|
const { batches } = txBatchData;
|
|
332
313
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
@@ -339,15 +320,11 @@ export async function prepareVersionedTxs(
|
|
|
339
320
|
const txs = batch.map((txData, txIndex) => {
|
|
340
321
|
let tx = null;
|
|
341
322
|
try {
|
|
342
|
-
const normalizedInstructions = normalizeComputeBudgetInstructions(
|
|
343
|
-
txData.instructions,
|
|
344
|
-
priorityFeeMicroLamports,
|
|
345
|
-
);
|
|
346
323
|
tx = compileVersionedTransaction(
|
|
347
324
|
blockhash,
|
|
348
325
|
multipleAddressLookupTableAccounts[batchIndex][txIndex],
|
|
349
326
|
txData.payer,
|
|
350
|
-
|
|
327
|
+
txData.instructions,
|
|
351
328
|
);
|
|
352
329
|
} catch (e: any) {
|
|
353
330
|
console.log("Error signing tx:", e.message);
|
package/test.ts
CHANGED
|
@@ -345,19 +345,15 @@ async function testStates() {
|
|
|
345
345
|
|
|
346
346
|
if (tests.updateWeights) {
|
|
347
347
|
let update_weights: UpdateWeightsInput = {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
token_mints_hash: [
|
|
358
|
-
0, 0, 0, 0,
|
|
359
|
-
],
|
|
360
|
-
},
|
|
348
|
+
token_weights: [
|
|
349
|
+
{
|
|
350
|
+
mint: "So11111111111111111111111111111111111111112",
|
|
351
|
+
weight_bps: 100,
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
token_mints_hash: [
|
|
355
|
+
0, 0, 0, 0,
|
|
356
|
+
],
|
|
361
357
|
};
|
|
362
358
|
let tx = await sdk.updateWeightsTx(task_context, update_weights);
|
|
363
359
|
let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
|
|
@@ -366,14 +362,10 @@ async function testStates() {
|
|
|
366
362
|
|
|
367
363
|
if (tests.makeDirectSwap) {
|
|
368
364
|
let make_direct_swap: MakeDirectSwapInput = {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
to_token_mint: "So11111111111111111111111111111111111111112",
|
|
374
|
-
amount_from: 100,
|
|
375
|
-
amount_to: 100,
|
|
376
|
-
},
|
|
365
|
+
from_token_mint: "So11111111111111111111111111111111111111112",
|
|
366
|
+
to_token_mint: "So11111111111111111111111111111111111111112",
|
|
367
|
+
amount_from: 100,
|
|
368
|
+
amount_to: 100,
|
|
377
369
|
};
|
|
378
370
|
let tx = await sdk.makeDirectSwapTx(task_context, make_direct_swap);
|
|
379
371
|
let res = await sdk.signAndSendTxPayloadBatchSequence({txPayloadBatchSequence: tx, wallet});
|
|
@@ -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
|
-
}
|