@parity/product-sdk-contracts 0.5.0 → 0.6.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 +25 -0
- package/dist/codegen.d.ts +1 -1
- package/dist/index.d.ts +34 -184
- package/dist/index.js +101 -15
- package/dist/index.js.map +1 -1
- package/dist/pvm.d.ts +1 -1
- package/dist/types-Bh0tqK9s.d.ts +435 -0
- package/package.json +4 -4
- package/dist/types-BdHp-xWt.d.ts +0 -196
package/dist/pvm.d.ts
CHANGED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { HexString, SS58String, PolkadotClient, PolkadotSigner } from 'polkadot-api';
|
|
2
|
+
import { Weight, SubmittableTransaction, TxResult, SubmitOptions, BatchableCall } from '@parity/product-sdk-tx';
|
|
3
|
+
import { SignerManager } from '@parity/product-sdk-signer';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result of a `Revive.call` extrinsic — present on the typed API as
|
|
7
|
+
* `api.tx.Revive.call(args)`. Returned object is a PAPI submittable that
|
|
8
|
+
* `submitAndWatch` consumes natively.
|
|
9
|
+
*
|
|
10
|
+
* `dest` is an H160 hex string and `data` is a raw `Uint8Array`: this matches
|
|
11
|
+
* what `polkadot-api` ≥2.0 codecs accept and produce. The class-based
|
|
12
|
+
* `Binary` / `FixedSizeBinary` wrappers from `@polkadot-api/substrate-bindings`
|
|
13
|
+
* 0.12 are *not* accepted by PAPI 2.x's compatibility check.
|
|
14
|
+
*/
|
|
15
|
+
type ReviveCallTx = (args: {
|
|
16
|
+
dest: HexString;
|
|
17
|
+
value: bigint;
|
|
18
|
+
weight_limit: Weight;
|
|
19
|
+
storage_deposit_limit: bigint;
|
|
20
|
+
data: Uint8Array;
|
|
21
|
+
}) => SubmittableTransaction;
|
|
22
|
+
/**
|
|
23
|
+
* Dry-run result returned by `ReviveApi.call`. Mirrors the shape exposed by
|
|
24
|
+
* descriptors (`paseo-asset-hub`, `polkadot-asset-hub`, `kusama-asset-hub`).
|
|
25
|
+
*
|
|
26
|
+
* `data` is a raw `Uint8Array` because PAPI ≥2.0 dropped the `Binary` class
|
|
27
|
+
* wrapper for `Vec<u8>` codecs.
|
|
28
|
+
*/
|
|
29
|
+
interface ReviveDryRunResult {
|
|
30
|
+
weight_consumed: Weight;
|
|
31
|
+
weight_required: Weight;
|
|
32
|
+
storage_deposit: {
|
|
33
|
+
type: "Refund" | "Charge";
|
|
34
|
+
value: bigint;
|
|
35
|
+
};
|
|
36
|
+
max_storage_deposit: {
|
|
37
|
+
type: "Refund" | "Charge";
|
|
38
|
+
value: bigint;
|
|
39
|
+
};
|
|
40
|
+
gas_consumed: bigint;
|
|
41
|
+
/**
|
|
42
|
+
* `success: true` carries `{ flags, data }`; `success: false` carries the
|
|
43
|
+
* dispatch error as the chain encoded it.
|
|
44
|
+
*/
|
|
45
|
+
result: {
|
|
46
|
+
success: true;
|
|
47
|
+
value: {
|
|
48
|
+
flags: number;
|
|
49
|
+
data: Uint8Array;
|
|
50
|
+
};
|
|
51
|
+
} | {
|
|
52
|
+
success: false;
|
|
53
|
+
value: unknown;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Block reference used to target `ReviveApi.call` dry-runs. Matches PAPI's
|
|
58
|
+
* runtime-call `at` option: `"best"`, `"finalized"`, or a block hash.
|
|
59
|
+
*/
|
|
60
|
+
type ContractDryRunAt = "best" | "finalized" | HexString;
|
|
61
|
+
/**
|
|
62
|
+
* Per-call options accepted by {@link ReviveDryRunCall}.
|
|
63
|
+
*
|
|
64
|
+
* Note on the trailing `options` arg: pallet-revive's Rust runtime API
|
|
65
|
+
* `ReviveApi::call` only takes the 6 positional args (origin, dest, value,
|
|
66
|
+
* gas_limit, storage_deposit_limit, input_data). This 7th `options` object
|
|
67
|
+
* is **injected by PAPI** on every `api.apis.X.Y` runtime-API call via its
|
|
68
|
+
* `WithCallOptions` type wrapper (see
|
|
69
|
+
* `polkadot-api/packages/client/src/viewFns.ts:9-11` upstream — defined
|
|
70
|
+
* as `WithCallOptions$2` in the bundled `.d.ts` due to TS bundler suffixing).
|
|
71
|
+
* It never reaches the Rust side — PAPI's `viewFns.ts:38-41` consumes it in
|
|
72
|
+
* JS, reads `options.at`, resolves it to a concrete block hash via the
|
|
73
|
+
* chain-head's runtime context, and uses that hash on the JSON-RPC
|
|
74
|
+
* `state_call` invocation. The 6-arg payload sent over the wire is
|
|
75
|
+
* unchanged.
|
|
76
|
+
*/
|
|
77
|
+
interface ReviveDryRunCallOptions {
|
|
78
|
+
at?: ContractDryRunAt;
|
|
79
|
+
}
|
|
80
|
+
/** Structural shape consumed by `ContractManager` / `createContract`. */
|
|
81
|
+
interface ReviveTypedApi {
|
|
82
|
+
tx: {
|
|
83
|
+
Revive: {
|
|
84
|
+
call: ReviveCallTx;
|
|
85
|
+
map_account(): SubmittableTransaction;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
query: {
|
|
89
|
+
Revive: {
|
|
90
|
+
OriginalAccount: {
|
|
91
|
+
getValue(address: HexString): Promise<SS58String | undefined>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
apis: {
|
|
96
|
+
ReviveApi: {
|
|
97
|
+
call(origin: SS58String, dest: HexString, value: bigint, gas_limit: Weight | undefined, storage_deposit_limit: bigint | undefined, input_data: Uint8Array, options?: ReviveDryRunCallOptions): Promise<ReviveDryRunResult>;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Signature of a `ReviveApi.call` dry-run, used by the wrapped contract layer
|
|
103
|
+
* to estimate weight + storage deposit and surface revert / OOG /
|
|
104
|
+
* `AccountNotMapped` failures before a tx is signed.
|
|
105
|
+
*
|
|
106
|
+
* Identical to `ReviveTypedApi.apis.ReviveApi.call`, but extracted so the
|
|
107
|
+
* runtime can route this single hot call through PAPI's *unsafe* API
|
|
108
|
+
* (skipping compatibility-token checks) on production runtimes whose
|
|
109
|
+
* descriptors lag a chain upgrade — every other surface still uses the
|
|
110
|
+
* compat-checked typed API.
|
|
111
|
+
*/
|
|
112
|
+
type ReviveDryRunCall = (origin: SS58String, dest: HexString, value: bigint, gas_limit: Weight | undefined, storage_deposit_limit: bigint | undefined, input_data: Uint8Array, options?: ReviveDryRunCallOptions) => Promise<ReviveDryRunResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Runtime handle that drives queries and transactions against a
|
|
115
|
+
* pallet-revive-capable chain.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { createChainClient } from "@parity/product-sdk-chain-client";
|
|
120
|
+
* import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
121
|
+
* import { createContractRuntimeFromClient } from "@parity/product-sdk-contracts";
|
|
122
|
+
*
|
|
123
|
+
* const client = await createChainClient({
|
|
124
|
+
* chains: { assetHub: paseo_asset_hub },
|
|
125
|
+
* rpcs: { assetHub: ["wss://paseo-asset-hub-next-rpc.polkadot.io"] },
|
|
126
|
+
* });
|
|
127
|
+
* const runtime = createContractRuntimeFromClient(client.raw.assetHub, paseo_asset_hub);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
interface ContractRuntime {
|
|
131
|
+
readonly api: ReviveTypedApi;
|
|
132
|
+
/**
|
|
133
|
+
* Dry-run entry point. Production factories route this through the
|
|
134
|
+
* *unsafe* API to avoid compatibility-token failures when the descriptor
|
|
135
|
+
* trails a runtime upgrade. The {@link createContractRuntime} test factory
|
|
136
|
+
* delegates to `api.apis.ReviveApi.call`.
|
|
137
|
+
*
|
|
138
|
+
* The runtime default `at` (set via {@link ContractRuntimeOptions.at} on
|
|
139
|
+
* the factory) is applied when the caller does not pass an explicit
|
|
140
|
+
* `options.at`. `.query()` per-call overrides flow through this argument.
|
|
141
|
+
*/
|
|
142
|
+
readonly dryRunCall: ReviveDryRunCall;
|
|
143
|
+
}
|
|
144
|
+
/** Options for {@link createContractRuntime} / {@link createContractRuntimeFromClient}. */
|
|
145
|
+
interface ContractRuntimeOptions {
|
|
146
|
+
/**
|
|
147
|
+
* Block to target for `ReviveApi.call` dry-runs. Defaults to `"best"`
|
|
148
|
+
* so contract `.query()` reads observe the same state as transactions
|
|
149
|
+
* resolved at best-block (the product-sdk `.tx()` default). Set to
|
|
150
|
+
* `"finalized"` to read the canonical, lagged state, or to a specific
|
|
151
|
+
* block hash to pin reads to a historical block. Can be overridden per
|
|
152
|
+
* call via `QueryOptions.at`.
|
|
153
|
+
*/
|
|
154
|
+
at?: ContractDryRunAt;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Wrap a typed PAPI API as a `ContractRuntime`. Intended for tests and
|
|
158
|
+
* advanced setups where the caller already holds a typed API. Routes the
|
|
159
|
+
* dry-run through the typed (compatibility-token-checked) `ReviveApi.call`
|
|
160
|
+
* — fine for mocks but susceptible to `Incompatible runtime entry` errors
|
|
161
|
+
* on a live chain whose descriptor lags. Prefer
|
|
162
|
+
* {@link createContractRuntimeFromClient} for production use.
|
|
163
|
+
*/
|
|
164
|
+
declare function createContractRuntime(api: ReviveTypedApi, options?: ContractRuntimeOptions): ContractRuntime;
|
|
165
|
+
/**
|
|
166
|
+
* Build a `ContractRuntime` from a raw `PolkadotClient` plus its descriptor.
|
|
167
|
+
*
|
|
168
|
+
* The typed API powers `tx.Revive.call`, `tx.Revive.map_account`, and
|
|
169
|
+
* `query.Revive.OriginalAccount` (extrinsics + storage are tolerant of
|
|
170
|
+
* descriptor drift). The runtime-API dry-run, which is *not* tolerant of
|
|
171
|
+
* descriptor drift on PAPI's compat-token path, is routed through
|
|
172
|
+
* `client.getUnsafeApi()` — bypassing the compat check while preserving
|
|
173
|
+
* argument and return shapes.
|
|
174
|
+
*
|
|
175
|
+
* Use this on every production code path that calls a contract's `.tx()` or
|
|
176
|
+
* `.query()` against a live chain.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
181
|
+
* import { createContractRuntimeFromClient } from "@parity/product-sdk-contracts";
|
|
182
|
+
*
|
|
183
|
+
* const runtime = createContractRuntimeFromClient(rawClient, paseo_asset_hub);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function createContractRuntimeFromClient<TDescriptor>(client: PolkadotClient, descriptor: TDescriptor, options?: ContractRuntimeOptions): ContractRuntime;
|
|
187
|
+
/**
|
|
188
|
+
* Ensure the SS58 account is mapped to its derived H160 on `pallet-revive`.
|
|
189
|
+
*
|
|
190
|
+
* `pallet-revive` requires every signing account to have a registered
|
|
191
|
+
* `OriginalAccount` mapping before the runtime accepts its `Revive.call`
|
|
192
|
+
* extrinsics. The mapping is one-time and cheap. This helper:
|
|
193
|
+
*
|
|
194
|
+
* 1. Reads `Revive.OriginalAccount` for the H160 derived from `address`.
|
|
195
|
+
* 2. Returns `null` if already mapped (idempotent fast-path).
|
|
196
|
+
* 3. Otherwise submits `Revive.map_account()` and waits for inclusion.
|
|
197
|
+
*
|
|
198
|
+
* Call this once per signing account at app startup — after that, every
|
|
199
|
+
* subsequent `contract.<method>.tx({ signer })` against the same chain will
|
|
200
|
+
* succeed without further mapping work.
|
|
201
|
+
*
|
|
202
|
+
* @param runtime - The contract runtime (typically `createContractRuntime(...)`).
|
|
203
|
+
* @param address - The SS58 address of the account to map.
|
|
204
|
+
* @param signer - A signer matching `address`.
|
|
205
|
+
* @param options - Optional timeout / status callback (forwarded to the underlying tx).
|
|
206
|
+
* @returns The `TxResult` from the mapping extrinsic, or `null` if already mapped.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { createContractRuntime, ensureContractAccountMapped } from "@parity/product-sdk-contracts";
|
|
211
|
+
*
|
|
212
|
+
* const runtime = createContractRuntime(client.getTypedApi(paseo_asset_hub));
|
|
213
|
+
* await ensureContractAccountMapped(runtime, signerManager.getState().selectedAccount!.address, signer);
|
|
214
|
+
* // now safe to call contract.<method>.tx({ signer })
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
declare function ensureContractAccountMapped(runtime: ContractRuntime, address: SS58String, signer: PolkadotSigner, options?: {
|
|
218
|
+
timeoutMs?: number;
|
|
219
|
+
onStatus?: (s: string) => void;
|
|
220
|
+
}): Promise<TxResult | null>;
|
|
221
|
+
|
|
222
|
+
/** Pins a target to specific asset-hub and Bulletin chain hashes in `cdm.json`. */
|
|
223
|
+
interface CdmJsonTarget {
|
|
224
|
+
"asset-hub": string;
|
|
225
|
+
bulletin: string;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A deployed contract's on-chain address, ABI, and optional metadata CID.
|
|
229
|
+
*
|
|
230
|
+
* `metadataCid` is optional because real-world cdm.json files (e.g.
|
|
231
|
+
* `paritytech/playground-cli/cdm.json`) don't always include it — only
|
|
232
|
+
* `version`, `address`, and `abi` are load-bearing for `getContract()`.
|
|
233
|
+
*/
|
|
234
|
+
interface CdmJsonContract {
|
|
235
|
+
version: number;
|
|
236
|
+
address: HexString;
|
|
237
|
+
abi: AbiEntry[];
|
|
238
|
+
metadataCid?: string;
|
|
239
|
+
}
|
|
240
|
+
/** A project's `cdm.json` manifest: declared targets, runtime dependencies, and per-target contract deployments. */
|
|
241
|
+
interface CdmJson {
|
|
242
|
+
targets: Record<string, CdmJsonTarget>;
|
|
243
|
+
dependencies: Record<string, Record<string, number | string>>;
|
|
244
|
+
contracts?: Record<string, Record<string, CdmJsonContract>>;
|
|
245
|
+
}
|
|
246
|
+
/** An ABI parameter or return value, with support for nested tuple and struct types. */
|
|
247
|
+
interface AbiParam {
|
|
248
|
+
name: string;
|
|
249
|
+
type: string;
|
|
250
|
+
components?: AbiParam[];
|
|
251
|
+
}
|
|
252
|
+
/** One function, constructor, or event in a contract's ABI. */
|
|
253
|
+
interface AbiEntry {
|
|
254
|
+
type: string;
|
|
255
|
+
name?: string;
|
|
256
|
+
inputs: AbiParam[];
|
|
257
|
+
outputs?: AbiParam[];
|
|
258
|
+
stateMutability?: string;
|
|
259
|
+
}
|
|
260
|
+
/** Per-contract definition shape — generated into `.cdm/contracts.d.ts` via module augmentation. */
|
|
261
|
+
interface ContractDef {
|
|
262
|
+
methods: Record<string, {
|
|
263
|
+
args: any[];
|
|
264
|
+
response: any;
|
|
265
|
+
}>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Augmentable interface extended by codegen with per-contract method types.
|
|
269
|
+
*
|
|
270
|
+
* After running `cdm install`, a generated `.d.ts` file augments this
|
|
271
|
+
* interface so that `ContractManager.getContract()` returns fully-typed
|
|
272
|
+
* contract handles.
|
|
273
|
+
*/
|
|
274
|
+
interface Contracts {
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Result from a read-only contract query.
|
|
278
|
+
*
|
|
279
|
+
* On success, `value` is the decoded response and `gasRequired` is the
|
|
280
|
+
* `Weight` consumed by `ReviveApi.call`'s dry-run — consumable directly by
|
|
281
|
+
* `Revive.call`'s `weight_limit` parameter.
|
|
282
|
+
*
|
|
283
|
+
* On failure, `value` carries the raw dispatch-error payload the runtime
|
|
284
|
+
* returned (typically a tagged enum like `{ type: "Module", value: ... }`,
|
|
285
|
+
* `{ type: "ContractReverted" }`, or `{ type: "AccountNotMapped" }` — see the
|
|
286
|
+
* `Revive` pallet error variants). Surfacing it lets callers narrow on shape
|
|
287
|
+
* to diagnose silent failures instead of seeing `undefined` and being unable
|
|
288
|
+
* to tell whether the contract reverted, gas estimation failed, or the
|
|
289
|
+
* dry-run never ran. `gasRequired` is still populated when the runtime
|
|
290
|
+
* reported a weight even though the call ultimately failed (e.g. a revert
|
|
291
|
+
* after partial execution); it's optional because some failure modes don't
|
|
292
|
+
* carry one.
|
|
293
|
+
*/
|
|
294
|
+
type QueryResult<T> = {
|
|
295
|
+
success: true;
|
|
296
|
+
value: T;
|
|
297
|
+
gasRequired: Weight;
|
|
298
|
+
} | {
|
|
299
|
+
success: false;
|
|
300
|
+
value: unknown;
|
|
301
|
+
gasRequired?: Weight;
|
|
302
|
+
};
|
|
303
|
+
/** Options for query calls — passed as the last argument after positional args. */
|
|
304
|
+
interface QueryOptions {
|
|
305
|
+
origin?: SS58String;
|
|
306
|
+
value?: bigint;
|
|
307
|
+
/**
|
|
308
|
+
* Override the block targeted by this dry-run. Accepts `"best"`,
|
|
309
|
+
* `"finalized"`, or a block hash. Defaults to the runtime's configured
|
|
310
|
+
* `at` (see `createContractRuntimeFromClient({ at })`), which is `"best"`
|
|
311
|
+
* unless overridden — chosen so `.query()` observes the same state as
|
|
312
|
+
* `.tx()` resolved at best-block.
|
|
313
|
+
*/
|
|
314
|
+
at?: ContractDryRunAt;
|
|
315
|
+
}
|
|
316
|
+
/** Options for transaction calls — passed as the last argument after positional args. */
|
|
317
|
+
interface TxOptions extends SubmitOptions {
|
|
318
|
+
signer?: PolkadotSigner;
|
|
319
|
+
origin?: SS58String;
|
|
320
|
+
value?: bigint;
|
|
321
|
+
gasLimit?: Weight;
|
|
322
|
+
storageDepositLimit?: bigint;
|
|
323
|
+
/**
|
|
324
|
+
* Override the block targeted by the sizing dry-run that `.tx()` runs
|
|
325
|
+
* before submission. Accepts `"best"`, `"finalized"`, or a block hash.
|
|
326
|
+
* Defaults to the runtime's configured `at` (see
|
|
327
|
+
* `createContractRuntimeFromClient({ at })`), which is `"best"` unless
|
|
328
|
+
* overridden. No-op when both `gasLimit` and `storageDepositLimit` are
|
|
329
|
+
* passed — the dry-run is skipped entirely in that case.
|
|
330
|
+
*/
|
|
331
|
+
at?: ContractDryRunAt;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Options for `.prepare()` — subset of {@link TxOptions}.
|
|
335
|
+
*
|
|
336
|
+
* Signer and submission lifecycle options (`signer`, `waitFor`, `timeoutMs`,
|
|
337
|
+
* `mortalityPeriod`, `onStatus`) are intentionally absent — those belong to
|
|
338
|
+
* the batch submission, not the individual prepared call.
|
|
339
|
+
*/
|
|
340
|
+
interface PrepareOptions {
|
|
341
|
+
origin?: SS58String;
|
|
342
|
+
value?: bigint;
|
|
343
|
+
gasLimit?: Weight;
|
|
344
|
+
storageDepositLimit?: bigint;
|
|
345
|
+
/**
|
|
346
|
+
* Override the block targeted by the sizing dry-run. See
|
|
347
|
+
* {@link TxOptions.at}.
|
|
348
|
+
*/
|
|
349
|
+
at?: ContractDryRunAt;
|
|
350
|
+
}
|
|
351
|
+
/** Mutable defaults shared across all contract handles from a manager. */
|
|
352
|
+
interface ContractDefaults {
|
|
353
|
+
origin?: SS58String;
|
|
354
|
+
signer?: PolkadotSigner;
|
|
355
|
+
signerManager?: SignerManager;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Options for {@link createContract} and base for {@link ContractManagerOptions}.
|
|
359
|
+
*
|
|
360
|
+
* Signer resolution order (highest wins):
|
|
361
|
+
* 1. Explicit override in call options
|
|
362
|
+
* 2. `signerManager` (current logged-in account)
|
|
363
|
+
* 3. Static `defaultSigner` / `defaultOrigin`
|
|
364
|
+
*/
|
|
365
|
+
interface ContractOptions {
|
|
366
|
+
/**
|
|
367
|
+
* Signer manager from `@parity/product-sdk-signer`. When provided, the
|
|
368
|
+
* currently selected account is used as the default signer and origin
|
|
369
|
+
* for all contract interactions. Resolved at call time so account
|
|
370
|
+
* switches are reflected immediately.
|
|
371
|
+
*/
|
|
372
|
+
signerManager?: SignerManager;
|
|
373
|
+
/** Static fallback caller address for queries. */
|
|
374
|
+
defaultOrigin?: SS58String;
|
|
375
|
+
/** Static fallback signer for transactions. */
|
|
376
|
+
defaultSigner?: PolkadotSigner;
|
|
377
|
+
}
|
|
378
|
+
/** Options for {@link ContractManager} construction. */
|
|
379
|
+
interface ContractManagerOptions extends ContractOptions {
|
|
380
|
+
/** Explicit target hash to select from cdm.json. Defaults to the first target. */
|
|
381
|
+
targetHash?: string;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* A typed contract handle where each ABI method exposes `.query()` and `.tx()`.
|
|
385
|
+
*
|
|
386
|
+
* Both accept the method's positional arguments followed by an optional
|
|
387
|
+
* options object as the last argument.
|
|
388
|
+
*/
|
|
389
|
+
type Contract<C extends ContractDef> = {
|
|
390
|
+
[K in keyof C["methods"]]: {
|
|
391
|
+
/**
|
|
392
|
+
* Dry-run the method (read-only). Does not submit a transaction or
|
|
393
|
+
* cost gas. Returns the decoded response and estimated gas required.
|
|
394
|
+
*
|
|
395
|
+
* Origin is resolved from: explicit `{ origin }` option → signerManager →
|
|
396
|
+
* defaultOrigin → dev fallback (Alice).
|
|
397
|
+
*/
|
|
398
|
+
query: (...args: [...C["methods"][K]["args"], opts?: QueryOptions]) => Promise<QueryResult<C["methods"][K]["response"]>>;
|
|
399
|
+
/**
|
|
400
|
+
* Sign, submit, and watch the method as an on-chain transaction.
|
|
401
|
+
* Resolves at best-block by default (configurable via `waitFor`).
|
|
402
|
+
*
|
|
403
|
+
* Signer is resolved from: explicit `{ signer }` option → signerManager →
|
|
404
|
+
* defaultSigner. Throws {@link ContractSignerMissingError} if none available.
|
|
405
|
+
*/
|
|
406
|
+
tx: (...args: [...C["methods"][K]["args"], opts?: TxOptions]) => Promise<TxResult>;
|
|
407
|
+
/**
|
|
408
|
+
* Prepare the method as a {@link BatchableCall} — returns the same
|
|
409
|
+
* submittable that `.tx()` would build, but without signing or
|
|
410
|
+
* submitting. Consumable directly by `batchSubmitAndWatch` from
|
|
411
|
+
* `@parity/product-sdk-tx`:
|
|
412
|
+
*
|
|
413
|
+
* ```ts
|
|
414
|
+
* import { batchSubmitAndWatch } from "@parity/product-sdk-tx";
|
|
415
|
+
*
|
|
416
|
+
* const a = contract.transfer.prepare(addr1, 100n);
|
|
417
|
+
* const b = contract.transfer.prepare(addr2, 200n);
|
|
418
|
+
* await batchSubmitAndWatch([a, b], api, signer);
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* Sizing: when either `gasLimit` or `storageDepositLimit` is
|
|
422
|
+
* omitted, `.prepare()` runs a `ReviveApi.call` dry-run (same as
|
|
423
|
+
* `.tx()`) against the dev fallback origin to fill the missing
|
|
424
|
+
* field(s) — pass both to skip the dry-run entirely. A failing
|
|
425
|
+
* dry-run throws {@link ContractDryRunFailedError} before the
|
|
426
|
+
* call is constructed.
|
|
427
|
+
*
|
|
428
|
+
* `.prepare()` does not require a signer; the batch's signer
|
|
429
|
+
* replaces the dispatched origin at submission.
|
|
430
|
+
*/
|
|
431
|
+
prepare: (...args: [...C["methods"][K]["args"], opts?: PrepareOptions]) => Promise<BatchableCall>;
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
export { type AbiEntry as A, type CdmJson as C, type PrepareOptions as P, type QueryOptions as Q, type ReviveDryRunCall as R, type TxOptions as T, type ContractRuntime as a, type ContractManagerOptions as b, type ContractDefaults as c, type ContractRuntimeOptions as d, type Contracts as e, type Contract as f, type ContractDef as g, type ContractOptions as h, type AbiParam as i, type CdmJsonContract as j, type CdmJsonTarget as k, type ContractDryRunAt as l, type QueryResult as m, type ReviveDryRunCallOptions as n, type ReviveDryRunResult as o, type ReviveTypedApi as p, createContractRuntime as q, createContractRuntimeFromClient as r, ensureContractAccountMapped as s };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parity/product-sdk-contracts",
|
|
3
3
|
"description": "Typed contract interactions on Polkadot Asset Hub",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"polkadot-api": "^2.1.2",
|
|
32
32
|
"viem": "^2.46.2",
|
|
33
33
|
"@parity/product-sdk-address": "0.1.1",
|
|
34
|
-
"@parity/product-sdk-keys": "0.
|
|
34
|
+
"@parity/product-sdk-keys": "0.3.1",
|
|
35
35
|
"@parity/product-sdk-logger": "0.1.1",
|
|
36
|
-
"@parity/product-sdk-signer": "0.
|
|
37
|
-
"@parity/product-sdk-tx": "0.2.
|
|
36
|
+
"@parity/product-sdk-signer": "0.4.0",
|
|
37
|
+
"@parity/product-sdk-tx": "0.2.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsup": "^8.4.0",
|
package/dist/types-BdHp-xWt.d.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { HexString, SS58String, PolkadotSigner } from 'polkadot-api';
|
|
2
|
-
import { Weight, SubmitOptions, TxResult, BatchableCall } from '@parity/product-sdk-tx';
|
|
3
|
-
import { SignerManager } from '@parity/product-sdk-signer';
|
|
4
|
-
|
|
5
|
-
/** Pins a target to specific asset-hub and Bulletin chain hashes in `cdm.json`. */
|
|
6
|
-
interface CdmJsonTarget {
|
|
7
|
-
"asset-hub": string;
|
|
8
|
-
bulletin: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A deployed contract's on-chain address, ABI, and optional metadata CID.
|
|
12
|
-
*
|
|
13
|
-
* `metadataCid` is optional because real-world cdm.json files (e.g.
|
|
14
|
-
* `paritytech/playground-cli/cdm.json`) don't always include it — only
|
|
15
|
-
* `version`, `address`, and `abi` are load-bearing for `getContract()`.
|
|
16
|
-
*/
|
|
17
|
-
interface CdmJsonContract {
|
|
18
|
-
version: number;
|
|
19
|
-
address: HexString;
|
|
20
|
-
abi: AbiEntry[];
|
|
21
|
-
metadataCid?: string;
|
|
22
|
-
}
|
|
23
|
-
/** A project's `cdm.json` manifest: declared targets, runtime dependencies, and per-target contract deployments. */
|
|
24
|
-
interface CdmJson {
|
|
25
|
-
targets: Record<string, CdmJsonTarget>;
|
|
26
|
-
dependencies: Record<string, Record<string, number | string>>;
|
|
27
|
-
contracts?: Record<string, Record<string, CdmJsonContract>>;
|
|
28
|
-
}
|
|
29
|
-
/** An ABI parameter or return value, with support for nested tuple and struct types. */
|
|
30
|
-
interface AbiParam {
|
|
31
|
-
name: string;
|
|
32
|
-
type: string;
|
|
33
|
-
components?: AbiParam[];
|
|
34
|
-
}
|
|
35
|
-
/** One function, constructor, or event in a contract's ABI. */
|
|
36
|
-
interface AbiEntry {
|
|
37
|
-
type: string;
|
|
38
|
-
name?: string;
|
|
39
|
-
inputs: AbiParam[];
|
|
40
|
-
outputs?: AbiParam[];
|
|
41
|
-
stateMutability?: string;
|
|
42
|
-
}
|
|
43
|
-
/** Per-contract definition shape — generated into `.cdm/contracts.d.ts` via module augmentation. */
|
|
44
|
-
interface ContractDef {
|
|
45
|
-
methods: Record<string, {
|
|
46
|
-
args: any[];
|
|
47
|
-
response: any;
|
|
48
|
-
}>;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Augmentable interface extended by codegen with per-contract method types.
|
|
52
|
-
*
|
|
53
|
-
* After running `cdm install`, a generated `.d.ts` file augments this
|
|
54
|
-
* interface so that `ContractManager.getContract()` returns fully-typed
|
|
55
|
-
* contract handles.
|
|
56
|
-
*/
|
|
57
|
-
interface Contracts {
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Result from a read-only contract query.
|
|
61
|
-
*
|
|
62
|
-
* On success, `value` is the decoded response and `gasRequired` is the
|
|
63
|
-
* `Weight` consumed by `ReviveApi.call`'s dry-run — consumable directly by
|
|
64
|
-
* `Revive.call`'s `weight_limit` parameter.
|
|
65
|
-
*
|
|
66
|
-
* On failure, `value` carries the raw dispatch-error payload the runtime
|
|
67
|
-
* returned (typically a tagged enum like `{ type: "Module", value: ... }`,
|
|
68
|
-
* `{ type: "ContractReverted" }`, or `{ type: "AccountNotMapped" }` — see the
|
|
69
|
-
* `Revive` pallet error variants). Surfacing it lets callers narrow on shape
|
|
70
|
-
* to diagnose silent failures instead of seeing `undefined` and being unable
|
|
71
|
-
* to tell whether the contract reverted, gas estimation failed, or the
|
|
72
|
-
* dry-run never ran. `gasRequired` is still populated when the runtime
|
|
73
|
-
* reported a weight even though the call ultimately failed (e.g. a revert
|
|
74
|
-
* after partial execution); it's optional because some failure modes don't
|
|
75
|
-
* carry one.
|
|
76
|
-
*/
|
|
77
|
-
type QueryResult<T> = {
|
|
78
|
-
success: true;
|
|
79
|
-
value: T;
|
|
80
|
-
gasRequired: Weight;
|
|
81
|
-
} | {
|
|
82
|
-
success: false;
|
|
83
|
-
value: unknown;
|
|
84
|
-
gasRequired?: Weight;
|
|
85
|
-
};
|
|
86
|
-
/** Options for query calls — passed as the last argument after positional args. */
|
|
87
|
-
interface QueryOptions {
|
|
88
|
-
origin?: SS58String;
|
|
89
|
-
value?: bigint;
|
|
90
|
-
}
|
|
91
|
-
/** Options for transaction calls — passed as the last argument after positional args. */
|
|
92
|
-
interface TxOptions extends SubmitOptions {
|
|
93
|
-
signer?: PolkadotSigner;
|
|
94
|
-
origin?: SS58String;
|
|
95
|
-
value?: bigint;
|
|
96
|
-
gasLimit?: Weight;
|
|
97
|
-
storageDepositLimit?: bigint;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Options for `.prepare()` — subset of {@link TxOptions}.
|
|
101
|
-
*
|
|
102
|
-
* Signer and submission lifecycle options (`signer`, `waitFor`, `timeoutMs`,
|
|
103
|
-
* `mortalityPeriod`, `onStatus`) are intentionally absent — those belong to
|
|
104
|
-
* the batch submission, not the individual prepared call.
|
|
105
|
-
*/
|
|
106
|
-
interface PrepareOptions {
|
|
107
|
-
origin?: SS58String;
|
|
108
|
-
value?: bigint;
|
|
109
|
-
gasLimit?: Weight;
|
|
110
|
-
storageDepositLimit?: bigint;
|
|
111
|
-
}
|
|
112
|
-
/** Mutable defaults shared across all contract handles from a manager. */
|
|
113
|
-
interface ContractDefaults {
|
|
114
|
-
origin?: SS58String;
|
|
115
|
-
signer?: PolkadotSigner;
|
|
116
|
-
signerManager?: SignerManager;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Options for {@link createContract} and base for {@link ContractManagerOptions}.
|
|
120
|
-
*
|
|
121
|
-
* Signer resolution order (highest wins):
|
|
122
|
-
* 1. Explicit override in call options
|
|
123
|
-
* 2. `signerManager` (current logged-in account)
|
|
124
|
-
* 3. Static `defaultSigner` / `defaultOrigin`
|
|
125
|
-
*/
|
|
126
|
-
interface ContractOptions {
|
|
127
|
-
/**
|
|
128
|
-
* Signer manager from `@parity/product-sdk-signer`. When provided, the
|
|
129
|
-
* currently selected account is used as the default signer and origin
|
|
130
|
-
* for all contract interactions. Resolved at call time so account
|
|
131
|
-
* switches are reflected immediately.
|
|
132
|
-
*/
|
|
133
|
-
signerManager?: SignerManager;
|
|
134
|
-
/** Static fallback caller address for queries. */
|
|
135
|
-
defaultOrigin?: SS58String;
|
|
136
|
-
/** Static fallback signer for transactions. */
|
|
137
|
-
defaultSigner?: PolkadotSigner;
|
|
138
|
-
}
|
|
139
|
-
/** Options for {@link ContractManager} construction. */
|
|
140
|
-
interface ContractManagerOptions extends ContractOptions {
|
|
141
|
-
/** Explicit target hash to select from cdm.json. Defaults to the first target. */
|
|
142
|
-
targetHash?: string;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* A typed contract handle where each ABI method exposes `.query()` and `.tx()`.
|
|
146
|
-
*
|
|
147
|
-
* Both accept the method's positional arguments followed by an optional
|
|
148
|
-
* options object as the last argument.
|
|
149
|
-
*/
|
|
150
|
-
type Contract<C extends ContractDef> = {
|
|
151
|
-
[K in keyof C["methods"]]: {
|
|
152
|
-
/**
|
|
153
|
-
* Dry-run the method (read-only). Does not submit a transaction or
|
|
154
|
-
* cost gas. Returns the decoded response and estimated gas required.
|
|
155
|
-
*
|
|
156
|
-
* Origin is resolved from: explicit `{ origin }` option → signerManager →
|
|
157
|
-
* defaultOrigin → dev fallback (Alice).
|
|
158
|
-
*/
|
|
159
|
-
query: (...args: [...C["methods"][K]["args"], opts?: QueryOptions]) => Promise<QueryResult<C["methods"][K]["response"]>>;
|
|
160
|
-
/**
|
|
161
|
-
* Sign, submit, and watch the method as an on-chain transaction.
|
|
162
|
-
* Resolves at best-block by default (configurable via `waitFor`).
|
|
163
|
-
*
|
|
164
|
-
* Signer is resolved from: explicit `{ signer }` option → signerManager →
|
|
165
|
-
* defaultSigner. Throws {@link ContractSignerMissingError} if none available.
|
|
166
|
-
*/
|
|
167
|
-
tx: (...args: [...C["methods"][K]["args"], opts?: TxOptions]) => Promise<TxResult>;
|
|
168
|
-
/**
|
|
169
|
-
* Prepare the method as a {@link BatchableCall} — returns the same
|
|
170
|
-
* submittable that `.tx()` would build, but without signing or
|
|
171
|
-
* submitting. Consumable directly by `batchSubmitAndWatch` from
|
|
172
|
-
* `@parity/product-sdk-tx`:
|
|
173
|
-
*
|
|
174
|
-
* ```ts
|
|
175
|
-
* import { batchSubmitAndWatch } from "@parity/product-sdk-tx";
|
|
176
|
-
*
|
|
177
|
-
* const a = contract.transfer.prepare(addr1, 100n);
|
|
178
|
-
* const b = contract.transfer.prepare(addr2, 200n);
|
|
179
|
-
* await batchSubmitAndWatch([a, b], api, signer);
|
|
180
|
-
* ```
|
|
181
|
-
*
|
|
182
|
-
* Sizing: when either `gasLimit` or `storageDepositLimit` is
|
|
183
|
-
* omitted, `.prepare()` runs a `ReviveApi.call` dry-run (same as
|
|
184
|
-
* `.tx()`) against the dev fallback origin to fill the missing
|
|
185
|
-
* field(s) — pass both to skip the dry-run entirely. A failing
|
|
186
|
-
* dry-run throws {@link ContractDryRunFailedError} before the
|
|
187
|
-
* call is constructed.
|
|
188
|
-
*
|
|
189
|
-
* `.prepare()` does not require a signer; the batch's signer
|
|
190
|
-
* replaces the dispatched origin at submission.
|
|
191
|
-
*/
|
|
192
|
-
prepare: (...args: [...C["methods"][K]["args"], opts?: PrepareOptions]) => Promise<BatchableCall>;
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
export type { AbiEntry as A, CdmJson as C, PrepareOptions as P, QueryOptions as Q, TxOptions as T, ContractManagerOptions as a, ContractDefaults as b, Contracts as c, Contract as d, ContractDef as e, ContractOptions as f, AbiParam as g, CdmJsonContract as h, CdmJsonTarget as i, QueryResult as j };
|