@shuffle-protocol/sdk 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.
@@ -0,0 +1,7 @@
1
+ export { ShuffleClient } from "./client";
2
+ export type { UserBalance, OrderInfo, DecryptedOrderInfo, BatchInfo, BatchResult, PairResult, ShuffleConfig, EstimatedPayout, EffectiveBalance, } from "./types";
3
+ export { AssetId, PairId, Direction, PROGRAM_ID, NUM_PAIRS, NUM_ASSETS, POOL_SEED, USER_SEED, BATCH_ACCUMULATOR_SEED, BATCH_LOG_SEED, VAULT_SEED, VAULT_ASSET_SEEDS, ASSET_LABELS, PAIR_TOKENS, } from "./constants";
4
+ export { getPoolPDA, getUserAccountPDA, getBatchAccumulatorPDA, getBatchLogPDA, getVaultPDA, } from "./pda";
5
+ export { generateEncryptionKeypair, createCipher, encryptValue, decryptValue, fetchMXEPublicKey, nonceToBN, } from "./encryption";
6
+ export type { EncryptionKeypair, EncryptedValue } from "./encryption";
7
+ export { ShuffleError, parseError, ERROR_MAP } from "./errors";
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_MAP = exports.parseError = exports.ShuffleError = exports.nonceToBN = exports.fetchMXEPublicKey = exports.decryptValue = exports.encryptValue = exports.createCipher = exports.generateEncryptionKeypair = exports.getVaultPDA = exports.getBatchLogPDA = exports.getBatchAccumulatorPDA = exports.getUserAccountPDA = exports.getPoolPDA = exports.PAIR_TOKENS = exports.ASSET_LABELS = exports.VAULT_ASSET_SEEDS = exports.VAULT_SEED = exports.BATCH_LOG_SEED = exports.BATCH_ACCUMULATOR_SEED = exports.USER_SEED = exports.POOL_SEED = exports.NUM_ASSETS = exports.NUM_PAIRS = exports.PROGRAM_ID = exports.Direction = exports.PairId = exports.AssetId = exports.ShuffleClient = void 0;
4
+ // Main SDK exports
5
+ var client_1 = require("./client");
6
+ Object.defineProperty(exports, "ShuffleClient", { enumerable: true, get: function () { return client_1.ShuffleClient; } });
7
+ // Constants & Enums
8
+ var constants_1 = require("./constants");
9
+ Object.defineProperty(exports, "AssetId", { enumerable: true, get: function () { return constants_1.AssetId; } });
10
+ Object.defineProperty(exports, "PairId", { enumerable: true, get: function () { return constants_1.PairId; } });
11
+ Object.defineProperty(exports, "Direction", { enumerable: true, get: function () { return constants_1.Direction; } });
12
+ Object.defineProperty(exports, "PROGRAM_ID", { enumerable: true, get: function () { return constants_1.PROGRAM_ID; } });
13
+ Object.defineProperty(exports, "NUM_PAIRS", { enumerable: true, get: function () { return constants_1.NUM_PAIRS; } });
14
+ Object.defineProperty(exports, "NUM_ASSETS", { enumerable: true, get: function () { return constants_1.NUM_ASSETS; } });
15
+ Object.defineProperty(exports, "POOL_SEED", { enumerable: true, get: function () { return constants_1.POOL_SEED; } });
16
+ Object.defineProperty(exports, "USER_SEED", { enumerable: true, get: function () { return constants_1.USER_SEED; } });
17
+ Object.defineProperty(exports, "BATCH_ACCUMULATOR_SEED", { enumerable: true, get: function () { return constants_1.BATCH_ACCUMULATOR_SEED; } });
18
+ Object.defineProperty(exports, "BATCH_LOG_SEED", { enumerable: true, get: function () { return constants_1.BATCH_LOG_SEED; } });
19
+ Object.defineProperty(exports, "VAULT_SEED", { enumerable: true, get: function () { return constants_1.VAULT_SEED; } });
20
+ Object.defineProperty(exports, "VAULT_ASSET_SEEDS", { enumerable: true, get: function () { return constants_1.VAULT_ASSET_SEEDS; } });
21
+ Object.defineProperty(exports, "ASSET_LABELS", { enumerable: true, get: function () { return constants_1.ASSET_LABELS; } });
22
+ Object.defineProperty(exports, "PAIR_TOKENS", { enumerable: true, get: function () { return constants_1.PAIR_TOKENS; } });
23
+ // PDA helpers
24
+ var pda_1 = require("./pda");
25
+ Object.defineProperty(exports, "getPoolPDA", { enumerable: true, get: function () { return pda_1.getPoolPDA; } });
26
+ Object.defineProperty(exports, "getUserAccountPDA", { enumerable: true, get: function () { return pda_1.getUserAccountPDA; } });
27
+ Object.defineProperty(exports, "getBatchAccumulatorPDA", { enumerable: true, get: function () { return pda_1.getBatchAccumulatorPDA; } });
28
+ Object.defineProperty(exports, "getBatchLogPDA", { enumerable: true, get: function () { return pda_1.getBatchLogPDA; } });
29
+ Object.defineProperty(exports, "getVaultPDA", { enumerable: true, get: function () { return pda_1.getVaultPDA; } });
30
+ // Encryption helpers
31
+ var encryption_1 = require("./encryption");
32
+ Object.defineProperty(exports, "generateEncryptionKeypair", { enumerable: true, get: function () { return encryption_1.generateEncryptionKeypair; } });
33
+ Object.defineProperty(exports, "createCipher", { enumerable: true, get: function () { return encryption_1.createCipher; } });
34
+ Object.defineProperty(exports, "encryptValue", { enumerable: true, get: function () { return encryption_1.encryptValue; } });
35
+ Object.defineProperty(exports, "decryptValue", { enumerable: true, get: function () { return encryption_1.decryptValue; } });
36
+ Object.defineProperty(exports, "fetchMXEPublicKey", { enumerable: true, get: function () { return encryption_1.fetchMXEPublicKey; } });
37
+ Object.defineProperty(exports, "nonceToBN", { enumerable: true, get: function () { return encryption_1.nonceToBN; } });
38
+ // Errors
39
+ var errors_1 = require("./errors");
40
+ Object.defineProperty(exports, "ShuffleError", { enumerable: true, get: function () { return errors_1.ShuffleError; } });
41
+ Object.defineProperty(exports, "parseError", { enumerable: true, get: function () { return errors_1.parseError; } });
42
+ Object.defineProperty(exports, "ERROR_MAP", { enumerable: true, get: function () { return errors_1.ERROR_MAP; } });
package/dist/pda.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import * as anchor from "@coral-xyz/anchor";
3
+ export declare function getPoolPDA(programId: PublicKey): [PublicKey, number];
4
+ export declare function getUserAccountPDA(programId: PublicKey, owner: PublicKey): [PublicKey, number];
5
+ export declare function getBatchAccumulatorPDA(programId: PublicKey): [PublicKey, number];
6
+ export declare function getBatchLogPDA(programId: PublicKey, batchId: number | anchor.BN): [PublicKey, number];
7
+ export declare function getVaultPDA(programId: PublicKey, assetSeed: string): [PublicKey, number];
package/dist/pda.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getPoolPDA = getPoolPDA;
37
+ exports.getUserAccountPDA = getUserAccountPDA;
38
+ exports.getBatchAccumulatorPDA = getBatchAccumulatorPDA;
39
+ exports.getBatchLogPDA = getBatchLogPDA;
40
+ exports.getVaultPDA = getVaultPDA;
41
+ const web3_js_1 = require("@solana/web3.js");
42
+ const anchor = __importStar(require("@coral-xyz/anchor"));
43
+ const constants_1 = require("./constants");
44
+ function getPoolPDA(programId) {
45
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.POOL_SEED)], programId);
46
+ }
47
+ function getUserAccountPDA(programId, owner) {
48
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.USER_SEED), owner.toBuffer()], programId);
49
+ }
50
+ function getBatchAccumulatorPDA(programId) {
51
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.BATCH_ACCUMULATOR_SEED)], programId);
52
+ }
53
+ function getBatchLogPDA(programId, batchId) {
54
+ const bn = typeof batchId === "number" ? new anchor.BN(batchId) : batchId;
55
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.BATCH_LOG_SEED), Buffer.from(bn.toArray("le", 8))], programId);
56
+ }
57
+ function getVaultPDA(programId, assetSeed) {
58
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(constants_1.VAULT_SEED), Buffer.from(assetSeed)], programId);
59
+ }
@@ -0,0 +1,83 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { AssetId, PairId, Direction } from "./constants";
3
+ import * as anchor from "@coral-xyz/anchor";
4
+ /** Decrypted balances for all 4 assets */
5
+ export interface UserBalance {
6
+ usdc: bigint;
7
+ tsla: bigint;
8
+ spy: bigint;
9
+ aapl: bigint;
10
+ }
11
+ /** Pending order info (decoded from on-chain UserProfile) */
12
+ export interface OrderInfo {
13
+ batchId: number;
14
+ pairId: number[];
15
+ direction: number[];
16
+ encryptedAmount: number[];
17
+ }
18
+ /** Decrypted order info - user-readable after decryption */
19
+ export interface DecryptedOrderInfo {
20
+ batchId: number;
21
+ pairId: number;
22
+ direction: number;
23
+ amount: bigint;
24
+ }
25
+ /** Batch accumulator state */
26
+ export interface BatchInfo {
27
+ batchId: number;
28
+ orderCount: number;
29
+ /** MXE nonce - 0 means batch state needs initialization */
30
+ mxeNonce: string;
31
+ }
32
+ /** Per-pair result from a batch execution */
33
+ export interface PairResult {
34
+ totalAIn: anchor.BN;
35
+ totalBIn: anchor.BN;
36
+ finalPoolA: anchor.BN;
37
+ finalPoolB: anchor.BN;
38
+ }
39
+ /** Full batch log with results for all 6 pairs */
40
+ export interface BatchResult {
41
+ batchId: number;
42
+ results: PairResult[];
43
+ }
44
+ /** SDK constructor configuration */
45
+ export interface ShuffleConfig {
46
+ connection: anchor.web3.Connection;
47
+ wallet: anchor.Wallet;
48
+ programId?: PublicKey;
49
+ /** Arcium cluster offset (default: 0 for localnet) */
50
+ clusterOffset?: number;
51
+ }
52
+ /** Estimated payout for a pending order after batch execution */
53
+ export interface EstimatedPayout {
54
+ /** The batch this payout is from */
55
+ batchId: number;
56
+ /** The pair for this order */
57
+ pairId: number;
58
+ /** Direction: 0=A_to_B, 1=B_to_A */
59
+ direction: number;
60
+ /** User's order amount (decrypted) */
61
+ orderAmount: bigint;
62
+ /** Total input to the pool for this direction */
63
+ totalInput: bigint;
64
+ /** Final pool output for this direction */
65
+ finalPoolOutput: bigint;
66
+ /** Calculated pro-rata payout */
67
+ estimatedPayout: bigint;
68
+ /** Output asset ID (what the user receives) */
69
+ outputAssetId: AssetId;
70
+ }
71
+ /** Effective balance including pending payout */
72
+ export interface EffectiveBalance {
73
+ /** Current on-chain balance */
74
+ currentBalance: bigint;
75
+ /** Estimated payout from pending order (0 if none) */
76
+ pendingPayout: bigint;
77
+ /** Total effective balance (current + pending) */
78
+ effectiveBalance: bigint;
79
+ /** Whether there's a pending order to settle */
80
+ hasPendingOrder: boolean;
81
+ }
82
+ /** Re-export enums for convenience */
83
+ export { AssetId, PairId, Direction };
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Direction = exports.PairId = exports.AssetId = void 0;
4
+ const constants_1 = require("./constants");
5
+ Object.defineProperty(exports, "AssetId", { enumerable: true, get: function () { return constants_1.AssetId; } });
6
+ Object.defineProperty(exports, "PairId", { enumerable: true, get: function () { return constants_1.PairId; } });
7
+ Object.defineProperty(exports, "Direction", { enumerable: true, get: function () { return constants_1.Direction; } });
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@shuffle-protocol/sdk",
3
+ "version": "0.1.0",
4
+ "description": "CLI and SDK for the Shuffle privacy protocol on Solana",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "shuffle": "./dist/cli/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
13
+ "clean": "rm -rf dist"
14
+ },
15
+ "keywords": [
16
+ "solana",
17
+ "privacy",
18
+ "defi",
19
+ "mpc",
20
+ "arcium",
21
+ "shuffle"
22
+ ],
23
+ "author": "tothster",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/tothster/shuffle"
28
+ },
29
+ "homepage": "https://github.com/tothster/shuffle#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/tothster/shuffle/issues"
32
+ },
33
+ "dependencies": {
34
+ "@arcium-hq/client": "0.6.3",
35
+ "@coral-xyz/anchor": "^0.32.1",
36
+ "@solana/web3.js": "^1.98.4",
37
+ "@solana/spl-token": "^0.4.14",
38
+ "commander": "^12.0.0",
39
+ "inquirer": "^8.2.6",
40
+ "ora": "^5.4.1",
41
+ "chalk": "^4.1.2"
42
+ },
43
+ "devDependencies": {
44
+ "typescript": "^5.3.0",
45
+ "@types/node": "^20.0.0",
46
+ "@types/inquirer": "^8.2.10"
47
+ },
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "files": [
52
+ "dist/**/*",
53
+ "README.md"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }