@0xsequence/account 1.10.15 → 2.0.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/dist/0xsequence-account.cjs.dev.js +51 -49
- package/dist/0xsequence-account.cjs.prod.js +51 -49
- package/dist/0xsequence-account.esm.js +52 -50
- package/dist/declarations/src/account.d.ts +5 -5
- package/dist/declarations/src/signer.d.ts +19 -17
- package/package.json +15 -12
- package/src/account.ts +40 -32
- package/src/orchestrator/wrapper.ts +5 -5
- package/src/signer.ts +43 -43
- package/src/utils.ts +0 -14
|
@@ -25,20 +25,9 @@ function _extends() {
|
|
|
25
25
|
return _extends.apply(this, arguments);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function isPromise(value) {
|
|
29
|
-
return !!value && typeof value.then === 'function';
|
|
30
|
-
}
|
|
31
|
-
function isDeferrable(value) {
|
|
32
|
-
// The value is deferrable if any of the properties is a Promises
|
|
33
|
-
if (typeof value === 'object') {
|
|
34
|
-
return Object.keys(value).some(key => isPromise(value[key]));
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
28
|
function encodeGasRefundTransaction(option) {
|
|
40
29
|
if (!option) return [];
|
|
41
|
-
const value =
|
|
30
|
+
const value = BigInt(option.value);
|
|
42
31
|
switch (option.token.type) {
|
|
43
32
|
case relayer.proto.FeeTokenType.UNKNOWN:
|
|
44
33
|
return [{
|
|
@@ -46,8 +35,8 @@ function encodeGasRefundTransaction(option) {
|
|
|
46
35
|
revertOnError: true,
|
|
47
36
|
gasLimit: option.gasLimit,
|
|
48
37
|
to: option.to,
|
|
49
|
-
value:
|
|
50
|
-
data:
|
|
38
|
+
value: utils.toHexString(value),
|
|
39
|
+
data: '0x'
|
|
51
40
|
}];
|
|
52
41
|
case relayer.proto.FeeTokenType.ERC20_TOKEN:
|
|
53
42
|
if (!option.token.contractAddress) {
|
|
@@ -59,7 +48,7 @@ function encodeGasRefundTransaction(option) {
|
|
|
59
48
|
gasLimit: option.gasLimit,
|
|
60
49
|
to: option.token.contractAddress,
|
|
61
50
|
value: 0,
|
|
62
|
-
data: new ethers.ethers.
|
|
51
|
+
data: new ethers.ethers.Interface([{
|
|
63
52
|
constant: false,
|
|
64
53
|
inputs: [{
|
|
65
54
|
type: 'address'
|
|
@@ -69,7 +58,7 @@ function encodeGasRefundTransaction(option) {
|
|
|
69
58
|
name: 'transfer',
|
|
70
59
|
outputs: [],
|
|
71
60
|
type: 'function'
|
|
72
|
-
}]).encodeFunctionData('transfer', [option.to,
|
|
61
|
+
}]).encodeFunctionData('transfer', [option.to, utils.toHexString(value)])
|
|
73
62
|
}];
|
|
74
63
|
default:
|
|
75
64
|
throw new Error(`Unhandled fee token type ${option.token.type}`);
|
|
@@ -80,7 +69,6 @@ class AccountSigner {
|
|
|
80
69
|
this.account = account;
|
|
81
70
|
this.chainId = chainId;
|
|
82
71
|
this.options = options;
|
|
83
|
-
this._isSigner = true;
|
|
84
72
|
}
|
|
85
73
|
get provider() {
|
|
86
74
|
return this.account.providerFor(this.chainId);
|
|
@@ -92,6 +80,10 @@ class AccountSigner {
|
|
|
92
80
|
var _this$options$cantVal, _this$options;
|
|
93
81
|
return this.account.signMessage(message, this.chainId, (_this$options$cantVal = (_this$options = this.options) == null ? void 0 : _this$options.cantValidateBehavior) != null ? _this$options$cantVal : 'throw');
|
|
94
82
|
}
|
|
83
|
+
signTypedData(domain, types, value) {
|
|
84
|
+
var _this$options$cantVal2, _this$options2;
|
|
85
|
+
return this.account.signTypedData(domain, types, value, this.chainId, (_this$options$cantVal2 = (_this$options2 = this.options) == null ? void 0 : _this$options2.cantValidateBehavior) != null ? _this$options$cantVal2 : 'throw');
|
|
86
|
+
}
|
|
95
87
|
async defaultSelectFee(_txs, options) {
|
|
96
88
|
// If no options, return undefined
|
|
97
89
|
if (options.length === 0) return undefined;
|
|
@@ -113,33 +105,32 @@ class AccountSigner {
|
|
|
113
105
|
if (option.token.type === relayer.proto.FeeTokenType.UNKNOWN) {
|
|
114
106
|
// Native token
|
|
115
107
|
const balance = await this.getBalance();
|
|
116
|
-
if (balance
|
|
108
|
+
if (balance >= BigInt(option.value)) {
|
|
117
109
|
return option;
|
|
118
110
|
}
|
|
119
111
|
} else if (option.token.contractAddress && option.token.type === relayer.proto.FeeTokenType.ERC20_TOKEN) {
|
|
120
112
|
// ERC20 token
|
|
121
113
|
const token = new ethers.ethers.Contract(option.token.contractAddress, balanceOfAbi, this.provider);
|
|
122
114
|
const balance = await token.balanceOf(this.account.address);
|
|
123
|
-
if (balance
|
|
115
|
+
if (balance >= BigInt(option.value)) {
|
|
124
116
|
return option;
|
|
125
117
|
}
|
|
126
118
|
} else ;
|
|
127
119
|
}
|
|
128
120
|
throw new Error('No fee option available - not enough balance');
|
|
129
121
|
}
|
|
130
|
-
async sendTransaction(
|
|
131
|
-
var _this$options$stubSig, _this$
|
|
132
|
-
const txs = isDeferrable(txsPromise) ? await ethers.ethers.utils.resolveProperties(txsPromise) : txsPromise;
|
|
122
|
+
async sendTransaction(txs, options) {
|
|
123
|
+
var _this$options$stubSig, _this$options3, _this$options$selectF, _this$options4, _this$options5;
|
|
133
124
|
const prepare = await this.account.prepareTransactions({
|
|
134
125
|
txs,
|
|
135
126
|
chainId: this.chainId,
|
|
136
|
-
stubSignatureOverrides: (_this$options$stubSig = (_this$
|
|
127
|
+
stubSignatureOverrides: (_this$options$stubSig = (_this$options3 = this.options) == null ? void 0 : _this$options3.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(),
|
|
137
128
|
simulateForFeeOptions: options == null ? void 0 : options.simulateForFeeOptions
|
|
138
129
|
});
|
|
139
|
-
const selectMethod = (_this$options$selectF = (_this$
|
|
130
|
+
const selectMethod = (_this$options$selectF = (_this$options4 = this.options) == null ? void 0 : _this$options4.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this);
|
|
140
131
|
const feeOption = await selectMethod(txs, prepare.feeOptions);
|
|
141
132
|
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)];
|
|
142
|
-
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$
|
|
133
|
+
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options5 = this.options) == null ? void 0 : _this$options5.nonceSpace) !== undefined ? {
|
|
143
134
|
nonceSpace: this.options.nonceSpace
|
|
144
135
|
} : undefined); // Will always have a transaction response
|
|
145
136
|
}
|
|
@@ -147,7 +138,9 @@ class AccountSigner {
|
|
|
147
138
|
return this.provider.getBalance(this.account.address, blockTag);
|
|
148
139
|
}
|
|
149
140
|
call(transaction, blockTag) {
|
|
150
|
-
return this.provider.call(transaction,
|
|
141
|
+
return this.provider.call(_extends({}, transaction, {
|
|
142
|
+
blockTag
|
|
143
|
+
}));
|
|
151
144
|
}
|
|
152
145
|
async resolveName(name) {
|
|
153
146
|
const res = await this.provider.resolveName(name);
|
|
@@ -167,7 +160,7 @@ class AccountSigner {
|
|
|
167
160
|
throw new Error('Method not implemented.');
|
|
168
161
|
}
|
|
169
162
|
getChainId() {
|
|
170
|
-
return Promise.resolve(
|
|
163
|
+
return Promise.resolve(Number(this.chainId));
|
|
171
164
|
}
|
|
172
165
|
getGasPrice() {
|
|
173
166
|
throw new Error('Method not implemented.');
|
|
@@ -175,10 +168,16 @@ class AccountSigner {
|
|
|
175
168
|
getFeeData() {
|
|
176
169
|
throw new Error('Method not implemented.');
|
|
177
170
|
}
|
|
171
|
+
getNonce(blockTag) {
|
|
172
|
+
throw new Error('Method not implemented.');
|
|
173
|
+
}
|
|
174
|
+
populateCall(tx) {
|
|
175
|
+
throw new Error('Method not implemented.');
|
|
176
|
+
}
|
|
178
177
|
checkTransaction(transaction) {
|
|
179
178
|
throw new Error('Method not implemented.');
|
|
180
179
|
}
|
|
181
|
-
populateTransaction(
|
|
180
|
+
async populateTransaction(tx) {
|
|
182
181
|
throw new Error('Method not implemented.');
|
|
183
182
|
}
|
|
184
183
|
_checkProvider(operation) {
|
|
@@ -197,7 +196,7 @@ class Chain0Reader {
|
|
|
197
196
|
return undefined;
|
|
198
197
|
}
|
|
199
198
|
async nonce(_wallet, _space) {
|
|
200
|
-
return
|
|
199
|
+
return 0n;
|
|
201
200
|
}
|
|
202
201
|
async isValidSignature(_wallet, _digest, _signature) {
|
|
203
202
|
throw new Error('Method not supported.');
|
|
@@ -214,7 +213,7 @@ class Account {
|
|
|
214
213
|
this.orchestrator = void 0;
|
|
215
214
|
this.jwt = void 0;
|
|
216
215
|
this.projectAccessKey = void 0;
|
|
217
|
-
this.address = ethers.ethers.
|
|
216
|
+
this.address = ethers.ethers.getAddress(options.address);
|
|
218
217
|
this.contexts = options.contexts;
|
|
219
218
|
this.tracker = options.tracker;
|
|
220
219
|
this.networks = options.networks;
|
|
@@ -264,21 +263,25 @@ class Account {
|
|
|
264
263
|
};
|
|
265
264
|
}
|
|
266
265
|
network(chainId) {
|
|
267
|
-
const tcid =
|
|
268
|
-
const found = this.networks.find(n => tcid
|
|
266
|
+
const tcid = BigInt(chainId);
|
|
267
|
+
const found = this.networks.find(n => tcid === BigInt(n.chainId));
|
|
269
268
|
if (!found) throw new Error(`Network not found for chainId ${chainId}`);
|
|
270
269
|
return found;
|
|
271
270
|
}
|
|
272
271
|
providerFor(chainId) {
|
|
273
272
|
const found = this.network(chainId);
|
|
274
|
-
if (!found.provider && !found.rpcUrl)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
if (!found.provider && !found.rpcUrl) {
|
|
274
|
+
throw new Error(`Provider not found for chainId ${chainId}`);
|
|
275
|
+
}
|
|
276
|
+
const network = new ethers.ethers.Network(found.name, found.chainId);
|
|
277
|
+
return found.provider || new ethers.ethers.JsonRpcProvider(utils.getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, {
|
|
278
|
+
staticNetwork: network
|
|
278
279
|
});
|
|
279
280
|
}
|
|
280
281
|
reader(chainId) {
|
|
281
|
-
if (
|
|
282
|
+
if (BigInt(chainId) === 0n) {
|
|
283
|
+
return new Chain0Reader();
|
|
284
|
+
}
|
|
282
285
|
|
|
283
286
|
// TODO: Networks should be able to provide a reader directly
|
|
284
287
|
// and we should default to the on-chain reader
|
|
@@ -310,7 +313,7 @@ class Account {
|
|
|
310
313
|
return this.walletFor(chainId, this.contextFor(status.version), status.config, coder);
|
|
311
314
|
}
|
|
312
315
|
walletFor(chainId, context, config, coders) {
|
|
313
|
-
const isNetworkZero =
|
|
316
|
+
const isNetworkZero = BigInt(chainId) === 0n;
|
|
314
317
|
return new wallet.Wallet({
|
|
315
318
|
config,
|
|
316
319
|
context,
|
|
@@ -512,7 +515,7 @@ class Account {
|
|
|
512
515
|
return coder.trim(chainedSignature);
|
|
513
516
|
}
|
|
514
517
|
async publishWitness() {
|
|
515
|
-
const digest = ethers.ethers.
|
|
518
|
+
const digest = ethers.ethers.id(`This is a Sequence account woo! ${Date.now()}`);
|
|
516
519
|
const signature = await this.signDigest(digest, 0, false);
|
|
517
520
|
const decoded = this.coders.signature.decode(signature);
|
|
518
521
|
const signatures = this.coders.signature.signaturesOfDecoded(decoded);
|
|
@@ -530,7 +533,7 @@ class Account {
|
|
|
530
533
|
// So we ignore the state on "chain zero" and instead use one of the states of the networks
|
|
531
534
|
// wallet-webapp should ensure the wallet is as migrated as possible, trying to mimic
|
|
532
535
|
// the behaviour of being migrated on all chains
|
|
533
|
-
const chainRef =
|
|
536
|
+
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId;
|
|
534
537
|
const status = await this.status(chainRef);
|
|
535
538
|
this.mustBeFullyMigrated(status);
|
|
536
539
|
|
|
@@ -561,11 +564,11 @@ class Account {
|
|
|
561
564
|
}
|
|
562
565
|
buildOnChainSignature(digest) {
|
|
563
566
|
const subdigest = core.commons.signature.subdigestOf({
|
|
564
|
-
digest: ethers.ethers.
|
|
567
|
+
digest: ethers.ethers.hexlify(digest),
|
|
565
568
|
chainId: 0,
|
|
566
569
|
address: this.address
|
|
567
570
|
});
|
|
568
|
-
const hexSubdigest = ethers.ethers.
|
|
571
|
+
const hexSubdigest = ethers.ethers.hexlify(subdigest);
|
|
569
572
|
const config = this.coders.config.fromSimple({
|
|
570
573
|
// Threshold *only* needs to be > 0, this is not a magic number
|
|
571
574
|
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
@@ -574,7 +577,7 @@ class Account {
|
|
|
574
577
|
signers: [],
|
|
575
578
|
subdigests: [hexSubdigest]
|
|
576
579
|
});
|
|
577
|
-
const walletInterface = new ethers.ethers.
|
|
580
|
+
const walletInterface = new ethers.ethers.Interface(abi.walletContracts.mainModule.abi);
|
|
578
581
|
const bundle = {
|
|
579
582
|
entrypoint: this.address,
|
|
580
583
|
transactions: [{
|
|
@@ -609,13 +612,13 @@ class Account {
|
|
|
609
612
|
if (bootstrapBundle.transactions.length === 0) {
|
|
610
613
|
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions');
|
|
611
614
|
}
|
|
612
|
-
const encoded = ethers.ethers.
|
|
613
|
-
return ethers.ethers.
|
|
615
|
+
const encoded = ethers.ethers.AbiCoder.defaultAbiCoder().encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]);
|
|
616
|
+
return ethers.ethers.solidityPacked(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]);
|
|
614
617
|
}
|
|
615
618
|
async editConfig(changes) {
|
|
616
619
|
const currentConfig = await this.status(0).then(s => s.config);
|
|
617
620
|
const newConfig = this.coders.config.editConfig(currentConfig, _extends({}, changes, {
|
|
618
|
-
checkpoint: this.coders.config.checkpointOf(currentConfig)
|
|
621
|
+
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n
|
|
619
622
|
}));
|
|
620
623
|
return this.updateConfig(newConfig);
|
|
621
624
|
}
|
|
@@ -675,7 +678,6 @@ class Account {
|
|
|
675
678
|
const deployTransaction = wallet.Wallet.buildDeployTransaction(status.original.context, status.original.imageHash);
|
|
676
679
|
transactions.push(...deployTransaction.transactions);
|
|
677
680
|
}
|
|
678
|
-
transactions.length;
|
|
679
681
|
|
|
680
682
|
// Get pending migrations
|
|
681
683
|
transactions.push(...status.signedMigrations.map(m => ({
|
|
@@ -719,7 +721,7 @@ class Account {
|
|
|
719
721
|
}), feeQuote);
|
|
720
722
|
}
|
|
721
723
|
signMessage(message, chainId, cantValidateBehavior = 'ignore') {
|
|
722
|
-
return this.signDigest(ethers.ethers.
|
|
724
|
+
return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior);
|
|
723
725
|
}
|
|
724
726
|
async signTransactions(txs, chainId, pstatus, options) {
|
|
725
727
|
const status = pstatus || (await this.status(chainId));
|
|
@@ -845,7 +847,7 @@ class Account {
|
|
|
845
847
|
const stubSignature = wallet.coders.config.buildStubSignature(wallet.config, stubSignatureOverrides);
|
|
846
848
|
|
|
847
849
|
// Now we can decorate the transactions as always, but we need to manually build the signed bundle
|
|
848
|
-
const intentId = ethers.ethers.
|
|
850
|
+
const intentId = ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
849
851
|
const signedBundle = {
|
|
850
852
|
chainId,
|
|
851
853
|
intent: {
|
|
@@ -25,20 +25,9 @@ function _extends() {
|
|
|
25
25
|
return _extends.apply(this, arguments);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function isPromise(value) {
|
|
29
|
-
return !!value && typeof value.then === 'function';
|
|
30
|
-
}
|
|
31
|
-
function isDeferrable(value) {
|
|
32
|
-
// The value is deferrable if any of the properties is a Promises
|
|
33
|
-
if (typeof value === 'object') {
|
|
34
|
-
return Object.keys(value).some(key => isPromise(value[key]));
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
28
|
function encodeGasRefundTransaction(option) {
|
|
40
29
|
if (!option) return [];
|
|
41
|
-
const value =
|
|
30
|
+
const value = BigInt(option.value);
|
|
42
31
|
switch (option.token.type) {
|
|
43
32
|
case relayer.proto.FeeTokenType.UNKNOWN:
|
|
44
33
|
return [{
|
|
@@ -46,8 +35,8 @@ function encodeGasRefundTransaction(option) {
|
|
|
46
35
|
revertOnError: true,
|
|
47
36
|
gasLimit: option.gasLimit,
|
|
48
37
|
to: option.to,
|
|
49
|
-
value:
|
|
50
|
-
data:
|
|
38
|
+
value: utils.toHexString(value),
|
|
39
|
+
data: '0x'
|
|
51
40
|
}];
|
|
52
41
|
case relayer.proto.FeeTokenType.ERC20_TOKEN:
|
|
53
42
|
if (!option.token.contractAddress) {
|
|
@@ -59,7 +48,7 @@ function encodeGasRefundTransaction(option) {
|
|
|
59
48
|
gasLimit: option.gasLimit,
|
|
60
49
|
to: option.token.contractAddress,
|
|
61
50
|
value: 0,
|
|
62
|
-
data: new ethers.ethers.
|
|
51
|
+
data: new ethers.ethers.Interface([{
|
|
63
52
|
constant: false,
|
|
64
53
|
inputs: [{
|
|
65
54
|
type: 'address'
|
|
@@ -69,7 +58,7 @@ function encodeGasRefundTransaction(option) {
|
|
|
69
58
|
name: 'transfer',
|
|
70
59
|
outputs: [],
|
|
71
60
|
type: 'function'
|
|
72
|
-
}]).encodeFunctionData('transfer', [option.to,
|
|
61
|
+
}]).encodeFunctionData('transfer', [option.to, utils.toHexString(value)])
|
|
73
62
|
}];
|
|
74
63
|
default:
|
|
75
64
|
throw new Error(`Unhandled fee token type ${option.token.type}`);
|
|
@@ -80,7 +69,6 @@ class AccountSigner {
|
|
|
80
69
|
this.account = account;
|
|
81
70
|
this.chainId = chainId;
|
|
82
71
|
this.options = options;
|
|
83
|
-
this._isSigner = true;
|
|
84
72
|
}
|
|
85
73
|
get provider() {
|
|
86
74
|
return this.account.providerFor(this.chainId);
|
|
@@ -92,6 +80,10 @@ class AccountSigner {
|
|
|
92
80
|
var _this$options$cantVal, _this$options;
|
|
93
81
|
return this.account.signMessage(message, this.chainId, (_this$options$cantVal = (_this$options = this.options) == null ? void 0 : _this$options.cantValidateBehavior) != null ? _this$options$cantVal : 'throw');
|
|
94
82
|
}
|
|
83
|
+
signTypedData(domain, types, value) {
|
|
84
|
+
var _this$options$cantVal2, _this$options2;
|
|
85
|
+
return this.account.signTypedData(domain, types, value, this.chainId, (_this$options$cantVal2 = (_this$options2 = this.options) == null ? void 0 : _this$options2.cantValidateBehavior) != null ? _this$options$cantVal2 : 'throw');
|
|
86
|
+
}
|
|
95
87
|
async defaultSelectFee(_txs, options) {
|
|
96
88
|
// If no options, return undefined
|
|
97
89
|
if (options.length === 0) return undefined;
|
|
@@ -113,33 +105,32 @@ class AccountSigner {
|
|
|
113
105
|
if (option.token.type === relayer.proto.FeeTokenType.UNKNOWN) {
|
|
114
106
|
// Native token
|
|
115
107
|
const balance = await this.getBalance();
|
|
116
|
-
if (balance
|
|
108
|
+
if (balance >= BigInt(option.value)) {
|
|
117
109
|
return option;
|
|
118
110
|
}
|
|
119
111
|
} else if (option.token.contractAddress && option.token.type === relayer.proto.FeeTokenType.ERC20_TOKEN) {
|
|
120
112
|
// ERC20 token
|
|
121
113
|
const token = new ethers.ethers.Contract(option.token.contractAddress, balanceOfAbi, this.provider);
|
|
122
114
|
const balance = await token.balanceOf(this.account.address);
|
|
123
|
-
if (balance
|
|
115
|
+
if (balance >= BigInt(option.value)) {
|
|
124
116
|
return option;
|
|
125
117
|
}
|
|
126
118
|
} else ;
|
|
127
119
|
}
|
|
128
120
|
throw new Error('No fee option available - not enough balance');
|
|
129
121
|
}
|
|
130
|
-
async sendTransaction(
|
|
131
|
-
var _this$options$stubSig, _this$
|
|
132
|
-
const txs = isDeferrable(txsPromise) ? await ethers.ethers.utils.resolveProperties(txsPromise) : txsPromise;
|
|
122
|
+
async sendTransaction(txs, options) {
|
|
123
|
+
var _this$options$stubSig, _this$options3, _this$options$selectF, _this$options4, _this$options5;
|
|
133
124
|
const prepare = await this.account.prepareTransactions({
|
|
134
125
|
txs,
|
|
135
126
|
chainId: this.chainId,
|
|
136
|
-
stubSignatureOverrides: (_this$options$stubSig = (_this$
|
|
127
|
+
stubSignatureOverrides: (_this$options$stubSig = (_this$options3 = this.options) == null ? void 0 : _this$options3.stubSignatureOverrides) != null ? _this$options$stubSig : new Map(),
|
|
137
128
|
simulateForFeeOptions: options == null ? void 0 : options.simulateForFeeOptions
|
|
138
129
|
});
|
|
139
|
-
const selectMethod = (_this$options$selectF = (_this$
|
|
130
|
+
const selectMethod = (_this$options$selectF = (_this$options4 = this.options) == null ? void 0 : _this$options4.selectFee) != null ? _this$options$selectF : this.defaultSelectFee.bind(this);
|
|
140
131
|
const feeOption = await selectMethod(txs, prepare.feeOptions);
|
|
141
132
|
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)];
|
|
142
|
-
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$
|
|
133
|
+
return this.account.sendTransaction(finalTransactions, this.chainId, prepare.feeQuote, undefined, undefined, ((_this$options5 = this.options) == null ? void 0 : _this$options5.nonceSpace) !== undefined ? {
|
|
143
134
|
nonceSpace: this.options.nonceSpace
|
|
144
135
|
} : undefined); // Will always have a transaction response
|
|
145
136
|
}
|
|
@@ -147,7 +138,9 @@ class AccountSigner {
|
|
|
147
138
|
return this.provider.getBalance(this.account.address, blockTag);
|
|
148
139
|
}
|
|
149
140
|
call(transaction, blockTag) {
|
|
150
|
-
return this.provider.call(transaction,
|
|
141
|
+
return this.provider.call(_extends({}, transaction, {
|
|
142
|
+
blockTag
|
|
143
|
+
}));
|
|
151
144
|
}
|
|
152
145
|
async resolveName(name) {
|
|
153
146
|
const res = await this.provider.resolveName(name);
|
|
@@ -167,7 +160,7 @@ class AccountSigner {
|
|
|
167
160
|
throw new Error('Method not implemented.');
|
|
168
161
|
}
|
|
169
162
|
getChainId() {
|
|
170
|
-
return Promise.resolve(
|
|
163
|
+
return Promise.resolve(Number(this.chainId));
|
|
171
164
|
}
|
|
172
165
|
getGasPrice() {
|
|
173
166
|
throw new Error('Method not implemented.');
|
|
@@ -175,10 +168,16 @@ class AccountSigner {
|
|
|
175
168
|
getFeeData() {
|
|
176
169
|
throw new Error('Method not implemented.');
|
|
177
170
|
}
|
|
171
|
+
getNonce(blockTag) {
|
|
172
|
+
throw new Error('Method not implemented.');
|
|
173
|
+
}
|
|
174
|
+
populateCall(tx) {
|
|
175
|
+
throw new Error('Method not implemented.');
|
|
176
|
+
}
|
|
178
177
|
checkTransaction(transaction) {
|
|
179
178
|
throw new Error('Method not implemented.');
|
|
180
179
|
}
|
|
181
|
-
populateTransaction(
|
|
180
|
+
async populateTransaction(tx) {
|
|
182
181
|
throw new Error('Method not implemented.');
|
|
183
182
|
}
|
|
184
183
|
_checkProvider(operation) {
|
|
@@ -197,7 +196,7 @@ class Chain0Reader {
|
|
|
197
196
|
return undefined;
|
|
198
197
|
}
|
|
199
198
|
async nonce(_wallet, _space) {
|
|
200
|
-
return
|
|
199
|
+
return 0n;
|
|
201
200
|
}
|
|
202
201
|
async isValidSignature(_wallet, _digest, _signature) {
|
|
203
202
|
throw new Error('Method not supported.');
|
|
@@ -214,7 +213,7 @@ class Account {
|
|
|
214
213
|
this.orchestrator = void 0;
|
|
215
214
|
this.jwt = void 0;
|
|
216
215
|
this.projectAccessKey = void 0;
|
|
217
|
-
this.address = ethers.ethers.
|
|
216
|
+
this.address = ethers.ethers.getAddress(options.address);
|
|
218
217
|
this.contexts = options.contexts;
|
|
219
218
|
this.tracker = options.tracker;
|
|
220
219
|
this.networks = options.networks;
|
|
@@ -264,21 +263,25 @@ class Account {
|
|
|
264
263
|
};
|
|
265
264
|
}
|
|
266
265
|
network(chainId) {
|
|
267
|
-
const tcid =
|
|
268
|
-
const found = this.networks.find(n => tcid
|
|
266
|
+
const tcid = BigInt(chainId);
|
|
267
|
+
const found = this.networks.find(n => tcid === BigInt(n.chainId));
|
|
269
268
|
if (!found) throw new Error(`Network not found for chainId ${chainId}`);
|
|
270
269
|
return found;
|
|
271
270
|
}
|
|
272
271
|
providerFor(chainId) {
|
|
273
272
|
const found = this.network(chainId);
|
|
274
|
-
if (!found.provider && !found.rpcUrl)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
if (!found.provider && !found.rpcUrl) {
|
|
274
|
+
throw new Error(`Provider not found for chainId ${chainId}`);
|
|
275
|
+
}
|
|
276
|
+
const network = new ethers.ethers.Network(found.name, found.chainId);
|
|
277
|
+
return found.provider || new ethers.ethers.JsonRpcProvider(utils.getFetchRequest(found.rpcUrl, this.projectAccessKey, this.jwt), network, {
|
|
278
|
+
staticNetwork: network
|
|
278
279
|
});
|
|
279
280
|
}
|
|
280
281
|
reader(chainId) {
|
|
281
|
-
if (
|
|
282
|
+
if (BigInt(chainId) === 0n) {
|
|
283
|
+
return new Chain0Reader();
|
|
284
|
+
}
|
|
282
285
|
|
|
283
286
|
// TODO: Networks should be able to provide a reader directly
|
|
284
287
|
// and we should default to the on-chain reader
|
|
@@ -310,7 +313,7 @@ class Account {
|
|
|
310
313
|
return this.walletFor(chainId, this.contextFor(status.version), status.config, coder);
|
|
311
314
|
}
|
|
312
315
|
walletFor(chainId, context, config, coders) {
|
|
313
|
-
const isNetworkZero =
|
|
316
|
+
const isNetworkZero = BigInt(chainId) === 0n;
|
|
314
317
|
return new wallet.Wallet({
|
|
315
318
|
config,
|
|
316
319
|
context,
|
|
@@ -512,7 +515,7 @@ class Account {
|
|
|
512
515
|
return coder.trim(chainedSignature);
|
|
513
516
|
}
|
|
514
517
|
async publishWitness() {
|
|
515
|
-
const digest = ethers.ethers.
|
|
518
|
+
const digest = ethers.ethers.id(`This is a Sequence account woo! ${Date.now()}`);
|
|
516
519
|
const signature = await this.signDigest(digest, 0, false);
|
|
517
520
|
const decoded = this.coders.signature.decode(signature);
|
|
518
521
|
const signatures = this.coders.signature.signaturesOfDecoded(decoded);
|
|
@@ -530,7 +533,7 @@ class Account {
|
|
|
530
533
|
// So we ignore the state on "chain zero" and instead use one of the states of the networks
|
|
531
534
|
// wallet-webapp should ensure the wallet is as migrated as possible, trying to mimic
|
|
532
535
|
// the behaviour of being migrated on all chains
|
|
533
|
-
const chainRef =
|
|
536
|
+
const chainRef = BigInt(chainId) === 0n ? this.networks[0].chainId : chainId;
|
|
534
537
|
const status = await this.status(chainRef);
|
|
535
538
|
this.mustBeFullyMigrated(status);
|
|
536
539
|
|
|
@@ -561,11 +564,11 @@ class Account {
|
|
|
561
564
|
}
|
|
562
565
|
buildOnChainSignature(digest) {
|
|
563
566
|
const subdigest = core.commons.signature.subdigestOf({
|
|
564
|
-
digest: ethers.ethers.
|
|
567
|
+
digest: ethers.ethers.hexlify(digest),
|
|
565
568
|
chainId: 0,
|
|
566
569
|
address: this.address
|
|
567
570
|
});
|
|
568
|
-
const hexSubdigest = ethers.ethers.
|
|
571
|
+
const hexSubdigest = ethers.ethers.hexlify(subdigest);
|
|
569
572
|
const config = this.coders.config.fromSimple({
|
|
570
573
|
// Threshold *only* needs to be > 0, this is not a magic number
|
|
571
574
|
// we only use 2 ** 15 because it may lead to lower gas costs in some chains
|
|
@@ -574,7 +577,7 @@ class Account {
|
|
|
574
577
|
signers: [],
|
|
575
578
|
subdigests: [hexSubdigest]
|
|
576
579
|
});
|
|
577
|
-
const walletInterface = new ethers.ethers.
|
|
580
|
+
const walletInterface = new ethers.ethers.Interface(abi.walletContracts.mainModule.abi);
|
|
578
581
|
const bundle = {
|
|
579
582
|
entrypoint: this.address,
|
|
580
583
|
transactions: [{
|
|
@@ -609,13 +612,13 @@ class Account {
|
|
|
609
612
|
if (bootstrapBundle.transactions.length === 0) {
|
|
610
613
|
throw new Error('Cannot build EIP-6492 signature without bootstrap transactions');
|
|
611
614
|
}
|
|
612
|
-
const encoded = ethers.ethers.
|
|
613
|
-
return ethers.ethers.
|
|
615
|
+
const encoded = ethers.ethers.AbiCoder.defaultAbiCoder().encode(['address', 'bytes', 'bytes'], [bootstrapBundle.entrypoint, core.commons.transaction.encodeBundleExecData(bootstrapBundle), signature]);
|
|
616
|
+
return ethers.ethers.solidityPacked(['bytes', 'bytes32'], [encoded, core.commons.EIP6492.EIP_6492_SUFFIX]);
|
|
614
617
|
}
|
|
615
618
|
async editConfig(changes) {
|
|
616
619
|
const currentConfig = await this.status(0).then(s => s.config);
|
|
617
620
|
const newConfig = this.coders.config.editConfig(currentConfig, _extends({}, changes, {
|
|
618
|
-
checkpoint: this.coders.config.checkpointOf(currentConfig)
|
|
621
|
+
checkpoint: this.coders.config.checkpointOf(currentConfig) + 1n
|
|
619
622
|
}));
|
|
620
623
|
return this.updateConfig(newConfig);
|
|
621
624
|
}
|
|
@@ -675,7 +678,6 @@ class Account {
|
|
|
675
678
|
const deployTransaction = wallet.Wallet.buildDeployTransaction(status.original.context, status.original.imageHash);
|
|
676
679
|
transactions.push(...deployTransaction.transactions);
|
|
677
680
|
}
|
|
678
|
-
transactions.length;
|
|
679
681
|
|
|
680
682
|
// Get pending migrations
|
|
681
683
|
transactions.push(...status.signedMigrations.map(m => ({
|
|
@@ -719,7 +721,7 @@ class Account {
|
|
|
719
721
|
}), feeQuote);
|
|
720
722
|
}
|
|
721
723
|
signMessage(message, chainId, cantValidateBehavior = 'ignore') {
|
|
722
|
-
return this.signDigest(ethers.ethers.
|
|
724
|
+
return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior);
|
|
723
725
|
}
|
|
724
726
|
async signTransactions(txs, chainId, pstatus, options) {
|
|
725
727
|
const status = pstatus || (await this.status(chainId));
|
|
@@ -845,7 +847,7 @@ class Account {
|
|
|
845
847
|
const stubSignature = wallet.coders.config.buildStubSignature(wallet.config, stubSignatureOverrides);
|
|
846
848
|
|
|
847
849
|
// Now we can decorate the transactions as always, but we need to manually build the signed bundle
|
|
848
|
-
const intentId = ethers.ethers.
|
|
850
|
+
const intentId = ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
849
851
|
const signedBundle = {
|
|
850
852
|
chainId,
|
|
851
853
|
intent: {
|