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
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 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 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 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 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 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"); | |
}; |
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
import ERC20 as ERC20 | |
owner: public(address) | |
tokenAddress: public(address) | |
erc20: ERC20 | |
@public | |
def __init__(_tokenAddress: address): | |
self.owner = msg.sender | |
self.tokenAddress = _tokenAddress |
NewerOlder