Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug auxo vault issues #42

Open
wants to merge 2 commits into
base: feature/beefy-strategy
Choose a base branch
from
Open
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
208 changes: 208 additions & 0 deletions test/debug/FixedPointMathLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*///////////////////////////////////////////////////////////////
COMMON BASE UNITS
//////////////////////////////////////////////////////////////*/

uint256 internal constant YAD = 1e8;
uint256 internal constant WAD = 1e18;
uint256 internal constant RAY = 1e27;
uint256 internal constant RAD = 1e45;

/*///////////////////////////////////////////////////////////////
FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/

function fmul(
uint256 x,
uint256 y,
uint256 baseUnit
) internal pure returns (uint256 z) {
assembly {
// Store x * y in z for now.
z := mul(x, y)

// Equivalent to require(x == 0 || (x * y) / x == y)
if iszero(or(iszero(x), eq(div(z, x), y))) {
revert(0, 0)
}

// If baseUnit is zero this will return zero instead of reverting.
z := div(z, baseUnit)
}
}

function fdiv(
uint256 x,
uint256 y,
uint256 baseUnit
) internal pure returns (uint256 z) {
assembly {
// Store x * baseUnit in z for now.
z := mul(x, baseUnit)

// Equivalent to require(y != 0 && (x == 0 || (x * baseUnit) / x == baseUnit))
if iszero(
and(iszero(iszero(y)), or(iszero(x), eq(div(z, x), baseUnit)))
) {
revert(0, 0)
}

// We ensure y is not zero above, so there is never division by zero here.
z := div(z, y)
}
}

function fpow(
uint256 x,
uint256 n,
uint256 baseUnit
) internal pure returns (uint256 z) {
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := baseUnit
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store baseUnit in z for now.
z := baseUnit
}
default {
// If n is odd, store x in z for now.
z := x
}

// Shifting right by 1 is like dividing by 2.
let half := shr(1, baseUnit)

for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}

// Store x squared.
let xx := mul(x, x)

// Round to the nearest number.
let xxRound := add(xx, half)

// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}

// Set x to scaled xxRound.
x := div(xxRound, baseUnit)

// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)

// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}

// Round to the nearest number.
let zxRound := add(zx, half)

// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}

// Return properly scaled zxRound.
z := div(zxRound, baseUnit)
}
}
}
}
}

/*///////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/

function sqrt(uint256 x) internal pure returns (uint256 z) {
assembly {
// Start off with z at 1.
z := 1

// Used below to help find a nearby power of 2.
let y := x

// Find the lowest power of 2 that is at least sqrt(x).
if iszero(lt(y, 0x100000000000000000000000000000000)) {
y := shr(128, y) // Like dividing by 2 ** 128.
z := shl(64, z)
}
if iszero(lt(y, 0x10000000000000000)) {
y := shr(64, y) // Like dividing by 2 ** 64.
z := shl(32, z)
}
if iszero(lt(y, 0x100000000)) {
y := shr(32, y) // Like dividing by 2 ** 32.
z := shl(16, z)
}
if iszero(lt(y, 0x10000)) {
y := shr(16, y) // Like dividing by 2 ** 16.
z := shl(8, z)
}
if iszero(lt(y, 0x100)) {
y := shr(8, y) // Like dividing by 2 ** 8.
z := shl(4, z)
}
if iszero(lt(y, 0x10)) {
y := shr(4, y) // Like dividing by 2 ** 4.
z := shl(2, z)
}
if iszero(lt(y, 0x8)) {
// Equivalent to 2 ** z.
z := shl(1, z)
}

// Shifting right by 1 is like dividing by 2.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))

// Compute a rounded down version of z.
let zRoundDown := div(x, z)

// If zRoundDown is smaller, use it.
if lt(zRoundDown, z) {
z := zRoundDown
}
}
}
}
56 changes: 56 additions & 0 deletions test/debug/IStrategy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.10;

import {IERC20Upgradeable as IERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

import {IVault} from "@interfaces/IVault.sol";

/// @title IStrategy
/// @notice Basic Vault Strategy interface.
interface IStrategy {
/*///////////////////////////////////////////////////////////////
GENERAL INFO
//////////////////////////////////////////////////////////////*/

/// @notice The strategy name.
function name() external view returns (string calldata);

/// @notice The Vault managing this strategy.
function vault() external view returns (IVault);

/*///////////////////////////////////////////////////////////////
DEPOSIT/WITHDRAW
//////////////////////////////////////////////////////////////*/

/// @notice Deposit a specific amount of underlying tokens.
function deposit(uint256) external returns (uint8);

/// @notice Withdraw a specific amount of underlying tokens.
function withdraw(uint256) external returns (uint8);

/*///////////////////////////////////////////////////////////////
DEPOSIT/WITHDRAW UNDERLYING
//////////////////////////////////////////////////////////////*/

/// @notice Deposit underlying in strategy's yielding option.
function depositUnderlying(uint256) external;

/// @notice Withdraw underlying from strategy's yielding option.
function withdrawUnderlying(uint256) external;

/*///////////////////////////////////////////////////////////////
ACCOUNTING
//////////////////////////////////////////////////////////////*/

/// @notice Float amount of underlying tokens.
function float() external view returns (uint256);

/// @notice The underlying token the strategy accepts.
function underlying() external view returns (IERC20);

/// @notice The amount deposited by the Vault in this strategy.
function depositedUnderlying() external returns (uint256);

/// @notice An estimate amount of underlying managed by the strategy.
function estimatedUnderlying() external returns (uint256);
}
31 changes: 31 additions & 0 deletions test/debug/IVaultAuth.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.10;

import {IVault} from "@interfaces/IVault.sol";

/// @title IVaultAuth
interface IVaultAuth {
/// @dev Determines whether `caller` is authorized to deposit in `vault`.
/// @param vault The Vault checking for authorization.
/// @param caller The address of caller.
/// @return true when `caller` is an authorized depositor for `vault`, otherwise false.
function isDepositor(IVault vault, address caller)
external
view
returns (bool);

/// @dev Determines whether `caller` is authorized to harvest for `vault`.
/// @param vault The vault checking for authorization.
/// @param caller The address of caller.
/// @return true when `caller` is authorized for `vault`, otherwise false.
function isHarvester(IVault vault, address caller)
external
view
returns (bool);

/// @dev Determines whether `caller` is authorized to call administration methods on `vault`.
/// @param vault The vault checking for authorization.
/// @param caller The address of caller.
/// @return true when `caller` is authorized for `vault`, otherwise false.
function isAdmin(IVault vault, address caller) external view returns (bool);
}
37 changes: 37 additions & 0 deletions test/debug/SafeCastLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Safe unsigned integer casting library that reverts on overflow.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeCastLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
library SafeCastLib {
function safeCastTo248(uint256 x) internal pure returns (uint248 y) {
require(x <= type(uint248).max);

y = uint248(x);
}

function safeCastTo128(uint256 x) internal pure returns (uint128 y) {
require(x <= type(uint128).max);

y = uint128(x);
}

function safeCastTo96(uint256 x) internal pure returns (uint96 y) {
require(x <= type(uint96).max);

y = uint96(x);
}

function safeCastTo64(uint256 x) internal pure returns (uint64 y) {
require(x <= type(uint64).max);

y = uint64(x);
}

function safeCastTo32(uint256 x) internal pure returns (uint32 y) {
require(x <= type(uint32).max);

y = uint32(x);
}
}
Loading