[contract-addresses] Add ChainId type predicate
This commit is contained in:
parent
b19e29e03d
commit
ac5e271229
@ -1,20 +1,16 @@
|
|||||||
import addresses from '../addresses.json';
|
import addresses from '../addresses.json';
|
||||||
|
|
||||||
export interface ContractAddresses {
|
export interface ContractAddresses {
|
||||||
zrxToken: string;
|
|
||||||
etherToken: string;
|
|
||||||
zeroExGovernor: string;
|
|
||||||
zrxVault: string;
|
|
||||||
staking: string;
|
|
||||||
stakingProxy: string;
|
|
||||||
erc20BridgeProxy: string;
|
erc20BridgeProxy: string;
|
||||||
erc20BridgeSampler: string;
|
erc20BridgeSampler: string;
|
||||||
exchangeProxyGovernor: string;
|
etherToken: string;
|
||||||
exchangeProxy: string;
|
exchangeProxy: string;
|
||||||
exchangeProxyTransformerDeployer: string;
|
|
||||||
exchangeProxyFlashWallet: string;
|
exchangeProxyFlashWallet: string;
|
||||||
|
exchangeProxyGovernor: string;
|
||||||
exchangeProxyLiquidityProviderSandbox: string;
|
exchangeProxyLiquidityProviderSandbox: string;
|
||||||
zrxTreasury: string;
|
exchangeProxyTransformerDeployer: string;
|
||||||
|
staking: string;
|
||||||
|
stakingProxy: string;
|
||||||
transformers: {
|
transformers: {
|
||||||
wethTransformer: string;
|
wethTransformer: string;
|
||||||
payTakerTransformer: string;
|
payTakerTransformer: string;
|
||||||
@ -22,21 +18,32 @@ export interface ContractAddresses {
|
|||||||
affiliateFeeTransformer: string;
|
affiliateFeeTransformer: string;
|
||||||
positiveSlippageFeeTransformer: string;
|
positiveSlippageFeeTransformer: string;
|
||||||
};
|
};
|
||||||
|
zeroExGovernor: string;
|
||||||
|
zrxToken: string;
|
||||||
|
zrxTreasury: string;
|
||||||
|
zrxVault: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ChainId {
|
export enum ChainId {
|
||||||
Mainnet = 1,
|
Mainnet = 1,
|
||||||
Goerli = 5,
|
Goerli = 5,
|
||||||
Ganache = 1337,
|
Optimism = 10,
|
||||||
BSC = 56,
|
BSC = 56,
|
||||||
Polygon = 137,
|
Polygon = 137,
|
||||||
PolygonMumbai = 80001,
|
|
||||||
Avalanche = 43114,
|
|
||||||
Fantom = 250,
|
Fantom = 250,
|
||||||
Celo = 42220,
|
Ganache = 1337,
|
||||||
Optimism = 10,
|
|
||||||
Arbitrum = 42161,
|
|
||||||
Base = 8453,
|
Base = 8453,
|
||||||
|
Arbitrum = 42161,
|
||||||
|
Avalanche = 43114,
|
||||||
|
Celo = 42220,
|
||||||
|
PolygonMumbai = 80001,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Narrow a JavaScript number to a Chain ID.
|
||||||
|
*/
|
||||||
|
export function isChainId(chainId: number): chainId is ChainId {
|
||||||
|
return Object.values(ChainId).includes(chainId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,7 @@ import * as chai from 'chai';
|
|||||||
import { bufferToHex, rlphash } from 'ethereumjs-util';
|
import { bufferToHex, rlphash } from 'ethereumjs-util';
|
||||||
import 'mocha';
|
import 'mocha';
|
||||||
|
|
||||||
import { ChainId, getContractAddressesForChainOrThrow } from '../src';
|
import { ChainId, getContractAddressesForChainOrThrow, isChainId } from '../src';
|
||||||
|
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
|
|
||||||
@ -68,3 +68,12 @@ describe('addresses.json sanity test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("isChainId", () => {
|
||||||
|
it("should return true for existing chain ids", () => {
|
||||||
|
expect(isChainId(1)).to.be.true;
|
||||||
|
});
|
||||||
|
it("should return false for non-existing chain ids", () => {
|
||||||
|
expect(isChainId(666)).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user