Skip to content

Commit

Permalink
Merge branch 'main' into add/contract-sizer
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Oct 12, 2023
2 parents da955ff + cde9924 commit a9c5d5a
Show file tree
Hide file tree
Showing 33 changed files with 4,885 additions and 5,702 deletions.
25 changes: 16 additions & 9 deletions contracts/interchain-token-service/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interf
import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';
import { Create3 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create3.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { StringToBytes32, Bytes32ToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/Bytes32String.sol';
import { Create3Address } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create3Address.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';
import { StringToBytes32, Bytes32ToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/Bytes32String.sol';

import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol';
import { ITokenManagerDeployer } from '../interfaces/ITokenManagerDeployer.sol';
Expand All @@ -32,7 +32,15 @@ import { Multicall } from '../utils/Multicall.sol';
* It (mostly) does not handle tokens, but is responsible for the messaging that needs to occur for cross chain transfers to happen.
* @dev The only storage used here is for ExpressCalls
*/
contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatable, ExpressCallHandler, Pausable, Multicall {
contract InterchainTokenService is
IInterchainTokenService,
Upgradable,
Operatable,
ExpressCallHandler,
Pausable,
Multicall,
Create3Address
{
using StringToBytes32 for string;
using Bytes32ToString for bytes32;
using AddressBytesUtils for bytes;
Expand Down Expand Up @@ -69,7 +77,7 @@ contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatab
* @param gateway_ the address of the AxelarGateway.
* @param gasService_ the address of the AxelarGasService.
* @param remoteAddressValidator_ the address of the RemoteAddressValidator.
* @param tokenManagerImplementations this need to have exactly 3 implementations in the following order: Lock/Unlock, mint/burn and then liquidity pool.
* @param tokenManagerImplementations this needs to have implementations in the order: Mint-burn, Mint-burn from, Lock-unlock, Lock-unlock with fee, and liquidity pool.
*/
constructor(
address tokenManagerDeployer_,
Expand Down Expand Up @@ -143,9 +151,8 @@ contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatab
* @param tokenId the tokenId.
* @return tokenManagerAddress deployment address of the TokenManager.
*/
// TODO: Maybe copy the code of the create3Deployer to save gas, but would introduce duplicate code problems.
function getTokenManagerAddress(bytes32 tokenId) public view returns (address tokenManagerAddress) {
tokenManagerAddress = Create3.deployedAddress(address(this), tokenId);
tokenManagerAddress = _create3Address(tokenId);
}

/**
Expand Down Expand Up @@ -176,7 +183,7 @@ contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatab
*/
function getStandardizedTokenAddress(bytes32 tokenId) public view returns (address tokenAddress) {
tokenId = _getStandardizedTokenSalt(tokenId);
tokenAddress = Create3.deployedAddress(address(this), tokenId);
tokenAddress = _create3Address(tokenId);
}

/**
Expand Down Expand Up @@ -841,7 +848,7 @@ contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatab
function _decodeMetadata(bytes memory metadata) internal pure returns (uint32 version, bytes memory data) {
data = new bytes(metadata.length - 4);
assembly {
version := shr(224, mload(data))
version := shr(224, mload(add(metadata, 32)))
}
if (data.length == 0) return (version, data);
uint256 n = (data.length - 1) / 32;
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
pragma solidity ^0.8.0;

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

import { IExpressCallHandler } from './IExpressCallHandler.sol';
import { ITokenManagerType } from './ITokenManagerType.sol';
import { IPausable } from './IPausable.sol';
import { IMulticall } from './IMulticall.sol';

interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAxelarExecutable, IPausable, IMulticall {
// more generic error
interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAxelarExecutable, IPausable, IMulticall, IContractIdentifier {
error ZeroAddress();
error LengthMismatch();
error InvalidTokenManagerImplementation();
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IRemoteAddressValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

pragma solidity ^0.8.0;

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

/**
* @title IRemoteAddressValidator
* @dev Manages and validates remote addresses, keeps track of addresses supported by the Axelar gateway contract
*/
interface IRemoteAddressValidator {
interface IRemoteAddressValidator is IContractIdentifier {
error ZeroAddress();
error LengthMismatch();
error ZeroStringLength();
Expand Down
11 changes: 4 additions & 7 deletions contracts/interfaces/IStandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
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';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';

/**
* @title StandardizedToken
* @notice This contract implements a standardized token which extends InterchainToken functionality.
* This contract also inherits Distributable and Implementation logic.
*/
interface IStandardizedToken is IImplementation, IInterchainToken, IDistributable, IERC20MintableBurnable, IERC20 {
interface IStandardizedToken is IImplementation, IInterchainToken, IDistributable, IERC20MintableBurnable, IERC20, IContractIdentifier {
error TokenManagerAddressZero();
error TokenNameEmpty();

/**
* @notice Returns the contract id, which a proxy can check to ensure no false implementation was used.
*/
function contractId() external view returns (bytes32);
}
5 changes: 1 addition & 4 deletions contracts/interfaces/IStandardizedTokenProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ pragma solidity ^0.8.0;
* @dev Proxy contract for StandardizedToken contracts. Inherits from FixedProxy and implements IStandardizedTokenProxy.
*/
interface IStandardizedTokenProxy {
/**
* @notice Returns the contract id, which a proxy can check to ensure no false implementation was used.
*/
function contractId() external view returns (bytes32);

}
2 changes: 1 addition & 1 deletion contracts/proxies/StandardizedTokenProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract StandardizedTokenProxy is FixedProxy, IStandardizedTokenProxy {
/**
* @notice Getter for the contract id.
*/
function contractId() external pure returns (bytes32) {
function contractId() internal pure override returns (bytes32) {
return CONTRACT_ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IRemoteAddressValidator } from '../interfaces/IRemoteAddressValidator.sol';
import { AddressToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/AddressString.sol';
import { AddressToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/AddressString.sol';
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';

/**
Expand Down
98 changes: 98 additions & 0 deletions contracts/test/InvalidStandardizedToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';

import { InterchainToken } from '../interchain-token/InterchainToken.sol';
import { ERC20Permit } from '../token-implementations/ERC20Permit.sol';
import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Implementation } from '../utils/Implementation.sol';
import { Distributable } from '../utils/Distributable.sol';

contract InvalidStandardizedToken is IERC20MintableBurnable, InterchainToken, ERC20Permit, Implementation, Distributable {
using AddressBytesUtils for bytes;

string public name;
string public symbol;
uint8 public decimals;
address internal tokenManager_;

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

modifier onlyDistributorOrTokenManager() {
if (msg.sender != tokenManager_) {
if (msg.sender != distributor()) revert NotDistributor();
}

_;
}

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

/**
* @notice Returns the token manager for this token
* @return ITokenManager The token manager contract
*/
function tokenManager() public view override returns (ITokenManager) {
return ITokenManager(tokenManager_);
}

/**
* @notice Setup function to initialize contract parameters
* @param params The setup parameters in bytes
* The setup params include tokenManager, distributor, tokenName, symbol, decimals, mintAmount and mintTo
*/
function setup(bytes calldata params) external override onlyProxy {
{
address distributor_;
address tokenManagerAddress;
string memory tokenName;
(tokenManagerAddress, distributor_, tokenName, symbol, decimals) = abi.decode(
params,
(address, address, string, string, uint8)
);

tokenManager_ = tokenManagerAddress;
name = tokenName;

_setDistributor(distributor_);
_setNameHash(tokenName);
}
{
uint256 mintAmount;
address mintTo;
(, , , , , mintAmount, mintTo) = abi.decode(params, (address, address, string, string, uint8, uint256, address));

if (mintAmount > 0 && mintTo != address(0)) {
_mint(mintTo, mintAmount);
}
}
}

/**
* @notice Function to mint new tokens
* Can only be called by the distributor address.
* @param account The address that will receive the minted tokens
* @param amount The amount of tokens to mint
*/
function mint(address account, uint256 amount) external onlyDistributorOrTokenManager {
_mint(account, amount);
}

/**
* @notice Function to burn tokens
* Can only be called by the distributor address.
* @param account The address that will have its tokens burnt
* @param amount The amount of tokens to burn
*/
function burn(address account, uint256 amount) external onlyDistributorOrTokenManager {
_burn(account, amount);
}
}
4 changes: 4 additions & 0 deletions contracts/test/MockAxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ contract MockAxelarGateway is IMockAxelarGateway {
_addressStorage[_getTokenAddressKey(symbol)] = tokenAddress;
}

function setCommandExecuted(bytes32 commandId, bool executed) external {
_setCommandExecuted(commandId, executed);
}

/********************\
|* Pure Key Getters *|
\********************/
Expand Down
18 changes: 18 additions & 0 deletions contracts/test/utils/AddressBytesUtilsTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

contract AddressBytesUtilsTest {
using AddressBytesUtils for address;
using AddressBytesUtils for bytes;

function toAddress(bytes memory bytesAddress) external pure returns (address addr) {
return bytesAddress.toAddress();
}

function toBytes(address addr) external pure returns (bytes memory bytesAddress) {
return addr.toBytes();
}
}
5 changes: 5 additions & 0 deletions contracts/test/utils/MulticallTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ contract MulticallTest is Multicall {
return nonce_;
}

function function3() external pure {
// solhint-disable-next-line reason-string
revert();
}

function multicallTest(bytes[] calldata data) external {
lastMulticallReturns = multicall(data);
}
Expand Down
17 changes: 17 additions & 0 deletions contracts/test/utils/NoReEntrancyTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

contract NoReEntrancyTest is NoReEntrancy {
uint256 public value;

function testFunction() external noReEntrancy {
value = 1;
this.callback();
value = 2;
}

function callback() external noReEntrancy {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';

import { ITokenManagerLiquidityPool } from '../../interfaces/ITokenManagerLiquidityPool.sol';
import { TokenManager } from '../TokenManager.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { SafeTokenTransfer, SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { SafeTokenTransfer, SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';

import { ITokenManagerLockUnlock } from '../../interfaces/ITokenManagerLockUnlock.sol';
import { TokenManager } from '../TokenManager.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { SafeTokenTransferFrom, SafeTokenTransfer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { SafeTokenTransferFrom, SafeTokenTransfer } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';

import { ITokenManagerLockUnlock } from '../../interfaces/ITokenManagerLockUnlock.sol';
import { TokenManager } from '../TokenManager.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { SafeTokenCall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { SafeTokenCall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';

import { TokenManager } from '../TokenManager.sol';
import { IERC20MintableBurnable } from '../../interfaces/IERC20MintableBurnable.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { SafeTokenCall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
import { SafeTokenCall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';

import { IERC20BurnableFrom } from '../../interfaces/IERC20BurnableFrom.sol';
import { TokenManagerMintBurn } from './TokenManagerMintBurn.sol';
Expand Down
6 changes: 3 additions & 3 deletions contracts/utils/StandardizedTokenDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StandardizedTokenProxy } from '../proxies/StandardizedTokenProxy.sol';
* @title StandardizedTokenDeployer
* @notice This contract is used to deploy new instances of the StandardizedTokenProxy contract.
*/
contract StandardizedTokenDeployer is IStandardizedTokenDeployer {
contract StandardizedTokenDeployer is IStandardizedTokenDeployer, Create3 {
address public immutable implementationAddress;

/**
Expand Down Expand Up @@ -50,11 +50,11 @@ contract StandardizedTokenDeployer is IStandardizedTokenDeployer {
// slither-disable-next-line too-many-digits
bytes memory bytecode = bytes.concat(type(StandardizedTokenProxy).creationCode, abi.encode(implementationAddress, params));

address tokenAddress = Create3.deploy(salt, bytecode);
address tokenAddress = _create3(bytecode, salt);
if (tokenAddress.code.length == 0) revert TokenDeploymentFailed();
}

function deployedAddress(bytes32 salt) external view returns (address tokenAddress) {
return Create3.deployedAddress(address(this), salt);
return _create3Address(salt);
}
}
Loading

0 comments on commit a9c5d5a

Please sign in to comment.