Skip to content

Commit

Permalink
Remove fromStake
Browse files Browse the repository at this point in the history
  • Loading branch information
pouya-eghbali committed Apr 4, 2024
1 parent 5f8b49b commit da37fde
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
uint256 amount;
uint256[] nftIds;
uint256 voted;
bool fromStake;
bool accepted;
uint256[] nonces;
}
Expand Down Expand Up @@ -102,7 +101,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
uint256 amount;
uint256[] nftIds;
uint256[] nonces;
bool fromStake;
}

struct EIP712TransferKey {
Expand All @@ -111,7 +109,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
uint256 amount;
uint256[] nftIds;
uint256[] nonces;
bool fromStake;
}

struct EIP712SetParams {
Expand Down Expand Up @@ -184,12 +181,12 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {

bytes32 constant EIP712_TRANSFER_TYPEHASH =
keccak256(
"EIP712Transfer(address signer,address from,address to,uint256 amount,uint256[] nftIds,uint256[] nonces,bool fromStake)"
"EIP712Transfer(address signer,address from,address to,uint256 amount,uint256[] nftIds,uint256[] nonces)"
);

bytes32 constant EIP712_TRANSFER_KEY_TYPEHASH =
keccak256(
"EIP712TransferKey(address from,address to,uint256 amount,uint256[] nonces,bool fromStake)"
"EIP712TransferKey(address from,address to,uint256 amount,uint256[] nonces)"
);

bytes32 constant EIP712_SET_SIGNER_TYPEHASH =
Expand Down Expand Up @@ -220,7 +217,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
uint256 private _votingTopicExpiration = 1 days;
uint256 private _totalVotingPower;

mapping(address => uint256) private _balances;
mapping(address => Stake) private _stakes;
mapping(bytes32 => Transfer) private _transfers;

Expand Down Expand Up @@ -389,8 +385,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
eip712Transfer.to,
eip712Transfer.amount,
keccak256(abi.encodePacked(eip712Transfer.nftIds)),
keccak256(abi.encodePacked(eip712Transfer.nonces)),
eip712Transfer.fromStake
keccak256(abi.encodePacked(eip712Transfer.nonces))
)
);
}
Expand All @@ -411,8 +406,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
key.to,
key.amount,
keccak256(abi.encodePacked(key.nftIds)),
keccak256(abi.encodePacked(key.nonces)),
key.fromStake
keccak256(abi.encodePacked(key.nonces))
)
);
}
Expand Down Expand Up @@ -540,16 +534,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
);
}

/**
* Allows transfering tokens to the Unchained Network.
* @param amount The amount of tokens to transfer to the Unchained Network.
*/
function transferIn(uint256 amount) external {
_token.safeTransferFrom(_msgSender(), address(this), amount);
_balances[_msgSender()] += amount;
emit TransferIn(_msgSender(), amount);
}

/**
* @dev Called by a user to stake their tokens along with NFTs if desired.
* @param duration The duration for which the tokens and NFTs are staked.
Expand Down Expand Up @@ -930,8 +914,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
eip712Transfer.to,
eip712Transfer.amount,
eip712Transfer.nftIds,
eip712Transfer.nonces,
eip712Transfer.fromStake
eip712Transfer.nonces
);

bytes32 eipHash = hash(transferKey);
Expand Down Expand Up @@ -975,7 +958,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
transferData.info.from = eip712Transfer.from;
transferData.info.to = eip712Transfer.to;
transferData.info.nonces = eip712Transfer.nonces;
transferData.info.fromStake = eip712Transfer.fromStake;
transferData.info.voted += updateGetVotingPower(userStake);

if (transferData.info.accepted) {
Expand All @@ -986,22 +968,13 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
burnTransferNonces(i, eip712Transfer.to, eip712Transfer.nonces);
transferData.info.accepted = true;

if (transferData.info.fromStake) {
_totalVotingPower -= eip712Transfer.amount;
_stakes[eip712Transfer.from].amount -= eip712Transfer
.amount;
} else {
_balances[eip712Transfer.from] -= eip712Transfer.amount;
}
_totalVotingPower -= eip712Transfer.amount;
_stakes[eip712Transfer.from].amount -= eip712Transfer.amount;

if (transferData.info.to != address(this)) {
_token.safeTransfer(
transferData.info.to,
transferData.info.amount
);
} else {
_balances[address(this)] += eip712Transfer.amount;
}
_token.safeTransfer(
transferData.info.to,
transferData.info.amount
);

for (uint256 n = 0; n < transferData.info.nftIds.length; n++) {
uint256 nftId = transferData.info.nftIds[n];
Expand Down

0 comments on commit da37fde

Please sign in to comment.