forked from TotlePlatform/defiat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefiat.sol
More file actions
82 lines (82 loc) · 2.22 KB
/
Defiat.sol
File metadata and controls
82 lines (82 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pragma solidity 0.5.1;
pragma experimental ABIEncoderV2;
/**
* @title Defiat
* @dev
*/
library TotlePrimaryUtils {
struct Order {
address payable exchangeHandler;
bytes encodedPayload;
}
struct Trade {
address sourceToken;
address destinationToken;
uint256 amount;
bool isSourceAmount; //true if amount is sourceToken, false if it's destinationToken
Order[] orders;
}
struct Swap {
Trade[] trades;
uint256 minimumExchangeRate;
uint256 minimumDestinationAmount;
uint256 sourceAmount;
uint256 tradeToTakeFeeFrom;
bool takeFeeFromSource; //Takes the fee before the trade if true, takes it after if false
address payable redirectAddress;
bool required;
}
struct SwapCollection {
Swap[] swaps;
address payable partnerContract;
uint256 expirationBlock;
bytes32 id;
uint256 maxGasPrice;
uint8 v;
bytes32 r;
bytes32 s;
}
}
interface TotlePrimary {
function performSwapCollection(
TotlePrimaryUtils.SwapCollection calldata swaps
) external payable;
}
contract Defiat {
address payable private admin;
address payable private owner;
bool private canceled;
constructor(address payable user) public {
admin = msg.sender;
owner = user;
}
modifier only(address _user) {
require(msg.sender == _user);
_;
}
modifier active() {
require(canceled == false);
_;
}
function swap(TotlePrimaryUtils.SwapCollection memory swapCollection, TotlePrimary primary) public active() only(admin) {
uint256 balance = address(this).balance;
require(balance > 0);
primary.performSwapCollection.value(balance)(swapCollection);
selfdestruct(owner);
}
function cancel() public only(owner) {
canceled = true;
if (address(this).balance > 0) {
owner.transfer(address(this).balance);
}
}
function destroy() public only(admin) {
selfdestruct(owner);
}
function () payable external {
if (canceled) {
owner.transfer(msg.value);
selfdestruct(owner);
}
}
}