@mycelium-sdk/core 1.0.0 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -93
- package/dist/index.cjs +281 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -27
- package/dist/index.d.ts +53 -27
- package/dist/index.js +261 -39
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
package/dist/index.cjs
CHANGED
|
@@ -37,8 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
39
|
// src/wallet/DefaultSmartWallet.ts
|
|
40
|
-
var
|
|
41
|
-
var import_account_abstraction = require("viem/account-abstraction");
|
|
40
|
+
var import_viem4 = require("viem");
|
|
42
41
|
|
|
43
42
|
// src/abis/smartWalletFactory.ts
|
|
44
43
|
var smartWalletFactoryAbi = [
|
|
@@ -265,6 +264,159 @@ function parseAssetAmount(amount, decimals) {
|
|
|
265
264
|
var SmartWallet = class {
|
|
266
265
|
};
|
|
267
266
|
|
|
267
|
+
// src/wallet/DefaultSmartWallet.ts
|
|
268
|
+
var import_account_abstraction2 = require("viem/account-abstraction");
|
|
269
|
+
|
|
270
|
+
// src/tools/Paymaster.ts
|
|
271
|
+
var import_viem3 = require("viem");
|
|
272
|
+
var import_account_abstraction = require("viem/account-abstraction");
|
|
273
|
+
var import_permissionless = require("permissionless");
|
|
274
|
+
|
|
275
|
+
// src/constants/paymaster.ts
|
|
276
|
+
var ERC20_PAYMASTER_ADDRESS = "0x6666666666667849c56f2850848ce1c4da65c68b";
|
|
277
|
+
|
|
278
|
+
// src/tools/Paymaster.ts
|
|
279
|
+
var Paymaster = class {
|
|
280
|
+
constructor(chainManager) {
|
|
281
|
+
this.chainManager = chainManager;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Gets paymaster client for the specified chain
|
|
285
|
+
*
|
|
286
|
+
* @internal
|
|
287
|
+
* @category Paymaster
|
|
288
|
+
* @param chainId Target chain ID
|
|
289
|
+
* @returns PimlicoClient instance
|
|
290
|
+
* @throws Error if no paymaster URL is configured
|
|
291
|
+
*/
|
|
292
|
+
getPaymasterClient(chainId) {
|
|
293
|
+
return this.chainManager.getPaymasterClient(chainId);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Prepares approval transaction if needed for ERC-20 paymaster
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
* @category Paymaster
|
|
300
|
+
* @param paymasterToken Paymaster token address
|
|
301
|
+
* @param walletAddress Wallet address
|
|
302
|
+
* @param chainId Target chain ID
|
|
303
|
+
* @returns Promise resolving to the approval transaction data or null if allowance exists
|
|
304
|
+
* @throws Error if no public client is available
|
|
305
|
+
*/
|
|
306
|
+
async preparePaymasterApproval(paymasterToken, walletAddress, chainId) {
|
|
307
|
+
const publicClient = this.chainManager.getPublicClient(chainId);
|
|
308
|
+
const allowance = await publicClient.readContract({
|
|
309
|
+
address: paymasterToken,
|
|
310
|
+
abi: import_viem3.erc20Abi,
|
|
311
|
+
functionName: "allowance",
|
|
312
|
+
args: [walletAddress, ERC20_PAYMASTER_ADDRESS]
|
|
313
|
+
});
|
|
314
|
+
if (allowance > 0n) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
to: paymasterToken,
|
|
319
|
+
value: 0n,
|
|
320
|
+
data: (0, import_viem3.encodeFunctionData)({
|
|
321
|
+
abi: import_viem3.erc20Abi,
|
|
322
|
+
functionName: "approve",
|
|
323
|
+
args: [ERC20_PAYMASTER_ADDRESS, import_viem3.maxUint256]
|
|
324
|
+
})
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Prepares calls array with approval if needed for ERC-20 paymaster
|
|
329
|
+
*
|
|
330
|
+
* @internal
|
|
331
|
+
* @category Paymaster
|
|
332
|
+
* @param transactionData Transaction data to prepare
|
|
333
|
+
* @param paymasterToken Paymaster token address
|
|
334
|
+
* @param walletAddress Wallet address
|
|
335
|
+
* @param chainId Target chain ID
|
|
336
|
+
* @returns Prepared calls array with approval if needed
|
|
337
|
+
* @throws Error if no paymaster URL is configured
|
|
338
|
+
*/
|
|
339
|
+
async prepareCallsWithApproval(transactionData, paymasterToken, walletAddress, chainId) {
|
|
340
|
+
const approvalTx = await this.preparePaymasterApproval(paymasterToken, walletAddress, chainId);
|
|
341
|
+
const calls = Array.isArray(transactionData) ? transactionData : [transactionData];
|
|
342
|
+
const callsWithApproval = approvalTx ? [approvalTx, ...calls] : calls;
|
|
343
|
+
return {
|
|
344
|
+
calls: callsWithApproval,
|
|
345
|
+
paymasterContext: {
|
|
346
|
+
token: paymasterToken
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Creates a SmartAccountClient configured with ERC-20 paymaster
|
|
352
|
+
*
|
|
353
|
+
* @internal
|
|
354
|
+
* @category Paymaster
|
|
355
|
+
* @param account Coinbase smart account
|
|
356
|
+
* @param chainId Target chain ID
|
|
357
|
+
* @returns SmartAccountClient instance
|
|
358
|
+
* @throws Error if no bundler URL is configured
|
|
359
|
+
*/
|
|
360
|
+
createSmartAccountClient(account, chainId) {
|
|
361
|
+
const pimlicoClient = this.getPaymasterClient(chainId);
|
|
362
|
+
if (!pimlicoClient) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"Paymaster client is not available. Probably the paymaster URL is not configured for this chain"
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const chain = this.chainManager.getChain(chainId);
|
|
368
|
+
const bundlerUrl = this.chainManager.getBundlerUrl(chainId);
|
|
369
|
+
if (!bundlerUrl) {
|
|
370
|
+
throw new Error(`Bundler URL not configured for chain ID: ${chainId}`);
|
|
371
|
+
}
|
|
372
|
+
return (0, import_permissionless.createSmartAccountClient)({
|
|
373
|
+
account,
|
|
374
|
+
chain,
|
|
375
|
+
bundlerTransport: (0, import_viem3.http)(bundlerUrl),
|
|
376
|
+
paymaster: pimlicoClient,
|
|
377
|
+
userOperation: {
|
|
378
|
+
estimateFeesPerGas: async () => {
|
|
379
|
+
const gasPrice = await pimlicoClient.getUserOperationGasPrice();
|
|
380
|
+
const bump = (value, pct = 20n) => value + value * pct / 100n;
|
|
381
|
+
return {
|
|
382
|
+
maxFeePerGas: bump(gasPrice.fast.maxFeePerGas),
|
|
383
|
+
maxPriorityFeePerGas: bump(gasPrice.fast.maxPriorityFeePerGas)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Sends transaction(s) with ERC-20 paymaster
|
|
391
|
+
*
|
|
392
|
+
* @internal
|
|
393
|
+
* @category Paymaster
|
|
394
|
+
* @param transactionData Transaction data to send
|
|
395
|
+
* @param account Coinbase smart account
|
|
396
|
+
* @param walletAddress Wallet address
|
|
397
|
+
* @param chainId Target chain ID
|
|
398
|
+
* @param paymasterToken Paymaster token address
|
|
399
|
+
* @returns Promise resolving to the transaction hash
|
|
400
|
+
*/
|
|
401
|
+
async sendWithERC20Paymaster(transactionData, account, walletAddress, chainId, paymasterToken) {
|
|
402
|
+
const smartAccountClient = this.createSmartAccountClient(account, chainId);
|
|
403
|
+
const { calls, paymasterContext } = await this.prepareCallsWithApproval(
|
|
404
|
+
transactionData,
|
|
405
|
+
paymasterToken,
|
|
406
|
+
walletAddress,
|
|
407
|
+
chainId
|
|
408
|
+
);
|
|
409
|
+
return smartAccountClient.sendTransaction({
|
|
410
|
+
calls: calls.map((call) => ({
|
|
411
|
+
to: call.to,
|
|
412
|
+
data: call.data,
|
|
413
|
+
value: call.value ?? 0n
|
|
414
|
+
})),
|
|
415
|
+
paymasterContext
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
268
420
|
// src/wallet/DefaultSmartWallet.ts
|
|
269
421
|
var DefaultSmartWallet = class extends SmartWallet {
|
|
270
422
|
/**
|
|
@@ -281,6 +433,7 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
281
433
|
*/
|
|
282
434
|
constructor(owners, signer, chainManager, protocolProvider, coinbaseCDP, deploymentAddress, signerOwnerIndex, nonce) {
|
|
283
435
|
super();
|
|
436
|
+
this.bumpGasLimits = (x, pct = 40n) => x + x * pct / 100n;
|
|
284
437
|
this.owners = owners;
|
|
285
438
|
this._signer = signer;
|
|
286
439
|
this.signerOwnerIndex = signerOwnerIndex;
|
|
@@ -289,6 +442,7 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
289
442
|
this.nonce = nonce;
|
|
290
443
|
this.protocolProvider = protocolProvider;
|
|
291
444
|
this.coinbaseCDP = coinbaseCDP;
|
|
445
|
+
this.paymaster = new Paymaster(this.chainManager);
|
|
292
446
|
}
|
|
293
447
|
/**
|
|
294
448
|
* Returns the signer account for this smart wallet
|
|
@@ -320,7 +474,7 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
320
474
|
}
|
|
321
475
|
const owners_bytes = this.owners.map((owner) => {
|
|
322
476
|
if (typeof owner === "string") {
|
|
323
|
-
return (0,
|
|
477
|
+
return (0, import_viem4.pad)(owner);
|
|
324
478
|
}
|
|
325
479
|
if (owner.type === "webAuthn") {
|
|
326
480
|
return owner.publicKey;
|
|
@@ -349,7 +503,7 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
349
503
|
* @returns Viem Coinbase Smart Account for the given chain
|
|
350
504
|
*/
|
|
351
505
|
async getCoinbaseSmartAccount(chainId) {
|
|
352
|
-
return (0,
|
|
506
|
+
return (0, import_account_abstraction2.toCoinbaseSmartAccount)({
|
|
353
507
|
address: this.deploymentAddress,
|
|
354
508
|
ownerIndex: this.signerOwnerIndex,
|
|
355
509
|
client: this.chainManager.getPublicClient(chainId),
|
|
@@ -421,14 +575,25 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
421
575
|
*
|
|
422
576
|
* @param transactionData Transaction details (`to`, `value`, `data`)
|
|
423
577
|
* @param chainId Target chain ID
|
|
578
|
+
* @param options Optional parameters
|
|
579
|
+
* @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
|
|
424
580
|
* @returns Promise that resolves to the UserOperation hash
|
|
425
581
|
* @throws Error with a readable message if submission or inclusion fails
|
|
426
582
|
*/
|
|
427
|
-
async send(transactionData, chainId) {
|
|
583
|
+
async send(transactionData, chainId, options) {
|
|
428
584
|
try {
|
|
429
585
|
const account = await this.getCoinbaseSmartAccount(chainId);
|
|
586
|
+
if (options?.paymasterToken) {
|
|
587
|
+
const walletAddress = await this.getAddress();
|
|
588
|
+
return this.paymaster.sendWithERC20Paymaster(
|
|
589
|
+
transactionData,
|
|
590
|
+
account,
|
|
591
|
+
walletAddress,
|
|
592
|
+
chainId,
|
|
593
|
+
options.paymasterToken
|
|
594
|
+
);
|
|
595
|
+
}
|
|
430
596
|
const bundlerClient = this.chainManager.getBundlerClient(chainId, account);
|
|
431
|
-
const bump = (x, pct = 40n) => x + x * pct / 100n;
|
|
432
597
|
const gas = await bundlerClient.estimateUserOperationGas({
|
|
433
598
|
account,
|
|
434
599
|
calls: [transactionData]
|
|
@@ -436,9 +601,9 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
436
601
|
const hash = await bundlerClient.sendUserOperation({
|
|
437
602
|
account,
|
|
438
603
|
calls: [transactionData],
|
|
439
|
-
callGasLimit:
|
|
440
|
-
verificationGasLimit:
|
|
441
|
-
preVerificationGas:
|
|
604
|
+
callGasLimit: this.bumpGasLimits(gas.callGasLimit),
|
|
605
|
+
verificationGasLimit: this.bumpGasLimits(gas.verificationGasLimit),
|
|
606
|
+
preVerificationGas: this.bumpGasLimits(gas.preVerificationGas)
|
|
442
607
|
});
|
|
443
608
|
await bundlerClient.waitForUserOperationReceipt({
|
|
444
609
|
hash
|
|
@@ -458,14 +623,25 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
458
623
|
*
|
|
459
624
|
* @param transactionData An array of calls to execute
|
|
460
625
|
* @param chainId Target chain ID
|
|
626
|
+
* @param options Optional parameters
|
|
627
|
+
* @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
|
|
461
628
|
* @returns Promise that resolves to the UserOperation hash for the batch
|
|
462
629
|
* @throws Error with a readable message if submission or inclusion fails
|
|
463
630
|
*/
|
|
464
|
-
async sendBatch(transactionData, chainId) {
|
|
631
|
+
async sendBatch(transactionData, chainId, options) {
|
|
465
632
|
try {
|
|
466
633
|
const account = await this.getCoinbaseSmartAccount(chainId);
|
|
634
|
+
if (options?.paymasterToken) {
|
|
635
|
+
const walletAddress = await this.getAddress();
|
|
636
|
+
return this.paymaster.sendWithERC20Paymaster(
|
|
637
|
+
transactionData,
|
|
638
|
+
account,
|
|
639
|
+
walletAddress,
|
|
640
|
+
chainId,
|
|
641
|
+
options.paymasterToken
|
|
642
|
+
);
|
|
643
|
+
}
|
|
467
644
|
const bundlerClient = this.chainManager.getBundlerClient(chainId, account);
|
|
468
|
-
const bump = (x, pct = 40n) => x + x * pct / 100n;
|
|
469
645
|
const gas = await bundlerClient.estimateUserOperationGas({
|
|
470
646
|
account,
|
|
471
647
|
calls: transactionData
|
|
@@ -473,9 +649,9 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
473
649
|
const hash = await bundlerClient.sendUserOperation({
|
|
474
650
|
account,
|
|
475
651
|
calls: transactionData,
|
|
476
|
-
callGasLimit:
|
|
477
|
-
verificationGasLimit:
|
|
478
|
-
preVerificationGas:
|
|
652
|
+
callGasLimit: this.bumpGasLimits(gas.callGasLimit),
|
|
653
|
+
verificationGasLimit: this.bumpGasLimits(gas.verificationGasLimit),
|
|
654
|
+
preVerificationGas: this.bumpGasLimits(gas.preVerificationGas)
|
|
479
655
|
});
|
|
480
656
|
await bundlerClient.waitForUserOperationReceipt({
|
|
481
657
|
hash
|
|
@@ -592,8 +768,8 @@ var DefaultSmartWallet = class extends SmartWallet {
|
|
|
592
768
|
}
|
|
593
769
|
const resolvedAsset = resolveAsset(asset, chainId);
|
|
594
770
|
const parsedAmount = parseAssetAmount(amount, resolvedAsset.decimals);
|
|
595
|
-
const transferData = (0,
|
|
596
|
-
abi:
|
|
771
|
+
const transferData = (0, import_viem4.encodeFunctionData)({
|
|
772
|
+
abi: import_viem4.erc20Abi,
|
|
597
773
|
functionName: "transfer",
|
|
598
774
|
args: [recipientAddress, parsedAmount]
|
|
599
775
|
});
|
|
@@ -642,8 +818,9 @@ var FundingNamespace = class {
|
|
|
642
818
|
};
|
|
643
819
|
|
|
644
820
|
// src/tools/ChainManager.ts
|
|
645
|
-
var
|
|
646
|
-
var
|
|
821
|
+
var import_viem6 = require("viem");
|
|
822
|
+
var import_account_abstraction3 = require("viem/account-abstraction");
|
|
823
|
+
var import_pimlico = require("permissionless/clients/pimlico");
|
|
647
824
|
|
|
648
825
|
// src/constants/chains.ts
|
|
649
826
|
var import_chains2 = require("viem/chains");
|
|
@@ -654,7 +831,7 @@ var CHAINS_MAP = {
|
|
|
654
831
|
var SUPPORTED_CHAIN_IDS = Object.values(CHAINS_MAP).map((c) => c.id);
|
|
655
832
|
|
|
656
833
|
// src/utils/chains.ts
|
|
657
|
-
var
|
|
834
|
+
var import_viem5 = require("viem");
|
|
658
835
|
var viemChains = __toESM(require("viem/chains"), 1);
|
|
659
836
|
var chainById = Object.values(viemChains).reduce(
|
|
660
837
|
(acc, maybeChain) => {
|
|
@@ -722,14 +899,14 @@ var ChainManager = class {
|
|
|
722
899
|
if (!bundlerUrl) {
|
|
723
900
|
throw new Error(`No bundler URL configured for chain ID: ${chainId}`);
|
|
724
901
|
}
|
|
725
|
-
const client = (0,
|
|
902
|
+
const client = (0, import_viem6.createPublicClient)({
|
|
726
903
|
chain: this.getChain(chainId),
|
|
727
|
-
transport: (0,
|
|
904
|
+
transport: (0, import_viem6.http)(rpcUrl)
|
|
728
905
|
});
|
|
729
|
-
return (0,
|
|
906
|
+
return (0, import_account_abstraction3.createBundlerClient)({
|
|
730
907
|
account,
|
|
731
908
|
client,
|
|
732
|
-
transport: (0,
|
|
909
|
+
transport: (0, import_viem6.http)(bundlerUrl),
|
|
733
910
|
chain: this.getChain(chainId)
|
|
734
911
|
});
|
|
735
912
|
}
|
|
@@ -807,12 +984,55 @@ var ChainManager = class {
|
|
|
807
984
|
*/
|
|
808
985
|
createPublicClient(chain) {
|
|
809
986
|
const chainObject = chainById[chain.chainId];
|
|
810
|
-
const client = (0,
|
|
987
|
+
const client = (0, import_viem6.createPublicClient)({
|
|
811
988
|
chain: chainObject,
|
|
812
|
-
transport: (0,
|
|
989
|
+
transport: (0, import_viem6.http)(chain.rpcUrl)
|
|
813
990
|
});
|
|
814
991
|
return client;
|
|
815
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Returns the paymaster URL for the given chain ID
|
|
995
|
+
*
|
|
996
|
+
* @internal
|
|
997
|
+
* @category URLs
|
|
998
|
+
* @param chainId Target chain ID
|
|
999
|
+
* @returns Paymaster URL string
|
|
1000
|
+
* @throws Error if chain config is missing or URL is invalid
|
|
1001
|
+
*/
|
|
1002
|
+
getPaymasterUrl(chainId) {
|
|
1003
|
+
const chainConfig = this.chainConfigs;
|
|
1004
|
+
if (!chainConfig) {
|
|
1005
|
+
throw new Error(`No chain config found for chain ID: ${chainId}`);
|
|
1006
|
+
}
|
|
1007
|
+
if (chainConfig.paymasterUrl && !this.isValidUrl(chainConfig.paymasterUrl)) {
|
|
1008
|
+
throw new Error(`Invalid paymaster URL for chain ID: ${chainId}`);
|
|
1009
|
+
}
|
|
1010
|
+
return chainConfig.paymasterUrl || "";
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Creates a {@link PimlicoClient} for the given chain ID
|
|
1014
|
+
*
|
|
1015
|
+
* @internal
|
|
1016
|
+
* @category Clients
|
|
1017
|
+
* @param chainId Target chain ID
|
|
1018
|
+
* @returns PimlicoClient instance
|
|
1019
|
+
* @throws Error if no paymaster URL is configured
|
|
1020
|
+
*/
|
|
1021
|
+
getPaymasterClient(chainId) {
|
|
1022
|
+
const paymasterUrl = this.getPaymasterUrl(chainId);
|
|
1023
|
+
if (!paymasterUrl) {
|
|
1024
|
+
throw new Error(`No paymaster URL configured for chain ID: ${chainId}`);
|
|
1025
|
+
}
|
|
1026
|
+
const chain = this.getChain(chainId);
|
|
1027
|
+
return (0, import_pimlico.createPimlicoClient)({
|
|
1028
|
+
chain,
|
|
1029
|
+
transport: (0, import_viem6.http)(paymasterUrl),
|
|
1030
|
+
entryPoint: {
|
|
1031
|
+
address: import_account_abstraction3.entryPoint07Address,
|
|
1032
|
+
version: "0.7"
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
816
1036
|
};
|
|
817
1037
|
|
|
818
1038
|
// src/wallet/WalletNamespace.ts
|
|
@@ -935,8 +1155,8 @@ var WalletNamespace = class {
|
|
|
935
1155
|
var import_chains7 = require("viem/chains");
|
|
936
1156
|
|
|
937
1157
|
// src/wallet/providers/DefaultSmartWalletProvider.ts
|
|
938
|
-
var
|
|
939
|
-
var
|
|
1158
|
+
var import_viem7 = require("viem");
|
|
1159
|
+
var import_account_abstraction4 = require("viem/account-abstraction");
|
|
940
1160
|
|
|
941
1161
|
// src/wallet/base/providers/SmartWalletProvider.ts
|
|
942
1162
|
var SmartWalletProvider = class {
|
|
@@ -1003,7 +1223,7 @@ var DefaultSmartWalletProvider = class extends SmartWalletProvider {
|
|
|
1003
1223
|
const { owners, nonce = 0n } = params;
|
|
1004
1224
|
const owners_bytes = owners.map((owner) => {
|
|
1005
1225
|
if (typeof owner === "string") {
|
|
1006
|
-
return (0,
|
|
1226
|
+
return (0, import_viem7.pad)(owner);
|
|
1007
1227
|
}
|
|
1008
1228
|
if (owner.type === "webAuthn") {
|
|
1009
1229
|
return owner.publicKey;
|
|
@@ -1238,11 +1458,11 @@ var WalletProvider = class {
|
|
|
1238
1458
|
};
|
|
1239
1459
|
|
|
1240
1460
|
// src/wallet/providers/PrivyEmbeddedWalletProvider.ts
|
|
1241
|
-
var
|
|
1461
|
+
var import_viem10 = require("viem");
|
|
1242
1462
|
|
|
1243
1463
|
// src/wallet/PrivyWallet.ts
|
|
1244
|
-
var
|
|
1245
|
-
var
|
|
1464
|
+
var import_viem8 = require("@privy-io/server-auth/viem");
|
|
1465
|
+
var import_viem9 = require("viem");
|
|
1246
1466
|
var import_chains5 = require("viem/chains");
|
|
1247
1467
|
|
|
1248
1468
|
// src/wallet/base/wallets/EmbeddedWallet.ts
|
|
@@ -1410,7 +1630,7 @@ var PrivyWallet = class extends EmbeddedWallet {
|
|
|
1410
1630
|
* @throws Error if wallet retrieval or account construction fails
|
|
1411
1631
|
*/
|
|
1412
1632
|
async account() {
|
|
1413
|
-
const account = await (0,
|
|
1633
|
+
const account = await (0, import_viem8.createViemAccount)({
|
|
1414
1634
|
walletId: this.walletId,
|
|
1415
1635
|
address: this.address,
|
|
1416
1636
|
privy: this.privyClient
|
|
@@ -1428,10 +1648,10 @@ var PrivyWallet = class extends EmbeddedWallet {
|
|
|
1428
1648
|
*/
|
|
1429
1649
|
async walletClient(chainId) {
|
|
1430
1650
|
const account = await this.account();
|
|
1431
|
-
return (0,
|
|
1651
|
+
return (0, import_viem9.createWalletClient)({
|
|
1432
1652
|
account,
|
|
1433
1653
|
chain: this.chainManager.getChain(chainId),
|
|
1434
|
-
transport: (0,
|
|
1654
|
+
transport: (0, import_viem9.http)(this.chainManager.getRpcUrl(chainId))
|
|
1435
1655
|
});
|
|
1436
1656
|
}
|
|
1437
1657
|
/**
|
|
@@ -1572,7 +1792,7 @@ var PrivyEmbeddedWalletProvider = class extends EmbeddedWalletProvider {
|
|
|
1572
1792
|
const walletInstance = new PrivyWallet(
|
|
1573
1793
|
this.privy,
|
|
1574
1794
|
wallet.id,
|
|
1575
|
-
(0,
|
|
1795
|
+
(0, import_viem10.getAddress)(wallet.address),
|
|
1576
1796
|
this.chainManager
|
|
1577
1797
|
);
|
|
1578
1798
|
return walletInstance;
|
|
@@ -1598,7 +1818,7 @@ var PrivyEmbeddedWalletProvider = class extends EmbeddedWalletProvider {
|
|
|
1598
1818
|
const walletInstance = new PrivyWallet(
|
|
1599
1819
|
this.privy,
|
|
1600
1820
|
wallet.id,
|
|
1601
|
-
(0,
|
|
1821
|
+
(0, import_viem10.getAddress)(wallet.address),
|
|
1602
1822
|
this.chainManager
|
|
1603
1823
|
);
|
|
1604
1824
|
return walletInstance;
|
|
@@ -1625,7 +1845,7 @@ var PrivyEmbeddedWalletProvider = class extends EmbeddedWalletProvider {
|
|
|
1625
1845
|
const walletInstance = new PrivyWallet(
|
|
1626
1846
|
this.privy,
|
|
1627
1847
|
wallet.id,
|
|
1628
|
-
(0,
|
|
1848
|
+
(0, import_viem10.getAddress)(wallet.address),
|
|
1629
1849
|
this.chainManager
|
|
1630
1850
|
);
|
|
1631
1851
|
return walletInstance;
|
|
@@ -1640,7 +1860,7 @@ var PrivyEmbeddedWalletProvider = class extends EmbeddedWalletProvider {
|
|
|
1640
1860
|
var import_server_auth = require("@privy-io/server-auth");
|
|
1641
1861
|
|
|
1642
1862
|
// src/protocols/base/BaseProtocol.ts
|
|
1643
|
-
var
|
|
1863
|
+
var import_viem11 = require("viem");
|
|
1644
1864
|
var BaseProtocol = class {
|
|
1645
1865
|
/**
|
|
1646
1866
|
* Ensure the protocol has been initialized
|
|
@@ -1662,19 +1882,19 @@ var BaseProtocol = class {
|
|
|
1662
1882
|
*/
|
|
1663
1883
|
async approveToken(tokenAddress, spenderAddress, amount, chainId, account) {
|
|
1664
1884
|
this.ensureInitialized();
|
|
1665
|
-
const walletClient = (0,
|
|
1885
|
+
const walletClient = (0, import_viem11.createWalletClient)({
|
|
1666
1886
|
account,
|
|
1667
1887
|
chain: this.chainManager.getChain(chainId),
|
|
1668
|
-
transport: (0,
|
|
1888
|
+
transport: (0, import_viem11.http)(this.chainManager.getRpcUrl(chainId))
|
|
1669
1889
|
});
|
|
1670
1890
|
const hash = await walletClient.writeContract({
|
|
1671
1891
|
address: tokenAddress,
|
|
1672
|
-
abi:
|
|
1892
|
+
abi: import_viem11.erc20Abi,
|
|
1673
1893
|
functionName: "approve",
|
|
1674
1894
|
args: [spenderAddress, amount],
|
|
1675
1895
|
gas: 100000n,
|
|
1676
|
-
maxFeePerGas: (0,
|
|
1677
|
-
maxPriorityFeePerGas: (0,
|
|
1896
|
+
maxFeePerGas: (0, import_viem11.parseGwei)("20"),
|
|
1897
|
+
maxPriorityFeePerGas: (0, import_viem11.parseGwei)("2")
|
|
1678
1898
|
});
|
|
1679
1899
|
return hash;
|
|
1680
1900
|
}
|
|
@@ -1691,7 +1911,7 @@ var BaseProtocol = class {
|
|
|
1691
1911
|
const publicClient = this.chainManager.getPublicClient(chainId);
|
|
1692
1912
|
return await publicClient.readContract({
|
|
1693
1913
|
address: tokenAddress,
|
|
1694
|
-
abi:
|
|
1914
|
+
abi: import_viem11.erc20Abi,
|
|
1695
1915
|
functionName: "allowance",
|
|
1696
1916
|
args: [walletAddress, spenderAddress]
|
|
1697
1917
|
});
|
|
@@ -1699,7 +1919,7 @@ var BaseProtocol = class {
|
|
|
1699
1919
|
};
|
|
1700
1920
|
|
|
1701
1921
|
// src/protocols/implementations/SparkProtocol.ts
|
|
1702
|
-
var
|
|
1922
|
+
var import_viem12 = require("viem");
|
|
1703
1923
|
|
|
1704
1924
|
// src/abis/protocols/spark.ts
|
|
1705
1925
|
var SPARK_VAULT_ABI = [
|
|
@@ -1848,7 +2068,7 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1848
2068
|
*/
|
|
1849
2069
|
async deposit(vaultInfo, amount, smartWallet) {
|
|
1850
2070
|
const owner = await smartWallet.getAddress();
|
|
1851
|
-
const assets = (0,
|
|
2071
|
+
const assets = (0, import_viem12.parseUnits)(amount, vaultInfo.tokenDecimals);
|
|
1852
2072
|
const allowance = await this.checkAllowance(
|
|
1853
2073
|
vaultInfo.tokenAddress,
|
|
1854
2074
|
vaultInfo.vaultAddress,
|
|
@@ -1859,8 +2079,8 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1859
2079
|
if (allowance < assets) {
|
|
1860
2080
|
ops.push({
|
|
1861
2081
|
to: vaultInfo.tokenAddress,
|
|
1862
|
-
data: (0,
|
|
1863
|
-
abi:
|
|
2082
|
+
data: (0, import_viem12.encodeFunctionData)({
|
|
2083
|
+
abi: import_viem12.erc20Abi,
|
|
1864
2084
|
functionName: "approve",
|
|
1865
2085
|
args: [vaultInfo.vaultAddress, assets]
|
|
1866
2086
|
})
|
|
@@ -1868,7 +2088,7 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1868
2088
|
}
|
|
1869
2089
|
ops.push({
|
|
1870
2090
|
to: vaultInfo.vaultAddress,
|
|
1871
|
-
data: (0,
|
|
2091
|
+
data: (0, import_viem12.encodeFunctionData)({
|
|
1872
2092
|
abi: SPARK_VAULT_ABI,
|
|
1873
2093
|
functionName: "deposit",
|
|
1874
2094
|
args: [assets, owner]
|
|
@@ -1889,10 +2109,10 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1889
2109
|
const owner = await smartWallet.getAddress();
|
|
1890
2110
|
let withdrawData;
|
|
1891
2111
|
if (amount) {
|
|
1892
|
-
const assets = (0,
|
|
2112
|
+
const assets = (0, import_viem12.parseUnits)(amount, vaultInfo.tokenDecimals);
|
|
1893
2113
|
withdrawData = {
|
|
1894
2114
|
to: vaultInfo.vaultAddress,
|
|
1895
|
-
data: (0,
|
|
2115
|
+
data: (0, import_viem12.encodeFunctionData)({
|
|
1896
2116
|
abi: SPARK_VAULT_ABI,
|
|
1897
2117
|
functionName: "withdraw",
|
|
1898
2118
|
args: [assets, owner, owner]
|
|
@@ -1902,7 +2122,7 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1902
2122
|
const maxShares = await this.getMaxRedeemableShares(vaultInfo, owner);
|
|
1903
2123
|
withdrawData = {
|
|
1904
2124
|
to: vaultInfo.vaultAddress,
|
|
1905
|
-
data: (0,
|
|
2125
|
+
data: (0, import_viem12.encodeFunctionData)({
|
|
1906
2126
|
abi: SPARK_VAULT_ABI,
|
|
1907
2127
|
functionName: "redeem",
|
|
1908
2128
|
args: [maxShares, owner, owner]
|
|
@@ -1958,7 +2178,7 @@ var SparkProtocol = class extends BaseProtocol {
|
|
|
1958
2178
|
});
|
|
1959
2179
|
return [
|
|
1960
2180
|
{
|
|
1961
|
-
balance: (0,
|
|
2181
|
+
balance: (0, import_viem12.formatUnits)(assets, vaultInfo.tokenDecimals),
|
|
1962
2182
|
vaultInfo
|
|
1963
2183
|
}
|
|
1964
2184
|
];
|
|
@@ -1973,7 +2193,7 @@ var availableProtocols = [
|
|
|
1973
2193
|
name: "Spark",
|
|
1974
2194
|
website: "https://spark.fi/",
|
|
1975
2195
|
logo: "/logos/spark.png",
|
|
1976
|
-
supportedChains: [8453],
|
|
2196
|
+
supportedChains: [8453, 84532],
|
|
1977
2197
|
riskLevel: "low",
|
|
1978
2198
|
isActive: true
|
|
1979
2199
|
},
|
|
@@ -1982,7 +2202,7 @@ var availableProtocols = [
|
|
|
1982
2202
|
];
|
|
1983
2203
|
|
|
1984
2204
|
// src/protocols/implementations/ProxyProtocol.ts
|
|
1985
|
-
var
|
|
2205
|
+
var import_viem13 = require("viem");
|
|
1986
2206
|
var ProxyProtocol = class extends BaseProtocol {
|
|
1987
2207
|
/**
|
|
1988
2208
|
* Initialize the Spark protocol with the provided chain manager
|
|
@@ -2074,7 +2294,7 @@ var ProxyProtocol = class extends BaseProtocol {
|
|
|
2074
2294
|
const depositTokenDecimals = vaultInfo.tokenDecimals;
|
|
2075
2295
|
const depositTokenAddress = vaultInfo.tokenAddress;
|
|
2076
2296
|
const vaultAddress = vaultInfo.vaultAddress;
|
|
2077
|
-
const rawDepositAmount = (0,
|
|
2297
|
+
const rawDepositAmount = (0, import_viem13.parseUnits)(amount, depositTokenDecimals);
|
|
2078
2298
|
const allowance = await this.checkAllowance(
|
|
2079
2299
|
depositTokenAddress,
|
|
2080
2300
|
vaultAddress,
|
|
@@ -2084,8 +2304,8 @@ var ProxyProtocol = class extends BaseProtocol {
|
|
|
2084
2304
|
if (allowance < rawDepositAmount) {
|
|
2085
2305
|
const approveData = {
|
|
2086
2306
|
to: depositTokenAddress,
|
|
2087
|
-
data: (0,
|
|
2088
|
-
abi:
|
|
2307
|
+
data: (0, import_viem13.encodeFunctionData)({
|
|
2308
|
+
abi: import_viem13.erc20Abi,
|
|
2089
2309
|
functionName: "approve",
|
|
2090
2310
|
args: [vaultAddress, rawDepositAmount]
|
|
2091
2311
|
})
|
|
@@ -2483,7 +2703,7 @@ var ProtocolsNamespace = class {
|
|
|
2483
2703
|
};
|
|
2484
2704
|
|
|
2485
2705
|
// src/constants/general.ts
|
|
2486
|
-
var BACKEND_HOSTNAME = process.env.NODE_ENV === "dev" ? "http://localhost:3000" : "https://mycelium
|
|
2706
|
+
var BACKEND_HOSTNAME = process.env.NODE_ENV === "dev" ? "http://localhost:3000" : "https://staging.mycelium.sh";
|
|
2487
2707
|
|
|
2488
2708
|
// src/tools/ApiClient.ts
|
|
2489
2709
|
var import_axios2 = __toESM(require("axios"), 1);
|
|
@@ -2713,7 +2933,8 @@ var MyceliumSDK = class _MyceliumSDK {
|
|
|
2713
2933
|
chain: {
|
|
2714
2934
|
chainId: config.chainId || backendConfig.chainId,
|
|
2715
2935
|
rpcUrl: backendConfig.rpcUrl,
|
|
2716
|
-
bundlerUrl: backendConfig.bundlerUrl
|
|
2936
|
+
bundlerUrl: backendConfig.bundlerUrl,
|
|
2937
|
+
paymasterUrl: backendConfig.paymasterUrl
|
|
2717
2938
|
},
|
|
2718
2939
|
protocolsSecurityConfig: config.protocolsSecurityConfig,
|
|
2719
2940
|
coinbaseCDPConfig: {
|