@nevermined-io/core-kit 0.2.15 → 0.3.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/dist/artifacts/generated.d.ts +85 -1197
- package/dist/artifacts/generated.d.ts.map +1 -1
- package/dist/artifacts/generated.js +62 -476
- package/dist/contracts/AssetRegistry.d.ts +1 -1
- package/dist/contracts/ContractBase.d.ts +11 -1
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +62 -28
- package/dist/contracts/NFT1155Base.d.ts +4 -2
- package/dist/contracts/NFT1155Base.d.ts.map +1 -1
- package/dist/contracts/NFT1155Base.js +2 -2
- 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
|
@@ -69,7 +69,7 @@ export declare class AssetRegistry extends ContractBase {
|
|
|
69
69
|
creditsConfig: {
|
|
70
70
|
isRedemptionAmountFixed: boolean;
|
|
71
71
|
redemptionType: import("@nevermined-io/commons").RedemptionType;
|
|
72
|
-
|
|
72
|
+
onchainMirror: boolean;
|
|
73
73
|
durationSecs: bigint;
|
|
74
74
|
amount: bigint;
|
|
75
75
|
minAmount: bigint;
|
|
@@ -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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iB,CAC5B,KAAK,EAAE,sBAAsB,EAAE,EAC/B,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,MAAM,GAAE,YAAiB;IAgBd,QAAQ,CACnB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,YAAiB;IAgBd,IAAI,CACf,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,YAAiB,GACxB,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;YAiBvC,6BAA6B;IA2E3C,OAAO,CAAC,qBAAqB;YAaf,wBAAwB;YAgHxB,4BAA4B;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,4 +1,5 @@
|
|
|
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';
|
|
@@ -164,17 +165,15 @@ export class ContractBase extends Instantiable {
|
|
|
164
165
|
contractAddress: this.address,
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
168
168
|
const kernelClient = createKernelAccountClient({
|
|
169
169
|
account: from,
|
|
170
170
|
chain: getChain(this.config.chainId),
|
|
171
|
-
bundlerTransport: http(this.
|
|
171
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
172
172
|
client: this.client.public,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
173
|
+
...this.getPaymasterConfig(),
|
|
174
|
+
userOperation: {
|
|
175
|
+
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
176
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
178
177
|
},
|
|
179
178
|
},
|
|
180
179
|
});
|
|
@@ -208,6 +207,7 @@ export class ContractBase extends Instantiable {
|
|
|
208
207
|
const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
209
208
|
this.logger.debug(`Transaction mined - UserOperationHash: ${userOpHash}`);
|
|
210
209
|
this.logger.debug(`Transaction receipt - TransactionHash: ${txReceipt.receipt.transactionHash}`);
|
|
210
|
+
this.assertUserOpSucceeded(txReceipt, 'multicall', userOpHash);
|
|
211
211
|
return txReceipt.receipt;
|
|
212
212
|
}
|
|
213
213
|
catch (err) {
|
|
@@ -218,6 +218,13 @@ export class ContractBase extends Instantiable {
|
|
|
218
218
|
throw new ContractsError(`Multicall failed: ${err}`);
|
|
219
219
|
}
|
|
220
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
|
+
}
|
|
221
228
|
async internalSendSmartAccount(name, from, args, txparams, progress) {
|
|
222
229
|
const functionInputs = getInputsOfFunctionFormatted(this.contract.abi, name, args);
|
|
223
230
|
const { gasLimit, value } = txparams;
|
|
@@ -250,17 +257,15 @@ export class ContractBase extends Instantiable {
|
|
|
250
257
|
}
|
|
251
258
|
throw new ContractsError(`Calling method "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
|
|
252
259
|
}
|
|
253
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
254
260
|
const kernelClient = createKernelAccountClient({
|
|
255
261
|
account: from,
|
|
256
262
|
chain: getChain(this.config.chainId),
|
|
257
|
-
bundlerTransport: http(this.
|
|
263
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
258
264
|
client: this.client.public,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
265
|
+
...this.getPaymasterConfig(),
|
|
266
|
+
userOperation: {
|
|
267
|
+
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
268
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
264
269
|
},
|
|
265
270
|
},
|
|
266
271
|
});
|
|
@@ -298,6 +303,7 @@ export class ContractBase extends Instantiable {
|
|
|
298
303
|
});
|
|
299
304
|
}
|
|
300
305
|
const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
306
|
+
this.assertUserOpSucceeded(txReceipt, name, userOpHash);
|
|
301
307
|
if (progress) {
|
|
302
308
|
progress({
|
|
303
309
|
stage: 'receipt',
|
|
@@ -485,22 +491,15 @@ export class ContractBase extends Instantiable {
|
|
|
485
491
|
}
|
|
486
492
|
async internalSimulateMulticallSmartAccount(calls, from, txparams) {
|
|
487
493
|
try {
|
|
488
|
-
const zerodevPaymaster = this.getOrCreatePaymaster();
|
|
489
494
|
const kernelClient = createKernelAccountClient({
|
|
490
495
|
account: from,
|
|
491
496
|
chain: getChain(this.config.chainId),
|
|
492
|
-
bundlerTransport: http(this.
|
|
497
|
+
bundlerTransport: http(this.getBundlerRPC()),
|
|
493
498
|
client: this.client.public,
|
|
494
|
-
|
|
495
|
-
getPaymasterData: (userOperation) => {
|
|
496
|
-
return zerodevPaymaster.sponsorUserOperation({
|
|
497
|
-
userOperation,
|
|
498
|
-
});
|
|
499
|
-
},
|
|
500
|
-
},
|
|
499
|
+
...this.getPaymasterConfig(),
|
|
501
500
|
userOperation: {
|
|
502
501
|
estimateFeesPerGas: async ({ bundlerClient }) => {
|
|
503
|
-
return
|
|
502
|
+
return estimateUserOperationFees(bundlerClient, this.client.public);
|
|
504
503
|
},
|
|
505
504
|
},
|
|
506
505
|
});
|
|
@@ -549,12 +548,47 @@ export class ContractBase extends Instantiable {
|
|
|
549
548
|
if (!this._zeroDevPaymaster) {
|
|
550
549
|
this._zeroDevPaymaster = createZeroDevPaymasterClient({
|
|
551
550
|
chain: getChain(this.config.chainId),
|
|
552
|
-
transport: http(this.
|
|
551
|
+
transport: http(this.getPaymasterRPC()),
|
|
553
552
|
});
|
|
554
553
|
}
|
|
555
554
|
return this._zeroDevPaymaster;
|
|
556
555
|
}
|
|
557
|
-
|
|
558
|
-
|
|
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);
|
|
559
593
|
}
|
|
560
594
|
}
|
|
@@ -39,10 +39,12 @@ export declare abstract class NFT1155Base extends ContractBase {
|
|
|
39
39
|
owner: Account | SmartAccount;
|
|
40
40
|
txParams?: TxParameters;
|
|
41
41
|
}): Promise<import("viem").TransactionReceipt | import("viem").UserOperationReceipt>;
|
|
42
|
-
burnBatch({ from, planIds, amounts, owner, txParams, }: {
|
|
43
|
-
from: Address
|
|
42
|
+
burnBatch({ from, planIds, amounts, keyspace, signature, owner, txParams, }: {
|
|
43
|
+
from: Address;
|
|
44
44
|
planIds: bigint[];
|
|
45
45
|
amounts: bigint[];
|
|
46
|
+
keyspace?: bigint;
|
|
47
|
+
signature?: string;
|
|
46
48
|
owner: Account | SmartAccount;
|
|
47
49
|
txParams?: TxParameters;
|
|
48
50
|
}): Promise<import("viem").TransactionReceipt | import("viem").UserOperationReceipt>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,OAAO,GAAG,YAAY,CAAA;QAC7B,QAAQ,CAAC,EAAE,YAAY,CAAA;KACxB;IASY,SAAS,CAAC,EACrB,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,GACT,EAAE;QACD,IAAI,EAAE,OAAO,CAAA;QACb,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,OAAO,GAAG,YAAY,CAAA;QAC7B,QAAQ,CAAC,EAAE,YAAY,CAAA;KACxB;CAQF"}
|
|
@@ -18,7 +18,7 @@ export class NFT1155Base extends ContractBase {
|
|
|
18
18
|
async burn({ from, planId, amount, keyspace, signature, owner, txParams, }) {
|
|
19
19
|
return this.send('burn', owner, [from, planId, amount, keyspace ?? 0n, signature ?? '0x'], txParams);
|
|
20
20
|
}
|
|
21
|
-
async burnBatch({ from, planIds, amounts, owner, txParams, }) {
|
|
22
|
-
return this.send('burnBatch', owner, [from, planIds, amounts], txParams);
|
|
21
|
+
async burnBatch({ from, planIds, amounts, keyspace, signature, owner, txParams, }) {
|
|
22
|
+
return this.send('burnBatch', owner, [from, planIds, amounts, keyspace ?? 0n, signature ?? '0x'], txParams);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -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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OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,mBAAmB,CAAC,CA4B9B;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,YAAY,CAAC,CAcvB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBAyBnF;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEAatF;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBA6BxF;AAED,wBAAsB,aAAa,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.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,GAAG,EAAoC,MAAM,MAAM,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,UAK3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,SAelE;AAED,wBAAgB,0BAA0B,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,CAA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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"}
|