Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/statics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export {
getTokenFeatures,
EVM_TOKEN_FEATURES,
EVM_TOKEN_FEATURES_NON_EIP1559,
STATIC_NETWORK_FEATURE_FAMILIES,
} from './networkFeatureMapForTokens';
export {
generateErc20Coin,
Expand Down
48 changes: 42 additions & 6 deletions modules/statics/src/networkFeatureMapForTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,72 @@ export function getTokenFeatures(
}

export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[]>> = {
abstracteth: EVM_TOKEN_FEATURES,
algo: AccountCoin.DEFAULT_FEATURES,
apt: APT_FEATURES,
arbeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
arcusdc: EVM_TOKEN_FEATURES,
avaxc: AccountCoin.DEFAULT_FEATURES,
baseeth: EVM_TOKEN_FEATURES,
bera: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
bobaeth: EVM_TOKEN_FEATURES,
bsc: BSC_TOKEN_FEATURES,
canton: CANTON_TOKEN_FEATURES,
celo: AccountCoin.DEFAULT_FEATURES,
// All SUPPORTS_ERC20 EVM families must be present statically: botTokens.ts resolves
// getTokenFeatures(family) at module load, before registerErc20Families runs in coins.ts.
chiliz: EVM_TOKEN_FEATURES,
codexeth: EVM_TOKEN_FEATURES,
dogeos: EVM_TOKEN_FEATURES,
eth: AccountCoin.DEFAULT_FEATURES,
baseeth: EVM_TOKEN_FEATURES,
eos: AccountCoin.DEFAULT_FEATURES,
// flow, okbxlayer and hoodeth must be static: botTokens.ts resolves getTokenFeatures at module load,
// before registerErc20Families backfills EVM families in coins.ts.
flow: EVM_TOKEN_FEATURES,
okbxlayer: EVM_TOKEN_FEATURES,
hoodeth: EVM_TOKEN_FEATURES,
gasevm: EVM_TOKEN_FEATURES,
h: EVM_TOKEN_FEATURES,
hbar: AccountCoin.DEFAULT_FEATURES,
opeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
hbarevm: EVM_TOKEN_FEATURES,
hemieth: EVM_TOKEN_FEATURES,
hoodeth: EVM_TOKEN_FEATURES,
hppeth: EVM_TOKEN_FEATURES,
hypeevm: EVM_TOKEN_FEATURES,
inketh: EVM_TOKEN_FEATURES,
ip: EVM_TOKEN_FEATURES,
jovayeth: EVM_TOKEN_FEATURES,
katanaeth: EVM_TOKEN_FEATURES,
lineaeth: EVM_TOKEN_FEATURES,
mantle: EVM_TOKEN_FEATURES,
megaeth: EVM_TOKEN_FEATURES,
morph: EVM_TOKEN_FEATURES,
morpheth: EVM_TOKEN_FEATURES,
og: EVM_TOKEN_FEATURES,
okbxlayer: EVM_TOKEN_FEATURES,
opeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
polygon: POLYGON_TOKEN_FEATURES,
prividiumeth: EVM_TOKEN_FEATURES_NON_EIP1559,
scrolleth: EVM_TOKEN_FEATURES,
seievm: EVM_TOKEN_FEATURES,
sol: SOL_TOKEN_FEATURES,
stx: STX_TOKEN_FEATURES,
sui: SUI_TOKEN_FEATURES,
tao: TAO_TOKEN_FEATURES,
polyx: POLYX_TOKEN_FEATURES,
trx: AccountCoin.DEFAULT_FEATURES,
unieth: EVM_TOKEN_FEATURES,
usdt0: EVM_TOKEN_FEATURES,
xlm: AccountCoin.DEFAULT_FEATURES,
xpl: EVM_TOKEN_FEATURES,
xrp: AccountCoin.DEFAULT_FEATURES,
xtzevm: EVM_TOKEN_FEATURES,
zksyncera: EVM_TOKEN_FEATURES,
ofc: [],
ada: ADA_TOKEN_FEATURES,
};

/**
* Snapshot of families statically present in `networkFeatureMapForTokens` at module load
* (before `registerErc20Families` runs in `coins.ts`). Used by unit tests to ensure every
* `SUPPORTS_ERC20` family can resolve `getTokenFeatures(family)` when `botTokens.ts` is evaluated.
*/
export const STATIC_NETWORK_FEATURE_FAMILIES: Readonly<Record<string, true>> = Object.freeze(
Object.fromEntries(Object.keys(networkFeatureMapForTokens).map((k) => [k, true as const]))
);
31 changes: 17 additions & 14 deletions modules/statics/test/unit/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
NetworkType,
registerNetwork,
SolCoin,
STATIC_NETWORK_FEATURE_FAMILIES,
SuiCoin,
tokens,
TrimmedAmsTokenConfig,
Expand Down Expand Up @@ -1899,26 +1900,28 @@ describe('create token map using config details', () => {
});

describe('getNetworkFeatures EVM fallback (drift guard)', () => {
it('should return EVM_TOKEN_FEATURES for every mainnet family that supports ERC20 but has no explicit entry in networkFeatureMapForTokens', () => {
const erc20Families = new Set(
allCoinsAndTokens
.filter(
(coin) =>
!coin.isToken &&
coin.network.type === NetworkType.MAINNET &&
coin.features.includes(CoinFeature.SUPPORTS_ERC20)
)
.map((coin) => coin.family)
it('should statically include every mainnet SUPPORTS_ERC20 family in networkFeatureMapForTokens before registerErc20Families runs', () => {
const erc20Coins = allCoinsAndTokens.filter(
(coin) =>
!coin.isToken && coin.network.type === NetworkType.MAINNET && coin.features.includes(CoinFeature.SUPPORTS_ERC20)
);

erc20Families.forEach((family) => {
const features = getNetworkFeatures(family);
erc20Coins.forEach((coin) => {
Boolean(STATIC_NETWORK_FEATURE_FAMILIES[coin.family]).should.eql(
true,
`Expected ${coin.family} (CoinFeature.SUPPORTS_ERC20) to be statically listed in networkFeatureMapForTokens so botTokens.ts can resolve getTokenFeatures('${coin.family}') at module load`
);
const features = getNetworkFeatures(coin.family);
features?.should.not.be.undefined();
const expected = coin.features.includes(CoinFeature.EIP1559)
? EVM_TOKEN_FEATURES
: EVM_TOKEN_FEATURES_NON_EIP1559;
features?.should.deepEqual(expected);
});

// baseeth is the concrete gap this fallback closes: it has no hand-written entry in
// networkFeatureMapForTokens, but its base coin supports ERC20.
getNetworkFeatures('baseeth')?.should.deepEqual(EVM_TOKEN_FEATURES);
getNetworkFeatures('chiliz')?.should.deepEqual(EVM_TOKEN_FEATURES);
getNetworkFeatures('prividiumeth')?.should.deepEqual(EVM_TOKEN_FEATURES_NON_EIP1559);
});
});

Expand Down
Loading