@parity/product-sdk-contracts 0.5.1 → 0.6.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.
@@ -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 };