@dynamic-labs-wallet/node-evm 1.0.50 → 1.0.52
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/index.cjs +480 -6
- package/index.esm.js +468 -8
- package/package.json +3 -3
- package/src/client/client.d.ts +48 -1
- package/src/client/client.d.ts.map +1 -1
- package/src/client/gasless.client.d.ts +35 -0
- package/src/client/gasless.client.d.ts.map +1 -0
- package/src/client/gasless.constants.d.ts +63 -0
- package/src/client/gasless.constants.d.ts.map +1 -0
- package/src/client/gasless.types.d.ts +153 -0
- package/src/client/gasless.types.d.ts.map +1 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var node = require('@dynamic-labs-wallet/node');
|
|
|
5
5
|
var viem = require('viem');
|
|
6
6
|
var utils = require('viem/utils');
|
|
7
7
|
var chains = require('viem/chains');
|
|
8
|
+
var node_crypto = require('node:crypto');
|
|
8
9
|
var client = require('@dynamic-labs-sdk/client');
|
|
9
10
|
var core = require('@dynamic-labs-sdk/client/core');
|
|
10
11
|
var viem$1 = require('@dynamic-labs-sdk/evm/viem');
|
|
@@ -95,7 +96,7 @@ const deriveAccountAddress = ({ rawPublicKey })=>{
|
|
|
95
96
|
};
|
|
96
97
|
};
|
|
97
98
|
|
|
98
|
-
const logError$
|
|
99
|
+
const logError$2 = node.createLogError('node-evm');
|
|
99
100
|
/**
|
|
100
101
|
* Creates a delegated EVM wallet client for functional operations
|
|
101
102
|
*/ const createDelegatedEvmWalletClient = ({ environmentId, baseApiUrl, baseMPCRelayApiUrl, apiKey, debug = false })=>{
|
|
@@ -134,7 +135,7 @@ const logError$1 = node.createLogError('node-evm');
|
|
|
134
135
|
});
|
|
135
136
|
return serializeECDSASignature(signatureEcdsa);
|
|
136
137
|
} catch (error) {
|
|
137
|
-
logError$
|
|
138
|
+
logError$2({
|
|
138
139
|
message: 'Error in delegatedSignMessage',
|
|
139
140
|
error: error,
|
|
140
141
|
context: {
|
|
@@ -180,7 +181,7 @@ const logError$1 = node.createLogError('node-evm');
|
|
|
180
181
|
});
|
|
181
182
|
return viem.serializeTransaction(signedTx);
|
|
182
183
|
} catch (error) {
|
|
183
|
-
logError$
|
|
184
|
+
logError$2({
|
|
184
185
|
message: 'Error in delegatedSignTransaction',
|
|
185
186
|
error: error,
|
|
186
187
|
context: {
|
|
@@ -213,7 +214,7 @@ const logError$1 = node.createLogError('node-evm');
|
|
|
213
214
|
});
|
|
214
215
|
return serializeECDSASignature(signatureEcdsa);
|
|
215
216
|
} catch (error) {
|
|
216
|
-
logError$
|
|
217
|
+
logError$2({
|
|
217
218
|
message: 'Error in delegatedSignTypedData',
|
|
218
219
|
error: error,
|
|
219
220
|
context: {
|
|
@@ -248,7 +249,7 @@ const logError$1 = node.createLogError('node-evm');
|
|
|
248
249
|
const serializedSignature = serializeECDSASignature(signatureEcdsa);
|
|
249
250
|
return viem.parseSignature(serializedSignature);
|
|
250
251
|
} catch (error) {
|
|
251
|
-
logError$
|
|
252
|
+
logError$2({
|
|
252
253
|
message: 'Error in delegatedSignAuthorization',
|
|
253
254
|
error: error,
|
|
254
255
|
context: {
|
|
@@ -281,7 +282,7 @@ const logError$1 = node.createLogError('node-evm');
|
|
|
281
282
|
});
|
|
282
283
|
return serializeECDSASignature(signatureEcdsa);
|
|
283
284
|
} catch (error) {
|
|
284
|
-
logError$
|
|
285
|
+
logError$2({
|
|
285
286
|
message: 'Error in delegatedSignRawMessage',
|
|
286
287
|
error: error,
|
|
287
288
|
context: {
|
|
@@ -397,6 +398,409 @@ const createAccountAdapter = ({ evmClient, walletMetadata, password, externalSer
|
|
|
397
398
|
});
|
|
398
399
|
};
|
|
399
400
|
|
|
401
|
+
/** The Fireblocks Universal Gasless Delegate (UGD) contract address used for EIP-7702 delegation. */ const DELEGATION_CONTRACT_ADDRESS = '0x0000Fb7702036ff9f76044a501ac1aA74cbab16b';
|
|
402
|
+
/** Default sponsored transaction validity duration in seconds (10 minutes). */ const DEFAULT_VALID_FOR_SECONDS = 600;
|
|
403
|
+
/** EIP-7702 delegation code prefix used to identify delegated accounts. */ const DELEGATION_CODE_PREFIX = '0xef0100';
|
|
404
|
+
/** ERC-7579 batch call with opData and auth mode identifier. */ const BATCH_CALL_OPDATA_AUTH_MODE = '0x0100000000007821000100000000000000000000000000000000000000000000';
|
|
405
|
+
/** EIP-712 typed data types for UGD AuthorizedExecutions signing. */ const AUTHORIZED_EXECUTIONS_TYPES = {
|
|
406
|
+
AuthorizedExecutions: [
|
|
407
|
+
{
|
|
408
|
+
name: 'calls',
|
|
409
|
+
type: 'Execution[]'
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: 'deadline',
|
|
413
|
+
type: 'uint256'
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
name: 'mode',
|
|
417
|
+
type: 'bytes32'
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
name: 'nonce',
|
|
421
|
+
type: 'uint256'
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
name: 'relayer',
|
|
425
|
+
type: 'address'
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
Execution: [
|
|
429
|
+
{
|
|
430
|
+
name: 'target',
|
|
431
|
+
type: 'address'
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
name: 'value',
|
|
435
|
+
type: 'uint256'
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
name: 'data',
|
|
439
|
+
type: 'bytes'
|
|
440
|
+
}
|
|
441
|
+
]
|
|
442
|
+
};
|
|
443
|
+
/** Minimal ABI for the UGD contract's nonce validation function. */ const UGD_ABI = [
|
|
444
|
+
{
|
|
445
|
+
inputs: [
|
|
446
|
+
{
|
|
447
|
+
name: 'nonce',
|
|
448
|
+
type: 'uint256'
|
|
449
|
+
}
|
|
450
|
+
],
|
|
451
|
+
name: 'isNonceUsed',
|
|
452
|
+
outputs: [
|
|
453
|
+
{
|
|
454
|
+
name: '',
|
|
455
|
+
type: 'bool'
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
stateMutability: 'view',
|
|
459
|
+
type: 'function'
|
|
460
|
+
}
|
|
461
|
+
];
|
|
462
|
+
/** Default polling interval for sponsored transaction status checks (milliseconds). */ const EVM_GASLESS_DEFAULT_POLL_INTERVAL_MS = 2000;
|
|
463
|
+
/** Default timeout for sponsored transaction polling (milliseconds). */ const EVM_GASLESS_DEFAULT_TIMEOUT_MS = 60000;
|
|
464
|
+
// Error messages
|
|
465
|
+
const ERROR_GASLESS_RPC_REQUIRED_FOR_AUTO_DELEGATE = 'rpcUrl is required when autoDelegate is true and no explicit authorization is provided. ' + 'Pass rpcUrl, pass an explicit authorization, or set autoDelegate: false.';
|
|
466
|
+
const ERROR_GASLESS_RELAY_FAILED = 'EVM sponsored transaction relay failed';
|
|
467
|
+
const ERROR_GASLESS_TIMEOUT = 'EVM sponsored transaction timed out waiting for terminal status';
|
|
468
|
+
const ERROR_GASLESS_MISSING_REQUEST_ID = 'Relay response did not include a requestId';
|
|
469
|
+
const ERROR_GASLESS_MISSING_YPARITY = 'Signed authorization is missing yParity';
|
|
470
|
+
const ERROR_GASLESS_RPC_REQUIRED = 'rpcUrl is required for this operation';
|
|
471
|
+
|
|
472
|
+
const logError$1 = node.createLogError('node-evm');
|
|
473
|
+
/**
|
|
474
|
+
* Builds a stateless gasless client for EVM sponsored transactions (Fireblocks-relayer
|
|
475
|
+
* native gasless via EIP-7702 / AuthorizedExecutions). It holds no wallet state — the
|
|
476
|
+
* signing primitives and API client are injected by the owning `DynamicEvmWalletClient`.
|
|
477
|
+
*/ const createEvmGaslessClient = ({ apiClient, createViemPublicClient, signAuthorization, signTypedData })=>{
|
|
478
|
+
const viemPublicClientForChain = (chainId, rpcUrl)=>{
|
|
479
|
+
if (!rpcUrl) {
|
|
480
|
+
throw new Error(ERROR_GASLESS_RPC_REQUIRED);
|
|
481
|
+
}
|
|
482
|
+
const chain = viem.defineChain({
|
|
483
|
+
id: chainId,
|
|
484
|
+
name: `Chain ${chainId}`,
|
|
485
|
+
nativeCurrency: {
|
|
486
|
+
name: 'Ether',
|
|
487
|
+
symbol: 'ETH',
|
|
488
|
+
decimals: 18
|
|
489
|
+
},
|
|
490
|
+
rpcUrls: {
|
|
491
|
+
default: {
|
|
492
|
+
http: [
|
|
493
|
+
rpcUrl
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
return createViemPublicClient({
|
|
499
|
+
chain,
|
|
500
|
+
rpcUrl
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
const generateRandomNonce = ()=>BigInt('0x' + node_crypto.randomBytes(32).toString('hex'));
|
|
504
|
+
const generateIntentNonce = async ({ walletAddress, chainId, rpcUrl })=>{
|
|
505
|
+
let nonce = generateRandomNonce();
|
|
506
|
+
if (rpcUrl) {
|
|
507
|
+
try {
|
|
508
|
+
const publicClient = viemPublicClientForChain(chainId, rpcUrl);
|
|
509
|
+
// On a brand-new (undelegated) wallet the address has no UGD code yet,
|
|
510
|
+
// so isNonceUsed reverts — the random value is safe regardless.
|
|
511
|
+
const isUsed = await publicClient.readContract({
|
|
512
|
+
address: walletAddress,
|
|
513
|
+
abi: UGD_ABI,
|
|
514
|
+
functionName: 'isNonceUsed',
|
|
515
|
+
args: [
|
|
516
|
+
nonce
|
|
517
|
+
]
|
|
518
|
+
});
|
|
519
|
+
if (isUsed) {
|
|
520
|
+
nonce = generateRandomNonce();
|
|
521
|
+
}
|
|
522
|
+
} catch (e) {
|
|
523
|
+
// RPC failure is tolerable — 256-bit random collision is negligible
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return nonce;
|
|
527
|
+
};
|
|
528
|
+
const is7702DelegationActive = async ({ walletAddress, chainId, rpcUrl })=>{
|
|
529
|
+
const publicClient = viemPublicClientForChain(chainId, rpcUrl);
|
|
530
|
+
const code = await publicClient.getCode({
|
|
531
|
+
address: walletAddress
|
|
532
|
+
});
|
|
533
|
+
if (!code) return false;
|
|
534
|
+
const expectedPrefix = DELEGATION_CODE_PREFIX + DELEGATION_CONTRACT_ADDRESS.slice(2).toLowerCase();
|
|
535
|
+
return code.toLowerCase().startsWith(expectedPrefix);
|
|
536
|
+
};
|
|
537
|
+
const sign7702Authorization = async ({ walletMetadata, chainId, rpcUrl, nonce, password, externalServerKeyShares })=>{
|
|
538
|
+
const address = walletMetadata.accountAddress;
|
|
539
|
+
try {
|
|
540
|
+
let eoaNonce;
|
|
541
|
+
if (nonce === undefined) {
|
|
542
|
+
if (!rpcUrl) {
|
|
543
|
+
throw new Error(ERROR_GASLESS_RPC_REQUIRED);
|
|
544
|
+
}
|
|
545
|
+
const publicClient = viemPublicClientForChain(chainId, rpcUrl);
|
|
546
|
+
eoaNonce = Number(await publicClient.getTransactionCount({
|
|
547
|
+
address
|
|
548
|
+
}));
|
|
549
|
+
} else {
|
|
550
|
+
eoaNonce = nonce;
|
|
551
|
+
}
|
|
552
|
+
const authorization = {
|
|
553
|
+
address: DELEGATION_CONTRACT_ADDRESS,
|
|
554
|
+
chainId,
|
|
555
|
+
nonce: eoaNonce
|
|
556
|
+
};
|
|
557
|
+
const sig = await signAuthorization({
|
|
558
|
+
authorization,
|
|
559
|
+
walletMetadata,
|
|
560
|
+
password,
|
|
561
|
+
externalServerKeyShares
|
|
562
|
+
});
|
|
563
|
+
if (sig.yParity === undefined) {
|
|
564
|
+
throw new Error(ERROR_GASLESS_MISSING_YPARITY);
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
address: DELEGATION_CONTRACT_ADDRESS,
|
|
568
|
+
chainId,
|
|
569
|
+
nonce: eoaNonce,
|
|
570
|
+
r: sig.r,
|
|
571
|
+
s: sig.s,
|
|
572
|
+
yParity: sig.yParity
|
|
573
|
+
};
|
|
574
|
+
} catch (error) {
|
|
575
|
+
logError$1({
|
|
576
|
+
message: 'Error signing 7702 authorization',
|
|
577
|
+
error: error,
|
|
578
|
+
context: {
|
|
579
|
+
accountAddress: address,
|
|
580
|
+
chainId
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
throw error;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
const getAvailableEvmGaslessRelayer = async ({ chainId, traceContext })=>{
|
|
587
|
+
const result = await apiClient.getAvailableEVMGaslessRelayer({
|
|
588
|
+
chainId,
|
|
589
|
+
traceContext
|
|
590
|
+
});
|
|
591
|
+
return {
|
|
592
|
+
relayerAddress: result.relayerAddress
|
|
593
|
+
};
|
|
594
|
+
};
|
|
595
|
+
const resolveSponsoredAuthorization = async ({ authorization, autoDelegate, walletMetadata, chainId, rpcUrl, password, externalServerKeyShares })=>{
|
|
596
|
+
if (authorization) {
|
|
597
|
+
return authorization;
|
|
598
|
+
}
|
|
599
|
+
if (!autoDelegate) {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
// The EOA nonce and delegation status are only knowable on-chain; without
|
|
603
|
+
// an RPC we can't safely auto-sign a 7702 authorization, so fail loud
|
|
604
|
+
// instead of relaying an intent that would revert.
|
|
605
|
+
if (!rpcUrl) {
|
|
606
|
+
throw new Error(ERROR_GASLESS_RPC_REQUIRED_FOR_AUTO_DELEGATE);
|
|
607
|
+
}
|
|
608
|
+
const walletAddress = walletMetadata.accountAddress;
|
|
609
|
+
const isDelegated = await is7702DelegationActive({
|
|
610
|
+
walletAddress,
|
|
611
|
+
chainId,
|
|
612
|
+
rpcUrl
|
|
613
|
+
});
|
|
614
|
+
if (isDelegated) {
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
return sign7702Authorization({
|
|
618
|
+
walletMetadata,
|
|
619
|
+
chainId,
|
|
620
|
+
rpcUrl,
|
|
621
|
+
password,
|
|
622
|
+
externalServerKeyShares
|
|
623
|
+
});
|
|
624
|
+
};
|
|
625
|
+
const signSponsoredTransaction = async ({ walletMetadata, calls, chainId, rpcUrl, authorization, autoDelegate = true, nonce: providedNonce, validForSeconds = DEFAULT_VALID_FOR_SECONDS, password, externalServerKeyShares, traceContext })=>{
|
|
626
|
+
const walletAddress = walletMetadata.accountAddress;
|
|
627
|
+
try {
|
|
628
|
+
const resolvedAuth = await resolveSponsoredAuthorization({
|
|
629
|
+
authorization,
|
|
630
|
+
autoDelegate,
|
|
631
|
+
walletMetadata,
|
|
632
|
+
chainId,
|
|
633
|
+
rpcUrl,
|
|
634
|
+
password,
|
|
635
|
+
externalServerKeyShares
|
|
636
|
+
});
|
|
637
|
+
const nonce = providedNonce != null ? providedNonce : await generateIntentNonce({
|
|
638
|
+
walletAddress,
|
|
639
|
+
chainId,
|
|
640
|
+
rpcUrl
|
|
641
|
+
});
|
|
642
|
+
const deadline = BigInt(Math.floor(Date.now() / 1000) + validForSeconds);
|
|
643
|
+
const { relayerAddress } = await getAvailableEvmGaslessRelayer({
|
|
644
|
+
chainId,
|
|
645
|
+
traceContext
|
|
646
|
+
});
|
|
647
|
+
const signature = await signTypedData({
|
|
648
|
+
walletMetadata,
|
|
649
|
+
password,
|
|
650
|
+
externalServerKeyShares,
|
|
651
|
+
typedData: {
|
|
652
|
+
domain: {
|
|
653
|
+
chainId,
|
|
654
|
+
verifyingContract: DELEGATION_CONTRACT_ADDRESS
|
|
655
|
+
},
|
|
656
|
+
message: {
|
|
657
|
+
calls: calls.map((c)=>({
|
|
658
|
+
data: c.data,
|
|
659
|
+
target: c.target,
|
|
660
|
+
value: c.value
|
|
661
|
+
})),
|
|
662
|
+
deadline,
|
|
663
|
+
mode: BATCH_CALL_OPDATA_AUTH_MODE,
|
|
664
|
+
nonce,
|
|
665
|
+
relayer: relayerAddress
|
|
666
|
+
},
|
|
667
|
+
primaryType: 'AuthorizedExecutions',
|
|
668
|
+
types: AUTHORIZED_EXECUTIONS_TYPES
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
return {
|
|
672
|
+
authorization: resolvedAuth,
|
|
673
|
+
calls,
|
|
674
|
+
chainId,
|
|
675
|
+
deadline: deadline.toString(),
|
|
676
|
+
nonce: nonce.toString(),
|
|
677
|
+
relayer: relayerAddress,
|
|
678
|
+
signature,
|
|
679
|
+
walletAddress
|
|
680
|
+
};
|
|
681
|
+
} catch (error) {
|
|
682
|
+
logError$1({
|
|
683
|
+
message: 'Error signing sponsored transaction',
|
|
684
|
+
error: error,
|
|
685
|
+
context: {
|
|
686
|
+
accountAddress: walletAddress,
|
|
687
|
+
chainId
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
throw error;
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
const getEVMSponsoredTransactionStatus = async ({ requestId, traceContext })=>{
|
|
694
|
+
const result = await apiClient.getEVMSponsoredTransactionStatus({
|
|
695
|
+
requestId,
|
|
696
|
+
traceContext
|
|
697
|
+
});
|
|
698
|
+
return result;
|
|
699
|
+
};
|
|
700
|
+
const isSignedTransactionParams = (params)=>'signedTransaction' in params;
|
|
701
|
+
const relaySponsoredTransaction = async (params)=>{
|
|
702
|
+
try {
|
|
703
|
+
const signed = isSignedTransactionParams(params) ? params.signedTransaction : await signSponsoredTransaction(params);
|
|
704
|
+
const { requestId } = await apiClient.sponsorEVMTransaction({
|
|
705
|
+
traceContext: params.traceContext,
|
|
706
|
+
request: _extends({
|
|
707
|
+
authorization: signed.authorization,
|
|
708
|
+
calls: signed.calls.map((c)=>({
|
|
709
|
+
data: c.data,
|
|
710
|
+
target: c.target,
|
|
711
|
+
value: c.value.toString()
|
|
712
|
+
})),
|
|
713
|
+
chainId: signed.chainId,
|
|
714
|
+
deadline: signed.deadline,
|
|
715
|
+
nonce: signed.nonce,
|
|
716
|
+
relayer: signed.relayer,
|
|
717
|
+
signature: signed.signature,
|
|
718
|
+
walletAddress: signed.walletAddress
|
|
719
|
+
}, params.userId ? {
|
|
720
|
+
userId: params.userId
|
|
721
|
+
} : {})
|
|
722
|
+
});
|
|
723
|
+
if (!requestId) {
|
|
724
|
+
throw new Error(ERROR_GASLESS_MISSING_REQUEST_ID);
|
|
725
|
+
}
|
|
726
|
+
return {
|
|
727
|
+
requestId
|
|
728
|
+
};
|
|
729
|
+
} catch (error) {
|
|
730
|
+
const { accountAddress, chainId } = isSignedTransactionParams(params) ? {
|
|
731
|
+
accountAddress: params.signedTransaction.walletAddress,
|
|
732
|
+
chainId: params.signedTransaction.chainId
|
|
733
|
+
} : {
|
|
734
|
+
accountAddress: params.walletMetadata.accountAddress,
|
|
735
|
+
chainId: params.chainId
|
|
736
|
+
};
|
|
737
|
+
logError$1({
|
|
738
|
+
message: 'Error relaying sponsored transaction',
|
|
739
|
+
error: error,
|
|
740
|
+
context: {
|
|
741
|
+
accountAddress,
|
|
742
|
+
chainId,
|
|
743
|
+
userId: params.userId
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
const waitForSponsoredTransaction = async ({ requestId, pollInterval = EVM_GASLESS_DEFAULT_POLL_INTERVAL_MS, timeout = EVM_GASLESS_DEFAULT_TIMEOUT_MS, traceContext })=>{
|
|
750
|
+
try {
|
|
751
|
+
// A zero or negative pollInterval makes attempts Infinity and turns this into a
|
|
752
|
+
// tight loop hammering the status API, so clamp it to a sane minimum.
|
|
753
|
+
const effectivePoll = Math.max(1, pollInterval);
|
|
754
|
+
const attempts = Math.max(1, Math.floor(timeout / effectivePoll));
|
|
755
|
+
for(let i = 0; i < attempts; i++){
|
|
756
|
+
const r = await getEVMSponsoredTransactionStatus({
|
|
757
|
+
requestId,
|
|
758
|
+
traceContext
|
|
759
|
+
});
|
|
760
|
+
if (r.status === 'failure') {
|
|
761
|
+
var _r_errorMessage;
|
|
762
|
+
throw new Error(`${ERROR_GASLESS_RELAY_FAILED}: ${(_r_errorMessage = r.errorMessage) != null ? _r_errorMessage : 'unknown'}`);
|
|
763
|
+
}
|
|
764
|
+
if (r.transactionHash) {
|
|
765
|
+
return {
|
|
766
|
+
transactionHash: r.transactionHash
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
if (i < attempts - 1) {
|
|
770
|
+
await new Promise((resolve)=>setTimeout(resolve, effectivePoll));
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
throw new Error(`${ERROR_GASLESS_TIMEOUT}: ${requestId}`);
|
|
774
|
+
} catch (error) {
|
|
775
|
+
logError$1({
|
|
776
|
+
message: 'Error waiting for sponsored transaction',
|
|
777
|
+
error: error,
|
|
778
|
+
context: {
|
|
779
|
+
requestId
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
throw error;
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
const sendSponsoredTransaction = async (params)=>{
|
|
786
|
+
const { requestId } = await relaySponsoredTransaction(params);
|
|
787
|
+
return waitForSponsoredTransaction({
|
|
788
|
+
requestId,
|
|
789
|
+
traceContext: params.traceContext
|
|
790
|
+
});
|
|
791
|
+
};
|
|
792
|
+
return {
|
|
793
|
+
getAvailableEvmGaslessRelayer,
|
|
794
|
+
getEVMSponsoredTransactionStatus,
|
|
795
|
+
is7702DelegationActive,
|
|
796
|
+
relaySponsoredTransaction,
|
|
797
|
+
sendSponsoredTransaction,
|
|
798
|
+
sign7702Authorization,
|
|
799
|
+
signSponsoredTransaction,
|
|
800
|
+
waitForSponsoredTransaction
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
|
|
400
804
|
const logError = node.createLogError('node-evm');
|
|
401
805
|
class DynamicEvmWalletClient extends node.DynamicWalletClient {
|
|
402
806
|
get jwtAuthToken() {
|
|
@@ -829,6 +1233,62 @@ class DynamicEvmWalletClient extends node.DynamicWalletClient {
|
|
|
829
1233
|
const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'EVM');
|
|
830
1234
|
return evmWallets;
|
|
831
1235
|
}
|
|
1236
|
+
// ---------------------------------------------------------------------------
|
|
1237
|
+
// EVM gasless (Fireblocks-relayer native gasless via EIP-7702 / AuthorizedExecutions)
|
|
1238
|
+
// ---------------------------------------------------------------------------
|
|
1239
|
+
get evmGasless() {
|
|
1240
|
+
return createEvmGaslessClient({
|
|
1241
|
+
apiClient: this.apiClient,
|
|
1242
|
+
createViemPublicClient: (args)=>this.createViemPublicClient(args),
|
|
1243
|
+
signAuthorization: (args)=>this.signAuthorization(args),
|
|
1244
|
+
signTypedData: (args)=>this.signTypedData(args)
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Checks whether the given wallet address has an active EIP-7702 delegation
|
|
1249
|
+
* to the Universal Gasless Delegate (UGD) contract.
|
|
1250
|
+
*/ async is7702DelegationActive(params) {
|
|
1251
|
+
return this.evmGasless.is7702DelegationActive(params);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Signs an EIP-7702 authorization that delegates the EOA to the UGD contract.
|
|
1255
|
+
* The EOA nonce is fetched from the chain unless explicitly provided.
|
|
1256
|
+
*/ async sign7702Authorization(params) {
|
|
1257
|
+
return this.evmGasless.sign7702Authorization(params);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Fetches the available gasless relayer address for a given chain.
|
|
1261
|
+
*/ async getAvailableEvmGaslessRelayer(params) {
|
|
1262
|
+
return this.evmGasless.getAvailableEvmGaslessRelayer(params);
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Signs a sponsored transaction intent: resolves 7702 authorization, generates
|
|
1266
|
+
* a bitmap nonce, fetches the relayer, and MPC-signs the EIP-712 typed data.
|
|
1267
|
+
*/ async signSponsoredTransaction(params) {
|
|
1268
|
+
return this.evmGasless.signSponsoredTransaction(params);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Returns the current status of an EVM sponsored transaction relay request.
|
|
1272
|
+
*/ async getEVMSponsoredTransactionStatus(params) {
|
|
1273
|
+
return this.evmGasless.getEVMSponsoredTransactionStatus(params);
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Relays a sponsored transaction to the Dynamic API.
|
|
1277
|
+
* Accepts either a pre-signed transaction or parameters to sign first.
|
|
1278
|
+
*/ async relaySponsoredTransaction(params) {
|
|
1279
|
+
return this.evmGasless.relaySponsoredTransaction(params);
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Relay then poll to completion. Fixed 60s/2s default (matches js-sdk).
|
|
1283
|
+
* For a custom timeout, use relaySponsoredTransaction + waitForSponsoredTransaction.
|
|
1284
|
+
*/ async sendSponsoredTransaction(params) {
|
|
1285
|
+
return this.evmGasless.sendSponsoredTransaction(params);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Polls the relay status until a terminal state (success or failure) is reached.
|
|
1289
|
+
*/ async waitForSponsoredTransaction(params) {
|
|
1290
|
+
return this.evmGasless.waitForSponsoredTransaction(params);
|
|
1291
|
+
}
|
|
832
1292
|
constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, debug, enableMPCAccelerator, logger }){
|
|
833
1293
|
super({
|
|
834
1294
|
environmentId,
|
|
@@ -1024,15 +1484,29 @@ const createZerodevClient = async (evmClient)=>{
|
|
|
1024
1484
|
return client;
|
|
1025
1485
|
};
|
|
1026
1486
|
|
|
1487
|
+
exports.AUTHORIZED_EXECUTIONS_TYPES = AUTHORIZED_EXECUTIONS_TYPES;
|
|
1488
|
+
exports.BATCH_CALL_OPDATA_AUTH_MODE = BATCH_CALL_OPDATA_AUTH_MODE;
|
|
1489
|
+
exports.DEFAULT_VALID_FOR_SECONDS = DEFAULT_VALID_FOR_SECONDS;
|
|
1490
|
+
exports.DELEGATION_CODE_PREFIX = DELEGATION_CODE_PREFIX;
|
|
1491
|
+
exports.DELEGATION_CONTRACT_ADDRESS = DELEGATION_CONTRACT_ADDRESS;
|
|
1027
1492
|
exports.DynamicEvmWalletClient = DynamicEvmWalletClient;
|
|
1028
1493
|
exports.ERROR_ACCOUNT_ADDRESS_REQUIRED = ERROR_ACCOUNT_ADDRESS_REQUIRED;
|
|
1029
1494
|
exports.ERROR_CREATE_WALLET_ACCOUNT = ERROR_CREATE_WALLET_ACCOUNT;
|
|
1495
|
+
exports.ERROR_GASLESS_MISSING_REQUEST_ID = ERROR_GASLESS_MISSING_REQUEST_ID;
|
|
1496
|
+
exports.ERROR_GASLESS_MISSING_YPARITY = ERROR_GASLESS_MISSING_YPARITY;
|
|
1497
|
+
exports.ERROR_GASLESS_RELAY_FAILED = ERROR_GASLESS_RELAY_FAILED;
|
|
1498
|
+
exports.ERROR_GASLESS_RPC_REQUIRED = ERROR_GASLESS_RPC_REQUIRED;
|
|
1499
|
+
exports.ERROR_GASLESS_RPC_REQUIRED_FOR_AUTO_DELEGATE = ERROR_GASLESS_RPC_REQUIRED_FOR_AUTO_DELEGATE;
|
|
1500
|
+
exports.ERROR_GASLESS_TIMEOUT = ERROR_GASLESS_TIMEOUT;
|
|
1030
1501
|
exports.ERROR_KEYGEN_FAILED = ERROR_KEYGEN_FAILED;
|
|
1031
1502
|
exports.ERROR_SIGN_MESSAGE = ERROR_SIGN_MESSAGE;
|
|
1032
1503
|
exports.ERROR_SIGN_RAW_MESSAGE = ERROR_SIGN_RAW_MESSAGE;
|
|
1033
1504
|
exports.ERROR_SIGN_TYPED_DATA = ERROR_SIGN_TYPED_DATA;
|
|
1034
1505
|
exports.ERROR_VERIFY_MESSAGE_SIGNATURE = ERROR_VERIFY_MESSAGE_SIGNATURE;
|
|
1506
|
+
exports.EVM_GASLESS_DEFAULT_POLL_INTERVAL_MS = EVM_GASLESS_DEFAULT_POLL_INTERVAL_MS;
|
|
1507
|
+
exports.EVM_GASLESS_DEFAULT_TIMEOUT_MS = EVM_GASLESS_DEFAULT_TIMEOUT_MS;
|
|
1035
1508
|
exports.EVM_SIGN_MESSAGE_PREFIX = EVM_SIGN_MESSAGE_PREFIX;
|
|
1509
|
+
exports.UGD_ABI = UGD_ABI;
|
|
1036
1510
|
exports.createAccountAdapter = createAccountAdapter;
|
|
1037
1511
|
exports.createDelegatedEvmWalletClient = createDelegatedEvmWalletClient;
|
|
1038
1512
|
exports.createZerodevClient = createZerodevClient;
|