@elemental-stv-core/sdk 0.11.0 → 0.12.3
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/elemental-lend/accounts.d.ts +2 -1
- package/dist/elemental-lend/accounts.js +4 -1
- package/dist/elemental-lend/constants.d.ts +4 -6
- package/dist/elemental-lend/constants.js +14 -9
- package/dist/elemental-lend/instructions.d.ts +16 -0
- package/dist/elemental-lend/instructions.js +32 -1
- package/dist/elemental-lend/types.d.ts +2 -1
- package/dist/jlpd-strategy/accounts.d.ts +6 -2
- package/dist/jlpd-strategy/accounts.js +7 -2
- package/dist/jlpd-strategy/constants.d.ts +1 -0
- package/dist/jlpd-strategy/constants.js +4 -2
- package/dist/jlpd-strategy/instructions.d.ts +53 -0
- package/dist/jlpd-strategy/instructions.js +99 -0
- package/dist/jlpd-strategy/types.d.ts +2 -0
- package/dist/p-stv-core/accounts.d.ts +46 -39
- package/dist/p-stv-core/accounts.js +87 -69
- package/dist/p-stv-core/constants.d.ts +8 -2
- package/dist/p-stv-core/constants.js +9 -3
- package/dist/p-stv-core/events.js +10 -0
- package/dist/p-stv-core/instructions.d.ts +79 -10
- package/dist/p-stv-core/instructions.js +90 -25
- package/dist/p-stv-core/types.d.ts +33 -3
- package/package.json +1 -1
|
@@ -61,46 +61,53 @@ function deserializeGlobalConfig(data) {
|
|
|
61
61
|
/**
|
|
62
62
|
* STV — per-vault state. Total 664 bytes (v2 layout).
|
|
63
63
|
*
|
|
64
|
-
*
|
|
64
|
+
* v2 layout (offsets include the 8-byte Anchor-compatible discriminator).
|
|
65
|
+
* All compile-time asserts in p-stv-core/programs/p-stv-core/src/state/stv.rs
|
|
66
|
+
* are the canonical source of truth; offsets here are copied from those asserts.
|
|
67
|
+
*
|
|
65
68
|
* [ 0.. 8] discriminator (sha256("account:Stv")[..8])
|
|
66
|
-
* [ 8.. 40] baseMint Pubkey
|
|
67
|
-
* [ 40.. 72] evMint Pubkey
|
|
68
|
-
* [ 72..104] strategy Pubkey (
|
|
69
|
-
* [104..136] feeReceiver Pubkey
|
|
70
|
-
* [136..168] lendProgram Pubkey (
|
|
71
|
-
* [168..200] vaultAta Pubkey (canonical ATA
|
|
72
|
-
* [200..
|
|
73
|
-
* [
|
|
74
|
-
* [
|
|
75
|
-
* [
|
|
76
|
-
* [
|
|
77
|
-
* [
|
|
78
|
-
* [
|
|
79
|
-
* [
|
|
80
|
-
* [
|
|
81
|
-
* [
|
|
82
|
-
* [
|
|
83
|
-
* [
|
|
84
|
-
* [
|
|
85
|
-
* [
|
|
86
|
-
* [
|
|
87
|
-
* [
|
|
88
|
-
* [
|
|
89
|
-
* [
|
|
90
|
-
* [
|
|
91
|
-
* [
|
|
92
|
-
* [
|
|
93
|
-
* [
|
|
94
|
-
* [
|
|
95
|
-
* [
|
|
96
|
-
* [
|
|
97
|
-
* [
|
|
98
|
-
* [
|
|
99
|
-
* [
|
|
100
|
-
* [
|
|
101
|
-
* [
|
|
102
|
-
* [
|
|
103
|
-
* [
|
|
69
|
+
* [ 8.. 40] baseMint Pubkey (_OFFSET_BASE_MINT == 8)
|
|
70
|
+
* [ 40.. 72] evMint Pubkey (_OFFSET_EV_MINT == 40)
|
|
71
|
+
* [ 72..104] strategy Pubkey (_OFFSET_STRATEGY == 72; immutable)
|
|
72
|
+
* [104..136] feeReceiver Pubkey (_OFFSET_FEE_RECEIVER == 104)
|
|
73
|
+
* [136..168] lendProgram Pubkey (_OFFSET_LEND_PROGRAM == 136; zero = inactive)
|
|
74
|
+
* [168..200] vaultAta Pubkey (_OFFSET_VAULT_ATA == 168; canonical ATA)
|
|
75
|
+
* [200..232] admin Pubkey (_OFFSET_ADMIN == 200; per-vault admin, never zero on v2)
|
|
76
|
+
* [232..264] pendingAdmin Pubkey (_OFFSET_PENDING_ADMIN == 232; zero = no rotation in progress)
|
|
77
|
+
* [264..296] childVaults[4] [u64; 4] (_OFFSET_CHILD_VAULTS == 264; MAX_CHILD_VAULTS = 4)
|
|
78
|
+
* [296..304] vaultId u64 (_OFFSET_VAULT_ID == 296)
|
|
79
|
+
* [304..312] reservedBase u64
|
|
80
|
+
* [312..320] requestedShares u64 (shares pending in escrow)
|
|
81
|
+
* [320..328] vaultCapacity u64 (0 = uncapped)
|
|
82
|
+
* [328..336] minDeposit u64
|
|
83
|
+
* [336..344] hwm u64 (high-water mark for perf fees)
|
|
84
|
+
* [344..352] lastFeeTs u64
|
|
85
|
+
* [352..360] epochPps u64 (locked PPS for current epoch claims)
|
|
86
|
+
* [360..368] lastNav u64 (snapshot for rate-limit window)
|
|
87
|
+
* [368..376] dailyWithdrawnBase u64 (rate-limit accumulator)
|
|
88
|
+
* [376..380] nextEpochTs u32
|
|
89
|
+
* [380..384] epochSec u32
|
|
90
|
+
* [384..388] currentEpochId u32
|
|
91
|
+
* [388..392] pendingWithdrawals u32
|
|
92
|
+
* [392..396] withdrawWindowStart u32
|
|
93
|
+
* [396..398] mgmtFeeBps u16
|
|
94
|
+
* [398..400] perfFeeBps u16
|
|
95
|
+
* [400..402] flags u16
|
|
96
|
+
* [402..404] dailyWithdrawLimitBps u16
|
|
97
|
+
* [404..405] childVaultCount u8
|
|
98
|
+
* [405..406] version u8 (== 2 for v2 accounts)
|
|
99
|
+
* [406..407] bump u8
|
|
100
|
+
* [407..408] _padding [u8; 1]
|
|
101
|
+
* [408..410] depositFeeBps u16 (_OFFSET_DEPOSIT_FEE_BPS == 408)
|
|
102
|
+
* [410..412] withdrawalFeeBps u16 (_OFFSET_WITHDRAWAL_FEE_BPS == 410)
|
|
103
|
+
* [412..416] pendingDepositCount u32 (_OFFSET_PENDING_DEPOSIT_COUNT == 412)
|
|
104
|
+
* [416..424] pendingDepositBase u64 (_OFFSET_PENDING_DEPOSIT_BASE == 416)
|
|
105
|
+
* [424..456] feeReceiverEvAta Pubkey (_OFFSET_FEE_RECEIVER_EV_ATA == 424)
|
|
106
|
+
* [456..464] lockedSeedShares u64 (_OFFSET_LOCKED_SEED_SHARES == 456)
|
|
107
|
+
* [464..465] withdrawalMode u8 (_OFFSET_WITHDRAWAL_MODE == 464; 0=instant, 1=X, 2=X+1)
|
|
108
|
+
* [465..468] _reservedPad [u8; 3] (_OFFSET_RESERVED_PAD == 465; alignment before last_nav_ts)
|
|
109
|
+
* [468..472] lastNavTs u32 (_OFFSET_LAST_NAV_TS == 468; unix seconds; 0 = no epoch yet)
|
|
110
|
+
* [472..664] _reserved [u8; 192] (_OFFSET_RESERVED == 472)
|
|
104
111
|
*/
|
|
105
112
|
function deserializeStv(data) {
|
|
106
113
|
if (data.length < constants_1.STV_SIZE) {
|
|
@@ -110,47 +117,58 @@ function deserializeStv(data) {
|
|
|
110
117
|
if (!disc.equals(constants_1.DISC_STV)) {
|
|
111
118
|
throw new Error(`Invalid Stv discriminator`);
|
|
112
119
|
}
|
|
120
|
+
// v2 gate: version must be 2 (stv.rs Stv::from_account — discriminator +
|
|
121
|
+
// version==2 is the complete loader gate; admin!=0 is enforced at write time
|
|
122
|
+
// by init_or_update_stv and is NOT re-checked by the on-chain loader).
|
|
123
|
+
const version = (0, buffer_1.readU8)(data, 405);
|
|
124
|
+
if (version !== 2) {
|
|
125
|
+
throw new Error(`Stv account is not v2: version=${version}`);
|
|
126
|
+
}
|
|
127
|
+
// childVaults: [u64; 4] at offset 264, MAX_CHILD_VAULTS = 4
|
|
113
128
|
const childVaults = [];
|
|
114
129
|
for (let i = 0; i < constants_1.MAX_STRATEGIES; i++) {
|
|
115
|
-
childVaults.push((0, buffer_1.readU64)(data,
|
|
130
|
+
childVaults.push((0, buffer_1.readU64)(data, 264 + i * 8));
|
|
116
131
|
}
|
|
117
132
|
return {
|
|
118
133
|
baseMint: (0, buffer_1.readPubkey)(data, 8),
|
|
119
134
|
evMint: (0, buffer_1.readPubkey)(data, 40),
|
|
120
135
|
strategy: (0, buffer_1.readPubkey)(data, 72),
|
|
121
136
|
feeReceiver: (0, buffer_1.readPubkey)(data, 104),
|
|
122
|
-
feeReceiverEvAta: (0, buffer_1.readPubkey)(data, 376),
|
|
123
137
|
lendProgram: (0, buffer_1.readPubkey)(data, 136),
|
|
124
138
|
vaultAta: (0, buffer_1.readPubkey)(data, 168),
|
|
139
|
+
admin: (0, buffer_1.readPubkey)(data, 200),
|
|
140
|
+
pendingAdmin: (0, buffer_1.readPubkey)(data, 232),
|
|
125
141
|
childVaults,
|
|
126
|
-
vaultId: (0, buffer_1.readU64)(data,
|
|
127
|
-
reservedBase: (0, buffer_1.readU64)(data,
|
|
128
|
-
requestedShares: (0, buffer_1.readU64)(data,
|
|
129
|
-
vaultCapacity: (0, buffer_1.readU64)(data,
|
|
130
|
-
minDeposit: (0, buffer_1.readU64)(data,
|
|
131
|
-
hwm: (0, buffer_1.readU64)(data,
|
|
132
|
-
lastFeeTs: (0, buffer_1.readU64)(data,
|
|
133
|
-
epochPps: (0, buffer_1.readU64)(data,
|
|
134
|
-
lastNav: (0, buffer_1.readU64)(data,
|
|
135
|
-
dailyWithdrawnBase: (0, buffer_1.readU64)(data,
|
|
136
|
-
nextEpochTs: (0, buffer_1.readU32)(data,
|
|
137
|
-
epochSec: (0, buffer_1.readU32)(data,
|
|
138
|
-
currentEpochId: (0, buffer_1.readU32)(data,
|
|
139
|
-
pendingWithdrawals: (0, buffer_1.readU32)(data,
|
|
140
|
-
withdrawWindowStart: (0, buffer_1.readU32)(data,
|
|
141
|
-
mgmtFeeBps: (0, buffer_1.readU16)(data,
|
|
142
|
-
perfFeeBps: (0, buffer_1.readU16)(data,
|
|
143
|
-
flags: (0, buffer_1.readU16)(data,
|
|
144
|
-
dailyWithdrawLimitBps: (0, buffer_1.readU16)(data,
|
|
145
|
-
childVaultCount: (0, buffer_1.readU8)(data,
|
|
146
|
-
version
|
|
147
|
-
bump: (0, buffer_1.readU8)(data,
|
|
148
|
-
depositFeeBps: (0, buffer_1.readU16)(data,
|
|
149
|
-
withdrawalFeeBps: (0, buffer_1.readU16)(data,
|
|
150
|
-
pendingDepositCount: (0, buffer_1.readU32)(data,
|
|
151
|
-
pendingDepositBase: (0, buffer_1.readU64)(data,
|
|
152
|
-
|
|
153
|
-
|
|
142
|
+
vaultId: (0, buffer_1.readU64)(data, 296),
|
|
143
|
+
reservedBase: (0, buffer_1.readU64)(data, 304),
|
|
144
|
+
requestedShares: (0, buffer_1.readU64)(data, 312),
|
|
145
|
+
vaultCapacity: (0, buffer_1.readU64)(data, 320),
|
|
146
|
+
minDeposit: (0, buffer_1.readU64)(data, 328),
|
|
147
|
+
hwm: (0, buffer_1.readU64)(data, 336),
|
|
148
|
+
lastFeeTs: (0, buffer_1.readU64)(data, 344),
|
|
149
|
+
epochPps: (0, buffer_1.readU64)(data, 352),
|
|
150
|
+
lastNav: (0, buffer_1.readU64)(data, 360),
|
|
151
|
+
dailyWithdrawnBase: (0, buffer_1.readU64)(data, 368),
|
|
152
|
+
nextEpochTs: (0, buffer_1.readU32)(data, 376),
|
|
153
|
+
epochSec: (0, buffer_1.readU32)(data, 380),
|
|
154
|
+
currentEpochId: (0, buffer_1.readU32)(data, 384),
|
|
155
|
+
pendingWithdrawals: (0, buffer_1.readU32)(data, 388),
|
|
156
|
+
withdrawWindowStart: (0, buffer_1.readU32)(data, 392),
|
|
157
|
+
mgmtFeeBps: (0, buffer_1.readU16)(data, 396),
|
|
158
|
+
perfFeeBps: (0, buffer_1.readU16)(data, 398),
|
|
159
|
+
flags: (0, buffer_1.readU16)(data, 400),
|
|
160
|
+
dailyWithdrawLimitBps: (0, buffer_1.readU16)(data, 402),
|
|
161
|
+
childVaultCount: (0, buffer_1.readU8)(data, 404),
|
|
162
|
+
version,
|
|
163
|
+
bump: (0, buffer_1.readU8)(data, 406),
|
|
164
|
+
depositFeeBps: (0, buffer_1.readU16)(data, 408),
|
|
165
|
+
withdrawalFeeBps: (0, buffer_1.readU16)(data, 410),
|
|
166
|
+
pendingDepositCount: (0, buffer_1.readU32)(data, 412),
|
|
167
|
+
pendingDepositBase: (0, buffer_1.readU64)(data, 416),
|
|
168
|
+
feeReceiverEvAta: (0, buffer_1.readPubkey)(data, 424),
|
|
169
|
+
lockedSeedShares: (0, buffer_1.readU64)(data, 456),
|
|
170
|
+
withdrawalMode: (0, buffer_1.readU8)(data, 464),
|
|
171
|
+
lastNavTs: (0, buffer_1.readU32)(data, 468),
|
|
154
172
|
};
|
|
155
173
|
}
|
|
156
174
|
/**
|
|
@@ -31,6 +31,8 @@ export declare const IX_PROCESS_DELAYED_DEPOSIT = 15;
|
|
|
31
31
|
export declare const IX_MIGRATE_CANCEL = 16;
|
|
32
32
|
export declare const IX_INSTANT_WITHDRAW = 17;
|
|
33
33
|
export declare const IX_SEED_STV = 18;
|
|
34
|
+
/** accept_vault_admin (disc 0x14 = 20) — complete a two-step vault-admin rotation. */
|
|
35
|
+
export declare const IX_ACCEPT_VAULT_ADMIN = 20;
|
|
34
36
|
export declare const EVT_CONFIG_INITIALIZED = 0;
|
|
35
37
|
export declare const EVT_CONFIG_UPDATED = 1;
|
|
36
38
|
export declare const EVT_STV_CREATED = 2;
|
|
@@ -54,6 +56,10 @@ export declare const EVT_MIGRATE_EXECUTED = 19;
|
|
|
54
56
|
export declare const EVT_DELAYED_DEPOSIT_PROCESSED = 20;
|
|
55
57
|
export declare const EVT_INSTANT_WITHDRAWN = 21;
|
|
56
58
|
export declare const EVT_STV_SEEDED = 22;
|
|
59
|
+
/** AdminRotationStarted — emitted when update sets pending_admin to nonzero. Fields: vault_id(8), newPendingAdmin(32). */
|
|
60
|
+
export declare const EVT_ADMIN_ROTATION_STARTED = 24;
|
|
61
|
+
/** AdminRotationAccepted — emitted by accept_vault_admin. Fields: vault_id(8), newAdmin(32). */
|
|
62
|
+
export declare const EVT_ADMIN_ROTATION_ACCEPTED = 25;
|
|
57
63
|
export declare const FLAG_PAUSED = 1;
|
|
58
64
|
export declare const FLAG_DEPOSITS_DISABLED = 2;
|
|
59
65
|
export declare const FLAG_WITHDRAWALS_DISABLED = 4;
|
|
@@ -87,8 +93,8 @@ export declare const FLAG_SEEDED = 4096;
|
|
|
87
93
|
*/
|
|
88
94
|
export declare const CFG_FLAG_GLOBAL_PAUSED = 1;
|
|
89
95
|
export { PPS_DECIMALS, BPS_DENOMINATOR, STALENESS_THRESHOLD } from "../common/constants";
|
|
90
|
-
export declare const MAX_CHILD_VAULTS =
|
|
91
|
-
export declare const MAX_STRATEGIES =
|
|
96
|
+
export declare const MAX_CHILD_VAULTS = 4;
|
|
97
|
+
export declare const MAX_STRATEGIES = 4;
|
|
92
98
|
export declare const FEE_CAP_BPS = 9900;
|
|
93
99
|
/** Max deposit_fee_bps / withdrawal_fee_bps (enforced at init_or_update_stv). */
|
|
94
100
|
export declare const MAX_FEE_BPS = 1000;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.MANAGER_ROLE_SIZE = exports.DELAYED_DEPOSIT_REQUEST_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.WR_FLAG_MIGRATE = exports.MAX_FEE_BPS = exports.FEE_CAP_BPS = exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS = exports.STALENESS_THRESHOLD = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.CFG_FLAG_GLOBAL_PAUSED = exports.FLAG_SEEDED = exports.FLAG_BYPASS_MIGRATE_DST_WAITOUT = exports.FLAG_BYPASS_MIGRATE_SRC_WAITOUT = exports.FLAG_DELAYED_DEPOSIT = exports.FLAG_DEPOSIT_FEE_ON_MIGRATE = exports.FLAG_WITHDRAWAL_FEE_ON_MIGRATE = exports.FLAG_BYPASS_WITHDRAW_LIMIT = exports.FLAG_ALLOCATOR = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.EVT_STV_SEEDED = exports.EVT_INSTANT_WITHDRAWN = exports.EVT_DELAYED_DEPOSIT_PROCESSED = exports.EVT_MIGRATE_EXECUTED = exports.EVT_MIGRATE_REQUESTED = void 0;
|
|
3
|
+
exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = exports.EVT_MANAGER_REMOVED = exports.EVT_MANAGER_ADDED = exports.EVT_STV_CLOSED = exports.EVT_FEES_SETTLED = exports.EVT_EPOCH_ADVANCED = exports.EVT_EPOCH_PROCESSED = exports.EVT_WITHDRAWN_FROM_STRATEGY = exports.EVT_DEPOSITED_TO_STRATEGY = exports.EVT_WITHDRAW_CLAIMED = exports.EVT_WITHDRAW_REQUEST_INCREASED = exports.EVT_WITHDRAW_REQUESTED = exports.EVT_DEPOSITED = exports.EVT_STV_UPDATED = exports.EVT_STV_CREATED = exports.EVT_CONFIG_UPDATED = exports.EVT_CONFIG_INITIALIZED = exports.IX_ACCEPT_VAULT_ADMIN = exports.IX_SEED_STV = exports.IX_INSTANT_WITHDRAW = exports.IX_MIGRATE_CANCEL = exports.IX_PROCESS_DELAYED_DEPOSIT = exports.IX_MIGRATE_EXECUTE = exports.IX_MIGRATE_REQUEST = exports.IX_MIGRATE_LEND = exports.IX_OVERRIDE_CLAIM_WITHDRAW = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_CLOSE_STV = exports.IX_WITHDRAW_FROM_STRATEGY = exports.IX_DEPOSIT_TO_STRATEGY = exports.IX_PROCESS_EPOCH = exports.IX_CLAIM_WITHDRAW = exports.IX_REQUEST_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_OR_UPDATE_STV = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_DELAYED_DEPOSIT_REQUEST = exports.DISC_WITHDRAW_REQUEST = exports.DISC_STV = exports.DISC_GLOBAL_CONFIG = exports.MANAGER_SEED = exports.DELAYED_DEPOSIT_SEED = exports.MIGRATE_REQUEST_SEED = exports.WITHDRAW_REQUEST_SEED = exports.EV_MINT_SEED = exports.STV_SEED = exports.CONFIG_SEED = exports.PROGRAM_ID = void 0;
|
|
4
|
+
exports.MANAGER_ROLE_SIZE = exports.DELAYED_DEPOSIT_REQUEST_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.WR_FLAG_MIGRATE = exports.MAX_FEE_BPS = exports.FEE_CAP_BPS = exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS = exports.STALENESS_THRESHOLD = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.CFG_FLAG_GLOBAL_PAUSED = exports.FLAG_SEEDED = exports.FLAG_BYPASS_MIGRATE_DST_WAITOUT = exports.FLAG_BYPASS_MIGRATE_SRC_WAITOUT = exports.FLAG_DELAYED_DEPOSIT = exports.FLAG_DEPOSIT_FEE_ON_MIGRATE = exports.FLAG_WITHDRAWAL_FEE_ON_MIGRATE = exports.FLAG_BYPASS_WITHDRAW_LIMIT = exports.FLAG_ALLOCATOR = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.EVT_ADMIN_ROTATION_ACCEPTED = exports.EVT_ADMIN_ROTATION_STARTED = exports.EVT_STV_SEEDED = exports.EVT_INSTANT_WITHDRAWN = exports.EVT_DELAYED_DEPOSIT_PROCESSED = exports.EVT_MIGRATE_EXECUTED = exports.EVT_MIGRATE_REQUESTED = exports.EVT_LEND_MIGRATED = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Program ID
|
|
@@ -57,6 +57,8 @@ exports.IX_PROCESS_DELAYED_DEPOSIT = 15;
|
|
|
57
57
|
exports.IX_MIGRATE_CANCEL = 16;
|
|
58
58
|
exports.IX_INSTANT_WITHDRAW = 17;
|
|
59
59
|
exports.IX_SEED_STV = 18;
|
|
60
|
+
/** accept_vault_admin (disc 0x14 = 20) — complete a two-step vault-admin rotation. */
|
|
61
|
+
exports.IX_ACCEPT_VAULT_ADMIN = 20;
|
|
60
62
|
// ---------------------------------------------------------------------------
|
|
61
63
|
// Event Discriminators (1-byte)
|
|
62
64
|
// ---------------------------------------------------------------------------
|
|
@@ -83,6 +85,10 @@ exports.EVT_MIGRATE_EXECUTED = 19;
|
|
|
83
85
|
exports.EVT_DELAYED_DEPOSIT_PROCESSED = 20;
|
|
84
86
|
exports.EVT_INSTANT_WITHDRAWN = 21;
|
|
85
87
|
exports.EVT_STV_SEEDED = 22;
|
|
88
|
+
/** AdminRotationStarted — emitted when update sets pending_admin to nonzero. Fields: vault_id(8), newPendingAdmin(32). */
|
|
89
|
+
exports.EVT_ADMIN_ROTATION_STARTED = 24;
|
|
90
|
+
/** AdminRotationAccepted — emitted by accept_vault_admin. Fields: vault_id(8), newAdmin(32). */
|
|
91
|
+
exports.EVT_ADMIN_ROTATION_ACCEPTED = 25;
|
|
86
92
|
// ---------------------------------------------------------------------------
|
|
87
93
|
// Vault Flags
|
|
88
94
|
// ---------------------------------------------------------------------------
|
|
@@ -127,7 +133,7 @@ var constants_2 = require("../common/constants");
|
|
|
127
133
|
Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
|
|
128
134
|
Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_2.BPS_DENOMINATOR; } });
|
|
129
135
|
Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_2.STALENESS_THRESHOLD; } });
|
|
130
|
-
exports.MAX_CHILD_VAULTS =
|
|
136
|
+
exports.MAX_CHILD_VAULTS = 4;
|
|
131
137
|
exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS; // backward compat
|
|
132
138
|
exports.FEE_CAP_BPS = 9900;
|
|
133
139
|
/** Max deposit_fee_bps / withdrawal_fee_bps (enforced at init_or_update_stv). */
|
|
@@ -213,6 +213,16 @@ function parseEventBuffer(data) {
|
|
|
213
213
|
return data.length >= 17 ? {
|
|
214
214
|
name: "StvSeeded", vaultId: (0, buffer_1.readU64)(data, 1), amount: (0, buffer_1.readU64)(data, 9),
|
|
215
215
|
} : null;
|
|
216
|
+
case constants_1.EVT_ADMIN_ROTATION_STARTED:
|
|
217
|
+
// Fields: vault_id(8), new_pending_admin(32) → total payload 41 bytes
|
|
218
|
+
return data.length >= 41 ? {
|
|
219
|
+
name: "AdminRotationStarted", vaultId: (0, buffer_1.readU64)(data, 1), newPendingAdmin: (0, buffer_1.readPubkey)(data, 9),
|
|
220
|
+
} : null;
|
|
221
|
+
case constants_1.EVT_ADMIN_ROTATION_ACCEPTED:
|
|
222
|
+
// Fields: vault_id(8), new_admin(32) → total payload 41 bytes
|
|
223
|
+
return data.length >= 41 ? {
|
|
224
|
+
name: "AdminRotationAccepted", vaultId: (0, buffer_1.readU64)(data, 1), newAdmin: (0, buffer_1.readPubkey)(data, 9),
|
|
225
|
+
} : null;
|
|
216
226
|
default:
|
|
217
227
|
return null;
|
|
218
228
|
}
|
|
@@ -49,6 +49,26 @@ export interface InitOrUpdateStvArgs {
|
|
|
49
49
|
* requires a C-1 seed floor and a non-allocator vault.
|
|
50
50
|
*/
|
|
51
51
|
withdrawalMode?: number;
|
|
52
|
+
/**
|
|
53
|
+
* CREATE path (STV does not yet exist): REQUIRED. Per-vault admin pubkey. Must be
|
|
54
|
+
* nonzero — the handler rejects zero / None. The global admin is the signer here;
|
|
55
|
+
* vaultAdmin can be a different key (e.g. a Squads multi-sig vault PDA).
|
|
56
|
+
*
|
|
57
|
+
* Wire encoding: `0x01 + 32 bytes` (Some(nonzero)). The handler will reject
|
|
58
|
+
* `None` (0x00) and `Some([0;32])` with `InvalidParameter`.
|
|
59
|
+
*/
|
|
60
|
+
vaultAdmin?: PublicKey;
|
|
61
|
+
/**
|
|
62
|
+
* UPDATE path (STV already exists): three-value encoding matching the handler:
|
|
63
|
+
* undefined / not provided → None → no change to pending rotation
|
|
64
|
+
* PublicKey.default ([0u8;32]) → Some([0;32]) → cancel pending rotation
|
|
65
|
+
* any nonzero PublicKey → Some(nonzero) → start/replace rotation; emits AdminRotationStarted
|
|
66
|
+
*
|
|
67
|
+
* Wire encoding: `0x00` (None) or `0x01 + 32 bytes` (Some).
|
|
68
|
+
* ONLY `accept_vault_admin` may change `stv.admin` post-create/migration.
|
|
69
|
+
* A pending admin has ZERO authority before accept.
|
|
70
|
+
*/
|
|
71
|
+
pendingAdmin?: PublicKey;
|
|
52
72
|
remainingAccounts?: AccountMeta[];
|
|
53
73
|
}
|
|
54
74
|
export declare function createInitOrUpdateStvIx(args: InitOrUpdateStvArgs, programId?: PublicKey): TransactionInstruction;
|
|
@@ -230,6 +250,13 @@ export interface CloseStvArgs {
|
|
|
230
250
|
evMint: PublicKey;
|
|
231
251
|
vaultAta: PublicKey;
|
|
232
252
|
tokenProgram: PublicKey;
|
|
253
|
+
/** canonical ATA(stv_pda, ev_mint) — escrow holding seed shares. */
|
|
254
|
+
escrowEvAta?: PublicKey;
|
|
255
|
+
baseMint?: PublicKey;
|
|
256
|
+
/** ATA(admin, base_mint) — receives drained seed base. */
|
|
257
|
+
adminBaseAta?: PublicKey;
|
|
258
|
+
strategyProgram?: PublicKey;
|
|
259
|
+
stvPosition?: PublicKey;
|
|
233
260
|
}
|
|
234
261
|
export declare function createCloseStvIx(args: CloseStvArgs, programId?: PublicKey): TransactionInstruction;
|
|
235
262
|
export interface AddManagerArgs {
|
|
@@ -244,9 +271,11 @@ export interface AddManagerArgs {
|
|
|
244
271
|
}
|
|
245
272
|
export declare function createAddManagerIx(args: AddManagerArgs, programId?: PublicKey): TransactionInstruction;
|
|
246
273
|
export interface RemoveManagerArgs {
|
|
274
|
+
/** Must be the per-vault admin (stv.admin). NOT the global config admin. */
|
|
247
275
|
admin: PublicKey;
|
|
248
276
|
payer: PublicKey;
|
|
249
|
-
|
|
277
|
+
/** STV PDA — required for vault-admin auth check (stv.admin == admin). */
|
|
278
|
+
stv: PublicKey;
|
|
250
279
|
managerRole: PublicKey;
|
|
251
280
|
}
|
|
252
281
|
export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
|
|
@@ -318,9 +347,8 @@ export interface MigrateRequestArgs {
|
|
|
318
347
|
*/
|
|
319
348
|
export declare function createMigrateRequestIx(args: MigrateRequestArgs, programId?: PublicKey): TransactionInstruction;
|
|
320
349
|
export interface MigrateExecuteArgs {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
managerRole: PublicKey;
|
|
350
|
+
/** Any signer. Permissionless — no ManagerRole required. */
|
|
351
|
+
caller: PublicKey;
|
|
324
352
|
/** GlobalConfig PDA — checked for CFG_FLAG_GLOBAL_PAUSED. */
|
|
325
353
|
config: PublicKey;
|
|
326
354
|
sourceStv: PublicKey;
|
|
@@ -338,7 +366,7 @@ export interface MigrateExecuteArgs {
|
|
|
338
366
|
destFeeRecvEvAta: PublicKey;
|
|
339
367
|
baseMint: PublicKey;
|
|
340
368
|
tokenProgram: PublicKey;
|
|
341
|
-
/** Account that receives the WR rent on close — must equal wr.user (slot
|
|
369
|
+
/** Account that receives the WR rent on close — must equal wr.user (slot 13). */
|
|
342
370
|
wrUserAccount: PublicKey;
|
|
343
371
|
/** Source-lend protocol AUM account count for update_aum. */
|
|
344
372
|
srcProtocolAumCount: number;
|
|
@@ -348,6 +376,16 @@ export interface MigrateExecuteArgs {
|
|
|
348
376
|
srcAutoUnrouteCount: number;
|
|
349
377
|
/** Dest-lend auto-route account count (sweep). */
|
|
350
378
|
dstAutoRouteCount: number;
|
|
379
|
+
/**
|
|
380
|
+
* Deferred path (dest has FLAG_DELAYED_DEPOSIT and FLAG_BYPASS_MIGRATE_DST_WAITOUT
|
|
381
|
+
* is unset): pass the DelayedDepositRequest PDA (writable, new account).
|
|
382
|
+
* The PDA is appended as the last two remaining_accounts after the normal
|
|
383
|
+
* lend/strategy accounts: [dest_delayed_request(w), system_program].
|
|
384
|
+
* Also requires destDelayedBump (the bump for the new PDA).
|
|
385
|
+
*/
|
|
386
|
+
destDelayedRequest?: PublicKey;
|
|
387
|
+
destDelayedBump?: number;
|
|
388
|
+
systemProgram?: PublicKey;
|
|
351
389
|
/**
|
|
352
390
|
* remaining_accounts (assemble with buildMigrateRemainingAccounts):
|
|
353
391
|
* src lend fixed(4) + src protocol AUM(srcProtocolAumCount)
|
|
@@ -355,17 +393,41 @@ export interface MigrateExecuteArgs {
|
|
|
355
393
|
* + dst lend fixed(4) + dst protocol AUM(dstProtocolAumCount)
|
|
356
394
|
* + dst strategy pairs(0 or 2) + dst auto-route(dstAutoRouteCount)
|
|
357
395
|
* Omit a lend section entirely when that side's lend_program is unset.
|
|
396
|
+
* Do NOT include dest_delayed_request/system_program here — pass them via
|
|
397
|
+
* destDelayedRequest/systemProgram instead; they are appended automatically.
|
|
358
398
|
*/
|
|
359
399
|
remainingAccounts?: AccountMeta[];
|
|
360
400
|
}
|
|
361
401
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
* dst_protocol_aum_count, src_auto_unroute_count, dst_auto_route_count
|
|
366
|
-
* (migrate_execute.rs:94-100).
|
|
402
|
+
* 14 fixed accounts (migrate_execute.rs:97 destructure). Permissionless.
|
|
403
|
+
* Instruction data: 4 bytes always; 5th byte (dest_delayed_bump) required
|
|
404
|
+
* on the deferred path (migrate_execute.rs:104-114 / 387-401).
|
|
367
405
|
*/
|
|
368
406
|
export declare function createMigrateExecuteIx(args: MigrateExecuteArgs, programId?: PublicKey): TransactionInstruction;
|
|
407
|
+
export interface MigrateCancelArgs {
|
|
408
|
+
/** Must equal wr.user. Signer + writable (receives WR rent back). */
|
|
409
|
+
user: PublicKey;
|
|
410
|
+
/** GlobalConfig PDA. */
|
|
411
|
+
config: PublicKey;
|
|
412
|
+
/** Source STV (writable). */
|
|
413
|
+
stv: PublicKey;
|
|
414
|
+
/** Migrate-kind WithdrawRequest PDA (writable). */
|
|
415
|
+
wrAccount: PublicKey;
|
|
416
|
+
/** Canonical vault ATA (writable). */
|
|
417
|
+
vaultAta: PublicKey;
|
|
418
|
+
/** User's base token ATA (receives base). */
|
|
419
|
+
userBaseAta: PublicKey;
|
|
420
|
+
/** Fee receiver's base ATA. */
|
|
421
|
+
feeReceiverBaseAta: PublicKey;
|
|
422
|
+
baseMint: PublicKey;
|
|
423
|
+
tokenProgram: PublicKey;
|
|
424
|
+
/** Lend auto-unroute accounts (0 = none). */
|
|
425
|
+
autoUnrouteCount?: number;
|
|
426
|
+
/** Lend protocol AUM accounts (0 = none). */
|
|
427
|
+
protocolAumCount?: number;
|
|
428
|
+
remainingAccounts?: AccountMeta[];
|
|
429
|
+
}
|
|
430
|
+
export declare function createMigrateCancelIx(args: MigrateCancelArgs, programId?: PublicKey): TransactionInstruction;
|
|
369
431
|
export declare function buildLendRemainingAccounts(lend: {
|
|
370
432
|
lendProgram: PublicKey;
|
|
371
433
|
lendStrategyState: PublicKey;
|
|
@@ -475,3 +537,10 @@ export interface SeedStvArgs {
|
|
|
475
537
|
amount: BN | number;
|
|
476
538
|
}
|
|
477
539
|
export declare function createSeedStvIx(args: SeedStvArgs, programId?: PublicKey): TransactionInstruction;
|
|
540
|
+
export interface AcceptVaultAdminArgs {
|
|
541
|
+
/** Must equal stv.pending_admin on-chain. Signer proves the new key is live. */
|
|
542
|
+
pendingAdmin: PublicKey;
|
|
543
|
+
/** STV account (writable). */
|
|
544
|
+
stv: PublicKey;
|
|
545
|
+
}
|
|
546
|
+
export declare function createAcceptVaultAdminIx(args: AcceptVaultAdminArgs, programId?: PublicKey): TransactionInstruction;
|
|
@@ -16,11 +16,13 @@ exports.createRemoveManagerIx = createRemoveManagerIx;
|
|
|
16
16
|
exports.createMigrateLendIx = createMigrateLendIx;
|
|
17
17
|
exports.createMigrateRequestIx = createMigrateRequestIx;
|
|
18
18
|
exports.createMigrateExecuteIx = createMigrateExecuteIx;
|
|
19
|
+
exports.createMigrateCancelIx = createMigrateCancelIx;
|
|
19
20
|
exports.buildLendRemainingAccounts = buildLendRemainingAccounts;
|
|
20
21
|
exports.buildMigrateRemainingAccounts = buildMigrateRemainingAccounts;
|
|
21
22
|
exports.buildStrategyRemainingAccounts = buildStrategyRemainingAccounts;
|
|
22
23
|
exports.createInstantWithdrawIx = createInstantWithdrawIx;
|
|
23
24
|
exports.createSeedStvIx = createSeedStvIx;
|
|
25
|
+
exports.createAcceptVaultAdminIx = createAcceptVaultAdminIx;
|
|
24
26
|
const web3_js_1 = require("@solana/web3.js");
|
|
25
27
|
const spl_token_1 = require("@solana/spl-token");
|
|
26
28
|
const buffer_1 = require("../common/buffer");
|
|
@@ -42,7 +44,7 @@ function createInitOrUpdateConfigIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
45
|
-
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, 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;
|
|
46
48
|
const data = [constants_1.IX_INIT_OR_UPDATE_STV];
|
|
47
49
|
(0, buffer_1.writeU64)(data, vaultId);
|
|
48
50
|
data.push(stvBump & 0xff);
|
|
@@ -65,6 +67,13 @@ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
65
67
|
throw new Error(`withdrawalMode must be 0 (instant), 1 (X) or 2 (X+1); got ${withdrawalMode}`);
|
|
66
68
|
}
|
|
67
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);
|
|
68
77
|
return new web3_js_1.TransactionInstruction({
|
|
69
78
|
keys: [
|
|
70
79
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
@@ -240,7 +249,7 @@ function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
240
249
|
}
|
|
241
250
|
return new web3_js_1.TransactionInstruction({
|
|
242
251
|
keys: [
|
|
243
|
-
{ pubkey: manager, isSigner: true, isWritable:
|
|
252
|
+
{ pubkey: manager, isSigner: true, isWritable: false },
|
|
244
253
|
{ pubkey: managerRole, isSigner: false, isWritable: false },
|
|
245
254
|
{ pubkey: config, isSigner: false, isWritable: false },
|
|
246
255
|
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
@@ -265,7 +274,7 @@ function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID)
|
|
|
265
274
|
data.push(protocolAumCount & 0xff);
|
|
266
275
|
return new web3_js_1.TransactionInstruction({
|
|
267
276
|
keys: [
|
|
268
|
-
{ pubkey: manager, isSigner: true, isWritable:
|
|
277
|
+
{ pubkey: manager, isSigner: true, isWritable: false },
|
|
269
278
|
{ pubkey: managerRole, isSigner: false, isWritable: false },
|
|
270
279
|
{ pubkey: config, isSigner: false, isWritable: false },
|
|
271
280
|
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
@@ -283,17 +292,26 @@ function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID)
|
|
|
283
292
|
});
|
|
284
293
|
}
|
|
285
294
|
function createCloseStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
286
|
-
const { admin, payer, config, stv, evMint, vaultAta, tokenProgram } = args;
|
|
295
|
+
const { admin, payer, config, stv, evMint, vaultAta, tokenProgram, escrowEvAta, baseMint, adminBaseAta, strategyProgram, stvPosition, } = args;
|
|
296
|
+
const keys = [
|
|
297
|
+
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
298
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
299
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
300
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
301
|
+
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
302
|
+
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
303
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
304
|
+
];
|
|
305
|
+
// Seeded path trailing accounts (close_stv.rs:122)
|
|
306
|
+
if (escrowEvAta !== undefined && baseMint !== undefined && adminBaseAta !== undefined) {
|
|
307
|
+
keys.push({ pubkey: escrowEvAta, isSigner: false, isWritable: true }, { pubkey: baseMint, isSigner: false, isWritable: false }, { pubkey: adminBaseAta, isSigner: false, isWritable: true });
|
|
308
|
+
// Strategy sub-path (close_stv.rs:149): required when stv.strategy != 0
|
|
309
|
+
if (strategyProgram !== undefined && stvPosition !== undefined) {
|
|
310
|
+
keys.push({ pubkey: strategyProgram, isSigner: false, isWritable: false }, { pubkey: stvPosition, isSigner: false, isWritable: false });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
287
313
|
return new web3_js_1.TransactionInstruction({
|
|
288
|
-
keys
|
|
289
|
-
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
290
|
-
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
291
|
-
{ pubkey: config, isSigner: false, isWritable: false },
|
|
292
|
-
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
293
|
-
{ pubkey: evMint, isSigner: false, isWritable: true },
|
|
294
|
-
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
295
|
-
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
296
|
-
],
|
|
314
|
+
keys,
|
|
297
315
|
programId,
|
|
298
316
|
data: Buffer.from([constants_1.IX_CLOSE_STV]),
|
|
299
317
|
});
|
|
@@ -316,12 +334,12 @@ function createAddManagerIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
316
334
|
});
|
|
317
335
|
}
|
|
318
336
|
function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
|
|
319
|
-
const { admin, payer,
|
|
337
|
+
const { admin, payer, stv, managerRole } = args;
|
|
320
338
|
return new web3_js_1.TransactionInstruction({
|
|
321
339
|
keys: [
|
|
322
340
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
323
341
|
{ pubkey: payer, isSigner: false, isWritable: true },
|
|
324
|
-
{ pubkey:
|
|
342
|
+
{ pubkey: stv, isSigner: false, isWritable: false },
|
|
325
343
|
{ pubkey: managerRole, isSigner: false, isWritable: true },
|
|
326
344
|
],
|
|
327
345
|
programId,
|
|
@@ -383,25 +401,38 @@ function createMigrateRequestIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
383
401
|
});
|
|
384
402
|
}
|
|
385
403
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* dst_protocol_aum_count, src_auto_unroute_count, dst_auto_route_count
|
|
390
|
-
* (migrate_execute.rs:94-100).
|
|
404
|
+
* 14 fixed accounts (migrate_execute.rs:97 destructure). Permissionless.
|
|
405
|
+
* Instruction data: 4 bytes always; 5th byte (dest_delayed_bump) required
|
|
406
|
+
* on the deferred path (migrate_execute.rs:104-114 / 387-401).
|
|
391
407
|
*/
|
|
392
408
|
function createMigrateExecuteIx(args, programId = constants_1.PROGRAM_ID) {
|
|
393
|
-
const {
|
|
394
|
-
const
|
|
409
|
+
const { caller, config, sourceStv, destStv, wrAccount, sourceVaultAta, destVaultAta, destEvMint, userDestEvAta, sourceFeeRecvAta, destFeeRecvEvAta, baseMint, tokenProgram, wrUserAccount, srcProtocolAumCount, dstProtocolAumCount, srcAutoUnrouteCount, dstAutoRouteCount, destDelayedRequest, destDelayedBump, systemProgram, remainingAccounts = [], } = args;
|
|
410
|
+
const dataBytes = [
|
|
395
411
|
constants_1.IX_MIGRATE_EXECUTE,
|
|
396
412
|
srcProtocolAumCount & 0xff,
|
|
397
413
|
dstProtocolAumCount & 0xff,
|
|
398
414
|
srcAutoUnrouteCount & 0xff,
|
|
399
415
|
dstAutoRouteCount & 0xff,
|
|
400
|
-
]
|
|
416
|
+
];
|
|
417
|
+
// 5th byte required on deferred path (migrate_execute.rs:388-390)
|
|
418
|
+
if (destDelayedRequest !== undefined) {
|
|
419
|
+
if (destDelayedBump === undefined) {
|
|
420
|
+
throw new Error("createMigrateExecuteIx: destDelayedBump is required when destDelayedRequest is provided");
|
|
421
|
+
}
|
|
422
|
+
dataBytes.push(destDelayedBump & 0xff);
|
|
423
|
+
}
|
|
424
|
+
// Trailing accounts for deferred path (migrate_execute.rs:393-401):
|
|
425
|
+
// [dest_delayed_request(w), system_program] appended after remaining.
|
|
426
|
+
const trailingKeys = [];
|
|
427
|
+
if (destDelayedRequest !== undefined) {
|
|
428
|
+
trailingKeys.push({ pubkey: destDelayedRequest, isSigner: false, isWritable: true }, { pubkey: systemProgram ?? web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false });
|
|
429
|
+
}
|
|
401
430
|
return new web3_js_1.TransactionInstruction({
|
|
402
431
|
keys: [
|
|
403
|
-
|
|
404
|
-
|
|
432
|
+
// caller must be writable on the deferred path: the handler calls
|
|
433
|
+
// check_writable(caller) at migrate_execute.rs:400 because caller funds
|
|
434
|
+
// the dest_delayed_request CreateAccount rent. Read-only on immediate path.
|
|
435
|
+
{ pubkey: caller, isSigner: true, isWritable: destDelayedRequest !== undefined },
|
|
405
436
|
{ pubkey: config, isSigner: false, isWritable: false },
|
|
406
437
|
{ pubkey: sourceStv, isSigner: false, isWritable: true },
|
|
407
438
|
{ pubkey: destStv, isSigner: false, isWritable: true },
|
|
@@ -416,6 +447,29 @@ function createMigrateExecuteIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
416
447
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
417
448
|
{ pubkey: wrUserAccount, isSigner: false, isWritable: true },
|
|
418
449
|
...remainingAccounts,
|
|
450
|
+
...trailingKeys,
|
|
451
|
+
],
|
|
452
|
+
programId,
|
|
453
|
+
data: Buffer.from(dataBytes),
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function createMigrateCancelIx(args, programId = constants_1.PROGRAM_ID) {
|
|
457
|
+
const { user, config, stv, wrAccount, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, autoUnrouteCount = 0, protocolAumCount = 0, remainingAccounts = [], } = args;
|
|
458
|
+
// Data bytes: [disc, auto_unroute_count, protocol_aum_count]
|
|
459
|
+
// Both counts are optional on-chain (data.is_empty() / data.len() > 1).
|
|
460
|
+
const data = Buffer.from([constants_1.IX_MIGRATE_CANCEL, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
|
|
461
|
+
return new web3_js_1.TransactionInstruction({
|
|
462
|
+
keys: [
|
|
463
|
+
{ pubkey: user, isSigner: true, isWritable: true },
|
|
464
|
+
{ pubkey: config, isSigner: false, isWritable: false },
|
|
465
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
466
|
+
{ pubkey: wrAccount, isSigner: false, isWritable: true },
|
|
467
|
+
{ pubkey: vaultAta, isSigner: false, isWritable: true },
|
|
468
|
+
{ pubkey: userBaseAta, isSigner: false, isWritable: true },
|
|
469
|
+
{ pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
|
|
470
|
+
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
471
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
472
|
+
...remainingAccounts,
|
|
419
473
|
],
|
|
420
474
|
programId,
|
|
421
475
|
data,
|
|
@@ -533,3 +587,14 @@ function createSeedStvIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
533
587
|
data: Buffer.from(data),
|
|
534
588
|
});
|
|
535
589
|
}
|
|
590
|
+
function createAcceptVaultAdminIx(args, programId = constants_1.PROGRAM_ID) {
|
|
591
|
+
const { pendingAdmin, stv } = args;
|
|
592
|
+
return new web3_js_1.TransactionInstruction({
|
|
593
|
+
keys: [
|
|
594
|
+
{ pubkey: pendingAdmin, isSigner: true, isWritable: false },
|
|
595
|
+
{ pubkey: stv, isSigner: false, isWritable: true },
|
|
596
|
+
],
|
|
597
|
+
programId,
|
|
598
|
+
data: Buffer.from([constants_1.IX_ACCEPT_VAULT_ADMIN]),
|
|
599
|
+
});
|
|
600
|
+
}
|