Fully on-chain LLMs.
First, make sure you have the requirements:
- We are using Foundry, so make sure you install it first.
- Upgradable contracts make use of NodeJS, so you should install that as well.
Clone the repository:
git clone git@github.com:firstbatchxyz/dria-oracle-contracts.git
Install dependencies with:
forge install
Compile the contracts with:
forge build
Note
We are using openzeppelin-foundry-upgrades library, which requires clean-up per compilation to ensure upgrades are done safely. We use force = true
option in foundry.toml
for this, which may increase build times.
Note that for some users this may fail (see issue) due to a missing NPM package called @openzeppelin/upgrades-core
. To fix it, you can install the package manually:
npm install @openzeppelin/upgrades-core@latest -g
To update contracts to the latest library versions, use:
forge update
To be able to deploy & use our contracts, we need two things:
We use keystores for wallet management, with the help of cast wallet
command.
Use the command below to create your keystore. The command will prompt for your private key, and a password to encrypt the keystore itself.
cast wallet import <WALLET_NAME> --interactive
[!ALERT]
Note that you will need to enter the password when you use this keystore.
You can see your keystores under the default directory (~/.foundry/keystores
) with the command:
cast wallet list
To interact with the blockchain, we require an RPC endpoint. You can get one from:
You will use this endpoint for the commands that interact with the blockchain, such as deploying and upgrading; or while doing fork tests.
Deploy the contract with:
forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
--rpc-url <RPC_URL> \
--account <WALLET_NAME> \
--broadcast
You can see deployed contract addresses under the deployment/<chainid>.json
You can verify the contract during deployment by adding the verification arguments as well:
forge script ./script/Deploy.s.sol:Deploy<CONTRACT_NAME> \
--rpc-url <RPC_URL> \
--account <WALLET_NAME> \
--broadcast \
--verify --verifier blockscout \
--verifier-url <VERIFIER_URL>
You can verify an existing contract with:
forge verify-contract <CONTRACT_ADDRESS> ./src/<CONTRACT_NAME>.sol:<CONTRACT_NAME> \
--verifier blockscout \
--verifier-url <VERIFIER_URL>
Note that the --verifier-url
value should be the target explorer's homepage URL. Some example URLs are:
https://base.blockscout.com/api/
for Base (Mainnet)https://base-sepolia.blockscout.com/api/
for Base Sepolia (Testnet)
Note
URL should not contain the API key! Foundry will read your ETHERSCAN_API_KEY
from environment.
Note
The --verifier
can accept any of the following: etherscan
, blockscout
, sourcify
, oklink
. We are using Blockscout most of the time.
To interact with the contracts, you need the contract ABIs. We store the ABIs under the abis
folder, and these can be generated using the following script:
./export-abis.sh
Upgrading an existing contract is done as per the instructions in openzeppelin-foundry-upgrades repository.
The --sender <ADDRESS>
field is required when deploying a contract,
Run tests on local network:
forge test
# or -vvv to show reverts in detail
forge test -vvv
or fork an existing chain and run the tests on it:
forge test --rpc-url <RPC_URL>
We have a script that generates the coverage information as an HTML page. This script requires lcov
and genhtml
command line tools. To run, do:
./coverage.sh
Alternatively, you can see a summarized text-only output as well:
forge coverage --no-match-coverage "(test|mock|script)"
You can print storage layouts for each contract using:
./storage.sh
The resulting Markdown files will be created under the storage
directory.
You can examine the gas usage metrics using the command:
forge snapshot --snap ./test/.gas-snapshot
You can see the snapshot .gas-snapshot
file in the current directory.
You can format the contracts with:
forge fmt ./src/**/*.sol ./script/**/*.sol
If you have solhint installed, you can lint all contracts with:
solhint 'contracts/**/*.sol'
We have auto-generated MDBook documentations under the docs
folder, generated with the following command:
forge doc
# serves the book as well
forge doc --serve
We are using Apache-2.0 license.