Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: more method and event renaming #143

Merged
merged 12 commits into from
Nov 3, 2023
172 changes: 99 additions & 73 deletions contracts/interchain-token-service/InterchainTokenService.sol

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,53 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
error TokenManagerDoesNotExist(bytes32 tokenId);
error NotTokenManager(address caller, address tokenManager);
error ExecuteWithInterchainTokenFailed(address contractAddress);
error InvalidCanonicalTokenId(bytes32 expectedCanonicalTokenId);
error ExpressExecuteWithInterchainTokenFailed(address contractAddress);
error GatewayToken();
error TokenManagerDeploymentFailed(bytes error);
error InterchainTokenDeploymentFailed(bytes error);
error SelectorUnknown(uint256 selector);
error InvalidMessageType(uint256 messageType);
error InvalidMetadataVersion(uint32 version);
error ExecuteWithTokenNotSupported();
error UntrustedChain(string chainName);
error InvalidExpressSelector(uint256 selector);
error InvalidExpressMessageType(uint256 messageType);

event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSentWithData(
event InterchainTransfer(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event InterchainTransferWithData(
bytes32 indexed tokenId,
string destinationChain,
bytes destinationAddress,
uint256 indexed amount,
address indexed sourceAddress,
bytes data
);
event TokenReceived(
event InterchainTransferReceived(
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 indexed amount
);
event TokenReceivedWithData(
event InterchainTransferReceivedWithData(
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 indexed amount
);
event RemoteTokenManagerDeploymentInitialized(
event TokenManagerDeploymentStarted(
bytes32 indexed tokenId,
string destinationChain,
uint256 indexed gasValue,
TokenManagerType indexed tokenManagerType,
bytes params
);
event RemoteInterchainTokenDeploymentInitialized(
event InterchainTokenDeploymentStarted(
bytes32 indexed tokenId,
string tokenName,
string tokenSymbol,
uint8 tokenDecimals,
bytes distributor,
bytes operator,
string destinationChain,
uint256 indexed gasValue
string destinationChain
);
event TokenManagerDeployed(bytes32 indexed tokenId, address tokenManager, TokenManagerType indexed tokenManagerType, bytes params);
event InterchainTokenDeployed(
Expand All @@ -78,8 +75,7 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
string symbol,
uint8 decimals
);
event CustomTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);
event PausedSet(bool indexed paused, address indexed msgSender);
event InterchainTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);

/**
* @notice Returns the address of the interchain router contract.
Expand Down Expand Up @@ -187,7 +183,7 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
bytes calldata metadata
) external payable;

function sendTokenWithData(
function callContractWithInterchainToken(
bytes32 tokenId,
string calldata destinationChain,
bytes calldata destinationAddress,
Expand All @@ -204,7 +200,7 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
* @param amount The amount of tokens to transmit.
* @param metadata The metadata associated with the transmission.
*/
function transmitSendToken(
function transmitInterchainTransfer(
bytes32 tokenId,
address sourceAddress,
string calldata destinationChain,
Expand Down Expand Up @@ -242,8 +238,8 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
function flowInAmount(bytes32 tokenId) external view returns (uint256 flowInAmount_);

/**
* @notice Sets the paused state of the contract.
* @param paused The boolean value indicating whether the contract is paused or not.
* @notice Allows the owner to pause/unpause the token service.
* @param paused whether to pause or unpause.
*/
function setPaused(bool paused) external;
function setPauseStatus(bool paused) external;
}
37 changes: 27 additions & 10 deletions contracts/token-manager/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
*/
constructor(address interchainTokenService_) {
if (interchainTokenService_ == address(0)) revert TokenLinkerZeroAddress();

interchainTokenService = IInterchainTokenService(interchainTokenService_);
}

Expand Down Expand Up @@ -75,18 +76,23 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
*/
function setup(bytes calldata params) external override onlyProxy {
bytes memory operatorBytes = abi.decode(params, (bytes));
address operator_;
address operator;

/**
* @dev Specifying an empty operator will default to the service being the operator. This makes it easy to deploy
* remote standardized tokens without knowing anything about the service address at the destination.
*/
if (operatorBytes.length == 0) {
operator_ = address(interchainTokenService);
operator = address(interchainTokenService);
} else {
operator_ = operatorBytes.toAddress();
operator = operatorBytes.toAddress();

// Add flow limiter role to the service by default. The operator can remove this if they so choose.
_addAccountRoles(address(interchainTokenService), 1 << uint8(Roles.FLOW_LIMITER));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the service by default to support operations

}

_addAccountRoles(operator_, (1 << uint8(Roles.FLOW_LIMITER)) | (1 << uint8(Roles.OPERATOR)));
_addAccountRoles(operator, (1 << uint8(Roles.FLOW_LIMITER)) | (1 << uint8(Roles.OPERATOR)));

_setup(params);
}

Expand All @@ -106,9 +112,11 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
address sender = msg.sender;

amount = _takeToken(sender, amount);

// rate limit the outgoing amount to destination
_addFlowOut(amount);

interchainTokenService.transmitSendToken{ value: msg.value }(
interchainTokenService.transmitInterchainTransfer{ value: msg.value }(
interchainTokenId(),
sender,
destinationChain,
Expand All @@ -132,10 +140,14 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
bytes calldata data
) external payable virtual {
address sender = msg.sender;

amount = _takeToken(sender, amount);

// rate limit the outgoing amount to destination
_addFlowOut(amount);

uint32 version = 0;
interchainTokenService.transmitSendToken{ value: msg.value }(
interchainTokenService.transmitInterchainTransfer{ value: msg.value }(
interchainTokenId(),
sender,
destinationChain,
Expand All @@ -161,8 +173,11 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
bytes calldata metadata
) external payable virtual onlyToken {
amount = _takeToken(sender, amount);

// rate limit the outgoing amount to destination
_addFlowOut(amount);
interchainTokenService.transmitSendToken{ value: msg.value }(

interchainTokenService.transmitInterchainTransfer{ value: msg.value }(
interchainTokenId(),
sender,
destinationChain,
Expand All @@ -179,6 +194,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
* @return the amount of token actually given, which will only be different than `amount` in cases where the token takes some on-transfer fee.
*/
function giveToken(address destinationAddress, uint256 amount) external onlyService returns (uint256) {
// rate limit the incoming amount from source
_addFlowIn(amount);
amount = _giveToken(destinationAddress, amount);
return amount;
Expand All @@ -191,8 +207,9 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
* @return the amount of token actually given, which will onle be differen than `amount` in cases where the token takes some on-transfer fee.
*/
function takeToken(address sourceAddress, uint256 amount) external onlyService returns (uint256) {
_addFlowOut(amount);
amount = _takeToken(sourceAddress, amount);
// rate limit the outgoing amount to destination
_addFlowOut(amount);
return amount;
}

Expand All @@ -209,8 +226,8 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
}

/**
* @notice This function adds a flow limiter for this TokenManager. Can only be called by the operator.
* @param flowLimiter the address of the new flow limiter.
* @notice This function removes a flow limiter for this TokenManager. Can only be called by the operator.
* @param flowLimiter the address of an existing flow limiter.
*/
function removeFlowLimiter(address flowLimiter) external onlyRole(uint8(Roles.OPERATOR)) {
if (flowLimiter == address(0)) revert ZeroAddress();
Expand Down
Loading
Loading