@0xsequence/account 1.2.0 → 1.2.1
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 +25 -25
- package/dist/0xsequence-account.cjs.prod.js +25 -25
- package/dist/0xsequence-account.esm.js +25 -25
- package/dist/declarations/src/signer.d.ts +4 -4
- package/package.json +10 -10
- package/src/signer.ts +76 -78
- package/src/utils.ts +3 -3
|
@@ -29,7 +29,7 @@ function isPromise(value) {
|
|
|
29
29
|
}
|
|
30
30
|
function isDeferrable(value) {
|
|
31
31
|
// The value is deferrable if any of the properties is a Promises
|
|
32
|
-
if (typeof value ===
|
|
32
|
+
if (typeof value === 'object') {
|
|
33
33
|
return Object.keys(value).some(key => isPromise(value[key]));
|
|
34
34
|
}
|
|
35
35
|
return false;
|
|
@@ -59,15 +59,15 @@ function encodeGasRefundTransaction(option) {
|
|
|
59
59
|
to: option.token.contractAddress,
|
|
60
60
|
value: 0,
|
|
61
61
|
data: new ethers.ethers.utils.Interface([{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
constant: false,
|
|
63
|
+
inputs: [{
|
|
64
|
+
type: 'address'
|
|
65
65
|
}, {
|
|
66
|
-
|
|
66
|
+
type: 'uint256'
|
|
67
67
|
}],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
name: 'transfer',
|
|
69
|
+
outputs: [],
|
|
70
|
+
type: 'function'
|
|
71
71
|
}]).encodeFunctionData('transfer', [option.to, value.toHexString()])
|
|
72
72
|
}];
|
|
73
73
|
default:
|
|
@@ -98,15 +98,15 @@ class AccountSigner {
|
|
|
98
98
|
// If there are multiple options, try them one by one
|
|
99
99
|
// until we find one that satisfies the balance requirement
|
|
100
100
|
const balanceOfAbi = [{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
constant: true,
|
|
102
|
+
inputs: [{
|
|
103
|
+
type: 'address'
|
|
104
104
|
}],
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
name: 'balanceOf',
|
|
106
|
+
outputs: [{
|
|
107
|
+
type: 'uint256'
|
|
108
108
|
}],
|
|
109
|
-
|
|
109
|
+
type: 'function'
|
|
110
110
|
}];
|
|
111
111
|
for (const option of options) {
|
|
112
112
|
if (option.token.type === relayer.proto.FeeTokenType.UNKNOWN) {
|
|
@@ -124,7 +124,7 @@ class AccountSigner {
|
|
|
124
124
|
}
|
|
125
125
|
} else ;
|
|
126
126
|
}
|
|
127
|
-
throw new Error(
|
|
127
|
+
throw new Error('No fee option available - not enough balance');
|
|
128
128
|
}
|
|
129
129
|
async sendTransaction(txsPromise) {
|
|
130
130
|
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4;
|
|
@@ -153,34 +153,34 @@ class AccountSigner {
|
|
|
153
153
|
return res;
|
|
154
154
|
}
|
|
155
155
|
connect(_provider) {
|
|
156
|
-
throw new Error(
|
|
156
|
+
throw new Error('Method not implemented.');
|
|
157
157
|
}
|
|
158
158
|
signTransaction(transaction) {
|
|
159
|
-
throw new Error(
|
|
159
|
+
throw new Error('Method not implemented.');
|
|
160
160
|
}
|
|
161
161
|
getTransactionCount(blockTag) {
|
|
162
|
-
throw new Error(
|
|
162
|
+
throw new Error('Method not implemented.');
|
|
163
163
|
}
|
|
164
164
|
estimateGas(transaction) {
|
|
165
|
-
throw new Error(
|
|
165
|
+
throw new Error('Method not implemented.');
|
|
166
166
|
}
|
|
167
167
|
getChainId() {
|
|
168
168
|
return Promise.resolve(ethers.ethers.BigNumber.from(this.chainId).toNumber());
|
|
169
169
|
}
|
|
170
170
|
getGasPrice() {
|
|
171
|
-
throw new Error(
|
|
171
|
+
throw new Error('Method not implemented.');
|
|
172
172
|
}
|
|
173
173
|
getFeeData() {
|
|
174
|
-
throw new Error(
|
|
174
|
+
throw new Error('Method not implemented.');
|
|
175
175
|
}
|
|
176
176
|
checkTransaction(transaction) {
|
|
177
|
-
throw new Error(
|
|
177
|
+
throw new Error('Method not implemented.');
|
|
178
178
|
}
|
|
179
179
|
populateTransaction(transaction) {
|
|
180
|
-
throw new Error(
|
|
180
|
+
throw new Error('Method not implemented.');
|
|
181
181
|
}
|
|
182
182
|
_checkProvider(operation) {
|
|
183
|
-
throw new Error(
|
|
183
|
+
throw new Error('Method not implemented.');
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -29,7 +29,7 @@ function isPromise(value) {
|
|
|
29
29
|
}
|
|
30
30
|
function isDeferrable(value) {
|
|
31
31
|
// The value is deferrable if any of the properties is a Promises
|
|
32
|
-
if (typeof value ===
|
|
32
|
+
if (typeof value === 'object') {
|
|
33
33
|
return Object.keys(value).some(key => isPromise(value[key]));
|
|
34
34
|
}
|
|
35
35
|
return false;
|
|
@@ -59,15 +59,15 @@ function encodeGasRefundTransaction(option) {
|
|
|
59
59
|
to: option.token.contractAddress,
|
|
60
60
|
value: 0,
|
|
61
61
|
data: new ethers.ethers.utils.Interface([{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
constant: false,
|
|
63
|
+
inputs: [{
|
|
64
|
+
type: 'address'
|
|
65
65
|
}, {
|
|
66
|
-
|
|
66
|
+
type: 'uint256'
|
|
67
67
|
}],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
name: 'transfer',
|
|
69
|
+
outputs: [],
|
|
70
|
+
type: 'function'
|
|
71
71
|
}]).encodeFunctionData('transfer', [option.to, value.toHexString()])
|
|
72
72
|
}];
|
|
73
73
|
default:
|
|
@@ -98,15 +98,15 @@ class AccountSigner {
|
|
|
98
98
|
// If there are multiple options, try them one by one
|
|
99
99
|
// until we find one that satisfies the balance requirement
|
|
100
100
|
const balanceOfAbi = [{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
constant: true,
|
|
102
|
+
inputs: [{
|
|
103
|
+
type: 'address'
|
|
104
104
|
}],
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
name: 'balanceOf',
|
|
106
|
+
outputs: [{
|
|
107
|
+
type: 'uint256'
|
|
108
108
|
}],
|
|
109
|
-
|
|
109
|
+
type: 'function'
|
|
110
110
|
}];
|
|
111
111
|
for (const option of options) {
|
|
112
112
|
if (option.token.type === relayer.proto.FeeTokenType.UNKNOWN) {
|
|
@@ -124,7 +124,7 @@ class AccountSigner {
|
|
|
124
124
|
}
|
|
125
125
|
} else ;
|
|
126
126
|
}
|
|
127
|
-
throw new Error(
|
|
127
|
+
throw new Error('No fee option available - not enough balance');
|
|
128
128
|
}
|
|
129
129
|
async sendTransaction(txsPromise) {
|
|
130
130
|
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4;
|
|
@@ -153,34 +153,34 @@ class AccountSigner {
|
|
|
153
153
|
return res;
|
|
154
154
|
}
|
|
155
155
|
connect(_provider) {
|
|
156
|
-
throw new Error(
|
|
156
|
+
throw new Error('Method not implemented.');
|
|
157
157
|
}
|
|
158
158
|
signTransaction(transaction) {
|
|
159
|
-
throw new Error(
|
|
159
|
+
throw new Error('Method not implemented.');
|
|
160
160
|
}
|
|
161
161
|
getTransactionCount(blockTag) {
|
|
162
|
-
throw new Error(
|
|
162
|
+
throw new Error('Method not implemented.');
|
|
163
163
|
}
|
|
164
164
|
estimateGas(transaction) {
|
|
165
|
-
throw new Error(
|
|
165
|
+
throw new Error('Method not implemented.');
|
|
166
166
|
}
|
|
167
167
|
getChainId() {
|
|
168
168
|
return Promise.resolve(ethers.ethers.BigNumber.from(this.chainId).toNumber());
|
|
169
169
|
}
|
|
170
170
|
getGasPrice() {
|
|
171
|
-
throw new Error(
|
|
171
|
+
throw new Error('Method not implemented.');
|
|
172
172
|
}
|
|
173
173
|
getFeeData() {
|
|
174
|
-
throw new Error(
|
|
174
|
+
throw new Error('Method not implemented.');
|
|
175
175
|
}
|
|
176
176
|
checkTransaction(transaction) {
|
|
177
|
-
throw new Error(
|
|
177
|
+
throw new Error('Method not implemented.');
|
|
178
178
|
}
|
|
179
179
|
populateTransaction(transaction) {
|
|
180
|
-
throw new Error(
|
|
180
|
+
throw new Error('Method not implemented.');
|
|
181
181
|
}
|
|
182
182
|
_checkProvider(operation) {
|
|
183
|
-
throw new Error(
|
|
183
|
+
throw new Error('Method not implemented.');
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -25,7 +25,7 @@ function isPromise(value) {
|
|
|
25
25
|
}
|
|
26
26
|
function isDeferrable(value) {
|
|
27
27
|
// The value is deferrable if any of the properties is a Promises
|
|
28
|
-
if (typeof value ===
|
|
28
|
+
if (typeof value === 'object') {
|
|
29
29
|
return Object.keys(value).some(key => isPromise(value[key]));
|
|
30
30
|
}
|
|
31
31
|
return false;
|
|
@@ -55,15 +55,15 @@ function encodeGasRefundTransaction(option) {
|
|
|
55
55
|
to: option.token.contractAddress,
|
|
56
56
|
value: 0,
|
|
57
57
|
data: new ethers.utils.Interface([{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
constant: false,
|
|
59
|
+
inputs: [{
|
|
60
|
+
type: 'address'
|
|
61
61
|
}, {
|
|
62
|
-
|
|
62
|
+
type: 'uint256'
|
|
63
63
|
}],
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
name: 'transfer',
|
|
65
|
+
outputs: [],
|
|
66
|
+
type: 'function'
|
|
67
67
|
}]).encodeFunctionData('transfer', [option.to, value.toHexString()])
|
|
68
68
|
}];
|
|
69
69
|
default:
|
|
@@ -94,15 +94,15 @@ class AccountSigner {
|
|
|
94
94
|
// If there are multiple options, try them one by one
|
|
95
95
|
// until we find one that satisfies the balance requirement
|
|
96
96
|
const balanceOfAbi = [{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
constant: true,
|
|
98
|
+
inputs: [{
|
|
99
|
+
type: 'address'
|
|
100
100
|
}],
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
name: 'balanceOf',
|
|
102
|
+
outputs: [{
|
|
103
|
+
type: 'uint256'
|
|
104
104
|
}],
|
|
105
|
-
|
|
105
|
+
type: 'function'
|
|
106
106
|
}];
|
|
107
107
|
for (const option of options) {
|
|
108
108
|
if (option.token.type === proto.FeeTokenType.UNKNOWN) {
|
|
@@ -120,7 +120,7 @@ class AccountSigner {
|
|
|
120
120
|
}
|
|
121
121
|
} else ;
|
|
122
122
|
}
|
|
123
|
-
throw new Error(
|
|
123
|
+
throw new Error('No fee option available - not enough balance');
|
|
124
124
|
}
|
|
125
125
|
async sendTransaction(txsPromise) {
|
|
126
126
|
var _this$options$stubSig, _this$options2, _this$options$selectF, _this$options3, _this$options4;
|
|
@@ -149,34 +149,34 @@ class AccountSigner {
|
|
|
149
149
|
return res;
|
|
150
150
|
}
|
|
151
151
|
connect(_provider) {
|
|
152
|
-
throw new Error(
|
|
152
|
+
throw new Error('Method not implemented.');
|
|
153
153
|
}
|
|
154
154
|
signTransaction(transaction) {
|
|
155
|
-
throw new Error(
|
|
155
|
+
throw new Error('Method not implemented.');
|
|
156
156
|
}
|
|
157
157
|
getTransactionCount(blockTag) {
|
|
158
|
-
throw new Error(
|
|
158
|
+
throw new Error('Method not implemented.');
|
|
159
159
|
}
|
|
160
160
|
estimateGas(transaction) {
|
|
161
|
-
throw new Error(
|
|
161
|
+
throw new Error('Method not implemented.');
|
|
162
162
|
}
|
|
163
163
|
getChainId() {
|
|
164
164
|
return Promise.resolve(ethers.BigNumber.from(this.chainId).toNumber());
|
|
165
165
|
}
|
|
166
166
|
getGasPrice() {
|
|
167
|
-
throw new Error(
|
|
167
|
+
throw new Error('Method not implemented.');
|
|
168
168
|
}
|
|
169
169
|
getFeeData() {
|
|
170
|
-
throw new Error(
|
|
170
|
+
throw new Error('Method not implemented.');
|
|
171
171
|
}
|
|
172
172
|
checkTransaction(transaction) {
|
|
173
|
-
throw new Error(
|
|
173
|
+
throw new Error('Method not implemented.');
|
|
174
174
|
}
|
|
175
175
|
populateTransaction(transaction) {
|
|
176
|
-
throw new Error(
|
|
176
|
+
throw new Error('Method not implemented.');
|
|
177
177
|
}
|
|
178
178
|
_checkProvider(operation) {
|
|
179
|
-
throw new Error(
|
|
179
|
+
throw new Error('Method not implemented.');
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ChainId } from
|
|
1
|
+
import { ChainId } from '@0xsequence/network';
|
|
2
2
|
import { Account } from "./account.js";
|
|
3
|
-
import { ethers } from
|
|
4
|
-
import { commons } from
|
|
5
|
-
import { FeeOption } from
|
|
3
|
+
import { ethers } from 'ethers';
|
|
4
|
+
import { commons } from '@0xsequence/core';
|
|
5
|
+
import { FeeOption } from '@0xsequence/relayer';
|
|
6
6
|
export type AccountSignerOptions = {
|
|
7
7
|
nonceSpace?: ethers.BigNumberish;
|
|
8
8
|
cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/account",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "tools for migrating sequence wallets to new versions",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/account",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^5.5.2",
|
|
13
|
-
"@0xsequence/core": "1.2.
|
|
14
|
-
"@0xsequence/migration": "1.2.
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/wallet": "1.2.
|
|
13
|
+
"@0xsequence/core": "1.2.1",
|
|
14
|
+
"@0xsequence/migration": "1.2.1",
|
|
15
|
+
"@0xsequence/network": "1.2.1",
|
|
16
|
+
"@0xsequence/relayer": "1.2.1",
|
|
17
|
+
"@0xsequence/utils": "1.2.1",
|
|
18
|
+
"@0xsequence/sessions": "1.2.1",
|
|
19
|
+
"@0xsequence/wallet": "1.2.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
23
23
|
"nyc": "^15.1.0",
|
|
24
|
-
"@0xsequence/signhub": "1.2.
|
|
25
|
-
"@0xsequence/tests": "1.2.
|
|
24
|
+
"@0xsequence/signhub": "1.2.1",
|
|
25
|
+
"@0xsequence/tests": "1.2.1"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
package/src/signer.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ChainId } from
|
|
2
|
-
import { Account } from
|
|
3
|
-
import { ethers } from
|
|
4
|
-
import { commons } from
|
|
5
|
-
import { FeeOption, proto } from
|
|
6
|
-
import { isDeferrable } from
|
|
1
|
+
import { ChainId } from '@0xsequence/network'
|
|
2
|
+
import { Account } from './account'
|
|
3
|
+
import { ethers } from 'ethers'
|
|
4
|
+
import { commons } from '@0xsequence/core'
|
|
5
|
+
import { FeeOption, proto } from '@0xsequence/relayer'
|
|
6
|
+
import { isDeferrable } from './utils'
|
|
7
7
|
|
|
8
8
|
export type AccountSignerOptions = {
|
|
9
|
-
nonceSpace?: ethers.BigNumberish
|
|
10
|
-
cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'
|
|
11
|
-
stubSignatureOverrides?: Map<string, string
|
|
9
|
+
nonceSpace?: ethers.BigNumberish
|
|
10
|
+
cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'
|
|
11
|
+
stubSignatureOverrides?: Map<string, string>
|
|
12
12
|
selectFee?: (
|
|
13
13
|
txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish,
|
|
14
14
|
options: FeeOption[]
|
|
@@ -22,37 +22,40 @@ function encodeGasRefundTransaction(option?: FeeOption) {
|
|
|
22
22
|
|
|
23
23
|
switch (option.token.type) {
|
|
24
24
|
case proto.FeeTokenType.UNKNOWN:
|
|
25
|
-
return [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
delegateCall: false,
|
|
28
|
+
revertOnError: true,
|
|
29
|
+
gasLimit: option.gasLimit,
|
|
30
|
+
to: option.to,
|
|
31
|
+
value: value.toHexString(),
|
|
32
|
+
data: []
|
|
33
|
+
}
|
|
34
|
+
]
|
|
33
35
|
|
|
34
36
|
case proto.FeeTokenType.ERC20_TOKEN:
|
|
35
37
|
if (!option.token.contractAddress) {
|
|
36
38
|
throw new Error(`No contract address for ERC-20 fee option`)
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
return [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
delegateCall: false,
|
|
44
|
+
revertOnError: true,
|
|
45
|
+
gasLimit: option.gasLimit,
|
|
46
|
+
to: option.token.contractAddress,
|
|
47
|
+
value: 0,
|
|
48
|
+
data: new ethers.utils.Interface([
|
|
49
|
+
{
|
|
50
|
+
constant: false,
|
|
51
|
+
inputs: [{ type: 'address' }, { type: 'uint256' }],
|
|
52
|
+
name: 'transfer',
|
|
53
|
+
outputs: [],
|
|
54
|
+
type: 'function'
|
|
55
|
+
}
|
|
56
|
+
]).encodeFunctionData('transfer', [option.to, value.toHexString()])
|
|
57
|
+
}
|
|
58
|
+
]
|
|
56
59
|
|
|
57
60
|
default:
|
|
58
61
|
throw new Error(`Unhandled fee token type ${option.token.type}`)
|
|
@@ -62,7 +65,7 @@ function encodeGasRefundTransaction(option?: FeeOption) {
|
|
|
62
65
|
export class AccountSigner implements ethers.Signer {
|
|
63
66
|
public readonly _isSigner = true
|
|
64
67
|
|
|
65
|
-
constructor
|
|
68
|
+
constructor(
|
|
66
69
|
public account: Account,
|
|
67
70
|
public chainId: ChainId,
|
|
68
71
|
public readonly options?: AccountSignerOptions
|
|
@@ -76,14 +79,8 @@ export class AccountSigner implements ethers.Signer {
|
|
|
76
79
|
return this.account.address
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
signMessage(
|
|
80
|
-
message
|
|
81
|
-
): Promise<string> {
|
|
82
|
-
return this.account.signMessage(
|
|
83
|
-
message,
|
|
84
|
-
this.chainId,
|
|
85
|
-
this.options?.cantValidateBehavior ?? 'throw'
|
|
86
|
-
)
|
|
82
|
+
signMessage(message: string | ethers.utils.Bytes): Promise<string> {
|
|
83
|
+
return this.account.signMessage(message, this.chainId, this.options?.cantValidateBehavior ?? 'throw')
|
|
87
84
|
}
|
|
88
85
|
|
|
89
86
|
private async defaultSelectFee(
|
|
@@ -95,14 +92,16 @@ export class AccountSigner implements ethers.Signer {
|
|
|
95
92
|
|
|
96
93
|
// If there are multiple options, try them one by one
|
|
97
94
|
// until we find one that satisfies the balance requirement
|
|
98
|
-
const balanceOfAbi = [
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
const balanceOfAbi = [
|
|
96
|
+
{
|
|
97
|
+
constant: true,
|
|
98
|
+
inputs: [{ type: 'address' }],
|
|
99
|
+
name: 'balanceOf',
|
|
100
|
+
outputs: [{ type: 'uint256' }],
|
|
101
|
+
type: 'function'
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
|
|
106
105
|
for (const option of options) {
|
|
107
106
|
if (option.token.type === proto.FeeTokenType.UNKNOWN) {
|
|
108
107
|
// Native token
|
|
@@ -122,14 +121,14 @@ export class AccountSigner implements ethers.Signer {
|
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
throw new Error(
|
|
124
|
+
throw new Error('No fee option available - not enough balance')
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
async sendTransaction(
|
|
129
128
|
txsPromise: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish
|
|
130
129
|
): Promise<ethers.providers.TransactionResponse> {
|
|
131
|
-
const txs = isDeferrable(txsPromise)
|
|
132
|
-
await ethers.utils.resolveProperties(txsPromise as ethers.utils.Deferrable<ethers.providers.TransactionRequest>)
|
|
130
|
+
const txs = isDeferrable(txsPromise)
|
|
131
|
+
? await ethers.utils.resolveProperties(txsPromise as ethers.utils.Deferrable<ethers.providers.TransactionRequest>)
|
|
133
132
|
: txsPromise
|
|
134
133
|
|
|
135
134
|
const prepare = await this.account.prepareTransactions({
|
|
@@ -141,10 +140,7 @@ export class AccountSigner implements ethers.Signer {
|
|
|
141
140
|
const selectMethod = this.options?.selectFee ?? this.defaultSelectFee.bind(this)
|
|
142
141
|
const feeOption = await selectMethod(txs, prepare.feeOptions)
|
|
143
142
|
|
|
144
|
-
const finalTransactions = [
|
|
145
|
-
...prepare.transactions,
|
|
146
|
-
...encodeGasRefundTransaction(feeOption)
|
|
147
|
-
]
|
|
143
|
+
const finalTransactions = [...prepare.transactions, ...encodeGasRefundTransaction(feeOption)]
|
|
148
144
|
|
|
149
145
|
return this.account.sendTransaction(
|
|
150
146
|
finalTransactions,
|
|
@@ -152,9 +148,11 @@ export class AccountSigner implements ethers.Signer {
|
|
|
152
148
|
prepare.feeQuote,
|
|
153
149
|
undefined,
|
|
154
150
|
undefined,
|
|
155
|
-
this.options?.nonceSpace
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
this.options?.nonceSpace
|
|
152
|
+
? {
|
|
153
|
+
nonceSpace: this.options.nonceSpace
|
|
154
|
+
}
|
|
155
|
+
: undefined
|
|
158
156
|
)
|
|
159
157
|
}
|
|
160
158
|
|
|
@@ -176,23 +174,19 @@ export class AccountSigner implements ethers.Signer {
|
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
connect(_provider: ethers.providers.Provider): ethers.Signer {
|
|
179
|
-
throw new Error(
|
|
177
|
+
throw new Error('Method not implemented.')
|
|
180
178
|
}
|
|
181
179
|
|
|
182
|
-
signTransaction(
|
|
183
|
-
|
|
184
|
-
): Promise<string> {
|
|
185
|
-
throw new Error("Method not implemented.")
|
|
180
|
+
signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string> {
|
|
181
|
+
throw new Error('Method not implemented.')
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
getTransactionCount(blockTag?: ethers.providers.BlockTag | undefined): Promise<number> {
|
|
189
|
-
throw new Error(
|
|
185
|
+
throw new Error('Method not implemented.')
|
|
190
186
|
}
|
|
191
187
|
|
|
192
|
-
estimateGas(
|
|
193
|
-
|
|
194
|
-
): Promise<ethers.BigNumber> {
|
|
195
|
-
throw new Error("Method not implemented.")
|
|
188
|
+
estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.BigNumber> {
|
|
189
|
+
throw new Error('Method not implemented.')
|
|
196
190
|
}
|
|
197
191
|
|
|
198
192
|
getChainId(): Promise<number> {
|
|
@@ -200,22 +194,26 @@ export class AccountSigner implements ethers.Signer {
|
|
|
200
194
|
}
|
|
201
195
|
|
|
202
196
|
getGasPrice(): Promise<ethers.BigNumber> {
|
|
203
|
-
throw new Error(
|
|
197
|
+
throw new Error('Method not implemented.')
|
|
204
198
|
}
|
|
205
199
|
|
|
206
200
|
getFeeData(): Promise<ethers.providers.FeeData> {
|
|
207
|
-
throw new Error(
|
|
201
|
+
throw new Error('Method not implemented.')
|
|
208
202
|
}
|
|
209
203
|
|
|
210
|
-
checkTransaction(
|
|
211
|
-
|
|
204
|
+
checkTransaction(
|
|
205
|
+
transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
|
|
206
|
+
): ethers.utils.Deferrable<ethers.providers.TransactionRequest> {
|
|
207
|
+
throw new Error('Method not implemented.')
|
|
212
208
|
}
|
|
213
209
|
|
|
214
|
-
populateTransaction(
|
|
215
|
-
|
|
210
|
+
populateTransaction(
|
|
211
|
+
transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
|
|
212
|
+
): Promise<ethers.providers.TransactionRequest> {
|
|
213
|
+
throw new Error('Method not implemented.')
|
|
216
214
|
}
|
|
217
215
|
|
|
218
216
|
_checkProvider(operation?: string | undefined): void {
|
|
219
|
-
throw new Error(
|
|
217
|
+
throw new Error('Method not implemented.')
|
|
220
218
|
}
|
|
221
219
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
2
|
|
|
3
3
|
function isPromise(value: any): value is Promise<any> {
|
|
4
4
|
return !!value && typeof value.then === 'function'
|
|
@@ -6,8 +6,8 @@ function isPromise(value: any): value is Promise<any> {
|
|
|
6
6
|
|
|
7
7
|
export function isDeferrable<T>(value: any): value is ethers.utils.Deferrable<T> {
|
|
8
8
|
// The value is deferrable if any of the properties is a Promises
|
|
9
|
-
if (typeof
|
|
10
|
-
return Object.keys(value).some(
|
|
9
|
+
if (typeof value === 'object') {
|
|
10
|
+
return Object.keys(value).some(key => isPromise(value[key]))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
return false
|