-
Notifications
You must be signed in to change notification settings - Fork 3
/
CurrencyOSV2.sol
executable file
·170 lines (147 loc) · 4.73 KB
/
CurrencyOSV2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
pragma solidity 0.8.4;
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* Written by 0xMotoko (0xmotoko@pm.me)
* Copyright (C) 2021 Yamato Protocol (DeFiGeek Community Japan)
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
import "./Interfaces/ICurrency.sol";
import "./Interfaces/ICurrencyOS.sol";
import "./Interfaces/IYMT.sol";
import "./veYMT.sol";
import "./Interfaces/IYamatoV3.sol";
import "./YmtOS.sol";
import "./Dependencies/UUPSBase.sol";
import "hardhat/console.sol";
contract CurrencyOSV2 is ICurrencyOS, UUPSBase {
string constant CURRENCY_SLOT_ID = "deps.Currency";
string constant PRICEFEED_SLOT_ID = "deps.PriceFeed";
string constant FEEPOOL_SLOT_ID = "deps.FeePool";
string constant YMTOS_SLOT_ID = "deps.YmtOS";
/*
===========================
!!! DANGER ZONE BEGINS !!!
===========================
*/
address[] public yamatoes;
/*
===========================
!!! DANGER ZONE ENDED !!!
===========================
*/
event YamatoAdded(address _yamatoAddr);
function initialize(
address currencyAddr,
address feedAddr,
address feePoolAddr
) public initializer {
__UUPSBase_init();
bytes32 CURRENCY_KEY = bytes32(keccak256(abi.encode(CURRENCY_SLOT_ID)));
bytes32 PRICEFEED_KEY = bytes32(
keccak256(abi.encode(PRICEFEED_SLOT_ID))
);
bytes32 FEEPOOL_KEY = bytes32(keccak256(abi.encode(FEEPOOL_SLOT_ID)));
assembly {
sstore(CURRENCY_KEY, currencyAddr)
sstore(PRICEFEED_KEY, feedAddr)
sstore(FEEPOOL_KEY, feePoolAddr)
}
}
function setPriceFeed(address feedAddr) external onlyGovernance {
bytes32 PRICEFEED_KEY = bytes32(
keccak256(abi.encode(PRICEFEED_SLOT_ID))
);
assembly {
sstore(PRICEFEED_KEY, feedAddr)
}
}
function setDeps(address _ymtOS) external onlyGovernance {
bytes32 YMTOS_KEY = bytes32(keccak256(abi.encode(YMTOS_SLOT_ID)));
assembly {
sstore(YMTOS_KEY, _ymtOS)
}
}
modifier onlyYamato() {
if (yamatoes.length == 0) {
revert("No Yamato is registered.");
} else {
require(_permitMe(), "You are not Yamato deps.");
_;
}
}
/*
=====================
Public Functions
=====================
*/
function addYamato(address _yamatoAddr) external onlyGovernance {
require(!exists(_yamatoAddr), "Duplicated Yamato.");
yamatoes.push(_yamatoAddr);
if (ymtOS() != address(0)) {
IYmtOS(ymtOS()).addYamatoOfCurrencyOS(_yamatoAddr);
}
emit YamatoAdded(_yamatoAddr);
}
function mintCurrency(
address to,
uint256 amount
) public override onlyYamato {
ICurrency(currency()).mint(to, amount);
}
function burnCurrency(
address to,
uint256 amount
) public override onlyYamato {
ICurrency(currency()).burn(to, amount);
}
/*
=====================
Getter Functions
=====================
*/
function currency() public view override returns (address _currency) {
bytes32 CURRENCY_KEY = bytes32(keccak256(abi.encode(CURRENCY_SLOT_ID)));
assembly {
_currency := sload(CURRENCY_KEY)
}
}
function priceFeed() public view override returns (address _feed) {
bytes32 PRICEFEED_KEY = bytes32(
keccak256(abi.encode(PRICEFEED_SLOT_ID))
);
assembly {
_feed := sload(PRICEFEED_KEY)
}
}
function feePool() public view override returns (address _feePool) {
bytes32 FEEPOOL_KEY = bytes32(keccak256(abi.encode(FEEPOOL_SLOT_ID)));
assembly {
_feePool := sload(FEEPOOL_KEY)
}
}
function ymtOS() public view override returns (address _ymtOS) {
bytes32 YMTOS_KEY = bytes32(keccak256(abi.encode(YMTOS_SLOT_ID)));
assembly {
_ymtOS := sload(YMTOS_KEY)
}
}
function YMT() public view override returns (address _YMT) {
_YMT = IYmtOS(ymtOS()).YMT();
}
function veYMT() public view override returns (address _veYMT) {
_veYMT = IYmtOS(ymtOS()).veYMT();
}
function exists(address _yamato) public view returns (bool) {
for (uint256 i = 0; i < yamatoes.length; i++) {
if (yamatoes[i] == _yamato) return true;
}
return false;
}
function _permitMe() internal view returns (bool) {
for (uint256 i = 0; i < yamatoes.length; i++) {
if (IYamato(yamatoes[i]).permitDeps(msg.sender)) return true;
}
return false;
}
}