Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/custm-executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Oct 3, 2023
2 parents dc83e28 + 7311951 commit d6ccbc2
Show file tree
Hide file tree
Showing 38 changed files with 594 additions and 883 deletions.
219 changes: 115 additions & 104 deletions contracts/interchain-token-service/InterchainTokenService.sol

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions contracts/interchain-token/InterchainToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ERC20 } from '../token-implementations/ERC20.sol';
* @title An example implementation of the IInterchainToken.
* @notice The implementation ERC20 can be done in any way, however this example assumes that an _approve internal function exists
* that can be used to create approvals, and that `allowance` is a mapping.
* @dev You can skip the `tokenManagerRequiresApproval()` function altogether if you know what it should return for your token.
*/
abstract contract InterchainToken is IInterchainToken, ERC20 {
/**
Expand Down Expand Up @@ -62,11 +61,11 @@ abstract contract InterchainToken is IInterchainToken, ERC20 {
) external payable {
uint256 _allowance = allowance[sender][msg.sender];

if (_allowance != type(uint256).max) {
if (_allowance != UINT256_MAX) {
_approve(sender, msg.sender, _allowance - amount);
}

_beforeInterchainTransfer(msg.sender, destinationChain, recipient, amount, metadata);
_beforeInterchainTransfer(sender, destinationChain, recipient, amount, metadata);

ITokenManager tokenManager_ = tokenManager();
tokenManager_.transmitInterchainTransfer{ value: msg.value }(sender, destinationChain, recipient, amount, metadata);
Expand Down
25 changes: 25 additions & 0 deletions contracts/interfaces/IERC20BurnableFrom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20BurnableFrom {
/**
* @notice Function to burn tokens from a burn deposit address
* @notice It is needed to support legacy Axelar Gateway tokens
* @dev Can only be called after token is transferred to a deposit address.
* @param salt The address that will have its tokens burnt
*/
function burn(bytes32 salt) external;

/**
* @notice Function to burn tokens
* @notice Requires the caller to have allowance for `amount` on `from`
* @dev Can only be called by the distributor address.
* @param from The address that will have its tokens burnt
* @param amount The amount of tokens to burn
*/
function burnFrom(address from, uint256 amount) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20BurnableMintable {
interface IERC20MintableBurnable {
/**
* @notice Function to mint new tokens
* Can only be called by the distributor address.
* @dev Can only be called by the distributor address.
* @param to The address that will receive the minted tokens
* @param amount The amount of tokens to mint
*/
function mint(address to, uint256 amount) external;

/**
* @notice Function to burn tokens
* Can only be called by the distributor address.
* @dev Can only be called by the distributor address.
* @param from The address that will have its tokens burnt
* @param amount The amount of tokens to burn
*/
Expand Down
69 changes: 4 additions & 65 deletions contracts/interfaces/IExpressCallHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,14 @@ interface IExpressCallHandler {
error AlreadyExpressCalled();
error SameDestinationAsCaller();

event ExpressReceive(
bytes32 indexed tokenId,
address indexed destinationAddress,
uint256 amount,
bytes32 indexed sendHash,
address expressCaller
);
event ExpressExecutionFulfilled(
bytes32 indexed tokenId,
address indexed destinationAddress,
uint256 amount,
bytes32 indexed sendHash,
address expressCaller
);

event ExpressReceiveWithData(
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 amount,
bytes data,
bytes32 indexed sendHash,
address expressCaller
);
event ExpressExecutionWithDataFulfilled(
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 amount,
bytes data,
bytes32 indexed sendHash,
address expressCaller
);
event ExpressReceive(bytes payload, bytes32 indexed sendHash, address indexed expressCaller);
event ExpressExecutionFulfilled(bytes payload, bytes32 indexed sendHash, address indexed expressCaller);

/**
* @notice Gets the address of the express caller for a specific token transfer
* @param tokenId The ID of the token being sent
* @param destinationAddress The address of the recipient
* @param amount The amount of tokens to be sent
* @param commandId The unique hash for this token transfer
* @return expressCaller The address of the express caller for this token transfer
*/
function getExpressReceiveToken(
bytes32 tokenId,
address destinationAddress,
uint256 amount,
bytes32 commandId
) external view returns (address expressCaller);

/**
* @notice Gets the address of the express caller for a specific token transfer with data
* @param tokenId The ID of the token being sent
* @param sourceChain The chain from which the token will be sent
* @param sourceAddress The originating address of the token on the source chain
* @param destinationAddress The address of the recipient on the destination chain
* @param amount The amount of tokens to be sent
* @param data The data associated with the token transfer
* @param payload the payload for the receive token
* @param commandId The unique hash for this token transfer
* @return expressCaller The address of the express caller for this token transfer
*/
function getExpressReceiveTokenWithData(
bytes32 tokenId,
string memory sourceChain,
bytes memory sourceAddress,
address destinationAddress,
uint256 amount,
bytes calldata data,
bytes32 commandId
) external view returns (address expressCaller);
function getExpressReceiveToken(bytes calldata payload, bytes32 commandId) external view returns (address expressCaller);
}
57 changes: 25 additions & 32 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

pragma solidity ^0.8.0;

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

import { IExpressCallHandler } from './IExpressCallHandler.sol';
import { ITokenManagerDeployer } from './ITokenManagerDeployer.sol';
import { ITokenManagerType } from './ITokenManagerType.sol';
import { IPausable } from './IPausable.sol';
import { IMulticall } from './IMulticall.sol';
Expand All @@ -29,10 +27,11 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
error InvalidMetadataVersion(uint32 version);
error AlreadyExecuted(bytes32 commandId);
error ExecuteWithTokenNotSupported();
error InvalidExpressSelector();

event TokenSent(bytes32 tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSentWithData(
bytes32 tokenId,
bytes32 indexed tokenId,
string destinationChain,
bytes destinationAddress,
uint256 indexed amount,
Expand Down Expand Up @@ -62,19 +61,19 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
uint8 tokenDecimals,
bytes distributor,
bytes mintTo,
uint256 mintAmount,
uint256 indexed mintAmount,
bytes operator,
string destinationChain,
uint256 indexed gasValue
);
event TokenManagerDeployed(bytes32 indexed tokenId, TokenManagerType indexed tokenManagerType, bytes params);
event StandardizedTokenDeployed(
bytes32 indexed tokenId,
address distributor,
address indexed distributor,
string name,
string symbol,
uint8 decimals,
uint256 mintAmount,
uint256 indexed mintAmount,
address mintTo
);
event CustomTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);
Expand Down Expand Up @@ -229,6 +228,22 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
*/
function getImplementation(uint256 tokenManagerType) external view returns (address tokenManagerAddress);

function interchainTransfer(
bytes32 tokenId,
string calldata destinationChain,
bytes calldata destinationAddress,
uint256 amount,
bytes calldata metadata
) external;

function sendTokenWithData(
bytes32 tokenId,
string calldata destinationChain,
bytes calldata destinationAddress,
uint256 amount,
bytes calldata data
) external;

/**
* @notice Initiates an interchain token transfer. Only callable by TokenManagers
* @param tokenId The tokenId of the token to be transmitted.
Expand Down Expand Up @@ -282,31 +297,9 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
function setPaused(bool paused) external;

/**
* @notice Uses the caller's tokens to fullfill a sendCall ahead of time. Use this only if you have detected an outgoing sendToken that matches the parameters passed here.
* @param tokenId the tokenId of the TokenManager used.
* @param destinationAddress the destinationAddress for the sendToken.
* @param amount the amount of token to give.
* @notice Uses the caller's tokens to fullfill a sendCall ahead of time. Use this only if you have detected an outgoing interchainTransfer that matches the parameters passed here.
* @param payload the payload of the receive token
* @param commandId the commandId calculated from the event at the sourceChain.
*/
function expressReceiveToken(bytes32 tokenId, address destinationAddress, uint256 amount, bytes32 commandId) external;

/**
* @notice Uses the caller's tokens to fullfill a callContractWithInterchainToken ahead of time. Use this only if you have detected an outgoing sendToken that matches the parameters passed here.
* @param tokenId the tokenId of the TokenManager used.
* @param sourceChain the name of the chain where the call came from.
* @param sourceAddress the caller of callContractWithInterchainToken.
* @param destinationAddress the destinationAddress for the sendToken.
* @param amount the amount of token to give.
* @param data the data to be passed to destinationAddress after giving them the tokens specified.
* @param commandId the commandId calculated from the event at the sourceChain.
*/
function expressReceiveTokenWithData(
bytes32 tokenId,
string memory sourceChain,
bytes memory sourceAddress,
address destinationAddress,
uint256 amount,
bytes calldata data,
bytes32 commandId
) external;
function expressReceiveToken(bytes calldata payload, bytes32 commandId, string calldata sourceChain) external;
}
6 changes: 6 additions & 0 deletions contracts/interfaces/INoReEntrancy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ pragma solidity ^0.8.0;
*/
interface INoReEntrancy {
error ReEntrancy();

/**
* @notice Check if the contract is already executing.
* @return entered A boolean representing the entered status. True if already executing, false otherwise.
*/
function hasEntered() external view returns (bool entered);
}
2 changes: 1 addition & 1 deletion contracts/interfaces/IPausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pragma solidity ^0.8.0;
* if a pause condition is activated.
*/
interface IPausable {
event PausedSet(bool paused);
event PausedSet(bool indexed paused);

error Paused();

Expand Down
20 changes: 0 additions & 20 deletions contracts/interfaces/IRemoteAddressValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ interface IRemoteAddressValidator {

event TrustedAddressAdded(string sourceChain, string sourceAddress);
event TrustedAddressRemoved(string sourceChain);
event GatewaySupportedChainAdded(string chain);
event GatewaySupportedChainRemoved(string chain);

/**
* @notice Returns the interchain token address
Expand Down Expand Up @@ -58,22 +56,4 @@ interface IRemoteAddressValidator {
* @return remoteAddress Interchain token service address for the specified chain
*/
function getRemoteAddress(string calldata chainName) external view returns (string memory remoteAddress);

/**
* @notice Returns true if the gateway delivers token to this chain.
* @param chainName Name of the chain
*/
function supportedByGateway(string calldata chainName) external view returns (bool);

/**
* @dev Adds chains that are supported by the Axelar gateway
* @param chainNames List of chain names to be added as supported
*/
function addGatewaySupportedChains(string[] calldata chainNames) external;

/**
* @dev Removes chains that are no longer supported by the Axelar gateway
* @param chainNames List of chain names to be removed as supported
*/
function removeGatewaySupportedChains(string[] calldata chainNames) external;
}
4 changes: 2 additions & 2 deletions contracts/interfaces/IStandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;

import { IInterchainToken } from './IInterchainToken.sol';
import { IDistributable } from './IDistributable.sol';
import { IERC20BurnableMintable } from './IERC20BurnableMintable.sol';
import { IERC20MintableBurnable } from './IERC20MintableBurnable.sol';
import { ITokenManager } from './ITokenManager.sol';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';

Expand All @@ -13,7 +13,7 @@ import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interf
* @notice This contract implements a standardized token which extends InterchainToken functionality.
* This contract also inherits Distributable and Implementation logic.
*/
interface IStandardizedToken is IInterchainToken, IDistributable, IERC20BurnableMintable, IERC20 {
interface IStandardizedToken is IInterchainToken, IDistributable, IERC20MintableBurnable, IERC20 {
/**
* @notice Returns the contract id, which a proxy can check to ensure no false implementation was used.
*/
Expand Down
10 changes: 9 additions & 1 deletion contracts/interfaces/ITokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ITokenManager is ITokenManagerType, IOperatable, IFlowLimit, IImplemen
* @param amount the amount of tokens to take from msg.sender.
* @param metadata any additional data to be sent with the transfer.
*/
function sendToken(
function interchainTransfer(
string calldata destinationChain,
bytes calldata destinationAddress,
uint256 amount,
Expand Down Expand Up @@ -87,6 +87,14 @@ interface ITokenManager is ITokenManagerType, IOperatable, IFlowLimit, IImplemen
*/
function giveToken(address destinationAddress, uint256 amount) external returns (uint256);

/**
* @notice This function takes token to from a specified address. Can only be called by the service.
* @param sourceAddress the address to take tokens from.
* @param amount the amount of token to take.
* @return the amount of token actually taken, which will onle be differen than `amount` in cases where the token takes some on-transfer fee.
*/
function takeToken(address sourceAddress, uint256 amount) external returns (uint256);

/**
* @notice This function sets the flow limit for this TokenManager. Can only be called by the operator.
* @param flowLimit the maximum difference between the tokens flowing in and/or out at any given interval of time (6h)
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ITokenManagerType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pragma solidity ^0.8.0;
*/
interface ITokenManagerType {
enum TokenManagerType {
LOCK_UNLOCK,
MINT_BURN,
MINT_BURN_FROM,
LOCK_UNLOCK,
LOCK_UNLOCK_FEE_ON_TRANSFER,
LIQUIDITY_POOL
}
Expand Down
5 changes: 0 additions & 5 deletions contracts/proxies/TokenManagerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,4 @@ contract TokenManagerProxy is ITokenManagerProxy {
}
}
}

/**
* @dev Receive function which allows this contract to receive ether.
*/
receive() external payable virtual {}
}
Loading

0 comments on commit d6ccbc2

Please sign in to comment.