@voltr/vault-sdk 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/adaptors.d.ts +9 -0
- package/dist/extensions/adaptors.d.ts.map +1 -0
- package/dist/extensions/adaptors.js +20 -0
- package/dist/extensions/adaptors.js.map +1 -0
- package/dist/extensions/events.d.ts +33 -0
- package/dist/extensions/events.d.ts.map +1 -0
- package/dist/extensions/events.js +208 -0
- package/dist/extensions/events.js.map +1 -0
- package/dist/extensions/index.d.ts +2 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +2 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/generated/accounts/protocol.d.ts +6 -6
- package/dist/generated/accounts/protocol.d.ts.map +1 -1
- package/dist/generated/accounts/protocol.js +2 -2
- package/dist/generated/accounts/protocol.js.map +1 -1
- package/dist/generated/accounts/vault.d.ts +6 -2
- package/dist/generated/accounts/vault.d.ts.map +1 -1
- package/dist/generated/accounts/vault.js +4 -2
- package/dist/generated/accounts/vault.js.map +1 -1
- package/dist/generated/errors/voltrVault.d.ts +5 -1
- package/dist/generated/errors/voltrVault.d.ts.map +1 -1
- package/dist/generated/errors/voltrVault.js +7 -1
- package/dist/generated/errors/voltrVault.js.map +1 -1
- package/dist/generated/instructions/harvestFee.d.ts +15 -15
- package/dist/generated/instructions/harvestFee.d.ts.map +1 -1
- package/dist/generated/instructions/harvestFee.js +21 -15
- package/dist/generated/instructions/harvestFee.js.map +1 -1
- package/dist/generated/instructions/index.d.ts +1 -0
- package/dist/generated/instructions/index.d.ts.map +1 -1
- package/dist/generated/instructions/index.js +1 -0
- package/dist/generated/instructions/index.js.map +1 -1
- package/dist/generated/instructions/initProtocol.d.ts +4 -0
- package/dist/generated/instructions/initProtocol.d.ts.map +1 -1
- package/dist/generated/instructions/initProtocol.js +2 -0
- package/dist/generated/instructions/initProtocol.js.map +1 -1
- package/dist/generated/instructions/updateVaultAdaptorPolicy.d.ts +56 -0
- package/dist/generated/instructions/updateVaultAdaptorPolicy.d.ts.map +1 -0
- package/dist/generated/instructions/updateVaultAdaptorPolicy.js +119 -0
- package/dist/generated/instructions/updateVaultAdaptorPolicy.js.map +1 -0
- package/dist/generated/programs/voltrVault.d.ts +9 -5
- package/dist/generated/programs/voltrVault.d.ts.map +1 -1
- package/dist/generated/programs/voltrVault.js +16 -4
- package/dist/generated/programs/voltrVault.js.map +1 -1
- package/dist/generated/types/index.d.ts +1 -0
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +1 -0
- package/dist/generated/types/index.js.map +1 -1
- package/dist/generated/types/initProtocolEvent.d.ts +2 -0
- package/dist/generated/types/initProtocolEvent.d.ts.map +1 -1
- package/dist/generated/types/initProtocolEvent.js +2 -0
- package/dist/generated/types/initProtocolEvent.js.map +1 -1
- package/dist/generated/types/protocolConfigField.d.ts +2 -1
- package/dist/generated/types/protocolConfigField.d.ts.map +1 -1
- package/dist/generated/types/protocolConfigField.js +1 -0
- package/dist/generated/types/protocolConfigField.js.map +1 -1
- package/dist/generated/types/updateVaultAdaptorPolicyEvent.d.ts +28 -0
- package/dist/generated/types/updateVaultAdaptorPolicyEvent.d.ts.map +1 -0
- package/dist/generated/types/updateVaultAdaptorPolicyEvent.js +37 -0
- package/dist/generated/types/updateVaultAdaptorPolicyEvent.js.map +1 -0
- package/package.json +1 -1
- package/src/extensions/adaptors.ts +35 -0
- package/src/extensions/events.ts +339 -0
- package/src/extensions/index.ts +2 -0
- package/src/generated/accounts/protocol.ts +8 -8
- package/src/generated/accounts/vault.ts +10 -4
- package/src/generated/errors/voltrVault.ts +8 -0
- package/src/generated/instructions/harvestFee.ts +56 -50
- package/src/generated/instructions/index.ts +1 -0
- package/src/generated/instructions/initProtocol.ts +11 -1
- package/src/generated/instructions/updateVaultAdaptorPolicy.ts +301 -0
- package/src/generated/programs/voltrVault.ts +35 -0
- package/src/generated/types/index.ts +1 -0
- package/src/generated/types/initProtocolEvent.ts +4 -0
- package/src/generated/types/protocolConfigField.ts +1 -0
- package/src/generated/types/updateVaultAdaptorPolicyEvent.ts +79 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { getBase64Encoder, type Decoder } from "@solana/kit";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAcceptProtocolAdminEventDecoder,
|
|
5
|
+
getAcceptVaultAdminEventDecoder,
|
|
6
|
+
getAddAdaptorEventDecoder,
|
|
7
|
+
getCalibrateHighWaterMarkEventDecoder,
|
|
8
|
+
getCalibrateHighWaterMarkUnsafeEventDecoder,
|
|
9
|
+
getCancelRequestWithdrawVaultEventDecoder,
|
|
10
|
+
getCloseStrategyEventDecoder,
|
|
11
|
+
getDepositStrategyEventDecoder,
|
|
12
|
+
getDepositVaultEventDecoder,
|
|
13
|
+
getDirectWithdrawStrategyEventDecoder,
|
|
14
|
+
getHarvestFeeEventDecoder,
|
|
15
|
+
getInitializeDirectWithdrawStrategyEventDecoder,
|
|
16
|
+
getInitializeStrategyEventDecoder,
|
|
17
|
+
getInitializeVaultEventDecoder,
|
|
18
|
+
getInitProtocolEventDecoder,
|
|
19
|
+
getInstantWithdrawStrategyEventDecoder,
|
|
20
|
+
getInstantWithdrawVaultEventDecoder,
|
|
21
|
+
getRemoveAdaptorEventDecoder,
|
|
22
|
+
getRequestWithdrawVaultEventDecoder,
|
|
23
|
+
getUpdateProtocolEventDecoder,
|
|
24
|
+
getUpdateVaultAdaptorPolicyEventDecoder,
|
|
25
|
+
getUpdateVaultConfigEventDecoder,
|
|
26
|
+
getUpdateVaultEventDecoder,
|
|
27
|
+
getUpdateVaultProtocolFeeEventDecoder,
|
|
28
|
+
getWithdrawStrategyEventDecoder,
|
|
29
|
+
getWithdrawVaultEventDecoder,
|
|
30
|
+
type AcceptProtocolAdminEvent,
|
|
31
|
+
type AcceptVaultAdminEvent,
|
|
32
|
+
type AddAdaptorEvent,
|
|
33
|
+
type CalibrateHighWaterMarkEvent,
|
|
34
|
+
type CalibrateHighWaterMarkUnsafeEvent,
|
|
35
|
+
type CancelRequestWithdrawVaultEvent,
|
|
36
|
+
type CloseStrategyEvent,
|
|
37
|
+
type DepositStrategyEvent,
|
|
38
|
+
type DepositVaultEvent,
|
|
39
|
+
type DirectWithdrawStrategyEvent,
|
|
40
|
+
type HarvestFeeEvent,
|
|
41
|
+
type InitializeDirectWithdrawStrategyEvent,
|
|
42
|
+
type InitializeStrategyEvent,
|
|
43
|
+
type InitializeVaultEvent,
|
|
44
|
+
type InitProtocolEvent,
|
|
45
|
+
type InstantWithdrawStrategyEvent,
|
|
46
|
+
type InstantWithdrawVaultEvent,
|
|
47
|
+
type RemoveAdaptorEvent,
|
|
48
|
+
type RequestWithdrawVaultEvent,
|
|
49
|
+
type UpdateProtocolEvent,
|
|
50
|
+
type UpdateVaultAdaptorPolicyEvent,
|
|
51
|
+
type UpdateVaultConfigEvent,
|
|
52
|
+
type UpdateVaultEvent,
|
|
53
|
+
type UpdateVaultProtocolFeeEvent,
|
|
54
|
+
type WithdrawStrategyEvent,
|
|
55
|
+
type WithdrawVaultEvent,
|
|
56
|
+
} from "../generated/types";
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Discriminated union of every Voltr Vault event Codama can decode. The first
|
|
60
|
+
* 8 bytes of each Anchor `emit!` payload identify the variant via
|
|
61
|
+
* `sha256("event:<EventName>")[..8]`; the remainder is the borsh-encoded
|
|
62
|
+
* payload for the named struct.
|
|
63
|
+
*/
|
|
64
|
+
export type ParsedVoltrEvent =
|
|
65
|
+
| ParsedEventOf<"AcceptProtocolAdminEvent", AcceptProtocolAdminEvent>
|
|
66
|
+
| ParsedEventOf<"AcceptVaultAdminEvent", AcceptVaultAdminEvent>
|
|
67
|
+
| ParsedEventOf<"AddAdaptorEvent", AddAdaptorEvent>
|
|
68
|
+
| ParsedEventOf<"CalibrateHighWaterMarkEvent", CalibrateHighWaterMarkEvent>
|
|
69
|
+
| ParsedEventOf<
|
|
70
|
+
"CalibrateHighWaterMarkUnsafeEvent",
|
|
71
|
+
CalibrateHighWaterMarkUnsafeEvent
|
|
72
|
+
>
|
|
73
|
+
| ParsedEventOf<
|
|
74
|
+
"CancelRequestWithdrawVaultEvent",
|
|
75
|
+
CancelRequestWithdrawVaultEvent
|
|
76
|
+
>
|
|
77
|
+
| ParsedEventOf<"CloseStrategyEvent", CloseStrategyEvent>
|
|
78
|
+
| ParsedEventOf<"DepositStrategyEvent", DepositStrategyEvent>
|
|
79
|
+
| ParsedEventOf<"DepositVaultEvent", DepositVaultEvent>
|
|
80
|
+
| ParsedEventOf<"DirectWithdrawStrategyEvent", DirectWithdrawStrategyEvent>
|
|
81
|
+
| ParsedEventOf<"HarvestFeeEvent", HarvestFeeEvent>
|
|
82
|
+
| ParsedEventOf<"InitProtocolEvent", InitProtocolEvent>
|
|
83
|
+
| ParsedEventOf<
|
|
84
|
+
"InitializeDirectWithdrawStrategyEvent",
|
|
85
|
+
InitializeDirectWithdrawStrategyEvent
|
|
86
|
+
>
|
|
87
|
+
| ParsedEventOf<"InitializeStrategyEvent", InitializeStrategyEvent>
|
|
88
|
+
| ParsedEventOf<"InitializeVaultEvent", InitializeVaultEvent>
|
|
89
|
+
| ParsedEventOf<"InstantWithdrawStrategyEvent", InstantWithdrawStrategyEvent>
|
|
90
|
+
| ParsedEventOf<"InstantWithdrawVaultEvent", InstantWithdrawVaultEvent>
|
|
91
|
+
| ParsedEventOf<"RemoveAdaptorEvent", RemoveAdaptorEvent>
|
|
92
|
+
| ParsedEventOf<"RequestWithdrawVaultEvent", RequestWithdrawVaultEvent>
|
|
93
|
+
| ParsedEventOf<"UpdateProtocolEvent", UpdateProtocolEvent>
|
|
94
|
+
| ParsedEventOf<
|
|
95
|
+
"UpdateVaultAdaptorPolicyEvent",
|
|
96
|
+
UpdateVaultAdaptorPolicyEvent
|
|
97
|
+
>
|
|
98
|
+
| ParsedEventOf<"UpdateVaultConfigEvent", UpdateVaultConfigEvent>
|
|
99
|
+
| ParsedEventOf<"UpdateVaultEvent", UpdateVaultEvent>
|
|
100
|
+
| ParsedEventOf<"UpdateVaultProtocolFeeEvent", UpdateVaultProtocolFeeEvent>
|
|
101
|
+
| ParsedEventOf<"WithdrawStrategyEvent", WithdrawStrategyEvent>
|
|
102
|
+
| ParsedEventOf<"WithdrawVaultEvent", WithdrawVaultEvent>;
|
|
103
|
+
|
|
104
|
+
type ParsedEventOf<Name extends string, Payload> = {
|
|
105
|
+
name: Name;
|
|
106
|
+
payload: Payload;
|
|
107
|
+
/** Top-level instruction index this event was emitted under. */
|
|
108
|
+
ixIndex: number;
|
|
109
|
+
/** Sequential index of this event within the transaction (0-based). */
|
|
110
|
+
eventIndex: number;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Minimal structural shape of a transaction `meta` object — narrow enough
|
|
115
|
+
* that callers can pass `meta` from any RPC client (web3.js legacy,
|
|
116
|
+
* @solana/kit, or a hand-rolled fixture) without conversion.
|
|
117
|
+
*/
|
|
118
|
+
export type TransactionMetaForEvents = {
|
|
119
|
+
logMessages?: readonly string[] | null;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type DispatchEntry = {
|
|
123
|
+
name: ParsedVoltrEvent["name"];
|
|
124
|
+
decoder: Decoder<unknown>;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Discriminators are sha256("event:<EventName>")[..8] — stable, fixed by the
|
|
128
|
+
// Anchor IDL. Hardcoded so this module has no runtime hashing dependency.
|
|
129
|
+
const EVENT_TABLE: ReadonlyArray<
|
|
130
|
+
readonly [ParsedVoltrEvent["name"], readonly number[], Decoder<unknown>]
|
|
131
|
+
> = [
|
|
132
|
+
[
|
|
133
|
+
"AcceptProtocolAdminEvent",
|
|
134
|
+
[0xc4, 0x5d, 0xad, 0xfd, 0xaf, 0x8c, 0x79, 0x20],
|
|
135
|
+
getAcceptProtocolAdminEventDecoder(),
|
|
136
|
+
],
|
|
137
|
+
[
|
|
138
|
+
"AcceptVaultAdminEvent",
|
|
139
|
+
[0x8c, 0xff, 0x1d, 0x44, 0x10, 0xc2, 0xfb, 0x23],
|
|
140
|
+
getAcceptVaultAdminEventDecoder(),
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
"AddAdaptorEvent",
|
|
144
|
+
[0x18, 0xb5, 0xc9, 0x94, 0xf0, 0xb7, 0xeb, 0x0c],
|
|
145
|
+
getAddAdaptorEventDecoder(),
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
"CalibrateHighWaterMarkEvent",
|
|
149
|
+
[0x8c, 0x4c, 0xc3, 0x90, 0xb4, 0xb2, 0x00, 0x9b],
|
|
150
|
+
getCalibrateHighWaterMarkEventDecoder(),
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"CalibrateHighWaterMarkUnsafeEvent",
|
|
154
|
+
[0xcd, 0x4c, 0xa9, 0xff, 0x25, 0xe4, 0x41, 0x82],
|
|
155
|
+
getCalibrateHighWaterMarkUnsafeEventDecoder(),
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
"CancelRequestWithdrawVaultEvent",
|
|
159
|
+
[0x2e, 0xa5, 0x18, 0x72, 0x01, 0x50, 0xcd, 0x88],
|
|
160
|
+
getCancelRequestWithdrawVaultEventDecoder(),
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
"CloseStrategyEvent",
|
|
164
|
+
[0xd5, 0x5f, 0xdb, 0xa1, 0x11, 0xd0, 0x5d, 0xff],
|
|
165
|
+
getCloseStrategyEventDecoder(),
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
"DepositStrategyEvent",
|
|
169
|
+
[0xca, 0xc9, 0x76, 0x31, 0x1d, 0xb4, 0x74, 0xaa],
|
|
170
|
+
getDepositStrategyEventDecoder(),
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
"DepositVaultEvent",
|
|
174
|
+
[0x0b, 0x0f, 0x07, 0x5c, 0x96, 0x64, 0xa5, 0xe8],
|
|
175
|
+
getDepositVaultEventDecoder(),
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
"DirectWithdrawStrategyEvent",
|
|
179
|
+
[0x71, 0xca, 0x97, 0x7c, 0x89, 0xff, 0x99, 0x65],
|
|
180
|
+
getDirectWithdrawStrategyEventDecoder(),
|
|
181
|
+
],
|
|
182
|
+
[
|
|
183
|
+
"HarvestFeeEvent",
|
|
184
|
+
[0x45, 0x30, 0xc0, 0x17, 0xe8, 0x16, 0x17, 0x1e],
|
|
185
|
+
getHarvestFeeEventDecoder(),
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
"InitProtocolEvent",
|
|
189
|
+
[0x0d, 0x51, 0xb7, 0x84, 0x58, 0x2b, 0xca, 0xd5],
|
|
190
|
+
getInitProtocolEventDecoder(),
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
"InitializeDirectWithdrawStrategyEvent",
|
|
194
|
+
[0xa9, 0x16, 0x39, 0x08, 0x0f, 0x49, 0xff, 0x73],
|
|
195
|
+
getInitializeDirectWithdrawStrategyEventDecoder(),
|
|
196
|
+
],
|
|
197
|
+
[
|
|
198
|
+
"InitializeStrategyEvent",
|
|
199
|
+
[0x1e, 0xe9, 0xd3, 0xf9, 0x53, 0xbc, 0xea, 0x98],
|
|
200
|
+
getInitializeStrategyEventDecoder(),
|
|
201
|
+
],
|
|
202
|
+
[
|
|
203
|
+
"InitializeVaultEvent",
|
|
204
|
+
[0xb3, 0x4b, 0x32, 0xa1, 0xbf, 0x1c, 0xf5, 0x6b],
|
|
205
|
+
getInitializeVaultEventDecoder(),
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
"InstantWithdrawStrategyEvent",
|
|
209
|
+
[0xdd, 0x17, 0x0c, 0xd7, 0x64, 0x2a, 0x61, 0x95],
|
|
210
|
+
getInstantWithdrawStrategyEventDecoder(),
|
|
211
|
+
],
|
|
212
|
+
[
|
|
213
|
+
"InstantWithdrawVaultEvent",
|
|
214
|
+
[0x2e, 0x39, 0x3c, 0x14, 0x06, 0xa0, 0xa4, 0xf7],
|
|
215
|
+
getInstantWithdrawVaultEventDecoder(),
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
"RemoveAdaptorEvent",
|
|
219
|
+
[0x9b, 0xb2, 0x02, 0x1d, 0xf5, 0x56, 0xf6, 0x99],
|
|
220
|
+
getRemoveAdaptorEventDecoder(),
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
"RequestWithdrawVaultEvent",
|
|
224
|
+
[0x3b, 0x5e, 0x1a, 0x26, 0x2f, 0x83, 0x9e, 0xa2],
|
|
225
|
+
getRequestWithdrawVaultEventDecoder(),
|
|
226
|
+
],
|
|
227
|
+
[
|
|
228
|
+
"UpdateProtocolEvent",
|
|
229
|
+
[0x0e, 0xe3, 0xcc, 0xd9, 0x3e, 0x2e, 0xf1, 0xed],
|
|
230
|
+
getUpdateProtocolEventDecoder(),
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
"UpdateVaultAdaptorPolicyEvent",
|
|
234
|
+
[0xd8, 0xbe, 0x81, 0xb6, 0xb5, 0x7b, 0xed, 0xbd],
|
|
235
|
+
getUpdateVaultAdaptorPolicyEventDecoder(),
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
"UpdateVaultConfigEvent",
|
|
239
|
+
[0x3d, 0x5c, 0xce, 0x97, 0xa2, 0x28, 0xed, 0x67],
|
|
240
|
+
getUpdateVaultConfigEventDecoder(),
|
|
241
|
+
],
|
|
242
|
+
[
|
|
243
|
+
"UpdateVaultEvent",
|
|
244
|
+
[0x7b, 0x1f, 0x1b, 0xbd, 0x66, 0x01, 0x79, 0x39],
|
|
245
|
+
getUpdateVaultEventDecoder(),
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
"UpdateVaultProtocolFeeEvent",
|
|
249
|
+
[0xac, 0x01, 0xad, 0xe6, 0xe4, 0x3d, 0x4d, 0xf4],
|
|
250
|
+
getUpdateVaultProtocolFeeEventDecoder(),
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
"WithdrawStrategyEvent",
|
|
254
|
+
[0x70, 0x2d, 0x10, 0xac, 0xaa, 0x21, 0x16, 0xd4],
|
|
255
|
+
getWithdrawStrategyEventDecoder(),
|
|
256
|
+
],
|
|
257
|
+
[
|
|
258
|
+
"WithdrawVaultEvent",
|
|
259
|
+
[0xc4, 0x7b, 0x4f, 0xd7, 0x04, 0xd6, 0x14, 0xc5],
|
|
260
|
+
getWithdrawVaultEventDecoder(),
|
|
261
|
+
],
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
const DISPATCH: ReadonlyMap<string, DispatchEntry> = new Map(
|
|
265
|
+
EVENT_TABLE.map(([name, disc, decoder]) => [
|
|
266
|
+
discriminatorKey(disc),
|
|
267
|
+
{ name, decoder },
|
|
268
|
+
])
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const PROGRAM_DATA_PREFIX = "Program data: ";
|
|
272
|
+
// Top-level instructions log "Program <id> invoke [1]" — depth >1 is a CPI.
|
|
273
|
+
const TOP_LEVEL_INVOKE_RE = /^Program \S+ invoke \[1\]$/;
|
|
274
|
+
|
|
275
|
+
const base64Encoder = getBase64Encoder();
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Walk a transaction's `meta.logMessages`, decode every Voltr event emitted
|
|
279
|
+
* via Anchor's `emit!`, and return them in emission order. Lines whose
|
|
280
|
+
* discriminator doesn't belong to a Voltr event are skipped, so logs from
|
|
281
|
+
* other programs in the same tx are safe to pass through.
|
|
282
|
+
*/
|
|
283
|
+
export function parseTransactionEvents(
|
|
284
|
+
meta: TransactionMetaForEvents | null | undefined
|
|
285
|
+
): ParsedVoltrEvent[] {
|
|
286
|
+
const logs = meta?.logMessages;
|
|
287
|
+
if (!logs || logs.length === 0) return [];
|
|
288
|
+
|
|
289
|
+
const out: ParsedVoltrEvent[] = [];
|
|
290
|
+
let ixIndex = -1;
|
|
291
|
+
let eventIndex = 0;
|
|
292
|
+
|
|
293
|
+
for (const line of logs) {
|
|
294
|
+
if (TOP_LEVEL_INVOKE_RE.test(line)) {
|
|
295
|
+
ixIndex++;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (!line.startsWith(PROGRAM_DATA_PREFIX)) continue;
|
|
299
|
+
|
|
300
|
+
const b64 = line.slice(PROGRAM_DATA_PREFIX.length);
|
|
301
|
+
let bytes: Uint8Array;
|
|
302
|
+
try {
|
|
303
|
+
bytes = base64Encoder.encode(b64) as Uint8Array;
|
|
304
|
+
} catch {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (bytes.length < 8) continue;
|
|
308
|
+
|
|
309
|
+
const entry = DISPATCH.get(discriminatorKey(bytes.subarray(0, 8)));
|
|
310
|
+
if (!entry) continue;
|
|
311
|
+
|
|
312
|
+
// The discriminator is 8 bytes of sha256, so spurious matches from other
|
|
313
|
+
// programs are unlikely but possible — and corrupt fixtures happen too.
|
|
314
|
+
// Skip the line rather than aborting the whole parse if borsh decode fails.
|
|
315
|
+
let payload: unknown;
|
|
316
|
+
try {
|
|
317
|
+
payload = entry.decoder.decode(bytes, 8);
|
|
318
|
+
} catch {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
out.push({
|
|
322
|
+
name: entry.name,
|
|
323
|
+
payload,
|
|
324
|
+
ixIndex: ixIndex < 0 ? 0 : ixIndex,
|
|
325
|
+
eventIndex: eventIndex++,
|
|
326
|
+
} as ParsedVoltrEvent);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function discriminatorKey(disc: ArrayLike<number>): string {
|
|
333
|
+
let s = "";
|
|
334
|
+
for (let i = 0; i < disc.length; i++) {
|
|
335
|
+
const b = disc[i] & 0xff;
|
|
336
|
+
s += (b < 16 ? "0" : "") + b.toString(16);
|
|
337
|
+
}
|
|
338
|
+
return s;
|
|
339
|
+
}
|
package/src/extensions/index.ts
CHANGED
|
@@ -53,7 +53,7 @@ export type Protocol = {
|
|
|
53
53
|
admin: Address;
|
|
54
54
|
/** The operational state of the protocol. */
|
|
55
55
|
operationalState: number;
|
|
56
|
-
/**
|
|
56
|
+
/** Padding after the operational-state flags. */
|
|
57
57
|
padding1: ReadonlyUint8Array;
|
|
58
58
|
/** The bump for the protocol. */
|
|
59
59
|
bump: number;
|
|
@@ -61,8 +61,8 @@ export type Protocol = {
|
|
|
61
61
|
padding0: ReadonlyUint8Array;
|
|
62
62
|
/** The pending admin for admin transfer. */
|
|
63
63
|
pendingAdmin: Address;
|
|
64
|
-
/**
|
|
65
|
-
|
|
64
|
+
/** The treasury that receives protocol fees. */
|
|
65
|
+
treasury: Address;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export type ProtocolArgs = {
|
|
@@ -70,7 +70,7 @@ export type ProtocolArgs = {
|
|
|
70
70
|
admin: Address;
|
|
71
71
|
/** The operational state of the protocol. */
|
|
72
72
|
operationalState: number;
|
|
73
|
-
/**
|
|
73
|
+
/** Padding after the operational-state flags. */
|
|
74
74
|
padding1: ReadonlyUint8Array;
|
|
75
75
|
/** The bump for the protocol. */
|
|
76
76
|
bump: number;
|
|
@@ -78,8 +78,8 @@ export type ProtocolArgs = {
|
|
|
78
78
|
padding0: ReadonlyUint8Array;
|
|
79
79
|
/** The pending admin for admin transfer. */
|
|
80
80
|
pendingAdmin: Address;
|
|
81
|
-
/**
|
|
82
|
-
|
|
81
|
+
/** The treasury that receives protocol fees. */
|
|
82
|
+
treasury: Address;
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/** Gets the encoder for {@link ProtocolArgs} account data. */
|
|
@@ -93,7 +93,7 @@ export function getProtocolEncoder(): FixedSizeEncoder<ProtocolArgs> {
|
|
|
93
93
|
["bump", getU8Encoder()],
|
|
94
94
|
["padding0", fixEncoderSize(getBytesEncoder(), 1)],
|
|
95
95
|
["pendingAdmin", getAddressEncoder()],
|
|
96
|
-
["
|
|
96
|
+
["treasury", getAddressEncoder()],
|
|
97
97
|
]),
|
|
98
98
|
(value) => ({ ...value, discriminator: PROTOCOL_DISCRIMINATOR }),
|
|
99
99
|
);
|
|
@@ -109,7 +109,7 @@ export function getProtocolDecoder(): FixedSizeDecoder<Protocol> {
|
|
|
109
109
|
["bump", getU8Decoder()],
|
|
110
110
|
["padding0", fixDecoderSize(getBytesDecoder(), 1)],
|
|
111
111
|
["pendingAdmin", getAddressDecoder()],
|
|
112
|
-
["
|
|
112
|
+
["treasury", getAddressDecoder()],
|
|
113
113
|
]);
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -112,7 +112,9 @@ export type Vault = {
|
|
|
112
112
|
lastUpdatedTs: bigint;
|
|
113
113
|
/** The version of the vault. */
|
|
114
114
|
version: number;
|
|
115
|
-
/**
|
|
115
|
+
/** Protocol-admin-controlled adaptor allowlist bypass. */
|
|
116
|
+
allowAnyAdaptor: number;
|
|
117
|
+
/** Padding to keep `locked_profit_state` at its existing 8-byte-aligned offset. */
|
|
116
118
|
padding0: ReadonlyUint8Array;
|
|
117
119
|
/** The locked profit state of the vault. */
|
|
118
120
|
lockedProfitState: LockedProfitState;
|
|
@@ -150,7 +152,9 @@ export type VaultArgs = {
|
|
|
150
152
|
lastUpdatedTs: number | bigint;
|
|
151
153
|
/** The version of the vault. */
|
|
152
154
|
version: number;
|
|
153
|
-
/**
|
|
155
|
+
/** Protocol-admin-controlled adaptor allowlist bypass. */
|
|
156
|
+
allowAnyAdaptor: number;
|
|
157
|
+
/** Padding to keep `locked_profit_state` at its existing 8-byte-aligned offset. */
|
|
154
158
|
padding0: ReadonlyUint8Array;
|
|
155
159
|
/** The locked profit state of the vault. */
|
|
156
160
|
lockedProfitState: LockedProfitStateArgs;
|
|
@@ -178,7 +182,8 @@ export function getVaultEncoder(): FixedSizeEncoder<VaultArgs> {
|
|
|
178
182
|
["highWaterMark", getHighWaterMarkEncoder()],
|
|
179
183
|
["lastUpdatedTs", getU64Encoder()],
|
|
180
184
|
["version", getU8Encoder()],
|
|
181
|
-
["
|
|
185
|
+
["allowAnyAdaptor", getU8Encoder()],
|
|
186
|
+
["padding0", fixEncoderSize(getBytesEncoder(), 6)],
|
|
182
187
|
["lockedProfitState", getLockedProfitStateEncoder()],
|
|
183
188
|
["reserved", fixEncoderSize(getBytesEncoder(), 240)],
|
|
184
189
|
]),
|
|
@@ -205,7 +210,8 @@ export function getVaultDecoder(): FixedSizeDecoder<Vault> {
|
|
|
205
210
|
["highWaterMark", getHighWaterMarkDecoder()],
|
|
206
211
|
["lastUpdatedTs", getU64Decoder()],
|
|
207
212
|
["version", getU8Decoder()],
|
|
208
|
-
["
|
|
213
|
+
["allowAnyAdaptor", getU8Decoder()],
|
|
214
|
+
["padding0", fixDecoderSize(getBytesDecoder(), 6)],
|
|
209
215
|
["lockedProfitState", getLockedProfitStateDecoder()],
|
|
210
216
|
["reserved", fixDecoderSize(getBytesDecoder(), 240)],
|
|
211
217
|
]);
|
|
@@ -46,13 +46,19 @@ export const VOLTR_VAULT_ERROR__INVALID_INPUT = 0x177d; // 6013
|
|
|
46
46
|
export const VOLTR_VAULT_ERROR__DIVISION_BY_ZERO = 0x177e; // 6014
|
|
47
47
|
/** InstantWithdrawNotAllowed: Instant withdraw not allowed. */
|
|
48
48
|
export const VOLTR_VAULT_ERROR__INSTANT_WITHDRAW_NOT_ALLOWED = 0x177f; // 6015
|
|
49
|
+
/** AdaptorProgramNotWhitelisted: Adaptor program not whitelisted. */
|
|
50
|
+
export const VOLTR_VAULT_ERROR__ADAPTOR_PROGRAM_NOT_WHITELISTED = 0x1780; // 6016
|
|
51
|
+
/** InvalidAdaptorPolicy: Invalid adaptor policy. */
|
|
52
|
+
export const VOLTR_VAULT_ERROR__INVALID_ADAPTOR_POLICY = 0x1781; // 6017
|
|
49
53
|
|
|
50
54
|
export type VoltrVaultError =
|
|
51
55
|
| typeof VOLTR_VAULT_ERROR__ADAPTOR_EPOCH_INVALID
|
|
56
|
+
| typeof VOLTR_VAULT_ERROR__ADAPTOR_PROGRAM_NOT_WHITELISTED
|
|
52
57
|
| typeof VOLTR_VAULT_ERROR__DIVISION_BY_ZERO
|
|
53
58
|
| typeof VOLTR_VAULT_ERROR__FEE_EXCEEDS_TOTAL_ASSET_VALUE
|
|
54
59
|
| typeof VOLTR_VAULT_ERROR__INSTANT_WITHDRAW_NOT_ALLOWED
|
|
55
60
|
| typeof VOLTR_VAULT_ERROR__INVALID_ACCOUNT_INPUT
|
|
61
|
+
| typeof VOLTR_VAULT_ERROR__INVALID_ADAPTOR_POLICY
|
|
56
62
|
| typeof VOLTR_VAULT_ERROR__INVALID_AMOUNT
|
|
57
63
|
| typeof VOLTR_VAULT_ERROR__INVALID_FEE_CONFIGURATION
|
|
58
64
|
| typeof VOLTR_VAULT_ERROR__INVALID_INPUT
|
|
@@ -69,10 +75,12 @@ let voltrVaultErrorMessages: Record<VoltrVaultError, string> | undefined;
|
|
|
69
75
|
if (process.env.NODE_ENV !== "production") {
|
|
70
76
|
voltrVaultErrorMessages = {
|
|
71
77
|
[VOLTR_VAULT_ERROR__ADAPTOR_EPOCH_INVALID]: `Adaptor epoch invalid.`,
|
|
78
|
+
[VOLTR_VAULT_ERROR__ADAPTOR_PROGRAM_NOT_WHITELISTED]: `Adaptor program not whitelisted.`,
|
|
72
79
|
[VOLTR_VAULT_ERROR__DIVISION_BY_ZERO]: `Division by zero.`,
|
|
73
80
|
[VOLTR_VAULT_ERROR__FEE_EXCEEDS_TOTAL_ASSET_VALUE]: `Fee exceeds total asset value.`,
|
|
74
81
|
[VOLTR_VAULT_ERROR__INSTANT_WITHDRAW_NOT_ALLOWED]: `Instant withdraw not allowed.`,
|
|
75
82
|
[VOLTR_VAULT_ERROR__INVALID_ACCOUNT_INPUT]: `Invalid account input.`,
|
|
83
|
+
[VOLTR_VAULT_ERROR__INVALID_ADAPTOR_POLICY]: `Invalid adaptor policy.`,
|
|
76
84
|
[VOLTR_VAULT_ERROR__INVALID_AMOUNT]: `Invalid amount provided.`,
|
|
77
85
|
[VOLTR_VAULT_ERROR__INVALID_FEE_CONFIGURATION]: `Fee configuration invalid.`,
|
|
78
86
|
[VOLTR_VAULT_ERROR__INVALID_INPUT]: `Invalid input.`,
|