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

Add swap token to native, directSend fix #140

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions contracts/message/apps/TransferSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ contract TransferSwap is MessageSenderApp, MessageReceiverApp {
SwapInfo calldata _srcSwap,
SwapInfo calldata _dstSwap,
uint32 _maxBridgeSlippage,
uint64 _nonce
uint64 _nonce,
bool _nativeOut
) external payable onlyEOA {
IERC20(_srcSwap.path[0]).safeTransferFrom(msg.sender, address(this), _amountIn);
_transferWithSwap(
Expand All @@ -122,7 +123,7 @@ contract TransferSwap is MessageSenderApp, MessageReceiverApp {
_dstSwap,
_maxBridgeSlippage,
_nonce,
false,
_nativeOut,
msg.value
);
}
Expand Down Expand Up @@ -169,7 +170,7 @@ contract TransferSwap is MessageSenderApp, MessageReceiverApp {
}

if (_dstChainId == chainId) {
_directSend(_receiver, _amountIn, chainId, _srcSwap, _nonce, srcTokenOut, srcAmtOut);
Copy link

Choose a reason for hiding this comment

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

Speaking spire

_directSend(msg.sender, _amountIn, chainId, _srcSwap, _nonce, srcTokenOut, srcAmtOut);
} else {
_crossChainTransferWithSwap(
_receiver,
Expand Down
16 changes: 9 additions & 7 deletions contracts/pegged/tokens/MultiBridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract MultiBridgeToken is ERC20, Ownable {
}

/**
* @notice Burns tokens from an address. Decreases total amount minted by the calling bridge.
* @notice Burns tokens from an address. Decreases total amount minted if called by a bridge.
* Alternative to {burnFrom} for compatibility with some bridge implementations.
* See {_burnFrom}.
* @param _from The address to burn tokens from.
Expand All @@ -62,7 +62,7 @@ contract MultiBridgeToken is ERC20, Ownable {
}

/**
* @notice Burns tokens from an address. Decreases total amount minted by the calling bridge.
* @notice Burns tokens from an address. Decreases total amount minted if called by a bridge.
* See {_burnFrom}.
* @param _from The address to burn tokens from.
* @param _amount The amount to burn.
Expand All @@ -72,16 +72,18 @@ contract MultiBridgeToken is ERC20, Ownable {
}

/**
* @dev Burns tokens from an address. Decreases total amount minted by the calling bridge.
* @dev Burns tokens from an address, deducting from the caller's allowance. Decreases total amount minted if called
* by a bridge.
* @param _from The address to burn tokens from.
* @param _amount The amount to burn.
*/
function _burnFrom(address _from, uint256 _amount) internal returns (bool) {
Supply storage b = bridges[msg.sender];
require(b.cap > 0, "invalid caller");
require(b.total >= _amount, "exceeds bridge minted amount");
unchecked {
b.total -= _amount;
if (b.cap > 0 || b.total > 0) {
require(b.total >= _amount, "exceeds bridge minted amount");
unchecked {
b.total -= _amount;
}
}
_spendAllowance(_from, msg.sender, _amount);
_burn(_from, _amount);
Expand Down
6 changes: 3 additions & 3 deletions contracts/pegged/tokens/SingleBridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract SingleBridgeToken is ERC20, Ownable {
* @param _from The address to burn tokens from.
* @param _amount The amount to burn.
*/
function burn(address _from, uint256 _amount) external onlyBridge returns (bool) {
function burn(address _from, uint256 _amount) external returns (bool) {
return _burnFrom(_from, _amount);
}

Expand All @@ -66,12 +66,12 @@ contract SingleBridgeToken is ERC20, Ownable {
* @param _from The address to burn tokens from.
* @param _amount The amount to burn.
*/
function burnFrom(address _from, uint256 _amount) external onlyBridge returns (bool) {
function burnFrom(address _from, uint256 _amount) external returns (bool) {
return _burnFrom(_from, _amount);
}

/**
* @dev Burns tokens from an address.
* @dev Burns tokens from an address, deducting from the caller's allowance.
* @param _from The address to burn tokens from.
* @param _amount The amount to burn.
*/
Expand Down