Skip to content
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

Rename fromE8s to fromUlps #492

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,18 @@ Represents an amount of tokens.

#### Methods

- [fromE8s](#gear-frome8s)
- [fromUlps](#gear-fromulps)
- [fromString](#gear-fromstring)
- [fromNumber](#gear-fromnumber)
- [toUlps](#gear-toulps)

##### :gear: fromE8s
##### :gear: fromUlps

Initialize from a bigint. Bigint are considered ulps.

| Method | Type |
| --------- | -------------------------------------------------------------------------- |
| `fromE8s` | `({ amount, token, }: { amount: bigint; token: Token; }) => TokenAmountV2` |
| Method | Type |
| ---------- | -------------------------------------------------------------------------- |
| `fromUlps` | `({ amount, token, }: { amount: bigint; token: Token; }) => TokenAmountV2` |

Parameters:

Expand Down
46 changes: 23 additions & 23 deletions packages/utils/src/parser/token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,47 +156,47 @@ describe("TokenAmountV2 with 18 decimals", () => {

it("can be initialized from a whole number string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "1" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000n,
}),
);
expect(TokenAmountV2.fromString({ token: token, amount: "1234" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1234000000000000000000n,
}),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "000001234" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1234000000000000000000n,
}),
);
expect(TokenAmountV2.fromString({ token: token, amount: " 1" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000n,
}),
);
expect(TokenAmountV2.fromString({ token: token, amount: "1,000" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000000n,
}),
);
expect(TokenAmountV2.fromString({ token: token, amount: "1'000" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000000n,
}),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "1'000'000" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000000000n,
}),
Expand All @@ -212,7 +212,7 @@ describe("TokenAmountV2 with 18 decimals", () => {
expect(
TokenAmountV2.fromString({ token: token, amount: "1'000'000" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1000000000000000000000000n,
}),
Expand All @@ -224,7 +224,7 @@ describe("TokenAmountV2 with 18 decimals", () => {

it("can be initialized from a fractional number string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "0.1" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 100000000000000000n,
}),
Expand All @@ -241,19 +241,19 @@ describe("TokenAmountV2 with 18 decimals", () => {
expect(
TokenAmountV2.fromString({ token: token, amount: "0.0001" }),
).toEqual(
TokenAmountV2.fromE8s({ token: token, amount: 100000000000000n }),
TokenAmountV2.fromUlps({ token: token, amount: 100000000000000n }),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "0.00000001" }),
).toEqual(TokenAmountV2.fromE8s({ token: token, amount: 10000000000n }));
).toEqual(TokenAmountV2.fromUlps({ token: token, amount: 10000000000n }));
expect(
TokenAmountV2.fromString({
token: token,
amount: "0.00000000000000000001",
}),
).toEqual(FromStringToTokenError.FractionalTooManyDecimals);
expect(TokenAmountV2.fromString({ token: token, amount: ".01" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 10000000000000000n,
}),
Expand All @@ -262,37 +262,37 @@ describe("TokenAmountV2 with 18 decimals", () => {

it("can be initialized from a mixed string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "1.1" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1100000000000000000n,
}),
);
expect(TokenAmountV2.fromString({ token: token, amount: "1.1" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 1100000000000000000n,
}),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "12,345.00000001" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 12345000000010000000000n,
}),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "12'345.00000001" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 12345000000010000000000n,
}),
);
expect(
TokenAmountV2.fromString({ token: token, amount: "12345.00000001" }),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 12345000000010000000000n,
}),
Expand All @@ -303,7 +303,7 @@ describe("TokenAmountV2 with 18 decimals", () => {
amount: "100000000.000000000000000001",
}),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 100000000000000000000000001n,
}),
Expand All @@ -314,7 +314,7 @@ describe("TokenAmountV2 with 18 decimals", () => {
amount: "199999999.999999999999999991",
}),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 199999999999999999999999991n,
}),
Expand Down Expand Up @@ -362,7 +362,7 @@ describe("TokenAmountV2 with 2 decimals", () => {

it("can be initialized from a whole number string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "123" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 12300n,
}),
Expand All @@ -371,7 +371,7 @@ describe("TokenAmountV2 with 2 decimals", () => {

it("can be initialized from a fractional number string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "0.99" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 99n,
}),
Expand All @@ -391,7 +391,7 @@ describe("TokenAmountV2 with 2 decimals", () => {
amount: "100000000.91",
}),
).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 10000000091n,
}),
Expand All @@ -408,7 +408,7 @@ describe("TokenAmountV2 with 0 decimals", () => {

it("can be initialized from a whole number string", () => {
expect(TokenAmountV2.fromString({ token: token, amount: "123" })).toEqual(
TokenAmountV2.fromE8s({
TokenAmountV2.fromUlps({
token: token,
amount: 123n,
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/parser/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class TokenAmountV2 {
* @param {bigint} params.amount The amount in bigint format.
* @param {Token} params.token The token type.
*/
public static fromE8s({
public static fromUlps({
amount,
token,
}: {
Expand Down