Skip to content

Commit

Permalink
Fix (L-02): calculateSwap in LockingProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Feb 28, 2024
1 parent fe200d3 commit 1af7853
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ abstract contract AbstractProcessor is IDefaultPool {
uint256 dx
)
external
pure
view
virtual
returns (uint256 amountOut)
{
// InterchainToken (0) -> UnderlyingToken (1)
Expand Down
27 changes: 27 additions & 0 deletions packages/contracts-interchain/src/processors/LockingProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeE
contract LockingProcessor is AbstractProcessor {
using SafeERC20 for IERC20;

/// @inheritdoc AbstractProcessor
function calculateSwap(
uint8 tokenIndexFrom,
uint8 tokenIndexTo,
uint256 dx
)
external
view
override
returns (uint256 amountOut)
{
// InterchainToken (0) -> UnderlyingToken (1)
if (tokenIndexFrom == 0 && tokenIndexTo == 1) {
// Check that amount does not exceed the processor balance of the UnderlyingToken
if (dx > IERC20(UNDERLYING_TOKEN).balanceOf(address(this))) {
return 0;
}
return dx;
}
// UnderlyingToken (1) -> InterchainToken (0)
if (tokenIndexFrom == 1 && tokenIndexTo == 0) {
return dx;
}
// Return 0 for unsupported operations
return 0;
}

/// @dev Burns the ICERC20 token taken from `msg.sender`, then
/// unlocks the same amount of the underlying token to `msg.sender`.
function _burnInterchainToken(uint256 amount) internal override {
Expand Down

0 comments on commit 1af7853

Please sign in to comment.