@brninpay/evm 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.
@@ -0,0 +1,4 @@
1
+
2
+ > @brninpay/evm@0.1.0 build /home/runner/work/brninpay/brninpay/packages/evm
3
+ > tsc
4
+
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2026 Runtimee Authors
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @runtimee/evm
2
+
3
+ EVM execution adapter for Runtimee.
4
+
5
+ Implements the ExecutionProvider interface for Base + USDC.
6
+
7
+ Includes: transaction building, gas estimation, broadcasting, receipt waiting.
@@ -0,0 +1,6 @@
1
+ import type { Broadcaster } from './types.js';
2
+ export interface BroadcasterConfig {
3
+ rpcUrl: string;
4
+ }
5
+ export declare function createViemBroadcaster(config: BroadcasterConfig): Broadcaster;
6
+ //# sourceMappingURL=broadcaster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcaster.d.ts","sourceRoot":"","sources":["../src/broadcaster.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAuC5E"}
@@ -0,0 +1,40 @@
1
+ import { createPublicClient, http } from 'viem';
2
+ import { base } from 'viem/chains';
3
+ export function createViemBroadcaster(config) {
4
+ const publicClient = createPublicClient({
5
+ chain: base,
6
+ transport: http(config.rpcUrl),
7
+ });
8
+ return {
9
+ async sendRawTransaction(signedTx) {
10
+ const hash = await publicClient.request({
11
+ method: 'eth_sendRawTransaction',
12
+ params: [signedTx],
13
+ });
14
+ return hash;
15
+ },
16
+ async getTransactionReceipt(txHash) {
17
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
18
+ if (!receipt)
19
+ return null;
20
+ return {
21
+ status: receipt.status === 'success' ? 'success' : 'reverted',
22
+ blockNumber: receipt.blockNumber,
23
+ gasUsed: receipt.gasUsed,
24
+ effectiveGasPrice: receipt.effectiveGasPrice,
25
+ };
26
+ },
27
+ async getTransactionCount(address) {
28
+ return publicClient.getTransactionCount({ address });
29
+ },
30
+ async estimateGas(tx) {
31
+ return publicClient.estimateGas({
32
+ account: tx.from,
33
+ to: tx.to,
34
+ data: tx.data,
35
+ value: tx.value,
36
+ });
37
+ },
38
+ };
39
+ }
40
+ //# sourceMappingURL=broadcaster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcaster.js","sourceRoot":"","sources":["../src/broadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAOlC,MAAM,UAAU,qBAAqB,CAAC,MAAyB;IAC7D,MAAM,YAAY,GAAG,kBAAkB,CAAC;QACtC,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;KAC/B,CAAC,CAAA;IAEF,OAAO;QACL,KAAK,CAAC,kBAAkB,CAAC,QAAQ;YAC/B,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC;gBACtC,MAAM,EAAE,wBAAwB;gBAChC,MAAM,EAAE,CAAC,QAAQ,CAAC;aACnB,CAAC,CAAA;YACF,OAAO,IAAI,CAAA;QACb,CAAC;QAED,KAAK,CAAC,qBAAqB,CAAC,MAAM;YAChC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;YAC1E,IAAI,CAAC,OAAO;gBAAE,OAAO,IAAI,CAAA;YACzB,OAAO;gBACL,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU;gBAC7D,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;aAC7C,CAAA;QACH,CAAC;QAED,KAAK,CAAC,mBAAmB,CAAC,OAAO;YAC/B,OAAO,YAAY,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QACtD,CAAC;QAED,KAAK,CAAC,WAAW,CAAC,EAAE;YAClB,OAAO,YAAY,CAAC,WAAW,CAAC;gBAC9B,OAAO,EAAE,EAAE,CAAC,IAAI;gBAChB,EAAE,EAAE,EAAE,CAAC,EAAE;gBACT,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,KAAK,EAAE,EAAE,CAAC,KAAK;aAChB,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ExecutionProvider, Signer } from './types.js';
2
+ import type { BroadcasterConfig } from './broadcaster.js';
3
+ export interface EVMProviderConfig extends BroadcasterConfig {
4
+ signerAddress: `0x${string}`;
5
+ }
6
+ export declare function createEVMProvider(config: EVMProviderConfig, signer?: Signer): ExecutionProvider;
7
+ //# sourceMappingURL=evm-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm-provider.d.ts","sourceRoot":"","sources":["../src/evm-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAKzD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,aAAa,EAAE,KAAK,MAAM,EAAE,CAAA;CAC7B;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,iBAAiB,EACzB,MAAM,CAAC,EAAE,MAAM,GACd,iBAAiB,CAuEnB"}
@@ -0,0 +1,69 @@
1
+ import { createViemBroadcaster } from './broadcaster.js';
2
+ import { estimateGasWithBuffer } from './gas-strategy.js';
3
+ import { buildEvmTransaction } from './transaction-builder.js';
4
+ export function createEVMProvider(config, signer) {
5
+ const broadcaster = createViemBroadcaster(config);
6
+ const chainId = 8453;
7
+ return {
8
+ async simulate(intent) {
9
+ return {
10
+ decision: 'approved',
11
+ policyResults: [],
12
+ estimatedGas: 100000n,
13
+ estimatedCost: intent.amount,
14
+ };
15
+ },
16
+ async sign(executionPlan) {
17
+ if (!signer) {
18
+ throw new Error('No signer configured. Cannot sign transactions.');
19
+ }
20
+ const auth = executionPlan.authorization;
21
+ const nonce = await broadcaster.getTransactionCount(config.signerAddress);
22
+ const gasEstimate = await broadcaster.estimateGas({
23
+ to: config.signerAddress,
24
+ data: '0x',
25
+ value: 0n,
26
+ from: config.signerAddress,
27
+ });
28
+ const gasLimit = estimateGasWithBuffer(gasEstimate);
29
+ const tx = buildEvmTransaction({
30
+ to: auth.intent.target,
31
+ from: config.signerAddress,
32
+ amount: auth.intent.amount,
33
+ chainId,
34
+ nonce,
35
+ gasLimit,
36
+ });
37
+ const serialized = await signer.signTransaction({
38
+ to: tx.to,
39
+ data: tx.data,
40
+ value: tx.value,
41
+ chainId: tx.chainId,
42
+ gasLimit: tx.gasLimit,
43
+ nonce: tx.nonce,
44
+ maxFeePerGas: tx.maxFeePerGas,
45
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
46
+ });
47
+ return { serialized, hash: '0x0000000000000000000000000000000000000000000000000000000000000000' };
48
+ },
49
+ async broadcast(signed) {
50
+ return broadcaster.sendRawTransaction(signed.serialized);
51
+ },
52
+ async wait(txHash, confirmations = 12) {
53
+ while (true) {
54
+ const receipt = await broadcaster.getTransactionReceipt(txHash);
55
+ if (receipt && receipt.blockNumber > 0n) {
56
+ return {
57
+ txHash,
58
+ status: receipt.status === 'success' ? 'confirmed' : 'failed',
59
+ blockNumber: receipt.blockNumber,
60
+ gasUsed: receipt.gasUsed,
61
+ effectiveGasPrice: receipt.effectiveGasPrice,
62
+ };
63
+ }
64
+ await new Promise((r) => setTimeout(r, 2000));
65
+ }
66
+ },
67
+ };
68
+ }
69
+ //# sourceMappingURL=evm-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm-provider.js","sourceRoot":"","sources":["../src/evm-provider.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export declare function estimateGasWithBuffer(estimatedGas: bigint): bigint;
2
+ //# sourceMappingURL=gas-strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-strategy.d.ts","sourceRoot":"","sources":["../src/gas-strategy.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAIlE"}
@@ -0,0 +1,7 @@
1
+ export function estimateGasWithBuffer(estimatedGas) {
2
+ if (estimatedGas === 0n)
3
+ return 0n;
4
+ // ceil(estimatedGas * 1.2) = ceil(estimatedGas * 6 / 5)
5
+ return (estimatedGas * 6n + 4n) / 5n;
6
+ }
7
+ //# sourceMappingURL=gas-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-strategy.js","sourceRoot":"","sources":["../src/gas-strategy.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB,CAAC,YAAoB;IACxD,IAAI,YAAY,KAAK,EAAE;QAAE,OAAO,EAAE,CAAA;IAClC,wDAAwD;IACxD,OAAO,CAAC,YAAY,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAA;AACtC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type { ExecutionProvider, Signer, Broadcaster } from './types.js';
2
+ export { USDC_DECIMALS, USDC_ADDRESS_BASE, USDC_ABI } from './types.js';
3
+ export { encodeUsdcTransfer, buildEvmTransaction } from './transaction-builder.js';
4
+ export type { BuildTxParams, EvmTransaction } from './transaction-builder.js';
5
+ export { estimateGasWithBuffer } from './gas-strategy.js';
6
+ export { createViemBroadcaster } from './broadcaster.js';
7
+ export type { BroadcasterConfig } from './broadcaster.js';
8
+ export { createEVMProvider } from './evm-provider.js';
9
+ export type { EVMProviderConfig } from './evm-provider.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAClF,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { USDC_DECIMALS, USDC_ADDRESS_BASE, USDC_ABI } from './types.js';
2
+ export { encodeUsdcTransfer, buildEvmTransaction } from './transaction-builder.js';
3
+ export { estimateGasWithBuffer } from './gas-strategy.js';
4
+ export { createViemBroadcaster } from './broadcaster.js';
5
+ export { createEVMProvider } from './evm-provider.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,23 @@
1
+ export interface BuildTxParams {
2
+ to: `0x${string}`;
3
+ from: `0x${string}`;
4
+ amount: bigint;
5
+ chainId: number;
6
+ nonce: number;
7
+ gasLimit: bigint;
8
+ maxFeePerGas?: bigint;
9
+ maxPriorityFeePerGas?: bigint;
10
+ }
11
+ export interface EvmTransaction {
12
+ to: `0x${string}`;
13
+ data: `0x${string}`;
14
+ value: bigint;
15
+ chainId: number;
16
+ nonce: number;
17
+ gasLimit: bigint;
18
+ maxFeePerGas?: bigint;
19
+ maxPriorityFeePerGas?: bigint;
20
+ }
21
+ export declare function encodeUsdcTransfer(recipient: `0x${string}`, amount: bigint): `0x${string}`;
22
+ export declare function buildEvmTransaction(params: BuildTxParams): EvmTransaction;
23
+ //# sourceMappingURL=transaction-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-builder.d.ts","sourceRoot":"","sources":["../src/transaction-builder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,KAAK,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,KAAK,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,KAAK,MAAM,EAAE,EACxB,MAAM,EAAE,MAAM,GACb,KAAK,MAAM,EAAE,CAMf;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAYzE"}
@@ -0,0 +1,23 @@
1
+ import { encodeFunctionData } from 'viem';
2
+ import { USDC_ADDRESS_BASE, USDC_ABI } from './types.js';
3
+ export function encodeUsdcTransfer(recipient, amount) {
4
+ return encodeFunctionData({
5
+ abi: USDC_ABI,
6
+ functionName: 'transfer',
7
+ args: [recipient, amount],
8
+ });
9
+ }
10
+ export function buildEvmTransaction(params) {
11
+ const data = encodeUsdcTransfer(params.to, params.amount);
12
+ return {
13
+ to: USDC_ADDRESS_BASE,
14
+ data,
15
+ value: 0n,
16
+ chainId: params.chainId,
17
+ nonce: params.nonce,
18
+ gasLimit: params.gasLimit,
19
+ maxFeePerGas: params.maxFeePerGas,
20
+ maxPriorityFeePerGas: params.maxPriorityFeePerGas,
21
+ };
22
+ }
23
+ //# sourceMappingURL=transaction-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-builder.js","sourceRoot":"","sources":["../src/transaction-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAwBxD,MAAM,UAAU,kBAAkB,CAChC,SAAwB,EACxB,MAAc;IAEd,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,QAAQ;QACb,YAAY,EAAE,UAAU;QACxB,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACzD,OAAO;QACL,EAAE,EAAE,iBAAiB;QACrB,IAAI;QACJ,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;KAClD,CAAA;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { Intent, ExecutionPlan, SignedTransaction, Receipt, SimulationResult } from '@brninpay/core';
2
+ export interface ExecutionProvider {
3
+ simulate(intent: Intent): Promise<SimulationResult>;
4
+ sign(executionPlan: ExecutionPlan): Promise<SignedTransaction>;
5
+ broadcast(signed: SignedTransaction): Promise<`0x${string}`>;
6
+ wait(txHash: `0x${string}`, confirmations?: number): Promise<Receipt>;
7
+ }
8
+ export interface Signer {
9
+ signTransaction(tx: {
10
+ to: `0x${string}`;
11
+ data: `0x${string}`;
12
+ value: bigint;
13
+ chainId: number;
14
+ gasLimit: bigint;
15
+ maxFeePerGas?: bigint;
16
+ maxPriorityFeePerGas?: bigint;
17
+ nonce: number;
18
+ }): Promise<`0x${string}`>;
19
+ }
20
+ export interface Broadcaster {
21
+ sendRawTransaction(signedTx: `0x${string}`): Promise<`0x${string}`>;
22
+ getTransactionReceipt(txHash: `0x${string}`): Promise<{
23
+ status: 'success' | 'reverted';
24
+ blockNumber: bigint;
25
+ gasUsed: bigint;
26
+ effectiveGasPrice: bigint;
27
+ } | null>;
28
+ getTransactionCount(address: `0x${string}`): Promise<number>;
29
+ estimateGas(tx: {
30
+ to: `0x${string}`;
31
+ data: `0x${string}`;
32
+ value: bigint;
33
+ from: `0x${string}`;
34
+ }): Promise<bigint>;
35
+ }
36
+ export declare const USDC_DECIMALS = 6;
37
+ export declare const USDC_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
38
+ export declare const USDC_ABI: readonly [{
39
+ readonly name: "transfer";
40
+ readonly type: "function";
41
+ readonly inputs: readonly [{
42
+ readonly name: "to";
43
+ readonly type: "address";
44
+ }, {
45
+ readonly name: "value";
46
+ readonly type: "uint256";
47
+ }];
48
+ readonly outputs: readonly [{
49
+ readonly name: "";
50
+ readonly type: "bool";
51
+ }];
52
+ readonly stateMutability: "nonpayable";
53
+ }];
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEzG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IACnD,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC9D,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;IAC5D,IAAI,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACtE;AAED,MAAM,WAAW,MAAM;IACrB,eAAe,CAAC,EAAE,EAAE;QAClB,EAAE,EAAE,KAAK,MAAM,EAAE,CAAA;QACjB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;QACnB,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,oBAAoB,CAAC,EAAE,MAAM,CAAA;QAC7B,KAAK,EAAE,MAAM,CAAA;KACd,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,kBAAkB,CAAC,QAAQ,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;IACnE,qBAAqB,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC;QACpD,MAAM,EAAE,SAAS,GAAG,UAAU,CAAA;QAC9B,WAAW,EAAE,MAAM,CAAA;QACnB,OAAO,EAAE,MAAM,CAAA;QACf,iBAAiB,EAAE,MAAM,CAAA;KAC1B,GAAG,IAAI,CAAC,CAAA;IACT,mBAAmB,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC5D,WAAW,CAAC,EAAE,EAAE;QAAE,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACjH;AAED,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,iBAAiB,+CAA+C,CAAA;AAE7E,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;EAWX,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,15 @@
1
+ export const USDC_DECIMALS = 6;
2
+ export const USDC_ADDRESS_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
3
+ export const USDC_ABI = [
4
+ {
5
+ name: 'transfer',
6
+ type: 'function',
7
+ inputs: [
8
+ { name: 'to', type: 'address' },
9
+ { name: 'value', type: 'uint256' },
10
+ ],
11
+ outputs: [{ name: '', type: 'bool' }],
12
+ stateMutability: 'nonpayable',
13
+ },
14
+ ];
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAkCA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA;AAC9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,4CAA4C,CAAA;AAE7E,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;YAC/B,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;SACnC;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACrC,eAAe,EAAE,YAAY;KAC9B;CACO,CAAA"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@brninpay/evm",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "viem": "^2.21.0",
15
+ "@brninpay/core": "0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^25.9.1",
19
+ "rimraf": "^6.0.0",
20
+ "typescript": "^5.5.0",
21
+ "vitest": "^2.0.0"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "clean": "rimraf dist tsconfig.tsbuildinfo",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "typecheck": "tsc --noEmit"
29
+ }
30
+ }
@@ -0,0 +1,48 @@
1
+ import { createPublicClient, http } from 'viem'
2
+ import { base } from 'viem/chains'
3
+ import type { Broadcaster } from './types.js'
4
+
5
+ export interface BroadcasterConfig {
6
+ rpcUrl: string
7
+ }
8
+
9
+ export function createViemBroadcaster(config: BroadcasterConfig): Broadcaster {
10
+ const publicClient = createPublicClient({
11
+ chain: base,
12
+ transport: http(config.rpcUrl),
13
+ })
14
+
15
+ return {
16
+ async sendRawTransaction(signedTx) {
17
+ const hash = await publicClient.request({
18
+ method: 'eth_sendRawTransaction',
19
+ params: [signedTx],
20
+ })
21
+ return hash
22
+ },
23
+
24
+ async getTransactionReceipt(txHash) {
25
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash })
26
+ if (!receipt) return null
27
+ return {
28
+ status: receipt.status === 'success' ? 'success' : 'reverted',
29
+ blockNumber: receipt.blockNumber,
30
+ gasUsed: receipt.gasUsed,
31
+ effectiveGasPrice: receipt.effectiveGasPrice,
32
+ }
33
+ },
34
+
35
+ async getTransactionCount(address) {
36
+ return publicClient.getTransactionCount({ address })
37
+ },
38
+
39
+ async estimateGas(tx) {
40
+ return publicClient.estimateGas({
41
+ account: tx.from,
42
+ to: tx.to,
43
+ data: tx.data,
44
+ value: tx.value,
45
+ })
46
+ },
47
+ }
48
+ }
@@ -0,0 +1,86 @@
1
+ import type { Intent, ExecutionPlan, SignedTransaction, Receipt, SimulationResult } from '@brninpay/core'
2
+ import type { ExecutionProvider, Signer } from './types.js'
3
+ import type { BroadcasterConfig } from './broadcaster.js'
4
+ import { createViemBroadcaster } from './broadcaster.js'
5
+ import { estimateGasWithBuffer } from './gas-strategy.js'
6
+ import { buildEvmTransaction } from './transaction-builder.js'
7
+
8
+ export interface EVMProviderConfig extends BroadcasterConfig {
9
+ signerAddress: `0x${string}`
10
+ }
11
+
12
+ export function createEVMProvider(
13
+ config: EVMProviderConfig,
14
+ signer?: Signer
15
+ ): ExecutionProvider {
16
+ const broadcaster = createViemBroadcaster(config)
17
+ const chainId = 8453
18
+
19
+ return {
20
+ async simulate(intent: Intent): Promise<SimulationResult> {
21
+ return {
22
+ decision: 'approved',
23
+ policyResults: [],
24
+ estimatedGas: 100000n,
25
+ estimatedCost: intent.amount,
26
+ }
27
+ },
28
+
29
+ async sign(executionPlan: ExecutionPlan): Promise<SignedTransaction> {
30
+ if (!signer) {
31
+ throw new Error('No signer configured. Cannot sign transactions.')
32
+ }
33
+ const auth = executionPlan.authorization
34
+ const nonce = await broadcaster.getTransactionCount(config.signerAddress)
35
+ const gasEstimate = await broadcaster.estimateGas({
36
+ to: config.signerAddress,
37
+ data: '0x' as `0x${string}`,
38
+ value: 0n,
39
+ from: config.signerAddress,
40
+ })
41
+ const gasLimit = estimateGasWithBuffer(gasEstimate)
42
+
43
+ const tx = buildEvmTransaction({
44
+ to: auth.intent.target as `0x${string}`,
45
+ from: config.signerAddress,
46
+ amount: auth.intent.amount,
47
+ chainId,
48
+ nonce,
49
+ gasLimit,
50
+ })
51
+
52
+ const serialized = await signer.signTransaction({
53
+ to: tx.to,
54
+ data: tx.data,
55
+ value: tx.value,
56
+ chainId: tx.chainId,
57
+ gasLimit: tx.gasLimit,
58
+ nonce: tx.nonce,
59
+ maxFeePerGas: tx.maxFeePerGas,
60
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
61
+ })
62
+
63
+ return { serialized, hash: '0x0000000000000000000000000000000000000000000000000000000000000000' as `0x${string}` }
64
+ },
65
+
66
+ async broadcast(signed: SignedTransaction): Promise<`0x${string}`> {
67
+ return broadcaster.sendRawTransaction(signed.serialized)
68
+ },
69
+
70
+ async wait(txHash: `0x${string}`, confirmations = 12): Promise<Receipt> {
71
+ while (true) {
72
+ const receipt = await broadcaster.getTransactionReceipt(txHash)
73
+ if (receipt && receipt.blockNumber > 0n) {
74
+ return {
75
+ txHash,
76
+ status: receipt.status === 'success' ? 'confirmed' : 'failed',
77
+ blockNumber: receipt.blockNumber,
78
+ gasUsed: receipt.gasUsed,
79
+ effectiveGasPrice: receipt.effectiveGasPrice,
80
+ }
81
+ }
82
+ await new Promise((r) => setTimeout(r, 2000))
83
+ }
84
+ },
85
+ }
86
+ }
@@ -0,0 +1,5 @@
1
+ export function estimateGasWithBuffer(estimatedGas: bigint): bigint {
2
+ if (estimatedGas === 0n) return 0n
3
+ // ceil(estimatedGas * 1.2) = ceil(estimatedGas * 6 / 5)
4
+ return (estimatedGas * 6n + 4n) / 5n
5
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type { ExecutionProvider, Signer, Broadcaster } from './types.js'
2
+ export { USDC_DECIMALS, USDC_ADDRESS_BASE, USDC_ABI } from './types.js'
3
+ export { encodeUsdcTransfer, buildEvmTransaction } from './transaction-builder.js'
4
+ export type { BuildTxParams, EvmTransaction } from './transaction-builder.js'
5
+ export { estimateGasWithBuffer } from './gas-strategy.js'
6
+ export { createViemBroadcaster } from './broadcaster.js'
7
+ export type { BroadcasterConfig } from './broadcaster.js'
8
+ export { createEVMProvider } from './evm-provider.js'
9
+ export type { EVMProviderConfig } from './evm-provider.js'
@@ -0,0 +1,49 @@
1
+ import { encodeFunctionData } from 'viem'
2
+ import { USDC_ADDRESS_BASE, USDC_ABI } from './types.js'
3
+
4
+ export interface BuildTxParams {
5
+ to: `0x${string}`
6
+ from: `0x${string}`
7
+ amount: bigint
8
+ chainId: number
9
+ nonce: number
10
+ gasLimit: bigint
11
+ maxFeePerGas?: bigint
12
+ maxPriorityFeePerGas?: bigint
13
+ }
14
+
15
+ export interface EvmTransaction {
16
+ to: `0x${string}`
17
+ data: `0x${string}`
18
+ value: bigint
19
+ chainId: number
20
+ nonce: number
21
+ gasLimit: bigint
22
+ maxFeePerGas?: bigint
23
+ maxPriorityFeePerGas?: bigint
24
+ }
25
+
26
+ export function encodeUsdcTransfer(
27
+ recipient: `0x${string}`,
28
+ amount: bigint
29
+ ): `0x${string}` {
30
+ return encodeFunctionData({
31
+ abi: USDC_ABI,
32
+ functionName: 'transfer',
33
+ args: [recipient, amount],
34
+ })
35
+ }
36
+
37
+ export function buildEvmTransaction(params: BuildTxParams): EvmTransaction {
38
+ const data = encodeUsdcTransfer(params.to, params.amount)
39
+ return {
40
+ to: USDC_ADDRESS_BASE,
41
+ data,
42
+ value: 0n,
43
+ chainId: params.chainId,
44
+ nonce: params.nonce,
45
+ gasLimit: params.gasLimit,
46
+ maxFeePerGas: params.maxFeePerGas,
47
+ maxPriorityFeePerGas: params.maxPriorityFeePerGas,
48
+ }
49
+ }
package/src/types.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { Intent, ExecutionPlan, SignedTransaction, Receipt, SimulationResult } from '@brninpay/core'
2
+
3
+ export interface ExecutionProvider {
4
+ simulate(intent: Intent): Promise<SimulationResult>
5
+ sign(executionPlan: ExecutionPlan): Promise<SignedTransaction>
6
+ broadcast(signed: SignedTransaction): Promise<`0x${string}`>
7
+ wait(txHash: `0x${string}`, confirmations?: number): Promise<Receipt>
8
+ }
9
+
10
+ export interface Signer {
11
+ signTransaction(tx: {
12
+ to: `0x${string}`
13
+ data: `0x${string}`
14
+ value: bigint
15
+ chainId: number
16
+ gasLimit: bigint
17
+ maxFeePerGas?: bigint
18
+ maxPriorityFeePerGas?: bigint
19
+ nonce: number
20
+ }): Promise<`0x${string}`>
21
+ }
22
+
23
+ export interface Broadcaster {
24
+ sendRawTransaction(signedTx: `0x${string}`): Promise<`0x${string}`>
25
+ getTransactionReceipt(txHash: `0x${string}`): Promise<{
26
+ status: 'success' | 'reverted'
27
+ blockNumber: bigint
28
+ gasUsed: bigint
29
+ effectiveGasPrice: bigint
30
+ } | null>
31
+ getTransactionCount(address: `0x${string}`): Promise<number>
32
+ estimateGas(tx: { to: `0x${string}`; data: `0x${string}`; value: bigint; from: `0x${string}` }): Promise<bigint>
33
+ }
34
+
35
+ export const USDC_DECIMALS = 6
36
+ export const USDC_ADDRESS_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
37
+
38
+ export const USDC_ABI = [
39
+ {
40
+ name: 'transfer',
41
+ type: 'function',
42
+ inputs: [
43
+ { name: 'to', type: 'address' },
44
+ { name: 'value', type: 'uint256' },
45
+ ],
46
+ outputs: [{ name: '', type: 'bool' }],
47
+ stateMutability: 'nonpayable',
48
+ },
49
+ ] as const
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { readFileSync, readdirSync, statSync } from 'fs'
3
+ import { join, relative } from 'path'
4
+
5
+ const SRC = join(import.meta.dirname, '../../src')
6
+
7
+ const forbiddenWorkspaceDeps = ['@brninpay/sdk', '@brninpay/node']
8
+
9
+ function walk(dir: string): string[] {
10
+ const files: string[] = []
11
+ try {
12
+ for (const entry of readdirSync(dir)) {
13
+ const full = join(dir, entry)
14
+ if (statSync(full).isDirectory()) {
15
+ files.push(...walk(full))
16
+ } else if (entry.endsWith('.ts') && !entry.endsWith('.d.ts')) {
17
+ files.push(full)
18
+ }
19
+ }
20
+ } catch { /* skip */ }
21
+ return files
22
+ }
23
+
24
+ function parseImports(source: string): string[] {
25
+ const imports: string[] = []
26
+ const re = /import(?: type)?\s+(?:\{[^}]*\}|[^'"]+)\s+from\s+['"]([^'"]+)['"]/g
27
+ let m
28
+ while ((m = re.exec(source)) !== null) imports.push(m[1])
29
+ return imports
30
+ }
31
+
32
+ describe('@brninpay/evm — adapter isolation invariants', () => {
33
+ const files = walk(SRC)
34
+ const wsViolations: { file: string; imp: string }[] = []
35
+
36
+ for (const file of files) {
37
+ const source = readFileSync(file, 'utf8')
38
+ const imports = parseImports(source)
39
+ const rel = relative(SRC, file)
40
+
41
+ for (const imp of imports) {
42
+ if (forbiddenWorkspaceDeps.some((d) => imp.startsWith(d))) {
43
+ wsViolations.push({ file: rel, imp })
44
+ }
45
+ }
46
+ }
47
+
48
+ it('must not import from @brninpay/sdk or @brninpay/node', () => {
49
+ expect(wsViolations, fmt('forbidden workspace imports', wsViolations)).toHaveLength(0)
50
+ })
51
+ })
52
+
53
+ function fmt(label: string, v: { file: string; imp: string }[]): string {
54
+ return v.length ? `\n\n${label}:\n${v.map((x) => ` ${x.file} → ${x.imp}`).join('\n')}` : ''
55
+ }
@@ -0,0 +1,45 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { USDC_ADDRESS_BASE, USDC_DECIMALS } from '../src/types.js'
3
+
4
+ describe('EVM types', () => {
5
+ it('USDC address on Base is valid hex', () => {
6
+ expect(USDC_ADDRESS_BASE).toMatch(/^0x[0-9a-fA-F]{40}$/)
7
+ })
8
+
9
+ it('USDC has 6 decimals', () => {
10
+ expect(USDC_DECIMALS).toBe(6)
11
+ })
12
+ })
13
+
14
+ import { estimateGasWithBuffer } from '../src/gas-strategy.js'
15
+ import { createEVMProvider } from '../src/evm-provider.js'
16
+ import type { Intent } from '@brninpay/core'
17
+
18
+ describe('EVMProvider', () => {
19
+ it('can be instantiated', () => {
20
+ const provider = createEVMProvider({
21
+ rpcUrl: 'https://sepolia.base.org',
22
+ signerAddress: '0x1234567890abcdef1234567890abcdef12345678' as `0x${string}`,
23
+ })
24
+ expect(provider).toBeDefined()
25
+ expect(typeof provider.simulate).toBe('function')
26
+ expect(typeof provider.broadcast).toBe('function')
27
+ })
28
+ })
29
+
30
+ describe('GasStrategy', () => {
31
+ it('adds 20% buffer to estimated gas', () => {
32
+ const result = estimateGasWithBuffer(100000n)
33
+ expect(result).toBe(120000n)
34
+ })
35
+
36
+ it('handles zero gas', () => {
37
+ const result = estimateGasWithBuffer(0n)
38
+ expect(result).toBe(0n)
39
+ })
40
+
41
+ it('rounds up fractional buffers', () => {
42
+ const result = estimateGasWithBuffer(1n)
43
+ expect(result).toBe(2n) // ceil(1 * 1.2) = 2
44
+ })
45
+ })
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { encodeUsdcTransfer, buildEvmTransaction } from '../src/transaction-builder.js'
3
+
4
+ describe('encodeUsdcTransfer', () => {
5
+ it('encodes a USDC transfer to a valid hex string', () => {
6
+ const data = encodeUsdcTransfer(
7
+ '0x1234567890abcdef1234567890abcdef12345678' as `0x${string}`,
8
+ 1000000n // 1 USDC
9
+ )
10
+ expect(data).toMatch(/^0x[0-9a-f]+$/)
11
+ // Should contain the transfer function signature
12
+ expect(data.length).toBeGreaterThan(10)
13
+ })
14
+
15
+ it('encodes different amounts differently', () => {
16
+ const a = encodeUsdcTransfer(
17
+ '0x1234567890abcdef1234567890abcdef12345678' as `0x${string}`,
18
+ 1000000n
19
+ )
20
+ const b = encodeUsdcTransfer(
21
+ '0x1234567890abcdef1234567890abcdef12345678' as `0x${string}`,
22
+ 2000000n
23
+ )
24
+ expect(a).not.toBe(b)
25
+ })
26
+ })
27
+
28
+ describe('buildEvmTransaction', () => {
29
+ it('builds a valid EVM transaction object', () => {
30
+ const tx = buildEvmTransaction({
31
+ to: '0x1234567890abcdef1234567890abcdef12345678' as `0x${string}`,
32
+ from: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd' as `0x${string}`,
33
+ amount: 5000000n, // 5 USDC
34
+ chainId: 8453,
35
+ nonce: 0,
36
+ gasLimit: 100000n,
37
+ })
38
+ expect(tx.to).toBe('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913')
39
+ expect(tx.value).toBe(0n) // USDC is ERC20, value is 0
40
+ expect(tx.data).toMatch(/^0x[0-9a-f]+$/)
41
+ expect(tx.chainId).toBe(8453)
42
+ expect(tx.nonce).toBe(0)
43
+ })
44
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"]
8
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['test/**/*.test.ts'],
6
+ exclude: ['test/**/*.integration.test.ts', 'test/**/*.e2e.test.ts'],
7
+ },
8
+ })