@aboutcircles/sdk-runner 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/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @aboutcircles/sdk-runner
2
+
3
+ Safe multisig wallet integration for executing blockchain operations with the Circles SDK.
4
+
5
+ ## Overview
6
+
7
+ This package provides the `SafeContractRunner` implementation for executing transactions through Safe multisig wallets. It handles transaction batching, signing, and confirmation, making it easy to interact with Circles protocol using Safe wallets.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @aboutcircles/sdk-runner
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### SafeContractRunner
18
+
19
+ The `SafeContractRunner` executes transactions through a Safe multisig wallet.
20
+
21
+ ```typescript
22
+ import { createPublicClient, http } from 'viem';
23
+ import { gnosis } from 'viem/chains';
24
+ import { SafeContractRunner } from '@aboutcircles/sdk-runner';
25
+
26
+ // Create a public client
27
+ const publicClient = createPublicClient({
28
+ chain: gnosis,
29
+ transport: http('https://rpc.gnosischain.com'),
30
+ });
31
+
32
+ // Create the runner
33
+ const runner = new SafeContractRunner(
34
+ publicClient,
35
+ '0x...', // private key of Safe signer
36
+ 'https://rpc.gnosischain.com',
37
+ '0x...' // Safe address
38
+ );
39
+
40
+ // Initialize the runner
41
+ await runner.init();
42
+
43
+ // Send a single transaction
44
+ const receipt = await runner.sendTransaction([{
45
+ to: '0x...',
46
+ data: '0x...',
47
+ value: 0n,
48
+ }]);
49
+
50
+ console.log('Transaction hash:', receipt.transactionHash);
51
+ console.log('Status:', receipt.status);
52
+ console.log('Gas used:', receipt.gasUsed);
53
+
54
+ // Batch multiple transactions atomically
55
+ const batchReceipt = await runner.sendTransaction([
56
+ { to: '0x...', data: '0x...', value: 0n },
57
+ { to: '0x...', data: '0x...', value: 0n },
58
+ { to: '0x...', data: '0x...', value: 0n },
59
+ ]);
60
+ ```
61
+
62
+ ## Features
63
+
64
+ - **Transaction Confirmation**: Automatically waits for transactions to be mined
65
+ - **Status Checking**: Throws errors if transactions revert
66
+ - **Atomic Batching**: Execute multiple transactions in a single Safe transaction
67
+ - **Full Receipt Data**: Returns complete viem TransactionReceipt with gas, logs, etc.
68
+
69
+ ## API
70
+
71
+ ### ContractRunner Interface
72
+
73
+ ```typescript
74
+ interface ContractRunner {
75
+ address?: Address;
76
+ publicClient: PublicClient;
77
+
78
+ init(): Promise<void>;
79
+ estimateGas?(tx: TransactionRequest): Promise<bigint>;
80
+ call?(tx: TransactionRequest): Promise<string>;
81
+ resolveName?(name: string): Promise<string | null>;
82
+ sendTransaction?(txs: TransactionRequest[]): Promise<TransactionResponse>;
83
+ sendBatchTransaction?(): BatchRun;
84
+ }
85
+ ```
86
+
87
+ ### SafeContractRunner
88
+
89
+ ```typescript
90
+ class SafeContractRunner implements ContractRunner {
91
+ constructor(
92
+ publicClient: PublicClient,
93
+ privateKey: Hex,
94
+ rpcUrl: string,
95
+ safeAddress?: Address
96
+ );
97
+
98
+ init(safeAddress?: Address): Promise<void>;
99
+ sendTransaction(txs: TransactionRequest[]): Promise<TransactionResponse>;
100
+ sendBatchTransaction(): SafeBatchRun;
101
+ }
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Runner Package Error Types
3
+ */
4
+ import { CirclesError } from '@aboutcircles/sdk-utils';
5
+ /**
6
+ * Runner-specific error sources
7
+ */
8
+ export type RunnerErrorSource = 'RUNNER' | 'RUNNER_INITIALIZATION' | 'TRANSACTION_EXECUTION' | 'WALLET' | 'SAFE';
9
+ /**
10
+ * Runner and transaction execution errors
11
+ */
12
+ export declare class RunnerError extends CirclesError<RunnerErrorSource> {
13
+ constructor(message: string, options?: {
14
+ code?: string | number;
15
+ source?: RunnerErrorSource;
16
+ cause?: unknown;
17
+ context?: Record<string, any>;
18
+ });
19
+ /**
20
+ * Create error for initialization failures
21
+ */
22
+ static initializationFailed(runnerType: string, cause?: unknown): RunnerError;
23
+ /**
24
+ * Create error for transaction execution failures
25
+ */
26
+ static executionFailed(reason: string, cause?: unknown): RunnerError;
27
+ /**
28
+ * Create error for wallet-related issues
29
+ */
30
+ static walletError(message: string, cause?: unknown): RunnerError;
31
+ /**
32
+ * Create error for Safe-specific issues
33
+ */
34
+ static safeError(message: string, safeAddress: string, cause?: unknown): RunnerError;
35
+ /**
36
+ * Create error for missing signer
37
+ */
38
+ static missingSigner(): RunnerError;
39
+ /**
40
+ * Create error for transaction timeout
41
+ */
42
+ static timeout(txHash: string, timeout: number): RunnerError;
43
+ /**
44
+ * Create error for reverted transactions
45
+ */
46
+ static transactionReverted(txHash: string, blockNumber: bigint, gasUsed: bigint, cause?: unknown): RunnerError;
47
+ }
48
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,uBAAuB,GACvB,uBAAuB,GACvB,QAAQ,GACR,MAAM,CAAC;AAEX;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,iBAAiB,CAAC;gBAE5D,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,iBAAiB,CAAC;QAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC/B;IAKH;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IAS7E;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IASpE;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IAQjE;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IASpF;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,WAAW;IAOnC;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW;IAQ5D;;OAEG;IACH,MAAM,CAAC,mBAAmB,CACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GACd,WAAW;CAYf"}
package/dist/errors.js ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Runner Package Error Types
3
+ */
4
+ import { CirclesError } from '@aboutcircles/sdk-utils';
5
+ /**
6
+ * Runner and transaction execution errors
7
+ */
8
+ export class RunnerError extends CirclesError {
9
+ constructor(message, options) {
10
+ super('RunnerError', message, { ...options, source: options?.source ?? 'RUNNER' });
11
+ }
12
+ /**
13
+ * Create error for initialization failures
14
+ */
15
+ static initializationFailed(runnerType, cause) {
16
+ return new RunnerError(`Failed to initialize ${runnerType}`, {
17
+ code: 'RUNNER_INIT_FAILED',
18
+ source: 'RUNNER_INITIALIZATION',
19
+ cause,
20
+ context: { runnerType },
21
+ });
22
+ }
23
+ /**
24
+ * Create error for transaction execution failures
25
+ */
26
+ static executionFailed(reason, cause) {
27
+ return new RunnerError(`Transaction execution failed: ${reason}`, {
28
+ code: 'RUNNER_EXECUTION_FAILED',
29
+ source: 'TRANSACTION_EXECUTION',
30
+ cause,
31
+ context: { reason },
32
+ });
33
+ }
34
+ /**
35
+ * Create error for wallet-related issues
36
+ */
37
+ static walletError(message, cause) {
38
+ return new RunnerError(message, {
39
+ code: 'RUNNER_WALLET_ERROR',
40
+ source: 'WALLET',
41
+ cause,
42
+ });
43
+ }
44
+ /**
45
+ * Create error for Safe-specific issues
46
+ */
47
+ static safeError(message, safeAddress, cause) {
48
+ return new RunnerError(message, {
49
+ code: 'RUNNER_SAFE_ERROR',
50
+ source: 'SAFE',
51
+ cause,
52
+ context: { safeAddress },
53
+ });
54
+ }
55
+ /**
56
+ * Create error for missing signer
57
+ */
58
+ static missingSigner() {
59
+ return new RunnerError('Signer is required for this operation', {
60
+ code: 'RUNNER_MISSING_SIGNER',
61
+ source: 'WALLET',
62
+ });
63
+ }
64
+ /**
65
+ * Create error for transaction timeout
66
+ */
67
+ static timeout(txHash, timeout) {
68
+ return new RunnerError('Transaction timed out', {
69
+ code: 'RUNNER_TX_TIMEOUT',
70
+ source: 'TRANSACTION_EXECUTION',
71
+ context: { txHash, timeout },
72
+ });
73
+ }
74
+ /**
75
+ * Create error for reverted transactions
76
+ */
77
+ static transactionReverted(txHash, blockNumber, gasUsed, cause) {
78
+ return new RunnerError('Transaction reverted', {
79
+ code: 'RUNNER_TX_REVERTED',
80
+ source: 'TRANSACTION_EXECUTION',
81
+ cause,
82
+ context: {
83
+ transactionHash: txHash,
84
+ blockNumber: blockNumber.toString(),
85
+ gasUsed: gasUsed.toString(),
86
+ },
87
+ });
88
+ }
89
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @aboutcircles/sdk-runner
3
+ *
4
+ * Contract runner implementations for executing blockchain operations.
5
+ * Provides Safe multisig wallet integration for transaction execution.
6
+ */
7
+ export type { ContractRunner, BatchRun } from './runner';
8
+ export { SafeContractRunner, SafeBatchRun } from './safe-runner';
9
+ export { SafeBrowserRunner, SafeBrowserBatchRun } from './safe-browser-runner';
10
+ export { RunnerError } from './errors';
11
+ export type { RunnerErrorSource } from './errors';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}