@veilo/sdk-core 0.5.0 → 0.7.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 +282 -18
- package/accounts.d.ts +2 -0
- package/accounts.js +3 -0
- package/cloak.d.ts +2 -0
- package/cloak.js +3 -0
- package/config.d.ts +2 -0
- package/config.js +3 -0
- package/dist/cjs/events/index.d.ts +6 -0
- package/dist/cjs/events/index.js +22 -0
- package/dist/cjs/events/parsing.d.ts +25 -0
- package/dist/cjs/events/parsing.js +158 -0
- package/dist/cjs/events/position.d.ts +26 -0
- package/dist/cjs/events/position.js +53 -0
- package/dist/cjs/events/recovery.d.ts +87 -0
- package/dist/cjs/events/recovery.js +281 -0
- package/dist/cjs/events/scanning.d.ts +35 -0
- package/dist/cjs/events/scanning.js +98 -0
- package/dist/cjs/events/tree.d.ts +27 -0
- package/dist/cjs/events/tree.js +63 -0
- package/dist/cjs/events/types.d.ts +39 -0
- package/dist/cjs/events/types.js +2 -0
- package/dist/cjs/events.d.ts +1 -77
- package/dist/cjs/events.js +6 -154
- package/dist/cjs/identity/encoding.d.ts +9 -0
- package/dist/cjs/identity/encoding.js +85 -0
- package/dist/cjs/identity/index.d.ts +4 -0
- package/dist/cjs/identity/index.js +20 -0
- package/dist/cjs/identity/noteKey.d.ts +33 -0
- package/dist/cjs/identity/noteKey.js +97 -0
- package/dist/cjs/identity/spending.d.ts +18 -0
- package/dist/cjs/identity/spending.js +46 -0
- package/dist/cjs/identity/viewKey.d.ts +38 -0
- package/dist/cjs/identity/viewKey.js +105 -0
- package/dist/cjs/idl/index.d.ts +18 -0
- package/dist/cjs/idl/index.js +24 -0
- package/dist/cjs/idl/privacy_pool.json +9907 -9907
- package/dist/cjs/idl/privacy_pool_legacy.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
- package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
- package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
- package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/cjs/index.d.ts +8 -3
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/notes/amount.d.ts +2 -0
- package/dist/cjs/notes/amount.js +21 -0
- package/dist/cjs/notes/index.d.ts +4 -0
- package/dist/cjs/notes/index.js +4 -0
- package/dist/cjs/notes/recovery.d.ts +16 -6
- package/dist/cjs/notes/recovery.js +33 -16
- package/dist/cjs/notes/scan.d.ts +74 -0
- package/dist/cjs/notes/scan.js +110 -0
- package/dist/cjs/notes/selection.d.ts +133 -0
- package/dist/cjs/notes/selection.js +260 -0
- package/dist/cjs/notes/spent.d.ts +60 -0
- package/dist/cjs/notes/spent.js +101 -0
- package/dist/cjs/perps/constants.d.ts +16 -0
- package/dist/cjs/perps/constants.js +52 -0
- package/dist/cjs/perps/index.d.ts +5 -0
- package/dist/cjs/perps/index.js +21 -0
- package/dist/cjs/perps/keys.d.ts +16 -0
- package/dist/cjs/perps/keys.js +43 -0
- package/dist/cjs/perps/pdas.d.ts +29 -0
- package/dist/cjs/perps/pdas.js +55 -0
- package/dist/cjs/perps/relayer.d.ts +9 -0
- package/dist/cjs/perps/relayer.js +35 -0
- package/dist/cjs/perps/types.d.ts +126 -0
- package/dist/cjs/perps/types.js +2 -0
- package/dist/cjs/positions/index.d.ts +4 -0
- package/dist/cjs/positions/index.js +20 -0
- package/dist/cjs/positions/keys.d.ts +29 -0
- package/dist/cjs/positions/keys.js +71 -0
- package/dist/cjs/positions/pdas.d.ts +15 -0
- package/dist/cjs/positions/pdas.js +54 -0
- package/dist/cjs/positions/relayer.d.ts +4 -0
- package/dist/cjs/positions/relayer.js +15 -0
- package/dist/cjs/positions/types.d.ts +97 -0
- package/dist/cjs/positions/types.js +2 -0
- package/dist/cjs/predictions/client.d.ts +41 -0
- package/dist/cjs/predictions/client.js +147 -0
- package/dist/cjs/predictions/index.d.ts +5 -0
- package/dist/cjs/predictions/index.js +21 -0
- package/dist/cjs/predictions/keys.d.ts +14 -0
- package/dist/cjs/predictions/keys.js +40 -0
- package/dist/cjs/predictions/pdas.d.ts +6 -0
- package/dist/cjs/predictions/pdas.js +13 -0
- package/dist/cjs/predictions/relayer.d.ts +3 -0
- package/dist/cjs/predictions/relayer.js +11 -0
- package/dist/cjs/predictions/types.d.ts +178 -0
- package/dist/cjs/predictions/types.js +2 -0
- package/dist/cjs/program.d.ts +2 -0
- package/dist/cjs/program.js +8 -7
- package/dist/cjs/prover.d.ts +27 -4
- package/dist/cjs/prover.js +107 -48
- package/dist/cjs/relayer/api.d.ts +41 -0
- package/dist/cjs/relayer/api.js +99 -0
- package/dist/cjs/relayer/client.d.ts +42 -17
- package/dist/cjs/relayer/client.js +94 -17
- package/dist/cjs/relayer/errors.d.ts +1 -1
- package/dist/cjs/relayer/errors.js +1 -1
- package/dist/cjs/relayer/index.d.ts +4 -1
- package/dist/cjs/relayer/index.js +1 -1
- package/dist/cjs/relayer/internal-config.d.ts +36 -0
- package/dist/cjs/relayer/internal-config.js +9 -0
- package/dist/cjs/relayer/internal.d.ts +6 -0
- package/dist/cjs/relayer/internal.js +14 -0
- package/dist/cjs/relayer/transport.d.ts +4 -2
- package/dist/cjs/relayer/transport.js +10 -5
- package/dist/cjs/relayer/types.d.ts +40 -10
- package/dist/cjs/relayer/types.js +1 -1
- package/dist/cjs/shield/owner.js +1 -4
- package/dist/esm/events/index.d.ts +6 -0
- package/dist/esm/events/index.js +6 -0
- package/dist/esm/events/parsing.d.ts +25 -0
- package/dist/esm/events/parsing.js +120 -0
- package/dist/esm/events/position.d.ts +26 -0
- package/dist/esm/events/position.js +48 -0
- package/dist/esm/events/recovery.d.ts +87 -0
- package/dist/esm/events/recovery.js +237 -0
- package/dist/esm/events/scanning.d.ts +35 -0
- package/dist/esm/events/scanning.js +92 -0
- package/dist/esm/events/tree.d.ts +27 -0
- package/dist/esm/events/tree.js +58 -0
- package/dist/esm/events/types.d.ts +39 -0
- package/dist/esm/events/types.js +1 -0
- package/dist/esm/events.d.ts +1 -77
- package/dist/esm/events.js +3 -129
- package/dist/esm/identity/encoding.d.ts +9 -0
- package/dist/esm/identity/encoding.js +75 -0
- package/dist/esm/identity/index.d.ts +4 -0
- package/dist/esm/identity/index.js +4 -0
- package/dist/esm/identity/noteKey.d.ts +33 -0
- package/dist/esm/identity/noteKey.js +91 -0
- package/dist/esm/identity/spending.d.ts +18 -0
- package/dist/esm/identity/spending.js +35 -0
- package/dist/esm/identity/viewKey.d.ts +38 -0
- package/dist/esm/identity/viewKey.js +96 -0
- package/dist/esm/idl/index.d.ts +18 -0
- package/dist/esm/idl/index.js +18 -0
- package/dist/esm/idl/privacy_pool.json +9907 -9907
- package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
- package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
- package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
- package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
- package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
- package/dist/esm/index.d.ts +8 -3
- package/dist/esm/index.js +8 -3
- package/dist/esm/notes/amount.d.ts +2 -0
- package/dist/esm/notes/amount.js +18 -0
- package/dist/esm/notes/index.d.ts +4 -0
- package/dist/esm/notes/index.js +4 -0
- package/dist/esm/notes/recovery.d.ts +16 -6
- package/dist/esm/notes/recovery.js +33 -16
- package/dist/esm/notes/scan.d.ts +74 -0
- package/dist/esm/notes/scan.js +105 -0
- package/dist/esm/notes/selection.d.ts +133 -0
- package/dist/esm/notes/selection.js +254 -0
- package/dist/esm/notes/spent.d.ts +60 -0
- package/dist/esm/notes/spent.js +96 -0
- package/dist/esm/perps/constants.d.ts +16 -0
- package/dist/esm/perps/constants.js +48 -0
- package/dist/esm/perps/index.d.ts +5 -0
- package/dist/esm/perps/index.js +5 -0
- package/dist/esm/perps/keys.d.ts +16 -0
- package/dist/esm/perps/keys.js +35 -0
- package/dist/esm/perps/pdas.d.ts +29 -0
- package/dist/esm/perps/pdas.js +47 -0
- package/dist/esm/perps/relayer.d.ts +9 -0
- package/dist/esm/perps/relayer.js +25 -0
- package/dist/esm/perps/types.d.ts +126 -0
- package/dist/esm/perps/types.js +1 -0
- package/dist/esm/positions/index.d.ts +4 -0
- package/dist/esm/positions/index.js +4 -0
- package/dist/esm/positions/keys.d.ts +29 -0
- package/dist/esm/positions/keys.js +65 -0
- package/dist/esm/positions/pdas.d.ts +15 -0
- package/dist/esm/positions/pdas.js +44 -0
- package/dist/esm/positions/relayer.d.ts +4 -0
- package/dist/esm/positions/relayer.js +10 -0
- package/dist/esm/positions/types.d.ts +97 -0
- package/dist/esm/positions/types.js +1 -0
- package/dist/esm/predictions/client.d.ts +41 -0
- package/dist/esm/predictions/client.js +141 -0
- package/dist/esm/predictions/index.d.ts +5 -0
- package/dist/esm/predictions/index.js +5 -0
- package/dist/esm/predictions/keys.d.ts +14 -0
- package/dist/esm/predictions/keys.js +33 -0
- package/dist/esm/predictions/pdas.d.ts +6 -0
- package/dist/esm/predictions/pdas.js +10 -0
- package/dist/esm/predictions/relayer.d.ts +3 -0
- package/dist/esm/predictions/relayer.js +7 -0
- package/dist/esm/predictions/types.d.ts +178 -0
- package/dist/esm/predictions/types.js +1 -0
- package/dist/esm/program.d.ts +2 -0
- package/dist/esm/program.js +4 -3
- package/dist/esm/prover.d.ts +27 -4
- package/dist/esm/prover.js +106 -15
- package/dist/esm/relayer/api.d.ts +41 -0
- package/dist/esm/relayer/api.js +66 -0
- package/dist/esm/relayer/client.d.ts +42 -17
- package/dist/esm/relayer/client.js +94 -17
- package/dist/esm/relayer/errors.d.ts +1 -1
- package/dist/esm/relayer/errors.js +1 -1
- package/dist/esm/relayer/index.d.ts +4 -1
- package/dist/esm/relayer/index.js +1 -1
- package/dist/esm/relayer/internal-config.d.ts +36 -0
- package/dist/esm/relayer/internal-config.js +6 -0
- package/dist/esm/relayer/internal.d.ts +6 -0
- package/dist/esm/relayer/internal.js +10 -0
- package/dist/esm/relayer/transport.d.ts +4 -2
- package/dist/esm/relayer/transport.js +10 -5
- package/dist/esm/relayer/types.d.ts +40 -10
- package/dist/esm/relayer/types.js +1 -1
- package/dist/esm/shield/owner.js +1 -4
- package/identity.d.ts +2 -0
- package/identity.js +3 -0
- package/idl.d.ts +2 -0
- package/idl.js +3 -0
- package/notes.d.ts +2 -0
- package/notes.js +3 -0
- package/package.json +85 -3
- package/perps.d.ts +2 -0
- package/perps.js +3 -0
- package/poseidon.d.ts +2 -0
- package/poseidon.js +3 -0
- package/positions.d.ts +2 -0
- package/positions.js +3 -0
- package/predictions.d.ts +2 -0
- package/predictions.js +3 -0
- package/proof.d.ts +2 -0
- package/proof.js +3 -0
- package/prover.d.ts +2 -0
- package/prover.js +3 -0
- package/relayer.d.ts +2 -0
- package/relayer.js +3 -0
- package/shield.d.ts +2 -0
- package/shield.js +3 -0
- package/transactions.d.ts +2 -0
- package/transactions.js +3 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JupiterPredictionClient = exports.JupiterPredictionApiError = exports.POLYMARKET_CLOB_API_URL = exports.JUPITER_PREDICTION_API_URL = void 0;
|
|
4
|
+
exports.deserializePredictionTransaction = deserializePredictionTransaction;
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
exports.JUPITER_PREDICTION_API_URL = "https://api.jup.ag/prediction/v1";
|
|
7
|
+
exports.POLYMARKET_CLOB_API_URL = "https://clob.polymarket.com";
|
|
8
|
+
class JupiterPredictionApiError extends Error {
|
|
9
|
+
constructor(status, responseBody) {
|
|
10
|
+
const body = typeof responseBody === "object" && responseBody !== null
|
|
11
|
+
? responseBody
|
|
12
|
+
: undefined;
|
|
13
|
+
const message = typeof responseBody === "string" && responseBody
|
|
14
|
+
? responseBody
|
|
15
|
+
: typeof body?.message === "string"
|
|
16
|
+
? body.message
|
|
17
|
+
: typeof body?.error === "string"
|
|
18
|
+
? body.error
|
|
19
|
+
: `Jupiter Prediction API request failed: ${status}`;
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "JupiterPredictionApiError";
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.code = typeof body?.error === "string" ? body.error : undefined;
|
|
24
|
+
this.responseBody = responseBody;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.JupiterPredictionApiError = JupiterPredictionApiError;
|
|
28
|
+
/** Typed client for the unsigned Jupiter Prediction transaction API. */
|
|
29
|
+
class JupiterPredictionClient {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.apiKey = config.apiKey;
|
|
32
|
+
this.baseUrl = normalizeBaseUrl(config.baseUrl ?? exports.JUPITER_PREDICTION_API_URL, "baseUrl");
|
|
33
|
+
this.polymarketBaseUrl = normalizeBaseUrl(config.polymarketBaseUrl ?? exports.POLYMARKET_CLOB_API_URL, "polymarketBaseUrl");
|
|
34
|
+
this.fetcher = config.fetch ?? fetch;
|
|
35
|
+
}
|
|
36
|
+
async listEvents(params = {}) {
|
|
37
|
+
const query = new URLSearchParams({ status: params.status ?? "live" });
|
|
38
|
+
if (params.category)
|
|
39
|
+
query.set("category", params.category);
|
|
40
|
+
return (await this.request(`/events?${query}`)).data;
|
|
41
|
+
}
|
|
42
|
+
async getEvent(eventId) {
|
|
43
|
+
return this.request(`/events/${encodeURIComponent(eventId)}`);
|
|
44
|
+
}
|
|
45
|
+
async listPositions(ownerPubkey) {
|
|
46
|
+
return (await this.request(`/positions?ownerPubkey=${encodeURIComponent(ownerPubkey)}`)).data;
|
|
47
|
+
}
|
|
48
|
+
async listHistory(ownerPubkey) {
|
|
49
|
+
return (await this.request(`/history?ownerPubkey=${encodeURIComponent(ownerPubkey)}`)).data;
|
|
50
|
+
}
|
|
51
|
+
async getPosition(positionPubkey) {
|
|
52
|
+
return this.request(`/positions/${encodeURIComponent(positionPubkey)}`);
|
|
53
|
+
}
|
|
54
|
+
async placeOrder(request) {
|
|
55
|
+
return this.request("/orders", { method: "POST", body: request });
|
|
56
|
+
}
|
|
57
|
+
async getOrderStatus(orderPubkey) {
|
|
58
|
+
return this.request(`/orders/status/${encodeURIComponent(orderPubkey)}`);
|
|
59
|
+
}
|
|
60
|
+
async closePosition(positionPubkey, ownerPubkey) {
|
|
61
|
+
return this.request(`/positions/${encodeURIComponent(positionPubkey)}`, {
|
|
62
|
+
method: "DELETE",
|
|
63
|
+
body: { ownerPubkey },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async closeAllPositions(ownerPubkey, minSellPriceSlippageBps = 300) {
|
|
67
|
+
return this.request("/positions", {
|
|
68
|
+
method: "DELETE",
|
|
69
|
+
body: { ownerPubkey, minSellPriceSlippageBps },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async claimPosition(positionPubkey, ownerPubkey) {
|
|
73
|
+
return this.request(`/positions/${encodeURIComponent(positionPubkey)}/claim`, { method: "POST", body: { ownerPubkey } });
|
|
74
|
+
}
|
|
75
|
+
async getPriceHistory(clobTokenId, interval) {
|
|
76
|
+
const fidelity = {
|
|
77
|
+
"1d": 5,
|
|
78
|
+
"1w": 30,
|
|
79
|
+
"1m": 180,
|
|
80
|
+
max: 180,
|
|
81
|
+
};
|
|
82
|
+
const query = new URLSearchParams({
|
|
83
|
+
market: clobTokenId,
|
|
84
|
+
interval,
|
|
85
|
+
fidelity: String(fidelity[interval]),
|
|
86
|
+
});
|
|
87
|
+
const response = await this.fetcher(`${this.polymarketBaseUrl}/prices-history?${query}`);
|
|
88
|
+
const body = await readResponseBody(response);
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new JupiterPredictionApiError(response.status, body);
|
|
91
|
+
}
|
|
92
|
+
return body.history ?? [];
|
|
93
|
+
}
|
|
94
|
+
async request(path, options = {}) {
|
|
95
|
+
const response = await this.fetcher(`${this.baseUrl}${path}`, {
|
|
96
|
+
method: options.method ?? "GET",
|
|
97
|
+
headers: {
|
|
98
|
+
"x-api-key": this.apiKey,
|
|
99
|
+
...(options.body === undefined
|
|
100
|
+
? {}
|
|
101
|
+
: { "Content-Type": "application/json" }),
|
|
102
|
+
},
|
|
103
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
104
|
+
});
|
|
105
|
+
const body = await readResponseBody(response);
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
throw new JupiterPredictionApiError(response.status, body);
|
|
108
|
+
}
|
|
109
|
+
return body;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.JupiterPredictionClient = JupiterPredictionClient;
|
|
113
|
+
/** Decode an unsigned transaction returned by Jupiter for wallet signing. */
|
|
114
|
+
function deserializePredictionTransaction(response) {
|
|
115
|
+
if (!response.transaction) {
|
|
116
|
+
throw new TypeError("Prediction transaction must not be empty");
|
|
117
|
+
}
|
|
118
|
+
return web3_js_1.VersionedTransaction.deserialize(decodeBase64(response.transaction));
|
|
119
|
+
}
|
|
120
|
+
function normalizeBaseUrl(value, label) {
|
|
121
|
+
const normalized = value.trim().replace(/\/+$/, "");
|
|
122
|
+
if (!normalized)
|
|
123
|
+
throw new TypeError(`${label} must not be empty`);
|
|
124
|
+
return normalized;
|
|
125
|
+
}
|
|
126
|
+
async function readResponseBody(response) {
|
|
127
|
+
const body = await response.text();
|
|
128
|
+
if (!body)
|
|
129
|
+
return {};
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(body);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return body;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function decodeBase64(encoded) {
|
|
138
|
+
if (typeof Buffer !== "undefined") {
|
|
139
|
+
return new Uint8Array(Buffer.from(encoded, "base64"));
|
|
140
|
+
}
|
|
141
|
+
const binary = atob(encoded);
|
|
142
|
+
const bytes = new Uint8Array(binary.length);
|
|
143
|
+
for (let index = 0; index < binary.length; index++) {
|
|
144
|
+
bytes[index] = binary.charCodeAt(index);
|
|
145
|
+
}
|
|
146
|
+
return bytes;
|
|
147
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types.js"), exports);
|
|
18
|
+
__exportStar(require("./keys.js"), exports);
|
|
19
|
+
__exportStar(require("./pdas.js"), exports);
|
|
20
|
+
__exportStar(require("./client.js"), exports);
|
|
21
|
+
__exportStar(require("./relayer.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Keypair } from "@solana/web3.js";
|
|
2
|
+
export interface PredictionKeyBundle {
|
|
3
|
+
withdrawalId: Uint8Array;
|
|
4
|
+
withdrawalIdHex: string;
|
|
5
|
+
ephemeral: Keypair;
|
|
6
|
+
claimantPublicKey: string;
|
|
7
|
+
claimantSecretKey: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function derivePredictionEphemeralKeypair(spendingKey: Uint8Array, nonce: number): Keypair;
|
|
10
|
+
export declare function derivePredictionWithdrawalId(spendingKey: Uint8Array, nonce: number): Uint8Array;
|
|
11
|
+
export declare function predictionWithdrawalIdToHex(withdrawalId: Uint8Array): string;
|
|
12
|
+
export declare function predictionWithdrawalIdFromHex(value: string): Uint8Array;
|
|
13
|
+
/** Derive every client-held key field needed across a prediction lifecycle. */
|
|
14
|
+
export declare function derivePredictionKeyBundle(spendingKey: Uint8Array, nonce: number): PredictionKeyBundle;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.derivePredictionEphemeralKeypair = derivePredictionEphemeralKeypair;
|
|
4
|
+
exports.derivePredictionWithdrawalId = derivePredictionWithdrawalId;
|
|
5
|
+
exports.predictionWithdrawalIdToHex = predictionWithdrawalIdToHex;
|
|
6
|
+
exports.predictionWithdrawalIdFromHex = predictionWithdrawalIdFromHex;
|
|
7
|
+
exports.derivePredictionKeyBundle = derivePredictionKeyBundle;
|
|
8
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
9
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
+
const encoding_js_1 = require("../identity/encoding.js");
|
|
11
|
+
function derivePredictionEphemeralKeypair(spendingKey, nonce) {
|
|
12
|
+
(0, encoding_js_1.assertBytes)(spendingKey, 32, "spending key");
|
|
13
|
+
if (!Number.isSafeInteger(nonce) || nonce < 0) {
|
|
14
|
+
throw new RangeError("prediction nonce must be a non-negative safe integer");
|
|
15
|
+
}
|
|
16
|
+
return web3_js_1.Keypair.fromSeed((0, sha256_1.sha256)((0, encoding_js_1.concatBytes)((0, encoding_js_1.utf8)("prediction_ephemeral"), spendingKey, (0, encoding_js_1.uint64Le)(BigInt(nonce), "prediction nonce"))));
|
|
17
|
+
}
|
|
18
|
+
function derivePredictionWithdrawalId(spendingKey, nonce) {
|
|
19
|
+
(0, encoding_js_1.assertBytes)(spendingKey, 32, "spending key");
|
|
20
|
+
return (0, sha256_1.sha256)((0, encoding_js_1.concatBytes)((0, encoding_js_1.utf8)("prediction_withdrawal_v1"), spendingKey, (0, encoding_js_1.uint32Le)(nonce, "prediction nonce")));
|
|
21
|
+
}
|
|
22
|
+
function predictionWithdrawalIdToHex(withdrawalId) {
|
|
23
|
+
(0, encoding_js_1.assertBytes)(withdrawalId, 32, "prediction withdrawal ID");
|
|
24
|
+
return (0, encoding_js_1.bytesToHex)(withdrawalId);
|
|
25
|
+
}
|
|
26
|
+
function predictionWithdrawalIdFromHex(value) {
|
|
27
|
+
return (0, encoding_js_1.hexToBytes)(value, 32, "prediction withdrawal ID");
|
|
28
|
+
}
|
|
29
|
+
/** Derive every client-held key field needed across a prediction lifecycle. */
|
|
30
|
+
function derivePredictionKeyBundle(spendingKey, nonce) {
|
|
31
|
+
const withdrawalId = derivePredictionWithdrawalId(spendingKey, nonce);
|
|
32
|
+
const ephemeral = derivePredictionEphemeralKeypair(spendingKey, nonce);
|
|
33
|
+
return {
|
|
34
|
+
withdrawalId,
|
|
35
|
+
withdrawalIdHex: predictionWithdrawalIdToHex(withdrawalId),
|
|
36
|
+
ephemeral,
|
|
37
|
+
claimantPublicKey: ephemeral.publicKey.toBase58(),
|
|
38
|
+
claimantSecretKey: (0, encoding_js_1.encodeBase58)(ephemeral.secretKey),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.derivePredictionSlotPda = derivePredictionSlotPda;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const encoding_js_1 = require("../identity/encoding.js");
|
|
6
|
+
function derivePredictionSlotPda(params) {
|
|
7
|
+
(0, encoding_js_1.assertBytes)(params.withdrawalId, 32, "prediction withdrawal ID");
|
|
8
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
9
|
+
(0, encoding_js_1.utf8)("prediction_slot_v1"),
|
|
10
|
+
params.mint.toBytes(),
|
|
11
|
+
params.withdrawalId,
|
|
12
|
+
], params.programId)[0];
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PredictionOpenRequest, PredictionOpenResponse, PredictionReissueRequest, PredictionReissueResponse } from "./types.js";
|
|
2
|
+
export declare function submitPredictionOpen(data: PredictionOpenRequest): Promise<PredictionOpenResponse>;
|
|
3
|
+
export declare function submitPredictionReissue(data: PredictionReissueRequest): Promise<PredictionReissueResponse>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitPredictionOpen = submitPredictionOpen;
|
|
4
|
+
exports.submitPredictionReissue = submitPredictionReissue;
|
|
5
|
+
const internal_js_1 = require("../relayer/internal.js");
|
|
6
|
+
function submitPredictionOpen(data) {
|
|
7
|
+
return (0, internal_js_1.getInternalRelayerClient)().submitPredictionOpen(data);
|
|
8
|
+
}
|
|
9
|
+
function submitPredictionReissue(data) {
|
|
10
|
+
return (0, internal_js_1.getInternalRelayerClient)().submitPredictionReissue(data);
|
|
11
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { TransactNote } from "../relayer/types.js";
|
|
2
|
+
export interface PredictionOpenRequest {
|
|
3
|
+
notes: TransactNote[];
|
|
4
|
+
/** USDC stake, raw 6-decimal units. */
|
|
5
|
+
depositAmount: string;
|
|
6
|
+
/** 32-byte prediction-slot withdrawal ID, hex. */
|
|
7
|
+
withdrawalId: string;
|
|
8
|
+
/** Deterministic ephemeral wallet and open-proof claimant, base58. */
|
|
9
|
+
claimantPublicKey: string;
|
|
10
|
+
userPublicKey: string;
|
|
11
|
+
}
|
|
12
|
+
export interface PredictionOpenResponse {
|
|
13
|
+
success: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
data?: {
|
|
16
|
+
txSignature: string;
|
|
17
|
+
ephemeralWallet: string;
|
|
18
|
+
ephemeralTokenAccount: string;
|
|
19
|
+
changeAmount: string;
|
|
20
|
+
fee: string;
|
|
21
|
+
feeBps: number;
|
|
22
|
+
totalDebited: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface PredictionReissueRequest {
|
|
26
|
+
withdrawalId: string;
|
|
27
|
+
claimantSecretKey: string;
|
|
28
|
+
/** Kept for API compatibility; the relayer reads the real chain balance. */
|
|
29
|
+
reissueAmount: string;
|
|
30
|
+
veiloPublicKey: string;
|
|
31
|
+
userPublicKey: string;
|
|
32
|
+
}
|
|
33
|
+
export interface PredictionReissueResponse {
|
|
34
|
+
success: boolean;
|
|
35
|
+
message: string;
|
|
36
|
+
data?: {
|
|
37
|
+
txSignature: string | null;
|
|
38
|
+
reissueAmount: string;
|
|
39
|
+
fee?: string;
|
|
40
|
+
tradeHappened?: boolean;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface PredictionMarketPricing {
|
|
44
|
+
buyYesPriceUsd: number;
|
|
45
|
+
sellYesPriceUsd: number;
|
|
46
|
+
buyNoPriceUsd: number;
|
|
47
|
+
sellNoPriceUsd: number;
|
|
48
|
+
volume: number;
|
|
49
|
+
}
|
|
50
|
+
export interface PredictionMarket {
|
|
51
|
+
provider: string;
|
|
52
|
+
marketId: string;
|
|
53
|
+
status: "open" | "closed" | "cancelled";
|
|
54
|
+
result: string | null;
|
|
55
|
+
title: string;
|
|
56
|
+
openTime: number;
|
|
57
|
+
closeTime: number;
|
|
58
|
+
rulesPrimary?: string;
|
|
59
|
+
imageUrl?: string;
|
|
60
|
+
clobTokenIds?: string[];
|
|
61
|
+
pricing: PredictionMarketPricing;
|
|
62
|
+
}
|
|
63
|
+
export interface PredictionEvent {
|
|
64
|
+
eventId: string;
|
|
65
|
+
isActive: boolean;
|
|
66
|
+
isLive: boolean;
|
|
67
|
+
category: string;
|
|
68
|
+
subcategory: string;
|
|
69
|
+
tags: string[];
|
|
70
|
+
metadata: {
|
|
71
|
+
title: string;
|
|
72
|
+
closeTime: string;
|
|
73
|
+
imageUrl?: string;
|
|
74
|
+
series?: string;
|
|
75
|
+
slug?: string;
|
|
76
|
+
};
|
|
77
|
+
volumeUsd: string;
|
|
78
|
+
volume24hr: string;
|
|
79
|
+
closeCondition?: string;
|
|
80
|
+
markets: PredictionMarket[];
|
|
81
|
+
}
|
|
82
|
+
export interface PredictionPosition {
|
|
83
|
+
pubkey: string;
|
|
84
|
+
owner: string;
|
|
85
|
+
marketId: string;
|
|
86
|
+
isYes: boolean;
|
|
87
|
+
contracts: string;
|
|
88
|
+
contractsDecimal: string;
|
|
89
|
+
totalCostUsd: string;
|
|
90
|
+
sizeUsd: string;
|
|
91
|
+
valueUsd: string;
|
|
92
|
+
avgPriceUsd: string;
|
|
93
|
+
markPriceUsd: string;
|
|
94
|
+
pnlUsd: string;
|
|
95
|
+
pnlUsdPercent: number;
|
|
96
|
+
feesPaidUsd: string;
|
|
97
|
+
claimed: boolean;
|
|
98
|
+
claimable: boolean;
|
|
99
|
+
payoutUsd: string;
|
|
100
|
+
sellPriceUsd: string;
|
|
101
|
+
settlementDate: number;
|
|
102
|
+
eventMetadata: {
|
|
103
|
+
title: string;
|
|
104
|
+
category: string;
|
|
105
|
+
imageUrl?: string;
|
|
106
|
+
};
|
|
107
|
+
marketMetadata: {
|
|
108
|
+
title: string;
|
|
109
|
+
result: string | null;
|
|
110
|
+
status: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export interface PlacePredictionOrderRequest {
|
|
114
|
+
ownerPubkey: string;
|
|
115
|
+
marketId: string;
|
|
116
|
+
isYes: boolean;
|
|
117
|
+
isBuy: true;
|
|
118
|
+
depositAmount: string;
|
|
119
|
+
depositMint: string;
|
|
120
|
+
}
|
|
121
|
+
export interface PredictionTransactionResponse {
|
|
122
|
+
transaction: string;
|
|
123
|
+
txMeta: {
|
|
124
|
+
blockhash: string;
|
|
125
|
+
lastValidBlockHeight: number;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export interface PlacePredictionOrderResponse extends PredictionTransactionResponse {
|
|
129
|
+
order: {
|
|
130
|
+
orderPubkey: string;
|
|
131
|
+
positionPubkey: string;
|
|
132
|
+
contracts: number;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export type PredictionOrderStatus = "pending" | "filled" | "partiallyfilled" | "failed";
|
|
136
|
+
export interface PredictionOrderStatusResponse {
|
|
137
|
+
orderPubkey: string;
|
|
138
|
+
status: PredictionOrderStatus;
|
|
139
|
+
latestEventType: string;
|
|
140
|
+
latestSignature: string;
|
|
141
|
+
history: Array<{
|
|
142
|
+
eventType: string;
|
|
143
|
+
status: string;
|
|
144
|
+
rawStatus: string;
|
|
145
|
+
timestamp: number;
|
|
146
|
+
signature: string;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
export interface PredictionHistoryEvent {
|
|
150
|
+
id: number;
|
|
151
|
+
eventType: string;
|
|
152
|
+
signature: string;
|
|
153
|
+
timestamp: number;
|
|
154
|
+
marketId: string;
|
|
155
|
+
isYes: boolean;
|
|
156
|
+
isBuy: boolean;
|
|
157
|
+
contractsDecimal: string;
|
|
158
|
+
avgFillPriceUsd?: string;
|
|
159
|
+
totalCostUsd?: string;
|
|
160
|
+
netProceedsUsd?: string;
|
|
161
|
+
realizedPnl?: string;
|
|
162
|
+
payoutAmountUsd?: string;
|
|
163
|
+
eventMetadata: {
|
|
164
|
+
title: string;
|
|
165
|
+
category?: string;
|
|
166
|
+
imageUrl?: string;
|
|
167
|
+
};
|
|
168
|
+
marketMetadata: {
|
|
169
|
+
title: string;
|
|
170
|
+
result: string | null;
|
|
171
|
+
status: string;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export type PredictionPriceInterval = "1d" | "1w" | "1m" | "max";
|
|
175
|
+
export interface PredictionPricePoint {
|
|
176
|
+
t: number;
|
|
177
|
+
p: number;
|
|
178
|
+
}
|
package/dist/cjs/program.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Program, Idl, Wallet } from "@coral-xyz/anchor";
|
|
2
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { PRIVACY_POOL_CURRENT_IDL, PRIVACY_POOL_IDLS, PRIVACY_POOL_LEGACY2_IDL, PRIVACY_POOL_LEGACY_IDL } from "./idl/index.js";
|
|
3
4
|
export declare const PRIVACY_POOL_IDL: Idl;
|
|
5
|
+
export { PRIVACY_POOL_CURRENT_IDL, PRIVACY_POOL_IDLS, PRIVACY_POOL_LEGACY_IDL, PRIVACY_POOL_LEGACY2_IDL, };
|
|
4
6
|
/** Deployed program ID extracted from the bundled IDL. */
|
|
5
7
|
export declare const PRIVACY_POOL_PROGRAM_ID: PublicKey;
|
|
6
8
|
/**
|
package/dist/cjs/program.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PRIVACY_POOL_PROGRAM_ID = exports.PRIVACY_POOL_IDL = void 0;
|
|
3
|
+
exports.PRIVACY_POOL_PROGRAM_ID = exports.PRIVACY_POOL_LEGACY2_IDL = exports.PRIVACY_POOL_LEGACY_IDL = exports.PRIVACY_POOL_IDLS = exports.PRIVACY_POOL_CURRENT_IDL = exports.PRIVACY_POOL_IDL = void 0;
|
|
7
4
|
exports.createVeiloProgram = createVeiloProgram;
|
|
8
5
|
exports.createReadonlyVeiloProgram = createReadonlyVeiloProgram;
|
|
9
6
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
10
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
-
const
|
|
8
|
+
const index_js_1 = require("./idl/index.js");
|
|
9
|
+
Object.defineProperty(exports, "PRIVACY_POOL_CURRENT_IDL", { enumerable: true, get: function () { return index_js_1.PRIVACY_POOL_CURRENT_IDL; } });
|
|
10
|
+
Object.defineProperty(exports, "PRIVACY_POOL_IDLS", { enumerable: true, get: function () { return index_js_1.PRIVACY_POOL_IDLS; } });
|
|
11
|
+
Object.defineProperty(exports, "PRIVACY_POOL_LEGACY2_IDL", { enumerable: true, get: function () { return index_js_1.PRIVACY_POOL_LEGACY2_IDL; } });
|
|
12
|
+
Object.defineProperty(exports, "PRIVACY_POOL_LEGACY_IDL", { enumerable: true, get: function () { return index_js_1.PRIVACY_POOL_LEGACY_IDL; } });
|
|
12
13
|
// Re-export so consumers can access the raw IDL if needed
|
|
13
|
-
exports.PRIVACY_POOL_IDL =
|
|
14
|
+
exports.PRIVACY_POOL_IDL = index_js_1.PRIVACY_POOL_CURRENT_IDL;
|
|
14
15
|
/** Deployed program ID extracted from the bundled IDL. */
|
|
15
|
-
exports.PRIVACY_POOL_PROGRAM_ID = new web3_js_1.PublicKey(
|
|
16
|
+
exports.PRIVACY_POOL_PROGRAM_ID = new web3_js_1.PublicKey(index_js_1.PRIVACY_POOL_CURRENT_IDL.address);
|
|
16
17
|
/**
|
|
17
18
|
* Create an Anchor `Program` instance for the Veilo Privacy Pool.
|
|
18
19
|
*
|
package/dist/cjs/prover.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { type SwapProofBuilder } from "./proofs/swap.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Circuit artifact paths required by snarkjs.
|
|
5
5
|
*
|
|
6
|
-
* These files are large (10-100 MB) and
|
|
7
|
-
*
|
|
6
|
+
* These files are large (10-100 MB) and are NOT bundled in the npm package —
|
|
7
|
+
* `files` ships `dist/` only. Optional: omit them and the prover resolves a
|
|
8
|
+
* local copy (see `resolveCircuitArtifacts`). Supply them explicitly whenever
|
|
9
|
+
* the defaults cannot apply, which includes every browser build.
|
|
8
10
|
*
|
|
9
11
|
* For Node.js: pass file system paths (e.g. "./circuits/transaction.wasm").
|
|
10
12
|
* For browsers: pass Uint8Array buffers or URLs that fetch returns as ArrayBuffer.
|
|
@@ -15,6 +17,27 @@ export interface CircuitArtifacts {
|
|
|
15
17
|
/** Path or buffer for the Groth16 proving key (.zkey) */
|
|
16
18
|
zkeyPath: string | Uint8Array;
|
|
17
19
|
}
|
|
20
|
+
/** The circuits this package can resolve artifacts for. */
|
|
21
|
+
export type CircuitName = "transaction" | "swap";
|
|
22
|
+
/**
|
|
23
|
+
* Resolve circuit artifacts from disk when the caller did not supply them.
|
|
24
|
+
*
|
|
25
|
+
* Search order, first hit wins:
|
|
26
|
+
*
|
|
27
|
+
* 1. $VEILO_CIRCUITS_DIR explicit override
|
|
28
|
+
* 2. <package>/circuits populated by `npm run copy:circuits`
|
|
29
|
+
* 3. <cwd>/circuits
|
|
30
|
+
* 4. <cwd>/node_modules/@veilo/sdk-core/circuits
|
|
31
|
+
*
|
|
32
|
+
* NODE ONLY, AND DELIBERATELY LAZY. `node:fs` is imported inside the call, not
|
|
33
|
+
* at module scope: this module is reachable from the package root export, and a
|
|
34
|
+
* top-level `node:fs` import throws at bundle time in browser builds with no
|
|
35
|
+
* Node polyfill — the same reason `random.ts` avoids `node:crypto`. Browsers
|
|
36
|
+
* must pass `CircuitArtifacts` explicitly; there is nothing to resolve there.
|
|
37
|
+
*
|
|
38
|
+
* @throws when no candidate directory holds both files, listing what it tried
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveCircuitArtifacts(circuit: CircuitName): Promise<CircuitArtifacts>;
|
|
18
41
|
/**
|
|
19
42
|
* Create a proof builder function for the transaction circuit.
|
|
20
43
|
*
|
|
@@ -41,9 +64,9 @@ export interface CircuitArtifacts {
|
|
|
41
64
|
* const proof = await prover(circuitInputs);
|
|
42
65
|
* ```
|
|
43
66
|
*/
|
|
44
|
-
export declare function createTransactionProver(artifacts
|
|
67
|
+
export declare function createTransactionProver(artifacts?: CircuitArtifacts): TransactionProofBuilder;
|
|
45
68
|
/** Create a proof builder for the current `swap.circom` witness shape. */
|
|
46
|
-
export declare function createSwapProver(artifacts
|
|
69
|
+
export declare function createSwapProver(artifacts?: CircuitArtifacts): SwapProofBuilder;
|
|
47
70
|
/**
|
|
48
71
|
* Verify a Groth16 proof against public signals and a verification key.
|
|
49
72
|
*
|