Skip to content

Commit 7481574

Browse files
committed
Merge branch 'main' of github.com:SundaeSwap-finance/defi-sdk
2 parents 77eccd7 + a72e5a7 commit 7481574

File tree

9 files changed

+63
-113
lines changed

9 files changed

+63
-113
lines changed

packages/asset/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [1.0.10](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/asset@1.0.9...@sundaeswap/asset@1.0.10) (2025-05-06)
7+
8+
**Note:** Version bump only for package @sundaeswap/asset
9+
10+
## [1.0.9](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/asset@1.0.8...@sundaeswap/asset@1.0.9) (2025-05-06)
11+
12+
**Note:** Version bump only for package @sundaeswap/asset
13+
14+
## [1.0.8](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/asset@1.0.7...@sundaeswap/asset@1.0.8) (2025-05-06)
15+
16+
**Note:** Version bump only for package @sundaeswap/asset
17+
18+
## [1.0.7](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/asset@1.0.6...@sundaeswap/asset@1.0.7) (2025-03-28)
19+
20+
**Note:** Version bump only for package @sundaeswap/asset
21+
622
## [1.0.6](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/asset@1.0.5...@sundaeswap/asset@1.0.6) (2024-07-25)
723

824
**Note:** Version bump only for package @sundaeswap/asset

packages/asset/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sundaeswap/asset",
3-
"version": "1.0.6",
3+
"version": "1.0.10",
44
"description": "A TypeScript interface to handle digital asset amounts along with their respective metadata.",
55
"type": "module",
66
"author": {

packages/asset/src/AssetAmount.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class AssetAmount<T extends IAssetAmountMetadata = IAssetAmountMetadata>
110110
add = (rhs: AssetAmount): AssetAmount<T> => {
111111
return this.withAmount(this.amount + rhs.amount);
112112
};
113+
113114
plus = this.add;
114115

115116
subtract = (rhs: AssetAmount): AssetAmount<T> => {
@@ -187,7 +188,7 @@ export class AssetAmount<T extends IAssetAmountMetadata = IAssetAmountMetadata>
187188
* @param {T} metadata The asset metadata object.
188189
* @returns {T}
189190
*/
190-
private normalizeMetadata(metadata: T): T {
191+
private normalizeMetadata(metadata: T) {
191192
const newMetadata = { ...metadata };
192193
if (
193194
newMetadata.assetId.length > AssetAmount.POLICY_ID_LENGTH &&

packages/cpp/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [1.0.11](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/cpp@1.0.10...@sundaeswap/cpp@1.0.11) (2025-05-06)
7+
8+
**Note:** Version bump only for package @sundaeswap/cpp
9+
10+
## [1.0.10](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/cpp@1.0.9...@sundaeswap/cpp@1.0.10) (2025-05-06)
11+
12+
**Note:** Version bump only for package @sundaeswap/cpp
13+
14+
## [1.0.9](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/cpp@1.0.8...@sundaeswap/cpp@1.0.9) (2025-05-06)
15+
16+
**Note:** Version bump only for package @sundaeswap/cpp
17+
18+
## [1.0.8](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/cpp@1.0.7...@sundaeswap/cpp@1.0.8) (2025-03-28)
19+
20+
**Note:** Version bump only for package @sundaeswap/cpp
21+
622
## [1.0.7](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/cpp@1.0.6...@sundaeswap/cpp@1.0.7) (2024-07-25)
723

824
**Note:** Version bump only for package @sundaeswap/cpp

packages/cpp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sundaeswap/cpp",
3-
"version": "1.0.7",
3+
"version": "1.0.11",
44
"description": "Minimal rational number library using BigInt",
55
"author": {
66
"name": "SundaeSwap Labs, Inc.",

packages/fraction/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [1.0.7](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/fraction@1.0.6...@sundaeswap/fraction@1.0.7) (2025-05-06)
7+
8+
### Bug Fixes
9+
10+
- default denominator ([9c45cd4](https://github.com/SundaeSwap-finance/defi-sdk/commit/9c45cd45dbd4db242a5672a8a67faeff4c09cf03))
11+
12+
## [1.0.6](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/fraction@1.0.5...@sundaeswap/fraction@1.0.6) (2025-05-06)
13+
14+
### Bug Fixes
15+
16+
- toString mehtid from Fraction class not working properly for negative values ([c37ac39](https://github.com/SundaeSwap-finance/defi-sdk/commit/c37ac3902adb99b2ea75d890a4190c5c5aea2ac3))
17+
618
## [1.0.5](https://github.com/SundaeSwap-finance/defi-sdk/compare/@sundaeswap/fraction@1.0.4...@sundaeswap/fraction@1.0.5) (2024-07-01)
719

820
### Bug Fixes

packages/fraction/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sundaeswap/fraction",
3-
"version": "1.0.5",
3+
"version": "1.0.7",
44
"description": "Minimal rational number library using BigInt",
55
"author": {
66
"name": "SundaeSwap Labs, Inc.",

packages/fraction/src/Fraction.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,7 @@ export class Fraction {
3131
: Fraction.parseString(fraction.toString());
3232
}
3333

34-
// static fromLocaleString(numStr: string, locale?: string): Fraction {
35-
// const { decimalSeparator, groupSeparator } = getLocaleFormatOptions(locale);
36-
// const [integerPart, fractionalPart] = numStr.split(decimalSeparator);
37-
// const quotient = BigInt(integerPart.split(groupSeparator).join(""));
38-
// if (!fractionalPart?.length) return new Fraction(quotient);
39-
// const denominator = 10n ** BigInt(fractionalPart.length);
40-
// return new Fraction(
41-
// quotient * denominator + BigInt(fractionalPart),
42-
// denominator
43-
// );
44-
// }
45-
4634
static parseString(fractionString: string): Fraction {
47-
// Parse a number in various forms (1000, 1.0003, 1.23e4, 1.23e-4) into a numerator and denominator
4835
fractionString = fractionString.replace(/,/g, "");
4936

5037
if (fractionString.match(/[eE]/)) {
@@ -62,8 +49,7 @@ export class Fraction {
6249
const numerator = BigInt(integerPart + fractionalPart);
6350
const denominator = 10n ** BigInt(fractionalPart.length);
6451

65-
// Simplify the fraction using the GCD function
66-
const gcd = (a, b) => (b === 0n ? a : gcd(b, a % b));
52+
const gcd = (a: bigint, b: bigint) => (b === 0n ? a : gcd(b, a % b));
6753
const divisor = gcd(numerator, denominator);
6854
return new Fraction(numerator / divisor, denominator / divisor);
6955
}
@@ -210,11 +196,13 @@ export class Fraction {
210196
}
211197

212198
toString(decimals = Fraction.MAX_DECIMALS): string {
213-
const formattedIntegerPart = this.getQuotient().toString();
214-
const formattedFractionalPart = this.remainderToString(decimals);
199+
const sign = this.lessThan(Fraction.ZERO) ? "-" : "";
200+
const absFrac = this.abs();
201+
const formattedIntegerPart = absFrac.getQuotient().toString();
202+
const formattedFractionalPart = absFrac.remainderToString(decimals);
215203
return formattedFractionalPart
216-
? `${formattedIntegerPart}.${formattedFractionalPart}`
217-
: formattedIntegerPart;
204+
? `${sign}${formattedIntegerPart}.${formattedFractionalPart}`
205+
: `${sign}${formattedIntegerPart}`;
218206
}
219207

220208
/**

packages/fraction/src/__tests__/Fraction.test.ts

Lines changed: 7 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@ describe("Fraction", () => {
3838

3939
test(".toString()", () => {
4040
expect(new Fraction(1, 25).toString()).toBe("0.04");
41+
expect(new Fraction(-123090, 1000000).toString()).toBe("-0.12309");
4142
expect(new Fraction(1_000_000 * 25 + 1, 25).toString()).toBe("1000000.04");
4243
expect(Fraction.ZERO.toString()).toBe("0");
4344
expect(Fraction.ONE.toString()).toBe("1");
4445
expect(Fraction.HUNDRED.toString()).toBe("100");
4546
});
4647

48+
test(".toNumber()", () => {
49+
expect(new Fraction(1, 25).toNumber()).toBe(0.04);
50+
expect(new Fraction(-123090, 1000000).toNumber()).toBe(-0.12309);
51+
expect(new Fraction(1, 3).toNumber(2)).toBe(0.33);
52+
});
53+
4754
test(".parseString()", () => {
4855
expect(Fraction.parseString("0.04").eq(new Fraction(1, 25))).toBe(true);
4956
expect(
@@ -83,94 +90,4 @@ describe("Fraction", () => {
8390
),
8491
);
8592
});
86-
87-
// test("#toLocaleString()", () => {
88-
// expect(new Fraction(1, 25).toLocaleString()).toBe("0.04");
89-
// expect(new Fraction(1_000_000 * 25 + 1, 25).toLocaleString()).toBe(
90-
// "1,000,000.04"
91-
// );
92-
// const testFraction = new Fraction(1_000_000 * 25_000 + 1, 25_000);
93-
// expect(testFraction.toLocaleString()).toBe("1,000,000.00004");
94-
// expect(testFraction.toLocaleString("en-US", 1)).toBe("1,000,000");
95-
// expect(testFraction.toLocaleString("en-US", 4)).toBe("1,000,000");
96-
// expect(testFraction.toLocaleString("en-US", 5)).toBe("1,000,000.00004");
97-
// expect(testFraction.toLocaleString("de-DE")).toBe("1.000.000,00004");
98-
// expect(testFraction.toLocaleString("it-CH")).toBe("1’000’000.00004");
99-
// expect(testFraction.toLocaleString("hu-HU")).toBe("1\xa0000\xa0000,00004");
100-
// expect(testFraction.toLocaleString("fr-FR")).toBe(
101-
// "1\u202f000\u202f000,00004"
102-
// );
103-
// expect(Fraction.ZERO.toLocaleString()).toBe("0");
104-
// expect(Fraction.ONE.toLocaleString()).toBe("1");
105-
// expect(Fraction.HUNDRED.toLocaleString()).toBe("100");
106-
// });
107-
108-
// test(".fromLocaleString()", () => {
109-
// const testFraction = new Fraction(1_000_000 * 25_000 + 1, 25_000);
110-
// expect(
111-
// Fraction.fromLocaleString("1.000.000,00004", "de-DE").eq(testFraction)
112-
// ).toBe(true);
113-
// expect(
114-
// Fraction.fromLocaleString("1’000’000.00004", "it-CH").eq(testFraction)
115-
// ).toBe(true);
116-
// expect(
117-
// Fraction.fromLocaleString("1\xa0000\xa0000,00004", "hu-HU").eq(
118-
// testFraction
119-
// )
120-
// ).toBe(true);
121-
// expect(
122-
// Fraction.fromLocaleString("1\u202f000\u202f000,00004", "fr-FR").eq(
123-
// testFraction
124-
// )
125-
// ).toBe(true);
126-
// expect(
127-
// Fraction.fromLocaleString("1,000,000.00004").eq(testFraction)
128-
// ).toBe(true);
129-
// expect(Fraction.fromLocaleString("0.04").eq(new Fraction(1, 25))).toBe(
130-
// true
131-
// );
132-
// expect(Fraction.fromLocaleString("0").eq(Fraction.ZERO)).toBe(true);
133-
// expect(Fraction.fromLocaleString("1").eq(Fraction.ONE)).toBe(true);
134-
// expect(Fraction.fromLocaleString("1000").eq(Fraction.THOUSAND)).toBe(
135-
// true
136-
// );
137-
// });
138-
139-
// test(".lessThanOrEqual()", () => {
140-
// const testFraction = new Fraction(1_000_000);
141-
// expect(
142-
// Fraction.fromLocaleString("1.000.000", "de-DE").lessThanOrEqual(
143-
// testFraction
144-
// )
145-
// ).toBe(true);
146-
// expect(
147-
// Fraction.fromLocaleString("999.999", "de-DE").lessThanOrEqual(
148-
// testFraction
149-
// )
150-
// ).toBe(true);
151-
// expect(
152-
// Fraction.fromLocaleString("1.000.001", "de-DE").lessThanOrEqual(
153-
// testFraction
154-
// )
155-
// ).toBe(false);
156-
// });
157-
158-
// test(".greaterThanOrEqual()", () => {
159-
// const testFraction = new Fraction(1_000_000);
160-
// expect(
161-
// Fraction.fromLocaleString("1.000.000", "de-DE").greaterThanOrEqual(
162-
// testFraction
163-
// )
164-
// ).toBe(true);
165-
// expect(
166-
// Fraction.fromLocaleString("999.999", "de-DE").greaterThanOrEqual(
167-
// testFraction
168-
// )
169-
// ).toBe(false);
170-
// expect(
171-
// Fraction.fromLocaleString("1.000.001", "de-DE").greaterThanOrEqual(
172-
// testFraction
173-
// )
174-
// ).toBe(true);
175-
// });
17693
});

0 commit comments

Comments
 (0)