@0xsequence/relayer 0.31.0 → 0.35.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/CHANGELOG.md +49 -0
- package/dist/0xsequence-relayer.cjs.dev.js +153 -48
- package/dist/0xsequence-relayer.cjs.prod.js +153 -48
- package/dist/0xsequence-relayer.esm.js +155 -50
- package/dist/declarations/src/base-relayer.d.ts +9 -1
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/provider-relayer.d.ts +2 -1
- package/dist/declarations/src/rpc-relayer/index.d.ts +2 -1
- package/dist/declarations/src/rpc-relayer/relayer.gen.d.ts +32 -1
- package/package.json +7 -7
- package/src/base-relayer.ts +38 -19
- package/src/index.ts +3 -0
- package/src/local-relayer.ts +11 -3
- package/src/provider-relayer.ts +19 -15
- package/src/rpc-relayer/index.ts +46 -28
- package/src/rpc-relayer/relayer.gen.ts +54 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @0xsequence/relayer
|
|
2
2
|
|
|
3
|
+
## 0.35.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- - config: add buildStubSignature
|
|
8
|
+
- provider: add checks to signing cases for wallet deployment and config statuses
|
|
9
|
+
- provider: add prompt for wallet deployment
|
|
10
|
+
- relayer: add BaseRelayer.prependWalletDeploy
|
|
11
|
+
- relayer: add Relayer.feeOptions
|
|
12
|
+
- relayer: account for wallet deployment in fee estimation
|
|
13
|
+
- transactions: add fromTransactionish
|
|
14
|
+
- wallet: add Account.prependConfigUpdate
|
|
15
|
+
- wallet: add Account.getFeeOptions
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @0xsequence/abi@0.35.0
|
|
21
|
+
- @0xsequence/config@0.35.0
|
|
22
|
+
- @0xsequence/transactions@0.35.0
|
|
23
|
+
- @0xsequence/utils@0.35.0
|
|
24
|
+
|
|
25
|
+
## 0.34.0
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- - upgrade deps
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies
|
|
34
|
+
- @0xsequence/abi@0.34.0
|
|
35
|
+
- @0xsequence/config@0.34.0
|
|
36
|
+
- @0xsequence/transactions@0.34.0
|
|
37
|
+
- @0xsequence/utils@0.34.0
|
|
38
|
+
|
|
39
|
+
## 0.33.2
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies
|
|
44
|
+
- @0xsequence/transactions@0.33.2
|
|
45
|
+
|
|
46
|
+
## 0.31.1
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- relayer: add Relayer.simulate
|
|
51
|
+
|
|
3
52
|
## 0.31.0
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
|
@@ -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
|
|
70
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -129,11 +168,10 @@ class ProviderRelayer extends BaseRelayer {
|
|
|
129
168
|
this.fromBlockLog = opts.fromBlockLog;
|
|
130
169
|
}
|
|
131
170
|
|
|
132
|
-
async
|
|
171
|
+
async simulate(wallet, ...transactions) {
|
|
133
172
|
var _this = this;
|
|
134
173
|
|
|
135
|
-
|
|
136
|
-
const gasCosts = await Promise.all(transactions.map(async function (tx) {
|
|
174
|
+
return (await Promise.all(transactions.map(async function (tx) {
|
|
137
175
|
// Respect gasLimit request of the transaction (as long as its not 0)
|
|
138
176
|
if (tx.gasLimit && !ethers.ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.ethers.constants.Zero)) {
|
|
139
177
|
return tx.gasLimit;
|
|
@@ -145,7 +183,7 @@ class ProviderRelayer extends BaseRelayer {
|
|
|
145
183
|
} // Fee can't be estimated for self-called if wallet hasn't been deployed
|
|
146
184
|
|
|
147
185
|
|
|
148
|
-
if (tx.to ===
|
|
186
|
+
if (tx.to === wallet && !(await _this.isWalletDeployed(wallet))) {
|
|
149
187
|
return DEFAULT_GAS_LIMIT;
|
|
150
188
|
}
|
|
151
189
|
|
|
@@ -156,16 +194,25 @@ class ProviderRelayer extends BaseRelayer {
|
|
|
156
194
|
|
|
157
195
|
|
|
158
196
|
return _this.provider.estimateGas({
|
|
159
|
-
from:
|
|
197
|
+
from: wallet,
|
|
160
198
|
to: tx.to,
|
|
161
199
|
data: tx.data,
|
|
162
200
|
value: tx.value
|
|
163
201
|
});
|
|
202
|
+
}))).map(gasLimit => ({
|
|
203
|
+
executed: true,
|
|
204
|
+
succeeded: true,
|
|
205
|
+
gasLimit: ethers.ethers.BigNumber.from(gasLimit).toNumber(),
|
|
206
|
+
gasUsed: ethers.ethers.BigNumber.from(gasLimit).toNumber()
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async estimateGasLimits(config$1, context, ...transactions) {
|
|
211
|
+
const walletAddr = config.addressOf(config$1, context);
|
|
212
|
+
const results = await this.simulate(walletAddr, ...transactions);
|
|
213
|
+
return transactions.map((t, i) => _extends({}, t, {
|
|
214
|
+
gasLimit: results[i].gasLimit
|
|
164
215
|
}));
|
|
165
|
-
return transactions.map((t, i) => {
|
|
166
|
-
t.gasLimit = gasCosts[i];
|
|
167
|
-
return t;
|
|
168
|
-
});
|
|
169
216
|
}
|
|
170
217
|
|
|
171
218
|
async getNonce(config$1, context, space, blockTag) {
|
|
@@ -273,18 +320,26 @@ class LocalRelayer extends ProviderRelayer {
|
|
|
273
320
|
throw new Error('LocalRelayer requires the context.guestModule address');
|
|
274
321
|
}
|
|
275
322
|
|
|
276
|
-
const
|
|
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
|
|
277
329
|
// NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
|
|
278
330
|
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
|
|
279
331
|
// txRequest.gasLimit = gasLimit
|
|
280
332
|
|
|
281
|
-
return this.signer.sendTransaction(
|
|
333
|
+
return this.signer.sendTransaction({
|
|
334
|
+
to,
|
|
335
|
+
data
|
|
336
|
+
});
|
|
282
337
|
}
|
|
283
338
|
|
|
284
339
|
}
|
|
285
340
|
|
|
286
341
|
/* eslint-disable */
|
|
287
|
-
// sequence-relayer v0.4.0
|
|
342
|
+
// sequence-relayer v0.4.0 7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd
|
|
288
343
|
// --
|
|
289
344
|
// This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
|
|
290
345
|
// Do not edit by hand. Update your webrpc schema and re-generate.
|
|
@@ -293,7 +348,7 @@ const WebRPCVersion = 'v1'; // Schema version of your RIDL schema
|
|
|
293
348
|
|
|
294
349
|
const WebRPCSchemaVersion = 'v0.4.0'; // Schema hash generated from your RIDL schema
|
|
295
350
|
|
|
296
|
-
const WebRPCSchemaHash = '
|
|
351
|
+
const WebRPCSchemaHash = '7dbfaf5c04cf28e9259ff1a9bf3274c8d73be5dd'; //
|
|
297
352
|
// Types
|
|
298
353
|
//
|
|
299
354
|
|
|
@@ -425,6 +480,16 @@ class Relayer {
|
|
|
425
480
|
});
|
|
426
481
|
};
|
|
427
482
|
|
|
483
|
+
this.simulate = (args, headers) => {
|
|
484
|
+
return this.fetch(this.url('Simulate'), createHTTPRequest(args, headers)).then(res => {
|
|
485
|
+
return buildResponse(res).then(_data => {
|
|
486
|
+
return {
|
|
487
|
+
results: _data.results
|
|
488
|
+
};
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
|
|
428
493
|
this.updateMetaTxnGasLimits = (args, headers) => {
|
|
429
494
|
return this.fetch(this.url('UpdateMetaTxnGasLimits'), createHTTPRequest(args, headers)).then(res => {
|
|
430
495
|
return buildResponse(res).then(_data => {
|
|
@@ -446,6 +511,16 @@ class Relayer {
|
|
|
446
511
|
});
|
|
447
512
|
};
|
|
448
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
|
+
|
|
449
524
|
this.getMetaTxnNetworkFeeOptions = (args, headers) => {
|
|
450
525
|
return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHTTPRequest(args, headers)).then(res => {
|
|
451
526
|
return buildResponse(res).then(_data => {
|
|
@@ -565,6 +640,15 @@ class RpcRelayer extends BaseRelayer {
|
|
|
565
640
|
return result;
|
|
566
641
|
}
|
|
567
642
|
|
|
643
|
+
async simulate(wallet, ...transactions$1) {
|
|
644
|
+
const coder = ethers.ethers.utils.defaultAbiCoder;
|
|
645
|
+
const encoded = coder.encode([transactions.MetaTransactionsType], [transactions.sequenceTxAbiEncode(transactions$1)]);
|
|
646
|
+
return (await this.service.simulate({
|
|
647
|
+
wallet,
|
|
648
|
+
transactions: encoded
|
|
649
|
+
})).results;
|
|
650
|
+
}
|
|
651
|
+
|
|
568
652
|
async estimateGasLimits(config$1, context, ...transactions$1) {
|
|
569
653
|
utils.logger.info(`[rpc-relayer/estimateGasLimits] estimate gas limits request ${JSON.stringify(transactions$1)}`);
|
|
570
654
|
|
|
@@ -609,23 +693,39 @@ class RpcRelayer extends BaseRelayer {
|
|
|
609
693
|
if (feeTokens.isFeeRequired) {
|
|
610
694
|
const symbols = feeTokens.tokens.map(token => token.symbol).join(', ');
|
|
611
695
|
utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are required, accepted tokens are ${symbols}`);
|
|
612
|
-
const
|
|
613
|
-
|
|
696
|
+
const wallet = config.addressOf(config$1, context);
|
|
697
|
+
let nonce = transactions.readSequenceNonce(...transactions$1);
|
|
698
|
+
|
|
699
|
+
if (nonce === undefined) {
|
|
700
|
+
nonce = await this.getNonce(config$1, context);
|
|
701
|
+
}
|
|
614
702
|
|
|
615
|
-
if (
|
|
616
|
-
|
|
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');
|
|
617
706
|
}
|
|
618
707
|
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
|
626
726
|
});
|
|
627
|
-
utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(
|
|
628
|
-
return
|
|
727
|
+
utils.logger.info(`[rpc-relayer/gasRefundOptions] got refund options ${JSON.stringify(options)}`);
|
|
728
|
+
return options;
|
|
629
729
|
} else {
|
|
630
730
|
utils.logger.info(`[rpc-relayer/gasRefundOptions] relayer fees are not required`);
|
|
631
731
|
return [];
|
|
@@ -654,13 +754,18 @@ class RpcRelayer extends BaseRelayer {
|
|
|
654
754
|
throw new Error('provider is not set');
|
|
655
755
|
}
|
|
656
756
|
|
|
657
|
-
const
|
|
658
|
-
|
|
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]);
|
|
659
764
|
const metaTxn = await this.service.sendMetaTxn({
|
|
660
765
|
call: {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
766
|
+
walletAddress,
|
|
767
|
+
contract,
|
|
768
|
+
input
|
|
664
769
|
}
|
|
665
770
|
});
|
|
666
771
|
utils.logger.info(`[rpc-relayer/relay] got relay result ${JSON.stringify(metaTxn)}`);
|