Last active
December 6, 2022 12:34
-
-
Save Dan-Nolan/07586c05853acf7f3e21bae26504d7f4 to your computer and use it in GitHub Desktop.
AaveEscrow.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// buyer - puts the funds in the account | |
// arbiter - ability to move the funds | |
// recipient - receiver of the funds | |
// ERC20s common standard for tokens | |
interface IWethGateway { | |
// going to send our ether into the AAVE protocol | |
function depositETH(address lendingPool, address onBehalfOf, uint16 referralCode) external payable; | |
function withdrawETH(address lendingPool, uint256 amount, address to) external; | |
} | |
interface ILendingPool { | |
function getUserAccountData(address user) external view returns ( | |
uint256 totalCollateralETH, | |
uint256 totalDebtETH, | |
uint256 availableBorrowsETH, | |
uint256 currentLiquidationThreshold, | |
uint256 ltv, | |
uint256 healthFactor | |
); | |
} | |
interface IERC20 { | |
function approve(address,uint256) external returns(bool); | |
} | |
contract Escrow { | |
address buyer; | |
address arbiter; | |
address recipient; | |
// remember: constants are NOT storage variables | |
IWethGateway constant gateway = IWethGateway(0xEFFC18fC3b7eb8E676dac549E0c693ad50D1Ce31); | |
address constant lendingPool = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9; | |
IERC20 constant aWETH = IERC20(0x030bA81f1c18d280636F32af80b9AAd02Cf0854e); | |
constructor(address _arbiter, address _recipient) { | |
buyer = msg.sender; | |
arbiter = _arbiter; | |
recipient = _recipient; | |
} | |
receive() external payable { | |
// deposit these funds into AAVE (5 ether) | |
gateway.depositETH{ value: msg.value }(lendingPool, address(this), 0); | |
} | |
// when the transaction is complete | |
function moveFunds() external { | |
require(arbiter == msg.sender); | |
// thank you Georgi!!! :wooohoooo: | |
aWETH.approve(gateway, type(uint).max); | |
gateway.withdrawETH(lendingPool, type(uint).max, recipient); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment