forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXGasPump.sol
60 lines (49 loc) · 1.96 KB
/
XGasPump.sol
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
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.12;
import { OmniGasPump } from "../token/OmniGasPump.sol";
/**
* @title XGasPump
* @notice Abstract contract that makes it easy to swap ETH for OMNI on Omni.
*/
abstract contract XGasPump {
event Refunded(address indexed recipient, uint256 amtETH, string reason);
event FundedOMNI(address indexed recipient, uint256 ethPaid, uint256 omniReceived);
OmniGasPump public immutable omniGasPump;
constructor(address exchange) {
omniGasPump = OmniGasPump(exchange);
}
/**
* @notice Swap `amtETH` ETH for OMNI on Omni, funding `recipient`.
* Reverts if `amtETH` does not cover xcall fee, or is > max allowed swap.
*/
function fillUp(address recipient, uint256 amtETH) internal {
_fillUp(recipient, amtETH);
}
/**
* @notice Fund `recipient` with `amtETH` worth of OMNI on Omni.
* If `amtETH` is not swappable, refund to `recipient`.
*/
function fillUpOrRefund(address recipient, uint256 amtETH) internal {
_fillUpOrRefund(recipient, recipient, amtETH);
}
/**
* @notice Fund `recipient` with `amtETH` worth of OMNI on Omni.
* If `amtETH` is not swappable, refund to `refundTo`.
*/
function fillUpOrRefund(address refundTo, address recipient, uint256 amtETH) internal {
_fillUpOrRefund(refundTo, recipient, amtETH);
}
function _fillUpOrRefund(address refundTo, address recipient, uint256 amtETH) internal {
(, bool succes, string memory reason) = omniGasPump.dryFillUp(amtETH);
if (!succes) {
emit Refunded(refundTo, amtETH, reason);
payable(refundTo).transfer(amtETH);
return;
}
_fillUp(recipient, amtETH);
}
function _fillUp(address recipient, uint256 amtETH) private {
uint256 amtOMNI = omniGasPump.fillUp{ value: amtETH }(recipient);
emit FundedOMNI(recipient, amtETH, amtOMNI);
}
}