From fd9afd9b5bc9f8b8dc15018a3a9f464cb3c8f6ff Mon Sep 17 00:00:00 2001 From: elizabeth Date: Wed, 29 May 2024 16:12:48 -0400 Subject: [PATCH] contract scripts and readme updates --- contracts/.gitignore | 2 +- contracts/README.md | 79 +++++++++------------- contracts/lib/forge-std | 1 + contracts/lib/openzeppelin-contracts | 1 + contracts/local.env.example | 14 ++++ contracts/script/AstriaMintableERC20.s.sol | 15 +++- grpc/execution/server.go | 6 +- 7 files changed, 67 insertions(+), 51 deletions(-) create mode 160000 contracts/lib/forge-std create mode 160000 contracts/lib/openzeppelin-contracts create mode 100644 contracts/local.env.example diff --git a/contracts/.gitignore b/contracts/.gitignore index 85198aaa5..060bcb39e 100644 --- a/contracts/.gitignore +++ b/contracts/.gitignore @@ -3,7 +3,7 @@ cache/ out/ # Ignores development broadcast logs -!/broadcast +broadcast/ /broadcast/*/31337/ /broadcast/**/dry-run/ diff --git a/contracts/README.md b/contracts/README.md index 9265b4558..998041eb5 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -1,66 +1,51 @@ -## Foundry +# astria bridgeable erc20s -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** +Forge project for the `AstriaMintableERC20` contract. -Foundry consists of: +Requirements: -- **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. +- foundry -## Documentation +Build: -https://book.getfoundry.sh/ - -## Usage - -### Build - -```shell -$ forge build +```sh +forge build ``` -### Test +Copy the example .env: -```shell -$ forge test -``` +`cp local.env.example .env && source .env` -### Format +Deploy `AstriaMintableERC20.sol`: -```shell -$ forge fmt +```sh +forge script script/AstriaMintableERC20.s.sol:AstriaMintableERC20Script \ + --rpc-url $RPC_URL --broadcast --sig "deploy()" -vvvv ``` -### Gas Snapshots - -```shell -$ forge snapshot -``` +Take note of the deployed address. -### Anvil +Add the following to the genesis file under `astriaBridgeAddresses`: -```shell -$ anvil ``` - -### Deploy - -```shell -$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key +"astriaBridgeAddresses": [ + { + "bridgeAddress": "0x1c0c490f1b5528d8173c5de46d131160e4b2c0c3", + "startHeight": 1, + "assetDenom": "nria", + "assetPrecision": 6, + "erc20asset": { + "contractAddress":"0x9Aae647A1CB2ec6b39afd552aD149F6A26Bb2aD6", + "contractPrecision": 6 + } + } +], ``` -### Cast +Note: this mints `nria` as an erc20 instead of the native asset. -```shell -$ cast -``` +`bridgeAddress` is the bridge address that corresponds to this asset on the sequencer chain. +`assetDenom` does not need to match the name of the token in the deployed contract, but it does need to match the denom of the token on the sequencer. +`contractAddress` in `erc20asset` is the address of the contract deployed above. -### Help - -```shell -$ forge --help -$ anvil --help -$ cast --help -``` +Stop and restart the geth node. diff --git a/contracts/lib/forge-std b/contracts/lib/forge-std new file mode 160000 index 000000000..52715a217 --- /dev/null +++ b/contracts/lib/forge-std @@ -0,0 +1 @@ +Subproject commit 52715a217dc51d0de15877878ab8213f6cbbbab5 diff --git a/contracts/lib/openzeppelin-contracts b/contracts/lib/openzeppelin-contracts new file mode 160000 index 000000000..1224d197c --- /dev/null +++ b/contracts/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit 1224d197c7335b29cf4b95d03a1db438658e6263 diff --git a/contracts/local.env.example b/contracts/local.env.example new file mode 100644 index 000000000..794a50106 --- /dev/null +++ b/contracts/local.env.example @@ -0,0 +1,14 @@ +# name of token to deploy +NAME="token" + +# symbol of token to deploy +SYMBOL="TKN" + +# the "astriaBridgeSenderAddress" built into the node; set in the genesis file +BRIDGE="0x00000000000000000000000000000000000000aa" + +# private key to alloc account in genesis +PRIVATE_KEY=0x0a6996ccaca77a1d48633da20062ae051e11c75f3f561dfd2ac01b0c9c874662 + +# default local rpc url +RPC_URL="http://localhost:8545" diff --git a/contracts/script/AstriaMintableERC20.s.sol b/contracts/script/AstriaMintableERC20.s.sol index 88b2fa66d..d10dd01be 100644 --- a/contracts/script/AstriaMintableERC20.s.sol +++ b/contracts/script/AstriaMintableERC20.s.sol @@ -2,11 +2,22 @@ pragma solidity ^0.8.13; import {Script, console} from "forge-std/Script.sol"; +import {AstriaMintableERC20} from "../src/AstriaMintableERC20.sol"; contract AstriaMintableERC20Script is Script { function setUp() public {} - function run() public { - vm.broadcast(); + function deploy() public { + string memory name = vm.envString("NAME"); + string memory symbol = vm.envString("SYMBOL"); + address bridge = vm.envAddress("BRIDGE"); + + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + AstriaMintableERC20 astriaMintableERC20 = new AstriaMintableERC20(bridge, name, symbol); + console.logAddress(address(astriaMintableERC20)); + + vm.stopBroadcast(); } } diff --git a/grpc/execution/server.go b/grpc/execution/server.go index a28cce3da..ea3a68627 100644 --- a/grpc/execution/server.go +++ b/grpc/execution/server.go @@ -121,6 +121,10 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ bridgeAddresses[string(cfg.BridgeAddress)] = &cfg assetID := sha256.Sum256([]byte(cfg.AssetDenom)) bridgeAllowedAssetIDs[assetID] = struct{}{} + log.Info("new bridge address", "bridgeAddress", cfg.BridgeAddress, "assetDenom", cfg.AssetDenom) + if cfg.Erc20Asset != nil { + log.Info("new bridge ERC20 asset", "contractAddress", cfg.Erc20Asset.ContractAddress) + } } } @@ -273,7 +277,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req * amount := bac.ScaledDepositAmount(protoU128ToBigInt(deposit.Amount)) if bac.Erc20Asset != nil { - log.Debug("creating deposit tx to mint ERC20 asset", "token", bac.AssetDenom, "erc20Address", bac.Erc20Asset.ContractAddress) + log.Info("creating deposit tx to mint ERC20 asset", "token", bac.AssetDenom, "erc20Address", bac.Erc20Asset.ContractAddress) abi, err := contracts.AstriaMintableERC20MetaData.GetAbi() if err != nil { // this should never happen, as the abi is hardcoded in the contract bindings