Badger OTC vs General OTC

Created Diff never expires
54 Entfernungen
Zeilen
Gesamt
Entfernt
Wörter
Gesamt
Entfernt
Um diese Funktion weiterhin zu nutzen, aktualisieren Sie auf
Diffchecker logo
Diffchecker Pro
74 Zeilen
46 Hinzufügungen
Zeilen
Gesamt
Hinzugefügt
Wörter
Gesamt
Hinzugefügt
Um diese Funktion weiterhin zu nutzen, aktualisieren Sie auf
Diffchecker logo
Diffchecker Pro
68 Zeilen
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.6.8;


import "deps/@openzeppelin/contracts/token/ERC20/IERC20.sol";
// SPDX-License-Identifier: GPL-3.0-or-later
import "deps/@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
pragma solidity ^0.8.4;
import "deps/@openzeppelin/contracts/math/SafeMath.sol";

import "deps/@openzeppelin/contracts/token/ERC20/TokenTimelock.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";


/*
/*
Simple OTC Escrow contract to transfer vested bBadger in exchange for specified USDC amount
Simple OTC Escrow contract to transfer tokens OTC
Inspired and forked from BadgerDAO
https://github.com/Badger-Finance/badger-system/blob/develop/contracts/badger-timelock/OtcEscrow.sol
*/
*/
contract OtcEscrow {
contract OtcEscrow {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using SafeERC20 for IERC20;


address constant usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address public receivedToken;
address constant bBadger = 0x19D97D8fA813EE2f51aD4B4e04EA08bAf4DFfC28;
address public sentToken;
address constant badgerGovernance = 0xB65cef03b9B89f99517643226d76e286ee999e77;
address public recipient;

event VestingDeployed(address vesting);


address public beneficiary;
address public beneficiary;
uint256 public duration;
uint256 public receivedAmount;
uint256 public usdcAmount;
uint256 public sentAmount;
uint256 public bBadgerAmount;


constructor(
constructor(
address beneficiary_,
address beneficiary_,
uint256 duration_,
address recipient_,
uint256 usdcAmount_,
address receivedToken_,
uint256 bBadgerAmount_
address sentToken_,
) public {
uint256 receivedAmount_,
uint256 sentAmount_
) {
beneficiary = beneficiary_;
beneficiary = beneficiary_;
duration = duration_;
recipient = recipient_;
usdcAmount = usdcAmount_;

bBadgerAmount = bBadgerAmount_;
receivedToken = receivedToken_;
sentToken = sentToken_;

receivedAmount = receivedAmount_;
sentAmount = sentAmount_;
}
}


modifier onlyApprovedParties() {
modifier onlyApprovedParties() {
require(msg.sender == badgerGovernance || msg.sender == beneficiary);
require(msg.sender == recipient || msg.sender == beneficiary);
_;
_;
}
}


/// @dev Atomically trade specified amonut of USDC for control over bBadger in vesting contract
/// @dev Atomically trade specified amount of receivedToken for control over sentToken in vesting contract
/// @dev Either counterparty may execute swap if sufficient token approval is given by recipient
/// @dev Either counterparty may execute swap if sufficient token approval is given by recipient
function swap() public onlyApprovedParties {
function swap() public onlyApprovedParties {
// Transfer expected USDC from beneficiary
// Transfer expected receivedToken from beneficiary
IERC20(usdc).safeTransferFrom(beneficiary, address(this), usdcAmount);
IERC20(receivedToken).safeTransferFrom(beneficiary, recipient, receivedAmount);

// Create Vesting contract
TokenTimelock vesting = new TokenTimelock(IERC20(bBadger), beneficiary, now + duration);

// Transfer bBadger to vesting contract
IERC20(bBadger).safeTransfer(address(vesting), bBadgerAmount);

// Transfer USDC to badger governance
IERC20(usdc).safeTransfer(badgerGovernance, usdcAmount);


emit VestingDeployed(address(vesting));
// Transfer sentToken to beneficiary
IERC20(sentToken).safeTransfer(address(beneficiary), sentAmount);
}
}


/// @dev Return bBadger to Badger Governance to revoke escrow deal
/// @dev Return sentToken to Fei Protocol to revoke escrow deal
function revoke() external {
function revoke() external {
require(msg.sender == badgerGovernance, "onlyBadgerGovernance");
require(msg.sender == recipient, "onlyRecipient");
uint256 bBadgerBalance = IERC20(bBadger).balanceOf(address(this));
uint256 sentTokenBalance = IERC20(sentToken).balanceOf(address(this));
IERC20(bBadger).safeTransfer(badgerGovernance, bBadgerBalance);
IERC20(sentToken).safeTransfer(recipient, sentTokenBalance);
}
}


function revokeUsdc() external onlyApprovedParties {
function revokeReceivedToken() external onlyApprovedParties {
uint256 usdcBalance = IERC20(usdc).balanceOf(address(this));
uint256 receivedTokenBalance = IERC20(receivedToken).balanceOf(address(this));
IERC20(usdc).safeTransfer(beneficiary, usdcBalance);
IERC20(receivedToken).safeTransfer(beneficiary, receivedTokenBalance);
}
}
}
}