This file contains hidden or 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
#define constant OWNER_SLOT = 0x00 | |
#define constant WITHDRAWER_SLOT = 0x01 | |
#define constant LAST_DEPOSITOR_SLOT = 0x02 | |
#define macro DEPOSIT() = takes(0) returns(0) { | |
callvalue iszero error jumpi // revert if msg.value == 0 | |
caller [LAST_DEPOSITOR_SLOT] sstore // store last depositor | |
stop | |
error: | |
0x00 0x00 revert |
This file contains hidden or 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
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; | |
import "@uniswap/v3-core/contracts/libraries/TickMath.sol"; | |
import "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol"; | |
import "@uniswap/v3-core/contracts/libraries/FullMath.sol"; | |
contract TwapGetter { | |
function getSqrtTwapX96(address uniswapV3Pool, uint32 twapInterval) public view returns (uint160 sqrtPriceX96) { | |
if (twapInterval == 0) { | |
// return the current price if twapInterval == 0 | |
(sqrtPriceX96, , , , , , ) = IUniswapV3Pool(uniswapV3Pool).slot0(); |
This file contains hidden or 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
// contract instance | |
CErc20 immutable cDai; | |
// constructor() { | |
cDaiAddress = 0x6D7F0754FFeb405d23C51CE938289d4835bE3b14; | |
cDai = CErc20(cDaiAddress); | |
// } | |
function swapETHToDaiToCompound() public payable returns(bool){ | |
address[] memory _paths = new address[](2); |
This file contains hidden or 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
function swapETHToDai() public payable returns(uint[] memory) { | |
// static array: address[k] memory array; | |
// The following is the dynamic array way of initialization | |
address[] memory _paths = new address[](2); | |
// Also, push() is for storage array. | |
_paths[0] = WETHAddress; | |
_paths[1] = DaiAddress; | |
return uniswapV2Router01.swapExactETHForTokens{value: msg.value}(0, _paths, msg.sender, now + 120); | |
} |
This file contains hidden or 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
IUniswapV2Router01 immutable uniswapV2Router01; | |
ERC20 immutable Dai; | |
CErc20 immutable cDai; | |
address public WETHAddress; | |
address public DaiAddress; | |
address public cDaiAddress; | |
uint public DaiAmount; | |
uint public ETHAmount; | |
uint[3] public addLiquidityResult; |
This file contains hidden or 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
function addLiquidity() public payable returns(uint[3] memory) { | |
require(msg.value == ETHAmount); | |
require(Dai.transferFrom(msg.sender, address(this), DaiAmount)); | |
// Do remember to approve | |
Dai.approve(address(uniswapV2Router01), DaiAmount); | |
(addLiquidityResult[0], addLiquidityResult[1], addLiquidityResult[2]) = uniswapV2Router01.addLiquidityETH{value: ETHAmount}( | |
DaiAddress, DaiAmount, 0, 0, msg.sender, now + 120); | |
return addLiquidityResult; | |
} |
This file contains hidden or 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
var SellToken = artifacts.require("SellToken"); | |
module.exports = function(deployer) { | |
deployer.deploy(SellToken, "0x7CC3C57cf280961b85920533A49cd62f176ef0E1"); | |
}; |
NewerOlder