@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/README.md +271 -0
- package/dist/index.d.mts +161 -14
- package/dist/index.d.ts +161 -14
- package/dist/index.js +819 -92
- package/dist/index.mjs +804 -86
- package/package.json +15 -3
- package/patches/@tetherto__wdk-safe-relay-kit@4.1.5.patch +68 -68
- package/scripts/postinstall.js +101 -80
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasfree-kit/evm-4337",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
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({
|
package/scripts/postinstall.js
CHANGED
|
@@ -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 {
|
|
17
|
-
const fs = require('fs');
|
|
18
|
-
const path = require('path');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
}
|