Skip to content

Commit

Permalink
Merge pull request iotubeproject#276 from iotubeproject/unwrapper_for…
Browse files Browse the repository at this point in the history
…_usdc

usdc unwrapper
  • Loading branch information
CoderZhi authored Nov 7, 2024
2 parents d7bdde5 + 629f38e commit 43e03f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
File renamed without changes.
37 changes: 37 additions & 0 deletions contracts/USDCUnwrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity = 0.8.20;

interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
}

interface ISwapper {
function usdc_e() external view returns (address);
function iousdc() external view returns (address);

function deposit(uint256 _amount) external;
}

contract USDCUnwrapper {
IERC20 public iousdc;
IERC20 public usdc_e;
ISwapper public swapper;

constructor(ISwapper _swapper) {
swapper = _swapper;
iousdc = IERC20(_swapper.iousdc());
usdc_e = IERC20(_swapper.usdc_e());
}

function onReceive(address _sender, address _token, uint256 _amount, bytes calldata _payload) external {
require(_token == address(iousdc), "USDCUnwrapper: invalid token");
address recipient = _sender;
if (_payload.length == 32) {
(recipient) = abi.decode(_payload, (address));
}
require(iousdc.approve(address(swapper), _amount), "USDCUnwrapper: approve failed");
swapper.deposit(_amount);
require(usdc_e.transfer(recipient, _amount), "USDCUnwrapper: transfer failed");
}
}

0 comments on commit 43e03f9

Please sign in to comment.