@thru/programs 0.3.3 → 0.3.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.
- package/README.md +123 -37
- package/dist/abi-manager/index.cjs +9568 -0
- package/dist/abi-manager/index.cjs.map +1 -0
- package/dist/abi-manager/index.d.cts +2169 -0
- package/dist/abi-manager/index.d.ts +2169 -0
- package/dist/abi-manager/index.js +4 -0
- package/dist/abi-manager/index.js.map +1 -0
- package/dist/amm/index.cjs +1 -3
- package/dist/amm/index.cjs.map +1 -1
- package/dist/amm/index.d.cts +1 -1
- package/dist/amm/index.d.ts +1 -1
- package/dist/amm/index.js +2 -2
- package/dist/amm/index.js.map +1 -1
- package/dist/chunk-6IC6CO5S.js +9443 -0
- package/dist/chunk-6IC6CO5S.js.map +1 -0
- package/dist/chunk-7DRJVAYI.js +8587 -0
- package/dist/chunk-7DRJVAYI.js.map +1 -0
- package/dist/chunk-7FBCBZIY.js +41 -0
- package/dist/chunk-7FBCBZIY.js.map +1 -0
- package/dist/chunk-BNYDH4ZP.js +4351 -0
- package/dist/chunk-BNYDH4ZP.js.map +1 -0
- package/dist/chunk-OODN6LJA.js +6567 -0
- package/dist/chunk-OODN6LJA.js.map +1 -0
- package/dist/chunk-YX7BLFQZ.js +81 -0
- package/dist/chunk-YX7BLFQZ.js.map +1 -0
- package/dist/clob/index.cjs +19361 -6851
- package/dist/clob/index.cjs.map +1 -1
- package/dist/clob/index.d.cts +1243 -63
- package/dist/clob/index.d.ts +1243 -63
- package/dist/clob/index.js +6826 -2818
- package/dist/clob/index.js.map +1 -1
- package/dist/deploy/index.cjs +24734 -0
- package/dist/deploy/index.cjs.map +1 -0
- package/dist/deploy/index.d.cts +180 -0
- package/dist/deploy/index.d.ts +180 -0
- package/dist/deploy/index.js +1846 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/helpers-DD7q61nr.d.cts +7 -0
- package/dist/helpers-DD7q61nr.d.ts +7 -0
- package/dist/manager/index.cjs +6680 -0
- package/dist/manager/index.cjs.map +1 -0
- package/dist/manager/index.d.cts +1279 -0
- package/dist/manager/index.d.ts +1279 -0
- package/dist/manager/index.js +4 -0
- package/dist/manager/index.js.map +1 -0
- package/dist/passkey-manager/index.cjs +4 -5
- package/dist/passkey-manager/index.cjs.map +1 -1
- package/dist/passkey-manager/index.js +2 -2
- package/dist/token/index.js +1 -8585
- package/dist/token/index.js.map +1 -1
- package/dist/uploader/index.cjs +4442 -0
- package/dist/uploader/index.cjs.map +1 -0
- package/dist/uploader/index.d.cts +761 -0
- package/dist/uploader/index.d.ts +761 -0
- package/dist/uploader/index.js +4 -0
- package/dist/uploader/index.js.map +1 -0
- package/package.json +22 -2
- package/src/abi-manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
- package/src/abi-manager/abi/thru/common/primitives/types.ts +2428 -0
- package/src/abi-manager/abi/thru/program/abi_manager/types.ts +7037 -0
- package/src/abi-manager/accounts.ts +91 -0
- package/src/abi-manager/constants.ts +19 -0
- package/src/abi-manager/derivation.ts +86 -0
- package/src/abi-manager/errors.ts +48 -0
- package/src/abi-manager/index.test.ts +136 -0
- package/src/abi-manager/index.ts +56 -0
- package/src/abi-manager/instructions.ts +573 -0
- package/src/abi-manager/types.ts +150 -0
- package/src/amm/index.test.ts +8 -2
- package/src/amm/index.ts +1 -1
- package/src/clob/abi/thru/program/clob/types.ts +6981 -3070
- package/src/clob/exchange-client.test.ts +592 -0
- package/src/clob/exchange-client.ts +953 -0
- package/src/clob/exchange.test.ts +18 -16
- package/src/clob/exchange.ts +4 -0
- package/src/clob/index.test.ts +134 -7
- package/src/clob/index.ts +303 -10
- package/src/clob/price.test.ts +32 -0
- package/src/clob/price.ts +77 -0
- package/src/deploy/accounts.ts +208 -0
- package/src/deploy/chain.ts +163 -0
- package/src/deploy/constants.ts +25 -0
- package/src/deploy/deploy.test.ts +349 -0
- package/src/deploy/errors.ts +72 -0
- package/src/deploy/index.ts +44 -0
- package/src/deploy/inspection.ts +146 -0
- package/src/deploy/seeds.ts +29 -0
- package/src/deploy/types.ts +178 -0
- package/src/deploy/uploader.test.ts +326 -0
- package/src/deploy/uploader.ts +558 -0
- package/src/deploy/validation-imports.test.ts +55 -0
- package/src/deploy/validation.ts +183 -0
- package/src/deploy/workflows.test.ts +422 -0
- package/src/deploy/workflows.ts +1088 -0
- package/src/helpers/bytes.test.ts +58 -0
- package/src/helpers/bytes.ts +28 -3
- package/src/manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
- package/src/manager/abi/thru/common/primitives/types.ts +2428 -0
- package/src/manager/abi/thru/program/manager/types.ts +3814 -0
- package/src/manager/accounts.ts +44 -0
- package/src/manager/constants.ts +16 -0
- package/src/manager/derivation.ts +32 -0
- package/src/manager/errors.ts +47 -0
- package/src/manager/index.test.ts +108 -0
- package/src/manager/index.ts +68 -0
- package/src/manager/instructions.ts +281 -0
- package/src/manager/types.ts +95 -0
- package/src/manager/validation.ts +35 -0
- package/src/uploader/abi/thru/common/primitives/types.ts +2428 -0
- package/src/uploader/abi/thru/program/uploader/types.ts +3022 -0
- package/src/uploader/accounts.ts +38 -0
- package/src/uploader/constants.ts +14 -0
- package/src/uploader/derivation.ts +34 -0
- package/src/uploader/errors.ts +25 -0
- package/src/uploader/index.test.ts +107 -0
- package/src/uploader/index.ts +34 -0
- package/src/uploader/instructions.ts +163 -0
- package/src/uploader/types.ts +67 -0
- package/src/utils/helpers.ts +121 -0
- package/tsup.config.ts +4 -0
- package/dist/chunk-P5OABVJI.js +0 -28
- package/dist/chunk-P5OABVJI.js.map +0 -1
|
@@ -30,6 +30,7 @@ const TOKEN_PROGRAM = address(2);
|
|
|
30
30
|
const BASE_MINT = address(3);
|
|
31
31
|
const QUOTE_MINT = address(4);
|
|
32
32
|
const WALLET_QUOTE = address(5);
|
|
33
|
+
const EXCHANGE_META = address(250);
|
|
33
34
|
|
|
34
35
|
describe('CLOB exchange balance SDK', () => {
|
|
35
36
|
it('aggregates compatible physical allocations without losing transferability', () => {
|
|
@@ -569,10 +570,10 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
569
570
|
|
|
570
571
|
expect([
|
|
571
572
|
bytes[0],
|
|
572
|
-
bytes[
|
|
573
|
-
bytes[
|
|
574
|
-
bytes[
|
|
575
|
-
bytes[
|
|
573
|
+
bytes[32],
|
|
574
|
+
bytes[56],
|
|
575
|
+
bytes[88],
|
|
576
|
+
bytes[112],
|
|
576
577
|
]).toEqual([
|
|
577
578
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
578
579
|
CLOB_INSTRUCTION_TOKEN_WITHDRAW,
|
|
@@ -581,12 +582,12 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
581
582
|
CLOB_INSTRUCTION_CREATE_ORDER_ENTRY,
|
|
582
583
|
]);
|
|
583
584
|
expect(bytes[1]).toBe(1);
|
|
584
|
-
expect(bytes[
|
|
585
|
-
expect(bytes[
|
|
586
|
-
expect(bytes[
|
|
587
|
-
expect(bytes[
|
|
588
|
-
expect(readU16(bytes,
|
|
589
|
-
expect(readU16(bytes,
|
|
585
|
+
expect(bytes[33]).toBe(1);
|
|
586
|
+
expect(bytes[57]).toBe(2);
|
|
587
|
+
expect(bytes[89]).toBe(2);
|
|
588
|
+
expect(bytes[114]).toBe(2);
|
|
589
|
+
expect(readU16(bytes, 24)).toBe(0xffff);
|
|
590
|
+
expect(readU16(bytes, 80)).toBe(0xffff);
|
|
590
591
|
expect(instructionPlan.readWriteAccounts).toContain(source.address);
|
|
591
592
|
expect(instructionPlan.readWriteAccounts).toContain(source.orderArena);
|
|
592
593
|
expect(instructionPlan.readWriteAccounts).toContain(source.bidsCbook);
|
|
@@ -638,7 +639,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
638
639
|
});
|
|
639
640
|
const bytes = await instructionPlan.instructionData(contextForPlan(instructionPlan));
|
|
640
641
|
|
|
641
|
-
expect([bytes[0], bytes[
|
|
642
|
+
expect([bytes[0], bytes[32], bytes[56], bytes[88], bytes[112]]).toEqual([
|
|
642
643
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
643
644
|
CLOB_INSTRUCTION_TOKEN_WITHDRAW,
|
|
644
645
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
@@ -646,7 +647,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
646
647
|
CLOB_INSTRUCTION_CREATE_ORDER_ENTRY,
|
|
647
648
|
]);
|
|
648
649
|
expect(readU32(bytes, 12)).toBe(3);
|
|
649
|
-
expect(readU32(bytes,
|
|
650
|
+
expect(readU32(bytes, 68)).toBe(2);
|
|
650
651
|
expect(instructionPlan.readWriteAccounts.filter((account) => account === target.address))
|
|
651
652
|
.toHaveLength(1);
|
|
652
653
|
});
|
|
@@ -691,7 +692,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
691
692
|
});
|
|
692
693
|
const bytes = await instructionPlan.instructionData(contextForPlan(instructionPlan));
|
|
693
694
|
|
|
694
|
-
expect([bytes[0], bytes[
|
|
695
|
+
expect([bytes[0], bytes[32], bytes[56], bytes[88], bytes[112], bytes[144], bytes[152], bytes[176]]).toEqual([
|
|
695
696
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
696
697
|
CLOB_INSTRUCTION_TOKEN_WITHDRAW,
|
|
697
698
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
@@ -701,7 +702,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
701
702
|
CLOB_INSTRUCTION_TOKEN_DEPOSIT,
|
|
702
703
|
CLOB_INSTRUCTION_CREATE_ORDER_ENTRY,
|
|
703
704
|
]);
|
|
704
|
-
expect([bytes[1], bytes[
|
|
705
|
+
expect([bytes[1], bytes[33], bytes[57], bytes[89], bytes[113], bytes[153], bytes[178]])
|
|
705
706
|
.toEqual([1, 1, 2, 2, 3, 3, 3]);
|
|
706
707
|
expect(instructionPlan.review.value.sourceMarketCount).toBe('2');
|
|
707
708
|
expect(instructionPlan.review.value.exchangeAmount).toBe('300');
|
|
@@ -744,7 +745,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
744
745
|
seatIndex: null,
|
|
745
746
|
});
|
|
746
747
|
const depositBytes = await deposit.instructionData(contextForPlan(deposit));
|
|
747
|
-
expect([depositBytes[0], depositBytes[
|
|
748
|
+
expect([depositBytes[0], depositBytes[32], depositBytes[40]]).toEqual([
|
|
748
749
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
749
750
|
CLOB_INSTRUCTION_SEAT_CREATE,
|
|
750
751
|
CLOB_INSTRUCTION_TOKEN_DEPOSIT,
|
|
@@ -760,7 +761,7 @@ describe('CLOB exchange balance SDK', () => {
|
|
|
760
761
|
seatIndex: 2,
|
|
761
762
|
});
|
|
762
763
|
const withdrawalBytes = await withdrawal.instructionData(contextForPlan(withdrawal));
|
|
763
|
-
expect([withdrawalBytes[0], withdrawalBytes[
|
|
764
|
+
expect([withdrawalBytes[0], withdrawalBytes[32]]).toEqual([
|
|
764
765
|
CLOB_INSTRUCTION_MARKET_RECORD,
|
|
765
766
|
CLOB_INSTRUCTION_TOKEN_WITHDRAW,
|
|
766
767
|
]);
|
|
@@ -825,6 +826,7 @@ function market(
|
|
|
825
826
|
): ClobTradingMarket {
|
|
826
827
|
return {
|
|
827
828
|
address: address(id),
|
|
829
|
+
exchangeMeta: EXCHANGE_META,
|
|
828
830
|
orderArena: address(id + 1),
|
|
829
831
|
bidsCbook: address(id + 2),
|
|
830
832
|
asksCbook: address(id + 3),
|
package/src/clob/exchange.ts
CHANGED
|
@@ -48,6 +48,7 @@ export interface ClobExchangeAssetBalance {
|
|
|
48
48
|
|
|
49
49
|
export interface ClobTradingMarket {
|
|
50
50
|
address: string;
|
|
51
|
+
exchangeMeta: string;
|
|
51
52
|
orderArena: string;
|
|
52
53
|
bidsCbook: string;
|
|
53
54
|
asksCbook: string;
|
|
@@ -775,6 +776,7 @@ function marketRecordInstruction(
|
|
|
775
776
|
asksCbookAccountBytes: addressBytes(market.asksCbook),
|
|
776
777
|
seatAuthorityAccountBytes: authority ? addressBytes(authority) : undefined,
|
|
777
778
|
seatIndex: seatIndex ?? undefined,
|
|
779
|
+
exchangeMetaAccountBytes: addressBytes(market.exchangeMeta),
|
|
778
780
|
tokenProgramAccountBytes: addressBytes(market.tokenProgram),
|
|
779
781
|
baseVaultAccountBytes: addressBytes(market.baseVault),
|
|
780
782
|
quoteVaultAccountBytes: addressBytes(market.quoteVault),
|
|
@@ -788,6 +790,7 @@ function addTargetMarketAccounts(accounts: AccountPlan, market: ClobTradingMarke
|
|
|
788
790
|
accounts.addWrite(market.asksCbook);
|
|
789
791
|
accounts.addRead(market.baseVault);
|
|
790
792
|
accounts.addRead(market.quoteVault);
|
|
793
|
+
accounts.addRead(market.exchangeMeta);
|
|
791
794
|
}
|
|
792
795
|
|
|
793
796
|
function addSourceMarketAccounts(
|
|
@@ -806,6 +809,7 @@ function addSourceMarketAccounts(
|
|
|
806
809
|
accounts.addWrite(market.asksCbook);
|
|
807
810
|
accounts.addRead(market.baseVault);
|
|
808
811
|
accounts.addRead(market.quoteVault);
|
|
812
|
+
accounts.addRead(market.exchangeMeta);
|
|
809
813
|
}
|
|
810
814
|
|
|
811
815
|
class AccountPlan {
|
package/src/clob/index.test.ts
CHANGED
|
@@ -5,6 +5,13 @@ import {
|
|
|
5
5
|
CLOB_NULL_INDEX,
|
|
6
6
|
CLOB_INSTRUCTION_CREATE_ORDER_ENTRY,
|
|
7
7
|
CLOB_INSTRUCTION_CREATE_SEATLESS_ORDER_ENTRY,
|
|
8
|
+
CLOB_INSTRUCTION_EXCHANGE_INITIALIZE,
|
|
9
|
+
CLOB_INSTRUCTION_EXCHANGE_SET_STATUS,
|
|
10
|
+
CLOB_INSTRUCTION_EXCHANGE_SET_ADMIN,
|
|
11
|
+
CLOB_INSTRUCTION_EXCHANGE_RECOVER_ADMIN,
|
|
12
|
+
CLOB_INSTRUCTION_MARKET_SET_EXCHANGE_STATUS,
|
|
13
|
+
CLOB_EXCHANGE_META_MAGIC,
|
|
14
|
+
CLOB_EXCHANGE_META_VERSION,
|
|
8
15
|
CLOB_CBOOK_MAX_PRICE_IN_TICKS,
|
|
9
16
|
CLOB_EVENT_SIDE_BUY,
|
|
10
17
|
CLOB_ORDER_FLAG_BUY,
|
|
@@ -13,18 +20,30 @@ import {
|
|
|
13
20
|
CLOB_ORDER_TYPE_GTC,
|
|
14
21
|
CLOB_ORDER_TYPE_IOC,
|
|
15
22
|
CLOB_ORDER_TYPE_MTL,
|
|
23
|
+
CLOB_STATUS_FLAG_DEPOSITS_FROZEN,
|
|
24
|
+
CLOB_STATUS_FLAG_PAUSED,
|
|
25
|
+
CLOB_STATUS_FLAG_POST_ONLY,
|
|
26
|
+
CLOB_STATUS_FLAG_WITHDRAWALS_FROZEN,
|
|
16
27
|
ClobEventBuilder,
|
|
28
|
+
ExchangeMetaAccountBuilder,
|
|
17
29
|
MarketAccountBuilder,
|
|
18
30
|
MarketCreatedEventBuilder,
|
|
19
31
|
OrderEntryBuilder,
|
|
20
32
|
OrderFilledEventBuilder,
|
|
21
33
|
SeatEntryBuilder,
|
|
22
34
|
buildOrderBookSnapshot,
|
|
35
|
+
createExchangeInitializeInstruction,
|
|
36
|
+
createExchangeSetStatusInstruction,
|
|
37
|
+
createExchangeSetAdminInstruction,
|
|
38
|
+
createExchangeRecoverAdminInstruction,
|
|
39
|
+
createMarketSetExchangeStatusInstruction,
|
|
23
40
|
createMarketRecordInstruction,
|
|
24
41
|
createOrderEntryInstruction,
|
|
25
42
|
createSeatlessOrderEntryInstruction,
|
|
43
|
+
effectiveClobStatusFlags,
|
|
26
44
|
encodeOrderFlags,
|
|
27
45
|
parseClobEvent,
|
|
46
|
+
parseExchangeMetaAccount,
|
|
28
47
|
parseMarketAccount,
|
|
29
48
|
parseOrderArenaAccount,
|
|
30
49
|
parseSeatArenaAccount,
|
|
@@ -48,16 +67,17 @@ function context(indexes: Record<string, number>) {
|
|
|
48
67
|
|
|
49
68
|
describe('clob helpers', () => {
|
|
50
69
|
it('validates market-record seat indices before ABI serialization', async () => {
|
|
51
|
-
const accounts = Array.from({ length:
|
|
70
|
+
const accounts = Array.from({ length: 8 }, (_, index) => key(index + 1));
|
|
52
71
|
const args = {
|
|
53
72
|
marketRecordIndex: 1,
|
|
54
73
|
seatArenaAccountBytes: accounts[0],
|
|
55
74
|
orderArenaAccountBytes: accounts[1],
|
|
56
75
|
bidsCbookAccountBytes: accounts[2],
|
|
57
76
|
asksCbookAccountBytes: accounts[3],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
exchangeMetaAccountBytes: accounts[4],
|
|
78
|
+
tokenProgramAccountBytes: accounts[5],
|
|
79
|
+
baseVaultAccountBytes: accounts[6],
|
|
80
|
+
quoteVaultAccountBytes: accounts[7],
|
|
61
81
|
};
|
|
62
82
|
const lookup = context(Object.fromEntries(
|
|
63
83
|
accounts.map((account, index) => [bytesToHex(account), index + 2])
|
|
@@ -76,6 +96,113 @@ describe('clob helpers', () => {
|
|
|
76
96
|
}
|
|
77
97
|
});
|
|
78
98
|
|
|
99
|
+
it('builds and parses exchange metadata instructions and accounts', async () => {
|
|
100
|
+
const exchangeMeta = key(1);
|
|
101
|
+
const programMeta = key(2);
|
|
102
|
+
const authority = key(3);
|
|
103
|
+
const tokenProgram = key(4);
|
|
104
|
+
const exchangeAdmin = key(5);
|
|
105
|
+
const proof = new Uint8Array([6, 7, 8]);
|
|
106
|
+
const instruction = await createExchangeInitializeInstruction({
|
|
107
|
+
exchangeMetaAccountBytes: exchangeMeta,
|
|
108
|
+
programMetaAccountBytes: programMeta,
|
|
109
|
+
authorityAccountBytes: authority,
|
|
110
|
+
tokenProgramAccountBytes: tokenProgram,
|
|
111
|
+
exchangeAdminAccountBytes: exchangeAdmin,
|
|
112
|
+
stateProof: proof,
|
|
113
|
+
})(context({
|
|
114
|
+
[bytesToHex(exchangeMeta)]: 10,
|
|
115
|
+
[bytesToHex(programMeta)]: 11,
|
|
116
|
+
[bytesToHex(authority)]: 12,
|
|
117
|
+
[bytesToHex(tokenProgram)]: 13,
|
|
118
|
+
[bytesToHex(exchangeAdmin)]: 14,
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
expect(instruction[0]).toBe(CLOB_INSTRUCTION_EXCHANGE_INITIALIZE);
|
|
122
|
+
const view = new DataView(instruction.buffer, instruction.byteOffset, instruction.byteLength);
|
|
123
|
+
expect(view.getUint16(2, true)).toBe(10);
|
|
124
|
+
expect(view.getUint16(4, true)).toBe(11);
|
|
125
|
+
expect(view.getUint16(6, true)).toBe(12);
|
|
126
|
+
expect(view.getUint16(8, true)).toBe(13);
|
|
127
|
+
expect(view.getUint16(10, true)).toBe(14);
|
|
128
|
+
expect(view.getUint32(12, true)).toBe(proof.length);
|
|
129
|
+
expect(instruction.slice(16)).toEqual(proof);
|
|
130
|
+
|
|
131
|
+
const data = new ExchangeMetaAccountBuilder()
|
|
132
|
+
.set_magic(CLOB_EXCHANGE_META_MAGIC)
|
|
133
|
+
.set_version(CLOB_EXCHANGE_META_VERSION)
|
|
134
|
+
.set_status_flags(3)
|
|
135
|
+
.set_reserved0([0, 0, 0, 0, 0, 0])
|
|
136
|
+
.set_token_program_pubkey(tokenProgram)
|
|
137
|
+
.set_exchange_admin_pubkey(exchangeAdmin)
|
|
138
|
+
.set_reserved1(new Uint8Array(16))
|
|
139
|
+
.build();
|
|
140
|
+
expect(parseExchangeMetaAccount(data)).toEqual({
|
|
141
|
+
magic: CLOB_EXCHANGE_META_MAGIC,
|
|
142
|
+
version: CLOB_EXCHANGE_META_VERSION,
|
|
143
|
+
statusFlags: 3,
|
|
144
|
+
tokenProgram: bytesToAddress(tokenProgram),
|
|
145
|
+
exchangeAdmin: bytesToAddress(exchangeAdmin),
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('builds exchange administration instructions', async () => {
|
|
150
|
+
const exchangeMeta = key(1);
|
|
151
|
+
const admin = key(2);
|
|
152
|
+
const nextAdmin = key(3);
|
|
153
|
+
const programMeta = key(4);
|
|
154
|
+
const lookup = context({
|
|
155
|
+
[bytesToHex(exchangeMeta)]: 10,
|
|
156
|
+
[bytesToHex(admin)]: 11,
|
|
157
|
+
[bytesToHex(nextAdmin)]: 12,
|
|
158
|
+
[bytesToHex(programMeta)]: 13,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const setStatus = await createExchangeSetStatusInstruction({
|
|
162
|
+
exchangeMetaAccountBytes: exchangeMeta,
|
|
163
|
+
exchangeAdminAccountBytes: admin,
|
|
164
|
+
statusFlags: 5,
|
|
165
|
+
})(lookup);
|
|
166
|
+
const setAdmin = await createExchangeSetAdminInstruction({
|
|
167
|
+
exchangeMetaAccountBytes: exchangeMeta,
|
|
168
|
+
authorityAccountBytes: admin,
|
|
169
|
+
newAdminAccountBytes: nextAdmin,
|
|
170
|
+
})(lookup);
|
|
171
|
+
const recoverAdmin = await createExchangeRecoverAdminInstruction({
|
|
172
|
+
exchangeMetaAccountBytes: exchangeMeta,
|
|
173
|
+
programMetaAccountBytes: programMeta,
|
|
174
|
+
authorityAccountBytes: admin,
|
|
175
|
+
newAdminAccountBytes: nextAdmin,
|
|
176
|
+
})(lookup);
|
|
177
|
+
const marketOverride = await createMarketSetExchangeStatusInstruction({
|
|
178
|
+
marketRecordIndex: 7,
|
|
179
|
+
exchangeAdminAccountBytes: admin,
|
|
180
|
+
statusFlags: 2,
|
|
181
|
+
})(lookup);
|
|
182
|
+
|
|
183
|
+
expect(setStatus[0]).toBe(CLOB_INSTRUCTION_EXCHANGE_SET_STATUS);
|
|
184
|
+
expect(setAdmin[0]).toBe(CLOB_INSTRUCTION_EXCHANGE_SET_ADMIN);
|
|
185
|
+
expect(recoverAdmin[0]).toBe(CLOB_INSTRUCTION_EXCHANGE_RECOVER_ADMIN);
|
|
186
|
+
expect(marketOverride[0]).toBe(CLOB_INSTRUCTION_MARKET_SET_EXCHANGE_STATUS);
|
|
187
|
+
await expect(createExchangeSetStatusInstruction({
|
|
188
|
+
exchangeMetaAccountBytes: exchangeMeta,
|
|
189
|
+
exchangeAdminAccountBytes: admin,
|
|
190
|
+
statusFlags: 16,
|
|
191
|
+
})(lookup)).rejects.toThrow(/statusFlags/);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('combines global, exchange-admin, and market-authority status flags', () => {
|
|
195
|
+
expect(effectiveClobStatusFlags(
|
|
196
|
+
CLOB_STATUS_FLAG_PAUSED,
|
|
197
|
+
{
|
|
198
|
+
statusFlags: CLOB_STATUS_FLAG_POST_ONLY,
|
|
199
|
+
exchangeStatusFlags: CLOB_STATUS_FLAG_WITHDRAWALS_FROZEN | CLOB_STATUS_FLAG_DEPOSITS_FROZEN,
|
|
200
|
+
},
|
|
201
|
+
)).toBe(15);
|
|
202
|
+
expect(() => effectiveClobStatusFlags(16, { statusFlags: 0, exchangeStatusFlags: 0 }))
|
|
203
|
+
.toThrow(/statusFlags/);
|
|
204
|
+
});
|
|
205
|
+
|
|
79
206
|
it('encodes order flags with C program bit semantics', () => {
|
|
80
207
|
expect(encodeOrderFlags({ side: 'buy', orderType: 'gtc' })).toBe(
|
|
81
208
|
CLOB_ORDER_FLAG_BUY | (CLOB_ORDER_TYPE_GTC << 1)
|
|
@@ -134,14 +261,14 @@ describe('clob helpers', () => {
|
|
|
134
261
|
const data = new MarketAccountBuilder()
|
|
135
262
|
.set_magic(0xc1)
|
|
136
263
|
.set_status_flags(3)
|
|
137
|
-
.
|
|
264
|
+
.set_exchange_status_flags(4)
|
|
265
|
+
.set_reserved0([0, 0, 0, 0, 0])
|
|
138
266
|
.set_lot_size(100n)
|
|
139
267
|
.set_tick_size(5n)
|
|
140
268
|
.set_next_order_id(42n)
|
|
141
269
|
.set_order_entry_pubkey(key(10))
|
|
142
270
|
.set_bids_cbook_pubkey(key(11))
|
|
143
271
|
.set_asks_cbook_pubkey(key(12))
|
|
144
|
-
.set_token_program_pubkey(key(16))
|
|
145
272
|
.set_base_vault_pubkey(key(13))
|
|
146
273
|
.set_quote_vault_pubkey(key(14))
|
|
147
274
|
.set_market_authority_pubkey(key(15))
|
|
@@ -150,11 +277,11 @@ describe('clob helpers', () => {
|
|
|
150
277
|
const market = parseMarketAccount(data);
|
|
151
278
|
expect(market.magic).toBe(0xc1);
|
|
152
279
|
expect(market.statusFlags).toBe(3);
|
|
280
|
+
expect(market.exchangeStatusFlags).toBe(4);
|
|
153
281
|
expect(market.lotSize).toBe(100n);
|
|
154
282
|
expect(market.tickSize).toBe(5n);
|
|
155
283
|
expect(market.nextOrderId).toBe(42n);
|
|
156
284
|
expect(market.bidsCbook).not.toBe(market.asksCbook);
|
|
157
|
-
expect(market.tokenProgram).toBe(bytesToAddress(key(16)));
|
|
158
285
|
});
|
|
159
286
|
|
|
160
287
|
it('parses order arenas and groups active orderbook depth', () => {
|