@nevermined-io/core-kit 0.0.58 → 0.1.0
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 +1386 -350
- package/dist/artifacts/generated.d.ts.map +1 -1
- package/dist/artifacts/generated.js +443 -14
- package/dist/contracts/AssetRegistry.js +2 -2
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +7 -31
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +11 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -1
- package/dist/nevermined/utils/BlockchainViemUtils.js +42 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +28 -11
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +68 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAddress, zeroAddress } from 'viem';
|
|
2
|
-
import { assetsRegistryConfig, nft1155CreditsAddress,
|
|
2
|
+
import { assetsRegistryConfig, nft1155CreditsAddress, nft1155ExpirableCreditsV2Address, oneTimeCreatorHookAddress, payAsYouGoTemplateAddress, protocolStandardFeesAddress, } from '../artifacts/generated.js';
|
|
3
3
|
import { AgentNotFound, PlanNotFound } from '../errors/NeverminedErrors.js';
|
|
4
4
|
import { zeroX, toAgentId } from '../utils/ConversionTypeHelpers.js';
|
|
5
5
|
import { ContractBase } from './ContractBase.js';
|
|
@@ -86,7 +86,7 @@ export class AssetRegistry extends ContractBase {
|
|
|
86
86
|
_priceConfig.templateAddress = zeroAddress;
|
|
87
87
|
if (!creditsConfig.nftAddress || !isAddress(creditsConfig.nftAddress)) {
|
|
88
88
|
if (creditsConfig.durationSecs > 0n) {
|
|
89
|
-
_creditsConfig.nftAddress =
|
|
89
|
+
_creditsConfig.nftAddress = nft1155ExpirableCreditsV2Address;
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
_creditsConfig.nftAddress = nft1155CreditsAddress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AACA,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;AAIxD,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,GAAG,CAAA;IACR,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;AAED,8BAAsB,YAAa,SAAQ,YAAY;IACrD,SAAgB,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;gBAEX,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;cAMlC,IAAI,CAClB,MAAM,EAAE,kBAAkB,EAC1B,cAAc,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAE;IAYzC,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBrE,qBAAqB,CAChC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,GAChD,OAAO,CAAC,kBAAkB,CAAC;IAiBvB,kBAAkB,CACvB,SAAS,EAAE,kBAAkB,GAAG,oBAAoB,EACpD,SAAS,CAAC,EAAE,MAAM,GAOZ,GAAG,EAAE;IA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AAM,EAAE,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAE;IAYzC,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBrE,qBAAqB,CAChC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,GAChD,OAAO,CAAC,kBAAkB,CAAC;IAiBvB,kBAAkB,CACvB,SAAS,EAAE,kBAAkB,GAAG,oBAAoB,EACpD,SAAS,CAAC,EAAE,MAAM,GAOZ,GAAG,EAAE;IAGA,SAAS,CACpB,KAAK,EAAE,cAAc,EAAE,EACvB,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;YA+E7B,wBAAwB;YA8HxB,4BAA4B;YAuB5B,oBAAoB;YAuBpB,gBAAgB;YAkGhB,qBAAqB;CAepC"}
|
|
@@ -285,38 +285,14 @@ export class ContractBase extends Instantiable {
|
|
|
285
285
|
return txReceipt;
|
|
286
286
|
}
|
|
287
287
|
async internalSimulateSmartAccount(name, from, args, txparams) {
|
|
288
|
-
const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
|
|
289
288
|
try {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
account: from,
|
|
296
|
-
|
|
297
|
-
chain: getChain(this.config.chainId),
|
|
298
|
-
// Find the RPC in your ZeroDev dashboard
|
|
299
|
-
bundlerTransport: http(ZERODEV_RPC),
|
|
300
|
-
// Required - the public client
|
|
301
|
-
client: this.contract.publicClient,
|
|
302
|
-
// Optional -- only if you want to use a paymaster
|
|
303
|
-
paymaster: {
|
|
304
|
-
getPaymasterData: (userOperation) => {
|
|
305
|
-
return zerodevPaymaster.sponsorUserOperation({
|
|
306
|
-
userOperation,
|
|
307
|
-
});
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
const data = encodeFunctionData({ abi: this.contract.abi, functionName: name, args });
|
|
312
|
-
kernelClient.estimateUserOperationGas({
|
|
313
|
-
callData: await kernelClient.account.encodeCalls([
|
|
314
|
-
{
|
|
315
|
-
to: this.address,
|
|
316
|
-
value: txparams.value || 0n,
|
|
317
|
-
data,
|
|
318
|
-
},
|
|
319
|
-
]),
|
|
289
|
+
await this.client.public.simulateContract({
|
|
290
|
+
address: this.address,
|
|
291
|
+
abi: this.contract.abi,
|
|
292
|
+
functionName: name,
|
|
293
|
+
args,
|
|
294
|
+
account: from.address,
|
|
295
|
+
...(txparams.value && { value: txparams.value }),
|
|
320
296
|
});
|
|
321
297
|
return true;
|
|
322
298
|
}
|
|
@@ -260,6 +260,17 @@ export declare function getApproval(signer: Signer, publicClient: any, policies:
|
|
|
260
260
|
export declare function useSessionKey(approval: string, signer: Signer, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
|
|
261
261
|
export declare function createSessionKey(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
|
|
262
262
|
export declare function getSessionKey(serializedSessionKey: string, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
|
|
263
|
+
/**
|
|
264
|
+
* Creates a delegated session key for an existing kernel account.
|
|
265
|
+
* The resulting serialized session key can be deserialized into a SmartAccount
|
|
266
|
+
* that shares the same address as the kernel account but enforces the given policies.
|
|
267
|
+
*
|
|
268
|
+
* @param kernelAccount The existing SmartAccount (kernel) to delegate from
|
|
269
|
+
* @param publicClient Viem PublicClient instance
|
|
270
|
+
* @param policies Array of policies to enforce for this session key
|
|
271
|
+
* @returns Serialized session key string
|
|
272
|
+
*/
|
|
273
|
+
export declare function createDelegatedSessionKeyFromKernel(kernelAccount: SmartAccount, publicClient: PublicClient, policies: any[]): Promise<string>;
|
|
263
274
|
export declare const WalletUtils: {
|
|
264
275
|
makeWallet: typeof makeWallet;
|
|
265
276
|
makeWallets: typeof makeWallets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockchainViemUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/BlockchainViemUtils.ts"],"names":[],"mappings":"AAOA,OAAO,EAML,mBAAmB,
|
|
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,EAaP,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;AAI9F,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAI3C;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,MAAM,EAAE,kBAAkB;CAIvC;AAQD;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,SAAa,EACb,YAAY,GACb,EAAE;IACD,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,E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AE,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"}
|
|
@@ -358,6 +358,48 @@ export async function getSessionKey(serializedSessionKey, publicClient) {
|
|
|
358
358
|
const sessionKeyAccount = await deserializePermissionAccount(publicClient, getEntryPoint(ENTRY_POINT_VERSION), KERNEL_V3_1, serializedSessionKey);
|
|
359
359
|
return sessionKeyAccount;
|
|
360
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Creates a delegated session key for an existing kernel account.
|
|
363
|
+
* The resulting serialized session key can be deserialized into a SmartAccount
|
|
364
|
+
* that shares the same address as the kernel account but enforces the given policies.
|
|
365
|
+
*
|
|
366
|
+
* @param kernelAccount The existing SmartAccount (kernel) to delegate from
|
|
367
|
+
* @param publicClient Viem PublicClient instance
|
|
368
|
+
* @param policies Array of policies to enforce for this session key
|
|
369
|
+
* @returns Serialized session key string
|
|
370
|
+
*/
|
|
371
|
+
export async function createDelegatedSessionKeyFromKernel(kernelAccount, publicClient, policies) {
|
|
372
|
+
// 1) Generate ephemeral session private key (used only for the permission plugin)
|
|
373
|
+
const sessionPrivateKey = generatePrivateKey();
|
|
374
|
+
const sessionAccount = privateKeyToAccount(sessionPrivateKey);
|
|
375
|
+
// 2) Wrap ephemeral key as ECDSA signer for permissions
|
|
376
|
+
const sessionKeySigner = await toECDSASigner({ signer: sessionAccount });
|
|
377
|
+
// 3) Create the permission validator plugin
|
|
378
|
+
const permissionValidator = await toPermissionValidator(publicClient, {
|
|
379
|
+
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
380
|
+
signer: sessionKeySigner,
|
|
381
|
+
policies,
|
|
382
|
+
kernelVersion: KERNEL_V3_1,
|
|
383
|
+
});
|
|
384
|
+
// 4) Extract the sudo validator from the existing kernel account
|
|
385
|
+
const kernelAccountTyped = kernelAccount;
|
|
386
|
+
const sudoValidator = kernelAccountTyped.kernelPluginManager.sudoValidator;
|
|
387
|
+
if (!sudoValidator) {
|
|
388
|
+
throw new Error('Kernel account does not have a sudo validator');
|
|
389
|
+
}
|
|
390
|
+
// 5) Create a new kernel account with both sudo (from original) and permission validator
|
|
391
|
+
const sessionKeyAccount = await createKernelAccount(publicClient, {
|
|
392
|
+
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
393
|
+
plugins: {
|
|
394
|
+
sudo: sudoValidator, // Use existing sudo validator
|
|
395
|
+
regular: permissionValidator,
|
|
396
|
+
},
|
|
397
|
+
kernelVersion: KERNEL_V3_1,
|
|
398
|
+
});
|
|
399
|
+
// 6) Serialize the session key account with the ephemeral private key
|
|
400
|
+
const serialized = await serializePermissionAccount(sessionKeyAccount, sessionPrivateKey);
|
|
401
|
+
return serialized;
|
|
402
|
+
}
|
|
361
403
|
export const WalletUtils = {
|
|
362
404
|
makeWallet,
|
|
363
405
|
makeWallets,
|
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import { Abi } from 'viem';
|
|
2
|
-
|
|
2
|
+
import { Policy } from '@zerodev/permissions';
|
|
3
|
+
export declare function getPolicy(permissions: any[]): Policy;
|
|
3
4
|
export declare function getPermissions(config: any, functionNames: string[]): any[];
|
|
4
5
|
export declare function getERC20ApprovePermissions(contractAddress: `0x${string}`): {
|
|
5
6
|
target: `0x${string}`;
|
|
6
7
|
abi: Abi;
|
|
7
8
|
functionName: string;
|
|
8
9
|
};
|
|
9
|
-
export declare const getERC20ApprovePolicy: (contractAddress: `0x${string}`) =>
|
|
10
|
-
export declare const getAgentRegistrationPolicy: () =>
|
|
11
|
-
export declare const getPricingPlanRegistrationPolicy: () =>
|
|
12
|
-
export declare const getRegisterAssetsPolicy: () =>
|
|
13
|
-
export declare const getOrderPolicy: () =>
|
|
14
|
-
export declare const getMintNFTPolicy: () =>
|
|
15
|
-
export declare const getBurnNFTPolicy: () =>
|
|
16
|
-
export declare const getRegisterPolicy: () =>
|
|
17
|
-
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) =>
|
|
18
|
-
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) =>
|
|
10
|
+
export declare const getERC20ApprovePolicy: (contractAddress: `0x${string}`) => Policy;
|
|
11
|
+
export declare const getAgentRegistrationPolicy: () => Policy;
|
|
12
|
+
export declare const getPricingPlanRegistrationPolicy: () => Policy;
|
|
13
|
+
export declare const getRegisterAssetsPolicy: () => Policy;
|
|
14
|
+
export declare const getOrderPolicy: () => Policy;
|
|
15
|
+
export declare const getMintNFTPolicy: () => Policy;
|
|
16
|
+
export declare const getBurnNFTPolicy: () => Policy;
|
|
17
|
+
export declare const getRegisterPolicy: () => Policy;
|
|
18
|
+
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) => Policy;
|
|
19
|
+
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) => Policy;
|
|
20
|
+
export type BurnPolicyOptions = {
|
|
21
|
+
contractAddress: `0x${string}`;
|
|
22
|
+
planId: bigint;
|
|
23
|
+
subscriberAddress: `0x${string}`;
|
|
24
|
+
maxAmount: bigint;
|
|
25
|
+
count?: number;
|
|
26
|
+
};
|
|
27
|
+
export declare const getZeroDevBurnPolicies: (burnPolicyOptions: BurnPolicyOptions) => Policy[];
|
|
28
|
+
export type OrderPolicyOptions = {
|
|
29
|
+
contractAddress: `0x${string}`;
|
|
30
|
+
planId: bigint;
|
|
31
|
+
subscriberAddress: `0x${string}`;
|
|
32
|
+
numberOfPurchases: bigint;
|
|
33
|
+
count?: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const getZeroDevOrderPolicies: (orderPolicyOptions: OrderPolicyOptions) => Policy[];
|
|
19
36
|
//# sourceMappingURL=ZeroDevPolicies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,GAAG,EAAY,MAAM,MAAM,CAAA;AACpC,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,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,WAmBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WAejE,CAAA;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,mBAAmB,iBAAiB,KAAG,MAAM,EAkCnF,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,iBAAiB,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,oBAAoB,kBAAkB,KAAG,MAAM,EAmCtF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallPolicyVersion, toCallPolicy } from '@zerodev/permissions/policies';
|
|
1
|
+
import { CallPolicyVersion, ParamCondition, toCallPolicy, toRateLimitPolicy, } from '@zerodev/permissions/policies';
|
|
2
2
|
import { assetsRegistryConfig, fixedPaymentTemplateConfig, nft1155CreditsConfig, payAsYouGoTemplateAddress, } from '../../artifacts/generated.js';
|
|
3
3
|
import { parseAbi } from 'viem';
|
|
4
4
|
export function getPolicy(permissions) {
|
|
@@ -83,3 +83,70 @@ export const getAllContractsPolicy = (contractAddress) => getPolicy([
|
|
|
83
83
|
...getPermissions(nft1155CreditsConfig, ['mint', 'burn']),
|
|
84
84
|
getERC20ApprovePermissions(contractAddress),
|
|
85
85
|
].filter(Boolean));
|
|
86
|
+
export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
87
|
+
const policies = [];
|
|
88
|
+
const burnPolicy = {
|
|
89
|
+
target: burnPolicyOptions.contractAddress,
|
|
90
|
+
abi: parseAbi([
|
|
91
|
+
'function burn(address _from, uint256 _planId, uint256 _value, uint256 _keyspace, bytes calldata _signature) external',
|
|
92
|
+
]),
|
|
93
|
+
valueLimit: 0n,
|
|
94
|
+
functionName: 'burn',
|
|
95
|
+
args: [
|
|
96
|
+
{
|
|
97
|
+
condition: ParamCondition.EQUAL,
|
|
98
|
+
value: burnPolicyOptions.subscriberAddress,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
condition: ParamCondition.EQUAL,
|
|
102
|
+
value: '0x' + burnPolicyOptions.planId.toString(16).padStart(64, '0'),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
condition: ParamCondition.LESS_THAN_OR_EQUAL,
|
|
106
|
+
value: burnPolicyOptions.maxAmount,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
policies.push(getPolicy([burnPolicy]));
|
|
111
|
+
if (burnPolicyOptions.count) {
|
|
112
|
+
const rateLimitPolicy = toRateLimitPolicy({
|
|
113
|
+
count: burnPolicyOptions.count,
|
|
114
|
+
});
|
|
115
|
+
policies.push(rateLimitPolicy);
|
|
116
|
+
}
|
|
117
|
+
return policies;
|
|
118
|
+
};
|
|
119
|
+
export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
|
|
120
|
+
const policies = [];
|
|
121
|
+
const orderCallPolicy = {
|
|
122
|
+
target: orderPolicyOptions.contractAddress,
|
|
123
|
+
abi: parseAbi([
|
|
124
|
+
'function order(bytes32 _seed, uint256 _planId, address _creditsReceiver, uint256 _numberOfPurchases, bytes[] memory _params) external payable',
|
|
125
|
+
]),
|
|
126
|
+
valueLimit: 0n,
|
|
127
|
+
functionName: 'order',
|
|
128
|
+
args: [
|
|
129
|
+
null,
|
|
130
|
+
{
|
|
131
|
+
condition: ParamCondition.EQUAL,
|
|
132
|
+
value: '0x' + orderPolicyOptions.planId.toString(16).padStart(64, '0'),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
condition: ParamCondition.EQUAL,
|
|
136
|
+
value: orderPolicyOptions.subscriberAddress,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
condition: ParamCondition.EQUAL,
|
|
140
|
+
value: orderPolicyOptions.numberOfPurchases,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
policies.push(getPolicy([orderCallPolicy]));
|
|
145
|
+
if (orderPolicyOptions.count) {
|
|
146
|
+
const rateLimitPolicy = toRateLimitPolicy({
|
|
147
|
+
count: orderPolicyOptions.count,
|
|
148
|
+
});
|
|
149
|
+
policies.push(rateLimitPolicy);
|
|
150
|
+
}
|
|
151
|
+
return policies;
|
|
152
|
+
};
|