Skip to content

Commit

Permalink
Removed a lot of unused imports and made routers upgradable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Oct 27, 2023
1 parent 7815108 commit de5bcda
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"no-inline-assembly": "off",
"no-empty-blocks": "off",
"avoid-low-level-calls": "off",
"not-rely-on-time": "off"
"not-rely-on-time": "off",
"immutable-vars-naming": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { IRemoteAddressValidator } from '../interfaces/IRemoteAddressValidator.s
import { IInterchainTokenExecutable } from '../interfaces/IInterchainTokenExecutable.sol';
import { IInterchainTokenExpressExecutable } from '../interfaces/IInterchainTokenExpressExecutable.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { ITokenManagerProxy } from '../interfaces/ITokenManagerProxy.sol';
import { IERC20Named } from '../interfaces/IERC20Named.sol';

import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/ICanonicalTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pragma solidity ^0.8.0;
interface ICanonicalTokenRegistrar {
error ZeroAddress();

function chainName() external view returns (string memory);

function chainNameHash() external view returns (bytes32);

function getCanonicalTokenSalt(address tokenAddress) external view returns (bytes32 salt);
Expand Down
1 change: 0 additions & 1 deletion contracts/interfaces/IStandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.0;

import { IContractIdentifier } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IContractIdentifier.sol';

import { IImplementation } from './IImplementation.sol';
import { IInterchainToken } from './IInterchainToken.sol';
import { IDistributable } from './IDistributable.sol';
import { IERC20MintableBurnable } from './IERC20MintableBurnable.sol';
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IStandardizedTokenDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity ^0.8.0;

import { Create3Deployer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create3Deployer.sol';

/**
* @title IStandardizedTokenDeployer
* @notice This contract is used to deploy new instances of the StandardizedTokenProxy contract.
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IStandardizedTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ interface IStandardizedTokenRegistrar {
error NotDistributor(address distributor);
error NotOperator(address operator);

function chainName() external view returns (string memory);

function chainNameHash() external view returns (bytes32);

function getStandardizedTokenSalt(address deployer, bytes32 salt) external view returns (bytes32);
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/ITokenManagerDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity ^0.8.0;

import { Create3Deployer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create3Deployer.sol';

/**
* @title ITokenManagerDeployer
* @notice This contract is used to deploy new instances of the TokenManagerProxy contract.
Expand Down
28 changes: 28 additions & 0 deletions contracts/proxies/CanonicalTokenRegistrarProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { FinalProxy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/FinalProxy.sol';

/**
* @title InterchainTokenServiceProxy
* @dev Proxy contract for interchain token service contracts. Inherits from the FinalProxy contract.
*/
contract CanonicalTokenRegistrarProxy is FinalProxy {
bytes32 private constant CONTRACT_ID = keccak256('canonical-token-registrar');

/**
* @dev Constructs the InterchainTokenServiceProxy contract.
* @param implementationAddress Address of the interchain token service implementation
* @param owner Address of the owner of the proxy
*/
constructor(address implementationAddress, address owner) FinalProxy(implementationAddress, owner, '') {}

/**
* @dev Override for the 'contractId' function in FinalProxy. Returns a unique identifier for this contract.
* @return bytes32 identifier for this contract
*/
function contractId() internal pure override returns (bytes32) {
return CONTRACT_ID;
}
}
28 changes: 28 additions & 0 deletions contracts/proxies/StandardizedTokenRegistrarProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { FinalProxy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/FinalProxy.sol';

/**
* @title InterchainTokenServiceProxy
* @dev Proxy contract for interchain token service contracts. Inherits from the FinalProxy contract.
*/
contract StandardizedTokenRegistrarProxy is FinalProxy {
bytes32 private constant CONTRACT_ID = keccak256('standardized-token-registrar');

/**
* @dev Constructs the InterchainTokenServiceProxy contract.
* @param implementationAddress Address of the interchain token service implementation
* @param owner Address of the owner of the proxy
*/
constructor(address implementationAddress, address owner) FinalProxy(implementationAddress, owner, '') {}

/**
* @dev Override for the 'contractId' function in FinalProxy. Returns a unique identifier for this contract.
* @return bytes32 identifier for this contract
*/
function contractId() internal pure override returns (bytes32) {
return CONTRACT_ID;
}
}
1 change: 0 additions & 1 deletion contracts/test/InterchainExecutableTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.0;

import { InterchainTokenExpressExecutable } from '../examples/InterchainTokenExpressExecutable.sol';
import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';

contract InterchainExecutableTest is InterchainTokenExpressExecutable {
Expand Down
1 change: 0 additions & 1 deletion contracts/token-implementations/StandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.0;
import { IImplementation } from '../interfaces/IImplementation.sol';
import { IStandardizedToken } from '../interfaces/IStandardizedToken.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IInterchainToken } from '../interfaces/IInterchainToken.sol';

import { InterchainToken } from '../interchain-token/InterchainToken.sol';
import { ERC20Permit } from '../token-implementations/ERC20Permit.sol';
Expand Down
1 change: 0 additions & 1 deletion contracts/token-manager/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.0;

import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';
import { ITokenManagerProxy } from '../interfaces/ITokenManagerProxy.sol';

import { Operatable } from '../utils/Operatable.sol';
import { FlowLimit } from '../utils/FlowLimit.sol';
Expand Down
14 changes: 11 additions & 3 deletions contracts/token-registrars/CanonicalTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@

pragma solidity ^0.8.0;

import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';

import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';
import { ICanonicalTokenRegistrar } from '../interfaces/ICanonicalTokenRegistrar.sol';
import { ITokenManagerType } from '../interfaces/ITokenManagerType.sol';
import { IERC20Named } from '../interfaces/IERC20Named.sol';

import { Multicall } from '../utils/Multicall.sol';

contract CanonicalTokenRegistrar is ICanonicalTokenRegistrar, ITokenManagerType, Multicall {
contract CanonicalTokenRegistrar is ICanonicalTokenRegistrar, ITokenManagerType, Multicall, Upgradable {
IInterchainTokenService public immutable service;
string public chainName;
bytes32 public immutable chainNameHash;

bytes32 internal constant PREFIX_CANONICAL_TOKEN_SALT = keccak256('canonical-token-salt');
bytes32 private constant CONTRACT_ID = keccak256('canonical-token-registrar');

constructor(address interchainTokenServiceAddress) {
if (interchainTokenServiceAddress == address(0)) revert ZeroAddress();
service = IInterchainTokenService(interchainTokenServiceAddress);
string memory chainName_ = IInterchainTokenService(interchainTokenServiceAddress).remoteAddressValidator().chainName();
chainName = chainName_;
chainNameHash = keccak256(bytes(chainName_));
}

/**
* @notice Getter for the contract id.
*/
function contractId() external pure returns (bytes32) {
return CONTRACT_ID;
}

function getCanonicalTokenSalt(address tokenAddress) public view returns (bytes32 salt) {
salt = keccak256(abi.encode(PREFIX_CANONICAL_TOKEN_SALT, chainNameHash, tokenAddress));
}
Expand Down
14 changes: 11 additions & 3 deletions contracts/token-registrars/StandardizedTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity ^0.8.0;

import { SafeTokenTransfer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';

import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';
import { IStandardizedTokenRegistrar } from '../interfaces/IStandardizedTokenRegistrar.sol';
Expand All @@ -14,15 +15,16 @@ import { Multicall } from '../utils/Multicall.sol';

import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';

contract StandardizedTokenRegistrar is IStandardizedTokenRegistrar, ITokenManagerType, Multicall {
contract StandardizedTokenRegistrar is IStandardizedTokenRegistrar, ITokenManagerType, Multicall, Upgradable {
using AddressBytesUtils for bytes;
using AddressBytesUtils for address;
using SafeTokenTransfer for IStandardizedToken;

IInterchainTokenService public immutable service;
string public chainName;
bytes32 public immutable chainNameHash;

bytes32 private constant CONTRACT_ID = keccak256('standardized-token-registrar');

struct DeployParams {
address deployer;
bytes distributor;
Expand All @@ -37,10 +39,16 @@ contract StandardizedTokenRegistrar is IStandardizedTokenRegistrar, ITokenManage
if (interchainTokenServiceAddress == address(0)) revert ZeroAddress();
service = IInterchainTokenService(interchainTokenServiceAddress);
string memory chainName_ = IInterchainTokenService(interchainTokenServiceAddress).remoteAddressValidator().chainName();
chainName = chainName_;
chainNameHash = keccak256(bytes(chainName_));
}

/**
* @notice Getter for the contract id.
*/
function contractId() external pure returns (bytes32) {
return CONTRACT_ID;
}

function getStandardizedTokenSalt(address deployer, bytes32 salt) public view returns (bytes32) {
return keccak256(abi.encode(PREFIX_STANDARDIZED_TOKEN_SALT, chainNameHash, deployer, salt));
}
Expand Down
9 changes: 9 additions & 0 deletions test/tokenRegistrars.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ describe('Token Registrsrs', () => {
const wallets = await ethers.getSigners();
wallet = wallets[0];
[service, gateway, gasService] = await deployAll(wallet, 'Test', [destinationChain]);
let proxy, factory;

canonicalTokenRegistrar = await deployContract(wallet, 'CanonicalTokenRegistrar', [service.address]);
proxy = await deployContract(wallet, 'CanonicalTokenRegistrarProxy', [canonicalTokenRegistrar.address, wallet.address]);
factory = await ethers.getContractFactory('CanonicalTokenRegistrar', wallet);
canonicalTokenRegistrar = factory.attach(proxy.address);

standardizedTokenRegistrar = await deployContract(wallet, 'StandardizedTokenRegistrar', [service.address]);
proxy = await deployContract(wallet, 'StandardizedTokenRegistrarProxy', [standardizedTokenRegistrar.address, wallet.address]);
factory = await ethers.getContractFactory('StandardizedTokenRegistrar', wallet);
standardizedTokenRegistrar = factory.attach(proxy.address);
});

describe('Canonical Token Registrar', async () => {
Expand Down

0 comments on commit de5bcda

Please sign in to comment.