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
37 changes: 22 additions & 15 deletions packages/contract-addresses/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
import addresses from '../addresses.json';

export interface ContractAddresses {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort

zrxToken: string;
etherToken: string;
zeroExGovernor: string;
zrxVault: string;
staking: string;
stakingProxy: string;
erc20BridgeProxy: string;
erc20BridgeSampler: string;
exchangeProxyGovernor: string;
etherToken: string;
exchangeProxy: string;
exchangeProxyTransformerDeployer: string;
exchangeProxyFlashWallet: string;
exchangeProxyGovernor: string;
exchangeProxyLiquidityProviderSandbox: string;
zrxTreasury: string;
exchangeProxyTransformerDeployer: string;
staking: string;
stakingProxy: string;
transformers: {
wethTransformer: string;
payTakerTransformer: string;
fillQuoteTransformer: string;
affiliateFeeTransformer: string;
positiveSlippageFeeTransformer: string;
};
zeroExGovernor: string;
zrxToken: string;
zrxTreasury: string;
zrxVault: string;
}

export enum ChainId {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort by number

Mainnet = 1,
Goerli = 5,
Ganache = 1337,
Optimism = 10,
BSC = 56,
Polygon = 137,
PolygonMumbai = 80001,
Avalanche = 43114,
Fantom = 250,
Celo = 42220,
Optimism = 10,
Arbitrum = 42161,
Ganache = 1337,
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);
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/contract-addresses/test/addresses_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as chai from 'chai';
import { bufferToHex, rlphash } from 'ethereumjs-util';
import 'mocha';

import { ChainId, getContractAddressesForChainOrThrow } from '../src';
import { ChainId, getContractAddressesForChainOrThrow, isChainId } from '../src';

const expect = chai.expect;

Expand Down Expand Up @@ -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;
});
});