Skip to content

Commit

Permalink
add interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JoscelynFarr committed Apr 12, 2024
1 parent 14ce8c5 commit 2fbfc94
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/JUSDRepayHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ contract JUSDRepayHelper is Ownable {
// add buffer JUSD
require(balance <= borrowed + buffer, "repayed jusd too much");
IJUSDBank(JusdBank).repay(balance, to);
IERC20(JUSD).safeTransfer(JusdBank.insurance(), balance - borrowed);
if (balance > borrowed) {
IERC20(JUSD).safeTransfer(JusdBank.insurance(), balance - borrowed);
}
emit HelpToTransfer(from, to, balance);
}
}
3 changes: 3 additions & 0 deletions src/support/FlattenHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import "../support/TestMarkPriceSource.sol";
import "../support/MockSwap.sol";
import "../support/TestVolatilePriceSource.sol";
import "./TestERC20.sol";
import "./help/IMessageHandler.sol";
import "./help/IMessageTransmitter.sol";
import "./help/ITokenMinter.sol";

// DO NOT REMOVE
abstract contract ContractForCodeGeneration {
Expand Down
36 changes: 36 additions & 0 deletions src/support/help/IMessageHandler.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022, Circle Internet Financial Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
/**
* @title IMessageHandler
* @notice Handles messages on destination domain forwarded from
* an IReceiver
*/
interface IMessageHandler {
/**
* @notice handles an incoming message from a Receiver
* @param sourceDomain the source domain of the message
* @param sender the sender of the message
* @param messageBody The message raw bytes
* @return success bool, true if successful
*/
function handleReceiveMessage(
uint32 sourceDomain,
bytes32 sender,
bytes calldata messageBody
) external returns (bool);
}
26 changes: 26 additions & 0 deletions src/support/help/IMessageTransmitter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022, Circle Internet Financial Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;

import "./IRelayer.sol";
import "./IReceiver.sol";

/**
* @title IMessageTransmitter
* @notice Interface for message transmitters, which both relay and receive messages.
*/
interface IMessageTransmitter is IRelayer, IReceiver { }
33 changes: 33 additions & 0 deletions src/support/help/IReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022, Circle Internet Financial Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
/**
* @title IReceiver
* @notice Receives messages on destination chain and forwards them to IMessageDestinationHandler
*/
interface IReceiver {
/**
* @notice Receives an incoming message, validating the header and passing
* the body to application-specific handler.
* @param message The message raw bytes
* @param signature The message signature
* @return success bool, true if successful
*/
function receiveMessage(bytes calldata message, bytes calldata signature)
external
returns (bool success);
}
72 changes: 72 additions & 0 deletions src/support/help/IRelayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2022, Circle Internet Financial Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
/**
* @title IRelayer
* @notice Sends messages from source domain to destination domain
*/
interface IRelayer {
/**
* @notice Sends an outgoing message from the source domain.
* @dev Increment nonce, format the message, and emit `MessageSent` event with message information.
* @param destinationDomain Domain of destination chain
* @param recipient Address of message recipient on destination domain as bytes32
* @param messageBody Raw bytes content of message
* @return nonce reserved by message
*/
function sendMessage(
uint32 destinationDomain,
bytes32 recipient,
bytes calldata messageBody
) external returns (uint64);

/**
* @notice Sends an outgoing message from the source domain, with a specified caller on the
* destination domain.
* @dev Increment nonce, format the message, and emit `MessageSent` event with message information.
* WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible
* to broadcast the message on the destination domain. This is an advanced feature, and the standard
* sendMessage() should be preferred for use cases where a specific destination caller is not required.
* @param destinationDomain Domain of destination chain
* @param recipient Address of message recipient on destination domain as bytes32
* @param destinationCaller caller on the destination domain, as bytes32
* @param messageBody Raw bytes content of message
* @return nonce reserved by message
*/
function sendMessageWithCaller(
uint32 destinationDomain,
bytes32 recipient,
bytes32 destinationCaller,
bytes calldata messageBody
) external returns (uint64);

/**
* @notice Replace a message with a new message body and/or destination caller.
* @dev The `originalAttestation` must be a valid attestation of `originalMessage`.
* @param originalMessage original message to replace
* @param originalAttestation attestation of `originalMessage`
* @param newMessageBody new message body of replaced message
* @param newDestinationCaller the new destination caller
*/
function replaceMessage(
bytes calldata originalMessage,
bytes calldata originalAttestation,
bytes calldata newMessageBody,
bytes32 newDestinationCaller
) external;
}
56 changes: 56 additions & 0 deletions src/support/help/ITokenMinter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @title ITokenMinter
* @notice interface for minter of tokens that are mintable, burnable, and interchangeable
* across domains.
*/
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.19;
interface ITokenMinter {
/**
* @notice Mints `amount` of local tokens corresponding to the
* given (`sourceDomain`, `burnToken`) pair, to `to` address.
* @dev reverts if the (`sourceDomain`, `burnToken`) pair does not
* map to a nonzero local token address. This mapping can be queried using
* getLocalToken().
* @param sourceDomain Source domain where `burnToken` was burned.
* @param burnToken Burned token address as bytes32.
* @param to Address to receive minted tokens, corresponding to `burnToken`,
* on this domain.
* @param amount Amount of tokens to mint. Must be less than or equal
* to the minterAllowance of this TokenMinter for given `_mintToken`.
* @return mintToken token minted.
*/
function mint(
uint32 sourceDomain,
bytes32 burnToken,
address to,
uint256 amount
) external returns (address mintToken);

/**
* @notice Burn tokens owned by this ITokenMinter.
* @param burnToken burnable token.
* @param amount amount of tokens to burn. Must be less than or equal to this ITokenMinter's
* account balance of the given `_burnToken`.
*/
function burn(address burnToken, uint256 amount) external;

/**
* @notice Get the local token associated with the given remote domain and token.
* @param remoteDomain Remote domain
* @param remoteToken Remote token
* @return local token address
*/
function getLocalToken(uint32 remoteDomain, bytes32 remoteToken)
external
view
returns (address);

/**
* @notice Set the token controller of this ITokenMinter. Token controller
* is responsible for mapping local tokens to remote tokens, and managing
* token-specific limits
* @param newTokenController new token controller address
*/
function setTokenController(address newTokenController) external;
}

0 comments on commit 2fbfc94

Please sign in to comment.