// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import { IProxy } from'../interfaces/IProxy.sol';
/**
* @title BaseProxy Contract
* @dev This abstract contract implements a basic proxy that stores an implementation address. Fallback function
* calls are delegated to the implementation. This contract is meant to be inherited by other proxy contracts.
*/abstractcontractBaseProxyisIProxy{
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)bytes32internalconstant _IMPLEMENTATION_SLOT =0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
// keccak256('owner')bytes32internalconstant _OWNER_SLOT =0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
/**
* @dev Returns the current implementation address.
* @return implementation_ The address of the current implementation contract
*/functionimplementation() publicviewvirtualreturns (address implementation_) {
assembly {
implementation_ :=sload(_IMPLEMENTATION_SLOT)
}
}
/**
* @dev Shadows the setup function of the implementation contract so it can't be called directly via the proxy.
* @param params The setup parameters for the implementation contract.
*/functionsetup(bytescalldata params) external{}
/**
* @dev Returns the contract ID. It can be used as a check during upgrades. Meant to be implemented in derived contracts.
* @return bytes32 The contract ID
*/functioncontractId() internalpurevirtualreturns (bytes32);
/**
* @dev Fallback function. Delegates the call to the current implementation contract.
*/fallback() externalpayablevirtual{
address implementation_ = implementation();
assembly {
calldatacopy(0, 0, calldatasize())
let result :=delegatecall(gas(), implementation_, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Payable fallback function. Can be overridden in derived contracts.
*/receive() externalpayablevirtual{}
}
Contract Source Code
File 2 of 6: IBaseTokenManager.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title IBaseTokenManager
* @notice This contract is defines the base token manager interface implemented by all token managers.
*/interfaceIBaseTokenManager{
/**
* @notice A function that returns the token id.
*/functioninterchainTokenId() externalviewreturns (bytes32);
/**
* @notice A function that should return the address of the token.
* Must be overridden in the inheriting contract.
* @return address address of the token.
*/functiontokenAddress() externalviewreturns (address);
/**
* @notice A function that should return the token address from the init params.
*/functiongetTokenAddressFromParams(bytescalldata params) externalpurereturns (address);
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/**
* @title ITokenManagerImplementation Interface
* @notice Interface for returning the token manager implementation type.
*/interfaceITokenManagerImplementation{
/**
* @notice Returns the implementation address for a given token manager type.
* @param tokenManagerType The type of token manager.
* @return tokenManagerAddress_ The address of the token manager implementation.
*/functiontokenManagerImplementation(uint256 tokenManagerType) externalviewreturns (address tokenManagerAddress_);
}
Contract Source Code
File 5 of 6: ITokenManagerProxy.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import { IProxy } from'@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IProxy.sol';
/**
* @title ITokenManagerProxy Interface
* @notice This interface is for a proxy for token manager contracts.
*/interfaceITokenManagerProxyisIProxy{
errorZeroAddress();
/**
* @notice Returns implementation type of this token manager.
* @return uint256 The implementation type of this token manager.
*/functionimplementationType() externalviewreturns (uint256);
/**
* @notice Returns the interchain token ID of the token manager.
* @return bytes32 The interchain token ID of the token manager.
*/functioninterchainTokenId() externalviewreturns (bytes32);
/**
* @notice Returns token address that this token manager manages.
* @return address The token address.
*/functiontokenAddress() externalviewreturns (address);
/**
* @notice Returns implementation type and token address.
* @return uint256 The implementation type.
* @return address The token address.
*/functiongetImplementationTypeAndTokenAddress() externalviewreturns (uint256, address);
}
Contract Source Code
File 6 of 6: TokenManagerProxy.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import { IProxy } from'@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IProxy.sol';
import { BaseProxy } from'@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/BaseProxy.sol';
import { IBaseTokenManager } from'../interfaces/IBaseTokenManager.sol';
import { ITokenManagerProxy } from'../interfaces/ITokenManagerProxy.sol';
import { ITokenManagerImplementation } from'../interfaces/ITokenManagerImplementation.sol';
/**
* @title TokenManagerProxy
* @notice This contract is a proxy for token manager contracts.
* @dev This contract implements BaseProxy and ITokenManagerProxy.
*/contractTokenManagerProxyisBaseProxy, ITokenManagerProxy{
bytes32privateconstant CONTRACT_ID =keccak256('token-manager');
addresspublicimmutable interchainTokenService;
uint256publicimmutable implementationType;
bytes32publicimmutable interchainTokenId;
addresspublicimmutable tokenAddress;
/**
* @notice Constructs the TokenManagerProxy contract.
* @param interchainTokenService_ The address of the interchain token service.
* @param implementationType_ The token manager type.
* @param tokenId The identifier for the token.
* @param params The initialization parameters for the token manager contract.
*/constructor(address interchainTokenService_, uint256 implementationType_, bytes32 tokenId, bytesmemory params) {
if (interchainTokenService_ ==address(0)) revert ZeroAddress();
interchainTokenService = interchainTokenService_;
implementationType = implementationType_;
interchainTokenId = tokenId;
address implementation_ = _tokenManagerImplementation(interchainTokenService_, implementationType_);
if (implementation_ ==address(0)) revert InvalidImplementation();
(bool success, ) = implementation_.delegatecall(abi.encodeWithSelector(IProxy.setup.selector, params));
if (!success) revert SetupFailed();
tokenAddress = IBaseTokenManager(implementation_).getTokenAddressFromParams(params);
}
/**
* @notice Getter for the contract id.
* @return bytes32 The contract id.
*/functioncontractId() internalpureoverridereturns (bytes32) {
return CONTRACT_ID;
}
/**
* @notice Returns implementation type and token address.
* @return implementationType_ The implementation type.
* @return tokenAddress_ The token address.
*/functiongetImplementationTypeAndTokenAddress() externalviewreturns (uint256 implementationType_, address tokenAddress_) {
implementationType_ = implementationType;
tokenAddress_ = tokenAddress;
}
/**
* @notice Returns the address of the current implementation.
* @return implementation_ The address of the current implementation.
*/functionimplementation() publicviewoverride(BaseProxy, IProxy) returns (address implementation_) {
implementation_ = _tokenManagerImplementation(interchainTokenService, implementationType);
}
/**
* @notice Returns the implementation address from the interchain token service for the provided type.
* @param interchainTokenService_ The address of the interchain token service.
* @param implementationType_ The token manager type.
* @return implementation_ The address of the implementation.
*/function_tokenManagerImplementation(address interchainTokenService_,
uint256 implementationType_
) internalviewreturns (address implementation_) {
implementation_ = ITokenManagerImplementation(interchainTokenService_).tokenManagerImplementation(implementationType_);
}
}