generated from PaulRBerg/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Tenderize/nv/uups
feat: UUPS upgradeable
- Loading branch information
Showing
8 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule openzeppelin-contracts-upgradeable
added at
65420c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import { Script, console2 } from "forge-std/Script.sol"; | ||
import { ERC20 } from "solmate/tokens/ERC20.sol"; | ||
import { TenderSwap, Config } from "@tenderize/swap/Swap.sol"; | ||
import { SD59x18 } from "@prb/math/SD59x18.sol"; | ||
import { Tenderizer } from "@tenderize/stake/tenderizer/Tenderizer.sol"; | ||
import { StakingXYZ } from "lib/staking/test/helpers/StakingXYZ.sol"; | ||
|
||
contract Stats is Script { | ||
function run() public { | ||
address tenderswap = vm.envAddress("TENDERSWAP"); | ||
TenderSwap swap = TenderSwap(tenderswap); | ||
console2.log( | ||
"staking xyz %s", | ||
StakingXYZ(0xd6d72408586887E37Cf299dbb50181892D3b184e).staked(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00) | ||
); | ||
console2.log("tenderizer asset %s", Tenderizer(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00).asset()); | ||
console2.log("tenderizer validator %s", Tenderizer(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00).validator()); | ||
|
||
console2.log( | ||
"tenderizer bal %s", | ||
Tenderizer(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00).balanceOf(0xF569CE1f749f073D6B85166141544288b3e24c2B) | ||
); | ||
|
||
console2.log("tenderizer supply %s", ERC20(address(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00)).totalSupply()); | ||
ERC20(address(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00)).approve(tenderswap, 1 ether); | ||
swap.swap(address(0xE3350e66D3850B4f4C97b6737E9e8Ff78CFC1b00), 1 ether, 0); | ||
uint256 liabilities = swap.liabilities(); | ||
uint256 liquidity = swap.liquidity(); | ||
SD59x18 utilisation = swap.utilisation(); | ||
|
||
console2.log("liabilities %s", liabilities); | ||
console2.log("liquidity %s", liquidity); | ||
console2.log("utilisation %s", utilisation.unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
UNIT = 1e18 | ||
BASE_FEE = 0.005 | ||
|
||
|
||
def quote(x, u, U, s, S, L, K): | ||
sumA = ((u + x) * K - U + u) * ((U + x) / L)**K | ||
|
||
sumB = (U - u - K * u) * (U / L)**K | ||
|
||
nom = (sumA + sumB) * (S + U) | ||
denom = K * (UNIT + K) * (s + u) | ||
|
||
fee = BASE_FEE * x + nom / denom | ||
out = x - fee | ||
return (out, fee) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from z3 import Solver, Int, sat | ||
import quote | ||
|
||
# Define Z3 variables corresponding to Solidity function inputs and parameters | ||
amount = Int('amount') | ||
L = Int('L') # Liability | ||
U = Int('U') # Example parameter from SwapParams | ||
x = Int('x') # Corresponds to 'amount' in Solidity | ||
K = Int('K') # Some constant from your function | ||
BASE_FEE = Int('BASE_FEE') # Base fee constant | ||
UNIT = Int('1') | ||
|
||
# SwapParams in Z3 (simplified) | ||
p_u = Int('p_u') | ||
p_U = Int('p_U') | ||
p_s = Int('p_s') | ||
p_S = Int('p_S') | ||
|
||
s = Solver() | ||
|
||
# Generate random values (as an example) | ||
# random_amount = random.uniform(0, 1000) # Random value between 0 and 1000 | ||
# ... generate other random values as needed | ||
|
||
# Add random values as constraints | ||
# s.add(amount == random_amount) | ||
|
||
# Define bounds (as an example) | ||
# lower_bound = 10 | ||
# upper_bound = 500 | ||
|
||
# Add constraints for bounds | ||
# s.add(amount >= lower_bound, amount <= upper_bound) | ||
|
||
# Simplified representation of the fee calculation logic | ||
# Note: This is highly simplified and should be replaced with the actual logic | ||
(out, fee) = quote.quote(amount, p_u, p_U, p_s, p_S, L, K) | ||
|
||
# Define invariants | ||
|
||
s.add(out <= amount, fee <= amount, out + fee == | ||
amount, out <= L - U, amount <= p_s) | ||
|
||
# Check if the invariants are satisfiable | ||
if s.check() == sat: | ||
print("Invariants are satisfiable. Function behaves as expected under these conditions.") | ||
else: | ||
print("Invariants are not satisfiable. Function may have an issue or the model may need refinement.") |