From 1d188a8ce5abe678c64dd57202bc154818ab3bb2 Mon Sep 17 00:00:00 2001 From: Andy Tudhope <13001517+andytudhope@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:48:03 +0200 Subject: [PATCH] Dev tooling (#42) * Edits all additions, updates what to build page * Add dev tooling page back to sidebar * fixes broken links error * fix typo * save how-to index page properly * Add back simple contract to make sidebar carets same size --- .github/workflows/pr-tests.yml | 3 +- docs/builder-solidity.mdx | 2 +- docs/dev-tooling.mdx | 14 +++ docs/how-to/create-contracts/confidential.mdx | 2 +- .../how-to/create-contracts/deploy-custom.mdx | 6 +- docs/how-to/create-contracts/index.mdx | 93 +++++++++++++++++++ docs/how-to/index.mdx | 14 +-- docs/index.mdx | 2 +- docs/sidebars.js | 2 + 9 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 docs/dev-tooling.mdx create mode 100644 docs/how-to/create-contracts/index.mdx diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 213c5c6a..4450b6f6 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -61,4 +61,5 @@ jobs: -e "https://github.com/flashbots/suave-bridge" \ -e "https://github.com/flashbots/suave-specs" \ -e "https://github.com/flashbots/suapp-examples" \ - -e "https://github.com/flashbots/suave-viem" + -e "https://github.com/flashbots/suave-viem" \ + -e "https://suave.flashbots.net" diff --git a/docs/builder-solidity.mdx b/docs/builder-solidity.mdx index 64bba39e..64f697c0 100644 --- a/docs/builder-solidity.mdx +++ b/docs/builder-solidity.mdx @@ -76,4 +76,4 @@ This ensures confidentiality **and** improves efficiency, enabling computation t We recommend [this early research talk from Andrew Miller](https://youtu.be/DhsDFKnHPa0?t=344) to get a sense of the ideas from which builder solidity has grown. -Please note that the pseudo code Andrew shows is now outdated and you are better off learning from our [how to create contracts guide](/how-to/create-contracts/deploy-custom) above, or looking directly at our [list of available precompiles](/technical/specs/rigil/precompiles). That said, the framework used in this talk and the background provided should still prove useful when writing your own builder solidity contracts. +Please note that the pseudo code Andrew shows is now outdated and you are better off learning from our [how to create contracts guide](/how-to/create-contracts/) above, or looking directly at our [list of available precompiles](/technical/specs/rigil/precompiles). That said, the framework used in this talk and the background provided should still prove useful when writing your own builder solidity contracts. diff --git a/docs/dev-tooling.mdx b/docs/dev-tooling.mdx new file mode 100644 index 00000000..6924da90 --- /dev/null +++ b/docs/dev-tooling.mdx @@ -0,0 +1,14 @@ +--- +title: Dev Tooling +description: An up-to-date list of software to help you build on SUAVE +--- + +Here is an up-to-date list of software and repositories to help you build on [SUAVE Rigil](/technical/specs/rigil): + +- [Golang SDK](/how-to/interact-with-suave/golang-sdk) +- [Typescript SDK: SUAVE-viem](/how-to/interact-with-suave/typescript-sdk) +- [Example Golang Script](/how-to/interact-with-suave/deploy-and-test-example-suapp) +- [SUAVE Rigil Specs](/technical/specs/rigil) +- [SUAPP Examples Repo](https://github.com/flashbots/suapp-examples) +- [suave-geth repo](https://github.com/flashbots/suave-geth) +- [SAUVE Forge](https://github.com/flashbots/suave-geth/blob/main/suave/sol/libraries/SuaveForge.sol) \ No newline at end of file diff --git a/docs/how-to/create-contracts/confidential.mdx b/docs/how-to/create-contracts/confidential.mdx index b48b31f0..85e3053d 100644 --- a/docs/how-to/create-contracts/confidential.mdx +++ b/docs/how-to/create-contracts/confidential.mdx @@ -11,7 +11,7 @@ keywords: # Confidential contracts on SUAVE -We can extend [the contract we deployed in the previous guide](/how-to/create-contracts/deploy-custom) so that it emits the results of the simulation performed by the MEVM allowed to decrypt the confidential inputs. +We can extend [the contract we deployed in the previous guide](/how-to/create-contracts/) so that it emits the results of the simulation performed by the MEVM allowed to decrypt the confidential inputs. ```solidity pragma solidity ^0.8.8; diff --git a/docs/how-to/create-contracts/deploy-custom.mdx b/docs/how-to/create-contracts/deploy-custom.mdx index 23f46b75..35bcf074 100644 --- a/docs/how-to/create-contracts/deploy-custom.mdx +++ b/docs/how-to/create-contracts/deploy-custom.mdx @@ -12,11 +12,9 @@ keywords: # Deploy a custom contract -This sub-section of guides will walk you through creating and deploying increasingly complex smart contracts. +Now, let's write our own simple contract that illustrates how to use confidential inputs. We'll also focus on **how to to deploy custom contracts**. -We'll begin with a simple contract that illustrates how to use confidential inputs. - -This focus of this first guide **how to to deploy custom contracts**. The following guides will provide more details about precompiles, the programming model, and the data flows we expect to see in SUAVE. +The following guides will provide more details about precompiles, the programming model, and the data flows we expect to see in SUAVE. ## 1. Write the contract diff --git a/docs/how-to/create-contracts/index.mdx b/docs/how-to/create-contracts/index.mdx new file mode 100644 index 00000000..29374d04 --- /dev/null +++ b/docs/how-to/create-contracts/index.mdx @@ -0,0 +1,93 @@ +--- +title: Create Contracts +description: Deploy a precompiled exxample contract on SUAVE +--- + +This sub-section of guides will walk you through creating and deploying increasingly complex smart contracts. + +We've written a number of example smart contracts to help get you started thinking about what's possible. + +This script uses the [golang SDK](/how-to/interact-with-suave/golang-sdk), and deploys an example contract we've already set up to keep things maximally simple. + +Inside `suave-geth` repo, create a new file in `suave/devenv/cmd` called `deploy.go`: + +```go +package main + +import ( + "crypto/ecdsa" + "fmt" + + _ "embed" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/suave/e2e" + "github.com/ethereum/go-ethereum/suave/sdk" +) + +var ( + // This is the address we used when starting the MEVM + exNodeEthAddr = common.HexToAddress("b5feafbdd752ad52afb7e1bd2e40432a485bbb7f") + exNodeNetAddr = "http://localhost:8545" + // This account is funded in your local SUAVE network + // address: 0xBE69d72ca5f88aCba033a063dF5DBe43a4148De0 + fundedAccount = newPrivKeyFromHex( + "91ab9a7e53c220e6210460b65a7a3bb2ca181412a8a7b43ff336b3df1737ce12" + ) +) + +var ( + mevShareArtifact = e2e.MevShareBidContract +) + +func main() { + rpcClient, _ := rpc.Dial(exNodeNetAddr) + mevmClt := sdk.NewClient(rpcClient, fundedAccount.priv, exNodeEthAddr) + + var mevShareContract *sdk.Contract + _ = mevShareContract + + txnResult, err := sdk.DeployContract(mevShareArtifact.Code, mevmClt) + if err != nil { + fmt.Errorf("Failed to deploy contract: %v", err) + } + receipt, err := txnResult.Wait() + if err != nil { + fmt.Errorf("Failed to wait for transaction result: %v", err) + } + if receipt.Status == 0 { + fmt.Errorf("Failed to deploy contract: %v", err) + } + + fmt.Printf("- Example contract deployed: %s\n", receipt.ContractAddress) + mevShareContract = sdk.GetContract(receipt.ContractAddress, mevShareArtifact.Abi, mevmClt) +} + +// Helpers, not unique to SUAVE + +type privKey struct { + priv *ecdsa.PrivateKey +} + +func newPrivKeyFromHex(hex string) *privKey { + key, err := crypto.HexToECDSA(hex) + if err != nil { + panic(fmt.Sprintf("failed to parse private key: %v", err)) + } + return &privKey{priv: key} +} +``` + +If you now run: + +```bash +go run suave/devenv/cmd/deploy.go +``` + +You should see the address of your new example contract printed in the terminal. + +The important parts to note when deploying contracts are the call to [`e2e`](https://github.com/flashbots/suave-geth/blob/main/suave/e2e/contracts.go), which helps generate ABIs and bytecode for contracts, and the `sdk.DeplyContract` and `sdk.GetContract`. + +If you're able to generate the necessary ABIs and bytecode, you should be able to deploy any contract you like using the above pattern. \ No newline at end of file diff --git a/docs/how-to/index.mdx b/docs/how-to/index.mdx index eaf6b112..80d57742 100644 --- a/docs/how-to/index.mdx +++ b/docs/how-to/index.mdx @@ -17,16 +17,4 @@ SUAVE is focused on delivering credible, confidential computation that enables y 2. **Compute confidentially**. - Builder solidity lets you request confidential computation, where your transaction data is encrypted to specific actors. Public contracts with verifiable logic, combined with confidential data, means that SUAVE can be seen as an open marketplace for mechanisms we can all inspect, collaborate on, and compete with to produce the most efficient MEV applications, while nevertheless protecting everyone's privacy. -> **SUAVE enables anyone to build and deploy MEV applications, on a decentralized network, which were not possible until today.** - -## Development Stack - -Here is an up-to-date list of software and repositories to help you build on [SUAVE Rigil](/technical/specs/rigil): - -- [Golang SDK](/how-to/interact-with-suave/golang-sdk) -- [Typescript SDK: SUAVE-viem](/how-to/interact-with-suave/typescript-sdk) -- [Example Golang Script](/how-to/interact-with-suave/deploy-and-test-example-suapp) -- [SUAVE Rigil Specs](/technical/specs/rigil) -- [SUAPP Examples Repo](https://github.com/flashbots/suapp-examples) -- [suave-geth repo](https://github.com/flashbots/suave-geth) -- [SAUVE Forge](https://github.com/flashbots/suave-geth/blob/main/suave/sol/libraries/SuaveForge.sol) \ No newline at end of file +> **SUAVE enables anyone to build and deploy MEV applications, on a decentralized network, which were not possible until today.** \ No newline at end of file diff --git a/docs/index.mdx b/docs/index.mdx index cb590818..230203ae 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -60,7 +60,7 @@ Welcome. Let's start building better mechanisms. Once you have SUAVE running, there are two broad categories of work you can get involved with:
- +
diff --git a/docs/sidebars.js b/docs/sidebars.js index a85b848e..500976e7 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -8,6 +8,7 @@ module.exports = { items: [ 'what-is-suave', 'novel-use-cases', + 'dev-tooling', 'technical/specs/rigil/glossary' ], }, @@ -40,6 +41,7 @@ module.exports = { { type: 'category', label: 'Create Contracts', + link: { type: 'doc', id: 'how-to/create-contracts/index' }, items: [ 'how-to/create-contracts/deploy-custom', 'how-to/create-contracts/confidential',