@stacks/clarinet-sdk 3.8.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 +91 -0
- package/dist/cjs/common/src/sdkProxyHelpers.d.ts +86 -0
- package/dist/cjs/common/src/sdkProxyHelpers.js +66 -0
- package/dist/cjs/common/src/sdkProxyHelpers.js.map +1 -0
- package/dist/cjs/node/src/index.d.ts +15 -0
- package/dist/cjs/node/src/index.js +68 -0
- package/dist/cjs/node/src/index.js.map +1 -0
- package/dist/cjs/node/src/sdkProxy.d.ts +11 -0
- package/dist/cjs/node/src/sdkProxy.js +98 -0
- package/dist/cjs/node/src/sdkProxy.js.map +1 -0
- package/dist/cjs/node/src/vfs.d.ts +3 -0
- package/dist/cjs/node/src/vfs.js +109 -0
- package/dist/cjs/node/src/vfs.js.map +1 -0
- package/dist/cjs/node/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/common/src/sdkProxyHelpers.d.ts +86 -0
- package/dist/esm/common/src/sdkProxyHelpers.js +61 -0
- package/dist/esm/common/src/sdkProxyHelpers.js.map +1 -0
- package/dist/esm/node/src/index.d.ts +15 -0
- package/dist/esm/node/src/index.js +30 -0
- package/dist/esm/node/src/index.js.map +1 -0
- package/dist/esm/node/src/sdkProxy.d.ts +11 -0
- package/dist/esm/node/src/sdkProxy.js +95 -0
- package/dist/esm/node/src/sdkProxy.js.map +1 -0
- package/dist/esm/node/src/vfs.d.ts +3 -0
- package/dist/esm/node/src/vfs.js +70 -0
- package/dist/esm/node/src/vfs.js.map +1 -0
- package/dist/esm/node/src/vitest/index.d.ts +31 -0
- package/dist/esm/node/src/vitest/index.js +49 -0
- package/dist/esm/node/src/vitest/index.js.map +1 -0
- package/dist/esm/node/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/package.json +1 -0
- package/package.json +73 -0
- package/vitest-helpers/src/clarityValuesMatchers.ts +389 -0
- package/vitest-helpers/src/global.d.ts +20 -0
- package/vitest-helpers/src/vitest.d.ts +28 -0
- package/vitest-helpers/src/vitest.setup.ts +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Clarinet SDK for Node.js
|
|
2
|
+
|
|
3
|
+
The Clarinet SDK allows to interact with the simnet in Node.js.
|
|
4
|
+
|
|
5
|
+
If you want to use the Clarinet SDK in web browsers, try [@stacks/clarinet-sdk-browser](https://www.npmjs.com/package/@stacks/clarinet-sdk-browser).
|
|
6
|
+
|
|
7
|
+
Find the API references of the SDK in [our documentation](https://docs.stacks.co/reference/clarinet-js-sdk/overview).
|
|
8
|
+
|
|
9
|
+
You can use this SDK to:
|
|
10
|
+
|
|
11
|
+
- Interact with a clarinet project as you would with the Clarinet CLI
|
|
12
|
+
- Call public, read-only, and private functions from smart contracts
|
|
13
|
+
- Get clarity maps or data-var values
|
|
14
|
+
- Get contract interfaces (available functions and data)
|
|
15
|
+
- Write unit tests for Clarity smart contracts
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @stacks/clarinet-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { initSimnet } from "@stacks/clarinet-sdk";
|
|
27
|
+
import { Cl } from "@stacks/transactions";
|
|
28
|
+
|
|
29
|
+
async function main() {
|
|
30
|
+
const simnet = await initSimnet();
|
|
31
|
+
|
|
32
|
+
const accounts = simnet.getAccounts();
|
|
33
|
+
const address1 = accounts.get("wallet_1");
|
|
34
|
+
if (!address1) throw new Error("invalid wallet name.");
|
|
35
|
+
|
|
36
|
+
const call = simnet.callPublicFn("counter", "add", [Cl.uint(1)], address1);
|
|
37
|
+
console.log(Cl.prettyPrint(call.result)); // (ok u1)
|
|
38
|
+
|
|
39
|
+
const counter = simnet.getDataVar("counter", "counter");
|
|
40
|
+
console.log(Cl.prettyPrint(counter)); // 2
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
By default, the SDK will look for a Clarinet.toml file in the current working directory.
|
|
47
|
+
It's also possible to provide the path to the manifest like so:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const simnet = await initSimnet("./path/to/Clarinet.toml");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Tests
|
|
54
|
+
|
|
55
|
+
The SDK can be used to write unit tests for Clarinet projects.
|
|
56
|
+
|
|
57
|
+
You'll need to have Node.js (>= 18) and NPM setup. If you are not sure how to set it up, [Volta](https://volta.sh/) is a nice tool to get started.
|
|
58
|
+
|
|
59
|
+
In the terminal, run `node --version` to make sure it's available and up to date.
|
|
60
|
+
|
|
61
|
+
Open your terminal and go to a new or existing Clarinet project:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
cd my-project
|
|
65
|
+
ls # you should see Clarinet.toml and package.json in the list
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Install the dependencies and run the test
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm install
|
|
72
|
+
npm test
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Visit the [clarity starter project](https://github.com/stx-labs/clarity-starter) to see the testing framework in action.
|
|
76
|
+
|
|
77
|
+
### Type checking
|
|
78
|
+
|
|
79
|
+
We recommend to use TypeScript to write the unit tests, but it's also possible to do it with JavaScript. To do so, rename your test files to `.test.js` instead of `.test.ts`. You can also delete the `tsconfig.json` and uninstall typescript with `npm uninstall typescript`.
|
|
80
|
+
|
|
81
|
+
Note: If you want to write your test in JavaScript but still have a certain level of type safety and autocompletion, VSCode can help you with that. You can create a basic `jsconfig.json` file:
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"compilerOptions": {
|
|
86
|
+
"checkJs": true,
|
|
87
|
+
"strict": true
|
|
88
|
+
},
|
|
89
|
+
"include": ["node_modules/@stacks/clarinet-sdk/vitest-helpers/src", "unit-tests"]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ClarityValue } from "@stacks/transactions";
|
|
2
|
+
export type ClarityEvent = {
|
|
3
|
+
event: string;
|
|
4
|
+
data: {
|
|
5
|
+
raw_value?: string;
|
|
6
|
+
value?: ClarityValue;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type ExecutionCost = {
|
|
11
|
+
writeLength: number;
|
|
12
|
+
writeCount: number;
|
|
13
|
+
readLength: number;
|
|
14
|
+
readCount: number;
|
|
15
|
+
runtime: number;
|
|
16
|
+
};
|
|
17
|
+
export type ClarityCosts = {
|
|
18
|
+
total: ExecutionCost;
|
|
19
|
+
limit: ExecutionCost;
|
|
20
|
+
memory: number;
|
|
21
|
+
memory_limit: number;
|
|
22
|
+
};
|
|
23
|
+
export type ParsedTransactionResult = {
|
|
24
|
+
result: ClarityValue;
|
|
25
|
+
events: ClarityEvent[];
|
|
26
|
+
costs: ClarityCosts | null;
|
|
27
|
+
performance: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export type CallFn = (contract: string, method: string, args: ClarityValue[], sender: string) => ParsedTransactionResult;
|
|
30
|
+
export type DeployContractOptions = {
|
|
31
|
+
clarityVersion: 1 | 2 | 3 | 4;
|
|
32
|
+
};
|
|
33
|
+
export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string) => ParsedTransactionResult;
|
|
34
|
+
export type TransferSTX = (amount: number | bigint, recipient: string, sender: string) => ParsedTransactionResult;
|
|
35
|
+
export type Tx = {
|
|
36
|
+
callPublicFn: {
|
|
37
|
+
contract: string;
|
|
38
|
+
method: string;
|
|
39
|
+
args: ClarityValue[];
|
|
40
|
+
sender: string;
|
|
41
|
+
};
|
|
42
|
+
callPrivateFn?: never;
|
|
43
|
+
deployContract?: never;
|
|
44
|
+
transferSTX?: never;
|
|
45
|
+
} | {
|
|
46
|
+
callPublicFn?: never;
|
|
47
|
+
callPrivateFn: {
|
|
48
|
+
contract: string;
|
|
49
|
+
method: string;
|
|
50
|
+
args: ClarityValue[];
|
|
51
|
+
sender: string;
|
|
52
|
+
};
|
|
53
|
+
deployContract?: never;
|
|
54
|
+
transferSTX?: never;
|
|
55
|
+
} | {
|
|
56
|
+
callPublicFn?: never;
|
|
57
|
+
callPrivateFn?: never;
|
|
58
|
+
deployContract: {
|
|
59
|
+
name: string;
|
|
60
|
+
content: string;
|
|
61
|
+
options: DeployContractOptions | null;
|
|
62
|
+
sender: string;
|
|
63
|
+
};
|
|
64
|
+
transferSTX?: never;
|
|
65
|
+
} | {
|
|
66
|
+
callPublicFn?: never;
|
|
67
|
+
callPrivateFn?: never;
|
|
68
|
+
deployContradct?: never;
|
|
69
|
+
transferSTX: {
|
|
70
|
+
amount: number;
|
|
71
|
+
recipient: string;
|
|
72
|
+
sender: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare const tx: {
|
|
76
|
+
callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
77
|
+
callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
78
|
+
deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string) => Tx;
|
|
79
|
+
transferSTX: (amount: number, recipient: string, sender: string) => Tx;
|
|
80
|
+
};
|
|
81
|
+
export declare function parseEvents(events: string): ClarityEvent[];
|
|
82
|
+
export declare function parseCosts(costs: string): ClarityCosts | null;
|
|
83
|
+
export type MineBlock = (txs: Array<Tx>) => ParsedTransactionResult[];
|
|
84
|
+
export type Execute = (snippet: string) => ParsedTransactionResult;
|
|
85
|
+
export type GetDataVar = (contract: string, dataVar: string) => ClarityValue;
|
|
86
|
+
export type GetMapEntry = (contract: string, mapName: string, mapKey: ClarityValue) => ClarityValue;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tx = void 0;
|
|
4
|
+
exports.parseEvents = parseEvents;
|
|
5
|
+
exports.parseCosts = parseCosts;
|
|
6
|
+
const transactions_1 = require("@stacks/transactions");
|
|
7
|
+
exports.tx = {
|
|
8
|
+
callPublicFn: (contract, method, args, sender) => ({
|
|
9
|
+
callPublicFn: { contract, method, args, sender },
|
|
10
|
+
}),
|
|
11
|
+
callPrivateFn: (contract, method, args, sender) => ({
|
|
12
|
+
callPrivateFn: { contract, method, args, sender },
|
|
13
|
+
}),
|
|
14
|
+
deployContract: (name, content, options, sender) => ({
|
|
15
|
+
deployContract: { name, content, options, sender },
|
|
16
|
+
}),
|
|
17
|
+
transferSTX: (amount, recipient, sender) => ({
|
|
18
|
+
transferSTX: { amount, recipient, sender },
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
function parseEvents(events) {
|
|
22
|
+
try {
|
|
23
|
+
// @todo: improve type safety
|
|
24
|
+
return JSON.parse(events).map((e) => {
|
|
25
|
+
const { event, data } = JSON.parse(e);
|
|
26
|
+
if ("raw_value" in data) {
|
|
27
|
+
data.value = transactions_1.Cl.deserialize(data.raw_value);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
event: event,
|
|
31
|
+
data: data,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(`Fail to parse events: ${e}`);
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function parseCosts(costs) {
|
|
41
|
+
try {
|
|
42
|
+
let { memory, memory_limit, total, limit } = JSON.parse(costs);
|
|
43
|
+
return {
|
|
44
|
+
memory: memory,
|
|
45
|
+
memory_limit: memory_limit,
|
|
46
|
+
total: {
|
|
47
|
+
writeLength: total.write_length,
|
|
48
|
+
writeCount: total.write_count,
|
|
49
|
+
readLength: total.read_length,
|
|
50
|
+
readCount: total.read_count,
|
|
51
|
+
runtime: total.runtime,
|
|
52
|
+
},
|
|
53
|
+
limit: {
|
|
54
|
+
writeLength: limit.write_length,
|
|
55
|
+
writeCount: limit.write_count,
|
|
56
|
+
readLength: limit.read_length,
|
|
57
|
+
readCount: limit.read_count,
|
|
58
|
+
runtime: limit.runtime,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (_e) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=sdkProxyHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":";;;AAiHA,kCAiBC;AAED,gCAwBC;AA5JD,uDAAwD;AA6F3C,QAAA,EAAE,GAAG;IAChB,YAAY,EAAE,CAAC,QAAgB,EAAE,MAAc,EAAE,IAAoB,EAAE,MAAc,EAAM,EAAE,CAAC,CAAC;QAC7F,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;KACjD,CAAC;IACF,aAAa,EAAE,CAAC,QAAgB,EAAE,MAAc,EAAE,IAAoB,EAAE,MAAc,EAAM,EAAE,CAAC,CAAC;QAC9F,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;KAClD,CAAC;IACF,cAAc,EAAE,CACd,IAAY,EACZ,OAAe,EACf,OAAqC,EACrC,MAAc,EACV,EAAE,CAAC,CAAC;QACR,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE;KACnD,CAAC;IACF,WAAW,EAAE,CAAC,MAAc,EAAE,SAAiB,EAAE,MAAc,EAAM,EAAE,CAAC,CAAC;QACvE,WAAW,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;KAC3C,CAAC;CACH,CAAC;AAEF,SAAgB,WAAW,CAAC,MAAc;IACxC,IAAI,CAAC;QAC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F,CAAC;IACJ,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { tx, type ClarityEvent, type ParsedTransactionResult, type DeployContractOptions, type Tx, type TransferSTX, } from "../../common/src/sdkProxyHelpers.js";
|
|
2
|
+
import { Simnet } from "./sdkProxy.js";
|
|
3
|
+
export { type Simnet } from "./sdkProxy.js";
|
|
4
|
+
type Options = {
|
|
5
|
+
trackCosts: boolean;
|
|
6
|
+
trackCoverage: boolean;
|
|
7
|
+
trackPerformance?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function getSDK(options?: Options): Promise<Simnet>;
|
|
10
|
+
export declare const initSimnet: (manifestPath?: string, noCache?: boolean, options?: {
|
|
11
|
+
trackCosts: boolean;
|
|
12
|
+
trackCoverage: boolean;
|
|
13
|
+
trackPerformance?: boolean;
|
|
14
|
+
performanceCostField?: string;
|
|
15
|
+
}) => Promise<Simnet>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.initSimnet = exports.tx = void 0;
|
|
37
|
+
exports.getSDK = getSDK;
|
|
38
|
+
const clarinet_sdk_wasm_1 = require("@stacks/clarinet-sdk-wasm");
|
|
39
|
+
var sdkProxyHelpers_js_1 = require("../../common/src/sdkProxyHelpers.js");
|
|
40
|
+
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return sdkProxyHelpers_js_1.tx; } });
|
|
41
|
+
const vfs_js_1 = require("./vfs.js");
|
|
42
|
+
const sdkProxy_js_1 = require("./sdkProxy.js");
|
|
43
|
+
const wasmModule = Promise.resolve().then(() => __importStar(require("@stacks/clarinet-sdk-wasm")));
|
|
44
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
BigInt.prototype.toJSON = function () {
|
|
47
|
+
return this.toString();
|
|
48
|
+
};
|
|
49
|
+
async function getSDK(options) {
|
|
50
|
+
const module = await wasmModule;
|
|
51
|
+
let sdkOptions = new clarinet_sdk_wasm_1.SDKOptions(!!options?.trackCosts, !!options?.trackCoverage, !!options?.trackPerformance);
|
|
52
|
+
const simnet = new Proxy(new module.SDK(vfs_js_1.vfs, sdkOptions), (0, sdkProxy_js_1.getSessionProxy)());
|
|
53
|
+
return simnet;
|
|
54
|
+
}
|
|
55
|
+
// load wasm only once and memoize it
|
|
56
|
+
function memoizedInit() {
|
|
57
|
+
let simnet = null;
|
|
58
|
+
return async (manifestPath = "./Clarinet.toml", noCache = false, options) => {
|
|
59
|
+
if (noCache || !simnet) {
|
|
60
|
+
simnet = await getSDK(options);
|
|
61
|
+
}
|
|
62
|
+
// start a new simnet session
|
|
63
|
+
await simnet.initSession(process.cwd(), manifestPath);
|
|
64
|
+
return simnet;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
exports.initSimnet = memoizedInit();
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,wBAUC;AAxCD,iEAAuD;AAEvD,0EAO6C;AAN3C,wGAAA,EAAE,OAAA;AAQJ,qCAA+B;AAC/B,+CAAwD;AAIxD,MAAM,UAAU,qDAAU,2BAA2B,GAAC,CAAC;AAEvD,0GAA0G;AAC1G,aAAa;AACb,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC,CAAC;AAQK,KAAK,UAAU,MAAM,CAAC,OAAiB;IAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC;IAChC,IAAI,UAAU,GAAG,IAAI,8BAAU,CAC7B,CAAC,CAAC,OAAO,EAAE,UAAU,EACrB,CAAC,CAAC,OAAO,EAAE,aAAa,EACxB,CAAC,CAAC,OAAO,EAAE,gBAAgB,CAC5B,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,YAAG,EAAE,UAAU,CAAC,EAAE,IAAA,6BAAe,GAAE,CAAsB,CAAC;IAClG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,qCAAqC;AACrC,SAAS,YAAY;IACnB,IAAI,MAAM,GAAkB,IAAI,CAAC;IAEjC,OAAO,KAAK,EACV,YAAY,GAAG,iBAAiB,EAChC,OAAO,GAAG,KAAK,EACf,OAKC,EACD,EAAE;QACF,IAAI,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,6BAA6B;QAC7B,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAEY,QAAA,UAAU,GAAG,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SDK } from "@stacks/clarinet-sdk-wasm";
|
|
2
|
+
import { type CallFn, type DeployContract, type GetDataVar, type GetMapEntry, type MineBlock, type Execute, type TransferSTX } from "../../common/src/sdkProxyHelpers.js";
|
|
3
|
+
/** @deprecated use `simnet.execute(command)` instead */
|
|
4
|
+
type RunSnippet = SDK["runSnippet"];
|
|
5
|
+
export type Simnet = {
|
|
6
|
+
[K in keyof SDK]: K extends "callReadOnlyFn" | "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "runSnippet" ? RunSnippet : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : SDK[K];
|
|
7
|
+
};
|
|
8
|
+
export declare function getSessionProxy(): {
|
|
9
|
+
get(session: SDK, prop: keyof SDK, receiver: any): string | number | CallFn | DeployContract | TransferSTX | MineBlock | GetMapEntry | ((cwd: string, manifest_path: string) => Promise<void>) | ((epoch: import("@stacks/clarinet-sdk-wasm").EpochString) => void) | ((count?: number | null) => number) | ((addresses: string[]) => void) | ((recipient: string, amount: bigint) => string) | ((include_boot_contracts: boolean, boot_contracts_path: string) => import("@stacks/clarinet-sdk-wasm").SessionReport);
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSessionProxy = getSessionProxy;
|
|
4
|
+
const transactions_1 = require("@stacks/transactions");
|
|
5
|
+
const clarinet_sdk_wasm_1 = require("@stacks/clarinet-sdk-wasm");
|
|
6
|
+
const sdkProxyHelpers_js_1 = require("../../common/src/sdkProxyHelpers.js");
|
|
7
|
+
function parseTxResponse(response) {
|
|
8
|
+
return {
|
|
9
|
+
result: transactions_1.Cl.deserialize(response.result),
|
|
10
|
+
events: (0, sdkProxyHelpers_js_1.parseEvents)(response.events),
|
|
11
|
+
costs: (0, sdkProxyHelpers_js_1.parseCosts)(response.costs),
|
|
12
|
+
performance: response.performance,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function getSessionProxy() {
|
|
16
|
+
return {
|
|
17
|
+
get(session, prop, receiver) {
|
|
18
|
+
// some of the WASM methods are proxied here to:
|
|
19
|
+
// - serialize clarity values input argument
|
|
20
|
+
// - deserialize output into clarity values
|
|
21
|
+
if (prop === "callReadOnlyFn" || prop === "callPublicFn" || prop === "callPrivateFn") {
|
|
22
|
+
const callFn = (contract, method, args, sender) => {
|
|
23
|
+
const response = session[prop](new clarinet_sdk_wasm_1.CallFnArgs(contract, method, args.map(transactions_1.serializeCVBytes), sender));
|
|
24
|
+
return parseTxResponse(response);
|
|
25
|
+
};
|
|
26
|
+
return callFn;
|
|
27
|
+
}
|
|
28
|
+
if (prop === "execute") {
|
|
29
|
+
const execute = (snippet) => {
|
|
30
|
+
const response = session.execute(snippet);
|
|
31
|
+
return parseTxResponse(response);
|
|
32
|
+
};
|
|
33
|
+
return execute;
|
|
34
|
+
}
|
|
35
|
+
if (prop === "deployContract") {
|
|
36
|
+
const callDeployContract = (name, content, options, sender) => {
|
|
37
|
+
const rustOptions = options
|
|
38
|
+
? new clarinet_sdk_wasm_1.ContractOptions(options.clarityVersion)
|
|
39
|
+
: new clarinet_sdk_wasm_1.ContractOptions();
|
|
40
|
+
const response = session.deployContract(new clarinet_sdk_wasm_1.DeployContractArgs(name, content, rustOptions, sender));
|
|
41
|
+
return parseTxResponse(response);
|
|
42
|
+
};
|
|
43
|
+
return callDeployContract;
|
|
44
|
+
}
|
|
45
|
+
if (prop === "transferSTX") {
|
|
46
|
+
const callTransferSTX = (amount, ...args) => {
|
|
47
|
+
const response = session.transferSTX(new clarinet_sdk_wasm_1.TransferSTXArgs(BigInt(amount), ...args));
|
|
48
|
+
return parseTxResponse(response);
|
|
49
|
+
};
|
|
50
|
+
return callTransferSTX;
|
|
51
|
+
}
|
|
52
|
+
if (prop === "mineBlock") {
|
|
53
|
+
const callMineBlock = (txs) => {
|
|
54
|
+
const serializedTxs = txs.map((tx) => {
|
|
55
|
+
if (tx.callPublicFn) {
|
|
56
|
+
return {
|
|
57
|
+
callPublicFn: {
|
|
58
|
+
...tx.callPublicFn,
|
|
59
|
+
args_maps: tx.callPublicFn.args.map(transactions_1.serializeCVBytes),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (tx.callPrivateFn) {
|
|
64
|
+
return {
|
|
65
|
+
callPrivateFn: {
|
|
66
|
+
...tx.callPrivateFn,
|
|
67
|
+
args_maps: tx.callPrivateFn.args.map(transactions_1.serializeCVBytes),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return tx;
|
|
72
|
+
});
|
|
73
|
+
const responses = session.mineBlock(serializedTxs);
|
|
74
|
+
return responses.map(parseTxResponse);
|
|
75
|
+
};
|
|
76
|
+
return callMineBlock;
|
|
77
|
+
}
|
|
78
|
+
if (prop === "getDataVar") {
|
|
79
|
+
const getDataVar = (...args) => {
|
|
80
|
+
const response = session.getDataVar(...args);
|
|
81
|
+
const result = transactions_1.Cl.deserialize(response);
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
return getDataVar;
|
|
85
|
+
}
|
|
86
|
+
if (prop === "getMapEntry") {
|
|
87
|
+
const getMapEntry = (contract, mapName, mapKey) => {
|
|
88
|
+
const response = session.getMapEntry(contract, mapName, (0, transactions_1.serializeCVBytes)(mapKey));
|
|
89
|
+
const result = transactions_1.Cl.deserialize(response);
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
return getMapEntry;
|
|
93
|
+
}
|
|
94
|
+
return Reflect.get(session, prop, receiver);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=sdkProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../src/sdkProxy.ts"],"names":[],"mappings":";;AAwDA,0CAgGC;AAxJD,uDAA4D;AAC5D,iEAOmC;AAEnC,4EAW6C;AA0B7C,SAAS,eAAe,CAAC,QAAwB;IAC/C,OAAO;QACL,MAAM,EAAE,iBAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC,MAAM,EAAE,IAAA,gCAAW,EAAC,QAAQ,CAAC,MAAM,CAAC;QACpC,KAAK,EAAE,IAAA,+BAAU,EAAC,QAAQ,CAAC,KAAK,CAAC;QACjC,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC;AAED,SAAgB,eAAe;IAC7B,OAAO;QACL,GAAG,CAAC,OAAY,EAAE,IAAe,EAAE,QAAa;YAC9C,gDAAgD;YAChD,4CAA4C;YAC5C,2CAA2C;YAE3C,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI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CAAC,GAAG,IAAI,CAAC,CAAC;oBAC7C,MAAM,MAAM,GAAG,iBAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBACxC,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC;gBACF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3B,MAAM,WAAW,GAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC7D,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAA,+BAAgB,EAAC,MAAM,CAAC,CAAC,CAAC;oBAClF,MAAM,MAAM,GAAG,iBAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBACxC,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC;gBACF,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.vfs = vfs;
|
|
40
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
41
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
42
|
+
function fileArrayToString(bufferArray) {
|
|
43
|
+
return Array.from(bufferArray)
|
|
44
|
+
.map((item) => String.fromCharCode(item))
|
|
45
|
+
.join("");
|
|
46
|
+
}
|
|
47
|
+
function isValidReadEvent(e) {
|
|
48
|
+
return typeof e?.path === "string";
|
|
49
|
+
}
|
|
50
|
+
function isValidReadManyEvent(e) {
|
|
51
|
+
return Array.isArray(e?.paths) && e.paths.every((s) => typeof s === "string");
|
|
52
|
+
}
|
|
53
|
+
function isValidWriteEvent(e) {
|
|
54
|
+
return typeof e?.path === "string" && Array.isArray(e?.content);
|
|
55
|
+
}
|
|
56
|
+
async function exists(event) {
|
|
57
|
+
if (!isValidReadEvent(event))
|
|
58
|
+
throw new Error("invalid read event");
|
|
59
|
+
try {
|
|
60
|
+
await fs.stat(event.path);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function readFile(event) {
|
|
68
|
+
if (!isValidReadEvent(event))
|
|
69
|
+
throw new Error("invalid read event");
|
|
70
|
+
return fileArrayToString(await fs.readFile(event.path));
|
|
71
|
+
}
|
|
72
|
+
async function readFiles(event) {
|
|
73
|
+
if (!isValidReadManyEvent(event))
|
|
74
|
+
throw new Error("invalid read event");
|
|
75
|
+
const files = await Promise.all(event.paths.map(async (p) => {
|
|
76
|
+
try {
|
|
77
|
+
return fs.readFile(p);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.warn(err);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
return Object.fromEntries(files.reduce((acc, f, i) => {
|
|
85
|
+
if (f === null)
|
|
86
|
+
return acc;
|
|
87
|
+
return acc.concat([[event.paths[i], fileArrayToString(f)]]);
|
|
88
|
+
}, []));
|
|
89
|
+
}
|
|
90
|
+
async function writeFile(event) {
|
|
91
|
+
if (!isValidWriteEvent(event))
|
|
92
|
+
throw new Error("invalid write event");
|
|
93
|
+
const dir = node_path_1.default.dirname(event.path);
|
|
94
|
+
if (dir !== ".")
|
|
95
|
+
await fs.mkdir(dir, { recursive: true });
|
|
96
|
+
return fs.writeFile(event.path, Uint8Array.from(event.content));
|
|
97
|
+
}
|
|
98
|
+
function vfs(action, data) {
|
|
99
|
+
if (action === "vfs/exists")
|
|
100
|
+
return exists(data);
|
|
101
|
+
if (action === "vfs/readFile")
|
|
102
|
+
return readFile(data);
|
|
103
|
+
if (action === "vfs/readFiles")
|
|
104
|
+
return readFiles(data);
|
|
105
|
+
if (action === "vfs/writeFile")
|
|
106
|
+
return writeFile(data);
|
|
107
|
+
throw new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,GAAG,GAAG,mBAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,GAAG,KAAK,GAAG;QAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,OAAO,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,GAAG,CAAC,MAAc,EAAE,IAAa;IAC/C,IAAI,MAAM,KAAK,YAAY;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,cAAc;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,MAAM,KAAK,eAAe;QAAE,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,MAAM,KAAK,eAAe;QAAE,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../../src/index.ts","../../../src/sdkproxy.ts","../../../src/vfs.ts","../../../../common/src/sdkproxyhelpers.ts"],"version":"5.9.2"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ClarityValue } from "@stacks/transactions";
|
|
2
|
+
export type ClarityEvent = {
|
|
3
|
+
event: string;
|
|
4
|
+
data: {
|
|
5
|
+
raw_value?: string;
|
|
6
|
+
value?: ClarityValue;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type ExecutionCost = {
|
|
11
|
+
writeLength: number;
|
|
12
|
+
writeCount: number;
|
|
13
|
+
readLength: number;
|
|
14
|
+
readCount: number;
|
|
15
|
+
runtime: number;
|
|
16
|
+
};
|
|
17
|
+
export type ClarityCosts = {
|
|
18
|
+
total: ExecutionCost;
|
|
19
|
+
limit: ExecutionCost;
|
|
20
|
+
memory: number;
|
|
21
|
+
memory_limit: number;
|
|
22
|
+
};
|
|
23
|
+
export type ParsedTransactionResult = {
|
|
24
|
+
result: ClarityValue;
|
|
25
|
+
events: ClarityEvent[];
|
|
26
|
+
costs: ClarityCosts | null;
|
|
27
|
+
performance: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export type CallFn = (contract: string, method: string, args: ClarityValue[], sender: string) => ParsedTransactionResult;
|
|
30
|
+
export type DeployContractOptions = {
|
|
31
|
+
clarityVersion: 1 | 2 | 3 | 4;
|
|
32
|
+
};
|
|
33
|
+
export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string) => ParsedTransactionResult;
|
|
34
|
+
export type TransferSTX = (amount: number | bigint, recipient: string, sender: string) => ParsedTransactionResult;
|
|
35
|
+
export type Tx = {
|
|
36
|
+
callPublicFn: {
|
|
37
|
+
contract: string;
|
|
38
|
+
method: string;
|
|
39
|
+
args: ClarityValue[];
|
|
40
|
+
sender: string;
|
|
41
|
+
};
|
|
42
|
+
callPrivateFn?: never;
|
|
43
|
+
deployContract?: never;
|
|
44
|
+
transferSTX?: never;
|
|
45
|
+
} | {
|
|
46
|
+
callPublicFn?: never;
|
|
47
|
+
callPrivateFn: {
|
|
48
|
+
contract: string;
|
|
49
|
+
method: string;
|
|
50
|
+
args: ClarityValue[];
|
|
51
|
+
sender: string;
|
|
52
|
+
};
|
|
53
|
+
deployContract?: never;
|
|
54
|
+
transferSTX?: never;
|
|
55
|
+
} | {
|
|
56
|
+
callPublicFn?: never;
|
|
57
|
+
callPrivateFn?: never;
|
|
58
|
+
deployContract: {
|
|
59
|
+
name: string;
|
|
60
|
+
content: string;
|
|
61
|
+
options: DeployContractOptions | null;
|
|
62
|
+
sender: string;
|
|
63
|
+
};
|
|
64
|
+
transferSTX?: never;
|
|
65
|
+
} | {
|
|
66
|
+
callPublicFn?: never;
|
|
67
|
+
callPrivateFn?: never;
|
|
68
|
+
deployContradct?: never;
|
|
69
|
+
transferSTX: {
|
|
70
|
+
amount: number;
|
|
71
|
+
recipient: string;
|
|
72
|
+
sender: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare const tx: {
|
|
76
|
+
callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
77
|
+
callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
78
|
+
deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string) => Tx;
|
|
79
|
+
transferSTX: (amount: number, recipient: string, sender: string) => Tx;
|
|
80
|
+
};
|
|
81
|
+
export declare function parseEvents(events: string): ClarityEvent[];
|
|
82
|
+
export declare function parseCosts(costs: string): ClarityCosts | null;
|
|
83
|
+
export type MineBlock = (txs: Array<Tx>) => ParsedTransactionResult[];
|
|
84
|
+
export type Execute = (snippet: string) => ParsedTransactionResult;
|
|
85
|
+
export type GetDataVar = (contract: string, dataVar: string) => ClarityValue;
|
|
86
|
+
export type GetMapEntry = (contract: string, mapName: string, mapKey: ClarityValue) => ClarityValue;
|