@elemental-stv-core/sdk 0.9.3 → 0.12.0
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/common/buffer.d.ts +3 -0
- package/dist/common/buffer.js +19 -0
- package/dist/elemental-lend/instructions.d.ts +14 -0
- package/dist/elemental-lend/instructions.js +18 -6
- package/dist/elemental-lend/protocol-actions.d.ts +6 -0
- package/dist/elemental-lend/protocol-actions.js +21 -10
- package/dist/jlpd-strategy/accounts.d.ts +4 -1
- package/dist/jlpd-strategy/accounts.js +6 -1
- package/dist/jlpd-strategy/adapter.d.ts +16 -6
- package/dist/jlpd-strategy/adapter.js +21 -9
- package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
- package/dist/jlpd-strategy/base-to-base-swap.js +199 -0
- package/dist/jlpd-strategy/constants.d.ts +11 -3
- package/dist/jlpd-strategy/constants.js +19 -10
- package/dist/jlpd-strategy/index.d.ts +1 -0
- package/dist/jlpd-strategy/index.js +1 -0
- package/dist/jlpd-strategy/instructions.d.ts +49 -0
- package/dist/jlpd-strategy/instructions.js +55 -0
- package/dist/jlpd-strategy/jlp-data.d.ts +11 -0
- package/dist/jlpd-strategy/jlp-data.js +15 -0
- package/dist/jlpd-strategy/settle-yield.d.ts +20 -1
- package/dist/jlpd-strategy/settle-yield.js +9 -6
- package/dist/jlpd-strategy/swap-jlp.d.ts +26 -0
- package/dist/jlpd-strategy/swap-jlp.js +74 -10
- package/dist/jlpd-strategy/types.d.ts +3 -1
- package/dist/p-stv-core/accounts.d.ts +74 -34
- package/dist/p-stv-core/accounts.js +163 -56
- package/dist/p-stv-core/constants.d.ts +49 -4
- package/dist/p-stv-core/constants.js +52 -5
- package/dist/p-stv-core/events.js +63 -9
- package/dist/p-stv-core/instructions.d.ts +302 -3
- package/dist/p-stv-core/instructions.js +277 -15
- package/dist/p-stv-core/pda.d.ts +15 -0
- package/dist/p-stv-core/pda.js +25 -0
- package/dist/p-stv-core/remaining-accounts.d.ts +4 -1
- package/dist/p-stv-core/remaining-accounts.js +17 -2
- package/dist/p-stv-core/types.d.ts +104 -4
- package/package.json +1 -1
|
@@ -7,14 +7,22 @@ exports.createRequestWithdrawIx = createRequestWithdrawIx;
|
|
|
7
7
|
exports.createClaimWithdrawIx = createClaimWithdrawIx;
|
|
8
8
|
exports.createOverrideClaimWithdrawIx = createOverrideClaimWithdrawIx;
|
|
9
9
|
exports.createProcessEpochIx = createProcessEpochIx;
|
|
10
|
+
exports.createProcessDelayedDepositIx = createProcessDelayedDepositIx;
|
|
10
11
|
exports.createDepositToStrategyIx = createDepositToStrategyIx;
|
|
11
12
|
exports.createWithdrawFromStrategyIx = createWithdrawFromStrategyIx;
|
|
12
13
|
exports.createCloseStvIx = createCloseStvIx;
|
|
13
14
|
exports.createAddManagerIx = createAddManagerIx;
|
|
14
15
|
exports.createRemoveManagerIx = createRemoveManagerIx;
|
|
15
16
|
exports.createMigrateLendIx = createMigrateLendIx;
|
|
17
|
+
exports.createMigrateRequestIx = createMigrateRequestIx;
|
|
18
|
+
exports.createMigrateExecuteIx = createMigrateExecuteIx;
|
|
16
19
|
exports.buildLendRemainingAccounts = buildLendRemainingAccounts;
|
|
20
|
+
exports.buildMigrateRemainingAccounts = buildMigrateRemainingAccounts;
|
|
17
21
|
exports.buildStrategyRemainingAccounts = buildStrategyRemainingAccounts;
|
|
22
|
+
exports.createInstantWithdrawIx = createInstantWithdrawIx;
|
|
23
|
+
exports.createSeedStvIx = createSeedStvIx;
|
|
24
|
+
exports.createMigrateStvLayoutIx = createMigrateStvLayoutIx;
|
|
25
|
+
exports.createAcceptVaultAdminIx = createAcceptVaultAdminIx;
|
|
18
26
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
27
|
const spl_token_1 = require("@solana/spl-token");
|
|
20
28
|
const buffer_1 = require("../common/buffer");
|
|
@@ -36,7 +44,7 @@ function createInitOrUpdateConfigIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
39
|
-
const { admin, payer, config, stv, evMint, baseMint, vaultAta, tokenProgram, ataProgram = spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, systemProgram = web3_js_1.SystemProgram.programId, vaultId, stvBump, evMintBump, feeReceiver, strategy, epochSec, mgmtFeeBps, perfFeeBps, vaultCapacity, minDeposit, flags, addStrategy, removeStrategy, lendProgram, dailyWithdrawLimitBps, remainingAccounts = [], } = args;
|
|
47
|
+
const { admin, payer, config, stv, evMint, baseMint, vaultAta, feeReceiverEvAta, tokenProgram, ataProgram = spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, systemProgram = web3_js_1.SystemProgram.programId, vaultId, stvBump, evMintBump, feeReceiver, strategy, epochSec, mgmtFeeBps, perfFeeBps, vaultCapacity, minDeposit, flags, addStrategy, removeStrategy, lendProgram, dailyWithdrawLimitBps, depositFeeBps, withdrawalFeeBps, withdrawalMode, vaultAdmin, pendingAdmin, remainingAccounts = [], } = args;
|
|
40
48
|
const data = [constants_1.IX_INIT_OR_UPDATE_STV];
|
|
41
49
|
(0, buffer_1.writeU64)(data, vaultId);
|
|
42
50
|
data.push(stvBump & 0xff);
|
|
@@ -53,6 +61,19 @@ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
53
61
|
(0, buffer_1.writeOptionalPubkey)(data, removeStrategy);
|
|
54
62
|
(0, buffer_1.writeOptionalPubkey)(data, lendProgram);
|
|
55
63
|
(0, buffer_1.writeOptionalU16)(data, dailyWithdrawLimitBps);
|
|
64
|
+
(0, buffer_1.writeOptionalU16)(data, depositFeeBps);
|
|
65
|
+
(0, buffer_1.writeOptionalU16)(data, withdrawalFeeBps);
|
|
66
|
+
if (withdrawalMode != null && (withdrawalMode < 0 || withdrawalMode > 2)) {
|
|
67
|
+
throw new Error(`withdrawalMode must be 0 (instant), 1 (X) or 2 (X+1); got ${withdrawalMode}`);
|
|
68
|
+
}
|
|
69
|
+
(0, buffer_1.writeOptionalU8)(data, withdrawalMode);
|
|
70
|
+
// NEW (v2): vault_admin_or_pending — the last optional-pubkey field.
|
|
71
|
+
// CREATE path: pass vaultAdmin (required nonzero). Handler rejects None/zero.
|
|
72
|
+
// UPDATE path: pass pendingAdmin (optional; None = no change, zero pubkey = cancel).
|
|
73
|
+
// Both share the same wire position; interpretation is per create/update branch.
|
|
74
|
+
// Wire: 0x00 = None, 0x01 + 32 bytes = Some(pubkey).
|
|
75
|
+
const vaultAdminOrPending = vaultAdmin ?? pendingAdmin;
|
|
76
|
+
(0, buffer_1.writeOptionalPubkey)(data, vaultAdminOrPending);
|
|
56
77
|
return new web3_js_1.TransactionInstruction({
|
|
57
78
|
keys: [
|
|
58
79
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
@@ -62,6 +83,7 @@ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
62
83
|
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
63
84
|
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
64
85
|
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
86
|
+
{ pubkey: feeReceiverEvAta, isSigner: false, isWritable: false },
|
|
65
87
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
66
88
|
{ pubkey: ataProgram, isSigner: false, isWritable: false },
|
|
67
89
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
@@ -72,12 +94,24 @@ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
72
94
|
});
|
|
73
95
|
}
|
|
74
96
|
function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
|
|
75
|
-
const { user, config, stv, vaultAta, userBaseAta, userEvAta, evMint, feeReceiverEvAta, baseMint, tokenProgram, amount, minShares, protocolAumCount = 0, autoRouteCount = 0, remainingAccounts = [], } = args;
|
|
97
|
+
const { user, config, stv, vaultAta, userBaseAta, userEvAta, evMint, feeReceiverEvAta, baseMint, tokenProgram, amount, minShares, protocolAumCount = 0, autoRouteCount = 0, delayedDepositRequest, delayedDepositBump, systemProgram = web3_js_1.SystemProgram.programId, remainingAccounts = [], } = args;
|
|
76
98
|
const data = [constants_1.IX_DEPOSIT];
|
|
77
99
|
(0, buffer_1.writeU64)(data, amount);
|
|
78
100
|
(0, buffer_1.writeU64)(data, minShares);
|
|
79
101
|
data.push(protocolAumCount & 0xff);
|
|
80
102
|
data.push(autoRouteCount & 0xff);
|
|
103
|
+
if (delayedDepositRequest) {
|
|
104
|
+
if (delayedDepositBump == null) {
|
|
105
|
+
throw new Error("delayedDepositBump is required when delayedDepositRequest is provided");
|
|
106
|
+
}
|
|
107
|
+
data.push(delayedDepositBump & 0xff);
|
|
108
|
+
}
|
|
109
|
+
const delayedAccounts = delayedDepositRequest
|
|
110
|
+
? [
|
|
111
|
+
{ pubkey: delayedDepositRequest, isSigner: false, isWritable: true },
|
|
112
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
113
|
+
]
|
|
114
|
+
: [];
|
|
81
115
|
return new web3_js_1.TransactionInstruction({
|
|
82
116
|
keys: [
|
|
83
117
|
{ pubkey: user, isSigner: true, isWritable: true },
|
|
@@ -90,6 +124,7 @@ function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
90
124
|
{ pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
|
|
91
125
|
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
92
126
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
127
|
+
...delayedAccounts,
|
|
93
128
|
...remainingAccounts,
|
|
94
129
|
],
|
|
95
130
|
programId,
|
|
@@ -118,11 +153,10 @@ function createRequestWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
118
153
|
});
|
|
119
154
|
}
|
|
120
155
|
function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
121
|
-
const { user, config, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
const data = Buffer.from([constants_1.IX_CLAIM_WITHDRAW, autoUnrouteCount & 0xff]);
|
|
156
|
+
const { user, config, stv, withdrawRequest, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, protocolAumCount = 0, } = args;
|
|
157
|
+
// Data: auto_unroute_count(1) + protocol_aum_count(1). Both always serialized —
|
|
158
|
+
// the on-chain handler reads data[0] and data[1].
|
|
159
|
+
const data = Buffer.from([constants_1.IX_CLAIM_WITHDRAW, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
|
|
126
160
|
return new web3_js_1.TransactionInstruction({
|
|
127
161
|
keys: [
|
|
128
162
|
{ pubkey: user, isSigner: true, isWritable: true },
|
|
@@ -131,6 +165,7 @@ function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
131
165
|
{ pubkey: withdrawRequest, isSigner: false, isWritable: true },
|
|
132
166
|
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
133
167
|
{ pubkey: userBaseAta, isSigner: false, isWritable: true },
|
|
168
|
+
{ pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
|
|
134
169
|
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
135
170
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
136
171
|
...remainingAccounts,
|
|
@@ -140,10 +175,10 @@ function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
140
175
|
});
|
|
141
176
|
}
|
|
142
177
|
function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
143
|
-
const { manager, managerRole, config, user, stv, withdrawRequest, vaultAta, userBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, } = args;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
178
|
+
const { manager, managerRole, config, user, stv, withdrawRequest, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, protocolAumCount = 0, } = args;
|
|
179
|
+
// Data: auto_unroute_count(1) + protocol_aum_count(1) — protocol_aum_count is data[1],
|
|
180
|
+
// so always serialize both bytes (handler reads data[0]/data[1]).
|
|
181
|
+
const data = Buffer.from([constants_1.IX_OVERRIDE_CLAIM_WITHDRAW, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
|
|
147
182
|
return new web3_js_1.TransactionInstruction({
|
|
148
183
|
keys: [
|
|
149
184
|
{ pubkey: manager, isSigner: true, isWritable: false },
|
|
@@ -154,6 +189,7 @@ function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID)
|
|
|
154
189
|
{ pubkey: withdrawRequest, isSigner: false, isWritable: true },
|
|
155
190
|
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
156
191
|
{ pubkey: userBaseAta, isSigner: false, isWritable: true },
|
|
192
|
+
{ pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
|
|
157
193
|
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
158
194
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
159
195
|
...remainingAccounts,
|
|
@@ -180,6 +216,26 @@ function createProcessEpochIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
180
216
|
data: Buffer.from([constants_1.IX_PROCESS_EPOCH, advanceEpoch ? 1 : 0, protocolAumCount & 0xff]),
|
|
181
217
|
});
|
|
182
218
|
}
|
|
219
|
+
function createProcessDelayedDepositIx(args, programId = constants_1.PROGRAM_ID) {
|
|
220
|
+
const { payer, config, stv, delayedDepositRequest, user, vaultAta, userEvAta, evMint, feeReceiverEvAta, tokenProgram, protocolAumCount = 0, remainingAccounts = [], } = args;
|
|
221
|
+
return new web3_js_1.TransactionInstruction({
|
|
222
|
+
keys: [
|
|
223
|
+
{ pubkey: payer, isSigner: true, isWritable: false },
|
|
224
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
225
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
226
|
+
{ pubkey: delayedDepositRequest, isSigner: false, isWritable: true },
|
|
227
|
+
{ pubkey: user, isSigner: false, isWritable: true },
|
|
228
|
+
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
229
|
+
{ pubkey: userEvAta, isSigner: false, isWritable: true },
|
|
230
|
+
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
231
|
+
{ pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
|
|
232
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
233
|
+
...remainingAccounts,
|
|
234
|
+
],
|
|
235
|
+
programId,
|
|
236
|
+
data: Buffer.from([constants_1.IX_PROCESS_DELAYED_DEPOSIT, protocolAumCount & 0xff]),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
183
239
|
function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
|
|
184
240
|
const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, amount, minShares, protocolAumCount, autoUnrouteCount = 0, remainingAccounts = [], } = args;
|
|
185
241
|
const data = [constants_1.IX_DEPOSIT_TO_STRATEGY];
|
|
@@ -211,9 +267,11 @@ function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
211
267
|
});
|
|
212
268
|
}
|
|
213
269
|
function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID) {
|
|
214
|
-
const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, shares, remainingAccounts = [], } = args;
|
|
270
|
+
const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, shares, protocolAumCount = 0, remainingAccounts = [], } = args;
|
|
271
|
+
// Data: shares(8) + protocol_aum_count(1).
|
|
215
272
|
const data = [constants_1.IX_WITHDRAW_FROM_STRATEGY];
|
|
216
273
|
(0, buffer_1.writeU64)(data, shares);
|
|
274
|
+
data.push(protocolAumCount & 0xff);
|
|
217
275
|
return new web3_js_1.TransactionInstruction({
|
|
218
276
|
keys: [
|
|
219
277
|
{ pubkey: manager, isSigner: true, isWritable: true },
|
|
@@ -267,12 +325,12 @@ function createAddManagerIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
267
325
|
});
|
|
268
326
|
}
|
|
269
327
|
function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
|
|
270
|
-
const { admin, payer,
|
|
328
|
+
const { admin, payer, stv, managerRole } = args;
|
|
271
329
|
return new web3_js_1.TransactionInstruction({
|
|
272
330
|
keys: [
|
|
273
331
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
274
332
|
{ pubkey: payer, isSigner: false, isWritable: true },
|
|
275
|
-
{ pubkey:
|
|
333
|
+
{ pubkey: stv, isSigner: false, isWritable: false },
|
|
276
334
|
{ pubkey: managerRole, isSigner: false, isWritable: true },
|
|
277
335
|
],
|
|
278
336
|
programId,
|
|
@@ -280,12 +338,15 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
280
338
|
});
|
|
281
339
|
}
|
|
282
340
|
function createMigrateLendIx(args, programId = constants_1.PROGRAM_ID) {
|
|
283
|
-
const { admin, payer, config, stv, vaultAta, baseMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, oldLendProgram, newLendProgram, protocolAumCount, autoUnrouteCount, remainingAccounts = [], } = args;
|
|
341
|
+
const { admin, payer, config, stv, vaultAta, baseMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, oldLendProgram, newLendProgram, protocolAumCount, autoUnrouteCount, newProtocolAumCount = 0, remainingAccounts = [], } = args;
|
|
342
|
+
// Data: old_lend(32) + new_lend(32) + protocol_aum_count(1) + auto_unroute_count(1)
|
|
343
|
+
// + new_protocol_aum_count(1).
|
|
284
344
|
const data = [constants_1.IX_MIGRATE_LEND];
|
|
285
345
|
data.push(...oldLendProgram.toBuffer());
|
|
286
346
|
data.push(...newLendProgram.toBuffer());
|
|
287
347
|
data.push(protocolAumCount & 0xff);
|
|
288
348
|
data.push(autoUnrouteCount & 0xff);
|
|
349
|
+
data.push(newProtocolAumCount & 0xff);
|
|
289
350
|
return new web3_js_1.TransactionInstruction({
|
|
290
351
|
keys: [
|
|
291
352
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
@@ -302,6 +363,73 @@ function createMigrateLendIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
302
363
|
data: Buffer.from(data),
|
|
303
364
|
});
|
|
304
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Instruction data layout (17 bytes, after the 1-byte disc is stripped by the
|
|
368
|
+
* dispatcher): shares(u64 LE) + wr_bump(u8) + min_dest_shares(u64 LE).
|
|
369
|
+
* Confirmed against migrate_request.rs:53-66.
|
|
370
|
+
*/
|
|
371
|
+
function createMigrateRequestIx(args, programId = constants_1.PROGRAM_ID) {
|
|
372
|
+
const { user, config, sourceStv, destStv, evMint, userEvAta, escrowEvAta, migrateRequest, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, shares, wrBump, minDestShares, } = args;
|
|
373
|
+
const data = [constants_1.IX_MIGRATE_REQUEST];
|
|
374
|
+
(0, buffer_1.writeU64)(data, shares);
|
|
375
|
+
data.push(wrBump & 0xff);
|
|
376
|
+
(0, buffer_1.writeU64)(data, minDestShares);
|
|
377
|
+
return new web3_js_1.TransactionInstruction({
|
|
378
|
+
keys: [
|
|
379
|
+
{ pubkey: user, isSigner: true, isWritable: true },
|
|
380
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
381
|
+
{ pubkey: sourceStv, isSigner: false, isWritable: true },
|
|
382
|
+
{ pubkey: destStv, isSigner: false, isWritable: false },
|
|
383
|
+
{ pubkey: evMint, isSigner: false, isWritable: false },
|
|
384
|
+
{ pubkey: userEvAta, isSigner: false, isWritable: true },
|
|
385
|
+
{ pubkey: escrowEvAta, isSigner: false, isWritable: true },
|
|
386
|
+
{ pubkey: migrateRequest, isSigner: false, isWritable: true },
|
|
387
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
388
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
389
|
+
],
|
|
390
|
+
programId,
|
|
391
|
+
data: Buffer.from(data),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 15 fixed accounts confirmed against migrate_execute.rs:87-91 (destructure)
|
|
396
|
+
* and the doc header at lines 29-52. Slot 14 = wrUserAccount (writable; must
|
|
397
|
+
* equal wr.user). Instruction data (4 bytes): src_protocol_aum_count,
|
|
398
|
+
* dst_protocol_aum_count, src_auto_unroute_count, dst_auto_route_count
|
|
399
|
+
* (migrate_execute.rs:94-100).
|
|
400
|
+
*/
|
|
401
|
+
function createMigrateExecuteIx(args, programId = constants_1.PROGRAM_ID) {
|
|
402
|
+
const { manager, managerRole, config, sourceStv, destStv, wrAccount, sourceVaultAta, destVaultAta, destEvMint, userDestEvAta, sourceFeeRecvAta, destFeeRecvEvAta, baseMint, tokenProgram, wrUserAccount, srcProtocolAumCount, dstProtocolAumCount, srcAutoUnrouteCount, dstAutoRouteCount, remainingAccounts = [], } = args;
|
|
403
|
+
const data = Buffer.from([
|
|
404
|
+
constants_1.IX_MIGRATE_EXECUTE,
|
|
405
|
+
srcProtocolAumCount & 0xff,
|
|
406
|
+
dstProtocolAumCount & 0xff,
|
|
407
|
+
srcAutoUnrouteCount & 0xff,
|
|
408
|
+
dstAutoRouteCount & 0xff,
|
|
409
|
+
]);
|
|
410
|
+
return new web3_js_1.TransactionInstruction({
|
|
411
|
+
keys: [
|
|
412
|
+
{ pubkey: manager, isSigner: true, isWritable: false },
|
|
413
|
+
{ pubkey: managerRole, isSigner: false, isWritable: false },
|
|
414
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
415
|
+
{ pubkey: sourceStv, isSigner: false, isWritable: true },
|
|
416
|
+
{ pubkey: destStv, isSigner: false, isWritable: true },
|
|
417
|
+
{ pubkey: wrAccount, isSigner: false, isWritable: true },
|
|
418
|
+
{ pubkey: sourceVaultAta, isSigner: false, isWritable: true },
|
|
419
|
+
{ pubkey: destVaultAta, isSigner: false, isWritable: true },
|
|
420
|
+
{ pubkey: destEvMint, isSigner: false, isWritable: true },
|
|
421
|
+
{ pubkey: userDestEvAta, isSigner: false, isWritable: true },
|
|
422
|
+
{ pubkey: sourceFeeRecvAta, isSigner: false, isWritable: true },
|
|
423
|
+
{ pubkey: destFeeRecvEvAta, isSigner: false, isWritable: true },
|
|
424
|
+
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
425
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
426
|
+
{ pubkey: wrUserAccount, isSigner: false, isWritable: true },
|
|
427
|
+
...remainingAccounts,
|
|
428
|
+
],
|
|
429
|
+
programId,
|
|
430
|
+
data,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
305
433
|
// ---------------------------------------------------------------------------
|
|
306
434
|
// Remaining Accounts Helpers
|
|
307
435
|
// ---------------------------------------------------------------------------
|
|
@@ -313,6 +441,50 @@ function buildLendRemainingAccounts(lend) {
|
|
|
313
441
|
{ pubkey: lend.lendBaseAta, isSigner: false, isWritable: true },
|
|
314
442
|
];
|
|
315
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* Assemble the migrate_execute remaining_accounts in the exact order
|
|
446
|
+
* parse_lend_accounts expects (migrate_execute.rs:298-338):
|
|
447
|
+
*
|
|
448
|
+
* [ source-lend section ] src.lend(4 fixed) + src.protocolAum(P_src)
|
|
449
|
+
* [ source auto-unroute ] src.autoUnroute (U accounts)
|
|
450
|
+
* [ dest-lend section ] dst.lend(4 fixed) + dst.protocolAum(P_dst)
|
|
451
|
+
* [ dest strategy + route] dst.strategy(0 or 2) + dst.autoRoute (R accounts)
|
|
452
|
+
*
|
|
453
|
+
* Pass `undefined` for a `lend` side whose STV has no lend_program (the 4
|
|
454
|
+
* fixed accounts + protocol AUM are omitted, matching the early return in
|
|
455
|
+
* parse_lend_accounts when lend_program_key == default).
|
|
456
|
+
*
|
|
457
|
+
* The 4 fixed lend accounts mirror `buildLendRemainingAccounts`:
|
|
458
|
+
* [lendProgram(ro), lendStrategyState(w), lendStvPosition(w), lendBaseAta(w)]
|
|
459
|
+
* `protocolAum` / `autoUnroute` / `autoRoute` / `strategy` accounts are passed
|
|
460
|
+
* through verbatim; the caller sets their writable flags per protocol.
|
|
461
|
+
*/
|
|
462
|
+
function buildMigrateRemainingAccounts(opts) {
|
|
463
|
+
const out = [];
|
|
464
|
+
// ---- source-lend section ----
|
|
465
|
+
if (opts.source.lend) {
|
|
466
|
+
out.push(...buildLendRemainingAccounts(opts.source.lend));
|
|
467
|
+
if (opts.source.protocolAum)
|
|
468
|
+
out.push(...opts.source.protocolAum);
|
|
469
|
+
}
|
|
470
|
+
// ---- source auto-unroute ----
|
|
471
|
+
if (opts.source.autoUnroute)
|
|
472
|
+
out.push(...opts.source.autoUnroute);
|
|
473
|
+
// ---- dest-lend section ----
|
|
474
|
+
if (opts.dest.lend) {
|
|
475
|
+
out.push(...buildLendRemainingAccounts(opts.dest.lend));
|
|
476
|
+
if (opts.dest.protocolAum)
|
|
477
|
+
out.push(...opts.dest.protocolAum);
|
|
478
|
+
}
|
|
479
|
+
// ---- dest strategy pair (writable state, read-only position) ----
|
|
480
|
+
if (opts.dest.strategy) {
|
|
481
|
+
out.push({ pubkey: opts.dest.strategy.strategyState, isSigner: false, isWritable: true }, { pubkey: opts.dest.strategy.stvPosition, isSigner: false, isWritable: false });
|
|
482
|
+
}
|
|
483
|
+
// ---- dest auto-route ----
|
|
484
|
+
if (opts.dest.autoRoute)
|
|
485
|
+
out.push(...opts.dest.autoRoute);
|
|
486
|
+
return out;
|
|
487
|
+
}
|
|
316
488
|
function buildStrategyRemainingAccounts(strategies) {
|
|
317
489
|
const accounts = [];
|
|
318
490
|
for (const s of strategies) {
|
|
@@ -320,3 +492,93 @@ function buildStrategyRemainingAccounts(strategies) {
|
|
|
320
492
|
}
|
|
321
493
|
return accounts;
|
|
322
494
|
}
|
|
495
|
+
function createInstantWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
|
|
496
|
+
const { user, config, stv, vaultAta, userBaseAta, feeReceiverBaseAta, feeReceiverEvAta, baseMint, evMint, userEvAta, tokenProgram, shares, minBaseOut, protocolAumCount = 0, autoUnrouteCount = 0, remainingAccounts = [], } = args;
|
|
497
|
+
// Data: shares(8) + min_base_out(8) + protocol_aum_count(1) + auto_unroute_count(1) = 18.
|
|
498
|
+
const data = [constants_1.IX_INSTANT_WITHDRAW];
|
|
499
|
+
(0, buffer_1.writeU64)(data, shares);
|
|
500
|
+
(0, buffer_1.writeU64)(data, minBaseOut);
|
|
501
|
+
data.push(protocolAumCount & 0xff);
|
|
502
|
+
data.push(autoUnrouteCount & 0xff);
|
|
503
|
+
return new web3_js_1.TransactionInstruction({
|
|
504
|
+
keys: [
|
|
505
|
+
{ pubkey: user, isSigner: true, isWritable: true },
|
|
506
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
507
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
508
|
+
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
509
|
+
{ pubkey: userBaseAta, isSigner: false, isWritable: true },
|
|
510
|
+
{ pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
|
|
511
|
+
{ pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
|
|
512
|
+
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
513
|
+
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
514
|
+
{ pubkey: userEvAta, isSigner: false, isWritable: true },
|
|
515
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
516
|
+
...remainingAccounts,
|
|
517
|
+
],
|
|
518
|
+
programId,
|
|
519
|
+
data: Buffer.from(data),
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function createSeedStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
523
|
+
const { admin, config, stv, evMint, escrowEvAta, vaultAta, adminBaseAta, baseMint, tokenProgram, ataProgram = spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, systemProgram = web3_js_1.SystemProgram.programId, amount, } = args;
|
|
524
|
+
// Data: amount(8).
|
|
525
|
+
const data = [constants_1.IX_SEED_STV];
|
|
526
|
+
(0, buffer_1.writeU64)(data, amount);
|
|
527
|
+
return new web3_js_1.TransactionInstruction({
|
|
528
|
+
keys: [
|
|
529
|
+
{ pubkey: admin, isSigner: true, isWritable: true },
|
|
530
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
531
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
532
|
+
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
533
|
+
{ pubkey: escrowEvAta, isSigner: false, isWritable: true },
|
|
534
|
+
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
535
|
+
{ pubkey: adminBaseAta, isSigner: false, isWritable: true },
|
|
536
|
+
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
537
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
538
|
+
{ pubkey: ataProgram, isSigner: false, isWritable: false },
|
|
539
|
+
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
540
|
+
],
|
|
541
|
+
programId,
|
|
542
|
+
data: Buffer.from(data),
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function createMigrateStvLayoutIx(args, programId = constants_1.PROGRAM_ID) {
|
|
546
|
+
const { admin, config, stv, expectedVaultId, expectedOldWithdrawalMode, newWithdrawalMode } = args;
|
|
547
|
+
// Data: expected_vault_id(8) + expected_old_withdrawal_mode(1)
|
|
548
|
+
// + new_withdrawal_mode (0x00 or 0x01 + byte).
|
|
549
|
+
const data = [constants_1.IX_MIGRATE_STV_LAYOUT];
|
|
550
|
+
(0, buffer_1.writeU64)(data, expectedVaultId);
|
|
551
|
+
data.push(expectedOldWithdrawalMode & 0xff);
|
|
552
|
+
if (newWithdrawalMode !== undefined && newWithdrawalMode !== null) {
|
|
553
|
+
if (newWithdrawalMode < 0 || newWithdrawalMode > 2) {
|
|
554
|
+
throw new Error(`newWithdrawalMode must be 0 (instant), 1 (X) or 2 (X+1); got ${newWithdrawalMode}`);
|
|
555
|
+
}
|
|
556
|
+
// Some(m): 0x01 tag + mode byte
|
|
557
|
+
data.push(0x01);
|
|
558
|
+
data.push(newWithdrawalMode & 0xff);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
// None: 0x00 tag
|
|
562
|
+
data.push(0x00);
|
|
563
|
+
}
|
|
564
|
+
return new web3_js_1.TransactionInstruction({
|
|
565
|
+
keys: [
|
|
566
|
+
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
567
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
568
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
569
|
+
],
|
|
570
|
+
programId,
|
|
571
|
+
data: Buffer.from(data),
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function createAcceptVaultAdminIx(args, programId = constants_1.PROGRAM_ID) {
|
|
575
|
+
const { pendingAdmin, stv } = args;
|
|
576
|
+
return new web3_js_1.TransactionInstruction({
|
|
577
|
+
keys: [
|
|
578
|
+
{ pubkey: pendingAdmin, isSigner: true, isWritable: false },
|
|
579
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
580
|
+
],
|
|
581
|
+
programId,
|
|
582
|
+
data: Buffer.from([constants_1.IX_ACCEPT_VAULT_ADMIN]),
|
|
583
|
+
});
|
|
584
|
+
}
|
package/dist/p-stv-core/pda.d.ts
CHANGED
|
@@ -4,6 +4,21 @@ export declare function findConfigPda(programId?: PublicKey): [PublicKey, number
|
|
|
4
4
|
export declare function findStvPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
|
|
5
5
|
export declare function findEvMintPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
|
|
6
6
|
export declare function findWithdrawRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
7
|
+
/**
|
|
8
|
+
* Derive the migrate-kind WithdrawRequest PDA.
|
|
9
|
+
* Seeds: `["migrate_request", stv, user, epoch_id_le4]`.
|
|
10
|
+
*
|
|
11
|
+
* Distinct prefix from `findWithdrawRequestPda` so a user can hold both a
|
|
12
|
+
* withdraw and a migrate request for the same (stv, user, epoch) without
|
|
13
|
+
* a PDA collision. `stv` is the SOURCE STV; `epochId` is the source STV's
|
|
14
|
+
* `currentEpochId` at request time.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findMigrateRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
17
|
+
/**
|
|
18
|
+
* Derive the per-user delayed deposit request PDA.
|
|
19
|
+
* Seeds: `["delayed_deposit", stv, user, epoch_id_le4]`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findDelayedDepositRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
7
22
|
/**
|
|
8
23
|
* Derive the per-STV `ManagerRole` PDA for p-STV Core.
|
|
9
24
|
* Seeds: `["manager", stv, manager]`.
|
package/dist/p-stv-core/pda.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.findConfigPda = findConfigPda;
|
|
|
7
7
|
exports.findStvPda = findStvPda;
|
|
8
8
|
exports.findEvMintPda = findEvMintPda;
|
|
9
9
|
exports.findWithdrawRequestPda = findWithdrawRequestPda;
|
|
10
|
+
exports.findMigrateRequestPda = findMigrateRequestPda;
|
|
11
|
+
exports.findDelayedDepositRequestPda = findDelayedDepositRequestPda;
|
|
10
12
|
exports.findStvManagerRolePda = findStvManagerRolePda;
|
|
11
13
|
const web3_js_1 = require("@solana/web3.js");
|
|
12
14
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -27,6 +29,29 @@ function findWithdrawRequestPda(stv, user, epochId, programId = constants_1.PROG
|
|
|
27
29
|
epochBuf.writeUInt32LE(epochId, 0);
|
|
28
30
|
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.WITHDRAW_REQUEST_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Derive the migrate-kind WithdrawRequest PDA.
|
|
34
|
+
* Seeds: `["migrate_request", stv, user, epoch_id_le4]`.
|
|
35
|
+
*
|
|
36
|
+
* Distinct prefix from `findWithdrawRequestPda` so a user can hold both a
|
|
37
|
+
* withdraw and a migrate request for the same (stv, user, epoch) without
|
|
38
|
+
* a PDA collision. `stv` is the SOURCE STV; `epochId` is the source STV's
|
|
39
|
+
* `currentEpochId` at request time.
|
|
40
|
+
*/
|
|
41
|
+
function findMigrateRequestPda(stv, user, epochId, programId = constants_1.PROGRAM_ID) {
|
|
42
|
+
const epochBuf = Buffer.alloc(4);
|
|
43
|
+
epochBuf.writeUInt32LE(epochId, 0);
|
|
44
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MIGRATE_REQUEST_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Derive the per-user delayed deposit request PDA.
|
|
48
|
+
* Seeds: `["delayed_deposit", stv, user, epoch_id_le4]`.
|
|
49
|
+
*/
|
|
50
|
+
function findDelayedDepositRequestPda(stv, user, epochId, programId = constants_1.PROGRAM_ID) {
|
|
51
|
+
const epochBuf = Buffer.alloc(4);
|
|
52
|
+
epochBuf.writeUInt32LE(epochId, 0);
|
|
53
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.DELAYED_DEPOSIT_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
54
|
+
}
|
|
30
55
|
/**
|
|
31
56
|
* Derive the per-STV `ManagerRole` PDA for p-STV Core.
|
|
32
57
|
* Seeds: `["manager", stv, manager]`.
|
|
@@ -29,6 +29,9 @@ export interface DepositContext {
|
|
|
29
29
|
export interface ClaimWithdrawContext {
|
|
30
30
|
remainingAccounts: AccountMeta[];
|
|
31
31
|
autoUnrouteCount: number;
|
|
32
|
+
/** Protocol-AUM accounts placed between the 4 fixed lend accounts and auto-unroute,
|
|
33
|
+
* feeding the pre-unsweep update_aum refresh. Pass to createClaimWithdrawIx.protocolAumCount. */
|
|
34
|
+
protocolAumCount: number;
|
|
32
35
|
/**
|
|
33
36
|
* Pre-instructions to add before the claim_withdraw ix.
|
|
34
37
|
* Currently always empty — see DepositContext.preInstructions.
|
|
@@ -72,7 +75,7 @@ export declare function buildDepositContext(connection: SolanaConnection, vault:
|
|
|
72
75
|
* - If lend is active, derives lend PDAs
|
|
73
76
|
* - If USDC + Jupiter Lend, appends auto-unroute accounts
|
|
74
77
|
*/
|
|
75
|
-
export declare function buildClaimWithdrawContext(vault: VaultInfo): Promise<ClaimWithdrawContext>;
|
|
78
|
+
export declare function buildClaimWithdrawContext(connection: SolanaConnection, vault: VaultInfo): Promise<ClaimWithdrawContext>;
|
|
76
79
|
/**
|
|
77
80
|
* Build the complete remaining_accounts for a deposit_to_strategy instruction.
|
|
78
81
|
*
|
|
@@ -144,13 +144,28 @@ async function buildDepositContext(connection, vault, payer) {
|
|
|
144
144
|
* - If lend is active, derives lend PDAs
|
|
145
145
|
* - If USDC + Jupiter Lend, appends auto-unroute accounts
|
|
146
146
|
*/
|
|
147
|
-
async function buildClaimWithdrawContext(vault) {
|
|
147
|
+
async function buildClaimWithdrawContext(connection, vault) {
|
|
148
148
|
const remainingAccounts = [];
|
|
149
149
|
const preInstructions = [];
|
|
150
150
|
let autoUnrouteCount = 0;
|
|
151
|
+
let protocolAumCount = 0;
|
|
151
152
|
if (!isDefault(vault.lendProgram)) {
|
|
152
153
|
const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
|
|
153
154
|
remainingAccounts.push(...lendAccounts);
|
|
155
|
+
// Protocol-AUM accounts (between fixed lend and auto-unroute) — feed the
|
|
156
|
+
// pre-unsweep update_aum refresh. The on-chain lend update_aum rejects an
|
|
157
|
+
// incomplete tail, so these MUST cover the strategy's full protocol set.
|
|
158
|
+
const lendState = await (0, accounts_1.fetchLendStrategyState)(connection, vault.baseMint, vault.lendProgram).catch(() => null);
|
|
159
|
+
if (lendState) {
|
|
160
|
+
try {
|
|
161
|
+
const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(connection, lendState, lendStrategyState, TOKEN_PROGRAM);
|
|
162
|
+
protocolAumCount = protocolAccounts.length;
|
|
163
|
+
remainingAccounts.push(...protocolAccounts);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Skip protocol accounts if resolution fails (no-protocol lend → 0).
|
|
167
|
+
}
|
|
168
|
+
}
|
|
154
169
|
// Auto-unroute from Jupiter Lend (for any asset with a configured pool)
|
|
155
170
|
const jupPoolForUnroute = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
|
|
156
171
|
if (jupPoolForUnroute) {
|
|
@@ -166,7 +181,7 @@ async function buildClaimWithdrawContext(vault) {
|
|
|
166
181
|
}
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
|
-
return { remainingAccounts, autoUnrouteCount, preInstructions };
|
|
184
|
+
return { remainingAccounts, autoUnrouteCount, protocolAumCount, preInstructions };
|
|
170
185
|
}
|
|
171
186
|
/**
|
|
172
187
|
* Build the complete remaining_accounts for a deposit_to_strategy instruction.
|