@nevermined-io/core-kit 0.1.3 → 0.1.5

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 (145) hide show
  1. package/dist/Instantiable.abstract.d.ts +33 -0
  2. package/dist/Instantiable.abstract.d.ts.map +1 -0
  3. package/dist/Instantiable.abstract.js +98 -0
  4. package/dist/artifacts/generated.d.ts +39371 -0
  5. package/dist/artifacts/generated.d.ts.map +1 -0
  6. package/dist/artifacts/generated.js +21448 -0
  7. package/dist/contracts/AccessManager.d.ts +17 -0
  8. package/dist/contracts/AccessManager.d.ts.map +1 -0
  9. package/dist/contracts/AccessManager.js +15 -0
  10. package/dist/contracts/AssetRegistry.d.ts +105 -0
  11. package/dist/contracts/AssetRegistry.d.ts.map +1 -0
  12. package/dist/contracts/AssetRegistry.js +155 -0
  13. package/dist/contracts/ContractBase.d.ts +45 -0
  14. package/dist/contracts/ContractBase.d.ts.map +1 -0
  15. package/dist/contracts/ContractBase.js +519 -0
  16. package/dist/contracts/ContractsApi.d.ts +69 -0
  17. package/dist/contracts/ContractsApi.d.ts.map +1 -0
  18. package/dist/contracts/ContractsApi.js +73 -0
  19. package/dist/contracts/CryptoTemplateBase.d.ts +11 -0
  20. package/dist/contracts/CryptoTemplateBase.d.ts.map +1 -0
  21. package/dist/contracts/CryptoTemplateBase.js +49 -0
  22. package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
  23. package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
  24. package/dist/contracts/FiatPaymentTemplate.js +14 -0
  25. package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
  26. package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
  27. package/dist/contracts/FiatSettlementCondition.js +18 -0
  28. package/dist/contracts/FixedPaymentTemplate.d.ts +12 -0
  29. package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
  30. package/dist/contracts/FixedPaymentTemplate.js +62 -0
  31. package/dist/contracts/NFT1155Base.d.ts +50 -0
  32. package/dist/contracts/NFT1155Base.d.ts.map +1 -0
  33. package/dist/contracts/NFT1155Base.js +24 -0
  34. package/dist/contracts/NFT1155Credits.d.ts +6 -0
  35. package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
  36. package/dist/contracts/NFT1155Credits.js +9 -0
  37. package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
  38. package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
  39. package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
  40. package/dist/contracts/NVMConfig.d.ts +10 -0
  41. package/dist/contracts/NVMConfig.d.ts.map +1 -0
  42. package/dist/contracts/NVMConfig.js +18 -0
  43. package/dist/contracts/PayAsYouGoTemplate.d.ts +12 -0
  44. package/dist/contracts/PayAsYouGoTemplate.d.ts.map +1 -0
  45. package/dist/contracts/PayAsYouGoTemplate.js +62 -0
  46. package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
  47. package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
  48. package/dist/contracts/ProtocolStandardFees.js +15 -0
  49. package/dist/contracts/Roles.d.ts +13 -0
  50. package/dist/contracts/Roles.d.ts.map +1 -0
  51. package/dist/contracts/Roles.js +12 -0
  52. package/dist/contracts/index.d.ts +3 -0
  53. package/dist/contracts/index.d.ts.map +1 -0
  54. package/dist/contracts/index.js +2 -0
  55. package/dist/errors/NeverminedErrors.d.ts +74 -0
  56. package/dist/errors/NeverminedErrors.d.ts.map +1 -0
  57. package/dist/errors/NeverminedErrors.js +128 -0
  58. package/dist/errors/index.d.ts +2 -0
  59. package/dist/errors/index.d.ts.map +1 -0
  60. package/dist/errors/index.js +1 -0
  61. package/dist/index.d.ts +8 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +8 -0
  64. package/dist/models/AgentAccessToken.d.ts +123 -0
  65. package/dist/models/AgentAccessToken.d.ts.map +1 -0
  66. package/dist/models/AgentAccessToken.js +164 -0
  67. package/dist/models/AgentX402AccessToken.d.ts +59 -0
  68. package/dist/models/AgentX402AccessToken.d.ts.map +1 -0
  69. package/dist/models/AgentX402AccessToken.js +78 -0
  70. package/dist/models/Logger.d.ts +9 -0
  71. package/dist/models/Logger.d.ts.map +1 -0
  72. package/dist/models/Logger.js +27 -0
  73. package/dist/models/NeverminedOptions.d.ts +30 -0
  74. package/dist/models/NeverminedOptions.d.ts.map +1 -0
  75. package/dist/models/NeverminedOptions.js +28 -0
  76. package/dist/models/NvmApiKey.d.ts +137 -0
  77. package/dist/models/NvmApiKey.d.ts.map +1 -0
  78. package/dist/models/NvmApiKey.js +235 -0
  79. package/dist/models/Transactions.d.ts +11 -0
  80. package/dist/models/Transactions.d.ts.map +1 -0
  81. package/dist/models/Transactions.js +1 -0
  82. package/dist/models/index.d.ts +7 -0
  83. package/dist/models/index.d.ts.map +1 -0
  84. package/dist/models/index.js +6 -0
  85. package/dist/nevermined/Nevermined.d.ts +48 -0
  86. package/dist/nevermined/Nevermined.d.ts.map +1 -0
  87. package/dist/nevermined/Nevermined.js +72 -0
  88. package/dist/nevermined/api/PaymentsApi.d.ts +24 -0
  89. package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
  90. package/dist/nevermined/api/PaymentsApi.js +179 -0
  91. package/dist/nevermined/api/ServicesApi.d.ts +23 -0
  92. package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
  93. package/dist/nevermined/api/ServicesApi.js +27 -0
  94. package/dist/nevermined/api/UtilsApi.d.ts +28 -0
  95. package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
  96. package/dist/nevermined/api/UtilsApi.js +33 -0
  97. package/dist/nevermined/index.d.ts +3 -0
  98. package/dist/nevermined/index.d.ts.map +1 -0
  99. package/dist/nevermined/index.js +2 -0
  100. package/dist/nevermined/utils/AgentUtils.d.ts +8 -0
  101. package/dist/nevermined/utils/AgentUtils.d.ts.map +1 -0
  102. package/dist/nevermined/utils/AgentUtils.js +56 -0
  103. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +280 -0
  104. package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
  105. package/dist/nevermined/utils/BlockchainViemUtils.js +408 -0
  106. package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
  107. package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
  108. package/dist/nevermined/utils/JwtUtils.js +161 -0
  109. package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
  110. package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
  111. package/dist/nevermined/utils/SignatureUtils.js +99 -0
  112. package/dist/nevermined/utils/WebServiceConnector.d.ts +30 -0
  113. package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
  114. package/dist/nevermined/utils/WebServiceConnector.js +170 -0
  115. package/dist/nevermined/utils/ZeroDevPolicies.d.ts +38 -0
  116. package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
  117. package/dist/nevermined/utils/ZeroDevPolicies.js +196 -0
  118. package/dist/nevermined/utils/index.d.ts +7 -0
  119. package/dist/nevermined/utils/index.d.ts.map +1 -0
  120. package/dist/nevermined/utils/index.js +6 -0
  121. package/dist/services/Api.d.ts +7 -0
  122. package/dist/services/Api.d.ts.map +1 -0
  123. package/dist/services/Api.js +25 -0
  124. package/dist/services/Profiles.d.ts +16 -0
  125. package/dist/services/Profiles.d.ts.map +1 -0
  126. package/dist/services/Profiles.js +84 -0
  127. package/dist/services/index.d.ts +3 -0
  128. package/dist/services/index.d.ts.map +1 -0
  129. package/dist/services/index.js +2 -0
  130. package/dist/utils/ConversionTypeHelpers.d.ts +5 -0
  131. package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
  132. package/dist/utils/ConversionTypeHelpers.js +30 -0
  133. package/dist/utils/DeploymentInfo.d.ts +15 -0
  134. package/dist/utils/DeploymentInfo.d.ts.map +1 -0
  135. package/dist/utils/DeploymentInfo.js +38 -0
  136. package/dist/utils/Network.d.ts +5 -0
  137. package/dist/utils/Network.d.ts.map +1 -0
  138. package/dist/utils/Network.js +224 -0
  139. package/dist/utils/helpers.d.ts +40 -0
  140. package/dist/utils/helpers.d.ts.map +1 -0
  141. package/dist/utils/helpers.js +189 -0
  142. package/dist/utils/index.d.ts +5 -0
  143. package/dist/utils/index.d.ts.map +1 -0
  144. package/dist/utils/index.js +4 -0
  145. package/package.json +1 -1
@@ -0,0 +1,519 @@
1
+ import { createKernelAccountClient, createZeroDevPaymasterClient, getUserOperationGasPrice, } from '@zerodev/sdk';
2
+ import { BaseError, ContractFunctionRevertedError, encodeFunctionData, getContract, http, parseAbi, parseEventLogs, } from 'viem';
3
+ import { ContractsError, ContractSimulationError } from '../errors/index.js';
4
+ import { Instantiable } from '../Instantiable.abstract.js';
5
+ import { getInputsOfFunctionFormatted, getTransactionReceipt } from '../nevermined/index.js';
6
+ import { getChain } from '../utils/Network.js';
7
+ export class ContractBase extends Instantiable {
8
+ contractName;
9
+ contract;
10
+ address;
11
+ constructor(contractName, address) {
12
+ super();
13
+ this.contractName = contractName;
14
+ this.address = address;
15
+ }
16
+ async init(config, contractConfig) {
17
+ this.setInstanceConfig(config);
18
+ this.address = contractConfig.address;
19
+ this.contract = getContract({
20
+ address: contractConfig.address,
21
+ abi: contractConfig.abi,
22
+ client: { public: this.publicClient, wallet: this.walletClient },
23
+ });
24
+ }
25
+ async call(functionName, args, from) {
26
+ try {
27
+ return (await this.client.public.readContract({
28
+ address: this.address,
29
+ abi: this.contract.abi,
30
+ functionName: parseAbi([functionName]),
31
+ args,
32
+ ...(from && { account: from }),
33
+ }));
34
+ //return await this.contract[functionSignature](...args, { from })
35
+ }
36
+ catch (err) {
37
+ throw new ContractsError(`Calling method "${functionName}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
38
+ }
39
+ }
40
+ async getTransactionReceipt(txHash) {
41
+ // Get the transaction receipt depending on the type of txHash
42
+ if ('transactionHash' in txHash) {
43
+ // txHash is TransactionReceipt
44
+ return txHash;
45
+ }
46
+ else if ('userOpHash' in txHash) {
47
+ // txHash is UserOperationReceipt, fetch the actual receipt using the utility function with retry logic
48
+ const hash = txHash.receipt.transactionHash;
49
+ return await getTransactionReceipt({
50
+ txHash: hash,
51
+ publicClient: this.client.public,
52
+ });
53
+ }
54
+ else {
55
+ throw new Error('Unknown transaction type');
56
+ }
57
+ }
58
+ getTransactionLogs(txReceipt, eventName) {
59
+ return parseEventLogs({
60
+ abi: this.contract.abi,
61
+ logs: txReceipt.logs,
62
+ eventName,
63
+ strict: false,
64
+ });
65
+ }
66
+ async multicall(calls, from, params = {}) {
67
+ if (from.type === 'local') {
68
+ this.logger.debug(`Blockchain Multicall using Local account`);
69
+ return await this.localAccountMulticall(calls, from, params, params.progress);
70
+ }
71
+ else if (from.type === 'json-rpc') {
72
+ this.logger.debug(`Blockchain Multicall using JSON-RPC account`);
73
+ return await this.localAccountMulticall(calls, from, params, params.progress);
74
+ }
75
+ else if (from.type === 'smart') {
76
+ this.logger.debug(`Blockchain Multicall using ZeroDev account`);
77
+ return await this.internalMulticallSmartAccount(calls, from, params, params.progress);
78
+ }
79
+ else {
80
+ throw new ContractsError(`Account not supported`);
81
+ }
82
+ }
83
+ async simulateMulticall(calls, from, params = {}) {
84
+ if (from.type === 'local') {
85
+ this.logger.debug(`Simulating calls using Local account`);
86
+ return await this.localAccountSimulateMulticall(calls, from, params);
87
+ }
88
+ else if (from.type === 'json-rpc') {
89
+ this.logger.debug(`Simulating calls using JSON-RPC account`);
90
+ return await this.localAccountSimulateMulticall(calls, from, params);
91
+ }
92
+ else if (from.type === 'smart') {
93
+ this.logger.debug(`Simulating calls using Smart Account account`);
94
+ return await this.internalSimulateMulticallSmartAccount(calls, from, params);
95
+ }
96
+ else {
97
+ throw new ContractsError(`Account not supported`);
98
+ }
99
+ }
100
+ async simulate(functionName, from, args, params = {}) {
101
+ if (from.type === 'local') {
102
+ this.logger.debug(`Simulating calls using Local account`);
103
+ return await this.localAccountSimulate(functionName, from, args, params);
104
+ }
105
+ else if (from.type === 'json-rpc') {
106
+ this.logger.debug(`Simulating calls using JSON-RPC account`);
107
+ return await this.localAccountSimulate(functionName, from, args, params);
108
+ }
109
+ else if (from.type === 'smart') {
110
+ this.logger.debug(`Simulating calls using Smart Account account`);
111
+ return await this.internalSimulateSmartAccount(functionName, from, args, params);
112
+ }
113
+ else {
114
+ throw new ContractsError(`Account not supported`);
115
+ }
116
+ }
117
+ async send(functionName, from, args, params = {}) {
118
+ if (from.type === 'local') {
119
+ this.logger.debug(`Blockchain Send using Local account with functionName: ${functionName} and following args: ${args}`);
120
+ return await this.localAccountSend(functionName, from, args, params, params.progress);
121
+ }
122
+ else if (from.type === 'json-rpc') {
123
+ this.logger.debug(`Blockchain Send using JSON-RPC account to ${functionName}`);
124
+ return await this.localAccountSend(functionName, from, args, params, params.progress);
125
+ }
126
+ else if (from.type === 'smart') {
127
+ this.logger.debug(`Blockchain Send using ZeroDev account`);
128
+ return await this.internalSendSmartAccount(functionName, from, args, params, params.progress);
129
+ }
130
+ else {
131
+ throw new ContractsError(`Account not supported`);
132
+ }
133
+ }
134
+ async internalMulticallSmartAccount(calls, from, txparams, progress) {
135
+ if (progress) {
136
+ progress({
137
+ stage: 'multicall-sending',
138
+ args: [],
139
+ method: '',
140
+ from: from,
141
+ contractAddress: this.address,
142
+ });
143
+ }
144
+ const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
145
+ const zerodevPaymaster = createZeroDevPaymasterClient({
146
+ chain: getChain(this.config.chainId),
147
+ transport: http(ZERODEV_RPC),
148
+ });
149
+ const kernelClient = createKernelAccountClient({
150
+ account: from,
151
+ chain: getChain(this.config.chainId),
152
+ bundlerTransport: http(ZERODEV_RPC),
153
+ client: this.client.public,
154
+ paymaster: {
155
+ getPaymasterData: (userOperation) => {
156
+ return zerodevPaymaster.sponsorUserOperation({
157
+ userOperation,
158
+ });
159
+ },
160
+ },
161
+ });
162
+ const encodedCalls = [];
163
+ calls.map((call) => {
164
+ encodedCalls.push({
165
+ to: call.contractAddress || this.address,
166
+ value: txparams.value || 0n,
167
+ data: encodeFunctionData({
168
+ abi: call.abi,
169
+ functionName: call.functionName,
170
+ args: call.args,
171
+ }),
172
+ });
173
+ });
174
+ try {
175
+ const userOpHash = await kernelClient.sendUserOperation({
176
+ callData: await kernelClient.account.encodeCalls(encodedCalls),
177
+ });
178
+ if (progress) {
179
+ progress({
180
+ stage: 'multicall-sent',
181
+ args: [],
182
+ method: '',
183
+ from: from,
184
+ contractAddress: this.address,
185
+ });
186
+ }
187
+ // Wait for the transaction to be mined
188
+ this.logger.debug(`Waiting for transaction to be mined... ${userOpHash}`);
189
+ const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
190
+ this.logger.debug(`Transaction mined - UserOperationHash: ${userOpHash}`);
191
+ this.logger.debug(`Transaction receipt - TransactionHash: ${txReceipt.receipt.transactionHash}`);
192
+ return txReceipt.receipt;
193
+ }
194
+ catch (err) {
195
+ if (err instanceof BaseError) {
196
+ const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
197
+ this.logger.error(`revertError: ${String(revertError)}`);
198
+ }
199
+ throw new ContractsError(`Multicall failed: ${err}`);
200
+ }
201
+ }
202
+ async internalSendSmartAccount(name, from, args, txparams, progress) {
203
+ const functionInputs = getInputsOfFunctionFormatted(this.contract.abi, name, args);
204
+ const { gasLimit, value } = txparams;
205
+ if (progress) {
206
+ progress({
207
+ stage: 'sending',
208
+ args: functionInputs,
209
+ method: name,
210
+ from: from,
211
+ value,
212
+ contractName: this.contractName,
213
+ contractAddress: this.address,
214
+ gasLimit,
215
+ });
216
+ }
217
+ const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
218
+ try {
219
+ await this.client.public.simulateContract({
220
+ address: this.address,
221
+ abi: this.contract.abi,
222
+ functionName: name,
223
+ args,
224
+ account: from,
225
+ ...(txparams.value && { value: txparams.value }),
226
+ });
227
+ }
228
+ catch (err) {
229
+ if (err instanceof BaseError) {
230
+ const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
231
+ this.logger.error(`revertError: ${String(revertError)}`);
232
+ }
233
+ throw new ContractsError(`Calling method "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
234
+ }
235
+ const zerodevPaymaster = createZeroDevPaymasterClient({
236
+ chain: getChain(this.config.chainId),
237
+ transport: http(ZERODEV_RPC),
238
+ });
239
+ const kernelClient = createKernelAccountClient({
240
+ account: from,
241
+ // Replace with your chain
242
+ chain: getChain(this.config.chainId),
243
+ // Find the RPC in your ZeroDev dashboard
244
+ bundlerTransport: http(ZERODEV_RPC),
245
+ // Required - the public client
246
+ client: this.client.public,
247
+ // Optional -- only if you want to use a paymaster
248
+ paymaster: {
249
+ getPaymasterData: (userOperation) => {
250
+ return zerodevPaymaster.sponsorUserOperation({
251
+ userOperation,
252
+ });
253
+ },
254
+ },
255
+ });
256
+ const data = encodeFunctionData({ abi: this.contract.abi, functionName: name, args });
257
+ let userOpHash;
258
+ try {
259
+ userOpHash = await kernelClient.sendUserOperation({
260
+ callData: await kernelClient.account.encodeCalls([
261
+ {
262
+ to: this.address,
263
+ value: txparams.value || 0n,
264
+ data,
265
+ },
266
+ ]),
267
+ });
268
+ }
269
+ catch (err) {
270
+ if (err instanceof BaseError) {
271
+ const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
272
+ this.logger.error(`revertError: ${String(revertError)}`);
273
+ }
274
+ throw new ContractsError(`Calling method "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
275
+ }
276
+ if (progress) {
277
+ progress({
278
+ stage: 'sent',
279
+ args: functionInputs,
280
+ userOpHash,
281
+ method: name,
282
+ from: from,
283
+ value,
284
+ contractName: this.contractName,
285
+ contractAddress: this.address,
286
+ gasLimit,
287
+ });
288
+ }
289
+ const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
290
+ if (progress) {
291
+ progress({
292
+ stage: 'receipt',
293
+ args: functionInputs,
294
+ txReceipt,
295
+ method: name,
296
+ from: from,
297
+ value,
298
+ contractName: this.contractName,
299
+ contractAddress: this.address,
300
+ gasLimit,
301
+ });
302
+ }
303
+ return txReceipt;
304
+ }
305
+ async internalSimulateSmartAccount(name, from, args, txparams) {
306
+ try {
307
+ await this.client.public.simulateContract({
308
+ address: this.address,
309
+ abi: this.contract.abi,
310
+ functionName: name,
311
+ args,
312
+ account: from.address,
313
+ ...(txparams.value && { value: txparams.value }),
314
+ });
315
+ return true;
316
+ }
317
+ catch (err) {
318
+ throw new ContractSimulationError(`Error Simulating contract call "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
319
+ }
320
+ }
321
+ async localAccountSimulate(name, from, args, txparams) {
322
+ try {
323
+ await this.client.public.simulateContract({
324
+ address: this.address,
325
+ abi: this.contract.abi,
326
+ functionName: name,
327
+ args,
328
+ account: from,
329
+ ...(txparams.value && { value: txparams.value }),
330
+ });
331
+ }
332
+ catch (err) {
333
+ throw new ContractSimulationError(`Error Simulating contract call "${name}" on contract "${this.contractName}" failed. Args: ${args} - ${err}`);
334
+ }
335
+ return true;
336
+ }
337
+ async localAccountSend(name, from, args, txparams, progress, _contractAbi, _contractAddress, _contractName) {
338
+ const abi = _contractAbi || this.contract.abi;
339
+ const contractAddress = _contractAddress || this.address;
340
+ const contractName = _contractName || this.contractName;
341
+ const functionInputs = getInputsOfFunctionFormatted(abi, name, args);
342
+ // Uncomment to debug contract calls
343
+ // if (name === 'order') {
344
+ // const functionSignature = getSignatureOfFunction(this.contract.abi, name, args)
345
+ // this.logger.info(`Making contract call ....: ${name} - ${from}`)
346
+ // this.logger.info(`With args: `, JSON.stringify(args, jsonReplacer))
347
+ // this.logger.info(`And signature: ${JSON.stringify(functionSignature, jsonReplacer)}`)
348
+ // this.logger.info('And amount: ', txparams.value)
349
+ // }
350
+ // abi.filter(({name, inputs}) => name === 'closeSignals' && inputs.length === 1)
351
+ // const abiFilter = this.contract.abi.filter((abi) => abi.name === name && abi.inputs.length === args.length)
352
+ // const abiFilter = this.contract.abi.filter((abi) => abi.name === name && abi.type === 'function')
353
+ // console.debug('abi', this.contract.abi.filter((abi) => abi.name === name))
354
+ // console.debug('abiFilter', abiFilter)
355
+ // if (!abiFilter)
356
+ // throw new ContractsError(
357
+ // `No ABI found for method "${name}" with ${args.length} arguments on contract "${this.contractName}"`,
358
+ // )
359
+ const { gasLimit, value } = txparams;
360
+ // make the call
361
+ if (progress) {
362
+ progress({
363
+ stage: 'sending',
364
+ args: functionInputs,
365
+ method: name,
366
+ from,
367
+ value,
368
+ contractName,
369
+ contractAddress,
370
+ gasLimit,
371
+ });
372
+ }
373
+ let txHash;
374
+ try {
375
+ const { request } = await this.client.public.simulateContract({
376
+ address: contractAddress,
377
+ abi,
378
+ functionName: name,
379
+ args,
380
+ account: from,
381
+ ...(txparams.value && { value: txparams.value }),
382
+ });
383
+ txHash = await this.client.wallet.writeContract({
384
+ ...request,
385
+ account: from,
386
+ });
387
+ }
388
+ catch (err) {
389
+ if (err instanceof BaseError) {
390
+ const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
391
+ this.logger.error(`revertError: ${String(revertError)}`);
392
+ }
393
+ throw new ContractsError(`Calling method "${name}" on contract "${contractName}" failed. Args: ${args} - ${err}`);
394
+ }
395
+ if (progress) {
396
+ progress({
397
+ stage: 'sent',
398
+ args: functionInputs,
399
+ txHash,
400
+ method: name,
401
+ from,
402
+ value,
403
+ contractName,
404
+ contractAddress,
405
+ gasLimit,
406
+ });
407
+ }
408
+ const txReceipt = getTransactionReceipt({ txHash, publicClient: this.client.public });
409
+ if (progress) {
410
+ progress({
411
+ stage: 'receipt',
412
+ args: functionInputs,
413
+ txReceipt,
414
+ method: name,
415
+ from,
416
+ value,
417
+ contractName,
418
+ contractAddress,
419
+ gasLimit,
420
+ });
421
+ }
422
+ return txReceipt;
423
+ }
424
+ async localAccountMulticall(calls, from, txparams, progress) {
425
+ const receipts = [];
426
+ for (const call of calls) {
427
+ receipts.push(await this.localAccountSend(call.functionName, from, call.args, txparams, progress, call.abi, call.contractAddress, call.contractName));
428
+ }
429
+ if (receipts.length > 0)
430
+ return receipts.pop();
431
+ else
432
+ throw new ContractsError(`No receipts found for multicall`);
433
+ }
434
+ async localAccountSimulateMulticall(calls, from, txparams) {
435
+ try {
436
+ const { results } = await this.client.public.simulateCalls({
437
+ calls,
438
+ account: from,
439
+ });
440
+ this.logger.debug(`Simulated multicall - ${results}`);
441
+ return true;
442
+ }
443
+ catch (err) {
444
+ if (err instanceof BaseError) {
445
+ const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
446
+ this.logger.error(`revertError: ${String(revertError)}`);
447
+ }
448
+ throw new ContractsError(`Error simulating multicall - ${err}`);
449
+ }
450
+ }
451
+ async internalSimulateMulticallSmartAccount(calls, from, txparams) {
452
+ try {
453
+ const zerodevPaymaster = createZeroDevPaymasterClient({
454
+ chain: getChain(this.config.chainId),
455
+ transport: http(this.getZeroDevRPC()),
456
+ });
457
+ const kernelClient = createKernelAccountClient({
458
+ account: from,
459
+ chain: getChain(this.config.chainId),
460
+ bundlerTransport: http(this.getZeroDevRPC()),
461
+ client: this.client.public,
462
+ paymaster: {
463
+ getPaymasterData: (userOperation) => {
464
+ return zerodevPaymaster.sponsorUserOperation({
465
+ userOperation,
466
+ });
467
+ },
468
+ },
469
+ userOperation: {
470
+ estimateFeesPerGas: async ({ bundlerClient }) => {
471
+ return getUserOperationGasPrice(bundlerClient);
472
+ },
473
+ },
474
+ });
475
+ const encodedCalls = [];
476
+ for (const call of calls) {
477
+ encodedCalls.push({
478
+ to: call.to,
479
+ value: call.value || 0n,
480
+ data: encodeFunctionData({
481
+ abi: call.abi,
482
+ functionName: call.functionName,
483
+ args: call.args,
484
+ }),
485
+ });
486
+ }
487
+ // DONT DELETE THE COMMENTED LINES - ARE NECESSARY FOR F***ING ZERODEV DEBUGGING
488
+ // this.logger.info(`Encoded multicall - ${JSON.stringify(encodedCalls, jsonReplacer)}`)
489
+ // const code = await this.client.public.getCode({ address: from.address })
490
+ // const isDeployed = code !== undefined && code !== '0x'
491
+ // this.logger.info(`++++++ Smart account ${from.address} deployment status: ${isDeployed ? 'DEPLOYED' : 'NOT DEPLOYED'}`)
492
+ // // Log account details
493
+ // this.logger.info(`Account type: ${from.type}`)
494
+ // this.logger.info(`Account address: ${from.address}`)
495
+ // // Log the calls being made
496
+ // this.logger.info(`Number of calls: ${encodedCalls.length}`)
497
+ // encodedCalls.forEach((call, index) => {
498
+ // this.logger.info(`Call ${index}: to=${call.to}, value=${call.value}, data=${call.data.slice(0, 10)}...`)
499
+ // })
500
+ await kernelClient.prepareUserOperation({
501
+ callData: await kernelClient.account.encodeCalls(encodedCalls),
502
+ });
503
+ return true;
504
+ }
505
+ catch (err) {
506
+ this.logger.error(`Error details: ${JSON.stringify(err, null, 2)}`);
507
+ if (err instanceof BaseError) {
508
+ const revertError = err.walk((e) => e instanceof ContractFunctionRevertedError);
509
+ if (revertError) {
510
+ this.logger.error(`Revert error: ${String(revertError)}`);
511
+ }
512
+ }
513
+ throw new ContractSimulationError(`Error Simulating Multicalls - ${err}`);
514
+ }
515
+ }
516
+ getZeroDevRPC() {
517
+ return `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
518
+ }
519
+ }
@@ -0,0 +1,69 @@
1
+ import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
2
+ import { AccessManager } from './AccessManager.js';
3
+ import { AssetRegistry } from './AssetRegistry.js';
4
+ import { FiatPaymentTemplate } from './FiatPaymentTemplate.js';
5
+ import { FixedPaymentTemplate } from './FixedPaymentTemplate.js';
6
+ import { PayAsYouGoTemplate } from './PayAsYouGoTemplate.js';
7
+ import { NFT1155Credits } from './NFT1155Credits.js';
8
+ import { NFT1155ExpirableCredits } from './NFT1155ExpirableCredits.js';
9
+ import { NeverminedConfig } from './NVMConfig.js';
10
+ import { ProtocolStandardFees } from './ProtocolStandardFees.js';
11
+ export declare class ContractsApi extends Instantiable {
12
+ /**
13
+ * Return ContractsApi instance
14
+ * @param config
15
+ * @returns {@link ContractsApi}
16
+ */
17
+ static getInstance(config: InstantiableConfig): Promise<ContractsApi>;
18
+ init(): Promise<void>;
19
+ /**
20
+ * Access Manager smart contract instance.
21
+ */
22
+ accessManager: AccessManager;
23
+ /**
24
+ * Nevermined Config smart contract instance.
25
+ */
26
+ nvmConfig: NeverminedConfig;
27
+ /**
28
+ * Asset registry smart contract instance.
29
+ */
30
+ assetRegistry: AssetRegistry;
31
+ /**
32
+ * NFT1155Credits smart contract instance.
33
+ * Manages non-expirable credits using the ERC-1155 standard.
34
+ * Allows minting, burning and balance checking of credits.
35
+ */
36
+ nft1155Credits: NFT1155Credits;
37
+ /**
38
+ * NFT1155ExpirableCredits smart contract instance.
39
+ * Manages expirable credits using the ERC-1155 standard.
40
+ * Similar to NFT1155Credits but with an additional expiration mechanism.
41
+ * Credits minted through this contract will expire after a specified duration.
42
+ */
43
+ nft1155ExpirableCredits: NFT1155ExpirableCredits;
44
+ /**
45
+ * FixedPaymentTemplate smart contract instance.
46
+ * Handles fixed payment agreements between parties.
47
+ * Used for creating and managing payment agreements with predefined terms.
48
+ */
49
+ fixedPaymentTemplate: FixedPaymentTemplate;
50
+ /**
51
+ * FiatPaymentTemplate smart contract instance.
52
+ * Handles fiat payment agreements between parties (i.e Stripe).
53
+ * Used for creating and managing payment agreements with predefined terms.
54
+ */
55
+ fiatPaymentTemplate: FiatPaymentTemplate;
56
+ /**
57
+ * PayAsYouGoTemplate smart contract instance.
58
+ * Handles pay as you go agreements between parties.
59
+ * Used for creating and managing payment agreements with predefined terms.
60
+ */
61
+ payAsYouGoTemplate: PayAsYouGoTemplate;
62
+ /**
63
+ * ProtocolStandardFees smart contract instance.
64
+ * It provides methods to calculate fees based on total amounts, price configurations, and credits configurations.
65
+ * This is the default fee controller for the protocol.
66
+ */
67
+ protocolStandardFees: ProtocolStandardFees;
68
+ }
69
+ //# sourceMappingURL=ContractsApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractsApi.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAEhE,qBAAa,YAAa,SAAQ,YAAY;IAC5C;;;;OAIG;WAC0B,WAAW,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAM9E,IAAI;IA6BjB;;OAEG;IACI,aAAa,EAAG,aAAa,CAAA;IACpC;;OAEG;IACI,SAAS,EAAG,gBAAgB,CAAA;IAEnC;;OAEG;IACI,aAAa,EAAG,aAAa,CAAA;IAEpC;;;;OAIG;IACI,cAAc,EAAG,cAAc,CAAA;IAEtC;;;;;OAKG;IACI,uBAAuB,EAAG,uBAAuB,CAAA;IAExD;;;;OAIG;IACI,oBAAoB,EAAG,oBAAoB,CAAA;IAElD;;;;OAIG;IACI,mBAAmB,EAAG,mBAAmB,CAAA;IAEhD;;;;OAIG;IACI,kBAAkB,EAAG,kBAAkB,CAAA;IAE9C;;;;OAIG;IACI,oBAAoB,EAAG,oBAAoB,CAAA;CACnD"}
@@ -0,0 +1,73 @@
1
+ import { Instantiable } from '../Instantiable.abstract.js';
2
+ export class ContractsApi extends Instantiable {
3
+ /**
4
+ * Return ContractsApi instance
5
+ * @param config
6
+ * @returns {@link ContractsApi}
7
+ */
8
+ static async getInstance(config) {
9
+ const contractsApi = new ContractsApi();
10
+ contractsApi.setInstanceConfig(config);
11
+ return contractsApi;
12
+ }
13
+ async init() {
14
+ this.accessManager = await (await import('./AccessManager.js')).AccessManager.getInstance(this.instanceConfig);
15
+ this.nvmConfig = await (await import('./NVMConfig.js')).NeverminedConfig.getInstance(this.instanceConfig);
16
+ this.assetRegistry = await (await import('./AssetRegistry.js')).AssetRegistry.getInstance(this.instanceConfig);
17
+ this.nft1155Credits = await (await import('./NFT1155Credits.js')).NFT1155Credits.getInstance(this.instanceConfig);
18
+ this.nft1155ExpirableCredits = await (await import('./NFT1155ExpirableCredits.js')).NFT1155ExpirableCredits.getInstance(this.instanceConfig);
19
+ this.fixedPaymentTemplate = await (await import('./FixedPaymentTemplate.js')).FixedPaymentTemplate.getInstance(this.instanceConfig);
20
+ this.fiatPaymentTemplate = await (await import('./FiatPaymentTemplate.js')).FiatPaymentTemplate.getInstance(this.instanceConfig);
21
+ this.payAsYouGoTemplate = await (await import('./PayAsYouGoTemplate.js')).PayAsYouGoTemplate.getInstance(this.instanceConfig);
22
+ this.protocolStandardFees = await (await import('./ProtocolStandardFees.js')).ProtocolStandardFees.getInstance(this.instanceConfig);
23
+ }
24
+ /**
25
+ * Access Manager smart contract instance.
26
+ */
27
+ accessManager;
28
+ /**
29
+ * Nevermined Config smart contract instance.
30
+ */
31
+ nvmConfig;
32
+ /**
33
+ * Asset registry smart contract instance.
34
+ */
35
+ assetRegistry;
36
+ /**
37
+ * NFT1155Credits smart contract instance.
38
+ * Manages non-expirable credits using the ERC-1155 standard.
39
+ * Allows minting, burning and balance checking of credits.
40
+ */
41
+ nft1155Credits;
42
+ /**
43
+ * NFT1155ExpirableCredits smart contract instance.
44
+ * Manages expirable credits using the ERC-1155 standard.
45
+ * Similar to NFT1155Credits but with an additional expiration mechanism.
46
+ * Credits minted through this contract will expire after a specified duration.
47
+ */
48
+ nft1155ExpirableCredits;
49
+ /**
50
+ * FixedPaymentTemplate smart contract instance.
51
+ * Handles fixed payment agreements between parties.
52
+ * Used for creating and managing payment agreements with predefined terms.
53
+ */
54
+ fixedPaymentTemplate;
55
+ /**
56
+ * FiatPaymentTemplate smart contract instance.
57
+ * Handles fiat payment agreements between parties (i.e Stripe).
58
+ * Used for creating and managing payment agreements with predefined terms.
59
+ */
60
+ fiatPaymentTemplate;
61
+ /**
62
+ * PayAsYouGoTemplate smart contract instance.
63
+ * Handles pay as you go agreements between parties.
64
+ * Used for creating and managing payment agreements with predefined terms.
65
+ */
66
+ payAsYouGoTemplate;
67
+ /**
68
+ * ProtocolStandardFees smart contract instance.
69
+ * It provides methods to calculate fees based on total amounts, price configurations, and credits configurations.
70
+ * This is the default fee controller for the protocol.
71
+ */
72
+ protocolStandardFees;
73
+ }
@@ -0,0 +1,11 @@
1
+ import { Abi, Account, Address } from 'viem';
2
+ import { SmartAccount } from 'viem/account-abstraction';
3
+ import { TxParameters } from '../models/Transactions.js';
4
+ import { ContractBase } from './ContractBase.js';
5
+ export declare class CryptoTemplateBase extends ContractBase {
6
+ protected TOKEN_APPROVE_ABI: Abi;
7
+ protected ERC20_TRANSFER_ABI: Abi;
8
+ transferERC20(from: Account | SmartAccount, to: Address, amount: bigint, erc20Address: Address, txParams?: TxParameters): Promise<import("viem").TransactionReceipt>;
9
+ approveERC20(amount: bigint, erc20Address: Address, owner: Account | SmartAccount, txParams?: TxParameters): Promise<import("viem").TransactionReceipt>;
10
+ }
11
+ //# sourceMappingURL=CryptoTemplateBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoTemplateBase.d.ts","sourceRoot":"","sources":["../../src/contracts/CryptoTemplateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAY,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAA;AAEhE,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,SAAS,CAAC,iBAAiB,EAErB,GAAG,CAAA;IAET,SAAS,CAAC,kBAAkB,EAEtB,GAAG,CAAA;IAEI,aAAa,CACxB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,QAAQ,CAAC,EAAE,YAAY;IAqBZ,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;CAqB1B"}