Skip to content

Commit

Permalink
contract scripts and readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed May 29, 2024
1 parent b04a771 commit fd9afd9
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
broadcast/
/broadcast/*/31337/
/broadcast/**/dry-run/

Expand Down
79 changes: 32 additions & 47 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -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 <your_rpc_url> --private-key <your_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 <subcommand>
```
`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.
1 change: 1 addition & 0 deletions contracts/lib/forge-std
Submodule forge-std added at 52715a
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 1224d1
14 changes: 14 additions & 0 deletions contracts/local.env.example
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 13 additions & 2 deletions contracts/script/AstriaMintableERC20.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 5 additions & 1 deletion grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fd9afd9

Please sign in to comment.