编译器
0.8.21+commit.d9974bed
文件 1 的 6:BaseProxy.sol
pragma solidity ^0.8.0;
import { IProxy } from '../interfaces/IProxy.sol';
abstract contract BaseProxy is IProxy {
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 internal constant _OWNER_SLOT = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0;
function implementation() public view virtual returns (address implementation_) {
assembly {
implementation_ := sload(_IMPLEMENTATION_SLOT)
}
}
function setup(bytes calldata params) external {}
function contractId() internal pure virtual returns (bytes32);
fallback() external payable virtual {
address implementation_ = implementation();
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation_, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable virtual {}
}
文件 2 的 6:IBaseTokenManager.sol
pragma solidity ^0.8.0;
interface IBaseTokenManager {
function interchainTokenId() external view returns (bytes32);
function tokenAddress() external view returns (address);
function getTokenAddressFromParams(bytes calldata params) external pure returns (address);
}
文件 3 的 6:IProxy.sol
pragma solidity ^0.8.0;
interface IProxy {
error InvalidOwner();
error InvalidImplementation();
error SetupFailed();
error NotOwner();
error AlreadyInitialized();
function implementation() external view returns (address);
function setup(bytes calldata setupParams) external;
}
文件 4 的 6:ITokenManagerImplementation.sol
pragma solidity ^0.8.0;
interface ITokenManagerImplementation {
function tokenManagerImplementation(uint256 tokenManagerType) external view returns (address tokenManagerAddress_);
}
文件 5 的 6:ITokenManagerProxy.sol
pragma solidity ^0.8.0;
import { IProxy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IProxy.sol';
interface ITokenManagerProxy is IProxy {
error ZeroAddress();
function implementationType() external view returns (uint256);
function interchainTokenId() external view returns (bytes32);
function tokenAddress() external view returns (address);
function getImplementationTypeAndTokenAddress() external view returns (uint256, address);
}
文件 6 的 6:TokenManagerProxy.sol
pragma solidity ^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';
contract TokenManagerProxy is BaseProxy, ITokenManagerProxy {
bytes32 private constant CONTRACT_ID = keccak256('token-manager');
address public immutable interchainTokenService;
uint256 public immutable implementationType;
bytes32 public immutable interchainTokenId;
address public immutable tokenAddress;
constructor(address interchainTokenService_, uint256 implementationType_, bytes32 tokenId, bytes memory 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);
}
function contractId() internal pure override returns (bytes32) {
return CONTRACT_ID;
}
function getImplementationTypeAndTokenAddress() external view returns (uint256 implementationType_, address tokenAddress_) {
implementationType_ = implementationType;
tokenAddress_ = tokenAddress;
}
function implementation() public view override(BaseProxy, IProxy) returns (address implementation_) {
implementation_ = _tokenManagerImplementation(interchainTokenService, implementationType);
}
function _tokenManagerImplementation(
address interchainTokenService_,
uint256 implementationType_
) internal view returns (address implementation_) {
implementation_ = ITokenManagerImplementation(interchainTokenService_).tokenManagerImplementation(implementationType_);
}
}
{
"compilationTarget": {
"contracts/proxies/TokenManagerProxy.sol": "TokenManagerProxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"interchainTokenService_","type":"address"},{"internalType":"uint256","name":"implementationType_","type":"uint256"},{"internalType":"bytes32","name":"tokenId","type":"bytes32"},{"internalType":"bytes","name":"params","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"InvalidImplementation","type":"error"},{"inputs":[],"name":"InvalidOwner","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"SetupFailed","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"getImplementationTypeAndTokenAddress","outputs":[{"internalType":"uint256","name":"implementationType_","type":"uint256"},{"internalType":"address","name":"tokenAddress_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"implementation_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementationType","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interchainTokenId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interchainTokenService","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"params","type":"bytes"}],"name":"setup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]