Skip to content

Commit

Permalink
Merge pull request #19 from Giveth/fix-withdraw
Browse files Browse the repository at this point in the history
fix: withdraw from sender
  • Loading branch information
0xKurt authored Jun 5, 2023
2 parents 15800c7 + 0c88f5b commit e4435b3
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 9 deletions.
297 changes: 297 additions & 0 deletions WrappedVaults/.openzeppelin/optimism-goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,303 @@
}
}
}
},
"38f03b05202efd7b6367a2542d26ce36a0188240dc478b3dffbd7f06a02de725": {
"address": "0xd85E882fC3eC8a5e3F6A3fA70B55ca614C843f35",
"txHash": "0xda51117d2ac50e918453825d308e231f81d5f6e200de6aa268d06f7d9d381abb",
"layout": {
"solcVersion": "0.8.17",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:62",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"label": "_balances",
"offset": 0,
"slot": "51",
"type": "t_mapping(t_address,t_uint256)",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:37"
},
{
"label": "_allowances",
"offset": 0,
"slot": "52",
"type": "t_mapping(t_address,t_mapping(t_address,t_uint256))",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:39"
},
{
"label": "_totalSupply",
"offset": 0,
"slot": "53",
"type": "t_uint256",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:41"
},
{
"label": "_name",
"offset": 0,
"slot": "54",
"type": "t_string_storage",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:43"
},
{
"label": "_symbol",
"offset": 0,
"slot": "55",
"type": "t_string_storage",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:44"
},
{
"label": "__gap",
"offset": 0,
"slot": "56",
"type": "t_array(t_uint256)45_storage",
"contract": "ERC20Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:400"
},
{
"label": "_HASHED_NAME",
"offset": 0,
"slot": "101",
"type": "t_bytes32",
"contract": "EIP712Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:32"
},
{
"label": "_HASHED_VERSION",
"offset": 0,
"slot": "102",
"type": "t_bytes32",
"contract": "EIP712Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:33"
},
{
"label": "__gap",
"offset": 0,
"slot": "103",
"type": "t_array(t_uint256)50_storage",
"contract": "EIP712Upgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:120"
},
{
"label": "_nonces",
"offset": 0,
"slot": "153",
"type": "t_mapping(t_address,t_struct(Counter)1442_storage)",
"contract": "ERC20PermitUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol:28"
},
{
"label": "_PERMIT_TYPEHASH_DEPRECATED_SLOT",
"offset": 0,
"slot": "154",
"type": "t_bytes32",
"contract": "ERC20PermitUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol:40",
"renamedFrom": "_PERMIT_TYPEHASH"
},
{
"label": "__gap",
"offset": 0,
"slot": "155",
"type": "t_array(t_uint256)49_storage",
"contract": "ERC20PermitUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol:108"
},
{
"label": "token",
"offset": 0,
"slot": "204",
"type": "t_contract(IERC20Upgradeable)858",
"contract": "WrappedPositionUpgradeable",
"src": "contracts/element-fi/WrappedPositionUpgradeable.sol:16"
},
{
"label": "_decimals",
"offset": 20,
"slot": "204",
"type": "t_uint8",
"contract": "WrappedPositionUpgradeable",
"src": "contracts/element-fi/WrappedPositionUpgradeable.sol:17"
},
{
"label": "owner",
"offset": 0,
"slot": "205",
"type": "t_address",
"contract": "Authorizable",
"src": "contracts/element-fi/libraries/AuthorizableUpgradeable.sol:8"
},
{
"label": "authorized",
"offset": 0,
"slot": "206",
"type": "t_mapping(t_address,t_bool)",
"contract": "Authorizable",
"src": "contracts/element-fi/libraries/AuthorizableUpgradeable.sol:10"
},
{
"label": "vault",
"offset": 0,
"slot": "207",
"type": "t_contract(IBeefyV6)3880",
"contract": "BeefyV6AssetProxyUpgradeable",
"src": "contracts/BeefyV6AssetProxyUpgradeable.sol:15"
},
{
"label": "conversionRate",
"offset": 20,
"slot": "207",
"type": "t_uint88",
"contract": "BeefyV6AssetProxyUpgradeable",
"src": "contracts/BeefyV6AssetProxyUpgradeable.sol:18"
},
{
"label": "paused",
"offset": 31,
"slot": "207",
"type": "t_bool",
"contract": "BeefyV6AssetProxyUpgradeable",
"src": "contracts/BeefyV6AssetProxyUpgradeable.sol:20"
},
{
"label": "vaultDecimals",
"offset": 0,
"slot": "208",
"type": "t_uint8",
"contract": "BeefyV6AssetProxyUpgradeable",
"src": "contracts/BeefyV6AssetProxyUpgradeable.sol:21"
},
{
"label": "fee",
"offset": 0,
"slot": "209",
"type": "t_uint256",
"contract": "GIVfiWrappedBeefyV6VaultUpgradeable",
"src": "contracts/GIVfiWrappedBeefyV6VaultUpgradeable.sol:12"
},
{
"label": "feeRecipient",
"offset": 0,
"slot": "210",
"type": "t_address",
"contract": "GIVfiWrappedBeefyV6VaultUpgradeable",
"src": "contracts/GIVfiWrappedBeefyV6VaultUpgradeable.sol:13"
},
{
"label": "balanceSnapshots",
"offset": 0,
"slot": "211",
"type": "t_mapping(t_address,t_uint256)",
"contract": "GIVfiWrappedBeefyV6VaultUpgradeable",
"src": "contracts/GIVfiWrappedBeefyV6VaultUpgradeable.sol:15"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_uint256)45_storage": {
"label": "uint256[45]",
"numberOfBytes": "1440"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_bytes32": {
"label": "bytes32",
"numberOfBytes": "32"
},
"t_contract(IBeefyV6)3880": {
"label": "contract IBeefyV6",
"numberOfBytes": "20"
},
"t_contract(IERC20Upgradeable)858": {
"label": "contract IERC20Upgradeable",
"numberOfBytes": "20"
},
"t_mapping(t_address,t_bool)": {
"label": "mapping(address => bool)",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_mapping(t_address,t_uint256))": {
"label": "mapping(address => mapping(address => uint256))",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_struct(Counter)1442_storage)": {
"label": "mapping(address => struct CountersUpgradeable.Counter)",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_uint256)": {
"label": "mapping(address => uint256)",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(Counter)1442_storage": {
"label": "struct CountersUpgradeable.Counter",
"members": [
{
"label": "_value",
"type": "t_uint256",
"offset": 0,
"slot": "0"
}
],
"numberOfBytes": "32"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
},
"t_uint88": {
"label": "uint88",
"numberOfBytes": "11"
}
}
}
}
}
}
18 changes: 9 additions & 9 deletions WrappedVaults/contracts/GIVfiWrappedBeefyV6VaultUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ contract GIVfiWrappedBeefyV6VaultUpgradeable is
feeRecipient = _feeRecipient;
}

modifier handleFeeOnInterest(address _destination) {
uint256 underlyingBalance = _underlying(balanceOf(_destination));
uint256 balanceSnapshot = balanceSnapshots[_destination];
modifier handleFeeOnInterest(address _account) {
uint256 underlyingBalance = _underlying(balanceOf(_account));
uint256 balanceSnapshot = balanceSnapshots[_account];
uint256 accruedInterest = 0;

// check if user has accrued interest (deposited amount - underlying balance)
Expand All @@ -52,9 +52,9 @@ contract GIVfiWrappedBeefyV6VaultUpgradeable is
// burn fee shares from _destination
if (feeInShares > 0) {
_mint(feeRecipient, feeInShares);
_burn(_destination, feeInShares);
_burn(_account, feeInShares);
emit FeesPaid(
_destination,
_account,
feeRecipient,
feeInShares,
feeAmount
Expand All @@ -63,7 +63,7 @@ contract GIVfiWrappedBeefyV6VaultUpgradeable is
}

_;
balanceSnapshots[_destination] = _underlying(balanceOf(_destination));
balanceSnapshots[_account] = _underlying(balanceOf(_account));
}

function deposit(
Expand All @@ -84,14 +84,14 @@ contract GIVfiWrappedBeefyV6VaultUpgradeable is
)
internal
override
handleFeeOnInterest(_destination)
handleFeeOnInterest(msg.sender)
returns (uint256 withdrawAmount)
{
uint256 shares = _shares;

// if shares are greater than balance (because of fee deduction), withdraw all
if (shares > balanceOf(_destination)) {
shares = balanceOf(_destination);
if (shares > balanceOf(msg.sender)) {
shares = balanceOf(msg.sender);
}

withdrawAmount = super._positionWithdraw(
Expand Down

0 comments on commit e4435b3

Please sign in to comment.