Skip to main content

SUAVE Standard Library

suave-std is a collection of Solidity contracts and libraries to help you create Suapps. It is included as a submodule in the SUAPP Examples repo, which we used in the previous tutorial.

In this tutorial, we will be diving deeper into the different capabilities offered by suave-std.

info

suave-std is the main entrypoint for developers who are interacting with SUAVE. It is a place to create building blocks, sdks, and common patterns that are useful to SUAVE developers.

The core functionalities that suave-std will help you handle include:

1

transaction parsing and construction

2

JSON object decoding and encoding

3

convenience wrapper around precompiles

Libraries​

Transactions.sol​

Helper library that defines types and encoding/decoding methods for the Ethereum transaction types.

Example usage​

import "suave-std/Transactions.sol";

contract Example {
function example() {
Transactions.Legacy memory legacyTxn0 = Transactions.Legacy({
to: address(0x095E7BAea6a6c7c4c2DfeB977eFac326aF552d87),
gas: 50000,
gasPrice: 10,
value: 10,
...
});

// Encode to RLP
bytes memory rlp = Transactions.encodeRLP(legacyTxn0);

// Decode from RLP
Transactions.Legacy memory legacyTxn1 = Transactions.decodeRLP(rlp);
}
}

MevShare.sol​

not in main branch yet but will be soon https://github.com/flashbots/suave-geth/blob/feature/suave-std/suave/sol/suave-std/mevshare.sol

    struct Bundle {
string version;
uint64 inclusionBlock;
bytes[] bodies;
bool[] canRevert;
uint8[] refundPercents;
}

function encodeBundle(Bundle memory bundle) internal view returns (bytes memory)
function sendBundle(string memory url, Bundle memory bundle) internal view
function toMinimalHexString(bytes memory value) internal pure returns (string memory str)

MevBoost.sol​

   function encode(Payload memory payload) internal view returns (bytes memory) 
function submitBlock(string memory baseUrl, SubmitBlockRequest memory bundle) internal view
function toMinimalHexString(bytes memory value) private pure returns (string memory str)

struct Bid {
uint64 slot;
bytes parentHash;
bytes blockHash;
bytes builderPubkey; // bytes48
bytes proposerPubkey; // bytes48
address proposerFeeRecipient;
uint64 gasLimit;
uint64 gasUsed;
uint256 value;
}

struct Withdrawal {
uint64 index;
uint64 validatorIndex;
address addr;
uint256 amount;
}

struct Payload {
bytes parentHash;
address feeRecipient;
bytes stateRoot;
bytes receiptsRoot;
bytes logsBloom;
bytes prevRandao;
uint64 blockNumber;
uint64 gasLimit;
uint64 gasUsed;
uint64 timestamp;
bytes extraData;
bytes baseFeePerGas;
bytes blockHash;
bytes[] transactions;
Withdrawal[] withdrawals;
}

struct SubmitBlockRequest {
Bid bid;
Payload payload;
bytes signature;
}