@masterpeach/market-sdk 0.2.0-beta.20260930.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/README.md +109 -0
- package/README.zh-CN.md +155 -0
- package/THIRD_PARTY_NOTICES.md +14 -0
- package/dist/abi/index.cjs +14051 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +10882 -0
- package/dist/abi/index.d.ts +10882 -0
- package/dist/abi/index.js +27 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/chunk-TMU4HSZR.js +231 -0
- package/dist/chunk-TMU4HSZR.js.map +1 -0
- package/dist/chunk-TTVBOGKZ.js +14015 -0
- package/dist/chunk-TTVBOGKZ.js.map +1 -0
- package/dist/core.cjs +271 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +99 -0
- package/dist/core.d.ts +99 -0
- package/dist/core.js +35 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +13327 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +840 -0
- package/dist/index.d.ts +840 -0
- package/dist/index.js +2705 -0
- package/dist/index.js.map +1 -0
- package/docs/earnings.md +71 -0
- package/docs/frontend.md +153 -0
- package/docs/latest-contract.md +38 -0
- package/docs/liquidity.md +87 -0
- package/docs/management.md +73 -0
- package/docs/pool-state.md +30 -0
- package/docs/pools.md +118 -0
- package/docs/positions.md +94 -0
- package/docs/variants.md +24 -0
- package/package.json +82 -0
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
MissingAccountError: () => MissingAccountError,
|
|
24
|
+
MissingChainError: () => MissingChainError,
|
|
25
|
+
PeachSdkError: () => PeachSdkError,
|
|
26
|
+
UnsupportedChainError: () => UnsupportedChainError,
|
|
27
|
+
createPreparedTransactionStore: () => createPreparedTransactionStore,
|
|
28
|
+
createRequestAbortScope: () => createRequestAbortScope,
|
|
29
|
+
formatAmount: () => formatAmount,
|
|
30
|
+
immutableClone: () => immutableClone,
|
|
31
|
+
isPeachSdkError: () => isPeachSdkError,
|
|
32
|
+
parseAmount: () => parseAmount,
|
|
33
|
+
requireWalletClient: () => requireWalletClient,
|
|
34
|
+
resolveChainValue: () => resolveChainValue,
|
|
35
|
+
resolveLiveWalletAccount: () => resolveLiveWalletAccount,
|
|
36
|
+
toPeachSdkError: () => toPeachSdkError,
|
|
37
|
+
transactionResultFromReceipt: () => transactionResultFromReceipt
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(core_exports);
|
|
40
|
+
|
|
41
|
+
// ../core/src/amount.ts
|
|
42
|
+
var import_viem2 = require("viem");
|
|
43
|
+
|
|
44
|
+
// ../core/src/errors.ts
|
|
45
|
+
var import_viem = require("viem");
|
|
46
|
+
var PEACH_SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("masterpeach.sdk-core.PeachSdkError");
|
|
47
|
+
var PeachSdkError = class extends Error {
|
|
48
|
+
code;
|
|
49
|
+
metadata;
|
|
50
|
+
constructor(code, message, options = {}) {
|
|
51
|
+
super(message, { cause: options.cause });
|
|
52
|
+
this.name = "PeachSdkError";
|
|
53
|
+
this.code = code;
|
|
54
|
+
this.metadata = options.metadata ?? {};
|
|
55
|
+
Object.defineProperty(this, PEACH_SDK_ERROR_BRAND, { value: true });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var UnsupportedChainError = class extends PeachSdkError {
|
|
59
|
+
constructor(chainId) {
|
|
60
|
+
super("UNSUPPORTED_CHAIN", `Unsupported chain: ${chainId}`, {
|
|
61
|
+
metadata: { chainId }
|
|
62
|
+
});
|
|
63
|
+
this.name = "UnsupportedChainError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var MissingChainError = class extends PeachSdkError {
|
|
67
|
+
constructor() {
|
|
68
|
+
super("MISSING_CHAIN", "A chain ID is required for this operation.");
|
|
69
|
+
this.name = "MissingChainError";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var MissingAccountError = class extends PeachSdkError {
|
|
73
|
+
constructor() {
|
|
74
|
+
super("MISSING_ACCOUNT", "A wallet account is required for this operation.");
|
|
75
|
+
this.name = "MissingAccountError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function isPeachSdkError(value, code) {
|
|
79
|
+
if (typeof value !== "object" || value === null) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (value[PEACH_SDK_ERROR_BRAND] !== true) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return code === void 0 || value.code === code;
|
|
86
|
+
}
|
|
87
|
+
function toPeachSdkError(error) {
|
|
88
|
+
if (isPeachSdkError(error)) {
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
if (error instanceof import_viem.UserRejectedRequestError) {
|
|
92
|
+
return new PeachSdkError("USER_REJECTED", "The wallet request was rejected.", {
|
|
93
|
+
cause: error
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return new PeachSdkError("UNKNOWN_ERROR", "An unknown SDK error occurred.", {
|
|
97
|
+
cause: error
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ../core/src/amount.ts
|
|
102
|
+
var DECIMAL_AMOUNT_PATTERN = /^(0|[1-9]\d*)(\.\d+)?$/;
|
|
103
|
+
function assertDecimals(decimals) {
|
|
104
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255) {
|
|
105
|
+
throw new PeachSdkError("INVALID_AMOUNT", `Invalid decimals: ${decimals}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function parseAmount(value, decimals) {
|
|
109
|
+
assertDecimals(decimals);
|
|
110
|
+
if (!DECIMAL_AMOUNT_PATTERN.test(value)) {
|
|
111
|
+
throw new PeachSdkError("INVALID_AMOUNT", `Invalid decimal amount: ${value}`);
|
|
112
|
+
}
|
|
113
|
+
const fraction = value.split(".")[1] ?? "";
|
|
114
|
+
if (fraction.length > decimals) {
|
|
115
|
+
throw new PeachSdkError(
|
|
116
|
+
"INVALID_AMOUNT",
|
|
117
|
+
`Amount has ${fraction.length} decimal places but token supports ${decimals}.`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return (0, import_viem2.parseUnits)(value, decimals);
|
|
121
|
+
}
|
|
122
|
+
function formatAmount(value, decimals) {
|
|
123
|
+
assertDecimals(decimals);
|
|
124
|
+
if (value < 0n) {
|
|
125
|
+
throw new PeachSdkError("INVALID_AMOUNT", "Token amounts cannot be negative.");
|
|
126
|
+
}
|
|
127
|
+
return (0, import_viem2.formatUnits)(value, decimals);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ../core/src/chain.ts
|
|
131
|
+
function resolveChainValue(registry, chainId) {
|
|
132
|
+
const value = registry[chainId];
|
|
133
|
+
if (value === void 0) {
|
|
134
|
+
throw new UnsupportedChainError(chainId);
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
function requireWalletClient(walletClient) {
|
|
139
|
+
if (!walletClient?.account) {
|
|
140
|
+
throw new MissingAccountError();
|
|
141
|
+
}
|
|
142
|
+
return walletClient;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ../core/src/prepared.ts
|
|
146
|
+
var import_viem3 = require("viem");
|
|
147
|
+
var import_accounts = require("viem/accounts");
|
|
148
|
+
function immutableClone(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
149
|
+
if (value === null || typeof value !== "object") return value;
|
|
150
|
+
const source = value;
|
|
151
|
+
const existing = seen.get(source);
|
|
152
|
+
if (existing !== void 0) return existing;
|
|
153
|
+
const clone = Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(source));
|
|
154
|
+
seen.set(source, clone);
|
|
155
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
156
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
157
|
+
if (!descriptor) continue;
|
|
158
|
+
if ("value" in descriptor) {
|
|
159
|
+
descriptor.value = immutableClone(descriptor.value, seen);
|
|
160
|
+
descriptor.writable = false;
|
|
161
|
+
}
|
|
162
|
+
descriptor.configurable = false;
|
|
163
|
+
Object.defineProperty(clone, key, descriptor);
|
|
164
|
+
}
|
|
165
|
+
return Object.freeze(clone);
|
|
166
|
+
}
|
|
167
|
+
function createPreparedTransactionStore() {
|
|
168
|
+
const canonicalRequests = /* @__PURE__ */ new WeakMap();
|
|
169
|
+
return Object.freeze({
|
|
170
|
+
create(request, preview, context) {
|
|
171
|
+
const canonicalRequest = immutableClone(request);
|
|
172
|
+
const prepared = Object.freeze({
|
|
173
|
+
request: immutableClone(request),
|
|
174
|
+
preview,
|
|
175
|
+
context
|
|
176
|
+
});
|
|
177
|
+
canonicalRequests.set(prepared, canonicalRequest);
|
|
178
|
+
return prepared;
|
|
179
|
+
},
|
|
180
|
+
has: (value) => canonicalRequests.has(value),
|
|
181
|
+
getCanonical: (value) => canonicalRequests.get(value)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async function resolveLiveWalletAccount(walletClient, expectedChainId, chainMismatch) {
|
|
185
|
+
const client = requireWalletClient(walletClient);
|
|
186
|
+
const actualChainId = await client.getChainId();
|
|
187
|
+
if (actualChainId !== expectedChainId) {
|
|
188
|
+
throw chainMismatch(expectedChainId, actualChainId);
|
|
189
|
+
}
|
|
190
|
+
const [liveAddress] = await client.getAddresses();
|
|
191
|
+
if (!liveAddress) throw new MissingAccountError();
|
|
192
|
+
const configuredAccount = client.account;
|
|
193
|
+
if (!configuredAccount) throw new MissingAccountError();
|
|
194
|
+
return (0, import_viem3.isAddressEqual)(configuredAccount.address, liveAddress) ? configuredAccount : (0, import_accounts.parseAccount)(liveAddress);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ../core/src/requestAbort.ts
|
|
198
|
+
function createRequestAbortScope(timeoutMs, callerSignal) {
|
|
199
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
200
|
+
throw new RangeError("timeoutMs must be a positive, finite number of milliseconds.");
|
|
201
|
+
}
|
|
202
|
+
const controller = new AbortController();
|
|
203
|
+
let didTimeout = false;
|
|
204
|
+
const abortFromCaller = () => controller.abort(callerSignal?.reason);
|
|
205
|
+
if (callerSignal?.aborted) {
|
|
206
|
+
abortFromCaller();
|
|
207
|
+
} else {
|
|
208
|
+
callerSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
209
|
+
}
|
|
210
|
+
const timeout = setTimeout(() => {
|
|
211
|
+
if (controller.signal.aborted) return;
|
|
212
|
+
didTimeout = true;
|
|
213
|
+
controller.abort(new Error(`Request timed out after ${timeoutMs}ms.`));
|
|
214
|
+
}, timeoutMs);
|
|
215
|
+
const waitFor = (operation) => {
|
|
216
|
+
if (controller.signal.aborted) {
|
|
217
|
+
return Promise.reject(controller.signal.reason);
|
|
218
|
+
}
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
const rejectFromAbort = () => reject(controller.signal.reason);
|
|
221
|
+
controller.signal.addEventListener("abort", rejectFromAbort, { once: true });
|
|
222
|
+
void Promise.resolve(operation).then(
|
|
223
|
+
(value) => {
|
|
224
|
+
controller.signal.removeEventListener("abort", rejectFromAbort);
|
|
225
|
+
resolve(value);
|
|
226
|
+
},
|
|
227
|
+
(error) => {
|
|
228
|
+
controller.signal.removeEventListener("abort", rejectFromAbort);
|
|
229
|
+
reject(error);
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
return Object.freeze({
|
|
235
|
+
signal: controller.signal,
|
|
236
|
+
timedOut: () => didTimeout,
|
|
237
|
+
waitFor,
|
|
238
|
+
release: () => {
|
|
239
|
+
clearTimeout(timeout);
|
|
240
|
+
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ../core/src/transaction.ts
|
|
246
|
+
function transactionResultFromReceipt(receipt) {
|
|
247
|
+
return {
|
|
248
|
+
hash: receipt.transactionHash,
|
|
249
|
+
status: receipt.status === "success" ? "confirmed" : "reverted",
|
|
250
|
+
receipt
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
254
|
+
0 && (module.exports = {
|
|
255
|
+
MissingAccountError,
|
|
256
|
+
MissingChainError,
|
|
257
|
+
PeachSdkError,
|
|
258
|
+
UnsupportedChainError,
|
|
259
|
+
createPreparedTransactionStore,
|
|
260
|
+
createRequestAbortScope,
|
|
261
|
+
formatAmount,
|
|
262
|
+
immutableClone,
|
|
263
|
+
isPeachSdkError,
|
|
264
|
+
parseAmount,
|
|
265
|
+
requireWalletClient,
|
|
266
|
+
resolveChainValue,
|
|
267
|
+
resolveLiveWalletAccount,
|
|
268
|
+
toPeachSdkError,
|
|
269
|
+
transactionResultFromReceipt
|
|
270
|
+
});
|
|
271
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.ts","../../core/src/amount.ts","../../core/src/errors.ts","../../core/src/chain.ts","../../core/src/prepared.ts","../../core/src/requestAbort.ts","../../core/src/transaction.ts"],"sourcesContent":["// Like the other product SDKs, inline the private core's intentional source entry point.\n// Its workspace package is not published and must not survive in emitted declarations.\nexport * from \"../../core/src/index\";\n","import { formatUnits, parseUnits } from \"viem\";\n\nimport { PeachSdkError } from \"./errors\";\n\nconst DECIMAL_AMOUNT_PATTERN = /^(0|[1-9]\\d*)(\\.\\d+)?$/;\n\nfunction assertDecimals(decimals: number): void {\n if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255) {\n throw new PeachSdkError(\"INVALID_AMOUNT\", `Invalid decimals: ${decimals}`);\n }\n}\n\n/** Parses a canonical unsigned decimal token amount into integer base units. */\nexport function parseAmount(value: string, decimals: number): bigint {\n assertDecimals(decimals);\n\n if (!DECIMAL_AMOUNT_PATTERN.test(value)) {\n throw new PeachSdkError(\"INVALID_AMOUNT\", `Invalid decimal amount: ${value}`);\n }\n\n const fraction = value.split(\".\")[1] ?? \"\";\n if (fraction.length > decimals) {\n throw new PeachSdkError(\n \"INVALID_AMOUNT\",\n `Amount has ${fraction.length} decimal places but token supports ${decimals}.`,\n );\n }\n\n return parseUnits(value, decimals);\n}\n\n/** Formats an unsigned base-unit token amount without introducing floating-point rounding. */\nexport function formatAmount(value: bigint, decimals: number): string {\n assertDecimals(decimals);\n\n if (value < 0n) {\n throw new PeachSdkError(\"INVALID_AMOUNT\", \"Token amounts cannot be negative.\");\n }\n\n return formatUnits(value, decimals);\n}\n","import { UserRejectedRequestError } from \"viem\";\n\nexport type PeachSdkErrorCode =\n | \"INVALID_AMOUNT\"\n | \"MISSING_ACCOUNT\"\n | \"MISSING_CHAIN\"\n | \"UNSUPPORTED_CHAIN\"\n | \"USER_REJECTED\"\n | \"TRANSPORT_ERROR\"\n | \"CONTRACT_ERROR\"\n | \"UNKNOWN_ERROR\";\n\n/**\n * Cross-copy brand for shared SDK errors.\n *\n * Every product SDK bundles its own copy of these primitives, so an error thrown by\n * `@masterpeach/launchpad-sdk` is not an `instanceof` the class of the same name exported by\n * `@masterpeach/lending-sdk`. `Symbol.for` resolves through the runtime-wide symbol registry, so\n * each copy brands its errors with the identical key and can recognize the others'.\n */\nconst PEACH_SDK_ERROR_BRAND = Symbol.for(\"masterpeach.sdk-core.PeachSdkError\");\n\n/** Base error carrying a stable machine-readable code and structured diagnostic metadata. */\nexport class PeachSdkError extends Error {\n readonly code: PeachSdkErrorCode;\n readonly metadata: Readonly<Record<string, unknown>>;\n\n constructor(\n code: PeachSdkErrorCode,\n message: string,\n options: { cause?: unknown; metadata?: Readonly<Record<string, unknown>> } = {},\n ) {\n super(message, { cause: options.cause });\n this.name = \"PeachSdkError\";\n this.code = code;\n this.metadata = options.metadata ?? {};\n // Non-enumerable so the brand stays out of structured clones and JSON diagnostics.\n Object.defineProperty(this, PEACH_SDK_ERROR_BRAND, { value: true });\n }\n}\n\nexport class UnsupportedChainError extends PeachSdkError {\n constructor(chainId: number) {\n super(\"UNSUPPORTED_CHAIN\", `Unsupported chain: ${chainId}`, {\n metadata: { chainId },\n });\n this.name = \"UnsupportedChainError\";\n }\n}\n\nexport class MissingChainError extends PeachSdkError {\n constructor() {\n super(\"MISSING_CHAIN\", \"A chain ID is required for this operation.\");\n this.name = \"MissingChainError\";\n }\n}\n\nexport class MissingAccountError extends PeachSdkError {\n constructor() {\n super(\"MISSING_ACCOUNT\", \"A wallet account is required for this operation.\");\n this.name = \"MissingAccountError\";\n }\n}\n\n/**\n * Recognizes a shared SDK error regardless of which product SDK created it.\n *\n * Prefer this over `instanceof PeachSdkError` whenever an application depends on more than one\n * MasterPeach SDK: each package carries its own copy of the class, so `instanceof` only matches\n * errors that happened to originate from the same package. Pass a `code` to narrow in one step.\n */\nexport function isPeachSdkError(value: unknown): value is PeachSdkError;\nexport function isPeachSdkError<TCode extends PeachSdkErrorCode>(\n value: unknown,\n code: TCode,\n): value is PeachSdkError & { readonly code: TCode };\nexport function isPeachSdkError(value: unknown, code?: PeachSdkErrorCode): boolean {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n if ((value as Record<symbol, unknown>)[PEACH_SDK_ERROR_BRAND] !== true) {\n return false;\n }\n return code === undefined || (value as PeachSdkError).code === code;\n}\n\n/** Normalizes wallet rejection and unknown failures at a shared SDK boundary. */\nexport function toPeachSdkError(error: unknown): PeachSdkError {\n // Brand check rather than `instanceof`, so an error raised by a sibling SDK keeps its code\n // instead of being flattened into UNKNOWN_ERROR.\n if (isPeachSdkError(error)) {\n return error;\n }\n\n if (error instanceof UserRejectedRequestError) {\n return new PeachSdkError(\"USER_REJECTED\", \"The wallet request was rejected.\", {\n cause: error,\n });\n }\n\n return new PeachSdkError(\"UNKNOWN_ERROR\", \"An unknown SDK error occurred.\", {\n cause: error,\n });\n}\n","import type { WalletClient } from \"viem\";\n\nimport { MissingAccountError, UnsupportedChainError } from \"./errors\";\n\nexport type ChainRegistry<T> = Readonly<Record<number, T>>;\n\n/** Resolves a chain-scoped configuration value or throws a stable unsupported-chain error. */\nexport function resolveChainValue<T>(registry: ChainRegistry<T>, chainId: number): T {\n const value = registry[chainId];\n if (value === undefined) {\n throw new UnsupportedChainError(chainId);\n }\n return value;\n}\n\n/** Requires a Wallet Client with an attached account before a signing or write operation. */\nexport function requireWalletClient(walletClient: WalletClient | undefined): WalletClient {\n if (!walletClient?.account) {\n throw new MissingAccountError();\n }\n return walletClient;\n}\n","import type { Account, WalletClient } from \"viem\";\nimport { isAddressEqual } from \"viem\";\nimport { parseAccount } from \"viem/accounts\";\nimport { requireWalletClient } from \"./chain\";\nimport { MissingAccountError } from \"./errors\";\n\n/** Public inspection shape shared by product-specific prepared transaction types. */\nexport interface PreparedTransactionSnapshot<Request extends object, Preview, Context> {\n readonly request: Readonly<Request>;\n readonly preview: Preview;\n readonly context: Context;\n}\n\n/** A module-local provenance store. Its canonical requests are never exposed to consumers. */\nexport interface PreparedTransactionStore {\n create<Request extends object, Preview, Context>(\n request: Request,\n preview: Preview,\n context: Context,\n ): PreparedTransactionSnapshot<Request, Preview, Context>;\n has(value: object): boolean;\n getCanonical<Request extends object>(value: object): Request | undefined;\n}\n\n/**\n * Copies and freezes plain Viem request data, retaining cycles, symbols, prototypes and functions.\n * Accessor descriptors are preserved without invoking them.\n */\nexport function immutableClone<Value>(value: Value, seen = new WeakMap<object, unknown>()): Value {\n if (value === null || typeof value !== \"object\") return value;\n\n const source = value as object;\n const existing = seen.get(source);\n if (existing !== undefined) return existing as Value;\n\n const clone: object = Array.isArray(value)\n ? []\n : Object.create(Object.getPrototypeOf(source) as object | null);\n seen.set(source, clone);\n\n for (const key of Reflect.ownKeys(source)) {\n const descriptor = Object.getOwnPropertyDescriptor(source, key);\n if (!descriptor) continue;\n if (\"value\" in descriptor) {\n descriptor.value = immutableClone(descriptor.value, seen);\n descriptor.writable = false;\n }\n descriptor.configurable = false;\n Object.defineProperty(clone, key, descriptor);\n }\n\n return Object.freeze(clone) as Value;\n}\n\n/**\n * Creates an isolated prepared-request registry for one product module.\n *\n * Sharing the factory removes duplicated security logic without sharing registry state: a value\n * prepared by one SDK can never become valid in another SDK's store.\n */\nexport function createPreparedTransactionStore(): PreparedTransactionStore {\n const canonicalRequests = new WeakMap<object, object>();\n\n return Object.freeze({\n create<Request extends object, Preview, Context>(\n request: Request,\n preview: Preview,\n context: Context,\n ): PreparedTransactionSnapshot<Request, Preview, Context> {\n const canonicalRequest = immutableClone(request);\n const prepared = Object.freeze({\n request: immutableClone(request),\n preview,\n context,\n });\n canonicalRequests.set(prepared, canonicalRequest);\n return prepared;\n },\n has: (value: object) => canonicalRequests.has(value),\n getCanonical: <Request extends object>(value: object) =>\n canonicalRequests.get(value) as Request | undefined,\n });\n}\n\n/**\n * Resolves the wallet's live account after proving its current chain.\n *\n * Product SDKs provide their own chain-mismatch error factory so this shared state-transition\n * check does not erase protocol-specific error contracts.\n */\nexport async function resolveLiveWalletAccount(\n walletClient: WalletClient | undefined,\n expectedChainId: number,\n chainMismatch: (expectedChainId: number, actualChainId: number) => Error,\n): Promise<Account> {\n const client = requireWalletClient(walletClient);\n const actualChainId = await client.getChainId();\n if (actualChainId !== expectedChainId) {\n throw chainMismatch(expectedChainId, actualChainId);\n }\n\n const [liveAddress] = await client.getAddresses();\n if (!liveAddress) throw new MissingAccountError();\n\n const configuredAccount = client.account;\n if (!configuredAccount) throw new MissingAccountError();\n return isAddressEqual(configuredAccount.address, liveAddress)\n ? configuredAccount\n : parseAccount(liveAddress);\n}\n","export interface RequestAbortScope {\n readonly signal: AbortSignal;\n readonly timedOut: () => boolean;\n /** Races work that cannot consume an AbortSignal, such as async credential resolution. */\n readonly waitFor: <Value>(operation: PromiseLike<Value>) => Promise<Value>;\n readonly release: () => void;\n}\n\n/** Links caller cancellation and an SDK deadline while keeping their causes distinguishable. */\nexport function createRequestAbortScope(\n timeoutMs: number,\n callerSignal?: AbortSignal,\n): RequestAbortScope {\n if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n throw new RangeError(\"timeoutMs must be a positive, finite number of milliseconds.\");\n }\n\n const controller = new AbortController();\n let didTimeout = false;\n const abortFromCaller = () => controller.abort(callerSignal?.reason);\n if (callerSignal?.aborted) {\n abortFromCaller();\n } else {\n callerSignal?.addEventListener(\"abort\", abortFromCaller, { once: true });\n }\n\n const timeout = setTimeout(() => {\n // Caller cancellation wins permanently. Without this guard the timer can fire later and make\n // a cancelled request look timed out to consumers that inspect the scope after async cleanup.\n if (controller.signal.aborted) return;\n didTimeout = true;\n controller.abort(new Error(`Request timed out after ${timeoutMs}ms.`));\n }, timeoutMs);\n\n const waitFor = <Value>(operation: PromiseLike<Value>): Promise<Value> => {\n if (controller.signal.aborted) {\n return Promise.reject(controller.signal.reason);\n }\n return new Promise<Value>((resolve, reject) => {\n const rejectFromAbort = () => reject(controller.signal.reason);\n controller.signal.addEventListener(\"abort\", rejectFromAbort, { once: true });\n void Promise.resolve(operation).then(\n (value) => {\n controller.signal.removeEventListener(\"abort\", rejectFromAbort);\n resolve(value);\n },\n (error: unknown) => {\n controller.signal.removeEventListener(\"abort\", rejectFromAbort);\n reject(error);\n },\n );\n });\n };\n\n return Object.freeze({\n signal: controller.signal,\n timedOut: () => didTimeout,\n waitFor,\n release: () => {\n clearTimeout(timeout);\n callerSignal?.removeEventListener(\"abort\", abortFromCaller);\n },\n });\n}\n","import type { Hash, TransactionReceipt } from \"viem\";\n\nexport type SdkTransactionStatus = \"pending\" | \"confirmed\" | \"reverted\";\n\n/** Framework-neutral transaction result shared by product SDK packages. */\nexport interface SdkTransactionResult {\n readonly hash: Hash;\n readonly status: SdkTransactionStatus;\n readonly receipt?: TransactionReceipt;\n}\n\n/** Converts a Viem receipt into the stable shared transaction result shape. */\nexport function transactionResultFromReceipt(receipt: TransactionReceipt): SdkTransactionResult {\n return {\n hash: receipt.transactionHash,\n status: receipt.status === \"success\" ? \"confirmed\" : \"reverted\",\n receipt,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAAwC;;;ACAxC,kBAAyC;AAoBzC,IAAM,wBAAwB,uBAAO,IAAI,oCAAoC;AAGtE,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YACE,MACA,SACA,UAA6E,CAAC,GAC9E;AACA,UAAM,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;AACvC,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW,QAAQ,YAAY,CAAC;AAErC,WAAO,eAAe,MAAM,uBAAuB,EAAE,OAAO,KAAK,CAAC;AAAA,EACpE;AACF;AAEO,IAAM,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ransactionReceipt } from 'viem';
|
|
2
|
+
|
|
3
|
+
/** Parses a canonical unsigned decimal token amount into integer base units. */
|
|
4
|
+
declare function parseAmount(value: string, decimals: number): bigint;
|
|
5
|
+
/** Formats an unsigned base-unit token amount without introducing floating-point rounding. */
|
|
6
|
+
declare function formatAmount(value: bigint, decimals: number): string;
|
|
7
|
+
|
|
8
|
+
type ChainRegistry<T> = Readonly<Record<number, T>>;
|
|
9
|
+
/** Resolves a chain-scoped configuration value or throws a stable unsupported-chain error. */
|
|
10
|
+
declare function resolveChainValue<T>(registry: ChainRegistry<T>, chainId: number): T;
|
|
11
|
+
/** Requires a Wallet Client with an attached account before a signing or write operation. */
|
|
12
|
+
declare function requireWalletClient(walletClient: WalletClient | undefined): WalletClient;
|
|
13
|
+
|
|
14
|
+
type PeachSdkErrorCode = "INVALID_AMOUNT" | "MISSING_ACCOUNT" | "MISSING_CHAIN" | "UNSUPPORTED_CHAIN" | "USER_REJECTED" | "TRANSPORT_ERROR" | "CONTRACT_ERROR" | "UNKNOWN_ERROR";
|
|
15
|
+
/** Base error carrying a stable machine-readable code and structured diagnostic metadata. */
|
|
16
|
+
declare class PeachSdkError extends Error {
|
|
17
|
+
readonly code: PeachSdkErrorCode;
|
|
18
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
19
|
+
constructor(code: PeachSdkErrorCode, message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
declare class UnsupportedChainError extends PeachSdkError {
|
|
25
|
+
constructor(chainId: number);
|
|
26
|
+
}
|
|
27
|
+
declare class MissingChainError extends PeachSdkError {
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
declare class MissingAccountError extends PeachSdkError {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Recognizes a shared SDK error regardless of which product SDK created it.
|
|
35
|
+
*
|
|
36
|
+
* Prefer this over `instanceof PeachSdkError` whenever an application depends on more than one
|
|
37
|
+
* MasterPeach SDK: each package carries its own copy of the class, so `instanceof` only matches
|
|
38
|
+
* errors that happened to originate from the same package. Pass a `code` to narrow in one step.
|
|
39
|
+
*/
|
|
40
|
+
declare function isPeachSdkError(value: unknown): value is PeachSdkError;
|
|
41
|
+
declare function isPeachSdkError<TCode extends PeachSdkErrorCode>(value: unknown, code: TCode): value is PeachSdkError & {
|
|
42
|
+
readonly code: TCode;
|
|
43
|
+
};
|
|
44
|
+
/** Normalizes wallet rejection and unknown failures at a shared SDK boundary. */
|
|
45
|
+
declare function toPeachSdkError(error: unknown): PeachSdkError;
|
|
46
|
+
|
|
47
|
+
/** Public inspection shape shared by product-specific prepared transaction types. */
|
|
48
|
+
interface PreparedTransactionSnapshot<Request extends object, Preview, Context> {
|
|
49
|
+
readonly request: Readonly<Request>;
|
|
50
|
+
readonly preview: Preview;
|
|
51
|
+
readonly context: Context;
|
|
52
|
+
}
|
|
53
|
+
/** A module-local provenance store. Its canonical requests are never exposed to consumers. */
|
|
54
|
+
interface PreparedTransactionStore {
|
|
55
|
+
create<Request extends object, Preview, Context>(request: Request, preview: Preview, context: Context): PreparedTransactionSnapshot<Request, Preview, Context>;
|
|
56
|
+
has(value: object): boolean;
|
|
57
|
+
getCanonical<Request extends object>(value: object): Request | undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Copies and freezes plain Viem request data, retaining cycles, symbols, prototypes and functions.
|
|
61
|
+
* Accessor descriptors are preserved without invoking them.
|
|
62
|
+
*/
|
|
63
|
+
declare function immutableClone<Value>(value: Value, seen?: WeakMap<object, unknown>): Value;
|
|
64
|
+
/**
|
|
65
|
+
* Creates an isolated prepared-request registry for one product module.
|
|
66
|
+
*
|
|
67
|
+
* Sharing the factory removes duplicated security logic without sharing registry state: a value
|
|
68
|
+
* prepared by one SDK can never become valid in another SDK's store.
|
|
69
|
+
*/
|
|
70
|
+
declare function createPreparedTransactionStore(): PreparedTransactionStore;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves the wallet's live account after proving its current chain.
|
|
73
|
+
*
|
|
74
|
+
* Product SDKs provide their own chain-mismatch error factory so this shared state-transition
|
|
75
|
+
* check does not erase protocol-specific error contracts.
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveLiveWalletAccount(walletClient: WalletClient | undefined, expectedChainId: number, chainMismatch: (expectedChainId: number, actualChainId: number) => Error): Promise<Account>;
|
|
78
|
+
|
|
79
|
+
interface RequestAbortScope {
|
|
80
|
+
readonly signal: AbortSignal;
|
|
81
|
+
readonly timedOut: () => boolean;
|
|
82
|
+
/** Races work that cannot consume an AbortSignal, such as async credential resolution. */
|
|
83
|
+
readonly waitFor: <Value>(operation: PromiseLike<Value>) => Promise<Value>;
|
|
84
|
+
readonly release: () => void;
|
|
85
|
+
}
|
|
86
|
+
/** Links caller cancellation and an SDK deadline while keeping their causes distinguishable. */
|
|
87
|
+
declare function createRequestAbortScope(timeoutMs: number, callerSignal?: AbortSignal): RequestAbortScope;
|
|
88
|
+
|
|
89
|
+
type SdkTransactionStatus = "pending" | "confirmed" | "reverted";
|
|
90
|
+
/** Framework-neutral transaction result shared by product SDK packages. */
|
|
91
|
+
interface SdkTransactionResult {
|
|
92
|
+
readonly hash: Hash;
|
|
93
|
+
readonly status: SdkTransactionStatus;
|
|
94
|
+
readonly receipt?: TransactionReceipt;
|
|
95
|
+
}
|
|
96
|
+
/** Converts a Viem receipt into the stable shared transaction result shape. */
|
|
97
|
+
declare function transactionResultFromReceipt(receipt: TransactionReceipt): SdkTransactionResult;
|
|
98
|
+
|
|
99
|
+
export { type ChainRegistry, MissingAccountError, MissingChainError, PeachSdkError, type PeachSdkErrorCode, type PreparedTransactionSnapshot, type PreparedTransactionStore, type RequestAbortScope, type SdkTransactionResult, type SdkTransactionStatus, UnsupportedChainError, createPreparedTransactionStore, createRequestAbortScope, formatAmount, immutableClone, isPeachSdkError, parseAmount, requireWalletClient, resolveChainValue, resolveLiveWalletAccount, toPeachSdkError, transactionResultFromReceipt };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { WalletClient, Account, Hash, TransactionReceipt } from 'viem';
|
|
2
|
+
|
|
3
|
+
/** Parses a canonical unsigned decimal token amount into integer base units. */
|
|
4
|
+
declare function parseAmount(value: string, decimals: number): bigint;
|
|
5
|
+
/** Formats an unsigned base-unit token amount without introducing floating-point rounding. */
|
|
6
|
+
declare function formatAmount(value: bigint, decimals: number): string;
|
|
7
|
+
|
|
8
|
+
type ChainRegistry<T> = Readonly<Record<number, T>>;
|
|
9
|
+
/** Resolves a chain-scoped configuration value or throws a stable unsupported-chain error. */
|
|
10
|
+
declare function resolveChainValue<T>(registry: ChainRegistry<T>, chainId: number): T;
|
|
11
|
+
/** Requires a Wallet Client with an attached account before a signing or write operation. */
|
|
12
|
+
declare function requireWalletClient(walletClient: WalletClient | undefined): WalletClient;
|
|
13
|
+
|
|
14
|
+
type PeachSdkErrorCode = "INVALID_AMOUNT" | "MISSING_ACCOUNT" | "MISSING_CHAIN" | "UNSUPPORTED_CHAIN" | "USER_REJECTED" | "TRANSPORT_ERROR" | "CONTRACT_ERROR" | "UNKNOWN_ERROR";
|
|
15
|
+
/** Base error carrying a stable machine-readable code and structured diagnostic metadata. */
|
|
16
|
+
declare class PeachSdkError extends Error {
|
|
17
|
+
readonly code: PeachSdkErrorCode;
|
|
18
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
19
|
+
constructor(code: PeachSdkErrorCode, message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
declare class UnsupportedChainError extends PeachSdkError {
|
|
25
|
+
constructor(chainId: number);
|
|
26
|
+
}
|
|
27
|
+
declare class MissingChainError extends PeachSdkError {
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
declare class MissingAccountError extends PeachSdkError {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Recognizes a shared SDK error regardless of which product SDK created it.
|
|
35
|
+
*
|
|
36
|
+
* Prefer this over `instanceof PeachSdkError` whenever an application depends on more than one
|
|
37
|
+
* MasterPeach SDK: each package carries its own copy of the class, so `instanceof` only matches
|
|
38
|
+
* errors that happened to originate from the same package. Pass a `code` to narrow in one step.
|
|
39
|
+
*/
|
|
40
|
+
declare function isPeachSdkError(value: unknown): value is PeachSdkError;
|
|
41
|
+
declare function isPeachSdkError<TCode extends PeachSdkErrorCode>(value: unknown, code: TCode): value is PeachSdkError & {
|
|
42
|
+
readonly code: TCode;
|
|
43
|
+
};
|
|
44
|
+
/** Normalizes wallet rejection and unknown failures at a shared SDK boundary. */
|
|
45
|
+
declare function toPeachSdkError(error: unknown): PeachSdkError;
|
|
46
|
+
|
|
47
|
+
/** Public inspection shape shared by product-specific prepared transaction types. */
|
|
48
|
+
interface PreparedTransactionSnapshot<Request extends object, Preview, Context> {
|
|
49
|
+
readonly request: Readonly<Request>;
|
|
50
|
+
readonly preview: Preview;
|
|
51
|
+
readonly context: Context;
|
|
52
|
+
}
|
|
53
|
+
/** A module-local provenance store. Its canonical requests are never exposed to consumers. */
|
|
54
|
+
interface PreparedTransactionStore {
|
|
55
|
+
create<Request extends object, Preview, Context>(request: Request, preview: Preview, context: Context): PreparedTransactionSnapshot<Request, Preview, Context>;
|
|
56
|
+
has(value: object): boolean;
|
|
57
|
+
getCanonical<Request extends object>(value: object): Request | undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Copies and freezes plain Viem request data, retaining cycles, symbols, prototypes and functions.
|
|
61
|
+
* Accessor descriptors are preserved without invoking them.
|
|
62
|
+
*/
|
|
63
|
+
declare function immutableClone<Value>(value: Value, seen?: WeakMap<object, unknown>): Value;
|
|
64
|
+
/**
|
|
65
|
+
* Creates an isolated prepared-request registry for one product module.
|
|
66
|
+
*
|
|
67
|
+
* Sharing the factory removes duplicated security logic without sharing registry state: a value
|
|
68
|
+
* prepared by one SDK can never become valid in another SDK's store.
|
|
69
|
+
*/
|
|
70
|
+
declare function createPreparedTransactionStore(): PreparedTransactionStore;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves the wallet's live account after proving its current chain.
|
|
73
|
+
*
|
|
74
|
+
* Product SDKs provide their own chain-mismatch error factory so this shared state-transition
|
|
75
|
+
* check does not erase protocol-specific error contracts.
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveLiveWalletAccount(walletClient: WalletClient | undefined, expectedChainId: number, chainMismatch: (expectedChainId: number, actualChainId: number) => Error): Promise<Account>;
|
|
78
|
+
|
|
79
|
+
interface RequestAbortScope {
|
|
80
|
+
readonly signal: AbortSignal;
|
|
81
|
+
readonly timedOut: () => boolean;
|
|
82
|
+
/** Races work that cannot consume an AbortSignal, such as async credential resolution. */
|
|
83
|
+
readonly waitFor: <Value>(operation: PromiseLike<Value>) => Promise<Value>;
|
|
84
|
+
readonly release: () => void;
|
|
85
|
+
}
|
|
86
|
+
/** Links caller cancellation and an SDK deadline while keeping their causes distinguishable. */
|
|
87
|
+
declare function createRequestAbortScope(timeoutMs: number, callerSignal?: AbortSignal): RequestAbortScope;
|
|
88
|
+
|
|
89
|
+
type SdkTransactionStatus = "pending" | "confirmed" | "reverted";
|
|
90
|
+
/** Framework-neutral transaction result shared by product SDK packages. */
|
|
91
|
+
interface SdkTransactionResult {
|
|
92
|
+
readonly hash: Hash;
|
|
93
|
+
readonly status: SdkTransactionStatus;
|
|
94
|
+
readonly receipt?: TransactionReceipt;
|
|
95
|
+
}
|
|
96
|
+
/** Converts a Viem receipt into the stable shared transaction result shape. */
|
|
97
|
+
declare function transactionResultFromReceipt(receipt: TransactionReceipt): SdkTransactionResult;
|
|
98
|
+
|
|
99
|
+
export { type ChainRegistry, MissingAccountError, MissingChainError, PeachSdkError, type PeachSdkErrorCode, type PreparedTransactionSnapshot, type PreparedTransactionStore, type RequestAbortScope, type SdkTransactionResult, type SdkTransactionStatus, UnsupportedChainError, createPreparedTransactionStore, createRequestAbortScope, formatAmount, immutableClone, isPeachSdkError, parseAmount, requireWalletClient, resolveChainValue, resolveLiveWalletAccount, toPeachSdkError, transactionResultFromReceipt };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MissingAccountError,
|
|
3
|
+
MissingChainError,
|
|
4
|
+
PeachSdkError,
|
|
5
|
+
UnsupportedChainError,
|
|
6
|
+
createPreparedTransactionStore,
|
|
7
|
+
createRequestAbortScope,
|
|
8
|
+
formatAmount,
|
|
9
|
+
immutableClone,
|
|
10
|
+
isPeachSdkError,
|
|
11
|
+
parseAmount,
|
|
12
|
+
requireWalletClient,
|
|
13
|
+
resolveChainValue,
|
|
14
|
+
resolveLiveWalletAccount,
|
|
15
|
+
toPeachSdkError,
|
|
16
|
+
transactionResultFromReceipt
|
|
17
|
+
} from "./chunk-TMU4HSZR.js";
|
|
18
|
+
export {
|
|
19
|
+
MissingAccountError,
|
|
20
|
+
MissingChainError,
|
|
21
|
+
PeachSdkError,
|
|
22
|
+
UnsupportedChainError,
|
|
23
|
+
createPreparedTransactionStore,
|
|
24
|
+
createRequestAbortScope,
|
|
25
|
+
formatAmount,
|
|
26
|
+
immutableClone,
|
|
27
|
+
isPeachSdkError,
|
|
28
|
+
parseAmount,
|
|
29
|
+
requireWalletClient,
|
|
30
|
+
resolveChainValue,
|
|
31
|
+
resolveLiveWalletAccount,
|
|
32
|
+
toPeachSdkError,
|
|
33
|
+
transactionResultFromReceipt
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|