sushi 7.1.1 → 7.2.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/_cjs/generic/currency/amount.js.map +1 -1
- package/_cjs/generic/currency/currency.js +1 -0
- package/_cjs/generic/currency/currency.js.map +1 -1
- package/_cjs/generic/currency/price.js.map +1 -1
- package/_cjs/generic/currency/token.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/generic/currency/amount.js.map +1 -1
- package/_esm/generic/currency/currency.js +1 -0
- package/_esm/generic/currency/currency.js.map +1 -1
- package/_esm/generic/currency/price.js.map +1 -1
- package/_esm/generic/currency/token.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/generic/currency/amount.d.ts +17 -17
- package/_types/generic/currency/amount.d.ts.map +1 -1
- package/_types/generic/currency/currency.d.ts +4 -2
- package/_types/generic/currency/currency.d.ts.map +1 -1
- package/_types/generic/currency/price.d.ts +4 -4
- package/_types/generic/currency/price.d.ts.map +1 -1
- package/_types/generic/currency/token.d.ts +1 -1
- package/_types/generic/currency/token.d.ts.map +1 -1
- package/_types/generic/types/id.d.ts +1 -1
- package/_types/generic/types/id.d.ts.map +1 -1
- package/_types/generic/utils/subtract-slippage.d.ts +2 -2
- package/_types/generic/utils/subtract-slippage.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/generic/currency/amount.ts +30 -25
- package/generic/currency/currency.ts +11 -2
- package/generic/currency/extensible-currency.test-d.ts +51 -0
- package/generic/currency/extensible-currency.test.ts +83 -0
- package/generic/currency/price.ts +11 -9
- package/generic/currency/token.ts +1 -1
- package/generic/types/id.ts +1 -1
- package/generic/utils/subtract-slippage.ts +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../generic/currency/amount.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAoD;AACpD,MAAY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Q,IAAK,EAAgB,CAAA;IAC/C,CAAC;IAIM,MAAM,CACX,
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../generic/currency/currency.ts"],"names":[],"mappings":";;;AAQA;IAiBE,YAAY,EACV,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,QAAQ,GAOT;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAK,EAAgB,CAAA;IAC/C,CAAC;IAIM,MAAM,CACX,KAAsE;QAEtE,OAAO,CACL,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;YAC9B,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE;YACpB,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ;YAChC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CACzB,CAAA;IACH,CAAC;CAUF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":";;;AAAA,qDAA8C;AAE9C,2CAAoC;AAGpC,WAGE,SAAQ,sBAAQ;IAOT,MAAM,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":";;;AAAA,qDAA8C;AAE9C,2CAAoC;AAGpC,WAGE,SAAQ,sBAAQ;IAOT,MAAM,CAAC,SAAS,CAGrB,IAAW,EAAE,KAAa,EAAE,KAAa;QACzC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAA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B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../generic/currency/token.ts"],"names":[],"mappings":";;;AAEA,+CAAmE;AAEnE,WAIE,SAAQ,0BAA0C;IAOlD,YAAY,EACV,OAAO,EACP,GAAG,IAAI,EAG6D;QACpE,KAAK,CAAC,IAAI,CAAC,CAAA;QAZK,SAAI,GAAG,OAAO,CAAA;QACd,aAAQ,GAAG,KAAK,CAAA;QAChB,YAAO,GAAG,IAAI,CAAA;QAW9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAa,EAAE;QACb,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;IAC1C,CAAC;IAEe,MAAM,CACpB,
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../generic/currency/token.ts"],"names":[],"mappings":";;;AAEA,+CAAmE;AAEnE,WAIE,SAAQ,0BAA0C;IAOlD,YAAY,EACV,OAAO,EACP,GAAG,IAAI,EAG6D;QACpE,KAAK,CAAC,IAAI,CAAC,CAAA;QAZK,SAAI,GAAG,OAAO,CAAA;QACd,aAAQ,GAAG,KAAK,CAAA;QAChB,YAAO,GAAG,IAAI,CAAA;QAW9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAa,EAAE;QACb,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;IAC1C,CAAC;IAEe,MAAM,CACpB,KAAsE;QAEtE,OAAO,CACL,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACnB,KAAK,YAAY,KAAK;YACtB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAC3D,CAAA;IACH,CAAC;CAGF"}
|
package/_cjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../generic/currency/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../generic/currency/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAU9C;;GAEG;AACH,MAAM,OAAO,MAAM;IAUjB,YAAY,QAAmB,EAAE,MAAiB;QAChD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IAC9B,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,SAAS,CACrB,QAAmB,EACnB,KAA+B;QAE/B,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACxD,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,YAAY,CACxB,QAAmB,EACnB,KAA+B;QAE/B,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAA;QAClB,CAAC;IACH,CAAC;IAED;;O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IAEvB,OAAO,CAAC,CAAC,MAAM,CAAC;QACd,QAAQ,EAAE,cAAc;QACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;KACnB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../generic/currency/currency.ts"],"names":[],"mappings":"AAQA,MAAM,OAAgB,YAAY;IAiBhC,YAAY,EACV,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,QAAQ,GAOT;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAK,EAAgB,CAAA;IAC/C,CAAC;IAIM,MAAM,CACX,
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../generic/currency/currency.ts"],"names":[],"mappings":"AAQA,MAAM,OAAgB,YAAY;IAiBhC,YAAY,EACV,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,QAAQ,GAOT;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAK,EAAgB,CAAA;IAC/C,CAAC;IAIM,MAAM,CACX,KAAsE;QAEtE,OAAO,CACL,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;YAC9B,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE;YACpB,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ;YAChC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CACzB,CAAA;IACH,CAAC;CAUF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,MAAM,OAAO,KAGX,SAAQ,QAAQ;IAIhB;;OAEG;IACI,MAAM,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,MAAM,OAAO,KAGX,SAAQ,QAAQ;IAIhB;;OAEG;IACI,MAAM,CAAC,SAAS,CAGrB,IAAW,EAAE,KAAa,EAAE,KAAa;QACzC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAA;QAC5C,CAAC;QAED,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACpD,MAAM,YAAY,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACnD,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,KAAK,GAAG,QAAQ,EAAE,CAAC,CAAA;QAE1D,OAAO,IAAI,KAAK,CAAC;YACf,IAAI;YACJ,KAAK;YACL,SAAS,EAAE,oBAAoB,GAAG,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC/D,WAAW,EAAE,YAAY,GAAG,GAAG,IAAI,MAAM,CAAC,IAAI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EAAE;QACb,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;IAC1C,CAAC;IAEe,MAAM,CACpB,
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../generic/currency/token.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAyB,MAAM,eAAe,CAAA;AAEnE,MAAM,OAAgB,KAIpB,SAAQ,YAA0C;IAOlD,YAAY,EACV,OAAO,EACP,GAAG,IAAI,EAG6D;QACpE,KAAK,CAAC,IAAI,CAAC,CAAA;QAZK,SAAI,GAAG,OAAO,CAAA;QACd,aAAQ,GAAG,KAAK,CAAA;QAChB,YAAO,GAAG,IAAI,CAAA;QAW9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,IAAa,EAAE;QACb,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;IAC1C,CAAC;IAEe,MAAM,CACpB,KAAsE;QAEtE,OAAO,CACL,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACnB,KAAK,YAAY,KAAK;YACtB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAC3D,CAAA;IACH,CAAC;CAGF"}
|
package/_esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '7.
|
|
1
|
+
export const version = '7.2.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -2,16 +2,16 @@ import * as z from 'zod';
|
|
|
2
2
|
import { numberToFixed } from '../format/number.js';
|
|
3
3
|
import { Fraction } from '../math/fraction.js';
|
|
4
4
|
import type { BigintIsh } from '../types/bigintish.js';
|
|
5
|
-
import type { Currency } from './currency.js';
|
|
6
|
-
import type { SerializedCurrency
|
|
7
|
-
export type SerializedAmount<TCurrency extends SerializedCurrency> = {
|
|
5
|
+
import type { AnyCurrency, Currency } from './currency.js';
|
|
6
|
+
import type { SerializedCurrency } from './serialized-currency.js';
|
|
7
|
+
export type SerializedAmount<TCurrency extends object = SerializedCurrency> = {
|
|
8
8
|
currency: TCurrency;
|
|
9
9
|
amount: string;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Represents an amount of a particular currency.
|
|
13
13
|
*/
|
|
14
|
-
export declare class Amount<TCurrency extends
|
|
14
|
+
export declare class Amount<TCurrency extends AnyCurrency = Currency> {
|
|
15
15
|
/** The currency of this amount */
|
|
16
16
|
readonly currency: TCurrency;
|
|
17
17
|
/** The raw integer amount */
|
|
@@ -23,11 +23,11 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
23
23
|
* Creates an Amount from a human-readable value, e.g. "1.5".
|
|
24
24
|
* Just a wrapper around viem's `parseUnits` to handle the currency's decimals.
|
|
25
25
|
*/
|
|
26
|
-
static fromHuman<TCurrency extends
|
|
26
|
+
static fromHuman<TCurrency extends AnyCurrency>(currency: TCurrency, human: bigint | number | string): Amount<TCurrency>;
|
|
27
27
|
/**
|
|
28
28
|
* Creates an Amount from a human-readable value, e.g. "1.5".
|
|
29
29
|
*/
|
|
30
|
-
static tryFromHuman<TCurrency extends
|
|
30
|
+
static tryFromHuman<TCurrency extends AnyCurrency>(currency: TCurrency, human: bigint | number | string): Amount<TCurrency> | undefined;
|
|
31
31
|
/**
|
|
32
32
|
* Wraps the amount's currency into a Token.
|
|
33
33
|
*/
|
|
@@ -36,7 +36,7 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
36
36
|
/**
|
|
37
37
|
* Adds another Amount or raw value.
|
|
38
38
|
*/
|
|
39
|
-
add(other: Amount | Fraction | bigint | string): Amount<TCurrency>;
|
|
39
|
+
add(other: Amount<AnyCurrency> | Fraction | bigint | string): Amount<TCurrency>;
|
|
40
40
|
/**
|
|
41
41
|
* Adds a human-readable value, e.g. "0.5".
|
|
42
42
|
*/
|
|
@@ -44,7 +44,7 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Subtracts another Amount or raw value.
|
|
46
46
|
*/
|
|
47
|
-
sub(other: Amount | Fraction | bigint | string): Amount<TCurrency>;
|
|
47
|
+
sub(other: Amount<AnyCurrency> | Fraction | bigint | string): Amount<TCurrency>;
|
|
48
48
|
/**
|
|
49
49
|
* Subtracts a human-readable value, e.g. "0.5".
|
|
50
50
|
*/
|
|
@@ -52,7 +52,7 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
52
52
|
/**
|
|
53
53
|
* Multiplies this amount by another amount or raw value.
|
|
54
54
|
*/
|
|
55
|
-
mul(other: Amount | Fraction | bigint | string): Amount<TCurrency>;
|
|
55
|
+
mul(other: Amount<AnyCurrency> | Fraction | bigint | string): Amount<TCurrency>;
|
|
56
56
|
/**
|
|
57
57
|
* Multiplies this amount by a human-readable multiplier.
|
|
58
58
|
*/
|
|
@@ -67,28 +67,28 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
67
67
|
* Divides this amount by another Amount or raw value.
|
|
68
68
|
* @returns a {@link Fraction} for a precise fractional result.
|
|
69
69
|
*/
|
|
70
|
-
divToFraction(other: Amount | Fraction | bigint | string): Fraction;
|
|
70
|
+
divToFraction(other: Amount<AnyCurrency> | Fraction | bigint | string): Fraction;
|
|
71
71
|
/**
|
|
72
72
|
* Returns true if this amount > other.
|
|
73
73
|
*/
|
|
74
|
-
gt(other: Amount | bigint | string): boolean;
|
|
74
|
+
gt(other: Amount<AnyCurrency> | bigint | string): boolean;
|
|
75
75
|
/**
|
|
76
76
|
* Returns true if this amount >= other.
|
|
77
77
|
*/
|
|
78
|
-
gte(other: Amount | bigint | string): boolean;
|
|
78
|
+
gte(other: Amount<AnyCurrency> | bigint | string): boolean;
|
|
79
79
|
/**
|
|
80
80
|
* Returns true if this amount < other.
|
|
81
81
|
*/
|
|
82
|
-
lt(other: Amount | bigint | string): boolean;
|
|
82
|
+
lt(other: Amount<AnyCurrency> | bigint | string): boolean;
|
|
83
83
|
/**
|
|
84
84
|
* Returns true if this amount <= other.
|
|
85
85
|
*/
|
|
86
|
-
lte(other: Amount | bigint | string): boolean;
|
|
86
|
+
lte(other: Amount<AnyCurrency> | bigint | string): boolean;
|
|
87
87
|
/**
|
|
88
88
|
* Returns true if this amount == other.
|
|
89
89
|
*/
|
|
90
|
-
eq(other: Amount | bigint | string): boolean;
|
|
91
|
-
toJSON(): SerializedAmount<
|
|
90
|
+
eq(other: Amount<AnyCurrency> | bigint | string): boolean;
|
|
91
|
+
toJSON(): SerializedAmount<ReturnType<TCurrency['toJSON']>>;
|
|
92
92
|
/**
|
|
93
93
|
* @param args.maxFixed - The maximum number of fixed decimal places to display, only if relevant, eg. "0" for 0, "1.23" for 1.23, etc.
|
|
94
94
|
* @param args.fixed - The number of fixed decimal places to display, always, eg. "0.00" for 0, "1.23" for 1.23, etc.
|
|
@@ -97,7 +97,7 @@ export declare class Amount<TCurrency extends Currency = Currency> {
|
|
|
97
97
|
toString(args?: Parameters<typeof numberToFixed>[1]): string;
|
|
98
98
|
toSignificant(significantDigits?: number): string;
|
|
99
99
|
}
|
|
100
|
-
export declare function serializedAmountSchema<TSchema extends
|
|
100
|
+
export declare function serializedAmountSchema<TSchema extends z.ZodType>(currencySchema: TSchema): z.ZodObject<{
|
|
101
101
|
currency: TSchema;
|
|
102
102
|
amount: z.ZodString;
|
|
103
103
|
}, z.core.$strip>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../generic/currency/amount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EA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AC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAGhE;IAED;;OAEG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAG/D;IAED;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAGhE;IAED;;OAEG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAG/D;IAEM,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAKjE;IAED;;;;OAIG;IACI,QAAQ,CACb,IAAI,GAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAEvC,GACA,MAAM,CAGR;IAEM,aAAa,CAAC,iBAAiB,SAAI,GAAG,MAAM,CAIlD;CACF;AAED,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EAC9D,cAAc,EAAE,OAAO;;;kBAMxB"}
|
|
@@ -4,7 +4,7 @@ import type { Native } from './native.js';
|
|
|
4
4
|
import type { SerializedCurrency } from './serialized-currency.js';
|
|
5
5
|
import type { Token } from './token.js';
|
|
6
6
|
export type CurrencyMetadata = Record<string, unknown>;
|
|
7
|
-
export declare abstract class BaseCurrency<TChainId extends
|
|
7
|
+
export declare abstract class BaseCurrency<TChainId extends string | number = ChainId, TMetadata extends CurrencyMetadata = Record<string, unknown>, TCurrencyType extends string = string, TSerializedCurrency extends object = SerializedCurrency<TMetadata>> {
|
|
8
8
|
readonly chainId: TChainId;
|
|
9
9
|
readonly symbol: string;
|
|
10
10
|
readonly name: string;
|
|
@@ -21,9 +21,11 @@ export declare abstract class BaseCurrency<TChainId extends ChainId = ChainId, T
|
|
|
21
21
|
metadata?: TMetadata;
|
|
22
22
|
});
|
|
23
23
|
abstract get id(): ID<TChainId, string, true>;
|
|
24
|
-
isSame(other: BaseCurrency<
|
|
24
|
+
isSame(other: BaseCurrency<string | number, CurrencyMetadata, string, object>): boolean;
|
|
25
25
|
abstract wrap(): BaseCurrency<TChainId, TMetadata, TCurrencyType, TSerializedCurrency>;
|
|
26
26
|
abstract toJSON(): TSerializedCurrency;
|
|
27
27
|
}
|
|
28
28
|
export type Currency<TChainId extends ChainId = ChainId, TMetadata extends CurrencyMetadata = Record<string, unknown>> = Native<TChainId, TMetadata> | Token<TChainId, string, TMetadata>;
|
|
29
|
+
/** The open currency contract accepted by generic monetary primitives. */
|
|
30
|
+
export type AnyCurrency = BaseCurrency<string | number, CurrencyMetadata, string, object>;
|
|
29
31
|
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../generic/currency/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEtD,8BAAsB,YAAY,CAChC,QAAQ,SAAS,
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../generic/currency/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CA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,CAClC,QAAQ,EACR,SAAS,EACT,aAAa,EACb,mBAAmB,CACpB,CAAA;IAED,SAAgB,MAAM,IAAI,mBAAmB,CAAA;CAC9C;AAED,MAAM,MAAM,QAAQ,CAClB,QAAQ,SAAS,OAAO,GAAG,OAAO,EAClC,SAAS,SAAS,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC1D,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AAEpE,0EAA0E;AAC1E,MAAM,MAAM,WAAW,GAAG,YAAY,CACpC,MAAM,GAAG,MAAM,EACf,gBAAgB,EAChB,MAAM,EACN,MAAM,CACP,CAAA"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Fraction } from '../math/fraction.js';
|
|
2
2
|
import type { BigintIsh } from '../types/bigintish.js';
|
|
3
3
|
import { Amount } from './amount.js';
|
|
4
|
-
import type {
|
|
5
|
-
export declare class Price<TBase extends
|
|
4
|
+
import type { AnyCurrency } from './currency.js';
|
|
5
|
+
export declare class Price<TBase extends AnyCurrency, TQuote extends AnyCurrency> extends Fraction {
|
|
6
6
|
readonly base: TBase;
|
|
7
7
|
readonly quote: TQuote;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a Price from a human-readable quote-per-base value, e.g. "1.5".
|
|
10
10
|
*/
|
|
11
|
-
static fromHuman<TBase extends
|
|
11
|
+
static fromHuman<TBase extends AnyCurrency, TQuote extends AnyCurrency>(base: TBase, quote: TQuote, value: string): Price<TBase, TQuote>;
|
|
12
12
|
/**
|
|
13
13
|
* Tries to create a Price from a human-readable quote-per-base value.
|
|
14
14
|
*/
|
|
15
|
-
static tryFromHuman<TBase extends
|
|
15
|
+
static tryFromHuman<TBase extends AnyCurrency, TQuote extends AnyCurrency>(base: TBase, quote: TQuote, value: string): Price<TBase, TQuote> | undefined;
|
|
16
16
|
constructor(args: {
|
|
17
17
|
base: TBase;
|
|
18
18
|
quote: TQuote;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../../generic/currency/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,qBAAa,KAAK,CAChB,KAAK,SAAS,WAAW,EACzB,MAAM,SAAS,WAAW,CAC1B,SAAQ,QAAQ;IAChB,SAAgB,IAAI,EAAE,KAAK,CAAA;IAC3B,SAAgB,KAAK,EAAE,MAAM,CAAA;IAE7B;;OAEG;IACH,OAAc,SAAS,CACrB,KAAK,SAAS,WAAW,EACzB,MAAM,SAAS,WAAW,EAC1B,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAejE;IAED;;OAEG;IACH,OAAc,YAAY,CACxB,KAAK,SAAS,WAAW,EACzB,MAAM,SAAS,WAAW,EAE1B,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAMlC;IAED,YACE,IAAI,EACA;QACE,IAAI,EAAE,KAAK,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,SAAS,CAAA;QACpB,WAAW,CAAC,EAAE,SAAS,CAAA;KACxB,GACD;QAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;KAAE,EAc/D;IAED,IAAI,MAAM,IAAI,QAAQ,CAKrB;IAED;;;;OAIG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAGzD;IAEe,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAO7C;IAEe,QAAQ,IAAI,MAAM,CAEjC;IAEe,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAE1E;IAEe,aAAa,CAAC,iBAAiB,SAAI,GAAG,MAAM,CAI3D;CACF"}
|
|
@@ -10,7 +10,7 @@ export declare abstract class Token<TChainId extends ChainId = ChainId, TAddress
|
|
|
10
10
|
address: TAddress;
|
|
11
11
|
} & ConstructorParameters<typeof BaseCurrency<TChainId, TMetadata>>[0]);
|
|
12
12
|
get id(): ID<TChainId, TAddress>;
|
|
13
|
-
isSame(other: BaseCurrency<
|
|
13
|
+
isSame(other: BaseCurrency<string | number, CurrencyMetadata, string, object>): boolean;
|
|
14
14
|
abstract wrap(): Token<TChainId, TAddress, TMetadata>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../generic/currency/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,KAAK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AO,QAAO;IAEhC,SAAgB,OAAO,EAAE,QAAQ,CAAA;IAEjC,YAAY,EACV,OAAO,EACP,GAAG,IAAI,EACR,EAAE;QACD,OAAO,EAAE,QAAQ,CAAA;KAClB,GAAG,qBAAqB,CAAC,OAAO,YAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAGrE;IAED,IAAa,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAExC;IAEe,MAAM,CACpB,KAAK,EAAE,YAAY,CAAC,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,GACrE,OAAO,CAMT;IAED,SAAyB,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;CACtE"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ChainId } from '../chain/chains.js';
|
|
2
|
-
export type ID<TChainId extends
|
|
2
|
+
export type ID<TChainId extends string | number = ChainId, TAddress extends string = string, TIncludeNative extends boolean = false> = `${TChainId}:${TAddress}` | (TIncludeNative extends true ? `${TChainId}:NATIVE` : never);
|
|
3
3
|
//# sourceMappingURL=id.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../generic/types/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,MAAM,EAAE,CACZ,QAAQ,SAAS,
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../generic/types/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,MAAM,EAAE,CACZ,QAAQ,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,EAC1C,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,cAAc,SAAS,OAAO,GAAG,KAAK,IAEpC,GAAG,QAAQ,IAAI,QAAQ,EAAE,GACzB,CAAC,cAAc,SAAS,IAAI,GAAG,GAAG,QAAQ,SAAS,GAAG,KAAK,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Amount } from '../currency/amount.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AnyCurrency } from '../currency/currency.js';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* @param amount The amount to subtract slippage from.
|
|
@@ -7,5 +7,5 @@ import type { Currency } from '../currency/currency.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @returns The amount after subtracting the slippage, eg. amount * 0.9 if slippage is 10% (0.1).
|
|
9
9
|
*/
|
|
10
|
-
export declare function subtractSlippage<TCurrency extends
|
|
10
|
+
export declare function subtractSlippage<TCurrency extends AnyCurrency>(amount: Amount<TCurrency>, slippage: number): Amount<TCurrency>;
|
|
11
11
|
//# sourceMappingURL=subtract-slippage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtract-slippage.d.ts","sourceRoot":"","sources":["../../../generic/utils/subtract-slippage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"subtract-slippage.d.ts","sourceRoot":"","sources":["../../../generic/utils/subtract-slippage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,SAAS,WAAW,EAC5D,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EACzB,QAAQ,EAAE,MAAM,qBAOjB"}
|
package/_types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "7.
|
|
1
|
+
export declare const version = "7.2.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -3,13 +3,10 @@ import * as z from 'zod'
|
|
|
3
3
|
import { numberToFixed } from '../format/number.js'
|
|
4
4
|
import { Fraction } from '../math/fraction.js'
|
|
5
5
|
import type { BigintIsh } from '../types/bigintish.js'
|
|
6
|
-
import type { Currency } from './currency.js'
|
|
7
|
-
import type {
|
|
8
|
-
SerializedCurrency,
|
|
9
|
-
SerializedCurrencySchema,
|
|
10
|
-
} from './serialized-currency.js'
|
|
6
|
+
import type { AnyCurrency, Currency } from './currency.js'
|
|
7
|
+
import type { SerializedCurrency } from './serialized-currency.js'
|
|
11
8
|
|
|
12
|
-
export type SerializedAmount<TCurrency extends SerializedCurrency> = {
|
|
9
|
+
export type SerializedAmount<TCurrency extends object = SerializedCurrency> = {
|
|
13
10
|
currency: TCurrency
|
|
14
11
|
amount: string
|
|
15
12
|
}
|
|
@@ -17,7 +14,7 @@ export type SerializedAmount<TCurrency extends SerializedCurrency> = {
|
|
|
17
14
|
/**
|
|
18
15
|
* Represents an amount of a particular currency.
|
|
19
16
|
*/
|
|
20
|
-
export class Amount<TCurrency extends
|
|
17
|
+
export class Amount<TCurrency extends AnyCurrency = Currency> {
|
|
21
18
|
/** The currency of this amount */
|
|
22
19
|
public readonly currency: TCurrency
|
|
23
20
|
|
|
@@ -36,7 +33,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
36
33
|
* Creates an Amount from a human-readable value, e.g. "1.5".
|
|
37
34
|
* Just a wrapper around viem's `parseUnits` to handle the currency's decimals.
|
|
38
35
|
*/
|
|
39
|
-
public static fromHuman<TCurrency extends
|
|
36
|
+
public static fromHuman<TCurrency extends AnyCurrency>(
|
|
40
37
|
currency: TCurrency,
|
|
41
38
|
human: bigint | number | string,
|
|
42
39
|
): Amount<TCurrency> {
|
|
@@ -47,7 +44,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
47
44
|
/**
|
|
48
45
|
* Creates an Amount from a human-readable value, e.g. "1.5".
|
|
49
46
|
*/
|
|
50
|
-
public static tryFromHuman<TCurrency extends
|
|
47
|
+
public static tryFromHuman<TCurrency extends AnyCurrency>(
|
|
51
48
|
currency: TCurrency,
|
|
52
49
|
human: bigint | number | string,
|
|
53
50
|
): Amount<TCurrency> | undefined {
|
|
@@ -68,9 +65,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
68
65
|
)
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
private static getRawAmount<TCurrency extends
|
|
68
|
+
private static getRawAmount<TCurrency extends AnyCurrency>(
|
|
72
69
|
_ref: Amount<TCurrency>,
|
|
73
|
-
other: Amount | bigint | string,
|
|
70
|
+
other: Amount<AnyCurrency> | bigint | string,
|
|
74
71
|
): bigint {
|
|
75
72
|
if (other instanceof Amount) {
|
|
76
73
|
return other.amount
|
|
@@ -81,7 +78,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
81
78
|
/**
|
|
82
79
|
* Adds another Amount or raw value.
|
|
83
80
|
*/
|
|
84
|
-
public add(
|
|
81
|
+
public add(
|
|
82
|
+
other: Amount<AnyCurrency> | Fraction | bigint | string,
|
|
83
|
+
): Amount<TCurrency> {
|
|
85
84
|
let add: bigint
|
|
86
85
|
|
|
87
86
|
if (other instanceof Fraction) {
|
|
@@ -104,7 +103,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
104
103
|
/**
|
|
105
104
|
* Subtracts another Amount or raw value.
|
|
106
105
|
*/
|
|
107
|
-
public sub(
|
|
106
|
+
public sub(
|
|
107
|
+
other: Amount<AnyCurrency> | Fraction | bigint | string,
|
|
108
|
+
): Amount<TCurrency> {
|
|
108
109
|
let sub: bigint
|
|
109
110
|
|
|
110
111
|
if (other instanceof Fraction) {
|
|
@@ -127,7 +128,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
127
128
|
/**
|
|
128
129
|
* Multiplies this amount by another amount or raw value.
|
|
129
130
|
*/
|
|
130
|
-
public mul(
|
|
131
|
+
public mul(
|
|
132
|
+
other: Amount<AnyCurrency> | Fraction | bigint | string,
|
|
133
|
+
): Amount<TCurrency> {
|
|
131
134
|
if (other instanceof Fraction) {
|
|
132
135
|
return new Amount(
|
|
133
136
|
this.currency,
|
|
@@ -164,7 +167,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
164
167
|
* Divides this amount by another Amount or raw value.
|
|
165
168
|
* @returns a {@link Fraction} for a precise fractional result.
|
|
166
169
|
*/
|
|
167
|
-
public divToFraction(
|
|
170
|
+
public divToFraction(
|
|
171
|
+
other: Amount<AnyCurrency> | Fraction | bigint | string,
|
|
172
|
+
): Fraction {
|
|
168
173
|
if (other instanceof Fraction) {
|
|
169
174
|
return new Fraction({
|
|
170
175
|
numerator: this.amount * other.denominator,
|
|
@@ -179,7 +184,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
179
184
|
/**
|
|
180
185
|
* Returns true if this amount > other.
|
|
181
186
|
*/
|
|
182
|
-
public gt(other: Amount | bigint | string): boolean {
|
|
187
|
+
public gt(other: Amount<AnyCurrency> | bigint | string): boolean {
|
|
183
188
|
const cmp = Amount.getRawAmount(this, other)
|
|
184
189
|
return this.amount > cmp
|
|
185
190
|
}
|
|
@@ -187,7 +192,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
187
192
|
/**
|
|
188
193
|
* Returns true if this amount >= other.
|
|
189
194
|
*/
|
|
190
|
-
public gte(other: Amount | bigint | string): boolean {
|
|
195
|
+
public gte(other: Amount<AnyCurrency> | bigint | string): boolean {
|
|
191
196
|
const cmp = Amount.getRawAmount(this, other)
|
|
192
197
|
return this.amount >= cmp
|
|
193
198
|
}
|
|
@@ -195,7 +200,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
195
200
|
/**
|
|
196
201
|
* Returns true if this amount < other.
|
|
197
202
|
*/
|
|
198
|
-
public lt(other: Amount | bigint | string): boolean {
|
|
203
|
+
public lt(other: Amount<AnyCurrency> | bigint | string): boolean {
|
|
199
204
|
const cmp = Amount.getRawAmount(this, other)
|
|
200
205
|
return this.amount < cmp
|
|
201
206
|
}
|
|
@@ -203,7 +208,7 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
203
208
|
/**
|
|
204
209
|
* Returns true if this amount <= other.
|
|
205
210
|
*/
|
|
206
|
-
public lte(other: Amount | bigint | string): boolean {
|
|
211
|
+
public lte(other: Amount<AnyCurrency> | bigint | string): boolean {
|
|
207
212
|
const cmp = Amount.getRawAmount(this, other)
|
|
208
213
|
return this.amount <= cmp
|
|
209
214
|
}
|
|
@@ -211,14 +216,14 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
211
216
|
/**
|
|
212
217
|
* Returns true if this amount == other.
|
|
213
218
|
*/
|
|
214
|
-
public eq(other: Amount | bigint | string): boolean {
|
|
219
|
+
public eq(other: Amount<AnyCurrency> | bigint | string): boolean {
|
|
215
220
|
const cmp = Amount.getRawAmount(this, other)
|
|
216
221
|
return this.amount === cmp
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
public toJSON(): SerializedAmount<
|
|
224
|
+
public toJSON(): SerializedAmount<ReturnType<TCurrency['toJSON']>> {
|
|
220
225
|
return {
|
|
221
|
-
currency: this.currency.toJSON()
|
|
226
|
+
currency: this.currency.toJSON() as ReturnType<TCurrency['toJSON']>,
|
|
222
227
|
amount: this.amount.toString(),
|
|
223
228
|
} as const
|
|
224
229
|
}
|
|
@@ -244,9 +249,9 @@ export class Amount<TCurrency extends Currency = Currency> {
|
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
|
|
247
|
-
export function serializedAmountSchema<
|
|
248
|
-
TSchema
|
|
249
|
-
|
|
252
|
+
export function serializedAmountSchema<TSchema extends z.ZodType>(
|
|
253
|
+
currencySchema: TSchema,
|
|
254
|
+
) {
|
|
250
255
|
return z.object({
|
|
251
256
|
currency: currencySchema,
|
|
252
257
|
amount: z.string(),
|
|
@@ -7,7 +7,7 @@ import type { Token } from './token.js'
|
|
|
7
7
|
export type CurrencyMetadata = Record<string, unknown>
|
|
8
8
|
|
|
9
9
|
export abstract class BaseCurrency<
|
|
10
|
-
TChainId extends
|
|
10
|
+
TChainId extends string | number = ChainId,
|
|
11
11
|
TMetadata extends CurrencyMetadata = Record<string, unknown>,
|
|
12
12
|
TCurrencyType extends string = string,
|
|
13
13
|
TSerializedCurrency extends object = SerializedCurrency<TMetadata>,
|
|
@@ -47,10 +47,11 @@ export abstract class BaseCurrency<
|
|
|
47
47
|
abstract get id(): ID<TChainId, string, true>
|
|
48
48
|
|
|
49
49
|
public isSame(
|
|
50
|
-
other: BaseCurrency<
|
|
50
|
+
other: BaseCurrency<string | number, CurrencyMetadata, string, object>,
|
|
51
51
|
): boolean {
|
|
52
52
|
return (
|
|
53
53
|
this.chainId === other.chainId &&
|
|
54
|
+
this.id === other.id &&
|
|
54
55
|
this.decimals === other.decimals &&
|
|
55
56
|
this.type === other.type
|
|
56
57
|
)
|
|
@@ -70,3 +71,11 @@ export type Currency<
|
|
|
70
71
|
TChainId extends ChainId = ChainId,
|
|
71
72
|
TMetadata extends CurrencyMetadata = Record<string, unknown>,
|
|
72
73
|
> = Native<TChainId, TMetadata> | Token<TChainId, string, TMetadata>
|
|
74
|
+
|
|
75
|
+
/** The open currency contract accepted by generic monetary primitives. */
|
|
76
|
+
export type AnyCurrency = BaseCurrency<
|
|
77
|
+
string | number,
|
|
78
|
+
CurrencyMetadata,
|
|
79
|
+
string,
|
|
80
|
+
object
|
|
81
|
+
>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
|
+
import { subtractSlippage } from '../utils/subtract-slippage.js'
|
|
3
|
+
import { Amount } from './amount.js'
|
|
4
|
+
import { BaseCurrency, type Currency } from './currency.js'
|
|
5
|
+
import { Price } from './price.js'
|
|
6
|
+
|
|
7
|
+
type SerializedPoints = Readonly<{
|
|
8
|
+
type: 'points'
|
|
9
|
+
chainId: 'rewards'
|
|
10
|
+
id: 'rewards:POINTS'
|
|
11
|
+
}>
|
|
12
|
+
|
|
13
|
+
class PointsCurrency extends BaseCurrency<
|
|
14
|
+
'rewards',
|
|
15
|
+
Record<string, never>,
|
|
16
|
+
'points',
|
|
17
|
+
SerializedPoints
|
|
18
|
+
> {
|
|
19
|
+
override readonly type = 'points' as const
|
|
20
|
+
override readonly isNative = false as const
|
|
21
|
+
override readonly isToken = false as const
|
|
22
|
+
override readonly id = 'rewards:POINTS' as const
|
|
23
|
+
|
|
24
|
+
public override wrap(): PointsCurrency {
|
|
25
|
+
return this
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public override toJSON(): SerializedPoints {
|
|
29
|
+
return { type: this.type, chainId: this.chainId, id: this.id }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare const points: PointsCurrency
|
|
34
|
+
|
|
35
|
+
describe('external currency extension types', () => {
|
|
36
|
+
it('preserves external currency and serialization types', () => {
|
|
37
|
+
const amount = new Amount(points, 1n)
|
|
38
|
+
|
|
39
|
+
expectTypeOf(amount).toEqualTypeOf<Amount<PointsCurrency>>()
|
|
40
|
+
expectTypeOf(amount.toJSON().currency).toEqualTypeOf<SerializedPoints>()
|
|
41
|
+
expectTypeOf<PointsCurrency>().not.toMatchTypeOf<Currency>()
|
|
42
|
+
|
|
43
|
+
expectTypeOf(amount.wrap()).toEqualTypeOf<Amount<PointsCurrency>>()
|
|
44
|
+
expectTypeOf(Price.fromHuman(points, points, '1')).toEqualTypeOf<
|
|
45
|
+
Price<PointsCurrency, PointsCurrency>
|
|
46
|
+
>()
|
|
47
|
+
expectTypeOf(subtractSlippage(amount, 0.1)).toEqualTypeOf<
|
|
48
|
+
Amount<PointsCurrency>
|
|
49
|
+
>()
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import * as z from 'zod'
|
|
3
|
+
import { subtractSlippage } from '../utils/subtract-slippage.js'
|
|
4
|
+
import { Amount, serializedAmountSchema } from './amount.js'
|
|
5
|
+
import { BaseCurrency } from './currency.js'
|
|
6
|
+
import { Price } from './price.js'
|
|
7
|
+
|
|
8
|
+
type SerializedPointsCurrency = Readonly<{
|
|
9
|
+
type: 'points'
|
|
10
|
+
chainId: 'rewards'
|
|
11
|
+
id: `rewards:${string}`
|
|
12
|
+
}>
|
|
13
|
+
|
|
14
|
+
class PointsCurrency extends BaseCurrency<
|
|
15
|
+
'rewards',
|
|
16
|
+
Record<string, never>,
|
|
17
|
+
'points',
|
|
18
|
+
SerializedPointsCurrency
|
|
19
|
+
> {
|
|
20
|
+
override readonly type = 'points' as const
|
|
21
|
+
override readonly isNative = false as const
|
|
22
|
+
override readonly isToken = false as const
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
public override readonly id: `rewards:${string}` = 'rewards:POINTS',
|
|
26
|
+
) {
|
|
27
|
+
super({
|
|
28
|
+
chainId: 'rewards',
|
|
29
|
+
decimals: 0,
|
|
30
|
+
symbol: 'PTS',
|
|
31
|
+
name: 'Reward Points',
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public override wrap(): PointsCurrency {
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public override toJSON(): SerializedPointsCurrency {
|
|
40
|
+
return { type: this.type, chainId: this.chainId, id: this.id }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('external currency extension contract', () => {
|
|
45
|
+
const points = new PointsCurrency()
|
|
46
|
+
|
|
47
|
+
it('works with Amount without joining the Currency union', () => {
|
|
48
|
+
const amount = new Amount(points, 100n)
|
|
49
|
+
|
|
50
|
+
expect(amount.amount).toBe(100n)
|
|
51
|
+
expect(amount.currency).toBe(points)
|
|
52
|
+
expect(amount.wrap().currency).toBe(points)
|
|
53
|
+
expect(amount.toJSON()).toEqual({
|
|
54
|
+
currency: points.toJSON(),
|
|
55
|
+
amount: '100',
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('uses the currency id for value identity', () => {
|
|
60
|
+
expect(points.isSame(new PointsCurrency('rewards:POINTS'))).toBe(true)
|
|
61
|
+
expect(points.isSame(new PointsCurrency('rewards:OTHER'))).toBe(false)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('accepts an external serialized currency schema', () => {
|
|
65
|
+
const schema = serializedAmountSchema(
|
|
66
|
+
z.object({
|
|
67
|
+
type: z.literal('points'),
|
|
68
|
+
chainId: z.literal('rewards'),
|
|
69
|
+
id: z.literal('rewards:POINTS'),
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
expect(schema.parse(new Amount(points, 100n).toJSON()).amount).toBe('100')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('works with the remaining generic currency utilities', () => {
|
|
77
|
+
const price = Price.fromHuman(points, points, '1.5')
|
|
78
|
+
const amount = new Amount(points, 100n)
|
|
79
|
+
|
|
80
|
+
expect(price.getQuote(amount).amount).toBe(150n)
|
|
81
|
+
expect(subtractSlippage(amount, 0.1).amount).toBe(90n)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Fraction } from '../math/fraction.js'
|
|
2
2
|
import type { BigintIsh } from '../types/bigintish.js'
|
|
3
3
|
import { Amount } from './amount.js'
|
|
4
|
-
import type {
|
|
4
|
+
import type { AnyCurrency } from './currency.js'
|
|
5
5
|
|
|
6
6
|
export class Price<
|
|
7
|
-
TBase extends
|
|
8
|
-
TQuote extends
|
|
7
|
+
TBase extends AnyCurrency,
|
|
8
|
+
TQuote extends AnyCurrency,
|
|
9
9
|
> extends Fraction {
|
|
10
10
|
public readonly base: TBase
|
|
11
11
|
public readonly quote: TQuote
|
|
@@ -13,11 +13,10 @@ export class Price<
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a Price from a human-readable quote-per-base value, e.g. "1.5".
|
|
15
15
|
*/
|
|
16
|
-
public static fromHuman<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
): Price<TBase, TQuote> {
|
|
16
|
+
public static fromHuman<
|
|
17
|
+
TBase extends AnyCurrency,
|
|
18
|
+
TQuote extends AnyCurrency,
|
|
19
|
+
>(base: TBase, quote: TQuote, value: string): Price<TBase, TQuote> {
|
|
21
20
|
if (!value.match(/^\d*\.?\d+$/)) {
|
|
22
21
|
throw new Error(`Invalid price: ${value}`)
|
|
23
22
|
}
|
|
@@ -37,7 +36,10 @@ export class Price<
|
|
|
37
36
|
/**
|
|
38
37
|
* Tries to create a Price from a human-readable quote-per-base value.
|
|
39
38
|
*/
|
|
40
|
-
public static tryFromHuman<
|
|
39
|
+
public static tryFromHuman<
|
|
40
|
+
TBase extends AnyCurrency,
|
|
41
|
+
TQuote extends AnyCurrency,
|
|
42
|
+
>(
|
|
41
43
|
base: TBase,
|
|
42
44
|
quote: TQuote,
|
|
43
45
|
value: string,
|
package/generic/types/id.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Amount } from '../currency/amount.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type { AnyCurrency } from '../currency/currency.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@ import type { Currency } from '../currency/currency.js'
|
|
|
8
8
|
*
|
|
9
9
|
* @returns The amount after subtracting the slippage, eg. amount * 0.9 if slippage is 10% (0.1).
|
|
10
10
|
*/
|
|
11
|
-
export function subtractSlippage<TCurrency extends
|
|
11
|
+
export function subtractSlippage<TCurrency extends AnyCurrency>(
|
|
12
12
|
amount: Amount<TCurrency>,
|
|
13
13
|
slippage: number,
|
|
14
14
|
) {
|