-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaucet.sol
82 lines (55 loc) · 1.94 KB
/
Faucet.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
/**************************************
:: Interface BenQi Asset ::
**************************************/
interface IAsset {
function decimals() external view returns (uint256);
function allocateTo(address, uint256) external;
}
/**************************************
:: Contract BenQi Faucet ::
**************************************/
contract Faucet {
// constants
address constant internal USDC = 0x45ea5d57BA80B5e3b0Ed502e9a08d568c96278F9;
address constant internal WETH = 0x4f5003fd2234Df46FB2eE1531C89b8bdcc372255;
address constant internal WBTC = 0x385104afA0BfdAc5A2BcE2E3fae97e96D1CB9160;
address constant internal LINK = 0x8913a950A5fBF2832B88B9F1e4D0EeBd5281Ac10;
// BenQi markets
mapping (string => address) public markets;
// events
event Used(address market, address sender, uint256 amount);
// errors
error InvalidMarket(string market);
/**************************************
Constructor
**************************************/
constructor() {
// init markets
markets["USDC"] = USDC;
markets["WETH"] = WETH;
markets["WBTC"] = WBTC;
markets["LINK"] = LINK;
}
/**************************************
Use faucet
**************************************/
function use(
string memory _market,
uint256 _amount
) external {
// retrieve market address from name
address market_ = markets[_market];
if (market_ == address(0x0)) {
// revert for unsupported market
revert InvalidMarket(_market);
}
// get decimals
uint256 decimals_ = IAsset(market_).decimals();
// mint
IAsset(market_).allocateTo(msg.sender, _amount * (10 ** decimals_));
// event
emit Used(market_, address(msg.sender), _amount);
}
}