@pancakeswap/swap-sdk-evm 1.2.1 → 1.2.2
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/dist/abis/B20.d.ts +90 -0
- package/dist/abis/B20.d.ts.map +1 -0
- package/dist/b20.d.ts +62 -0
- package/dist/b20.d.ts.map +1 -0
- package/dist/constants.d.ts +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +221 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -24
- package/dist/index.mjs.map +1 -1
- package/dist/scaledUIAmount.d.ts +407 -43
- package/dist/scaledUIAmount.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -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"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export declare const NATIVE: {
|
|
|
67
67
|
decimals: number;
|
|
68
68
|
};
|
|
69
69
|
56: {
|
|
70
|
-
readonly name: "Binance Chain
|
|
70
|
+
readonly name: "Binance Chain";
|
|
71
71
|
readonly symbol: "BNB";
|
|
72
72
|
readonly decimals: 18;
|
|
73
73
|
};
|
|
@@ -107,7 +107,7 @@ export declare const NATIVE: {
|
|
|
107
107
|
readonly decimals: 18;
|
|
108
108
|
};
|
|
109
109
|
204: {
|
|
110
|
-
readonly name: "Binance Chain
|
|
110
|
+
readonly name: "Binance Chain";
|
|
111
111
|
readonly symbol: "BNB";
|
|
112
112
|
readonly decimals: 18;
|
|
113
113
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ 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';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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"}
|
package/dist/index.js
CHANGED
|
@@ -269,7 +269,7 @@ var WNATIVE = {
|
|
|
269
269
|
};
|
|
270
270
|
var ETHER = { name: "Ether", symbol: "ETH", decimals: 18 };
|
|
271
271
|
var BNB = {
|
|
272
|
-
name: "Binance Chain
|
|
272
|
+
name: "Binance Chain",
|
|
273
273
|
symbol: "BNB",
|
|
274
274
|
decimals: 18
|
|
275
275
|
};
|
|
@@ -278,7 +278,7 @@ var NATIVE = {
|
|
|
278
278
|
[chains.ChainId.GOERLI]: { name: "Goerli Ether", symbol: "GOR", decimals: 18 },
|
|
279
279
|
[chains.ChainId.BSC]: BNB,
|
|
280
280
|
[chains.ChainId.BSC_TESTNET]: {
|
|
281
|
-
name: "Binance Chain
|
|
281
|
+
name: "Binance Chain",
|
|
282
282
|
symbol: "tBNB",
|
|
283
283
|
decimals: 18
|
|
284
284
|
},
|
|
@@ -294,7 +294,7 @@ var NATIVE = {
|
|
|
294
294
|
[chains.ChainId.LINEA_TESTNET]: ETHER,
|
|
295
295
|
[chains.ChainId.OPBNB]: BNB,
|
|
296
296
|
[chains.ChainId.OPBNB_TESTNET]: {
|
|
297
|
-
name: "Binance Chain
|
|
297
|
+
name: "Binance Chain",
|
|
298
298
|
symbol: "tBNB",
|
|
299
299
|
decimals: 18
|
|
300
300
|
},
|
|
@@ -462,6 +462,67 @@ var scaledUIAmountAbi = [
|
|
|
462
462
|
]
|
|
463
463
|
}
|
|
464
464
|
];
|
|
465
|
+
|
|
466
|
+
// src/abis/B20.ts
|
|
467
|
+
var b20AssetAbi = [
|
|
468
|
+
{
|
|
469
|
+
type: "function",
|
|
470
|
+
name: "multiplier",
|
|
471
|
+
inputs: [],
|
|
472
|
+
outputs: [{ type: "uint256" }],
|
|
473
|
+
stateMutability: "view"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
type: "function",
|
|
477
|
+
name: "WAD_PRECISION",
|
|
478
|
+
inputs: [],
|
|
479
|
+
outputs: [{ type: "uint256" }],
|
|
480
|
+
stateMutability: "view"
|
|
481
|
+
},
|
|
482
|
+
// B20 does NOT claim the ERC-8056 Conversion extension id (0x57854fc3) — it keeps these native
|
|
483
|
+
// names unaliased, so detect them by ABI, never by `supportsInterface`.
|
|
484
|
+
{
|
|
485
|
+
type: "function",
|
|
486
|
+
name: "toScaledBalance",
|
|
487
|
+
inputs: [{ name: "rawBalance", type: "uint256" }],
|
|
488
|
+
outputs: [{ type: "uint256" }],
|
|
489
|
+
stateMutability: "view"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
type: "function",
|
|
493
|
+
name: "toRawBalance",
|
|
494
|
+
inputs: [{ name: "scaledBalance", type: "uint256" }],
|
|
495
|
+
outputs: [{ name: "rawBalance", type: "uint256" }],
|
|
496
|
+
stateMutability: "view"
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
type: "function",
|
|
500
|
+
name: "scaledBalanceOf",
|
|
501
|
+
inputs: [{ name: "account", type: "address" }],
|
|
502
|
+
outputs: [{ type: "uint256" }],
|
|
503
|
+
stateMutability: "view"
|
|
504
|
+
},
|
|
505
|
+
// Post-#173 shapes, verbatim from base-std. The DEPLOYED precompile predates them and the
|
|
506
|
+
// Coinbase doc calls its event `MultiplierUpdated` with an unverified arg list — probe the real
|
|
507
|
+
// topic0 before indexing multiplier history.
|
|
508
|
+
{
|
|
509
|
+
type: "event",
|
|
510
|
+
name: "UIMultiplierUpdated",
|
|
511
|
+
inputs: [
|
|
512
|
+
{ name: "oldMultiplier", type: "uint256", indexed: false },
|
|
513
|
+
{ name: "newMultiplier", type: "uint256", indexed: false },
|
|
514
|
+
{ name: "effectiveAtTimestamp", type: "uint256", indexed: false }
|
|
515
|
+
]
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
type: "event",
|
|
519
|
+
name: "MultiplierUpdateCancelled",
|
|
520
|
+
inputs: [
|
|
521
|
+
{ name: "cancelledMultiplier", type: "uint256", indexed: false },
|
|
522
|
+
{ name: "cancelledEffectiveAt", type: "uint256", indexed: false }
|
|
523
|
+
]
|
|
524
|
+
}
|
|
525
|
+
];
|
|
465
526
|
var _Ether = class extends swapSdkCore.NativeCurrency {
|
|
466
527
|
constructor(chainId) {
|
|
467
528
|
super(chainId, 18, "ETH", "Ether");
|
|
@@ -483,13 +544,147 @@ var _Ether = class extends swapSdkCore.NativeCurrency {
|
|
|
483
544
|
};
|
|
484
545
|
var Ether = _Ether;
|
|
485
546
|
Ether._etherCache = {};
|
|
547
|
+
var B20_SUPPORTED_CHAIN_IDS = [chains.ChainId.BASE, chains.ChainId.BASE_SEPOLIA];
|
|
548
|
+
var B20_ADDRESS_PREFIX = "b2000000000000000000";
|
|
549
|
+
var B20Variant = /* @__PURE__ */ ((B20Variant2) => {
|
|
550
|
+
B20Variant2[B20Variant2["ASSET"] = 0] = "ASSET";
|
|
551
|
+
B20Variant2[B20Variant2["STABLECOIN"] = 1] = "STABLECOIN";
|
|
552
|
+
return B20Variant2;
|
|
553
|
+
})(B20Variant || {});
|
|
554
|
+
var B20_FACTORY_ADDRESS = "0xB20f000000000000000000000000000000000000";
|
|
555
|
+
var B20_ACTIVATION_REGISTRY_ADDRESS = "0x8453000000000000000000000000000000000001";
|
|
556
|
+
var B20_POLICY_REGISTRY_ADDRESS = "0x8453000000000000000000000000000000000002";
|
|
557
|
+
var HEX_ADDRESS_LENGTH = 40;
|
|
558
|
+
var VARIANT_NIBBLE_START = B20_ADDRESS_PREFIX.length;
|
|
559
|
+
var VARIANT_NIBBLE_END = VARIANT_NIBBLE_START + 2;
|
|
560
|
+
var stripHexPrefix = (address) => (address.startsWith("0x") || address.startsWith("0X") ? address.slice(2) : address).toLowerCase();
|
|
561
|
+
function isB20SupportedChainId(chainId) {
|
|
562
|
+
return B20_SUPPORTED_CHAIN_IDS.includes(chainId);
|
|
563
|
+
}
|
|
564
|
+
function isB20Address(address) {
|
|
565
|
+
if (!address)
|
|
566
|
+
return false;
|
|
567
|
+
const hex = stripHexPrefix(address);
|
|
568
|
+
return hex.length === HEX_ADDRESS_LENGTH && hex.startsWith(B20_ADDRESS_PREFIX);
|
|
569
|
+
}
|
|
570
|
+
function getB20Variant(address) {
|
|
571
|
+
if (!isB20Address(address))
|
|
572
|
+
return void 0;
|
|
573
|
+
switch (stripHexPrefix(address).slice(VARIANT_NIBBLE_START, VARIANT_NIBBLE_END)) {
|
|
574
|
+
case "00":
|
|
575
|
+
return 0 /* ASSET */;
|
|
576
|
+
case "01":
|
|
577
|
+
return 1 /* STABLECOIN */;
|
|
578
|
+
default:
|
|
579
|
+
return void 0;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function isB20AssetToken(chainId, address) {
|
|
583
|
+
return isB20SupportedChainId(chainId) && getB20Variant(address) === 0 /* ASSET */;
|
|
584
|
+
}
|
|
585
|
+
var isB20AssetAddress = (chainId, address) => isB20AssetToken(chainId, address);
|
|
586
|
+
var B20_ERROR_SELECTORS = {
|
|
587
|
+
"0xa43fec12": "PolicyForbids",
|
|
588
|
+
// (bytes32 policyScope, uint64 policyId)
|
|
589
|
+
"0xfd8c4245": "ContractPaused",
|
|
590
|
+
// (PausableFeature feature)
|
|
591
|
+
"0xcccad523": "PolicyNotFound",
|
|
592
|
+
// (uint64 policyId)
|
|
593
|
+
"0xcdd98a4a": "UnsupportedPolicyType",
|
|
594
|
+
// (bytes32 policyScope)
|
|
595
|
+
"0xf58f733a": "SupplyCapExceeded",
|
|
596
|
+
// ()
|
|
597
|
+
"0x6f12f3dc": "InvalidMultiplier"
|
|
598
|
+
// ()
|
|
599
|
+
};
|
|
600
|
+
var B20_PAUSABLE_FEATURES = ["TRANSFER", "MINT", "BURN"];
|
|
601
|
+
var SELECTOR_PATTERN = /0x[0-9a-fA-F]{8}/g;
|
|
602
|
+
function matchB20RevertError(input) {
|
|
603
|
+
if (!input)
|
|
604
|
+
return void 0;
|
|
605
|
+
const matches = input.match(SELECTOR_PATTERN);
|
|
606
|
+
if (!matches)
|
|
607
|
+
return void 0;
|
|
608
|
+
for (const candidate of matches) {
|
|
609
|
+
const name = B20_ERROR_SELECTORS[candidate.toLowerCase()];
|
|
610
|
+
if (!name)
|
|
611
|
+
continue;
|
|
612
|
+
if (name !== "ContractPaused")
|
|
613
|
+
return { name };
|
|
614
|
+
const dataMatch = input.match(new RegExp(`${candidate}([0-9a-fA-F]{64})`, "i"));
|
|
615
|
+
const featureIndex = dataMatch ? Number.parseInt(dataMatch[1], 16) : Number.NaN;
|
|
616
|
+
const feature = B20_PAUSABLE_FEATURES[featureIndex];
|
|
617
|
+
return feature ? { name, feature } : { name };
|
|
618
|
+
}
|
|
619
|
+
return void 0;
|
|
620
|
+
}
|
|
486
621
|
var SCALED_UI_AMOUNT_INTERFACE_ID = "0xa60bf13d";
|
|
487
622
|
var SCALED_UI_AMOUNT_BALANCES_INTERFACE_ID = "0xd890fd71";
|
|
623
|
+
var DIALECTS = {
|
|
624
|
+
erc8056: {
|
|
625
|
+
// Deliberately no `multiplier()` fallback: it's a generic name that leverage/rebasing tokens
|
|
626
|
+
// use for unrelated values, so reading it off an arbitrary token would corrupt displayed
|
|
627
|
+
// amounts. Safe in the b20 dialect only because that's gated on a verified B20 address.
|
|
628
|
+
multiplierFns: ["uiMultiplier"],
|
|
629
|
+
pendingFns: ["newUIMultiplier", "effectiveAt"]
|
|
630
|
+
},
|
|
631
|
+
b20: {
|
|
632
|
+
// `multiplier()` first — the only getter that resolves today. `uiMultiplier()` is kept for
|
|
633
|
+
// forward-compat: it starts working as an alias once base-std #173 reaches mainnet.
|
|
634
|
+
multiplierFns: ["multiplier", "uiMultiplier"],
|
|
635
|
+
pendingFns: ["newUIMultiplier", "effectiveAt"]
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
var ABI_BY_FN = {
|
|
639
|
+
uiMultiplier: scaledUIAmountAbi,
|
|
640
|
+
newUIMultiplier: scaledUIAmountAbi,
|
|
641
|
+
effectiveAt: scaledUIAmountAbi,
|
|
642
|
+
multiplier: b20AssetAbi
|
|
643
|
+
};
|
|
644
|
+
function resolveScaledUIDialect(chainId, address) {
|
|
645
|
+
return isB20AssetToken(chainId, address) ? "b20" : "erc8056";
|
|
646
|
+
}
|
|
647
|
+
function buildScaledUIAmountReads(params) {
|
|
648
|
+
const { address, chainId, dialect } = params;
|
|
649
|
+
const spec = DIALECTS[dialect];
|
|
650
|
+
return [...spec.multiplierFns, ...spec.pendingFns].map((functionName) => ({
|
|
651
|
+
address,
|
|
652
|
+
abi: ABI_BY_FN[functionName],
|
|
653
|
+
functionName,
|
|
654
|
+
...chainId === void 0 ? {} : { chainId }
|
|
655
|
+
}));
|
|
656
|
+
}
|
|
657
|
+
var asBigInt = (entry) => entry?.status === "success" && typeof entry.result === "bigint" ? entry.result : void 0;
|
|
488
658
|
var IDENTITY_SCALED_UI_AMOUNT_METADATA = {
|
|
489
659
|
enabled: false,
|
|
490
660
|
multiplier: swapSdkCore.SCALED_UI_DENOMINATOR
|
|
491
661
|
};
|
|
492
|
-
|
|
662
|
+
function parseScaledUIAmountReads(results, dialect) {
|
|
663
|
+
const spec = DIALECTS[dialect];
|
|
664
|
+
const multiplierCount = spec.multiplierFns.length;
|
|
665
|
+
let multiplier;
|
|
666
|
+
for (let i = 0; i < multiplierCount; i++) {
|
|
667
|
+
const candidate = asBigInt(results[i]);
|
|
668
|
+
if (candidate !== void 0 && candidate !== 0n) {
|
|
669
|
+
multiplier = candidate;
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (multiplier === void 0)
|
|
674
|
+
return IDENTITY_SCALED_UI_AMOUNT_METADATA;
|
|
675
|
+
const pendingIndex = (fn) => {
|
|
676
|
+
const offset = spec.pendingFns.indexOf(fn);
|
|
677
|
+
return offset === -1 ? -1 : multiplierCount + offset;
|
|
678
|
+
};
|
|
679
|
+
const newMultiplier = asBigInt(results[pendingIndex("newUIMultiplier")]);
|
|
680
|
+
const effectiveAtRaw = asBigInt(results[pendingIndex("effectiveAt")]);
|
|
681
|
+
const effectiveAt = effectiveAtRaw !== void 0 ? Number(effectiveAtRaw) : void 0;
|
|
682
|
+
const hasPending = newMultiplier !== void 0 && effectiveAt !== void 0 && newMultiplier !== multiplier && effectiveAt > 0;
|
|
683
|
+
return hasPending ? { enabled: true, multiplier, newMultiplier, effectiveAt } : { enabled: true, multiplier };
|
|
684
|
+
}
|
|
685
|
+
async function probeIsScaledUIAmount(client, address, chainId) {
|
|
686
|
+
if (isB20AssetToken(chainId ?? client.chain?.id, address))
|
|
687
|
+
return true;
|
|
493
688
|
try {
|
|
494
689
|
const result = await client.readContract({
|
|
495
690
|
address,
|
|
@@ -502,28 +697,13 @@ async function probeIsScaledUIAmount(client, address) {
|
|
|
502
697
|
return false;
|
|
503
698
|
}
|
|
504
699
|
}
|
|
505
|
-
async function fetchScaledUIAmountMetadata(client, address) {
|
|
700
|
+
async function fetchScaledUIAmountMetadata(client, address, chainId) {
|
|
701
|
+
const dialect = resolveScaledUIDialect(chainId ?? client.chain?.id, address);
|
|
506
702
|
const results = await client.multicall({
|
|
507
|
-
contracts:
|
|
508
|
-
{ address, abi: scaledUIAmountAbi, functionName: "uiMultiplier" },
|
|
509
|
-
{ address, abi: scaledUIAmountAbi, functionName: "newUIMultiplier" },
|
|
510
|
-
{ address, abi: scaledUIAmountAbi, functionName: "effectiveAt" }
|
|
511
|
-
],
|
|
703
|
+
contracts: buildScaledUIAmountReads({ address, dialect }),
|
|
512
704
|
allowFailure: true
|
|
513
705
|
});
|
|
514
|
-
|
|
515
|
-
if (activeRes.status !== "success") {
|
|
516
|
-
return IDENTITY_SCALED_UI_AMOUNT_METADATA;
|
|
517
|
-
}
|
|
518
|
-
const multiplier = activeRes.result;
|
|
519
|
-
if (multiplier === 0n) {
|
|
520
|
-
return IDENTITY_SCALED_UI_AMOUNT_METADATA;
|
|
521
|
-
}
|
|
522
|
-
const newMultiplier = pendingMRes.status === "success" ? pendingMRes.result : void 0;
|
|
523
|
-
const effectiveAtRaw = pendingTsRes.status === "success" ? pendingTsRes.result : void 0;
|
|
524
|
-
const effectiveAt = effectiveAtRaw !== void 0 ? Number(effectiveAtRaw) : void 0;
|
|
525
|
-
const hasPending = newMultiplier !== void 0 && effectiveAt !== void 0 && newMultiplier !== multiplier && effectiveAt > 0;
|
|
526
|
-
return hasPending ? { enabled: true, multiplier, newMultiplier, effectiveAt } : { enabled: true, multiplier };
|
|
706
|
+
return parseScaledUIAmountReads(results, dialect);
|
|
527
707
|
}
|
|
528
708
|
|
|
529
709
|
Object.defineProperty(exports, 'SCALED_UI_DENOMINATOR', {
|
|
@@ -546,6 +726,14 @@ Object.defineProperty(exports, 'toScaledUIAmount', {
|
|
|
546
726
|
enumerable: true,
|
|
547
727
|
get: function () { return swapSdkCore.toScaledUIAmount; }
|
|
548
728
|
});
|
|
729
|
+
exports.B20Variant = B20Variant;
|
|
730
|
+
exports.B20_ACTIVATION_REGISTRY_ADDRESS = B20_ACTIVATION_REGISTRY_ADDRESS;
|
|
731
|
+
exports.B20_ADDRESS_PREFIX = B20_ADDRESS_PREFIX;
|
|
732
|
+
exports.B20_ERROR_SELECTORS = B20_ERROR_SELECTORS;
|
|
733
|
+
exports.B20_FACTORY_ADDRESS = B20_FACTORY_ADDRESS;
|
|
734
|
+
exports.B20_PAUSABLE_FEATURES = B20_PAUSABLE_FEATURES;
|
|
735
|
+
exports.B20_POLICY_REGISTRY_ADDRESS = B20_POLICY_REGISTRY_ADDRESS;
|
|
736
|
+
exports.B20_SUPPORTED_CHAIN_IDS = B20_SUPPORTED_CHAIN_IDS;
|
|
549
737
|
exports.ERC20Token = ERC20Token;
|
|
550
738
|
exports.Ether = Ether;
|
|
551
739
|
exports.IDENTITY_SCALED_UI_AMOUNT_METADATA = IDENTITY_SCALED_UI_AMOUNT_METADATA;
|
|
@@ -558,10 +746,20 @@ exports.WBNB = WBNB;
|
|
|
558
746
|
exports.WETH9 = WETH9;
|
|
559
747
|
exports.WNATIVE = WNATIVE;
|
|
560
748
|
exports.ZERO_PERCENT = ZERO_PERCENT;
|
|
749
|
+
exports.b20AssetAbi = b20AssetAbi;
|
|
750
|
+
exports.buildScaledUIAmountReads = buildScaledUIAmountReads;
|
|
561
751
|
exports.erc165Abi = erc165Abi;
|
|
562
752
|
exports.erc20Abi = erc20Abi;
|
|
563
753
|
exports.fetchScaledUIAmountMetadata = fetchScaledUIAmountMetadata;
|
|
754
|
+
exports.getB20Variant = getB20Variant;
|
|
755
|
+
exports.isB20Address = isB20Address;
|
|
756
|
+
exports.isB20AssetAddress = isB20AssetAddress;
|
|
757
|
+
exports.isB20AssetToken = isB20AssetToken;
|
|
758
|
+
exports.isB20SupportedChainId = isB20SupportedChainId;
|
|
759
|
+
exports.matchB20RevertError = matchB20RevertError;
|
|
760
|
+
exports.parseScaledUIAmountReads = parseScaledUIAmountReads;
|
|
564
761
|
exports.probeIsScaledUIAmount = probeIsScaledUIAmount;
|
|
762
|
+
exports.resolveScaledUIDialect = resolveScaledUIDialect;
|
|
565
763
|
exports.scaledUIAmountAbi = scaledUIAmountAbi;
|
|
566
764
|
exports.validateAndParseAddress = validateAndParseAddress;
|
|
567
765
|
//# sourceMappingURL=out.js.map
|