-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: update ark decimals to 18 and new helpers #114
Merged
ItsANameToo
merged 22 commits into
feat/mainsail-evm
from
refactor/update-decimals-and-helpers
Nov 18, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6fff57b
refactor: update satoshi to 1e18
patricio0312rev 8e4ce81
refactor: update network decimals
patricio0312rev 6982f57
refactor: update milestones
patricio0312rev 98b4b6c
feat: format units util
patricio0312rev 5ce9dfa
feat: parse units util
patricio0312rev 64e1084
feat: multiplier constants
patricio0312rev 8e22e5b
refactor: network decimals
patricio0312rev 19a674e
test: helper methods for mainsail
patricio0312rev 7949a9d
wip
patricio0312rev acf2d1a
wip
patricio0312rev ed366a5
wip
patricio0312rev 5237b2c
fix: revert changes on ark
patricio0312rev 0b20ab2
fix: move helpers to mainsail folder
patricio0312rev e78e457
style: resolve style guide violations
patricio0312rev f53e146
fix: unit tests
patricio0312rev 7f5c138
Merge branch 'refactor/update-decimals-and-helpers' of https://github…
patricio0312rev 4e4ac59
style: resolve style guide violations
patricio0312rev 650b7cd
fix: use big number for methods
patricio0312rev 5c7f3e1
fix: unit tests
patricio0312rev 9a69437
Merge branch 'refactor/update-decimals-and-helpers' of https://github…
patricio0312rev c58e8b9
style: resolve style guide violations
patricio0312rev 1affe59
wip
ItsANameToo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export const SATOSHI = 1e8; | ||
export const SATOSHI = 1e18; | ||
|
||
export const WEI_MULTIPLIER = 1; | ||
export const GWEI_MULTIPLIER = 1e9; | ||
export const ARK_MULTIPLIER = 1e18; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { formatUnits } from "./format-units"; | ||
|
||
describe("formatUnits", async ({ assert, it, loader }) => { | ||
it("should format the value to wei", () => { | ||
assert.equal(formatUnits("1", "wei"), "1"); | ||
assert.equal(formatUnits("1000000000", "gwei"), "1"); | ||
assert.equal(formatUnits("100000000000000000000", "ark"), "1"); | ||
}); | ||
|
||
it("should throw an error for unsupported units", () => { | ||
assert.throws( | ||
() => formatUnits("1", "btc"), | ||
"Unsupported unit: btc. Supported units are 'wei', 'gwei', and 'ark'.", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable unicorn/require-number-to-fixed-digits-argument */ | ||
import { BigNumber } from "@mainsail/kernel/distribution/utils"; | ||
|
||
import { ARK_MULTIPLIER, GWEI_MULTIPLIER, WEI_MULTIPLIER } from "../crypto/constants"; | ||
|
||
export const formatUnits = (value: string, unit = "ark"): string => { | ||
switch (unit.toLowerCase()) { | ||
case "wei": | ||
return BigNumber.make(value).dividedBy(WEI_MULTIPLIER).toFixed(); | ||
case "gwei": | ||
return BigNumber.make(value).dividedBy(GWEI_MULTIPLIER).toFixed(); | ||
case "ark": | ||
return BigNumber.make(value).dividedBy(ARK_MULTIPLIER).toFixed(); | ||
default: | ||
throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { parseUnits } from "./parse-units"; | ||
|
||
describe("parseUnits", async ({ assert, it, loader }) => { | ||
it("should parse the value to wei", () => { | ||
assert.equal(parseUnits(1, "wei"), "1"); | ||
assert.equal(parseUnits(1, "gwei"), "1000000000"); | ||
assert.equal(parseUnits(1, "ark"), "100000000000000000000"); | ||
}); | ||
|
||
it("should throw an error for unsupported units", () => { | ||
assert.throws( | ||
() => parseUnits(1, "btc"), | ||
"Unsupported unit: btc. Supported units are 'wei', 'gwei', and 'ark'.", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BigNumber } from "@mainsail/kernel/distribution/utils"; | ||
|
||
import { ARK_MULTIPLIER, GWEI_MULTIPLIER, WEI_MULTIPLIER } from "../crypto/constants"; | ||
|
||
export const parseUnits = (value: number | string, unit = "ark"): string => { | ||
switch (unit.toLowerCase()) { | ||
case "wei": | ||
return BigNumber.make(value).times(WEI_MULTIPLIER).toString(); | ||
case "gwei": | ||
return BigNumber.make(value).times(GWEI_MULTIPLIER).toString(); | ||
case "ark": | ||
return BigNumber.make(value).times(ARK_MULTIPLIER).toString(); | ||
default: | ||
throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the tests aren't configured yet for mainsail. Should I remove these files until then? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue is that the mainsail package is a copy of ark and not everything may work. I'll add a card though to enable tests based on the areas that are working so those run at least