@dotdm/contracts 0.1.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/dist/builder.d.ts +17 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +103 -0
- package/dist/builder.js.map +1 -0
- package/dist/cdm-json.d.ts +16 -0
- package/dist/cdm-json.d.ts.map +1 -0
- package/dist/cdm-json.js +22 -0
- package/dist/cdm-json.js.map +1 -0
- package/dist/cid.d.ts +2 -0
- package/dist/cid.d.ts.map +1 -0
- package/dist/cid.js +10 -0
- package/dist/cid.js.map +1 -0
- package/dist/deployer.d.ts +76 -0
- package/dist/deployer.d.ts.map +1 -0
- package/dist/deployer.js +129 -0
- package/dist/deployer.js.map +1 -0
- package/dist/detection.d.ts +86 -0
- package/dist/detection.d.ts.map +1 -0
- package/dist/detection.js +293 -0
- package/dist/detection.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/publisher.d.ts +25 -0
- package/dist/publisher.d.ts.map +1 -0
- package/dist/publisher.js +84 -0
- package/dist/publisher.js.map +1 -0
- package/dist/registry.d.ts +105 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +74 -0
- package/dist/registry.js.map +1 -0
- package/dist/store.d.ts +14 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +35 -0
- package/dist/store.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface BuildResult {
|
|
2
|
+
crateName: string;
|
|
3
|
+
success: boolean;
|
|
4
|
+
stdout: string;
|
|
5
|
+
stderr: string;
|
|
6
|
+
durationMs: number;
|
|
7
|
+
}
|
|
8
|
+
export type BuildProgressCallback = (processed: number, total: number, currentCrate: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Build a single contract using `cargo pvm-contract build`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pvmContractBuild(rootDir: string, crateName: string, registryAddr?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Build a single contract asynchronously with progress tracking.
|
|
15
|
+
*/
|
|
16
|
+
export declare function pvmContractBuildAsync(rootDir: string, crateName: string, registryAddr?: string, onProgress?: BuildProgressCallback): Promise<BuildResult>;
|
|
17
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,qBAAqB,GAAG,CAChC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,KACnB,IAAI,CAAC;AAEV;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAUhG;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,qBAAqB,GACnC,OAAO,CAAC,WAAW,CAAC,CAsFtB"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { execFileSync, spawn } from "child_process";
|
|
3
|
+
/**
|
|
4
|
+
* Build a single contract using `cargo pvm-contract build`.
|
|
5
|
+
*/
|
|
6
|
+
export function pvmContractBuild(rootDir, crateName, registryAddr) {
|
|
7
|
+
const manifestPath = resolve(rootDir, "Cargo.toml");
|
|
8
|
+
const args = ["pvm-contract", "build", "--manifest-path", manifestPath, "-p", crateName];
|
|
9
|
+
const env = {
|
|
10
|
+
...process.env,
|
|
11
|
+
};
|
|
12
|
+
if (registryAddr) {
|
|
13
|
+
env.CONTRACTS_REGISTRY_ADDR = registryAddr;
|
|
14
|
+
}
|
|
15
|
+
execFileSync("cargo", args, { cwd: rootDir, stdio: "inherit", env });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build a single contract asynchronously with progress tracking.
|
|
19
|
+
*/
|
|
20
|
+
export async function pvmContractBuildAsync(rootDir, crateName, registryAddr, onProgress) {
|
|
21
|
+
const manifestPath = resolve(rootDir, "Cargo.toml");
|
|
22
|
+
return new Promise((done) => {
|
|
23
|
+
const startTime = Date.now();
|
|
24
|
+
const args = [
|
|
25
|
+
"pvm-contract",
|
|
26
|
+
"build",
|
|
27
|
+
"--manifest-path",
|
|
28
|
+
manifestPath,
|
|
29
|
+
"-p",
|
|
30
|
+
crateName,
|
|
31
|
+
"--message-format",
|
|
32
|
+
"json,json-diagnostic-rendered-ansi",
|
|
33
|
+
];
|
|
34
|
+
const env = {
|
|
35
|
+
...process.env,
|
|
36
|
+
};
|
|
37
|
+
if (registryAddr) {
|
|
38
|
+
env.CONTRACTS_REGISTRY_ADDR = registryAddr;
|
|
39
|
+
}
|
|
40
|
+
const child = spawn("cargo", args, {
|
|
41
|
+
cwd: rootDir,
|
|
42
|
+
env,
|
|
43
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
44
|
+
});
|
|
45
|
+
let stdout = "";
|
|
46
|
+
let stderr = "";
|
|
47
|
+
let compilerMessages = "";
|
|
48
|
+
let artifactsSeen = 0;
|
|
49
|
+
let total = 0;
|
|
50
|
+
child.stdout.on("data", (data) => {
|
|
51
|
+
const text = data.toString();
|
|
52
|
+
stdout += text;
|
|
53
|
+
for (const line of text.split("\n")) {
|
|
54
|
+
const trimmed = line.trim();
|
|
55
|
+
if (!trimmed)
|
|
56
|
+
continue;
|
|
57
|
+
try {
|
|
58
|
+
const msg = JSON.parse(trimmed);
|
|
59
|
+
if (msg.reason === "build-plan") {
|
|
60
|
+
// Emitted by cargo-pvm-contract before build starts
|
|
61
|
+
total = msg.total ?? 0;
|
|
62
|
+
}
|
|
63
|
+
else if (msg.reason === "compiler-artifact") {
|
|
64
|
+
artifactsSeen++;
|
|
65
|
+
const name = msg.target?.name ?? "unknown";
|
|
66
|
+
onProgress?.(artifactsSeen, total, name);
|
|
67
|
+
}
|
|
68
|
+
else if (msg.reason === "compiler-message" && msg.message?.rendered) {
|
|
69
|
+
compilerMessages += msg.message.rendered;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Not JSON, ignore
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
child.stderr.on("data", (data) => {
|
|
78
|
+
const text = data.toString();
|
|
79
|
+
stderr += text;
|
|
80
|
+
});
|
|
81
|
+
child.on("close", (code) => {
|
|
82
|
+
const fullStderr = compilerMessages ? compilerMessages + stderr : stderr;
|
|
83
|
+
done({
|
|
84
|
+
crateName,
|
|
85
|
+
success: code === 0,
|
|
86
|
+
stdout,
|
|
87
|
+
stderr: fullStderr,
|
|
88
|
+
durationMs: Date.now() - startTime,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
child.on("error", (err) => {
|
|
92
|
+
const fullStderr = compilerMessages ? compilerMessages + stderr : stderr;
|
|
93
|
+
done({
|
|
94
|
+
crateName,
|
|
95
|
+
success: false,
|
|
96
|
+
stdout,
|
|
97
|
+
stderr: fullStderr + "\n" + err.message,
|
|
98
|
+
durationMs: Date.now() - startTime,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,O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bulletin: string;
|
|
4
|
+
registry: string;
|
|
5
|
+
}
|
|
6
|
+
export interface CdmJson {
|
|
7
|
+
targets: Record<string, CdmJsonTarget>;
|
|
8
|
+
dependencies: Record<string, Record<string, number | "latest">>;
|
|
9
|
+
}
|
|
10
|
+
export declare function computeTargetHash(assethubUrl: string, ipfsGatewayUrl: string, registryAddress: string): string;
|
|
11
|
+
export declare function readCdmJson(startDir?: string): {
|
|
12
|
+
cdmJson: CdmJson;
|
|
13
|
+
cdmJsonPath: string;
|
|
14
|
+
} | null;
|
|
15
|
+
export declare function writeCdmJson(cdmJson: CdmJson, dir?: string): void;
|
|
16
|
+
//# sourceMappingURL=cdm-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdm-json.d.ts","sourceRoot":"","sources":["../src/cdm-json.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;CACnE;AAED,wBAAgB,iBAAiB,CAC7B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACxB,MAAM,CAIR;AAED,wBAAgB,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ/F;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAGjE"}
|
package/dist/cdm-json.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2.js";
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
export function computeTargetHash(assethubUrl, ipfsGatewayUrl, registryAddress) {
|
|
5
|
+
const input = `${assethubUrl}\n${ipfsGatewayUrl}\n${registryAddress}`;
|
|
6
|
+
const hash = blake2b(new TextEncoder().encode(input), { dkLen: 32 });
|
|
7
|
+
return Buffer.from(hash.slice(0, 8)).toString("hex");
|
|
8
|
+
}
|
|
9
|
+
export function readCdmJson(startDir) {
|
|
10
|
+
const dir = startDir ?? process.cwd();
|
|
11
|
+
const candidate = resolve(dir, "cdm.json");
|
|
12
|
+
if (existsSync(candidate)) {
|
|
13
|
+
const content = readFileSync(candidate, "utf-8");
|
|
14
|
+
return { cdmJson: JSON.parse(content), cdmJsonPath: candidate };
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export function writeCdmJson(cdmJson, dir) {
|
|
19
|
+
const target = resolve(dir ?? process.cwd(), "cdm.json");
|
|
20
|
+
writeFileSync(target, JSON.stringify(cdmJson, null, 2) + "\n");
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cdm-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdm-json.js","sourceRoot":"","sources":["../src/cdm-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAW,MAAM,MAAM,CAAC;AAaxC,MAAM,UAAU,iBAAiB,CAC7B,WAAmB,EACnB,cAAsB,EACtB,eAAuB;IAEvB,MAAM,KAAK,GAAG,GAAG,WAAW,KAAK,cAAc,KAAK,eAAe,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAiB;IACzC,MAAM,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC3C,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAY,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;IAC/E,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,GAAY;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IACzD,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/cid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAOA,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAGnD"}
|
package/dist/cid.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
import * as Digest from "multiformats/hashes/digest";
|
|
3
|
+
import { blake2b } from "@noble/hashes/blake2.js";
|
|
4
|
+
const BLAKE2B_256 = 0xb220;
|
|
5
|
+
const RAW_CODEC = 0x55;
|
|
6
|
+
export function computeCid(data) {
|
|
7
|
+
const hash = blake2b(data, { dkLen: 32 });
|
|
8
|
+
return CID.createV1(RAW_CODEC, Digest.create(BLAKE2B_256, hash)).toString();
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=cid.js.map
|
package/dist/cid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,MAAM,UAAU,UAAU,CAAC,IAAgB;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,OAAO,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { PolkadotClient, TypedApi, Binary } from "polkadot-api";
|
|
2
|
+
import { AssetHub } from "@polkadot-api/descriptors";
|
|
3
|
+
import { prepareSigner } from "@dotdm/env";
|
|
4
|
+
export interface AbiParam {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
components?: AbiParam[];
|
|
8
|
+
}
|
|
9
|
+
export interface AbiEntry {
|
|
10
|
+
type: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
inputs: AbiParam[];
|
|
13
|
+
outputs?: AbiParam[];
|
|
14
|
+
stateMutability?: string;
|
|
15
|
+
anonymous?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface Metadata {
|
|
18
|
+
publish_block: number;
|
|
19
|
+
published_at: string;
|
|
20
|
+
description: string;
|
|
21
|
+
readme: string;
|
|
22
|
+
authors: string[];
|
|
23
|
+
homepage: string;
|
|
24
|
+
repository: string;
|
|
25
|
+
abi: AbiEntry[];
|
|
26
|
+
}
|
|
27
|
+
export declare class ContractDeployer {
|
|
28
|
+
signer: ReturnType<typeof prepareSigner>;
|
|
29
|
+
api: TypedApi<AssetHub>;
|
|
30
|
+
client: PolkadotClient;
|
|
31
|
+
constructor(signer: ReturnType<typeof prepareSigner>, client: PolkadotClient, api: TypedApi<AssetHub>);
|
|
32
|
+
/**
|
|
33
|
+
* Deploy a PVM contract and return its address.
|
|
34
|
+
* Uses a dry-run to estimate gas, then submits with the estimated values.
|
|
35
|
+
*/
|
|
36
|
+
deploy(pvmPath: string): Promise<{
|
|
37
|
+
address: string;
|
|
38
|
+
txHash: string;
|
|
39
|
+
blockHash: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Dry-run a contract deploy to estimate gas/storage, returning the
|
|
43
|
+
* transaction descriptor (unsigned) and the bytecode for later batching.
|
|
44
|
+
*/
|
|
45
|
+
dryRunDeploy(pvmPath: string): Promise<{
|
|
46
|
+
tx: import("polkadot-api").Transaction<{
|
|
47
|
+
data: Binary;
|
|
48
|
+
code: Binary;
|
|
49
|
+
value: bigint;
|
|
50
|
+
weight_limit: {
|
|
51
|
+
ref_time: bigint;
|
|
52
|
+
proof_size: bigint;
|
|
53
|
+
};
|
|
54
|
+
storage_deposit_limit: bigint;
|
|
55
|
+
salt: import("polkadot-api").FixedSizeBinary<32> | undefined;
|
|
56
|
+
}, "Revive", "instantiate_with_code", {
|
|
57
|
+
parents: number;
|
|
58
|
+
interior: import("@polkadot-api/descriptors").XcmV5Junctions;
|
|
59
|
+
} | undefined, Partial<import("@polkadot-api/descriptors").AssetHubExtensions>>;
|
|
60
|
+
gasLimit: {
|
|
61
|
+
ref_time: bigint;
|
|
62
|
+
proof_size: bigint;
|
|
63
|
+
};
|
|
64
|
+
storageDeposit: bigint;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Deploy multiple contracts in a single Utility.batch_all transaction.
|
|
68
|
+
* Returns addresses in the same order as the input paths.
|
|
69
|
+
*/
|
|
70
|
+
deployBatch(pvmPaths: string[]): Promise<{
|
|
71
|
+
addresses: string[];
|
|
72
|
+
txHash: string;
|
|
73
|
+
blockHash: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=deployer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployer.d.ts","sourceRoot":"","sources":["../src/deployer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAQ,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,qBAAa,gBAAgB;IAClB,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;IACzC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxB,MAAM,EAAE,cAAc,CAAC;gBAG1B,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,EACxC,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC;IAO3B;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAyD9F;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;IA2ClC;;;OAGG;IACG,WAAW,CACb,QAAQ,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CA2CzE"}
|
package/dist/deployer.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Binary, Enum } from "polkadot-api";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { stringifyBigInt, ALICE_SS58, STORAGE_DEPOSIT_LIMIT } from "@dotdm/utils";
|
|
4
|
+
export class ContractDeployer {
|
|
5
|
+
signer;
|
|
6
|
+
api;
|
|
7
|
+
client;
|
|
8
|
+
constructor(signer, client, api) {
|
|
9
|
+
this.signer = signer;
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.api = api;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Deploy a PVM contract and return its address.
|
|
15
|
+
* Uses a dry-run to estimate gas, then submits with the estimated values.
|
|
16
|
+
*/
|
|
17
|
+
async deploy(pvmPath) {
|
|
18
|
+
const bytecode = readFileSync(pvmPath);
|
|
19
|
+
const code = Binary.fromBytes(bytecode);
|
|
20
|
+
const data = Binary.fromBytes(new Uint8Array(0));
|
|
21
|
+
// Dry-run to estimate gas requirements
|
|
22
|
+
const dryRun = await this.api.apis.ReviveApi.instantiate(ALICE_SS58, 0n, undefined, // unlimited gas for estimation
|
|
23
|
+
undefined, // unlimited storage deposit for estimation
|
|
24
|
+
Enum("Upload", code), data, undefined);
|
|
25
|
+
if (dryRun.result.success === false) {
|
|
26
|
+
throw new Error(`Contract instantiation dry-run failed: ${stringifyBigInt(dryRun.result)}`);
|
|
27
|
+
}
|
|
28
|
+
// Use weight_required from dry-run with 20% headroom
|
|
29
|
+
const gasLimit = {
|
|
30
|
+
ref_time: (dryRun.weight_required.ref_time * 120n) / 100n,
|
|
31
|
+
proof_size: (dryRun.weight_required.proof_size * 120n) / 100n,
|
|
32
|
+
};
|
|
33
|
+
// Derive storage deposit from dry-run
|
|
34
|
+
let storageDeposit = STORAGE_DEPOSIT_LIMIT;
|
|
35
|
+
if (dryRun.storage_deposit.type === "Charge") {
|
|
36
|
+
storageDeposit = (dryRun.storage_deposit.value * 120n) / 100n;
|
|
37
|
+
}
|
|
38
|
+
const result = await this.api.tx.Revive.instantiate_with_code({
|
|
39
|
+
value: 0n,
|
|
40
|
+
weight_limit: gasLimit,
|
|
41
|
+
storage_deposit_limit: storageDeposit,
|
|
42
|
+
code,
|
|
43
|
+
data,
|
|
44
|
+
salt: undefined,
|
|
45
|
+
}).signAndSubmit(this.signer);
|
|
46
|
+
const failures = this.api.event.System.ExtrinsicFailed.filter(result.events);
|
|
47
|
+
if (failures.length > 0) {
|
|
48
|
+
throw new Error(`Deployment transaction failed: ${stringifyBigInt(failures[0])}`);
|
|
49
|
+
}
|
|
50
|
+
const instantiated = this.api.event.Revive.Instantiated.filter(result.events);
|
|
51
|
+
if (instantiated.length === 0) {
|
|
52
|
+
throw new Error("Contract instantiation failed - no Instantiated event");
|
|
53
|
+
}
|
|
54
|
+
const address = instantiated[0].contract.asHex();
|
|
55
|
+
return { address, txHash: result.txHash, blockHash: result.block.hash };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Dry-run a contract deploy to estimate gas/storage, returning the
|
|
59
|
+
* transaction descriptor (unsigned) and the bytecode for later batching.
|
|
60
|
+
*/
|
|
61
|
+
async dryRunDeploy(pvmPath) {
|
|
62
|
+
const bytecode = readFileSync(pvmPath);
|
|
63
|
+
const code = Binary.fromBytes(bytecode);
|
|
64
|
+
const data = Binary.fromBytes(new Uint8Array(0));
|
|
65
|
+
const dryRun = await this.api.apis.ReviveApi.instantiate(ALICE_SS58, 0n, undefined, undefined, Enum("Upload", code), data, undefined);
|
|
66
|
+
if (dryRun.result.success === false) {
|
|
67
|
+
throw new Error(`Dry-run failed: ${stringifyBigInt(dryRun.result)}`);
|
|
68
|
+
}
|
|
69
|
+
const gasLimit = {
|
|
70
|
+
ref_time: (dryRun.weight_required.ref_time * 120n) / 100n,
|
|
71
|
+
proof_size: (dryRun.weight_required.proof_size * 120n) / 100n,
|
|
72
|
+
};
|
|
73
|
+
let storageDeposit = STORAGE_DEPOSIT_LIMIT;
|
|
74
|
+
if (dryRun.storage_deposit.type === "Charge") {
|
|
75
|
+
storageDeposit = (dryRun.storage_deposit.value * 120n) / 100n;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
tx: this.api.tx.Revive.instantiate_with_code({
|
|
79
|
+
value: 0n,
|
|
80
|
+
weight_limit: gasLimit,
|
|
81
|
+
storage_deposit_limit: storageDeposit,
|
|
82
|
+
code,
|
|
83
|
+
data,
|
|
84
|
+
salt: undefined,
|
|
85
|
+
}),
|
|
86
|
+
gasLimit,
|
|
87
|
+
storageDeposit,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Deploy multiple contracts in a single Utility.batch_all transaction.
|
|
92
|
+
* Returns addresses in the same order as the input paths.
|
|
93
|
+
*/
|
|
94
|
+
async deployBatch(pvmPaths) {
|
|
95
|
+
if (pvmPaths.length === 0)
|
|
96
|
+
return { addresses: [], txHash: "", blockHash: "" };
|
|
97
|
+
if (pvmPaths.length === 1) {
|
|
98
|
+
const result = await this.deploy(pvmPaths[0]);
|
|
99
|
+
return {
|
|
100
|
+
addresses: [result.address],
|
|
101
|
+
txHash: result.txHash,
|
|
102
|
+
blockHash: result.blockHash,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const prepared = await Promise.all(pvmPaths.map((p) => this.dryRunDeploy(p)));
|
|
106
|
+
const calls = await Promise.all(prepared.map(async (p) => {
|
|
107
|
+
const call = p.tx.decodedCall;
|
|
108
|
+
return call instanceof Promise ? await call : call;
|
|
109
|
+
}));
|
|
110
|
+
const result = await this.api.tx.Utility.batch_all({
|
|
111
|
+
calls,
|
|
112
|
+
}).signAndSubmit(this.signer);
|
|
113
|
+
const failures = this.api.event.System.ExtrinsicFailed.filter(result.events);
|
|
114
|
+
if (failures.length > 0) {
|
|
115
|
+
throw new Error(`Batch deploy failed: ${stringifyBigInt(failures[0])}`);
|
|
116
|
+
}
|
|
117
|
+
const instantiated = this.api.event.Revive.Instantiated.filter(result.events);
|
|
118
|
+
if (instantiated.length !== pvmPaths.length) {
|
|
119
|
+
throw new Error(`Expected ${pvmPaths.length} Instantiated events, got ${instantiated.length}`);
|
|
120
|
+
}
|
|
121
|
+
const addresses = instantiated.map((e) => e.contract.asHex());
|
|
122
|
+
return {
|
|
123
|
+
addresses,
|
|
124
|
+
txHash: result.txHash,
|
|
125
|
+
blockHash: result.block.hash,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL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4
|
+
/** CDM package name (e.g., "@polkadot/reputation") - null if no CDM macro or not yet built */
|
|
5
|
+
cdmPackage: string | null;
|
|
6
|
+
/** Description from Cargo.toml [package] section */
|
|
7
|
+
description: string | null;
|
|
8
|
+
/** Authors from Cargo.toml [package] section */
|
|
9
|
+
authors: string[];
|
|
10
|
+
/** Homepage URL from Cargo.toml [package] section */
|
|
11
|
+
homepage: string | null;
|
|
12
|
+
/** Repository URL from Cargo.toml [package] section */
|
|
13
|
+
repository: string | null;
|
|
14
|
+
/** Absolute path to readme file */
|
|
15
|
+
readmePath: string | null;
|
|
16
|
+
/** Path to contract crate directory */
|
|
17
|
+
path: string;
|
|
18
|
+
/** Crate names this contract depends on (from Cargo dependency graph) */
|
|
19
|
+
dependsOnCrates: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface DeploymentOrder {
|
|
22
|
+
/** Crate names in deployment order */
|
|
23
|
+
crateNames: string[];
|
|
24
|
+
/** CDM package names in deployment order (null for contracts without CDM) */
|
|
25
|
+
cdmPackages: (string | null)[];
|
|
26
|
+
/** Full contract info for each contract, in deployment order */
|
|
27
|
+
contracts: ContractInfo[];
|
|
28
|
+
}
|
|
29
|
+
export interface DeploymentOrderLayered {
|
|
30
|
+
/** Layers of crate names - each layer can be processed in parallel */
|
|
31
|
+
layers: string[][];
|
|
32
|
+
/** Full contract info indexed by crate name */
|
|
33
|
+
contractMap: Map<string, ContractInfo>;
|
|
34
|
+
/** CDM package name indexed by crate name (only contracts with CDM packages) */
|
|
35
|
+
cdmPackageMap: Map<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read CDM package name from post-build .cdm.json file.
|
|
39
|
+
* Returns null if contract has no CDM annotation or hasn't been built yet.
|
|
40
|
+
*
|
|
41
|
+
* The .cdm.json file is generated by cargo-pvm-contract during compilation
|
|
42
|
+
* by extracting the __PVM_CDM symbol from the compiled ELF.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readCdmPackage(rootDir: string, crateName: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Detect all PVM contracts in a workspace using cargo metadata.
|
|
47
|
+
*
|
|
48
|
+
* This replaces the old regex-based detection with Cargo's own resolver:
|
|
49
|
+
* - Workspace members come from cargo metadata (not recursive file scanning)
|
|
50
|
+
* - PVM contract detection uses resolved dependency graph (not string matching)
|
|
51
|
+
* - Inter-contract dependencies come from Cargo.toml (not regex on source)
|
|
52
|
+
* - CDM package names come from .cdm.json files (not regex on source)
|
|
53
|
+
*/
|
|
54
|
+
export declare function detectContracts(rootDir: string): ContractInfo[];
|
|
55
|
+
/**
|
|
56
|
+
* Build a dependency graph from contract info.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildDependencyGraph(contracts: ContractInfo[]): Map<string, string[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Topological sort using Kahn's algorithm.
|
|
61
|
+
* Returns nodes in dependency order (dependencies come first).
|
|
62
|
+
*/
|
|
63
|
+
export declare function toposort(graph: Map<string, string[]>): string[];
|
|
64
|
+
/**
|
|
65
|
+
* Topological sort (layered) using modified Kahn's algorithm.
|
|
66
|
+
* Collects ALL zero-in-degree nodes at each iteration as a layer.
|
|
67
|
+
* Each layer can be processed in parallel.
|
|
68
|
+
*/
|
|
69
|
+
export declare function toposortLayers(graph: Map<string, string[]>): string[][];
|
|
70
|
+
/**
|
|
71
|
+
* Create a mapping from crate name to CDM package name.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createCrateToPackageMap(contracts: ContractInfo[]): Map<string, string>;
|
|
74
|
+
/**
|
|
75
|
+
* Detect contracts and determine deployment order based on dependencies.
|
|
76
|
+
* Uses cargo metadata for reliable workspace and dependency resolution.
|
|
77
|
+
*/
|
|
78
|
+
export declare function detectDeploymentOrder(rootDir: string): DeploymentOrder;
|
|
79
|
+
/**
|
|
80
|
+
* Detect contracts and determine layered deployment order.
|
|
81
|
+
* Each layer contains contracts that can be deployed in parallel.
|
|
82
|
+
*/
|
|
83
|
+
export declare function detectDeploymentOrderLayered(rootDir: string): DeploymentOrderLayered;
|
|
84
|
+
export declare function getGitRemoteUrl(rootDir: string): string | null;
|
|
85
|
+
export declare function readReadmeContent(readmePath: string | null): string;
|
|
86
|
+
//# sourceMappingURL=detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detection.d.ts","sourceRoot":"","sources":["../src/detection.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IACzB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,8FAA8F;IAC9F,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,oDAAoD;IACpD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gDAAgD;IAChD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,mCAAmC;IACnC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,eAAe,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC5B,sCAAsC;IACtC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,6EAA6E;IAC7E,WAAW,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAC/B,gEAAgE;IAChE,SAAS,EAAE,YAAY,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,sBAAsB;IACnC,sEAAsE;IACtE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,+CAA+C;IAC/C,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACvC,gFAAgF;IAChF,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAwDD;;;;;;GAMG;AACH,w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