RIF Relay Deployment
Set Up RIF Relay Contracts and Server
Deploy Contracts
Start by deploying on-chain components. All tools needed are in the RIF Relay Contract repository
Regtest
- Clone the Repository:
git clone https://github.com/rsksmart/rif-relay-contracts
- Navigate to the directory and install dependencies:
cd rif-relay-contracts
npm install
- Deploy the contract:
npx hardhat deploy --network regtest
This uses the Regtest configuration from
hardhat.config.ts
.
After deployment, you'll see a summary of the deployed contracts. This summary includes the on-chain components essential for RIF Relay, and additional contracts for testing and validation purposes.
┌───────────────────────────────────────┬──────────────────────────────────────────────┐
│ (index) │ Values │
├───────────────────────────────────────┼──────────────────────────────────────────────┤
│ Penalizer │ '0x77045E71a7A2c50903d88e564cD72fab11e82051' │
│ RelayHub │ '0xDA7Ce79725418F4F6E13Bf5F520C89Cec5f6A974' │
│ SmartWallet │ '0x83C5541A6c8D2dBAD642f385d8d06Ca9B6C731ee' │
│ SmartWalletFactory │ '0xE0825f57Dd05Ef62FF731c27222A86E104CC4Cad' │
│ DeployVerifier │ '0x73ec81da0C72DD112e06c09A6ec03B5544d26F05' │
│ RelayVerifier │ '0x03F23ae1917722d5A27a2Ea0Bcc98725a2a2a49a' │
│ CustomSmartWallet │ '0x1eD614cd3443EFd9c70F04b6d777aed947A4b0c4' │
│ CustomSmartWalletFactory │ '0x5159345aaB821172e795d56274D0f5FDFdC6aBD9' │
│ CustomSmartWalletDeployVerifier │ '0x7557fcE0BbFAe81a9508FF469D481f2c72a8B5f3' │
│ CustomSmartWalletRelayVerifier │ '0x0e19674ebc2c2B6Df3e7a1417c49b50235c61924' │
│ NativeHolderSmartWallet │ '0x4aC9422c7720eF71Cb219B006aB363Ab54BB4183' │
│ NativeHolderSmartWalletFactory │ '0xBaDb31cAf5B95edd785446B76219b60fB1f07233' │
│ NativeHolderSmartWalletDeployVerifier │ '0xAe59e767768c6c25d64619Ee1c498Fd7D83e3c24' │
│ NativeHolderSmartWalletRelayVerifier │ '0x5897E84216220663F306676458Afc7bf2A6A3C52' │
│ UtilToken │ '0x1Af2844A588759D0DE58abD568ADD96BB8B3B6D8' │
│ VersionRegistry │ '0x8901a2Bbf639bFD21A97004BA4D7aE2BD00B8DA8' │
└───────────────────────────────────────┴──────────────────────────────────────────────┘
The deployment summary shows two sets of Smart Wallets, each paired with its verifiers. This is because the verifier is used for both deployment and transaction validation. For testing purposes, the focus will be on using these Smart Wallet Contracts.
Testnet
- Ensure your account is funded. You can get funds from the tRBTC Faucet. Additional faucet options include; Thirdweb and Blast Faucets.
- Deploy on Testnet:
npx hardhat deploy --network testnet
Remember to configure Testnet in
hardhat.config.ts
. Existing RIF Relay contracts deployed on Testnet can be found in the contracts section.
Mainnet
- Ensure your account is funded.
- Deploy on Mainnet:
npx hardhat deploy --network mainnet
Ensure Mainnet is set up in
hardhat.config.ts
. Existing RIF Relay contracts deployed on Mainnet can be found in the contracts section.
Revenue Sharing
Revenue Sharing is an optional feature in RIF Relay that can be implemented using collector contracts. You can deploy multiple Collector contracts, but they are not included in the default Relay contract deployment. For detailed information on Collector contracts, refer to the architecture documentation.
Before deploying a Collector contract ensure the following:
- Ensure the chosen token for the Collector contract is the same as the one used for transaction fees.
Note: You cannot retrieve any other tokens other than the one set during Collector deployment.
- Select an appropriate owner for the Collector contract. This owner doesn't have to be the deployer but must have the authority to execute the withdraw function, or else the revenue funds will be locked in the contract.
- Set up partners and their share percentages, ensuring the total adds up to 100%. Incorrectly sent tokens to an inaccessible address without a private key from the beneficiary will be lost. For an example of a structurally valid revenue shares definition see sample configuration.
Regtest
To deploy the Collector contract, we'll use the RIF Relay Contract.
- Create a configuration file named
deploy-collector.input.json
with the required structure:{
"collectorOwner": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"partners": [
{
"beneficiary": "0x7986b3DF570230288501EEa3D890bd66948C9B79",
"share": 20
},
{
"beneficiary": "0x0a3aA774752ec2042c46548456c094A76C7F3a79",
"share": 35
},
{
"beneficiary": "0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036",
"share": 13
},
{
"beneficiary": "0x39B12C05E8503356E3a7DF0B7B33efA4c054C409",
"share": 32
}
],
"tokenAddresses": ["0x1Af2844A588759D0DE58abD568ADD96BB8B3B6D8"],
"remainderAddress": "0xc354D97642FAa06781b76Ffb6786f72cd7746C97"
}
Note: The
collectorOwner
,beneficiaries
, andremainderAddress
are the first five accounts provided by the node in Regtest.
- Deploy the contract:
npx hardhat collector:deploy --network regtest
The collector is ready and can start receiving fees.
Testnet
Using the configuration file you created in the regtest section, run this command to deploy the contract:
npx hardhat collector:deploy --network testnet
Mainnet
Using the configuration file you created in the regtest section, run this command to deploy the contract:
npx hardhat collector:deploy --network mainnet
Allow Tokens
RIF Relay only accepts whitelisted tokens, primarily to ensure only tokens of value to the operator are accepted. To whitelist a token:
Execute the acceptToken(address token)
function on the Relay Verifiers contracts, which include:
SmartWalletDeployVerifier
SmartWalletRelayVerifier
This action must be performed by the contracts' owner, typically the account that conducted the deployment.
Regtest
In the RIF Relay Contracts, execute this command:
npx hardhat allow-tokens --network regtest --token-list <TOKEN_ADDRESSES>
<TOKEN_ADDRESSES>
is a comma-separated list of the token addresses to be allowed on the available verifiers. TheallowTokens
uses the first account (referred to as account[0]) as the owner of the contracts. This is important because only the account owner can allow tokens.
Testnet
In the RIF Relay Contracts, execute the command:
npx hardhat allow-tokens --network testnet --token-list <TOKEN_ADDRESSES>
<TOKEN_ADDRESSES>
is a comma-separated list of the token addresses to be allowed on the available verifiers. TheallowTokens
script will use the Testnet network configured in thehardhat.config.ts
, this network will be required to use the account that deployed the contracts. You can also modify the allowed tokens for specific verifiers only by using the--verifier-list
option as follows:
npx hardhat allow-tokens --network testnet --token-list <TOKEN_ADDRESSES> --verifier-list <VERIFIER_ADRESSES>
The
<TOKEN_ADDRESSES>
,<VERIFIER_ADDRESSES>
is a comma-seperated list of verifier addresses to allow the tokens for.