diff --git a/fuel-relayer/README.md b/fuel-relayer/README.md index 23f11e1c7eb..a907e301a09 100644 --- a/fuel-relayer/README.md +++ b/fuel-relayer/README.md @@ -24,4 +24,23 @@ The relayer background task is a simple loop that polls the fuel database and DA If the state determines that the relayer is out of sync with the DA layer then log messages from the DA contract are downloaded and written to the database. The range of blocks is `(last_downloaded_height + 1)..=current_finalized_height`. -Logs are paginated into sets of blocks to avoid overloading a single rpc call. \ No newline at end of file +Logs are paginated into sets of blocks to avoid overloading a single rpc call. + +## Contract Flake +The `flake.nix` in this repo has a tool to fetch, compile and generate the abi for the fuel contracts. +While it is not mandatory to use nix to do this the advantage is the exact versions of the contracts that were used to generate the abi files is pinned in the `flake.lock` file. + +### Usage +To generate the api files run the following from the `fuel-relayer` directory. +```bash +nix run .#generate-abi-json abi +``` +To update the version of the contracts that is used run: +```bash +nix flake update +nix run .#generate-abi-json abi +``` +You can see the versions that are pinned by running: +```bash +nix flake info +``` \ No newline at end of file diff --git a/fuel-relayer/flake.lock b/fuel-relayer/flake.lock new file mode 100644 index 00000000000..7170f71583b --- /dev/null +++ b/fuel-relayer/flake.lock @@ -0,0 +1,129 @@ +{ + "nodes": { + "dapptools": { + "flake": false, + "locked": { + "lastModified": 1663083918, + "narHash": "sha256-JVRKYeHidAdaqzypn4UZvJ/1WGCt8nK7VUm5W7KDZyA=", + "owner": "dapphub", + "repo": "dapptools", + "rev": "01ef8ea418c3fe49089a44d56013d8fcc34a1ec2", + "type": "github" + }, + "original": { + "owner": "dapphub", + "ref": "master", + "repo": "dapptools", + "type": "github" + } + }, + "fuel-v1-contracts": { + "flake": false, + "locked": { + "lastModified": 1659016279, + "narHash": "sha256-naEkyaXa5BROsIDas1sYdJ5mvZPK1j/ftB7i7k5BqzM=", + "owner": "FuelLabs", + "repo": "fuel-merkle-sol", + "rev": "90e8463074d9c038ef7f0b15d3bb91549812bb02", + "type": "github" + }, + "original": { + "owner": "FuelLabs", + "repo": "fuel-merkle-sol", + "type": "github" + } + }, + "fuel-v2-contracts": { + "flake": false, + "locked": { + "lastModified": 1660957336, + "narHash": "sha256-J+jgpJabagUwE6Orlb5kqfBGS11psBBw5SoghUoeQyA=", + "ref": "refs/heads/master", + "rev": "3161ba9a80b827bfbb9fbc9c8f2db421db30d230", + "revCount": 209, + "type": "git", + "url": "ssh://git@github.com/fuellabs/fuel-v2-contracts/" + }, + "original": { + "type": "git", + "url": "ssh://git@github.com/fuellabs/fuel-v2-contracts/" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1664370076, + "narHash": "sha256-NDnIo0nxJozLwEw0VPM+RApMA90uTfbvaNNtC5eB7Os=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "854fdc68881791812eddd33b2fed94b954979a8e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1653917367, + "narHash": "sha256-04MsJC0g9kE01nBuXThMppZK+yvCZECQnUaZKSU+HJo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "437c8e6554911095f0557d524e9d2ffe1c26e33a", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "npm": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1664286682, + "narHash": "sha256-OBdpqW2zpwYF/JWUk013rbMdIC3R17ynX78tQPbfHNw=", + "owner": "serokell", + "repo": "nix-npm-buildpackage", + "rev": "bc0c4989f664ff262d3ab39cad9dc0f6f1c10017", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "nix-npm-buildpackage", + "type": "github" + } + }, + "open-zeppelin": { + "flake": false, + "locked": { + "lastModified": 1664402754, + "narHash": "sha256-Yj+YrCTmAcEYrl39YKYg3gL+rHABQi9PAqO01cC9cCc=", + "owner": "OpenZeppelin", + "repo": "openzeppelin-contracts", + "rev": "26dddee1c05ff91264ae24c5c172bd05827cf5d8", + "type": "github" + }, + "original": { + "owner": "OpenZeppelin", + "repo": "openzeppelin-contracts", + "type": "github" + } + }, + "root": { + "inputs": { + "dapptools": "dapptools", + "fuel-v1-contracts": "fuel-v1-contracts", + "fuel-v2-contracts": "fuel-v2-contracts", + "nixpkgs": "nixpkgs", + "npm": "npm", + "open-zeppelin": "open-zeppelin" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/fuel-relayer/flake.nix b/fuel-relayer/flake.nix new file mode 100644 index 00000000000..d68f9aa6f97 --- /dev/null +++ b/fuel-relayer/flake.nix @@ -0,0 +1,68 @@ +{ + description = '' + A Nix flake for compiling and extracting the fuel contract abi. + ''; + + inputs = { + open-zeppelin = { + url = "github:OpenZeppelin/openzeppelin-contracts"; + flake = false; + }; + fuel-v1-contracts = { + url = "github:FuelLabs/fuel-merkle-sol"; + flake = false; + }; + fuel-v2-contracts.url = "git+ssh://git@github.com/fuellabs/fuel-v2-contracts/"; + fuel-v2-contracts.flake = false; + nixpkgs = { + url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + dapptools = { + url = "github:dapphub/dapptools/master"; + flake = false; + }; + npm.url = "github:/serokell/nix-npm-buildpackage"; + }; + + outputs = inputs: let + system = "x86_64-darwin"; + dapp = import inputs.dapptools {inherit system;}; + solc = dapp.runCommand "solc" {} "mkdir -p $out/bin; ln -s ${dapp.solc-static-versions.solc_0_8_9}/bin/solc-0.8.9 $out/bin/solc"; + overlays = [inputs.npm.overlays.default]; + pkgs = import inputs.nixpkgs {inherit overlays system;}; + in { + packages."x86_64-darwin" = { + add-folder = pkgs.linkFarm "contracts-with-layer" [ + { + name = "merkle-sol"; + path = inputs.fuel-v1-contracts; + } + ]; + build-abi-json = + pkgs.runCommand + "build-abi-json" + {} + '' + ${solc}/bin/solc --abi --pretty-json ${inputs.fuel-v2-contracts}/contracts/sidechain/FuelSidechain.sol @openzeppelin=${inputs.open-zeppelin} @fuel-contracts=${inputs.self.packages."${system}".add-folder} -o $out/build + ''; + generate-abi-json = pkgs.writeShellApplication { + name = "generate-abi-0json"; + runtimeInputs = [solc pkgs.jq inputs.self.packages."${system}".build-abi-json]; + text = '' + if [[ -z $1 ]] + then + echo "Invalid input. Must provide output directoy" >&2; exit 1; + fi + declare -a arr=("FuelMessagePortal") + for i in "''${arr[@]}" + do + (cat ${inputs.self.packages."${system}".build-abi-json}/build/"$i".abi) | jq '.' > "$1"/"$i".json + done + ''; + }; + + + }; + formatter.x86_64-darwin = pkgs.alejandra; + }; +}