Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Update smart contract calculation, testing, and readme docs #1

Merged
merged 27 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b606553
forge install: openzeppelin-contracts
fiando Nov 13, 2024
2992897
WIP: Eduena endowment fund contract
fiando Nov 14, 2024
4b30c34
WIP: Eduena endowment fund contract
fiando Nov 15, 2024
cac4eff
modify updateYield
ardyerd Nov 15, 2024
6f8e8f6
modify updateYield
ardyerd Nov 15, 2024
628a3cc
modify updateYield
ardyerd Nov 15, 2024
8923f7f
forge install: openzeppelin-contracts
ardyerd Nov 15, 2024
d00bf5d
update import lib
ardyerd Nov 15, 2024
d3e16b7
WIP: eduena testing
fiando Nov 15, 2024
8e85214
update function deposit
ardyerd Nov 15, 2024
a0628ba
WIP: env example integration test fork
fiando Nov 15, 2024
8a8cc95
WIP: testing yield
fiando Nov 15, 2024
dbc8428
WIP: test yield contract
fiando Nov 15, 2024
4d2d83a
WIP: Test increasing last asset for yield
fiando Nov 17, 2024
b5d4da3
Merge branch 'dev' of https://github.com/Eduena-Endownment-Fund/eduen…
ardyerd Nov 17, 2024
3a2f219
Merge branch 'dev' of https://github.com/Eduena-Endownment-Fund/eduen…
ardyerd Nov 17, 2024
373c7e0
WIP: Fix calculation
fiando Nov 22, 2024
24bb7c0
update deposit
ardyerd Nov 22, 2024
81bc687
update deposit function
ardyerd Nov 22, 2024
fc02d5f
WIP: fix deposit, withdraw
fiando Nov 22, 2024
31bdc6b
WIP: test eduena
fiando Nov 22, 2024
0facc2b
WIP: fixing yield
fiando Nov 22, 2024
98d0f7f
WIP: test yield
fiando Nov 22, 2024
4f07a8d
WIP: smart contract docs
fiando Nov 24, 2024
4172549
WIP: smart contract docs
fiando Nov 24, 2024
55ee9d2
WIP: smart contract docs
fiando Nov 24, 2024
77b0482
Update smart contract calculation, testing, and readme docs
fiando Nov 27, 2024
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/account_key_xxx
FORK_BLOCK_NUMBER=21272472
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
115 changes: 77 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,105 @@
## Foundry
## Eduena Frontend

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
[Eduena Frontend](https://github.com/Eduena-Endownment-Fund/eduena-web)

Foundry consists of:
## Smart Contract Functionality

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
The `Eduena` contract in [`src/Eduena.sol`](src/Eduena.sol)

## Documentation
### Functions

https://book.getfoundry.sh/
- **deposit(uint256 amount)**: Allows users to deposit a specified amount of USDe tokens and it immediately staked to sUSDe. The equivalent amount of Eduena tokens (EDN) is minted and assigned to the user.
- **withdraw(uint256 shares)**: Allows users to withdraw a specified amount of Eduena tokens (EDN). The equivalent amount of sUSDe tokens is transferred back to the user.
- **distribute(address recipient, uint256 shares)**: Distributes a specified amount of yield to a recipient.
- **accrueYield()**: Updates the yield based on the current asset value in USDe.

## Usage
### Events

### Build
- **DepositAndStake(address indexed user, uint256 amount)**: Emitted when a deposit is made and staked.
- **Withdraw(address indexed recipient, uint256 amount)**: Emitted when a withdrawal is made.
- **Distribute(address indexed recipient, uint256 amount)**: Emitted when yield is distributed.
- **YieldAccrued(uint256 newAssetValueInUSDe, uint256 yield)**: Emitted when the yield is updated.

```shell
$ forge build
```
### Errors

### Test
- **InsufficientBalance()**: Thrown when a user tries to withdraw more than their balance.
- **DepositAmountZero()**: Thrown when a deposit amount is zero.
- **ExceedsUnclaimedYield()**: Thrown when the amount exceeds the unclaimed yield.

```shell
$ forge test
```
## Testing

The `EduenaTest` contract in [`test/Eduena.t.sol`](test/Eduena.t.sol) includes tests for the deposit and withdrawal functionalities.

### Format
### Example Test Functions

```shell
$ forge fmt
```solidity
function testDepositAndWithdraw() public {
// Test deposit and withdrawal functionality
}

function testAccrueYield() public {
// Test yield accrual functionality
}
```

### Gas Snapshots
### Setting Up Environment Variables

To run the tests, you need to set up the following environment variables in a `.env` file:

```shell
$ forge snapshot
```env
MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/account_key_xxx
FORK_BLOCK_NUMBER=21272472
```

### Anvil
Running the Tests
To run the tests using Foundry, use the following command:

```shell
$ anvil
```
forge test
```

### Deployment

### Deploy
The Eduena contract is deployed on [Tenderly](https://tenderly.co/) for testing purposes.

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```
echo "
unknown_chain = { key = \"${TENDERLY_ACCESS_KEY}\", chain = 1, url = \"$TENDERLY_RPC_URL\" }" >> foundry.toml

forge create Eduena \
--private-key $PRIVATE_KEY \
--rpc-url $TENDERLY_RPC_URL \
--etherscan-api-key $TENDERLY_ACCESS_KEY \
--verify \
--verifier-url $TENDERLY_RPC_URL/verify/etherscan \
--constructor-args 0x4c9EDD5852cd905f086C759E8383e09bff1E68B3 0x9D39A5DE30e57443BfF2A8307A4256c8797A3497
```

### Cast
Fund account for gas fee

```shell
$ cast <subcommand>
```
curl "$TENDERLY_RPC_URL" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tenderly_setBalance",
"params": [["0xE58b9ee93700A616b50509C8292977FA7a0f8ce1"], "0xDE0B6B3A7640000"]
}'
```

### Help
Fund your account with USDe for testing Eduena deposits. The first parameter is the USDe contract address, the second parameter is your wallet address, and the third parameter is a 32-byte hash representing the token amount in wei. The example below sets a balance of $100,000 USDe to the user's address.

```shell
$ forge --help
$ anvil --help
$ cast --help
```
curl --location '${TENDERLY_RPC_URL}' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "tenderly_setErc20Balance",
"params": [
"0x4c9EDD5852cd905f086C759E8383e09bff1E68B3",
"{{$USER_WALLET_ADDRESS}}",
"0x152d02c7e14af6000000"
]
}'
```
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

unknown_chain = { key = "{{TENDERLY_ACCESS_KEY}}", chain = 1, url = "{{TENDERLY_RPC_URL}}" }
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 69c8de
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@openzeppelin/contracts=lib/openzeppelin-contracts/contracts
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

73 changes: 0 additions & 73 deletions src/EduEna.sol

This file was deleted.

Loading
Loading