Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bridged RARI token for Arbitrum ecosystem (Arbitrum + RARI chains) #305

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0ed9cd1
chore: deployed RariToken to sepolia
evgenynacu May 27, 2024
a698234
chore: deployed RariToken to sepolia (in separate project)
evgenynacu May 27, 2024
3cc6979
chore: deployed RariToken to sepolia (in separate project)
evgenynacu May 27, 2024
e266e40
chore: removed unneeded deps
evgenynacu May 27, 2024
29ccb94
chore: deployed initial version of bridged token version to arbitrum
evgenynacu May 27, 2024
a96fba0
chore: deployed initial version of bridged token version to arbitrum
evgenynacu May 27, 2024
34e7314
chore: deployed initial version of bridged token version to arbitrum …
evgenynacu May 27, 2024
917f49e
fix: add tests for bridged tokens, add wrap function
evgenynacu May 29, 2024
6b468e7
fix: deployed bridged token with proxy
evgenynacu Jun 5, 2024
bf88846
chore: deployed RARI bridged token to RARI sepolia
evgenynacu Jun 10, 2024
f4c033c
fix: add functions to set router and gateway addresses
evgenynacu Jun 12, 2024
f69e9d7
fix: C2 Factory
evgenynacu Jun 19, 2024
d17d7b9
fix: add test to check values after init
evgenynacu Jul 5, 2024
ddf9338
fix: minor
evgenynacu Jul 5, 2024
f22063b
fix: fixes after preliminary audit report
evgenynacu Jul 10, 2024
43e1def
fix: deploy RariBridgedToken config for Arbitrum chain
evgenynacu Aug 13, 2024
dd3868f
chore: deployed RariBridgedToken to Arbitrum
evgenynacu Aug 13, 2024
8dc4ab1
chore: deployed RariBridgedToken to RARI chain
evgenynacu Aug 14, 2024
f3e5768
chore: deployed RariBridgedToken to RARI chain
evgenynacu Aug 21, 2024
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
642 changes: 642 additions & 0 deletions projects/hardhat-deploy/deployments/sepolia/RariToken.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions projects/hardhat-deploy/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ dotenv.config();
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.5.17",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
{
version: "0.7.6",
settings: {
Expand Down
1 change: 1 addition & 0 deletions projects/hardhat-deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@rarible/royalties-registry": "^0.8.4-beta.3",
"@rarible/transfer-manager": "^0.8.4-beta.3",
"@rarible/upgrade-executor": "^0.8.4-beta.3",
"@rarible/rari-token": "^0.8.4-beta.3",
"zksync-ethers": "^5.0.0",
"@matterlabs/hardhat-zksync-toolbox": "^0.2.0",
"@matterlabs/hardhat-zksync-chai-matchers": "1.2.1",
Expand Down
5 changes: 5 additions & 0 deletions projects/hardhat-deploy/src/RariTokenImport.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.5.17;

import {RariToken} from "@rarible/rari-token/contracts/RARI.sol";
13 changes: 13 additions & 0 deletions projects/rari-bridged-token/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

cache-zk
artifacts-zk
4 changes: 4 additions & 0 deletions projects/rari-bridged-token/contracts/EIP173Proxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import "hardhat-deploy-immutable-proxy/solc_0.8/proxy/EIP173Proxy.sol";
114 changes: 114 additions & 0 deletions projects/rari-bridged-token/contracts/RariBridgedToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20VotesUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {IArbToken} from "@arbitrum/token-bridge-contracts/contracts/tokenbridge/arbitrum/IArbToken.sol";

/**
* @title Interface needed to call function registerTokenToL2 of the L1CustomGateway
*/
interface IL1CustomGateway {
function registerTokenToL2(address _l2Address, uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost, address _creditBackAddress) external payable returns (uint256);
}

/**
* @title Interface needed to call function setGateway of the L2GatewayRouter
*/
interface IL2GatewayRouter {
function setGateway(address _gateway, uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost, address _creditBackAddress) external payable returns (uint256);
}

contract RariBridgedToken is IArbToken, AccessControlUpgradeable, ERC20VotesUpgradeable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
IERC20 private _previous;
address private _l1;
address private _customGateway;
address private _router;

function __RariBridgedToken_init(IERC20 previousToken, address adminAddress, address minterAddress, address l1, address customGatewayAddress, address routerAddress) external initializer {
__Context_init();
__EIP712_init("RARI", "1");
__AccessControl_init();
__ERC20_init("RARI", "RARI");
__ERC20Votes_init();

if (adminAddress != address(0)) {
_grantRole(DEFAULT_ADMIN_ROLE, adminAddress);
} else {
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

if (minterAddress != address(0)) {
_grantRole(MINTER_ROLE, minterAddress);
}

_previous = previousToken;
_l1 = l1;
_customGateway = customGatewayAddress;
_router = routerAddress;
}

function setCustomGateway(address customGatewayAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
_customGateway = customGatewayAddress;
}

function setRouter(address routerAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
_router = routerAddress;
}

function wrap(address account, uint256 amount) external {
require(_previous.transferFrom(_msgSender(), address(this), amount));
super._mint(account, amount);
}

function bridgeMint(address account, uint256 amount) external override onlyRole(MINTER_ROLE) {
super._mint(account, amount);
}

function bridgeBurn(address account, uint256 amount) external override onlyRole(MINTER_ROLE) {
super._burn(account, amount);
}

function l1Address() external view returns (address) {
return _l1;
}

function previous() external view returns (address) {
return address(_previous);
}

function customGateway() external view returns (address) {
return _customGateway;
}

function router() external view returns (address) {
return _router;
}

function isArbitrumEnabled() external pure returns (uint8) {
return 0xb1;
}

function registerTokenOnL2(
address l2CustomTokenAddress,
uint256 maxSubmissionCostForCustomGateway,
uint256 maxSubmissionCostForRouter,
uint256 maxGasForCustomGateway,
uint256 maxGasForRouter,
uint256 gasPriceBid,
uint256 valueForGateway,
uint256 valueForRouter,
address creditBackAddress
) external payable onlyRole(DEFAULT_ADMIN_ROLE) {

IL1CustomGateway(_customGateway).registerTokenToL2{value: valueForGateway}(
l2CustomTokenAddress, maxGasForCustomGateway, gasPriceBid, maxSubmissionCostForCustomGateway, creditBackAddress
);

IL2GatewayRouter(_router).setGateway{value: valueForRouter}(
_customGateway, maxGasForRouter, gasPriceBid, maxSubmissionCostForRouter, creditBackAddress
);
}
}
88 changes: 88 additions & 0 deletions projects/rari-bridged-token/deploy/101_deploy_RariBridgedToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';

type NetworkConfig = {
l1Address: `0x${string}`,
previousAddress: `0x${string}`,
customGatewayAddress: `0x${string}`,
routerAddress: `0x${string}`,
minterAddress: `0x${string}`
}

const zero = "0x0000000000000000000000000000000000000000"
const configs: Record<string, NetworkConfig> = {
"arbitrum": {
l1Address: "0xFca59Cd816aB1eaD66534D82bc21E7515cE441CF",
previousAddress: "0xCF8600347Dc375C5f2FdD6Dab9BB66e0b6773cd7",
customGatewayAddress: "0x8bE956aB42274056ef4471BEb211b33e258b7324",
routerAddress: "0x2623C144B4d167f70893f6A8968B98c89a6C5F97",
minterAddress: "0x096760F208390250649E3e8763348E783AEF5562"
},
"rari": {
l1Address: "0xcf78572a8fe97b2b9a4b9709f6a7d9a863c1b8e0",
previousAddress: "0xC6e8a38FA44720d9d89Fef0A9E71F5a15E0b2C38",
customGatewayAddress: zero,
routerAddress: zero,
minterAddress: "0x90E43f5d772e50B01B3F9596f65AD5653467d010"
},
"arbitrum_sepolia": {
l1Address: "0xfac63865d9ca6f1e70e9c441d4b01255519f7a54",
previousAddress: "0xcca8413d36c6061934e13ab1ad685a638dc2210a",
customGatewayAddress: "0x7EDA0d4c14Af6B0920F4e3C0F0cA18d18212fB0A",
routerAddress: "0xece5902AD6Bbf4689EA8aD4B95237fAf5B65FB26",
minterAddress: "0x8ca1e1ac0f260bc4da7dd60aca6ca66208e642c5"
},
"rari_sepolia": {
l1Address: "0x1Bb02CB1A846d14c3741b5f7d74Be1A3f2b22d7d",
previousAddress: zero,
customGatewayAddress: "0x7EDA0d4c14Af6B0920F4e3C0F0cA18d18212fB0A",
routerAddress: zero,
minterAddress: "0x311c5fe27874fbc8ea9d06beda2ff316e37c3e2f"
}
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

console.log(`deploying contracts on network ${hre.network.name}`)

const { deploy } = hre.deployments;
const { deployer } = await hre.getNamedAccounts();

console.log("deploying contracts with the account:", deployer);

const proxyResult = await deploy('EIP173Proxy', {
from: deployer,
log: true,
autoMine: true,
deterministicDeployment: "0x11111115",
args: ["0x0000000000000000000000000000000000000000", deployer, "0x"]
});

console.log("deployed proxy, result is", proxyResult.address)

const implResult = await deploy('RariBridgedToken', {
from: deployer,
log: true,
autoMine: true,
});

console.log("deployed impl, result is", implResult.address)

const proxyFactory = await hre.ethers.getContractFactory("EIP173Proxy")
const proxy = proxyFactory.attach(proxyResult.address)
const upgradeResult = await proxy.upgradeTo(implResult.address)

console.log("Upgraded. result=", upgradeResult.hash)

const tokenFactory = await hre.ethers.getContractFactory("RariBridgedToken")
const token = tokenFactory.attach(proxyResult.address)

const config = configs[hre.network.name]
console.log("using config", config)
const initResult = await token.__RariBridgedToken_init(config.previousAddress, zero, config.minterAddress, config.l1Address, config.customGatewayAddress, config.routerAddress)

console.log("initialized. result is", initResult.hash)
};

export default func;
func.tags = ['deploy-rari-bridged-token'];
1 change: 1 addition & 0 deletions projects/rari-bridged-token/deployments/arbitrum/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42161
Loading