Skip to content

Instantly share code, notes, and snippets.

@izqui izqui/EscrowManager.sol Secret
Last active Sep 24, 2018

What would you like to do?
contract EscrowManager is LockManager {
enum State {
State public state;
// would be set in constructor
StakeLocking public staking = StakeLocking(0);
bytes32 public party1Lock = bytes32(1);
bytes32 public party2Lock = bytes32(2);
address public party1 = address(1);
address public party2 = address(1);
address public arbiter = address(3);
function activate() external {
var (,,,unlocked1,staker1,manager1,) = staking.locks(party1Lock);
var (,,,unlocked2,staker2,manager2,) = staking.locks(party2Lock);
require(unlocked1 == 0 && manager1 == address(this) && staker1 == party1);
require(unlocked2 == 0 && manager2 == address(this) && staker2 == party2);
state = State.Locked;
// resolve transfering amount from party2 to party1
function resolveForParty1(uint256 amount) external {
staking.transferFromLock(party2Lock, amount, party1, party1Lock);
// a fee from the loser could be transfered to the arbiter too!
// resolve transfering amount from party1 to party2
function resolveForParty2(uint256 amount) external {
staking.transferFromLock(party1Lock, amount, party2, party2Lock);
// arbiter can call resolve directly and not modify lock balances
function resolve() public {
// ideally both parties could also agree to resolve without involving arbiter
require(msg.sender == arbiter);
state = State.Resolved;
// Both locks became unlocked now, but arbiter doesn't need to pay for the unlocking execution
// Locks will now be managed by another manager (different resolution mechanism)
function escalate(LockManager newManager) external {
require(msg.sender == arbiter);
staking.setLockManager(party1Lock, newManager);
staking.setLockManager(party2Lock, newManager);
function canUnlock(bytes32, bytes lockData) public view returns (bool) {
// before activating escrow funds can be unlocked
return state != State.Locked;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.