@bench.games/conviction-markets 0.1.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.
Files changed (107) hide show
  1. package/README.md +298 -0
  2. package/dist/constants.d.ts +29 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +29 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/idl/conviction_market.d.ts +3760 -0
  7. package/dist/idl/conviction_market.d.ts.map +1 -0
  8. package/dist/idl/conviction_market.js +2 -0
  9. package/dist/idl/conviction_market.js.map +1 -0
  10. package/dist/idl/conviction_market.json +3753 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +6 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/instructions/addMarketOption.d.ts +38 -0
  16. package/dist/instructions/addMarketOption.d.ts.map +1 -0
  17. package/dist/instructions/addMarketOption.js +30 -0
  18. package/dist/instructions/addMarketOption.js.map +1 -0
  19. package/dist/instructions/buyMarketShares.d.ts +47 -0
  20. package/dist/instructions/buyMarketShares.d.ts.map +1 -0
  21. package/dist/instructions/buyMarketShares.js +63 -0
  22. package/dist/instructions/buyMarketShares.js.map +1 -0
  23. package/dist/instructions/claimVoteTokens.d.ts +40 -0
  24. package/dist/instructions/claimVoteTokens.d.ts.map +1 -0
  25. package/dist/instructions/claimVoteTokens.js +49 -0
  26. package/dist/instructions/claimVoteTokens.js.map +1 -0
  27. package/dist/instructions/closeShareAccount.d.ts +36 -0
  28. package/dist/instructions/closeShareAccount.d.ts.map +1 -0
  29. package/dist/instructions/closeShareAccount.js +28 -0
  30. package/dist/instructions/closeShareAccount.js.map +1 -0
  31. package/dist/instructions/createMarket.d.ts +48 -0
  32. package/dist/instructions/createMarket.d.ts.map +1 -0
  33. package/dist/instructions/createMarket.js +64 -0
  34. package/dist/instructions/createMarket.js.map +1 -0
  35. package/dist/instructions/incrementOptionTally.d.ts +35 -0
  36. package/dist/instructions/incrementOptionTally.d.ts.map +1 -0
  37. package/dist/instructions/incrementOptionTally.js +27 -0
  38. package/dist/instructions/incrementOptionTally.js.map +1 -0
  39. package/dist/instructions/index.d.ts +13 -0
  40. package/dist/instructions/index.d.ts.map +1 -0
  41. package/dist/instructions/index.js +16 -0
  42. package/dist/instructions/index.js.map +1 -0
  43. package/dist/instructions/initShareAccount.d.ts +34 -0
  44. package/dist/instructions/initShareAccount.d.ts.map +1 -0
  45. package/dist/instructions/initShareAccount.js +33 -0
  46. package/dist/instructions/initShareAccount.js.map +1 -0
  47. package/dist/instructions/initVoteTokenAccount.d.ts +37 -0
  48. package/dist/instructions/initVoteTokenAccount.d.ts.map +1 -0
  49. package/dist/instructions/initVoteTokenAccount.js +48 -0
  50. package/dist/instructions/initVoteTokenAccount.js.map +1 -0
  51. package/dist/instructions/mintVoteTokens.d.ts +40 -0
  52. package/dist/instructions/mintVoteTokens.d.ts.map +1 -0
  53. package/dist/instructions/mintVoteTokens.js +49 -0
  54. package/dist/instructions/mintVoteTokens.js.map +1 -0
  55. package/dist/instructions/openMarket.d.ts +34 -0
  56. package/dist/instructions/openMarket.d.ts.map +1 -0
  57. package/dist/instructions/openMarket.js +29 -0
  58. package/dist/instructions/openMarket.js.map +1 -0
  59. package/dist/instructions/revealShares.d.ts +43 -0
  60. package/dist/instructions/revealShares.d.ts.map +1 -0
  61. package/dist/instructions/revealShares.js +47 -0
  62. package/dist/instructions/revealShares.js.map +1 -0
  63. package/dist/instructions/selectOption.d.ts +36 -0
  64. package/dist/instructions/selectOption.d.ts.map +1 -0
  65. package/dist/instructions/selectOption.js +28 -0
  66. package/dist/instructions/selectOption.js.map +1 -0
  67. package/dist/types/accounts.d.ts +104 -0
  68. package/dist/types/accounts.d.ts.map +1 -0
  69. package/dist/types/accounts.js +2 -0
  70. package/dist/types/accounts.js.map +1 -0
  71. package/dist/types/common.d.ts +21 -0
  72. package/dist/types/common.d.ts.map +1 -0
  73. package/dist/types/common.js +2 -0
  74. package/dist/types/common.js.map +1 -0
  75. package/dist/types/index.d.ts +3 -0
  76. package/dist/types/index.d.ts.map +1 -0
  77. package/dist/types/index.js +3 -0
  78. package/dist/types/index.js.map +1 -0
  79. package/dist/utils/arcium.d.ts +3 -0
  80. package/dist/utils/arcium.d.ts.map +1 -0
  81. package/dist/utils/arcium.js +6 -0
  82. package/dist/utils/arcium.js.map +1 -0
  83. package/dist/utils/awaitComputationFinalization.d.ts +37 -0
  84. package/dist/utils/awaitComputationFinalization.d.ts.map +1 -0
  85. package/dist/utils/awaitComputationFinalization.js +32 -0
  86. package/dist/utils/awaitComputationFinalization.js.map +1 -0
  87. package/dist/utils/computations.d.ts +27 -0
  88. package/dist/utils/computations.d.ts.map +1 -0
  89. package/dist/utils/computations.js +35 -0
  90. package/dist/utils/computations.js.map +1 -0
  91. package/dist/utils/encryption.d.ts +46 -0
  92. package/dist/utils/encryption.d.ts.map +1 -0
  93. package/dist/utils/encryption.js +53 -0
  94. package/dist/utils/encryption.js.map +1 -0
  95. package/dist/utils/index.d.ts +7 -0
  96. package/dist/utils/index.d.ts.map +1 -0
  97. package/dist/utils/index.js +7 -0
  98. package/dist/utils/index.js.map +1 -0
  99. package/dist/utils/keypairs.d.ts +20 -0
  100. package/dist/utils/keypairs.d.ts.map +1 -0
  101. package/dist/utils/keypairs.js +29 -0
  102. package/dist/utils/keypairs.js.map +1 -0
  103. package/dist/utils/pdas.d.ts +38 -0
  104. package/dist/utils/pdas.d.ts.map +1 -0
  105. package/dist/utils/pdas.js +57 -0
  106. package/dist/utils/pdas.js.map +1 -0
  107. package/package.json +45 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { BN } from "@coral-xyz/anchor";
2
+ /**
3
+ * X25519 keypair for MPC encryption
4
+ * Used for encrypted computations with Arcium
5
+ */
6
+ export interface X25519Keypair {
7
+ /** Public key (32 bytes) */
8
+ publicKey: Uint8Array;
9
+ /** Secret/private key (32 bytes) */
10
+ secretKey: Uint8Array;
11
+ }
12
+ /**
13
+ * Result from an MPC computation
14
+ */
15
+ export interface ComputationResult {
16
+ /** Transaction signature */
17
+ signature: string;
18
+ /** Unique computation offset used */
19
+ offset: BN;
20
+ }
21
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,oCAAoC;IACpC,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,MAAM,EAAE,EAAE,CAAC;CACZ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./accounts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./accounts";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const ARCIUM_CLUSTER_OFFSET = 456;
2
+ export declare function getClusterAddress(): import("@solana/web3.js").PublicKey;
3
+ //# sourceMappingURL=arcium.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arcium.d.ts","sourceRoot":"","sources":["../../src/utils/arcium.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,wBAAgB,iBAAiB,wCAEhC"}
@@ -0,0 +1,6 @@
1
+ import { getClusterAccAddress } from "@arcium-hq/client";
2
+ export const ARCIUM_CLUSTER_OFFSET = 456;
3
+ export function getClusterAddress() {
4
+ return getClusterAccAddress(ARCIUM_CLUSTER_OFFSET);
5
+ }
6
+ //# sourceMappingURL=arcium.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arcium.js","sourceRoot":"","sources":["../../src/utils/arcium.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC,MAAM,UAAU,iBAAiB;IAC/B,OAAO,oBAAoB,CAAC,qBAAqB,CAAC,CAAA;AACpD,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { BN, type AnchorProvider } from "@coral-xyz/anchor";
2
+ import type { PublicKey } from "@solana/web3.js";
3
+ /**
4
+ * Options for awaiting computation finalization
5
+ */
6
+ export interface AwaitComputationOptions {
7
+ /** Commitment level (default: "confirmed") */
8
+ commitment?: "confirmed" | "finalized";
9
+ /** Program ID (default: PROGRAM_ID) */
10
+ programId?: PublicKey;
11
+ }
12
+ /**
13
+ * Awaits the finalization of an MPC computation
14
+ *
15
+ * After sending an instruction that triggers an MPC computation,
16
+ * call this function with the returned computation offset to wait
17
+ * for the computation to complete.
18
+ *
19
+ * @param provider - Anchor provider for connection
20
+ * @param computationOffset - The offset returned from the MPC instruction
21
+ * @param options - Optional configuration
22
+ * @returns Promise resolving to the computation result transaction signature
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const { signature, computationOffset } = await mintVoteTokens(provider, {
27
+ * signer: user,
28
+ * userX25519Keypair,
29
+ * amount: 100,
30
+ * });
31
+ *
32
+ * // Wait for MPC computation to complete
33
+ * await awaitComputationFinalization(provider, computationOffset);
34
+ * ```
35
+ */
36
+ export declare function awaitComputationFinalization(provider: AnchorProvider, computationOffset: BN, options?: AwaitComputationOptions): Promise<string>;
37
+ //# sourceMappingURL=awaitComputationFinalization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awaitComputationFinalization.d.ts","sourceRoot":"","sources":["../../src/utils/awaitComputationFinalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,8CAA8C;IAC9C,UAAU,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACvC,uCAAuC;IACvC,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,cAAc,EACxB,iBAAiB,EAAE,EAAE,EACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC,CAKjB"}
@@ -0,0 +1,32 @@
1
+ import { awaitComputationFinalization as arciumAwait } from "@arcium-hq/client";
2
+ import { PROGRAM_ID } from "../constants";
3
+ /**
4
+ * Awaits the finalization of an MPC computation
5
+ *
6
+ * After sending an instruction that triggers an MPC computation,
7
+ * call this function with the returned computation offset to wait
8
+ * for the computation to complete.
9
+ *
10
+ * @param provider - Anchor provider for connection
11
+ * @param computationOffset - The offset returned from the MPC instruction
12
+ * @param options - Optional configuration
13
+ * @returns Promise resolving to the computation result transaction signature
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const { signature, computationOffset } = await mintVoteTokens(provider, {
18
+ * signer: user,
19
+ * userX25519Keypair,
20
+ * amount: 100,
21
+ * });
22
+ *
23
+ * // Wait for MPC computation to complete
24
+ * await awaitComputationFinalization(provider, computationOffset);
25
+ * ```
26
+ */
27
+ export async function awaitComputationFinalization(provider, computationOffset, options) {
28
+ const commitment = options?.commitment ?? "confirmed";
29
+ const programId = options?.programId ?? PROGRAM_ID;
30
+ return await arciumAwait(provider, computationOffset, programId, commitment);
31
+ }
32
+ //# sourceMappingURL=awaitComputationFinalization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awaitComputationFinalization.js","sourceRoot":"","sources":["../../src/utils/awaitComputationFinalization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,QAAwB,EACxB,iBAAqB,EACrB,OAAiC;IAEjC,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,WAAW,CAAC;IACtD,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,UAAU,CAAC;IAEnD,OAAO,MAAM,WAAW,CAAC,QAAQ,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { BN } from "@coral-xyz/anchor";
2
+ /**
3
+ * Generates a random computation offset for MPC operations
4
+ *
5
+ * Each MPC instruction requires a unique offset to identify the computation.
6
+ * This function generates a random 8-byte value.
7
+ *
8
+ * @returns A random BN to use as computation offset
9
+ */
10
+ export declare function generateComputationOffset(): BN;
11
+ /**
12
+ * Generates a random nonce for encryption
13
+ *
14
+ * Nonces are used to ensure encryption produces different ciphertexts
15
+ * for the same plaintext.
16
+ *
17
+ * @returns A random 16-byte Uint8Array
18
+ */
19
+ export declare function generateNonce(): Uint8Array;
20
+ /**
21
+ * Converts a nonce to a u128 BN for passing to instructions
22
+ *
23
+ * @param nonce - 16-byte nonce
24
+ * @returns BN representation of the nonce
25
+ */
26
+ export declare function nonceToU128(nonce: Uint8Array): BN;
27
+ //# sourceMappingURL=computations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computations.d.ts","sourceRoot":"","sources":["../../src/utils/computations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAGvC;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,IAAI,EAAE,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,EAAE,CAEjD"}
@@ -0,0 +1,35 @@
1
+ import { randomBytes } from "crypto";
2
+ import { BN } from "@coral-xyz/anchor";
3
+ import { deserializeLE } from "@arcium-hq/client";
4
+ /**
5
+ * Generates a random computation offset for MPC operations
6
+ *
7
+ * Each MPC instruction requires a unique offset to identify the computation.
8
+ * This function generates a random 8-byte value.
9
+ *
10
+ * @returns A random BN to use as computation offset
11
+ */
12
+ export function generateComputationOffset() {
13
+ return new BN(randomBytes(8), "hex");
14
+ }
15
+ /**
16
+ * Generates a random nonce for encryption
17
+ *
18
+ * Nonces are used to ensure encryption produces different ciphertexts
19
+ * for the same plaintext.
20
+ *
21
+ * @returns A random 16-byte Uint8Array
22
+ */
23
+ export function generateNonce() {
24
+ return randomBytes(16);
25
+ }
26
+ /**
27
+ * Converts a nonce to a u128 BN for passing to instructions
28
+ *
29
+ * @param nonce - 16-byte nonce
30
+ * @returns BN representation of the nonce
31
+ */
32
+ export function nonceToU128(nonce) {
33
+ return new BN(deserializeLE(nonce).toString());
34
+ }
35
+ //# sourceMappingURL=computations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computations.js","sourceRoot":"","sources":["../../src/utils/computations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,IAAI,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { RescueCipher } from "@arcium-hq/client";
2
+ import type { AnchorProvider } from "@coral-xyz/anchor";
3
+ import type { PublicKey } from "@solana/web3.js";
4
+ import type { X25519Keypair } from "../types";
5
+ /**
6
+ * Encryption context for working with encrypted data
7
+ */
8
+ export interface EncryptionContext {
9
+ /** Rescue cipher for encryption/decryption */
10
+ cipher: RescueCipher;
11
+ /** User's X25519 keypair */
12
+ x25519Keypair: X25519Keypair;
13
+ }
14
+ /**
15
+ * Fetches the MXE public key from the on-chain program
16
+ *
17
+ * @param provider - Anchor provider
18
+ * @param programId - Program ID
19
+ * @returns The MXE's X25519 public key
20
+ */
21
+ export declare function fetchMXEPublicKey(provider: AnchorProvider, programId: PublicKey): Promise<Uint8Array>;
22
+ /**
23
+ * Creates an encryption context for a user
24
+ *
25
+ * Derives a shared secret with the MXE and creates a Rescue cipher
26
+ * for encryption/decryption operations.
27
+ *
28
+ * @param x25519Keypair - User's X25519 keypair
29
+ * @param mxePublicKey - MXE's public key (fetch with fetchMXEPublicKey)
30
+ * @returns Encryption context with cipher
31
+ */
32
+ export declare function createEncryptionContext(x25519Keypair: X25519Keypair, mxePublicKey: Uint8Array): EncryptionContext;
33
+ /**
34
+ * Encrypts values for buying market shares
35
+ *
36
+ * @param context - Encryption context
37
+ * @param amount - Number of shares to buy
38
+ * @param selectedOption - Option index (1-based)
39
+ * @param nonce - 16-byte nonce for encryption
40
+ * @returns Encrypted amount and option as Uint8Arrays
41
+ */
42
+ export declare function encryptBuySharesInput(context: EncryptionContext, amount: bigint, selectedOption: bigint, nonce: Uint8Array): {
43
+ amountCiphertext: Uint8Array;
44
+ selectedOptionCiphertext: Uint8Array;
45
+ };
46
+ //# sourceMappingURL=encryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,MAAM,EAAE,YAAY,CAAC;IACrB,4BAA4B;IAC5B,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,UAAU,GACvB,iBAAiB,CAWnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,UAAU,GAChB;IACD,gBAAgB,EAAE,UAAU,CAAC;IAC7B,wBAAwB,EAAE,UAAU,CAAC;CACtC,CAWA"}
@@ -0,0 +1,53 @@
1
+ import { x25519, RescueCipher, getMXEPublicKey } from "@arcium-hq/client";
2
+ /**
3
+ * Fetches the MXE public key from the on-chain program
4
+ *
5
+ * @param provider - Anchor provider
6
+ * @param programId - Program ID
7
+ * @returns The MXE's X25519 public key
8
+ */
9
+ export async function fetchMXEPublicKey(provider, programId) {
10
+ const key = await getMXEPublicKey(provider, programId);
11
+ if (!key) {
12
+ throw new Error("Failed to fetch MXE public key");
13
+ }
14
+ return key;
15
+ }
16
+ /**
17
+ * Creates an encryption context for a user
18
+ *
19
+ * Derives a shared secret with the MXE and creates a Rescue cipher
20
+ * for encryption/decryption operations.
21
+ *
22
+ * @param x25519Keypair - User's X25519 keypair
23
+ * @param mxePublicKey - MXE's public key (fetch with fetchMXEPublicKey)
24
+ * @returns Encryption context with cipher
25
+ */
26
+ export function createEncryptionContext(x25519Keypair, mxePublicKey) {
27
+ const sharedSecret = x25519.getSharedSecret(x25519Keypair.secretKey, mxePublicKey);
28
+ const cipher = new RescueCipher(sharedSecret);
29
+ return {
30
+ cipher,
31
+ x25519Keypair,
32
+ };
33
+ }
34
+ /**
35
+ * Encrypts values for buying market shares
36
+ *
37
+ * @param context - Encryption context
38
+ * @param amount - Number of shares to buy
39
+ * @param selectedOption - Option index (1-based)
40
+ * @param nonce - 16-byte nonce for encryption
41
+ * @returns Encrypted amount and option as Uint8Arrays
42
+ */
43
+ export function encryptBuySharesInput(context, amount, selectedOption, nonce) {
44
+ const ciphertexts = context.cipher.encrypt([amount, selectedOption], nonce);
45
+ if (!ciphertexts[0] || !ciphertexts[1]) {
46
+ throw new Error("Encryption failed");
47
+ }
48
+ return {
49
+ amountCiphertext: new Uint8Array(ciphertexts[0]),
50
+ selectedOptionCiphertext: new Uint8Array(ciphertexts[1]),
51
+ };
52
+ }
53
+ //# sourceMappingURL=encryption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAe1E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAwB,EACxB,SAAoB;IAEpB,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CACrC,aAA4B,EAC5B,YAAwB;IAExB,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CACzC,aAAa,CAAC,SAAS,EACvB,YAAY,CACb,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;IAE9C,OAAO;QACL,MAAM;QACN,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA0B,EAC1B,MAAc,EACd,cAAsB,EACtB,KAAiB;IAKjB,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC;IAE5E,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IAED,OAAO;QACL,gBAAgB,EAAE,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAChD,wBAAwB,EAAE,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;KACzD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./pdas";
2
+ export * from "./keypairs";
3
+ export * from "./computations";
4
+ export * from "./encryption";
5
+ export * from "./awaitComputationFinalization";
6
+ export * from "./arcium";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./pdas";
2
+ export * from "./keypairs";
3
+ export * from "./computations";
4
+ export * from "./encryption";
5
+ export * from "./awaitComputationFinalization";
6
+ export * from "./arcium";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,UAAU,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { Keypair } from "@solana/web3.js";
2
+ import type { X25519Keypair } from "../types";
3
+ /**
4
+ * Generates a new Solana keypair
5
+ *
6
+ * Used for transaction signing and account ownership
7
+ *
8
+ * @returns A new Solana Keypair
9
+ */
10
+ export declare function generateSolanaKeypair(): Keypair;
11
+ /**
12
+ * Generates a new X25519 keypair for MPC encryption
13
+ *
14
+ * Used for encrypted computations with Arcium.
15
+ * The keypair is used to derive a shared secret with the MXE.
16
+ *
17
+ * @returns A new X25519Keypair with publicKey and secretKey
18
+ */
19
+ export declare function generateX25519Keypair(): X25519Keypair;
20
+ //# sourceMappingURL=keypairs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keypairs.d.ts","sourceRoot":"","sources":["../../src/utils/keypairs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,aAAa,CAQrD"}
@@ -0,0 +1,29 @@
1
+ import { Keypair } from "@solana/web3.js";
2
+ import { x25519 } from "@arcium-hq/client";
3
+ /**
4
+ * Generates a new Solana keypair
5
+ *
6
+ * Used for transaction signing and account ownership
7
+ *
8
+ * @returns A new Solana Keypair
9
+ */
10
+ export function generateSolanaKeypair() {
11
+ return Keypair.generate();
12
+ }
13
+ /**
14
+ * Generates a new X25519 keypair for MPC encryption
15
+ *
16
+ * Used for encrypted computations with Arcium.
17
+ * The keypair is used to derive a shared secret with the MXE.
18
+ *
19
+ * @returns A new X25519Keypair with publicKey and secretKey
20
+ */
21
+ export function generateX25519Keypair() {
22
+ const secretKey = x25519.utils.randomPrivateKey();
23
+ const publicKey = x25519.getPublicKey(secretKey);
24
+ return {
25
+ publicKey,
26
+ secretKey,
27
+ };
28
+ }
29
+ //# sourceMappingURL=keypairs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keypairs.js","sourceRoot":"","sources":["../../src/utils/keypairs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAClD,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAEjD,OAAO;QACL,SAAS;QACT,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { BN } from "@coral-xyz/anchor";
3
+ /**
4
+ * Derives the PDA for a Conviction Market account
5
+ *
6
+ * @param creator - Market creator's public key
7
+ * @param index - Unique market index
8
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
9
+ * @returns Tuple of [PublicKey, bump]
10
+ */
11
+ export declare function deriveMarketPda(creator: PublicKey, index: BN | number, programId?: PublicKey): [PublicKey, number];
12
+ /**
13
+ * Derives the PDA for a Vote Token Account
14
+ *
15
+ * @param owner - Account owner's public key
16
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
17
+ * @returns Tuple of [PublicKey, bump]
18
+ */
19
+ export declare function deriveVoteTokenAccountPda(owner: PublicKey, programId?: PublicKey): [PublicKey, number];
20
+ /**
21
+ * Derives the PDA for a Share Account
22
+ *
23
+ * @param owner - Account owner's public key
24
+ * @param market - Market PDA
25
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
26
+ * @returns Tuple of [PublicKey, bump]
27
+ */
28
+ export declare function deriveShareAccountPda(owner: PublicKey, market: PublicKey, programId?: PublicKey): [PublicKey, number];
29
+ /**
30
+ * Derives the PDA for a Market Option
31
+ *
32
+ * @param market - Market PDA
33
+ * @param optionIndex - Option index (1-based)
34
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
35
+ * @returns Tuple of [PublicKey, bump]
36
+ */
37
+ export declare function deriveOptionPda(market: PublicKey, optionIndex: number, programId?: PublicKey): [PublicKey, number];
38
+ //# sourceMappingURL=pdas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdas.d.ts","sourceRoot":"","sources":["../../src/utils/pdas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AASvC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,EAAE,GAAG,MAAM,EAClB,SAAS,GAAE,SAAsB,GAChC,CAAC,SAAS,EAAE,MAAM,CAAC,CAWrB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,EAChB,SAAS,GAAE,SAAsB,GAChC,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS,EACjB,SAAS,GAAE,SAAsB,GAChC,CAAC,SAAS,EAAE,MAAM,CAAC,CAKrB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,SAAsB,GAChC,CAAC,SAAS,EAAE,MAAM,CAAC,CAWrB"}
@@ -0,0 +1,57 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { BN } from "@coral-xyz/anchor";
3
+ import { PROGRAM_ID, CONVICTION_MARKET_SEED, VOTE_TOKEN_ACCOUNT_SEED, SHARE_ACCOUNT_SEED, OPTION_SEED, } from "../constants";
4
+ /**
5
+ * Derives the PDA for a Conviction Market account
6
+ *
7
+ * @param creator - Market creator's public key
8
+ * @param index - Unique market index
9
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
10
+ * @returns Tuple of [PublicKey, bump]
11
+ */
12
+ export function deriveMarketPda(creator, index, programId = PROGRAM_ID) {
13
+ const indexBN = typeof index === "number" ? new BN(index) : index;
14
+ return PublicKey.findProgramAddressSync([
15
+ Buffer.from(CONVICTION_MARKET_SEED),
16
+ creator.toBuffer(),
17
+ indexBN.toArrayLike(Buffer, "le", 8), // u64 = 8 bytes
18
+ ], programId);
19
+ }
20
+ /**
21
+ * Derives the PDA for a Vote Token Account
22
+ *
23
+ * @param owner - Account owner's public key
24
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
25
+ * @returns Tuple of [PublicKey, bump]
26
+ */
27
+ export function deriveVoteTokenAccountPda(owner, programId = PROGRAM_ID) {
28
+ return PublicKey.findProgramAddressSync([Buffer.from(VOTE_TOKEN_ACCOUNT_SEED), owner.toBuffer()], programId);
29
+ }
30
+ /**
31
+ * Derives the PDA for a Share Account
32
+ *
33
+ * @param owner - Account owner's public key
34
+ * @param market - Market PDA
35
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
36
+ * @returns Tuple of [PublicKey, bump]
37
+ */
38
+ export function deriveShareAccountPda(owner, market, programId = PROGRAM_ID) {
39
+ return PublicKey.findProgramAddressSync([Buffer.from(SHARE_ACCOUNT_SEED), owner.toBuffer(), market.toBuffer()], programId);
40
+ }
41
+ /**
42
+ * Derives the PDA for a Market Option
43
+ *
44
+ * @param market - Market PDA
45
+ * @param optionIndex - Option index (1-based)
46
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
47
+ * @returns Tuple of [PublicKey, bump]
48
+ */
49
+ export function deriveOptionPda(market, optionIndex, programId = PROGRAM_ID) {
50
+ const optionIndexBN = new BN(optionIndex);
51
+ return PublicKey.findProgramAddressSync([
52
+ Buffer.from(OPTION_SEED),
53
+ market.toBuffer(),
54
+ optionIndexBN.toArrayLike(Buffer, "le", 2), // u16 = 2 bytes
55
+ ], programId);
56
+ }
57
+ //# sourceMappingURL=pdas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdas.js","sourceRoot":"","sources":["../../src/utils/pdas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAkB,EAClB,KAAkB,EAClB,YAAuB,UAAU;IAEjC,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAElE,OAAO,SAAS,CAAC,sBAAsB,CACrC;QACE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC;QACnC,OAAO,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,gBAAgB;KACvD,EACD,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAgB,EAChB,YAAuB,UAAU;IAEjC,OAAO,SAAS,CAAC,sBAAsB,CACrC,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,EACxD,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAgB,EAChB,MAAiB,EACjB,YAAuB,UAAU;IAEjC,OAAO,SAAS,CAAC,sBAAsB,CACrC,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,EACtE,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAiB,EACjB,WAAmB,EACnB,YAAuB,UAAU;IAEjC,MAAM,aAAa,GAAG,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC;IAE1C,OAAO,SAAS,CAAC,sBAAsB,CACrC;QACE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;QACxB,MAAM,CAAC,QAAQ,EAAE;QACjB,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,gBAAgB;KAC7D,EACD,SAAS,CACV,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@bench.games/conviction-markets",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for Solana Conviction Markets with encrypted votes using Arcium MPC",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "prepublishOnly": "bun run build",
24
+ "type-check": "tsc --noEmit"
25
+ },
26
+ "keywords": [
27
+ "solana",
28
+ "conviction-voting",
29
+ "prediction-market",
30
+ "mpc",
31
+ "arcium",
32
+ "encrypted-voting"
33
+ ],
34
+ "author": "Bench",
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "@arcium-hq/client": "^0.6.0",
38
+ "@coral-xyz/anchor": "^0.30.0",
39
+ "@solana/web3.js": "^1.87.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/bun": "latest",
43
+ "typescript": "^5.3.0"
44
+ }
45
+ }