Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions examples/app-ofa-private/ofa-private.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@ pragma solidity ^0.8.8;
import "suave-std/suavelib/Suave.sol";
import "suave-std/Context.sol";

library DagStore {
address constant DAG_RETRIEVE = address(0x0000000000000000000000000000000052020001);
address constant DAG_STORE = address(0x0000000000000000000000000000000052020000);

function get(bytes32 dagId) internal view returns (bytes memory) {
(bool success, bytes memory data) = DAG_RETRIEVE.call(abi.encode(dagId));
if (!success) {
revert PeekerReverted(DAG_RETRIEVE, data);
}
return data;
}

function set(bytes32 dagId, bytes memory data) internal {
(bool success, bytes memory data) = DAG_STORE.call(abi.encode(dagId, data));
if (!success) {
revert PeekerReverted(DAG_STORE, data);
}
}
}

contract OFAPrivate {
// Struct to hold hint-related information for an order.
struct HintOrder {
Suave.DataId id;
bytes32 id;
bytes hint;
}

Expand All @@ -32,12 +52,13 @@ contract OFAPrivate {
allowedList[1] = 0x0000000000000000000000000000000043200001;

// Store the bundle and the simulation results in the confidential datastore.
Suave.DataRecord memory dataRecord = Suave.newDataRecord(decryptionCondition, allowedList, allowedList, "");
Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundles", bundleData);
Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundleSimResults", abi.encode(egp));
// Suave.DataRecord memory dataRecord = Suave.newDataRecord(decryptionCondition, allowedList, allowedList, "");
// Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundles", bundleData);
// Suave.confidentialStore(dataRecord.id, "mevshare:v0:ethBundleSimResults", abi.encode(egp));
dagId = DagStore.set(bundleData);

HintOrder memory hintOrder;
hintOrder.id = dataRecord.id;
hintOrder.id = dagId;
hintOrder.hint = hint;

return hintOrder;
Expand All @@ -54,17 +75,18 @@ contract OFAPrivate {
}

// Function to match and backrun another dataRecord.
function newMatch(Suave.DataId shareDataRecordId, uint64 decryptionCondition) external returns (bytes memory) {
function newMatch(bytes32 shareDataRecordId, uint64 decryptionCondition) external returns (bytes memory) {
HintOrder memory hintOrder = saveOrder(decryptionCondition);

// Merge the dataRecords and store them in the confidential datastore.
// The 'fillMevShareBundle' precompile will use this information to send the bundles.
Suave.DataId[] memory dataRecords = new Suave.DataId[](2);
dataRecords[0] = shareDataRecordId;
dataRecords[1] = hintOrder.id;
Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(dataRecords));
// Suave.confidentialStore(hintOrder.id, "mevshare:v0:mergedDataRecords", abi.encode(dataRecords));
bytes32 recordsId = DagStore.set(abi.encode(dataRecords));

return abi.encodeWithSelector(this.emitHint.selector, hintOrder);
return abi.encodeWithSelector(this.emitHint.selector, recordsId);
}

function emitMatchDataRecordAndHintCallback(string memory bundleRawResponse) external {
Expand Down