@nevermined-io/core-kit 0.4.5 → 0.5.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.
Files changed (105) hide show
  1. package/dist/Instantiable.abstract.js +15 -13
  2. package/dist/Instantiable.abstract.js.map +1 -0
  3. package/dist/artifacts/generated.d.ts +174 -40
  4. package/dist/artifacts/generated.d.ts.map +1 -1
  5. package/dist/artifacts/generated.js +22805 -7111
  6. package/dist/artifacts/generated.js.map +1 -0
  7. package/dist/contracts/AccessManager.js +12 -3
  8. package/dist/contracts/AccessManager.js.map +1 -0
  9. package/dist/contracts/AssetRegistry.d.ts +1 -0
  10. package/dist/contracts/AssetRegistry.d.ts.map +1 -1
  11. package/dist/contracts/AssetRegistry.js +134 -69
  12. package/dist/contracts/AssetRegistry.js.map +1 -0
  13. package/dist/contracts/ContractBase.d.ts.map +1 -1
  14. package/dist/contracts/ContractBase.js +173 -140
  15. package/dist/contracts/ContractBase.js.map +1 -0
  16. package/dist/contracts/ContractsApi.js +6 -54
  17. package/dist/contracts/ContractsApi.js.map +1 -0
  18. package/dist/contracts/CryptoTemplateBase.js +23 -11
  19. package/dist/contracts/CryptoTemplateBase.js.map +1 -0
  20. package/dist/contracts/FiatPaymentTemplate.js +9 -1
  21. package/dist/contracts/FiatPaymentTemplate.js.map +1 -0
  22. package/dist/contracts/FiatSettlementCondition.js +8 -1
  23. package/dist/contracts/FiatSettlementCondition.js.map +1 -0
  24. package/dist/contracts/FixedPaymentTemplate.js +42 -10
  25. package/dist/contracts/FixedPaymentTemplate.js.map +1 -0
  26. package/dist/contracts/NFT1155Base.js +48 -12
  27. package/dist/contracts/NFT1155Base.js.map +1 -0
  28. package/dist/contracts/NFT1155Credits.js +2 -0
  29. package/dist/contracts/NFT1155Credits.js.map +1 -0
  30. package/dist/contracts/NFT1155ExpirableCredits.js +26 -6
  31. package/dist/contracts/NFT1155ExpirableCredits.js.map +1 -0
  32. package/dist/contracts/NVMConfig.js +2 -0
  33. package/dist/contracts/NVMConfig.js.map +1 -0
  34. package/dist/contracts/PayAsYouGoTemplate.js +36 -10
  35. package/dist/contracts/PayAsYouGoTemplate.js.map +1 -0
  36. package/dist/contracts/ProtocolStandardFees.js +7 -1
  37. package/dist/contracts/ProtocolStandardFees.js.map +1 -0
  38. package/dist/contracts/Roles.js +2 -0
  39. package/dist/contracts/Roles.js.map +1 -0
  40. package/dist/contracts/index.js +2 -0
  41. package/dist/contracts/index.js.map +1 -0
  42. package/dist/errors/NeverminedErrors.js +27 -26
  43. package/dist/errors/NeverminedErrors.js.map +1 -0
  44. package/dist/errors/index.js +2 -0
  45. package/dist/errors/index.js.map +1 -0
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/models/AgentX402AccessToken.js +78 -46
  49. package/dist/models/AgentX402AccessToken.js.map +1 -0
  50. package/dist/models/Logger.js +12 -12
  51. package/dist/models/Logger.js.map +1 -0
  52. package/dist/models/NeverminedOptions.d.ts +3 -3
  53. package/dist/models/NeverminedOptions.d.ts.map +1 -1
  54. package/dist/models/NeverminedOptions.js +3 -28
  55. package/dist/models/NeverminedOptions.js.map +1 -0
  56. package/dist/models/NvmApiKey.js +96 -147
  57. package/dist/models/NvmApiKey.js.map +1 -0
  58. package/dist/models/Transactions.js +3 -1
  59. package/dist/models/Transactions.js.map +1 -0
  60. package/dist/models/index.js +2 -0
  61. package/dist/models/index.js.map +1 -0
  62. package/dist/nevermined/Nevermined.js +20 -42
  63. package/dist/nevermined/Nevermined.js.map +1 -0
  64. package/dist/nevermined/api/PaymentsApi.js +38 -43
  65. package/dist/nevermined/api/PaymentsApi.js.map +1 -0
  66. package/dist/nevermined/api/ServicesApi.js +7 -15
  67. package/dist/nevermined/api/ServicesApi.js.map +1 -0
  68. package/dist/nevermined/api/UtilsApi.js +7 -19
  69. package/dist/nevermined/api/UtilsApi.js.map +1 -0
  70. package/dist/nevermined/index.js +2 -0
  71. package/dist/nevermined/index.js.map +1 -0
  72. package/dist/nevermined/utils/AgentUtils.js +25 -23
  73. package/dist/nevermined/utils/AgentUtils.js.map +1 -0
  74. package/dist/nevermined/utils/AnvilHelpers.js +34 -19
  75. package/dist/nevermined/utils/AnvilHelpers.js.map +1 -0
  76. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +4 -4
  77. package/dist/nevermined/utils/BlockchainViemUtils.js +102 -108
  78. package/dist/nevermined/utils/BlockchainViemUtils.js.map +1 -0
  79. package/dist/nevermined/utils/JwtUtils.js +33 -28
  80. package/dist/nevermined/utils/JwtUtils.js.map +1 -0
  81. package/dist/nevermined/utils/SignatureUtils.js +23 -27
  82. package/dist/nevermined/utils/SignatureUtils.js.map +1 -0
  83. package/dist/nevermined/utils/WebServiceConnector.js +18 -20
  84. package/dist/nevermined/utils/WebServiceConnector.js.map +1 -0
  85. package/dist/nevermined/utils/ZeroDevPolicies.js +115 -75
  86. package/dist/nevermined/utils/ZeroDevPolicies.js.map +1 -0
  87. package/dist/nevermined/utils/index.js +2 -0
  88. package/dist/nevermined/utils/index.js.map +1 -0
  89. package/dist/services/Api.js +11 -5
  90. package/dist/services/Api.js.map +1 -0
  91. package/dist/services/Profiles.js +15 -20
  92. package/dist/services/Profiles.js.map +1 -0
  93. package/dist/services/index.js +2 -0
  94. package/dist/services/index.js.map +1 -0
  95. package/dist/utils/ConversionTypeHelpers.js +13 -6
  96. package/dist/utils/ConversionTypeHelpers.js.map +1 -0
  97. package/dist/utils/DeploymentInfo.js +12 -7
  98. package/dist/utils/DeploymentInfo.js.map +1 -0
  99. package/dist/utils/Network.js +27 -19
  100. package/dist/utils/Network.js.map +1 -0
  101. package/dist/utils/helpers.js +42 -31
  102. package/dist/utils/helpers.js.map +1 -0
  103. package/dist/utils/index.js +2 -0
  104. package/dist/utils/index.js.map +1 -0
  105. package/package.json +17 -1
@@ -2,17 +2,18 @@ import { PlanTransactionPaymentType } from '@nevermined-io/commons';
2
2
  import { isAddress, parseAbi, zeroAddress } from 'viem';
3
3
  import { NotEnoughBalance } from '../../errors/NeverminedErrors.js';
4
4
  import { Instantiable } from '../../Instantiable.abstract.js';
5
- const TOKEN_BALANCE_ABI = parseAbi(['function balanceOf(address) view returns (uint256)']);
5
+ const TOKEN_BALANCE_ABI = parseAbi([
6
+ 'function balanceOf(address) view returns (uint256)'
7
+ ]);
6
8
  const GET_FEE_RATES_ABI = parseAbi([
7
- 'function getFeeRates() view returns (uint256, uint256, uint256)',
9
+ 'function getFeeRates() view returns (uint256, uint256, uint256)'
8
10
  ]);
9
11
  export class PaymentsApi extends Instantiable {
10
12
  /**
11
- * Creates a new PaymentsApi
12
- * @param config - Configuration of the Nevermined instance
13
- * @returns {@link PaymentsApi}
14
- */
15
- constructor(config) {
13
+ * Creates a new PaymentsApi
14
+ * @param config - Configuration of the Nevermined instance
15
+ * @returns {@link PaymentsApi}
16
+ */ constructor(config){
16
17
  super();
17
18
  this.setInstanceConfig(config);
18
19
  }
@@ -22,10 +23,11 @@ export class PaymentsApi extends Instantiable {
22
23
  address: tokenAddress,
23
24
  abi: TOKEN_BALANCE_ABI,
24
25
  functionName: 'balanceOf',
25
- args: [userAddress],
26
+ args: [
27
+ userAddress
28
+ ]
26
29
  });
27
- }
28
- catch (error) {
30
+ } catch (error) {
29
31
  this.logger.debug(`Error fetching ERC20 balance for ${userAddress} in ${tokenAddress}: ${error}`);
30
32
  }
31
33
  return 0n;
@@ -34,44 +36,40 @@ export class PaymentsApi extends Instantiable {
34
36
  try {
35
37
  const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId);
36
38
  let feeControllerAddress;
37
- if (plan.price.feeController &&
38
- isAddress(plan.price.feeController) &&
39
- plan.price.feeController !== zeroAddress) {
39
+ if (plan.price.feeController && isAddress(plan.price.feeController) && plan.price.feeController !== zeroAddress) {
40
40
  feeControllerAddress = plan.price.feeController;
41
- }
42
- else {
41
+ } else {
43
42
  feeControllerAddress = await this.nevermined.contracts.nvmConfig.getDefaultFeeController();
44
43
  }
45
44
  const result = await this.client.public.readContract({
46
45
  address: feeControllerAddress,
47
46
  abi: GET_FEE_RATES_ABI,
48
47
  functionName: 'getFeeRates',
49
- args: [],
48
+ args: []
50
49
  });
51
50
  const feeReceiver = await this.nevermined.contracts.nvmConfig.getFeeReceiver();
52
51
  let amountToReward = 0n;
53
- plan.price.receivers.map((r, i) => {
52
+ plan.price.receivers.map((r, i)=>{
54
53
  if (r.toLowerCase() !== feeReceiver.toLowerCase()) {
55
54
  amountToReward += plan.price.amounts[i];
56
55
  }
57
56
  });
58
- const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
57
+ const totalAmount = plan.price.amounts.reduce((a, b)=>a + b, 0n);
59
58
  return {
60
59
  cryptoFeeRate: result[0],
61
60
  fiatFeeRate: result[1],
62
61
  feeDenominator: result[2],
63
62
  ownerAmount: amountToReward,
64
- totalAmount,
63
+ totalAmount
65
64
  };
66
- }
67
- catch (error) {
65
+ } catch (error) {
68
66
  this.logger.error(`Error fetching plan fee for planId ${planId}: ${String(error)}`);
69
67
  throw error;
70
68
  }
71
69
  }
72
70
  async orderFiatPayment(planId, planReceiver, from, numberOfPurchases = 1n) {
73
71
  const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId);
74
- const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
72
+ const totalAmount = plan.price.amounts.reduce((a, b)=>a + b, 0n);
75
73
  this.logger.info(`Ordering fiat payment for planId ${planId} to ${planReceiver} from account ${from.address} `);
76
74
  const txHash = await this.nevermined.contracts.fiatPaymentTemplate.order(planId, planReceiver, from, numberOfPurchases);
77
75
  const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
@@ -82,15 +80,14 @@ export class PaymentsApi extends Instantiable {
82
80
  totalAmount,
83
81
  numCredits: plan.credits.amount,
84
82
  paymentMethod: PlanTransactionPaymentType.Fiat,
85
- currency: 'USD',
83
+ currency: 'USD'
86
84
  };
87
85
  }
88
86
  async orderCryptoPlan(planId, plan, from, planReceiver, numberOfPurchases = 1n) {
89
87
  if (plan.price.templateAddress === this.nevermined.contracts.payAsYouGoTemplate.address) {
90
88
  this.logger.debug(`Setting up Pay-As-You-Go order...`);
91
89
  return this._orderCryptoPlan(planId, plan, from, 'payAsYouGo');
92
- }
93
- else {
90
+ } else {
94
91
  this.logger.debug(`Setting up Fixed Payment order...`);
95
92
  return this._orderCryptoPlan(planId, plan, from, 'fixed', planReceiver, numberOfPurchases);
96
93
  }
@@ -98,7 +95,7 @@ export class PaymentsApi extends Instantiable {
98
95
  async _orderCryptoPlan(planId, plan, from, planType, planReceiver, numberOfPurchases = 1n) {
99
96
  try {
100
97
  const tokenAddress = plan.price.tokenAddress;
101
- const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n) * numberOfPurchases;
98
+ const totalAmount = plan.price.amounts.reduce((a, b)=>a + b, 0n) * numberOfPurchases;
102
99
  this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`);
103
100
  let txHash;
104
101
  if (tokenAddress && tokenAddress !== zeroAddress) {
@@ -112,17 +109,14 @@ export class PaymentsApi extends Instantiable {
112
109
  }
113
110
  if (planType === 'payAsYouGo') {
114
111
  txHash = await this.nevermined.contracts.payAsYouGoTemplate.orderWithApprovals(planId, totalAmount, tokenAddress, from);
115
- }
116
- else {
112
+ } else {
117
113
  txHash = await this.nevermined.contracts.fixedPaymentTemplate.orderWithApprovals(planId, totalAmount, tokenAddress, from, planReceiver || from.address, numberOfPurchases);
118
114
  }
119
115
  this.logger.debug(`Token approved + Agreement Created: ${txHash}`);
120
- }
121
- else {
116
+ } else {
122
117
  if (planType === 'payAsYouGo') {
123
118
  txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from);
124
- }
125
- else {
119
+ } else {
126
120
  txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(planId, from, planReceiver || from.address);
127
121
  }
128
122
  }
@@ -139,23 +133,23 @@ export class PaymentsApi extends Instantiable {
139
133
  numCredits: plan.credits.amount * numberOfPurchases,
140
134
  paymentMethod: PlanTransactionPaymentType.Crypto,
141
135
  currency: 'USDC',
142
- tokenAddress,
136
+ tokenAddress
143
137
  };
144
- }
145
- else {
138
+ } else {
146
139
  // Native token payment
147
- const nativeTokenBalance = await this.client.public.getBalance({ address: from.address });
140
+ const nativeTokenBalance = await this.client.public.getBalance({
141
+ address: from.address
142
+ });
148
143
  if (nativeTokenBalance < totalAmount) {
149
144
  throw new NotEnoughBalance(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
150
145
  }
151
146
  if (planType === 'payAsYouGo') {
152
147
  txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from, {
153
- value: totalAmount,
148
+ value: totalAmount
154
149
  });
155
- }
156
- else {
150
+ } else {
157
151
  txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(planId, from, planReceiver || from.address, numberOfPurchases, {
158
- value: totalAmount,
152
+ value: totalAmount
159
153
  });
160
154
  }
161
155
  const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
@@ -167,13 +161,14 @@ export class PaymentsApi extends Instantiable {
167
161
  numCredits: plan.credits.amount * numberOfPurchases,
168
162
  paymentMethod: PlanTransactionPaymentType.Crypto,
169
163
  currency: 'Native',
170
- tokenAddress: zeroAddress,
164
+ tokenAddress: zeroAddress
171
165
  };
172
166
  }
173
- }
174
- catch (error) {
167
+ } catch (error) {
175
168
  this.logger.error(`Error in PaymentsApi order method: ${String(error)}`);
176
169
  throw error;
177
170
  }
178
171
  }
179
172
  }
173
+
174
+ //# sourceMappingURL=PaymentsApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/nevermined/api/PaymentsApi.ts"],"sourcesContent":["import { OrderResult, Plan, PlanTransactionPaymentType } from '@nevermined-io/commons'\nimport { Account, Address, isAddress, parseAbi, zeroAddress } from 'viem'\nimport { SmartAccount } from 'viem/account-abstraction'\nimport { NotEnoughBalance } from '../../errors/NeverminedErrors.js'\nimport { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js'\n\nconst TOKEN_BALANCE_ABI = parseAbi(['function balanceOf(address) view returns (uint256)'])\nconst GET_FEE_RATES_ABI = parseAbi([\n 'function getFeeRates() view returns (uint256, uint256, uint256)',\n])\n\nexport class PaymentsApi extends Instantiable {\n /**\n * Creates a new PaymentsApi\n * @param config - Configuration of the Nevermined instance\n * @returns {@link PaymentsApi}\n */\n constructor(config: InstantiableConfig) {\n super()\n this.setInstanceConfig(config)\n }\n\n public async getERC20Balance(userAddress: Address, tokenAddress: Address): Promise<bigint> {\n try {\n return this.client.public.readContract({\n address: tokenAddress,\n abi: TOKEN_BALANCE_ABI,\n functionName: 'balanceOf',\n args: [userAddress],\n })\n } catch (error) {\n this.logger.debug(\n `Error fetching ERC20 balance for ${userAddress} in ${tokenAddress}: ${error}`,\n )\n }\n return 0n\n }\n\n public async getPlanFees(planId: bigint): Promise<{\n cryptoFeeRate: bigint\n fiatFeeRate: bigint\n feeDenominator: bigint\n totalAmount: bigint\n ownerAmount: bigint\n }> {\n try {\n const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId)\n\n let feeControllerAddress: Address\n if (\n plan.price.feeController &&\n isAddress(plan.price.feeController) &&\n plan.price.feeController !== zeroAddress\n ) {\n feeControllerAddress = plan.price.feeController\n } else {\n feeControllerAddress = await this.nevermined.contracts.nvmConfig.getDefaultFeeController()\n }\n\n const result = await this.client.public.readContract({\n address: feeControllerAddress,\n abi: GET_FEE_RATES_ABI,\n functionName: 'getFeeRates',\n args: [],\n })\n\n const feeReceiver = await this.nevermined.contracts.nvmConfig.getFeeReceiver()\n let amountToReward = 0n\n plan.price.receivers.map((r, i) => {\n if (r.toLowerCase() !== feeReceiver.toLowerCase()) {\n amountToReward += plan.price.amounts[i]\n }\n })\n\n const totalAmount = plan.price.amounts.reduce((a: bigint, b: bigint) => a + b, 0n)\n return {\n cryptoFeeRate: result[0],\n fiatFeeRate: result[1],\n feeDenominator: result[2],\n ownerAmount: amountToReward,\n totalAmount,\n }\n } catch (error) {\n this.logger.error(`Error fetching plan fee for planId ${planId}: ${String(error)}`)\n throw error\n }\n }\n\n public async orderFiatPayment(\n planId: bigint,\n planReceiver: Address,\n from: Account | SmartAccount,\n numberOfPurchases = 1n,\n ): Promise<OrderResult> {\n const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId)\n const totalAmount = plan.price.amounts.reduce((a: bigint, b: bigint) => a + b, 0n)\n\n this.logger.info(\n `Ordering fiat payment for planId ${planId} to ${planReceiver} from account ${from.address} `,\n )\n\n const txHash = await this.nevermined.contracts.fiatPaymentTemplate.order(\n planId,\n planReceiver,\n from,\n numberOfPurchases,\n )\n const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash)\n return {\n txHash: txReceipt.transactionHash,\n planId,\n planReceiver: from.address,\n totalAmount,\n numCredits: plan.credits.amount,\n paymentMethod: PlanTransactionPaymentType.Fiat,\n currency: 'USD',\n }\n }\n\n public async orderCryptoPlan(\n planId: bigint,\n plan: Plan,\n from: Account | SmartAccount,\n planReceiver?: Address,\n numberOfPurchases = 1n,\n ): Promise<OrderResult> {\n if (plan.price.templateAddress === this.nevermined.contracts.payAsYouGoTemplate.address) {\n this.logger.debug(`Setting up Pay-As-You-Go order...`)\n return this._orderCryptoPlan(planId, plan, from, 'payAsYouGo')\n } else {\n this.logger.debug(`Setting up Fixed Payment order...`)\n return this._orderCryptoPlan(planId, plan, from, 'fixed', planReceiver, numberOfPurchases)\n }\n }\n\n private async _orderCryptoPlan(\n planId: bigint,\n plan: Plan,\n from: Account | SmartAccount,\n planType: 'fixed' | 'payAsYouGo',\n planReceiver?: Address,\n numberOfPurchases = 1n,\n ): Promise<OrderResult> {\n try {\n const tokenAddress = plan.price.tokenAddress\n const totalAmount =\n plan.price.amounts.reduce((a: bigint, b: bigint) => a + b, 0n) * numberOfPurchases\n\n this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`)\n\n let txHash\n if (tokenAddress && tokenAddress !== zeroAddress) {\n this.logger.debug(`Processing ERC20 payment...`)\n // ERC20 token payment\n if (totalAmount > 0n) {\n const erc20Balance = await this.getERC20Balance(from.address, tokenAddress)\n this.logger.debug(\n `ERC20 balance for ${from.address} in ${tokenAddress}: balance = ${erc20Balance} - total amount = ${totalAmount}`,\n )\n if (erc20Balance < totalAmount) {\n throw new NotEnoughBalance(\n `Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`,\n )\n }\n if (planType === 'payAsYouGo') {\n txHash = await this.nevermined.contracts.payAsYouGoTemplate.orderWithApprovals(\n planId,\n totalAmount,\n tokenAddress,\n from,\n )\n } else {\n txHash = await this.nevermined.contracts.fixedPaymentTemplate.orderWithApprovals(\n planId,\n totalAmount,\n tokenAddress,\n from,\n planReceiver || from.address,\n numberOfPurchases,\n )\n }\n this.logger.debug(`Token approved + Agreement Created: ${txHash}`)\n } else {\n if (planType === 'payAsYouGo') {\n txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from)\n } else {\n txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(\n planId,\n from,\n planReceiver || from.address,\n )\n }\n }\n if (!txHash) {\n this.logger.error('Error in PaymentsApi order method: txHash not defined')\n throw new Error('txHash not defined')\n }\n\n const txReceipt =\n await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash)\n return {\n txHash: txReceipt.transactionHash,\n planId,\n planReceiver: from.address,\n totalAmount,\n numCredits: plan.credits.amount * numberOfPurchases,\n paymentMethod: PlanTransactionPaymentType.Crypto,\n currency: 'USDC',\n tokenAddress,\n }\n } else {\n // Native token payment\n const nativeTokenBalance = await this.client.public.getBalance({ address: from.address })\n if (nativeTokenBalance < totalAmount) {\n throw new NotEnoughBalance(\n `Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`,\n )\n }\n if (planType === 'payAsYouGo') {\n txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from, {\n value: totalAmount,\n })\n } else {\n txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(\n planId,\n from,\n planReceiver || from.address,\n numberOfPurchases,\n {\n value: totalAmount,\n },\n )\n }\n\n const txReceipt =\n await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash)\n return {\n txHash: txReceipt.transactionHash,\n planId,\n planReceiver: from.address,\n totalAmount,\n numCredits: plan.credits.amount * numberOfPurchases,\n paymentMethod: PlanTransactionPaymentType.Crypto,\n currency: 'Native',\n tokenAddress: zeroAddress,\n }\n }\n } catch (error) {\n this.logger.error(`Error in PaymentsApi order method: ${String(error)}`)\n throw error\n }\n }\n}\n"],"names":["PlanTransactionPaymentType","isAddress","parseAbi","zeroAddress","NotEnoughBalance","Instantiable","TOKEN_BALANCE_ABI","GET_FEE_RATES_ABI","PaymentsApi","config","setInstanceConfig","getERC20Balance","userAddress","tokenAddress","client","public","readContract","address","abi","functionName","args","error","logger","debug","getPlanFees","planId","plan","nevermined","contracts","assetRegistry","getPlan","feeControllerAddress","price","feeController","nvmConfig","getDefaultFeeController","result","feeReceiver","getFeeReceiver","amountToReward","receivers","map","r","i","toLowerCase","amounts","totalAmount","reduce","a","b","cryptoFeeRate","fiatFeeRate","feeDenominator","ownerAmount","String","orderFiatPayment","planReceiver","from","numberOfPurchases","info","txHash","fiatPaymentTemplate","order","txReceipt","getTransactionReceipt","transactionHash","numCredits","credits","amount","paymentMethod","Fiat","currency","orderCryptoPlan","templateAddress","payAsYouGoTemplate","_orderCryptoPlan","planType","erc20Balance","orderWithApprovals","fixedPaymentTemplate","Error","Crypto","nativeTokenBalance","getBalance","value"],"mappings":"AAAA,SAA4BA,0BAA0B,QAAQ,yBAAwB;AACtF,SAA2BC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,OAAM;AAEzE,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,YAAY,QAA4B,iCAAgC;AAEjF,MAAMC,oBAAoBJ,SAAS;IAAC;CAAqD;AACzF,MAAMK,oBAAoBL,SAAS;IACjC;CACD;AAED,OAAO,MAAMM,oBAAoBH;IA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AAGV;oBAClCW,eAAerE,2BAA2BiF,MAAM;oBAChDV,UAAU;oBACV1D;gBACF;YACF,OAAO;gBACL,uBAAuB;gBACvB,MAAMqE,qBAAqB,MAAM,IAAI,CAACpE,MAAM,CAACC,MAAM,CAACoE,UAAU,CAAC;oBAAElE,SAASwC,KAAKxC,OAAO;gBAAC;gBACvF,IAAIiE,qBAAqBpC,aAAa;oBACpC,MAAM,IAAI1C,iBACR,CAAC,sBAAsB,EAAE8E,mBAAmB,GAAG,EAAEpC,YAAY,0BAA0B,CAAC;gBAE5F;gBACA,IAAI8B,aAAa,cAAc;oBAC7BhB,SAAS,MAAM,IAAI,CAACjC,UAAU,CAACC,SAAS,CAAC8C,kBAAkB,CAACZ,KAAK,CAACrC,QAAQgC,MAAM;wBAC9E2B,OAAOtC;oBACT;gBACF,OAAO;oBACLc,SAAS,MAAM,IAAI,CAACjC,UAAU,CAACC,SAAS,CAACmD,oBAAoB,CAACjB,KAAK,CACjErC,QACAgC,MACAD,gBAAgBC,KAAKxC,OAAO,EAC5ByC,mBACA;wBACE0B,OAAOtC;oBACT;gBAEJ;gBAEA,MAAMiB,YACJ,MAAM,IAAI,CAACpC,UAAU,CAACC,SAAS,CAACC,aAAa,CAACmC,qBAAqB,CAACJ;gBACtE,OAAO;oBACLA,QAAQG,UAAUE,eAAe;oBACjCxC;oBACA+B,cAAcC,KAAKxC,OAAO;oBAC1B6B;oBACAoB,YAAYxC,KAAKyC,OAAO,CAACC,MAAM,GAAGV;oBAClCW,eAAerE,2BAA2BiF,MAAM;oBAChDV,UAAU;oBACV1D,cAAcV;gBAChB;YACF;QACF,EAAE,OAAOkB,OAAO;YACd,IAAI,CAACC,MAAM,CAACD,KAAK,CAAC,CAAC,mCAAmC,EAAEiC,OAAOjC,QAAQ;YACvE,MAAMA;QACR;IACF;AACF"}
@@ -3,25 +3,17 @@ import { Api } from '../../services/Api.js';
3
3
  import { Profiles } from '../../services/Profiles.js';
4
4
  /**
5
5
  * Utils internal submodule of Nevermined.
6
- */
7
- export class ServicesApi extends Instantiable {
6
+ */ export class ServicesApi extends Instantiable {
8
7
  /**
9
- * Nevermined Node Service
10
- */
11
- api;
12
- /**
13
- * Profiles instance
14
- */
15
- profiles;
16
- /**
17
- * Creates a new ServicesApi
18
- * @param config - Configuration of the Nevermined instance
19
- * @returns {@link ServicesApi}
20
- */
21
- constructor(config) {
8
+ * Creates a new ServicesApi
9
+ * @param config - Configuration of the Nevermined instance
10
+ * @returns {@link ServicesApi}
11
+ */ constructor(config){
22
12
  super();
23
13
  this.setInstanceConfig(config);
24
14
  this.api = new Api(config);
25
15
  this.profiles = new Profiles(config);
26
16
  }
27
17
  }
18
+
19
+ //# sourceMappingURL=ServicesApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/nevermined/api/ServicesApi.ts"],"sourcesContent":["import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js'\nimport { Api } from '../../services/Api.js'\nimport { Profiles } from '../../services/Profiles.js'\n\n/**\n * Utils internal submodule of Nevermined.\n */\nexport class ServicesApi extends Instantiable {\n /**\n * Nevermined Node Service\n */\n public api: Api\n\n /**\n * Profiles instance\n */\n public profiles: Profiles\n\n /**\n * Creates a new ServicesApi\n * @param config - Configuration of the Nevermined instance\n * @returns {@link ServicesApi}\n */\n constructor(config: InstantiableConfig) {\n super()\n this.setInstanceConfig(config)\n\n this.api = new Api(config)\n this.profiles = new Profiles(config)\n }\n}\n"],"names":["Instantiable","Api","Profiles","ServicesApi","config","setInstanceConfig","api","profiles"],"mappings":"AAAA,SAASA,YAAY,QAA4B,iCAAgC;AACjF,SAASC,GAAG,QAAQ,wBAAuB;AAC3C,SAASC,QAAQ,QAAQ,6BAA4B;AAErD;;CAEC,GACD,OAAO,MAAMC,oBAAoBH;IAW/B;;;;GAIC,GACD,YAAYI,MAA0B,CAAE;QACtC,KAAK;QACL,IAAI,CAACC,iBAAiB,CAACD;QAEvB,IAAI,CAACE,GAAG,GAAG,IAAIL,IAAIG;QACnB,IAAI,CAACG,QAAQ,GAAG,IAAIL,SAASE;IAC/B;AACF"}
@@ -4,26 +4,12 @@ import { SignatureUtils } from '../utils/SignatureUtils.js';
4
4
  import { WebServiceConnector } from '../utils/WebServiceConnector.js';
5
5
  /**
6
6
  * Nevermined Utils API
7
- */
8
- export class UtilsApi extends Instantiable {
7
+ */ export class UtilsApi extends Instantiable {
9
8
  /**
10
- * Fetch utils.
11
- */
12
- fetch;
13
- /**
14
- * Jwt utils.
15
- */
16
- jwt;
17
- /**
18
- * Signature utils.
19
- */
20
- signature;
21
- /**
22
- * Creates a new AssetsApi
23
- * @param config - Configuration of the Nevermined instance
24
- * @returns {@link UtilsApi}
25
- */
26
- constructor(config) {
9
+ * Creates a new AssetsApi
10
+ * @param config - Configuration of the Nevermined instance
11
+ * @returns {@link UtilsApi}
12
+ */ constructor(config){
27
13
  super();
28
14
  this.setInstanceConfig(config);
29
15
  this.fetch = new WebServiceConnector(config);
@@ -31,3 +17,5 @@ export class UtilsApi extends Instantiable {
31
17
  this.signature = new SignatureUtils(config);
32
18
  }
33
19
  }
20
+
21
+ //# sourceMappingURL=UtilsApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/nevermined/api/UtilsApi.ts"],"sourcesContent":["import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js'\nimport { JwtUtils } from '../utils/JwtUtils.js'\nimport { SignatureUtils } from '../utils/SignatureUtils.js'\nimport { WebServiceConnector } from '../utils/WebServiceConnector.js'\n\n/**\n * Nevermined Utils API\n */\nexport class UtilsApi extends Instantiable {\n /**\n * Fetch utils.\n */\n public fetch: WebServiceConnector\n\n /**\n * Jwt utils.\n */\n public jwt: JwtUtils\n\n /**\n * Signature utils.\n */\n public signature: SignatureUtils\n\n /**\n * Creates a new AssetsApi\n * @param config - Configuration of the Nevermined instance\n * @returns {@link UtilsApi}\n */\n constructor(config: InstantiableConfig) {\n super()\n this.setInstanceConfig(config)\n\n this.fetch = new WebServiceConnector(config)\n this.jwt = new JwtUtils(config)\n this.signature = new SignatureUtils(config)\n }\n}\n"],"names":["Instantiable","JwtUtils","SignatureUtils","WebServiceConnector","UtilsApi","config","setInstanceConfig","fetch","jwt","signature"],"mappings":"AAAA,SAASA,YAAY,QAA4B,iCAAgC;AACjF,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,mBAAmB,QAAQ,kCAAiC;AAErE;;CAEC,GACD,OAAO,MAAMC,iBAAiBJ;IAgB5B;;;;GAIC,GACD,YAAYK,MAA0B,CAAE;QACtC,KAAK;QACL,IAAI,CAACC,iBAAiB,CAACD;QAEvB,IAAI,CAACE,KAAK,GAAG,IAAIJ,oBAAoBE;QACrC,IAAI,CAACG,GAAG,GAAG,IAAIP,SAASI;QACxB,IAAI,CAACI,SAAS,GAAG,IAAIP,eAAeG;IACtC;AACF"}
@@ -1,2 +1,4 @@
1
1
  export { Nevermined } from './Nevermined.js';
2
2
  export * from './utils/index.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/nevermined/index.ts"],"sourcesContent":["export { Nevermined } from './Nevermined.js'\nexport * from './utils/index.js'\n"],"names":["Nevermined"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,cAAc,mBAAkB"}
@@ -6,7 +6,7 @@ export function isEndpointRequestedIncluded(requestEndpoint, requestedHTTPVerb,
6
6
  let urlMatching, verbMatching;
7
7
  const requestedUrl = new URL(requestEndpoint);
8
8
  // Is the endpoint an open endpoint?
9
- for (const openEndpoint of agentOpenEndpoints) {
9
+ for (const openEndpoint of agentOpenEndpoints){
10
10
  try {
11
11
  const agentUrl = new URL(openEndpoint);
12
12
  if (areUrlsEqualIgnoringQuery(agentUrl, requestedUrl)) {
@@ -14,46 +14,48 @@ export function isEndpointRequestedIncluded(requestEndpoint, requestedHTTPVerb,
14
14
  matches = true;
15
15
  break;
16
16
  }
17
- }
18
- catch (error) {
19
- // Skip invalid URLs and continue with next endpoint
17
+ } catch (error) {
20
18
  continue;
21
19
  }
22
20
  }
23
- if (matches)
24
- return { matches: true, urlMatching };
21
+ if (matches) return {
22
+ matches: true,
23
+ urlMatching
24
+ };
25
25
  // check if the endpoint/verb is part of the list
26
- for (const ep of agentEndpoints) {
26
+ for (const ep of agentEndpoints){
27
27
  try {
28
28
  const [verb, url] = Object.entries(ep)[0];
29
29
  const normalizedVerb = verb.toLowerCase();
30
30
  const _url = new URL(url);
31
- const fn = match(_url.pathname, { decode: decodeURIComponent });
32
- const verbMatches = normalizedVerb === requestedHTTPVerb ||
33
- normalizedVerb === '*' ||
34
- requestedHTTPVerb === '*';
31
+ const fn = match(_url.pathname, {
32
+ decode: decodeURIComponent
33
+ });
34
+ const verbMatches = normalizedVerb === requestedHTTPVerb || normalizedVerb === '*' || requestedHTTPVerb === '*';
35
35
  if (fn(requestedUrl.pathname) && verbMatches) {
36
36
  matches = true;
37
37
  urlMatching = _url;
38
38
  verbMatching = verb;
39
39
  break;
40
40
  }
41
- }
42
- catch (error) {
43
- // Skip invalid patterns and continue with next endpoint
41
+ } catch (error) {
44
42
  continue;
45
43
  }
46
44
  }
47
- return { matches, urlMatching, verbMatching };
48
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
- }
50
- catch (error) {
51
- return { matches: false };
45
+ return {
46
+ matches,
47
+ urlMatching,
48
+ verbMatching
49
+ };
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
+ } catch (error) {
52
+ return {
53
+ matches: false
54
+ };
52
55
  }
53
56
  }
54
57
  export function areUrlsEqualIgnoringQuery(url1, url2) {
55
- return (url1.protocol === url2.protocol &&
56
- url1.hostname === url2.hostname &&
57
- url1.port === url2.port &&
58
- url1.pathname === url2.pathname);
58
+ return url1.protocol === url2.protocol && url1.hostname === url2.hostname && url1.port === url2.port && url1.pathname === url2.pathname;
59
59
  }
60
+
61
+ //# sourceMappingURL=AgentUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/nevermined/utils/AgentUtils.ts"],"sourcesContent":["import { ApiEndpoint } from '@nevermined-io/commons'\nimport { match } from 'path-to-regexp'\n\nexport function isEndpointRequestedIncluded(\n requestEndpoint: string,\n requestedHTTPVerb: string,\n agentEndpoints: ApiEndpoint[],\n agentOpenEndpoints: string[] = [],\n): { matches: boolean; urlMatching?: URL; verbMatching?: string } {\n try {\n let matches = false\n requestedHTTPVerb = requestedHTTPVerb.toLowerCase()\n let urlMatching, verbMatching\n\n const requestedUrl = new URL(requestEndpoint)\n // Is the endpoint an open endpoint?\n for (const openEndpoint of agentOpenEndpoints) {\n try {\n const agentUrl = new URL(openEndpoint)\n if (areUrlsEqualIgnoringQuery(agentUrl, requestedUrl)) {\n urlMatching = new URL(openEndpoint)\n matches = true\n break\n }\n } catch (error) {\n // Skip invalid URLs and continue with next endpoint\n continue\n }\n }\n if (matches) return { matches: true, urlMatching }\n\n // check if the endpoint/verb is part of the list\n\n for (const ep of agentEndpoints) {\n try {\n const [verb, url] = Object.entries(ep)[0]\n const normalizedVerb = verb.toLowerCase()\n const _url = new URL(url)\n const fn = match(_url.pathname, { decode: decodeURIComponent })\n const verbMatches =\n normalizedVerb === requestedHTTPVerb ||\n normalizedVerb === '*' ||\n requestedHTTPVerb === '*'\n if (fn(requestedUrl.pathname) && verbMatches) {\n matches = true\n urlMatching = _url\n verbMatching = verb\n break\n }\n } catch (error) {\n // Skip invalid patterns and continue with next endpoint\n continue\n }\n }\n\n return { matches, urlMatching, verbMatching }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n return { matches: false }\n }\n}\n\nexport function areUrlsEqualIgnoringQuery(url1: URL, url2: URL): boolean {\n return (\n url1.protocol === url2.protocol &&\n url1.hostname === url2.hostname &&\n url1.port === url2.port &&\n url1.pathname === url2.pathname\n )\n}\n"],"names":["match","isEndpointRequestedIncluded","requestEndpoint","requestedHTTPVerb","agentEndpoints","agentOpenEndpoints","matches","toLowerCase","urlMatching","verbMatching","requestedUrl","URL","openEndpoint","agentUrl","areUrlsEqualIgnoringQuery","error","ep","verb","url","Object","entries","normalizedVerb","_url","fn","pathname","decode","decodeURIComponent","verbMatches","url1","url2","protocol","hostname","port"],"mappings":"AACA,SAASA,KAAK,QAAQ,iBAAgB;AAEtC,OAAO,SAASC,4BACdC,eAAuB,EACvBC,iBAAyB,EACzBC,cAA6B,EAC7BC,qBAA+B,EAAE;IAEjC,IAAI;QACF,IAAIC,UAAU;QACdH,oBAAoBA,kBAAkBI,WAAW;QACjD,IAAIC,aAAaC;QAEjB,MAAMC,eAAe,IAAIC,IAAIT;QAC7B,oCAAoC;QACpC,KAAK,MAAMU,gBAAgBP,mBAAoB;YAC7C,IAAI;gBACF,MAAMQ,WAAW,IAAIF,IAAIC;gBACzB,IAAIE,0BAA0BD,UAAUH,eAAe;oBACrDF,cAAc,IAAIG,IAAIC;oBACtBN,UAAU;oBACV;gBACF;YACF,EAAE,OAAOS,OAAO;gBAEd;YACF;QACF;QACA,IAAIT,SAAS,OAAO;YAAEA,SAAS;YAAME;QAAY;QAEjD,iDAAiD;QAEjD,KAAK,MAAMQ,MAAMZ,eAAgB;YAC/B,IAAI;gBACF,MAAM,CAACa,MAAMC,IAAI,GAAGC,OAAOC,OAAO,CAACJ,GAAG,CAAC,EAAE;gBACzC,MAAMK,iBAAiBJ,KAAKV,WAAW;gBACvC,MAAMe,OAAO,IAAIX,IAAIO;gBACrB,MAAMK,KAAKvB,MAAMsB,KAAKE,QAAQ,EAAE;oBAAEC,QAAQC;gBAAmB;gBAC7D,MAAMC,cACJN,mBAAmBlB,qBACnBkB,mBAAmB,OACnBlB,sBAAsB;gBACxB,IAAIoB,GAAGb,aAAac,QAAQ,KAAKG,aAAa;oBAC5CrB,UAAU;oBACVE,cAAcc;oBACdb,eAAeQ;oBACf;gBACF;YACF,EAAE,OAAOF,OAAO;gBAEd;YACF;QACF;QAEA,OAAO;YAAET;YAASE;YAAaC;QAAa;IAC5C,6DAA6D;IAC/D,EAAE,OAAOM,OAAO;QACd,OAAO;YAAET,SAAS;QAAM;IAC1B;AACF;AAEA,OAAO,SAASQ,0BAA0Bc,IAAS,EAAEC,IAAS;IAC5D,OACED,KAAKE,QAAQ,KAAKD,KAAKC,QAAQ,IAC/BF,KAAKG,QAAQ,KAAKF,KAAKE,QAAQ,IAC/BH,KAAKI,IAAI,KAAKH,KAAKG,IAAI,IACvBJ,KAAKJ,QAAQ,KAAKK,KAAKL,QAAQ;AAEnC"}
@@ -1,11 +1,10 @@
1
- import { encodeAbiParameters, keccak256, pad, parseAbi, toHex, } from 'viem';
1
+ import { encodeAbiParameters, keccak256, pad, parseAbi, toHex } from 'viem';
2
2
  /**
3
3
  * Returns true when the test/dev process is running against a local
4
4
  * anvil-fork stack (i.e. `BUNDLER_RPC_URL_OVERRIDE` is set). Helpers that
5
5
  * depend on anvil cheatcodes should early-return when this is false so the
6
6
  * same code path stays portable to the real network.
7
- */
8
- export function isAnvilFork() {
7
+ */ export function isAnvilFork() {
9
8
  return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE);
10
9
  }
11
10
  /**
@@ -15,8 +14,7 @@ export function isAnvilFork() {
15
14
  *
16
15
  * The lower 159 bits hold the balance; the high bit is the blacklist flag.
17
16
  * Writing the raw amount (as long as it fits in 159 bits) is safe.
18
- */
19
- const FIAT_TOKEN_BALANCE_SLOT = 9n;
17
+ */ const FIAT_TOKEN_BALANCE_SLOT = 9n;
20
18
  /**
21
19
  * Forces `holder`'s ERC20 balance on `token` to `amount`, writing the value
22
20
  * directly into storage via `anvil_setStorageAt`. No-op when not running on
@@ -24,40 +22,57 @@ const FIAT_TOKEN_BALANCE_SLOT = 9n;
24
22
  *
25
23
  * Assumes the FiatTokenV2.2 storage layout (Circle's USDC). For other ERC20s
26
24
  * pass a different `balanceSlot` matching the implementation's storage.
27
- */
28
- export async function setErc20Balance(publicClient, token, holder, amount, balanceSlot = FIAT_TOKEN_BALANCE_SLOT) {
25
+ */ export async function setErc20Balance(publicClient, token, holder, amount, balanceSlot = FIAT_TOKEN_BALANCE_SLOT) {
29
26
  if (!isAnvilFork()) {
30
27
  // Surface the no-op so a test author who copy/pasted the helper without
31
28
  // setting BUNDLER_RPC_URL_OVERRIDE doesn't silently end up debugging an
32
29
  // 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`);
30
+ console.warn(`[AnvilHelpers.setErc20Balance] no-op: BUNDLER_RPC_URL_OVERRIDE not set; ` + `holder=${holder} token=${token} amount=${amount} skipped`);
35
31
  return;
36
32
  }
37
- const slot = keccak256(encodeAbiParameters([{ type: 'address' }, { type: 'uint256' }], [holder, balanceSlot]));
38
- const value = pad(toHex(amount), { size: 32 });
33
+ const slot = keccak256(encodeAbiParameters([
34
+ {
35
+ type: 'address'
36
+ },
37
+ {
38
+ type: 'uint256'
39
+ }
40
+ ], [
41
+ holder,
42
+ balanceSlot
43
+ ]));
44
+ const value = pad(toHex(amount), {
45
+ size: 32
46
+ });
39
47
  await publicClient.request({
40
48
  method: 'anvil_setStorageAt',
41
- params: [token, slot, value],
49
+ params: [
50
+ token,
51
+ slot,
52
+ value
53
+ ]
42
54
  });
43
- const balanceOfAbi = parseAbi(['function balanceOf(address) view returns (uint256)']);
55
+ const balanceOfAbi = parseAbi([
56
+ 'function balanceOf(address) view returns (uint256)'
57
+ ]);
44
58
  const written = await publicClient.readContract({
45
59
  address: token,
46
60
  abi: balanceOfAbi,
47
61
  functionName: 'balanceOf',
48
- args: [holder],
62
+ args: [
63
+ holder
64
+ ]
49
65
  });
50
66
  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).`);
67
+ throw new Error(`setErc20Balance: balance write mismatch on ${token} for ${holder}. ` + `Expected ${amount}, got ${written}. The balance slot may differ ` + `from the assumed ${balanceSlot} (FiatTokenV2.2 layout).`);
54
68
  }
55
69
  }
56
70
  /**
57
71
  * Convenience wrapper that funds Base Sepolia USDC on a kernel SCA. Only
58
72
  * takes effect on an anvil fork.
59
- */
60
- export async function fundUsdcOnFork(publicClient, holder, amountUsdcUnits) {
73
+ */ export async function fundUsdcOnFork(publicClient, holder, amountUsdcUnits) {
61
74
  const usdc = process.env.TEST_ERC20_USDC_ADDRESS || '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
62
75
  await setErc20Balance(publicClient, usdc, holder, amountUsdcUnits);
63
76
  }
77
+
78
+ //# sourceMappingURL=AnvilHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/nevermined/utils/AnvilHelpers.ts"],"sourcesContent":["import {\n type Address,\n type PublicClient,\n encodeAbiParameters,\n keccak256,\n pad,\n parseAbi,\n toHex,\n} from 'viem'\n\n/**\n * Returns true when the test/dev process is running against a local\n * anvil-fork stack (i.e. `BUNDLER_RPC_URL_OVERRIDE` is set). Helpers that\n * depend on anvil cheatcodes should early-return when this is false so the\n * same code path stays portable to the real network.\n */\nexport function isAnvilFork(): boolean {\n return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE)\n}\n\n/**\n * Storage slot of `balanceAndBlacklistStates` (the balance mapping) in\n * Circle's `FiatTokenV2_2`, the implementation behind the USDC proxy on\n * Base Sepolia at `0x036CbD53842c5426634e7929541eC2318f3dCF7e`.\n *\n * The lower 159 bits hold the balance; the high bit is the blacklist flag.\n * Writing the raw amount (as long as it fits in 159 bits) is safe.\n */\nconst FIAT_TOKEN_BALANCE_SLOT = 9n\n\n/**\n * Forces `holder`'s ERC20 balance on `token` to `amount`, writing the value\n * directly into storage via `anvil_setStorageAt`. No-op when not running on\n * an anvil fork so the same call site stays portable to the real network.\n *\n * Assumes the FiatTokenV2.2 storage layout (Circle's USDC). For other ERC20s\n * pass a different `balanceSlot` matching the implementation's storage.\n */\nexport async function setErc20Balance(\n publicClient: PublicClient,\n token: Address,\n holder: Address,\n amount: bigint,\n balanceSlot: bigint = FIAT_TOKEN_BALANCE_SLOT,\n): Promise<void> {\n if (!isAnvilFork()) {\n // Surface the no-op so a test author who copy/pasted the helper without\n // setting BUNDLER_RPC_URL_OVERRIDE doesn't silently end up debugging an\n // unrelated `transferFrom` revert deep inside the actual test.\n console.warn(\n `[AnvilHelpers.setErc20Balance] no-op: BUNDLER_RPC_URL_OVERRIDE not set; ` +\n `holder=${holder} token=${token} amount=${amount} skipped`,\n )\n return\n }\n\n const slot = keccak256(\n encodeAbiParameters([{ type: 'address' }, { type: 'uint256' }], [holder, balanceSlot]),\n )\n const value = pad(toHex(amount), { size: 32 })\n\n await publicClient.request({\n method: 'anvil_setStorageAt' as never,\n params: [token, slot, value] as never,\n })\n\n const balanceOfAbi = parseAbi(['function balanceOf(address) view returns (uint256)'])\n const written = await publicClient.readContract({\n address: token,\n abi: balanceOfAbi,\n functionName: 'balanceOf',\n args: [holder],\n })\n if (written !== amount) {\n throw new Error(\n `setErc20Balance: balance write mismatch on ${token} for ${holder}. ` +\n `Expected ${amount}, got ${written}. The balance slot may differ ` +\n `from the assumed ${balanceSlot} (FiatTokenV2.2 layout).`,\n )\n }\n}\n\n/**\n * Convenience wrapper that funds Base Sepolia USDC on a kernel SCA. Only\n * takes effect on an anvil fork.\n */\nexport async function fundUsdcOnFork(\n publicClient: PublicClient,\n holder: Address,\n amountUsdcUnits: bigint,\n): Promise<void> {\n const usdc =\n (process.env.TEST_ERC20_USDC_ADDRESS as Address) || '0x036CbD53842c5426634e7929541eC2318f3dCF7e'\n await setErc20Balance(publicClient, usdc, holder, amountUsdcUnits)\n}\n"],"names":["encodeAbiParameters","keccak256","pad","parseAbi","toHex","isAnvilFork","Boolean","process","env","BUNDLER_RPC_URL_OVERRIDE","FIAT_TOKEN_BALANCE_SLOT","setErc20Balance","publicClient","token","holder","amount","balanceSlot","console","warn","slot","type","value","size","request","method","params","balanceOfAbi","written","readContract","address","abi","functionName","args","Error","fundUsdcOnFork","amountUsdcUnits","usdc","TEST_ERC20_USDC_ADDRESS"],"mappings":"AAAA,SAGEA,mBAAmB,EACnBC,SAAS,EACTC,GAAG,EACHC,QAAQ,EACRC,KAAK,QACA,OAAM;AAEb;;;;;CAKC,GACD,OAAO,SAASC;IACd,OAAOC,QAAQC,QAAQC,GAAG,CAACC,wBAAwB;AACrD;AAEA;;;;;;;CAOC,GACD,MAAMC,0BAA0B,EAAE;AAElC;;;;;;;CAOC,GACD,OAAO,eAAeC,gBACpBC,YAA0B,EAC1BC,KAAc,EACdC,MAAe,EACfC,MAAc,EACdC,cAAsBN,uBAAuB;IAE7C,IAAI,CAACL,eAAe;QAClB,wEAAwE;QACxE,wEAAwE;QACxE,+DAA+D;QAC/DY,QAAQC,IAAI,CACV,CAAC,wEAAwE,CAAC,GACxE,CAAC,OAAO,EAAEJ,OAAO,OAAO,EAAED,MAAM,QAAQ,EAAEE,OAAO,QAAQ,CAAC;QAE9D;IACF;IAEA,MAAMI,OAAOlB,UACXD,oBAAoB;QAAC;YAAEoB,MAAM;QAAU;QAAG;YAAEA,MAAM;QAAU;KAAE,EAAE;QAACN;QAAQE;KAAY;IAEvF,MAAMK,QAAQnB,IAAIE,MAAMW,SAAS;QAAEO,MAAM;IAAG;IAE5C,MAAMV,aAAaW,OAAO,CAAC;QACzBC,QAAQ;QACRC,QAAQ;YAACZ;YAAOM;YAAME;SAAM;IAC9B;IAEA,MAAMK,eAAevB,SAAS;QAAC;KAAqD;IACpF,MAAMwB,UAAU,MAAMf,aAAagB,YAAY,CAAC;QAC9CC,SAAShB;QACTiB,KAAKJ;QACLK,cAAc;QACdC,MAAM;YAAClB;SAAO;IAChB;IACA,IAAIa,YAAYZ,QAAQ;QACtB,MAAM,IAAIkB,MACR,CAAC,2CAA2C,EAAEpB,MAAM,KAAK,EAAEC,OAAO,EAAE,CAAC,GACnE,CAAC,SAAS,EAAEC,OAAO,MAAM,EAAEY,QAAQ,8BAA8B,CAAC,GAClE,CAAC,iBAAiB,EAAEX,YAAY,wBAAwB,CAAC;IAE/D;AACF;AAEA;;;CAGC,GACD,OAAO,eAAekB,eACpBtB,YAA0B,EAC1BE,MAAe,EACfqB,eAAuB;IAEvB,MAAMC,OACJ,AAAC7B,QAAQC,GAAG,CAAC6B,uBAAuB,IAAgB;IACtD,MAAM1B,gBAAgBC,cAAcwB,MAAMtB,QAAQqB;AACpD"}
@@ -67,10 +67,10 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
67
67
  };
68
68
  getEvents: {
69
69
  [x: string]: (...parameters: [options?: {
70
- blockHash?: `0x${string}` | undefined;
71
70
  strict?: boolean | undefined;
72
71
  fromBlock?: bigint | import("viem").BlockTag | undefined;
73
72
  toBlock?: bigint | import("viem").BlockTag | undefined;
73
+ blockHash?: `0x${string}` | undefined;
74
74
  } | undefined] | [args?: readonly unknown[] | {
75
75
  [x: string]: unknown;
76
76
  address?: undefined;
@@ -85,10 +85,10 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
85
85
  batch?: undefined;
86
86
  pollingInterval?: undefined;
87
87
  } | undefined, options?: {
88
- blockHash?: `0x${string}` | undefined;
89
88
  strict?: boolean | undefined;
90
89
  fromBlock?: bigint | import("viem").BlockTag | undefined;
91
90
  toBlock?: bigint | import("viem").BlockTag | undefined;
91
+ blockHash?: `0x${string}` | undefined;
92
92
  } | undefined]) => Promise<import("viem").GetContractEventsReturnType<Abi, string>>;
93
93
  };
94
94
  watchEvent: {
@@ -96,8 +96,8 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
96
96
  batch?: boolean | undefined | undefined;
97
97
  pollingInterval?: number | undefined | undefined;
98
98
  strict?: boolean | undefined;
99
- onError?: ((error: Error) => void) | undefined | undefined;
100
99
  fromBlock?: bigint | undefined;
100
+ onError?: ((error: Error) => void) | undefined | undefined;
101
101
  onLogs: import("viem").WatchContractEventOnLogsFn<Abi, string, undefined>;
102
102
  poll?: true | undefined | undefined;
103
103
  } | undefined] | [args: readonly unknown[] | {
@@ -117,8 +117,8 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
117
117
  batch?: boolean | undefined | undefined;
118
118
  pollingInterval?: number | undefined | undefined;
119
119
  strict?: boolean | undefined;
120
- onError?: ((error: Error) => void) | undefined | undefined;
121
120
  fromBlock?: bigint | undefined;
121
+ onError?: ((error: Error) => void) | undefined | undefined;
122
122
  onLogs: import("viem").WatchContractEventOnLogsFn<Abi, string, undefined>;
123
123
  poll?: true | undefined | undefined;
124
124
  } | undefined]) => import("viem").WatchContractEventReturnType;