@acta-markets/ts-sdk 0.0.19-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 (40) 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/generated/instructions/closeOracle.d.ts +5 -10
  23. package/dist/generated/instructions/closeOracle.js +2 -13
  24. package/dist/generated/instructions/createMarket.d.ts +11 -21
  25. package/dist/generated/instructions/createMarket.js +1 -10
  26. package/dist/generated/instructions/createOracle.d.ts +7 -12
  27. package/dist/generated/instructions/createOracle.js +1 -4
  28. package/dist/generated/instructions/depositFundsToPosition.d.ts +9 -14
  29. package/dist/generated/instructions/depositFundsToPosition.js +5 -11
  30. package/dist/generated/instructions/finalizeMarket.d.ts +4 -9
  31. package/dist/generated/instructions/finalizeMarket.js +1 -9
  32. package/dist/generated/instructions/updateOraclePrice.d.ts +5 -10
  33. package/dist/generated/instructions/updateOraclePrice.js +2 -13
  34. package/dist/idl/acta_contract.json +5 -61
  35. package/dist/idl/hash.d.ts +1 -1
  36. package/dist/idl/hash.js +1 -1
  37. package/dist/ws/apy.d.ts +1 -1
  38. package/dist/ws/apy.js +4 -10
  39. package/dist/ws/apy.test.js +37 -1
  40. package/package.json +1 -1
@@ -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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acta-markets/ts-sdk",
3
- "version": "0.0.19-beta",
3
+ "version": "0.0.20-beta",
4
4
  "description": "TypeScript SDK for Acta Protocol",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",