Skip to content

Commit

Permalink
Goodbye bids (#78)
Browse files Browse the repository at this point in the history
* Goodbye to bids

* further viem updates
  • Loading branch information
andytudhope authored Dec 22, 2023
1 parent 0b3bfce commit c21906a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 61 deletions.
14 changes: 7 additions & 7 deletions docs/builder-solidity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ pragma solidity ^0.8.8;
import "../libraries/Suave.sol";
contract AnyBidContract {
contract AnyBundleContract {
event BidEvent(
Suave.BidId bidId,
uint64 decryptionCondition,
event DataRecordEvent(
Suave.DataId dataId,
uint64 decryptionCondition,
address[] allowedPeekers
);
function fetchBidConfidentialBundleData() public returns (bytes memory) {
function fetchConfidentialBundleData() public returns (bytes memory) {
require(Suave.isConfidential());
bytes memory confidentialInputs = Suave.confidentialInputs();
return abi.decode(confidentialInputs, (bytes));
}
function emitBid(Suave.Bid calldata bid) public {
emit BidEvent(bid.id, bid.decryptionCondition, bid.allowedPeekers);
function emitDataRecord(Suave.DataRecord calldata dataRecord) public {
emit DataRecordEvent(dataRecord.id, dataRecord.decryptionCondition, dataRecord.allowedPeekers);
}
}
```
Expand Down
20 changes: 15 additions & 5 deletions docs/resources/forge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ contract Example is Script {
address[] public addressList = [Suave.ANYALLOWED];
function run() public {
Suave.Bid memory bid = SuaveForge.newBid(
0,
addressList,
addressList,
"namespace"
Suave.DataRecord memory record = SuaveForge.newDataRecord(
0,
addressList,
addressList,
"default:v0:ethBundles"
);
Suave.DataRecord[] memory allShareMatchRecords = SuaveForge.fetchDataRecords(
0,
"default:v0:ethBundles"
);
console.log(allShareMatchRecords.length);
SuaveForge.confidentialStore(record.id, "a", abi.encodePacked("bbbbbb"));
bytes memory result = SuaveForge.confidentialRetrieve(record.id, "a");
console.logBytes(result);
}
}
```
Expand Down
66 changes: 33 additions & 33 deletions docs/tutorials/build-suapps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,39 +182,39 @@ In this case, we need to:
The [code which achieves this can be found here](https://github.com/flashbots/suave-viem/blob/main/examples/suave-web-demo/src/suave.ts) and looks like this:

```ts
const sendBid = async (suaveWallet: any) => {
// create sample transaction; won't land onchain, but will pass payload validation
const sampleTx = {
type: "eip1559" as 'eip1559',
chainId: 5,
nonce: 0,
maxBaseFeePerGas: 0x3b9aca00n,
maxPriorityFeePerGas: 0x5208n,
to: '0x0000000000000000000000000000000000000000' as Address,
value: 0n,
data: '0xf00ba7' as Hex,
}
const signedTx = await goerliWallet.signTransaction(sampleTx)
console.log("signed goerli tx", signedTx)

// create bid & send ccr
try {
const bid = new MevShareBid(
1n + await goerliProvider.getBlockNumber(),
signedTx,
KETTLE_ADDRESS,
BID_CONTRACT,
suaveRigil.id
)
console.log(bid)
const ccr = bid.toConfidentialRequest()
const txHash = await suaveWallet.sendTransaction(ccr)
console.log("sendResult", txHash)
// callback with result
onSendBid(txHash)
} catch (e) {
return onSendBid('0x', e)
}
const sendDataRecord = async (suaveWallet: any) => {
// create sample transaction; won't land onchain, but will pass payload validation
const sampleTx = {
type: "eip1559" as 'eip1559',
chainId: 5,
nonce: 0,
maxBaseFeePerGas: 0x3b9aca00n,
maxPriorityFeePerGas: 0x5208n,
to: '0x0000000000000000000000000000000000000000' as Address,
value: 0n,
data: '0xf00ba7' as Hex,
}
const signedTx = await goerliWallet.signTransaction(sampleTx)
console.log("signed goerli tx", signedTx)

// create bid & send ccr
try {
const bid = new MevShareRecord(
1n + await goerliProvider.getBlockNumber(),
signedTx,
KETTLE_ADDRESS,
MevShareContract.address as Address,
suaveRigil.id
)
console.log(bid)
const ccr = bid.toConfidentialRequest()
const txHash = await suaveWallet.sendTransaction(ccr)
console.log("sendResult", txHash)
// callback with result
onSendDataRecord(txHash)
} catch (e) {
return onSendDataRecord('0x', e)
}
}
```

Expand Down
27 changes: 11 additions & 16 deletions docs/tutorials/send-transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ txnResult, err := sdk.DeployContract(mevShareArtifact.Code, mevmClt)

### Step 3: Send Confidential Compute Request

:::info

The word "bid" is an artefact of early development. It refers to a generic "Data Identifier" used when operating on confidential data. In this context, a "bid" refers to the Ethereum L1 transaction data the is stored by the MEVM when we send it a CCR.

:::

In practice, the transactions in the `bundle` are from other blockchains, and may contain MEV on that chain which the user wants to share with searchers listening for hints on SUAVE.
In this example, the transactions in the `bundle` would be from other blockchains, and may contain MEV on those chains which the user wants to share with searchers listening for hints on SUAVE.

```go
refundPercent := 10
Expand All @@ -75,18 +69,19 @@ In practice, the transactions in the `bundle` are from other blockchains, and ma
}
bundleBytes, _ := json.Marshal(bundle)

// new mevshare transaction inputs
targetBlock := uint64(1)
allowedPeekers := []common.Address{mevShareContract.Address()}

confidentialDataBytes, _ := bundleBidContract.Abi.Methods["fetchBidConfidentialBundleData"].Outputs.Pack(bundleBytes)
confidentialDataBytes, _ := bundleContract.Abi.Methods["fetchConfidentialBundleData"].Outputs.Pack(bundleBytes)

txnResult, err := mevShareContract.SendTransaction("newBid", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}}, confidentialDataBytes)
txnResult, err := mevShareContract.SendTransaction("newTransaction", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}}, confidentialDataBytes)
if err != nil {
return err
}
```

- Craft a Confidential Compute Request using the MEV-Share contract function `newBid`.
- Craft a Confidential Compute Request using the MEV-Share contract function `newTransaction`.
- Serialize the bundle of transactions to include in the CCR, along with the `refundPercent` the sender of the CCR is looking for.
- Sets a `targetBlock` which is used as the `decryptionCondition`, along with the `allowedPeekers`. That is, the data in the bundle may be decrypted after a specific block (i.e the `targetBlock`) by any of the `allowedPeekers` (which, in this context, is the mevShareContract itself who needs to store the bundle and potentially match it with any backruns it receives once a hint is emitted). This is what we mean by "programmable privacy" which, in this case, is being used to ensure pre-trade privacy because the `decryptionCondition` is just a block number.
- Send the CCR to the specified Kettle and validate its inclusion.
Expand All @@ -102,13 +97,13 @@ In practice, this transaction would be sent by a searcher listening for hints on
}
backRunBundleBytes, _ := json.Marshal(backRunBundle)

confidentialDataMatchBytes, _ := bundleBidContract.Abi.Methods["fetchBidConfidentialBundleData"].Outputs.Pack(backRunBundleBytes)
confidentialDataMatchBytes, _ := bundleContract.Abi.Methods["fetchConfidentialBundleData"].Outputs.Pack(backRunBundleBytes)

// backrun inputs
targetBlock := uint64(1)
allowedPeekers := []common.Address{mevShareContract.Address()}

txnResult, err := mevShareContract.SendTransaction("newMatch", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}, bidId}, confidentialDataMatchBytes)
txnResult, err := mevShareContract.SendTransaction("newMatch", []interface{}{targetBlock + 1, allowedPeekers, []common.Address{}, DataID}, confidentialDataMatchBytes)
if err != nil {
return err
}
Expand All @@ -134,10 +129,10 @@ Step 0: Create and fund test accounts
- Funded test account: 0x66d5a8D6B34329c0639071275b3d78D29e11EbC6 (100000000)
Step 1: Deploy mev-share contract
- Mev share contract deployed: 0x8f21Fdd6B4f4CacD33151777A46c122797c8BF17
Step 2: Send bid
- Bid sent at txn: 0xb49debcdead2b306d6ab6282b88fdad7c8d6a33d87df34b79f56d141eae7c08a
- Bid id: 30bbc65298f24e67aaf5c95bf5f0686c
Step 2: Send user transaction
- transaction sent at txn: 0xb49debcdead2b306d6ab6282b88fdad7c8d6a33d87df34b79f56d141eae7c08a
- Data record id: 30bbc65298f24e67aaf5c95bf5f0686c
Step 3: Send backrun
- Backrun sent at txn: 0xcf7880e61e94aaab48c60655c321716ecab6edab752586448b0412e93a969889
- Backrun bid id: db98b83d02694fc2b13c042ad22c233
- Backrun data record id: db98b83d02694fc2b13c042ad22c233
```

0 comments on commit c21906a

Please sign in to comment.