@0xsequence/relayer 0.34.0 → 0.35.3

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.
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var providers = require('@ethersproject/providers');
7
6
  var abi = require('@0xsequence/abi');
8
7
  var transactions = require('@0xsequence/transactions');
8
+ var providers = require('@ethersproject/providers');
9
9
  var config = require('@0xsequence/config');
10
10
  var utils$1 = require('ethers/lib/utils');
11
11
  var utils = require('@0xsequence/utils');
@@ -66,8 +66,14 @@ class BaseRelayer {
66
66
  };
67
67
  }
68
68
 
69
- async prepareTransactions(config$1, context, signature, ...transactions$1) {
70
- //, gasLimit?: ethers.BigNumberish }> {
69
+ async prependWalletDeploy(signedTransactions) {
70
+ const {
71
+ config: config$1,
72
+ context,
73
+ transactions: transactions$1,
74
+ nonce,
75
+ signature
76
+ } = signedTransactions;
71
77
  const walletAddress = config.addressOf(config$1, context);
72
78
  const walletInterface = new utils$1.Interface(abi.walletContracts.mainModule.abi);
73
79
 
@@ -80,28 +86,61 @@ class BaseRelayer {
80
86
  if (this.bundleCreation && !(await this.isWalletDeployed(walletAddress))) {
81
87
  return {
82
88
  to: context.guestModule,
83
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode([_extends({}, this.prepareWalletDeploy(config$1, context), {
84
- delegateCall: false,
85
- revertOnError: false,
86
- gasLimit: this.creationGasLimit,
87
- value: ethers.ethers.constants.Zero
88
- }), {
89
- delegateCall: false,
90
- revertOnError: true,
91
- gasLimit: ethers.ethers.constants.Zero,
92
- to: walletAddress,
93
- value: ethers.ethers.constants.Zero,
94
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), transactions.readSequenceNonce(...transactions$1), await encodedSignature])
95
- }]), 0, []])
89
+ execute: {
90
+ transactions: [_extends({}, this.prepareWalletDeploy(config$1, context), {
91
+ delegateCall: false,
92
+ revertOnError: false,
93
+ gasLimit: this.creationGasLimit,
94
+ value: ethers.ethers.constants.Zero
95
+ }), {
96
+ delegateCall: false,
97
+ revertOnError: true,
98
+ gasLimit: ethers.ethers.constants.Zero,
99
+ to: walletAddress,
100
+ value: ethers.ethers.constants.Zero,
101
+ data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), nonce, await encodedSignature])
102
+ }],
103
+ nonce: ethers.ethers.constants.Zero,
104
+ signature: '0x'
105
+ }
96
106
  };
97
107
  } else {
98
108
  return {
99
109
  to: walletAddress,
100
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), transactions.readSequenceNonce(...transactions$1), await encodedSignature])
110
+ execute: {
111
+ transactions: transactions$1,
112
+ nonce: ethers.ethers.BigNumber.from(nonce),
113
+ signature: await encodedSignature
114
+ }
101
115
  };
102
116
  }
103
117
  }
104
118
 
119
+ async prepareTransactions(config, context, signature, ...transactions$1) {
120
+ //, gasLimit?: ethers.BigNumberish }> {
121
+ const nonce = transactions.readSequenceNonce(...transactions$1);
122
+
123
+ if (!nonce) {
124
+ throw new Error('Unable to prepare transactions without a defined nonce');
125
+ }
126
+
127
+ const {
128
+ to,
129
+ execute
130
+ } = await this.prependWalletDeploy({
131
+ config,
132
+ context,
133
+ transactions: transactions$1,
134
+ nonce,
135
+ signature
136
+ });
137
+ const walletInterface = new utils$1.Interface(abi.walletContracts.mainModule.abi);
138
+ return {
139
+ to,
140
+ data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature])
141
+ };
142
+ }
143
+
105
144
  }
106
145
 
107
146
  const DEFAULT_GAS_LIMIT = ethers.ethers.BigNumber.from(800000);
@@ -281,18 +320,26 @@ class LocalRelayer extends ProviderRelayer {
281
320
  throw new Error('LocalRelayer requires the context.guestModule address');
282
321
  }
283
322
 
284
- const txRequest = await this.prepareTransactions(signedTxs.config, signedTxs.context, signedTxs.signature, ...signedTxs.transactions); // TODO: think about computing gas limit individually, summing together and passing across
323
+ const {
324
+ to,
325
+ execute
326
+ } = await this.prependWalletDeploy(signedTxs);
327
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
328
+ const data = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]); // TODO: think about computing gas limit individually, summing together and passing across
285
329
  // NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
286
330
  // const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
287
331
  // txRequest.gasLimit = gasLimit
288
332
 
289
- return this.signer.sendTransaction(txRequest);
333
+ return this.signer.sendTransaction({
334
+ to,
335
+ data
336
+ });
290
337
  }
291
338
 
292
339
  }
293
340
 
294
341
  /* eslint-disable */
295
- // sequence-relayer v0.4.0 1598ae8045a4f054fefc0fa3b244f61f75a7c8bd
342
+ // sequence-relayer v0.4.0 7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd
296
343
  // --
297
344
  // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
298
345
  // Do not edit by hand. Update your webrpc schema and re-generate.
@@ -301,7 +348,7 @@ const WebRPCVersion = 'v1'; // Schema version of your RIDL schema
301
348
 
302
349
  const WebRPCSchemaVersion = 'v0.4.0'; // Schema hash generated from your RIDL schema
303
350
 
304
- const WebRPCSchemaHash = '1598ae8045a4f054fefc0fa3b244f61f75a7c8bd'; //
351
+ const WebRPCSchemaHash = '7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd'; //
305
352
  // Types
306
353
  //
307
354
 
@@ -464,6 +511,16 @@ class Relayer {
464
511
  });
465
512
  };
466
513
 
514
+ this.feeOptions = (args, headers) => {
515
+ return this.fetch(this.url('FeeOptions'), createHTTPRequest(args, headers)).then(res => {
516
+ return buildResponse(res).then(_data => {
517
+ return {
518
+ options: _data.options
519
+ };
520
+ });
521
+ });
522
+ };
523
+
467
524
  this.getMetaTxnNetworkFeeOptions = (args, headers) => {
468
525
  return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHTTPRequest(args, headers)).then(res => {
469
526
  return buildResponse(res).then(_data => {
@@ -636,23 +693,39 @@ class RpcRelayer extends BaseRelayer {
636
693
  if (feeTokens.isFeeRequired) {
637
694
  const symbols = feeTokens.tokens.map(token => token.symbol).join(', ');
638
695
  utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are required, accepted tokens are ${symbols}`);
639
- const addr = config.addressOf(config$1, context);
640
- const prevNonce = transactions.readSequenceNonce(...transactions$1); // Set temporal nonce to simulate meta-txn
696
+ const wallet = config.addressOf(config$1, context);
697
+ let nonce = transactions.readSequenceNonce(...transactions$1);
641
698
 
642
- if (prevNonce === undefined) {
643
- transactions$1 = transactions.appendNonce(transactions$1, await this.getNonce(config$1, context));
699
+ if (nonce === undefined) {
700
+ nonce = await this.getNonce(config$1, context);
644
701
  }
645
702
 
646
- const coder = ethers.ethers.utils.defaultAbiCoder;
647
- const encoded = coder.encode([transactions.MetaTransactionsType], [transactions.sequenceTxAbiEncode(transactions$1)]);
648
- const res = await this.service.getMetaTxnNetworkFeeOptions({
649
- walletConfig: _extends({}, config$1, {
650
- address: addr
651
- }),
652
- payload: encoded
703
+ if (!this.provider) {
704
+ utils.logger.warn(`[rpc-relayer/gasRefundOptions] provider not set, needed for stub signature`);
705
+ throw new Error('provider is not set');
706
+ }
707
+
708
+ const {
709
+ to,
710
+ execute
711
+ } = await this.prependWalletDeploy({
712
+ config: config$1,
713
+ context,
714
+ transactions: transactions$1,
715
+ nonce,
716
+ signature: config.buildStubSignature(this.provider, config$1)
717
+ });
718
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
719
+ const data = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]);
720
+ const {
721
+ options
722
+ } = await this.service.feeOptions({
723
+ wallet,
724
+ to,
725
+ data
653
726
  });
654
- utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(res.options)}`);
655
- return res.options;
727
+ utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(options)}`);
728
+ return options;
656
729
  } else {
657
730
  utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are not required`);
658
731
  return [];
@@ -681,13 +754,18 @@ class RpcRelayer extends BaseRelayer {
681
754
  throw new Error('provider is not set');
682
755
  }
683
756
 
684
- const addr = config.addressOf(signedTxs.config, signedTxs.context);
685
- const prep = await this.prepareTransactions(signedTxs.config, signedTxs.context, signedTxs.signature, ...signedTxs.transactions);
757
+ const {
758
+ to: contract,
759
+ execute
760
+ } = await this.prependWalletDeploy(signedTxs);
761
+ const walletAddress = config.addressOf(signedTxs.config, signedTxs.context);
762
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
763
+ const input = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]);
686
764
  const metaTxn = await this.service.sendMetaTxn({
687
765
  call: {
688
- contract: prep.to,
689
- input: prep.data,
690
- walletAddress: addr
766
+ walletAddress,
767
+ contract,
768
+ input
691
769
  }
692
770
  });
693
771
  utils.logger.info(`[rpc-relayer/relay] got relay result ${JSON.stringify(metaTxn)}`);
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ethers = require('ethers');
6
- var providers = require('@ethersproject/providers');
7
6
  var abi = require('@0xsequence/abi');
8
7
  var transactions = require('@0xsequence/transactions');
8
+ var providers = require('@ethersproject/providers');
9
9
  var config = require('@0xsequence/config');
10
10
  var utils$1 = require('ethers/lib/utils');
11
11
  var utils = require('@0xsequence/utils');
@@ -66,8 +66,14 @@ class BaseRelayer {
66
66
  };
67
67
  }
68
68
 
69
- async prepareTransactions(config$1, context, signature, ...transactions$1) {
70
- //, gasLimit?: ethers.BigNumberish }> {
69
+ async prependWalletDeploy(signedTransactions) {
70
+ const {
71
+ config: config$1,
72
+ context,
73
+ transactions: transactions$1,
74
+ nonce,
75
+ signature
76
+ } = signedTransactions;
71
77
  const walletAddress = config.addressOf(config$1, context);
72
78
  const walletInterface = new utils$1.Interface(abi.walletContracts.mainModule.abi);
73
79
 
@@ -80,28 +86,61 @@ class BaseRelayer {
80
86
  if (this.bundleCreation && !(await this.isWalletDeployed(walletAddress))) {
81
87
  return {
82
88
  to: context.guestModule,
83
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode([_extends({}, this.prepareWalletDeploy(config$1, context), {
84
- delegateCall: false,
85
- revertOnError: false,
86
- gasLimit: this.creationGasLimit,
87
- value: ethers.ethers.constants.Zero
88
- }), {
89
- delegateCall: false,
90
- revertOnError: true,
91
- gasLimit: ethers.ethers.constants.Zero,
92
- to: walletAddress,
93
- value: ethers.ethers.constants.Zero,
94
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), transactions.readSequenceNonce(...transactions$1), await encodedSignature])
95
- }]), 0, []])
89
+ execute: {
90
+ transactions: [_extends({}, this.prepareWalletDeploy(config$1, context), {
91
+ delegateCall: false,
92
+ revertOnError: false,
93
+ gasLimit: this.creationGasLimit,
94
+ value: ethers.ethers.constants.Zero
95
+ }), {
96
+ delegateCall: false,
97
+ revertOnError: true,
98
+ gasLimit: ethers.ethers.constants.Zero,
99
+ to: walletAddress,
100
+ value: ethers.ethers.constants.Zero,
101
+ data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), nonce, await encodedSignature])
102
+ }],
103
+ nonce: ethers.ethers.constants.Zero,
104
+ signature: '0x'
105
+ }
96
106
  };
97
107
  } else {
98
108
  return {
99
109
  to: walletAddress,
100
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(transactions$1), transactions.readSequenceNonce(...transactions$1), await encodedSignature])
110
+ execute: {
111
+ transactions: transactions$1,
112
+ nonce: ethers.ethers.BigNumber.from(nonce),
113
+ signature: await encodedSignature
114
+ }
101
115
  };
102
116
  }
103
117
  }
104
118
 
119
+ async prepareTransactions(config, context, signature, ...transactions$1) {
120
+ //, gasLimit?: ethers.BigNumberish }> {
121
+ const nonce = transactions.readSequenceNonce(...transactions$1);
122
+
123
+ if (!nonce) {
124
+ throw new Error('Unable to prepare transactions without a defined nonce');
125
+ }
126
+
127
+ const {
128
+ to,
129
+ execute
130
+ } = await this.prependWalletDeploy({
131
+ config,
132
+ context,
133
+ transactions: transactions$1,
134
+ nonce,
135
+ signature
136
+ });
137
+ const walletInterface = new utils$1.Interface(abi.walletContracts.mainModule.abi);
138
+ return {
139
+ to,
140
+ data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature])
141
+ };
142
+ }
143
+
105
144
  }
106
145
 
107
146
  const DEFAULT_GAS_LIMIT = ethers.ethers.BigNumber.from(800000);
@@ -281,18 +320,26 @@ class LocalRelayer extends ProviderRelayer {
281
320
  throw new Error('LocalRelayer requires the context.guestModule address');
282
321
  }
283
322
 
284
- const txRequest = await this.prepareTransactions(signedTxs.config, signedTxs.context, signedTxs.signature, ...signedTxs.transactions); // TODO: think about computing gas limit individually, summing together and passing across
323
+ const {
324
+ to,
325
+ execute
326
+ } = await this.prependWalletDeploy(signedTxs);
327
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
328
+ const data = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]); // TODO: think about computing gas limit individually, summing together and passing across
285
329
  // NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
286
330
  // const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
287
331
  // txRequest.gasLimit = gasLimit
288
332
 
289
- return this.signer.sendTransaction(txRequest);
333
+ return this.signer.sendTransaction({
334
+ to,
335
+ data
336
+ });
290
337
  }
291
338
 
292
339
  }
293
340
 
294
341
  /* eslint-disable */
295
- // sequence-relayer v0.4.0 1598ae8045a4f054fefc0fa3b244f61f75a7c8bd
342
+ // sequence-relayer v0.4.0 7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd
296
343
  // --
297
344
  // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
298
345
  // Do not edit by hand. Update your webrpc schema and re-generate.
@@ -301,7 +348,7 @@ const WebRPCVersion = 'v1'; // Schema version of your RIDL schema
301
348
 
302
349
  const WebRPCSchemaVersion = 'v0.4.0'; // Schema hash generated from your RIDL schema
303
350
 
304
- const WebRPCSchemaHash = '1598ae8045a4f054fefc0fa3b244f61f75a7c8bd'; //
351
+ const WebRPCSchemaHash = '7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd'; //
305
352
  // Types
306
353
  //
307
354
 
@@ -464,6 +511,16 @@ class Relayer {
464
511
  });
465
512
  };
466
513
 
514
+ this.feeOptions = (args, headers) => {
515
+ return this.fetch(this.url('FeeOptions'), createHTTPRequest(args, headers)).then(res => {
516
+ return buildResponse(res).then(_data => {
517
+ return {
518
+ options: _data.options
519
+ };
520
+ });
521
+ });
522
+ };
523
+
467
524
  this.getMetaTxnNetworkFeeOptions = (args, headers) => {
468
525
  return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHTTPRequest(args, headers)).then(res => {
469
526
  return buildResponse(res).then(_data => {
@@ -636,23 +693,39 @@ class RpcRelayer extends BaseRelayer {
636
693
  if (feeTokens.isFeeRequired) {
637
694
  const symbols = feeTokens.tokens.map(token => token.symbol).join(', ');
638
695
  utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are required, accepted tokens are ${symbols}`);
639
- const addr = config.addressOf(config$1, context);
640
- const prevNonce = transactions.readSequenceNonce(...transactions$1); // Set temporal nonce to simulate meta-txn
696
+ const wallet = config.addressOf(config$1, context);
697
+ let nonce = transactions.readSequenceNonce(...transactions$1);
641
698
 
642
- if (prevNonce === undefined) {
643
- transactions$1 = transactions.appendNonce(transactions$1, await this.getNonce(config$1, context));
699
+ if (nonce === undefined) {
700
+ nonce = await this.getNonce(config$1, context);
644
701
  }
645
702
 
646
- const coder = ethers.ethers.utils.defaultAbiCoder;
647
- const encoded = coder.encode([transactions.MetaTransactionsType], [transactions.sequenceTxAbiEncode(transactions$1)]);
648
- const res = await this.service.getMetaTxnNetworkFeeOptions({
649
- walletConfig: _extends({}, config$1, {
650
- address: addr
651
- }),
652
- payload: encoded
703
+ if (!this.provider) {
704
+ utils.logger.warn(`[rpc-relayer/gasRefundOptions] provider not set, needed for stub signature`);
705
+ throw new Error('provider is not set');
706
+ }
707
+
708
+ const {
709
+ to,
710
+ execute
711
+ } = await this.prependWalletDeploy({
712
+ config: config$1,
713
+ context,
714
+ transactions: transactions$1,
715
+ nonce,
716
+ signature: config.buildStubSignature(this.provider, config$1)
717
+ });
718
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
719
+ const data = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]);
720
+ const {
721
+ options
722
+ } = await this.service.feeOptions({
723
+ wallet,
724
+ to,
725
+ data
653
726
  });
654
- utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(res.options)}`);
655
- return res.options;
727
+ utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(options)}`);
728
+ return options;
656
729
  } else {
657
730
  utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are not required`);
658
731
  return [];
@@ -681,13 +754,18 @@ class RpcRelayer extends BaseRelayer {
681
754
  throw new Error('provider is not set');
682
755
  }
683
756
 
684
- const addr = config.addressOf(signedTxs.config, signedTxs.context);
685
- const prep = await this.prepareTransactions(signedTxs.config, signedTxs.context, signedTxs.signature, ...signedTxs.transactions);
757
+ const {
758
+ to: contract,
759
+ execute
760
+ } = await this.prependWalletDeploy(signedTxs);
761
+ const walletAddress = config.addressOf(signedTxs.config, signedTxs.context);
762
+ const walletInterface = new ethers.ethers.utils.Interface(abi.walletContracts.mainModule.abi);
763
+ const input = walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [transactions.sequenceTxAbiEncode(execute.transactions), execute.nonce, execute.signature]);
686
764
  const metaTxn = await this.service.sendMetaTxn({
687
765
  call: {
688
- contract: prep.to,
689
- input: prep.data,
690
- walletAddress: addr
766
+ walletAddress,
767
+ contract,
768
+ input
691
769
  }
692
770
  });
693
771
  utils.logger.info(`[rpc-relayer/relay] got relay result ${JSON.stringify(metaTxn)}`);