Skip to content

Commit

Permalink
Merge branch 'main' of github.com:JOJOexchange/smart-contract-EVM
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyjojoex committed Apr 23, 2024
2 parents c7dde5e + eea1101 commit 84f992a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
69 changes: 69 additions & 0 deletions src/DepositStableCoinToDegenDealer.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 84f992a

Please sign in to comment.