@acta-markets/ts-sdk 0.0.1-beta → 0.0.2-beta
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/chain/fetch.js +24 -26
- package/dist/chain/fetch.test.js +30 -1
- package/dist/cjs/chain/fetch.js +24 -26
- package/dist/cjs/chain/fetch.test.js +29 -0
- package/dist/ws/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/chain/fetch.js
CHANGED
|
@@ -86,6 +86,13 @@ async function fetchAndDecode(rpc, config, decode) {
|
|
|
86
86
|
function dataSize(bytes) {
|
|
87
87
|
return { dataSize: BigInt(bytes) };
|
|
88
88
|
}
|
|
89
|
+
function marketAccountFilters(...extra) {
|
|
90
|
+
return [
|
|
91
|
+
dataSize(MARKET_ACCOUNT_SIZE_BYTES),
|
|
92
|
+
memcmp(0, new Uint8Array([MARKET_ACCOUNT_DISCRIMINATOR])),
|
|
93
|
+
...extra,
|
|
94
|
+
];
|
|
95
|
+
}
|
|
89
96
|
// --- Positions ---
|
|
90
97
|
export async function fetchPositionsByMaker(rpc, makerOwner, options) {
|
|
91
98
|
return rpc
|
|
@@ -236,10 +243,7 @@ export async function fetchAllMarketsDecoded(rpc, options) {
|
|
|
236
243
|
return fetchAndDecode(rpc, {
|
|
237
244
|
commitment: options?.commitment,
|
|
238
245
|
dataSlice: options?.dataSlice,
|
|
239
|
-
filters:
|
|
240
|
-
dataSize(MARKET_ACCOUNT_SIZE_BYTES),
|
|
241
|
-
memcmp(0, new Uint8Array([MARKET_ACCOUNT_DISCRIMINATOR])),
|
|
242
|
-
],
|
|
246
|
+
filters: marketAccountFilters(),
|
|
243
247
|
}, decodeMarketAccount);
|
|
244
248
|
}
|
|
245
249
|
export async function fetchAllOraclesDecoded(rpc, options) {
|
|
@@ -268,7 +272,7 @@ export async function fetchMarketsByUnderlying(rpc, underlying, options) {
|
|
|
268
272
|
.getProgramAccounts(getActaProgramId(), {
|
|
269
273
|
commitment: options?.commitment,
|
|
270
274
|
dataSlice: options?.dataSlice,
|
|
271
|
-
filters:
|
|
275
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))),
|
|
272
276
|
})
|
|
273
277
|
.send();
|
|
274
278
|
}
|
|
@@ -276,7 +280,7 @@ export async function fetchMarketsByUnderlyingDecoded(rpc, underlying, options)
|
|
|
276
280
|
return fetchAndDecode(rpc, {
|
|
277
281
|
commitment: options?.commitment,
|
|
278
282
|
dataSlice: options?.dataSlice,
|
|
279
|
-
filters:
|
|
283
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))),
|
|
280
284
|
}, decodeMarketAccount);
|
|
281
285
|
}
|
|
282
286
|
export async function fetchMarketsByQuote(rpc, quote, options) {
|
|
@@ -284,7 +288,7 @@ export async function fetchMarketsByQuote(rpc, quote, options) {
|
|
|
284
288
|
.getProgramAccounts(getActaProgramId(), {
|
|
285
289
|
commitment: options?.commitment,
|
|
286
290
|
dataSlice: options?.dataSlice,
|
|
287
|
-
filters:
|
|
291
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))),
|
|
288
292
|
})
|
|
289
293
|
.send();
|
|
290
294
|
}
|
|
@@ -292,7 +296,7 @@ export async function fetchMarketsByQuoteDecoded(rpc, quote, options) {
|
|
|
292
296
|
return fetchAndDecode(rpc, {
|
|
293
297
|
commitment: options?.commitment,
|
|
294
298
|
dataSlice: options?.dataSlice,
|
|
295
|
-
filters:
|
|
299
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))),
|
|
296
300
|
}, decodeMarketAccount);
|
|
297
301
|
}
|
|
298
302
|
export async function fetchMarketsByExpiry(rpc, expiryTs, options) {
|
|
@@ -300,7 +304,7 @@ export async function fetchMarketsByExpiry(rpc, expiryTs, options) {
|
|
|
300
304
|
.getProgramAccounts(getActaProgramId(), {
|
|
301
305
|
commitment: options?.commitment,
|
|
302
306
|
dataSlice: options?.dataSlice,
|
|
303
|
-
filters:
|
|
307
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
304
308
|
})
|
|
305
309
|
.send();
|
|
306
310
|
}
|
|
@@ -308,7 +312,7 @@ export async function fetchMarketsByExpiryDecoded(rpc, expiryTs, options) {
|
|
|
308
312
|
return fetchAndDecode(rpc, {
|
|
309
313
|
commitment: options?.commitment,
|
|
310
314
|
dataSlice: options?.dataSlice,
|
|
311
|
-
filters:
|
|
315
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
312
316
|
}, decodeMarketAccount);
|
|
313
317
|
}
|
|
314
318
|
export async function fetchMarketsByQuoteAndExpiry(rpc, quote, expiryTs, options) {
|
|
@@ -316,10 +320,7 @@ export async function fetchMarketsByQuoteAndExpiry(rpc, quote, expiryTs, options
|
|
|
316
320
|
.getProgramAccounts(getActaProgramId(), {
|
|
317
321
|
commitment: options?.commitment,
|
|
318
322
|
dataSlice: options?.dataSlice,
|
|
319
|
-
filters:
|
|
320
|
-
memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
321
|
-
memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
322
|
-
],
|
|
323
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)), memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
323
324
|
})
|
|
324
325
|
.send();
|
|
325
326
|
}
|
|
@@ -327,10 +328,7 @@ export async function fetchMarketsByQuoteAndExpiryDecoded(rpc, quote, expiryTs,
|
|
|
327
328
|
return fetchAndDecode(rpc, {
|
|
328
329
|
commitment: options?.commitment,
|
|
329
330
|
dataSlice: options?.dataSlice,
|
|
330
|
-
filters:
|
|
331
|
-
memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
332
|
-
memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
333
|
-
],
|
|
331
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)), memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
334
332
|
}, decodeMarketAccount);
|
|
335
333
|
}
|
|
336
334
|
export async function fetchMarketsByUnderlyingAndExpiry(rpc, underlying, expiryTs, options) {
|
|
@@ -338,10 +336,7 @@ export async function fetchMarketsByUnderlyingAndExpiry(rpc, underlying, expiryT
|
|
|
338
336
|
.getProgramAccounts(getActaProgramId(), {
|
|
339
337
|
commitment: options?.commitment,
|
|
340
338
|
dataSlice: options?.dataSlice,
|
|
341
|
-
filters:
|
|
342
|
-
memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
343
|
-
memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
344
|
-
],
|
|
339
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)), memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
345
340
|
})
|
|
346
341
|
.send();
|
|
347
342
|
}
|
|
@@ -368,10 +363,7 @@ export async function fetchMarketsByUnderlyingAndExpiryDecoded(rpc, underlying,
|
|
|
368
363
|
return fetchAndDecode(rpc, {
|
|
369
364
|
commitment: options?.commitment,
|
|
370
365
|
dataSlice: options?.dataSlice,
|
|
371
|
-
filters:
|
|
372
|
-
memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
373
|
-
memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
374
|
-
],
|
|
366
|
+
filters: marketAccountFilters(memcmp(MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)), memcmp(MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
375
367
|
}, decodeMarketAccount);
|
|
376
368
|
}
|
|
377
369
|
// --- Decode helpers ---
|
|
@@ -379,6 +371,12 @@ export function decodePositionAccount(data) {
|
|
|
379
371
|
return getPositionDecoder().decode(data);
|
|
380
372
|
}
|
|
381
373
|
export function decodeMarketAccount(data) {
|
|
374
|
+
if (data.length < MARKET_ACCOUNT_SIZE_BYTES) {
|
|
375
|
+
throw new Error(`Invalid Market account size: expected >= ${MARKET_ACCOUNT_SIZE_BYTES}, got ${data.length}`);
|
|
376
|
+
}
|
|
377
|
+
if (data[0] !== MARKET_ACCOUNT_DISCRIMINATOR) {
|
|
378
|
+
throw new Error(`Invalid Market account discriminator: expected ${MARKET_ACCOUNT_DISCRIMINATOR}, got ${data[0]}`);
|
|
379
|
+
}
|
|
382
380
|
return getMarketDecoder().decode(data);
|
|
383
381
|
}
|
|
384
382
|
export function decodeConfigAccount(data) {
|
package/dist/chain/fetch.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAKER_OFFSET_MAKER_OWNER, MAKER_OFFSET_QUOTE_SIGNING, MARKET_OFFSET_EXPIRY_TS, MARKET_OFFSET_FLAGS, MARKET_OFFSET_SETTLEMENT_PRICE, MARKET_OFFSET_UNDERLYING_DECIMALS, MARKET_OFFSET_QUOTE_DECIMALS, MARKET_OFFSET_QUOTE_MINT, MARKET_OFFSET_QUOTE_ORACLE_ADDRESS, MARKET_OFFSET_UNDERLYING_MINT, MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS, POSITION_OFFSET_MAKER_OWNER, POSITION_OFFSET_MARKET, POSITION_OFFSET_STATUS, POSITION_OFFSET_TAKER_OWNER, } from "./fetch";
|
|
1
|
+
import { decodeMarketAccount, MAKER_OFFSET_MAKER_OWNER, MAKER_OFFSET_QUOTE_SIGNING, MARKET_OFFSET_EXPIRY_TS, MARKET_OFFSET_FLAGS, MARKET_OFFSET_SETTLEMENT_PRICE, MARKET_OFFSET_UNDERLYING_DECIMALS, MARKET_OFFSET_QUOTE_DECIMALS, MARKET_OFFSET_QUOTE_MINT, MARKET_OFFSET_QUOTE_ORACLE_ADDRESS, MARKET_OFFSET_UNDERLYING_MINT, MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS, POSITION_OFFSET_MAKER_OWNER, POSITION_OFFSET_MARKET, POSITION_OFFSET_STATUS, POSITION_OFFSET_TAKER_OWNER, } from "./fetch";
|
|
2
2
|
import { getAddressDecoder } from "@solana/addresses";
|
|
3
3
|
import { encodeOrderPreimage } from "./orders";
|
|
4
4
|
import { getMakerEncoder, getMakerSize } from "../generated/accounts/maker";
|
|
@@ -155,4 +155,33 @@ describe("fetch offsets and order encode", () => {
|
|
|
155
155
|
expect(preimage.slice(base + 66, base + 98)).toEqual(makerBytes);
|
|
156
156
|
expect(preimage.slice(base + 98, base + 130)).toEqual(takerBytes);
|
|
157
157
|
});
|
|
158
|
+
it("decodeMarketAccount rejects non-market discriminator and short data", () => {
|
|
159
|
+
const decoder = getAddressDecoder();
|
|
160
|
+
const marketBytes = new Uint8Array(Array(32).fill(1));
|
|
161
|
+
const makerBytes = new Uint8Array(Array(32).fill(7));
|
|
162
|
+
const takerBytes = new Uint8Array(Array(32).fill(8));
|
|
163
|
+
const market = decoder.decode(marketBytes);
|
|
164
|
+
const makerOwner = decoder.decode(makerBytes);
|
|
165
|
+
const takerOwner = decoder.decode(takerBytes);
|
|
166
|
+
const positionData = getPositionEncoder().encode({
|
|
167
|
+
discriminator: 1,
|
|
168
|
+
version: 1,
|
|
169
|
+
bump: 7,
|
|
170
|
+
positionType: 0,
|
|
171
|
+
status: 1,
|
|
172
|
+
flags: 0,
|
|
173
|
+
flags2: 0,
|
|
174
|
+
flags3: 0,
|
|
175
|
+
takerOwner,
|
|
176
|
+
makerOwner,
|
|
177
|
+
market,
|
|
178
|
+
strike: 1n,
|
|
179
|
+
quantity: 1n,
|
|
180
|
+
totalPremium: 1n,
|
|
181
|
+
orderId: new Uint8Array(32).fill(0x11),
|
|
182
|
+
reserved: Array(32).fill(0n),
|
|
183
|
+
});
|
|
184
|
+
expect(() => decodeMarketAccount(Buffer.from(positionData))).toThrow("Invalid Market account discriminator");
|
|
185
|
+
expect(() => decodeMarketAccount(Buffer.alloc(8))).toThrow("Invalid Market account size");
|
|
186
|
+
});
|
|
158
187
|
});
|
package/dist/cjs/chain/fetch.js
CHANGED
|
@@ -125,6 +125,13 @@ async function fetchAndDecode(rpc, config, decode) {
|
|
|
125
125
|
function dataSize(bytes) {
|
|
126
126
|
return { dataSize: BigInt(bytes) };
|
|
127
127
|
}
|
|
128
|
+
function marketAccountFilters(...extra) {
|
|
129
|
+
return [
|
|
130
|
+
dataSize(exports.MARKET_ACCOUNT_SIZE_BYTES),
|
|
131
|
+
memcmp(0, new Uint8Array([exports.MARKET_ACCOUNT_DISCRIMINATOR])),
|
|
132
|
+
...extra,
|
|
133
|
+
];
|
|
134
|
+
}
|
|
128
135
|
// --- Positions ---
|
|
129
136
|
async function fetchPositionsByMaker(rpc, makerOwner, options) {
|
|
130
137
|
return rpc
|
|
@@ -275,10 +282,7 @@ async function fetchAllMarketsDecoded(rpc, options) {
|
|
|
275
282
|
return fetchAndDecode(rpc, {
|
|
276
283
|
commitment: options?.commitment,
|
|
277
284
|
dataSlice: options?.dataSlice,
|
|
278
|
-
filters:
|
|
279
|
-
dataSize(exports.MARKET_ACCOUNT_SIZE_BYTES),
|
|
280
|
-
memcmp(0, new Uint8Array([exports.MARKET_ACCOUNT_DISCRIMINATOR])),
|
|
281
|
-
],
|
|
285
|
+
filters: marketAccountFilters(),
|
|
282
286
|
}, decodeMarketAccount);
|
|
283
287
|
}
|
|
284
288
|
async function fetchAllOraclesDecoded(rpc, options) {
|
|
@@ -307,7 +311,7 @@ async function fetchMarketsByUnderlying(rpc, underlying, options) {
|
|
|
307
311
|
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
308
312
|
commitment: options?.commitment,
|
|
309
313
|
dataSlice: options?.dataSlice,
|
|
310
|
-
filters:
|
|
314
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))),
|
|
311
315
|
})
|
|
312
316
|
.send();
|
|
313
317
|
}
|
|
@@ -315,7 +319,7 @@ async function fetchMarketsByUnderlyingDecoded(rpc, underlying, options) {
|
|
|
315
319
|
return fetchAndDecode(rpc, {
|
|
316
320
|
commitment: options?.commitment,
|
|
317
321
|
dataSlice: options?.dataSlice,
|
|
318
|
-
filters:
|
|
322
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))),
|
|
319
323
|
}, decodeMarketAccount);
|
|
320
324
|
}
|
|
321
325
|
async function fetchMarketsByQuote(rpc, quote, options) {
|
|
@@ -323,7 +327,7 @@ async function fetchMarketsByQuote(rpc, quote, options) {
|
|
|
323
327
|
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
324
328
|
commitment: options?.commitment,
|
|
325
329
|
dataSlice: options?.dataSlice,
|
|
326
|
-
filters:
|
|
330
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))),
|
|
327
331
|
})
|
|
328
332
|
.send();
|
|
329
333
|
}
|
|
@@ -331,7 +335,7 @@ async function fetchMarketsByQuoteDecoded(rpc, quote, options) {
|
|
|
331
335
|
return fetchAndDecode(rpc, {
|
|
332
336
|
commitment: options?.commitment,
|
|
333
337
|
dataSlice: options?.dataSlice,
|
|
334
|
-
filters:
|
|
338
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))),
|
|
335
339
|
}, decodeMarketAccount);
|
|
336
340
|
}
|
|
337
341
|
async function fetchMarketsByExpiry(rpc, expiryTs, options) {
|
|
@@ -339,7 +343,7 @@ async function fetchMarketsByExpiry(rpc, expiryTs, options) {
|
|
|
339
343
|
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
340
344
|
commitment: options?.commitment,
|
|
341
345
|
dataSlice: options?.dataSlice,
|
|
342
|
-
filters:
|
|
346
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
343
347
|
})
|
|
344
348
|
.send();
|
|
345
349
|
}
|
|
@@ -347,7 +351,7 @@ async function fetchMarketsByExpiryDecoded(rpc, expiryTs, options) {
|
|
|
347
351
|
return fetchAndDecode(rpc, {
|
|
348
352
|
commitment: options?.commitment,
|
|
349
353
|
dataSlice: options?.dataSlice,
|
|
350
|
-
filters:
|
|
354
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
351
355
|
}, decodeMarketAccount);
|
|
352
356
|
}
|
|
353
357
|
async function fetchMarketsByQuoteAndExpiry(rpc, quote, expiryTs, options) {
|
|
@@ -355,10 +359,7 @@ async function fetchMarketsByQuoteAndExpiry(rpc, quote, expiryTs, options) {
|
|
|
355
359
|
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
356
360
|
commitment: options?.commitment,
|
|
357
361
|
dataSlice: options?.dataSlice,
|
|
358
|
-
filters:
|
|
359
|
-
memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
360
|
-
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
361
|
-
],
|
|
362
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)), memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
362
363
|
})
|
|
363
364
|
.send();
|
|
364
365
|
}
|
|
@@ -366,10 +367,7 @@ async function fetchMarketsByQuoteAndExpiryDecoded(rpc, quote, expiryTs, options
|
|
|
366
367
|
return fetchAndDecode(rpc, {
|
|
367
368
|
commitment: options?.commitment,
|
|
368
369
|
dataSlice: options?.dataSlice,
|
|
369
|
-
filters:
|
|
370
|
-
memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
371
|
-
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
372
|
-
],
|
|
370
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)), memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
373
371
|
}, decodeMarketAccount);
|
|
374
372
|
}
|
|
375
373
|
async function fetchMarketsByUnderlyingAndExpiry(rpc, underlying, expiryTs, options) {
|
|
@@ -377,10 +375,7 @@ async function fetchMarketsByUnderlyingAndExpiry(rpc, underlying, expiryTs, opti
|
|
|
377
375
|
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
378
376
|
commitment: options?.commitment,
|
|
379
377
|
dataSlice: options?.dataSlice,
|
|
380
|
-
filters:
|
|
381
|
-
memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
382
|
-
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
383
|
-
],
|
|
378
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)), memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
384
379
|
})
|
|
385
380
|
.send();
|
|
386
381
|
}
|
|
@@ -407,10 +402,7 @@ async function fetchMarketsByUnderlyingAndExpiryDecoded(rpc, underlying, expiryT
|
|
|
407
402
|
return fetchAndDecode(rpc, {
|
|
408
403
|
commitment: options?.commitment,
|
|
409
404
|
dataSlice: options?.dataSlice,
|
|
410
|
-
filters:
|
|
411
|
-
memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
412
|
-
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
413
|
-
],
|
|
405
|
+
filters: marketAccountFilters(memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)), memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))),
|
|
414
406
|
}, decodeMarketAccount);
|
|
415
407
|
}
|
|
416
408
|
// --- Decode helpers ---
|
|
@@ -418,6 +410,12 @@ function decodePositionAccount(data) {
|
|
|
418
410
|
return (0, position_1.getPositionDecoder)().decode(data);
|
|
419
411
|
}
|
|
420
412
|
function decodeMarketAccount(data) {
|
|
413
|
+
if (data.length < exports.MARKET_ACCOUNT_SIZE_BYTES) {
|
|
414
|
+
throw new Error(`Invalid Market account size: expected >= ${exports.MARKET_ACCOUNT_SIZE_BYTES}, got ${data.length}`);
|
|
415
|
+
}
|
|
416
|
+
if (data[0] !== exports.MARKET_ACCOUNT_DISCRIMINATOR) {
|
|
417
|
+
throw new Error(`Invalid Market account discriminator: expected ${exports.MARKET_ACCOUNT_DISCRIMINATOR}, got ${data[0]}`);
|
|
418
|
+
}
|
|
421
419
|
return (0, market_1.getMarketDecoder)().decode(data);
|
|
422
420
|
}
|
|
423
421
|
function decodeConfigAccount(data) {
|
|
@@ -157,4 +157,33 @@ describe("fetch offsets and order encode", () => {
|
|
|
157
157
|
expect(preimage.slice(base + 66, base + 98)).toEqual(makerBytes);
|
|
158
158
|
expect(preimage.slice(base + 98, base + 130)).toEqual(takerBytes);
|
|
159
159
|
});
|
|
160
|
+
it("decodeMarketAccount rejects non-market discriminator and short data", () => {
|
|
161
|
+
const decoder = (0, addresses_1.getAddressDecoder)();
|
|
162
|
+
const marketBytes = new Uint8Array(Array(32).fill(1));
|
|
163
|
+
const makerBytes = new Uint8Array(Array(32).fill(7));
|
|
164
|
+
const takerBytes = new Uint8Array(Array(32).fill(8));
|
|
165
|
+
const market = decoder.decode(marketBytes);
|
|
166
|
+
const makerOwner = decoder.decode(makerBytes);
|
|
167
|
+
const takerOwner = decoder.decode(takerBytes);
|
|
168
|
+
const positionData = (0, position_1.getPositionEncoder)().encode({
|
|
169
|
+
discriminator: 1,
|
|
170
|
+
version: 1,
|
|
171
|
+
bump: 7,
|
|
172
|
+
positionType: 0,
|
|
173
|
+
status: 1,
|
|
174
|
+
flags: 0,
|
|
175
|
+
flags2: 0,
|
|
176
|
+
flags3: 0,
|
|
177
|
+
takerOwner,
|
|
178
|
+
makerOwner,
|
|
179
|
+
market,
|
|
180
|
+
strike: 1n,
|
|
181
|
+
quantity: 1n,
|
|
182
|
+
totalPremium: 1n,
|
|
183
|
+
orderId: new Uint8Array(32).fill(0x11),
|
|
184
|
+
reserved: Array(32).fill(0n),
|
|
185
|
+
});
|
|
186
|
+
expect(() => (0, fetch_1.decodeMarketAccount)(buffer_1.Buffer.from(positionData))).toThrow("Invalid Market account discriminator");
|
|
187
|
+
expect(() => (0, fetch_1.decodeMarketAccount)(buffer_1.Buffer.alloc(8))).toThrow("Invalid Market account size");
|
|
188
|
+
});
|
|
160
189
|
});
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -628,6 +628,8 @@ export type MakerPositionInfo = {
|
|
|
628
628
|
strike: WsU64;
|
|
629
629
|
quantity: WsU64;
|
|
630
630
|
price: WsU64;
|
|
631
|
+
/** Net premium amount from on-chain position state (quote token base units). */
|
|
632
|
+
total_premium: WsU64;
|
|
631
633
|
collateral_locked: WsU64;
|
|
632
634
|
created_at: WsU64;
|
|
633
635
|
expiry_ts: WsU64;
|
|
@@ -813,6 +815,8 @@ export type PositionInfo = {
|
|
|
813
815
|
strike: WsU64;
|
|
814
816
|
quantity: WsU64;
|
|
815
817
|
price: WsU64;
|
|
818
|
+
/** Net premium amount from on-chain position state (quote token base units). */
|
|
819
|
+
total_premium: WsU64;
|
|
816
820
|
created_at: WsU64;
|
|
817
821
|
};
|
|
818
822
|
export type TradeInfo = {
|