Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/VaultVotes.sol/VaultVotes.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/v1.1/VaultTokenized.sol/VaultTokenized.json

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/contracts/vault/v1.1/VaultTokenizedImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract VaultTokenizedImplementation is
function deposit(
address onBehalfOf,
uint256 amount
) external returns (uint256 depositedAmount, uint256 mintedShares) {
) public virtual returns (uint256 depositedAmount, uint256 mintedShares) {
(depositedAmount, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.deposit, (onBehalfOf, amount))),
(uint256, uint256)
Expand All @@ -70,7 +70,10 @@ contract VaultTokenizedImplementation is
emit Transfer(address(0), onBehalfOf, mintedShares);
}

function withdraw(address claimer, uint256 amount) external returns (uint256 burnedShares, uint256 mintedShares) {
function withdraw(
address claimer,
uint256 amount
) public virtual returns (uint256 burnedShares, uint256 mintedShares) {
(burnedShares, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.withdraw, (claimer, amount))),
(uint256, uint256)
Expand All @@ -79,7 +82,10 @@ contract VaultTokenizedImplementation is
emit Transfer(msg.sender, address(0), burnedShares);
}

function redeem(address claimer, uint256 shares) external returns (uint256 withdrawnAssets, uint256 mintedShares) {
function redeem(
address claimer,
uint256 shares
) public virtual returns (uint256 withdrawnAssets, uint256 mintedShares) {
(withdrawnAssets, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.redeem, (claimer, shares))),
(uint256, uint256)
Expand All @@ -91,7 +97,7 @@ contract VaultTokenizedImplementation is
/**
* @inheritdoc ERC20Upgradeable
*/
function _update(address from, address to, uint256 value) internal override {
function _update(address from, address to, uint256 value) internal virtual override {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_activeShares.push(Time.timestamp(), totalSupply() + value);
Expand Down
58 changes: 17 additions & 41 deletions src/contracts/vault/v1.1/VaultVotesImplementation.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {VaultStorage} from "./VaultStorage.sol";
import {VaultTokenizedImplementation} from "src/contracts/vault/v1.1/VaultTokenizedImplementation.sol";

import {IVault} from "../../../interfaces/vault/v1.1/IVault.sol";
import {IVaultVotes} from "../../../interfaces/vault/v1.1/IVaultVotes.sol";
Expand All @@ -17,20 +17,15 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {VotesUpgradeable} from "@openzeppelin/contracts-upgradeable/governance/utils/VotesUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract VaultVotesImplementation is VaultStorage, VotesUpgradeable, Proxy, IVaultVotes {
contract VaultVotesImplementation is VaultTokenizedImplementation, VotesUpgradeable, IVaultVotes {
using Checkpoints for Checkpoints.Trace208;
using Checkpoints for Checkpoints.Trace256;
using Address for address;

address private immutable BASE_IMPLEMENTATION;

constructor(
address baseImplementation
) {
BASE_IMPLEMENTATION = baseImplementation;
}
) VaultTokenizedImplementation(baseImplementation) {}

/**
* @inheritdoc IERC6372
Expand Down Expand Up @@ -62,11 +57,8 @@ contract VaultVotesImplementation is VaultStorage, VotesUpgradeable, Proxy, IVau
function deposit(
address onBehalfOf,
uint256 amount
) external returns (uint256 depositedAmount, uint256 mintedShares) {
(depositedAmount, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.deposit, (onBehalfOf, amount))),
(uint256, uint256)
);
) public override returns (uint256 depositedAmount, uint256 mintedShares) {
(depositedAmount, mintedShares) = super.deposit(onBehalfOf, amount);

if (_activeShares.latest() > type(uint208).max) {
revert SafeSupplyExceeded();
Expand All @@ -75,35 +67,26 @@ contract VaultVotesImplementation is VaultStorage, VotesUpgradeable, Proxy, IVau
_transferVotingUnits(address(0), onBehalfOf, mintedShares);
}

function withdraw(address claimer, uint256 amount) external returns (uint256 burnedShares, uint256 mintedShares) {
(burnedShares, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.withdraw, (claimer, amount))),
(uint256, uint256)
);
function withdraw(
address claimer,
uint256 amount
) public override returns (uint256 burnedShares, uint256 mintedShares) {
(burnedShares, mintedShares) = super.withdraw(claimer, amount);

_transferVotingUnits(msg.sender, address(0), burnedShares);
}

function redeem(address claimer, uint256 shares) external returns (uint256 withdrawnAssets, uint256 mintedShares) {
(withdrawnAssets, mintedShares) = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IVault.redeem, (claimer, shares))),
(uint256, uint256)
);
function redeem(
address claimer,
uint256 shares
) public override returns (uint256 withdrawnAssets, uint256 mintedShares) {
(withdrawnAssets, mintedShares) = super.redeem(claimer, shares);

_transferVotingUnits(msg.sender, address(0), shares);
}

function transfer(address to, uint256 value) external returns (bool result) {
result =
abi.decode(BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transfer, (to, value))), (bool));

_transferVotingUnits(msg.sender, to, value);
}

function transferFrom(address from, address to, uint256 value) external returns (bool result) {
result = abi.decode(
BASE_IMPLEMENTATION.functionDelegateCall(abi.encodeCall(IERC20.transferFrom, (from, to, value))), (bool)
);
function _update(address from, address to, uint256 value) internal override {
super._update(from, to, value);

_transferVotingUnits(from, to, value);
}
Expand All @@ -124,13 +107,6 @@ contract VaultVotesImplementation is VaultStorage, VotesUpgradeable, Proxy, IVau
return _activeSharesOf[account].latest();
}

/**
* @inheritdoc Proxy
*/
function _implementation() internal view override returns (address) {
return BASE_IMPLEMENTATION;
}

function _VaultVotes_init() external {
__EIP712_init("VaultVotes", "1");
}
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/vault/v1.1/IVaultVotes.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IVaultTokenized} from "./IVaultTokenized.sol";

import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";

interface IVaultVotes is IERC5805 {
interface IVaultVotes is IVaultTokenized, IERC5805 {
error InvalidOrigin();
error InvalidData();
error SafeSupplyExceeded();
Expand Down
2 changes: 1 addition & 1 deletion test/vault/v1.1/VaultVotes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ contract VaultVotesTest is Test {
address vaultTokenizedImpl = address(new VaultTokenized(address(vaultFactory), vaultTokenizedImplementation));
vaultFactory.whitelist(vaultTokenizedImpl);

address vaultVotesImplementation = address(new VaultVotesImplementation(vaultTokenizedImplementation));
address vaultVotesImplementation = address(new VaultVotesImplementation(vaultImplementation));
address vaultImpl = address(new VaultVotes(address(vaultFactory), vaultVotesImplementation));
vaultFactory.whitelist(vaultImpl);

Expand Down
Loading