@symbiome-forge/cow-sdk-wasm 0.1.0-alpha.1
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/LICENSE +674 -0
- package/README.md +278 -0
- package/dist/cloudflare/callbacks.cjs +2 -0
- package/dist/cloudflare/callbacks.d.ts +55 -0
- package/dist/cloudflare/callbacks.js +1 -0
- package/dist/cloudflare/envelope.cjs +2 -0
- package/dist/cloudflare/envelope.d.ts +5 -0
- package/dist/cloudflare/envelope.js +1 -0
- package/dist/cloudflare/errors.cjs +150 -0
- package/dist/cloudflare/errors.d.ts +82 -0
- package/dist/cloudflare/errors.js +145 -0
- package/dist/cloudflare/index.cjs +286 -0
- package/dist/cloudflare/index.d.ts +78 -0
- package/dist/cloudflare/index.js +1 -0
- package/dist/cloudflare/index.mjs +223 -0
- package/dist/cloudflare/internal.cjs +127 -0
- package/dist/cloudflare/internal.d.ts +40 -0
- package/dist/cloudflare/internal.js +115 -0
- package/dist/cloudflare/options.cjs +2 -0
- package/dist/cloudflare/options.d.ts +70 -0
- package/dist/cloudflare/options.js +1 -0
- package/dist/cloudflare/raw/cloudflare.cjs +65 -0
- package/dist/cloudflare/raw/cloudflare.d.ts +30 -0
- package/dist/cloudflare/raw/cloudflare.js +29 -0
- package/dist/default/callbacks.cjs +2 -0
- package/dist/default/callbacks.d.ts +55 -0
- package/dist/default/callbacks.js +1 -0
- package/dist/default/envelope.cjs +2 -0
- package/dist/default/envelope.d.ts +5 -0
- package/dist/default/envelope.js +1 -0
- package/dist/default/errors.cjs +150 -0
- package/dist/default/errors.d.ts +82 -0
- package/dist/default/errors.js +145 -0
- package/dist/default/index.cjs +359 -0
- package/dist/default/index.d.ts +94 -0
- package/dist/default/index.js +1 -0
- package/dist/default/index.mjs +295 -0
- package/dist/default/internal.cjs +127 -0
- package/dist/default/internal.d.ts +40 -0
- package/dist/default/internal.js +115 -0
- package/dist/default/options.cjs +2 -0
- package/dist/default/options.d.ts +70 -0
- package/dist/default/options.js +1 -0
- package/dist/default/raw/default.cjs +66 -0
- package/dist/default/raw/default.d.ts +31 -0
- package/dist/default/raw/default.js +30 -0
- package/dist/orderbook/callbacks.cjs +2 -0
- package/dist/orderbook/callbacks.d.ts +55 -0
- package/dist/orderbook/callbacks.js +1 -0
- package/dist/orderbook/envelope.cjs +2 -0
- package/dist/orderbook/envelope.d.ts +5 -0
- package/dist/orderbook/envelope.js +1 -0
- package/dist/orderbook/errors.cjs +150 -0
- package/dist/orderbook/errors.d.ts +82 -0
- package/dist/orderbook/errors.js +145 -0
- package/dist/orderbook/index.cjs +195 -0
- package/dist/orderbook/index.d.ts +57 -0
- package/dist/orderbook/index.js +1 -0
- package/dist/orderbook/index.mjs +139 -0
- package/dist/orderbook/internal.cjs +127 -0
- package/dist/orderbook/internal.d.ts +40 -0
- package/dist/orderbook/internal.js +115 -0
- package/dist/orderbook/options.cjs +2 -0
- package/dist/orderbook/options.d.ts +70 -0
- package/dist/orderbook/options.js +1 -0
- package/dist/orderbook/raw/orderbook.cjs +58 -0
- package/dist/orderbook/raw/orderbook.d.ts +23 -0
- package/dist/orderbook/raw/orderbook.js +22 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm.d.ts +2870 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm.js +2183 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm.d.ts +65 -0
- package/dist/raw/default-bundler/cow_sdk_wasm.d.ts +2916 -0
- package/dist/raw/default-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.js +2297 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm.d.ts +75 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm.cjs +2330 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm.d.ts +2916 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm_bg.wasm.d.ts +75 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm.d.ts +1876 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.js +1636 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm.d.ts +50 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm.cjs +1661 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm.d.ts +1876 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm_bg.wasm.d.ts +50 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm.d.ts +774 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.js +1059 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm.d.ts +27 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm.cjs +1078 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm.d.ts +774 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm_bg.wasm.d.ts +27 -0
- package/dist/signing/callbacks.cjs +2 -0
- package/dist/signing/callbacks.d.ts +55 -0
- package/dist/signing/callbacks.js +1 -0
- package/dist/signing/envelope.cjs +2 -0
- package/dist/signing/envelope.d.ts +5 -0
- package/dist/signing/envelope.js +1 -0
- package/dist/signing/errors.cjs +150 -0
- package/dist/signing/errors.d.ts +82 -0
- package/dist/signing/errors.js +145 -0
- package/dist/signing/index.cjs +93 -0
- package/dist/signing/index.d.ts +23 -0
- package/dist/signing/index.js +1 -0
- package/dist/signing/index.mjs +44 -0
- package/dist/signing/internal.cjs +127 -0
- package/dist/signing/internal.d.ts +40 -0
- package/dist/signing/internal.js +115 -0
- package/dist/signing/options.cjs +2 -0
- package/dist/signing/options.d.ts +70 -0
- package/dist/signing/options.js +1 -0
- package/dist/signing/raw/signing.cjs +52 -0
- package/dist/signing/raw/signing.d.ts +17 -0
- package/dist/signing/raw/signing.js +16 -0
- package/package.json +112 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const knownKinds = new Set([
|
|
2
|
+
"invalidInput",
|
|
3
|
+
"unknownEnumValue",
|
|
4
|
+
"unsupportedChain",
|
|
5
|
+
"walletRequest",
|
|
6
|
+
"walletTimeout",
|
|
7
|
+
"transport",
|
|
8
|
+
"orderbook",
|
|
9
|
+
"subgraph",
|
|
10
|
+
"signing",
|
|
11
|
+
"appData",
|
|
12
|
+
"cancelled",
|
|
13
|
+
"internal",
|
|
14
|
+
"__unknown"
|
|
15
|
+
]);
|
|
16
|
+
export function normalizeError(raw) {
|
|
17
|
+
if (isRecord(raw)) {
|
|
18
|
+
// The Rust `WasmError` serializes with serde `rename_all(_fields) = "camelCase"`
|
|
19
|
+
// through a json-compatible serializer, so it already crosses the boundary as a
|
|
20
|
+
// camelCase plain object — no field renaming is needed here.
|
|
21
|
+
const normalized = raw;
|
|
22
|
+
const kind = typeof normalized.kind === "string" ? normalized.kind : undefined;
|
|
23
|
+
if (kind && knownKinds.has(kind)) {
|
|
24
|
+
const schemaVersion = normalized.schemaVersion === "__unknown" ? "__unknown" : "v1";
|
|
25
|
+
if (kind === "__unknown") {
|
|
26
|
+
return {
|
|
27
|
+
schemaVersion,
|
|
28
|
+
kind: "__unknown",
|
|
29
|
+
message: unknownMessage(),
|
|
30
|
+
raw: normalized.raw ?? raw
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return withActionableMessage({
|
|
34
|
+
...normalized,
|
|
35
|
+
schemaVersion,
|
|
36
|
+
kind
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (kind) {
|
|
40
|
+
return {
|
|
41
|
+
schemaVersion: normalized.schemaVersion === "__unknown" ? "__unknown" : "v1",
|
|
42
|
+
kind: "__unknown",
|
|
43
|
+
message: unknownMessage(),
|
|
44
|
+
raw
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (raw instanceof Error) {
|
|
49
|
+
return (classifyDeserializationFailure(raw.message) ?? {
|
|
50
|
+
schemaVersion: "v1",
|
|
51
|
+
kind: "internal",
|
|
52
|
+
message: internalMessage(raw.message)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return (classifyDeserializationFailure(String(raw)) ?? {
|
|
56
|
+
schemaVersion: "v1",
|
|
57
|
+
kind: "internal",
|
|
58
|
+
message: internalMessage(String(raw))
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Input-DTO deserialization failures cross the wasm boundary as a plain
|
|
62
|
+
// `Error`: the generated wasm-bindgen glue throws the serde message, so it
|
|
63
|
+
// never carries a structured `kind`. These are CALLER input errors — a value
|
|
64
|
+
// that does not match the documented input type (unknown enum variant,
|
|
65
|
+
// missing/unknown field, wrong type) — not SDK-internal faults, so they must
|
|
66
|
+
// normalize to `invalidInput` rather than `internal` (whose contract implies
|
|
67
|
+
// an SDK bug). The verbatim detail is preserved because it already names the
|
|
68
|
+
// offending field/variant and the expected set, e.g.
|
|
69
|
+
// "unknown variant `teleport`, expected `sell` or `buy`".
|
|
70
|
+
const DESERIALIZATION_FAILURE_PATTERNS = [
|
|
71
|
+
/unknown variant `/,
|
|
72
|
+
/missing field `/,
|
|
73
|
+
/unknown field `/,
|
|
74
|
+
/duplicate field `/,
|
|
75
|
+
/invalid type:/,
|
|
76
|
+
/invalid length\b/,
|
|
77
|
+
/invalid value:/,
|
|
78
|
+
/data did not match any variant/
|
|
79
|
+
];
|
|
80
|
+
function classifyDeserializationFailure(message) {
|
|
81
|
+
if (!DESERIALIZATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const detail = message.replace(/^Error:\s*/, "");
|
|
85
|
+
const field = detail.match(/(?:missing|unknown|duplicate) field `([^`]+)`/)?.[1];
|
|
86
|
+
const reason = `Invalid SDK input: ${detail}. Check the value against the documented input type and retry.`;
|
|
87
|
+
return field !== undefined
|
|
88
|
+
? { schemaVersion: "v1", kind: "invalidInput", field, message: reason }
|
|
89
|
+
: { schemaVersion: "v1", kind: "invalidInput", message: reason };
|
|
90
|
+
}
|
|
91
|
+
export function cancelledError() {
|
|
92
|
+
return {
|
|
93
|
+
schemaVersion: "v1",
|
|
94
|
+
kind: "cancelled",
|
|
95
|
+
message: "Operation was cancelled. Create a fresh AbortController or retry without an already-aborted signal."
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function invalidInput(field, reason) {
|
|
99
|
+
return {
|
|
100
|
+
schemaVersion: "v1",
|
|
101
|
+
kind: "invalidInput",
|
|
102
|
+
field,
|
|
103
|
+
message: `Invalid \`${field}\`: ${reason}. Check the value supplied for \`${field}\` and retry with a valid SDK input.`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return typeof value === "object" && value !== null;
|
|
108
|
+
}
|
|
109
|
+
function withActionableMessage(error) {
|
|
110
|
+
if ("message" in error && typeof error.message === "string" && error.message.length > 0) {
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
switch (error.kind) {
|
|
114
|
+
case "unknownEnumValue":
|
|
115
|
+
return {
|
|
116
|
+
...error,
|
|
117
|
+
message: `Unsupported value \`${error.value}\` for \`${error.field}\`. Use one of the documented values for this field.`
|
|
118
|
+
};
|
|
119
|
+
case "unsupportedChain":
|
|
120
|
+
return {
|
|
121
|
+
...error,
|
|
122
|
+
message: `Unsupported chain ID ${error.chainId}. Call supportedChainIds() before constructing requests and route unsupported networks to another integration.`
|
|
123
|
+
};
|
|
124
|
+
case "walletTimeout":
|
|
125
|
+
return {
|
|
126
|
+
...error,
|
|
127
|
+
message: `Wallet request timed out after ${error.timeoutMs} ms. Increase walletConfig.timeoutMs or ask the user to approve the wallet request before the timeout.`
|
|
128
|
+
};
|
|
129
|
+
case "cancelled":
|
|
130
|
+
return cancelledError();
|
|
131
|
+
case "__unknown":
|
|
132
|
+
return {
|
|
133
|
+
...error,
|
|
134
|
+
message: unknownMessage()
|
|
135
|
+
};
|
|
136
|
+
default:
|
|
137
|
+
return error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function internalMessage(detail) {
|
|
141
|
+
return `SDK internal error: ${detail}. This indicates serialization or invariant failure; retry with the same inputs only after checking the reported input shape.`;
|
|
142
|
+
}
|
|
143
|
+
function unknownMessage() {
|
|
144
|
+
return "SDK received an unrecognized error variant. Inspect raw, preserve it in logs without credentials, and update the SDK if the variant is now documented.";
|
|
145
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
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.TradingClient = exports.OrderBookClient = void 0;
|
|
37
|
+
exports.initialize = initialize;
|
|
38
|
+
exports.appDataDoc = appDataDoc;
|
|
39
|
+
exports.appDataHexToCid = appDataHexToCid;
|
|
40
|
+
exports.appDataInfo = appDataInfo;
|
|
41
|
+
exports.buildCancelOrderTx = buildCancelOrderTx;
|
|
42
|
+
exports.buildPresignTx = buildPresignTx;
|
|
43
|
+
exports.cidToAppDataHex = cidToAppDataHex;
|
|
44
|
+
exports.computeOrderUid = computeOrderUid;
|
|
45
|
+
exports.decodeEthFlowLog = decodeEthFlowLog;
|
|
46
|
+
exports.decodeSettlementLog = decodeSettlementLog;
|
|
47
|
+
exports.deploymentAddresses = deploymentAddresses;
|
|
48
|
+
exports.domainSeparator = domainSeparator;
|
|
49
|
+
exports.eip1271SignaturePayload = eip1271SignaturePayload;
|
|
50
|
+
exports.orderTypedData = orderTypedData;
|
|
51
|
+
exports.signCancellationEthSignDigest = signCancellationEthSignDigest;
|
|
52
|
+
exports.signCancellationWithEip1193 = signCancellationWithEip1193;
|
|
53
|
+
exports.signCancellationWithTypedDataSigner = signCancellationWithTypedDataSigner;
|
|
54
|
+
exports.signOrderEthSignDigest = signOrderEthSignDigest;
|
|
55
|
+
exports.signOrderWithCustomEip1271 = signOrderWithCustomEip1271;
|
|
56
|
+
exports.signOrderWithEip1193 = signOrderWithEip1193;
|
|
57
|
+
exports.signOrderWithEip1271 = signOrderWithEip1271;
|
|
58
|
+
exports.signOrderWithTypedDataSigner = signOrderWithTypedDataSigner;
|
|
59
|
+
exports.supportedChainIds = supportedChainIds;
|
|
60
|
+
exports.validateAppDataDoc = validateAppDataDoc;
|
|
61
|
+
exports.wasmVersion = wasmVersion;
|
|
62
|
+
const raw = __importStar(require("./raw/cloudflare.cjs"));
|
|
63
|
+
const internal_js_1 = require("./internal.cjs");
|
|
64
|
+
let initialized;
|
|
65
|
+
async function initialize(module) {
|
|
66
|
+
if (!initialized) {
|
|
67
|
+
initialized = raw.initializeRaw({ module_or_path: module }).then(() => undefined);
|
|
68
|
+
}
|
|
69
|
+
await initialized;
|
|
70
|
+
}
|
|
71
|
+
exports.default = initialize;
|
|
72
|
+
class OrderBookClient {
|
|
73
|
+
#inner;
|
|
74
|
+
#defaults;
|
|
75
|
+
#disposed = false;
|
|
76
|
+
constructor(config) {
|
|
77
|
+
try {
|
|
78
|
+
this.#defaults = (0, internal_js_1.defaultsFrom)(config);
|
|
79
|
+
this.#inner = new raw.RawOrderBookClient((0, internal_js_1.translateClientConfig)(config));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw (0, internal_js_1.callSync)(() => {
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async cancelOrders(signed, options) {
|
|
88
|
+
return this.#call((client, merged) => client.cancelOrders(signed, merged), options);
|
|
89
|
+
}
|
|
90
|
+
async getNativePrice(token, options) {
|
|
91
|
+
return this.#call((client, merged) => client.getNativePrice(token, merged), options);
|
|
92
|
+
}
|
|
93
|
+
async getOrder(orderUid, options) {
|
|
94
|
+
return this.#call((client, merged) => client.getOrder(orderUid, merged), options);
|
|
95
|
+
}
|
|
96
|
+
async getOrders(owner, pagination, options) {
|
|
97
|
+
return this.#call((client, merged) => client.getOrders(owner, pagination ?? null, merged), options);
|
|
98
|
+
}
|
|
99
|
+
async getOrderMultiEnv(orderUid, options) {
|
|
100
|
+
return this.#call((client, merged) => client.getOrderMultiEnv(orderUid, merged), options);
|
|
101
|
+
}
|
|
102
|
+
async getTxOrders(txHash, options) {
|
|
103
|
+
return this.#call((client, merged) => client.getTxOrders(txHash, merged), options);
|
|
104
|
+
}
|
|
105
|
+
async getVersion(options) {
|
|
106
|
+
return this.#call((client, merged) => client.getVersion(merged), options);
|
|
107
|
+
}
|
|
108
|
+
getOrderLink(orderUid) {
|
|
109
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
110
|
+
return (0, internal_js_1.callSync)(() => this.#inner.getOrderLink(orderUid));
|
|
111
|
+
}
|
|
112
|
+
async getQuote(request, options) {
|
|
113
|
+
return this.#call((client, merged) => client.getQuote(request, merged), options);
|
|
114
|
+
}
|
|
115
|
+
async getTrades(query, options) {
|
|
116
|
+
return this.#call((client, merged) => client.getTrades(query, merged), options);
|
|
117
|
+
}
|
|
118
|
+
async getOrderCompetitionStatus(orderUid, options) {
|
|
119
|
+
return this.#call((client, merged) => client.getOrderCompetitionStatus(orderUid, merged), options);
|
|
120
|
+
}
|
|
121
|
+
async getTotalSurplus(owner, options) {
|
|
122
|
+
return this.#call((client, merged) => client.getTotalSurplus(owner, merged), options);
|
|
123
|
+
}
|
|
124
|
+
async getAppData(appDataHash, options) {
|
|
125
|
+
return this.#call((client, merged) => client.getAppData(appDataHash, merged), options);
|
|
126
|
+
}
|
|
127
|
+
async uploadAppData(appDataHash, fullAppData, options) {
|
|
128
|
+
return this.#call((client, merged) => client.uploadAppData(appDataHash, fullAppData, merged), options);
|
|
129
|
+
}
|
|
130
|
+
async sendOrder(signed, options) {
|
|
131
|
+
return this.#call((client, merged) => client.sendOrder(signed, merged), options);
|
|
132
|
+
}
|
|
133
|
+
async sendOrderCreation(input, options) {
|
|
134
|
+
return this.#call((client, merged) => client.sendOrderCreation(input, merged), options);
|
|
135
|
+
}
|
|
136
|
+
dispose() {
|
|
137
|
+
if (!this.#disposed) {
|
|
138
|
+
(0, internal_js_1.disposeRaw)(this.#inner);
|
|
139
|
+
this.#disposed = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
[Symbol.dispose]() {
|
|
143
|
+
this.dispose();
|
|
144
|
+
}
|
|
145
|
+
#call(operation, options) {
|
|
146
|
+
return (0, internal_js_1.callAsync)(() => {
|
|
147
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
148
|
+
return operation(this.#inner, (0, internal_js_1.mergeOptions)(this.#defaults, options));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.OrderBookClient = OrderBookClient;
|
|
153
|
+
class TradingClient {
|
|
154
|
+
#inner;
|
|
155
|
+
#defaults;
|
|
156
|
+
#disposed = false;
|
|
157
|
+
constructor(config) {
|
|
158
|
+
try {
|
|
159
|
+
this.#defaults = (0, internal_js_1.defaultsFrom)(config);
|
|
160
|
+
this.#inner = new raw.RawTradingClient((0, internal_js_1.translateClientConfig)(config));
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
throw (0, internal_js_1.callSync)(() => {
|
|
164
|
+
throw error;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async buildSellNativeCurrencyTx(order, quoteId, from, options) {
|
|
169
|
+
return this.#call((client, merged) => client.buildSellNativeCurrencyTx(order, quoteId, from, merged), options);
|
|
170
|
+
}
|
|
171
|
+
async getCowProtocolAllowance(params, readContractCallback, options) {
|
|
172
|
+
return this.#call((client, merged) => client.getCowProtocolAllowance(params, readContractCallback, merged), options);
|
|
173
|
+
}
|
|
174
|
+
async buildApprovalTx(params, options) {
|
|
175
|
+
return this.#call((client, merged) => client.buildApprovalTx(params, merged), options);
|
|
176
|
+
}
|
|
177
|
+
async getQuote(params, options) {
|
|
178
|
+
return this.#call((client, merged) => client.getQuote(params, merged), options);
|
|
179
|
+
}
|
|
180
|
+
async postLimitOrder(params, owner, signerCallback, options) {
|
|
181
|
+
return this.#callSigning((client, merged) => client.postLimitOrder(params, owner, signerCallback, merged ?? null), options);
|
|
182
|
+
}
|
|
183
|
+
async postSwapOrder(params, owner, signerCallback, options) {
|
|
184
|
+
return this.#callSigning((client, merged) => client.postSwapOrder(params, owner, signerCallback, merged ?? null), options);
|
|
185
|
+
}
|
|
186
|
+
async postSwapOrderFromQuote(quoteResults, owner, signerCallback, options) {
|
|
187
|
+
return this.#callSigning((client, merged) => client.postSwapOrderFromQuote(quoteResults, owner, signerCallback, merged ?? null), options);
|
|
188
|
+
}
|
|
189
|
+
async postSwapOrderWithEip1271(params, owner, customCallback, options) {
|
|
190
|
+
return this.#callSigning((client, merged) => client.postSwapOrderWithEip1271(params, owner, customCallback, merged ?? null), options);
|
|
191
|
+
}
|
|
192
|
+
dispose() {
|
|
193
|
+
if (!this.#disposed) {
|
|
194
|
+
(0, internal_js_1.disposeRaw)(this.#inner);
|
|
195
|
+
this.#disposed = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
[Symbol.dispose]() {
|
|
199
|
+
this.dispose();
|
|
200
|
+
}
|
|
201
|
+
#call(operation, options) {
|
|
202
|
+
return (0, internal_js_1.callAsync)(() => {
|
|
203
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
204
|
+
return operation(this.#inner, (0, internal_js_1.mergeOptions)(this.#defaults, options));
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
#callSigning(operation, options) {
|
|
208
|
+
return (0, internal_js_1.callAsync)(() => {
|
|
209
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
210
|
+
return operation(this.#inner, (0, internal_js_1.mergeSigningOptions)(this.#defaults, options));
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.TradingClient = TradingClient;
|
|
215
|
+
function appDataDoc(doc) {
|
|
216
|
+
return (0, internal_js_1.callSync)(() => raw.appDataDoc(doc));
|
|
217
|
+
}
|
|
218
|
+
function appDataHexToCid(appDataHex) {
|
|
219
|
+
return (0, internal_js_1.callSync)(() => raw.appDataHexToCid(appDataHex));
|
|
220
|
+
}
|
|
221
|
+
function appDataInfo(doc) {
|
|
222
|
+
return (0, internal_js_1.callSync)(() => raw.appDataInfo(doc));
|
|
223
|
+
}
|
|
224
|
+
function buildCancelOrderTx(params) {
|
|
225
|
+
return (0, internal_js_1.callSync)(() => raw.buildCancelOrderTx(params));
|
|
226
|
+
}
|
|
227
|
+
function buildPresignTx(params) {
|
|
228
|
+
return (0, internal_js_1.callSync)(() => raw.buildPresignTx(params));
|
|
229
|
+
}
|
|
230
|
+
function cidToAppDataHex(cid) {
|
|
231
|
+
return (0, internal_js_1.callSync)(() => raw.cidToAppDataHex(cid));
|
|
232
|
+
}
|
|
233
|
+
function computeOrderUid(input, chainId, owner) {
|
|
234
|
+
return (0, internal_js_1.callSync)(() => raw.computeOrderUid(input, chainId, owner));
|
|
235
|
+
}
|
|
236
|
+
function decodeEthFlowLog(log) {
|
|
237
|
+
return (0, internal_js_1.callSync)(() => raw.decodeEthFlowLog(log));
|
|
238
|
+
}
|
|
239
|
+
function decodeSettlementLog(log) {
|
|
240
|
+
return (0, internal_js_1.callSync)(() => raw.decodeSettlementLog(log));
|
|
241
|
+
}
|
|
242
|
+
function deploymentAddresses(chainId, env) {
|
|
243
|
+
return (0, internal_js_1.callSync)(() => raw.deploymentAddresses(chainId, env ?? null));
|
|
244
|
+
}
|
|
245
|
+
function domainSeparator(chainId) {
|
|
246
|
+
return (0, internal_js_1.callSync)(() => raw.domainSeparator(chainId));
|
|
247
|
+
}
|
|
248
|
+
function eip1271SignaturePayload(input, ecdsaSignature) {
|
|
249
|
+
return (0, internal_js_1.callSync)(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
|
|
250
|
+
}
|
|
251
|
+
function orderTypedData(input, chainId) {
|
|
252
|
+
return (0, internal_js_1.callSync)(() => raw.orderTypedData(input, chainId));
|
|
253
|
+
}
|
|
254
|
+
function signCancellationEthSignDigest(orderUids, chainId, digestSigner, options) {
|
|
255
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationEthSignDigest(orderUids, chainId, digestSigner, options ?? null));
|
|
256
|
+
}
|
|
257
|
+
function signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options) {
|
|
258
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options ?? null));
|
|
259
|
+
}
|
|
260
|
+
function signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options) {
|
|
261
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options ?? null));
|
|
262
|
+
}
|
|
263
|
+
function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
|
|
264
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
|
|
265
|
+
}
|
|
266
|
+
function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
|
|
267
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
|
|
268
|
+
}
|
|
269
|
+
function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
|
|
270
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
|
|
271
|
+
}
|
|
272
|
+
function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
|
|
273
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
|
|
274
|
+
}
|
|
275
|
+
function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
|
|
276
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
|
|
277
|
+
}
|
|
278
|
+
function supportedChainIds() {
|
|
279
|
+
return (0, internal_js_1.callSync)(() => raw.supportedChainIds());
|
|
280
|
+
}
|
|
281
|
+
function validateAppDataDoc(doc) {
|
|
282
|
+
return (0, internal_js_1.callSync)(() => raw.validateAppDataDoc(doc));
|
|
283
|
+
}
|
|
284
|
+
function wasmVersion() {
|
|
285
|
+
return (0, internal_js_1.callSync)(() => raw.wasmVersion());
|
|
286
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import * as raw from "./raw/cloudflare.js";
|
|
3
|
+
import type { WasmEnvelope } from "./envelope.js";
|
|
4
|
+
import type { CommonClientConfig, SdkClientOptions, SigningOptions, TradingClientConfig } from "./options.js";
|
|
5
|
+
import type { ContractReadCallback, CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
|
|
6
|
+
export interface OrderBookClientConfig extends CommonClientConfig {
|
|
7
|
+
}
|
|
8
|
+
export declare function initialize(module: WebAssembly.Module | raw.InitInput): Promise<void>;
|
|
9
|
+
export default initialize;
|
|
10
|
+
export declare class OrderBookClient {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(config: OrderBookClientConfig);
|
|
13
|
+
cancelOrders(signed: raw.SignedCancellationsInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<{
|
|
14
|
+
cancelled: true;
|
|
15
|
+
}>>;
|
|
16
|
+
getNativePrice(token: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.NativePriceResponseDto>>;
|
|
17
|
+
getOrder(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto>>;
|
|
18
|
+
getOrders(owner: string, pagination?: raw.PaginationOptions | null, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto[]>>;
|
|
19
|
+
getOrderMultiEnv(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto>>;
|
|
20
|
+
getTxOrders(txHash: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto[]>>;
|
|
21
|
+
getVersion(options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
22
|
+
getOrderLink(orderUid: string): WasmEnvelope<string>;
|
|
23
|
+
getQuote(request: raw.OrderQuoteRequestInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderQuoteResponseDto>>;
|
|
24
|
+
getTrades(query: raw.TradesQueryInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.TradeDto[]>>;
|
|
25
|
+
getOrderCompetitionStatus(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.CompetitionOrderStatusDto>>;
|
|
26
|
+
getTotalSurplus(owner: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.TotalSurplusDto>>;
|
|
27
|
+
getAppData(appDataHash: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.AppDataObjectDto>>;
|
|
28
|
+
uploadAppData(appDataHash: string, fullAppData: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<{
|
|
29
|
+
uploaded: true;
|
|
30
|
+
}>>;
|
|
31
|
+
sendOrder(signed: raw.SignedOrderDto, options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
32
|
+
sendOrderCreation(input: raw.OrderCreationInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
[Symbol.dispose](): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class TradingClient {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(config: TradingClientConfig);
|
|
39
|
+
buildSellNativeCurrencyTx(order: raw.OrderInput, quoteId: number, from: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.BuiltSellNativeCurrencyTxDto>>;
|
|
40
|
+
getCowProtocolAllowance(params: raw.AllowanceParametersInput, readContractCallback: ContractReadCallback, options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
41
|
+
buildApprovalTx(params: raw.ApprovalParametersInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.TransactionRequestDto>>;
|
|
42
|
+
getQuote(params: raw.SwapParametersInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.QuoteResultsDto>>;
|
|
43
|
+
postLimitOrder(params: raw.LimitTradeParametersInput, owner: string, signerCallback: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.OrderPostingResultDto>>;
|
|
44
|
+
postSwapOrder(params: raw.SwapParametersInput, owner: string, signerCallback: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.OrderPostingResultDto>>;
|
|
45
|
+
postSwapOrderFromQuote(quoteResults: raw.QuoteResultsDto, owner: string, signerCallback: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.OrderPostingResultDto>>;
|
|
46
|
+
postSwapOrderWithEip1271(params: raw.SwapParametersInput, owner: string, customCallback: CustomEip1271Callback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.OrderPostingResultDto>>;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
[Symbol.dispose](): void;
|
|
49
|
+
}
|
|
50
|
+
export declare function appDataDoc(doc: raw.AppDataDocInput): WasmEnvelope<raw.AppDataDocDto>;
|
|
51
|
+
export declare function appDataHexToCid(appDataHex: string): WasmEnvelope<string>;
|
|
52
|
+
export declare function appDataInfo(doc: raw.AppDataDocInput): WasmEnvelope<raw.AppDataInfoDto>;
|
|
53
|
+
export declare function buildCancelOrderTx(params: raw.OrderTraderParametersInput): WasmEnvelope<raw.TransactionRequestDto>;
|
|
54
|
+
export declare function buildPresignTx(params: raw.OrderTraderParametersInput): WasmEnvelope<raw.TransactionRequestDto>;
|
|
55
|
+
export declare function cidToAppDataHex(cid: string): WasmEnvelope<string>;
|
|
56
|
+
export declare function computeOrderUid(input: raw.OrderInput, chainId: number, owner: string): WasmEnvelope<raw.GeneratedOrderUidDto>;
|
|
57
|
+
export declare function decodeEthFlowLog(log: raw.EventLogInput): WasmEnvelope<raw.EthFlowEventDto>;
|
|
58
|
+
export declare function decodeSettlementLog(log: raw.EventLogInput): WasmEnvelope<raw.SettlementEventDto>;
|
|
59
|
+
export declare function deploymentAddresses(chainId: number, env?: string | null): WasmEnvelope<raw.DeploymentAddressesDto>;
|
|
60
|
+
export declare function domainSeparator(chainId: number): string;
|
|
61
|
+
export declare function eip1271SignaturePayload(input: raw.OrderInput, ecdsaSignature: string): WasmEnvelope<string>;
|
|
62
|
+
export declare function orderTypedData(input: raw.OrderInput, chainId: number): WasmEnvelope<raw.TypedDataEnvelopeDto>;
|
|
63
|
+
export declare function signCancellationEthSignDigest(orderUids: string[], chainId: number, digestSigner: DigestSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
64
|
+
export declare function signCancellationWithEip1193(orderUids: string[], chainId: number, owner: string, requestCallback: Eip1193RequestCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
65
|
+
export declare function signCancellationWithTypedDataSigner(orderUids: string[], chainId: number, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
66
|
+
export declare function signOrderEthSignDigest(input: raw.OrderInput, chainId: number, owner: string, digestSigner: DigestSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
67
|
+
export declare function signOrderWithCustomEip1271(input: raw.OrderInput, chainId: number, owner: string, customCallback: CustomEip1271Callback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
68
|
+
export declare function signOrderWithEip1193(input: raw.OrderInput, chainId: number, owner: string, requestCallback: Eip1193RequestCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
69
|
+
export declare function signOrderWithEip1271(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
70
|
+
export declare function signOrderWithTypedDataSigner(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
71
|
+
export declare function supportedChainIds(): Uint32Array;
|
|
72
|
+
export declare function validateAppDataDoc(doc: raw.AppDataDocInput): WasmEnvelope<raw.ValidationResultDto>;
|
|
73
|
+
export declare function wasmVersion(): string;
|
|
74
|
+
export type { AllowanceParametersInput, AmountsDto, AppDataDocDto, AppDataDocInput, AppDataInfoDto, AppDataObjectDto, ApprovalParametersInput, BuiltSellNativeCurrencyTxDto, CompetitionOrderStatusDto, CompetitionOrderStatusKindDto, ContractCallDto, CostsDto, CowEip1271SignRequest, CowEnvDto, DeploymentAddressesDto, Eip1193Request, EthFlowEventDto, EthflowDataDto, EventLogInput, ExecutedAmountsDto, ExecutedProtocolFeeDto, FeeComponentDto, GeneratedOrderUidDto, InitInput, InteractionDataDto, LimitTradeParametersInput, NativePriceResponseDto, NetworkFeeDto, OnchainOrderDataDto, OrderClassDto, OrderCreationInput, OrderDataDto, OrderDto, OrderInput, OrderInteractionsDto, OrderKindDto, OrderPostingResultDto, OrderQuoteRequestInput, OrderQuoteResponseDto, OrderStatusDto, OrderTraderParametersInput, OrderBookRuntimeBindingDto, PaginationOptions, PartnerFeeDto, PartnerFeeInput, PartnerFeePolicyDto, PartnerFeePolicyInput, QuoteAmountsAndCostsDto, QuoteDataDto, QuoteResultsDto, SettlementEventDto, SignedCancellationsInput, SignedOrderDto, SigningSchemeDto, SolverExecutionDto, StoredOrderQuoteDto, SwapParametersInput, TokenBalanceDto, TotalSurplusDto, TradeDto, TradeParametersDto, TradesQueryInput, TradingAppDataInfoDto, TransactionRequestDto, TypedDataDomainDto, TypedDataEnvelopeDto, TypedDataFieldDto, ValidationResultDto } from "./raw/cloudflare.js";
|
|
75
|
+
export type { ContractReadCallback, CowEip1271SignCallback, CowEnv, CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
|
|
76
|
+
export type { OrderBookRejectionCategory, CowError } from "./errors.js";
|
|
77
|
+
export type { SchemaVersion, WasmEnvelope } from "./envelope.js";
|
|
78
|
+
export type { CowFetchCallback, CowFetchRequest, CowFetchResponse, HttpTransportConfig, JitterStrategyConfig, LimiterScopeConfig, RequestRateLimiterConfig, RetryPolicyConfig, SdkClientOptions, SigningOptions, TradingClientConfig, TransportPolicyConfig, WalletConfig } from "./options.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./default.js";
|