@nevermined-io/core-kit 0.3.0 → 0.3.2
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/dist/contracts/ContractBase.d.ts +11 -1
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +63 -56
- package/dist/nevermined/utils/AnvilHelpers.d.ts +23 -0
- package/dist/nevermined/utils/AnvilHelpers.d.ts.map +1 -0
- package/dist/nevermined/utils/AnvilHelpers.js +63 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +31 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -1
- package/dist/nevermined/utils/BlockchainViemUtils.js +60 -14
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +0 -8
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +0 -36
- package/dist/nevermined/utils/index.d.ts +1 -0
- package/dist/nevermined/utils/index.d.ts.map +1 -1
- package/dist/nevermined/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -34,6 +34,7 @@ export declare abstract class ContractBase extends Instantiable {
|
|
|
34
34
|
simulate(functionName: string, from: Account | SmartAccount, args: any[], params?: TxParameters): Promise<boolean>;
|
|
35
35
|
send(functionName: string, from: Account | SmartAccount, args: any[], params?: TxParameters): Promise<TransactionReceipt | UserOperationReceipt>;
|
|
36
36
|
private internalMulticallSmartAccount;
|
|
37
|
+
private assertUserOpSucceeded;
|
|
37
38
|
private internalSendSmartAccount;
|
|
38
39
|
private internalSimulateSmartAccount;
|
|
39
40
|
private localAccountSimulate;
|
|
@@ -42,6 +43,15 @@ export declare abstract class ContractBase extends Instantiable {
|
|
|
42
43
|
private localAccountSimulateMulticall;
|
|
43
44
|
private internalSimulateMulticallSmartAccount;
|
|
44
45
|
private getOrCreatePaymaster;
|
|
45
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Builds the `paymaster` partial for `createKernelAccountClient`. In relayer
|
|
48
|
+
* mode (e.g. local `ultra-relay` for tests) returns an empty object so the
|
|
49
|
+
* kernel client submits UserOps without paymaster fields and the bundler
|
|
50
|
+
* pays gas via its executor key. In production returns the ZeroDev paymaster
|
|
51
|
+
* sponsorship callback.
|
|
52
|
+
*/
|
|
53
|
+
private getPaymasterConfig;
|
|
54
|
+
protected getBundlerRPC(): string;
|
|
55
|
+
private getPaymasterRPC;
|
|
46
56
|
}
|
|
47
57
|
//# sourceMappingURL=ContractBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,GAAG,EACH,OAAO,EACP,OAAO,EAQP,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE7E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAKxD,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,GAAG,CAAA;IACR,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;AA8BD,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;CACZ;AAED,8BAAsB,YAAa,SAAQ,YAAY;IACrD,SAAgB,YAAY,EAA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;YAuB5B,oBAAoB;YAuBpB,gBAAgB;YAmIhB,qBAAqB;YAyBrB,6BAA6B;YAqB7B,qCAAqC;IAkEnD,OAAO,CAAC,oBAAoB;IAU5B;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAW1B,SAAS,CAAC,aAAa,IAAI,MAAM;IAcjC,OAAO,CAAC,eAAe;CAYxB"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { createKernelAccountClient, createZeroDevPaymasterClient
|
|
1
|
+
import { createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk';
|
|
2
|
+
import { estimateUserOperationFees, getBundlerRpcUrl, getPaymasterRpcUrl, isRelayerMode, } from '../nevermined/utils/BlockchainViemUtils.js';
|
|
2
3
|
import { BaseError, ContractFunctionRevertedError, encodeFunctionData, getContract, http, parseAbi, parseEventLogs, } from 'viem';
|
|
3
4
|
import { ContractsError, ContractSimulationError } from '../errors/index.js';
|
|
4
5
|
import { Instantiable } from '../Instantiable.abstract.js';
|
|
5
6
|
import { getInputsOfFunctionFormatted, getTransactionReceipt } from '../nevermined/index.js';
|
|
6
7
|
import { getChain } from '../utils/Network.js';
|
|
7
|
-
// import { jsonReplacer } from '../utils/helpers.js'
|
|
8
|
-
// TODO(v1.4.0): remove once Base Sepolia is upgraded. See `getTransactionLogs`.
|
|
9
|
-
const legacyPlanRegisteredAbi = parseAbi([
|
|
10
|
-
'event PlanRegistered(uint256 indexed planId, address indexed creator)',
|
|
11
|
-
]);
|
|
12
8
|
/**
|
|
13
9
|
* When a testnet RPC (Base Sepolia) fails internally, some providers return
|
|
14
10
|
* `eth_estimateGas` values equal to — or even above — the block gas limit
|
|
@@ -84,34 +80,12 @@ export class ContractBase extends Instantiable {
|
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
82
|
getTransactionLogs(txReceipt, eventName) {
|
|
87
|
-
|
|
83
|
+
return parseEventLogs({
|
|
88
84
|
abi: this.contract.abi,
|
|
89
85
|
logs: txReceipt.logs,
|
|
90
86
|
eventName,
|
|
91
87
|
strict: false,
|
|
92
88
|
});
|
|
93
|
-
// TODO(v1.4.0): remove this legacy-PlanRegistered fallback once Base Sepolia
|
|
94
|
-
// is upgraded to v1.4.0. The v1.3.2 contract still in production emits the
|
|
95
|
-
// 2-arg `PlanRegistered(uint256,address)` form, whose topic0 differs from
|
|
96
|
-
// the 3-arg form in the current wagmi ABI, so the primary parse above
|
|
97
|
-
// returns `[]` and every caller's `logs[0].args.planId` throws. We reparse
|
|
98
|
-
// with the legacy signature and default the missing `onchainMirror` to
|
|
99
|
-
// `false` — the deployed v1.3.2 behavior.
|
|
100
|
-
if (parsed.length === 0 && (eventName === 'PlanRegistered' || !eventName)) {
|
|
101
|
-
const legacy = parseEventLogs({
|
|
102
|
-
abi: legacyPlanRegisteredAbi,
|
|
103
|
-
logs: txReceipt.logs,
|
|
104
|
-
eventName: 'PlanRegistered',
|
|
105
|
-
strict: false,
|
|
106
|
-
});
|
|
107
|
-
if (legacy.length > 0) {
|
|
108
|
-
return legacy.map((log) => ({
|
|
109
|
-
...log,
|
|
110
|
-
args: { ...log.args, onchainMirror: false },
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return parsed;
|
|
115
89
|
}
|
|
116
90
|
async multicall(calls, from, params = {}) {
|
|
117
91
|
if (from.type === 'local') {
|
|
@@ -191,17 +165,15 @@ export class ContractBase extends Instantiable {
|
|
|
191
165
|
contractAddress: this.address,
|
|
192
166
|
});
|
|
193
167
|
}
|
|
194
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
195
168
|
const kernelClient = createKernelAccountClient({
|
|
196
169
|
account: from,
|
|
197
170
|
chain: getChain(this.config.chainId),
|
|
198
|
-
bundlerTransport: http(this.
|
|
171
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
199
172
|
client: this.client.public,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
173
|
+
...this.getPaymasterConfig(),
|
|
174
|
+
userOperation: {
|
|
175
|
+
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
176
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
205
177
|
},
|
|
206
178
|
},
|
|
207
179
|
});
|
|
@@ -235,6 +207,7 @@ export class ContractBase extends Instantiable {
|
|
|
235
207
|
const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
236
208
|
this.logger.debug(`Transaction mined - UserOperationHash: ${userOpHash}`);
|
|
237
209
|
this.logger.debug(`Transaction receipt - TransactionHash: ${txReceipt.receipt.transactionHash}`);
|
|
210
|
+
this.assertUserOpSucceeded(txReceipt, 'multicall', userOpHash);
|
|
238
211
|
return txReceipt.receipt;
|
|
239
212
|
}
|
|
240
213
|
catch (err) {
|
|
@@ -245,6 +218,13 @@ export class ContractBase extends Instantiable {
|
|
|
245
218
|
throw new ContractsError(`Multicall failed: ${err}`);
|
|
246
219
|
}
|
|
247
220
|
}
|
|
221
|
+
assertUserOpSucceeded(txReceipt, method, userOpHash) {
|
|
222
|
+
if (txReceipt.success)
|
|
223
|
+
return;
|
|
224
|
+
throw new ContractsError(`UserOp inner call reverted for "${method}" on "${this.contractName}". ` +
|
|
225
|
+
`userOpHash=${userOpHash} txHash=${txReceipt.receipt.transactionHash} ` +
|
|
226
|
+
`reason=${txReceipt.reason ?? 'unknown'}`);
|
|
227
|
+
}
|
|
248
228
|
async internalSendSmartAccount(name, from, args, txparams, progress) {
|
|
249
229
|
const functionInputs = getInputsOfFunctionFormatted(this.contract.abi, name, args);
|
|
250
230
|
const { gasLimit, value } = txparams;
|
|
@@ -277,17 +257,15 @@ export class ContractBase extends Instantiable {
|
|
|
277
257
|
}
|
|
278
258
|
throw new ContractsError(`Calling method "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
|
|
279
259
|
}
|
|
280
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
281
260
|
const kernelClient = createKernelAccountClient({
|
|
282
261
|
account: from,
|
|
283
262
|
chain: getChain(this.config.chainId),
|
|
284
|
-
bundlerTransport: http(this.
|
|
263
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
285
264
|
client: this.client.public,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
});
|
|
265
|
+
...this.getPaymasterConfig(),
|
|
266
|
+
userOperation: {
|
|
267
|
+
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
268
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
291
269
|
},
|
|
292
270
|
},
|
|
293
271
|
});
|
|
@@ -325,6 +303,7 @@ export class ContractBase extends Instantiable {
|
|
|
325
303
|
});
|
|
326
304
|
}
|
|
327
305
|
const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
306
|
+
this.assertUserOpSucceeded(txReceipt, name, userOpHash);
|
|
328
307
|
if (progress) {
|
|
329
308
|
progress({
|
|
330
309
|
stage: 'receipt',
|
|
@@ -512,22 +491,15 @@ export class ContractBase extends Instantiable {
|
|
|
512
491
|
}
|
|
513
492
|
async internalSimulateMulticallSmartAccount(calls, from, txparams) {
|
|
514
493
|
try {
|
|
515
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
516
494
|
const kernelClient = createKernelAccountClient({
|
|
517
495
|
account: from,
|
|
518
496
|
chain: getChain(this.config.chainId),
|
|
519
|
-
bundlerTransport: http(this.
|
|
497
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
520
498
|
client: this.client.public,
|
|
521
|
-
|
|
522
|
-
getPaymasterData: (userOperation) => {
|
|
523
|
-
return zerodevPaymaster.sponsorUserOperation({
|
|
524
|
-
userOperation,
|
|
525
|
-
});
|
|
526
|
-
},
|
|
527
|
-
},
|
|
499
|
+
...this.getPaymasterConfig(),
|
|
528
500
|
userOperation: {
|
|
529
501
|
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
530
|
-
return
|
|
502
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
531
503
|
},
|
|
532
504
|
},
|
|
533
505
|
});
|
|
@@ -576,12 +548,47 @@ export class ContractBase extends Instantiable {
|
|
|
576
548
|
if (!this._zeroDevPaymaster) {
|
|
577
549
|
this._zeroDevPaymaster = createZeroDevPaymasterClient({
|
|
578
550
|
chain: getChain(this.config.chainId),
|
|
579
|
-
transport: http(this.
|
|
551
|
+
transport: http(this.getPaymasterRPC()),
|
|
580
552
|
});
|
|
581
553
|
}
|
|
582
554
|
return this._zeroDevPaymaster;
|
|
583
555
|
}
|
|
584
|
-
|
|
585
|
-
|
|
556
|
+
/**
|
|
557
|
+
* Builds the `paymaster` partial for `createKernelAccountClient`. In relayer
|
|
558
|
+
* mode (e.g. local `ultra-relay` for tests) returns an empty object so the
|
|
559
|
+
* kernel client submits UserOps without paymaster fields and the bundler
|
|
560
|
+
* pays gas via its executor key. In production returns the ZeroDev paymaster
|
|
561
|
+
* sponsorship callback.
|
|
562
|
+
*/
|
|
563
|
+
getPaymasterConfig() {
|
|
564
|
+
if (isRelayerMode())
|
|
565
|
+
return {};
|
|
566
|
+
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
567
|
+
return {
|
|
568
|
+
paymaster: {
|
|
569
|
+
getPaymasterData: (userOperation) => zerodevPaymaster.sponsorUserOperation({ userOperation }),
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
getBundlerRPC() {
|
|
574
|
+
// In relayer mode `getBundlerRpcUrl` reads `BUNDLER_RPC_URL_OVERRIDE`
|
|
575
|
+
// and never touches the project id, so an empty value is harmless. In
|
|
576
|
+
// production callers must pass a project id — surface a clear error if
|
|
577
|
+
// the SDK was instantiated without one and we need it.
|
|
578
|
+
const projectId = this.config.zeroDevProjectId;
|
|
579
|
+
if (!projectId && !isRelayerMode()) {
|
|
580
|
+
throw new ContractsError('getBundlerRPC: zeroDevProjectId is required for non-relayer (production) mode');
|
|
581
|
+
}
|
|
582
|
+
return getBundlerRpcUrl(projectId ?? '', this.config.chainId);
|
|
583
|
+
}
|
|
584
|
+
getPaymasterRPC() {
|
|
585
|
+
// Only ever consulted when `getPaymasterConfig` decides to attach a
|
|
586
|
+
// paymaster, which is gated on `!isRelayerMode()`. A missing project
|
|
587
|
+
// id at this point is a configuration bug worth surfacing.
|
|
588
|
+
const projectId = this.config.zeroDevProjectId;
|
|
589
|
+
if (!projectId) {
|
|
590
|
+
throw new ContractsError('getPaymasterRPC: zeroDevProjectId is required to build the paymaster URL');
|
|
591
|
+
}
|
|
592
|
+
return getPaymasterRpcUrl(projectId, this.config.chainId);
|
|
586
593
|
}
|
|
587
594
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Address, type PublicClient } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when the test/dev process is running against a local
|
|
4
|
+
* anvil-fork stack (i.e. `BUNDLER_RPC_URL_OVERRIDE` is set). Helpers that
|
|
5
|
+
* depend on anvil cheatcodes should early-return when this is false so the
|
|
6
|
+
* same code path stays portable to the real network.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isAnvilFork(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Forces `holder`'s ERC20 balance on `token` to `amount`, writing the value
|
|
11
|
+
* directly into storage via `anvil_setStorageAt`. No-op when not running on
|
|
12
|
+
* an anvil fork so the same call site stays portable to the real network.
|
|
13
|
+
*
|
|
14
|
+
* Assumes the FiatTokenV2.2 storage layout (Circle's USDC). For other ERC20s
|
|
15
|
+
* pass a different `balanceSlot` matching the implementation's storage.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setErc20Balance(publicClient: PublicClient, token: Address, holder: Address, amount: bigint, balanceSlot?: bigint): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Convenience wrapper that funds Base Sepolia USDC on a kernel SCA. Only
|
|
20
|
+
* takes effect on an anvil fork.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fundUsdcOnFork(publicClient: PublicClient, holder: Address, amountUsdcUnits: bigint): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=AnvilHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnvilHelpers.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/AnvilHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,YAAY,EAMlB,MAAM,MAAM,CAAA;AAEb;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAYD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,MAAgC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256, pad, parseAbi, toHex, } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when the test/dev process is running against a local
|
|
4
|
+
* anvil-fork stack (i.e. `BUNDLER_RPC_URL_OVERRIDE` is set). Helpers that
|
|
5
|
+
* depend on anvil cheatcodes should early-return when this is false so the
|
|
6
|
+
* same code path stays portable to the real network.
|
|
7
|
+
*/
|
|
8
|
+
export function isAnvilFork() {
|
|
9
|
+
return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Storage slot of `balanceAndBlacklistStates` (the balance mapping) in
|
|
13
|
+
* Circle's `FiatTokenV2_2`, the implementation behind the USDC proxy on
|
|
14
|
+
* Base Sepolia at `0x036CbD53842c5426634e7929541eC2318f3dCF7e`.
|
|
15
|
+
*
|
|
16
|
+
* The lower 159 bits hold the balance; the high bit is the blacklist flag.
|
|
17
|
+
* Writing the raw amount (as long as it fits in 159 bits) is safe.
|
|
18
|
+
*/
|
|
19
|
+
const FIAT_TOKEN_BALANCE_SLOT = 9n;
|
|
20
|
+
/**
|
|
21
|
+
* Forces `holder`'s ERC20 balance on `token` to `amount`, writing the value
|
|
22
|
+
* directly into storage via `anvil_setStorageAt`. No-op when not running on
|
|
23
|
+
* an anvil fork so the same call site stays portable to the real network.
|
|
24
|
+
*
|
|
25
|
+
* Assumes the FiatTokenV2.2 storage layout (Circle's USDC). For other ERC20s
|
|
26
|
+
* pass a different `balanceSlot` matching the implementation's storage.
|
|
27
|
+
*/
|
|
28
|
+
export async function setErc20Balance(publicClient, token, holder, amount, balanceSlot = FIAT_TOKEN_BALANCE_SLOT) {
|
|
29
|
+
if (!isAnvilFork()) {
|
|
30
|
+
// Surface the no-op so a test author who copy/pasted the helper without
|
|
31
|
+
// setting BUNDLER_RPC_URL_OVERRIDE doesn't silently end up debugging an
|
|
32
|
+
// unrelated `transferFrom` revert deep inside the actual test.
|
|
33
|
+
console.warn(`[AnvilHelpers.setErc20Balance] no-op: BUNDLER_RPC_URL_OVERRIDE not set; ` +
|
|
34
|
+
`holder=${holder} token=${token} amount=${amount} skipped`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const slot = keccak256(encodeAbiParameters([{ type: 'address' }, { type: 'uint256' }], [holder, balanceSlot]));
|
|
38
|
+
const value = pad(toHex(amount), { size: 32 });
|
|
39
|
+
await publicClient.request({
|
|
40
|
+
method: 'anvil_setStorageAt',
|
|
41
|
+
params: [token, slot, value],
|
|
42
|
+
});
|
|
43
|
+
const balanceOfAbi = parseAbi(['function balanceOf(address) view returns (uint256)']);
|
|
44
|
+
const written = await publicClient.readContract({
|
|
45
|
+
address: token,
|
|
46
|
+
abi: balanceOfAbi,
|
|
47
|
+
functionName: 'balanceOf',
|
|
48
|
+
args: [holder],
|
|
49
|
+
});
|
|
50
|
+
if (written !== amount) {
|
|
51
|
+
throw new Error(`setErc20Balance: balance write mismatch on ${token} for ${holder}. ` +
|
|
52
|
+
`Expected ${amount}, got ${written}. The balance slot may differ ` +
|
|
53
|
+
`from the assumed ${balanceSlot} (FiatTokenV2.2 layout).`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convenience wrapper that funds Base Sepolia USDC on a kernel SCA. Only
|
|
58
|
+
* takes effect on an anvil fork.
|
|
59
|
+
*/
|
|
60
|
+
export async function fundUsdcOnFork(publicClient, holder, amountUsdcUnits) {
|
|
61
|
+
const usdc = process.env.TEST_ERC20_USDC_ADDRESS || '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
|
|
62
|
+
await setErc20Balance(publicClient, usdc, holder, amountUsdcUnits);
|
|
63
|
+
}
|
|
@@ -248,6 +248,37 @@ export declare function keccak256WithEncode(types: any[], values: any[]): string
|
|
|
248
248
|
* @returns the hash
|
|
249
249
|
*/
|
|
250
250
|
export declare function keccak256Packed(types: any[], values: any[]): string;
|
|
251
|
+
/**
|
|
252
|
+
* Returns the bundler RPC URL. When `BUNDLER_RPC_URL_OVERRIDE` is set
|
|
253
|
+
* (used by tests against a local Alto + anvil-fork stack), it takes precedence
|
|
254
|
+
* over the canonical ZeroDev URL.
|
|
255
|
+
*/
|
|
256
|
+
export declare function getBundlerRpcUrl(zeroDevProjectId: string, chainId: number): string;
|
|
257
|
+
/**
|
|
258
|
+
* Returns the paymaster RPC URL (ZeroDev-only; the local fork stack uses
|
|
259
|
+
* `ultra-relay` which sponsors via the bundler's executor key without a
|
|
260
|
+
* paymaster, so this URL is not consulted when `BUNDLER_RPC_URL_OVERRIDE` is
|
|
261
|
+
* set).
|
|
262
|
+
*/
|
|
263
|
+
export declare function getPaymasterRpcUrl(zeroDevProjectId: string, chainId: number): string;
|
|
264
|
+
/**
|
|
265
|
+
* Returns true when the kernel client should run in "relayer mode" — no
|
|
266
|
+
* paymaster, gas fees zeroed out. Used by tests against a local
|
|
267
|
+
* `ultra-relay` (ZeroDev's fork of Alto) on top of an anvil-fork. The relayer's
|
|
268
|
+
* executor key pays gas directly via `EntryPoint.handleOps`, avoiding the
|
|
269
|
+
* paymaster sponsorship handshake altogether.
|
|
270
|
+
*/
|
|
271
|
+
export declare function isRelayerMode(): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Returns gas prices for UserOperation fee estimation. ZeroDev's bundler
|
|
274
|
+
* exposes a custom `zd_getUserOperationGasPrice` method; standard ERC-4337
|
|
275
|
+
* bundlers do not. In relayer mode the bundler accepts UserOps with zeroed
|
|
276
|
+
* `maxFeePerGas`/`maxPriorityFeePerGas` and pays gas itself.
|
|
277
|
+
*/
|
|
278
|
+
export declare function estimateUserOperationFees(bundlerClient: any, _publicClient: any): Promise<{
|
|
279
|
+
maxFeePerGas: bigint;
|
|
280
|
+
maxPriorityFeePerGas: bigint;
|
|
281
|
+
}>;
|
|
251
282
|
/**
|
|
252
283
|
* It creates a ZeroDev Kernel client.
|
|
253
284
|
* @param signer the signer account
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockchainViemUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/BlockchainViemUtils.ts"],"names":[],"mappings":"AAOA,OAAO,EAML,mBAAmB,EAEpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,OAAO,EAYP,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAQvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAG9F,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAI3C;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;g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Aa,CAAC,oBAAoB,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEASlF;AAED;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,aAAa,EAAE,YAAY,EAC3B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,GAAG,EAAE,GACd,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAA"}
|
|
@@ -241,6 +241,49 @@ export function keccak256Packed(types, values) {
|
|
|
241
241
|
return keccak256WithEncode(types, values);
|
|
242
242
|
}
|
|
243
243
|
/////// ZERO DEV
|
|
244
|
+
/**
|
|
245
|
+
* Returns the bundler RPC URL. When `BUNDLER_RPC_URL_OVERRIDE` is set
|
|
246
|
+
* (used by tests against a local Alto + anvil-fork stack), it takes precedence
|
|
247
|
+
* over the canonical ZeroDev URL.
|
|
248
|
+
*/
|
|
249
|
+
export function getBundlerRpcUrl(zeroDevProjectId, chainId) {
|
|
250
|
+
// `||` (not `??`) because Vite replaces missing browser env vars with the
|
|
251
|
+
// empty string at build time; an empty override is equivalent to "no
|
|
252
|
+
// override" for our purposes.
|
|
253
|
+
return (process.env.BUNDLER_RPC_URL_OVERRIDE ||
|
|
254
|
+
`https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Returns the paymaster RPC URL (ZeroDev-only; the local fork stack uses
|
|
258
|
+
* `ultra-relay` which sponsors via the bundler's executor key without a
|
|
259
|
+
* paymaster, so this URL is not consulted when `BUNDLER_RPC_URL_OVERRIDE` is
|
|
260
|
+
* set).
|
|
261
|
+
*/
|
|
262
|
+
export function getPaymasterRpcUrl(zeroDevProjectId, chainId) {
|
|
263
|
+
return `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Returns true when the kernel client should run in "relayer mode" — no
|
|
267
|
+
* paymaster, gas fees zeroed out. Used by tests against a local
|
|
268
|
+
* `ultra-relay` (ZeroDev's fork of Alto) on top of an anvil-fork. The relayer's
|
|
269
|
+
* executor key pays gas directly via `EntryPoint.handleOps`, avoiding the
|
|
270
|
+
* paymaster sponsorship handshake altogether.
|
|
271
|
+
*/
|
|
272
|
+
export function isRelayerMode() {
|
|
273
|
+
return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Returns gas prices for UserOperation fee estimation. ZeroDev's bundler
|
|
277
|
+
* exposes a custom `zd_getUserOperationGasPrice` method; standard ERC-4337
|
|
278
|
+
* bundlers do not. In relayer mode the bundler accepts UserOps with zeroed
|
|
279
|
+
* `maxFeePerGas`/`maxPriorityFeePerGas` and pays gas itself.
|
|
280
|
+
*/
|
|
281
|
+
export async function estimateUserOperationFees(bundlerClient, _publicClient) {
|
|
282
|
+
if (isRelayerMode()) {
|
|
283
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
284
|
+
}
|
|
285
|
+
return getUserOperationGasPrice(bundlerClient);
|
|
286
|
+
}
|
|
244
287
|
/**
|
|
245
288
|
* It creates a ZeroDev Kernel client.
|
|
246
289
|
* @param signer the signer account
|
|
@@ -249,26 +292,29 @@ export function keccak256Packed(types, values) {
|
|
|
249
292
|
* @returns the kernel client
|
|
250
293
|
*/
|
|
251
294
|
export async function createKernelClient(kernelAccount, chainId, zeroDevProjectId, publicClient) {
|
|
252
|
-
const
|
|
295
|
+
const bundlerRpc = getBundlerRpcUrl(zeroDevProjectId, chainId);
|
|
296
|
+
const paymasterRpc = getPaymasterRpcUrl(zeroDevProjectId, chainId);
|
|
253
297
|
return createKernelAccountClient({
|
|
254
298
|
account: kernelAccount,
|
|
255
299
|
chain: getChain(chainId),
|
|
256
|
-
bundlerTransport: http(
|
|
300
|
+
bundlerTransport: http(bundlerRpc),
|
|
257
301
|
client: publicClient,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
302
|
+
...(isRelayerMode()
|
|
303
|
+
? {}
|
|
304
|
+
: {
|
|
305
|
+
paymaster: {
|
|
306
|
+
getPaymasterData: (userOperation) => {
|
|
307
|
+
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
308
|
+
chain: getChain(chainId),
|
|
309
|
+
transport: http(paymasterRpc),
|
|
310
|
+
});
|
|
311
|
+
return zerodevPaymaster.sponsorUserOperation({ userOperation });
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
}),
|
|
269
315
|
userOperation: {
|
|
270
316
|
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
271
|
-
return
|
|
317
|
+
return estimateUserOperationFees(bundlerClient, publicClient);
|
|
272
318
|
},
|
|
273
319
|
},
|
|
274
320
|
});
|
|
@@ -17,14 +17,6 @@ export declare const getBurnNFTPolicy: () => Policy;
|
|
|
17
17
|
export declare const getRegisterPolicy: () => Policy;
|
|
18
18
|
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) => Policy;
|
|
19
19
|
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) => Policy;
|
|
20
|
-
export type BurnPolicyOptions = {
|
|
21
|
-
contractAddresses: `0x${string}`[];
|
|
22
|
-
subscriberAddress: `0x${string}`;
|
|
23
|
-
maxAmount: bigint;
|
|
24
|
-
count?: number;
|
|
25
|
-
validUntil?: number;
|
|
26
|
-
};
|
|
27
|
-
export declare const getZeroDevBurnPolicies: (burnPolicyOptions: BurnPolicyOptions) => Policy[];
|
|
28
20
|
export type OrderContract = {
|
|
29
21
|
address: `0x${string}`;
|
|
30
22
|
isPayAsYouGo: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.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AA0B,CAAC,eAAe,EAAE,KAAK,MAAM,EAAE;;SAK/D,GAAG;;EAGZ;AACD,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,cACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,cAC2C,CAAA;AAExF,eAAO,MAAM,uBAAuB,cACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,cAM1B,CAAA;AAED,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,iBAAiB,cAU3B,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,WAoBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WAgBjE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,aAAa,EAAE,CAAA;IAC1B,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;IACpC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,oBAAoB,kBAAkB,KAAG,MAAM,EAgFtF,CAAA"}
|
|
@@ -85,42 +85,6 @@ export const getAllContractsPolicy = (contractAddress) => getPolicy([
|
|
|
85
85
|
...getPermissions(nft1155CreditsConfig, ['mint', 'burn']),
|
|
86
86
|
getERC20ApprovePermissions(contractAddress),
|
|
87
87
|
].filter(Boolean));
|
|
88
|
-
export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
89
|
-
const policies = [];
|
|
90
|
-
const burnPermissions = burnPolicyOptions.contractAddresses.map((contractAddress) => ({
|
|
91
|
-
target: contractAddress,
|
|
92
|
-
abi: parseAbi([
|
|
93
|
-
'function burn(address _from, uint256 _planId, uint256 _value, uint256 _keyspace, bytes calldata _signature) external',
|
|
94
|
-
]),
|
|
95
|
-
valueLimit: 0n,
|
|
96
|
-
functionName: 'burn',
|
|
97
|
-
args: [
|
|
98
|
-
{
|
|
99
|
-
condition: ParamCondition.EQUAL,
|
|
100
|
-
value: burnPolicyOptions.subscriberAddress,
|
|
101
|
-
},
|
|
102
|
-
null,
|
|
103
|
-
{
|
|
104
|
-
condition: ParamCondition.LESS_THAN_OR_EQUAL,
|
|
105
|
-
value: burnPolicyOptions.maxAmount,
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
}));
|
|
109
|
-
policies.push(getPolicy(burnPermissions));
|
|
110
|
-
if (burnPolicyOptions.count) {
|
|
111
|
-
const rateLimitPolicy = toRateLimitPolicy({
|
|
112
|
-
count: burnPolicyOptions.count,
|
|
113
|
-
});
|
|
114
|
-
policies.push(rateLimitPolicy);
|
|
115
|
-
}
|
|
116
|
-
if (burnPolicyOptions.validUntil) {
|
|
117
|
-
const timestampPolicy = toTimestampPolicy({
|
|
118
|
-
validUntil: burnPolicyOptions.validUntil,
|
|
119
|
-
});
|
|
120
|
-
policies.push(timestampPolicy);
|
|
121
|
-
}
|
|
122
|
-
return policies;
|
|
123
|
-
};
|
|
124
88
|
export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
|
|
125
89
|
const policies = [];
|
|
126
90
|
const orderPermissions = orderPolicyOptions.contracts.map((contract) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA"}
|