Skip to content

Commit

Permalink
Merge pull request #44 from niftyhorde/nmlinaric/fix-contract
Browse files Browse the repository at this point in the history
Bugfixing
  • Loading branch information
nmlinaric authored Nov 4, 2021
2 parents 050ef86 + 90dadce commit 983e1c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions contracts/SwapKiwi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ contract SwapKiwi is Ownable, IERC721Receiver {

uint256 public fee;

mapping (address => uint256) private _balances;
mapping (uint256 => Swap) private _swaps;

struct Swap {
Expand Down Expand Up @@ -46,6 +45,9 @@ contract SwapKiwi is Ownable, IERC721Receiver {
uint256[] nftIds,
uint256 etherValue
);
event AppFeeChanged(
uint256 fee
);

modifier onlyInitiator(uint256 swapId) {
require(msg.sender == _swaps[swapId].initiator,
Expand All @@ -68,8 +70,9 @@ contract SwapKiwi is Ownable, IERC721Receiver {
super.transferOwnership(contractOwnerAddress);
}

function setAppFee(uint newFee) public onlyOwner {
function setAppFee(uint newFee) external onlyOwner {
fee = newFee;
emit AppFeeChanged(newFee);
}

/**
Expand Down Expand Up @@ -180,11 +183,15 @@ contract SwapKiwi is Ownable, IERC721Receiver {

if (_swaps[swapId].initiatorEtherValue != 0) {
_etherLocked -= _swaps[swapId].initiatorEtherValue;
_swaps[swapId].secondUser.transfer(_swaps[swapId].initiatorEtherValue);
uint amountToTransfer = _swaps[swapId].initiatorEtherValue;
_swaps[swapId].initiatorEtherValue = 0;
_swaps[swapId].secondUser.transfer(amountToTransfer);
}
if (_swaps[swapId].secondUserEtherValue != 0) {
_etherLocked -= _swaps[swapId].secondUserEtherValue;
_swaps[swapId].initiator.transfer(_swaps[swapId].secondUserEtherValue);
uint amountToTransfer = _swaps[swapId].secondUserEtherValue;
_swaps[swapId].secondUserEtherValue = 0;
_swaps[swapId].initiator.transfer(amountToTransfer);
}

emit SwapExecuted(_swaps[swapId].initiator, _swaps[swapId].secondUser, swapId);
Expand Down Expand Up @@ -223,14 +230,17 @@ contract SwapKiwi is Ownable, IERC721Receiver {

if (_swaps[swapId].initiatorEtherValue != 0) {
_etherLocked -= _swaps[swapId].initiatorEtherValue;
_swaps[swapId].initiator.transfer(_swaps[swapId].initiatorEtherValue);
uint amountToTransfer = _swaps[swapId].initiatorEtherValue;
_swaps[swapId].initiatorEtherValue = 0;
_swaps[swapId].initiator.transfer(amountToTransfer);
}
if (_swaps[swapId].secondUserEtherValue != 0) {
_etherLocked -= _swaps[swapId].secondUserEtherValue;
_swaps[swapId].secondUser.transfer(_swaps[swapId].secondUserEtherValue);
uint amountToTransfer = _swaps[swapId].secondUserEtherValue;
_swaps[swapId].secondUserEtherValue = 0;
_swaps[swapId].secondUser.transfer(amountToTransfer);
}


emit SwapCanceled(msg.sender, swapId);

delete _swaps[swapId];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@niftyhorde/swap-kiwi-contracts",
"version": "0.5.0-beta",
"version": "0.6.0-beta",
"private": false,
"repository": {
"url": "[email protected]:niftyhorde/swap.kiwi.git",
Expand Down

0 comments on commit 983e1c1

Please sign in to comment.