@symmetry-hq/temp-v3-sdk 0.0.16 → 0.0.18
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.d.ts +49 -34
- package/dist/src/index.js +153 -40
- package/dist/src/instructions/automation/rebalanceIntent.d.ts +2 -1
- package/dist/src/instructions/automation/rebalanceIntent.js +2 -2
- package/dist/src/instructions/management/edit.js +8 -8
- package/dist/src/layouts/basket.d.ts +96 -84
- package/dist/src/layouts/intents/intent.d.ts +36 -35
- package/dist/src/layouts/oracle.d.ts +1 -0
- package/dist/src/layouts/oracle.js +2 -1
- package/dist/src/states/basket.js +75 -72
- package/dist/src/states/intents/intent.d.ts +5 -4
- package/dist/src/states/intents/intent.js +37 -15
- package/dist/test.js +25 -18
- package/package.json +1 -1
- package/src/index.ts +246 -124
- package/src/instructions/automation/rebalanceIntent.ts +6 -4
- package/src/instructions/management/edit.ts +23 -23
- package/src/layouts/basket.ts +80 -62
- package/src/layouts/intents/intent.ts +50 -48
- package/src/layouts/oracle.ts +2 -0
- package/src/states/basket.ts +101 -91
- package/src/states/intents/intent.ts +36 -25
- package/test.ts +40 -30
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BN } from '@coral-xyz/anchor';
|
|
2
2
|
import { Connection, PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
|
-
import { Basket
|
|
3
|
+
import { Basket } from './layouts/basket';
|
|
4
4
|
import { GlobalConfig } from './layouts/config';
|
|
5
|
-
import {
|
|
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';
|
|
@@ -30,6 +31,8 @@ export declare class SymmetryCore {
|
|
|
30
31
|
deriveBasketsByMints(mints: string[]): Promise<Map<string, string>>;
|
|
31
32
|
fetchBasketsFromMints(mints: string[]): Promise<Map<string, Basket>>;
|
|
32
33
|
loadBasketPrice(basket: Basket): Promise<Basket>;
|
|
34
|
+
fetchIntent(intentPubkey: string): Promise<Intent>;
|
|
35
|
+
fetchMultipleIntents(intentPubkeys: string[]): Promise<Map<string, Intent>>;
|
|
33
36
|
fetchAllIntents(filters: IntentFilter[]): Promise<Intent[]>;
|
|
34
37
|
fetchAllRebalanceIntents(filters: RebalanceIntentFilter[]): Promise<RebalanceIntent[]>;
|
|
35
38
|
createGlobalConfigTx(params: {
|
|
@@ -45,26 +48,27 @@ export declare class SymmetryCore {
|
|
|
45
48
|
name: string;
|
|
46
49
|
symbol: string;
|
|
47
50
|
metadata_uri: string;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
host_platform_params?: {
|
|
52
|
+
host_pubkey: string;
|
|
53
|
+
host_deposit_fee_bps: number;
|
|
54
|
+
host_withdraw_fee_bps: number;
|
|
55
|
+
host_management_fee_bps: number;
|
|
56
|
+
host_performance_fee_bps: number;
|
|
57
|
+
};
|
|
54
58
|
}): Promise<TxPayloadBatchSequence>;
|
|
55
|
-
editCreatorTx(context: TaskContext, settings:
|
|
56
|
-
editManagersTx(context: TaskContext, settings:
|
|
57
|
-
editScheduleTx(context: TaskContext, settings:
|
|
58
|
-
editFeesTx(context: TaskContext, settings:
|
|
59
|
-
editAutomationTx(context: TaskContext, settings:
|
|
60
|
-
editLpTx(context: TaskContext, settings:
|
|
61
|
-
editMetadataTx(context: TaskContext, settings:
|
|
62
|
-
editDepositsTx(context: TaskContext, settings:
|
|
63
|
-
editForceRebalanceTx(context: TaskContext, settings:
|
|
64
|
-
editCustomRebalanceTx(context: TaskContext, settings:
|
|
65
|
-
editAddTokenDelayTx(context: TaskContext, settings:
|
|
66
|
-
editUpdateWeightsDelayTx(context: TaskContext, settings:
|
|
67
|
-
editSwapDelayTx(context: TaskContext, settings:
|
|
59
|
+
editCreatorTx(context: TaskContext, settings: EditCreatorSettings): Promise<TxPayloadBatchSequence>;
|
|
60
|
+
editManagersTx(context: TaskContext, settings: EditManagerSettings): Promise<TxPayloadBatchSequence>;
|
|
61
|
+
editScheduleTx(context: TaskContext, settings: EditScheduleSettings): Promise<TxPayloadBatchSequence>;
|
|
62
|
+
editFeesTx(context: TaskContext, settings: EditFeeSettings): Promise<TxPayloadBatchSequence>;
|
|
63
|
+
editAutomationTx(context: TaskContext, settings: EditAutomationSettings): Promise<TxPayloadBatchSequence>;
|
|
64
|
+
editLpTx(context: TaskContext, settings: EditLpSettings): Promise<TxPayloadBatchSequence>;
|
|
65
|
+
editMetadataTx(context: TaskContext, settings: EditMetadataSettings): Promise<TxPayloadBatchSequence>;
|
|
66
|
+
editDepositsTx(context: TaskContext, settings: EditDepositsSettings): Promise<TxPayloadBatchSequence>;
|
|
67
|
+
editForceRebalanceTx(context: TaskContext, settings: EditForceRebalanceSettings): Promise<TxPayloadBatchSequence>;
|
|
68
|
+
editCustomRebalanceTx(context: TaskContext, settings: EditCustomRebalanceSettings): Promise<TxPayloadBatchSequence>;
|
|
69
|
+
editAddTokenDelayTx(context: TaskContext, settings: EditAddTokenSettings): Promise<TxPayloadBatchSequence>;
|
|
70
|
+
editUpdateWeightsDelayTx(context: TaskContext, settings: EditUpdateWeightsSettings): Promise<TxPayloadBatchSequence>;
|
|
71
|
+
editSwapDelayTx(context: TaskContext, settings: EditMakeDirectSwapSettings): Promise<TxPayloadBatchSequence>;
|
|
68
72
|
addTokenTx(context: TaskContext, settings: AddTokenInput): Promise<TxPayloadBatchSequence>;
|
|
69
73
|
updateWeightsTx(context: TaskContext, settings: UpdateWeightsInput): Promise<TxPayloadBatchSequence>;
|
|
70
74
|
makeDirectSwapTx(context: TaskContext, settings: MakeDirectSwapInput): Promise<TxPayloadBatchSequence>;
|
|
@@ -74,22 +78,32 @@ export declare class SymmetryCore {
|
|
|
74
78
|
settings: Settings;
|
|
75
79
|
}): Promise<TxPayloadBatchSequence>;
|
|
76
80
|
executeBasketIntentTx(params: {
|
|
77
|
-
intent:
|
|
78
|
-
|
|
81
|
+
intent: string;
|
|
82
|
+
executor: string;
|
|
79
83
|
}): Promise<TxPayloadBatchSequence>;
|
|
80
84
|
buyBasketTx(params: {
|
|
81
|
-
buyer:
|
|
82
|
-
|
|
85
|
+
buyer: string;
|
|
86
|
+
basket_mint: string;
|
|
83
87
|
contributions: {
|
|
84
|
-
mint:
|
|
88
|
+
mint: string;
|
|
85
89
|
amount: number;
|
|
86
90
|
}[];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
rebalance_slippage_bps?: number;
|
|
92
|
+
per_trade_rebalance_slippage_bps?: number;
|
|
93
|
+
execution_start_time?: number;
|
|
94
|
+
min_bounty_amount?: number;
|
|
95
|
+
max_bounty_amount?: number;
|
|
96
|
+
}): Promise<TxPayloadBatchSequence>;
|
|
97
|
+
sellBasketTx(params: {
|
|
98
|
+
seller: string;
|
|
99
|
+
basket_mint: string;
|
|
100
|
+
withdraw_amount: number;
|
|
101
|
+
keep_tokens: string[];
|
|
102
|
+
rebalance_slippage_bps?: number;
|
|
103
|
+
per_trade_rebalance_slippage_bps?: number;
|
|
104
|
+
execution_start_time?: number;
|
|
105
|
+
min_bounty_amount?: number;
|
|
106
|
+
max_bounty_amount?: number;
|
|
93
107
|
}): Promise<TxPayloadBatchSequence>;
|
|
94
108
|
updateTokenPricesTx(params: {
|
|
95
109
|
keeper: PublicKey;
|
|
@@ -127,5 +141,6 @@ export declare class SymmetryCore {
|
|
|
127
141
|
wallet: Wallet;
|
|
128
142
|
}): Promise<TransactionSignature[][]>;
|
|
129
143
|
}
|
|
130
|
-
export { Basket,
|
|
131
|
-
export { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings,
|
|
144
|
+
export { Basket, BasketFilter, Intent, IntentFilter, RebalanceIntent, RebalanceIntentFilter };
|
|
145
|
+
export { FormattedCreatorSettings, FormattedManagersSettings, FormattedFeeSettings, FormattedScheduleSettings, FormattedAutomationSettings, FormattedLpSettings, FormattedMetadataSettings, FormattedDepositsSettings, FormattedForceRebalanceSettings, FormattedCustomRebalanceSettings, FormattedAddTokenSettings, FormattedUpdateWeightsSettings, FormattedMakeDirectSwapSettings, FormattedAccumulatedFees, FormattedLookupTables, FormattedAsset, FormattedOracleSettings, FormattedOracleAggregator, FormattedOracle, FormattedBasket, };
|
|
146
|
+
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
|
|
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
|
|
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/";
|
|
@@ -58,15 +59,12 @@ class SymmetryCore {
|
|
|
58
59
|
// }
|
|
59
60
|
fetchBasket(basketPubkey) {
|
|
60
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
return basketState;
|
|
62
|
+
return yield (0, basket_2.fetchBasket)(this.sdkParams.connection, new web3_js_1.PublicKey(basketPubkey));
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
fetchMultipleBaskets(basketPubkeys) {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
68
|
-
const basketsMap = yield (0, basket_2.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeysArray);
|
|
69
|
-
return basketsMap;
|
|
67
|
+
return yield (0, basket_2.fetchBaskektsMultiple)(this.sdkParams.connection, basketPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
fetchAllBaskets(basketFilter) {
|
|
@@ -126,15 +124,24 @@ class SymmetryCore {
|
|
|
126
124
|
return yield (0, basket_2.loadBasketPrice)(basket, this.sdkParams.connection);
|
|
127
125
|
});
|
|
128
126
|
}
|
|
127
|
+
fetchIntent(intentPubkey) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return yield (0, intent_2.fetchIntent)(this.sdkParams.connection, new web3_js_1.PublicKey(intentPubkey));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
fetchMultipleIntents(intentPubkeys) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return yield (0, intent_2.fetchIntentsMultiple)(this.sdkParams.connection, intentPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
135
|
+
});
|
|
136
|
+
}
|
|
129
137
|
fetchAllIntents(filters) {
|
|
130
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
|
|
132
|
-
return intents;
|
|
139
|
+
return yield (0, intent_2.fetchIntents)(this.sdkParams.connection, filters);
|
|
133
140
|
});
|
|
134
141
|
}
|
|
135
142
|
fetchAllRebalanceIntents(filters) {
|
|
136
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const rebalanceIntents = yield (0,
|
|
144
|
+
const rebalanceIntents = yield (0, rebalanceIntent_3.fetchRebalanceIntents)(this.sdkParams.connection, filters);
|
|
138
145
|
return rebalanceIntents;
|
|
139
146
|
});
|
|
140
147
|
}
|
|
@@ -174,14 +181,14 @@ class SymmetryCore {
|
|
|
174
181
|
}
|
|
175
182
|
createBasketTx(params) {
|
|
176
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
var _a;
|
|
184
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
178
185
|
const creator = new web3_js_1.PublicKey(params.creator);
|
|
179
|
-
const host = new web3_js_1.PublicKey(params.host_pubkey);
|
|
186
|
+
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
187
|
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,
|
|
188
|
+
hostDepositFeeBps: (_d = (_c = params.host_platform_params) === null || _c === void 0 ? void 0 : _c.host_deposit_fee_bps) !== null && _d !== void 0 ? _d : 0,
|
|
189
|
+
hostWithdrawalFeeBps: (_f = (_e = params.host_platform_params) === null || _e === void 0 ? void 0 : _e.host_withdraw_fee_bps) !== null && _f !== void 0 ? _f : 0,
|
|
190
|
+
hostManagementFeeBps: (_h = (_g = params.host_platform_params) === null || _g === void 0 ? void 0 : _g.host_management_fee_bps) !== null && _h !== void 0 ? _h : 0,
|
|
191
|
+
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
192
|
};
|
|
186
193
|
const metadataParams = {
|
|
187
194
|
name: params.name,
|
|
@@ -190,7 +197,7 @@ class SymmetryCore {
|
|
|
190
197
|
};
|
|
191
198
|
const startPrice = (0, fraction_1.decimalToFraction)(new decimal_js_1.default(parseFloat(params.start_price) / 10 ** 6));
|
|
192
199
|
let globalConfigData = yield this.sdkParams.connection.getAccountInfo((0, pda_1.getGlobalConfigPda)());
|
|
193
|
-
let globalConfig = config_1.GlobalConfigLayout.decode((
|
|
200
|
+
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
201
|
let basketId = parseInt(globalConfig.totalNumberOfBaskets.toString());
|
|
195
202
|
let mint = (0, pda_1.getBasketTokenMintPda)(basketId);
|
|
196
203
|
let basket = (0, pda_1.getBasketState)(mint);
|
|
@@ -384,7 +391,8 @@ class SymmetryCore {
|
|
|
384
391
|
}
|
|
385
392
|
executeBasketIntentTx(params) {
|
|
386
393
|
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
-
let
|
|
394
|
+
let keeper = new web3_js_1.PublicKey(params.executor);
|
|
395
|
+
let intent = yield this.fetchIntent(params.intent);
|
|
388
396
|
let basketMint;
|
|
389
397
|
if (intent.taskType === intent_1.TaskType.EditMetadataSettings) {
|
|
390
398
|
let basket = yield this.fetchBasket(intent.basket.toBase58());
|
|
@@ -414,48 +422,46 @@ class SymmetryCore {
|
|
|
414
422
|
}
|
|
415
423
|
buyBasketTx(params) {
|
|
416
424
|
return __awaiter(this, void 0, void 0, function* () {
|
|
417
|
-
var _a, _b, _c, _d;
|
|
418
|
-
let
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (!priorityFee)
|
|
430
|
-
priorityFee = this.sdkParams.priorityFee;
|
|
425
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
426
|
+
let buyer = new web3_js_1.PublicKey(params.buyer);
|
|
427
|
+
let basketMint = new web3_js_1.PublicKey(params.basket_mint);
|
|
428
|
+
let contributions = params.contributions.map(contribution => ({
|
|
429
|
+
mint: new web3_js_1.PublicKey(contribution.mint),
|
|
430
|
+
amount: new anchor_1.BN(contribution.amount),
|
|
431
|
+
}));
|
|
432
|
+
let rebalanceSlippageBps = (_a = params.rebalance_slippage_bps) !== null && _a !== void 0 ? _a : 100;
|
|
433
|
+
let perTradeRebalanceSlippageBps = (_b = params.per_trade_rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
|
|
434
|
+
let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
|
|
435
|
+
let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
|
|
436
|
+
let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
431
437
|
const basket = (0, pda_1.getBasketState)(basketMint);
|
|
432
438
|
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
|
|
433
439
|
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
434
440
|
let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
|
|
435
441
|
let rebalanceIntentRentPayer = buyer;
|
|
436
442
|
// TODO: check actual lamports required for rent
|
|
437
|
-
if (((
|
|
443
|
+
if (((_g = (_f = accountInfos.get(rentPayer.toBase58())) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : 0) > 0)
|
|
438
444
|
rebalanceIntentRentPayer = rentPayer;
|
|
439
|
-
let basketState = basket_1.BasketLayout.decode((
|
|
445
|
+
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
446
|
let bountyMint = basketState.bountyMint;
|
|
441
447
|
let txBatchData = { batches: [
|
|
442
448
|
[{
|
|
443
449
|
payer: buyer,
|
|
444
450
|
instructions: [
|
|
445
|
-
(0,
|
|
451
|
+
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
446
452
|
signer: buyer,
|
|
447
453
|
owner: buyer,
|
|
448
454
|
basket: basket,
|
|
449
455
|
}),
|
|
450
|
-
(0,
|
|
451
|
-
(0,
|
|
456
|
+
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
457
|
+
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
452
458
|
signer: buyer,
|
|
453
459
|
owner: buyer,
|
|
454
460
|
basket,
|
|
455
461
|
basketTokenMint: basketMint,
|
|
456
462
|
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
457
463
|
bountyMint: bountyMint,
|
|
458
|
-
rebalanceType:
|
|
464
|
+
rebalanceType: rebalanceIntent_2.RebalanceType.Deposit,
|
|
459
465
|
basketRebalanceIntent: undefined,
|
|
460
466
|
rebalanceSlippageBps: rebalanceSlippageBps,
|
|
461
467
|
perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
|
|
@@ -506,6 +512,113 @@ class SymmetryCore {
|
|
|
506
512
|
return txPayloadBatchSequence;
|
|
507
513
|
});
|
|
508
514
|
}
|
|
515
|
+
sellBasketTx(params) {
|
|
516
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
517
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
518
|
+
let seller = new web3_js_1.PublicKey(params.seller);
|
|
519
|
+
let basketMint = new web3_js_1.PublicKey(params.basket_mint);
|
|
520
|
+
let withdrawAmount = new anchor_1.BN(params.withdraw_amount);
|
|
521
|
+
let keepTokens = (_a = params.keep_tokens) === null || _a === void 0 ? void 0 : _a.map(mint => new web3_js_1.PublicKey(mint));
|
|
522
|
+
let rebalanceSlippageBps = (_b = params.rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
|
|
523
|
+
let perTradeRebalanceSlippageBps = (_c = params.per_trade_rebalance_slippage_bps) !== null && _c !== void 0 ? _c : 100;
|
|
524
|
+
let executionStartTime = (_d = params.execution_start_time) !== null && _d !== void 0 ? _d : 0;
|
|
525
|
+
let minBountyAmount = (_e = params.min_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
526
|
+
let maxBountyAmount = (_f = params.max_bounty_amount) !== null && _f !== void 0 ? _f : 0;
|
|
527
|
+
const basket = (0, pda_1.getBasketState)(basketMint);
|
|
528
|
+
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, seller);
|
|
529
|
+
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
530
|
+
let accountInfos = yield (0, txUtils_1.getMultipleAccountsInfoBatched)(this.sdkParams.connection, [rentPayer, basket]);
|
|
531
|
+
let rebalanceIntentRentPayer = seller;
|
|
532
|
+
// TODO: check actual lamports required for rent
|
|
533
|
+
if (((_h = (_g = accountInfos.get(rentPayer.toBase58())) === null || _g === void 0 ? void 0 : _g.lamports) !== null && _h !== void 0 ? _h : 0) > 0)
|
|
534
|
+
rebalanceIntentRentPayer = rentPayer;
|
|
535
|
+
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));
|
|
536
|
+
let bountyMint = basketState.bountyMint;
|
|
537
|
+
let keepAllTokensFlag = 1;
|
|
538
|
+
for (let i = 0; i < basketState.numTokens; i++) {
|
|
539
|
+
if (!keepTokens.includes(basketState.composition[i].mint.toBase58())) {
|
|
540
|
+
keepAllTokensFlag = 0;
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
let tokenMintsHash = Buffer.alloc(32);
|
|
545
|
+
for (let i = 0; i < basketState.numTokens; i++) {
|
|
546
|
+
tokenMintsHash = (0, crypto_1.createHash)('sha256')
|
|
547
|
+
.update(Buffer.concat([tokenMintsHash, basketState.composition[i].mint.toBuffer()]))
|
|
548
|
+
.digest();
|
|
549
|
+
}
|
|
550
|
+
let keepTokensBitmask = new anchor_1.BN(0);
|
|
551
|
+
if (keepTokens && keepTokens.length > 0) {
|
|
552
|
+
for (const mint of keepTokens) {
|
|
553
|
+
let tokenIndex = -1;
|
|
554
|
+
for (let i = 0; i < basketState.numTokens; i++) {
|
|
555
|
+
if (basketState.composition[i].mint.equals(mint)) {
|
|
556
|
+
tokenIndex = i;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (tokenIndex === -1) {
|
|
561
|
+
throw new Error(`Token mint not in basket: ${mint.toBase58()}`);
|
|
562
|
+
}
|
|
563
|
+
keepTokensBitmask = keepTokensBitmask.or(new anchor_1.BN(1).shln(tokenIndex));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const basketRebalanceIntent = basketState.settings.activeRebalance > 0
|
|
567
|
+
? (0, pda_1.getRebalanceIntentPda)(basket, basket)
|
|
568
|
+
: undefined;
|
|
569
|
+
let txBatchData = { batches: [
|
|
570
|
+
[{
|
|
571
|
+
payer: seller,
|
|
572
|
+
instructions: [
|
|
573
|
+
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
574
|
+
signer: seller,
|
|
575
|
+
owner: seller,
|
|
576
|
+
basket: basket,
|
|
577
|
+
}),
|
|
578
|
+
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
579
|
+
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
580
|
+
signer: seller,
|
|
581
|
+
owner: seller,
|
|
582
|
+
basket,
|
|
583
|
+
basketTokenMint: basketMint,
|
|
584
|
+
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
585
|
+
bountyMint: bountyMint,
|
|
586
|
+
rebalanceType: rebalanceIntent_2.RebalanceType.Withdraw,
|
|
587
|
+
basketRebalanceIntent: basketRebalanceIntent,
|
|
588
|
+
rebalanceSlippageBps: rebalanceSlippageBps,
|
|
589
|
+
perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
|
|
590
|
+
executionStartTime: executionStartTime,
|
|
591
|
+
minBountyAmount: minBountyAmount,
|
|
592
|
+
maxBountyAmount: maxBountyAmount,
|
|
593
|
+
withdrawParamsBurnAmount: withdrawAmount,
|
|
594
|
+
withdrawParamsTokenMintsHash: Array.from(tokenMintsHash),
|
|
595
|
+
withdrawParamsKeepTokensBitmask: keepTokensBitmask,
|
|
596
|
+
withdrawParamsKeepAllTokens: keepAllTokensFlag,
|
|
597
|
+
}),
|
|
598
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
599
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
600
|
+
],
|
|
601
|
+
lookupTables: [],
|
|
602
|
+
}],
|
|
603
|
+
[{
|
|
604
|
+
payer: seller,
|
|
605
|
+
instructions: [
|
|
606
|
+
executionStartTime ? (0, priceUpdate_1.startPriceUpdatesIx)({
|
|
607
|
+
keeper: seller,
|
|
608
|
+
basket: basket,
|
|
609
|
+
rebalanceIntent: rebalanceIntent,
|
|
610
|
+
}) : web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
611
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: exports.COMPUTE_UNITS }),
|
|
612
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
613
|
+
],
|
|
614
|
+
lookupTables: [],
|
|
615
|
+
}]
|
|
616
|
+
] };
|
|
617
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
618
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
619
|
+
return txPayloadBatchSequence;
|
|
620
|
+
});
|
|
621
|
+
}
|
|
509
622
|
updateTokenPricesTx(params) {
|
|
510
623
|
return __awaiter(this, void 0, void 0, function* () {
|
|
511
624
|
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?:
|
|
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(
|
|
71
|
+
Buffer.from(withdrawParamsKeepTokensBitmask.toArray("le", 16)),
|
|
72
72
|
Buffer.from([withdrawParamsKeepAllTokens]),
|
|
73
73
|
]);
|
|
74
74
|
const keys = [
|
|
@@ -185,7 +185,7 @@ function createEditBasketIntentIx(params) {
|
|
|
185
185
|
case intent_1.TaskType.EditAutomationSettings: // 5
|
|
186
186
|
let automationSettings = editData;
|
|
187
187
|
let editAutomationSettings = {
|
|
188
|
-
allowAutomation: automationSettings.
|
|
188
|
+
allowAutomation: automationSettings.enabled ? 1 : 0,
|
|
189
189
|
rebalanceSlippageThresholdBps: automationSettings.rebalance_slippage_threshold_bps,
|
|
190
190
|
perTradeRebalanceSlippageThresholdBps: automationSettings.per_trade_rebalance_slippage_threshold_bps,
|
|
191
191
|
rebalanceActivationThresholdAbsBps: automationSettings.rebalance_activation_threshold_abs_bps,
|
|
@@ -199,7 +199,7 @@ function createEditBasketIntentIx(params) {
|
|
|
199
199
|
case intent_1.TaskType.EditLpSettings: // 6
|
|
200
200
|
let lpSettings = editData;
|
|
201
201
|
let editLpSettings = {
|
|
202
|
-
allowLp: lpSettings.
|
|
202
|
+
allowLp: lpSettings.enabled ? 1 : 0,
|
|
203
203
|
lpThresholdBps: lpSettings.lp_threshold_bps,
|
|
204
204
|
extraData: new Array(32).fill(0),
|
|
205
205
|
modificationDelay: new anchor_1.BN(lpSettings.modification_delay),
|
|
@@ -221,19 +221,19 @@ function createEditBasketIntentIx(params) {
|
|
|
221
221
|
break;
|
|
222
222
|
case intent_1.TaskType.EditDepositsSettings: // 8
|
|
223
223
|
let depositsSettings = editData;
|
|
224
|
-
let editDepositsSettings = depositsSettings.
|
|
224
|
+
let editDepositsSettings = depositsSettings.enabled ? 1 : 0;
|
|
225
225
|
editDataBuf[0] = editDepositsSettings;
|
|
226
226
|
break;
|
|
227
227
|
case intent_1.TaskType.EditForceRebalanceSettings: // 9
|
|
228
228
|
let forceRebalanceSettings = editData;
|
|
229
|
-
let editForceRebalanceSettings = forceRebalanceSettings.
|
|
229
|
+
let editForceRebalanceSettings = forceRebalanceSettings.enabled ? 1 : 0;
|
|
230
230
|
let editForceRebalanceModificationDelayBN = new anchor_1.BN(forceRebalanceSettings.modification_delay);
|
|
231
231
|
editDataBuf[0] = editForceRebalanceSettings;
|
|
232
232
|
editDataBuf.writeBigUint64LE(BigInt(editForceRebalanceModificationDelayBN.toString()), 1);
|
|
233
233
|
break;
|
|
234
234
|
case intent_1.TaskType.EditCustomRebalanceSettings: // 10
|
|
235
235
|
let customRebalanceSettings = editData;
|
|
236
|
-
let editCustomRebalanceSettings = customRebalanceSettings.
|
|
236
|
+
let editCustomRebalanceSettings = customRebalanceSettings.enabled ? 1 : 0;
|
|
237
237
|
let editCustomRebalanceModificationDelayBN = new anchor_1.BN(customRebalanceSettings.modification_delay);
|
|
238
238
|
editDataBuf[0] = editCustomRebalanceSettings;
|
|
239
239
|
editDataBuf.writeBigUint64LE(BigInt(editCustomRebalanceModificationDelayBN.toString()), 1);
|
|
@@ -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.
|
|
325
|
+
for (let i = 0; i < addTokenData.oracles.length; i++) {
|
|
326
326
|
additionalAccounts.push({
|
|
327
|
-
pubkey: new web3_js_1.PublicKey(addTokenData.
|
|
327
|
+
pubkey: new web3_js_1.PublicKey(addTokenData.oracles[i].account),
|
|
328
328
|
isWritable: false,
|
|
329
329
|
isSigner: false
|
|
330
330
|
});
|