Skip to content

Commit 2720bec

Browse files
committed
first commit
0 parents  commit 2720bec

File tree

103 files changed

+10768
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+10768
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Triggers the workflow on push events
2+
on:
3+
push:
4+
paths:
5+
- 'contracts/**'
6+
- 'test/**'
7+
- 'lib/**'
8+
- 'foundry.toml'
9+
- 'package.json'
10+
11+
name: Contracts Tests
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
test:
19+
env:
20+
FOUNDRY_FUZZ_RUNS: '1000'
21+
runs-on: 'ubuntu-latest'
22+
timeout-minutes: 30
23+
steps:
24+
- name: 'Check out the repo'
25+
uses: 'actions/checkout@v3'
26+
with:
27+
submodules: 'recursive'
28+
29+
- name: 'Install Foundry'
30+
uses: 'foundry-rs/foundry-toolchain@v1'
31+
with:
32+
version: nightly
33+
34+
- name: 'Install the Node.js dependencies'
35+
run: 'yarn'
36+
37+
- name: 'Copy fork cache to foundry cache'
38+
run: 'yarn test:cache:apply'
39+
40+
- name: 'Run the foundry tests'
41+
run: 'yarn test:ci'
42+
43+
- name: 'Add test summary'
44+
run: |
45+
echo "## Tests result" >> $GITHUB_STEP_SUMMARY
46+
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
# Smart Contracts
133+
tmp
134+
build/
135+
/abi/
136+
artifacts/
137+
cache/
138+
coverage/
139+
exports/
140+
/types/
141+
coverage.json
142+
.env
143+
.DS_Store
144+
.idea/
145+
flatten
146+
cache_forge/
147+
cache_hardhat/
148+
lcov.info
149+
.wallet
150+
.wallet-*
151+
!.wallet-hardhat
152+
153+
# Deployment snapshots
154+
.openzeppelin/unknown-*.json
155+
!.openzeppelin/mainnet.json
156+
157+
deployed/localhost/
158+
deployed/hardhat/
159+
160+
typechain-types/

.gitmodules

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[submodule "lib/forge-std"]
2+
path = lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/solmate"]
5+
path = lib/solmate
6+
url = https://github.com/transmissions11/solmate
7+
[submodule "lib/openzeppelin-contracts"]
8+
path = lib/openzeppelin-contracts
9+
url = https://github.com/OpenZeppelin/openzeppelin-contracts
10+
[submodule "lib/prb-test"]
11+
path = lib/prb-test
12+
url = https://github.com/PaulRBerg/prb-test
13+
[submodule "lib/openzeppelin-contracts-upgradeable"]
14+
path = lib/openzeppelin-contracts-upgradeable
15+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Stakeland
2+
3+
This repository contains the core smart contracts for the Stakeland Protocol.
4+
5+
## Getting started
6+
7+
1. Run `forge --version` to verify your installation of Foundry. If you haven't installed Foundry on your machine,
8+
[click here](https://getfoundry.sh/)
9+
2. Run `yarn` to install dependencies
10+
3. Run `cp .env.example .env` to create a `.env` file from example and input the respective values inside
11+
4. Run `yarn build` to get the ABI and artifacts of contracts
12+
5. [Optional]If you are using VS Code, it is recommended to install Hardhat Solidity extensions by Nomic Foundation
13+
([Click here](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity))
14+
6. Install Solidity extensions by Juan Blanco (For auto formatting .sol files using `Forge`)
15+
7. That's it! You can start development with Hardhat and run test with Foundry
16+
17+
## Test
18+
19+
1. Go through `Getting started` to ensure necessary dependencies are installed
20+
2. Run `yarn test:cache:apply` to copy committed cache to foundry for fork testing
21+
3. Run `yarn test` or `yarn test:watch`
22+
23+
NB: console.log won't work on Foundry Fuzz Tests
24+
25+
### For any new test that gets updated blockchain data from RPC
26+
27+
If you have updated cache from rpc, make sure you commit the latest cache to repo by running `yarn test:cache:update`.
28+
So when others apply the cache, they will have the latest cache and no need for them to get blockchain data from RPC
29+
30+
### Reasons we use PRB-Test over Foundry's DSTest
31+
32+
https://github.com/PaulRBerg/prb-test#why-choose-prbtest-over-dstest
33+
34+
### Unable to get blockchain data from RPC
35+
36+
In fork testing, we are forking states from remote to local and Foundry creates a local cache to allow reusing the
37+
necessary states for testing. We have specified block `SEPOLIA_BLOCK_NO = 5567682` in `Constants.sol` to lock the
38+
contract states on Sepolia to ensure fork tests won't fail. Though we have committed cache that we can apply. As new
39+
test cases are added, it's possible Foundry needs to retrieve more states from RPC. As you try to get blockchain data
40+
from RPC, it's likely that you will encounter the RPC error `missing trie node ... (path ) <nil>, data: None'`. This
41+
happens when you try to querying for a state past the immediately previous 16-128 blocks and this often requires an
42+
archive node. There are 2 fixes:
43+
44+
- [Click here](https://nodereal.io/) to register for a RPC URL that supports archive node. They provide querying of
45+
archive data for free (At least for now).
46+
- Use specified block by `setUpSepoliaFork(uint256 blockNo)` and save the newly created cache using `test:cache:update`
47+
to repo and commit afterwards

contracts/abstract/VaultBase.sol

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.23;
3+
4+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5+
6+
import {IAddressesProvider} from "../interfaces/IAddressesProvider.sol";
7+
import {IACLManager} from "./../interfaces/IACLManager.sol";
8+
import {IVault} from "../interfaces/IVault.sol";
9+
import {ProviderSanityCheckLib} from "../libraries/ProviderSanityCheckLib.sol";
10+
11+
abstract contract VaultBase is Initializable, IVault {
12+
using ProviderSanityCheckLib for IAddressesProvider;
13+
14+
/// @dev No storage gaps needed since Namespaced Storage is used in OZ v5 upgradeable contracts
15+
IAddressesProvider internal _addressesProvider;
16+
IACLManager internal _aclManager;
17+
18+
address private _vaultAdmin;
19+
20+
modifier onlyVaultAdmin() {
21+
if (msg.sender != _vaultAdmin) revert OnlyVaultAdmin();
22+
_;
23+
}
24+
25+
/**
26+
* @dev Initializes the Vault contract
27+
* @param params The decoded parameters for initializing the EthVault contract
28+
*/
29+
function __VaultBase_init(address addressesProvider_, VaultBaseParams memory params) internal onlyInitializing {
30+
_addressesProvider = IAddressesProvider(addressesProvider_);
31+
_aclManager = IACLManager(_addressesProvider.checkContractZeroAddress("ACL_MANAGER"));
32+
_vaultAdmin = params.vaultAdmin;
33+
}
34+
35+
receive() external payable {
36+
revert DoesNotReceiveETHDirectly();
37+
}
38+
39+
/*//////////////////////////////////////////////////////////////
40+
ADMIN
41+
//////////////////////////////////////////////////////////////*/
42+
43+
/// @inheritdoc IVault
44+
function receiveAllocatedETH() external payable virtual {}
45+
46+
/// @inheritdoc IVault
47+
function setVaultAdmin(address newAdmin) external onlyVaultAdmin {
48+
_vaultAdmin = newAdmin;
49+
}
50+
51+
/*//////////////////////////////////////////////////////////////
52+
VIEWS
53+
//////////////////////////////////////////////////////////////*/
54+
// /**
55+
// * @notice Checks if the Vault's capacity is fully utilized.
56+
// * @param amount The amount of ETH to check if the Vault will be fully utilized after adding it
57+
// */
58+
// function isFullyUtilized(uint256 amount) external view virtual returns (bool) {
59+
// // check if rebase/non-rebase vault has exceeded capacity
60+
// if (this.getVaultTokensInETH() + amount > _capacity) return true;
61+
62+
// return false;
63+
// }
64+
65+
/// @inheritdoc IVault
66+
function getVaultTokensInETH() external view virtual returns (uint256);
67+
68+
/// @inheritdoc IVault
69+
function getVaultAdmin() external view virtual returns (address) {
70+
return _vaultAdmin;
71+
}
72+
}

0 commit comments

Comments
 (0)