Skip to content

Commit 59bce78

Browse files
authored
Merge pull request #787 from mds1/from-fix
2 parents 084c96b + 8d15eaf commit 59bce78

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

src/dapp-tests/integration/tests.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,46 @@ test-lookup-address2() {
412412
= $(seth lookup-address 0x49c92f2ce8f876b070b114a6b2f8a60b83c281ad --rpc-url=$ETH_RPC_URL) ]] || error
413413
}
414414
test-lookup-address2
415+
416+
# SETH FIXED POINT TESTS
417+
# seth --from-fix
418+
test-from-fix1() {
419+
[[ $(seth --from-fix 6 1) = 1000000 ]] || error
420+
}
421+
test-from-fix1
422+
423+
test-from-fix2() {
424+
[[ $(seth --from-fix 18 1) = 1000000000000000000 ]] || error
425+
}
426+
test-from-fix2
427+
428+
test-from-fix3() {
429+
[[ $(seth --from-fix 6 1.2345) = 1234500 ]] || error
430+
}
431+
test-from-fix3
432+
433+
test-from-fix4() {
434+
[[ $(seth --from-fix 18 1.23456789) = 1234567890000000000 ]] || error
435+
}
436+
test-from-fix4
437+
438+
# seth --to-fix
439+
test-to-fix1() {
440+
[[ $(seth --to-fix 6 1000000) = 1.000000 ]] || error
441+
}
442+
test-to-fix1
443+
444+
test-to-fix2() {
445+
[[ $(seth --to-fix 18 1000000000000000000) = 1.000000000000000000 ]] || error
446+
}
447+
test-to-fix2
448+
449+
test-to-fix3() {
450+
[[ $(seth --to-fix 6 1234500) = 1.234500 ]] || error
451+
}
452+
test-to-fix3
453+
454+
test-to-fix4() {
455+
[[ $(seth --to-fix 18 1234567890000000000) = 1.234567890000000000 ]] || error
456+
}
457+
test-to-fix4

src/seth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- `seth 4byte-event` command returns the response from querying 4byte.directory for a given event topic
1414
- `seth abi-encode` command returns the ABI encoded values without the function signature
1515
- `seth index` command returns the slot number for the specified mapping type and input data
16+
- `seth --from-fix` command converts fixed point numbers into parsed integers with the specified number of decimals
1617

1718
### Fixed
1819

src/seth/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ hardware wallets—even if you use a remote RPC node like Infura's.
5757
- [`seth --calldata-decode`]
5858
- [`seth --from-ascii`]
5959
- [`seth --from-bin`]
60+
- [`seth --from-fix`]
6061
- [`seth --from-wei`]
6162
- [`seth --max-int`]
6263
- [`seth --max-uint`]
@@ -65,6 +66,7 @@ hardware wallets—even if you use a remote RPC node like Infura's.
6566
- [`seth --to-ascii`]
6667
- [`seth --to-bytes32`]
6768
- [`seth --to-dec`]
69+
- [`seth --to-fix`]
6870
- [`seth --to-hex`]
6971
- [`seth --to-int256`]
7072
- [`seth --to-uint256`]
@@ -374,6 +376,14 @@ Convert binary data into hex data.
374376

375377
Reads binary data from standard input and prints it as hex data.
376378

379+
### `seth --from-fix`
380+
381+
Convert fixed point numbers into parsed integers with the specified number of decimals.
382+
383+
seth --from-fix <decimals> <value>
384+
385+
For example, use `seth --to-fix 6 1` to convert 1 USDC into the parsed quantity of 1,000,000 USDC
386+
377387
### `seth --from-wei`
378388

379389
Convert a wei amount into another unit (ETH by default).
@@ -430,6 +440,14 @@ Convert a hex value with 0x prefix into a decimal number.
430440

431441
seth --to-dec <hexvalue>
432442

443+
### `seth --to-fix`
444+
445+
Convert parsed integers into fixed point with the specified number of decimals.
446+
447+
seth --to-fix <decimals> <value>
448+
449+
For example, use `seth --to-fix 6 1000000` to convert the parsed amount of 1,000,000 USDC into a formatted amount of 1 USDC.
450+
433451
### `seth --to-hex`
434452

435453
Convert a decimal number into a hex value.
@@ -865,7 +883,9 @@ Show all fields unless `<field>` is given.
865883
[`seth --abi-decode`]: #seth---abi-decode
866884
[`seth --from-ascii`]: #seth---from-ascii
867885
[`seth --from-bin`]: #seth---from-bin
886+
[`seth --from-fix`]: #seth---from-fix
868887
[`seth --from-wei`]: #seth---from-wei
888+
[`seth --to-fix`]: #seth---to-fix
869889
[`seth --to-wei`]: #seth---to-wei
870890
[`seth --to-int256`]: #seth---to-int256
871891
[`seth --to-uint256`]: #seth---to-uint256
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
### seth---from-fix -- convert fixed point into specified number of decimals
3+
### Usage: seth --from-fix <decimals> <wei>
4+
set -e
5+
[[ $# -eq 2 ]] || seth --fail-usage "$0"
6+
7+
decimals=$1
8+
number=$2
9+
10+
bc <<<"$number * 10 ^ $decimals / 1" # dividing by 1 ensures integer output

src/seth/libexec/seth/seth-4byte-decode

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
### seth-4byte-decode -- querys 4byte.directory to find a matching signature, then decodes the calldata with it
2+
### seth-4byte-decode -- queries 4byte.directory to find a matching signature, then decodes the calldata with it
33
### Usage: seth 4byte-decode <calldata> [<options>]
44
###
55
### Queries 4byte.directory to find matching signatures and prompts the user to to select one. The selected

0 commit comments

Comments
 (0)