Contracts
Install dependencies
- Install node.js 20+
- Install solidity compiler:
- solc-select
- or svm-rs
- or manually install a specific version if you are working with only one version.
Generate Go wrappers via abigen
Regenerate after you change contract source.
- Install solidity compiler
- Run
go generate
Unit test and coverage test
npm install
npx hardhat compile
npx hardhat test
npx hardhat test --grep Bridge
npx hardhat coverage
npx hardhat coverage --testfiles test/Bridge/bridge.test.ts
Source code organization
Testing contracts
The contracts in contracts/testing
are used for unit testing and performance benchmarks.
Libraries
These contracts in contracts/libs
are external dependencies and libraries. Some old libraries are kept to support other legacy contracts.
kip13/InterfaceIdentifier.sol
: The ERC-165 supportsInterface.
openzeppelin-contracts-v2/*
: OpenZeppelin contracts.
Ownable.sol
: Ownable contract.
SafeMath.sol
: SafeMath for older solidity versions.
ValidContract.sol
: Check if the contract is valid.
Some libraries are outside /contracts
directory and are installed via npm
node_modules/@openzeppelin/contracts
: OpenZeppelin contracts.
node_modules/openzeppelin-contracts-5.0
: OpenZeppelin contracts v5.0.
Service chain contracts
These contracts in contracts/service_chain
are the service chain token bridges.
bridge/*.sol
: Token bridge implementation.
- The
subbridge_deployBridge
API deploys this contract.
sc_erc20/IERC20BridgeReceiver.sol
: onERC20Received interface.
sc_erc721/IERC721BridgeReceiver.sol
: onERC721Received interface.
System contracts
These contracts in contracts/system_contracts
are deployed or planned to be deployed on the mainnet.
consensus/AddressBook.sol
: The validator registry.
consensus/CnStakingContract.sol
: Validator (CN) staking contract V1.
- Deployed instances: search, example1, example2
- Introduced since genesis in 2018, currently deprecated over KIP-82's CnStakingV2. The V1 to V2 migration has started since March 2023 and still some V1 instances remain active (i.e. registered in AddressBook).
gov/GovParam.sol
: On-chain storage for governance parameters.
- Deployed instance: Kairos, not on mainnet.
- Introduced with v1.10.0 in Dec 2022, not been used after a test drive in Kairos.
kip103/TreasuryRebalance.sol
: The KIP-103 treasury rebalance implementation.
- Deployed instances: Kairos, mainnet
- Introduced with v1.10.2 in Mar 2023, activated at the KIP-103 hardfork blocks and now finalized.
kip113/SimpleBlsRegistry.sol
: The KIP-113 BLS public key registry.
- Deployed instances: Kairos (proxy, logic), mainnet (proxy, logic)
- Introduced with v1.12.0 in Dec 2023. active to date.
kip149/Registry.sol
: The KIP-146 system contract registry.
- Deployed at address 0x401 via hardfork: Kairos, mainnet
- Introduced with v1.12.0 in Dec 2023. active to date.
kip163/CnStakingV3MultiSig.sol
: TBA.
kip163/PublicDelegation.sol
: TBA.
misc/credit.sol
: The credit data.
- Deployed at address 0x0, not on Kairos.
- Deployed at the genesis block in 2018, relevant to date.
proxy/proxy.sol
: The ERC1967 Upgradable Proxy.