@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.
- package/README.md +119 -0
- package/dist/cli/commands.d.ts +54 -0
- package/dist/cli/commands.js +1229 -0
- package/dist/cli/config.d.ts +50 -0
- package/dist/cli/config.js +247 -0
- package/dist/cli/devnet.d.ts +81 -0
- package/dist/cli/devnet.js +106 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.js +155 -0
- package/dist/cli/output.d.ts +102 -0
- package/dist/cli/output.js +251 -0
- package/dist/client.d.ts +121 -0
- package/dist/client.js +691 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.js +61 -0
- package/dist/encryption.d.ts +24 -0
- package/dist/encryption.js +90 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +45 -0
- package/dist/idl/shuffle_protocol.json +6333 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +42 -0
- package/dist/pda.d.ts +7 -0
- package/dist/pda.js +59 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +7 -0
- package/package.json +58 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal Output Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides spinners, colorized output, and formatted displays
|
|
5
|
+
* for an impressive terminal UX.
|
|
6
|
+
*/
|
|
7
|
+
import { Ora } from "ora";
|
|
8
|
+
/**
|
|
9
|
+
* Create a spinner with Shuffle branding
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSpinner(text: string): Ora;
|
|
12
|
+
/**
|
|
13
|
+
* Run an async operation with a spinner
|
|
14
|
+
*/
|
|
15
|
+
export declare function withSpinner<T>(text: string, operation: () => Promise<T>, successMessage?: string): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Show a multi-step progress spinner
|
|
18
|
+
*/
|
|
19
|
+
export declare function createProgressSpinner(steps: string[]): {
|
|
20
|
+
start: () => void;
|
|
21
|
+
nextStep: () => void;
|
|
22
|
+
succeed: (message?: string) => void;
|
|
23
|
+
fail: (message?: string) => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Print a section header
|
|
27
|
+
*/
|
|
28
|
+
export declare function printHeader(title: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Print balance table showing shielded and unshielded balances side-by-side
|
|
31
|
+
* If pendingPayout is provided, add it to the relevant asset in a different color
|
|
32
|
+
*/
|
|
33
|
+
export declare function printBalanceTable(shielded: {
|
|
34
|
+
usdc: bigint;
|
|
35
|
+
tsla: bigint;
|
|
36
|
+
spy: bigint;
|
|
37
|
+
aapl: bigint;
|
|
38
|
+
}, unshielded?: {
|
|
39
|
+
usdc: bigint;
|
|
40
|
+
tsla: bigint;
|
|
41
|
+
spy: bigint;
|
|
42
|
+
aapl: bigint;
|
|
43
|
+
}, pendingPayout?: {
|
|
44
|
+
amount: bigint;
|
|
45
|
+
assetId: number;
|
|
46
|
+
} | null): void;
|
|
47
|
+
/**
|
|
48
|
+
* Print order status
|
|
49
|
+
*/
|
|
50
|
+
export declare function printOrderStatus(order: {
|
|
51
|
+
batchId: number;
|
|
52
|
+
pairId: number;
|
|
53
|
+
direction: number;
|
|
54
|
+
amount: bigint;
|
|
55
|
+
} | null): void;
|
|
56
|
+
/**
|
|
57
|
+
* Print batch status
|
|
58
|
+
*/
|
|
59
|
+
export declare function printBatchStatus(batch: {
|
|
60
|
+
batchId: number;
|
|
61
|
+
orderCount: number;
|
|
62
|
+
}): void;
|
|
63
|
+
/**
|
|
64
|
+
* Print transaction success with explorer link
|
|
65
|
+
*/
|
|
66
|
+
export declare function printTxSuccess(signature: string, network: "devnet" | "localnet"): void;
|
|
67
|
+
/**
|
|
68
|
+
* Print error message
|
|
69
|
+
*/
|
|
70
|
+
export declare function printError(message: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Print info message
|
|
73
|
+
*/
|
|
74
|
+
export declare function printInfo(message: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Print success message
|
|
77
|
+
*/
|
|
78
|
+
export declare function printSuccess(message: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Print mock mode warning
|
|
81
|
+
*/
|
|
82
|
+
export declare function printMockWarning(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Print batch history table
|
|
85
|
+
*/
|
|
86
|
+
export declare function printBatchHistory(logs: Array<{
|
|
87
|
+
batchId: number;
|
|
88
|
+
results: Array<{
|
|
89
|
+
totalAIn: {
|
|
90
|
+
toString: () => string;
|
|
91
|
+
};
|
|
92
|
+
totalBIn: {
|
|
93
|
+
toString: () => string;
|
|
94
|
+
};
|
|
95
|
+
finalPoolA: {
|
|
96
|
+
toString: () => string;
|
|
97
|
+
};
|
|
98
|
+
finalPoolB: {
|
|
99
|
+
toString: () => string;
|
|
100
|
+
};
|
|
101
|
+
}>;
|
|
102
|
+
}>): void;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Terminal Output Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides spinners, colorized output, and formatted displays
|
|
6
|
+
* for an impressive terminal UX.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createSpinner = createSpinner;
|
|
13
|
+
exports.withSpinner = withSpinner;
|
|
14
|
+
exports.createProgressSpinner = createProgressSpinner;
|
|
15
|
+
exports.printHeader = printHeader;
|
|
16
|
+
exports.printBalanceTable = printBalanceTable;
|
|
17
|
+
exports.printOrderStatus = printOrderStatus;
|
|
18
|
+
exports.printBatchStatus = printBatchStatus;
|
|
19
|
+
exports.printTxSuccess = printTxSuccess;
|
|
20
|
+
exports.printError = printError;
|
|
21
|
+
exports.printInfo = printInfo;
|
|
22
|
+
exports.printSuccess = printSuccess;
|
|
23
|
+
exports.printMockWarning = printMockWarning;
|
|
24
|
+
exports.printBatchHistory = printBatchHistory;
|
|
25
|
+
const ora_1 = __importDefault(require("ora"));
|
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Spinner Helpers
|
|
29
|
+
// ============================================================================
|
|
30
|
+
/**
|
|
31
|
+
* Create a spinner with Shuffle branding
|
|
32
|
+
*/
|
|
33
|
+
function createSpinner(text) {
|
|
34
|
+
return (0, ora_1.default)({
|
|
35
|
+
text: chalk_1.default.cyan(text),
|
|
36
|
+
spinner: "dots",
|
|
37
|
+
color: "cyan",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run an async operation with a spinner
|
|
42
|
+
*/
|
|
43
|
+
async function withSpinner(text, operation, successMessage) {
|
|
44
|
+
const spinner = createSpinner(text);
|
|
45
|
+
spinner.start();
|
|
46
|
+
try {
|
|
47
|
+
const result = await operation();
|
|
48
|
+
spinner.succeed(chalk_1.default.green(successMessage || text + " ✓"));
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Just stop the spinner, let the caller handle error display
|
|
53
|
+
spinner.stop();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Show a multi-step progress spinner
|
|
59
|
+
*/
|
|
60
|
+
function createProgressSpinner(steps) {
|
|
61
|
+
let currentStep = 0;
|
|
62
|
+
const spinner = createSpinner(steps[0]);
|
|
63
|
+
return {
|
|
64
|
+
start: () => spinner.start(),
|
|
65
|
+
nextStep: () => {
|
|
66
|
+
currentStep++;
|
|
67
|
+
if (currentStep < steps.length) {
|
|
68
|
+
spinner.text = chalk_1.default.cyan(steps[currentStep]);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
succeed: (msg) => spinner.succeed(chalk_1.default.green(msg || "Complete ✓")),
|
|
72
|
+
fail: (msg) => spinner.fail(chalk_1.default.red(msg || "Failed")),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Formatted Output
|
|
77
|
+
// ============================================================================
|
|
78
|
+
/**
|
|
79
|
+
* Print a section header
|
|
80
|
+
*/
|
|
81
|
+
function printHeader(title) {
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(chalk_1.default.bold.cyan(`🃏 ${title}`));
|
|
84
|
+
console.log(chalk_1.default.gray("─".repeat(40)));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Print balance table showing shielded and unshielded balances side-by-side
|
|
88
|
+
* If pendingPayout is provided, add it to the relevant asset in a different color
|
|
89
|
+
*/
|
|
90
|
+
function printBalanceTable(shielded, unshielded, pendingPayout) {
|
|
91
|
+
printHeader("Your Balances");
|
|
92
|
+
const format = (val) => {
|
|
93
|
+
const num = Number(val) / 1000000; // 6 decimals
|
|
94
|
+
// Use more decimal places for small values to avoid showing 0.00 for non-zero amounts
|
|
95
|
+
if (num === 0) {
|
|
96
|
+
return "0.00";
|
|
97
|
+
}
|
|
98
|
+
else if (num < 0.01) {
|
|
99
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 6, maximumFractionDigits: 6 });
|
|
100
|
+
}
|
|
101
|
+
else if (num < 1) {
|
|
102
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 4, maximumFractionDigits: 4 });
|
|
103
|
+
}
|
|
104
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
105
|
+
};
|
|
106
|
+
const pad = (str, len) => str.padStart(len);
|
|
107
|
+
// Map asset IDs to keys: 0=USDC, 1=TSLA, 2=SPY, 3=AAPL
|
|
108
|
+
const assetKeys = ['usdc', 'tsla', 'spy', 'aapl'];
|
|
109
|
+
if (unshielded) {
|
|
110
|
+
// Show both shielded and unshielded
|
|
111
|
+
console.log(chalk_1.default.gray(" Token 🔒 Shielded 🔓 Unshielded"));
|
|
112
|
+
console.log();
|
|
113
|
+
const printRow = (token, color, assetId, shieldedVal, unshieldedVal) => {
|
|
114
|
+
const hasPending = pendingPayout && pendingPayout.assetId === assetId && pendingPayout.amount > 0n;
|
|
115
|
+
const effectiveBalance = hasPending ? shieldedVal + pendingPayout.amount : shieldedVal;
|
|
116
|
+
let shieldedStr;
|
|
117
|
+
if (hasPending) {
|
|
118
|
+
// Show effective balance in cyan to indicate pending payout included
|
|
119
|
+
shieldedStr = chalk_1.default.cyan(pad(format(effectiveBalance), 12));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
shieldedStr = chalk_1.default.white(pad(format(shieldedVal), 12));
|
|
123
|
+
}
|
|
124
|
+
const unshieldedStr = pad(format(unshieldedVal), 14);
|
|
125
|
+
console.log(` ${color(token.padEnd(5))} │ ${shieldedStr} │ ${chalk_1.default.gray(unshieldedStr)}`);
|
|
126
|
+
};
|
|
127
|
+
printRow("USDC", chalk_1.default.yellow, 0, shielded.usdc, unshielded.usdc);
|
|
128
|
+
printRow("TSLA", chalk_1.default.magenta, 1, shielded.tsla, unshielded.tsla);
|
|
129
|
+
printRow("SPY", chalk_1.default.blue, 2, shielded.spy, unshielded.spy);
|
|
130
|
+
printRow("AAPL", chalk_1.default.green, 3, shielded.aapl, unshielded.aapl);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Original format (shielded only)
|
|
134
|
+
console.log(` ${chalk_1.default.yellow("USDC")}: ${chalk_1.default.white(format(shielded.usdc))}`);
|
|
135
|
+
console.log(` ${chalk_1.default.magenta("TSLA")}: ${chalk_1.default.white(format(shielded.tsla))}`);
|
|
136
|
+
console.log(` ${chalk_1.default.blue("SPY")}: ${chalk_1.default.white(format(shielded.spy))}`);
|
|
137
|
+
console.log(` ${chalk_1.default.green("AAPL")}: ${chalk_1.default.white(format(shielded.aapl))}`);
|
|
138
|
+
}
|
|
139
|
+
console.log();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Print order status
|
|
143
|
+
*/
|
|
144
|
+
function printOrderStatus(order) {
|
|
145
|
+
if (!order) {
|
|
146
|
+
console.log(chalk_1.default.gray(" No pending order"));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const pairLabels = ["TSLA/USDC", "SPY/USDC", "AAPL/USDC", "TSLA/SPY", "TSLA/AAPL", "SPY/AAPL"];
|
|
150
|
+
const directionLabel = order.direction === 0 ? chalk_1.default.green("BUY") : chalk_1.default.red("SELL");
|
|
151
|
+
const amount = (Number(order.amount) / 1000000).toLocaleString();
|
|
152
|
+
console.log(` Batch: ${chalk_1.default.cyan(order.batchId)}`);
|
|
153
|
+
console.log(` Pair: ${chalk_1.default.white(pairLabels[order.pairId] || "Unknown")}`);
|
|
154
|
+
console.log(` Direction: ${directionLabel}`);
|
|
155
|
+
console.log(` Amount: ${chalk_1.default.white(amount)}`);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Print batch status
|
|
159
|
+
*/
|
|
160
|
+
function printBatchStatus(batch) {
|
|
161
|
+
console.log(` Batch ID: ${chalk_1.default.cyan(batch.batchId)}`);
|
|
162
|
+
console.log(` Order Count: ${chalk_1.default.white(batch.orderCount)}`);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Print transaction success with explorer link
|
|
166
|
+
*/
|
|
167
|
+
function printTxSuccess(signature, network) {
|
|
168
|
+
console.log();
|
|
169
|
+
console.log(chalk_1.default.green("✓ Transaction confirmed"));
|
|
170
|
+
if (network === "devnet") {
|
|
171
|
+
const url = `https://explorer.solana.com/tx/${signature}?cluster=devnet`;
|
|
172
|
+
console.log(chalk_1.default.gray(` View: ${chalk_1.default.underline(url)}`));
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Localnet: use custom RPC URL in explorer
|
|
176
|
+
const customUrl = encodeURIComponent("http://localhost:8899");
|
|
177
|
+
const url = `https://explorer.solana.com/tx/${signature}?cluster=custom&customUrl=${customUrl}`;
|
|
178
|
+
console.log(chalk_1.default.gray(` View: ${chalk_1.default.underline(url)}`));
|
|
179
|
+
}
|
|
180
|
+
console.log();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Print error message
|
|
184
|
+
*/
|
|
185
|
+
function printError(message) {
|
|
186
|
+
console.log();
|
|
187
|
+
console.log(chalk_1.default.red(`✗ Error: ${message}`));
|
|
188
|
+
console.log();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Print info message
|
|
192
|
+
*/
|
|
193
|
+
function printInfo(message) {
|
|
194
|
+
console.log(chalk_1.default.cyan(`ℹ ${message}`));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Print success message
|
|
198
|
+
*/
|
|
199
|
+
function printSuccess(message) {
|
|
200
|
+
console.log(chalk_1.default.green(`✓ ${message}`));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Print mock mode warning
|
|
204
|
+
*/
|
|
205
|
+
function printMockWarning() {
|
|
206
|
+
console.log(chalk_1.default.yellow("⚠ Running in mock mode - no blockchain interaction"));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Print batch history table
|
|
210
|
+
*/
|
|
211
|
+
function printBatchHistory(logs) {
|
|
212
|
+
printHeader("Batch History");
|
|
213
|
+
if (logs.length === 0) {
|
|
214
|
+
console.log(chalk_1.default.gray(" No executed batches found."));
|
|
215
|
+
console.log(chalk_1.default.gray(" Batches are executed when 8+ orders accumulate."));
|
|
216
|
+
console.log();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const pairLabels = ["TSLA/USDC", "SPY/USDC", "AAPL/USDC", "TSLA/SPY", "TSLA/AAPL", "SPY/AAPL"];
|
|
220
|
+
const format = (val) => {
|
|
221
|
+
const num = Number(val) / 1000000; // 6 decimals
|
|
222
|
+
if (num === 0)
|
|
223
|
+
return chalk_1.default.gray("-");
|
|
224
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
225
|
+
};
|
|
226
|
+
for (const log of logs) {
|
|
227
|
+
console.log();
|
|
228
|
+
console.log(chalk_1.default.bold.white(` Batch #${log.batchId}`));
|
|
229
|
+
console.log(chalk_1.default.gray(" " + "─".repeat(50)));
|
|
230
|
+
// Check if there was any activity
|
|
231
|
+
let hasActivity = false;
|
|
232
|
+
for (let i = 0; i < log.results.length; i++) {
|
|
233
|
+
const r = log.results[i];
|
|
234
|
+
const totalAIn = r.totalAIn.toString();
|
|
235
|
+
const totalBIn = r.totalBIn.toString();
|
|
236
|
+
if (totalAIn !== "0" || totalBIn !== "0") {
|
|
237
|
+
hasActivity = true;
|
|
238
|
+
const [baseAsset, quoteAsset] = pairLabels[i].split("/");
|
|
239
|
+
console.log(` ${chalk_1.default.cyan(pairLabels[i])}:`);
|
|
240
|
+
console.log(` ${chalk_1.default.gray("Inflow")} ${baseAsset}: ${format(totalAIn)} ${quoteAsset}: ${format(totalBIn)}`);
|
|
241
|
+
console.log(` ${chalk_1.default.gray("Pool")} A: ${format(r.finalPoolA.toString())} B: ${format(r.finalPoolB.toString())}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!hasActivity) {
|
|
245
|
+
console.log(chalk_1.default.gray(" No trading activity"));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
console.log();
|
|
249
|
+
console.log(chalk_1.default.gray(` Total batches executed: ${logs.length}`));
|
|
250
|
+
console.log();
|
|
251
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { RescueCipher } from "@arcium-hq/client";
|
|
4
|
+
import { AssetId, PairId, Direction } from "./constants";
|
|
5
|
+
import type { ShuffleConfig, UserBalance, OrderInfo, DecryptedOrderInfo, BatchInfo, BatchResult, EstimatedPayout, EffectiveBalance } from "./types";
|
|
6
|
+
export declare class ShuffleClient {
|
|
7
|
+
private connection;
|
|
8
|
+
private wallet;
|
|
9
|
+
private programId;
|
|
10
|
+
private provider;
|
|
11
|
+
private program;
|
|
12
|
+
private mxePublicKey;
|
|
13
|
+
private clusterOffset;
|
|
14
|
+
private clusterAccount;
|
|
15
|
+
private poolPDA;
|
|
16
|
+
private batchAccumulatorPDA;
|
|
17
|
+
private cipher;
|
|
18
|
+
private encryptionPublicKey;
|
|
19
|
+
private constructor();
|
|
20
|
+
/** Async factory — creates and initializes the client */
|
|
21
|
+
static create(config: ShuffleConfig): Promise<ShuffleClient>;
|
|
22
|
+
private initialize;
|
|
23
|
+
/** Get the MXE public key (needed for cipher creation) */
|
|
24
|
+
getMXEPublicKey(): Uint8Array;
|
|
25
|
+
/** Get the underlying Anchor program */
|
|
26
|
+
getProgram(): Program<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Initialize encryption from a user's x25519 private key.
|
|
29
|
+
* Creates the cipher and derives the public key.
|
|
30
|
+
* Call this after create() to enable encrypted operations.
|
|
31
|
+
*/
|
|
32
|
+
initEncryption(privateKey: Uint8Array): void;
|
|
33
|
+
/** Get the encryption public key (available after initEncryption) */
|
|
34
|
+
getEncryptionPublicKey(): Uint8Array | null;
|
|
35
|
+
/** Get the cipher (available after initEncryption) */
|
|
36
|
+
getCipher(): RescueCipher | null;
|
|
37
|
+
private _requireEncryption;
|
|
38
|
+
/** Create a new user privacy account. Uses internal encryption if initialized. */
|
|
39
|
+
createUserAccount(encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
40
|
+
/** Fetch UserProfile data for an owner */
|
|
41
|
+
fetchUserAccount(owner?: PublicKey): Promise<any>;
|
|
42
|
+
/** Check if account exists */
|
|
43
|
+
accountExists(owner?: PublicKey): Promise<boolean>;
|
|
44
|
+
/** Deposit tokens into the protocol (add_balance). Uses internal encryption if params omitted. */
|
|
45
|
+
deposit(assetId: AssetId, amount: number, cipher?: RescueCipher, encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
46
|
+
/** Withdraw tokens from the protocol (sub_balance). Uses internal encryption if params omitted. */
|
|
47
|
+
withdraw(assetId: AssetId, amount: number, cipher?: RescueCipher, encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
48
|
+
/** Decrypt all 4 asset balances from on-chain account. Uses internal cipher if param omitted. */
|
|
49
|
+
getBalance(cipher?: RescueCipher, owner?: PublicKey): Promise<UserBalance>;
|
|
50
|
+
/** Get unshielded (normal SPL token) balances from wallet */
|
|
51
|
+
getUnshieldedBalances(owner?: PublicKey): Promise<UserBalance>;
|
|
52
|
+
/** Internal P2P transfer (USDC only). Uses internal encryption if params omitted. */
|
|
53
|
+
transfer(recipientPubkey: PublicKey, amount: number, cipher?: RescueCipher, encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Initialize batch state with encrypted zeros.
|
|
56
|
+
* This must be called before the first order of each new batch.
|
|
57
|
+
* After batch execution, the batch state needs to be re-initialized for the next batch.
|
|
58
|
+
*/
|
|
59
|
+
initBatchState(): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Place an encrypted order in the current batch.
|
|
62
|
+
* Automatically initializes batch state if needed (first order of a new batch).
|
|
63
|
+
* Uses internal encryption if params omitted.
|
|
64
|
+
*/
|
|
65
|
+
placeOrder(pairId: PairId, direction: Direction, amount: number, sourceAssetId: AssetId, cipher?: RescueCipher, encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
66
|
+
/** Get current pending order info, or null */
|
|
67
|
+
getPendingOrder(owner?: PublicKey): Promise<OrderInfo | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Get decrypted pending order info.
|
|
70
|
+
* Decrypts pairId, direction, and amount using user's cipher.
|
|
71
|
+
* The order nonce is stored on-chain, so no need to save it locally.
|
|
72
|
+
*
|
|
73
|
+
* @param cipher - Optional cipher (uses internal if omitted)
|
|
74
|
+
* @param owner - Optional owner pubkey (uses wallet if omitted)
|
|
75
|
+
*/
|
|
76
|
+
getDecryptedOrder(cipher?: RescueCipher, owner?: PublicKey): Promise<DecryptedOrderInfo | null>;
|
|
77
|
+
/** Cancel pending order — not yet implemented */
|
|
78
|
+
cancelOrder(): Promise<never>;
|
|
79
|
+
/** Execute the current batch when 8+ orders are accumulated. Anyone can call this. */
|
|
80
|
+
executeBatch(): Promise<string>;
|
|
81
|
+
/** Settle a pending order after batch execution. Uses internal encryption if param omitted. */
|
|
82
|
+
settleOrder(pairId: number, direction: number, encryptionPublicKey?: Uint8Array): Promise<string>;
|
|
83
|
+
/** Fetch current batch accumulator state */
|
|
84
|
+
getBatchInfo(): Promise<BatchInfo>;
|
|
85
|
+
/** Fetch historical batch log */
|
|
86
|
+
getBatchLog(batchId: number): Promise<BatchResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Fetch all historical batch logs.
|
|
89
|
+
* Iterates from batch 1 to the current batch ID and returns all found logs.
|
|
90
|
+
* @returns Array of BatchResult for all executed batches
|
|
91
|
+
*/
|
|
92
|
+
getAllBatchLogs(): Promise<BatchResult[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Estimate payout for a pending order after batch execution.
|
|
95
|
+
* Uses client-side calculation: payout = (orderAmount / totalInput) * finalPoolOutput
|
|
96
|
+
*
|
|
97
|
+
* @param cipher - Optional cipher (uses internal if omitted)
|
|
98
|
+
* @param owner - Optional owner pubkey (uses wallet if omitted)
|
|
99
|
+
* @returns EstimatedPayout or null if no pending order or batch not executed
|
|
100
|
+
*/
|
|
101
|
+
estimatePayout(cipher?: RescueCipher, owner?: PublicKey): Promise<EstimatedPayout | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Get effective balance for an asset, including pending payout.
|
|
104
|
+
* Combines current on-chain balance with estimated payout from pending order.
|
|
105
|
+
*
|
|
106
|
+
* @param assetId - Asset to check (0=USDC, 1=TSLA, 2=SPY, 3=AAPL)
|
|
107
|
+
* @param cipher - Optional cipher (uses internal if omitted)
|
|
108
|
+
* @param owner - Optional owner pubkey (uses wallet if omitted)
|
|
109
|
+
* @returns EffectiveBalance with current, pending, and total
|
|
110
|
+
*/
|
|
111
|
+
getEffectiveBalance(assetId: AssetId, cipher?: RescueCipher, owner?: PublicKey): Promise<EffectiveBalance>;
|
|
112
|
+
/**
|
|
113
|
+
* Helper to determine output asset ID based on pair and direction
|
|
114
|
+
*/
|
|
115
|
+
private _getOutputAssetId;
|
|
116
|
+
/** Fetch pool account data */
|
|
117
|
+
getPoolInfo(): Promise<any>;
|
|
118
|
+
private _getArciumAccounts;
|
|
119
|
+
private _awaitComputation;
|
|
120
|
+
private _generateComputationOffset;
|
|
121
|
+
}
|