@swimmingkiim/pay-sdk 0.1.17 → 0.1.19
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.
|
@@ -3,5 +3,16 @@ export declare class PaymasterManager {
|
|
|
3
3
|
constructor(rpcUrl?: string, apiKey?: string);
|
|
4
4
|
getClient(): any;
|
|
5
5
|
getStubPaymasterData(userOp: any): Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Appends a fee transfer transaction to the list of calls.
|
|
8
|
+
* @param calls Array of transaction calls { to, value, data }
|
|
9
|
+
* @param feeConfig Configuration for the fee { treasury, amount, token }
|
|
10
|
+
* @returns New array of calls with the fee transaction appended
|
|
11
|
+
*/
|
|
12
|
+
static appendFeeToCalls(calls: any[], feeConfig?: {
|
|
13
|
+
treasury: string;
|
|
14
|
+
amount: bigint;
|
|
15
|
+
token: string;
|
|
16
|
+
}): any[];
|
|
6
17
|
}
|
|
7
18
|
//# sourceMappingURL=paymaster.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymaster.d.ts","sourceRoot":"","sources":["../../src/paymaster/paymaster.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paymaster.d.ts","sourceRoot":"","sources":["../../src/paymaster/paymaster.ts"],"names":[],"mappings":"AAMA,qBAAa,gBAAgB;IACzB,OAAO,CAAC,MAAM,CAAK;gBAEP,MAAM,GAAE,MAA6C,EAAE,MAAM,CAAC,EAAE,MAAM;IAYlF,SAAS;IAIH,oBAAoB,CAAC,MAAM,EAAE,GAAG;IAMtC;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;CAwBxG"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createPimlicoClient } from "permissionless/clients/pimlico";
|
|
2
|
-
import { http } from "viem";
|
|
2
|
+
import { http, encodeFunctionData, parseAbi } from "viem";
|
|
3
|
+
const ERC20_ABI = parseAbi(['function transfer(address to, uint256 amount) returns (bool)']);
|
|
3
4
|
export class PaymasterManager {
|
|
4
5
|
client;
|
|
5
6
|
constructor(rpcUrl = "http://localhost:8080/v1/paymaster", apiKey) {
|
|
@@ -20,5 +21,32 @@ export class PaymasterManager {
|
|
|
20
21
|
userOperation: userOp
|
|
21
22
|
});
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Appends a fee transfer transaction to the list of calls.
|
|
26
|
+
* @param calls Array of transaction calls { to, value, data }
|
|
27
|
+
* @param feeConfig Configuration for the fee { treasury, amount, token }
|
|
28
|
+
* @returns New array of calls with the fee transaction appended
|
|
29
|
+
*/
|
|
30
|
+
static appendFeeToCalls(calls, feeConfig) {
|
|
31
|
+
// Defaults matching the Paymaster Config
|
|
32
|
+
const config = {
|
|
33
|
+
treasury: feeConfig?.treasury || '0x0000000000000000000000000000000000000000', // Must be set by user
|
|
34
|
+
amount: feeConfig?.amount || 100000n, // 0.1 USDC
|
|
35
|
+
token: feeConfig?.token || '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // USDC on Base
|
|
36
|
+
};
|
|
37
|
+
if (config.treasury === '0x0000000000000000000000000000000000000000') {
|
|
38
|
+
console.warn("PaymasterManager: Treasury address is not set. Fee transaction might fail validation.");
|
|
39
|
+
}
|
|
40
|
+
const feeCall = {
|
|
41
|
+
to: config.token,
|
|
42
|
+
value: 0n,
|
|
43
|
+
data: encodeFunctionData({
|
|
44
|
+
abi: ERC20_ABI,
|
|
45
|
+
functionName: 'transfer',
|
|
46
|
+
args: [config.treasury, config.amount]
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
return [...calls, feeCall];
|
|
50
|
+
}
|
|
23
51
|
}
|
|
24
52
|
//# sourceMappingURL=paymaster.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paymaster.js","sourceRoot":"","sources":["../../src/paymaster/paymaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"paymaster.js","sourceRoot":"","sources":["../../src/paymaster/paymaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAO,MAAM,MAAM,CAAA;AAE9D,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,8DAA8D,CAAC,CAAC,CAAC;AAG7F,MAAM,OAAO,gBAAgB;IACjB,MAAM,CAAK;IAEnB,YAAY,SAAiB,oCAAoC,EAAE,MAAe;QAC9E,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAE/E,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC;YAC9B,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,YAAY,EAAE,CAAC;YACzC,UAAU,EAAE;gBACR,OAAO,EAAE,4CAA4C;gBACrD,OAAO,EAAE,KAAK;aACjB;SACJ,CAAC,CAAA;IACN,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,MAAW;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;YACpC,aAAa,EAAE,MAAM;SACxB,CAAC,CAAA;IACN,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAY,EAAE,SAA+D;QACjG,yCAAyC;QACzC,MAAM,MAAM,GAAG;YACX,QAAQ,EAAE,SAAS,EAAE,QAAQ,IAAI,4CAA4C,EAAE,sBAAsB;YACrG,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,OAAO,EAAE,WAAW;YACjD,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,4CAA4C,CAAC,eAAe;SAC1F,CAAC;QAEF,IAAI,MAAM,CAAC,QAAQ,KAAK,4CAA4C,EAAE,CAAC;YACnE,OAAO,CAAC,IAAI,CAAC,uFAAuF,CAAC,CAAC;QAC1G,CAAC;QAED,MAAM,OAAO,GAAG;YACZ,EAAE,EAAE,MAAM,CAAC,KAAY;YACvB,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,kBAAkB,CAAC;gBACrB,GAAG,EAAE,SAAS;gBACd,YAAY,EAAE,UAAU;gBACxB,IAAI,EAAE,CAAC,MAAM,CAAC,QAAe,EAAE,MAAM,CAAC,MAAM,CAAC;aAChD,CAAC;SACL,CAAC;QAEF,OAAO,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createPimlicoClient } from "permissionless/clients/pimlico"
|
|
2
|
-
import { http } from "viem"
|
|
2
|
+
import { http, encodeFunctionData, parseAbi, Hex } from "viem"
|
|
3
|
+
|
|
4
|
+
const ERC20_ABI = parseAbi(['function transfer(address to, uint256 amount) returns (bool)']);
|
|
5
|
+
|
|
3
6
|
|
|
4
7
|
export class PaymasterManager {
|
|
5
8
|
private client: any
|
|
@@ -25,4 +28,35 @@ export class PaymasterManager {
|
|
|
25
28
|
userOperation: userOp
|
|
26
29
|
})
|
|
27
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Appends a fee transfer transaction to the list of calls.
|
|
34
|
+
* @param calls Array of transaction calls { to, value, data }
|
|
35
|
+
* @param feeConfig Configuration for the fee { treasury, amount, token }
|
|
36
|
+
* @returns New array of calls with the fee transaction appended
|
|
37
|
+
*/
|
|
38
|
+
static appendFeeToCalls(calls: any[], feeConfig?: { treasury: string, amount: bigint, token: string }) {
|
|
39
|
+
// Defaults matching the Paymaster Config
|
|
40
|
+
const config = {
|
|
41
|
+
treasury: feeConfig?.treasury || '0x0000000000000000000000000000000000000000', // Must be set by user
|
|
42
|
+
amount: feeConfig?.amount || 100000n, // 0.1 USDC
|
|
43
|
+
token: feeConfig?.token || '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // USDC on Base
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (config.treasury === '0x0000000000000000000000000000000000000000') {
|
|
47
|
+
console.warn("PaymasterManager: Treasury address is not set. Fee transaction might fail validation.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const feeCall = {
|
|
51
|
+
to: config.token as Hex,
|
|
52
|
+
value: 0n,
|
|
53
|
+
data: encodeFunctionData({
|
|
54
|
+
abi: ERC20_ABI,
|
|
55
|
+
functionName: 'transfer',
|
|
56
|
+
args: [config.treasury as Hex, config.amount]
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return [...calls, feeCall];
|
|
61
|
+
}
|
|
28
62
|
}
|