-
-
Save yaronvel/4137f4e6e4b242d17f6350b912bfc456 to your computer and use it in GitHub Desktop.
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
pragma solidity >=0.5.12; | |
interface CatLike { | |
function bite(bytes32 ilk, address urn) external; | |
} | |
interface VatLike { | |
function urns(bytes32 ilk, address u) external view returns (uint ink, uint art); | |
} | |
contract BiteRebate { | |
address vat; | |
// TODO - read from regitery | |
address cat; | |
// TODO - make configurable, and also use dai instead of art | |
uint public maxArtForRebate = 1500e18; // a bit more than 1500 dai | |
// TODO - make configurable, and also use dai instead of art | |
uint public minArtForRebate = 200e18; // a bit more than 200 dai | |
// TODO - make configurable | |
uint fixedRebateInEth = 0.01 ether; | |
// TODO - make configurable | |
uint gasCostNum = 2; | |
uint gasCostDen = 3; | |
constructor(address _vat, address _cat) public { | |
vat = _vat; | |
cat = _cat; | |
} | |
// TODO - let DAO withdraw remaining ETH | |
function deposit() public payable {} | |
function biteWithRebate(bytes32 ilk, address urn) external { | |
uint gasLeftBefore = gasleft(); | |
(, uint art) = VatLike(vat).urns(ilk, urn); | |
require(art >= minArtForRebate, "urn-too-small"); | |
require(art <= maxArtForRebate, "urn-too-big"); | |
CatLike(cat).bite(ilk, urn); | |
uint gasLeftAfter = gasleft(); | |
// consider having a cap on gas cost to avoid attacks with gas token burning | |
uint gasCost = (gasLeftBefore - gasLeftAfter) * tx.gasprice; | |
// TODO - send dai instead of ETH ? | |
(bool succ, ) = msg.sender.call.value(gasCost * gasCostNum / gasCostDen + fixedRebateInEth)(""); | |
require(succ, "eth-transfer-failed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment