diff --git a/README.md b/README.md index 619c598..83e6571 100644 --- a/README.md +++ b/README.md @@ -170,12 +170,7 @@ Two lending system examples include: ## Funding Rate Arbitrage -The core contract [FundingRateArbitrage](./src/FundingRateArbitrage.sol) involves offsetting trades in both spot and perpetual markets to capture funding rate income in perpetual trading. - -Key functions: - -- LPs can deposit USDC into the arbitrage pool via the deposit function, earning interest. Withdrawal requests for both interest and capital can be made by users, executed within 24 hours through permitWithdrawRequests. -- Upon users depositing USDC into the arbitrage pool, the admin utilizes the USDC to purchase ETH and deposits it into the JUSDBank system via the swapBuyEth function. Subsequently, the admin borrows JUSD using borrow and deposits it into the trading system. Finally, the admin initiates short interest in the trading system to accumulate funding fees. +Comming soon ## Other Components diff --git a/src/DepositStableCoinToDegenDealer.sol b/src/DepositStableCoinToDegenDealer.sol new file mode 100644 index 0000000..39f08ce --- /dev/null +++ b/src/DepositStableCoinToDegenDealer.sol @@ -0,0 +1,69 @@ +/* + Copyright 2022 JOJO Exchange + SPDX-License-Identifier: BUSL-1.1 +*/ +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import "./DegenDealer.sol"; + +interface IWETH { + function deposit() external payable; +} + +contract DepositStableCoinToDegenDealer is Ownable { + using SafeERC20 for IERC20; + + address public immutable degenDealer; + address public immutable usdc; + address public immutable weth; + mapping(address => bool) public whiteListContract; + + constructor(address _degenDealer, address _weth) { + degenDealer = _degenDealer; + usdc = DegenDealer(degenDealer).primaryAsset(); + weth = _weth; + } + + function setWhiteListContract(address targetContract, bool isValid) public onlyOwner { + whiteListContract[targetContract] = isValid; + } + + function depositStableCoin( + address asset, + uint256 amount, + address to, + bytes calldata param, + uint256 minReceive + ) + external + payable + { + if (asset == weth && msg.value == amount) { + IWETH(weth).deposit{ value: amount }(); + } else { + IERC20(asset).safeTransferFrom(msg.sender, address(this), amount); + } + (address approveTarget, address swapTarget, bytes memory data) = abi.decode(param, (address, address, bytes)); + require(whiteListContract[approveTarget], "approve target is not in the whitelist"); + require(whiteListContract[swapTarget], "swap target is not in the whitelist"); + // if usdt + IERC20(asset).safeApprove(approveTarget, 0); + IERC20(asset).safeApprove(approveTarget, amount); + (bool success,) = swapTarget.call(data); + if (success == false) { + assembly { + let ptr := mload(0x40) + let size := returndatasize() + returndatacopy(ptr, 0, size) + revert(ptr, size) + } + } + + uint256 usdcAmount = IERC20(usdc).balanceOf(address(this)); + require(usdcAmount >= minReceive, "receive amount is too small"); + IERC20(usdc).approve(degenDealer, usdcAmount); + DegenDealer(degenDealer).deposit(msg.sender, to, usdcAmount); + } +}