@exodus/ethereum-lib 5.6.0 → 5.8.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 +25 -0
- package/README.md +3 -0
- package/package.json +6 -9
- package/src/account-state/parse-legacy-balances.js +1 -1
- package/src/constants.js +2 -2
- package/src/create-contract/erc20.js +19 -19
- package/src/encode.js +14 -8
- package/src/sign-message.js +1 -1
- package/src/unsigned-tx/create-ethereumjs-tx.js +2 -4
- package/src/unsigned-tx/create-unsigned-tx.js +1 -2
- package/src/unsigned-tx/parse-unsigned-tx.js +3 -3
- package/src/utils/calculate-extra-eth.js +6 -1
- package/src/utils/index.js +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,31 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.8.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.7.0...@exodus/ethereum-lib@5.8.0) (2024-12-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat: migrate ethereum arbnova to be indexless (#4642)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## [5.7.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.6.0...@exodus/ethereum-lib@5.7.0) (2024-10-29)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* introduce exodus/ethereumjs ([#4339](https://github.com/ExodusMovement/assets/issues/4339)) ([e81d577](https://github.com/ExodusMovement/assets/commit/e81d5771c4956a22cfcf434a999310bbb5be81a3))
|
|
22
|
+
* load more imports from ethereumjs/util ([#4379](https://github.com/ExodusMovement/assets/issues/4379)) ([dead85c](https://github.com/ExodusMovement/assets/commit/dead85cfb55223c344af506d8d7ca7cf7eeb516c))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* remove stray direct dependencies ([#4176](https://github.com/ExodusMovement/assets/issues/4176)) ([c4f93fa](https://github.com/ExodusMovement/assets/commit/c4f93fad5a930b40d326d7add1093b2d4f243f2a))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
6
31
|
## [5.6.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-lib@5.5.0...@exodus/ethereum-lib@5.6.0) (2024-10-04)
|
|
7
32
|
|
|
8
33
|
|
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-lib",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"description": "Ethereum
|
|
3
|
+
"version": "5.8.0",
|
|
4
|
+
"description": "Ethereum utils, such as for cryptography, address encoding/decoding, transaction building, etc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"files": [
|
|
@@ -22,17 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@exodus/basic-utils": "^3.0.1",
|
|
25
|
-
"@exodus/currency": "^
|
|
26
|
-
"@exodus/
|
|
27
|
-
"@exodus/ethereumjs-common": "^2.4.0-exodus.6",
|
|
28
|
-
"@exodus/ethereumjs-tx": "^3.3.0-exodus.7",
|
|
29
|
-
"@exodus/ethereumjs-util": "^7.1.0-exodus.7",
|
|
25
|
+
"@exodus/currency": "^6.0.1",
|
|
26
|
+
"@exodus/ethereumjs": "^1.2.0",
|
|
30
27
|
"@exodus/key-utils": "^3.7.0",
|
|
31
28
|
"@exodus/models": "^12.0.1",
|
|
32
29
|
"@exodus/solidity-contract": "^1.1.3",
|
|
33
30
|
"@metamask/eth-sig-util": "^4.0.1",
|
|
34
31
|
"base-x": "^3.0.2",
|
|
35
|
-
"ethjs-util": "^0.1.6",
|
|
36
32
|
"lodash": "^4.17.15",
|
|
37
33
|
"minimalistic-assert": "^1.0.1",
|
|
38
34
|
"ms": "^2.1.1",
|
|
@@ -43,6 +39,7 @@
|
|
|
43
39
|
"@exodus/bitcoin-meta": "^2.0.0",
|
|
44
40
|
"@exodus/bsc-meta": "^2.0.0",
|
|
45
41
|
"@exodus/crypto": "^1.0.0-rc.13",
|
|
42
|
+
"@exodus/ethereum-meta": "^2.0.0",
|
|
46
43
|
"@exodus/ethereumclassic-meta": "^2.0.0",
|
|
47
44
|
"@exodus/fantommainnet-meta": "^2.0.0",
|
|
48
45
|
"@exodus/matic-meta": "^2.0.0"
|
|
@@ -54,5 +51,5 @@
|
|
|
54
51
|
"type": "git",
|
|
55
52
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
56
53
|
},
|
|
57
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "e533b61cf7895212101c3be53f90463e13e91f36"
|
|
58
55
|
}
|
|
@@ -11,7 +11,7 @@ function parseBalance({ asset, balance }) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
throw new Error(
|
|
14
|
-
`Balance '${balance.toDefaultString()}' is not of currency ${currency.
|
|
14
|
+
`Balance '${balance.toDefaultString({ unit: true })}' is not of currency ${currency.toDefaultString({ unit: true })}`
|
|
15
15
|
)
|
|
16
16
|
}
|
|
17
17
|
|
package/src/constants.js
CHANGED
|
@@ -58,9 +58,9 @@ const CHAIN_DATA = {
|
|
|
58
58
|
},
|
|
59
59
|
ethereumarbnova: {
|
|
60
60
|
chainId: 42_170,
|
|
61
|
-
serverUrl: 'https://
|
|
61
|
+
serverUrl: 'https://nova.arbitrum.io/rpc',
|
|
62
62
|
confirmationsNumber: 3,
|
|
63
|
-
monitorType: '
|
|
63
|
+
monitorType: 'no-history',
|
|
64
64
|
},
|
|
65
65
|
ethereumarbone: {
|
|
66
66
|
chainId: 42_161,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { bufferToHex, toBuffer } from '@exodus/ethereumjs/util'
|
|
2
2
|
|
|
3
3
|
// TODO: obsolete, remove this
|
|
4
4
|
// TODO: migrate to using solidity-contract
|
|
5
5
|
export default function createContract(addresses, currency) {
|
|
6
6
|
// First 4 bytes of Keccak256('transfer(address,uint256)')
|
|
7
|
-
// const TRANSFER_METHOD_ID =
|
|
7
|
+
// const TRANSFER_METHOD_ID = bufferToHex(sha3('transfer(address,uint256)').slice(0, 4))
|
|
8
8
|
const TRANSFER_METHOD_ID = '0xa9059cbb'
|
|
9
9
|
|
|
10
10
|
// Keccak256('Transfer(address,address,uint256)')
|
|
11
|
-
// const TRANSFER_EVENT_ID =
|
|
11
|
+
// const TRANSFER_EVENT_ID = bufferToHex(sha3('Transfer(address,address,uint256)'))
|
|
12
12
|
const TRANSFER_EVENT_ID = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
13
13
|
|
|
14
14
|
const transfer = {
|
|
@@ -17,33 +17,33 @@ export default function createContract(addresses, currency) {
|
|
|
17
17
|
|
|
18
18
|
build(to, bufAmount) {
|
|
19
19
|
return Buffer.concat([
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
toBuffer(TRANSFER_METHOD_ID),
|
|
21
|
+
Buffer.alloc(12),
|
|
22
|
+
toBuffer(to),
|
|
23
|
+
Buffer.alloc(32 - bufAmount.length),
|
|
24
24
|
bufAmount,
|
|
25
25
|
])
|
|
26
26
|
},
|
|
27
27
|
|
|
28
28
|
test(data) {
|
|
29
|
-
return
|
|
29
|
+
return bufferToHex(data.slice(0, 4)) === TRANSFER_METHOD_ID
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
parse(data) {
|
|
33
33
|
if (!transfer.test(data)) throw new Error('It is not transfer data')
|
|
34
34
|
|
|
35
35
|
return {
|
|
36
|
-
to:
|
|
37
|
-
amount: currency.baseUnit(
|
|
36
|
+
to: bufferToHex(data.slice(16, 36)),
|
|
37
|
+
amount: currency.baseUnit(bufferToHex(data.slice(36, 68))),
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
//
|
|
42
|
+
// bufferToHex(sha3('approve(address,uint256)').slice(0, 4))
|
|
43
43
|
const APPROVE_METHOD_ID = '0x095ea7b3'
|
|
44
44
|
|
|
45
45
|
// TODO: not verified:
|
|
46
|
-
//
|
|
46
|
+
// bufferToHex(sha3('Approval(address,address,uint256)'))
|
|
47
47
|
const APPROVE_EVENT_ID = '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925'
|
|
48
48
|
|
|
49
49
|
const approve = {
|
|
@@ -52,24 +52,24 @@ export default function createContract(addresses, currency) {
|
|
|
52
52
|
|
|
53
53
|
build(address, bufAmount) {
|
|
54
54
|
return Buffer.concat([
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
toBuffer(APPROVE_METHOD_ID),
|
|
56
|
+
Buffer.alloc(12),
|
|
57
|
+
toBuffer(address),
|
|
58
|
+
Buffer.alloc(32 - bufAmount.length),
|
|
59
59
|
bufAmount,
|
|
60
60
|
])
|
|
61
61
|
},
|
|
62
62
|
|
|
63
63
|
test(data) {
|
|
64
|
-
return
|
|
64
|
+
return bufferToHex(data.slice(0, 4)) === APPROVE_METHOD_ID
|
|
65
65
|
},
|
|
66
66
|
|
|
67
67
|
parse(data) {
|
|
68
68
|
if (!approve.test(data)) throw new Error('It is not approve data')
|
|
69
69
|
|
|
70
70
|
return {
|
|
71
|
-
address:
|
|
72
|
-
amount: currency.baseUnit(
|
|
71
|
+
address: bufferToHex(data.slice(16, 36)),
|
|
72
|
+
amount: currency.baseUnit(bufferToHex(data.slice(36, 68))),
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
}
|
package/src/encode.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isValidChecksumAddress,
|
|
3
|
+
isValidPrivate as _isValidPrivate,
|
|
4
|
+
privateToAddress,
|
|
5
|
+
publicToAddress,
|
|
6
|
+
toChecksumAddress,
|
|
7
|
+
} from '@exodus/ethereumjs/util'
|
|
2
8
|
import assert from 'minimalistic-assert'
|
|
3
9
|
|
|
4
10
|
export const validateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
|
|
@@ -15,8 +21,8 @@ export const validateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
|
|
|
15
21
|
if (!hasChecksum(address)) return true
|
|
16
22
|
|
|
17
23
|
return (
|
|
18
|
-
(useEip1191ChainIdChecksum &&
|
|
19
|
-
|
|
24
|
+
(useEip1191ChainIdChecksum && isValidChecksumAddress(address, chainId)) ||
|
|
25
|
+
isValidChecksumAddress(address)
|
|
20
26
|
)
|
|
21
27
|
}
|
|
22
28
|
}
|
|
@@ -35,9 +41,9 @@ export const encodePublicFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
|
|
|
35
41
|
'chainId is required when useEip1191ChainIdChecksum is true'
|
|
36
42
|
)
|
|
37
43
|
return (compressedPubKey) => {
|
|
38
|
-
const hash160bits =
|
|
44
|
+
const hash160bits = publicToAddress(compressedPubKey, true)
|
|
39
45
|
|
|
40
|
-
const basicAddress =
|
|
46
|
+
const basicAddress = toChecksumAddress(
|
|
41
47
|
'0x' + hash160bits.toString('hex'),
|
|
42
48
|
useEip1191ChainIdChecksum ? chainId : undefined
|
|
43
49
|
)
|
|
@@ -46,7 +52,7 @@ export const encodePublicFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
|
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export function isValidPrivate(privateKey) {
|
|
49
|
-
return
|
|
55
|
+
return privateKey.length === 32 && _isValidPrivate(privateKey)
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
export const encodePublicFromPrivateFactory = ({ chainId, useEip1191ChainIdChecksum }) => {
|
|
@@ -55,8 +61,8 @@ export const encodePublicFromPrivateFactory = ({ chainId, useEip1191ChainIdCheck
|
|
|
55
61
|
'chainId is required when useEip1191ChainIdChecksum is true'
|
|
56
62
|
)
|
|
57
63
|
return (privateKey) => {
|
|
58
|
-
return
|
|
59
|
-
'0x' +
|
|
64
|
+
return toChecksumAddress(
|
|
65
|
+
'0x' + privateToAddress(privateKey).toString('hex'),
|
|
60
66
|
useEip1191ChainIdChecksum ? chainId : undefined
|
|
61
67
|
)
|
|
62
68
|
}
|
package/src/sign-message.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs
|
|
3
|
-
|
|
4
|
-
const Common = CommonCJS.default || CommonCJS
|
|
1
|
+
import { Common, Hardfork } from '@exodus/ethereumjs/common'
|
|
2
|
+
import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs/tx'
|
|
5
3
|
|
|
6
4
|
export default function createEthereumJsTx(unsignedTx) {
|
|
7
5
|
const {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { bufferToInt } from '@exodus/ethereumjs/util'
|
|
2
2
|
|
|
3
3
|
import { buffer2currency, isToken } from '../utils/index.js'
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ export default function parseUnsignedTx(asset, unsignedTx) {
|
|
|
7
7
|
const _isToken = isToken(asset)
|
|
8
8
|
const baseAsset = asset.baseAsset
|
|
9
9
|
const gasPrice = buffer2currency({ asset: baseAsset, value: txData.gasPrice })
|
|
10
|
-
const gasLimit =
|
|
10
|
+
const gasLimit = bufferToInt(txData.gasLimit)
|
|
11
11
|
|
|
12
12
|
let { to, data, value } = txData
|
|
13
13
|
let amount
|
|
@@ -16,7 +16,7 @@ export default function parseUnsignedTx(asset, unsignedTx) {
|
|
|
16
16
|
const { method, values } = asset.contract.decodeInput(data)
|
|
17
17
|
if (method === 'transfer' || method === 'approve') {
|
|
18
18
|
to = values[0]
|
|
19
|
-
amount = asset.currency.baseUnit(values[1])
|
|
19
|
+
amount = asset.currency.baseUnit(values[1])
|
|
20
20
|
} else {
|
|
21
21
|
to = values[0]
|
|
22
22
|
amount = asset.currency.ZERO
|
|
@@ -6,5 +6,10 @@ export default function ({ fee, balance, multiplier = defaultMultiplier }) {
|
|
|
6
6
|
if (typeof multiplier !== 'number' || multiplier < 1) multiplier = defaultMultiplier
|
|
7
7
|
if (balance.gt(fee)) return balance.unitType.ZERO
|
|
8
8
|
|
|
9
|
-
return fee
|
|
9
|
+
return fee
|
|
10
|
+
.mul(multiplier)
|
|
11
|
+
.sub(balance)
|
|
12
|
+
.toDefault() // ensure correct unit before `toFixed`
|
|
13
|
+
.toFixed(4, 'ceil')
|
|
14
|
+
.toDefaultString({ unit: true })
|
|
10
15
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs
|
|
2
|
-
import
|
|
1
|
+
import { FeeMarketEIP1559Transaction, Transaction } from '@exodus/ethereumjs/tx'
|
|
2
|
+
import { padToEven, toBuffer } from '@exodus/ethereumjs/util'
|
|
3
3
|
import baseX from 'base-x'
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @exodus/import/no-deprecated
|
|
@@ -61,7 +61,7 @@ export const isEthereumLikeByName = (assetName) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export function buffer2currency({ asset, value }) {
|
|
64
|
-
return asset.currency.baseUnit(base10.encode(value))
|
|
64
|
+
return asset.currency.baseUnit(base10.encode(value))
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export function currency2buffer(value) {
|
|
@@ -75,7 +75,7 @@ export function currency2buffer(value) {
|
|
|
75
75
|
throw new RangeError(`${value.toBaseString()} can not be converted to Buffer`)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
return Buffer.from(
|
|
78
|
+
return Buffer.from(padToEven(hexValue), 'hex')
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export function normalizeTxId(txId) {
|
|
@@ -92,7 +92,7 @@ const TRANSACTION_TYPE = 2
|
|
|
92
92
|
const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex')
|
|
93
93
|
|
|
94
94
|
export function deserialize(hex) {
|
|
95
|
-
const buf =
|
|
95
|
+
const buf = toBuffer(hex)
|
|
96
96
|
return buf.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)
|
|
97
97
|
? FeeMarketEIP1559Transaction.fromSerializedTx(buf)
|
|
98
98
|
: Transaction.fromSerializedTx(buf)
|