Skip to content

Commit

Permalink
update withdraw methond
Browse files Browse the repository at this point in the history
  • Loading branch information
JoscelynFarr committed Mar 21, 2024
1 parent fd59bb6 commit 9f5175a
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/DegenDealer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@

pragma solidity ^0.8.19;

import "./libraries/EIP712.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract DegenDealer is Ownable {
struct WithdrawInfo {
address account;
uint256 amount;
}

struct PositionInfo {
address trader;
int256 paperAmount;
Expand All @@ -25,10 +18,7 @@ contract DegenDealer is Ownable {
string perp;
}

bytes32 public immutable domainSeparator;
bytes32 public constant WITHDRAW_TYPEHASH = keccak256("Withdraw(address account,uint256 amount)");
address public primaryAsset;
address public operator;

using SafeERC20 for IERC20;

Expand All @@ -40,26 +30,16 @@ contract DegenDealer is Ownable {

constructor(address _primaryAsset) {
primaryAsset = _primaryAsset;
domainSeparator = EIP712._buildDomainSeparator("JOJODegen", "1", address(this));
}

function deposit(address account, uint256 amount) external {
IERC20(primaryAsset).safeTransferFrom(msg.sender, address(this), amount);
emit DegenDeposit(account, amount);
}

function withdraw(WithdrawInfo memory withdrawInfo, bytes memory signature) external {
bytes32 hashStruct = keccak256(abi.encode(WITHDRAW_TYPEHASH, withdrawInfo.account, withdrawInfo.amount));
bytes32 withdrawHash = EIP712._hashTypedDataV4(domainSeparator, hashStruct);
(address recoverSigner,) = ECDSA.tryRecover(withdrawHash, signature);
require(recoverSigner == operator, "INVALID_ORDER_SIGNATURE");
require(withdrawInfo.account == msg.sender);
IERC20(primaryAsset).safeTransfer(msg.sender, withdrawInfo.amount);
emit DegenWithdraw(msg.sender, withdrawInfo.amount);
}

function updateGlobalOperator(address newOperator) public onlyOwner {
operator = newOperator;
function withdraw(address account, uint256 amount) external onlyOwner {
IERC20(primaryAsset).safeTransfer(account, amount);
emit DegenWithdraw(account, amount);
}

function batchUpdatePosition(PositionInfo[] memory positionDatas) public onlyOwner {
Expand Down

0 comments on commit 9f5175a

Please sign in to comment.