@pancakeswap/swap-sdk-evm 1.2.1 → 1.3.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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Base B20 Asset ABI fragments (Coinbase's `IB20Asset`).
3
+ *
4
+ * B20's ASSET variant has the same cosmetic display multiplier as ERC-8056, under different names.
5
+ * Probed on Base mainnet 2026-07-28: `multiplier()` / `WAD_PRECISION()` / `toScaledBalance()` work;
6
+ * `uiMultiplier()`, the pending getters and ALL of `supportsInterface()` revert. ERC-8056
7
+ * conformance exists in base-std (PR #173) but is not deployed.
8
+ *
9
+ * https://docs.base.org/base-chain/specs/upgrades/beryl/b20
10
+ */
11
+ export declare const b20AssetAbi: readonly [{
12
+ readonly type: "function";
13
+ readonly name: "multiplier";
14
+ readonly inputs: readonly [];
15
+ readonly outputs: readonly [{
16
+ readonly type: "uint256";
17
+ }];
18
+ readonly stateMutability: "view";
19
+ }, {
20
+ readonly type: "function";
21
+ readonly name: "WAD_PRECISION";
22
+ readonly inputs: readonly [];
23
+ readonly outputs: readonly [{
24
+ readonly type: "uint256";
25
+ }];
26
+ readonly stateMutability: "view";
27
+ }, {
28
+ readonly type: "function";
29
+ readonly name: "toScaledBalance";
30
+ readonly inputs: readonly [{
31
+ readonly name: "rawBalance";
32
+ readonly type: "uint256";
33
+ }];
34
+ readonly outputs: readonly [{
35
+ readonly type: "uint256";
36
+ }];
37
+ readonly stateMutability: "view";
38
+ }, {
39
+ readonly type: "function";
40
+ readonly name: "toRawBalance";
41
+ readonly inputs: readonly [{
42
+ readonly name: "scaledBalance";
43
+ readonly type: "uint256";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly name: "rawBalance";
47
+ readonly type: "uint256";
48
+ }];
49
+ readonly stateMutability: "view";
50
+ }, {
51
+ readonly type: "function";
52
+ readonly name: "scaledBalanceOf";
53
+ readonly inputs: readonly [{
54
+ readonly name: "account";
55
+ readonly type: "address";
56
+ }];
57
+ readonly outputs: readonly [{
58
+ readonly type: "uint256";
59
+ }];
60
+ readonly stateMutability: "view";
61
+ }, {
62
+ readonly type: "event";
63
+ readonly name: "UIMultiplierUpdated";
64
+ readonly inputs: readonly [{
65
+ readonly name: "oldMultiplier";
66
+ readonly type: "uint256";
67
+ readonly indexed: false;
68
+ }, {
69
+ readonly name: "newMultiplier";
70
+ readonly type: "uint256";
71
+ readonly indexed: false;
72
+ }, {
73
+ readonly name: "effectiveAtTimestamp";
74
+ readonly type: "uint256";
75
+ readonly indexed: false;
76
+ }];
77
+ }, {
78
+ readonly type: "event";
79
+ readonly name: "MultiplierUpdateCancelled";
80
+ readonly inputs: readonly [{
81
+ readonly name: "cancelledMultiplier";
82
+ readonly type: "uint256";
83
+ readonly indexed: false;
84
+ }, {
85
+ readonly name: "cancelledEffectiveAt";
86
+ readonly type: "uint256";
87
+ readonly indexed: false;
88
+ }];
89
+ }];
90
+ //# sourceMappingURL=B20.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"B20.d.ts","sourceRoot":"","sources":["../../src/abis/B20.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4Dd,CAAA"}
package/dist/b20.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Base B20 — extension module for the scaled-UI subsystem.
3
+ *
4
+ * Owns everything B20-specific: address recognition, precompile addresses, revert decoding.
5
+ * Nothing outside this file and its ABI sibling needs to know B20 exists.
6
+ *
7
+ * Detection is by address prefix, not ERC-165: `supportsInterface` REVERTS on live B20 tokens for
8
+ * every id including ERC-165's own, so the probe could only ever answer "no". Addresses are
9
+ * self-describing instead — `[10-byte prefix][1-byte variant][9-byte keccak(deployer, salt)]` —
10
+ * so the variant is recoverable with zero RPC.
11
+ *
12
+ * https://docs.base.org/base-chain/specs/upgrades/beryl/b20
13
+ */
14
+ import { ChainId } from '@pancakeswap/chains';
15
+ import type { Address } from 'viem';
16
+ /** Detection is gated on these so a `0xb2000…` vanity address elsewhere can't be mistaken for B20. */
17
+ export declare const B20_SUPPORTED_CHAIN_IDS: readonly [ChainId.BASE, ChainId.BASE_SEPOLIA];
18
+ export type B20SupportedChainId = (typeof B20_SUPPORTED_CHAIN_IDS)[number];
19
+ /** The 10-byte prefix shared by every B20 token, lowercase, without `0x`. */
20
+ export declare const B20_ADDRESS_PREFIX: "b2000000000000000000";
21
+ /** Encoded in address byte `[10]`. */
22
+ export declare enum B20Variant {
23
+ ASSET = 0,
24
+ STABLECOIN = 1
25
+ }
26
+ export declare const B20_FACTORY_ADDRESS: "0xB20f000000000000000000000000000000000000";
27
+ export declare const B20_ACTIVATION_REGISTRY_ADDRESS: "0x8453000000000000000000000000000000000001";
28
+ export declare const B20_POLICY_REGISTRY_ADDRESS: "0x8453000000000000000000000000000000000002";
29
+ export declare function isB20SupportedChainId(chainId?: number): chainId is B20SupportedChainId;
30
+ /** Chain-agnostic. Verified equivalent to the factory's own `isB20()` over 24 cases. */
31
+ export declare function isB20Address(address?: string | null): boolean;
32
+ export declare function getB20Variant(address?: string | null): B20Variant | undefined;
33
+ /** Only the ASSET variant carries a multiplier, so a B20 stablecoin must not be treated as scaled. */
34
+ export declare function isB20AssetToken(chainId?: number, address?: string | null): boolean;
35
+ export declare const isB20AssetAddress: (chainId: number | undefined, address: Address | undefined) => boolean;
36
+ /**
37
+ * B20 raises ABI-encoded custom errors, and a swap reverts through the router — whose ABI doesn't
38
+ * declare them — so viem can't name them and only the bare 4-byte selector survives. Matching it is
39
+ * the only reliable hook. `PausableFeature` is an enum, hence `uint8`. Verified against `IB20.sol`.
40
+ */
41
+ export declare const B20_ERROR_SELECTORS: {
42
+ readonly '0xa43fec12': "PolicyForbids";
43
+ readonly '0xfd8c4245': "ContractPaused";
44
+ readonly '0xcccad523': "PolicyNotFound";
45
+ readonly '0xcdd98a4a': "UnsupportedPolicyType";
46
+ readonly '0xf58f733a': "SupplyCapExceeded";
47
+ readonly '0x6f12f3dc': "InvalidMultiplier";
48
+ };
49
+ export type B20ErrorName = (typeof B20_ERROR_SELECTORS)[keyof typeof B20_ERROR_SELECTORS];
50
+ export declare const B20_PAUSABLE_FEATURES: readonly ["TRANSFER", "MINT", "BURN"];
51
+ export type B20PausableFeature = (typeof B20_PAUSABLE_FEATURES)[number];
52
+ export type B20RevertMatch = {
53
+ name: B20ErrorName;
54
+ /** Only for `ContractPaused`, when the revert data carried a decodable feature. */
55
+ feature?: B20PausableFeature;
56
+ };
57
+ /**
58
+ * Scan an error payload for a known B20 custom error. Takes a flattened string so it stays
59
+ * dependency-free; returns `undefined` so callers keep their generic handling.
60
+ */
61
+ export declare function matchB20RevertError(input?: string | null): B20RevertMatch | undefined;
62
+ //# sourceMappingURL=b20.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b20.d.ts","sourceRoot":"","sources":["../src/b20.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,sGAAsG;AACtG,eAAO,MAAM,uBAAuB,+CAAgD,CAAA;AAEpF,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1E,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,EAAG,sBAA+B,CAAA;AAEjE,sCAAsC;AACtC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,UAAU,IAAI;CACf;AAED,eAAO,MAAM,mBAAmB,EAAG,4CAAqD,CAAA;AACxF,eAAO,MAAM,+BAA+B,EAAG,4CAAqD,CAAA;AACpG,eAAO,MAAM,2BAA2B,EAAG,4CAAqD,CAAA;AAShG,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,IAAI,mBAAmB,CAEtF;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAI7D;AAED,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAW7E;AAED,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAElF;AAED,eAAO,MAAM,iBAAiB,YAAa,MAAM,GAAG,SAAS,WAAW,OAAO,GAAG,SAAS,KAAG,OAC3D,CAAA;AAMnC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;CAOtB,CAAA;AAEV,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAA;AAEzF,eAAO,MAAM,qBAAqB,uCAAwC,CAAA;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvE,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAA;IAClB,mFAAmF;IACnF,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B,CAAA;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,GAAG,SAAS,CAkBrF"}
@@ -1,3 +1,4 @@
1
+ import { ChainId } from '@pancakeswap/chains';
1
2
  import { Percent } from '@pancakeswap/swap-sdk-core';
2
3
  import { ERC20Token } from './entities/erc20Token';
3
4
  export declare const ZERO_PERCENT: Percent;
@@ -32,29 +33,16 @@ export declare const WBNB: {
32
33
  5611: ERC20Token;
33
34
  204: ERC20Token;
34
35
  };
35
- export declare const WNATIVE: {
36
- 1: ERC20Token;
37
- 5: ERC20Token;
38
- 56: ERC20Token;
39
- 97: ERC20Token;
40
- 42161: ERC20Token;
41
- 421613: ERC20Token;
42
- 324: ERC20Token;
43
- 280: ERC20Token;
44
- 59144: ERC20Token;
45
- 59140: ERC20Token;
46
- 5611: ERC20Token;
47
- 204: ERC20Token;
48
- 8453: ERC20Token;
49
- 84531: ERC20Token;
50
- 534351: ERC20Token;
51
- 11155111: ERC20Token;
52
- 421614: ERC20Token;
53
- 84532: ERC20Token;
54
- 143: ERC20Token;
55
- 10143: ERC20Token;
56
- 4663: ERC20Token;
57
- };
36
+ export declare const WNATIVE: Partial<Record<ChainId, ERC20Token>>;
37
+ /**
38
+ * The ERC-20 a chain's native currency wraps into.
39
+ *
40
+ * Not every EVM chain has one: on Arc the native USDC already satisfies IERC20, so
41
+ * nothing wraps it and the chain is absent here. Read it through
42
+ * {@link getWrappedNative} rather than indexing directly, so the missing case has to
43
+ * be handled instead of blowing up at the first property access.
44
+ */
45
+ export declare const getWrappedNative: (chainId: ChainId) => ERC20Token | undefined;
58
46
  export declare const NATIVE: {
59
47
  1: {
60
48
  readonly name: "Ether";
@@ -67,7 +55,7 @@ export declare const NATIVE: {
67
55
  decimals: number;
68
56
  };
69
57
  56: {
70
- readonly name: "Binance Chain Native Token";
58
+ readonly name: "BNB Chain Native Token";
71
59
  readonly symbol: "BNB";
72
60
  readonly decimals: 18;
73
61
  };
@@ -107,7 +95,7 @@ export declare const NATIVE: {
107
95
  readonly decimals: 18;
108
96
  };
109
97
  204: {
110
- readonly name: "Binance Chain Native Token";
98
+ readonly name: "BNB Chain Native Token";
111
99
  readonly symbol: "BNB";
112
100
  readonly decimals: 18;
113
101
  };
@@ -161,5 +149,10 @@ export declare const NATIVE: {
161
149
  readonly symbol: "ETH";
162
150
  readonly decimals: 18;
163
151
  };
152
+ 5042: {
153
+ name: string;
154
+ symbol: string;
155
+ decimals: number;
156
+ };
164
157
  };
165
158
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD,eAAO,MAAM,YAAY,SAAmB,CAAA;AAC5C,eAAO,MAAM,mBAAmB,SAAmB,CAAA;AAEnD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;CAyKjB,CAAA;AAED,eAAO,MAAM,IAAI;;;;;;CAyChB,CAAA;AAED,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;CAsB4B,CAAA;AAUhD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+DlB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD,eAAO,MAAM,YAAY,SAAmB,CAAA;AAC5C,eAAO,MAAM,mBAAmB,SAAmB,CAAA;AAEnD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;CAyKjB,CAAA;AAED,eAAO,MAAM,IAAI;;;;;;CAyChB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAsBxD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,YAAa,OAAO,KAAG,UAAU,GAAG,SAA6B,CAAA;AAU9F,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmElB,CAAA"}
@@ -12,7 +12,26 @@ export declare class Native extends NativeCurrency {
12
12
  });
13
13
  get wrapped(): Token;
14
14
  private static cache;
15
+ /**
16
+ * The chain's RPC-native currency.
17
+ *
18
+ * On a chain that wraps nothing, this instance is a hazard rather than a convenience: its
19
+ * `wrapped` getter throws, and the repo has ~900 unguarded `.wrapped` reads, so one leaking
20
+ * into the UI takes a page down somewhere far from where it was created. Those chains are
21
+ * meant to go through `resolveNativeCurrency`, which hands back the ERC-20 they declare.
22
+ *
23
+ * Constructing one anyway is therefore almost always a mistake, and this fails loudly at the
24
+ * point of construction — where it can be traced — rather than five frames deep in a getter
25
+ * on an unrelated screen. Only outside production: a wrong page beats a blank one, and the
26
+ * existing behaviour is what ships today.
27
+ *
28
+ * Gas and balance arithmetic genuinely needs the RPC native and its decimals. Those call
29
+ * sites use {@link getRpcNative}, which is greppable, so they read as a deliberate whitelist
30
+ * instead of disappearing into the same 81 anonymous `Native.onChain` calls.
31
+ */
15
32
  static onChain(chainId: number): Native;
33
+ /** @internal shared by `onChain` and `getRpcNative` — the actual construction. */
34
+ static rpcNative(chainId: number): Native;
16
35
  equals(other: Currency): boolean;
17
36
  }
18
37
  //# sourceMappingURL=native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/entities/native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAI5E;;;GAGG;AACH,qBAAa,MAAO,SAAQ,cAAc;IACxC,SAAS,aAAa,EACpB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;KACb;IAID,IAAW,OAAO,IAAI,KAAK,CAI1B;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAoC;WAE1C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAUvC,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;CAGxC"}
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/entities/native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAI5E;;;GAGG;AACH,qBAAa,MAAO,SAAQ,cAAc;IACxC,SAAS,aAAa,EACpB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;KACb;IAID,IAAW,OAAO,IAAI,KAAK,CAI1B;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAoC;IAExD;;;;;;;;;;;;;;;;OAgBG;WACW,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAW9C,kFAAkF;WACpE,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAUzC,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;CAGxC"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,10 @@ export * from './entities';
3
3
  export * from './abis/ERC20';
4
4
  export * from './abis/ERC165';
5
5
  export * from './abis/ScaledUIAmount';
6
+ export * from './abis/B20';
6
7
  export * from './utils';
7
8
  export * from './ether';
8
9
  export * from './scaledUIAmount';
10
+ export * from './b20';
11
+ export * from './resolveNativeCurrency';
9
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,OAAO,CAAA;AACrB,cAAc,yBAAyB,CAAA"}