@symmetry-hq/sdk 1.0.1
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 +23 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/index.d.ts +804 -0
- package/dist/src/index.js +2097 -0
- package/dist/src/instructions/automation/auction.d.ts +6 -0
- package/dist/src/instructions/automation/auction.js +40 -0
- package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
- package/dist/src/instructions/automation/claimBounty.js +44 -0
- package/dist/src/instructions/automation/flashSwap.d.ts +21 -0
- package/dist/src/instructions/automation/flashSwap.js +74 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +19 -0
- package/dist/src/instructions/automation/priceUpdate.js +89 -0
- package/dist/src/instructions/automation/rebalanceIntent.d.ts +32 -0
- package/dist/src/instructions/automation/rebalanceIntent.js +117 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +11 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +41 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +53 -0
- package/dist/src/instructions/management/claimFees.d.ts +15 -0
- package/dist/src/instructions/management/claimFees.js +95 -0
- package/dist/src/instructions/management/createBasket.d.ts +21 -0
- package/dist/src/instructions/management/createBasket.js +98 -0
- package/dist/src/instructions/management/edit.d.ts +51 -0
- package/dist/src/instructions/management/edit.js +477 -0
- package/dist/src/instructions/management/luts.d.ts +30 -0
- package/dist/src/instructions/management/luts.js +99 -0
- package/dist/src/instructions/pda.d.ts +25 -0
- package/dist/src/instructions/pda.js +128 -0
- package/dist/src/instructions/user/deposit.d.ts +20 -0
- package/dist/src/instructions/user/deposit.js +100 -0
- package/dist/src/instructions/user/withdraw.d.ts +8 -0
- package/dist/src/instructions/user/withdraw.js +36 -0
- package/dist/src/jup.d.ts +49 -0
- package/dist/src/jup.js +80 -0
- package/dist/src/keeperMonitor.d.ts +52 -0
- package/dist/src/keeperMonitor.js +624 -0
- package/dist/src/layouts/basket.d.ts +191 -0
- package/dist/src/layouts/basket.js +51 -0
- package/dist/src/layouts/config.d.ts +281 -0
- package/dist/src/layouts/config.js +237 -0
- package/dist/src/layouts/fraction.d.ts +20 -0
- package/dist/src/layouts/fraction.js +164 -0
- package/dist/src/layouts/intents/bounty.d.ts +18 -0
- package/dist/src/layouts/intents/bounty.js +19 -0
- package/dist/src/layouts/intents/intent.d.ts +209 -0
- package/dist/src/layouts/intents/intent.js +97 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +212 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +94 -0
- package/dist/src/layouts/lookupTable.d.ts +7 -0
- package/dist/src/layouts/lookupTable.js +10 -0
- package/dist/src/layouts/oracle.d.ts +63 -0
- package/dist/src/layouts/oracle.js +96 -0
- package/dist/src/states/basket.d.ts +14 -0
- package/dist/src/states/basket.js +479 -0
- package/dist/src/states/config.d.ts +3 -0
- package/dist/src/states/config.js +71 -0
- package/dist/src/states/intents/intent.d.ts +10 -0
- package/dist/src/states/intents/intent.js +316 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +42 -0
- package/dist/src/states/intents/rebalanceIntent.js +680 -0
- package/dist/src/states/oracles/constants.d.ts +9 -0
- package/dist/src/states/oracles/constants.js +15 -0
- package/dist/src/states/oracles/oracle.d.ts +24 -0
- package/dist/src/states/oracles/oracle.js +168 -0
- package/dist/src/states/oracles/pythOracle.d.ts +132 -0
- package/dist/src/states/oracles/pythOracle.js +609 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +184 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +843 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +120 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +540 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/withdrawBasketFees.d.ts +10 -0
- package/dist/src/states/withdrawBasketFees.js +154 -0
- package/dist/src/txUtils.d.ts +65 -0
- package/dist/src/txUtils.js +306 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +561 -0
- package/package.json +31 -0
- package/src/constants.ts +40 -0
- package/src/index.ts +2431 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/flashSwap.ts +104 -0
- package/src/instructions/automation/priceUpdate.ts +117 -0
- package/src/instructions/automation/rebalanceIntent.ts +181 -0
- package/src/instructions/management/addBounty.ts +55 -0
- package/src/instructions/management/admin.ts +72 -0
- package/src/instructions/management/claimFees.ts +129 -0
- package/src/instructions/management/createBasket.ts +138 -0
- package/src/instructions/management/edit.ts +602 -0
- package/src/instructions/management/luts.ts +157 -0
- package/src/instructions/pda.ts +151 -0
- package/src/instructions/user/deposit.ts +143 -0
- package/src/instructions/user/withdraw.ts +53 -0
- package/src/jup.ts +113 -0
- package/src/keeperMonitor.ts +585 -0
- package/src/layouts/basket.ts +233 -0
- package/src/layouts/config.ts +576 -0
- package/src/layouts/fraction.ts +164 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +324 -0
- package/src/layouts/intents/rebalanceIntent.ts +306 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +157 -0
- package/src/states/basket.ts +527 -0
- package/src/states/config.ts +62 -0
- package/src/states/intents/intent.ts +311 -0
- package/src/states/intents/rebalanceIntent.ts +751 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +212 -0
- package/src/states/oracles/pythOracle.ts +874 -0
- package/src/states/oracles/raydiumClmmOracle.ts +1193 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +784 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/states/withdrawBasketFees.ts +160 -0
- package/src/txUtils.ts +424 -0
- package/test.ts +609 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,2097 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RebalanceHandler = exports.KeeperMonitor = exports.getJupTokenLedgerAndSwapInstructions = exports.TaskType = exports.SymmetryCore = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
18
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
19
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
+
const constants_1 = require("./constants");
|
|
21
|
+
const claimBounty_1 = require("./instructions/automation/claimBounty");
|
|
22
|
+
const flashSwap_1 = require("./instructions/automation/flashSwap");
|
|
23
|
+
const priceUpdate_1 = require("./instructions/automation/priceUpdate");
|
|
24
|
+
const rebalanceIntent_1 = require("./instructions/automation/rebalanceIntent");
|
|
25
|
+
const addBounty_1 = require("./instructions/management/addBounty");
|
|
26
|
+
const admin_1 = require("./instructions/management/admin");
|
|
27
|
+
const claimFees_1 = require("./instructions/management/claimFees");
|
|
28
|
+
const createBasket_1 = require("./instructions/management/createBasket");
|
|
29
|
+
const edit_1 = require("./instructions/management/edit");
|
|
30
|
+
const luts_1 = require("./instructions/management/luts");
|
|
31
|
+
const pda_1 = require("./instructions/pda");
|
|
32
|
+
const deposit_1 = require("./instructions/user/deposit");
|
|
33
|
+
const withdraw_1 = require("./instructions/user/withdraw");
|
|
34
|
+
const jup_1 = require("./jup");
|
|
35
|
+
Object.defineProperty(exports, "getJupTokenLedgerAndSwapInstructions", { enumerable: true, get: function () { return jup_1.getJupTokenLedgerAndSwapInstructions; } });
|
|
36
|
+
const fraction_1 = require("./layouts/fraction");
|
|
37
|
+
const intent_1 = require("./layouts/intents/intent");
|
|
38
|
+
Object.defineProperty(exports, "TaskType", { enumerable: true, get: function () { return intent_1.TaskType; } });
|
|
39
|
+
const rebalanceIntent_2 = require("./layouts/intents/rebalanceIntent");
|
|
40
|
+
const oracle_1 = require("./layouts/oracle");
|
|
41
|
+
const basket_1 = require("./states/basket");
|
|
42
|
+
const config_1 = require("./states/config");
|
|
43
|
+
const intent_2 = require("./states/intents/intent");
|
|
44
|
+
const rebalanceIntent_3 = require("./states/intents/rebalanceIntent");
|
|
45
|
+
const withdrawBasketFees_1 = require("./states/withdrawBasketFees");
|
|
46
|
+
const pythOracle_1 = require("./states/oracles/pythOracle");
|
|
47
|
+
const txUtils_1 = require("./txUtils");
|
|
48
|
+
class SymmetryCore {
|
|
49
|
+
/**
|
|
50
|
+
* Initializes the SymmetryCore SDK.
|
|
51
|
+
* @param params {connection: Connection, network: "devnet" | "mainnet", priorityFee?: number} - The parameters for the SDK.
|
|
52
|
+
* @param params.connection - The connection to the Solana network.
|
|
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 (25_000).
|
|
55
|
+
*/
|
|
56
|
+
constructor(params) {
|
|
57
|
+
var _a;
|
|
58
|
+
this.sdkParams = {
|
|
59
|
+
connection: params.connection,
|
|
60
|
+
network: params.network,
|
|
61
|
+
priorityFee: (_a = params.priorityFee) !== null && _a !== void 0 ? _a : constants_1.PRIORITY_FEE,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sets the priority fee for the SDK.
|
|
66
|
+
* @param {number} priorityFee - The priority fee in micro-lamports.
|
|
67
|
+
*/
|
|
68
|
+
setPriorityFee(priorityFee) {
|
|
69
|
+
this.sdkParams.priorityFee = priorityFee;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetches the global config account.
|
|
73
|
+
* @returns {Promise<GlobalConfig>} The global config.
|
|
74
|
+
*/
|
|
75
|
+
fetchGlobalConfig() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return yield (0, config_1.fetchGlobalConfig)(this.sdkParams.connection);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Fetches a basket by its public key.
|
|
82
|
+
* @param {string} basketPubkey - The public key of the basket.
|
|
83
|
+
* @returns {Promise<Basket>} The basket.
|
|
84
|
+
*/
|
|
85
|
+
fetchBasket(basketPubkey) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
return yield (0, basket_1.fetchBasket)(this.sdkParams.connection, new web3_js_1.PublicKey(basketPubkey));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Fetches multiple baskets by their public keys.
|
|
92
|
+
* @param {string[]} basketPubkeys - The public keys of the baskets.
|
|
93
|
+
* @returns {Promise<Map<string, Basket>>} A map of basket public keys to baskets.
|
|
94
|
+
*/
|
|
95
|
+
fetchMultipleBaskets(basketPubkeys) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return yield (0, basket_1.fetchBasketsMultiple)(this.sdkParams.connection, basketPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Fetches all baskets.
|
|
102
|
+
* @param {BasketFilter} basketFilter - Optional. The filter to apply to the baskets.
|
|
103
|
+
* @param {"creator" | "host" | "manager"} basketFilter.type - The type of the basket filter ("creator", "host", "manager").
|
|
104
|
+
* @param {string} basketFilter.pubkey - The public key of the basket filter.
|
|
105
|
+
* @returns {Promise<Basket[]>} The baskets.
|
|
106
|
+
*/
|
|
107
|
+
fetchAllBaskets(basketFilter) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, basketFilter);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Fetches all baskets created by a given public key.
|
|
114
|
+
* @param {string} creatorPubkey - The public key of the creator.
|
|
115
|
+
* @returns {Promise<Basket[]>} The baskets.
|
|
116
|
+
*/
|
|
117
|
+
fetchCreatedBaskets(creatorPubkey) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "creator", pubkey: creatorPubkey });
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Fetches all baskets hosted by a given public key.
|
|
124
|
+
* @param {string} hostPubkey - The public key of the host.
|
|
125
|
+
* @returns {Promise<Basket[]>} The baskets.
|
|
126
|
+
*/
|
|
127
|
+
fetchHostedBaskets(hostPubkey) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "host", pubkey: hostPubkey });
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Fetches all baskets managed by a given public key.
|
|
134
|
+
* @param {string} managerPubkey - The public key of the manager.
|
|
135
|
+
* @returns {Promise<Basket[]>} The baskets.
|
|
136
|
+
*/
|
|
137
|
+
fetchManagedBaskets(managerPubkey) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
return yield (0, basket_1.fetchBaskets)(this.sdkParams.connection, { type: "manager", pubkey: managerPubkey });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Derives baskets by their mints.
|
|
144
|
+
* @param {string[]} mints - The mint public keys of the baskets.
|
|
145
|
+
* @returns {Promise<Map<string, string>>} A map of basket mint public keys to basket public keys.
|
|
146
|
+
*/
|
|
147
|
+
deriveBasketsByMints(mints) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
let result = new Map();
|
|
150
|
+
for (let basketId = 0; basketId < 50000; basketId++) {
|
|
151
|
+
let mint = (0, pda_1.getBasketTokenMintPda)(basketId).toBase58();
|
|
152
|
+
if (mints.includes(mint)) {
|
|
153
|
+
result.set(mint, (0, pda_1.getBasketState)(new web3_js_1.PublicKey(mint)).toBase58());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Fetches baskets by their mint public keys.
|
|
161
|
+
* @param {string[]} mints - The mint public keys of the baskets.
|
|
162
|
+
* @returns {Promise<Map<string, Basket>>} A map of basket mint public keys to baskets.
|
|
163
|
+
*/
|
|
164
|
+
fetchBasketsFromMints(mints) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
let basketPubkeys = mints.map(mint => {
|
|
167
|
+
let res = null;
|
|
168
|
+
try {
|
|
169
|
+
res = (0, pda_1.getBasketState)(new web3_js_1.PublicKey(mint));
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return res;
|
|
175
|
+
}).filter(mint => mint !== null);
|
|
176
|
+
const basketsMap = yield (0, basket_1.fetchBasketsMultiple)(this.sdkParams.connection, basketPubkeys);
|
|
177
|
+
let mintsMap = new Map();
|
|
178
|
+
for (let basket of basketsMap.values()) {
|
|
179
|
+
mintsMap.set(basket.mint.toBase58(), basket);
|
|
180
|
+
}
|
|
181
|
+
return mintsMap;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Loads the price of a basket.
|
|
186
|
+
* @param {Basket} basket - The basket.
|
|
187
|
+
* @returns {Promise<Basket>} The basket with the price.
|
|
188
|
+
*/
|
|
189
|
+
loadBasketPrice(basket) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
return yield (0, basket_1.loadBasketPrice)(basket, this.sdkParams.connection);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Fetches an intent by its public key.
|
|
196
|
+
* @param {string} intentPubkey - The public key of the intent.
|
|
197
|
+
* @returns {Promise<Intent>} The intent.
|
|
198
|
+
*/
|
|
199
|
+
fetchIntent(intentPubkey) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
return yield (0, intent_2.fetchIntent)(this.sdkParams.connection, new web3_js_1.PublicKey(intentPubkey));
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Fetches multiple intents by their public keys.
|
|
206
|
+
* @param {string[]} intentPubkeys - The public keys of the intents.
|
|
207
|
+
* @returns {Promise<Map<string, Intent>>} A map of intent public keys to intents.
|
|
208
|
+
*/
|
|
209
|
+
fetchMultipleIntents(intentPubkeys) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
return yield (0, intent_2.fetchIntentsMultiple)(this.sdkParams.connection, intentPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Fetches all intents.
|
|
216
|
+
* @param {IntentFilter} filter - Optional. The filter to apply to the intents.
|
|
217
|
+
* @param {"creator" | "host" | "manager" | "basket" | "owner"} filter.type - The type of the intent filter ("creator", "host", "manager", "basket", "owner").
|
|
218
|
+
* @param {string} filter.pubkey - The public key of the intent filter.
|
|
219
|
+
* @returns {Promise<Intent[]>} The intents.
|
|
220
|
+
*/
|
|
221
|
+
fetchAllIntents(filter) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
return yield (0, intent_2.fetchIntents)(this.sdkParams.connection, filter);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Fetches all intents created by a given public key.
|
|
228
|
+
* @param {string} creatorPubkey - The public key of the creator.
|
|
229
|
+
* @returns {Promise<Intent[]>} The intents.
|
|
230
|
+
*/
|
|
231
|
+
fetchCreatedIntents(creatorPubkey) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
return yield (0, intent_2.fetchIntents)(this.sdkParams.connection, { type: "manager", pubkey: creatorPubkey });
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Fetches all intents for a given basket.
|
|
238
|
+
* @param {string} basketPubkey - The public key of the basket.
|
|
239
|
+
* @returns {Promise<Intent[]>} The intents.
|
|
240
|
+
*/
|
|
241
|
+
fetchBasketIntents(basketPubkey) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
return yield (0, intent_2.fetchIntents)(this.sdkParams.connection, { type: "basket", pubkey: basketPubkey });
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Fetches a rebalance intent by its public key.
|
|
248
|
+
* @param {string} rebalanceIntentPubkey - The public key of the rebalance intent.
|
|
249
|
+
* @returns {Promise<UIRebalanceIntent>} The rebalance intent.
|
|
250
|
+
*/
|
|
251
|
+
fetchRebalanceIntent(rebalanceIntentPubkey) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
return yield (0, rebalanceIntent_3.fetchRebalanceIntent)(this.sdkParams.connection, new web3_js_1.PublicKey(rebalanceIntentPubkey));
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Fetches multiple rebalance intents by their public keys.
|
|
258
|
+
* @param {string[]} rebalanceIntentPubkeys - The public keys of the rebalance intents.
|
|
259
|
+
* @returns {Promise<Map<string, UIRebalanceIntent>>} A map of rebalance intent public keys to rebalance intents.
|
|
260
|
+
*/
|
|
261
|
+
fetchMultipleRebalanceIntents(rebalanceIntentPubkeys) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
return yield (0, rebalanceIntent_3.fetchRebalanceIntentsMultiple)(this.sdkParams.connection, rebalanceIntentPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Fetches all rebalance intents.
|
|
268
|
+
* @param {RebalanceIntentFilter} filter - Optional. The filter to apply to the rebalance intents.
|
|
269
|
+
* @param {"owner" | "basket"} filter.type - The type of the rebalance intent filter ("owner", "basket").
|
|
270
|
+
* @param {string} filter.pubkey - The public key of the rebalance intent filter.
|
|
271
|
+
* @returns {Promise<UIRebalanceIntent[]>} The rebalance intents.
|
|
272
|
+
*/
|
|
273
|
+
fetchAllRebalanceIntents(filter) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
return yield (0, rebalanceIntent_3.fetchRebalanceIntents)(this.sdkParams.connection, filter);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Fetches all rebalance intents for a given owner.
|
|
280
|
+
* @param {string} ownerPubkey - The public key of the owner.
|
|
281
|
+
* @returns {Promise<UIRebalanceIntent[]>} The rebalance intents.
|
|
282
|
+
*/
|
|
283
|
+
fetchOwnerRebalanceIntents(ownerPubkey) {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
return yield (0, rebalanceIntent_3.fetchRebalanceIntents)(this.sdkParams.connection, { type: "owner", pubkey: ownerPubkey });
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Fetches all rebalance intents for a given basket.
|
|
290
|
+
* @param {string} basketPubkey - The public key of the basket.
|
|
291
|
+
* @returns {Promise<UIRebalanceIntent[]>} The rebalance intents.
|
|
292
|
+
*/
|
|
293
|
+
fetchBasketRebalanceIntents(basketPubkey) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
return yield (0, rebalanceIntent_3.fetchRebalanceIntents)(this.sdkParams.connection, { type: "basket", pubkey: basketPubkey });
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Fetches a WithdrawBasketFees account by its public key.
|
|
300
|
+
* @param {string} withdrawBasketFeesPubkey - The public key of the WithdrawBasketFees account.
|
|
301
|
+
* @returns {Promise<WithdrawBasketFees>} The WithdrawBasketFees account.
|
|
302
|
+
*/
|
|
303
|
+
fetchWithdrawBasketFees(withdrawBasketFeesPubkey) {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFees)(this.sdkParams.connection, new web3_js_1.PublicKey(withdrawBasketFeesPubkey));
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Fetches multiple WithdrawBasketFees accounts by their public keys.
|
|
310
|
+
* @param {string[]} withdrawBasketFeesPubkeys - The public keys of the WithdrawBasketFees accounts.
|
|
311
|
+
* @returns {Promise<Map<string, WithdrawBasketFees>>} A map of WithdrawBasketFees public keys to WithdrawBasketFees accounts.
|
|
312
|
+
*/
|
|
313
|
+
fetchMultipleWithdrawBasketFees(withdrawBasketFeesPubkeys) {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesMultiple)(this.sdkParams.connection, withdrawBasketFeesPubkeys.map(key => new web3_js_1.PublicKey(key)));
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Fetches all WithdrawBasketFees accounts with optional filter.
|
|
320
|
+
* @param {WithdrawBasketFeesFilter} filter - Optional. The filter to apply to the WithdrawBasketFees accounts.
|
|
321
|
+
* @param {"basket" | "manager" | "creator" | "host" | "symmetry"} filter.type - The type of the filter.
|
|
322
|
+
* @param {string} filter.pubkey - The public key to filter by.
|
|
323
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
324
|
+
*/
|
|
325
|
+
fetchAllWithdrawBasketFees(filter) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, filter);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Fetches all WithdrawBasketFees accounts for a given basket.
|
|
332
|
+
* @param {string} basketPubkey - The public key of the basket.
|
|
333
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
334
|
+
*/
|
|
335
|
+
fetchBasketWithdrawBasketFees(basketPubkey) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, { type: "basket", pubkey: basketPubkey });
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Fetches all WithdrawBasketFees accounts for a given manager.
|
|
342
|
+
* @param {string} managerPubkey - The public key of the manager.
|
|
343
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
344
|
+
*/
|
|
345
|
+
fetchManagerWithdrawBasketFees(managerPubkey) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, { type: "manager", pubkey: managerPubkey });
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Fetches all WithdrawBasketFees accounts for a given creator.
|
|
352
|
+
* @param {string} creatorPubkey - The public key of the creator.
|
|
353
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
354
|
+
*/
|
|
355
|
+
fetchCreatorWithdrawBasketFees(creatorPubkey) {
|
|
356
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, { type: "creator", pubkey: creatorPubkey });
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Fetches all WithdrawBasketFees accounts for a given host.
|
|
362
|
+
* @param {string} hostPubkey - The public key of the host.
|
|
363
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
364
|
+
*/
|
|
365
|
+
fetchHostWithdrawBasketFees(hostPubkey) {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, { type: "host", pubkey: hostPubkey });
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Fetches all WithdrawBasketFees accounts for a given symmetry fee collector.
|
|
372
|
+
* @param {string} symmetryPubkey - The public key of the symmetry fee collector.
|
|
373
|
+
* @returns {Promise<WithdrawBasketFees[]>} The WithdrawBasketFees accounts.
|
|
374
|
+
*/
|
|
375
|
+
fetchSymmetryWithdrawBasketFees(symmetryPubkey) {
|
|
376
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
+
return yield (0, withdrawBasketFees_1.fetchWithdrawBasketFeesList)(this.sdkParams.connection, { type: "symmetry", pubkey: symmetryPubkey });
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
createGlobalConfigTx(params) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
let ix = (0, admin_1.createGlobalConfigIx)({ admin: params.signer });
|
|
383
|
+
let txBatchData = { batches: [[{
|
|
384
|
+
payer: params.signer,
|
|
385
|
+
instructions: [
|
|
386
|
+
ix,
|
|
387
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
388
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
389
|
+
],
|
|
390
|
+
lookupTables: [],
|
|
391
|
+
}]] };
|
|
392
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
393
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
394
|
+
return txPayloadBatchSequence;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
editGlobalConfigTx(params) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
let ix = (0, admin_1.editGlobalConfigIx)(params);
|
|
400
|
+
let txBatchData = { batches: [[{
|
|
401
|
+
payer: params.signer,
|
|
402
|
+
instructions: [
|
|
403
|
+
ix,
|
|
404
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
405
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
406
|
+
],
|
|
407
|
+
lookupTables: [],
|
|
408
|
+
}]] };
|
|
409
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
410
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
411
|
+
return txPayloadBatchSequence;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Creates a basket.
|
|
416
|
+
* @param {Object} params - The parameters for the basket creation.
|
|
417
|
+
* @param {string} params.creator - The public key of the creator.
|
|
418
|
+
* @param {string} params.start_price - The start price of the basket.
|
|
419
|
+
* @param {string} params.name - The name of the basket.
|
|
420
|
+
* @param {string} params.symbol - The symbol of the basket.
|
|
421
|
+
* @param {string} params.metadata_uri - The metadata URI of the basket.
|
|
422
|
+
* @param {Object} params.host_platform_params - Optional. The host platform parameters.
|
|
423
|
+
* @param {string} params.host_platform_params.host_pubkey - The public key of the host.
|
|
424
|
+
* @param {number} params.host_platform_params.host_deposit_fee_bps - The host deposit fee in basis points.
|
|
425
|
+
* @param {number} params.host_platform_params.host_withdraw_fee_bps - The host withdrawal fee in basis points.
|
|
426
|
+
* @param {number} params.host_platform_params.host_management_fee_bps - The host management fee in basis points.
|
|
427
|
+
* @param {number} params.host_platform_params.host_performance_fee_bps - The host performance fee in basis points.
|
|
428
|
+
* @returns {Promise<BasketCreationTx>} The basket creation transaction.
|
|
429
|
+
*/
|
|
430
|
+
createBasketTx(params) {
|
|
431
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
433
|
+
const creator = new web3_js_1.PublicKey(params.creator);
|
|
434
|
+
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);
|
|
435
|
+
const hostFees = {
|
|
436
|
+
hostDepositFeeBps: (_d = (_c = params.host_platform_params) === null || _c === void 0 ? void 0 : _c.host_deposit_fee_bps) !== null && _d !== void 0 ? _d : 0,
|
|
437
|
+
hostWithdrawalFeeBps: (_f = (_e = params.host_platform_params) === null || _e === void 0 ? void 0 : _e.host_withdraw_fee_bps) !== null && _f !== void 0 ? _f : 0,
|
|
438
|
+
hostManagementFeeBps: (_h = (_g = params.host_platform_params) === null || _g === void 0 ? void 0 : _g.host_management_fee_bps) !== null && _h !== void 0 ? _h : 0,
|
|
439
|
+
hostPerformanceFeeBps: (_k = (_j = params.host_platform_params) === null || _j === void 0 ? void 0 : _j.host_performance_fee_bps) !== null && _k !== void 0 ? _k : 0,
|
|
440
|
+
};
|
|
441
|
+
const metadataParams = {
|
|
442
|
+
name: params.name,
|
|
443
|
+
symbol: params.symbol,
|
|
444
|
+
uri: params.metadata_uri,
|
|
445
|
+
};
|
|
446
|
+
const startPrice = (0, fraction_1.decimalToFraction)(new decimal_js_1.default(parseFloat(params.start_price) / 10 ** 6));
|
|
447
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
448
|
+
let bountyWsolAmount = 0;
|
|
449
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
450
|
+
let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
|
|
451
|
+
let minBasketAutomationBounty = parseInt(globalConfig.minBountyForBasketAutomation.toString());
|
|
452
|
+
bountyWsolAmount = boundBounty + minBasketAutomationBounty;
|
|
453
|
+
}
|
|
454
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, creator, bountyWsolAmount);
|
|
455
|
+
let basketId = parseInt(globalConfig.totalNumberOfBaskets.toString());
|
|
456
|
+
let mint = (0, pda_1.getBasketTokenMintPda)(basketId);
|
|
457
|
+
let basket = (0, pda_1.getBasketState)(mint);
|
|
458
|
+
const slot = yield this.sdkParams.connection.getSlot();
|
|
459
|
+
let ix = (0, createBasket_1.createBasketIx)({
|
|
460
|
+
basket,
|
|
461
|
+
mint,
|
|
462
|
+
slot,
|
|
463
|
+
creator,
|
|
464
|
+
host,
|
|
465
|
+
startPrice: startPrice,
|
|
466
|
+
hostFees,
|
|
467
|
+
metadataParams,
|
|
468
|
+
network: this.sdkParams.network,
|
|
469
|
+
});
|
|
470
|
+
let preIx = (0, createBasket_1.createBasketStateAccountIx)({
|
|
471
|
+
creator,
|
|
472
|
+
basket
|
|
473
|
+
});
|
|
474
|
+
let preIx2 = (0, createBasket_1.resizeBasketStateIx)({
|
|
475
|
+
basket
|
|
476
|
+
});
|
|
477
|
+
let createBasketFeesAccountIx = (0, spl_token_1.createAssociatedTokenAccountInstruction)(creator, (0, pda_1.getAta)((0, pda_1.getBasketFeesPda)(basket), mint), (0, pda_1.getBasketFeesPda)(basket), mint);
|
|
478
|
+
let txBatchData = { batches: [[{
|
|
479
|
+
payer: creator,
|
|
480
|
+
instructions: [
|
|
481
|
+
...wsolIxs,
|
|
482
|
+
preIx, preIx2, preIx2, ix, createBasketFeesAccountIx,
|
|
483
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
484
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
485
|
+
],
|
|
486
|
+
lookupTables: [],
|
|
487
|
+
}]] };
|
|
488
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
489
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
490
|
+
return {
|
|
491
|
+
mint: mint.toBase58(),
|
|
492
|
+
basket: basket.toBase58(),
|
|
493
|
+
batches: txPayloadBatchSequence.batches,
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Changes the creator of a basket.
|
|
499
|
+
* @param {TaskContext} context - The context of the task.
|
|
500
|
+
* @param {EditCreatorSettings} settings - The settings for the creator edit.
|
|
501
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
502
|
+
*/
|
|
503
|
+
editCreatorTx(context, settings) {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditCreator, context, settings });
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Creates an edit manager settings intent for a basket.
|
|
510
|
+
* @param {TaskContext} context - The context of the task.
|
|
511
|
+
* @param {EditManagerSettings} settings - The settings for the manager edit.
|
|
512
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
513
|
+
*/
|
|
514
|
+
editManagersTx(context, settings) {
|
|
515
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
516
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditManagerSettings, context, settings });
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Creates an edit schedule settings intent for a basket.
|
|
521
|
+
* @param {TaskContext} context - The context of the task.
|
|
522
|
+
* @param {EditScheduleSettings} settings - The settings for the schedule edit.
|
|
523
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
524
|
+
*/
|
|
525
|
+
editScheduleTx(context, settings) {
|
|
526
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditScheduleSettings, context, settings });
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Creates an edit fees settings intent for a basket.
|
|
532
|
+
* @param {TaskContext} context - The context of the task.
|
|
533
|
+
* @param {EditFeeSettings} settings - The settings for the fee edit.
|
|
534
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
535
|
+
*/
|
|
536
|
+
editFeesTx(context, settings) {
|
|
537
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
538
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditFeeSettings, context, settings });
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Creates an edit automation settings intent for a basket.
|
|
543
|
+
* @param {TaskContext} context - The context of the task.
|
|
544
|
+
* @param {EditAutomationSettings} settings - The settings for the automation edit.
|
|
545
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
546
|
+
*/
|
|
547
|
+
editAutomationTx(context, settings) {
|
|
548
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
549
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditAutomationSettings, context, settings });
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Creates an edit LP settings intent for a basket.
|
|
554
|
+
* @param {TaskContext} context - The context of the task.
|
|
555
|
+
* @param {EditLpSettings} settings - The settings for the LP edit.
|
|
556
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
557
|
+
*/
|
|
558
|
+
editLpTx(context, settings) {
|
|
559
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
560
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditLpSettings, context, settings });
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Creates an edit metadata settings intent for a basket.
|
|
565
|
+
* @param {TaskContext} context - The context of the task.
|
|
566
|
+
* @param {EditMetadataSettings} settings - The settings for the metadata edit.
|
|
567
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
568
|
+
*/
|
|
569
|
+
editMetadataTx(context, settings) {
|
|
570
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
571
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditMetadataSettings, context, settings });
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Creates an edit deposits settings intent for a basket.
|
|
576
|
+
* @param {TaskContext} context - The context of the task.
|
|
577
|
+
* @param {EditDepositsSettings} settings - The settings for the deposits edit.
|
|
578
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
579
|
+
*/
|
|
580
|
+
editDepositsTx(context, settings) {
|
|
581
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
582
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditDepositsSettings, context, settings });
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Creates an edit force rebalance settings intent for a basket.
|
|
587
|
+
* @param {TaskContext} context - The context of the task.
|
|
588
|
+
* @param {EditForceRebalanceSettings} settings - The settings for the force rebalance edit.
|
|
589
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
590
|
+
*/
|
|
591
|
+
editForceRebalanceTx(context, settings) {
|
|
592
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditForceRebalanceSettings, context, settings });
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Creates an edit custom rebalance settings intent for a basket.
|
|
598
|
+
* @param {TaskContext} context - The context of the task.
|
|
599
|
+
* @param {EditCustomRebalanceSettings} settings - The settings for the custom rebalance edit.
|
|
600
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
601
|
+
*/
|
|
602
|
+
editCustomRebalanceTx(context, settings) {
|
|
603
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditCustomRebalanceSettings, context, settings });
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Creates an edit add token delay intent for a basket.
|
|
609
|
+
* @param {TaskContext} context - The context of the task.
|
|
610
|
+
* @param {EditAddTokenSettings} settings - The settings for the add token delay edit.
|
|
611
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
612
|
+
*/
|
|
613
|
+
editAddTokenDelayTx(context, settings) {
|
|
614
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditAddTokenDelay, context, settings });
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Creates an edit update weights delay intent for a basket.
|
|
620
|
+
* @param {TaskContext} context - The context of the task.
|
|
621
|
+
* @param {EditUpdateWeightsSettings} settings - The settings for the update weights delay edit.
|
|
622
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
623
|
+
*/
|
|
624
|
+
editUpdateWeightsDelayTx(context, settings) {
|
|
625
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
626
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditUpdateWeightsDelay, context, settings });
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Creates an edit swap delay intent for a basket.
|
|
631
|
+
* @param {TaskContext} context - The context of the task.
|
|
632
|
+
* @param {EditMakeDirectSwapSettings} settings - The settings for the make direct swap delay edit.
|
|
633
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
634
|
+
*/
|
|
635
|
+
editSwapDelayTx(context, settings) {
|
|
636
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
637
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.EditMakeDirectSwapDelay, context, settings });
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Creates an add or edit token intent for a basket.
|
|
642
|
+
* @param {TaskContext} context - The context of the task.
|
|
643
|
+
* @param {AddOrEditTokenInput} settings - The settings for the add or edit token.
|
|
644
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
645
|
+
*/
|
|
646
|
+
addOrEditTokenTx(context, settings) {
|
|
647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.AddToken, context, settings });
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Creates a update weights intent for a basket.
|
|
653
|
+
* @param {TaskContext} context - The context of the task.
|
|
654
|
+
* @param {UpdateWeightsInput} settings - The settings for the update weights.
|
|
655
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
656
|
+
*/
|
|
657
|
+
updateWeightsTx(context, settings) {
|
|
658
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
659
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.UpdateWeights, context, settings });
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Creates a direct swap intent for a basket.
|
|
664
|
+
* @param {TaskContext} context - The context of the task.
|
|
665
|
+
* @param {MakeDirectSwapInput} settings - The settings for the make direct swap.
|
|
666
|
+
* @param {TransactionInstruction} jup_swap_ix - Optional. The JUP swap instruction.
|
|
667
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
668
|
+
*/
|
|
669
|
+
makeDirectSwapTx(context, settings, jup_swap_ix) {
|
|
670
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
671
|
+
return this.openBasketIntentTx({ type: intent_1.TaskType.MakeDirectSwap, context, settings, jup_swap_ix: jup_swap_ix });
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Creates basket intent account.
|
|
676
|
+
* @param {Object} params - The parameters for the basket intent.
|
|
677
|
+
* @param {TaskContext} params.context - The context of the task.
|
|
678
|
+
* @param {TaskType} params.type - The type of the task.
|
|
679
|
+
* @param {Settings} params.settings - The settings for the task.
|
|
680
|
+
* @param {number} params.min_bounty_per_task - Optional. The minimum bounty per task.
|
|
681
|
+
* @param {number} params.max_bounty_per_task - Optional. The maximum bounty per task.
|
|
682
|
+
* @param {TransactionInstruction} params.jup_swap_ix - Optional. The JUP swap instruction (for MakeDirectSwap task).
|
|
683
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
684
|
+
*/
|
|
685
|
+
openBasketIntentTx(params) {
|
|
686
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
687
|
+
var _a, _b;
|
|
688
|
+
let basket = yield this.fetchBasket(params.context.basket);
|
|
689
|
+
let manager = new web3_js_1.PublicKey(params.context.manager);
|
|
690
|
+
let activationTimestamp = new bn_js_1.default((_a = params.context.activation_timestamp) !== null && _a !== void 0 ? _a : 0);
|
|
691
|
+
let expirationTimestamp = new bn_js_1.default((_b = params.context.expiration_timestamp) !== null && _b !== void 0 ? _b : 0);
|
|
692
|
+
let editType = params.type;
|
|
693
|
+
let editData = params.settings;
|
|
694
|
+
let modificationDelay = (() => {
|
|
695
|
+
switch (editType) {
|
|
696
|
+
case intent_1.TaskType.EditCreator: return new bn_js_1.default(0);
|
|
697
|
+
case intent_1.TaskType.EditManagerSettings: return basket.settings.managers.modificationDelay;
|
|
698
|
+
case intent_1.TaskType.EditFeeSettings: return basket.settings.fees.modificationDelay;
|
|
699
|
+
case intent_1.TaskType.EditScheduleSettings: return basket.settings.schedule.modificationDelay;
|
|
700
|
+
case intent_1.TaskType.EditAutomationSettings: return basket.settings.automation.modificationDelay;
|
|
701
|
+
case intent_1.TaskType.EditLpSettings: return basket.settings.lp.modificationDelay;
|
|
702
|
+
case intent_1.TaskType.EditMetadataSettings: return basket.settings.metadata.modificationDelay;
|
|
703
|
+
case intent_1.TaskType.EditDepositsSettings: return new bn_js_1.default(0);
|
|
704
|
+
case intent_1.TaskType.EditForceRebalanceSettings: return basket.settings.forceRebalanceModificationDelay;
|
|
705
|
+
case intent_1.TaskType.EditCustomRebalanceSettings: return basket.settings.customRebalanceModificationDelay;
|
|
706
|
+
case intent_1.TaskType.EditAddTokenDelay: return basket.settings.addTokenDelay;
|
|
707
|
+
case intent_1.TaskType.EditUpdateWeightsDelay: return basket.settings.updateWeightsDelay;
|
|
708
|
+
case intent_1.TaskType.EditMakeDirectSwapDelay: return basket.settings.makeDirectSwapDelay;
|
|
709
|
+
case intent_1.TaskType.AddToken: return basket.settings.addTokenDelay;
|
|
710
|
+
case intent_1.TaskType.UpdateWeights: return basket.settings.updateWeightsDelay;
|
|
711
|
+
case intent_1.TaskType.MakeDirectSwap: return basket.settings.makeDirectSwapDelay;
|
|
712
|
+
default: return new bn_js_1.default(0);
|
|
713
|
+
}
|
|
714
|
+
})();
|
|
715
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
716
|
+
let minBounty = params.context.min_bounty !== undefined
|
|
717
|
+
? new bn_js_1.default(params.context.min_bounty)
|
|
718
|
+
: globalConfig.bountyPerTask.minBounty;
|
|
719
|
+
let maxBounty = params.context.max_bounty !== undefined
|
|
720
|
+
? new bn_js_1.default(params.context.max_bounty)
|
|
721
|
+
: globalConfig.bountyPerTask.maxBounty;
|
|
722
|
+
if (parseInt(minBounty.toString()) > parseInt(maxBounty.toString()))
|
|
723
|
+
minBounty = maxBounty.div(new bn_js_1.default(2));
|
|
724
|
+
let bountyWsolAmount = 0;
|
|
725
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
726
|
+
let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
|
|
727
|
+
let maxBountyPerTask = parseInt(maxBounty.toString());
|
|
728
|
+
bountyWsolAmount = maxBountyPerTask + boundBounty;
|
|
729
|
+
}
|
|
730
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, manager, bountyWsolAmount);
|
|
731
|
+
let intentSeedArray = web3_js_1.Keypair.generate().publicKey.toBytes();
|
|
732
|
+
let tokenProgram = undefined;
|
|
733
|
+
if (editType === intent_1.TaskType.AddToken) {
|
|
734
|
+
let tokenMint = new web3_js_1.PublicKey(editData.token_mint);
|
|
735
|
+
intentSeedArray = tokenMint.toBytes();
|
|
736
|
+
let tokenInfo = yield this.sdkParams.connection.getAccountInfo(tokenMint);
|
|
737
|
+
if (tokenInfo.owner.equals(spl_token_1.TOKEN_PROGRAM_ID) || tokenInfo.owner.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)) {
|
|
738
|
+
tokenProgram = tokenInfo.owner;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
let intent = (0, pda_1.getIntentPda)(basket.ownAddress, intentSeedArray, editType);
|
|
742
|
+
let openBasketIntentIx = (0, edit_1.createEditBasketIntentIx)({
|
|
743
|
+
manager: manager,
|
|
744
|
+
basket: basket,
|
|
745
|
+
intent: intent,
|
|
746
|
+
intentSeedArray: intentSeedArray,
|
|
747
|
+
editType: editType,
|
|
748
|
+
editData: editData,
|
|
749
|
+
activationTimestamp: activationTimestamp,
|
|
750
|
+
expirationTimestamp: expirationTimestamp,
|
|
751
|
+
minBounty: minBounty,
|
|
752
|
+
maxBounty: maxBounty,
|
|
753
|
+
tokenProgram: tokenProgram,
|
|
754
|
+
});
|
|
755
|
+
let txBatchData = { batches: [[{
|
|
756
|
+
payer: manager,
|
|
757
|
+
instructions: [
|
|
758
|
+
...wsolIxs,
|
|
759
|
+
openBasketIntentIx,
|
|
760
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
761
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
762
|
+
],
|
|
763
|
+
lookupTables: [],
|
|
764
|
+
}]] };
|
|
765
|
+
// Only execute in the same transaction when there is no delay and no scheduled activation.
|
|
766
|
+
if (modificationDelay.eq(new bn_js_1.default(0)) && activationTimestamp.eq(new bn_js_1.default(0))) {
|
|
767
|
+
let executeBasketIntentIx = (0, edit_1.executeEditBasketIntentIx)({
|
|
768
|
+
basket: basket.ownAddress,
|
|
769
|
+
intent: intent,
|
|
770
|
+
editType: editType,
|
|
771
|
+
manager: manager,
|
|
772
|
+
bountyMint: basket.settings.bountyMint,
|
|
773
|
+
keeper: manager,
|
|
774
|
+
basketMint: basket.mint,
|
|
775
|
+
});
|
|
776
|
+
if (editType == intent_1.TaskType.MakeDirectSwap && params.jup_swap_ix) {
|
|
777
|
+
let flashParams = {
|
|
778
|
+
keeper: manager,
|
|
779
|
+
basket: basket.ownAddress,
|
|
780
|
+
rebalanceIntent: undefined,
|
|
781
|
+
intent: intent,
|
|
782
|
+
mintIn: new web3_js_1.PublicKey(editData.from_token_mint),
|
|
783
|
+
mintOut: new web3_js_1.PublicKey(editData.to_token_mint),
|
|
784
|
+
amountIn: new bn_js_1.default(editData.amount_from),
|
|
785
|
+
amountOut: new bn_js_1.default(editData.amount_to),
|
|
786
|
+
mode: undefined,
|
|
787
|
+
};
|
|
788
|
+
let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
|
|
789
|
+
let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
|
|
790
|
+
txBatchData.batches.push([{
|
|
791
|
+
payer: manager,
|
|
792
|
+
instructions: [
|
|
793
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintIn), manager, flashParams.mintIn),
|
|
794
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(manager, (0, pda_1.getAta)(manager, flashParams.mintOut), manager, flashParams.mintOut),
|
|
795
|
+
ixWithdraw,
|
|
796
|
+
params.jup_swap_ix,
|
|
797
|
+
ixDeposit,
|
|
798
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
799
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
800
|
+
],
|
|
801
|
+
lookupTables: [],
|
|
802
|
+
}]);
|
|
803
|
+
txBatchData.batches.push([{
|
|
804
|
+
payer: manager,
|
|
805
|
+
instructions: [
|
|
806
|
+
executeBasketIntentIx,
|
|
807
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
808
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
809
|
+
],
|
|
810
|
+
lookupTables: [],
|
|
811
|
+
}]);
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
txBatchData.batches[0][0].instructions = [
|
|
815
|
+
...wsolIxs,
|
|
816
|
+
openBasketIntentIx,
|
|
817
|
+
executeBasketIntentIx,
|
|
818
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
819
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
820
|
+
];
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
824
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
825
|
+
return txPayloadBatchSequence;
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Executes a basket intent. Basket intent will be executed immediately.
|
|
830
|
+
* @param {Object} params - The parameters for the basket intent.
|
|
831
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
832
|
+
* @param {string} params.intent - The public key of the intent.
|
|
833
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
834
|
+
*/
|
|
835
|
+
executeBasketIntentTx(params) {
|
|
836
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
837
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
838
|
+
let intent = yield this.fetchIntent(params.intent);
|
|
839
|
+
let basketMint;
|
|
840
|
+
if (intent.taskType === intent_1.TaskType.EditMetadataSettings) {
|
|
841
|
+
let basket = yield this.fetchBasket(intent.basket.toBase58());
|
|
842
|
+
basketMint = basket.mint;
|
|
843
|
+
}
|
|
844
|
+
let ix = (0, edit_1.executeEditBasketIntentIx)({
|
|
845
|
+
basket: intent.basket,
|
|
846
|
+
intent: intent.ownAddress,
|
|
847
|
+
editType: intent.taskType,
|
|
848
|
+
manager: intent.manager,
|
|
849
|
+
bountyMint: intent.bounty.bountyMint,
|
|
850
|
+
keeper: keeper,
|
|
851
|
+
basketMint: intent.taskType === intent_1.TaskType.EditMetadataSettings ? basketMint : undefined,
|
|
852
|
+
});
|
|
853
|
+
let txBatchData = { batches: [[{
|
|
854
|
+
payer: keeper,
|
|
855
|
+
instructions: [
|
|
856
|
+
ix,
|
|
857
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
858
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
859
|
+
],
|
|
860
|
+
lookupTables: [],
|
|
861
|
+
}]] };
|
|
862
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
863
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
864
|
+
return txPayloadBatchSequence;
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Cancels a basket intent. Basket intent account will get closed.
|
|
869
|
+
* @param {Object} params - The parameters for the basket intent.
|
|
870
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
871
|
+
* @param {string} params.intent - The public key of the intent.
|
|
872
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
873
|
+
*/
|
|
874
|
+
cancelBasketIntentTx(params) {
|
|
875
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
876
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
877
|
+
let intent = yield this.fetchIntent(params.intent);
|
|
878
|
+
let ix = (0, edit_1.cancelIntentIx)({
|
|
879
|
+
keeper: keeper,
|
|
880
|
+
basket: intent.basket,
|
|
881
|
+
intent: intent.ownAddress,
|
|
882
|
+
editType: intent.taskType,
|
|
883
|
+
manager: intent.manager,
|
|
884
|
+
bountyMint: intent.bounty.bountyMint,
|
|
885
|
+
});
|
|
886
|
+
let txBatchData = { batches: [[{
|
|
887
|
+
payer: keeper,
|
|
888
|
+
instructions: [
|
|
889
|
+
ix,
|
|
890
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
891
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
892
|
+
],
|
|
893
|
+
lookupTables: [],
|
|
894
|
+
}]] };
|
|
895
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
896
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
897
|
+
return txPayloadBatchSequence;
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Cancels a rebalance intent. Rebalance intent status will be set to AuctionFinished.
|
|
902
|
+
* @param {Object} params - The parameters for the rebalance intent.
|
|
903
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
904
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent.
|
|
905
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
906
|
+
*/
|
|
907
|
+
cancelRebalanceIntentTx(params) {
|
|
908
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
909
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
910
|
+
let intent = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
|
|
911
|
+
let ix = (0, rebalanceIntent_1.cancelRebalanceIx)({
|
|
912
|
+
keeper: keeper,
|
|
913
|
+
basket: intent.basket,
|
|
914
|
+
rebalanceIntent: intent.ownAddress,
|
|
915
|
+
});
|
|
916
|
+
let txBatchData = { batches: [[{
|
|
917
|
+
payer: keeper,
|
|
918
|
+
instructions: [
|
|
919
|
+
ix,
|
|
920
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
921
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
922
|
+
],
|
|
923
|
+
lookupTables: [],
|
|
924
|
+
}]] };
|
|
925
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
926
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
927
|
+
return txPayloadBatchSequence;
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Creates a rebalance intent for a user to deposit tokens into a basket.
|
|
932
|
+
*
|
|
933
|
+
* Batch layout:
|
|
934
|
+
*
|
|
935
|
+
* batch 0:
|
|
936
|
+
* * tx0: [create, resize, init rebalance intent],
|
|
937
|
+
*
|
|
938
|
+
* batch 1:
|
|
939
|
+
* * tx0: [deposit tokens ix],
|
|
940
|
+
* * tx1: [deposit tokens ix],
|
|
941
|
+
* * ...
|
|
942
|
+
*
|
|
943
|
+
* batch 2:
|
|
944
|
+
* * tx0: [lock deposits ix, start price updates ix],
|
|
945
|
+
*
|
|
946
|
+
* @param {Object} params - The parameters for the basket purchase.
|
|
947
|
+
* @param {string} params.buyer - The public key of the buyer.
|
|
948
|
+
* @param {string} params.basket_mint - The mint public key of the basket.
|
|
949
|
+
* @param {{mint: string, amount: number}[]} params.contributions - The contributions to the basket.
|
|
950
|
+
* @param {string} params.contributions[].mint - The mint public key of the contribution.
|
|
951
|
+
* @param {number} params.contributions[].amount - The amount of the contribution.
|
|
952
|
+
* @param {number} params.rebalance_slippage_bps - Optional. The rebalance slippage in basis points.
|
|
953
|
+
* @param {number} params.per_trade_rebalance_slippage_bps - Optional. The per trade rebalance slippage in basis points.
|
|
954
|
+
* @param {number} params.execution_start_time - Optional. The execution start time.
|
|
955
|
+
* @param {number} params.min_bounty_amount - Optional. The minimum bounty amount.
|
|
956
|
+
* @param {number} params.max_bounty_amount - Optional. The maximum bounty amount.
|
|
957
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
958
|
+
*/
|
|
959
|
+
buyBasketTx(params) {
|
|
960
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
961
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
962
|
+
let buyer = new web3_js_1.PublicKey(params.buyer);
|
|
963
|
+
let contributions = params.contributions.map(contribution => ({
|
|
964
|
+
mint: new web3_js_1.PublicKey(contribution.mint),
|
|
965
|
+
amount: contribution.amount,
|
|
966
|
+
}));
|
|
967
|
+
let rebalanceSlippageBps = (_a = params.rebalance_slippage_bps) !== null && _a !== void 0 ? _a : 100;
|
|
968
|
+
let perTradeRebalanceSlippageBps = (_b = params.per_trade_rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
|
|
969
|
+
let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
|
|
970
|
+
let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
|
|
971
|
+
let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
972
|
+
const basket = yield this.fetchBasket((0, pda_1.getBasketState)(new web3_js_1.PublicKey(params.basket_mint)).toBase58());
|
|
973
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
974
|
+
let bountyWsolAmount = 0;
|
|
975
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
976
|
+
let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
|
|
977
|
+
let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
|
|
978
|
+
let bountyPerPriceUpdateTaskDivisor = parseInt(globalConfig.bountyPerPriceUpdateTaskDivisor.toString());
|
|
979
|
+
if (maxBountyAmount > maxBountyPerTask)
|
|
980
|
+
maxBountyPerTask = maxBountyAmount;
|
|
981
|
+
bountyWsolAmount = (0, rebalanceIntent_3.computeRebalanceIntentBountyAmount)(rebalanceIntent_2.RebalanceType.Deposit, basket.numTokens, boundBounty, maxBountyPerTask, Math.floor(maxBountyPerTask / bountyPerPriceUpdateTaskDivisor));
|
|
982
|
+
}
|
|
983
|
+
let wsolContributionAmount = (_g = (_f = params.contributions.find(contribution => contribution.mint === constants_1.MINTS["mainnet"].WSOL.toBase58())) === null || _f === void 0 ? void 0 : _f.amount) !== null && _g !== void 0 ? _g : 0;
|
|
984
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, buyer, bountyWsolAmount + wsolContributionAmount);
|
|
985
|
+
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, buyer);
|
|
986
|
+
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
987
|
+
let rentPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
|
|
988
|
+
let rebalanceIntentRentPayer = buyer;
|
|
989
|
+
// TODO: check actual lamports required for rent
|
|
990
|
+
if ((_h = rentPayerAi === null || rentPayerAi === void 0 ? void 0 : rentPayerAi.lamports) !== null && _h !== void 0 ? _h : 0 > 500000000)
|
|
991
|
+
rebalanceIntentRentPayer = rentPayer;
|
|
992
|
+
let bountyMint = basket.settings.bountyMint;
|
|
993
|
+
// let lockDepositsIxs: TransactionInstruction[] = [
|
|
994
|
+
// lockDepositsIx({
|
|
995
|
+
// owner: buyer,
|
|
996
|
+
// basket: basket.ownAddress,
|
|
997
|
+
// })
|
|
998
|
+
// ];
|
|
999
|
+
let txBatchData = { batches: [
|
|
1000
|
+
[{
|
|
1001
|
+
payer: buyer,
|
|
1002
|
+
instructions: [
|
|
1003
|
+
...wsolIxs,
|
|
1004
|
+
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
1005
|
+
signer: buyer,
|
|
1006
|
+
owner: buyer,
|
|
1007
|
+
basket: basket.ownAddress,
|
|
1008
|
+
}),
|
|
1009
|
+
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
1010
|
+
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
1011
|
+
signer: buyer,
|
|
1012
|
+
owner: buyer,
|
|
1013
|
+
basket: basket.ownAddress,
|
|
1014
|
+
basketTokenMint: basket.mint,
|
|
1015
|
+
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
1016
|
+
bountyMint: bountyMint,
|
|
1017
|
+
rebalanceType: rebalanceIntent_2.RebalanceType.Deposit,
|
|
1018
|
+
basketRebalanceIntent: undefined,
|
|
1019
|
+
rebalanceSlippageBps: rebalanceSlippageBps,
|
|
1020
|
+
perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
|
|
1021
|
+
executionStartTime: executionStartTime,
|
|
1022
|
+
minBountyAmount: minBountyAmount,
|
|
1023
|
+
maxBountyAmount: maxBountyAmount,
|
|
1024
|
+
}),
|
|
1025
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1026
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1027
|
+
],
|
|
1028
|
+
lookupTables: [],
|
|
1029
|
+
}],
|
|
1030
|
+
(0, deposit_1.depositTokensIx)({
|
|
1031
|
+
owner: buyer,
|
|
1032
|
+
basket: basket.ownAddress,
|
|
1033
|
+
contributions: contributions,
|
|
1034
|
+
}).map(ix => {
|
|
1035
|
+
return {
|
|
1036
|
+
payer: buyer,
|
|
1037
|
+
instructions: [
|
|
1038
|
+
ix,
|
|
1039
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1040
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee })
|
|
1041
|
+
],
|
|
1042
|
+
lookupTables: [],
|
|
1043
|
+
};
|
|
1044
|
+
}),
|
|
1045
|
+
// [{
|
|
1046
|
+
// payer: buyer,
|
|
1047
|
+
// instructions: [
|
|
1048
|
+
// ...lockDepositsIxs,
|
|
1049
|
+
// ComputeBudgetProgram.setComputeUnitLimit({units: COMPUTE_UNITS}),
|
|
1050
|
+
// ComputeBudgetProgram.setComputeUnitPrice({microLamports: this.sdkParams.priorityFee}),
|
|
1051
|
+
// ],
|
|
1052
|
+
// lookupTables: [],
|
|
1053
|
+
// }]
|
|
1054
|
+
] };
|
|
1055
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1056
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1057
|
+
return txPayloadBatchSequence;
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Deposits additional tokens into an existing user deposit rebalance intent.
|
|
1062
|
+
*
|
|
1063
|
+
* This is useful when the user already created a deposit intent (for example via buyBasketTx),
|
|
1064
|
+
* but has not called lockDepositsTx yet and wants to add more contributions.
|
|
1065
|
+
*
|
|
1066
|
+
* @param {Object} params - The parameters for depositing more tokens.
|
|
1067
|
+
* @param {string} params.buyer - The public key of the buyer / deposit owner.
|
|
1068
|
+
* @param {{mint: string, amount: number}[]} params.contributions - Extra token contributions.
|
|
1069
|
+
* @param {string} params.rebalance_intent - Optional. Existing rebalance intent pubkey.
|
|
1070
|
+
* @param {RebalanceIntent} params.rebalance_intent_chain_data - Optional. Existing rebalance intent chain data.
|
|
1071
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1072
|
+
*/
|
|
1073
|
+
depositTokensTx(params) {
|
|
1074
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1075
|
+
let buyer = new web3_js_1.PublicKey(params.buyer);
|
|
1076
|
+
if (params.contributions.length === 0) {
|
|
1077
|
+
throw new Error("Contributions cannot be empty");
|
|
1078
|
+
}
|
|
1079
|
+
let contributions = params.contributions.map(contribution => ({
|
|
1080
|
+
mint: new web3_js_1.PublicKey(contribution.mint),
|
|
1081
|
+
amount: contribution.amount,
|
|
1082
|
+
}));
|
|
1083
|
+
let rebalanceIntentState;
|
|
1084
|
+
if (params.rebalance_intent_chain_data) {
|
|
1085
|
+
rebalanceIntentState = params.rebalance_intent_chain_data;
|
|
1086
|
+
}
|
|
1087
|
+
else if (params.rebalance_intent) {
|
|
1088
|
+
rebalanceIntentState = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
throw new Error("Provide one of rebalance_intent_chain_data or rebalance_intent");
|
|
1092
|
+
}
|
|
1093
|
+
let wsolContributionAmount = params.contributions
|
|
1094
|
+
.filter(contribution => contribution.mint === constants_1.MINTS["mainnet"].WSOL.toBase58())
|
|
1095
|
+
.reduce((acc, contribution) => acc + contribution.amount, 0);
|
|
1096
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, buyer, wsolContributionAmount);
|
|
1097
|
+
let txBatchData = { batches: [] };
|
|
1098
|
+
if (wsolIxs.length > 0) {
|
|
1099
|
+
txBatchData.batches.push([{
|
|
1100
|
+
payer: buyer,
|
|
1101
|
+
instructions: [
|
|
1102
|
+
...wsolIxs,
|
|
1103
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1104
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1105
|
+
],
|
|
1106
|
+
lookupTables: [],
|
|
1107
|
+
}]);
|
|
1108
|
+
}
|
|
1109
|
+
txBatchData.batches.push((0, deposit_1.depositTokensIx)({
|
|
1110
|
+
owner: buyer,
|
|
1111
|
+
basket: rebalanceIntentState.basket,
|
|
1112
|
+
contributions: contributions,
|
|
1113
|
+
}).map(ix => ({
|
|
1114
|
+
payer: buyer,
|
|
1115
|
+
instructions: [
|
|
1116
|
+
ix,
|
|
1117
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1118
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1119
|
+
],
|
|
1120
|
+
lookupTables: [],
|
|
1121
|
+
})));
|
|
1122
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1123
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1124
|
+
return txPayloadBatchSequence;
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Locks deposits for a user and starts auction flow.
|
|
1129
|
+
* @param {Object} params - The parameters for the lock deposits.
|
|
1130
|
+
* @param {string} params.buyer - The public key of the buyer.
|
|
1131
|
+
* @param {string} params.basket_mint - The mint public key of the basket.
|
|
1132
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1133
|
+
*/
|
|
1134
|
+
lockDepositsTx(params) {
|
|
1135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1136
|
+
let buyer = new web3_js_1.PublicKey(params.buyer);
|
|
1137
|
+
let basket = yield this.fetchBasket((0, pda_1.getBasketState)(new web3_js_1.PublicKey(params.basket_mint)).toBase58());
|
|
1138
|
+
let txBatchData = { batches: [[{
|
|
1139
|
+
payer: buyer,
|
|
1140
|
+
instructions: [
|
|
1141
|
+
(0, deposit_1.lockDepositsIx)({
|
|
1142
|
+
owner: buyer,
|
|
1143
|
+
basket: basket.ownAddress,
|
|
1144
|
+
}),
|
|
1145
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1146
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1147
|
+
],
|
|
1148
|
+
lookupTables: [],
|
|
1149
|
+
}]] };
|
|
1150
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1151
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1152
|
+
return txPayloadBatchSequence;
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Creates a rebalance intent for a user to withdraw tokens from a basket.
|
|
1157
|
+
* @param {{Object}} params - The parameters for the basket sale.
|
|
1158
|
+
* @param {string} params.seller - The public key of the seller.
|
|
1159
|
+
* @param {string} params.basket_mint - The mint public key of the basket.
|
|
1160
|
+
* @param {number} params.withdraw_amount - The amount of the withdrawal.
|
|
1161
|
+
* @param {string[]} params.keep_tokens - The token mints to skip rebalancing (will directly be sent to the user without being rebalanced).
|
|
1162
|
+
* @param {number} params.rebalance_slippage_bps - Optional. The rebalance slippage in basis points.
|
|
1163
|
+
* @param {number} params.per_trade_rebalance_slippage_bps - Optional. The per trade rebalance slippage in basis points.
|
|
1164
|
+
* @param {number} params.execution_start_time - Optional. The execution start time.
|
|
1165
|
+
* @param {number} params.min_bounty_amount - Optional. The minimum bounty amount.
|
|
1166
|
+
* @param {number} params.max_bounty_amount - Optional. The maximum bounty amount.
|
|
1167
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1168
|
+
*/
|
|
1169
|
+
sellBasketTx(params) {
|
|
1170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1171
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1172
|
+
let seller = new web3_js_1.PublicKey(params.seller);
|
|
1173
|
+
let basketMint = new web3_js_1.PublicKey(params.basket_mint);
|
|
1174
|
+
let withdrawAmount = params.withdraw_amount;
|
|
1175
|
+
let keepTokens = params.keep_tokens;
|
|
1176
|
+
let rebalanceSlippageBps = (_a = params.rebalance_slippage_bps) !== null && _a !== void 0 ? _a : 100;
|
|
1177
|
+
let perTradeRebalanceSlippageBps = (_b = params.per_trade_rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
|
|
1178
|
+
let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
|
|
1179
|
+
let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
|
|
1180
|
+
let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
1181
|
+
const basket = yield this.fetchBasket((0, pda_1.getBasketState)(basketMint).toBase58());
|
|
1182
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
1183
|
+
let bountyWsolAmount = 0;
|
|
1184
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
1185
|
+
let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
|
|
1186
|
+
let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
|
|
1187
|
+
let bountyPerPriceUpdateTaskDivisor = parseInt(globalConfig.bountyPerPriceUpdateTaskDivisor.toString());
|
|
1188
|
+
if (maxBountyAmount > maxBountyPerTask)
|
|
1189
|
+
maxBountyPerTask = maxBountyAmount;
|
|
1190
|
+
bountyWsolAmount = (0, rebalanceIntent_3.computeRebalanceIntentBountyAmount)(rebalanceIntent_2.RebalanceType.Deposit, basket.numTokens, boundBounty, maxBountyPerTask, Math.floor(maxBountyPerTask / bountyPerPriceUpdateTaskDivisor));
|
|
1191
|
+
}
|
|
1192
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, seller, bountyWsolAmount);
|
|
1193
|
+
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, seller);
|
|
1194
|
+
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
1195
|
+
let rentPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
|
|
1196
|
+
let rebalanceIntentRentPayer = seller;
|
|
1197
|
+
// TODO: check actual lamports required for rent
|
|
1198
|
+
if ((_f = rentPayerAi === null || rentPayerAi === void 0 ? void 0 : rentPayerAi.lamports) !== null && _f !== void 0 ? _f : 0 > 500000000)
|
|
1199
|
+
rebalanceIntentRentPayer = rentPayer;
|
|
1200
|
+
let bountyMint = basket.settings.bountyMint;
|
|
1201
|
+
let keepAllTokensFlag = 1;
|
|
1202
|
+
for (let i = 0; i < basket.numTokens; i++) {
|
|
1203
|
+
if (!keepTokens.includes(basket.composition[i].mint.toBase58())) {
|
|
1204
|
+
keepAllTokensFlag = 0;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
let tokenMintsHash = (0, basket_1.computeTokenMintsHash)(basket.composition.slice(0, basket.numTokens)
|
|
1209
|
+
.map(asset => asset.mint.toBase58()));
|
|
1210
|
+
let keepTokensBitmask = new bn_js_1.default(0);
|
|
1211
|
+
if (keepTokens && keepTokens.length > 0) {
|
|
1212
|
+
for (const mint of keepTokens) {
|
|
1213
|
+
let tokenIndex = -1;
|
|
1214
|
+
for (let i = 0; i < basket.numTokens; i++) {
|
|
1215
|
+
if (basket.composition[i].mint.toBase58() === mint) {
|
|
1216
|
+
tokenIndex = i;
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
if (tokenIndex === -1) {
|
|
1221
|
+
throw new Error(`Token mint not in basket: ${mint}`);
|
|
1222
|
+
}
|
|
1223
|
+
keepTokensBitmask = keepTokensBitmask.or(new bn_js_1.default(1).shln(tokenIndex));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
const basketRebalanceIntent = basket.settings.activeRebalance.gt(new bn_js_1.default(0))
|
|
1227
|
+
? (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, basket.ownAddress)
|
|
1228
|
+
: undefined;
|
|
1229
|
+
let txBatchData = { batches: [
|
|
1230
|
+
[{
|
|
1231
|
+
payer: seller,
|
|
1232
|
+
instructions: [
|
|
1233
|
+
...wsolIxs,
|
|
1234
|
+
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
1235
|
+
signer: seller,
|
|
1236
|
+
owner: seller,
|
|
1237
|
+
basket: basket.ownAddress,
|
|
1238
|
+
}),
|
|
1239
|
+
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
1240
|
+
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
1241
|
+
signer: seller,
|
|
1242
|
+
owner: seller,
|
|
1243
|
+
basket: basket.ownAddress,
|
|
1244
|
+
basketTokenMint: basketMint,
|
|
1245
|
+
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
1246
|
+
bountyMint: bountyMint,
|
|
1247
|
+
rebalanceType: rebalanceIntent_2.RebalanceType.Withdraw,
|
|
1248
|
+
basketRebalanceIntent: basketRebalanceIntent,
|
|
1249
|
+
rebalanceSlippageBps: rebalanceSlippageBps,
|
|
1250
|
+
perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
|
|
1251
|
+
executionStartTime: executionStartTime,
|
|
1252
|
+
minBountyAmount: minBountyAmount,
|
|
1253
|
+
maxBountyAmount: maxBountyAmount,
|
|
1254
|
+
withdrawParamsBurnAmount: withdrawAmount,
|
|
1255
|
+
withdrawParamsTokenMintsHash: tokenMintsHash,
|
|
1256
|
+
withdrawParamsKeepTokensBitmask: keepTokensBitmask,
|
|
1257
|
+
withdrawParamsKeepAllTokens: keepAllTokensFlag,
|
|
1258
|
+
}),
|
|
1259
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1260
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1261
|
+
],
|
|
1262
|
+
lookupTables: [],
|
|
1263
|
+
}],
|
|
1264
|
+
] };
|
|
1265
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1266
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1267
|
+
return txPayloadBatchSequence;
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Creates a rebalance intent for a basket rebalance.
|
|
1272
|
+
* @param {Object} params - The parameters for the basket rebalance.
|
|
1273
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1274
|
+
* @param {string} params.basket_mint - The basket token mint public key.
|
|
1275
|
+
* @param {number} params.rebalance_slippage_bps - Optional. The rebalance slippage in basis points.
|
|
1276
|
+
* @param {number} params.per_trade_rebalance_slippage_bps - Optional. The per trade rebalance slippage in basis points.
|
|
1277
|
+
* @param {number} params.execution_start_time - Optional. The execution start time.
|
|
1278
|
+
* @param {number} params.min_bounty_amount - Optional. The minimum bounty amount.
|
|
1279
|
+
* @param {number} params.max_bounty_amount - Optional. The maximum bounty amount.
|
|
1280
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1281
|
+
*/
|
|
1282
|
+
rebalanceBasketTx(params) {
|
|
1283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1284
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1285
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1286
|
+
let rebalanceSlippageBps = (_a = params.rebalance_slippage_bps) !== null && _a !== void 0 ? _a : 100;
|
|
1287
|
+
let perTradeRebalanceSlippageBps = (_b = params.per_trade_rebalance_slippage_bps) !== null && _b !== void 0 ? _b : 100;
|
|
1288
|
+
let executionStartTime = (_c = params.execution_start_time) !== null && _c !== void 0 ? _c : 0;
|
|
1289
|
+
let minBountyAmount = (_d = params.min_bounty_amount) !== null && _d !== void 0 ? _d : 0;
|
|
1290
|
+
let maxBountyAmount = (_e = params.max_bounty_amount) !== null && _e !== void 0 ? _e : 0;
|
|
1291
|
+
const basket = yield this.fetchBasket((0, pda_1.getBasketState)(new web3_js_1.PublicKey(params.basket_mint)).toBase58());
|
|
1292
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
1293
|
+
let bountyWsolAmount = 0;
|
|
1294
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
1295
|
+
let boundBounty = parseInt(globalConfig.bountyBondAmount.toString());
|
|
1296
|
+
let maxBountyPerTask = parseInt(globalConfig.bountyPerTask.maxBounty.toString());
|
|
1297
|
+
let bountyPerPriceUpdateTaskDivisor = parseInt(globalConfig.bountyPerPriceUpdateTaskDivisor.toString());
|
|
1298
|
+
if (maxBountyAmount > maxBountyPerTask)
|
|
1299
|
+
maxBountyPerTask = maxBountyAmount;
|
|
1300
|
+
bountyWsolAmount = (0, rebalanceIntent_3.computeRebalanceIntentBountyAmount)(rebalanceIntent_2.RebalanceType.Basket, basket.numTokens, boundBounty, maxBountyPerTask, Math.floor(maxBountyPerTask / bountyPerPriceUpdateTaskDivisor));
|
|
1301
|
+
}
|
|
1302
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, keeper, bountyWsolAmount);
|
|
1303
|
+
const rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, basket.ownAddress);
|
|
1304
|
+
let rentPayer = (0, pda_1.getRentPayerPda)();
|
|
1305
|
+
let rentPayerAi = yield this.sdkParams.connection.getAccountInfo(rentPayer);
|
|
1306
|
+
let rebalanceIntentRentPayer = keeper;
|
|
1307
|
+
// TODO: check actual lamports required for rent
|
|
1308
|
+
if ((_f = rentPayerAi === null || rentPayerAi === void 0 ? void 0 : rentPayerAi.lamports) !== null && _f !== void 0 ? _f : 0 > 500000000)
|
|
1309
|
+
rebalanceIntentRentPayer = rentPayer;
|
|
1310
|
+
let bountyMint = basket.settings.bountyMint;
|
|
1311
|
+
let txBatchData = { batches: [[{
|
|
1312
|
+
payer: keeper,
|
|
1313
|
+
instructions: [
|
|
1314
|
+
...wsolIxs,
|
|
1315
|
+
(0, rebalanceIntent_1.createRebalanceIntentIx)({
|
|
1316
|
+
signer: keeper,
|
|
1317
|
+
owner: basket.ownAddress,
|
|
1318
|
+
basket: basket.ownAddress,
|
|
1319
|
+
}),
|
|
1320
|
+
(0, rebalanceIntent_1.resizeRebalanceIntentIx)(rebalanceIntent),
|
|
1321
|
+
(0, rebalanceIntent_1.initRebalanceIntentIx)({
|
|
1322
|
+
signer: keeper,
|
|
1323
|
+
owner: basket.ownAddress,
|
|
1324
|
+
basket: basket.ownAddress,
|
|
1325
|
+
basketTokenMint: basket.mint,
|
|
1326
|
+
rebalanceIntentRentPayer: rebalanceIntentRentPayer,
|
|
1327
|
+
bountyMint: bountyMint,
|
|
1328
|
+
rebalanceType: rebalanceIntent_2.RebalanceType.Basket,
|
|
1329
|
+
basketRebalanceIntent: undefined,
|
|
1330
|
+
rebalanceSlippageBps: rebalanceSlippageBps,
|
|
1331
|
+
perTradeRebalanceSlippageBps: perTradeRebalanceSlippageBps,
|
|
1332
|
+
executionStartTime: executionStartTime,
|
|
1333
|
+
minBountyAmount: minBountyAmount,
|
|
1334
|
+
maxBountyAmount: maxBountyAmount,
|
|
1335
|
+
}),
|
|
1336
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1337
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1338
|
+
],
|
|
1339
|
+
lookupTables: [],
|
|
1340
|
+
}]] };
|
|
1341
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1342
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1343
|
+
return txPayloadBatchSequence;
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Build update token prices transactions.
|
|
1348
|
+
*
|
|
1349
|
+
* For pyth oracle accounts, fetches feed IDs, builds vaa [create init encode], [write verify],
|
|
1350
|
+
*
|
|
1351
|
+
* [update feed], [close vaa] instructions. For all tokens, builds [update token prices] instructions.
|
|
1352
|
+
*
|
|
1353
|
+
* returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1354
|
+
*
|
|
1355
|
+
* Batch layout:
|
|
1356
|
+
*
|
|
1357
|
+
* batch 0:
|
|
1358
|
+
* * tx0: [vaa0CreateIx, vaa0InitIx, vaa0WriteIx],
|
|
1359
|
+
* * tx1: [vaa1CreateIx, vaa1InitIx, vaa1WriteIx],
|
|
1360
|
+
* * ...
|
|
1361
|
+
*
|
|
1362
|
+
* batch 1:
|
|
1363
|
+
* * tx0: [vaa0WriteVerifyIx, vaa0VerifyIx],
|
|
1364
|
+
* * tx1: [vaa1WriteVerifyIx, vaa1VerifyIx],
|
|
1365
|
+
* * ...
|
|
1366
|
+
*
|
|
1367
|
+
* batch 2:
|
|
1368
|
+
* * tx0: [updateFeed0Ix],
|
|
1369
|
+
* * tx1: [updateFeed1Ix],
|
|
1370
|
+
* * ...
|
|
1371
|
+
*
|
|
1372
|
+
* batch 3:
|
|
1373
|
+
* * tx0: [updateTokenPricesIx(max 10 tokens)],
|
|
1374
|
+
* * tx1: [updateTokenPricesIx(max 10 tokens)],
|
|
1375
|
+
* * ...
|
|
1376
|
+
* * txLast: [closeVaa0Ix, closeVaa1Ix, ...]
|
|
1377
|
+
*
|
|
1378
|
+
* @param {Object} params - The parameters for the update token prices.
|
|
1379
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1380
|
+
* @param {string} params.basket - The public key of the basket.
|
|
1381
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent.
|
|
1382
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1383
|
+
*/
|
|
1384
|
+
updateTokenPricesTx(params) {
|
|
1385
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1386
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1387
|
+
let rebalanceIntent = new web3_js_1.PublicKey(params.rebalance_intent);
|
|
1388
|
+
let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(new web3_js_1.PublicKey(params.basket), new web3_js_1.PublicKey(params.basket));
|
|
1389
|
+
let basket = yield this.fetchBasket(params.basket);
|
|
1390
|
+
let pythPriceFeeds = [];
|
|
1391
|
+
let updateTokenPricesIxs = [];
|
|
1392
|
+
for (let startIndex = 0; startIndex < basket.numTokens; startIndex++) {
|
|
1393
|
+
let allKeys = [];
|
|
1394
|
+
let tokenIndices = [];
|
|
1395
|
+
for (let endIndex = startIndex; endIndex < basket.numTokens; endIndex++) {
|
|
1396
|
+
let numAccounts = basket.composition[endIndex].oracleAggregator.oracles
|
|
1397
|
+
.slice(0, basket.composition[endIndex].oracleAggregator.numOracles)
|
|
1398
|
+
.reduce((acc, oracle) => acc + oracle.oracleSettings.numRequiredAccounts, 0);
|
|
1399
|
+
if (allKeys.length + numAccounts > constants_1.UPDATE_TOKEN_PRICES_MAX_ACCOUNTS)
|
|
1400
|
+
break;
|
|
1401
|
+
if (tokenIndices.length == 20)
|
|
1402
|
+
break;
|
|
1403
|
+
startIndex = endIndex;
|
|
1404
|
+
tokenIndices.push(endIndex);
|
|
1405
|
+
let agg = basket.composition[endIndex].oracleAggregator;
|
|
1406
|
+
for (let i = 0; i < agg.numOracles; i++) {
|
|
1407
|
+
const oracleData = agg.oracles[i];
|
|
1408
|
+
for (let j = 0; j < oracleData.oracleSettings.numRequiredAccounts; j++) {
|
|
1409
|
+
const lutId = oracleData.accountsToLoadLutIds[j];
|
|
1410
|
+
const lutIdx = oracleData.accountsToLoadLutIndices[j];
|
|
1411
|
+
allKeys.push(basket.lutPubkeys[lutId].state.addresses[lutIdx]);
|
|
1412
|
+
if (oracleData.oracleSettings.oracleType === oracle_1.OracleType.Pyth)
|
|
1413
|
+
pythPriceFeeds.push(basket.lutPubkeys[lutId].state.addresses[lutIdx]);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
while (tokenIndices.length < 20)
|
|
1418
|
+
tokenIndices.push(0);
|
|
1419
|
+
// TODO: in last instruction we should include performance fee accounts
|
|
1420
|
+
let performanceFees = basket.settings.fees.hostPerformanceFeeBps + basket.settings.fees.creatorPerformanceFeeBps + basket.settings.fees.managersPerformanceFeeBps;
|
|
1421
|
+
updateTokenPricesIxs.push((0, priceUpdate_1.updateTokenPricesIx)({
|
|
1422
|
+
keeper: keeper,
|
|
1423
|
+
basket: basket.ownAddress,
|
|
1424
|
+
rebalanceIntent: rebalanceIntent,
|
|
1425
|
+
lookupTable0: basket.lookupTables.active[0],
|
|
1426
|
+
lookupTable1: basket.lookupTables.active[1],
|
|
1427
|
+
tokenIndices: tokenIndices,
|
|
1428
|
+
additionalOracleAccounts: allKeys,
|
|
1429
|
+
basketRebalanceIntent: basket.settings.activeRebalance.eq(new bn_js_1.default(0)) ? undefined : basketRebalanceIntent,
|
|
1430
|
+
basketMint: performanceFees > 0 ? basket.mint : undefined,
|
|
1431
|
+
}));
|
|
1432
|
+
}
|
|
1433
|
+
const { feedIds } = yield (0, pythOracle_1.fetchFeedIdsFromAccounts)(this.sdkParams.connection, pythPriceFeeds);
|
|
1434
|
+
const { vaaCreateInitEncodeIxs, vaaWriteVerifyIxs, updateFeedIxs, closeVaaIxs, } = yield (0, pythOracle_1.buildPythPriceFeedUpdateIxs)(keeper, feedIds);
|
|
1435
|
+
let txBatchData = { batches: [
|
|
1436
|
+
[
|
|
1437
|
+
...vaaCreateInitEncodeIxs.map(ixs => ({
|
|
1438
|
+
payer: keeper,
|
|
1439
|
+
instructions: [
|
|
1440
|
+
...ixs.ixs,
|
|
1441
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1442
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1443
|
+
],
|
|
1444
|
+
lookupTables: [],
|
|
1445
|
+
})),
|
|
1446
|
+
],
|
|
1447
|
+
[
|
|
1448
|
+
...vaaWriteVerifyIxs.map(ixs => ({
|
|
1449
|
+
payer: keeper,
|
|
1450
|
+
instructions: [
|
|
1451
|
+
...ixs,
|
|
1452
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1453
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1454
|
+
],
|
|
1455
|
+
lookupTables: [],
|
|
1456
|
+
})),
|
|
1457
|
+
],
|
|
1458
|
+
[
|
|
1459
|
+
...updateFeedIxs.map(ix => ({
|
|
1460
|
+
payer: keeper,
|
|
1461
|
+
instructions: [
|
|
1462
|
+
ix,
|
|
1463
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1464
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1465
|
+
],
|
|
1466
|
+
lookupTables: [],
|
|
1467
|
+
})),
|
|
1468
|
+
],
|
|
1469
|
+
[
|
|
1470
|
+
...updateTokenPricesIxs.map(ix => ({
|
|
1471
|
+
payer: keeper,
|
|
1472
|
+
instructions: [
|
|
1473
|
+
ix,
|
|
1474
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1475
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1476
|
+
],
|
|
1477
|
+
lookupTables: [basket.lookupTables.active[0], basket.lookupTables.active[1]],
|
|
1478
|
+
})),
|
|
1479
|
+
{
|
|
1480
|
+
payer: keeper,
|
|
1481
|
+
instructions: [
|
|
1482
|
+
...closeVaaIxs,
|
|
1483
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1484
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1485
|
+
],
|
|
1486
|
+
lookupTables: [],
|
|
1487
|
+
}
|
|
1488
|
+
],
|
|
1489
|
+
] };
|
|
1490
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1491
|
+
for (let [txId, vaaCreateInitEncodeIx] of vaaCreateInitEncodeIxs.entries()) {
|
|
1492
|
+
versionedTxs.batches[0][txId].sign([vaaCreateInitEncodeIx.signer]);
|
|
1493
|
+
}
|
|
1494
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1495
|
+
return txPayloadBatchSequence;
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Build Pyth price feed update transactions from on-chain price account pubkeys.
|
|
1500
|
+
* Fetches feed IDs from accounts, builds update instructions, and returns
|
|
1501
|
+
* TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1502
|
+
*
|
|
1503
|
+
* Batch layout:
|
|
1504
|
+
*
|
|
1505
|
+
* batch 0:
|
|
1506
|
+
* * tx0: [vaa0CreateIx, vaa0InitIx, vaa0WriteIx],
|
|
1507
|
+
* * tx1: [vaa1CreateIx, vaa1InitIx, vaa1WriteIx],
|
|
1508
|
+
* * ...
|
|
1509
|
+
*
|
|
1510
|
+
* batch 1:
|
|
1511
|
+
* * tx0: [vaa0WriteVerifyIx, vaa0VerifyIx],
|
|
1512
|
+
* * tx1: [vaa1WriteVerifyIx, vaa1VerifyIx],
|
|
1513
|
+
* * ...
|
|
1514
|
+
*
|
|
1515
|
+
* batch 2:
|
|
1516
|
+
* * tx0: [updateFeed0Ix],
|
|
1517
|
+
* * tx1: [updateFeed1Ix],
|
|
1518
|
+
* * ...
|
|
1519
|
+
*
|
|
1520
|
+
* batch 3:
|
|
1521
|
+
* * txLast: [closeVaa0Ix, closeVaa1Ix, ...]
|
|
1522
|
+
*
|
|
1523
|
+
*/
|
|
1524
|
+
updatePythPriceFeedsTx(params) {
|
|
1525
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1526
|
+
const payer = new web3_js_1.PublicKey(params.keeper);
|
|
1527
|
+
const priceAccounts = params.accounts.map(a => new web3_js_1.PublicKey(a));
|
|
1528
|
+
const { feedIds } = yield (0, pythOracle_1.fetchFeedIdsFromAccounts)(this.sdkParams.connection, priceAccounts);
|
|
1529
|
+
const { vaaCreateInitEncodeIxs, vaaWriteVerifyIxs, updateFeedIxs, closeVaaIxs, } = yield (0, pythOracle_1.buildPythPriceFeedUpdateIxs)(payer, feedIds);
|
|
1530
|
+
let txBatchData = { batches: [
|
|
1531
|
+
[
|
|
1532
|
+
...vaaCreateInitEncodeIxs.map(ixs => ({
|
|
1533
|
+
payer: payer,
|
|
1534
|
+
instructions: [
|
|
1535
|
+
...ixs.ixs,
|
|
1536
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1537
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1538
|
+
],
|
|
1539
|
+
lookupTables: [],
|
|
1540
|
+
})),
|
|
1541
|
+
],
|
|
1542
|
+
[
|
|
1543
|
+
...vaaWriteVerifyIxs.map(ixs => ({
|
|
1544
|
+
payer: payer,
|
|
1545
|
+
instructions: [
|
|
1546
|
+
...ixs,
|
|
1547
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1548
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1549
|
+
],
|
|
1550
|
+
lookupTables: [],
|
|
1551
|
+
})),
|
|
1552
|
+
],
|
|
1553
|
+
[
|
|
1554
|
+
...updateFeedIxs.map(ix => ({
|
|
1555
|
+
payer: payer,
|
|
1556
|
+
instructions: [
|
|
1557
|
+
ix,
|
|
1558
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1559
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1560
|
+
],
|
|
1561
|
+
lookupTables: [],
|
|
1562
|
+
})),
|
|
1563
|
+
],
|
|
1564
|
+
[
|
|
1565
|
+
{
|
|
1566
|
+
payer: payer,
|
|
1567
|
+
instructions: [
|
|
1568
|
+
...closeVaaIxs,
|
|
1569
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1570
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1571
|
+
],
|
|
1572
|
+
lookupTables: [],
|
|
1573
|
+
}
|
|
1574
|
+
],
|
|
1575
|
+
] };
|
|
1576
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1577
|
+
for (let [txId, vaaCreateInitEncodeIx] of vaaCreateInitEncodeIxs.entries()) {
|
|
1578
|
+
versionedTxs.batches[0][txId].sign([vaaCreateInitEncodeIx.signer]);
|
|
1579
|
+
}
|
|
1580
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1581
|
+
return txPayloadBatchSequence;
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Build flash swap transactions (Rebalance or MakeDirectSwap).
|
|
1586
|
+
*
|
|
1587
|
+
* Withdraws amount_out tokens(mint_out) from basket, deposits amount_in tokens(mint_in) to basket.
|
|
1588
|
+
*
|
|
1589
|
+
* If jup_swap_ix is provided, uses it to swap amount_out tokens(mint_out) for amount_in tokens(mint_in).
|
|
1590
|
+
*
|
|
1591
|
+
* returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1592
|
+
*
|
|
1593
|
+
* Batch layout: batch 0: tx: 0:
|
|
1594
|
+
* * create associated token account_mint_out
|
|
1595
|
+
* * create associated token account_mint_in
|
|
1596
|
+
* * jup_token_ledger_ix
|
|
1597
|
+
* * flash withdraw
|
|
1598
|
+
* * jup_swap_ix
|
|
1599
|
+
* * flash deposit
|
|
1600
|
+
* * set compute unit limit
|
|
1601
|
+
* * set compute unit price
|
|
1602
|
+
*
|
|
1603
|
+
* @param {Object} params - The parameters for the flash swap.
|
|
1604
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1605
|
+
* @param {string} params.basket - The public key of the basket.
|
|
1606
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent (for Rebalance).
|
|
1607
|
+
* @param {string} params.intent - The public key of the intent (for MakeDirectSwap).
|
|
1608
|
+
* @param {string} params.mint_in - The mint of the input token (deposited to basket).
|
|
1609
|
+
* @param {string} params.mint_out - The mint of the output token (withdrawn from basket).
|
|
1610
|
+
* @param {number} params.amount_in - The amount of the input token (deposited to basket).
|
|
1611
|
+
* @param {number} params.amount_out - The amount of the output token (withdrawn from basket).
|
|
1612
|
+
* @param {"exact_in" | "exact_out" | "ioc"} params.mode - The mode of the flash swap.
|
|
1613
|
+
* @param {TransactionInstruction} params.jup_token_ledger_ix - The jup token ledger ix.
|
|
1614
|
+
* @param {TransactionInstruction} params.jup_swap_ix - The jup swap ix.
|
|
1615
|
+
* @param {PublicKey[]} params.jup_address_lookup_table_addresses - The jup address lookup table addresses.
|
|
1616
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1617
|
+
*/
|
|
1618
|
+
flashSwapTx(params) {
|
|
1619
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1620
|
+
var _a;
|
|
1621
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1622
|
+
let basket = new web3_js_1.PublicKey(params.basket);
|
|
1623
|
+
let rebalanceIntent = params.rebalance_intent ? new web3_js_1.PublicKey(params.rebalance_intent) : undefined;
|
|
1624
|
+
let intent = params.intent ? new web3_js_1.PublicKey(params.intent) : undefined;
|
|
1625
|
+
let mintIn = new web3_js_1.PublicKey(params.mint_in);
|
|
1626
|
+
let mintOut = new web3_js_1.PublicKey(params.mint_out);
|
|
1627
|
+
let amountIn = new bn_js_1.default(params.amount_in);
|
|
1628
|
+
let amountOut = new bn_js_1.default(params.amount_out);
|
|
1629
|
+
let mode = params.mode ? params.mode : 0;
|
|
1630
|
+
let flashParams = {
|
|
1631
|
+
keeper: keeper,
|
|
1632
|
+
basket: basket,
|
|
1633
|
+
rebalanceIntent: rebalanceIntent,
|
|
1634
|
+
intent: intent,
|
|
1635
|
+
mintIn: mintIn,
|
|
1636
|
+
mintOut: mintOut,
|
|
1637
|
+
amountIn: amountIn,
|
|
1638
|
+
amountOut: amountOut,
|
|
1639
|
+
mode: mode,
|
|
1640
|
+
};
|
|
1641
|
+
let ixWithdraw = (0, flashSwap_1.flashWithdrawIx)(flashParams);
|
|
1642
|
+
let ixDeposit = (0, flashSwap_1.flashDepositIx)(flashParams);
|
|
1643
|
+
let ixs = [];
|
|
1644
|
+
ixs = ixs.concat([
|
|
1645
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintIn), keeper, mintIn),
|
|
1646
|
+
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(keeper, (0, pda_1.getAta)(keeper, mintOut), keeper, mintOut),
|
|
1647
|
+
]);
|
|
1648
|
+
if (params.jup_token_ledger_ix) {
|
|
1649
|
+
ixs.push(params.jup_token_ledger_ix);
|
|
1650
|
+
}
|
|
1651
|
+
ixs.push(ixWithdraw);
|
|
1652
|
+
if (params.jup_swap_ix) {
|
|
1653
|
+
ixs.push(params.jup_swap_ix);
|
|
1654
|
+
}
|
|
1655
|
+
ixs.push(ixDeposit);
|
|
1656
|
+
ixs = ixs.concat([
|
|
1657
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1658
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1659
|
+
]);
|
|
1660
|
+
let txBatchData = { batches: [[{
|
|
1661
|
+
payer: keeper,
|
|
1662
|
+
instructions: ixs,
|
|
1663
|
+
lookupTables: (_a = params.jup_address_lookup_table_addresses) !== null && _a !== void 0 ? _a : [],
|
|
1664
|
+
}]] };
|
|
1665
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1666
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1667
|
+
return txPayloadBatchSequence;
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Mints basket tokens for a user. Executable when the rebalance intent has finished its auctions.
|
|
1672
|
+
*
|
|
1673
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1674
|
+
*
|
|
1675
|
+
* @param {Object} params - The parameters for the mint.
|
|
1676
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1677
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent.
|
|
1678
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1679
|
+
*/
|
|
1680
|
+
mintTx(params) {
|
|
1681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1682
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1683
|
+
let rebalanceIntent = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
|
|
1684
|
+
let basket = yield this.fetchBasket(rebalanceIntent.basket.toBase58());
|
|
1685
|
+
let basketRebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket.ownAddress, rebalanceIntent.owner);
|
|
1686
|
+
let ix = (0, deposit_1.mintBasketIx)({
|
|
1687
|
+
keeper: keeper,
|
|
1688
|
+
basket: basket.ownAddress,
|
|
1689
|
+
basketTokenMint: basket.mint,
|
|
1690
|
+
buyer: rebalanceIntent.owner,
|
|
1691
|
+
basketRebalanceIntent: basket.settings.activeRebalance.eq(new bn_js_1.default(0)) ? undefined : basketRebalanceIntent,
|
|
1692
|
+
});
|
|
1693
|
+
let txBatchData = { batches: [[{
|
|
1694
|
+
payer: keeper,
|
|
1695
|
+
instructions: [
|
|
1696
|
+
ix,
|
|
1697
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1698
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1699
|
+
],
|
|
1700
|
+
lookupTables: [],
|
|
1701
|
+
}]] };
|
|
1702
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1703
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1704
|
+
return txPayloadBatchSequence;
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Redeems tokens from the rebalance intent with Withdraw status.
|
|
1709
|
+
*
|
|
1710
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1711
|
+
*
|
|
1712
|
+
* @param {Object} params - The parameters for the redeem tokens.
|
|
1713
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1714
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent.
|
|
1715
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1716
|
+
*/
|
|
1717
|
+
redeemTokensTx(params) {
|
|
1718
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1719
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1720
|
+
let rebalanceIntent = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
|
|
1721
|
+
let batchSize = 7;
|
|
1722
|
+
let ixs = [];
|
|
1723
|
+
for (let batchStart = 0; batchStart < rebalanceIntent.tokens.length; batchStart += batchSize) {
|
|
1724
|
+
let tokenMints = [];
|
|
1725
|
+
for (let i = batchStart; i < rebalanceIntent.tokens.length && i < batchStart + batchSize; i++)
|
|
1726
|
+
if (rebalanceIntent.tokens[i].amount.gt(new bn_js_1.default(0)))
|
|
1727
|
+
tokenMints.push(rebalanceIntent.tokens[i].mint);
|
|
1728
|
+
if (tokenMints.length > 0) {
|
|
1729
|
+
ixs.push((0, withdraw_1.redeemTokensIx)({
|
|
1730
|
+
keeper: keeper,
|
|
1731
|
+
basket: rebalanceIntent.basket,
|
|
1732
|
+
owner: rebalanceIntent.owner,
|
|
1733
|
+
tokenMints: tokenMints,
|
|
1734
|
+
}));
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
let txBatchData = { batches: [ixs.map(ix => ({
|
|
1738
|
+
payer: keeper,
|
|
1739
|
+
instructions: [
|
|
1740
|
+
ix,
|
|
1741
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1742
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1743
|
+
],
|
|
1744
|
+
lookupTables: [],
|
|
1745
|
+
}))] };
|
|
1746
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1747
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1748
|
+
return txPayloadBatchSequence;
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Claims the bounty to keepers who have completed tasks for rebalance intent.
|
|
1753
|
+
*
|
|
1754
|
+
* Executebale when the rebalance intent has finished its auctions.
|
|
1755
|
+
*
|
|
1756
|
+
* For Withdraw status rebalance intent, tokens have to be redeemed first.
|
|
1757
|
+
*
|
|
1758
|
+
* Closes the rebalance intent if all keepers have claimed the bounty.
|
|
1759
|
+
*
|
|
1760
|
+
* @param {Object} params - The parameters for the claim bounty.
|
|
1761
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1762
|
+
* @param {string} params.rebalance_intent - The public key of the rebalance intent.
|
|
1763
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1764
|
+
*/
|
|
1765
|
+
claimBountyTx(params) {
|
|
1766
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1767
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1768
|
+
let rebalanceIntent = (yield this.fetchRebalanceIntent(params.rebalance_intent)).chain_data;
|
|
1769
|
+
let keepersArray = [];
|
|
1770
|
+
if (!rebalanceIntent.auctionCreationTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
1771
|
+
keepersArray.push(rebalanceIntent.auctionCreationTask.completedBy.toBase58());
|
|
1772
|
+
if (!rebalanceIntent.cancelRebalanceTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
1773
|
+
keepersArray.push(rebalanceIntent.cancelRebalanceTask.completedBy.toBase58());
|
|
1774
|
+
if (!rebalanceIntent.placeholderTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
1775
|
+
keepersArray.push(rebalanceIntent.placeholderTask.completedBy.toBase58());
|
|
1776
|
+
if (!rebalanceIntent.finishPriceUpdateTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
1777
|
+
keepersArray.push(rebalanceIntent.finishPriceUpdateTask.completedBy.toBase58());
|
|
1778
|
+
if (!rebalanceIntent.mintBasketTask.completedBy.equals(web3_js_1.PublicKey.default))
|
|
1779
|
+
keepersArray.push(rebalanceIntent.mintBasketTask.completedBy.toBase58());
|
|
1780
|
+
for (let i = 0; i < rebalanceIntent.priceUpdateTasks.length; i++)
|
|
1781
|
+
if (!rebalanceIntent.priceUpdateTasks[i].completedBy.equals(web3_js_1.PublicKey.default))
|
|
1782
|
+
keepersArray.push(rebalanceIntent.priceUpdateTasks[i].completedBy.toBase58());
|
|
1783
|
+
for (let i = 0; i < rebalanceIntent.tokenSettlementTasks.length; i++)
|
|
1784
|
+
if (!rebalanceIntent.tokenSettlementTasks[i].completedBy.equals(web3_js_1.PublicKey.default))
|
|
1785
|
+
keepersArray.push(rebalanceIntent.tokenSettlementTasks[i].completedBy.toBase58());
|
|
1786
|
+
keepersArray = Array.from(new Set(keepersArray));
|
|
1787
|
+
let batchSize = 10;
|
|
1788
|
+
let ixs = [];
|
|
1789
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, keeper, 0);
|
|
1790
|
+
ixs.push(...wsolIxs);
|
|
1791
|
+
for (let batchStart = 0; batchStart < keepersArray.length; batchStart += batchSize)
|
|
1792
|
+
ixs.push((0, claimBounty_1.claimBountyIx)({
|
|
1793
|
+
keeper: keeper,
|
|
1794
|
+
basket: rebalanceIntent.basket, //@ts-ignore
|
|
1795
|
+
intent: rebalanceIntent.ownAddress,
|
|
1796
|
+
bountyMint: rebalanceIntent.bounty.bountyMint,
|
|
1797
|
+
bountyDepositor: rebalanceIntent.bounty.bountyDepositor,
|
|
1798
|
+
rentPayer: rebalanceIntent.rentPayer,
|
|
1799
|
+
keepers: keepersArray.map(keeper => new web3_js_1.PublicKey(keeper)).slice(batchStart, batchStart + batchSize),
|
|
1800
|
+
}));
|
|
1801
|
+
let txBatchData = { batches: [ixs.map(ix => ({
|
|
1802
|
+
payer: keeper,
|
|
1803
|
+
instructions: [
|
|
1804
|
+
ix,
|
|
1805
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1806
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1807
|
+
],
|
|
1808
|
+
lookupTables: [],
|
|
1809
|
+
}))] };
|
|
1810
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1811
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1812
|
+
return txPayloadBatchSequence;
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Adds bounty for automation to basket.
|
|
1817
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1818
|
+
*
|
|
1819
|
+
* @param {Object} params - The parameters for the add bounty.
|
|
1820
|
+
* @param {string} params.keeper - The public key of the keeper.
|
|
1821
|
+
* @param {string} params.basket - The public key of the basket.
|
|
1822
|
+
* @param {number} params.amount - The amount of the bounty.
|
|
1823
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1824
|
+
*/
|
|
1825
|
+
addBountyTx(params) {
|
|
1826
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1827
|
+
let keeper = new web3_js_1.PublicKey(params.keeper);
|
|
1828
|
+
let basket = yield this.fetchBasket(params.basket);
|
|
1829
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
1830
|
+
let bountyWsolAmount = 0;
|
|
1831
|
+
if (globalConfig.bountyMint.equals(constants_1.MINTS["mainnet"].WSOL)) {
|
|
1832
|
+
bountyWsolAmount = params.amount;
|
|
1833
|
+
}
|
|
1834
|
+
let wsolIxs = yield (0, txUtils_1.wrapWsolIxs)(this.sdkParams.connection, keeper, bountyWsolAmount);
|
|
1835
|
+
let ix = (0, addBounty_1.addBountyIx)({
|
|
1836
|
+
keeper: keeper,
|
|
1837
|
+
basket: basket.ownAddress,
|
|
1838
|
+
bountyMint: basket.settings.bountyMint,
|
|
1839
|
+
amount: params.amount,
|
|
1840
|
+
});
|
|
1841
|
+
let txBatchData = { batches: [[{
|
|
1842
|
+
payer: keeper,
|
|
1843
|
+
instructions: [
|
|
1844
|
+
...wsolIxs,
|
|
1845
|
+
ix,
|
|
1846
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1847
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1848
|
+
],
|
|
1849
|
+
lookupTables: [],
|
|
1850
|
+
}]] };
|
|
1851
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1852
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1853
|
+
return txPayloadBatchSequence;
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Withdraws fees from the basket, initializes WithdrawBasketFees accounts, and claims the fee tokens
|
|
1858
|
+
* for all fee types that the claimer is authorized to claim (symmetry, creator, host, or manager fees).
|
|
1859
|
+
*
|
|
1860
|
+
* This function automatically determines which fee types the claimer can claim based on:
|
|
1861
|
+
* - Symmetry fees: if claimer equals globalConfig.symmetryFeeCollector
|
|
1862
|
+
* - Creator fees: if claimer equals basket.settings.creator
|
|
1863
|
+
* - Host fees: if claimer equals basket.settings.host
|
|
1864
|
+
* - Manager fees: if claimer is in basket.settings.managers.managers
|
|
1865
|
+
*
|
|
1866
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1867
|
+
*
|
|
1868
|
+
* Batch layout:
|
|
1869
|
+
* - batch 0: One transaction per claimable fee type, each containing a withdrawFeesIx instruction.
|
|
1870
|
+
* All transactions in this batch can run in parallel. These create and populate the WithdrawBasketFees accounts.
|
|
1871
|
+
* - batch 1: Multiple transactions for claiming fee tokens, automatically batched based on account limits.
|
|
1872
|
+
* All transactions in this batch can run in parallel. These transfer tokens from WithdrawBasketFees accounts to claimers.
|
|
1873
|
+
*
|
|
1874
|
+
* Note: If not all tokens are claimed in batch 1 (e.g., due to account limits or errors),
|
|
1875
|
+
* use claimTokenFeesFromBasketTx to claim the remaining tokens.
|
|
1876
|
+
*
|
|
1877
|
+
* @param {Object} params - The parameters for withdrawing and claiming basket fees.
|
|
1878
|
+
* @param {string} params.claimer - The public key of the claimer.
|
|
1879
|
+
* @param {string} params.basket - The public key of the basket.
|
|
1880
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1881
|
+
*/
|
|
1882
|
+
withdrawBasketFeesTx(params) {
|
|
1883
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1884
|
+
let claimer = new web3_js_1.PublicKey(params.claimer);
|
|
1885
|
+
let basket = yield this.fetchBasket(params.basket);
|
|
1886
|
+
let globalConfig = yield this.fetchGlobalConfig();
|
|
1887
|
+
let claimableFeeTypes = [];
|
|
1888
|
+
let owners = [];
|
|
1889
|
+
if (claimer.equals(globalConfig.symmetryFeeCollector)) {
|
|
1890
|
+
claimableFeeTypes.push(0);
|
|
1891
|
+
owners.push([globalConfig.symmetryFeeCollector]);
|
|
1892
|
+
}
|
|
1893
|
+
if (claimer.equals(basket.settings.creator)) {
|
|
1894
|
+
claimableFeeTypes.push(1);
|
|
1895
|
+
owners.push([basket.settings.creator]);
|
|
1896
|
+
}
|
|
1897
|
+
if (claimer.equals(basket.settings.host)) {
|
|
1898
|
+
claimableFeeTypes.push(2);
|
|
1899
|
+
owners.push([basket.settings.host]);
|
|
1900
|
+
}
|
|
1901
|
+
if (basket.settings.managers.managers.find(manager => manager.equals(claimer))) {
|
|
1902
|
+
claimableFeeTypes.push(3);
|
|
1903
|
+
owners.push(basket.settings.managers.managers);
|
|
1904
|
+
}
|
|
1905
|
+
let withdrawFeesIxs = [];
|
|
1906
|
+
let claimTokenFeesFromBasketIxs = [];
|
|
1907
|
+
claimableFeeTypes.forEach((feeType, index) => {
|
|
1908
|
+
withdrawFeesIxs.push((0, claimFees_1.withdrawFeesIx)({
|
|
1909
|
+
claimer,
|
|
1910
|
+
basketTokenMint: basket.mint,
|
|
1911
|
+
feeType: feeType,
|
|
1912
|
+
}));
|
|
1913
|
+
claimTokenFeesFromBasketIxs.push(...(0, claimFees_1.claimFeeTokensFromBasketIxs)(claimer, basket.ownAddress, (0, pda_1.getWithdrawBasketFeesPda)(basket.ownAddress, feeType), claimer, owners[index], basket.composition.map(composition => composition.mint)));
|
|
1914
|
+
});
|
|
1915
|
+
let txBatchData = { batches: [
|
|
1916
|
+
withdrawFeesIxs.map(ix => ({
|
|
1917
|
+
payer: claimer,
|
|
1918
|
+
instructions: [
|
|
1919
|
+
ix,
|
|
1920
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1921
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1922
|
+
],
|
|
1923
|
+
lookupTables: [],
|
|
1924
|
+
})),
|
|
1925
|
+
claimTokenFeesFromBasketIxs.map(ix => ({
|
|
1926
|
+
payer: claimer,
|
|
1927
|
+
instructions: [
|
|
1928
|
+
ix,
|
|
1929
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1930
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1931
|
+
],
|
|
1932
|
+
lookupTables: [],
|
|
1933
|
+
})),
|
|
1934
|
+
] };
|
|
1935
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1936
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1937
|
+
return txPayloadBatchSequence;
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Claims fee tokens from a WithdrawBasketFees account.
|
|
1942
|
+
*
|
|
1943
|
+
* This function transfers accumulated fee tokens from the WithdrawBasketFees account
|
|
1944
|
+
* to the claimers (owners) based on their weights. The tokens are automatically batched
|
|
1945
|
+
* into multiple transactions if needed to respect Solana's account limit (30 accounts per transaction).
|
|
1946
|
+
*
|
|
1947
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1948
|
+
*
|
|
1949
|
+
* @param {Object} params - The parameters for claiming basket fees.
|
|
1950
|
+
* @param {string} params.claimer - The public key of the claimer.
|
|
1951
|
+
* @param {string} params.basket - The public key of the basket.
|
|
1952
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1953
|
+
*/
|
|
1954
|
+
claimTokenFeesFromBasketTx(params) {
|
|
1955
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1956
|
+
let claimer = new web3_js_1.PublicKey(params.claimer);
|
|
1957
|
+
let withdrawBasketFees = yield this.fetchWithdrawBasketFees(params.withdrawBasketFees);
|
|
1958
|
+
let claimTokenFeesFromBasketIxs = (0, claimFees_1.claimFeeTokensFromBasketIxs)(claimer, withdrawBasketFees.basket, withdrawBasketFees.ownAddress, withdrawBasketFees.rentPayer, withdrawBasketFees.owners, withdrawBasketFees.accumulatedTokens);
|
|
1959
|
+
// Create batches: all claim instructions can run in parallel
|
|
1960
|
+
let txBatchData = { batches: [
|
|
1961
|
+
claimTokenFeesFromBasketIxs.map(ix => ({
|
|
1962
|
+
payer: claimer,
|
|
1963
|
+
instructions: [
|
|
1964
|
+
ix,
|
|
1965
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
1966
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
1967
|
+
],
|
|
1968
|
+
lookupTables: [],
|
|
1969
|
+
}))
|
|
1970
|
+
] };
|
|
1971
|
+
let versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
1972
|
+
let txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
1973
|
+
return txPayloadBatchSequence;
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Rewrites lookup tables for the basket. (Used when the basket lookup tables are full)
|
|
1978
|
+
*
|
|
1979
|
+
* Returns TxPayloadBatchSequence ready for signAndSendTxPayloadBatchSequence.
|
|
1980
|
+
*
|
|
1981
|
+
* Batch layout:
|
|
1982
|
+
*
|
|
1983
|
+
* batch 0:
|
|
1984
|
+
* * tx0: [create temp lookup tables],
|
|
1985
|
+
*
|
|
1986
|
+
* batch 1:
|
|
1987
|
+
* * tx0: [extend temp lookup tables (with oracles of active tokens)],
|
|
1988
|
+
* * tx1: [extend temp lookup tables (with oracles of active tokens)],
|
|
1989
|
+
* * ...
|
|
1990
|
+
*
|
|
1991
|
+
* batch 2:
|
|
1992
|
+
* * tx0: [overwrite lookup tables with temp, deactivate old lookup tables],
|
|
1993
|
+
*
|
|
1994
|
+
* @param {Object} params - The parameters for the rewrite lookup tables.
|
|
1995
|
+
* @param {string} params.signer - The public key of the signer.
|
|
1996
|
+
* @param {string} params.basket_mint - The mint of the basket.
|
|
1997
|
+
* @param {string[]} params.additional_accounts - The additional accounts.
|
|
1998
|
+
* @returns {Promise<TxPayloadBatchSequence>} The transaction payload batch sequence.
|
|
1999
|
+
*/
|
|
2000
|
+
rewriteLookupTablesTx(params) {
|
|
2001
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2002
|
+
const signer = new web3_js_1.PublicKey(params.signer);
|
|
2003
|
+
const basketMint = new web3_js_1.PublicKey(params.basket_mint);
|
|
2004
|
+
const additionalAccounts = params.additional_accounts.map(a => new web3_js_1.PublicKey(a));
|
|
2005
|
+
const basketAddress = (0, pda_1.getBasketState)(basketMint);
|
|
2006
|
+
const basket = yield this.fetchBasket(basketAddress.toBase58());
|
|
2007
|
+
const activeLut0 = basket.lookupTables.active[0];
|
|
2008
|
+
const activeLut1 = basket.lookupTables.active[1];
|
|
2009
|
+
let oldTempLut0 = basket.lookupTables.temp[0];
|
|
2010
|
+
let oldTempLut1 = basket.lookupTables.temp[1];
|
|
2011
|
+
const slot = yield this.sdkParams.connection.getSlot("finalized");
|
|
2012
|
+
const newLut0 = (0, pda_1.getLookupTableAccount)(basketAddress, slot);
|
|
2013
|
+
const newLut1 = (0, pda_1.getLookupTableAccount)(basketAddress, slot - 1);
|
|
2014
|
+
// Step 1: create lookup tables
|
|
2015
|
+
const createIx = (0, luts_1.createBasketLookupTablesInstruction)({
|
|
2016
|
+
signer,
|
|
2017
|
+
basket: basketAddress,
|
|
2018
|
+
oldTempLookupTable0: oldTempLut0,
|
|
2019
|
+
oldTempLookupTable1: oldTempLut1,
|
|
2020
|
+
newTempLookupTable0: newLut0,
|
|
2021
|
+
newTempLookupTable1: newLut1,
|
|
2022
|
+
slot,
|
|
2023
|
+
});
|
|
2024
|
+
const txBatchData = { batches: [
|
|
2025
|
+
[{
|
|
2026
|
+
payer: signer,
|
|
2027
|
+
instructions: [
|
|
2028
|
+
createIx,
|
|
2029
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
2030
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
2031
|
+
],
|
|
2032
|
+
lookupTables: [],
|
|
2033
|
+
}],
|
|
2034
|
+
] };
|
|
2035
|
+
// Step 2: extend LUTs in batches of ~20
|
|
2036
|
+
const BATCH_SIZE = constants_1.LUT_EXTEND_BATCH_SIZE;
|
|
2037
|
+
for (let i = 0; i < additionalAccounts.length; i += BATCH_SIZE) {
|
|
2038
|
+
const batch = additionalAccounts.slice(i, i + BATCH_SIZE);
|
|
2039
|
+
const extendIx = (0, luts_1.extendBasketLookupTablesIx)({
|
|
2040
|
+
signer,
|
|
2041
|
+
basket: basketAddress,
|
|
2042
|
+
tempLookupTable0: newLut0,
|
|
2043
|
+
tempLookupTable1: newLut1,
|
|
2044
|
+
additionalAccounts: batch,
|
|
2045
|
+
});
|
|
2046
|
+
txBatchData.batches.push([{
|
|
2047
|
+
payer: signer,
|
|
2048
|
+
instructions: [
|
|
2049
|
+
extendIx,
|
|
2050
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
2051
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
2052
|
+
],
|
|
2053
|
+
lookupTables: [],
|
|
2054
|
+
}]);
|
|
2055
|
+
}
|
|
2056
|
+
// Step 3: overwrite active LUTs
|
|
2057
|
+
const overwriteIx = (0, luts_1.overwriteBasketLookupTablesIx)({
|
|
2058
|
+
signer,
|
|
2059
|
+
basket: basketAddress,
|
|
2060
|
+
tempLookupTable0: newLut0,
|
|
2061
|
+
tempLookupTable1: newLut1,
|
|
2062
|
+
activeLookupTable0: activeLut0,
|
|
2063
|
+
activeLookupTable1: activeLut1,
|
|
2064
|
+
});
|
|
2065
|
+
txBatchData.batches.push([{
|
|
2066
|
+
payer: signer,
|
|
2067
|
+
instructions: [
|
|
2068
|
+
overwriteIx,
|
|
2069
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: constants_1.COMPUTE_UNITS }),
|
|
2070
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: this.sdkParams.priorityFee }),
|
|
2071
|
+
],
|
|
2072
|
+
lookupTables: [],
|
|
2073
|
+
}]);
|
|
2074
|
+
const versionedTxs = yield (0, txUtils_1.prepareVersionedTxs)(this.sdkParams.connection, txBatchData);
|
|
2075
|
+
const txPayloadBatchSequence = (0, txUtils_1.prepareTxPayloadBatchSequence)(txBatchData, versionedTxs);
|
|
2076
|
+
return txPayloadBatchSequence;
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
signAndSendVersionedTxs(params) {
|
|
2080
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2081
|
+
let { versionedTxs, wallet } = params;
|
|
2082
|
+
versionedTxs = yield (0, txUtils_1.signVersionedTxs)(wallet, versionedTxs);
|
|
2083
|
+
return yield (0, txUtils_1.sendVersionedTxs)(this.sdkParams.connection, versionedTxs, false);
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
signAndSendTxPayloadBatchSequence(params) {
|
|
2087
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2088
|
+
let { txPayloadBatchSequence, wallet, simulateTransactions = false } = params;
|
|
2089
|
+
txPayloadBatchSequence = yield (0, txUtils_1.signTxPayloadBatchSequence)(wallet, txPayloadBatchSequence);
|
|
2090
|
+
return yield (0, txUtils_1.sendTxPayloadBatchSequence)(this.sdkParams.connection, txPayloadBatchSequence, simulateTransactions);
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
exports.SymmetryCore = SymmetryCore;
|
|
2095
|
+
var keeperMonitor_1 = require("./keeperMonitor");
|
|
2096
|
+
Object.defineProperty(exports, "KeeperMonitor", { enumerable: true, get: function () { return keeperMonitor_1.KeeperMonitor; } });
|
|
2097
|
+
Object.defineProperty(exports, "RebalanceHandler", { enumerable: true, get: function () { return keeperMonitor_1.RebalanceHandler; } });
|