@thru/programs 0.3.17 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/abi-manager/index.cjs +154 -33
- package/dist/abi-manager/index.cjs.map +1 -1
- package/dist/abi-manager/index.d.cts +1 -1
- package/dist/abi-manager/index.d.ts +1 -1
- package/dist/abi-manager/index.js +3 -2
- package/dist/amm/index.cjs +81 -47
- package/dist/amm/index.cjs.map +1 -1
- package/dist/amm/index.js +2 -3
- package/dist/amm/index.js.map +1 -1
- package/dist/bootstrap-addresses/index.cjs +58 -20
- package/dist/bootstrap-addresses/index.cjs.map +1 -1
- package/dist/bootstrap-addresses/index.d.cts +38 -19
- package/dist/bootstrap-addresses/index.d.ts +38 -19
- package/dist/bootstrap-addresses/index.js +2 -3
- package/dist/{chunk-6IC6CO5S.js → chunk-2NNQJFKS.js} +5 -4
- package/dist/chunk-2NNQJFKS.js.map +1 -0
- package/dist/chunk-4F54VFIH.js +58 -0
- package/dist/chunk-4F54VFIH.js.map +1 -0
- package/dist/{chunk-BNYDH4ZP.js → chunk-A2BWZE2D.js} +12 -10
- package/dist/chunk-A2BWZE2D.js.map +1 -0
- package/dist/{chunk-7DRJVAYI.js → chunk-A44ZPXY6.js} +5 -58
- package/dist/chunk-A44ZPXY6.js.map +1 -0
- package/dist/{chunk-YX7BLFQZ.js → chunk-JHINXDSG.js} +44 -5
- package/dist/chunk-JHINXDSG.js.map +1 -0
- package/dist/chunk-QGOAPK5X.js +174 -0
- package/dist/chunk-QGOAPK5X.js.map +1 -0
- package/dist/chunk-S3UTJHRO.js +77 -0
- package/dist/chunk-S3UTJHRO.js.map +1 -0
- package/dist/{chunk-CYG4PB65.js → chunk-ZOFTRAAH.js} +4 -4
- package/dist/{chunk-CYG4PB65.js.map → chunk-ZOFTRAAH.js.map} +1 -1
- package/dist/{chunk-ZHF2PH5H.js → chunk-ZP7A3GHV.js} +3 -4
- package/dist/chunk-ZP7A3GHV.js.map +1 -0
- package/dist/clob/index.cjs +380 -322
- package/dist/clob/index.cjs.map +1 -1
- package/dist/clob/index.d.cts +4 -3
- package/dist/clob/index.d.ts +4 -3
- package/dist/clob/index.js +36 -198
- package/dist/clob/index.js.map +1 -1
- package/dist/deploy/index.cjs +241 -169
- package/dist/deploy/index.cjs.map +1 -1
- package/dist/deploy/index.d.cts +5 -0
- package/dist/deploy/index.d.ts +5 -0
- package/dist/deploy/index.js +66 -37
- package/dist/deploy/index.js.map +1 -1
- package/dist/manager/index.cjs +15 -2
- package/dist/manager/index.cjs.map +1 -1
- package/dist/manager/index.d.cts +6 -79
- package/dist/manager/index.d.ts +6 -79
- package/dist/manager/index.js +2 -3
- package/dist/multicall/index.cjs +57 -23
- package/dist/multicall/index.cjs.map +1 -1
- package/dist/multicall/index.js +3 -4
- package/dist/oracle/index.cjs +64 -30
- package/dist/oracle/index.cjs.map +1 -1
- package/dist/oracle/index.d.cts +3 -39
- package/dist/oracle/index.d.ts +3 -39
- package/dist/oracle/index.js +2 -3
- package/dist/oracle/index.js.map +1 -1
- package/dist/orderbook-CEYM4N_S.d.cts +5 -0
- package/dist/orderbook-CEYM4N_S.d.ts +5 -0
- package/dist/passkey-manager/index.cjs +52 -18
- package/dist/passkey-manager/index.cjs.map +1 -1
- package/dist/passkey-manager/index.js +2 -3
- package/dist/passkey-manager/index.js.map +1 -1
- package/dist/perp/index.cjs +16750 -0
- package/dist/perp/index.cjs.map +1 -0
- package/dist/perp/index.d.cts +4577 -0
- package/dist/perp/index.d.ts +4577 -0
- package/dist/perp/index.js +16244 -0
- package/dist/perp/index.js.map +1 -0
- package/dist/token/index.js +2 -1
- package/dist/types-5XmDprcB.d.ts +81 -0
- package/dist/types-Cpi7Ibs2.d.cts +81 -0
- package/dist/types-T4cL02K7.d.cts +39 -0
- package/dist/types-T4cL02K7.d.ts +39 -0
- package/dist/uploader/index.cjs +46 -8
- package/dist/uploader/index.cjs.map +1 -1
- package/dist/uploader/index.d.cts +2 -1
- package/dist/uploader/index.d.ts +2 -1
- package/dist/uploader/index.js +2 -2
- package/package.json +7 -2
- package/src/abi-manager/constants.ts +2 -1
- package/src/abi-manager/index.test.ts +2 -2
- package/src/bootstrap-addresses/index.test.ts +70 -18
- package/src/bootstrap-addresses/index.ts +56 -19
- package/src/clob/index.ts +67 -201
- package/src/deploy/accounts.ts +7 -3
- package/src/deploy/chain.ts +1 -1
- package/src/deploy/constants.ts +3 -4
- package/src/deploy/deploy.test.ts +11 -10
- package/src/deploy/inspection.ts +3 -2
- package/src/deploy/types.ts +5 -0
- package/src/deploy/uploader.ts +5 -4
- package/src/deploy/workflows.test.ts +74 -5
- package/src/deploy/workflows.ts +55 -17
- package/src/manager/constants.ts +14 -2
- package/src/manager/derivation.ts +3 -3
- package/src/manager/index.test.ts +3 -3
- package/src/manager/index.ts +3 -0
- package/src/manager/types.ts +1 -1
- package/src/multicall/index.test.ts +1 -1
- package/src/passkey-manager/validate.test.ts +1 -1
- package/src/perp/abi/thru/common/primitives/types.ts +2428 -0
- package/src/perp/abi/thru/program/perp/types.ts +16813 -0
- package/src/perp/index.test.ts +822 -0
- package/src/perp/index.ts +1793 -0
- package/src/uploader/constants.ts +5 -4
- package/src/uploader/index.test.ts +2 -2
- package/src/uploader/index.ts +1 -0
- package/src/utils/helpers.ts +1 -1
- package/src/utils/orderbook.test.ts +86 -0
- package/src/utils/orderbook.ts +214 -0
- package/tsup.config.ts +1 -0
- package/dist/chunk-6IC6CO5S.js.map +0 -1
- package/dist/chunk-7DHFYBRW.js +0 -51
- package/dist/chunk-7DHFYBRW.js.map +0 -1
- package/dist/chunk-7DRJVAYI.js.map +0 -1
- package/dist/chunk-BNYDH4ZP.js.map +0 -1
- package/dist/chunk-VNTPD4AR.js +0 -37
- package/dist/chunk-VNTPD4AR.js.map +0 -1
- package/dist/chunk-YX7BLFQZ.js.map +0 -1
- package/dist/chunk-ZHF2PH5H.js.map +0 -1
package/dist/clob/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _thru_sdk from '@thru/sdk';
|
|
2
2
|
import { Pubkey as Pubkey$1, Account } from '@thru/sdk';
|
|
3
|
+
import { b as OrderType, a as OrderSide, O as OrderRemovalReason } from '../orderbook-CEYM4N_S.cjs';
|
|
3
4
|
import { Thru } from '@thru/sdk/client';
|
|
4
5
|
|
|
5
6
|
type __TnValidateResult$1 = {
|
|
@@ -3925,8 +3926,8 @@ declare const CLOB_CBOOK_MAX_PRICE_IN_TICKS: bigint;
|
|
|
3925
3926
|
declare const CLOB_CLIENT_ID_SIZE = 16;
|
|
3926
3927
|
declare const CLOB_SEATLESS_SEAT_IDX = 1;
|
|
3927
3928
|
declare const CLOB_NULL_INDEX = 1048575;
|
|
3928
|
-
type ClobOrderSide =
|
|
3929
|
-
type ClobOrderType =
|
|
3929
|
+
type ClobOrderSide = OrderSide;
|
|
3930
|
+
type ClobOrderType = OrderType;
|
|
3930
3931
|
type AccountLookupContext = {
|
|
3931
3932
|
getAccountIndex: (pubkey: Uint8Array) => number;
|
|
3932
3933
|
};
|
|
@@ -4111,7 +4112,7 @@ interface ClobOrderBookSnapshot {
|
|
|
4111
4112
|
bestAsk: ClobOrderBookLevel | null;
|
|
4112
4113
|
}
|
|
4113
4114
|
type ClobTokenSide = 'base' | 'quote';
|
|
4114
|
-
type ClobOrderRemovalReason =
|
|
4115
|
+
type ClobOrderRemovalReason = OrderRemovalReason;
|
|
4115
4116
|
interface ParsedClobEventBase {
|
|
4116
4117
|
eventType: bigint;
|
|
4117
4118
|
variant: string;
|
package/dist/clob/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _thru_sdk from '@thru/sdk';
|
|
2
2
|
import { Pubkey as Pubkey$1, Account } from '@thru/sdk';
|
|
3
|
+
import { b as OrderType, a as OrderSide, O as OrderRemovalReason } from '../orderbook-CEYM4N_S.js';
|
|
3
4
|
import { Thru } from '@thru/sdk/client';
|
|
4
5
|
|
|
5
6
|
type __TnValidateResult$1 = {
|
|
@@ -3925,8 +3926,8 @@ declare const CLOB_CBOOK_MAX_PRICE_IN_TICKS: bigint;
|
|
|
3925
3926
|
declare const CLOB_CLIENT_ID_SIZE = 16;
|
|
3926
3927
|
declare const CLOB_SEATLESS_SEAT_IDX = 1;
|
|
3927
3928
|
declare const CLOB_NULL_INDEX = 1048575;
|
|
3928
|
-
type ClobOrderSide =
|
|
3929
|
-
type ClobOrderType =
|
|
3929
|
+
type ClobOrderSide = OrderSide;
|
|
3930
|
+
type ClobOrderType = OrderType;
|
|
3930
3931
|
type AccountLookupContext = {
|
|
3931
3932
|
getAccountIndex: (pubkey: Uint8Array) => number;
|
|
3932
3933
|
};
|
|
@@ -4111,7 +4112,7 @@ interface ClobOrderBookSnapshot {
|
|
|
4111
4112
|
bestAsk: ClobOrderBookLevel | null;
|
|
4112
4113
|
}
|
|
4113
4114
|
type ClobTokenSide = 'base' | 'quote';
|
|
4114
|
-
type ClobOrderRemovalReason =
|
|
4115
|
+
type ClobOrderRemovalReason = OrderRemovalReason;
|
|
4115
4116
|
interface ParsedClobEventBase {
|
|
4116
4117
|
eventType: bigint;
|
|
4117
4118
|
variant: string;
|
package/dist/clob/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
1
|
+
import { fixedSeed, CLIENT_ID_SIZE, EVENT_REMOVE_REASON_EVICTED, EVENT_REMOVE_REASON_EXPIRED, EVENT_REMOVE_REASON_FILLED, EVENT_REMOVE_REASON_USER, EVENT_SIDE_BUY, EVENT_SIDE_SELL, ORDER_FLAG_BUY, ORDER_FLAG_HAS_CLIENT_ID, ORDER_TYPE_ALO, ORDER_TYPE_FOK, ORDER_TYPE_GTC, ORDER_TYPE_IOC, ORDER_TYPE_MTL, STATUS_FLAG_DEPOSITS_FROZEN, STATUS_FLAG_MASK, STATUS_FLAG_PAUSED, STATUS_FLAG_POST_ONLY, STATUS_FLAG_WITHDRAWALS_FROZEN, assertStatusFlags, assertU8, optionalAccountIndex, assertU64, orderFlags, assertClientId, buildModifyOrderMetadata, pubkeyViewToAddress, cbookLevelFromView, groupByPrice, bytesFromView, eventSideFromValue, removalReasonFromValue, orderTypeFromValue, bitField } from '../chunk-QGOAPK5X.js';
|
|
2
|
+
import { parseTokenAccountData, isAccountNotFoundError, parseMintAccountData, createInitializeAccountInstruction } from '../chunk-A44ZPXY6.js';
|
|
3
|
+
import { deriveTokenAccountAddress } from '../chunk-4F54VFIH.js';
|
|
4
|
+
import { MULTICALL_PROGRAM_ADDRESS, buildMulticallInstruction } from '../chunk-ZOFTRAAH.js';
|
|
5
|
+
import { BOOTSTRAP_PROGRAM_ADDRESSES } from '../chunk-S3UTJHRO.js';
|
|
6
|
+
import { accountIndex, accountData } from '../chunk-JHINXDSG.js';
|
|
6
7
|
import { Pubkey as Pubkey$1, deriveProgramAddress } from '@thru/sdk';
|
|
7
|
-
import { encodeAddress } from '@thru/sdk/helpers';
|
|
8
8
|
|
|
9
9
|
// src/clob/abi/thru/common/primitives/types.ts
|
|
10
10
|
var __tnWarnings = /* @__PURE__ */ new Set();
|
|
@@ -14578,7 +14578,7 @@ function wrapClobPlanWithTokenAccountInitialization(args) {
|
|
|
14578
14578
|
};
|
|
14579
14579
|
}
|
|
14580
14580
|
function validateAllocation(allocation) {
|
|
14581
|
-
|
|
14581
|
+
assertU642(allocation.freeAmount, "allocation.freeAmount");
|
|
14582
14582
|
assertClobActiveSeatIndex(allocation.seatIndex, "allocation.seatIndex");
|
|
14583
14583
|
}
|
|
14584
14584
|
function assertMarketCanTrade(market, orderType) {
|
|
@@ -14804,12 +14804,12 @@ function minBigInt(a, b) {
|
|
|
14804
14804
|
return a < b ? a : b;
|
|
14805
14805
|
}
|
|
14806
14806
|
function assertPositiveU64(value, label) {
|
|
14807
|
-
|
|
14807
|
+
assertU642(value, label);
|
|
14808
14808
|
if (value === 0n) {
|
|
14809
14809
|
throw new ClobExchangeError("invalid_funding_amount", label + " must be positive");
|
|
14810
14810
|
}
|
|
14811
14811
|
}
|
|
14812
|
-
function
|
|
14812
|
+
function assertU642(value, label) {
|
|
14813
14813
|
if (value < 0n || value > 0xffffffffffffffffn) {
|
|
14814
14814
|
throw new Error(label + " must be between 0 and 18446744073709551615");
|
|
14815
14815
|
}
|
|
@@ -15514,27 +15514,27 @@ var CLOB_EVENT_EXCHANGE_INITIALIZED = 11;
|
|
|
15514
15514
|
var CLOB_EVENT_EXCHANGE_STATUS = 12;
|
|
15515
15515
|
var CLOB_EVENT_EXCHANGE_ADMIN = 13;
|
|
15516
15516
|
var CLOB_EVENT_MARKET_EXCHANGE_STATUS = 14;
|
|
15517
|
-
var CLOB_EVENT_SIDE_BUY =
|
|
15518
|
-
var CLOB_EVENT_SIDE_SELL =
|
|
15517
|
+
var CLOB_EVENT_SIDE_BUY = EVENT_SIDE_BUY;
|
|
15518
|
+
var CLOB_EVENT_SIDE_SELL = EVENT_SIDE_SELL;
|
|
15519
15519
|
var CLOB_EVENT_TOKEN_SIDE_BASE = 0;
|
|
15520
15520
|
var CLOB_EVENT_TOKEN_SIDE_QUOTE = 1;
|
|
15521
|
-
var CLOB_EVENT_REMOVE_REASON_FILLED =
|
|
15522
|
-
var CLOB_EVENT_REMOVE_REASON_EXPIRED =
|
|
15523
|
-
var CLOB_EVENT_REMOVE_REASON_EVICTED =
|
|
15524
|
-
var CLOB_EVENT_REMOVE_REASON_USER =
|
|
15525
|
-
var CLOB_STATUS_FLAG_PAUSED =
|
|
15526
|
-
var CLOB_STATUS_FLAG_POST_ONLY =
|
|
15527
|
-
var CLOB_STATUS_FLAG_WITHDRAWALS_FROZEN =
|
|
15528
|
-
var CLOB_STATUS_FLAG_DEPOSITS_FROZEN =
|
|
15529
|
-
var CLOB_STATUS_FLAG_MASK =
|
|
15521
|
+
var CLOB_EVENT_REMOVE_REASON_FILLED = EVENT_REMOVE_REASON_FILLED;
|
|
15522
|
+
var CLOB_EVENT_REMOVE_REASON_EXPIRED = EVENT_REMOVE_REASON_EXPIRED;
|
|
15523
|
+
var CLOB_EVENT_REMOVE_REASON_EVICTED = EVENT_REMOVE_REASON_EVICTED;
|
|
15524
|
+
var CLOB_EVENT_REMOVE_REASON_USER = EVENT_REMOVE_REASON_USER;
|
|
15525
|
+
var CLOB_STATUS_FLAG_PAUSED = STATUS_FLAG_PAUSED;
|
|
15526
|
+
var CLOB_STATUS_FLAG_POST_ONLY = STATUS_FLAG_POST_ONLY;
|
|
15527
|
+
var CLOB_STATUS_FLAG_WITHDRAWALS_FROZEN = STATUS_FLAG_WITHDRAWALS_FROZEN;
|
|
15528
|
+
var CLOB_STATUS_FLAG_DEPOSITS_FROZEN = STATUS_FLAG_DEPOSITS_FROZEN;
|
|
15529
|
+
var CLOB_STATUS_FLAG_MASK = STATUS_FLAG_MASK;
|
|
15530
15530
|
var CLOB_PROGRAM_ADDRESS = BOOTSTRAP_PROGRAM_ADDRESSES.clob;
|
|
15531
|
-
var CLOB_ORDER_TYPE_GTC =
|
|
15532
|
-
var CLOB_ORDER_TYPE_MTL =
|
|
15533
|
-
var CLOB_ORDER_TYPE_ALO =
|
|
15534
|
-
var CLOB_ORDER_TYPE_IOC =
|
|
15535
|
-
var CLOB_ORDER_TYPE_FOK =
|
|
15536
|
-
var CLOB_ORDER_FLAG_BUY =
|
|
15537
|
-
var CLOB_ORDER_FLAG_HAS_CLIENT_ID =
|
|
15531
|
+
var CLOB_ORDER_TYPE_GTC = ORDER_TYPE_GTC;
|
|
15532
|
+
var CLOB_ORDER_TYPE_MTL = ORDER_TYPE_MTL;
|
|
15533
|
+
var CLOB_ORDER_TYPE_ALO = ORDER_TYPE_ALO;
|
|
15534
|
+
var CLOB_ORDER_TYPE_IOC = ORDER_TYPE_IOC;
|
|
15535
|
+
var CLOB_ORDER_TYPE_FOK = ORDER_TYPE_FOK;
|
|
15536
|
+
var CLOB_ORDER_FLAG_BUY = ORDER_FLAG_BUY;
|
|
15537
|
+
var CLOB_ORDER_FLAG_HAS_CLIENT_ID = ORDER_FLAG_HAS_CLIENT_ID;
|
|
15538
15538
|
var CLOB_MODIFY_FLAG_FAIL_IF_OUT_OF_RANGE = 1 << 0;
|
|
15539
15539
|
var CLOB_MODIFY_FLAG_HAS_CLIENT_ID = 1 << 1;
|
|
15540
15540
|
var CLOB_MODIFY_FLAG_HAS_ORDER_ID = 1 << 2;
|
|
@@ -15554,7 +15554,7 @@ var CLOB_CBOOK_LEVEL_SIZE = 8;
|
|
|
15554
15554
|
var CLOB_CBOOK_MAX_SIZE = ((1 << 24) - CLOB_CBOOK_HEADER_SIZE) / CLOB_CBOOK_LEVEL_SIZE;
|
|
15555
15555
|
var CLOB_CBOOK_EMPTY_PRICE_IN_TICKS = (1n << 64n) - 1n;
|
|
15556
15556
|
var CLOB_CBOOK_MAX_PRICE_IN_TICKS = CLOB_CBOOK_EMPTY_PRICE_IN_TICKS - 2n - BigInt(CLOB_CBOOK_MAX_SIZE);
|
|
15557
|
-
var CLOB_CLIENT_ID_SIZE =
|
|
15557
|
+
var CLOB_CLIENT_ID_SIZE = CLIENT_ID_SIZE;
|
|
15558
15558
|
var CLOB_SEATLESS_SEAT_IDX = 1;
|
|
15559
15559
|
var CLOB_NULL_INDEX = 1048575;
|
|
15560
15560
|
function deriveClobExchangeMetaAddress(clobProgramAddress) {
|
|
@@ -15598,8 +15598,8 @@ function createMarketRecordInstruction(args) {
|
|
|
15598
15598
|
}
|
|
15599
15599
|
function createMarketCreateInstruction(args) {
|
|
15600
15600
|
return async (context) => {
|
|
15601
|
-
|
|
15602
|
-
|
|
15601
|
+
assertU64(args.lotSize, "lotSize");
|
|
15602
|
+
assertU64(args.tickSize, "tickSize");
|
|
15603
15603
|
const builder = new MarketCreateInstructionBuilder().set_market_record_idx(assertU8(args.marketRecordIndex, "marketRecordIndex")).set_reserved0([0, 0, 0, 0, 0, 0]).set_lot_size(args.lotSize).set_tick_size(args.tickSize).set_token_program_idx(accountIndex(context, args.tokenProgramAccountBytes)).set_exchange_meta_account_idx(accountIndex(context, args.exchangeMetaAccountBytes)).set_base_mint_idx(accountIndex(context, args.baseMintAccountBytes)).set_quote_mint_idx(accountIndex(context, args.quoteMintAccountBytes)).set_seat_arena_account_idx(accountIndex(context, args.seatArenaAccountBytes)).set_order_arena_account_idx(accountIndex(context, args.orderArenaAccountBytes)).set_bids_cbook_account_idx(accountIndex(context, args.bidsCbookAccountBytes)).set_asks_cbook_account_idx(accountIndex(context, args.asksCbookAccountBytes)).set_base_vault_account_idx(accountIndex(context, args.baseVaultAccountBytes)).set_quote_vault_account_idx(accountIndex(context, args.quoteVaultAccountBytes)).set_market_authority_account_idx(optionalAccountIndex(context, args.marketAuthorityAccountBytes)).set_reserved1([0, 0]);
|
|
15604
15604
|
builder.proof_seat_arena().write(args.seatArenaStateProof).finish();
|
|
15605
15605
|
builder.proof_order_arena().write(args.orderArenaStateProof).finish();
|
|
@@ -15625,8 +15625,8 @@ function createTokenWithdrawInstruction(args) {
|
|
|
15625
15625
|
function createOrderEntryInstruction(args) {
|
|
15626
15626
|
return async () => {
|
|
15627
15627
|
const flags = orderFlags(args);
|
|
15628
|
-
|
|
15629
|
-
|
|
15628
|
+
assertU64(args.price, "price");
|
|
15629
|
+
assertU64(args.quantity, "quantity");
|
|
15630
15630
|
const builder = new CreateOrderEntryInstructionBuilder().set_instruction_flags(flags).set_market_record_idx(assertU8(args.marketRecordIndex, "marketRecordIndex")).set_reserved0([0, 0, 0, 0, 0]).set_price(args.price).set_quantity(args.quantity).set_exp_time(args.expirationTime);
|
|
15631
15631
|
if (args.clientId) builder.client_id().write(assertClientId(args.clientId)).finish();
|
|
15632
15632
|
return buildClobInstruction("create_order_entry", builder.build());
|
|
@@ -15635,8 +15635,8 @@ function createOrderEntryInstruction(args) {
|
|
|
15635
15635
|
function createSeatlessOrderEntryInstruction(args) {
|
|
15636
15636
|
return async (context) => {
|
|
15637
15637
|
const flags = orderFlags(args);
|
|
15638
|
-
|
|
15639
|
-
|
|
15638
|
+
assertU64(args.price, "price");
|
|
15639
|
+
assertU64(args.quantity, "quantity");
|
|
15640
15640
|
const builder = new CreateSeatlessOrderEntryInstructionBuilder().set_instruction_flags(flags).set_market_record_idx(assertU8(args.marketRecordIndex, "marketRecordIndex")).set_reserved0([0, 0, 0, 0, 0]).set_price(args.price).set_quantity(args.quantity).set_quote_wallet_idx(accountIndex(context, args.quoteWalletBytes)).set_base_wallet_idx(accountIndex(context, args.baseWalletBytes)).set_reserved1([0, 0, 0, 0]);
|
|
15641
15641
|
if (args.clientId) builder.client_id().write(assertClientId(args.clientId)).finish();
|
|
15642
15642
|
return buildClobInstruction("create_seatless_order_entry", builder.build());
|
|
@@ -15648,7 +15648,7 @@ function createModifyOrderEntryInstruction(args) {
|
|
|
15648
15648
|
if (args.clientId) flags |= CLOB_MODIFY_FLAG_HAS_CLIENT_ID;
|
|
15649
15649
|
if (args.orderId !== void 0) flags |= CLOB_MODIFY_FLAG_HAS_ORDER_ID;
|
|
15650
15650
|
const metadata = buildModifyOrderMetadata(args);
|
|
15651
|
-
|
|
15651
|
+
assertU64(args.quantity, "quantity");
|
|
15652
15652
|
const builder = new ModifyOrderEntryInstructionBuilder().set_instruction_flags(flags).set_market_record_idx(assertU8(args.marketRecordIndex, "marketRecordIndex")).set_reserved0(0).set_order_entry_idx(args.orderEntryIndex).set_quantity(args.quantity).set_exp_time(args.expirationTime);
|
|
15653
15653
|
if (metadata.length) builder.metadata().write(metadata).finish();
|
|
15654
15654
|
return buildClobInstruction("modify_order_entry", builder.build());
|
|
@@ -15973,22 +15973,9 @@ function parseClobEvent(data) {
|
|
|
15973
15973
|
function encodeOrderFlags(args) {
|
|
15974
15974
|
return orderFlags(args);
|
|
15975
15975
|
}
|
|
15976
|
-
function buildModifyOrderMetadata(args) {
|
|
15977
|
-
const metadata = new Uint8Array((args.clientId ? CLOB_CLIENT_ID_SIZE : 0) + (args.orderId !== void 0 ? 8 : 0));
|
|
15978
|
-
let offset = 0;
|
|
15979
|
-
if (args.clientId) {
|
|
15980
|
-
metadata.set(assertClientId(args.clientId), offset);
|
|
15981
|
-
offset += CLOB_CLIENT_ID_SIZE;
|
|
15982
|
-
}
|
|
15983
|
-
if (args.orderId !== void 0) {
|
|
15984
|
-
assertU642(args.orderId, "orderId");
|
|
15985
|
-
new DataView(metadata.buffer).setBigUint64(offset, args.orderId, true);
|
|
15986
|
-
}
|
|
15987
|
-
return metadata;
|
|
15988
|
-
}
|
|
15989
15976
|
function createTokenTransferInstruction(variant, args) {
|
|
15990
15977
|
return async (context) => {
|
|
15991
|
-
|
|
15978
|
+
assertU64(args.amount, "amount");
|
|
15992
15979
|
const payload = new TokenTransferInstructionBuilder().set_market_record_idx(assertU8(args.marketRecordIndex, "marketRecordIndex")).set_token_program_idx(accountIndex(context, args.tokenProgramAccountBytes)).set_reserved0([0, 0, 0, 0]).set_amount(args.amount).set_from_account_idx(accountIndex(context, args.fromAccountBytes)).set_to_account_idx(accountIndex(context, args.toAccountBytes)).set_reserved1([0, 0, 0, 0]).build();
|
|
15993
15980
|
return buildClobInstruction(variant, payload);
|
|
15994
15981
|
};
|
|
@@ -15998,28 +15985,6 @@ function buildClobInstruction(variant, payload) {
|
|
|
15998
15985
|
builder.payload().select(variant).writePayload(payload).finish();
|
|
15999
15986
|
return builder.build();
|
|
16000
15987
|
}
|
|
16001
|
-
function orderFlags(args) {
|
|
16002
|
-
let flags = args.side === "buy" ? CLOB_ORDER_FLAG_BUY : 0;
|
|
16003
|
-
flags |= orderTypeValue(args.orderType ?? "gtc") << 1;
|
|
16004
|
-
if (args.discardAfterMatch) flags |= 1 << 4;
|
|
16005
|
-
if (args.failIfOutsideBook) flags |= 1 << 5;
|
|
16006
|
-
if (args.clientId) flags |= CLOB_ORDER_FLAG_HAS_CLIENT_ID;
|
|
16007
|
-
return flags;
|
|
16008
|
-
}
|
|
16009
|
-
function orderTypeValue(orderType) {
|
|
16010
|
-
switch (orderType) {
|
|
16011
|
-
case "gtc":
|
|
16012
|
-
return CLOB_ORDER_TYPE_GTC;
|
|
16013
|
-
case "mtl":
|
|
16014
|
-
return CLOB_ORDER_TYPE_MTL;
|
|
16015
|
-
case "alo":
|
|
16016
|
-
return CLOB_ORDER_TYPE_ALO;
|
|
16017
|
-
case "ioc":
|
|
16018
|
-
return CLOB_ORDER_TYPE_IOC;
|
|
16019
|
-
case "fok":
|
|
16020
|
-
return CLOB_ORDER_TYPE_FOK;
|
|
16021
|
-
}
|
|
16022
|
-
}
|
|
16023
15988
|
function marketFromView(view) {
|
|
16024
15989
|
return {
|
|
16025
15990
|
magic: view.get_magic(),
|
|
@@ -16075,13 +16040,6 @@ function orderEntryFromView(view, orderEntryIndex) {
|
|
|
16075
16040
|
expirationTime: view.get_expiry()
|
|
16076
16041
|
};
|
|
16077
16042
|
}
|
|
16078
|
-
function cbookLevelFromView(view, levelIndex) {
|
|
16079
|
-
return {
|
|
16080
|
-
levelIndex,
|
|
16081
|
-
headOrderEntryIndex: view.get_head_entry_idx(),
|
|
16082
|
-
tailOrderEntryIndex: view.get_tail_entry_idx()
|
|
16083
|
-
};
|
|
16084
|
-
}
|
|
16085
16043
|
function normalizeBookOrder(order, side, cbook, prices) {
|
|
16086
16044
|
if ("priceInTicks" in order) return order;
|
|
16087
16045
|
return {
|
|
@@ -16095,29 +16053,6 @@ function normalizeBookOrder(order, side, cbook, prices) {
|
|
|
16095
16053
|
expirationTime: order.expirationTime
|
|
16096
16054
|
};
|
|
16097
16055
|
}
|
|
16098
|
-
function groupByPrice(orders, side) {
|
|
16099
|
-
const levels = /* @__PURE__ */ new Map();
|
|
16100
|
-
for (const order of orders) {
|
|
16101
|
-
if (order.quantityInLots === 0n) continue;
|
|
16102
|
-
const existing = levels.get(order.priceInTicks);
|
|
16103
|
-
if (existing) {
|
|
16104
|
-
existing.quantityInLots += order.quantityInLots;
|
|
16105
|
-
existing.orders.push(order);
|
|
16106
|
-
} else {
|
|
16107
|
-
levels.set(order.priceInTicks, {
|
|
16108
|
-
side,
|
|
16109
|
-
priceInTicks: order.priceInTicks,
|
|
16110
|
-
quantityInLots: order.quantityInLots,
|
|
16111
|
-
orders: [order]
|
|
16112
|
-
});
|
|
16113
|
-
}
|
|
16114
|
-
}
|
|
16115
|
-
return [...levels.values()].sort((a, b) => {
|
|
16116
|
-
if (a.priceInTicks === b.priceInTicks) return 0;
|
|
16117
|
-
const asc = a.priceInTicks < b.priceInTicks ? -1 : 1;
|
|
16118
|
-
return side === "buy" ? -asc : asc;
|
|
16119
|
-
});
|
|
16120
|
-
}
|
|
16121
16056
|
function priceForLevel(levelIndex, side, cbook, prices) {
|
|
16122
16057
|
if (cbook) return priceForCbookLevel(levelIndex, side, cbook);
|
|
16123
16058
|
const mappedPrice = priceFromMap(levelIndex, prices);
|
|
@@ -16141,117 +16076,20 @@ function priceForCbookLevel(levelIndex, side, cbook) {
|
|
|
16141
16076
|
const cbookPriceInTicks = cbook.bestPriceInTicks + BigInt(distance);
|
|
16142
16077
|
return side === "buy" ? CLOB_CBOOK_MAX_PRICE_IN_TICKS - cbookPriceInTicks : cbookPriceInTicks;
|
|
16143
16078
|
}
|
|
16144
|
-
function accountData(accountOrData, label) {
|
|
16145
|
-
const data = accountOrData instanceof Uint8Array ? accountOrData : accountOrData.data?.data;
|
|
16146
|
-
if (!data) throw new Error(`${label} data is missing`);
|
|
16147
|
-
return data;
|
|
16148
|
-
}
|
|
16149
|
-
function fixedSeed(value) {
|
|
16150
|
-
const bytes = new TextEncoder().encode(value);
|
|
16151
|
-
if (bytes.length > 32) throw new Error("seed cannot exceed 32 bytes");
|
|
16152
|
-
const seed = new Uint8Array(32);
|
|
16153
|
-
seed.set(bytes);
|
|
16154
|
-
return seed;
|
|
16155
|
-
}
|
|
16156
|
-
function optionalAccountIndex(context, pubkey) {
|
|
16157
|
-
return pubkey ? accountIndex(context, pubkey) : 65535;
|
|
16158
|
-
}
|
|
16159
|
-
function accountIndex(context, pubkey) {
|
|
16160
|
-
const index = context.getAccountIndex(pubkey);
|
|
16161
|
-
return assertU16(index, "account index");
|
|
16162
|
-
}
|
|
16163
|
-
function assertU8(value, label) {
|
|
16164
|
-
if (!Number.isInteger(value) || value < 0 || value > 255) {
|
|
16165
|
-
throw new Error(`${label} must be an integer between 0 and 255`);
|
|
16166
|
-
}
|
|
16167
|
-
return value;
|
|
16168
|
-
}
|
|
16169
|
-
function assertStatusFlags(value) {
|
|
16170
|
-
const flags = assertU8(value, "statusFlags");
|
|
16171
|
-
if ((flags & ~CLOB_STATUS_FLAG_MASK) !== 0) {
|
|
16172
|
-
throw new Error("statusFlags may only contain bits in mask 0x" + CLOB_STATUS_FLAG_MASK.toString(16));
|
|
16173
|
-
}
|
|
16174
|
-
return flags;
|
|
16175
|
-
}
|
|
16176
16079
|
function effectiveClobStatusFlags(exchangeStatusFlags, market) {
|
|
16177
16080
|
return assertStatusFlags(exchangeStatusFlags) | assertStatusFlags(market.statusFlags) | assertStatusFlags(market.exchangeStatusFlags);
|
|
16178
16081
|
}
|
|
16179
|
-
function assertU16(value, label) {
|
|
16180
|
-
if (!Number.isInteger(value) || value < 0 || value > 65535) {
|
|
16181
|
-
throw new Error(`${label} must be an integer between 0 and 65535`);
|
|
16182
|
-
}
|
|
16183
|
-
return value;
|
|
16184
|
-
}
|
|
16185
16082
|
function assertClobActiveSeatIndex(value, label = "seatIndex") {
|
|
16186
16083
|
if (!Number.isSafeInteger(value) || value < 2 || value >= CLOB_NULL_INDEX) {
|
|
16187
16084
|
throw new Error(`${label} must be an integer between 2 and ${CLOB_NULL_INDEX - 1}`);
|
|
16188
16085
|
}
|
|
16189
16086
|
return value;
|
|
16190
16087
|
}
|
|
16191
|
-
function assertU642(value, label) {
|
|
16192
|
-
if (value < 0n || value > 0xffffffffffffffffn) {
|
|
16193
|
-
throw new Error(`${label} must be between 0 and 18446744073709551615`);
|
|
16194
|
-
}
|
|
16195
|
-
}
|
|
16196
|
-
function assertClientId(value) {
|
|
16197
|
-
if (value.length !== CLOB_CLIENT_ID_SIZE) {
|
|
16198
|
-
throw new Error(`clientId must be ${CLOB_CLIENT_ID_SIZE} bytes`);
|
|
16199
|
-
}
|
|
16200
|
-
return value;
|
|
16201
|
-
}
|
|
16202
|
-
function bitField(value, begin, end) {
|
|
16203
|
-
const mask = (1n << end - begin) - 1n;
|
|
16204
|
-
return Number(value >> begin & mask);
|
|
16205
|
-
}
|
|
16206
|
-
function eventSideFromValue(value) {
|
|
16207
|
-
if (value === CLOB_EVENT_SIDE_BUY) return "buy";
|
|
16208
|
-
if (value === CLOB_EVENT_SIDE_SELL) return "sell";
|
|
16209
|
-
throw new Error(`unknown CLOB event side: ${value}`);
|
|
16210
|
-
}
|
|
16211
16088
|
function tokenSideFromValue(value) {
|
|
16212
16089
|
if (value === CLOB_EVENT_TOKEN_SIDE_BASE) return "base";
|
|
16213
16090
|
if (value === CLOB_EVENT_TOKEN_SIDE_QUOTE) return "quote";
|
|
16214
16091
|
throw new Error(`unknown CLOB token side: ${value}`);
|
|
16215
16092
|
}
|
|
16216
|
-
function removalReasonFromValue(value) {
|
|
16217
|
-
switch (value) {
|
|
16218
|
-
case CLOB_EVENT_REMOVE_REASON_FILLED:
|
|
16219
|
-
return "filled";
|
|
16220
|
-
case CLOB_EVENT_REMOVE_REASON_EXPIRED:
|
|
16221
|
-
return "expired";
|
|
16222
|
-
case CLOB_EVENT_REMOVE_REASON_EVICTED:
|
|
16223
|
-
return "evicted";
|
|
16224
|
-
case CLOB_EVENT_REMOVE_REASON_USER:
|
|
16225
|
-
return "user";
|
|
16226
|
-
default:
|
|
16227
|
-
throw new Error(`unknown CLOB removal reason: ${value}`);
|
|
16228
|
-
}
|
|
16229
|
-
}
|
|
16230
|
-
function orderTypeFromValue(value) {
|
|
16231
|
-
switch (value) {
|
|
16232
|
-
case CLOB_ORDER_TYPE_GTC:
|
|
16233
|
-
return "gtc";
|
|
16234
|
-
case CLOB_ORDER_TYPE_MTL:
|
|
16235
|
-
return "mtl";
|
|
16236
|
-
case CLOB_ORDER_TYPE_ALO:
|
|
16237
|
-
return "alo";
|
|
16238
|
-
case CLOB_ORDER_TYPE_IOC:
|
|
16239
|
-
return "ioc";
|
|
16240
|
-
case CLOB_ORDER_TYPE_FOK:
|
|
16241
|
-
return "fok";
|
|
16242
|
-
default:
|
|
16243
|
-
throw new Error(`unknown CLOB order type: ${value}`);
|
|
16244
|
-
}
|
|
16245
|
-
}
|
|
16246
|
-
function pubkeyViewToAddress(pubkey) {
|
|
16247
|
-
return encodeAddress(bytesFromView(pubkey));
|
|
16248
|
-
}
|
|
16249
|
-
function bytesFromView(value) {
|
|
16250
|
-
const buffer = value.buffer;
|
|
16251
|
-
if (buffer instanceof Uint8Array) return new Uint8Array(buffer);
|
|
16252
|
-
if (value instanceof Pubkey$1) return value.toBytes();
|
|
16253
|
-
throw new Error("generated view did not expose a byte buffer");
|
|
16254
|
-
}
|
|
16255
16093
|
|
|
16256
16094
|
export { ArenaHeader, ArenaHeaderBuilder, CLOB_ARENA_HEADER_SIZE, CLOB_CBOOK_EMPTY_PRICE_IN_TICKS, CLOB_CBOOK_HEADER_SIZE, CLOB_CBOOK_LEVEL_SIZE, CLOB_CBOOK_MAX_PRICE_IN_TICKS, CLOB_CBOOK_MAX_SIZE, CLOB_CLIENT_ID_SIZE, CLOB_EVENT_EXCHANGE_ADMIN, CLOB_EVENT_EXCHANGE_INITIALIZED, CLOB_EVENT_EXCHANGE_STATUS, CLOB_EVENT_MARKET_CREATED, CLOB_EVENT_MARKET_EXCHANGE_STATUS, CLOB_EVENT_MARKET_STATUS, CLOB_EVENT_ORDER_CANCELLED, CLOB_EVENT_ORDER_ENTRY_REMOVED, CLOB_EVENT_ORDER_FILLED, CLOB_EVENT_ORDER_MODIFIED, CLOB_EVENT_ORDER_POSTED, CLOB_EVENT_REMOVE_REASON_EVICTED, CLOB_EVENT_REMOVE_REASON_EXPIRED, CLOB_EVENT_REMOVE_REASON_FILLED, CLOB_EVENT_REMOVE_REASON_USER, CLOB_EVENT_SEAT_ASSIGNED, CLOB_EVENT_SIDE_BUY, CLOB_EVENT_SIDE_SELL, CLOB_EVENT_TOKEN_DEPOSIT, CLOB_EVENT_TOKEN_SIDE_BASE, CLOB_EVENT_TOKEN_SIDE_QUOTE, CLOB_EVENT_TOKEN_WITHDRAW, CLOB_EXCHANGE_META_ACCOUNT_SIZE, CLOB_EXCHANGE_META_MAGIC, CLOB_EXCHANGE_META_SEED, CLOB_EXCHANGE_META_VERSION, CLOB_INSTRUCTION_CREATE_ORDER_ENTRY, CLOB_INSTRUCTION_CREATE_SEATLESS_ORDER_ENTRY, CLOB_INSTRUCTION_EXCHANGE_INITIALIZE, CLOB_INSTRUCTION_EXCHANGE_RECOVER_ADMIN, CLOB_INSTRUCTION_EXCHANGE_SET_ADMIN, CLOB_INSTRUCTION_EXCHANGE_SET_STATUS, CLOB_INSTRUCTION_MARKET_CREATE, CLOB_INSTRUCTION_MARKET_RECORD, CLOB_INSTRUCTION_MARKET_SET_EXCHANGE_STATUS, CLOB_INSTRUCTION_MARKET_SET_STATUS, CLOB_INSTRUCTION_MODIFY_ORDER_ENTRY, CLOB_INSTRUCTION_SEAT_CREATE, CLOB_INSTRUCTION_TOKEN_DEPOSIT, CLOB_INSTRUCTION_TOKEN_WITHDRAW, CLOB_MARKET_ACCOUNT_SIZE, CLOB_MARKET_MAGIC, CLOB_MAX_ATOMIC_FUNDING_SOURCES, CLOB_MODIFY_FLAG_FAIL_IF_OUT_OF_RANGE, CLOB_MODIFY_FLAG_HAS_CLIENT_ID, CLOB_MODIFY_FLAG_HAS_ORDER_ID, CLOB_NULL_INDEX, CLOB_ORDER_ENTRY_SIZE, CLOB_ORDER_FLAG_BUY, CLOB_ORDER_FLAG_HAS_CLIENT_ID, CLOB_ORDER_TYPE_ALO, CLOB_ORDER_TYPE_FOK, CLOB_ORDER_TYPE_GTC, CLOB_ORDER_TYPE_IOC, CLOB_ORDER_TYPE_MTL, CLOB_PROGRAM_ADDRESS, CLOB_SEATLESS_SEAT_IDX, CLOB_SEAT_ARENA_ENTRIES_OFFSET, CLOB_SEAT_ENTRY_SIZE, CLOB_SEAT_MANAGER_RESERVED_SIZE, CLOB_STATUS_FLAG_DEPOSITS_FROZEN, CLOB_STATUS_FLAG_MASK, CLOB_STATUS_FLAG_PAUSED, CLOB_STATUS_FLAG_POST_ONLY, CLOB_STATUS_FLAG_WITHDRAWALS_FROZEN, CbookAccount, CbookHeader, CbookHeaderBuilder, CbookLevel, CbookLevelBuilder, ClientId, ClobError, ClobErrorBuilder, ClobEvent, ClobEventBuilder, ClobExchangeClientError, ClobExchangeError, ClobInstruction, ClobInstructionBuilder, ClobProgramAccount, ClobProgramAccountBuilder, CreateOrderEntryInstruction, CreateOrderEntryInstructionBuilder, CreateSeatlessOrderEntryInstruction, CreateSeatlessOrderEntryInstructionBuilder, ExchangeAdminEvent, ExchangeAdminEventBuilder, ExchangeInitializeInstruction, ExchangeInitializeInstructionBuilder, ExchangeInitializedEvent, ExchangeInitializedEventBuilder, ExchangeMetaAccount, ExchangeMetaAccountBuilder, ExchangeRecoverAdminInstruction, ExchangeRecoverAdminInstructionBuilder, ExchangeSetAdminInstruction, ExchangeSetAdminInstructionBuilder, ExchangeSetStatusInstruction, ExchangeSetStatusInstructionBuilder, ExchangeStatusEvent, ExchangeStatusEventBuilder, MarketAccountBuilder, MarketAccount as MarketAccountView, MarketCreateInstruction, MarketCreateInstructionBuilder, MarketCreatedEvent, MarketCreatedEventBuilder, MarketExchangeStatusEvent, MarketExchangeStatusEventBuilder, MarketRecordInstruction, MarketRecordInstructionBuilder, MarketSetExchangeStatusInstruction, MarketSetExchangeStatusInstructionBuilder, MarketSetStatusInstruction, MarketSetStatusInstructionBuilder, ModifyOrderEntryInstruction, ModifyOrderEntryInstructionBuilder, OrderArenaAccount, OrderCancelledEvent, OrderCancelledEventBuilder, OrderEntryBuilder, OrderEntryRemovedEvent, OrderEntryRemovedEventBuilder, OrderEntry as OrderEntryView, OrderFilledEvent, OrderFilledEventBuilder, OrderModifiedEvent, OrderModifiedEventBuilder, OrderPostedEvent, OrderPostedEventBuilder, SeatArenaAccount, SeatAssignedEvent, SeatAssignedEventBuilder, SeatCreateInstruction, SeatCreateInstructionBuilder, SeatEntryBuilder, SeatEntry as SeatEntryView, TokenBalanceEvent, TokenBalanceEventBuilder, TokenTransferInstruction, TokenTransferInstructionBuilder, aggregateClobExchangeBalances, assertClobActiveSeatIndex, buildClobExchangeDepositInstructionPlan, buildClobExchangeWithdrawalInstructionPlan, buildClobFundedOrderInstructionPlan, buildOrderBookSnapshot, calculateClobOrderFundingAmount, clobMarketPriceNumber, concatClobInstructions, createClobExchangeClient, createExchangeInitializeInstruction, createExchangeRecoverAdminInstruction, createExchangeSetAdminInstruction, createExchangeSetStatusInstruction, createMarketCreateInstruction, createMarketRecordInstruction, createMarketSetExchangeStatusInstruction, createMarketSetStatusInstruction, createModifyOrderEntryInstruction, createOrderEntryInstruction, createSeatCreateInstruction, createSeatlessOrderEntryInstruction, createTokenDepositInstruction, createTokenWithdrawInstruction, deriveClobExchangeMetaAddress, effectiveClobStatusFlags, encodeOrderFlags, formatClobMarketPrice, parseCbookAccount, parseClobEvent, parseClobMarketPrice, parseClobProgramAccount, parseExchangeMetaAccount, parseMarketAccount, parseOrderArenaAccount, parseSeatArenaAccount, planClobOrderFunding, validateClobOrderFundingPlanSeats, wrapClobPlanWithTokenAccountInitialization };
|
|
16257
16095
|
//# sourceMappingURL=index.js.map
|