diff --git a/contracts/OpenSTUtility.sol b/contracts/OpenSTUtility.sol index 9ec64eb7..64333245 100644 --- a/contracts/OpenSTUtility.sol +++ b/contracts/OpenSTUtility.sol @@ -322,7 +322,7 @@ contract OpenSTUtility is Hasher, OpsManaged { require(nonces[_staker] < _stakerNonce); require(_amountST > 0); require(_amountUT > 0); - // escrowunlockheight needs to be checked against the core that tracks the value chain + // stakingUnlockheight needs to be checked against the core that tracks the value chain require(_stakingUnlockHeight > 0); require(_stakingIntentHash != ""); @@ -469,8 +469,6 @@ contract OpenSTUtility is Hasher, OpsManaged { return (amountSTP, unlockHeight, redemptionIntentHash); } - - /* * Operation functions */ diff --git a/contracts/OpenSTValue.sol b/contracts/OpenSTValue.sol index 6f5f23c0..695dbdda 100644 --- a/contracts/OpenSTValue.sol +++ b/contracts/OpenSTValue.sol @@ -47,6 +47,8 @@ contract OpenSTValue is OpsManaged, Hasher { uint256 _chainIdUtility); event ProcessedStake(bytes32 indexed _uuid, bytes32 indexed _stakingIntentHash, address _stake, address _staker, uint256 _amountST, uint256 _amountUT); + event RedemptionIntentConfirmed(bytes32 indexed uuid, bytes32 _redemptionIntentHash, + address _redeemer, uint256 _amountST, uint256 _amountUT, uint256 _unlockHeight); /* * Constants @@ -83,8 +85,10 @@ contract OpenSTValue is OpsManaged, Hasher { struct Unstake { bytes32 uuid; - address unstaker; - uint256 amount; + address redeemer; + uint256 amountST; + uint256 amountUT; + uint256 unlockHeight; } /* @@ -231,6 +235,61 @@ contract OpenSTValue is OpsManaged, Hasher { return stakeAddress; } + function confirmRedemptionIntent( + bytes32 _uuid, + address _redeemer, + uint256 _redeemerNonce, + uint256 _amountUT, + uint256 _redemptionUnlockHeight, + bytes32 _redemptionIntentHash) + external + onlyRegistrar + returns ( + uint256 amountST, + uint256 unlockHeight) + { + require(utilityTokens[_uuid].simpleStake != address(0)); + require(_amountUT > 0); + // later core will provide a view on the block height of the + // utility chain + require(_redemptionUnlockHeight > 0); + require(_redemptionIntentHash != ""); + + require(nonces[_redeemer] + 1 == _redeemerNonce); + nonces[_redeemer]++; + + bytes32 redemptionIntentHash = hashRedemptionIntent( + _uuid, + _redeemer, + nonces[_redeemer]++, + _amountUT, + _redemptionUnlockHeight + ); + + require(_redemptionIntentHash == redemptionIntentHash); + + unlockHeight = block.number + BLOCKS_TO_WAIT_SHORT; + + UtilityToken storage utilityToken = utilityTokens[_uuid]; + amountST = _amountUT.div(utilityToken.conversionRate); + + require(valueToken.balanceOf(address(utilityToken.simpleStake)) >= amountST); + + unstakes[redemptionIntentHash] = Unstake({ + uuid: _uuid, + redeemer: _redeemer, + amountUT: _amountUT, + amountST: amountST, + unlockHeight: unlockHeight + }); + + RedemptionIntentConfirmed(_uuid, redemptionIntentHash, _redeemer, + amountST, _amountUT, unlockHeight); + + return (amountST, unlockHeight); + } + + /* * Public view functions */