-
Notifications
You must be signed in to change notification settings - Fork 10
/
RWAHubOffChainRedemptions.sol
117 lines (103 loc) · 4.06 KB
/
RWAHubOffChainRedemptions.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
/**SPDX-License-Identifier: BUSL-1.1
▄▄█████████▄
╓██▀└ ,╓▄▄▄, '▀██▄
██▀ ▄██▀▀╙╙▀▀██▄ └██µ ,, ,, , ,,, ,,,
██ ,██¬ ▄████▄ ▀█▄ ╙█▄ ▄███▀▀███▄ ███▄ ██ ███▀▀▀███▄ ▄███▀▀███,
██ ██ ╒█▀' ╙█▌ ╙█▌ ██ ▐██ ███ █████, ██ ██▌ └██▌ ██▌ └██▌
██ ▐█▌ ██ ╟█ █▌ ╟█ ██▌ ▐██ ██ └███ ██ ██▌ ╟██ j██ ╟██
╟█ ██ ╙██ ▄█▀ ▐█▌ ██ ╙██ ██▌ ██ ╙████ ██▌ ▄██▀ ██▌ ,██▀
██ "██, ╙▀▀███████████⌐ ╙████████▀ ██ ╙██ ███████▀▀ ╙███████▀`
██▄ ╙▀██▄▄▄▄▄,,, ¬─ '─¬
╙▀██▄ '╙╙╙▀▀▀▀▀▀▀▀
╙▀▀██████R⌐
*/
pragma solidity 0.8.16;
import "contracts/RWAHub.sol";
import "contracts/interfaces/IRWAHubOffChainRedemptions.sol";
abstract contract RWAHubOffChainRedemptions is
RWAHub,
IRWAHubOffChainRedemptions
{
// To enable and disable off chain redemptions
bool public offChainRedemptionPaused;
// Minimum off chain redemption amount
uint256 public minimumOffChainRedemptionAmount;
constructor(
address _collateral,
address _rwa,
address managerAdmin,
address pauser,
address _assetSender,
address _feeRecipient,
uint256 _minimumDepositAmount,
uint256 _minimumRedemptionAmount
)
RWAHub(
_collateral,
_rwa,
managerAdmin,
pauser,
_assetSender,
_feeRecipient,
_minimumDepositAmount,
_minimumRedemptionAmount
)
{
// Default to the same minimum redemption amount as for On-Chain
// redemptions.
minimumOffChainRedemptionAmount = _minimumRedemptionAmount;
}
/**
* @notice Request a redemption to be serviced off chain.
*
* @param amountRWATokenToRedeem The requested redemption amount
* @param offChainDestination A hash of the destination to which
* the request should be serviced to.
*/
function requestRedemptionServicedOffchain(
uint256 amountRWATokenToRedeem,
bytes32 offChainDestination
) external nonReentrant ifNotPaused(offChainRedemptionPaused) {
if (amountRWATokenToRedeem < minimumOffChainRedemptionAmount) {
revert RedemptionTooSmall();
}
bytes32 redemptionId = bytes32(redemptionRequestCounter++);
rwa.burnFrom(msg.sender, amountRWATokenToRedeem);
emit RedemptionRequestedServicedOffChain(
msg.sender,
redemptionId,
amountRWATokenToRedeem,
offChainDestination
);
}
/**
* @notice Function to pause off chain redemptoins
*/
function pauseOffChainRedemption() external onlyRole(PAUSER_ADMIN) {
offChainRedemptionPaused = true;
emit OffChainRedemptionPaused(msg.sender);
}
/**
* @notice Function to unpause off chain redemptoins
*/
function unpauseOffChainRedemption() external onlyRole(MANAGER_ADMIN) {
offChainRedemptionPaused = false;
emit OffChainRedemptionUnpaused(msg.sender);
}
/**
* @notice Admin Function to set the minimum off chain redemption amount
*
* @param _minimumOffChainRedemptionAmount The new minimum off chain
* redemption amount
*/
function setOffChainRedemptionMinimum(
uint256 _minimumOffChainRedemptionAmount
) external onlyRole(MANAGER_ADMIN) {
uint256 oldMinimum = minimumOffChainRedemptionAmount;
minimumOffChainRedemptionAmount = _minimumOffChainRedemptionAmount;
emit OffChainRedemptionMinimumSet(
oldMinimum,
_minimumOffChainRedemptionAmount
);
}
}