sushi 7.1.0 → 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/evm/config/subgraphs/get-subgraph-url.js +13 -1
- package/_cjs/evm/config/subgraphs/get-subgraph-url.js.map +1 -1
- package/_cjs/evm/config/subgraphs/index.js.map +1 -1
- 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/evm/config/subgraphs/get-subgraph-url.js +13 -1
- package/_esm/evm/config/subgraphs/get-subgraph-url.js.map +1 -1
- package/_esm/evm/config/subgraphs/index.js.map +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/evm/config/subgraphs/get-subgraph-url.d.ts +7 -1
- package/_types/evm/config/subgraphs/get-subgraph-url.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/index.d.ts +1 -0
- package/_types/evm/config/subgraphs/index.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/blade.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/blade.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/blocks.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/blocks.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/master-chef-v1.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/master-chef-v1.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/master-chef-v2.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/master-chef-v2.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/mini-chef.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/mini-chef.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushi-bar.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/sushi-bar.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v2.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v2.d.ts.map +1 -1
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v3.d.ts +5 -2
- package/_types/evm/config/subgraphs/subgraphs/sushiswap-v3.d.ts.map +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/evm/config/subgraphs/get-subgraph-url.ts +31 -1
- package/evm/config/subgraphs/index.ts +1 -0
- package/evm/config/subgraphs/subgraph-url.test-d.ts +51 -0
- package/evm/config/subgraphs/subgraph-url.test.ts +28 -0
- 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.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,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../generic/currency/amount.ts"],"names":[],"mappings":"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"}
|
|
@@ -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,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,MAAM,GAAG,MAAM,GAAG,OAAO,EAC1C,SAAS,SAAS,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,mBAAmB,SAAS,MAAM,GAAG,kBAAkB,CAAC,SAAS,CAAC;IAElE,SAAgB,OAAO,EAAE,QAAQ,CAAA;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAA;IAC9B,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC,SAAgB,QAAQ,EAAE,SAAS,CAAA;IAEnC,kBAAyB,IAAI,EAAE,aAAa,CAAA;IAC5C,kBAAyB,QAAQ,EAAE,OAAO,CAAA;IAC1C,kBAAyB,OAAO,EAAE,OAAO,CAAA;IAEzC,YAAY,EACV,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,QAAQ,CAAA;QACjB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,CAAC,EAAE,SAAS,CAAA;KACrB,EAOA;IAED,QAAQ,KAAK,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAEtC,MAAM,CACX,KAAK,EAAE,YAAY,CAAC,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,GACrE,OAAO,CAOT;IAED,SAAgB,IAAI,IAAI,YAAY,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,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEnE,8BAAsB,KAAK,CACzB,QAAQ,SAAS,OAAO,GAAG,OAAO,EAClC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,SAAS,SAAS,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC5D,SAAQ,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;IAClD,SAAkB,IAAI,WAAU;IAChC,SAAkB,QAAQ,SAAQ;IAClC,SAAkB,OAAO,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,
|
|
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,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEnE,8BAAsB,KAAK,CACzB,QAAQ,SAAS,OAAO,GAAG,OAAO,EAClC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,SAAS,SAAS,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC5D,SAAQ,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;IAClD,SAAkB,IAAI,WAAU;IAChC,SAAkB,QAAQ,SAAQ;IAClC,SAAkB,OAAO,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
|
|
@@ -34,6 +34,12 @@ type DecentralizedEntry = {
|
|
|
34
34
|
|
|
35
35
|
type _COMPLETENESS = 'COMPLETE' | 'PARTIAL'
|
|
36
36
|
|
|
37
|
+
export type SubgraphChainId<
|
|
38
|
+
TResolver extends {
|
|
39
|
+
readonly chainIds: readonly EvmChainId[]
|
|
40
|
+
},
|
|
41
|
+
> = TResolver['chainIds'][number]
|
|
42
|
+
|
|
37
43
|
// Double-wrap to allow of automatic DECENTRALIZED and OTHER type inference
|
|
38
44
|
function getSubgraphUrlWrapperWrapper<
|
|
39
45
|
DECENTRALIZED extends EvmChainId,
|
|
@@ -50,6 +56,22 @@ function getSubgraphUrlWrapperWrapper<
|
|
|
50
56
|
: EvmChainId,
|
|
51
57
|
COMPLETENESS extends _COMPLETENESS,
|
|
52
58
|
>() {
|
|
59
|
+
const chainIds = Object.freeze(
|
|
60
|
+
Array.from(
|
|
61
|
+
new Set([
|
|
62
|
+
...Object.keys(subgraphs.decentralizedIds).map(Number),
|
|
63
|
+
...Object.keys(subgraphs.otherUrls).map(Number),
|
|
64
|
+
]),
|
|
65
|
+
) as (DECENTRALIZED | OTHER)[],
|
|
66
|
+
)
|
|
67
|
+
const chainIdSet = new Set<EvmChainId>(chainIds)
|
|
68
|
+
|
|
69
|
+
function supportsChainId(
|
|
70
|
+
chainId: CHAINS,
|
|
71
|
+
): chainId is Extract<DECENTRALIZED | OTHER, CHAINS> {
|
|
72
|
+
return chainIdSet.has(chainId)
|
|
73
|
+
}
|
|
74
|
+
|
|
53
75
|
// Handles the actual url lookup
|
|
54
76
|
function getSubgraphUrl<PASSED_CHAIN extends CHAINS>(
|
|
55
77
|
chainId: PASSED_CHAIN,
|
|
@@ -84,7 +106,15 @@ function getSubgraphUrlWrapperWrapper<
|
|
|
84
106
|
return undefined as Result<PASSED_CHAIN, DECENTRALIZED | OTHER>
|
|
85
107
|
}
|
|
86
108
|
|
|
87
|
-
|
|
109
|
+
const capabilities: {
|
|
110
|
+
readonly chainIds: readonly (DECENTRALIZED | OTHER)[]
|
|
111
|
+
supportsChainId: typeof supportsChainId
|
|
112
|
+
} = {
|
|
113
|
+
chainIds,
|
|
114
|
+
supportsChainId,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return Object.assign(getSubgraphUrl, capabilities)
|
|
88
118
|
}
|
|
89
119
|
|
|
90
120
|
return getSubgraphUrlWrapper
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vitest'
|
|
2
|
+
import { EvmChainId } from '../../chain/index.js'
|
|
3
|
+
import {
|
|
4
|
+
getBlocksSubgraphUrl,
|
|
5
|
+
getSushiSwapV3SubgraphUrl,
|
|
6
|
+
type SubgraphChainId,
|
|
7
|
+
} from '../../index.js'
|
|
8
|
+
|
|
9
|
+
test('resolver capabilities retain their configured chain union', () => {
|
|
10
|
+
type BlocksSubgraphChainId = SubgraphChainId<typeof getBlocksSubgraphUrl>
|
|
11
|
+
|
|
12
|
+
expectTypeOf(getBlocksSubgraphUrl.chainIds).toEqualTypeOf<
|
|
13
|
+
readonly BlocksSubgraphChainId[]
|
|
14
|
+
>()
|
|
15
|
+
expectTypeOf<typeof EvmChainId.ETHEREUM>().toExtend<BlocksSubgraphChainId>()
|
|
16
|
+
expectTypeOf<
|
|
17
|
+
Extract<typeof EvmChainId.ROBINHOOD, BlocksSubgraphChainId>
|
|
18
|
+
>().toBeNever()
|
|
19
|
+
|
|
20
|
+
expectTypeOf(getSushiSwapV3SubgraphUrl.chainIds).toEqualTypeOf<
|
|
21
|
+
readonly SubgraphChainId<typeof getSushiSwapV3SubgraphUrl>[]
|
|
22
|
+
>()
|
|
23
|
+
|
|
24
|
+
function cannotReplaceChainIds() {
|
|
25
|
+
// @ts-expect-error Resolver capability metadata is readonly.
|
|
26
|
+
getBlocksSubgraphUrl.chainIds = []
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void cannotReplaceChainIds
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('supportsChainId narrows chain IDs and guarded lookup results', () => {
|
|
33
|
+
const chainId = {} as EvmChainId
|
|
34
|
+
|
|
35
|
+
if (getBlocksSubgraphUrl.supportsChainId(chainId)) {
|
|
36
|
+
expectTypeOf(chainId).toEqualTypeOf<
|
|
37
|
+
SubgraphChainId<typeof getBlocksSubgraphUrl>
|
|
38
|
+
>()
|
|
39
|
+
expectTypeOf(
|
|
40
|
+
getBlocksSubgraphUrl(chainId, { decentralizedKey: 'test' }),
|
|
41
|
+
).toEqualTypeOf<string>()
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('existing resolver call signatures remain unchanged', () => {
|
|
46
|
+
expectTypeOf(
|
|
47
|
+
getBlocksSubgraphUrl(EvmChainId.ROBINHOOD, {
|
|
48
|
+
decentralizedKey: 'test',
|
|
49
|
+
}),
|
|
50
|
+
).toEqualTypeOf<string | undefined>()
|
|
51
|
+
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, it } from 'vitest'
|
|
2
2
|
import { EvmChainId } from '../../chain/index.js'
|
|
3
|
+
import { getSubgraphUrlWrapper } from './get-subgraph-url.js'
|
|
3
4
|
import { getBlocksSubgraphUrl } from './subgraphs/blocks.js'
|
|
4
5
|
import { getSushiSwapV3SubgraphUrl } from './subgraphs/sushiswap-v3.js'
|
|
5
6
|
|
|
@@ -28,4 +29,31 @@ describe('subgraph urls', () => {
|
|
|
28
29
|
})
|
|
29
30
|
expect(actual).toBeUndefined()
|
|
30
31
|
})
|
|
32
|
+
|
|
33
|
+
it('derives immutable capabilities from both endpoint maps', () => {
|
|
34
|
+
const resolver = getSubgraphUrlWrapper({
|
|
35
|
+
decentralizedIds: {
|
|
36
|
+
[EvmChainId.ETHEREUM]: { type: 'subgraphId', id: 'ethereum' },
|
|
37
|
+
[EvmChainId.POLYGON]: { type: 'subgraphId', id: 'polygon' },
|
|
38
|
+
},
|
|
39
|
+
otherUrls: {
|
|
40
|
+
[EvmChainId.POLYGON]: 'polygon',
|
|
41
|
+
[EvmChainId.FILECOIN]: 'filecoin',
|
|
42
|
+
},
|
|
43
|
+
})<EvmChainId, 'PARTIAL'>()
|
|
44
|
+
|
|
45
|
+
expect(resolver.chainIds).toEqual([
|
|
46
|
+
EvmChainId.ETHEREUM,
|
|
47
|
+
EvmChainId.POLYGON,
|
|
48
|
+
EvmChainId.FILECOIN,
|
|
49
|
+
])
|
|
50
|
+
expect(Object.isFrozen(resolver.chainIds)).toBe(true)
|
|
51
|
+
expect(resolver.supportsChainId(EvmChainId.ETHEREUM)).toBe(true)
|
|
52
|
+
expect(resolver.supportsChainId(EvmChainId.FILECOIN)).toBe(true)
|
|
53
|
+
expect(resolver.supportsChainId(EvmChainId.ROBINHOOD)).toBe(false)
|
|
54
|
+
const mutableChainIds = resolver.chainIds as EvmChainId[]
|
|
55
|
+
expect(() => {
|
|
56
|
+
mutableChainIds.push(EvmChainId.ROBINHOOD)
|
|
57
|
+
}).toThrow(TypeError)
|
|
58
|
+
})
|
|
31
59
|
})
|
|
@@ -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
|
+
})
|