diff --git a/src/AcuityAccount.sol b/src/AcuityAccount.sol index 4007514..c754f97 100644 --- a/src/AcuityAccount.sol +++ b/src/AcuityAccount.sol @@ -8,11 +8,6 @@ contract AcuityAccount { */ mapping (address => bytes32) accountAcuAccount; - /** - * @dev Mapping of account to proxy account. - */ - mapping (address => address) accountProxyAccount; - /** * @dev ACU account has been set for an account. * @param account Account that has set its ACU account. @@ -20,13 +15,6 @@ contract AcuityAccount { */ event AcuAccountSet(address indexed account, bytes32 indexed acuAccount); - /** - * @dev Proxy account has been set for an account. - * @param account Account that has set its Proxy account. - * @param proxyAccount Proxy account that has been set for account. - */ - event ProxyAccountSet(address indexed account, address indexed proxyAccount); - /** * @dev Set Acu account for sender. * @param acuAccount ACU account to set for sender. @@ -38,17 +26,6 @@ contract AcuityAccount { emit AcuAccountSet(msg.sender, acuAccount); } - /** - * @dev Set proxy account for sender. - * @param proxyAccount Proxy account to set for sender. - */ - function setProxyAccount(address proxyAccount) - external - { - accountProxyAccount[msg.sender] = proxyAccount; - emit ProxyAccountSet(msg.sender, proxyAccount); - } - /** * @dev Get ACU account for account. * @param account Account to get ACU account for. @@ -62,32 +39,4 @@ contract AcuityAccount { acuAccount = accountAcuAccount[account]; } - /** - * @dev Get proxy account for account. - * @param account Account to get proxy account for. - * @return proxyAccount Proxy account for account. - */ - function getProxyAccount(address account) - external - view - returns (address proxyAccount) - { - proxyAccount = accountProxyAccount[account]; - } - - /** - * @dev Get accounts for account. - * @param account Account to get accounts for. - * @return acuAccount ACU account for account. - * @return proxyAccount Proxy account for account. - */ - function getAccounts(address account) - external - view - returns (bytes32 acuAccount, address proxyAccount) - { - acuAccount = accountAcuAccount[account]; - proxyAccount = accountProxyAccount[account]; - } - } diff --git a/src/AcuityAccount.t.sol b/src/AcuityAccount.t.sol index 4d1f417..2c6867d 100644 --- a/src/AcuityAccount.t.sol +++ b/src/AcuityAccount.t.sol @@ -16,18 +16,4 @@ contract AcuityAccountTest is DSTest { acuityAccount.setAcuAccount(hex"1234"); } - function testSetProxyAccount() public { - acuityAccount.setProxyAccount(address(0x2345)); - assertEq(acuityAccount.getProxyAccount(address(this)), address(0x2345)); - } - - function testGetAccounts() public { - acuityAccount.setAcuAccount(hex"1234"); - acuityAccount.setProxyAccount(address(0x2345)); - - (bytes32 acuAccount, address proxyAccount) = acuityAccount.getAccounts(address(this)); - assertEq(acuAccount, hex"1234"); - assertEq(proxyAccount, address(0x2345)); - } - } diff --git a/src/AcuityAtomicSwap.sol b/src/AcuityAtomicSwap.sol index 35cf254..4717348 100644 --- a/src/AcuityAtomicSwap.sol +++ b/src/AcuityAtomicSwap.sol @@ -10,37 +10,11 @@ contract AcuityAtomicSwap { */ AcuityAccount public immutable acuityAccount; - /** - * @dev Mapping of assetId to linked list of accounts, starting with the largest. - */ - mapping (bytes32 => mapping (address => address)) stashAssetIdAccountLL; - - /** - * @dev Mapping of assetId to selling address to value. - */ - mapping (bytes32 => mapping (address => uint)) stashAssetIdAccountValue; - /** * @dev Mapping of lockId to value stored in the lock. */ mapping (bytes32 => uint) lockIdValue; - /** - * @dev Value has been added to a stash. - * @param account Account adding to a stash. - * @param assetId Asset the stash is to be sold for. - * @param value How much value has been added to the stash. - */ - event StashAdd(address indexed account, bytes32 indexed assetId, uint value); - - /** - * @dev Value has been removed from a stash. - * @param account Account removing from a stash. - * @param assetId Asset the stash is to be sold for. - * @param value How much value has been removed from the stash. - */ - event StashRemove(address indexed account, bytes32 indexed assetId, uint value); - /** * @dev Value has been locked with sell asset info. * @param sender Account that locked the value. @@ -130,13 +104,6 @@ contract AcuityAtomicSwap { */ error LockNotTimedOut(bytes32 lockId); - /** - * @dev Invalid proxy account. - * @param account Account being proxied. - * @param proxyAccount Invalid proxy account. - */ - error InvalidProxy(address account, address proxyAccount); - /** * @dev Ensure value is nonzero. * @param value Value to ensure not zero. @@ -146,17 +113,6 @@ contract AcuityAtomicSwap { _; } - /** - * @dev Check if account is proxy for msg.sender - * @param account Account to check. - */ - modifier checkProxy(address account) { - if (acuityAccount.getProxyAccount(account) != msg.sender) { - revert InvalidProxy(account, msg.sender); - } - _; - } - /** * @param _acuityAccount Address of AcuityAccount contract. */ @@ -164,177 +120,6 @@ contract AcuityAtomicSwap { acuityAccount = _acuityAccount; } - /** - * @dev Add value to stash be sold for a specific asset. - * @param account Account to add stash for. - * @param assetId Asset the stash is to be sold for. - * @param value Size of deposit to add. 0 will malfunction. - */ - function stashAdd(address account, bytes32 assetId, uint value) - internal - { - mapping (address => address) storage accountLL = stashAssetIdAccountLL[assetId]; - mapping (address => uint) storage accountValue = stashAssetIdAccountValue[assetId]; - // Get new total. - uint currentValue = accountValue[account]; - uint total = currentValue + value; - // Search for new previous. - address prev = address(0); - address next = accountLL[prev]; - while (accountValue[next] >= total) { - prev = next; - next = accountLL[prev]; - } - // Is sender already in the list? - if (currentValue != 0) { - // Search for old previous. - address oldPrev = prev; - address oldNext = next; - while (oldNext != account) { - oldPrev = oldNext; - oldNext = accountLL[oldPrev]; - } - // Is it in a different position? - if (prev != oldPrev) { - // Remove sender from current position. - accountLL[oldPrev] = accountLL[account]; - // Insert into linked list. - accountLL[account] = next; - accountLL[prev] = account; - } - } - else { - // Insert into linked list. - accountLL[account] = next; - accountLL[prev] = account; - } - // Update the value deposited. - accountValue[account] = total; - // Log info. - emit StashAdd(account, assetId, value); - } - - /** - * @dev Remove value from stash be sold for a specific asset. - * @param account Account to add stash for. - * @param assetId Asset the stash is to be sold for. - * @param value Size of deposit to remove. 0 will malfunction. - */ - function stashRemove(address account, bytes32 assetId, uint value) - internal - { - mapping (address => address) storage accountLL = stashAssetIdAccountLL[assetId]; - mapping (address => uint) storage accountValue = stashAssetIdAccountValue[assetId]; - // Get new total. Will revert if value is bigger than current stash. - uint total = accountValue[account] - value; - // Search for old previous. - address oldPrev = address(0); - address oldNext = accountLL[oldPrev]; - while (oldNext != account) { - oldPrev = oldNext; - oldNext = accountLL[oldPrev]; - } - // Is there still a stash? - if (total != 0) { - // Search for new previous. - address prev = oldPrev; - address next = oldNext; - while (accountValue[next] >= total) { - prev = next; - next = accountLL[prev]; - } - // Is it in a new position? - if (prev != account) { - // Remove sender from old position. - accountLL[oldPrev] = accountLL[account]; - // Insert into new position. - accountLL[account] = next; - accountLL[prev] = account; - } - } - else { - // Remove sender from list. - accountLL[oldPrev] = accountLL[account]; - } - // Update the value deposited. - accountValue[account] = total; - // Log info. - emit StashRemove(account, assetId, value); - } - - /** - * @dev Stash value to be sold for a specific asset. - * @param assetId Asset the stash is to be sold for. - */ - function depositStash(bytes32 assetId) - external - payable - notZero(msg.value) - { - // Records the deposit. - stashAdd(msg.sender, assetId, msg.value); - } - - /** - * @dev Move value from one stash to another. - * @param assetIdFrom Asset the source stash is to be sold for. - * @param assetIdTo Asset the destination stash is to be sold for. - * @param value Value to move. - */ - function moveStash(bytes32 assetIdFrom, bytes32 assetIdTo, uint value) - external - notZero(value) - { - // Move the deposit. - stashRemove(msg.sender, assetIdFrom, value); - stashAdd(msg.sender, assetIdTo, value); - } - - /** - * @dev Withdraw value from a stash. - * @param assetId Asset the stash is to be sold for. - * @param value Value to withdraw. - */ - function withdrawStash(bytes32 assetId, uint value) - external - notZero(value) - { - // Remove the deposit. - stashRemove(msg.sender, assetId, value); - // Send the funds back. - payable(msg.sender).transfer(value); - } - - /** - * @dev Withdraw all value from a stash. - * @param assetId Asset the stash is to be sold for. - */ - function withdrawStashAll(bytes32 assetId) - external - { - // Get stash value. - mapping (address => uint) storage accountValue = stashAssetIdAccountValue[assetId]; - uint value = accountValue[msg.sender]; - // Ensure lock has value - if (value == 0) return; - // Search for previous. - mapping (address => address) storage accountLL = stashAssetIdAccountLL[assetId]; - address prev = address(0); - address next = accountLL[prev]; - while (next != msg.sender) { - prev = next; - next = accountLL[prev]; - } - // Remove sender from list. - accountLL[prev] = accountLL[msg.sender]; - // Update the stash value. - delete accountValue[msg.sender]; - // Send the funds back. - payable(msg.sender).transfer(value); - // Log info. - emit StashRemove(msg.sender, assetId, value); - } - /** * @dev Lock value. * @param recipient Account that can unlock the lock. @@ -364,48 +149,21 @@ contract AcuityAtomicSwap { * @param recipient Account that can unlock the lock. * @param hashedSecret Hash of the secret. * @param timeout Timestamp when the lock will open. - * @param stashAssetId Asset the stash is to be sold for. - * @param value Value from the stash to lock. + * @param buyAssetId Asset the stash is to be sold for. */ - function lockSell(address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId, uint value, bytes32 buyLockId) + function lockSell(address recipient, bytes32 hashedSecret, uint timeout, bytes32 buyAssetId, bytes32 buyLockId) external - notZero(value) + payable + notZero(msg.value) { // Calculate lockId. bytes32 lockId = keccak256(abi.encode(msg.sender, recipient, hashedSecret, timeout)); // Ensure lockId is not already in use. if (lockIdValue[lockId] != 0) revert LockAlreadyExists(lockId); // Move value into sell lock. - stashRemove(msg.sender, stashAssetId, value); - lockIdValue[lockId] = value; - // Log info. - emit SellLock(msg.sender, recipient, hashedSecret, timeout, value, lockId, stashAssetId, buyLockId); - } - - /** - * @dev Lock stashed value. - * @param buyLockId The buy lock this lock is responding to. - * @param sender Sender of the value (checked for proxy). - * @param recipient Account that can unlock the lock. - * @param hashedSecret Hash of the secret. - * @param timeout Timestamp when the lock will open. - * @param stashAssetId Asset the stash is to be sold for. - * @param value Value from the stash to lock. - */ - function lockSellProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId, uint value, bytes32 buyLockId) - external - checkProxy(sender) - notZero(value) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(sender, recipient, hashedSecret, timeout)); - // Ensure lockId is not already in use. - if (lockIdValue[lockId] != 0) revert LockAlreadyExists(lockId); - // Move value into sell lock. - stashRemove(sender, stashAssetId, value); - lockIdValue[lockId] = value; + lockIdValue[lockId] = msg.value; // Log info. - emit SellLock(sender, recipient, hashedSecret, timeout, value, lockId, stashAssetId, buyLockId); + emit SellLock(msg.sender, recipient, hashedSecret, timeout, msg.value, lockId, buyAssetId, buyLockId); } /** @@ -481,85 +239,6 @@ contract AcuityAtomicSwap { emit UnlockByRecipient(sender, msg.sender, lockId, secret); } - /** - * @dev Transfer value from lock to recipient (called by recipient). - * @param sender Sender of the value. - * @param recipient Receiver of the value (checked for proxy). - * @param secret Secret to unlock the value. - * @param timeout Timeout of the lock. - */ - function unlockByRecipientProxy(address sender, address recipient, bytes32 secret, uint timeout) - external - checkProxy(recipient) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(sender, recipient, keccak256(abi.encodePacked(secret)), timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has not timed out. - if (timeout <= block.timestamp) revert LockTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Transfer the value. - payable(recipient).transfer(value); - // Log info. - emit UnlockByRecipient(sender, recipient, lockId, secret); - } - - /** - * @dev Transfer value from lock back to sender's stash. - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret recipient unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutStash(address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(msg.sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Return funds. - stashAdd(msg.sender, stashAssetId, value); - // Log info. - emit Timeout(msg.sender, recipient, lockId); - } - - /** - * @dev Transfer value from lock back to sender's stash. - * @param sender Sender of the value (checked for proxy). - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret recipient unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutStashProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - checkProxy(sender) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Return funds. - stashAdd(sender, stashAssetId, value); - // Log info. - emit Timeout(sender, recipient, lockId); - } - /** * @dev Transfer value from lock back to sender. * @param recipient Recipient of the value. @@ -585,88 +264,6 @@ contract AcuityAtomicSwap { emit Timeout(msg.sender, recipient, lockId); } - /** - * @dev Transfer value from lock back to sender. - * @param sender Sender of the value (checked for proxy). - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret to unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutValueProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout) - external - checkProxy(sender) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Transfer the value. - payable(sender).transfer(value); - // Log info. - emit Timeout(sender, recipient, lockId); - } - - /** - * @dev Get a list of deposits for a specific asset. - * @param assetId Asset the stash is to be sold for. - * @param offset Number of deposits to skip from the start of the list. - * @param limit Maximum number of deposits to return. - */ - function getStashes(bytes32 assetId, uint offset, uint limit) - external - view - returns (address[] memory accounts, uint[] memory values) - { - mapping (address => address) storage accountLL = stashAssetIdAccountLL[assetId]; - mapping (address => uint) storage accountValue = stashAssetIdAccountValue[assetId]; - // Find first account after offset. - address account = address(0); - address next = accountLL[account]; - while (offset != 0) { - if (next == address(0)) { - break; - } - account = next; - next = accountLL[account]; - --offset; - } - // Count how many accounts to return. - uint _limit = 0; - while (next != address(0) && _limit < limit) { - next = accountLL[next]; - ++_limit; - } - // Allocate the arrays. - accounts = new address[](_limit); - values = new uint[](_limit); - // Populate the arrays. - for (uint i = 0; i != _limit; ++i) { - account = accountLL[account]; - accounts[i] = account; - values[i] = accountValue[account]; - } - } - - /** - * @dev Get value held in a stash. - * @param assetId Asset the stash is to be sold for. - * @param seller Owner of the stash. - * @return value Value held in the stash. - */ - function getStashValue(bytes32 assetId, address seller) - external - view - returns (uint value) - { - value = stashAssetIdAccountValue[assetId][seller]; - } - /** * @dev Get value locked. * @param sender Account that locked the value. diff --git a/src/AcuityAtomicSwap.t.sol b/src/AcuityAtomicSwap.t.sol index a467de8..943241f 100644 --- a/src/AcuityAtomicSwap.t.sol +++ b/src/AcuityAtomicSwap.t.sol @@ -18,56 +18,16 @@ contract AccountProxy { receive() payable external {} - function setProxyAccount(address proxyAccount) external { - acuityAccount.setProxyAccount(proxyAccount); - } - - function depositStash(bytes32 assetId) payable external { - acuityAtomicSwap.depositStash{value: msg.value}(assetId); - } - - function withdrawStash(bytes32 assetId, uint value) external { - acuityAtomicSwap.withdrawStash(assetId, value); - } - - function withdrawStashAll(bytes32 assetId) external { - acuityAtomicSwap.withdrawStashAll(assetId); - } - - function lockSellProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId, uint value, bytes32 buyLockId) - external - { - acuityAtomicSwap.lockSellProxy(sender, recipient, hashedSecret, timeout, stashAssetId, value, buyLockId); - } - function unlockByRecipient(address sender, bytes32 secret, uint timeout) external { acuityAtomicSwap.unlockByRecipient(sender, secret, timeout); } - function unlockByRecipientProxy(address sender, address recipient, bytes32 secret, uint timeout) - external - { - acuityAtomicSwap.unlockByRecipientProxy(sender, recipient, secret, timeout); - } - function declineByRecipient(address sender, bytes32 hashedSecret, uint timeout) external { acuityAtomicSwap.declineByRecipient(sender, hashedSecret, timeout); } - function timeoutStashProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - { - acuityAtomicSwap.timeoutStashProxy(sender, recipient, hashedSecret, timeout, stashAssetId); - } - - function timeoutValueProxy(address sender, address recipient, bytes32 hashedSecret, uint timeout) - external - { - acuityAtomicSwap.timeoutValueProxy(sender, recipient, hashedSecret, timeout); - } - } contract AcuityAtomicSwapTest is DSTest { @@ -89,355 +49,25 @@ contract AcuityAtomicSwapTest is DSTest { account3 = new AccountProxy(acuityAccount, acuityAtomicSwap); } - function testControlDepositStashZeroValue() public { - account0.depositStash{value: 50}(hex"1234"); - } - - function testFailDepositStashZeroValue() public { - account0.depositStash{value: 0}(hex"1234"); - } - - function testDepositStash() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash{value: 50}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - account1.depositStash{value: 40}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account2.depositStash{value: 60}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - account3.depositStash{value: 45}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - account0.depositStash{value: 10}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 60); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - account0.depositStash{value: 1}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 61); - assertEq(accounts[1], address(account2)); - assertEq(values[1], 60); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - } - - function testControlWithdrawStashNotZero() public { - account0.depositStash{value: 50}(hex"1234"); - account0.withdrawStash(hex"1234", 50); - } - - function testFailWithdrawStashNotZero() public { - account0.depositStash{value: 50}(hex"1234"); - account0.withdrawStash(hex"1234", 0); - } - - function testControlWithdrawStashNotEnough() public { - account0.depositStash{value: 50}(hex"1234"); - account0.withdrawStash(hex"1234", 50); - } - - function testFailWithdrawStashNotEnough() public { - account0.depositStash{value: 50}(hex"1234"); - account0.withdrawStash(hex"1234", 51); - } - - function testWithdrawStash() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash{value: 50}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - uint startBalance = address(account0).balance; - account0.withdrawStash(hex"1234", 2); - assertEq(startBalance + 2, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - - account1.depositStash{value: 40}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account2.depositStash{value: 60}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 48); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - account3.depositStash{value: 45}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 48); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - startBalance = address(account2).balance; - account2.withdrawStash(hex"1234", 40); - assertEq(startBalance + 40, address(account2).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - assertEq(accounts[3], address(account2)); - assertEq(values[3], 20); - - startBalance = address(account0).balance; - account0.withdrawStash(hex"1234", 3); - assertEq(startBalance + 3, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - assertEq(accounts[3], address(account2)); - assertEq(values[3], 20); - - startBalance = address(account2).balance; - account2.withdrawStash(hex"1234", 20); - assertEq(startBalance + 20, address(account2).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - startBalance = address(account3).balance; - account3.withdrawStash(hex"1234", 45); - assertEq(startBalance + 45, address(account3).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = address(account0).balance; - account0.withdrawStash(hex"1234", 45); - assertEq(startBalance + 45, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = address(account1).balance; - account1.withdrawStash(hex"1234", 40); - assertEq(startBalance + 40, address(account1).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - - function testWithdrawStashAll() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash{value: 50}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - uint startBalance = address(account0).balance; - account0.withdrawStashAll(hex"1234"); - assertEq(startBalance + 50, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account1.depositStash{value: 40}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - account2.depositStash{value: 60}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account3.depositStash{value: 45}(hex"1234"); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - startBalance = address(account2).balance; - account2.withdrawStashAll(hex"1234"); - assertEq(startBalance + 60, address(account2).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = address(account0).balance; - account0.withdrawStashAll(hex"1234"); - assertEq(startBalance, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = address(account2).balance; - account2.withdrawStashAll(hex"1234"); - assertEq(startBalance, address(account2).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = address(account3).balance; - account3.withdrawStashAll(hex"1234"); - assertEq(startBalance + 45, address(account3).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = address(account0).balance; - account0.withdrawStashAll(hex"1234"); - assertEq(startBalance, address(account0).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = address(account1).balance; - account1.withdrawStashAll(hex"1234"); - assertEq(startBalance + 40, address(account1).balance); - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - - function testControlLockBuyZeroValue() public { + function testControllockBuyZeroValue() public { acuityAtomicSwap.lockBuy{value: 1}(address(account0), hex"1234", block.timestamp + 1, hex"1234", 1); } - function testFailLockBuyZeroValue() public { + function testFaillockBuyZeroValue() public { acuityAtomicSwap.lockBuy{value: 0}(address(account0), hex"1234", block.timestamp + 1, hex"1234", 1); } - function testControlLockBuyLockAlreadyExists() public { + function testControllockBuyLockAlreadyExists() public { acuityAtomicSwap.lockBuy{value: 1}(address(account0), hex"1234", block.timestamp + 1, hex"1234", 1); acuityAtomicSwap.lockBuy{value: 1}(address(account0), hex"3456", block.timestamp + 1, hex"1234", 1); } - function testFailLockBuyLockAlreadyExists() public { + function testFaillockBuyLockAlreadyExists() public { acuityAtomicSwap.lockBuy{value: 1}(address(account0), hex"1234", block.timestamp + 1, hex"1234", 1); acuityAtomicSwap.lockBuy{value: 1}(address(account0), hex"1234", block.timestamp + 1, hex"1234", 1); } - function testLockBuy() public { + function testlockBuy() public { bytes32 secret = hex"1234"; bytes32 hashedSecret = keccak256(abi.encodePacked(secret)); uint timeout = block.timestamp + 1; @@ -447,168 +77,41 @@ contract AcuityAtomicSwapTest is DSTest { assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); } - function testControlLockSellZeroValue() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellZeroValue() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", 0, hex"1234"); - } - - function testControlLockSellNotBigEnough() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellNotBigEnough() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value + 1, hex"1234"); - } - - function testControlLockSellLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value * 2}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"3456", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value * 2}(hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - acuityAtomicSwap.lockSell(address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testLockSell() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"1234"; - bytes32 hashedSecret = keccak256(abi.encodePacked(secret)); - uint timeout = block.timestamp + 1; - uint value = 10; - - acuityAtomicSwap.depositStash{value: 50}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, hex"1234", value, hex"1234"); - - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 40); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - } - - function testControlLockSellProxyInvalidProxy() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyInvalidProxy() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", 0, hex"1234"); - } - - function testControlLockSellProxyZeroValue() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyZeroValue() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", 0, hex"1234"); - } - - function testControlLockSellProxyNotBigEnough() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyNotBigEnough() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value + 1, hex"1234"); - } - - function testControlLockSellProxyLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value * 2}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - account1.lockSellProxy(address(this), address(account0), hex"3456", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwap.depositStash{value: value * 2}(hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - account1.lockSellProxy(address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testLockSellProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"1234"; - bytes32 hashedSecret = keccak256(abi.encodePacked(secret)); - uint timeout = block.timestamp + 1; - uint value = 10; - - acuityAtomicSwap.depositStash{value: 50}(assetId); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(this), address(account0), hashedSecret, timeout, hex"1234", value, hex"1234"); - - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 40); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - } - function testControlDeclineByRecipientLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.declineByRecipient(address(this), hashedSecret, timeout); } function testFailDeclineByRecipientLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.declineByRecipient(address(this), hashedSecret, timeout); account0.declineByRecipient(address(this), hashedSecret, timeout); } function testDeclineByRecipient() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - assertEq(address(acuityAtomicSwap).balance, 50); + assertEq(address(acuityAtomicSwap).balance, value); uint startBalance = address(this).balance; account0.declineByRecipient(address(this), hashedSecret, timeout); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 40); + assertEq(address(acuityAtomicSwap).balance, 0); assertEq(address(this).balance, startBalance + value); } @@ -618,8 +121,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); } @@ -629,8 +131,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); } @@ -641,8 +142,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); } @@ -652,27 +152,25 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); } function testUnlockBySender() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - assertEq(address(acuityAtomicSwap).balance, 50); + assertEq(address(acuityAtomicSwap).balance, 10); uint startBalance = address(account0).balance; acuityAtomicSwap.unlockBySender(address(account0), secret, timeout); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 40); + assertEq(address(acuityAtomicSwap).balance, 0); assertEq(address(account0).balance, startBalance + 10); } @@ -682,8 +180,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.unlockByRecipient(address(this), secret, timeout); } @@ -693,8 +190,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.unlockByRecipient(address(this), secret, timeout); account0.unlockByRecipient(address(this), secret, timeout); } @@ -705,8 +201,7 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.unlockByRecipient(address(this), secret, timeout); } @@ -716,601 +211,81 @@ contract AcuityAtomicSwapTest is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); account0.unlockByRecipient(address(this), secret, timeout); } function testUnlockByRecipient() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - assertEq(address(acuityAtomicSwap).balance, 50); + assertEq(address(acuityAtomicSwap).balance, value); uint startBalance = address(account0).balance; account0.unlockByRecipient(address(this), secret, timeout); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 40); - assertEq(address(account0).balance, startBalance + 10); - } - - function testControlUnlockByRecipientProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testControlUnlockByRecipientProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testControlUnlockByRecipientProxyTimedOut() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyTimedOut() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.depositStash{value: 10}(assetId); - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - } - - function testUnlockByRecipientProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - uint value = 10; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - - assertEq(address(acuityAtomicSwap).balance, 50); - uint startBalance = address(account0).balance; - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(this), address(account0), secret, timeout); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 40); + assertEq(address(acuityAtomicSwap).balance, 0); assertEq(address(account0).balance, startBalance + 10); } - function testControlTimeoutStashLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - } - - function testTimeoutStash() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - acuityAtomicSwap.timeoutStash(address(account0), hashedSecret, timeout, assetId); - - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 50); - (accounts, values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 50); - } - - function testControlTimeoutStashProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testTimeoutStashProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(this), address(account0), hashedSecret, timeout, assetId); - - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), 0); - assertEq(address(acuityAtomicSwap).balance, 50); - (accounts, values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 50); - } - function testControlTimeoutValueLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); } function testFailTimeoutValueLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); } function testControlTimeoutValueNotTimedOut() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); } function testFailTimeoutValueNotTimedOut() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); + acuityAtomicSwap.lockSell{value: 10}(address(account0), hashedSecret, timeout, assetId, hex"1234"); acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); } function testTimeoutValue() public { bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; uint value = 10; - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); + acuityAtomicSwap.lockSell{value: value}(address(account0), hashedSecret, timeout, assetId, hex"1234"); assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - uint startBalance = address(this).balance; acuityAtomicSwap.timeoutValue(address(account0), hashedSecret, timeout); assertEq(address(this).balance, startBalance + value); } - function testControlTimeoutValueProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testControlTimeoutValueProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testControlTimeoutValueProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - } - - function testTimeoutValueProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwap.depositStash{value: 50}(assetId); - assertEq(acuityAtomicSwap.getStashValue(assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwap.lockSell(address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwap.getLockValue(address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - uint startBalance = address(this).balance; - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(this), address(account0), hashedSecret, timeout); - assertEq(address(this).balance, startBalance + value); - } - - function testGetStashes() public { - account0.depositStash{value: 50}(hex"1234"); - account1.depositStash{value: 40}(hex"1234"); - account2.depositStash{value: 60}(hex"1234"); - account3.depositStash{value: 45}(hex"1234"); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwap.getStashes(hex"1234", 0, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 3); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 4); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 0, 5); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 1, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 1, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 1, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 1, 3); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 1, 4); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 2, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 2, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 2, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 2, 3); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 3, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 3, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 3, 2); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 4, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwap.getStashes(hex"1234", 4, 1); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - } diff --git a/src/AcuityAtomicSwapERC20.sol b/src/AcuityAtomicSwapERC20.sol index 4f21fb4..89148a0 100644 --- a/src/AcuityAtomicSwapERC20.sol +++ b/src/AcuityAtomicSwapERC20.sol @@ -11,39 +11,11 @@ contract AcuityAtomicSwapERC20 { */ AcuityAccount public immutable acuityAccount; - /** - * @dev Mapping of sell token address to buy assetId to linked list of accounts, starting with the largest. - */ - mapping (address => mapping (bytes32 => mapping (address => address))) tokenAssetIdAccountLL; - - /** - * @dev Mapping of sell token address to buy assetId to selling account to value. - */ - mapping (address => mapping (bytes32 => mapping (address => uint))) tokenAssetIdAccountValue; - /** * @dev Mapping of lockId to value stored in the lock. */ mapping (bytes32 => uint) lockIdValue; - /** - * @dev Value has been added to a stash. - * @param token Address of token. - * @param account Account adding to a stash. - * @param assetId Asset the stash is to be sold for. - * @param value How much value has been added to the stash. - */ - event StashAdd(address indexed token, address indexed account, bytes32 indexed assetId, uint value); - - /** - * @dev Value has been removed from a stash. - * @param token Address of token. - * @param account Account removing from a stash. - * @param assetId Asset the stash is to be sold for. - * @param value How much value has been removed from the stash. - */ - event StashRemove(address indexed token, address indexed account, bytes32 indexed assetId, uint value); - /** * @dev Value has been locked with sell asset info. * @param token Address of token. @@ -144,13 +116,6 @@ contract AcuityAtomicSwapERC20 { */ error TokenTransferFailed(address token, address from, address to, uint value); - /** - * @dev Invalid proxy account. - * @param account Account being proxied. - * @param proxyAccount Invalid proxy account. - */ - error InvalidProxy(address account, address proxyAccount); - /** * @dev Ensure value is nonzero. * @param value Value to ensure not zero. @@ -160,17 +125,6 @@ contract AcuityAtomicSwapERC20 { _; } - /** - * @dev Check if account is proxy for msg.sender - * @param account Account to check. - */ - modifier checkProxy(address account) { - if (acuityAccount.getProxyAccount(account) != msg.sender) { - revert InvalidProxy(account, msg.sender); - } - _; - } - /** * @param _acuityAccount Address of AcuityAccount contract. */ @@ -198,185 +152,6 @@ contract AcuityAtomicSwapERC20 { if (!success || (data.length != 0 && !abi.decode(data, (bool)))) revert TokenTransferFailed(token, from, to, value); } - /** - * @dev Add value to stash be sold for a specific asset. - * @param token Address of sell token. - * @param account Account to add stash for. - * @param assetId Asset the stash is to be sold for. - * @param value Size of deposit to add. 0 will malfunction. - */ - function stashAdd(address token, address account, bytes32 assetId, uint value) - internal - { - mapping (address => address) storage accountLL = tokenAssetIdAccountLL[token][assetId]; - mapping (address => uint) storage accountValue = tokenAssetIdAccountValue[token][assetId]; - // Get new total. - uint currentValue = accountValue[account]; - uint total = currentValue + value; - // Search for new previous. - address prev = address(0); - address next = accountLL[prev]; - while (accountValue[next] >= total) { - prev = next; - next = accountLL[prev]; - } - // Is sender already in the list? - if (currentValue != 0) { - // Search for old previous. - address oldPrev = prev; - address oldNext = next; - while (oldNext != account) { - oldPrev = oldNext; - oldNext = accountLL[oldPrev]; - } - // Is it in a different position? - if (prev != oldPrev) { - // Remove sender from current position. - accountLL[oldPrev] = accountLL[account]; - // Insert into linked list. - accountLL[account] = next; - accountLL[prev] = account; - } - } - else { - // Insert into linked list. - accountLL[account] = next; - accountLL[prev] = account; - } - // Update the value deposited. - accountValue[account] = total; - // Log info. - emit StashAdd(token, account, assetId, value); - } - - /** - * @dev Remove value from stash be sold for a specific asset. - * @param token Address of sell token. - * @param account Account to add stash for. - * @param assetId Asset the stash is to be sold for. - * @param value Size of deposit to remove. 0 will malfunction. - */ - function stashRemove(address token, address account, bytes32 assetId, uint value) - internal - { - mapping (address => address) storage accountLL = tokenAssetIdAccountLL[token][assetId]; - mapping (address => uint) storage accountValue = tokenAssetIdAccountValue[token][assetId]; - // Get new total. Will revert if value is bigger than current stash. - uint total = accountValue[account] - value; - // Search for old previous. - address oldPrev = address(0); - address oldNext = accountLL[oldPrev]; - while (oldNext != account) { - oldPrev = oldNext; - oldNext = accountLL[oldPrev]; - } - // Is there still a stash? - if (total != 0) { - // Search for new previous. - address prev = oldPrev; - address next = oldNext; - while (accountValue[next] >= total) { - prev = next; - next = accountLL[prev]; - } - // Is it in a new position? - if (prev != account) { - // Remove sender from old position. - accountLL[oldPrev] = accountLL[account]; - // Insert into new position. - accountLL[account] = next; - accountLL[prev] = account; - } - } - else { - // Remove sender from list. - accountLL[oldPrev] = accountLL[account]; - } - // Update the value deposited. - accountValue[account] = total; - // Log info. - emit StashRemove(token, account, assetId, value); - } - - /** - * @dev Stash value to be sold for a specific asset. - * @param sellToken Address of sell token. - * @param assetId Asset the stash is to be sold for. - * @param value Size of deposit. - */ - function depositStash(address sellToken, bytes32 assetId, uint value) - external - notZero(value) - { - // Move the token. - safeTransferFrom(sellToken, msg.sender, address(this), value); - // Record the deposit. - stashAdd(sellToken, msg.sender, assetId, value); - } - - /** - * @dev Move value from one stash to another. - * @param sellToken Address of sell token. - * @param assetIdFrom Asset the source stash is to be sold for. - * @param assetIdTo Asset the destination stash is to be sold for. - * @param value Value to move. - */ - function moveStash(address sellToken, bytes32 assetIdFrom, bytes32 assetIdTo, uint value) - external - notZero(value) - { - // Move the deposit. - stashRemove(sellToken, msg.sender, assetIdFrom, value); - stashAdd(sellToken, msg.sender, assetIdTo, value); - } - - /** - * @dev Withdraw value from a stash. - * @param sellToken Address of sell token. - * @param assetId Asset the stash is to be sold for. - * @param value Value to withdraw. - */ - function withdrawStash(address sellToken, bytes32 assetId, uint value) - external - notZero(value) - { - // Remove the deposit. - stashRemove(sellToken, msg.sender, assetId, value); - // Send the funds back. - safeTransfer(sellToken, msg.sender, value); - } - - /** - * @dev Withdraw all value from a stash. - * @param sellToken Address of sell token. - * @param assetId Asset the stash is to be sold for. - */ - function withdrawStashAll(address sellToken, bytes32 assetId) - external - { - // Get stash value. - mapping (address => uint) storage accountValue = tokenAssetIdAccountValue[sellToken][assetId]; - uint value = accountValue[msg.sender]; - // Ensure lock has value - if (value == 0) return; - // Search for previous. - mapping (address => address) storage accountLL = tokenAssetIdAccountLL[sellToken][assetId]; - address prev = address(0); - address next = accountLL[prev]; - while (next != msg.sender) { - prev = next; - next = accountLL[prev]; - } - // Remove sender from list. - accountLL[prev] = accountLL[msg.sender]; - // Update the stash value. - delete accountValue[msg.sender]; - // Send the funds back. - safeTransfer(sellToken, msg.sender, value); - // Log info. - emit StashRemove(sellToken, msg.sender, assetId, value); - } - /** * @dev Lock value. * @param recipient Account that can unlock the lock. @@ -421,39 +196,12 @@ contract AcuityAtomicSwapERC20 { // Ensure lockId is not already in use. if (lockIdValue[lockId] != 0) revert LockAlreadyExists(lockId); // Move value into sell lock. - stashRemove(sellToken, msg.sender, stashAssetId, value); + safeTransferFrom(sellToken, msg.sender, address(this), value); lockIdValue[lockId] = value; // Log info. emit SellLock(sellToken, msg.sender, recipient, hashedSecret, timeout, value, lockId, stashAssetId, buyLockId); } - /** - * @dev Lock stashed value. - * @param sellToken Address of sell token. - * @param sender Sender of the value (checked for proxy). - * @param recipient Account that can unlock the lock. - * @param hashedSecret Hash of the secret. - * @param timeout Timestamp when the lock will open. - * @param stashAssetId Asset the stash is to be sold for. - * @param value Value from the stash to lock. - * @param buyLockId The buy lock this lock is responding to. - */ - function lockSellProxy(address sellToken, address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId, uint value, bytes32 buyLockId) - external - checkProxy(sender) - notZero(value) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(sellToken, sender, recipient, hashedSecret, timeout)); - // Ensure lockId is not already in use. - if (lockIdValue[lockId] != 0) revert LockAlreadyExists(lockId); - // Move value into sell lock. - stashRemove(sellToken, sender, stashAssetId, value); - lockIdValue[lockId] = value; - // Log info. - emit SellLock(sellToken, sender, recipient, hashedSecret, timeout, value, lockId, stashAssetId, buyLockId); - } - /** * @dev Transfer value back to the sender (called by recipient). * @param token Address of token. @@ -530,88 +278,6 @@ contract AcuityAtomicSwapERC20 { emit UnlockByRecipient(token, sender, msg.sender, lockId, secret); } - /** - * @dev Transfer value from lock to recipient (called by recipient). - * @param token Address of token. - * @param sender Sender of the value. - * @param recipient Receiver of the value (checked for proxy). - * @param secret Secret to unlock the value. - * @param timeout Timeout of the lock. - */ - function unlockByRecipientProxy(address token, address sender, address recipient, bytes32 secret, uint timeout) - external - checkProxy(recipient) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(token, sender, recipient, keccak256(abi.encodePacked(secret)), timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has not timed out. - if (timeout <= block.timestamp) revert LockTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Transfer the value. - safeTransfer(token, recipient, value); - // Log info. - emit UnlockByRecipient(token, sender, recipient, lockId, secret); - } - - /** - * @dev Transfer value from lock back to sender's stash. - * @param token Address of token. - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret recipient unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutStash(address token, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(token, msg.sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Return funds. - stashAdd(token, msg.sender, stashAssetId, value); - // Log info. - emit Timeout(token, msg.sender, recipient, lockId); - } - - /** - * @dev Transfer value from lock back to sender's stash. - * @param token Address of token. - * @param sender Sender of the value (checked for proxy). - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret recipient unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutStashProxy(address token, address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - checkProxy(sender) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(token, sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Return funds. - stashAdd(token, sender, stashAssetId, value); - // Log info. - emit Timeout(token, sender, recipient, lockId); - } - /** * @dev Transfer value from lock back to sender. * @param token Address of token. @@ -638,91 +304,6 @@ contract AcuityAtomicSwapERC20 { emit Timeout(token, msg.sender, recipient, lockId); } - /** - * @dev Transfer value from lock back to sender. - * @param token Address of token. - * @param sender Sender of the value (checked for proxy). - * @param recipient Recipient of the value. - * @param hashedSecret Hash of secret to unlock the value. - * @param timeout Timeout of the lock. - */ - function timeoutValueProxy(address token, address sender, address recipient, bytes32 hashedSecret, uint timeout) - external - checkProxy(sender) - { - // Calculate lockId. - bytes32 lockId = keccak256(abi.encode(token, sender, recipient, hashedSecret, timeout)); - // Get lock value. - uint value = lockIdValue[lockId]; - // Check if the lock exists. - if (value == 0) revert LockNotFound(lockId); - // Check lock has timed out. - if (timeout > block.timestamp) revert LockNotTimedOut(lockId); - // Delete lock. - delete lockIdValue[lockId]; - // Transfer the value. - safeTransfer(token, sender, value); - // Log info. - emit Timeout(token, sender, recipient, lockId); - } - - /** - * @dev Get a list of deposits for a specific asset. - * @param token Address of token stashed. - * @param assetId Asset the stash is to be sold for. - * @param offset Number of deposits to skip from the start of the list. - * @param limit Maximum number of deposits to return. - */ - function getStashes(address token, bytes32 assetId, uint offset, uint limit) - external - view - returns (address[] memory accounts, uint[] memory values) - { - mapping (address => address) storage accountLL = tokenAssetIdAccountLL[token][assetId]; - mapping (address => uint) storage accountValue = tokenAssetIdAccountValue[token][assetId]; - // Find first account after offset. - address account = address(0); - address next = accountLL[account]; - while (offset != 0) { - if (next == address(0)) { - break; - } - account = next; - next = accountLL[account]; - --offset; - } - // Count how many accounts to return. - uint _limit = 0; - while (next != address(0) && _limit < limit) { - next = accountLL[next]; - ++_limit; - } - // Allocate the arrays. - accounts = new address[](_limit); - values = new uint[](_limit); - // Populate the arrays. - for (uint i = 0; i != _limit; ++i) { - account = accountLL[account]; - accounts[i] = account; - values[i] = accountValue[account]; - } - } - - /** - * @dev Get value held in a stash. - * @param token Address of token stashed. - * @param assetId Asset the stash is to be sold for. - * @param seller Owner of the stash. - * @return value Value held in the stash. - */ - function getStashValue(address token, bytes32 assetId, address seller) - external - view - returns (uint value) - { - value = tokenAssetIdAccountValue[token][assetId][seller]; - } - /** * @dev Get value locked. * @param token Address of token. diff --git a/src/AcuityAtomicSwapERC20.t.sol b/src/AcuityAtomicSwapERC20.t.sol index 08f2c69..4187939 100644 --- a/src/AcuityAtomicSwapERC20.t.sol +++ b/src/AcuityAtomicSwapERC20.t.sol @@ -17,58 +17,18 @@ contract AccountProxy { acuityAtomicSwapERC20 = _acuityAtomicSwapERC20; } - function setProxyAccount(address proxyAccount) external { - acuityAccount.setProxyAccount(proxyAccount); - } - - function depositStash(address sellToken, bytes32 assetId, uint value) payable external { - acuityAtomicSwapERC20.depositStash(sellToken, assetId, value); - } - - function withdrawStash(address sellToken, bytes32 assetId, uint value) external { - acuityAtomicSwapERC20.withdrawStash(sellToken, assetId, value); - } - - function withdrawStashAll(address sellToken, bytes32 assetId) external { - acuityAtomicSwapERC20.withdrawStashAll(sellToken, assetId); - } - - function lockSellProxy(address sellToken, address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId, uint value, bytes32 buyLockId) - external - { - acuityAtomicSwapERC20.lockSellProxy(sellToken, sender, recipient, hashedSecret, timeout, stashAssetId, value, buyLockId); - } - function unlockByRecipient(address token, address sender, bytes32 secret, uint timeout) external { acuityAtomicSwapERC20.unlockByRecipient(token, sender, secret, timeout); } - function unlockByRecipientProxy(address token, address sender, address recipient, bytes32 secret, uint timeout) - external - { - acuityAtomicSwapERC20.unlockByRecipientProxy(token, sender, recipient, secret, timeout); - } - function declineByRecipient(address token, address sender, bytes32 hashedSecret, uint timeout) external { acuityAtomicSwapERC20.declineByRecipient(token, sender, hashedSecret, timeout); } - function timeoutStashProxy(address token, address sender, address recipient, bytes32 hashedSecret, uint timeout, bytes32 stashAssetId) - external - { - acuityAtomicSwapERC20.timeoutStashProxy(token, sender, recipient, hashedSecret, timeout, stashAssetId); - } - - function timeoutValueProxy(address token, address sender, address recipient, bytes32 hashedSecret, uint timeout) - external - { - acuityAtomicSwapERC20.timeoutValueProxy(token, sender, recipient, hashedSecret, timeout); - } - } contract DummyToken is ERC20 { @@ -130,336 +90,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { dummyToken = new DummyToken(accounts); } - function testControlDepositStashZeroValue() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - } - - function testFailDepositStashZeroValue() public { - account0.depositStash(address(dummyToken), hex"1234", 0); - } - - function testDepositStash() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash(address(dummyToken), hex"1234", 50); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - account1.depositStash(address(dummyToken), hex"1234", 40); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account2.depositStash(address(dummyToken), hex"1234", 60); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - account3.depositStash(address(dummyToken), hex"1234", 45); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - account0.depositStash(address(dummyToken), hex"1234", 10); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 60); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - account0.depositStash(address(dummyToken), hex"1234", 1); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 61); - assertEq(accounts[1], address(account2)); - assertEq(values[1], 60); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - } - - function testControlWithdrawStashNotZero() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - account0.withdrawStash(address(dummyToken), hex"1234", 50); - } - - function testFailWithdrawStashNotZero() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - account0.withdrawStash(address(dummyToken), hex"1234", 0); - } - - function testControlWithdrawStashNotEnough() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - account0.withdrawStash(address(dummyToken), hex"1234", 50); - } - - function testFailWithdrawStashNotEnough() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - account0.withdrawStash(address(dummyToken), hex"1234", 51); - } - - function testWithdrawStash() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash(address(dummyToken), hex"1234", 50); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - uint startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStash(address(dummyToken), hex"1234", 2); - assertEq(startBalance + 2, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - - account1.depositStash(address(dummyToken), hex"1234", 40); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account2.depositStash(address(dummyToken), hex"1234", 60); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 48); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - account3.depositStash(address(dummyToken), hex"1234", 45); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 48); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - startBalance = dummyToken.balanceOf(address(account2)); - account2.withdrawStash(address(dummyToken), hex"1234", 40); - assertEq(startBalance + 40, dummyToken.balanceOf(address(account2))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 48); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - assertEq(accounts[3], address(account2)); - assertEq(values[3], 20); - - startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStash(address(dummyToken), hex"1234", 3); - assertEq(startBalance + 3, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - assertEq(accounts[3], address(account2)); - assertEq(values[3], 20); - - startBalance = dummyToken.balanceOf(address(account2)); - account2.withdrawStash(address(dummyToken), hex"1234", 20); - assertEq(startBalance + 20, dummyToken.balanceOf(address(account2))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - startBalance = dummyToken.balanceOf(address(account3)); - account3.withdrawStash(address(dummyToken), hex"1234", 45); - assertEq(startBalance + 45, dummyToken.balanceOf(address(account3))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStash(address(dummyToken), hex"1234", 45); - assertEq(startBalance + 45, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = dummyToken.balanceOf(address(account1)); - account1.withdrawStash(address(dummyToken), hex"1234", 40); - assertEq(startBalance + 40, dummyToken.balanceOf(address(account1))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - - function testWithdrawStashAll() public { - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account0.depositStash(address(dummyToken), hex"1234", 50); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - uint startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance + 50, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - account1.depositStash(address(dummyToken), hex"1234", 40); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - account2.depositStash(address(dummyToken), hex"1234", 60); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - account3.depositStash(address(dummyToken), hex"1234", 45); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - startBalance = dummyToken.balanceOf(address(account2)); - account2.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance + 60, dummyToken.balanceOf(address(account2))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = dummyToken.balanceOf(address(account2)); - account2.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance, dummyToken.balanceOf(address(account2))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - startBalance = dummyToken.balanceOf(address(account3)); - account3.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance + 45, dummyToken.balanceOf(address(account3))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = dummyToken.balanceOf(address(account0)); - account0.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance, dummyToken.balanceOf(address(account0))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - startBalance = dummyToken.balanceOf(address(account1)); - account1.withdrawStashAll(address(dummyToken), hex"1234"); - assertEq(startBalance + 40, dummyToken.balanceOf(address(account1))); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 50); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - function testControlLockBuyZeroValue() public { acuityAtomicSwapERC20.lockBuy(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", 1, 1); } @@ -489,39 +119,21 @@ contract AcuityAtomicSwapERC20Test is DSTest { } function testControlLockSellZeroValue() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); + acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", 50, hex"1234"); } function testFailLockSellZeroValue() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", 0, hex"1234"); } - function testControlLockSellNotBigEnough() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellNotBigEnough() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value + 1, hex"1234"); - } - function testControlLockSellLockAlreadyExists() public { uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value * 2); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"3456", block.timestamp + 1, hex"1234", value, hex"1234"); } function testFailLockSellLockAlreadyExists() public { uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value * 2); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); } @@ -533,88 +145,13 @@ contract AcuityAtomicSwapERC20Test is DSTest { uint timeout = block.timestamp + 1; uint value = 10; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, hex"1234", value, hex"1234"); - - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 40); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - } - - function testControlLockSellProxyInvalidProxy() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyInvalidProxy() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testControlLockSellProxyZeroValue() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyZeroValue() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", 0, hex"1234"); - } - - function testControlLockSellProxyNotBigEnough() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyNotBigEnough() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value + 1, hex"1234"); - } - - function testControlLockSellProxyLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value * 2); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"3456", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testFailLockSellProxyLockAlreadyExists() public { - uint value = 50; - acuityAtomicSwapERC20.depositStash(address(dummyToken), hex"1234", value * 2); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hex"1234", block.timestamp + 1, hex"1234", value, hex"1234"); - } - - function testLockSellProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"1234"; - bytes32 hashedSecret = keccak256(abi.encodePacked(secret)); - uint timeout = block.timestamp + 1; - uint value = 10; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - acuityAccount.setProxyAccount(address(account1)); - account1.lockSellProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, hex"1234", value, hex"1234"); + acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 40); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); } function testControlDeclineByRecipientLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; @@ -625,7 +162,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testFailDeclineByRecipientLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; @@ -637,7 +173,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testDeclineByRecipient() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; uint value = 10; @@ -645,11 +180,11 @@ contract AcuityAtomicSwapERC20Test is DSTest { acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 10); uint startBalance = dummyToken.balanceOf(address(this)); account0.declineByRecipient(address(dummyToken), address(this), hashedSecret, timeout); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 40); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 0); assertEq(dummyToken.balanceOf(address(this)), startBalance + value); } @@ -659,7 +194,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); } @@ -670,7 +204,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); @@ -682,7 +215,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); } @@ -693,14 +225,12 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); } function testUnlockBySender() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; @@ -709,11 +239,11 @@ contract AcuityAtomicSwapERC20Test is DSTest { acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 10); uint startBalance = dummyToken.balanceOf(address(account0)); acuityAtomicSwapERC20.unlockBySender(address(dummyToken), address(account0), secret, timeout); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 40); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 0); assertEq(dummyToken.balanceOf(address(account0)), startBalance + 10); } @@ -723,7 +253,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); } @@ -734,7 +263,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); @@ -746,7 +274,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); } @@ -757,14 +284,12 @@ contract AcuityAtomicSwapERC20Test is DSTest { bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); } function testUnlockByRecipient() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; @@ -773,281 +298,16 @@ contract AcuityAtomicSwapERC20Test is DSTest { acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 10); uint startBalance = dummyToken.balanceOf(address(account0)); account0.unlockByRecipient(address(dummyToken), address(this), secret, timeout); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 40); - assertEq(dummyToken.balanceOf(address(account0)), startBalance + 10); - } - - function testControlUnlockByRecipientProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testControlUnlockByRecipientProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testControlUnlockByRecipientProxyTimedOut() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testFailUnlockByRecipientProxyTimedOut() public { - bytes32 assetId = hex"1234"; - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 10); - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - } - - function testUnlockByRecipientProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - bytes32 secret = hex"4b1694df15172648181bcb37868b25d3bd9ff95d0f10ec150f783802a81a07fb"; - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - uint value = 10; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); - uint startBalance = dummyToken.balanceOf(address(account0)); - account0.setProxyAccount(address(account1)); - account1.unlockByRecipientProxy(address(dummyToken), address(this), address(account0), secret, timeout); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 40); + assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 0); assertEq(dummyToken.balanceOf(address(account0)), startBalance + 10); } - function testControlTimeoutStashLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - } - - function testTimeoutStash() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - acuityAtomicSwapERC20.timeoutStash(address(dummyToken), address(account0), hashedSecret, timeout, assetId); - - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 50); - } - - function testControlTimeoutStashProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testControlTimeoutStashProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testFailTimeoutStashProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - } - - function testTimeoutStashProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutStashProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout, assetId); - - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), 0); - assertEq(dummyToken.balanceOf(address(acuityAtomicSwapERC20)), 50); - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 50); - } - function testControlTimeoutValueLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; @@ -1058,7 +318,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testFailTimeoutValueLockNotFound() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; @@ -1070,7 +329,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testControlTimeoutValueNotTimedOut() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; @@ -1081,7 +339,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testFailTimeoutValueNotTimedOut() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp + 1; @@ -1092,8 +349,6 @@ contract AcuityAtomicSwapERC20Test is DSTest { function testTimeoutValue() public { bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 50); bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; uint timeout = block.timestamp; @@ -1102,256 +357,9 @@ contract AcuityAtomicSwapERC20Test is DSTest { acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - uint startBalance = dummyToken.balanceOf(address(this)); acuityAtomicSwapERC20.timeoutValue(address(dummyToken), address(account0), hashedSecret, timeout); assertEq(dummyToken.balanceOf(address(this)), startBalance + value); } - function testControlTimeoutValueProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyInvalidProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testControlTimeoutValueProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyLockNotFound() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testControlTimeoutValueProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testFailTimeoutValueProxyNotTimedOut() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp + 1; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, 10, hex"1234"); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - } - - function testTimeoutValueProxy() public { - bytes32 assetId = hex"1234"; - acuityAtomicSwapERC20.depositStash(address(dummyToken), assetId, 50); - assertEq(acuityAtomicSwapERC20.getStashValue(address(dummyToken), assetId, address(this)), 50); - - bytes32 hashedSecret = hex"094cd46013683e3929f474bf04e9ff626a6d7332c195dfe014e4b4a3fbb3ea54"; - uint timeout = block.timestamp; - uint value = 10; - - acuityAtomicSwapERC20.lockSell(address(dummyToken), address(account0), hashedSecret, timeout, assetId, value, hex"1234"); - assertEq(acuityAtomicSwapERC20.getLockValue(address(dummyToken), address(this), address(account0), hashedSecret, timeout), value); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), assetId, 0, 50); - assertEq(accounts.length, 1); - assertEq(accounts[0], address(this)); - assertEq(values[0], 40); - - uint startBalance = dummyToken.balanceOf(address(this)); - acuityAccount.setProxyAccount(address(account1)); - account1.timeoutValueProxy(address(dummyToken), address(this), address(account0), hashedSecret, timeout); - assertEq(dummyToken.balanceOf(address(this)), startBalance + value); - } - - function testGetStashes() public { - account0.depositStash(address(dummyToken), hex"1234", 50); - account1.depositStash(address(dummyToken), hex"1234", 40); - account2.depositStash(address(dummyToken), hex"1234", 60); - account3.depositStash(address(dummyToken), hex"1234", 45); - - (address[] memory accounts, uint[] memory values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 3); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 4); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 0, 5); - assertEq(accounts.length, 4); - assertEq(values.length, 4); - assertEq(accounts[0], address(account2)); - assertEq(values[0], 60); - assertEq(accounts[1], address(account0)); - assertEq(values[1], 50); - assertEq(accounts[2], address(account3)); - assertEq(values[2], 45); - assertEq(accounts[3], address(account1)); - assertEq(values[3], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 1, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 1, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 1, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 1, 3); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 1, 4); - assertEq(accounts.length, 3); - assertEq(values.length, 3); - assertEq(accounts[0], address(account0)); - assertEq(values[0], 50); - assertEq(accounts[1], address(account3)); - assertEq(values[1], 45); - assertEq(accounts[2], address(account1)); - assertEq(values[2], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 2, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 2, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 2, 2); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 2, 3); - assertEq(accounts.length, 2); - assertEq(values.length, 2); - assertEq(accounts[0], address(account3)); - assertEq(values[0], 45); - assertEq(accounts[1], address(account1)); - assertEq(values[1], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 3, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 3, 1); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 3, 2); - assertEq(accounts.length, 1); - assertEq(values.length, 1); - assertEq(accounts[0], address(account1)); - assertEq(values[0], 40); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 4, 0); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - - (accounts, values) = acuityAtomicSwapERC20.getStashes(address(dummyToken), hex"1234", 4, 1); - assertEq(accounts.length, 0); - assertEq(values.length, 0); - } - }