- Foundry from here
The bridge is composed of three main components:
- The bridge contract, which is deployed on supported chains and it's the scope of this documentation.
- The bridge UI, which is a web application that allows users to interact with the bridge contract.
- The bridge server, which is a server that listens to events emitted by the bridge contract and performs the actual transfer of assets between chains.
forge script forge script .\script\BridgeERC20Impl.s.sol:DeployAllAndSetBridgeERC20
to point a chain, add -f "https://RPCLINK"
to the command
to broadcast the transaction on chain, add --broadcast
to the command
To run tests we use Foundry from Paradigm. To install it, follow the instructions here If you're using Windows you can download the binaries and add them to your PATH, without needing to install and compile the project.
Install the required libraries and edit the foundry.toml remapping based on your local setup.
forge install foundry-rs/forge-std --no-commit
forge install openzeppelin/openzeppelin-contracts --no-commit
To execute a test, run forge test
- User approves the bridge contract to transfer the NFTs
- User calls depositSingleERC721 with the NFT address & tokenID (paying the fees in ERC20 & ETH if active)
- Bridge backend listen for and register the deposit event
- Bridge signer calls calls withdrawSingleERC721 with the NFT address & tokenID
To initialize the contract, the project owner needs to call the initialize
function with the following parameters:
_bridgeSigner
: Address of the signer of the bridge._feeReceiver
: Address of the fee receiver._operator
: Address of the operator.
The operator can set the supported chains using the setSupportedChain
function. This function accepts the chainId
of the chain and a status
(true/false) to enable or disable the chain.
The operator can set the maximum number of NFTs that can be used in a single transaction using the setMaxNFTsPerTx
function. This function accepts the maxNFTsPerTx
parameter, which represents the maximum number of NFTs allowed per transaction.
The operator can set the bridge status (online/offline) using the setBridgeStatus
function. This function accepts a boolean value (true
for online, false
for offline) to activate or deactivate the bridge.
The operator can set the fee status (active/inactive) using the setFeeStatus
function. This function accepts a boolean value (true
for active, false
for inactive) to activate or deactivate the fees.
The operator can set the ETH deposit fees for specific chain IDs using the setETHFee
function. This function accepts the chainId
of the chain, a boolean value (true
for active, false
for inactive), and the amount
of the fee.
The operator can set the fees for ERC20 tokens using the setTokenFees
function. This function accepts the following parameters:
active
: Boolean value (true
for active,false
for inactive) to activate or deactivate the fees.nftAddress
: Address of the NFT token.depositFee
: Fee amount for depositing the NFT token.withdrawFee
: Fee amount for withdrawing the NFT token.
The operator can set the address of the fee receiver using the setFeeReceiver
function. This function accepts the receiver
parameter, which represents the address of the fee receiver.
The operator can set the details of an NFT address using the setNFTDetails
function. This function accepts the following parameters:
isActive
: Boolean value (true
for active,false
for inactive) to activate or deactivate the NFT contract.nftContractAddress
: Address of the NFT contract.feeTokenAddress
: Address of the token used to pay the fee.depositFeeAmount
: Deposit fee amount for the NFT contract.withdrawFeeAmount
: Withdraw fee amount for the NFT contract.
The operator can set the details of an ERC20 address using the setERC20Details
function. This function accepts the following parameters:
isActive
: Boolean value (true
for active,false
for inactive) to activate or deactivate the ERC20 contract.erc20ContractAddress
: Address of the ERC20 contract.
The bridge signer can withdraw ERC721 tokens from the bridge using the withdrawSingleERC721
function. This function requires the following parameters:
to
: Address of the user to withdraw to.nftContractAddress
: Address of the NFT contract.tokenId
: ID of the NFT token.uniqueKey
: Unique key associated with the withdrawal.
The bridge signer can mint ERC721 tokens using the mintERC721
function. This function requires the following parameters:
nftAddress
: Address of the NFT contract.to
: Address of the user to mint to.tokenId
: ID of the NFT token.uniqueKey
: Unique key associated with the minting._marketplaceDistributionRates
: Array ofuint16
values representing the marketplace distribution rates._marketplaceDistributionAddresses
: Array of addresses representing the marketplace distribution addresses.
The operator can set the base URI of an NFT contract using the setBaseURI
function. This function requires the following parameters:
nftAddress
: Address of the NFT contract.baseURI_
: Base URI string.
The operator can change the owner of an NFT contract using the changeOwnerNft
function. This function requires the following parameters:
nftAddress
: Address of the NFT contract.newOwner
: Address of the new owner.
To initialize the contract, the project owner needs to call the initialize
function with the following parameters:
_bridgeSigner
: Address of the signer of the bridge._feeReceiver
: Address of the fee receiver._operator
: Address of the operator.
The operator can set the supported chains using the setSupportedChain
function. This function accepts the chainId
of the chain and a status
(true/false) to enable or disable the chain.
The operator can set the bridge status (online/offline) using the setBridgeStatus
function. This function accepts a boolean value to activate or deactivate the bridge.
The operator can set the bridge fee status (active/inactive) using the setFeeStatus
function. This function accepts a boolean value to activate or deactivate the fees.
The operator can set the ETH fee for a specific chain using the setETHFee
function. This function accepts the chainId
of the chain, a boolean value to activate or deactivate the fees, and the fee amount.
The operator can set the fees for ERC20 tokens using the setTokenFees
function. This function accepts the tokenAddress
of the token contract, the deposit fee amount, the withdraw fee amount, and the target chain id.
The operator can set the fee receiver address using the setFeeReceiver
function. This function accepts the receiver
address.
The operator can set the settings of an ERC20 token using the setERC20Details
function. This function accepts the tokenAddress
of the ERC20 contract, a boolean value to activate or deactivate the contract, a boolean value to burn the tokens on deposit, the deposit fee amount, the withdraw fee amount, the maximum deposit amount per 24 hours, the maximum withdraw amount per 24 hours, the maximum mint amount per 24 hours, the maximum burn amount per 24 hours, and the target chain id.
Users can deposit ERC20 tokens to the bridge by calling the depositERC20
function. This function accepts the tokenAddress
of the token contract, the token amount, and the target chain id.
The bridge can withdraw ERC20 tokens by calling the withdrawERC20
function. This function accepts the tokenAddress
of the token contract, the user address, the token amount, and a unique key.
The project owner can get the amount of deposit fees for a given ERC20 contract by calling the getDepositFeeAmount
function. This function accepts the contractAddress
of the ERC20 contract and the target chain id.
The project owner can get the amount of withdraw fees for a given ERC20 contract by calling the getWithdrawFeeAmount
function. This function accepts the contractAddress
of the ERC20 contract and the target chain id.
Contract | Type | Bases | ||
---|---|---|---|---|
β | Function Name | Visibility | Mutability | Modifiers |
ERC721BridgeImpl | Implementation | ERC721Holder, AccessControlUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable | ||
β | Public βοΈ | π | NOβοΈ | |
β | _authorizeUpgrade | Internal π | π | onlyRole |
β | initialize | External βοΈ | π | initializer |
β | setSupportedChain | External βοΈ | π | onlyRole |
β | setMaxNFTsPerTx | External βοΈ | π | onlyRole |
β | setBridgeStatus | External βοΈ | π | onlyRole |
β | setFeeStatus | External βοΈ | π | onlyRole |
β | setETHFee | External βοΈ | π | onlyRole |
β | setTokenFees | External βοΈ | π | onlyRole |
β | setFeeReceiver | External βοΈ | π | onlyRole |
β | setNFTDetails | External βοΈ | π | onlyRole |
β | setERC20Details | External βοΈ | π | onlyRole |
β | depositSingleERC721 | Public βοΈ | π΅ | NOβοΈ |
β | depositMultipleERC721 | External βοΈ | π΅ | nonReentrant |
β | withdrawSingleERC721 | Public βοΈ | π | onlyRole |
β | withdrawMultipleERC721 | External βοΈ | π | onlyRole |
β | takeFees | Private π | π | |
β | getDepositFeeAddressAndAmount | External βοΈ | NOβοΈ | |
β | createERC721 | Public βοΈ | π | onlyRole |
β | mintERC721 | Public βοΈ | π | onlyRole |
β | setMarketplaceDistributions | Public βοΈ | π | onlyRole |
β | setBaseURI | Public βοΈ | π | onlyRole |
β | changeOwnerNft | Public βοΈ | π | onlyRole |
base_erc721 | Implementation | ERC721, Ownable | ||
β | Public βοΈ | π | ERC721 Ownable | |
β | safeMint | Public βοΈ | π | onlyOwner |
β | safeMintTo | Public βοΈ | π | onlyOwner |
β | setBaseURI | Public βοΈ | π | onlyOwner |
β | setMarketplaceDistributions | External βοΈ | π | onlyOwner |
β | _baseURI | Internal π | ||
β | getMarketplaceDistributionForERC721 | External βοΈ | NOβοΈ | |
BridgeERC721_test | Implementation | BaseTest | ||
β | setUp | Public βοΈ | π | NOβοΈ |
β | createToken | Public βοΈ | π | NOβοΈ |
β | onERC721Received | Public βοΈ | NOβοΈ | |
β | test_check_deployment_initialization | Public βοΈ | π | NOβοΈ |
β | test_setSupportedChain | Public βοΈ | π | NOβοΈ |
β | test_setMaxNFTsPerTx | Public βοΈ | π | NOβοΈ |
β | test_setBridgeStatus | Public βοΈ | π | NOβοΈ |
β | test_setFeeStatus | Public βοΈ | π | NOβοΈ |
β | test_setETHFee | Public βοΈ | π | NOβοΈ |
β | test_setTokenFees | Public βοΈ | π | NOβοΈ |
β | test_setFeeReceiver | Public βοΈ | π | NOβοΈ |
β | test_setNFTDetails | Public βοΈ | π | NOβοΈ |
β | test_setERC20Details | Public βοΈ | π | NOβοΈ |
β | test_depositSingleERC721 | Public βοΈ | π | NOβοΈ |
β | test_depositMultipleERC721 | Public βοΈ | π | NOβοΈ |
β | test_depositMultipleERC721_withFees | Public βοΈ | π | NOβοΈ |
β | test_withdrawSingleERC721 | Public βοΈ | π | NOβοΈ |
β | test_withdrawMultipleERC721 | Public βοΈ | π | NOβοΈ |
β | test_getDepositFeeAddressAndAmount | Public βοΈ | π | NOβοΈ |
β | test_setBaseURI | Public βοΈ | π | NOβοΈ |
β | test_changeOwnerNft | Public βοΈ | π | NOβοΈ |
BaseTest | Implementation | Test | ||
base_erc20 | Implementation | ERC20, Ownable, ERC20Capped | ||
β | Public βοΈ | π | ERC20 ERC20Capped Ownable | |
β | decimals | Public βοΈ | NOβοΈ | |
β | airdrop | External βοΈ | π | NOβοΈ |
β | airdropD | External βοΈ | π | NOβοΈ |
β | mint | External βοΈ | π | onlyOwner |
β | burn | External βοΈ | π | NOβοΈ |
β | _update | Internal π | π | |
IERC20 | Interface | |||
β | decimals | External βοΈ | NOβοΈ | |
β | balanceOf | External βοΈ | NOβοΈ | |
β | transfer | External βοΈ | π | NOβοΈ |
β | transferFrom | External βοΈ | π | NOβοΈ |
β | allowance | External βοΈ | NOβοΈ | |
β | burn | External βοΈ | π | NOβοΈ |
ERC20BridgeImpl | Implementation | AccessControlUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable | ||
β | Public βοΈ | π | NOβοΈ | |
β | _authorizeUpgrade | Internal π | π | onlyRole |
β | initialize | External βοΈ | π | initializer |
β | setSupportedChain | External βοΈ | π | onlyRole |
β | setBridgeStatus | External βοΈ | π | onlyRole |
β | setFeeStatus | External βοΈ | π | onlyRole |
β | setETHFee | External βοΈ | π | onlyRole |
β | setTokenFees | External βοΈ | π | onlyRole |
β | setFeeReceiver | External βοΈ | π | onlyRole |
β | setERC20Details | External βοΈ | π | onlyRole |
β | depositERC20 | External βοΈ | π΅ | nonReentrant |
β | withdrawERC20 | External βοΈ | π | nonReentrant |
β | calculateFees | Private π | ||
β | getDepositFeeAmount | External βοΈ | NOβοΈ | |
β | getWithdrawFeeAmount | External βοΈ | NOβοΈ | |
β | createNewToken | External βοΈ | π | NOβοΈ |
β | mintToken | Public βοΈ | π | NOβοΈ |
β | burnToken | Public βοΈ | π | NOβοΈ |
Base | Implementation | Script | ||
β | attachContracts | Public βοΈ | π | NOβοΈ |
β | deployBridge | Public βοΈ | π | NOβοΈ |
β | deployERC20 | Public βοΈ | π | NOβοΈ |
β | deployERC721 | Public βοΈ | π | NOβοΈ |
β | setNftDetails | Public βοΈ | π | NOβοΈ |
β | setERC20Details | Public βοΈ | π | NOβοΈ |
β | setBridgeStatus | Public βοΈ | π | NOβοΈ |
β | setFeeStatus | Public βοΈ | π | NOβοΈ |
β | setETHFee | Public βοΈ | π | NOβοΈ |
β | showAddresses | Public βοΈ | NOβοΈ | |
DeployAllAndSetBridgeERC721Impl | Implementation | Base | ||
β | run | External βοΈ | π | NOβοΈ |
DeployBridgeImpl | Implementation | Base | ||
β | run | External βοΈ | π | NOβοΈ |
UpgradeBridgeImpl | Implementation | Base | ||
β | run | External βοΈ | π | NOβοΈ |
DepositInBridgeERC721Impl | Implementation | Base | ||
β | run | External βοΈ | π | NOβοΈ |
Legend
Symbol | Meaning |
---|---|
π | Function can modify state |
π΅ | Function is payable |