@parity/product-sdk-contracts 0.8.3 → 0.9.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/dist/codegen.d.ts +5 -3
- package/dist/index.d.ts +15 -74
- package/dist/index.js +58 -42
- package/dist/index.js.map +1 -1
- package/dist/pvm.d.ts +5 -3
- package/dist/testing.d.ts +85 -0
- package/dist/testing.js +99 -0
- package/dist/testing.js.map +1 -0
- package/dist/{types-pkS1R9Bk.d.ts → types-BKcrGoiN.d.ts} +91 -9
- package/package.json +12 -5
package/dist/codegen.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { A as AbiEntry } from './types-
|
|
2
|
-
import '
|
|
3
|
-
import '@parity/product-sdk-tx';
|
|
1
|
+
import { A as AbiEntry } from './types-BKcrGoiN.js';
|
|
2
|
+
import '@parity/result';
|
|
4
3
|
import '@parity/product-sdk-signer';
|
|
4
|
+
import '@parity/product-sdk-tx';
|
|
5
|
+
import 'polkadot-api';
|
|
6
|
+
import '@parity/product-sdk-errors';
|
|
5
7
|
|
|
6
8
|
/** A contract input to {@link generateContractTypes}: either an inline ABI or a `cargo-pvm-contract` artefact path. */
|
|
7
9
|
type ContractTypeInput = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
import { Result } from '@parity/result';
|
|
1
2
|
import { PolkadotClient, HexString, SS58String } from 'polkadot-api';
|
|
2
|
-
import { C as CdmJson, a as ContractRuntime, b as ContractManagerOptions, c as ContractDefaults, d as ContractRuntimeOptions, L as LiveContractResolutionOptions, e as
|
|
3
|
-
export {
|
|
3
|
+
import { C as CdmJson, a as ContractRuntime, b as ContractManagerOptions, c as ContractDefaults, d as ContractRuntimeOptions, L as LiveContractResolutionOptions, e as ContractError, f as Contracts, g as Contract, h as ContractDef, A as AbiEntry, i as ContractOptions } from './types-BKcrGoiN.js';
|
|
4
|
+
export { j as AbiParam, k as CdmJsonContract, l as CdmJsonDependencyVersion, m as ContractDryRunAt, n as ContractDryRunFailedError, o as ContractLiveAddressResolutionError, p as ContractNotFoundError, q as ContractRevertInfo, r as ContractRevertedError, s as ContractSignerMissingError, D as DecodedContractRevert, P as PrepareOptions, Q as QueryOptions, t as QueryResult, R as ReviveDryRunCall, u as ReviveDryRunCallOptions, v as ReviveDryRunResult, w as ReviveTypedApi, T as TxOptions, x as createContractRuntime, y as createContractRuntimeFromClient, z as ensureContractAccountMapped } from './types-BKcrGoiN.js';
|
|
4
5
|
export { BatchableCall, TxResult } from '@parity/product-sdk-tx';
|
|
5
6
|
import '@parity/product-sdk-signer';
|
|
7
|
+
import '@parity/product-sdk-errors';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Return a cloned manifest whose installed contract addresses have been
|
|
9
11
|
* replaced by live addresses from the CDM registry.
|
|
10
12
|
*
|
|
11
|
-
* This is intentionally strict: if a requested library cannot be resolved
|
|
12
|
-
*
|
|
13
|
+
* This is intentionally strict: if a requested library cannot be resolved from
|
|
14
|
+
* the registry, the result is `err`. Use `new ContractManager(...)` or
|
|
13
15
|
* `ContractManager.fromClient(...)` directly for snapshot-only behavior.
|
|
16
|
+
*
|
|
17
|
+
* @returns A {@link Result}: `ok(CdmJson)` with live addresses patched in, or
|
|
18
|
+
* `err(ContractError)` — a `ContractLiveAddressResolutionError` (missing
|
|
19
|
+
* contracts, no registry, or a lookup that failed / returned nothing) or a
|
|
20
|
+
* `ContractNotFoundError` (a requested library isn't installed).
|
|
14
21
|
*/
|
|
15
|
-
declare function withLiveContractAddresses(cdmJson: CdmJson, runtime: ContractRuntime, options?: LiveContractResolutionOptions): Promise<CdmJson
|
|
22
|
+
declare function withLiveContractAddresses(cdmJson: CdmJson, runtime: ContractRuntime, options?: LiveContractResolutionOptions): Promise<Result<CdmJson, ContractError>>;
|
|
16
23
|
/**
|
|
17
24
|
* Manages typed contract interactions backed by a `cdm.json` manifest.
|
|
18
25
|
*
|
|
@@ -65,12 +72,12 @@ declare class ContractManager {
|
|
|
65
72
|
* Create a manager after strictly resolving installed contract addresses
|
|
66
73
|
* from the live CDM registry. ABIs still come from the installed manifest.
|
|
67
74
|
*/
|
|
68
|
-
static fromLive(cdmJson: CdmJson, runtime: ContractRuntime, options?: ContractManagerOptions & LiveContractResolutionOptions): Promise<ContractManager
|
|
75
|
+
static fromLive(cdmJson: CdmJson, runtime: ContractRuntime, options?: ContractManagerOptions & LiveContractResolutionOptions): Promise<Result<ContractManager, ContractError>>;
|
|
69
76
|
/**
|
|
70
77
|
* Convenience factory for {@link fromLive} when the caller has a raw
|
|
71
78
|
* `PolkadotClient` and descriptor.
|
|
72
79
|
*/
|
|
73
|
-
static fromLiveClient<TDescriptor>(cdmJson: CdmJson, client: PolkadotClient, descriptor: TDescriptor, options?: ContractManagerOptions & ContractRuntimeOptions & LiveContractResolutionOptions): Promise<ContractManager
|
|
80
|
+
static fromLiveClient<TDescriptor>(cdmJson: CdmJson, client: PolkadotClient, descriptor: TDescriptor, options?: ContractManagerOptions & ContractRuntimeOptions & LiveContractResolutionOptions): Promise<Result<ContractManager, ContractError>>;
|
|
74
81
|
private getContractData;
|
|
75
82
|
/**
|
|
76
83
|
* Get a typed contract handle.
|
|
@@ -125,70 +132,4 @@ declare function createContractFromClient<TDescriptor>(client: PolkadotClient, d
|
|
|
125
132
|
|
|
126
133
|
declare const QUERY_FALLBACK_ORIGIN: SS58String;
|
|
127
134
|
|
|
128
|
-
|
|
129
|
-
declare class ContractError extends Error {
|
|
130
|
-
constructor(message: string, options?: ErrorOptions);
|
|
131
|
-
}
|
|
132
|
-
/** No signer was available for a transaction call. */
|
|
133
|
-
declare class ContractSignerMissingError extends ContractError {
|
|
134
|
-
constructor();
|
|
135
|
-
}
|
|
136
|
-
/** A contract was not found in the cdm.json manifest. */
|
|
137
|
-
declare class ContractNotFoundError extends ContractError {
|
|
138
|
-
readonly library: string;
|
|
139
|
-
constructor(library: string);
|
|
140
|
-
}
|
|
141
|
-
/** Live CDM registry address resolution failed. */
|
|
142
|
-
declare class ContractLiveAddressResolutionError extends ContractError {
|
|
143
|
-
readonly library: string | undefined;
|
|
144
|
-
readonly detail: unknown;
|
|
145
|
-
constructor(message: string, options?: {
|
|
146
|
-
library?: string;
|
|
147
|
-
detail?: unknown;
|
|
148
|
-
cause?: unknown;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* A pre-flight `ReviveApi.call` dry-run reported failure. Thrown from the `.tx()`
|
|
153
|
-
* path before the extrinsic is built — prevents callers from paying gas on a
|
|
154
|
-
* transaction the chain already told us would revert.
|
|
155
|
-
*
|
|
156
|
-
* `dispatchError` carries the chain's encoded error (typically `ModuleError`,
|
|
157
|
-
* `ContractReverted`, `OutOfGas`, or `AccountNotMapped` — see the `Revive`
|
|
158
|
-
* pallet error variants).
|
|
159
|
-
*/
|
|
160
|
-
declare class ContractDryRunFailedError extends ContractError {
|
|
161
|
-
readonly methodName: string;
|
|
162
|
-
readonly dispatchError: unknown;
|
|
163
|
-
constructor(methodName: string, dispatchError: unknown);
|
|
164
|
-
}
|
|
165
|
-
/** viem-decoded standard or ABI-defined contract error. */
|
|
166
|
-
interface DecodedContractRevert {
|
|
167
|
-
errorName: string;
|
|
168
|
-
args: readonly unknown[] | undefined;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Tagged-enum value surfaced on `QueryResult.value` when a contract reverts
|
|
172
|
-
* via the REVERT flag. The discriminant is intentionally distinct from
|
|
173
|
-
* `pallet-revive`'s bare `{ type: "ContractReverted" }` dispatch-error variant,
|
|
174
|
-
* which is the other path that can populate `QueryResult.value` on failure.
|
|
175
|
-
*/
|
|
176
|
-
interface ContractRevertInfo {
|
|
177
|
-
type: "ContractRevertedWithPayload";
|
|
178
|
-
data: HexString;
|
|
179
|
-
reason?: string;
|
|
180
|
-
decoded?: DecodedContractRevert;
|
|
181
|
-
}
|
|
182
|
-
/** A contract call returned with the `REVERT` flag set on a dispatched-OK call. */
|
|
183
|
-
declare class ContractRevertedError extends ContractError {
|
|
184
|
-
readonly methodName: string;
|
|
185
|
-
readonly data: HexString;
|
|
186
|
-
readonly reason?: string;
|
|
187
|
-
readonly decoded?: DecodedContractRevert;
|
|
188
|
-
constructor(methodName: string, data: HexString, info?: {
|
|
189
|
-
reason?: string;
|
|
190
|
-
decoded?: DecodedContractRevert;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export { AbiEntry, CdmJson, Contract, ContractDef, ContractDefaults, ContractDryRunFailedError, ContractError, ContractLiveAddressResolutionError, ContractManager, ContractManagerOptions, ContractNotFoundError, ContractOptions, type ContractRevertInfo, ContractRevertedError, ContractRuntime, ContractRuntimeOptions, ContractSignerMissingError, Contracts, type DecodedContractRevert, LiveContractResolutionOptions, QUERY_FALLBACK_ORIGIN, createContract, createContractFromClient, withLiveContractAddresses };
|
|
135
|
+
export { AbiEntry, CdmJson, Contract, ContractDef, ContractDefaults, ContractError, ContractManager, ContractManagerOptions, ContractOptions, ContractRuntime, ContractRuntimeOptions, Contracts, LiveContractResolutionOptions, QUERY_FALLBACK_ORIGIN, createContract, createContractFromClient, withLiveContractAddresses };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ensureAccountMapped, submitAndWatch } from '@parity/product-sdk-tx';
|
|
1
|
+
import { ok, err } from '@parity/result';
|
|
3
2
|
import { createLogger } from '@parity/product-sdk-logger';
|
|
3
|
+
import { ensureAccountMapped, submitAndWatch } from '@parity/product-sdk-tx';
|
|
4
4
|
import { ss58Address } from '@polkadot-labs/hdkd-helpers';
|
|
5
|
+
import { encodeFunctionData, bytesToHex, decodeErrorResult, decodeFunctionResult } from 'viem';
|
|
5
6
|
import { ss58ToH160 } from '@parity/product-sdk-address';
|
|
6
7
|
|
|
7
|
-
// src/
|
|
8
|
+
// src/manager.ts
|
|
8
9
|
|
|
9
10
|
// src/errors.ts
|
|
10
11
|
var ContractError = class extends Error {
|
|
12
|
+
isSdkError = true;
|
|
13
|
+
source = "contracts";
|
|
11
14
|
constructor(message, options) {
|
|
12
15
|
super(message, options);
|
|
13
16
|
this.name = "ContractError";
|
|
@@ -72,8 +75,6 @@ var ContractRevertedError = class extends ContractError {
|
|
|
72
75
|
this.decoded = info?.decoded;
|
|
73
76
|
}
|
|
74
77
|
};
|
|
75
|
-
|
|
76
|
-
// src/wrap.ts
|
|
77
78
|
var log = createLogger("contracts");
|
|
78
79
|
function buildMethodArgMap(abi) {
|
|
79
80
|
const map = {};
|
|
@@ -207,25 +208,27 @@ async function buildReviveCall(runtime, dest, abi, methodName, positionalArgs, o
|
|
|
207
208
|
overrides?.at !== void 0 ? { at: overrides.at } : void 0
|
|
208
209
|
);
|
|
209
210
|
if (!dryRun.result.success) {
|
|
210
|
-
|
|
211
|
+
return err(new ContractDryRunFailedError(methodName, dryRun.result.value));
|
|
211
212
|
}
|
|
212
213
|
if ((dryRun.result.value.flags & REVERT_FLAG) !== 0) {
|
|
213
214
|
const { data, reason, decoded } = decodeRevert(abi, dryRun.result.value.data);
|
|
214
215
|
log.debug("Contract reverted", { methodName, reason, errorName: decoded?.errorName });
|
|
215
|
-
|
|
216
|
+
return err(new ContractRevertedError(methodName, data, { reason, decoded }));
|
|
216
217
|
}
|
|
217
218
|
weightLimit = weightLimit ?? dryRun.weight_required;
|
|
218
219
|
if (storageDepositLimit === void 0) {
|
|
219
220
|
storageDepositLimit = dryRun.storage_deposit.type === "Charge" ? dryRun.storage_deposit.value : 0n;
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
return ok(
|
|
224
|
+
runtime.api.tx.Revive.call({
|
|
225
|
+
dest,
|
|
226
|
+
value,
|
|
227
|
+
weight_limit: weightLimit,
|
|
228
|
+
storage_deposit_limit: storageDepositLimit,
|
|
229
|
+
data: calldata
|
|
230
|
+
})
|
|
231
|
+
);
|
|
229
232
|
}
|
|
230
233
|
function wrapContract(runtime, address, abi, defaults) {
|
|
231
234
|
const methodArgs = buildMethodArgMap(abi);
|
|
@@ -287,10 +290,10 @@ function wrapContract(runtime, address, abi, defaults) {
|
|
|
287
290
|
);
|
|
288
291
|
const signer = resolveSigner(defaults, overrides?.signer);
|
|
289
292
|
if (!signer) {
|
|
290
|
-
|
|
293
|
+
return err(new ContractSignerMissingError());
|
|
291
294
|
}
|
|
292
295
|
const origin = resolveOrigin(defaults, overrides?.origin) ?? ss58Address(signer.publicKey);
|
|
293
|
-
const
|
|
296
|
+
const built = await buildReviveCall(
|
|
294
297
|
runtime,
|
|
295
298
|
dest,
|
|
296
299
|
abi,
|
|
@@ -299,7 +302,8 @@ function wrapContract(runtime, address, abi, defaults) {
|
|
|
299
302
|
origin,
|
|
300
303
|
overrides
|
|
301
304
|
);
|
|
302
|
-
|
|
305
|
+
if (!built.ok) return built;
|
|
306
|
+
return submitAndWatch(built.value, signer, {
|
|
303
307
|
waitFor: overrides?.waitFor,
|
|
304
308
|
timeoutMs: overrides?.timeoutMs,
|
|
305
309
|
mortalityPeriod: overrides?.mortalityPeriod,
|
|
@@ -450,33 +454,44 @@ async function queryLiveAddress(registry, library, version) {
|
|
|
450
454
|
return value.value;
|
|
451
455
|
}
|
|
452
456
|
async function withLiveContractAddresses(cdmJson, runtime, options) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
try {
|
|
458
|
+
const contracts = cdmJson.contracts;
|
|
459
|
+
if (!contracts || Object.keys(contracts).length === 0) {
|
|
460
|
+
throw new ContractLiveAddressResolutionError(
|
|
461
|
+
"No installed contracts found in cdm.json for live address resolution."
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
const libraries = options?.libraries ?? Object.keys(contracts);
|
|
465
|
+
for (const library of libraries) {
|
|
466
|
+
if (!(library in contracts)) {
|
|
467
|
+
throw new ContractNotFoundError(library);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const registryAddress = resolveRegistryAddress(cdmJson, options?.registryAddress);
|
|
471
|
+
const registry = createContract(runtime, registryAddress, CDM_REGISTRY_ABI, {
|
|
472
|
+
defaultOrigin: options?.registryOrigin
|
|
473
|
+
});
|
|
474
|
+
const liveAddresses = await Promise.all(
|
|
475
|
+
libraries.map(async (library) => {
|
|
476
|
+
const version = resolveLiveVersionSpec(cdmJson, library, contracts[library]);
|
|
477
|
+
return [library, await queryLiveAddress(registry, library, version)];
|
|
478
|
+
})
|
|
457
479
|
);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (!(library in contracts)) {
|
|
462
|
-
throw new ContractNotFoundError(library);
|
|
480
|
+
const resolved = cloneCdmJson(cdmJson);
|
|
481
|
+
for (const [library, address] of liveAddresses) {
|
|
482
|
+
patchContractAddress(resolved, library, address);
|
|
463
483
|
}
|
|
484
|
+
return ok(resolved);
|
|
485
|
+
} catch (cause) {
|
|
486
|
+
if (cause instanceof ContractError) return err(cause);
|
|
487
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
488
|
+
return err(
|
|
489
|
+
new ContractLiveAddressResolutionError(
|
|
490
|
+
`Live contract address resolution failed: ${message}`,
|
|
491
|
+
{ cause }
|
|
492
|
+
)
|
|
493
|
+
);
|
|
464
494
|
}
|
|
465
|
-
const registryAddress = resolveRegistryAddress(cdmJson, options?.registryAddress);
|
|
466
|
-
const registry = createContract(runtime, registryAddress, CDM_REGISTRY_ABI, {
|
|
467
|
-
defaultOrigin: options?.registryOrigin
|
|
468
|
-
});
|
|
469
|
-
const liveAddresses = await Promise.all(
|
|
470
|
-
libraries.map(async (library) => {
|
|
471
|
-
const version = resolveLiveVersionSpec(cdmJson, library, contracts[library]);
|
|
472
|
-
return [library, await queryLiveAddress(registry, library, version)];
|
|
473
|
-
})
|
|
474
|
-
);
|
|
475
|
-
const resolved = cloneCdmJson(cdmJson);
|
|
476
|
-
for (const [library, address] of liveAddresses) {
|
|
477
|
-
patchContractAddress(resolved, library, address);
|
|
478
|
-
}
|
|
479
|
-
return resolved;
|
|
480
495
|
}
|
|
481
496
|
var ContractManager = class _ContractManager {
|
|
482
497
|
contracts;
|
|
@@ -527,7 +542,8 @@ var ContractManager = class _ContractManager {
|
|
|
527
542
|
...options,
|
|
528
543
|
registryOrigin: options?.registryOrigin ?? options?.defaultOrigin
|
|
529
544
|
});
|
|
530
|
-
|
|
545
|
+
if (!resolved.ok) return resolved;
|
|
546
|
+
return ok(new _ContractManager(resolved.value, runtime, options));
|
|
531
547
|
}
|
|
532
548
|
/**
|
|
533
549
|
* Convenience factory for {@link fromLive} when the caller has a raw
|