-
Notifications
You must be signed in to change notification settings - Fork 38
/
UBIProxy.sol
154 lines (135 loc) · 4.64 KB
/
UBIProxy.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
/**
* @authors: [@fraserdscott*]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
* @tools: []
*/
pragma solidity ^0.7.3;
interface IProofOfHumanity {
/** @dev Return true if the submission is registered and not expired.
* @param _submissionID The address of the submission.
* @return Whether the submission is registered or not.
*/
function isRegistered(address _submissionID) external view returns (bool);
/** @dev Return the number of submissions irrespective of their status.
* @return The number of submissions.
*/
function submissionCounter() external view returns (uint256);
}
/**
* @title ERC20 Interface
* @dev See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol.
*/
interface IERC20 {
function balanceOf(address _human) external view returns (uint256);
function totalSupply() external view returns (uint256);
}
/**
* @title UBIProxy
* A proxy contract for UBI that implements a token interface to interact with other dapps.
* Note that it isn't an ERC20 and only implements its interface in order to be compatible with Snapshot.
*/
contract UBIProxy {
IProofOfHumanity public PoH;
IERC20 public UBI;
address public governor = msg.sender;
string public name = "UBI Vote";
string public symbol = "UBIVOTE";
uint8 public decimals = 18;
/** @dev Constructor.
* @param _PoH The address of the related ProofOfHumanity contract.
* @param _UBI The address of the related UBI contract.
*/
constructor(IProofOfHumanity _PoH, IERC20 _UBI) public {
PoH = _PoH;
UBI = _UBI;
}
/** @dev Changes the address of the the related ProofOfHumanity contract.
* @param _PoH The address of the new contract.
*/
function changePoH(IProofOfHumanity _PoH) external {
require(msg.sender == governor, "The caller must be the governor.");
PoH = _PoH;
}
/** @dev Changes the address of the the related UBI contract.
* @param _UBI The address of the new contract.
*/
function changeUBI(IERC20 _UBI) external {
require(msg.sender == governor, "The caller must be the governor.");
UBI = _UBI;
}
/** @dev Changes the address of the the governor.
* @param _governor The address of the new governor.
*/
function changeGovernor(address _governor) external {
require(msg.sender == governor, "The caller must be the governor.");
governor = _governor;
}
/** @dev Returns true if the submission is registered and not expired.
* @param _submissionID The address of the submission.
* @return Whether the submission is registered or not.
*/
function isRegistered(address _submissionID) public view returns (bool) {
return PoH.isRegistered(_submissionID);
}
/**
* @dev Calculates the square root of a number. Uses the Babylonian Method.
* @param x The input.
* @return y The square root of the input.
**/
function sqrt(uint256 x) private pure returns (uint256 y) {
uint256 z = (x + 1) / 2;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
}
// ******************** //
// * IERC20 * //
// ******************** //
/** @dev Returns the square root of the UBI balance of a particular submission of the ProofOfHumanity contract.
* Note that this function takes the expiration date into account.
* @param _submissionID The address of the submission.
* @return The balance of the submission.
*/
function balanceOf(address _submissionID) external view returns (uint256) {
return
isRegistered(_submissionID)
? sqrt(UBI.balanceOf(_submissionID))
: 0;
}
/** @dev Returns the total supply of the UBI token.
* This function should really count the square root of each humans balance, but this would be costly.
* @return The total supply.
*/
function totalSupply() external view returns (uint256) {
return UBI.totalSupply();
}
function transfer(address _recipient, uint256 _amount)
external
returns (bool)
{
return false;
}
function allowance(address _owner, address _spender)
external
view
returns (uint256)
{}
function approve(address _spender, uint256 _amount)
external
returns (bool)
{
return false;
}
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
) external returns (bool) {
return false;
}
}