@nevermined-io/core-kit 1.10.0 → 1.11.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.
@@ -56,6 +56,17 @@ export declare class AssetRegistry extends ContractBase {
56
56
  planExists(id: bigint): Promise<boolean>;
57
57
  addPlanToAgent(planId: bigint, agentId: string | bigint, owner: Account | SmartAccount, txParams?: TxParameters): Promise<TransactionReceipt | UserOperationReceipt>;
58
58
  removePlanFromAgent(planId: bigint, agentId: string | bigint, owner: Account | SmartAccount, txParams?: TxParameters): Promise<TransactionReceipt | UserOperationReceipt>;
59
+ /**
60
+ * Move an agent's on-chain ownership. Only the CURRENT owner can call it.
61
+ *
62
+ * Used by the EIP-7702 migration healing path (#2152): a user's pre-migration
63
+ * agents stay owned by their Kernel v3.1 SCA while every new write is signed by
64
+ * their 7702 EOA, so the SCA hands the agent over before the EOA can operate on
65
+ * it. Deliberately NOT part of the session-key CallPolicy (`REGISTER_GROUP_FNS`)
66
+ * — it is signed by the SCA's sudo validator, and the merkle is already at its
67
+ * Tempo enable-gas ceiling (#1929).
68
+ */
69
+ transferAgentOwnership(agentId: string | bigint, newOwner: `0x${string}`, owner: Account | SmartAccount, txParams?: TxParameters): Promise<TransactionReceipt | UserOperationReceipt>;
59
70
  planConfigPreFilter(priceConfig: PriceConfig, creditsConfig: CreditsConfig, includeFees?: boolean, organizationCryptoFee?: bigint, organizationCryptoWallet?: string): Promise<{
60
71
  priceConfig: {
61
72
  isCrypto: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"AssetRegistry.d.ts","sourceRoot":"","sources":["../../src/contracts/AssetRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACnF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAa,kBAAkB,EAAe,MAAM,MAAM,CAAA;AACnF,OAAO,EAAE,YAAY,EAAE,oB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C,EAAE,MAAM,EAC9B,wBAAwB,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IA+CtB,UAAU,CACrB,YAAY,EAAE,WAAW,EACzB,cAAc,EAAE,aAAa,EAC7B,KAAK,EAAE,OAAO,EACd,OAAO,UAAO,EACd,KAAK,SAAK,EACV,qBAAqB,CAAC,EAAE,MAAM,EAC9B,wBAAwB,CAAC,EAAE,MAAM,GAChC,OAAO,CAAC,MAAM,CAAC;IAsClB;;;;OAIG;IACU,yBAAyB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOlF;;;;;;;OAOG;IACU,iCAAiC,CAC5C,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAQhC;;;;;;OAMG;IACU,6BAA6B,CACxC,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;CAOjC"}
@@ -106,6 +106,21 @@ export class AssetRegistry extends ContractBase {
106
106
  planId
107
107
  ], txParams);
108
108
  }
109
+ /**
110
+ * Move an agent's on-chain ownership. Only the CURRENT owner can call it.
111
+ *
112
+ * Used by the EIP-7702 migration healing path (#2152): a user's pre-migration
113
+ * agents stay owned by their Kernel v3.1 SCA while every new write is signed by
114
+ * their 7702 EOA, so the SCA hands the agent over before the EOA can operate on
115
+ * it. Deliberately NOT part of the session-key CallPolicy (`REGISTER_GROUP_FNS`)
116
+ * — it is signed by the SCA's sudo validator, and the merkle is already at its
117
+ * Tempo enable-gas ceiling (#1929).
118
+ */ async transferAgentOwnership(agentId, newOwner, owner, txParams) {
119
+ return this.send('transferAgentOwnership', owner, [
120
+ toAgentId(agentId),
121
+ newOwner
122
+ ], txParams);
123
+ }
109
124
  async planConfigPreFilter(priceConfig, creditsConfig, includeFees = true, organizationCryptoFee, organizationCryptoWallet) {
110
125
  const _priceConfig = {
111
126
  ...priceConfig
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/AssetRegistry.ts"],"sourcesContent":["import { CreditsConfig, DIDAgent, Plan, PriceConfig } from '@nevermined-io/commons'\nimport { Account, Address, isAddress, TransactionReceipt, zeroAddress } from 'viem'\nimport { SmartAccount, UserOperationReceipt } from 'viem/account-abstraction'\nimport {\n assetsRegistryConfig,\n nft1155CreditsAddress,\n nft1155ExpirableCreditsV2Address,\n oneTimeCreatorHookAddress,\n payAsYouGoTemplateAddress,\n protocolStandardFeesAddress,\n} from '../artifacts/generated.js'\nimport { AgentNotFound, PlanNotFound } from '../errors/NeverminedErrors.js'\nimport { InstantiableConfig } from '../Instantiable.abstract.js'\nimport { TxParameters } from '../models/Transactions.js'\nimport { toAgentId, zeroX } from '../utils/ConversionTypeHelpers.js'\nimport { ContractBase } from './ContractBase.js'\n\n/**\n * Loose structural type for the ABI items we filter in `hashPlanId` to\n * disambiguate the legacy 3-arg overload from the 4-arg one. Mirrors only\n * the fields we read, so it stays usable against the auto-generated tuple\n * type emitted by wagmi codegen without dragging in the full viem type.\n */\ntype AbiItemLike = {\n type: string\n name?: string\n inputs?: ReadonlyArray<unknown>\n}\n\nexport class AssetRegistry extends ContractBase {\n public static override async getInstance(config: InstantiableConfig): Promise<AssetRegistry> {\n const assetRegistry: AssetRegistry = new AssetRegistry(\n 'AssetRegistry',\n assetsRegistryConfig.address,\n )\n await assetRegistry.init(config, assetsRegistryConfig)\n return assetRegistry\n }\n\n public async hashAgentId(seed: string, owner: Address): Promise<bigint> {\n return this.contract.read.hashAgentId([seed, owner])\n }\n\n public async getAgent(agentId: string | bigint): Promise<DIDAgent> {\n const didAgent = await this.contract.read.getAgent([toAgentId(agentId)])\n if (didAgent.lastUpdated != 0) return didAgent\n else throw new AgentNotFound(`Agent with id ${agentId} not found`)\n }\n\n public async register({\n seed,\n url,\n plans,\n owner,\n txParams,\n }: {\n seed: string\n url: string\n plans: bigint[]\n owner: Account | SmartAccount\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('register', owner, [zeroX(seed), url, plans], txParams)\n }\n\n public async createPayAsYouGoPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce = 0n,\n addFees = true,\n isTrialPlan = false,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n nonce?: bigint\n addFees?: boolean\n isTrialPlan?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n priceConfig.templateAddress = payAsYouGoTemplateAddress\n return this.createPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce,\n addFees,\n isTrialPlan,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n })\n }\n\n public async createPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce = 0n,\n addFees = true,\n isTrialPlan = false,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n nonce?: bigint\n addFees?: boolean\n isTrialPlan?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n const _config = await this.planConfigPreFilter(\n priceConfig,\n creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n\n if (isTrialPlan) {\n const hooks: Address[] = [oneTimeCreatorHookAddress]\n return this.send(\n 'createPlanWithHooks',\n owner,\n [_config.priceConfig, _config.creditsConfig, hooks, nonce],\n txParams,\n )\n } else {\n return this.send(\n 'createPlan',\n owner,\n [_config.priceConfig, _config.creditsConfig, nonce],\n txParams,\n )\n }\n }\n\n public async registerAgentAndPlan({\n seed,\n url,\n priceConfig,\n creditsConfig,\n owner,\n addFees = true,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n seed: string\n url: string\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n addFees?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n const _config = await this.planConfigPreFilter(\n priceConfig,\n creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n\n return this.send(\n 'registerAgentAndPlan',\n owner,\n [zeroX(seed), url, _config.priceConfig, _config.creditsConfig],\n txParams,\n )\n }\n\n public async getPlan(planId: bigint): Promise<Plan> {\n const plan = this.contract.read.getPlan([planId])\n if (plan.lastUpdated != 0) return plan\n else throw new PlanNotFound('Plan not registered')\n }\n\n public async getPlanTotalPrice({\n planId,\n plan,\n }: {\n planId?: bigint\n plan?: Plan\n }): Promise<bigint> {\n if (!plan && !planId) {\n throw new PlanNotFound('Plan not registered')\n }\n if (!plan) {\n plan = await this.getPlan(planId!)\n }\n\n if (plan.lastUpdated === 0n) throw new PlanNotFound('Plan not registered')\n return plan.price.amounts.reduce((a: bigint, b: bigint) => a + b, 0n)\n }\n\n public async planExists(id: bigint): Promise<boolean> {\n return this.contract.read.planExists([id])\n }\n\n public async addPlanToAgent(\n planId: bigint,\n agentId: string | bigint,\n owner: Account | SmartAccount,\n txParams?: TxParameters,\n ): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('addPlanToAgent', owner, [toAgentId(agentId), planId], txParams)\n }\n\n public async removePlanFromAgent(\n planId: bigint,\n agentId: string | bigint,\n owner: Account | SmartAccount,\n txParams?: TxParameters,\n ): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('removePlanFromAgent', owner, [toAgentId(agentId), planId], txParams)\n }\n\n public async planConfigPreFilter(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n includeFees = true,\n organizationCryptoFee?: bigint,\n organizationCryptoWallet?: string,\n ) {\n const _priceConfig = { ...priceConfig }\n // Compat shim: the contract ABI in `artifacts/generated.ts` still names\n // the credits-config slot `proofRequired` (legacy EIP-712 signed-burn\n // flag, see nvm-monorepo#1253). The TS interface renamed it to\n // `onchainMirror` in PR #1277. Viem looks up tuple components by name\n // when ABI-encoding, so without this alias every downstream\n // `contract.read.*([creditsConfig, ...])` call resolves the slot to\n // `undefined` and throws \"Invalid boolean value: 'undefined'\". Inject\n // the alias here so every method that runs through `planConfigPreFilter`\n // (`createPlan`, `hashPlanId`, `registerAgentAndPlan`,\n // `includeFeesInPaymentsDistribution` via line 244) sees a config\n // viem can encode. Drop once the contract artifact is regenerated.\n const _creditsConfig = {\n ...creditsConfig,\n proofRequired: creditsConfig.onchainMirror,\n }\n\n if (!priceConfig.feeController || !isAddress(priceConfig.feeController!))\n _priceConfig.feeController = protocolStandardFeesAddress\n\n if (!priceConfig.templateAddress || !isAddress(priceConfig.templateAddress!))\n _priceConfig.templateAddress = zeroAddress\n\n if (!creditsConfig.nftAddress || !isAddress(creditsConfig.nftAddress)) {\n if (creditsConfig.durationSecs > 0n) {\n _creditsConfig.nftAddress = nft1155ExpirableCreditsV2Address\n } else {\n _creditsConfig.nftAddress = nft1155CreditsAddress\n }\n }\n\n if (includeFees) {\n const fees = await this.includeFeesInPaymentsDistribution(_priceConfig, _creditsConfig)\n _priceConfig.amounts = fees[0]\n _priceConfig.receivers = fees[1]\n }\n\n if (organizationCryptoFee && organizationCryptoWallet) {\n _priceConfig.amounts.push(organizationCryptoFee)\n _priceConfig.receivers.push(organizationCryptoWallet)\n }\n\n return { priceConfig: _priceConfig, creditsConfig: _creditsConfig }\n }\n\n public async hashPlanId(\n _priceConfig: PriceConfig,\n _creditsConfig: CreditsConfig,\n owner: Address,\n addFees = true,\n nonce = 0n,\n organizationCryptoFee?: bigint,\n organizationCryptoWallet?: string,\n ): Promise<bigint> {\n const _config = await this.planConfigPreFilter(\n _priceConfig,\n _creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n // The generated ABI carries both the legacy 3-arg `hashPlanId(_priceConfig,\n // _creditsConfig, _creator)` overload and the new 4-arg\n // `hashPlanId(_priceConfig, _creditsConfig, _creator, _nonce)` overload.\n // Viem's `getContract().read.<name>` proxy resolves overloads by NAME\n // only — it picks the first matching ABI item without re-checking\n // arity — so the 4-arg call below was being encoded against the 3-arg\n // overload and erroring with `AbiEncodingLengthMismatchError: Expected\n // length 3, Given length 4` (CI run 25872339578, core-kit e2e).\n //\n // Drop directly to `readContract` with an ABI restricted to the 4-arg\n // function so there's only one possible match. Same effect as\n // dropping the legacy overload from the artifact, but local to this\n // call site (the artifact is regenerated by `pnpm generate:wagmi:*`\n // from the protocol submodule, so a tree-side artifact edit would be\n // wiped on the next codegen).\n const hashPlanIdAbi = (this.contract.abi as readonly AbiItemLike[]).filter(\n (item) =>\n item.type === 'function' &&\n item.name === 'hashPlanId' &&\n Array.isArray(item.inputs) &&\n item.inputs.length === 4,\n )\n return (await this.client.public.readContract({\n address: this.address,\n abi: hashPlanIdAbi,\n functionName: 'hashPlanId',\n args: [_config.priceConfig, _config.creditsConfig, owner, nonce],\n })) as bigint\n }\n\n /**\n * @notice Checks if Nevermined fees are included in the payment distribution\n * @param _planId The ID of the plan to check\n * @return bool True if Nevermined fees are properly included\n */\n public async areNeverminedFeesIncluded(priceConfig: PriceConfig): Promise<boolean> {\n return await this.contract.read.areNeverminedFeesIncluded([\n priceConfig.amounts,\n priceConfig.receivers,\n ])\n }\n\n /**\n * @notice Getting a payment distribution, it includes the Nevermined fees if not already included\n * This method subsctracts the fees from the original amounts and adds a new entry for the fee recipient\n * @param priceConfig The price configuration of the plan\n * @param creditsConfig The credits configuration of the plan\n * @return amounts Updated array of payment amounts including fees\n * @return receivers Updated array of payment receivers including fee recipient\n */\n public async includeFeesInPaymentsDistribution(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n ): Promise<[bigint[], string[]]> {\n const result = await this.contract.read.includeFeesInPaymentsDistribution([\n priceConfig,\n creditsConfig,\n ])\n return result\n }\n\n /**\n * @notice Adds Nevermined fees to the payment distribution if not already included\n * @param priceConfig The price configuration of the plan\n * @param creditsConfig The credits configuration of the plan\n * @return amounts Updated array of payment amounts including fees\n * @return receivers Updated array of payment receivers including fee recipient\n */\n public async addFeesToPaymentsDistribution(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n ): Promise<[bigint[], string[]]> {\n const result = await this.contract.read.addFeesToPaymentsDistribution([\n priceConfig,\n creditsConfig,\n ])\n return result\n }\n}\n"],"names":["isAddress","zeroAddress","assetsRegistryConfig","nft1155CreditsAddress","nft1155ExpirableCreditsV2Address","oneTimeCreatorHookAddress","payAsYouGoTemplateAddress","protocolStandardFeesAddress","AgentNotFound","PlanNotFound","toAgentId","zeroX","ContractBase","AssetRegistry","getInstance","config","assetRegistry","address","init","hashAgentId","seed","owner","contract","read","getAgent","agentId","didAgent","lastUpdated","register","url","plans","txParams","send","createPayAsYouGoPlan","priceConfig","creditsConfig","nonce","addFees","isTrialPlan","organizationCryptoFee","organizationCryptoWallet","templateAddress","createPlan","_config","planConfigPreFilter","hooks","registerAgentAndPlan","getPlan","planId","plan","getPlanTotalPrice","price","amounts","reduce","a","b","planExists","id","addPlanToAgent","removePlanFromAgent","includeFees","_priceConfig","_creditsConfig","proofRequired","onchainMirror","feeController","nftAddress","durationSecs","fees","includeFeesInPaymentsDistribution","receivers","push","hashPlanId","hashPlanIdAbi","abi","filter","item","type","name","Array","isArray","inputs","length","client","public","readContract","functionName","args","areNeverminedFeesIncluded","result","addFeesToPaymentsDistribution"],"mappings":"AACA,SAA2BA,SAAS,EAAsBC,WAAW,QAAQ,OAAM;AAEnF,SACEC,oBAAoB,EACpBC,qBAAqB,EACrBC,gCAAgC,EAChCC,yBAAyB,EACzBC,yBAAyB,EACzBC,2BAA2B,QACtB,4BAA2B;AAClC,SAASC,aAAa,EAAEC,YAAY,QAAQ,gCAA+B;AAG3E,SAASC,SAAS,EAAEC,KAAK,QA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AM,CAACC,MAAM,CAACC,YAAY,CAAC;YAC5CpE,SAAS,IAAI,CAACA,OAAO;YACrByD,KAAKD;YACLa,cAAc;YACdC,MAAM;gBAAC5C,QAAQT,WAAW;gBAAES,QAAQR,aAAa;gBAAEd;gBAAOe;aAAM;QAClE;IACF;IAEA;;;;GAIC,GACD,MAAaoD,0BAA0BtD,WAAwB,EAAoB;QACjF,OAAO,MAAM,IAAI,CAACZ,QAAQ,CAACC,IAAI,CAACiE,yBAAyB,CAAC;YACxDtD,YAAYkB,OAAO;YACnBlB,YAAYoC,SAAS;SACtB;IACH;IAEA;;;;;;;GAOC,GACD,MAAaD,kCACXnC,WAAwB,EACxBC,aAA4B,EACG;QAC/B,MAAMsD,SAAS,MAAM,IAAI,CAACnE,QAAQ,CAACC,IAAI,CAAC8C,iCAAiC,CAAC;YACxEnC;YACAC;SACD;QACD,OAAOsD;IACT;IAEA;;;;;;GAMC,GACD,MAAaC,8BACXxD,WAAwB,EACxBC,aAA4B,EACG;QAC/B,MAAMsD,SAAS,MAAM,IAAI,CAACnE,QAAQ,CAACC,IAAI,CAACmE,6BAA6B,CAAC;YACpExD;YACAC;SACD;QACD,OAAOsD;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/contracts/AssetRegistry.ts"],"sourcesContent":["import { CreditsConfig, DIDAgent, Plan, PriceConfig } from '@nevermined-io/commons'\nimport { Account, Address, isAddress, TransactionReceipt, zeroAddress } from 'viem'\nimport { SmartAccount, UserOperationReceipt } from 'viem/account-abstraction'\nimport {\n assetsRegistryConfig,\n nft1155CreditsAddress,\n nft1155ExpirableCreditsV2Address,\n oneTimeCreatorHookAddress,\n payAsYouGoTemplateAddress,\n protocolStandardFeesAddress,\n} from '../artifacts/generated.js'\nimport { AgentNotFound, PlanNotFound } from '../errors/NeverminedErrors.js'\nimport { InstantiableConfig } from '../Instantiable.abstract.js'\nimport { TxParameters } from '../models/Transactions.js'\nimport { toAgentId, zeroX } from '../utils/ConversionTypeHelpers.js'\nimport { ContractBase } from './ContractBase.js'\n\n/**\n * Loose structural type for the ABI items we filter in `hashPlanId` to\n * disambiguate the legacy 3-arg overload from the 4-arg one. Mirrors only\n * the fields we read, so it stays usable against the auto-generated tuple\n * type emitted by wagmi codegen without dragging in the full viem type.\n */\ntype AbiItemLike = {\n type: string\n name?: string\n inputs?: ReadonlyArray<unknown>\n}\n\nexport class AssetRegistry extends ContractBase {\n public static override async getInstance(config: InstantiableConfig): Promise<AssetRegistry> {\n const assetRegistry: AssetRegistry = new AssetRegistry(\n 'AssetRegistry',\n assetsRegistryConfig.address,\n )\n await assetRegistry.init(config, assetsRegistryConfig)\n return assetRegistry\n }\n\n public async hashAgentId(seed: string, owner: Address): Promise<bigint> {\n return this.contract.read.hashAgentId([seed, owner])\n }\n\n public async getAgent(agentId: string | bigint): Promise<DIDAgent> {\n const didAgent = await this.contract.read.getAgent([toAgentId(agentId)])\n if (didAgent.lastUpdated != 0) return didAgent\n else throw new AgentNotFound(`Agent with id ${agentId} not found`)\n }\n\n public async register({\n seed,\n url,\n plans,\n owner,\n txParams,\n }: {\n seed: string\n url: string\n plans: bigint[]\n owner: Account | SmartAccount\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('register', owner, [zeroX(seed), url, plans], txParams)\n }\n\n public async createPayAsYouGoPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce = 0n,\n addFees = true,\n isTrialPlan = false,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n nonce?: bigint\n addFees?: boolean\n isTrialPlan?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n priceConfig.templateAddress = payAsYouGoTemplateAddress\n return this.createPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce,\n addFees,\n isTrialPlan,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n })\n }\n\n public async createPlan({\n priceConfig,\n creditsConfig,\n owner,\n nonce = 0n,\n addFees = true,\n isTrialPlan = false,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n nonce?: bigint\n addFees?: boolean\n isTrialPlan?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n const _config = await this.planConfigPreFilter(\n priceConfig,\n creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n\n if (isTrialPlan) {\n const hooks: Address[] = [oneTimeCreatorHookAddress]\n return this.send(\n 'createPlanWithHooks',\n owner,\n [_config.priceConfig, _config.creditsConfig, hooks, nonce],\n txParams,\n )\n } else {\n return this.send(\n 'createPlan',\n owner,\n [_config.priceConfig, _config.creditsConfig, nonce],\n txParams,\n )\n }\n }\n\n public async registerAgentAndPlan({\n seed,\n url,\n priceConfig,\n creditsConfig,\n owner,\n addFees = true,\n organizationCryptoFee,\n organizationCryptoWallet,\n txParams,\n }: {\n seed: string\n url: string\n priceConfig: PriceConfig\n creditsConfig: CreditsConfig\n owner: Account | SmartAccount\n addFees?: boolean\n organizationCryptoFee?: bigint\n organizationCryptoWallet?: string\n txParams?: TxParameters\n }): Promise<TransactionReceipt | UserOperationReceipt> {\n const _config = await this.planConfigPreFilter(\n priceConfig,\n creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n\n return this.send(\n 'registerAgentAndPlan',\n owner,\n [zeroX(seed), url, _config.priceConfig, _config.creditsConfig],\n txParams,\n )\n }\n\n public async getPlan(planId: bigint): Promise<Plan> {\n const plan = this.contract.read.getPlan([planId])\n if (plan.lastUpdated != 0) return plan\n else throw new PlanNotFound('Plan not registered')\n }\n\n public async getPlanTotalPrice({\n planId,\n plan,\n }: {\n planId?: bigint\n plan?: Plan\n }): Promise<bigint> {\n if (!plan && !planId) {\n throw new PlanNotFound('Plan not registered')\n }\n if (!plan) {\n plan = await this.getPlan(planId!)\n }\n\n if (plan.lastUpdated === 0n) throw new PlanNotFound('Plan not registered')\n return plan.price.amounts.reduce((a: bigint, b: bigint) => a + b, 0n)\n }\n\n public async planExists(id: bigint): Promise<boolean> {\n return this.contract.read.planExists([id])\n }\n\n public async addPlanToAgent(\n planId: bigint,\n agentId: string | bigint,\n owner: Account | SmartAccount,\n txParams?: TxParameters,\n ): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('addPlanToAgent', owner, [toAgentId(agentId), planId], txParams)\n }\n\n public async removePlanFromAgent(\n planId: bigint,\n agentId: string | bigint,\n owner: Account | SmartAccount,\n txParams?: TxParameters,\n ): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('removePlanFromAgent', owner, [toAgentId(agentId), planId], txParams)\n }\n\n /**\n * Move an agent's on-chain ownership. Only the CURRENT owner can call it.\n *\n * Used by the EIP-7702 migration healing path (#2152): a user's pre-migration\n * agents stay owned by their Kernel v3.1 SCA while every new write is signed by\n * their 7702 EOA, so the SCA hands the agent over before the EOA can operate on\n * it. Deliberately NOT part of the session-key CallPolicy (`REGISTER_GROUP_FNS`)\n * — it is signed by the SCA's sudo validator, and the merkle is already at its\n * Tempo enable-gas ceiling (#1929).\n */\n public async transferAgentOwnership(\n agentId: string | bigint,\n newOwner: `0x${string}`,\n owner: Account | SmartAccount,\n txParams?: TxParameters,\n ): Promise<TransactionReceipt | UserOperationReceipt> {\n return this.send('transferAgentOwnership', owner, [toAgentId(agentId), newOwner], txParams)\n }\n\n public async planConfigPreFilter(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n includeFees = true,\n organizationCryptoFee?: bigint,\n organizationCryptoWallet?: string,\n ) {\n const _priceConfig = { ...priceConfig }\n // Compat shim: the contract ABI in `artifacts/generated.ts` still names\n // the credits-config slot `proofRequired` (legacy EIP-712 signed-burn\n // flag, see nvm-monorepo#1253). The TS interface renamed it to\n // `onchainMirror` in PR #1277. Viem looks up tuple components by name\n // when ABI-encoding, so without this alias every downstream\n // `contract.read.*([creditsConfig, ...])` call resolves the slot to\n // `undefined` and throws \"Invalid boolean value: 'undefined'\". Inject\n // the alias here so every method that runs through `planConfigPreFilter`\n // (`createPlan`, `hashPlanId`, `registerAgentAndPlan`,\n // `includeFeesInPaymentsDistribution` via line 244) sees a config\n // viem can encode. Drop once the contract artifact is regenerated.\n const _creditsConfig = {\n ...creditsConfig,\n proofRequired: creditsConfig.onchainMirror,\n }\n\n if (!priceConfig.feeController || !isAddress(priceConfig.feeController!))\n _priceConfig.feeController = protocolStandardFeesAddress\n\n if (!priceConfig.templateAddress || !isAddress(priceConfig.templateAddress!))\n _priceConfig.templateAddress = zeroAddress\n\n if (!creditsConfig.nftAddress || !isAddress(creditsConfig.nftAddress)) {\n if (creditsConfig.durationSecs > 0n) {\n _creditsConfig.nftAddress = nft1155ExpirableCreditsV2Address\n } else {\n _creditsConfig.nftAddress = nft1155CreditsAddress\n }\n }\n\n if (includeFees) {\n const fees = await this.includeFeesInPaymentsDistribution(_priceConfig, _creditsConfig)\n _priceConfig.amounts = fees[0]\n _priceConfig.receivers = fees[1]\n }\n\n if (organizationCryptoFee && organizationCryptoWallet) {\n _priceConfig.amounts.push(organizationCryptoFee)\n _priceConfig.receivers.push(organizationCryptoWallet)\n }\n\n return { priceConfig: _priceConfig, creditsConfig: _creditsConfig }\n }\n\n public async hashPlanId(\n _priceConfig: PriceConfig,\n _creditsConfig: CreditsConfig,\n owner: Address,\n addFees = true,\n nonce = 0n,\n organizationCryptoFee?: bigint,\n organizationCryptoWallet?: string,\n ): Promise<bigint> {\n const _config = await this.planConfigPreFilter(\n _priceConfig,\n _creditsConfig,\n addFees,\n organizationCryptoFee,\n organizationCryptoWallet,\n )\n // The generated ABI carries both the legacy 3-arg `hashPlanId(_priceConfig,\n // _creditsConfig, _creator)` overload and the new 4-arg\n // `hashPlanId(_priceConfig, _creditsConfig, _creator, _nonce)` overload.\n // Viem's `getContract().read.<name>` proxy resolves overloads by NAME\n // only — it picks the first matching ABI item without re-checking\n // arity — so the 4-arg call below was being encoded against the 3-arg\n // overload and erroring with `AbiEncodingLengthMismatchError: Expected\n // length 3, Given length 4` (CI run 25872339578, core-kit e2e).\n //\n // Drop directly to `readContract` with an ABI restricted to the 4-arg\n // function so there's only one possible match. Same effect as\n // dropping the legacy overload from the artifact, but local to this\n // call site (the artifact is regenerated by `pnpm generate:wagmi:*`\n // from the protocol submodule, so a tree-side artifact edit would be\n // wiped on the next codegen).\n const hashPlanIdAbi = (this.contract.abi as readonly AbiItemLike[]).filter(\n (item) =>\n item.type === 'function' &&\n item.name === 'hashPlanId' &&\n Array.isArray(item.inputs) &&\n item.inputs.length === 4,\n )\n return (await this.client.public.readContract({\n address: this.address,\n abi: hashPlanIdAbi,\n functionName: 'hashPlanId',\n args: [_config.priceConfig, _config.creditsConfig, owner, nonce],\n })) as bigint\n }\n\n /**\n * @notice Checks if Nevermined fees are included in the payment distribution\n * @param _planId The ID of the plan to check\n * @return bool True if Nevermined fees are properly included\n */\n public async areNeverminedFeesIncluded(priceConfig: PriceConfig): Promise<boolean> {\n return await this.contract.read.areNeverminedFeesIncluded([\n priceConfig.amounts,\n priceConfig.receivers,\n ])\n }\n\n /**\n * @notice Getting a payment distribution, it includes the Nevermined fees if not already included\n * This method subsctracts the fees from the original amounts and adds a new entry for the fee recipient\n * @param priceConfig The price configuration of the plan\n * @param creditsConfig The credits configuration of the plan\n * @return amounts Updated array of payment amounts including fees\n * @return receivers Updated array of payment receivers including fee recipient\n */\n public async includeFeesInPaymentsDistribution(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n ): Promise<[bigint[], string[]]> {\n const result = await this.contract.read.includeFeesInPaymentsDistribution([\n priceConfig,\n creditsConfig,\n ])\n return result\n }\n\n /**\n * @notice Adds Nevermined fees to the payment distribution if not already included\n * @param priceConfig The price configuration of the plan\n * @param creditsConfig The credits configuration of the plan\n * @return amounts Updated array of payment amounts including fees\n * @return receivers Updated array of payment receivers including fee recipient\n */\n public async addFeesToPaymentsDistribution(\n priceConfig: PriceConfig,\n creditsConfig: CreditsConfig,\n ): Promise<[bigint[], string[]]> {\n const result = await this.contract.read.addFeesToPaymentsDistribution([\n priceConfig,\n creditsConfig,\n ])\n return result\n }\n}\n"],"names":["isAddress","zeroAddress","assetsRegistryConfig","nft1155CreditsAddress","nft1155ExpirableCreditsV2Address","oneTimeCreatorHookAddress","payAsYouGoTemplateAddress","protocolStandardFeesAddress","AgentNotFound","PlanNotFound","toAgentId","zeroX","ContractBase","AssetRegistry","getInstance","config","assetRegistry","address","init","hashAgentId","seed","owner","contract","read","getAgent","agentId","didAgent","lastUpdated","register","url","plans","txParams","send","createPayAsYouGoPlan","priceConfig","creditsConfig","nonce","addFees","isTrialPlan","organizationCryptoFee","organizationCryptoWallet","templateAddress","createPlan","_config","planConfigPreFilter","hooks","registerAgentAndPlan","getPlan","planId","plan","getPlanTotalPrice","price","amounts","reduce","a","b","planExists","id","addPlanToAgent","removePlanFromAgent","transferAgentOwnership","newOwner","includeFees","_priceConfig","_creditsConfig","proofRequired","onchainMirror","feeController","nftAddress","durationSecs","fees","includeFeesInPaymentsDistribution","receivers","push","hashPlanId","hashPlanIdAbi","abi","filter","item","type","name","Array","isArray","inputs","length","client","public","readContract","functionName","args","areNeverminedFeesIncluded","result","addFeesToPaymentsDistribution"],"mappings":"AACA,SAA2BA,SAAS,EAAsBC,WAAW,QAAQ,OAAM;AAEnF,SACEC,oBAAoB,EACpBC,qBAAqB,EACrBC,gCAAgC,EAChCC,yBAAyB,EACzBC,yBAAyB,EACzBC,2BAA2B,QACtB,4BAA2B;AAClC,SAASC,aAAa,EAAEC,YAAY,QAAQ,gCAA+B;AAG3E,SAASC,SAAS,EAAEC,KAAK,QAAQ,oCAAmC;AACpE,SAASC,YAAY,QAAQ,oBAAmB;AAchD,OAAO,MAAMC,sBAAsBD;IACjC,aAA6BE,Y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OAAO,CAACJ,KAAKK,MAAM,KACzBL,KAAKK,MAAM,CAACC,MAAM,KAAK;QAE3B,OAAQ,MAAM,IAAI,CAACC,MAAM,CAACC,MAAM,CAACC,YAAY,CAAC;YAC5CtE,SAAS,IAAI,CAACA,OAAO;YACrB2D,KAAKD;YACLa,cAAc;YACdC,MAAM;gBAAC9C,QAAQT,WAAW;gBAAES,QAAQR,aAAa;gBAAEd;gBAAOe;aAAM;QAClE;IACF;IAEA;;;;GAIC,GACD,MAAasD,0BAA0BxD,WAAwB,EAAoB;QACjF,OAAO,MAAM,IAAI,CAACZ,QAAQ,CAACC,IAAI,CAACmE,yBAAyB,CAAC;YACxDxD,YAAYkB,OAAO;YACnBlB,YAAYsC,SAAS;SACtB;IACH;IAEA;;;;;;;GAOC,GACD,MAAaD,kCACXrC,WAAwB,EACxBC,aAA4B,EACG;QAC/B,MAAMwD,SAAS,MAAM,IAAI,CAACrE,QAAQ,CAACC,IAAI,CAACgD,iCAAiC,CAAC;YACxErC;YACAC;SACD;QACD,OAAOwD;IACT;IAEA;;;;;;GAMC,GACD,MAAaC,8BACX1D,WAAwB,EACxBC,aAA4B,EACG;QAC/B,MAAMwD,SAAS,MAAM,IAAI,CAACrE,QAAQ,CAACC,IAAI,CAACqE,6BAA6B,CAAC;YACpE1D;YACAC;SACD;QACD,OAAOwD;IACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nevermined-io/core-kit",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",