From Decentralized Capital Open Sources Their Asset Contract Code:
We’ve open sourced our contract code for community review, third party scrutiny is much appreciated! We’ve got a few other projects under development and will be open sourcing those too once they are released. Stay tuned!
Website – Decentralized Capital.
But your cash is centralised with Decentralized Capital – they can suspend your account anytime.
Older news:
Decentralized Capital Unveils Real Time Proof of Reserves
Decentralized Capital and Dapp Integration: Synergy is More Than Just a Buzzword
Decentralized Capital issuing fiat-backed digital assets on the Ethereum blockchain
Decentralized Capital is live with support for 8 fiat currencies
For your reference here is the link to the Ethereum Contract Security Techniques and Tips.
1842 lines of source code below from https://github.com/decentralizedcapital/dcasset.
Here are the contents of the lib subdirectory with the import statements showing the dependencies:
- lib/Assertive.sol
- lib/Owned.sol
- import “./Assertive.sol”;
- lib/Precision.sol
- lib/Relay.sol
- lib/StateTransferrable.sol
- import “./Owned.sol”;
- lib/TokenRecipient.sol
- lib/TokenBase.sol
- import “./Owned.sol”;
- import “./TokenRecipient.sol”;
- lib/Token.sol
- import “./TokenBase.sol”;
- import “./Precision.sol”;
- lib/TrustClient.sol
- import “../Trust.sol”;
- import “./Assertive.sol”;
- import “./StateTransferrable.sol”;
- lib/TrustEvents.sol
- lib/Util.sol
And here are the contents of the base directory with the import statements showing the dependencies:
- README.md
- LICENSE
- DVIP.sol
- import “lib/Token.sol”;
- import “lib/TokenRecipient.sol”;
- import “lib/StateTransferrable.sol”;
- import “lib/TrustClient.sol”;
- import “lib/Util.sol”;
- DCAssetBackend.sol
- import “lib/Token.sol”;
- import “lib/TokenRecipient.sol”;
- import “lib/StateTransferrable.sol”;
- import “lib/TrustClient.sol”;
- import “lib/Util.sol”;
- import “lib/Relay.sol”;
- import “./DVIP.sol”;
- DCAsset.sol
- import “lib/TokenBase.sol”;
- import “lib/TokenRecipient.sol”;
- import “lib/StateTransferrable.sol”;
- import “lib/TrustClient.sol”;
- import “lib/Relay.sol”;
- import “./DCAssetBackend.sol”;
- Oversight.sol
- import “lib/TrustEvents.sol”;
- import “lib/StateTransferrable.sol”;
- import “DCAsset.sol”;
- import “DCAssetBackend.sol”;
- HotWallet.sol
- import “lib/StateTransferrable.sol”;
- import “lib/Token.sol”;
- import “lib/TrustClient.sol”;
- import “Oversight.sol”;
- Trust.sol
- import “lib/StateTransferrable.sol”;
- import “lib/TrustEvents.sol”;
LICENSE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
The MIT License (MIT) Copyright (c) 2016 Decentralized Capital Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
lib/Assertive.sol
1 2 3 4 5 |
contract Assertive { function assert(bool assertion) { if (!assertion) throw; } } |
lib/Owned.sol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import "./Assertive.sol"; // @title Owned contract Owned is Assertive { address internal owner; event SetOwner(address indexed previousOwner, address indexed newOwner); function Owned () { owner = msg.sender; } modifier onlyOwner { assert(msg.sender == owner); _ } function setOwner(address newOwner) onlyOwner { SetOwner(owner, newOwner); owner = newOwner; } function getOwner() returns (address out) { return owner; } } |
lib/Precision.sol
1 2 3 |
contract Precision { uint8 public decimals; } |
lib/Relay.sol
1 2 3 |
contract Relay { function relayReceiveApproval(address _caller, address _spender, uint256 _amount, bytes _extraData) returns (bool success); } |
lib/StateTransferrable.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 |
import "./Owned.sol"; contract StateTransferrable is Owned { bool internal locked; event Locked(address indexed from); event PropertySet(address indexed from); modifier onlyIfUnlocked { assert(!locked); _ } modifier setter { _ PropertySet(msg.sender); } modifier onlyOwnerUnlocked { assert(!locked && msg.sender == owner); _ } function lock() onlyOwner onlyIfUnlocked { locked = true; Locked(msg.sender); } function isLocked() returns (bool status) { return locked; } } |
lib/TokenRecipient.sol
1 2 3 |
contract TokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); } |
lib/TokenBase.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 |
import "./Owned.sol"; import "./TokenRecipient.sol"; contract TokenBase is Owned { bytes32 public standard = 'Token 0.1'; bytes32 public name; bytes32 public symbol; uint256 public totalSupply; bool public allowTransactions; event Approval(address indexed from, address indexed spender, uint256 amount); mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); function transfer(address _to, uint256 _value) returns (bool success); function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success); function approve(address _spender, uint256 _value) returns (bool success); function transferFrom(address _from, address _to, uint256 _value) returns (bool success); function () { throw; } } |
lib/Token.sol
1 2 3 4 |
import "./TokenBase.sol"; import "./Precision.sol"; contract Token is TokenBase, Precision {} |
lib/TrustClient.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 |
import "../Trust.sol"; import "./Assertive.sol"; import "./StateTransferrable.sol"; contract TrustClient is StateTransferrable, TrustEvents { address public trustAddress; modifier multisig (bytes32 hash) { assert(trustAddress != address(0x0)); address current = Trust(trustAddress).functionCalls(uint256(hash)); uint8 code = Trust(trustAddress).authCall(msg.sender, hash); if (code == 0) Unauthorized(msg.sender); else if (code == 1) AuthInit(msg.sender); else if (code == 2) { AuthComplete(current, msg.sender); _ } else if (code == 3) { AuthPending(msg.sender); } } function setTrust(address addr) setter onlyOwnerUnlocked { trustAddress = addr; } function cancel() returns (uint8 status) { assert(trustAddress != address(0x0)); uint8 code = Trust(trustAddress).authCancel(msg.sender); if (code == 0) Unauthorized(msg.sender); else if (code == 1) NothingToCancel(msg.sender); else if (code == 2) AuthCancel(msg.sender, msg.sender); return code; } } |
lib/TrustEvents.sol
1 2 3 4 5 6 7 8 9 10 |
contract TrustEvents { event AuthInit(address indexed from); event AuthComplete(address indexed from, address indexed with); event AuthPending(address indexed from); event Unauthorized(address indexed from); event InitCancel(address indexed from); event NothingToCancel(address indexed from); event SetMasterKey(address indexed from); event AuthCancel(address indexed from, address indexed with); } |
lib/Util.sol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
contract Util { function pow10(uint256 a, uint8 b) internal returns (uint256 result) { for (uint8 i = 0; i < b; i++) { a *= 10; } return a; } function div10(uint256 a, uint8 b) internal returns (uint256 result) { for (uint8 i = 0; i < b; i++) { a /= 10; } return a; } function max(uint256 a, uint256 b) internal returns (uint256 res) { if (a >= b) return a; return b; } } |
DVIP.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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
import "lib/Token.sol"; import "lib/TokenRecipient.sol"; import "lib/StateTransferrable.sol"; import "lib/TrustClient.sol"; import "lib/Util.sol"; /** * @title DVIP Contract. DCAsset Membership Token contract. * * @author Ray Pulver, ray@decentralizedcapital.com */ contract DVIP is Token, StateTransferrable, TrustClient, Util { uint256 public totalSupply; mapping (address => bool) public frozenAccount; mapping (address => address[]) public allowanceIndex; mapping (address => mapping (address => bool)) public allowanceActive; address[] public accountIndex; mapping (address => bool) public accountActive; address public oversightAddress; mapping (address => bool) public authorizedVendors; uint256 public expiry; uint256 public treasuryBalance; bool public isActive; mapping (address => uint256) public exportFee; address[] public exportFeeIndex; mapping (address => bool) exportFeeActive; mapping (address => uint256) public importFee; address[] public importFeeIndex; mapping (address => bool) importFeeActive; event FrozenFunds(address target, bool frozen); event PrecisionSet(address indexed from, uint8 precision); event TransactionsShutDown(address indexed from); event FeeSetup(address indexed from, address indexed target, uint256 amount); /** * Constructor. * */ function DVIP() { isActive = true; treasuryBalance = 0; totalSupply = 0; name = "DVIP"; symbol = "DVIP"; decimals = 6; allowTransactions = true; expiry = 1514764800; //1 jan 2018 } /* --------------- modifiers --------------*/ /** * Makes sure a method is only called by an overseer. */ modifier onlyOverseer { assert(msg.sender == oversightAddress); _ } /* --------------- setter methods, only for the unlocked state --------------*/ /** * Sets the oversight address (not the contract). * * @param addr The oversight contract address. */ function setOversight(address addr) onlyOwnerUnlocked setter { oversightAddress = addr; } /** * Sets the total supply * * @param total Total supply of the asset. */ function setTotalSupply(uint256 total) onlyOwnerUnlocked setter { totalSupply = total; } /** * Set the Token Standard the contract applies to. * * @param std the Standard. */ function setStandard(bytes32 std) onlyOwnerUnlocked setter { standard = std; } /** * Sets the name of the contraxt * * @param _name the name. */ function setName(bytes32 _name) onlyOwnerUnlocked setter { name = _name; } /** * Sets the symbol * * @param sym The Symbol */ function setSymbol(bytes32 sym) onlyOwnerUnlocked setter { symbol = sym; } /** * Sets the precision * * @param precision Amount of decimals */ function setPrecisionDirect(uint8 precision) onlyOwnerUnlocked { decimals = precision; PrecisionSet(msg.sender, precision); } /** * Sets the balance of a certain account. * * @param addr Address of the account * @param amount Amount of assets to set on the account */ function setAccountBalance(address addr, uint256 amount) onlyOwnerUnlocked { balanceOf[addr] = amount; activateAccount(addr); } /** * Sets an allowance from a specific account to a specific account. * * @param from From-part of the allowance * @param to To-part of the allowance * @param amount Amount of the allowance */ function setAccountAllowance(address from, address to, uint256 amount) onlyOwnerUnlocked { allowance[from][to] = amount; activateAllowanceRecord(from, to); } /** * Sets the treasure balance to a certain account. * * @param amount Amount of assets to pre-set in the treasury */ function setTreasuryBalance(uint256 amount) onlyOwnerUnlocked { treasuryBalance = amount; } /** * Sets a certain account on frozen/unfrozen * * @param addr Account that will be frozen/unfrozen * @param frozen Boolean to freeze or unfreeze */ function setAccountFrozenStatus(address addr, bool frozen) onlyOwnerUnlocked { activateAccount(addr); frozenAccount[addr] = frozen; } /** * Sets up a import fee for a certain address. * * @param addr Address that will require fee * @param fee Amount of fee */ function setupImportFee(address addr, uint256 fee) onlyOwnerUnlocked { importFee[addr] = fee; activateImportFeeChargeRecord(addr); FeeSetup(msg.sender, addr, fee); } /** * Sets up a export fee for a certain address. * * @param addr Address that will require fee * @param fee Amount of fee */ function setupExportFee(address addr, uint256 fee) onlyOwnerUnlocked { exportFee[addr] = fee; activateExportFeeChargeRecord(addr); FeeSetup(msg.sender, addr, fee); } /* --------------- main token methods --------------*/ /** * @notice Transfer `_amount` from `msg.sender.address()` to `_to`. * * @param _to Address that will receive. * @param _amount Amount to be transferred. */ function transfer(address _to, uint256 _amount) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); assert(balanceOf[msg.sender] >= _amount); uint256 pointZeroOne; if (!authorizedVendors[msg.sender]) { pointZeroOne = pow10(1, decimals - 2); assert(balanceOf[msg.sender] >= pointZeroOne); } assert(balanceOf[_to] + _amount >= balanceOf[_to]); activateAccount(msg.sender); activateAccount(_to); balanceOf[msg.sender] -= _amount; if (_to == address(this)) treasuryBalance += _amount; else if (!authorizedVendors[msg.sender]) { balanceOf[_to] += _amount - pointZeroOne; treasuryBalance += pointZeroOne; } else { balanceOf[_to] += _amount; } Transfer(msg.sender, _to, _amount); return true; } /** * @notice Transfer `_amount` from `_from` to `_to`. * * @param _from Origin address * @param _to Address that will receive * @param _amount Amount to be transferred. * @return result of the method call */ function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); assert(!frozenAccount[_from]); assert(balanceOf[_from] >= _amount); assert(balanceOf[_to] + _amount >= balanceOf[_to]); uint256 pointZeroOne; if (!authorizedVendors[_from]) { pointZeroOne = pow10(1, decimals - 2); assert(balanceOf[_from] >= pointZeroOne); } assert(_amount <= allowance[_from][msg.sender]); balanceOf[_from] -= _amount; if (!authorizedVendors[_from]) { balanceOf[_to] += _amount - pointZeroOne; treasuryBalance += pointZeroOne; } else { balanceOf[_to] += _amount; } allowance[_from][msg.sender] -= _amount; activateAccount(_from); activateAccount(_to); activateAccount(msg.sender); Transfer(_from, _to, _amount); return true; } /** * @notice Approve spender `_spender` to transfer `_amount` from `msg.sender.address()` * * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @param _extraData Consequential contract to be executed by spender in same transcation. * @return result of the method call */ function approveAndCall(address _spender, uint256 _amount, bytes _extraData) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); allowance[msg.sender][_spender] = _amount; activateAccount(msg.sender); activateAccount(_spender); activateAllowanceRecord(msg.sender, _spender); TokenRecipient spender = TokenRecipient(_spender); spender.receiveApproval(msg.sender, _amount, this, _extraData); Approval(msg.sender, _spender, _amount); return true; } /** * @notice Approve spender `_spender` to transfer `_amount` from `msg.sender.address()` * * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @return result of the method call */ function approve(address _spender, uint256 _amount) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); allowance[msg.sender][_spender] = _amount; activateAccount(msg.sender); activateAccount(_spender); activateAllowanceRecord(msg.sender, _spender); Approval(msg.sender, _spender, _amount); return true; } /* --------------- multisig admin methods --------------*/ /** * @notice Sets the expiry time in milliseconds since 1970. * * @param ts milliseconds since 1970. * */ function setExpiry(uint256 ts) multisig(sha3(msg.data)) { expiry = ts; } function setAuthorizedVendor(address addr, bool authorized) multisig(sha3(msg.data)) { authorizedVendors[addr] = authorized; } /** * @notice Mints `mintedAmount` new tokens to the hotwallet `hotWalletAddress`. * * @param mintedAmount Amount of new tokens to be minted. */ function mint(uint256 mintedAmount) multisig(sha3(msg.data)) { treasuryBalance += mintedAmount; totalSupply += mintedAmount; } /** * @notice Destroys `destroyAmount` new tokens from the hotwallet `hotWalletAddress` * * @param destroyAmount Amount of new tokens to be minted. */ function destroyTokens(uint256 destroyAmount) multisig(sha3(msg.data)) { assert(treasuryBalance >= destroyAmount); treasuryBalance -= destroyAmount; totalSupply -= destroyAmount; } /** * @notice Transfers `amount` from the treasury to `to` * * @param to Address to transfer to * @param amount Amount to transfer from treasury */ function transferFromTreasury(address to, uint256 amount) multisig(sha3(msg.data)) { assert(treasuryBalance >= amount); treasuryBalance -= amount; balanceOf[to] += amount; activateAccount(to); } /* --------------- fee setting administration methods --------------*/ /** * @notice Sets an export fee of `fee` on address `addr` * * @param addr Address for which the fee is valid * @param addr fee Fee * */ function setExportFee(address addr, uint256 fee) multisig(sha3(msg.data)) { uint256 max = 1; max = pow10(1, decimals); assert(fee <= max); exportFee[addr] = fee; activateExportFeeChargeRecord(addr); } /* --------------- multisig emergency methods --------------*/ /** * @notice Sets allow transactions to `allow` * * @param allow Allow or disallow transactions */ function voteAllowTransactions(bool allow) multisig(sha3(msg.data)) { assert(allow != allowTransactions); allowTransactions = allow; } /** * @notice Destructs the contract and sends remaining `this.balance` Ether to `beneficiary` * * @param beneficiary Beneficiary of remaining Ether on contract */ function voteSuicide(address beneficiary) multisig(sha3(msg.data)) { selfdestruct(beneficiary); } /** * @notice Sets frozen to `freeze` for account `target` * * @param addr Address to be frozen/unfrozen * @param freeze Freeze/unfreeze account */ function freezeAccount(address addr, bool freeze) multisig(sha3(msg.data)) { frozenAccount[addr] = freeze; activateAccount(addr); } /** * @notice Seizes `seizeAmount` of tokens from `address` and transfers it to hotwallet * * @param addr Adress to seize tokens from * @param amount Amount of tokens to seize */ function seizeTokens(address addr, uint256 amount) multisig(sha3(msg.data)) { assert(balanceOf[addr] >= amount); assert(frozenAccount[addr]); activateAccount(addr); balanceOf[addr] -= amount; treasuryBalance += amount; } /* --------------- fee calculation method ---------------- */ /** * @notice 'Returns the fee for a transfer from `from` to `to` on an amount `amount`. * * Fee's consist of a possible * - import fee on transfers to an address * - export fee on transfers from an address * DVIP ownership on an address * - reduces fee on a transfer from this address to an import fee-ed address * - reduces the fee on a transfer to this address from an export fee-ed address * DVIP discount does not work for addresses that have an import fee or export fee set up against them. * * DVIP discount goes up to 100% * * @param from From address * @param to To address * @param amount Amount for which fee needs to be calculated. * */ function feeFor(address from, address to, uint256 amount) constant external returns (uint256 value) { uint256 fee = exportFee[from]; if (fee == 0) return 0; uint256 amountHeld; bool discounted = true; uint256 oneDVIPUnit; if (exportFee[from] == 0 && balanceOf[from] != 0 && now < expiry) { amountHeld = balanceOf[from]; } else discounted = false; if (discounted) { oneDVIPUnit = pow10(1, decimals); if (amountHeld > oneDVIPUnit) amountHeld = oneDVIPUnit; uint256 remaining = oneDVIPUnit - amountHeld; return div10(amount*fee*remaining, decimals*2); } return div10(amount*fee, decimals); } /* --------------- overseer methods for emergency --------------*/ /** * @notice Shuts down all transaction and approval options on the asset contract */ function shutdownTransactions() onlyOverseer { allowTransactions = false; TransactionsShutDown(msg.sender); } /* --------------- helper methods for siphoning --------------*/ function extractAccountAllowanceRecordLength(address addr) constant returns (uint256 len) { return allowanceIndex[addr].length; } function extractAccountLength() constant returns (uint256 length) { return accountIndex.length; } /* --------------- private methods --------------*/ function activateAccount(address addr) internal { if (!accountActive[addr]) { accountActive[addr] = true; accountIndex.push(addr); } } function activateAllowanceRecord(address from, address to) internal { if (!allowanceActive[from][to]) { allowanceActive[from][to] = true; allowanceIndex[from].push(to); } } function activateExportFeeChargeRecord(address addr) internal { if (!exportFeeActive[addr]) { exportFeeActive[addr] = true; exportFeeIndex.push(addr); } } function activateImportFeeChargeRecord(address addr) internal { if (!importFeeActive[addr]) { importFeeActive[addr] = true; importFeeIndex.push(addr); } } function extractImportFeeChargeLength() returns (uint256 length) { return importFeeIndex.length; } function extractExportFeeChargeLength() returns (uint256 length) { return exportFeeIndex.length; } } |
DCAssetBackend.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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
import "lib/Token.sol"; import "lib/TokenRecipient.sol"; import "lib/StateTransferrable.sol"; import "lib/TrustClient.sol"; import "lib/Util.sol"; import "lib/Relay.sol"; import "./DVIP.sol"; /** * @title DCAssetBackend Contract * * @author Ray Pulver, ray@decentralizedcapital.com */ contract DCAssetBackend is Owned, Precision, StateTransferrable, TrustClient, Util { bytes32 public standard = 'Token 0.1'; bytes32 public name; bytes32 public symbol; bool public allowTransactions; event Approval(address indexed from, address indexed spender, uint256 amount); mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); uint256 public totalSupply; address public hotWalletAddress; address public assetAddress; address public oversightAddress; address public membershipAddress; mapping (address => bool) public frozenAccount; mapping (address => address[]) public allowanceIndex; mapping (address => mapping (address => bool)) public allowanceActive; address[] public accountIndex; mapping (address => bool) public accountActive; bool public isActive; uint256 public treasuryBalance; mapping (address => uint256) public feeCharge; address[] public feeChargeIndex; mapping (address => bool) feeActive; event FrozenFunds(address target, bool frozen); event PrecisionSet(address indexed from, uint8 precision); event TransactionsShutDown(address indexed from); event FeeSetup(address indexed from, address indexed target, uint256 amount); /** * Constructor. * * @param tokenName Name of the Token * @param tokenSymbol The Token Symbol */ function DCAssetBackend(bytes32 tokenSymbol, bytes32 tokenName) { isActive = true; name = tokenName; symbol = tokenSymbol; decimals = 6; allowTransactions = true; } /* --------------- modifiers --------------*/ /** * Makes sure a method is only called by an overseer. */ modifier onlyOverseer { assert(msg.sender == oversightAddress); _ } /** * Make sure only the front end Asset can call the transfer methods */ modifier onlyAsset { assert(msg.sender == assetAddress); _ } /* --------------- setter methods, only for the unlocked state --------------*/ /** * Sets the hot wallet contract address * * @param addr Address of the Hotwallet */ function setHotWallet(address addr) onlyOwnerUnlocked setter { hotWalletAddress = addr; } /** * Sets the token facade contract address * * @param addr Address of the front-end Asset */ function setAsset(address addr) onlyOwnerUnlocked setter { assetAddress = addr; } /** * Sets the membership contract address * * @param addr Address of the membership contract */ function setMembership(address addr) onlyOwnerUnlocked setter { membershipAddress = addr; } /** * Sets the oversight address (not the contract). * * @param addr The oversight contract address. */ function setOversight(address addr) onlyOwnerUnlocked setter { oversightAddress = addr; } /** * Sets the total supply * * @param total Total supply of the asset. */ function setTotalSupply(uint256 total) onlyOwnerUnlocked setter { totalSupply = total; } /** * Set the Token Standard the contract applies to. * * @param std the Standard. */ function setStandard(bytes32 std) onlyOwnerUnlocked setter { standard = std; } /** * Sets the name of the contraxt * * @param _name the name. */ function setName(bytes32 _name) onlyOwnerUnlocked setter { name = _name; } /** * Sets the symbol * * @param sym The Symbol */ function setSymbol(bytes32 sym) onlyOwnerUnlocked setter { symbol = sym; } /** * Sets the precision * * @param precision Amount of decimals */ function setPrecisionDirect(uint8 precision) onlyOwnerUnlocked { decimals = precision; PrecisionSet(msg.sender, precision); } /** * Sets the balance of a certain account. * * @param addr Address of the account * @param amount Amount of assets to set on the account */ function setAccountBalance(address addr, uint256 amount) onlyOwnerUnlocked { balanceOf[addr] = amount; activateAccount(addr); } /** * Sets an allowance from a specific account to a specific account. * * @param from From-part of the allowance * @param to To-part of the allowance * @param amount Amount of the allowance */ function setAccountAllowance(address from, address to, uint256 amount) onlyOwnerUnlocked { allowance[from][to] = amount; activateAllowanceRecord(from, to); } /** * Sets the treasure balance to a certain account. * * @param amount Amount of assets to pre-set in the treasury */ function setTreasuryBalance(uint256 amount) onlyOwnerUnlocked { treasuryBalance = amount; } /** * Sets a certain account on frozen/unfrozen * * @param addr Account that will be frozen/unfrozen * @param frozen Boolean to freeze or unfreeze */ function setAccountFrozenStatus(address addr, bool frozen) onlyOwnerUnlocked { activateAccount(addr); frozenAccount[addr] = frozen; } /* --------------- main token methods --------------*/ /** * @notice Transfer `_amount` from `_caller` to `_to`. * * @param _caller Origin address * @param _to Address that will receive. * @param _amount Amount to be transferred. */ function transfer(address _caller, address _to, uint256 _amount) onlyAsset returns (bool success) { assert(allowTransactions); assert(!frozenAccount[_caller]); assert(balanceOf[_caller] >= _amount); assert(balanceOf[_to] + _amount >= balanceOf[_to]); activateAccount(_caller); activateAccount(_to); balanceOf[_caller] -= _amount; if (_to == address(this)) treasuryBalance += _amount; else { uint256 fee = feeFor(_caller, _to, _amount); balanceOf[_to] += _amount - fee; treasuryBalance += fee; } Transfer(_caller, _to, _amount); return true; } /** * @notice Transfer `_amount` from `_from` to `_to`, invoked by `_caller`. * * @param _caller Invoker of the call (owner of the allowance) * @param _from Origin address * @param _to Address that will receive * @param _amount Amount to be transferred. * @return result of the method call */ function transferFrom(address _caller, address _from, address _to, uint256 _amount) onlyAsset returns (bool success) { assert(allowTransactions); assert(!frozenAccount[_caller]); assert(!frozenAccount[_from]); assert(balanceOf[_from] >= _amount); assert(balanceOf[_to] + _amount >= balanceOf[_to]); assert(_amount <= allowance[_from][_caller]); balanceOf[_from] -= _amount; uint256 fee = feeFor(_from, _to, _amount); balanceOf[_to] += _amount - fee; treasuryBalance += fee; allowance[_from][_caller] -= _amount; activateAccount(_from); activateAccount(_to); activateAccount(_caller); Transfer(_from, _to, _amount); return true; } /** * @notice Approve Approves spender `_spender` to transfer `_amount` from `_caller` * * @param _caller Address that grants the allowance * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @param _extraData Consequential contract to be executed by spender in same transcation. * @return result of the method call */ function approveAndCall(address _caller, address _spender, uint256 _amount, bytes _extraData) onlyAsset returns (bool success) { assert(allowTransactions); assert(!frozenAccount[_caller]); allowance[_caller][_spender] = _amount; activateAccount(_caller); activateAccount(_spender); activateAllowanceRecord(_caller, _spender); TokenRecipient spender = TokenRecipient(_spender); assert(Relay(assetAddress).relayReceiveApproval(_caller, _spender, _amount, _extraData)); Approval(_caller, _spender, _amount); return true; } /** * @notice Approve Approves spender `_spender` to transfer `_amount` from `_caller` * * @param _caller Address that grants the allowance * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @return result of the method call */ function approve(address _caller, address _spender, uint256 _amount) onlyAsset returns (bool success) { assert(allowTransactions); assert(!frozenAccount[_caller]); allowance[_caller][_spender] = _amount; activateAccount(_caller); activateAccount(_spender); activateAllowanceRecord(_caller, _spender); Approval(_caller, _spender, _amount); return true; } /* --------------- multisig admin methods --------------*/ /** * @notice Mints `mintedAmount` new tokens to the hotwallet `hotWalletAddress`. * * @param mintedAmount Amount of new tokens to be minted. */ function mint(uint256 mintedAmount) multisig(sha3(msg.data)) { activateAccount(hotWalletAddress); balanceOf[hotWalletAddress] += mintedAmount; totalSupply += mintedAmount; } /** * @notice Destroys `destroyAmount` new tokens from the hotwallet `hotWalletAddress` * * @param destroyAmount Amount of new tokens to be minted. */ function destroyTokens(uint256 destroyAmount) multisig(sha3(msg.data)) { assert(balanceOf[hotWalletAddress] >= destroyAmount); activateAccount(hotWalletAddress); balanceOf[hotWalletAddress] -= destroyAmount; totalSupply -= destroyAmount; } /** * @notice Transfers `amount` from the treasury to `to` * * @param to Address to transfer to * @param amount Amount to transfer from treasury */ function transferFromTreasury(address to, uint256 amount) multisig(sha3(msg.data)) { assert(treasuryBalance >= amount); treasuryBalance -= amount; balanceOf[to] += amount; activateAccount(to); } /* --------------- multisig emergency methods --------------*/ /** * @notice Sets allow transactions to `allow` * * @param allow Allow or disallow transactions */ function voteAllowTransactions(bool allow) multisig(sha3(msg.data)) { if (allow == allowTransactions) throw; allowTransactions = allow; } /** * @notice Destructs the contract and sends remaining `this.balance` Ether to `beneficiary` * * @param beneficiary Beneficiary of remaining Ether on contract */ function voteSuicide(address beneficiary) multisig(sha3(msg.data)) { selfdestruct(beneficiary); } /** * @notice Sets frozen to `freeze` for account `target` * * @param addr Address to be frozen/unfrozen * @param freeze Freeze/unfreeze account */ function freezeAccount(address addr, bool freeze) multisig(sha3(msg.data)) { frozenAccount[addr] = freeze; activateAccount(addr); } /** * @notice Seizes `seizeAmount` of tokens from `address` and transfers it to hotwallet * * @param addr Adress to seize tokens from * @param amount Amount of tokens to seize */ function seizeTokens(address addr, uint256 amount) multisig(sha3(msg.data)) { assert(balanceOf[addr] >= amount); assert(frozenAccount[addr]); activateAccount(addr); balanceOf[addr] -= amount; balanceOf[hotWalletAddress] += amount; } /* --------------- overseer methods for emergency --------------*/ /** * @notice Shuts down all transaction and approval options on the asset contract */ function shutdownTransactions() onlyOverseer { allowTransactions = false; TransactionsShutDown(msg.sender); } /* --------------- helper methods for siphoning --------------*/ function extractAccountAllowanceRecordLength(address addr) returns (uint256 len) { return allowanceIndex[addr].length; } function extractAccountLength() returns (uint256 length) { return accountIndex.length; } /* --------------- private methods --------------*/ function activateAccount(address addr) internal { if (!accountActive[addr]) { accountActive[addr] = true; accountIndex.push(addr); } } function activateAllowanceRecord(address from, address to) internal { if (!allowanceActive[from][to]) { allowanceActive[from][to] = true; allowanceIndex[from].push(to); } } function feeFor(address a, address b, uint256 amount) returns (uint256 value) { if (membershipAddress == address(0x0)) return 0; return DVIP(membershipAddress).feeFor(a, b, amount); } } |
DCAsset.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 |
import "lib/TokenBase.sol"; import "lib/TokenRecipient.sol"; import "lib/StateTransferrable.sol"; import "lib/TrustClient.sol"; import "lib/Relay.sol"; import "./DCAssetBackend.sol"; /** * @title DCAssetFacade, Facade for the underlying back-end dcasset token contract. Allow to be updated later. * * @author P.S.D. Reitsma, peter@decentralizedcapital.com * */ contract DCAsset is TokenBase, StateTransferrable, TrustClient, Relay { address public backendContract; /** * Constructor * * */ function DCAsset(address _backendContract) { backendContract = _backendContract; } function standard() constant returns (bytes32 std) { return DCAssetBackend(backendContract).standard(); } function name() constant returns (bytes32 nm) { return DCAssetBackend(backendContract).name(); } function symbol() constant returns (bytes32 sym) { return DCAssetBackend(backendContract).symbol(); } function decimals() constant returns (uint8 precision) { return DCAssetBackend(backendContract).decimals(); } function allowance(address from, address to) constant returns (uint256 res) { return DCAssetBackend(backendContract).allowance(from, to); } /* --------------- multisig admin methods --------------*/ /** * @notice Sets the backend contract to `_backendContract`. Can only be switched by multisig. * * @param _backendContract Address of the underlying token contract. */ function setBackend(address _backendContract) multisig(sha3(msg.data)) { backendContract = _backendContract; } /* --------------- main token methods --------------*/ /** * @notice Returns the balance of `_address`. * * @param _address The address of the balance. */ function balanceOf(address _address) constant returns (uint256 balance) { return DCAssetBackend(backendContract).balanceOf(_address); } /** * @notice Returns the total supply of the token * */ function totalSupply() constant returns (uint256 balance) { return DCAssetBackend(backendContract).totalSupply(); } /** * @notice Transfer `_amount` to `_to`. * * @param _to Address that will receive. * @param _amount Amount to be transferred. */ function transfer(address _to, uint256 _amount) returns (bool success) { if (!DCAssetBackend(backendContract).transfer(msg.sender, _to, _amount)) throw; Transfer(msg.sender, _to, _amount); return true; } /** * @notice Approve Approves spender `_spender` to transfer `_amount`. * * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @param _extraData Consequential contract to be executed by spender in same transcation. * @return result of the method call */ function approveAndCall(address _spender, uint256 _amount, bytes _extraData) returns (bool success) { if (!DCAssetBackend(backendContract).approveAndCall(msg.sender, _spender, _amount, _extraData)) throw; Approval(msg.sender, _spender, _amount); return true; } /** * @notice Approve Approves spender `_spender` to transfer `_amount`. * * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @return result of the method call */ function approve(address _spender, uint256 _amount) returns (bool success) { if (!DCAssetBackend(backendContract).approve(msg.sender, _spender, _amount)) throw; Approval(msg.sender, _spender, _amount); return true; } /** * @notice Transfer `_amount` from `_from` to `_to`. * * @param _from Origin address * @param _to Address that will receive * @param _amount Amount to be transferred. * @return result of the method call */ function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) { if (!DCAssetBackend(backendContract).transferFrom(msg.sender, _from, _to, _amount)) throw; Transfer(_from, _to, _amount); return true; } /** * @notice Returns fee for transferral of `_amount` from `_from` to `_to`. * * @param _from Origin address * @param _to Address that will receive * @param _amount Amount to be transferred. * @return height of the fee */ function feeFor(address _from, address _to, uint256 _amount) returns (uint256 amount) { return DCAssetBackend(backendContract).feeFor(_from, _to, _amount); } /* --------------- to be called by backend --------------*/ function relayReceiveApproval(address _caller, address _spender, uint256 _amount, bytes _extraData) returns (bool success) { assert(msg.sender == backendContract); TokenRecipient spender = TokenRecipient(_spender); spender.receiveApproval(_caller, _amount, this, _extraData); return true; } } |
Oversight.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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
import "lib/TrustClient.sol"; import "lib/StateTransferrable.sol"; import "./DCAsset.sol"; import "./DCAssetBackend.sol"; /** * @title Oversight Contract that is hooked into HotWallet to provide extra security. * * @author Ray Pulver, ray@decentralizedcapital.com */ contract Oversight is StateTransferrable, TrustClient { address public hotWalletAddress; mapping (address => uint256) public approved; //map of approved amounts per currency address[] public approvedIndex; //array of approved currencies mapping (address => uint256) public expiry; //map of expiry times per currency mapping (address => bool) public currencyActive; //map of active/inactive currencies mapping (address => bool) public oversightAddresses; //map of active/inactive oversight addresses address[] public oversightAddressesIndex; //array of oversight addresses mapping (address => bool) public oversightAddressActive; //map of active oversight addresses (for siphoning/uploading) uint256 public timeWindow; //expiry time for an approval event TransactionsShutDown(address indexed from); /** * Constructor. Sets expiry to 10 minutes. */ function Oversight() { timeWindow = 10 minutes; } /* --------------- modifiers --------------*/ /** * Makes sure a method is only called by an overseer. */ modifier onlyOverseer { assert(oversightAddresses[msg.sender]); _ } /** * Makes sure a method is only called from the HotWallet. */ modifier onlyHotWallet { assert(msg.sender == hotWalletAddress); _ } /* --------------- setter methods, only for the unlocked state --------------*/ /** * Sets the HotWallet address. * * @param addr Address of the hotwallet. */ function setHotWallet(address addr) onlyOwnerUnlocked setter { hotWalletAddress = addr; } /** * Sets the approval expiry window, called before the contract is locked. * * @param secs Expiry time in seconds. */ function setupTimeWindow(uint256 secs) onlyOwnerUnlocked setter { timeWindow = secs; } /** * Approves an amount for a certain currency, called before the contract is locked. * * @param addr Currency. * @param amount The amount to approve. */ function setApproved(address addr, uint256 amount) onlyOwnerUnlocked setter { activateCurrency(addr); approved[addr] = amount; } /** * Sets the expiry window for a certain currency, called before the contracted is locked. * * @param addr Currency. * @param ts Window in seconds */ function setExpiry(address addr, uint256 ts) onlyOwnerUnlocked setter { activateCurrency(addr); expiry[addr] = ts; } /** * Sets an oversight address, on active or inactive, called before the contract is locked. * * @param addr The oversight address. * @param value Whether to activate or deactivate the address. */ function setOversightAddress(address addr, bool value) onlyOwnerUnlocked setter { activateOversightAddress(addr); oversightAddresses[addr] = value; } /* --------------- multisig admin methods --------------*/ /** * @notice Sets the approval expiry window to `secs`. * * @param secs Expiry time in seconds. */ function setTimeWindow(uint256 secs) external multisig(sha3(msg.data)) { timeWindow = secs; } /** * @notice Adds and activates new oversight address `addr`. * * @param addr The oversight addresss. */ function addOversight(address addr) external multisig(sha3(msg.data)) { activateOversightAddress(addr); oversightAddresses[addr] = true; } /** * @notice Removes/deactivates oversight address `addr`. * * @param addr The oversight address to be removed. */ function removeOversight(address addr) external multisig(sha3(msg.data)) { oversightAddresses[addr] = false; } /* --------------- multisig main methods --------------*/ /** * @notice Approve `amount` of asset `currency` to be withdrawn. * * @param currency Address of the currency/asset to approve a certain amount for. * @param amount The amount to approve. */ function approve(address currency, uint256 amount) external multisig(sha3(msg.data)) { activateCurrency(currency); approved[currency] = amount; expiry[currency] = now + timeWindow; } /* --------------- method for hotwallet --------------*/ /** * @notice Validate that `amount` is allowed to be transacted for `currency`. * Called by the HotWallet to validate a transaction. * * @param currency Address of the currency/asset for which is validated. * @param amount The amount that is validated. */ function validate(address currency, uint256 amount) external onlyHotWallet returns (bool) { assert(approved[currency] >= amount); approved[currency] -= amount; return true; } /* --------------- Overseer methods for emergency --------------*/ /** * @notice Shutdown transactions on asset `currency` * * @param currency Address of the currency/asset contract to be shut down. */ function shutdownTransactions(address currency) onlyOverseer { address backend = DCAsset(currency).backendContract(); DCAssetBackend(backend).shutdownTransactions(); TransactionsShutDown(msg.sender); } /* --------------- Helper methods for siphoning --------------*/ /** * Returns the amount of approvals. */ function extractApprovedIndexLength() returns (uint256) { return approvedIndex.length; } /** * Returns the amount of oversight addresses. */ function extractOversightAddressesIndexLength() returns (uint256) { return oversightAddressesIndex.length; } /* --------------- private methods --------------*/ function activateOversightAddress(address addr) internal { if (!oversightAddressActive[addr]) { oversightAddressActive[addr] = true; oversightAddressesIndex.push(addr); } } function activateCurrency(address addr) internal { if (!currencyActive[addr]) { currencyActive[addr] = true; approvedIndex.push(addr); } } } |
HotWallet.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 |
import "lib/StateTransferrable.sol"; import "lib/Token.sol"; import "lib/TrustClient.sol"; import "./Oversight.sol"; /** * @title HotWallet contract into which all freshly minted assets end-up. Controlled by Oversight Contract * * @author Ray Pulver, ray@decentralizedcapital.com */ contract HotWallet is StateTransferrable, TrustClient { address public oversightAddress; mapping (address => uint256) public invoiced; address[] public invoicedIndex; mapping (address => bool) public invoicedActive; event HotWalletDeposit(address indexed from, uint256 amount); event PerformedTransfer(address indexed to, uint256 amount); event PerformedTransferFrom(address indexed from, address indexed to, uint256 amount); event PerformedApprove(address indexed spender, uint256 amount); /* --------------- modifiers --------------*/ /** * Makes sure the Oversight Contract is set */ modifier onlyWithOversight { assert(oversightAddress != 0x0); _ } /** * Check if the amount of for a certain asset/currency has been approved in the Oversight address */ modifier spendControl(address currency, uint256 amount) { assert(Oversight(oversightAddress).validate(currency, amount)); _ } /** * Check if the amount of for a certain asset/currency has been approved in the Oversight address * and that the transfer is not to the HotWallet itself */ modifier spendControlTargeted (address currency, address to, uint256 amount) { if (to != address(this)) { assert(Oversight(oversightAddress).validate(currency, amount)); } _ } /* --------------- setter methods, only for the unlocked state --------------*/ /** * Sets the Oversight contract address. * * @param addr Address of the Oversight contract. */ function setOversight(address addr) onlyOwnerUnlocked setter { oversightAddress = addr; } /* --------------- main methods --------------*/ /** * @notice Transfer `amount` of asset `currency` from the hotwallet to `to`. * * @param currency Address of the currency/asset. * @param to Destination address of the transfer. * @param amount The amount to be transferred. */ function transfer(address currency, address to, uint256 amount) multisig(sha3(msg.data)) spendControl(currency, amount) onlyWithOversight { Token(currency).transfer(to, amount); PerformedTransfer(to, amount); } /** * @notice Transfer `amount` of asset `currency` from `from` to `to`. * * @param currency Address of the currency/asset. * @param from Origin address. * @param to Destination address of the transfer. * @param amount The amount to be transferred */ function transferFrom(address currency, address from, address to, uint256 amount) multisig(sha3(msg.data)) spendControlTargeted(currency, to, amount) onlyWithOversight { Token(currency).transferFrom(from, to, amount); PerformedTransferFrom(from, to, amount); } /** * @notice Approve `spender` to transfer `amount` of asset `currency` from the Hotwallet and make a consequential call. * * @param currency Address of the currency/asset. * @param spender Address that receives the cheque/approval to spend * @param amount The amount that is approved */ function approve(address currency, address spender, uint256 amount) multisig(sha3(msg.data)) spendControl(currency, amount) onlyWithOversight { Token(currency).approve(spender, amount); PerformedApprove(spender, amount); } /** * @notice Approve `spender` to transfer `amount` of asset `currency` from the Hotwallet and make a consequential call. * * @param currency Address of the currency/asset. * @param spender Address that receives the cheque/approval to spend * @param amount The amount that is approved * @param extraData consequential call that is made */ function approveAndCall(address currency, address spender, uint256 amount, bytes extraData) multisig(sha3(msg.data)) spendControl(currency, amount) onlyWithOversight { Token(currency).approveAndCall(spender, amount, extraData); PerformedApprove(spender, amount); } /** * @notice Receives approval to drain the invoice. * * @param from Address from which the transfer can be made. * @param amount The amount that is approved. * @param currency Address of the currency * @param extraData consequential call that can be made */ function receiveApproval(address from, uint256 amount, address currency, bytes extraData) external { Token(currency).transferFrom(from, this, amount); HotWalletDeposit(from, amount); } /* --------------- methods for siphoning, uploading --------------*/ function activateInvoiced(address addr) internal { if (!invoicedActive[addr]) { invoicedActive[addr] = true; invoicedIndex.push(addr); } } function extractInvoicedLength() external returns (uint256 len) { return invoicedIndex.length; } } |
Trust.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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
import "./lib/StateTransferrable.sol"; import "./lib/TrustEvents.sol"; /** * @title Trust Contract, providing multisig security to list of client contracts. * * @author Ray Pulver, ray@decentralizedcapital.com */ contract Trust is StateTransferrable, TrustEvents { mapping (address => bool) public masterKeys; mapping (address => bytes32) public nameRegistry; address[] public masterKeyIndex; mapping (address => bool) public masterKeyActive; mapping (address => bool) public trustedClients; mapping (uint256 => address) public functionCalls; mapping (address => uint256) public functionCalling; /* --------------- modifiers --------------*/ modifier multisig (bytes32 hash) { if (!masterKeys[msg.sender]) { Unauthorized(msg.sender); } else if (functionCalling[msg.sender] == 0) { if (functionCalls[uint256(hash)] == 0x0) { functionCalls[uint256(hash)] = msg.sender; functionCalling[msg.sender] = uint256(hash); AuthInit(msg.sender); } else { AuthComplete(functionCalls[uint256(hash)], msg.sender); resetAction(uint256(hash)); _ } } else { AuthPending(msg.sender); } } /* --------------- setter methods, only for the unlocked state --------------*/ /** * @notice Sets a master key * * @param addr Address */ function setMasterKey(address addr) onlyOwnerUnlocked { assert(!masterKeys[addr]); activateMasterKey(addr); masterKeys[addr] = true; SetMasterKey(msg.sender); } /** * @notice Adds a trusted client * * @param addr Address */ function setTrustedClient(address addr) onlyOwnerUnlocked setter { trustedClients[addr] = true; } /* --------------- methods to be called by a Master Key --------------*/ /* --------------- multisig admin methods --------------*/ /** * @notice remove contract `addr` from the list of trusted contracts * * @param addr Address of client contract to be removed */ function untrustClient(address addr) multisig(sha3(msg.data)) { trustedClients[addr] = false; } /** * @notice add contract `addr` to the list of trusted contracts * * @param addr Address of contract to be added */ function trustClient(address addr) multisig(sha3(msg.data)) { trustedClients[addr] = true; } /** * @notice remove key `addr` to the list of master keys * * @param addr Address of the masterkey */ function voteOutMasterKey(address addr) multisig(sha3(msg.data)) { assert(masterKeys[addr]); masterKeys[addr] = false; } /** * @notice add key `addr` to the list of master keys * * @param addr Address of the masterkey */ function voteInMasterKey(address addr) multisig(sha3(msg.data)) { assert(!masterKeys[addr]); activateMasterKey(addr); masterKeys[addr] = true; } /* --------------- methods to be called by Trusted Client Contracts --------------*/ /** * @notice Cancel outstanding multisig method call from address `from`. Called from trusted clients. * * @param from Address that issued the call that needs to be cancelled */ function authCancel(address from) external returns (uint8 status) { if (!masterKeys[from] || !trustedClients[msg.sender]) { Unauthorized(from); return 0; } uint256 call = functionCalling[from]; if (call == 0) { NothingToCancel(from); return 1; } else { AuthCancel(from, from); functionCalling[from] = 0; functionCalls[call] = 0x0; return 2; } } /** * @notice Authorize multisig call on a trusted client. Called from trusted clients. * * @param from Address from which call is made. * @param hash of method call */ function authCall(address from, bytes32 hash) external returns (uint8 code) { if (!masterKeys[from] || !trustedClients[msg.sender]) { Unauthorized(from); return 0; } if (functionCalling[from] == 0) { if (functionCalls[uint256(hash)] == 0x0) { functionCalls[uint256(hash)] = from; functionCalling[from] = uint256(hash); AuthInit(from); return 1; } else { AuthComplete(functionCalls[uint256(hash)], from); resetAction(uint256(hash)); return 2; } } else { AuthPending(from); return 3; } } /* --------------- methods to be called directly on the contract --------------*/ /** * @notice cancel any outstanding multisig call * */ function cancel() returns (uint8 code) { if (!masterKeys[msg.sender]) { Unauthorized(msg.sender); return 0; } uint256 call = functionCalling[msg.sender]; if (call == 0) { NothingToCancel(msg.sender); return 1; } else { AuthCancel(msg.sender, msg.sender); uint256 hash = functionCalling[msg.sender]; functionCalling[msg.sender] = 0x0; functionCalls[hash] = 0; return 2; } } /* --------------- private methods --------------*/ function resetAction(uint256 hash) internal { address addr = functionCalls[hash]; functionCalls[hash] = 0x0; functionCalling[addr] = 0; } function activateMasterKey(address addr) internal { if (!masterKeyActive[addr]) { masterKeyActive[addr] = true; masterKeyIndex.push(addr); } } /* --------------- helper methods for siphoning --------------*/ function extractMasterKeyIndexLength() returns (uint256 length) { return masterKeyIndex.length; } } |