/
DirectPaymentAddress.sol
72 lines (60 loc) 路 2.3 KB
/
DirectPaymentAddress.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
import "./interfaces/IDirectPaymentAddress.sol";
import "./interfaces/ITerminalDirectory.sol";
/**
@notice
A contract that can receive funds directly and forward to a project's current terminal.
*/
contract DirectPaymentAddress is IDirectPaymentAddress {
// --- public immutable stored properties --- //
/// @notice The directory to use when resolving which terminal to send the payment to.
ITerminalDirectory public immutable override terminalDirectory;
/// @notice The ID of the project to pay when this contract receives funds.
uint256 public immutable override projectId;
// --- public stored properties --- //
/// @notice The memo to use when this contract forwards a payment to a terminal.
string public override memo;
// --- external transactions --- //
/**
@param _terminalDirectory A directory of a project's current Juicebox terminal to receive payments in.
@param _projectId The ID of the project to pay when this contract receives funds.
@param _memo The memo to use when this contract forwards a payment to a terminal.
*/
constructor(
ITerminalDirectory _terminalDirectory,
uint256 _projectId,
string memory _memo
) {
terminalDirectory = _terminalDirectory;
projectId = _projectId;
memo = _memo;
}
// Receive funds and make a payment to the project's current terminal.
receive() external payable {
// Check to see if the sender has configured a beneficiary.
address _storedBeneficiary = terminalDirectory.beneficiaryOf(
msg.sender
);
// If no beneficiary is configured, use the sender's address.
address _beneficiary = _storedBeneficiary != address(0)
? _storedBeneficiary
: msg.sender;
bool _preferUnstakedTickets = terminalDirectory
.unstakedTicketsPreferenceOf(msg.sender);
terminalDirectory.terminalOf(projectId).pay{value: msg.value}(
projectId,
_beneficiary,
memo,
_preferUnstakedTickets
);
emit Forward(
msg.sender,
projectId,
_beneficiary,
msg.value,
memo,
_preferUnstakedTickets
);
}
}