@elmntl/jlpd-sdk 0.2.0 → 0.13.5

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.
Files changed (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +185 -404
  3. package/dist/common/ata.d.ts +26 -0
  4. package/dist/common/ata.js +48 -0
  5. package/dist/common/buffer.d.ts +15 -0
  6. package/dist/common/buffer.js +118 -0
  7. package/dist/common/connection.d.ts +13 -0
  8. package/dist/common/connection.js +2 -0
  9. package/dist/common/constants.d.ts +14 -0
  10. package/dist/common/constants.js +31 -0
  11. package/dist/common/index.d.ts +6 -0
  12. package/dist/common/index.js +28 -0
  13. package/dist/common/strategy-interface.d.ts +59 -0
  14. package/dist/common/strategy-interface.js +42 -0
  15. package/dist/elemental-lend/accounts.d.ts +103 -0
  16. package/dist/elemental-lend/accounts.js +354 -0
  17. package/dist/elemental-lend/constants.d.ts +25 -0
  18. package/dist/elemental-lend/constants.js +48 -0
  19. package/dist/elemental-lend/index.d.ts +8 -0
  20. package/dist/elemental-lend/index.js +24 -0
  21. package/dist/elemental-lend/instructions.d.ts +104 -0
  22. package/dist/elemental-lend/instructions.js +266 -0
  23. package/dist/elemental-lend/jupiter-lend.d.ts +91 -0
  24. package/dist/elemental-lend/jupiter-lend.js +189 -0
  25. package/dist/elemental-lend/kamino-vault.d.ts +173 -0
  26. package/dist/elemental-lend/kamino-vault.js +483 -0
  27. package/dist/elemental-lend/pda.d.ts +12 -0
  28. package/dist/elemental-lend/pda.js +24 -0
  29. package/dist/elemental-lend/protocol-actions.d.ts +56 -0
  30. package/dist/elemental-lend/protocol-actions.js +244 -0
  31. package/dist/elemental-lend/types.d.ts +113 -0
  32. package/dist/elemental-lend/types.js +2 -0
  33. package/dist/elemental-lend-v2/accounts.d.ts +14 -0
  34. package/dist/elemental-lend-v2/accounts.js +136 -0
  35. package/dist/elemental-lend-v2/adapters.d.ts +22 -0
  36. package/dist/elemental-lend-v2/adapters.js +50 -0
  37. package/dist/elemental-lend-v2/constants.d.ts +48 -0
  38. package/dist/elemental-lend-v2/constants.js +104 -0
  39. package/dist/elemental-lend-v2/index.d.ts +8 -0
  40. package/dist/elemental-lend-v2/index.js +24 -0
  41. package/dist/elemental-lend-v2/instructions.d.ts +96 -0
  42. package/dist/elemental-lend-v2/instructions.js +190 -0
  43. package/dist/elemental-lend-v2/lut.d.ts +20 -0
  44. package/dist/elemental-lend-v2/lut.js +65 -0
  45. package/dist/elemental-lend-v2/pda.d.ts +9 -0
  46. package/dist/elemental-lend-v2/pda.js +27 -0
  47. package/dist/elemental-lend-v2/types.d.ts +105 -0
  48. package/dist/elemental-lend-v2/types.js +2 -0
  49. package/dist/elemental-lend-v2/update-aum.d.ts +29 -0
  50. package/dist/elemental-lend-v2/update-aum.js +82 -0
  51. package/dist/index.d.ts +5 -4199
  52. package/dist/index.js +37 -5187
  53. package/dist/jlpd-strategy/accounts.d.ts +83 -0
  54. package/dist/jlpd-strategy/accounts.js +216 -0
  55. package/dist/jlpd-strategy/adapter.d.ts +81 -0
  56. package/dist/jlpd-strategy/adapter.js +118 -0
  57. package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
  58. package/dist/jlpd-strategy/base-to-base-swap.js +205 -0
  59. package/dist/jlpd-strategy/constants.d.ts +127 -0
  60. package/dist/jlpd-strategy/constants.js +174 -0
  61. package/dist/jlpd-strategy/fluid-view.d.ts +199 -0
  62. package/dist/jlpd-strategy/fluid-view.js +799 -0
  63. package/dist/jlpd-strategy/hedge-derived.d.ts +135 -0
  64. package/dist/jlpd-strategy/hedge-derived.js +231 -0
  65. package/dist/jlpd-strategy/hedge-instructions.d.ts +206 -0
  66. package/dist/jlpd-strategy/hedge-instructions.js +296 -0
  67. package/dist/jlpd-strategy/hedge-state.d.ts +88 -0
  68. package/dist/jlpd-strategy/hedge-state.js +110 -0
  69. package/dist/jlpd-strategy/index.d.ts +17 -0
  70. package/dist/jlpd-strategy/index.js +33 -0
  71. package/dist/jlpd-strategy/instructions.d.ts +159 -0
  72. package/dist/jlpd-strategy/instructions.js +234 -0
  73. package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
  74. package/dist/jlpd-strategy/jlp-borrow.js +87 -0
  75. package/dist/jlpd-strategy/jlp-data.d.ts +166 -0
  76. package/dist/jlpd-strategy/jlp-data.js +611 -0
  77. package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
  78. package/dist/jlpd-strategy/jupusd-earn.js +166 -0
  79. package/dist/jlpd-strategy/live-jlp-price.d.ts +46 -0
  80. package/dist/jlpd-strategy/live-jlp-price.js +267 -0
  81. package/dist/jlpd-strategy/pda.d.ts +13 -0
  82. package/dist/jlpd-strategy/pda.js +28 -0
  83. package/dist/jlpd-strategy/settle-yield.d.ts +45 -0
  84. package/dist/jlpd-strategy/settle-yield.js +113 -0
  85. package/dist/jlpd-strategy/swap-jlp.d.ts +198 -0
  86. package/dist/jlpd-strategy/swap-jlp.js +586 -0
  87. package/dist/jlpd-strategy/types.d.ts +101 -0
  88. package/dist/jlpd-strategy/types.js +29 -0
  89. package/dist/p-stv-core/accounts.d.ts +152 -0
  90. package/dist/p-stv-core/accounts.js +407 -0
  91. package/dist/p-stv-core/constants.d.ts +138 -0
  92. package/dist/p-stv-core/constants.js +181 -0
  93. package/dist/p-stv-core/events.d.ts +7 -0
  94. package/dist/p-stv-core/events.js +246 -0
  95. package/dist/p-stv-core/index.d.ts +11 -0
  96. package/dist/p-stv-core/index.js +27 -0
  97. package/dist/p-stv-core/instructions.d.ts +637 -0
  98. package/dist/p-stv-core/instructions.js +670 -0
  99. package/dist/p-stv-core/lut.d.ts +41 -0
  100. package/dist/p-stv-core/lut.js +81 -0
  101. package/dist/p-stv-core/pda.d.ts +30 -0
  102. package/dist/p-stv-core/pda.js +65 -0
  103. package/dist/p-stv-core/prices.d.ts +20 -0
  104. package/dist/p-stv-core/prices.js +77 -0
  105. package/dist/p-stv-core/remaining-accounts.d.ts +107 -0
  106. package/dist/p-stv-core/remaining-accounts.js +326 -0
  107. package/dist/p-stv-core/send-tx.d.ts +72 -0
  108. package/dist/p-stv-core/send-tx.js +290 -0
  109. package/dist/p-stv-core/sol-wrap.d.ts +34 -0
  110. package/dist/p-stv-core/sol-wrap.js +74 -0
  111. package/dist/p-stv-core/types.d.ts +361 -0
  112. package/dist/p-stv-core/types.js +2 -0
  113. package/package.json +56 -15
  114. package/dist/index.d.mts +0 -4199
  115. package/dist/index.mjs +0 -5090
@@ -0,0 +1,670 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInitOrUpdateConfigIx = createInitOrUpdateConfigIx;
4
+ exports.createInitOrUpdateStvIx = createInitOrUpdateStvIx;
5
+ exports.createDepositIx = createDepositIx;
6
+ exports.createRequestWithdrawIx = createRequestWithdrawIx;
7
+ exports.createClaimWithdrawIx = createClaimWithdrawIx;
8
+ exports.createOverrideClaimWithdrawIx = createOverrideClaimWithdrawIx;
9
+ exports.createProcessEpochIx = createProcessEpochIx;
10
+ exports.createProcessDelayedDepositIx = createProcessDelayedDepositIx;
11
+ exports.createDepositToStrategyIx = createDepositToStrategyIx;
12
+ exports.createWithdrawFromStrategyIx = createWithdrawFromStrategyIx;
13
+ exports.createCloseStvIx = createCloseStvIx;
14
+ exports.createAddManagerIx = createAddManagerIx;
15
+ exports.createRemoveManagerIx = createRemoveManagerIx;
16
+ exports.createMigrateLendIx = createMigrateLendIx;
17
+ exports.createMigrateRequestIx = createMigrateRequestIx;
18
+ exports.createMigrateExecuteIx = createMigrateExecuteIx;
19
+ exports.createMigrateCancelIx = createMigrateCancelIx;
20
+ exports.buildLendRemainingAccounts = buildLendRemainingAccounts;
21
+ exports.buildMigrateRemainingAccounts = buildMigrateRemainingAccounts;
22
+ exports.buildStrategyRemainingAccounts = buildStrategyRemainingAccounts;
23
+ exports.createInstantWithdrawIx = createInstantWithdrawIx;
24
+ exports.createSeedStvIx = createSeedStvIx;
25
+ exports.createAcceptVaultAdminIx = createAcceptVaultAdminIx;
26
+ exports.createTripCircuitBreakerIx = createTripCircuitBreakerIx;
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const spl_token_1 = require("@solana/spl-token");
29
+ const buffer_1 = require("../common/buffer");
30
+ const constants_1 = require("./constants");
31
+ function createInitOrUpdateConfigIx(args, programId = constants_1.PROGRAM_ID) {
32
+ const { admin, payer, config, systemProgram = web3_js_1.SystemProgram.programId, bump, newAdmin, newFlags } = args;
33
+ const data = [constants_1.IX_INIT_OR_UPDATE_CONFIG, bump & 0xff];
34
+ (0, buffer_1.writeOptionalPubkey)(data, newAdmin);
35
+ (0, buffer_1.writeOptionalU16)(data, newFlags);
36
+ return new web3_js_1.TransactionInstruction({
37
+ keys: [
38
+ { pubkey: admin, isSigner: true, isWritable: false },
39
+ { pubkey: payer, isSigner: true, isWritable: true },
40
+ { pubkey: config, isSigner: false, isWritable: true },
41
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
42
+ ],
43
+ programId,
44
+ data: Buffer.from(data),
45
+ });
46
+ }
47
+ function createInitOrUpdateStvIx(args, programId = constants_1.PROGRAM_ID) {
48
+ 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, strategyStalenessThreshold, warmAdmin, lendInitAccounts, remainingAccounts = [], } = args;
49
+ // Reject simultaneous vaultAdmin + pendingAdmin: they share one wire position
50
+ // but are branch-interpreted (create vs update). Providing both is always wrong.
51
+ if (vaultAdmin !== undefined && pendingAdmin !== undefined) {
52
+ throw new Error("createInitOrUpdateStvIx: supply exactly one of vaultAdmin (create) or pendingAdmin (update), not both");
53
+ }
54
+ const data = [constants_1.IX_INIT_OR_UPDATE_STV];
55
+ (0, buffer_1.writeU64)(data, vaultId);
56
+ data.push(stvBump & 0xff);
57
+ data.push(evMintBump & 0xff);
58
+ (0, buffer_1.writeOptionalPubkey)(data, feeReceiver);
59
+ (0, buffer_1.writeOptionalPubkey)(data, strategy);
60
+ (0, buffer_1.writeOptionalU32)(data, epochSec);
61
+ (0, buffer_1.writeOptionalU16)(data, mgmtFeeBps);
62
+ (0, buffer_1.writeOptionalU16)(data, perfFeeBps);
63
+ (0, buffer_1.writeOptionalU64)(data, vaultCapacity);
64
+ (0, buffer_1.writeOptionalU64)(data, minDeposit);
65
+ (0, buffer_1.writeOptionalU16)(data, flags);
66
+ (0, buffer_1.writeOptionalPubkey)(data, addStrategy);
67
+ (0, buffer_1.writeOptionalPubkey)(data, removeStrategy);
68
+ (0, buffer_1.writeOptionalPubkey)(data, lendProgram);
69
+ (0, buffer_1.writeOptionalU16)(data, dailyWithdrawLimitBps);
70
+ (0, buffer_1.writeOptionalU16)(data, depositFeeBps);
71
+ (0, buffer_1.writeOptionalU16)(data, withdrawalFeeBps);
72
+ if (withdrawalMode != null && (withdrawalMode < 0 || withdrawalMode > 2)) {
73
+ throw new Error(`withdrawalMode must be 0 (instant), 1 (X) or 2 (X+1); got ${withdrawalMode}`);
74
+ }
75
+ (0, buffer_1.writeOptionalU8)(data, withdrawalMode);
76
+ // vault_admin_or_pending — the last optional-pubkey field.
77
+ // CREATE path: pass vaultAdmin (required nonzero). Handler rejects None/zero.
78
+ // UPDATE path: pass pendingAdmin (optional; None = no change, zero pubkey = cancel).
79
+ // Both share the same wire position; interpretation is per create/update branch.
80
+ // Wire: 0x00 = None, 0x01 + 32 bytes = Some(pubkey).
81
+ const vaultAdminOrPending = vaultAdmin ?? pendingAdmin;
82
+ (0, buffer_1.writeOptionalPubkey)(data, vaultAdminOrPending);
83
+ // NEW (cca48d8): strategy_staleness_threshold — appended after vault_admin_or_pending.
84
+ // parse_optional_u32 in init_or_update_stv.rs is called immediately after
85
+ // vault_admin_or_pending (line 105 of the instruction handler). Old clients
86
+ // that stop here produce EOF which the handler treats as None (no change).
87
+ (0, buffer_1.writeOptionalU32)(data, strategyStalenessThreshold);
88
+ // NEW (warm-admin-guardrails): warm_admin_arg — the LAST optional field,
89
+ // appended immediately after strategy_staleness_threshold (preserves every
90
+ // earlier optional's wire position; see the InitOrUpdateStvArgs.warmAdmin
91
+ // jsdoc above for the full create/update semantics). Old clients that stop
92
+ // before this position produce EOF, which parse_optional_pubkey treats
93
+ // identically to an explicit None.
94
+ (0, buffer_1.writeOptionalPubkey)(data, warmAdmin);
95
+ // The lend-init tail [lend_strategy_state(RO), lend_position_pda(W)] is consumed
96
+ // by the program ONLY when lend is being activated, i.e. when
97
+ // old_lend_program != new_lend && new_lend != 0 (lend_init_size = 2,
98
+ // init_or_update_stv.rs:723-729). Re-passing the already-set lend program
99
+ // (old == new) computes lend_init_size = 0 and consumes no tail. Because this
100
+ // builder has no on-chain state it cannot tell activation from a re-pass, so it
101
+ // does NOT hard-require the tail: pass lendInitAccounts when activating; omit it
102
+ // otherwise. A genuinely-missing activation tail is caught on-chain
103
+ // (IncompleteStrategyAccounts) — a revert, never a wrong-account tx.
104
+ // Prepend lend-init accounts when lend activation is requested.
105
+ // On-chain: cpi_lend_init_position reads remaining[0]=lend_strategy_state (RO)
106
+ // and remaining[1]=lend_position_pda (W) — see lend.rs:488,529 and
107
+ // init_or_update_stv.rs:554,739. Missing these causes IncompleteStrategyAccounts.
108
+ const lendInitMeta = lendInitAccounts
109
+ ? [
110
+ { pubkey: lendInitAccounts.lendStrategyState, isSigner: false, isWritable: false },
111
+ { pubkey: lendInitAccounts.lendPositionPda, isSigner: false, isWritable: true },
112
+ ]
113
+ : [];
114
+ return new web3_js_1.TransactionInstruction({
115
+ keys: [
116
+ { pubkey: admin, isSigner: true, isWritable: false },
117
+ { pubkey: payer, isSigner: true, isWritable: true },
118
+ { pubkey: config, isSigner: false, isWritable: true },
119
+ { pubkey: stv, isSigner: false, isWritable: true },
120
+ { pubkey: evMint, isSigner: false, isWritable: true },
121
+ { pubkey: baseMint, isSigner: false, isWritable: false },
122
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
123
+ { pubkey: feeReceiverEvAta, isSigner: false, isWritable: false },
124
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
125
+ { pubkey: ataProgram, isSigner: false, isWritable: false },
126
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
127
+ // lend-init accounts (when activating lend): [strategy_state(ro), position_pda(w)]
128
+ ...lendInitMeta,
129
+ ...remainingAccounts,
130
+ ],
131
+ programId,
132
+ data: Buffer.from(data),
133
+ });
134
+ }
135
+ function createDepositIx(args, programId = constants_1.PROGRAM_ID) {
136
+ 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;
137
+ const data = [constants_1.IX_DEPOSIT];
138
+ (0, buffer_1.writeU64)(data, amount);
139
+ (0, buffer_1.writeU64)(data, minShares);
140
+ data.push(protocolAumCount & 0xff);
141
+ data.push(autoRouteCount & 0xff);
142
+ if (delayedDepositRequest) {
143
+ if (delayedDepositBump == null) {
144
+ throw new Error("delayedDepositBump is required when delayedDepositRequest is provided");
145
+ }
146
+ data.push(delayedDepositBump & 0xff);
147
+ }
148
+ const delayedAccounts = delayedDepositRequest
149
+ ? [
150
+ { pubkey: delayedDepositRequest, isSigner: false, isWritable: true },
151
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
152
+ ]
153
+ : [];
154
+ return new web3_js_1.TransactionInstruction({
155
+ keys: [
156
+ { pubkey: user, isSigner: true, isWritable: true },
157
+ { pubkey: config, isSigner: false, isWritable: false },
158
+ { pubkey: stv, isSigner: false, isWritable: true },
159
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
160
+ { pubkey: userBaseAta, isSigner: false, isWritable: true },
161
+ { pubkey: userEvAta, isSigner: false, isWritable: true },
162
+ { pubkey: evMint, isSigner: false, isWritable: true },
163
+ { pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
164
+ { pubkey: baseMint, isSigner: false, isWritable: false },
165
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
166
+ ...delayedAccounts,
167
+ ...remainingAccounts,
168
+ ],
169
+ programId,
170
+ data: Buffer.from(data),
171
+ });
172
+ }
173
+ function createRequestWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
174
+ const { user, config, stv, withdrawRequest, userEvAta, escrowEvAta, evMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, shares, wrBump, } = args;
175
+ const data = [constants_1.IX_REQUEST_WITHDRAW];
176
+ (0, buffer_1.writeU64)(data, shares);
177
+ data.push(wrBump & 0xff);
178
+ return new web3_js_1.TransactionInstruction({
179
+ keys: [
180
+ { pubkey: user, isSigner: true, isWritable: true },
181
+ { pubkey: config, isSigner: false, isWritable: false },
182
+ { pubkey: stv, isSigner: false, isWritable: true },
183
+ { pubkey: withdrawRequest, isSigner: false, isWritable: true },
184
+ { pubkey: userEvAta, isSigner: false, isWritable: true },
185
+ { pubkey: escrowEvAta, isSigner: false, isWritable: true },
186
+ { pubkey: evMint, isSigner: false, isWritable: false },
187
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
188
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
189
+ ],
190
+ programId,
191
+ data: Buffer.from(data),
192
+ });
193
+ }
194
+ function createClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
195
+ const { user, config, stv, withdrawRequest, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, protocolAumCount = 0, } = args;
196
+ // Data: auto_unroute_count(1) + protocol_aum_count(1). Both always serialized —
197
+ // the on-chain handler reads data[0] and data[1].
198
+ const data = Buffer.from([constants_1.IX_CLAIM_WITHDRAW, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
199
+ return new web3_js_1.TransactionInstruction({
200
+ keys: [
201
+ { pubkey: user, isSigner: true, isWritable: true },
202
+ { pubkey: config, isSigner: false, isWritable: false },
203
+ { pubkey: stv, isSigner: false, isWritable: true },
204
+ { pubkey: withdrawRequest, isSigner: false, isWritable: true },
205
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
206
+ { pubkey: userBaseAta, isSigner: false, isWritable: true },
207
+ { pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
208
+ { pubkey: baseMint, isSigner: false, isWritable: false },
209
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
210
+ ...remainingAccounts,
211
+ ],
212
+ programId,
213
+ data,
214
+ });
215
+ }
216
+ function createOverrideClaimWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
217
+ const { authority, config, user, stv, withdrawRequest, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, remainingAccounts = [], autoUnrouteCount = 0, protocolAumCount = 0, } = args;
218
+ // Data: auto_unroute_count(1) + protocol_aum_count(1) — protocol_aum_count is data[1],
219
+ // so always serialize both bytes (handler reads data[0]/data[1]). Data layout
220
+ // is unchanged by warm-admin-guardrails — only the account list changed.
221
+ const data = Buffer.from([constants_1.IX_OVERRIDE_CLAIM_WITHDRAW, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
222
+ return new web3_js_1.TransactionInstruction({
223
+ keys: [
224
+ { pubkey: authority, isSigner: true, isWritable: false },
225
+ { pubkey: config, isSigner: false, isWritable: false },
226
+ { pubkey: user, isSigner: false, isWritable: true },
227
+ { pubkey: stv, isSigner: false, isWritable: true },
228
+ { pubkey: withdrawRequest, isSigner: false, isWritable: true },
229
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
230
+ { pubkey: userBaseAta, isSigner: false, isWritable: true },
231
+ { pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
232
+ { pubkey: baseMint, isSigner: false, isWritable: false },
233
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
234
+ ...remainingAccounts,
235
+ ],
236
+ programId,
237
+ data,
238
+ });
239
+ }
240
+ function createProcessEpochIx(args, programId = constants_1.PROGRAM_ID) {
241
+ const { payer, config, stv, evMint, feeReceiverEvAta, escrowEvAta, vaultAta, tokenProgram, advanceEpoch, protocolAumCount = 0, remainingAccounts = [], } = args;
242
+ return new web3_js_1.TransactionInstruction({
243
+ keys: [
244
+ { pubkey: payer, isSigner: true, isWritable: true },
245
+ { pubkey: config, isSigner: false, isWritable: false },
246
+ { pubkey: stv, isSigner: false, isWritable: true },
247
+ { pubkey: evMint, isSigner: false, isWritable: true },
248
+ { pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
249
+ { pubkey: escrowEvAta, isSigner: false, isWritable: true },
250
+ // vaultAta: read-only. check_vault_ata performs address+owner validation only
251
+ // (no transfer or balance mutation). process_epoch.rs never writes vault_ata.
252
+ { pubkey: vaultAta, isSigner: false, isWritable: false },
253
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
254
+ ...remainingAccounts,
255
+ ],
256
+ programId,
257
+ data: Buffer.from([constants_1.IX_PROCESS_EPOCH, advanceEpoch ? 1 : 0, protocolAumCount & 0xff]),
258
+ });
259
+ }
260
+ function createProcessDelayedDepositIx(args, programId = constants_1.PROGRAM_ID) {
261
+ const { payer, config, stv, delayedDepositRequest, user, vaultAta, userEvAta, evMint, feeReceiverEvAta, tokenProgram, protocolAumCount = 0, remainingAccounts = [], } = args;
262
+ return new web3_js_1.TransactionInstruction({
263
+ keys: [
264
+ { pubkey: payer, isSigner: true, isWritable: false },
265
+ { pubkey: config, isSigner: false, isWritable: false },
266
+ { pubkey: stv, isSigner: false, isWritable: true },
267
+ { pubkey: delayedDepositRequest, isSigner: false, isWritable: true },
268
+ { pubkey: user, isSigner: false, isWritable: true },
269
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
270
+ { pubkey: userEvAta, isSigner: false, isWritable: true },
271
+ { pubkey: evMint, isSigner: false, isWritable: true },
272
+ { pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
273
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
274
+ ...remainingAccounts,
275
+ ],
276
+ programId,
277
+ data: Buffer.from([constants_1.IX_PROCESS_DELAYED_DEPOSIT, protocolAumCount & 0xff]),
278
+ });
279
+ }
280
+ function createDepositToStrategyIx(args, programId = constants_1.PROGRAM_ID) {
281
+ const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, amount, minShares, protocolAumCount, autoUnrouteCount = 0, remainingAccounts = [], } = args;
282
+ const data = [constants_1.IX_DEPOSIT_TO_STRATEGY];
283
+ (0, buffer_1.writeU64)(data, amount);
284
+ (0, buffer_1.writeU64)(data, minShares);
285
+ // Always emit protocol_aum_count at offset 16 (even if 0); auto_unroute_count
286
+ // remains optional and is appended only when > 0.
287
+ data.push(protocolAumCount & 0xff);
288
+ if (autoUnrouteCount > 0) {
289
+ data.push(autoUnrouteCount & 0xff);
290
+ }
291
+ return new web3_js_1.TransactionInstruction({
292
+ keys: [
293
+ { pubkey: manager, isSigner: true, isWritable: false },
294
+ { pubkey: managerRole, isSigner: false, isWritable: false },
295
+ { pubkey: config, isSigner: false, isWritable: false },
296
+ { pubkey: stv, isSigner: false, isWritable: true },
297
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
298
+ { pubkey: baseMint, isSigner: false, isWritable: false },
299
+ { pubkey: strategyProgram, isSigner: false, isWritable: false },
300
+ { pubkey: strategyState, isSigner: false, isWritable: true },
301
+ { pubkey: stvPosition, isSigner: false, isWritable: true },
302
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: true },
303
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
304
+ ...remainingAccounts,
305
+ ],
306
+ programId,
307
+ data: Buffer.from(data),
308
+ });
309
+ }
310
+ function createWithdrawFromStrategyIx(args, programId = constants_1.PROGRAM_ID) {
311
+ const { manager, managerRole, config, stv, vaultAta, baseMint, strategyProgram, strategyState, stvPosition, strategyBaseAta, tokenProgram, shares, protocolAumCount = 0, remainingAccounts = [], } = args;
312
+ // Data: shares(8) + protocol_aum_count(1).
313
+ const data = [constants_1.IX_WITHDRAW_FROM_STRATEGY];
314
+ (0, buffer_1.writeU64)(data, shares);
315
+ data.push(protocolAumCount & 0xff);
316
+ return new web3_js_1.TransactionInstruction({
317
+ keys: [
318
+ { pubkey: manager, isSigner: true, isWritable: false },
319
+ { pubkey: managerRole, isSigner: false, isWritable: false },
320
+ { pubkey: config, isSigner: false, isWritable: false },
321
+ { pubkey: stv, isSigner: false, isWritable: true },
322
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
323
+ { pubkey: baseMint, isSigner: false, isWritable: false },
324
+ { pubkey: strategyProgram, isSigner: false, isWritable: false },
325
+ { pubkey: strategyState, isSigner: false, isWritable: true },
326
+ { pubkey: stvPosition, isSigner: false, isWritable: true },
327
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: true },
328
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
329
+ ...remainingAccounts,
330
+ ],
331
+ programId,
332
+ data: Buffer.from(data),
333
+ });
334
+ }
335
+ function createCloseStvIx(args, programId = constants_1.PROGRAM_ID) {
336
+ const { admin, payer, config, stv, evMint, vaultAta, tokenProgram, escrowEvAta, baseMint, adminBaseAta, strategyProgram, stvPosition, } = args;
337
+ // FIX B: guard against partial seeded-tail or partial strategy-tail.
338
+ // The seeded tail [escrowEvAta, baseMint, adminBaseAta] is ALL-or-none:
339
+ // partial supply leads to a silently malformed account list.
340
+ const seededCount = [escrowEvAta, baseMint, adminBaseAta].filter(x => x !== undefined).length;
341
+ if (seededCount > 0 && seededCount < 3) {
342
+ throw new Error("createCloseStvIx: seeded-path tail requires all three accounts " +
343
+ "(escrowEvAta, baseMint, adminBaseAta) — got " + seededCount + " of 3");
344
+ }
345
+ // The strategy sub-tail [strategyProgram, stvPosition] is ALL-or-none.
346
+ const strategyCount = [strategyProgram, stvPosition].filter(x => x !== undefined).length;
347
+ if (strategyCount > 0 && strategyCount < 2) {
348
+ throw new Error("createCloseStvIx: strategy sub-tail requires both accounts " +
349
+ "(strategyProgram, stvPosition) — got " + strategyCount + " of 2");
350
+ }
351
+ const keys = [
352
+ { pubkey: admin, isSigner: true, isWritable: false },
353
+ { pubkey: payer, isSigner: true, isWritable: true },
354
+ { pubkey: config, isSigner: false, isWritable: false },
355
+ { pubkey: stv, isSigner: false, isWritable: true },
356
+ { pubkey: evMint, isSigner: false, isWritable: true },
357
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
358
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
359
+ ];
360
+ // Seeded path trailing accounts (close_stv.rs:122)
361
+ if (escrowEvAta !== undefined && baseMint !== undefined && adminBaseAta !== undefined) {
362
+ keys.push({ pubkey: escrowEvAta, isSigner: false, isWritable: true }, { pubkey: baseMint, isSigner: false, isWritable: false }, { pubkey: adminBaseAta, isSigner: false, isWritable: true });
363
+ // Strategy sub-path (close_stv.rs:149): required when stv.strategy != 0
364
+ if (strategyProgram !== undefined && stvPosition !== undefined) {
365
+ keys.push({ pubkey: strategyProgram, isSigner: false, isWritable: false }, { pubkey: stvPosition, isSigner: false, isWritable: false });
366
+ }
367
+ }
368
+ return new web3_js_1.TransactionInstruction({
369
+ keys,
370
+ programId,
371
+ data: Buffer.from([constants_1.IX_CLOSE_STV]),
372
+ });
373
+ }
374
+ function createAddManagerIx(args, programId = constants_1.PROGRAM_ID) {
375
+ const { admin, payer, config, stv, managerRole, managerRoleBump, manager, systemProgram = web3_js_1.SystemProgram.programId, } = args;
376
+ const data = [constants_1.IX_ADD_MANAGER, managerRoleBump & 0xff];
377
+ data.push(...manager.toBuffer());
378
+ return new web3_js_1.TransactionInstruction({
379
+ keys: [
380
+ { pubkey: admin, isSigner: true, isWritable: false },
381
+ { pubkey: payer, isSigner: true, isWritable: true },
382
+ { pubkey: config, isSigner: false, isWritable: false },
383
+ { pubkey: stv, isSigner: false, isWritable: false },
384
+ { pubkey: managerRole, isSigner: false, isWritable: true },
385
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
386
+ ],
387
+ programId,
388
+ data: Buffer.from(data),
389
+ });
390
+ }
391
+ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
392
+ const { admin, payer, stv, managerRole } = args;
393
+ return new web3_js_1.TransactionInstruction({
394
+ keys: [
395
+ { pubkey: admin, isSigner: true, isWritable: false },
396
+ { pubkey: payer, isSigner: false, isWritable: true },
397
+ { pubkey: stv, isSigner: false, isWritable: false },
398
+ { pubkey: managerRole, isSigner: false, isWritable: true },
399
+ ],
400
+ programId,
401
+ data: Buffer.from([constants_1.IX_REMOVE_MANAGER]),
402
+ });
403
+ }
404
+ function createMigrateLendIx(args, programId = constants_1.PROGRAM_ID) {
405
+ const { admin, payer, config, stv, vaultAta, baseMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, oldLendProgram, newLendProgram, protocolAumCount, autoUnrouteCount, newProtocolAumCount = 0, remainingAccounts = [], } = args;
406
+ // Data: old_lend(32) + new_lend(32) + protocol_aum_count(1) + auto_unroute_count(1)
407
+ // + new_protocol_aum_count(1).
408
+ const data = [constants_1.IX_MIGRATE_LEND];
409
+ data.push(...oldLendProgram.toBuffer());
410
+ data.push(...newLendProgram.toBuffer());
411
+ data.push(protocolAumCount & 0xff);
412
+ data.push(autoUnrouteCount & 0xff);
413
+ data.push(newProtocolAumCount & 0xff);
414
+ return new web3_js_1.TransactionInstruction({
415
+ keys: [
416
+ { pubkey: admin, isSigner: true, isWritable: false },
417
+ { pubkey: payer, isSigner: true, isWritable: true },
418
+ { pubkey: config, isSigner: false, isWritable: false },
419
+ { pubkey: stv, isSigner: false, isWritable: true },
420
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
421
+ { pubkey: baseMint, isSigner: false, isWritable: false },
422
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
423
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
424
+ ...remainingAccounts,
425
+ ],
426
+ programId,
427
+ data: Buffer.from(data),
428
+ });
429
+ }
430
+ /**
431
+ * Instruction data layout (17 bytes, after the 1-byte disc is stripped by the
432
+ * dispatcher): shares(u64 LE) + wr_bump(u8) + min_dest_shares(u64 LE).
433
+ * Confirmed against migrate_request.rs:53-66.
434
+ */
435
+ function createMigrateRequestIx(args, programId = constants_1.PROGRAM_ID) {
436
+ const { user, config, sourceStv, destStv, evMint, userEvAta, escrowEvAta, migrateRequest, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, shares, wrBump, minDestShares, } = args;
437
+ const data = [constants_1.IX_MIGRATE_REQUEST];
438
+ (0, buffer_1.writeU64)(data, shares);
439
+ data.push(wrBump & 0xff);
440
+ (0, buffer_1.writeU64)(data, minDestShares);
441
+ return new web3_js_1.TransactionInstruction({
442
+ keys: [
443
+ { pubkey: user, isSigner: true, isWritable: true },
444
+ { pubkey: config, isSigner: false, isWritable: false },
445
+ { pubkey: sourceStv, isSigner: false, isWritable: true },
446
+ { pubkey: destStv, isSigner: false, isWritable: false },
447
+ { pubkey: evMint, isSigner: false, isWritable: false },
448
+ { pubkey: userEvAta, isSigner: false, isWritable: true },
449
+ { pubkey: escrowEvAta, isSigner: false, isWritable: true },
450
+ { pubkey: migrateRequest, isSigner: false, isWritable: true },
451
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
452
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
453
+ ],
454
+ programId,
455
+ data: Buffer.from(data),
456
+ });
457
+ }
458
+ /**
459
+ * 14 fixed accounts (migrate_execute.rs:97 destructure). Permissionless.
460
+ * Instruction data: 4 bytes always; 5th byte (dest_delayed_bump) required
461
+ * on the deferred path (migrate_execute.rs:104-114 / 387-401).
462
+ */
463
+ function createMigrateExecuteIx(args, programId = constants_1.PROGRAM_ID) {
464
+ const { caller, config, sourceStv, destStv, wrAccount, sourceVaultAta, destVaultAta, destEvMint, userDestEvAta, sourceFeeRecvAta, destFeeRecvEvAta, baseMint, tokenProgram, wrUserAccount, srcProtocolAumCount, dstProtocolAumCount, srcAutoUnrouteCount, dstAutoRouteCount, destDelayedRequest, destDelayedBump, systemProgram, remainingAccounts = [], } = args;
465
+ const dataBytes = [
466
+ constants_1.IX_MIGRATE_EXECUTE,
467
+ srcProtocolAumCount & 0xff,
468
+ dstProtocolAumCount & 0xff,
469
+ srcAutoUnrouteCount & 0xff,
470
+ dstAutoRouteCount & 0xff,
471
+ ];
472
+ // 5th byte required on deferred path (migrate_execute.rs:388-390)
473
+ if (destDelayedRequest !== undefined) {
474
+ if (destDelayedBump === undefined) {
475
+ throw new Error("createMigrateExecuteIx: destDelayedBump is required when destDelayedRequest is provided");
476
+ }
477
+ dataBytes.push(destDelayedBump & 0xff);
478
+ }
479
+ // Trailing accounts for deferred path (migrate_execute.rs:393-401):
480
+ // [dest_delayed_request(w), system_program] appended after remaining.
481
+ const trailingKeys = [];
482
+ if (destDelayedRequest !== undefined) {
483
+ trailingKeys.push({ pubkey: destDelayedRequest, isSigner: false, isWritable: true }, { pubkey: systemProgram ?? web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false });
484
+ }
485
+ return new web3_js_1.TransactionInstruction({
486
+ keys: [
487
+ // caller must be writable on the deferred path: the handler calls
488
+ // check_writable(caller) at migrate_execute.rs:400 because caller funds
489
+ // the dest_delayed_request CreateAccount rent. Read-only on immediate path.
490
+ { pubkey: caller, isSigner: true, isWritable: destDelayedRequest !== undefined },
491
+ { pubkey: config, isSigner: false, isWritable: false },
492
+ { pubkey: sourceStv, isSigner: false, isWritable: true },
493
+ { pubkey: destStv, isSigner: false, isWritable: true },
494
+ { pubkey: wrAccount, isSigner: false, isWritable: true },
495
+ { pubkey: sourceVaultAta, isSigner: false, isWritable: true },
496
+ { pubkey: destVaultAta, isSigner: false, isWritable: true },
497
+ { pubkey: destEvMint, isSigner: false, isWritable: true },
498
+ { pubkey: userDestEvAta, isSigner: false, isWritable: true },
499
+ { pubkey: sourceFeeRecvAta, isSigner: false, isWritable: true },
500
+ { pubkey: destFeeRecvEvAta, isSigner: false, isWritable: true },
501
+ { pubkey: baseMint, isSigner: false, isWritable: false },
502
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
503
+ { pubkey: wrUserAccount, isSigner: false, isWritable: true },
504
+ ...remainingAccounts,
505
+ ...trailingKeys,
506
+ ],
507
+ programId,
508
+ data: Buffer.from(dataBytes),
509
+ });
510
+ }
511
+ function createMigrateCancelIx(args, programId = constants_1.PROGRAM_ID) {
512
+ const { user, config, stv, wrAccount, vaultAta, userBaseAta, feeReceiverBaseAta, baseMint, tokenProgram, autoUnrouteCount = 0, protocolAumCount = 0, remainingAccounts = [], } = args;
513
+ // Data bytes: [disc, auto_unroute_count, protocol_aum_count]
514
+ // Both counts are optional on-chain (data.is_empty() / data.len() > 1).
515
+ const data = Buffer.from([constants_1.IX_MIGRATE_CANCEL, autoUnrouteCount & 0xff, protocolAumCount & 0xff]);
516
+ return new web3_js_1.TransactionInstruction({
517
+ keys: [
518
+ { pubkey: user, isSigner: true, isWritable: true },
519
+ { pubkey: config, isSigner: false, isWritable: false },
520
+ { pubkey: stv, isSigner: false, isWritable: true },
521
+ { pubkey: wrAccount, isSigner: false, isWritable: true },
522
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
523
+ { pubkey: userBaseAta, isSigner: false, isWritable: true },
524
+ { pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
525
+ { pubkey: baseMint, isSigner: false, isWritable: false },
526
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
527
+ ...remainingAccounts,
528
+ ],
529
+ programId,
530
+ data,
531
+ });
532
+ }
533
+ // ---------------------------------------------------------------------------
534
+ // Remaining Accounts Helpers
535
+ // ---------------------------------------------------------------------------
536
+ function buildLendRemainingAccounts(lend) {
537
+ return [
538
+ { pubkey: lend.lendProgram, isSigner: false, isWritable: false },
539
+ { pubkey: lend.lendStrategyState, isSigner: false, isWritable: true },
540
+ { pubkey: lend.lendStvPosition, isSigner: false, isWritable: true },
541
+ { pubkey: lend.lendBaseAta, isSigner: false, isWritable: true },
542
+ ];
543
+ }
544
+ /**
545
+ * Assemble the migrate_execute remaining_accounts in the exact order
546
+ * parse_lend_accounts expects (migrate_execute.rs:298-338):
547
+ *
548
+ * [ source-lend section ] src.lend(4 fixed) + src.protocolAum(P_src)
549
+ * [ source auto-unroute ] src.autoUnroute (U accounts)
550
+ * [ dest-lend section ] dst.lend(4 fixed) + dst.protocolAum(P_dst)
551
+ * [ dest strategy + route] dst.strategy(0 or 2) + dst.autoRoute (R accounts)
552
+ *
553
+ * Pass `undefined` for a `lend` side whose STV has no lend_program (the 4
554
+ * fixed accounts + protocol AUM are omitted, matching the early return in
555
+ * parse_lend_accounts when lend_program_key == default).
556
+ *
557
+ * The 4 fixed lend accounts mirror `buildLendRemainingAccounts`:
558
+ * [lendProgram(ro), lendStrategyState(w), lendStvPosition(w), lendBaseAta(w)]
559
+ * `protocolAum` / `autoUnroute` / `autoRoute` / `strategy` accounts are passed
560
+ * through verbatim; the caller sets their writable flags per protocol.
561
+ */
562
+ function buildMigrateRemainingAccounts(opts) {
563
+ const out = [];
564
+ // ---- source-lend section ----
565
+ if (opts.source.lend) {
566
+ out.push(...buildLendRemainingAccounts(opts.source.lend));
567
+ if (opts.source.protocolAum)
568
+ out.push(...opts.source.protocolAum);
569
+ }
570
+ // ---- source auto-unroute ----
571
+ if (opts.source.autoUnroute)
572
+ out.push(...opts.source.autoUnroute);
573
+ // ---- dest-lend section ----
574
+ if (opts.dest.lend) {
575
+ out.push(...buildLendRemainingAccounts(opts.dest.lend));
576
+ if (opts.dest.protocolAum)
577
+ out.push(...opts.dest.protocolAum);
578
+ }
579
+ // ---- dest strategy pair (writable state, read-only position) ----
580
+ if (opts.dest.strategy) {
581
+ out.push({ pubkey: opts.dest.strategy.strategyState, isSigner: false, isWritable: true }, { pubkey: opts.dest.strategy.stvPosition, isSigner: false, isWritable: false });
582
+ }
583
+ // ---- dest auto-route ----
584
+ if (opts.dest.autoRoute)
585
+ out.push(...opts.dest.autoRoute);
586
+ return out;
587
+ }
588
+ function buildStrategyRemainingAccounts(strategies) {
589
+ const accounts = [];
590
+ for (const s of strategies) {
591
+ accounts.push({ pubkey: s.strategyState, isSigner: false, isWritable: true }, { pubkey: s.stvPosition, isSigner: false, isWritable: false });
592
+ }
593
+ return accounts;
594
+ }
595
+ function createInstantWithdrawIx(args, programId = constants_1.PROGRAM_ID) {
596
+ const { user, config, stv, vaultAta, userBaseAta, feeReceiverBaseAta, feeReceiverEvAta, baseMint, evMint, userEvAta, tokenProgram, shares, minBaseOut, protocolAumCount = 0, autoUnrouteCount = 0, remainingAccounts = [], } = args;
597
+ // Data: shares(8) + min_base_out(8) + protocol_aum_count(1) + auto_unroute_count(1) = 18.
598
+ const data = [constants_1.IX_INSTANT_WITHDRAW];
599
+ (0, buffer_1.writeU64)(data, shares);
600
+ (0, buffer_1.writeU64)(data, minBaseOut);
601
+ data.push(protocolAumCount & 0xff);
602
+ data.push(autoUnrouteCount & 0xff);
603
+ return new web3_js_1.TransactionInstruction({
604
+ keys: [
605
+ { pubkey: user, isSigner: true, isWritable: true },
606
+ { pubkey: config, isSigner: false, isWritable: false },
607
+ { pubkey: stv, isSigner: false, isWritable: true },
608
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
609
+ { pubkey: userBaseAta, isSigner: false, isWritable: true },
610
+ { pubkey: feeReceiverBaseAta, isSigner: false, isWritable: true },
611
+ { pubkey: feeReceiverEvAta, isSigner: false, isWritable: true },
612
+ { pubkey: baseMint, isSigner: false, isWritable: false },
613
+ { pubkey: evMint, isSigner: false, isWritable: true },
614
+ { pubkey: userEvAta, isSigner: false, isWritable: true },
615
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
616
+ ...remainingAccounts,
617
+ ],
618
+ programId,
619
+ data: Buffer.from(data),
620
+ });
621
+ }
622
+ function createSeedStvIx(args, programId = constants_1.PROGRAM_ID) {
623
+ 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;
624
+ // Data: amount(8).
625
+ const data = [constants_1.IX_SEED_STV];
626
+ (0, buffer_1.writeU64)(data, amount);
627
+ return new web3_js_1.TransactionInstruction({
628
+ keys: [
629
+ { pubkey: admin, isSigner: true, isWritable: true },
630
+ { pubkey: config, isSigner: false, isWritable: false },
631
+ { pubkey: stv, isSigner: false, isWritable: true },
632
+ { pubkey: evMint, isSigner: false, isWritable: true },
633
+ { pubkey: escrowEvAta, isSigner: false, isWritable: true },
634
+ { pubkey: vaultAta, isSigner: false, isWritable: true },
635
+ { pubkey: adminBaseAta, isSigner: false, isWritable: true },
636
+ { pubkey: baseMint, isSigner: false, isWritable: false },
637
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
638
+ { pubkey: ataProgram, isSigner: false, isWritable: false },
639
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
640
+ ],
641
+ programId,
642
+ data: Buffer.from(data),
643
+ });
644
+ }
645
+ function createAcceptVaultAdminIx(args, programId = constants_1.PROGRAM_ID) {
646
+ const { pendingAdmin, stv } = args;
647
+ return new web3_js_1.TransactionInstruction({
648
+ keys: [
649
+ { pubkey: pendingAdmin, isSigner: true, isWritable: false },
650
+ { pubkey: stv, isSigner: false, isWritable: true },
651
+ ],
652
+ programId,
653
+ data: Buffer.from([constants_1.IX_ACCEPT_VAULT_ADMIN]),
654
+ });
655
+ }
656
+ function createTripCircuitBreakerIx(args, programId = constants_1.PROGRAM_ID) {
657
+ const { authority, stv, managerRole } = args;
658
+ const keys = [
659
+ { pubkey: authority, isSigner: true, isWritable: false },
660
+ { pubkey: stv, isSigner: false, isWritable: true },
661
+ ];
662
+ if (managerRole !== undefined) {
663
+ keys.push({ pubkey: managerRole, isSigner: false, isWritable: false });
664
+ }
665
+ return new web3_js_1.TransactionInstruction({
666
+ keys,
667
+ programId,
668
+ data: Buffer.from([constants_1.IX_TRIP_CIRCUIT_BREAKER]),
669
+ });
670
+ }