@acta-markets/ts-sdk 0.0.18-beta → 0.0.20-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.
Files changed (48) hide show
  1. package/dist/chain/instructions.market.d.ts +0 -1
  2. package/dist/chain/instructions.market.js +1 -6
  3. package/dist/chain/instructions.oracle.d.ts +0 -3
  4. package/dist/chain/instructions.oracle.js +1 -5
  5. package/dist/chain/instructions.position.js +8 -16
  6. package/dist/chain/instructions.shared.d.ts +0 -1
  7. package/dist/chain/instructions.shared.js +0 -1
  8. package/dist/cjs/chain/instructions.market.js +0 -5
  9. package/dist/cjs/chain/instructions.oracle.js +0 -4
  10. package/dist/cjs/chain/instructions.position.js +8 -16
  11. package/dist/cjs/chain/instructions.shared.js +1 -2
  12. package/dist/cjs/generated/instructions/closeOracle.js +2 -13
  13. package/dist/cjs/generated/instructions/createMarket.js +1 -10
  14. package/dist/cjs/generated/instructions/createOracle.js +1 -4
  15. package/dist/cjs/generated/instructions/depositFundsToPosition.js +5 -11
  16. package/dist/cjs/generated/instructions/finalizeMarket.js +1 -9
  17. package/dist/cjs/generated/instructions/updateOraclePrice.js +2 -13
  18. package/dist/cjs/idl/acta_contract.json +5 -61
  19. package/dist/cjs/idl/hash.js +1 -1
  20. package/dist/cjs/ws/apy.js +4 -10
  21. package/dist/cjs/ws/apy.test.js +37 -1
  22. package/dist/cjs/ws/client.handshake.integration.test.js +2 -1
  23. package/dist/cjs/ws/client.js +32 -14
  24. package/dist/cjs/ws/client.test.js +5 -1
  25. package/dist/generated/instructions/closeOracle.d.ts +5 -10
  26. package/dist/generated/instructions/closeOracle.js +2 -13
  27. package/dist/generated/instructions/createMarket.d.ts +11 -21
  28. package/dist/generated/instructions/createMarket.js +1 -10
  29. package/dist/generated/instructions/createOracle.d.ts +7 -12
  30. package/dist/generated/instructions/createOracle.js +1 -4
  31. package/dist/generated/instructions/depositFundsToPosition.d.ts +9 -14
  32. package/dist/generated/instructions/depositFundsToPosition.js +5 -11
  33. package/dist/generated/instructions/finalizeMarket.d.ts +4 -9
  34. package/dist/generated/instructions/finalizeMarket.js +1 -9
  35. package/dist/generated/instructions/updateOraclePrice.d.ts +5 -10
  36. package/dist/generated/instructions/updateOraclePrice.js +2 -13
  37. package/dist/idl/acta_contract.json +5 -61
  38. package/dist/idl/hash.d.ts +1 -1
  39. package/dist/idl/hash.js +1 -1
  40. package/dist/ws/apy.d.ts +1 -1
  41. package/dist/ws/apy.js +4 -10
  42. package/dist/ws/apy.test.js +37 -1
  43. package/dist/ws/client.d.ts +16 -4
  44. package/dist/ws/client.handshake.integration.test.js +2 -1
  45. package/dist/ws/client.js +32 -14
  46. package/dist/ws/client.test.js +5 -1
  47. package/dist/ws/types.d.ts +20 -0
  48. package/package.json +1 -1
@@ -38,12 +38,8 @@ export function getDepositFundsToPositionInstruction(input, config) {
38
38
  value: input.posSettlementAta ?? null,
39
39
  isWritable: true,
40
40
  },
41
- underlyingTokenProgram: {
42
- value: input.underlyingTokenProgram ?? null,
43
- isWritable: false,
44
- },
45
- quoteTokenProgram: {
46
- value: input.quoteTokenProgram ?? null,
41
+ settlementTokenProgram: {
42
+ value: input.settlementTokenProgram ?? null,
47
43
  isWritable: false,
48
44
  },
49
45
  };
@@ -57,15 +53,14 @@ export function getDepositFundsToPositionInstruction(input, config) {
57
53
  getAccountMeta(accounts.marketPda),
58
54
  getAccountMeta(accounts.makerFundingAta),
59
55
  getAccountMeta(accounts.posSettlementAta),
60
- getAccountMeta(accounts.underlyingTokenProgram),
61
- getAccountMeta(accounts.quoteTokenProgram),
56
+ getAccountMeta(accounts.settlementTokenProgram),
62
57
  ],
63
58
  data: getDepositFundsToPositionInstructionDataEncoder().encode({}),
64
59
  programAddress,
65
60
  });
66
61
  }
67
62
  export function parseDepositFundsToPositionInstruction(instruction) {
68
- if (instruction.accounts.length < 8) {
63
+ if (instruction.accounts.length < 7) {
69
64
  // TODO: Coded error.
70
65
  throw new Error("Not enough accounts");
71
66
  }
@@ -84,8 +79,7 @@ export function parseDepositFundsToPositionInstruction(instruction) {
84
79
  marketPda: getNextAccount(),
85
80
  makerFundingAta: getNextAccount(),
86
81
  posSettlementAta: getNextAccount(),
87
- underlyingTokenProgram: getNextAccount(),
88
- quoteTokenProgram: getNextAccount(),
82
+ settlementTokenProgram: getNextAccount(),
89
83
  },
90
84
  data: getDepositFundsToPositionInstructionDataDecoder().decode(instruction.data),
91
85
  };
@@ -9,13 +9,12 @@ import { type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeC
9
9
  import { ACTA_CONTRACT_PROGRAM_ADDRESS } from "../programs";
10
10
  export declare const FINALIZE_MARKET_DISCRIMINATOR = 8;
11
11
  export declare function getFinalizeMarketDiscriminatorBytes(): ReadonlyUint8Array;
12
- export type FinalizeMarketInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta<string> = string, TAccountMarketPda extends string | AccountMeta<string> = string, TAccountConfigPda extends string | AccountMeta<string> = string, TAccountOracleUnderlying extends string | AccountMeta<string> = string, TAccountOracleQuote extends string | AccountMeta<string> = string, TAccountClockSysvar extends string | AccountMeta<string> = "SysvarC1ock11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[
12
+ export type FinalizeMarketInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta<string> = string, TAccountMarketPda extends string | AccountMeta<string> = string, TAccountConfigPda extends string | AccountMeta<string> = string, TAccountOracleUnderlying extends string | AccountMeta<string> = string, TAccountOracleQuote extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[
13
13
  TAccountAdmin extends string ? ReadonlySignerAccount<TAccountAdmin> & AccountSignerMeta<TAccountAdmin> : TAccountAdmin,
14
14
  TAccountMarketPda extends string ? WritableAccount<TAccountMarketPda> : TAccountMarketPda,
15
15
  TAccountConfigPda extends string ? ReadonlyAccount<TAccountConfigPda> : TAccountConfigPda,
16
16
  TAccountOracleUnderlying extends string ? ReadonlyAccount<TAccountOracleUnderlying> : TAccountOracleUnderlying,
17
17
  TAccountOracleQuote extends string ? ReadonlyAccount<TAccountOracleQuote> : TAccountOracleQuote,
18
- TAccountClockSysvar extends string ? ReadonlyAccount<TAccountClockSysvar> : TAccountClockSysvar,
19
18
  ...TRemainingAccounts
20
19
  ]>;
21
20
  export type FinalizeMarketInstructionData = {
@@ -25,7 +24,7 @@ export type FinalizeMarketInstructionDataArgs = {};
25
24
  export declare function getFinalizeMarketInstructionDataEncoder(): FixedSizeEncoder<FinalizeMarketInstructionDataArgs>;
26
25
  export declare function getFinalizeMarketInstructionDataDecoder(): FixedSizeDecoder<FinalizeMarketInstructionData>;
27
26
  export declare function getFinalizeMarketInstructionDataCodec(): FixedSizeCodec<FinalizeMarketInstructionDataArgs, FinalizeMarketInstructionData>;
28
- export type FinalizeMarketInput<TAccountAdmin extends string = string, TAccountMarketPda extends string = string, TAccountConfigPda extends string = string, TAccountOracleUnderlying extends string = string, TAccountOracleQuote extends string = string, TAccountClockSysvar extends string = string> = {
27
+ export type FinalizeMarketInput<TAccountAdmin extends string = string, TAccountMarketPda extends string = string, TAccountConfigPda extends string = string, TAccountOracleUnderlying extends string = string, TAccountOracleQuote extends string = string> = {
29
28
  /** Protocol admin authority */
30
29
  admin: TransactionSigner<TAccountAdmin>;
31
30
  /** Market PDA to finalize */
@@ -36,12 +35,10 @@ export type FinalizeMarketInput<TAccountAdmin extends string = string, TAccountM
36
35
  oracleUnderlying: Address<TAccountOracleUnderlying>;
37
36
  /** Quote oracle PDA */
38
37
  oracleQuote: Address<TAccountOracleQuote>;
39
- /** Clock sysvar account */
40
- clockSysvar?: Address<TAccountClockSysvar>;
41
38
  };
42
- export declare function getFinalizeMarketInstruction<TAccountAdmin extends string, TAccountMarketPda extends string, TAccountConfigPda extends string, TAccountOracleUnderlying extends string, TAccountOracleQuote extends string, TAccountClockSysvar extends string, TProgramAddress extends Address = typeof ACTA_CONTRACT_PROGRAM_ADDRESS>(input: FinalizeMarketInput<TAccountAdmin, TAccountMarketPda, TAccountConfigPda, TAccountOracleUnderlying, TAccountOracleQuote, TAccountClockSysvar>, config?: {
39
+ export declare function getFinalizeMarketInstruction<TAccountAdmin extends string, TAccountMarketPda extends string, TAccountConfigPda extends string, TAccountOracleUnderlying extends string, TAccountOracleQuote extends string, TProgramAddress extends Address = typeof ACTA_CONTRACT_PROGRAM_ADDRESS>(input: FinalizeMarketInput<TAccountAdmin, TAccountMarketPda, TAccountConfigPda, TAccountOracleUnderlying, TAccountOracleQuote>, config?: {
43
40
  programAddress?: TProgramAddress;
44
- }): FinalizeMarketInstruction<TProgramAddress, TAccountAdmin, TAccountMarketPda, TAccountConfigPda, TAccountOracleUnderlying, TAccountOracleQuote, TAccountClockSysvar>;
41
+ }): FinalizeMarketInstruction<TProgramAddress, TAccountAdmin, TAccountMarketPda, TAccountConfigPda, TAccountOracleUnderlying, TAccountOracleQuote>;
45
42
  export type ParsedFinalizeMarketInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = {
46
43
  programAddress: Address<TProgram>;
47
44
  accounts: {
@@ -55,8 +52,6 @@ export type ParsedFinalizeMarketInstruction<TProgram extends string = typeof ACT
55
52
  oracleUnderlying: TAccountMetas[3];
56
53
  /** Quote oracle PDA */
57
54
  oracleQuote: TAccountMetas[4];
58
- /** Clock sysvar account */
59
- clockSysvar: TAccountMetas[5];
60
55
  };
61
56
  data: FinalizeMarketInstructionData;
62
57
  };
@@ -34,14 +34,8 @@ export function getFinalizeMarketInstruction(input, config) {
34
34
  isWritable: false,
35
35
  },
36
36
  oracleQuote: { value: input.oracleQuote ?? null, isWritable: false },
37
- clockSysvar: { value: input.clockSysvar ?? null, isWritable: false },
38
37
  };
39
38
  const accounts = originalAccounts;
40
- // Resolve default values.
41
- if (!accounts.clockSysvar.value) {
42
- accounts.clockSysvar.value =
43
- "SysvarC1ock11111111111111111111111111111111";
44
- }
45
39
  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
46
40
  return Object.freeze({
47
41
  accounts: [
@@ -50,14 +44,13 @@ export function getFinalizeMarketInstruction(input, config) {
50
44
  getAccountMeta(accounts.configPda),
51
45
  getAccountMeta(accounts.oracleUnderlying),
52
46
  getAccountMeta(accounts.oracleQuote),
53
- getAccountMeta(accounts.clockSysvar),
54
47
  ],
55
48
  data: getFinalizeMarketInstructionDataEncoder().encode({}),
56
49
  programAddress,
57
50
  });
58
51
  }
59
52
  export function parseFinalizeMarketInstruction(instruction) {
60
- if (instruction.accounts.length < 6) {
53
+ if (instruction.accounts.length < 5) {
61
54
  // TODO: Coded error.
62
55
  throw new Error("Not enough accounts");
63
56
  }
@@ -75,7 +68,6 @@ export function parseFinalizeMarketInstruction(instruction) {
75
68
  configPda: getNextAccount(),
76
69
  oracleUnderlying: getNextAccount(),
77
70
  oracleQuote: getNextAccount(),
78
- clockSysvar: getNextAccount(),
79
71
  },
80
72
  data: getFinalizeMarketInstructionDataDecoder().decode(instruction.data),
81
73
  };
@@ -5,14 +5,13 @@
5
5
  *
6
6
  * @see https://github.com/codama-idl/codama
7
7
  */
8
- import { type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from "@solana/kit";
8
+ import { type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from "@solana/kit";
9
9
  import { ACTA_CONTRACT_PROGRAM_ADDRESS } from "../programs";
10
10
  export declare const UPDATE_ORACLE_PRICE_DISCRIMINATOR = 16;
11
11
  export declare function getUpdateOraclePriceDiscriminatorBytes(): ReadonlyUint8Array;
12
- export type UpdateOraclePriceInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountOraclePda extends string | AccountMeta<string> = string, TAccountClockSysvar extends string | AccountMeta<string> = "SysvarC1ock11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[
12
+ export type UpdateOraclePriceInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountOraclePda extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[
13
13
  TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority> : TAccountAuthority,
14
14
  TAccountOraclePda extends string ? WritableAccount<TAccountOraclePda> : TAccountOraclePda,
15
- TAccountClockSysvar extends string ? ReadonlyAccount<TAccountClockSysvar> : TAccountClockSysvar,
16
15
  ...TRemainingAccounts
17
16
  ]>;
18
17
  export type UpdateOraclePriceInstructionData = {
@@ -27,19 +26,17 @@ export type UpdateOraclePriceInstructionDataArgs = {
27
26
  export declare function getUpdateOraclePriceInstructionDataEncoder(): FixedSizeEncoder<UpdateOraclePriceInstructionDataArgs>;
28
27
  export declare function getUpdateOraclePriceInstructionDataDecoder(): FixedSizeDecoder<UpdateOraclePriceInstructionData>;
29
28
  export declare function getUpdateOraclePriceInstructionDataCodec(): FixedSizeCodec<UpdateOraclePriceInstructionDataArgs, UpdateOraclePriceInstructionData>;
30
- export type UpdateOraclePriceInput<TAccountAuthority extends string = string, TAccountOraclePda extends string = string, TAccountClockSysvar extends string = string> = {
29
+ export type UpdateOraclePriceInput<TAccountAuthority extends string = string, TAccountOraclePda extends string = string> = {
31
30
  /** Oracle authority signer (or protocol admin) */
32
31
  authority: TransactionSigner<TAccountAuthority>;
33
32
  /** Oracle PDA to update */
34
33
  oraclePda: Address<TAccountOraclePda>;
35
- /** Clock sysvar account */
36
- clockSysvar?: Address<TAccountClockSysvar>;
37
34
  price: UpdateOraclePriceInstructionDataArgs["price"];
38
35
  settledExpiryTs: UpdateOraclePriceInstructionDataArgs["settledExpiryTs"];
39
36
  };
40
- export declare function getUpdateOraclePriceInstruction<TAccountAuthority extends string, TAccountOraclePda extends string, TAccountClockSysvar extends string, TProgramAddress extends Address = typeof ACTA_CONTRACT_PROGRAM_ADDRESS>(input: UpdateOraclePriceInput<TAccountAuthority, TAccountOraclePda, TAccountClockSysvar>, config?: {
37
+ export declare function getUpdateOraclePriceInstruction<TAccountAuthority extends string, TAccountOraclePda extends string, TProgramAddress extends Address = typeof ACTA_CONTRACT_PROGRAM_ADDRESS>(input: UpdateOraclePriceInput<TAccountAuthority, TAccountOraclePda>, config?: {
41
38
  programAddress?: TProgramAddress;
42
- }): UpdateOraclePriceInstruction<TProgramAddress, TAccountAuthority, TAccountOraclePda, TAccountClockSysvar>;
39
+ }): UpdateOraclePriceInstruction<TProgramAddress, TAccountAuthority, TAccountOraclePda>;
43
40
  export type ParsedUpdateOraclePriceInstruction<TProgram extends string = typeof ACTA_CONTRACT_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = {
44
41
  programAddress: Address<TProgram>;
45
42
  accounts: {
@@ -47,8 +44,6 @@ export type ParsedUpdateOraclePriceInstruction<TProgram extends string = typeof
47
44
  authority: TAccountMetas[0];
48
45
  /** Oracle PDA to update */
49
46
  oraclePda: TAccountMetas[1];
50
- /** Clock sysvar account */
51
- clockSysvar: TAccountMetas[2];
52
47
  };
53
48
  data: UpdateOraclePriceInstructionData;
54
49
  };
@@ -36,29 +36,22 @@ export function getUpdateOraclePriceInstruction(input, config) {
36
36
  const originalAccounts = {
37
37
  authority: { value: input.authority ?? null, isWritable: false },
38
38
  oraclePda: { value: input.oraclePda ?? null, isWritable: true },
39
- clockSysvar: { value: input.clockSysvar ?? null, isWritable: false },
40
39
  };
41
40
  const accounts = originalAccounts;
42
41
  // Original args.
43
42
  const args = { ...input };
44
- // Resolve default values.
45
- if (!accounts.clockSysvar.value) {
46
- accounts.clockSysvar.value =
47
- "SysvarC1ock11111111111111111111111111111111";
48
- }
49
43
  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
50
44
  return Object.freeze({
51
45
  accounts: [
52
46
  getAccountMeta(accounts.authority),
53
47
  getAccountMeta(accounts.oraclePda),
54
- getAccountMeta(accounts.clockSysvar),
55
48
  ],
56
49
  data: getUpdateOraclePriceInstructionDataEncoder().encode(args),
57
50
  programAddress,
58
51
  });
59
52
  }
60
53
  export function parseUpdateOraclePriceInstruction(instruction) {
61
- if (instruction.accounts.length < 3) {
54
+ if (instruction.accounts.length < 2) {
62
55
  // TODO: Coded error.
63
56
  throw new Error("Not enough accounts");
64
57
  }
@@ -70,11 +63,7 @@ export function parseUpdateOraclePriceInstruction(instruction) {
70
63
  };
71
64
  return {
72
65
  programAddress: instruction.programAddress,
73
- accounts: {
74
- authority: getNextAccount(),
75
- oraclePda: getNextAccount(),
76
- clockSysvar: getNextAccount(),
77
- },
66
+ accounts: { authority: getNextAccount(), oraclePda: getNextAccount() },
78
67
  data: getUpdateOraclePriceInstructionDataDecoder().decode(instruction.data),
79
68
  };
80
69
  }
@@ -344,7 +344,7 @@
344
344
  "isMut": false,
345
345
  "isSigner": false,
346
346
  "docs": [
347
- "Underlying SPL mint"
347
+ "Underlying SPL mint (used for PDA seed and decimals)"
348
348
  ]
349
349
  },
350
350
  {
@@ -352,23 +352,7 @@
352
352
  "isMut": false,
353
353
  "isSigner": false,
354
354
  "docs": [
355
- "Quote SPL mint"
356
- ]
357
- },
358
- {
359
- "name": "underlyingMintAcc",
360
- "isMut": false,
361
- "isSigner": false,
362
- "docs": [
363
- "Underlying mint account (for decimals)"
364
- ]
365
- },
366
- {
367
- "name": "quoteMintAcc",
368
- "isMut": false,
369
- "isSigner": false,
370
- "docs": [
371
- "Quote mint account (for decimals)"
355
+ "Quote SPL mint (used for PDA seed and decimals)"
372
356
  ]
373
357
  },
374
358
  {
@@ -617,14 +601,6 @@
617
601
  "docs": [
618
602
  "Quote oracle PDA"
619
603
  ]
620
- },
621
- {
622
- "name": "clockSysvar",
623
- "isMut": false,
624
- "isSigner": false,
625
- "docs": [
626
- "Clock sysvar account"
627
- ]
628
604
  }
629
605
  ],
630
606
  "args": [],
@@ -685,19 +661,11 @@
685
661
  ]
686
662
  },
687
663
  {
688
- "name": "underlyingTokenProgram",
689
- "isMut": false,
690
- "isSigner": false,
691
- "docs": [
692
- "Token program for underlying mint"
693
- ]
694
- },
695
- {
696
- "name": "quoteTokenProgram",
664
+ "name": "settlementTokenProgram",
697
665
  "isMut": false,
698
666
  "isSigner": false,
699
667
  "docs": [
700
- "Token program for quote mint"
668
+ "Token program for the settlement mint"
701
669
  ]
702
670
  }
703
671
  ],
@@ -1063,15 +1031,7 @@
1063
1031
  "isMut": false,
1064
1032
  "isSigner": false,
1065
1033
  "docs": [
1066
- "SPL mint this oracle prices"
1067
- ]
1068
- },
1069
- {
1070
- "name": "mintAcc",
1071
- "isMut": false,
1072
- "isSigner": false,
1073
- "docs": [
1074
- "Mint account (for decimals + token program owner)"
1034
+ "SPL mint this oracle prices (also used for decimals + token program owner)"
1075
1035
  ]
1076
1036
  },
1077
1037
  {
@@ -1129,14 +1089,6 @@
1129
1089
  "docs": [
1130
1090
  "Oracle PDA to update"
1131
1091
  ]
1132
- },
1133
- {
1134
- "name": "clockSysvar",
1135
- "isMut": false,
1136
- "isSigner": false,
1137
- "docs": [
1138
- "Clock sysvar account"
1139
- ]
1140
1092
  }
1141
1093
  ],
1142
1094
  "args": [
@@ -1251,14 +1203,6 @@
1251
1203
  "docs": [
1252
1204
  "Oracle PDA to close"
1253
1205
  ]
1254
- },
1255
- {
1256
- "name": "clockSysvar",
1257
- "isMut": false,
1258
- "isSigner": false,
1259
- "docs": [
1260
- "Clock sysvar account"
1261
- ]
1262
1206
  }
1263
1207
  ],
1264
1208
  "args": [],
@@ -1 +1 @@
1
- export declare const ACTA_IDL_SHA256 = "8072bc43541635b8c359d8c0209c3ab63f6a264d6843997d20c9d6c9473130c9";
1
+ export declare const ACTA_IDL_SHA256 = "34f93515df3ceed9854715fb73e9fe0de615383e5ff3f0d627ecd029e65e5688";
package/dist/idl/hash.js CHANGED
@@ -1 +1 @@
1
- export const ACTA_IDL_SHA256 = "8072bc43541635b8c359d8c0209c3ab63f6a264d6843997d20c9d6c9473130c9";
1
+ export const ACTA_IDL_SHA256 = "34f93515df3ceed9854715fb73e9fe0de615383e5ff3f0d627ecd029e65e5688";
package/dist/ws/apy.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function computeApyFromAmounts(args: {
42
42
  premiumPerUnderlying: number;
43
43
  /** for puts: strike price per 1 underlying (quote units) */
44
44
  strikePrice: number;
45
- /** for calls: current spot price per 1 underlying (quote units) */
45
+ /** current spot price per 1 underlying (quote units), required for both calls and puts */
46
46
  spotPrice?: number;
47
47
  /** seconds to option expiry (market expiry, not RFQ TTL) */
48
48
  secondsToExpiry: number;
package/dist/ws/apy.js CHANGED
@@ -50,17 +50,11 @@ export function computeApyFromAmounts(args) {
50
50
  if (!Number.isFinite(premPU) || premPU < 0)
51
51
  throw new Error("invalid premiumPerUnderlying");
52
52
  const premiumNotional = qty * premPU;
53
- let collateralPerUnderlying;
54
- if (args.positionType === "cash_secured_put") {
55
- collateralPerUnderlying = args.strikePrice;
56
- }
57
- else {
58
- collateralPerUnderlying = args.spotPrice ?? NaN;
59
- }
53
+ // Collateral always valued at spot so APR is monotonic across strikes.
54
+ // On-chain collateral requirements are unchanged — display metric only.
55
+ const collateralPerUnderlying = args.spotPrice ?? NaN;
60
56
  if (!Number.isFinite(collateralPerUnderlying) || collateralPerUnderlying <= 0) {
61
- throw new Error(args.positionType === "covered_call"
62
- ? "spotPrice is required for covered_call yield"
63
- : "invalid strikePrice");
57
+ throw new Error("spotPrice is required for yield calculation");
64
58
  }
65
59
  const collateralNotional = qty * collateralPerUnderlying;
66
60
  const termYield = termYieldFromNotionals({ premiumNotional, collateralNotional });
@@ -5,7 +5,7 @@ describe("ws apy helpers", () => {
5
5
  positionType: "covered_call",
6
6
  underlyingAmount: 10,
7
7
  spotPrice: 150,
8
- strikePrice: 150, // not used for calls
8
+ strikePrice: 150, // not used for collateral, kept for API compat
9
9
  premiumPerUnderlying: 1.5,
10
10
  secondsToExpiry: 7 * 24 * 60 * 60,
11
11
  });
@@ -20,8 +20,44 @@ describe("ws apy helpers", () => {
20
20
  underlyingAmount: 10,
21
21
  grossPremiumPerUnit1e9: 1_500_000_000, // 1.5
22
22
  strike1e9: 150_000_000_000, // 150
23
+ spotPrice1e9: 150_000_000_000, // 150 (ATM)
23
24
  secondsToExpiry: 7 * 24 * 60 * 60,
24
25
  });
25
26
  expect(res.premiumNotional).toBeCloseTo(15, 10);
26
27
  });
28
+ it("put APR uses spot as collateral (not strike)", () => {
29
+ const spot = 150;
30
+ const strike = 120; // OTM put
31
+ const res = computeApyFromAmounts({
32
+ positionType: "cash_secured_put",
33
+ underlyingAmount: 1,
34
+ spotPrice: spot,
35
+ strikePrice: strike,
36
+ premiumPerUnderlying: 1.5,
37
+ secondsToExpiry: 30 * 24 * 60 * 60,
38
+ });
39
+ // collateral should be spot-based, not strike-based
40
+ expect(res.collateralNotional).toBeCloseTo(spot, 10);
41
+ });
42
+ it("put APR is monotonically decreasing for OTM strikes", () => {
43
+ const spot1e9 = 150_000_000_000; // 150
44
+ const strikes = [140, 130, 120, 110].map(s => s * 1_000_000_000);
45
+ // Premiums decrease with OTM (roughly realistic)
46
+ const premiums = [5, 2.5, 1, 0.3].map(p => p * 1_000_000_000);
47
+ const aprs = strikes.map((strike, i) => {
48
+ const res = computeApyFromScaledPrices({
49
+ positionType: "cash_secured_put",
50
+ underlyingAmount: 1,
51
+ grossPremiumPerUnit1e9: premiums[i],
52
+ strike1e9: strike,
53
+ spotPrice1e9: spot1e9,
54
+ secondsToExpiry: 30 * 24 * 60 * 60,
55
+ });
56
+ return res.apr;
57
+ });
58
+ // Each APR should be less than the previous
59
+ for (let i = 1; i < aprs.length; i++) {
60
+ expect(aprs[i]).toBeLessThan(aprs[i - 1]);
61
+ }
62
+ });
27
63
  });
@@ -2,7 +2,7 @@
2
2
  import type { AuthProvider } from "./auth";
3
3
  import type { SignerLike } from "../chain/orders";
4
4
  import type { Address } from "@solana/addresses";
5
- import type { ActiveRfqInfo, ChainEventMessage, EarnSummaryData, TokenMarketsInfoData, GlobalStats, MarketDescriptorInfo, MarketInfo, MyActiveRfqInfo, MyActiveRfqsMessage, OrderStatusMessage, PositionInfo, QuoteAcknowledgedMessage, QuoteBestStatusMessage, QuoteCancelledMessage, QuoteMessage, QuoteRefreshRequestedMessage, QuoteOutbidMessage, QuoteReceivedMessage, QuoteSelectedMessage, QuotesUpdateMessage, RfqBroadcastMessage, RfqClosedMessage, RfqCreatedMessage, RfqSkippedMessage, RfqRequestMessage, RfqAvailableAgainMessage, QuoteExpiredMessage, QuoteFilledMessage, IndicativePricesMessage, IndicativePricesRequestMessage, IndicativePricesResponseMessage, GetIndicativePricesMessage, RequestId, ServerMessage, SnapshotMessage, StatsDelta, SubscriptionsMessage, TokenInfo, TradeInfo, UuidString, VersionMismatchMessage, WelcomeMessage, WsChannel } from "./types";
5
+ import type { ActiveRfqInfo, ChainEventMessage, EarnSummaryData, TokenMarketsInfoData, GlobalStats, MarketDescriptorInfo, MarketInfo, MyActiveRfqInfo, MyActiveRfqsMessage, OrderStatusMessage, PositionInfo, QuoteAcknowledgedMessage, QuoteBestStatusMessage, QuoteCancelledMessage, QuoteMessage, QuoteRefreshRequestedMessage, QuoteOutbidMessage, QuoteReceivedMessage, QuoteSelectedMessage, QuotesUpdateMessage, RfqBroadcastMessage, RfqClosedMessage, RfqCreatedMessage, RfqSkippedMessage, RfqRequestMessage, RfqAvailableAgainMessage, QuoteExpiredMessage, QuoteFilledMessage, IndicativePricesMessage, IndicativePricesRequestMessage, IndicativePricesResponseMessage, GetIndicativePricesMessage, RequestId, ServerError, ServerMessage, SnapshotMessage, StatsDelta, SubscriptionsMessage, TokenInfo, TradeInfo, UuidString, VersionMismatchMessage, WelcomeMessage, WsChannel } from "./types";
6
6
  export type ConnectionState = "disconnected" | "connecting" | "authenticating" | "authenticated" | "error";
7
7
  export type ClientRole = "taker" | "maker";
8
8
  export type PendingMessagesOverflowPolicy = "drop_oldest" | "drop_newest" | "throw";
@@ -60,7 +60,19 @@ export type ActaWsClientEvents = {
60
60
  authError: (reason: string, message?: string) => void;
61
61
  logoutSuccess: () => void;
62
62
  disconnected: (code: number, reason: string) => void;
63
- error: (error: Error) => void;
63
+ error: (error: ServerError) => void;
64
+ requestError: (data: {
65
+ request_id: RequestId;
66
+ error: ServerError;
67
+ }) => void;
68
+ subscribeAck: (data: {
69
+ request_id: RequestId;
70
+ subscribed: WsChannel[];
71
+ }) => void;
72
+ unsubscribeAck: (data: {
73
+ request_id: RequestId;
74
+ unsubscribed: WsChannel[];
75
+ }) => void;
64
76
  stateChange: (state: ConnectionState) => void;
65
77
  message: (message: ServerMessage) => void;
66
78
  snapshot: (snapshot: SnapshotMessage) => void;
@@ -241,8 +253,8 @@ export declare class ActaWsClient extends TypedEventEmitter<ActaWsClientEvents>
241
253
  makerSigner: SignerLike;
242
254
  }): Promise<void>;
243
255
  cancelQuote(rfqId: string): RequestId;
244
- subscribe(channels: WsChannel[], markets?: string[]): void;
245
- unsubscribe(channels: WsChannel[]): void;
256
+ subscribe(channels: WsChannel[], markets?: string[]): RequestId;
257
+ unsubscribe(channels: WsChannel[]): RequestId;
246
258
  ping(): void;
247
259
  resumeAuth(sessionId: string): void;
248
260
  private doConnect;
@@ -50,7 +50,8 @@ describeIfWsUrl("ws handshake integration (real backend)", () => {
50
50
  });
51
51
  client.on("error", (err) => {
52
52
  if (!welcomeReceived) {
53
- finish(err);
53
+ const msg = err.type === "generic" ? err.data.message : err.type;
54
+ finish(new Error(msg));
54
55
  }
55
56
  });
56
57
  client.on("disconnected", (code, reason) => {
package/dist/ws/client.js CHANGED
@@ -1,6 +1,10 @@
1
1
  /** Acta WebSocket client (rfq-server). */
2
2
  import { buildSignedQuoteMessage, buildAcceptQuoteMessage } from "./flows";
3
3
  import { assertWsU64Safe, validateQuantityBySizeRule } from "./wirePolicy";
4
+ function toGenericServerError(err) {
5
+ const message = err instanceof Error ? err.message : String(err);
6
+ return { type: "generic", data: { code: "client_error", message } };
7
+ }
4
8
  function formatServerError(error) {
5
9
  if (error.type === "generic") {
6
10
  return `${error.data.code}: ${error.data.message}`;
@@ -157,7 +161,7 @@ export class ActaWsClient extends TypedEventEmitter {
157
161
  if (this.ws?.readyState === WS_OPEN) {
158
162
  if (this.welcomeReceived && !this.startAuthSent) {
159
163
  void this.beginAuthHandshake().catch((err) => {
160
- this.emit("error", err);
164
+ this.emit("error", toGenericServerError(err));
161
165
  this.setConnectionState("error");
162
166
  });
163
167
  }
@@ -390,6 +394,7 @@ export class ActaWsClient extends TypedEventEmitter {
390
394
  }
391
395
  subscribe(channels, markets) {
392
396
  this.ensureAuthenticated();
397
+ const request_id = this.nextRequestId();
393
398
  for (const c of channels)
394
399
  this.subscribedChannels.add(c);
395
400
  if (markets) {
@@ -399,18 +404,21 @@ export class ActaWsClient extends TypedEventEmitter {
399
404
  this.send({
400
405
  type: "Subscribe",
401
406
  data: this.hasMarketScope
402
- ? { channels, markets: Array.from(this.subscribedMarkets) }
403
- : { channels },
407
+ ? { request_id, channels, markets: Array.from(this.subscribedMarkets) }
408
+ : { request_id, channels },
404
409
  });
410
+ return request_id;
405
411
  }
406
412
  unsubscribe(channels) {
407
413
  this.ensureAuthenticated();
414
+ const request_id = this.nextRequestId();
408
415
  for (const c of channels)
409
416
  this.subscribedChannels.delete(c);
410
417
  this.send({
411
418
  type: "Unsubscribe",
412
- data: { channels },
419
+ data: { request_id, channels },
413
420
  });
421
+ return request_id;
414
422
  }
415
423
  ping() {
416
424
  if (this.ws?.readyState === WS_OPEN) {
@@ -465,7 +473,7 @@ export class ActaWsClient extends TypedEventEmitter {
465
473
  };
466
474
  ws.onerror = (ev) => {
467
475
  this.log("WebSocket error:", ev);
468
- this.emit("error", new Error("WebSocket error"));
476
+ this.emit("error", toGenericServerError("WebSocket error"));
469
477
  if (this.shouldReconnect) {
470
478
  this.cleanup();
471
479
  this.scheduleReconnect();
@@ -482,7 +490,7 @@ export class ActaWsClient extends TypedEventEmitter {
482
490
  this.flushPendingMessages();
483
491
  if (this.authRequested && this.authProvider && !this.startAuthSent) {
484
492
  void this.beginAuthHandshake().catch((err) => {
485
- this.emit("error", err);
493
+ this.emit("error", toGenericServerError(err));
486
494
  this.setConnectionState("error");
487
495
  });
488
496
  }
@@ -708,7 +716,16 @@ export class ActaWsClient extends TypedEventEmitter {
708
716
  case "Pong":
709
717
  break;
710
718
  case "Error":
711
- this.emit("error", new Error(formatServerError(message.data)));
719
+ this.emit("error", message.data);
720
+ break;
721
+ case "RequestError":
722
+ this.emit("requestError", message.data);
723
+ break;
724
+ case "SubscribeAck":
725
+ this.emit("subscribeAck", message.data);
726
+ break;
727
+ case "UnsubscribeAck":
728
+ this.emit("unsubscribeAck", message.data);
712
729
  break;
713
730
  }
714
731
  }
@@ -729,7 +746,7 @@ export class ActaWsClient extends TypedEventEmitter {
729
746
  async handleAuthRequest(challenge) {
730
747
  this.setConnectionState("authenticating");
731
748
  if (!this.authProvider) {
732
- this.emit("error", new Error("No auth provider configured"));
749
+ this.emit("error", toGenericServerError("No auth provider configured"));
733
750
  return;
734
751
  }
735
752
  try {
@@ -743,7 +760,7 @@ export class ActaWsClient extends TypedEventEmitter {
743
760
  });
744
761
  }
745
762
  catch (err) {
746
- this.emit("error", err);
763
+ this.emit("error", toGenericServerError(err));
747
764
  this.setConnectionState("error");
748
765
  }
749
766
  }
@@ -794,9 +811,10 @@ export class ActaWsClient extends TypedEventEmitter {
794
811
  this.emit("authenticated", sessionId, expiresAt);
795
812
  if (this.subscribedChannels.size > 0) {
796
813
  const channels = Array.from(this.subscribedChannels);
814
+ const request_id = this.nextRequestId();
797
815
  const data = this.hasMarketScope
798
- ? { channels, markets: Array.from(this.subscribedMarkets) }
799
- : { channels };
816
+ ? { request_id, channels, markets: Array.from(this.subscribedMarkets) }
817
+ : { request_id, channels };
800
818
  this.send({ type: "Subscribe", data });
801
819
  }
802
820
  }
@@ -810,14 +828,14 @@ export class ActaWsClient extends TypedEventEmitter {
810
828
  this.lastAuthSessionId = null;
811
829
  this.startAuthSent = false;
812
830
  void this.sendStartAuth().catch((err) => {
813
- this.emit("error", err);
831
+ this.emit("error", toGenericServerError(err));
814
832
  this.setConnectionState("error");
815
833
  });
816
834
  return;
817
835
  }
818
836
  this.setConnectionState("error");
819
837
  const details = message ? `${reason}: ${message}` : reason;
820
- this.emit("error", new Error(`Authentication failed: ${details}`));
838
+ this.emit("error", toGenericServerError(`Authentication failed: ${details}`));
821
839
  }
822
840
  handleSnapshot(snapshot) {
823
841
  this.state.markets.clear();
@@ -956,7 +974,7 @@ export class ActaWsClient extends TypedEventEmitter {
956
974
  this.log("Pending queue full, dropping newest message:", message.type);
957
975
  return false;
958
976
  case "throw":
959
- this.emit("error", new Error(`Pending queue overflow (maxPendingMessages=${maxPending}) for message type=${message.type}`));
977
+ this.emit("error", toGenericServerError(`Pending queue overflow (maxPendingMessages=${maxPending}) for message type=${message.type}`));
960
978
  return false;
961
979
  }
962
980
  }
@@ -418,7 +418,11 @@ describe("ActaWsClient", () => {
418
418
  client.getMarkets();
419
419
  client.getTokens();
420
420
  expect(errors).toHaveLength(1);
421
- expect(errors[0].message).toContain("Pending queue overflow");
421
+ const err0 = errors[0];
422
+ expect(err0.type).toBe("generic");
423
+ if (err0.type === "generic") {
424
+ expect(err0.data.message).toContain("Pending queue overflow");
425
+ }
422
426
  ws.triggerMessage(WELCOME_MESSAGE);
423
427
  const flushedTypes = ws.sent
424
428
  .slice(1)