@gasfree-kit/evm-4337 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasfree-kit/evm-4337",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "ERC-4337 gasless transactions for EVM chains — powered by WDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -15,15 +15,27 @@
15
15
  "files": [
16
16
  "dist",
17
17
  "patches",
18
- "scripts"
18
+ "scripts",
19
+ "README.md"
19
20
  ],
20
21
  "dependencies": {
22
+ "@noble/hashes": "^2.0.1",
21
23
  "abstractionkit": "^0.2.30",
22
- "@gasfree-kit/core": "0.1.0"
24
+ "@gasfree-kit/core": "0.1.1"
23
25
  },
24
26
  "peerDependencies": {
27
+ "@safe-global/protocol-kit": "^5.0.0",
28
+ "@safe-global/relay-kit": "^4.0.0",
25
29
  "@tetherto/wdk-wallet-evm-erc-4337": "^1.0.0-beta.5"
26
30
  },
31
+ "peerDependenciesMeta": {
32
+ "@safe-global/protocol-kit": {
33
+ "optional": true
34
+ },
35
+ "@safe-global/relay-kit": {
36
+ "optional": true
37
+ }
38
+ },
27
39
  "license": "MIT",
28
40
  "publishConfig": {
29
41
  "access": "public"
@@ -1,68 +1,68 @@
1
- diff --git a/dist/cjs/src/index.cjs b/dist/cjs/src/index.cjs
2
- --- a/dist/cjs/src/index.cjs
3
- +++ b/dist/cjs/src/index.cjs
4
- @@ -1946,6 +1946,9 @@ var GenericFeeEstimator = class {
5
- const context = "paymasterTokenAddress" in paymasterOptions ? {
6
- token: paymasterOptions.paymasterTokenAddress
7
- } : paymasterOptions.paymasterContext ?? {};
8
- + if (paymasterOptions.sponsorshipPolicyId) {
9
- + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
10
- + }
11
- const [feeData, paymasterStubData] = await Promise.all([
12
- this.#getUserOperationGasPrices(this.rpcUrl),
13
- paymasterClient.request({
14
- @@ -2017,7 +2020,8 @@ var GenericFeeEstimator = class {
15
- const sponsoredData = await paymasterClient.request({
16
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
17
- params
18
- });
19
- - return sponsoredData;
20
- + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
21
- + return sponsoredData;
22
- }
23
- const erc20PaymasterData = await paymasterClient.request({
24
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
25
- @@ -2032,7 +2036,8 @@ var GenericFeeEstimator = class {
26
- const threshold = await protocolKit.getThreshold();
27
- erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
28
- }
29
- - return erc20PaymasterData;
30
- + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
31
- + return erc20PaymasterData;
32
- }
33
- async #getUserOperationGasPrices(rpcUrl) {
34
- const client = (0, import_viem11.createPublicClient)({
35
- diff --git a/dist/esm/src/index.mjs b/dist/esm/src/index.mjs
36
- --- a/dist/esm/src/index.mjs
37
- +++ b/dist/esm/src/index.mjs
38
- @@ -1923,6 +1923,9 @@ var GenericFeeEstimator = class {
39
- const context = "paymasterTokenAddress" in paymasterOptions ? {
40
- token: paymasterOptions.paymasterTokenAddress
41
- } : paymasterOptions.paymasterContext ?? {};
42
- + if (paymasterOptions.sponsorshipPolicyId) {
43
- + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
44
- + }
45
- const [feeData, paymasterStubData] = await Promise.all([
46
- this.#getUserOperationGasPrices(this.rpcUrl),
47
- paymasterClient.request({
48
- @@ -1994,7 +1997,8 @@ var GenericFeeEstimator = class {
49
- const sponsoredData = await paymasterClient.request({
50
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
51
- params
52
- });
53
- - return sponsoredData;
54
- + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
55
- + return sponsoredData;
56
- }
57
- const erc20PaymasterData = await paymasterClient.request({
58
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
59
- @@ -2009,7 +2013,8 @@ var GenericFeeEstimator = class {
60
- const threshold = await protocolKit.getThreshold();
61
- erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
62
- }
63
- - return erc20PaymasterData;
64
- + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
65
- + return erc20PaymasterData;
66
- }
67
- async #getUserOperationGasPrices(rpcUrl) {
68
- const client = createPublicClient2({
1
+ diff --git a/dist/cjs/src/index.cjs b/dist/cjs/src/index.cjs
2
+ --- a/dist/cjs/src/index.cjs
3
+ +++ b/dist/cjs/src/index.cjs
4
+ @@ -1946,6 +1946,9 @@ var GenericFeeEstimator = class {
5
+ const context = "paymasterTokenAddress" in paymasterOptions ? {
6
+ token: paymasterOptions.paymasterTokenAddress
7
+ } : paymasterOptions.paymasterContext ?? {};
8
+ + if (paymasterOptions.sponsorshipPolicyId) {
9
+ + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
10
+ + }
11
+ const [feeData, paymasterStubData] = await Promise.all([
12
+ this.#getUserOperationGasPrices(this.rpcUrl),
13
+ paymasterClient.request({
14
+ @@ -2017,7 +2020,8 @@ var GenericFeeEstimator = class {
15
+ const sponsoredData = await paymasterClient.request({
16
+ method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
17
+ params
18
+ });
19
+ - return sponsoredData;
20
+ + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
21
+ + return sponsoredData;
22
+ }
23
+ const erc20PaymasterData = await paymasterClient.request({
24
+ method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
25
+ @@ -2032,7 +2036,8 @@ var GenericFeeEstimator = class {
26
+ const threshold = await protocolKit.getThreshold();
27
+ erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
28
+ }
29
+ - return erc20PaymasterData;
30
+ + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
31
+ + return erc20PaymasterData;
32
+ }
33
+ async #getUserOperationGasPrices(rpcUrl) {
34
+ const client = (0, import_viem11.createPublicClient)({
35
+ diff --git a/dist/esm/src/index.mjs b/dist/esm/src/index.mjs
36
+ --- a/dist/esm/src/index.mjs
37
+ +++ b/dist/esm/src/index.mjs
38
+ @@ -1923,6 +1923,9 @@ var GenericFeeEstimator = class {
39
+ const context = "paymasterTokenAddress" in paymasterOptions ? {
40
+ token: paymasterOptions.paymasterTokenAddress
41
+ } : paymasterOptions.paymasterContext ?? {};
42
+ + if (paymasterOptions.sponsorshipPolicyId) {
43
+ + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
44
+ + }
45
+ const [feeData, paymasterStubData] = await Promise.all([
46
+ this.#getUserOperationGasPrices(this.rpcUrl),
47
+ paymasterClient.request({
48
+ @@ -1994,7 +1997,8 @@ var GenericFeeEstimator = class {
49
+ const sponsoredData = await paymasterClient.request({
50
+ method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
51
+ params
52
+ });
53
+ - return sponsoredData;
54
+ + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
55
+ + return sponsoredData;
56
+ }
57
+ const erc20PaymasterData = await paymasterClient.request({
58
+ method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
59
+ @@ -2009,7 +2013,8 @@ var GenericFeeEstimator = class {
60
+ const threshold = await protocolKit.getThreshold();
61
+ erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
62
+ }
63
+ - return erc20PaymasterData;
64
+ + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
65
+ + return erc20PaymasterData;
66
+ }
67
+ async #getUserOperationGasPrices(rpcUrl) {
68
+ const client = createPublicClient2({
@@ -1,80 +1,101 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Postinstall script for @gasfree-kit/evm-4337.
5
- *
6
- * Applies a critical patch to @tetherto/wdk-safe-relay-kit that fixes:
7
- * 1. sponsorshipPolicyId not being passed to Candide paymaster context
8
- * 2. callGasLimit being dropped by paymaster response (both sponsored & ERC-20)
9
- *
10
- * Without this patch, gas estimation fails on Candide-sponsored transactions.
11
- *
12
- * Works with npm, pnpm, and yarn.
13
- * pnpm users can also use patchedDependencies in package.json instead.
14
- */
15
-
16
- const { execSync } = require('child_process');
17
- const fs = require('fs');
18
- const path = require('path');
19
-
20
- const patchFile = path.join(
21
- __dirname,
22
- '..',
23
- 'patches',
24
- '@tetherto__wdk-safe-relay-kit@4.1.5.patch',
25
- );
26
-
27
- if (!fs.existsSync(patchFile)) {
28
- // Patch file not found — skip (might be in a CI environment or already applied)
29
- process.exit(0);
30
- }
31
-
32
- // Find the target package
33
- const possiblePaths = [
34
- // npm/yarn hoisted
35
- path.resolve(__dirname, '..', '..', '@tetherto', 'wdk-safe-relay-kit'),
36
- // pnpm non-hoisted
37
- path.resolve(__dirname, '..', 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
38
- // monorepo root
39
- path.resolve(__dirname, '..', '..', '..', 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
40
- ];
41
-
42
- const targetDir = possiblePaths.find((p) => fs.existsSync(p));
43
-
44
- if (!targetDir) {
45
- // @tetherto/wdk-safe-relay-kit not installed yet — skip
46
- // The user's package manager will install peer deps and this runs again
47
- process.exit(0);
48
- }
49
-
50
- // Check if patch is already applied by looking for our marker
51
- const cjsFile = path.join(targetDir, 'dist', 'cjs', 'src', 'index.cjs');
52
- if (fs.existsSync(cjsFile)) {
53
- const content = fs.readFileSync(cjsFile, 'utf8');
54
- if (content.includes('context.sponsorshipPolicyId')) {
55
- // Patch already applied
56
- process.exit(0);
57
- }
58
- }
59
-
60
- try {
61
- execSync(`npx patch-package --patch-dir "${path.dirname(patchFile)}"`, {
62
- cwd: path.resolve(targetDir, '..', '..'),
63
- stdio: 'pipe',
64
- });
65
- console.log('@gasfree-kit/evm-4337: Applied wdk-safe-relay-kit patch (Candide paymaster fix)');
66
- } catch {
67
- // patch-package not available — try git apply
68
- try {
69
- execSync(`git apply --directory="${targetDir}" "${patchFile}"`, {
70
- stdio: 'pipe',
71
- });
72
- console.log('@gasfree-kit/evm-4337: Applied wdk-safe-relay-kit patch via git apply');
73
- } catch {
74
- console.warn(
75
- '@gasfree-kit/evm-4337: Could not auto-apply wdk-safe-relay-kit patch.\n' +
76
- 'Please apply manually: patches/@tetherto__wdk-safe-relay-kit@4.1.5.patch\n' +
77
- 'See: https://github.com/gasfree-kit/evm-4337#patch',
78
- );
79
- }
80
- }
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for @gasfree-kit/evm-4337.
5
+ *
6
+ * Applies a critical patch to @tetherto/wdk-safe-relay-kit that fixes:
7
+ * 1. sponsorshipPolicyId not being passed to Candide paymaster context
8
+ * 2. callGasLimit being dropped by paymaster response (both sponsored & ERC-20)
9
+ *
10
+ * Without this patch, gas estimation fails on Candide-sponsored transactions.
11
+ *
12
+ * Works with npm, pnpm, and yarn.
13
+ * pnpm users can also use patchedDependencies in package.json instead.
14
+ */
15
+
16
+ const { spawnSync } = require('child_process');
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+ const packageRoot = path.resolve(__dirname, '..');
20
+
21
+ function findProjectRoot(startDir) {
22
+ let current = startDir;
23
+ while (true) {
24
+ const parent = path.dirname(current);
25
+ if (parent === current) {
26
+ return startDir;
27
+ }
28
+ if (fs.existsSync(path.join(parent, 'package.json'))) {
29
+ return parent;
30
+ }
31
+ current = parent;
32
+ }
33
+ }
34
+
35
+ function runOrThrow(command, args, options) {
36
+ const result = spawnSync(command, args, {
37
+ stdio: 'pipe',
38
+ windowsHide: true,
39
+ ...options,
40
+ });
41
+
42
+ if (result.error) {
43
+ throw result.error;
44
+ }
45
+
46
+ if (result.status !== 0) {
47
+ const stderr = result.stderr ? result.stderr.toString().trim() : '';
48
+ throw new Error(stderr || `${command} exited with code ${result.status}`);
49
+ }
50
+ }
51
+
52
+ const patchFile = path.join(
53
+ __dirname,
54
+ '..',
55
+ 'patches',
56
+ '@tetherto__wdk-safe-relay-kit@4.1.5.patch',
57
+ );
58
+
59
+ if (!fs.existsSync(patchFile)) {
60
+ // Patch file not found — skip (might be in a CI environment or already applied)
61
+ process.exit(0);
62
+ }
63
+
64
+ // Find the target package
65
+ const projectRoot = findProjectRoot(packageRoot);
66
+ const possiblePaths = [
67
+ path.join(projectRoot, 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
68
+ path.join(packageRoot, 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
69
+ ];
70
+
71
+ const targetDir = possiblePaths.find((p) => fs.existsSync(p));
72
+
73
+ if (!targetDir) {
74
+ // @tetherto/wdk-safe-relay-kit not installed yet — skip
75
+ // The user's package manager will install peer deps and this runs again
76
+ process.exit(0);
77
+ }
78
+
79
+ // Check if patch is already applied by looking for our marker
80
+ const cjsFile = path.join(targetDir, 'dist', 'cjs', 'src', 'index.cjs');
81
+ if (fs.existsSync(cjsFile)) {
82
+ const content = fs.readFileSync(cjsFile, 'utf8');
83
+ if (content.includes('context.sponsorshipPolicyId')) {
84
+ // Patch already applied
85
+ process.exit(0);
86
+ }
87
+ }
88
+
89
+ // Apply the patch using git apply without shell interpolation.
90
+ try {
91
+ runOrThrow('git', ['apply', '--unsafe-paths', `--directory=${targetDir}`, patchFile], {
92
+ cwd: projectRoot,
93
+ });
94
+ console.log('@gasfree-kit/evm-4337: Applied wdk-safe-relay-kit patch (Candide paymaster fix)');
95
+ } catch {
96
+ console.warn(
97
+ '@gasfree-kit/evm-4337: Could not auto-apply wdk-safe-relay-kit patch.\n' +
98
+ 'Please apply manually: patches/@tetherto__wdk-safe-relay-kit@4.1.5.patch\n' +
99
+ 'See: https://github.com/gasfree-kit/evm-4337#patch',
100
+ );
101
+ }