Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goodbye bids #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions examples/suave-web-demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './style.css'
import viteLogo from '/vite.svg'
import typescriptLogo from './typescript.svg'
import flashbotsLogo from './flashbots_icon.svg'
import { setupConnectButton, setupDripFaucetButton, setupSendBidButton } from './suave'
import { setupConnectButton, setupDripFaucetButton, setupSendDataRecordButton } from './suave'
import { Logo } from './components'
import { custom, formatEther } from 'viem'
import { getSuaveWallet, getSuaveProvider } from 'viem/chains/utils'
Expand Down Expand Up @@ -53,9 +53,9 @@ setupConnectButton(document.querySelector<HTMLButtonElement>('#connect')!,
})

// setup other buttons once we've connected
setupSendBidButton(document.querySelector<HTMLButtonElement>('#sendBid')!, suaveWallet, (txHash, err) => {
setupSendDataRecordButton(document.querySelector<HTMLButtonElement>('#sendBid')!, suaveWallet, (txHash, err) => {
if (err) {
console.error("error in setupSendBidButton", err)
console.error("error in setupSendDataRecordButton", err)
alert(err.message + (err as any).data)
}
const suaveProvider = getSuaveProvider(custom(ethereum))
Expand Down
26 changes: 13 additions & 13 deletions examples/suave-web-demo/src/suave.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address, Hex, createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { suaveRigil, goerli } from "viem/chains"
import { MevShareBid } from "../../suave/bids"
import { MevShareRecord } from "../../suave/bundles"
import { getSuaveWallet } from 'viem/chains/utils'
import BidContractDeployment from '../../suave/deployedAddress.json'
import MevShareContract from '../../suave/deployedAddress.json'

// defaults for local suave-geth devnet:
const KETTLE_ADDRESS: Address = "0xb5feafbdd752ad52afb7e1bd2e40432a485bbb7f"
Expand Down Expand Up @@ -49,9 +49,9 @@ export function setupConnectButton(element: HTMLButtonElement, onConnect: (accou
}
}

export function setupSendBidButton(element: HTMLButtonElement, suaveWallet: any, onSendBid: (txHash: Hex, err?: any) => void) {
element.innerHTML = `send bid`
const sendBid = async (suaveWallet: any) => {
export function setupSendDataRecordButton(element: HTMLButtonElement, suaveWallet: any, onSendDataRecord: (txHash: Hex, err?: any) => void) {
element.innerHTML = `send data`
const sendDataRecord = async (suaveWallet: any) => {
// create sample transaction; won't land onchain, but will pass payload validation
const sampleTx = {
type: "eip1559" as 'eip1559',
Expand All @@ -66,26 +66,26 @@ export function setupSendBidButton(element: HTMLButtonElement, suaveWallet: any,
const signedTx = await goerliWallet.signTransaction(sampleTx)
console.log("signed goerli tx", signedTx)

// create bid & send ccr
// create data record & send ccr
try {
const bid = new MevShareBid(
const dataRecord = new MevShareRecord(
1n + await goerliProvider.getBlockNumber(),
signedTx,
KETTLE_ADDRESS,
BidContractDeployment.address as Address,
MevShareContract.address as Address,
suaveRigil.id
)
console.log(bid)
const ccr = bid.toConfidentialRequest()
console.log(dataRecord)
const ccr = dataRecord.toConfidentialRequest()
const txHash = await suaveWallet.sendTransaction(ccr)
console.log("sendResult", txHash)
// callback with result
onSendBid(txHash)
onSendDataRecord(txHash)
} catch (e) {
return onSendBid('0x', e)
return onSendDataRecord('0x', e)
}
}
element.addEventListener('click', () => sendBid(suaveWallet))
element.addEventListener('click', () => sendDataRecord(suaveWallet))
}

export function setupDripFaucetButton(element: HTMLButtonElement, account: Address, onFaucet: (txHash: Hex, err?: any) => void) {
Expand Down
16 changes: 8 additions & 8 deletions examples/suave/bids/index.ts → examples/suave/bundles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from 'viem'
import { suaveRigil } from '../../../src/chains'
import { SuaveTxTypes, TransactionRequestSuave } from '../../../src/chains/suave/types'
import MevShareBidContract from '../contracts/out/bids.sol/MevShareBidContract.json'
import MevShareContract from '../contracts/out/bids.sol/MevShareContract.json'

export interface MevShareBid {
export interface MevShareRecord {
allowedPeekers: Address[]
allowedStores: Address[]
blockNumber: bigint
Expand All @@ -19,8 +19,8 @@ export interface MevShareBid {
chainId: number
}

/** Helper class to create MEV-Share bids on SUAVE. */
export class MevShareBid {
/** Helper class to create MEV-Share data records on SUAVE. */
export class MevShareRecord {
constructor(
blockNumber: bigint,
signedTx: Hex,
Expand All @@ -40,10 +40,10 @@ export class MevShareBid {
this.allowedStores = []
}

/** Encodes calldata to call the `newBid` function. */
private newBidCalldata() {
/** Encodes calldata to call the `newTransaction` function. */
private newCalldata() {
return encodeFunctionData({
abi: MevShareBidContract.abi,
abi: MevShareContract.abi,
functionName: 'newBid',
args: [this.blockNumber, this.allowedPeekers, this.allowedStores],
})
Expand All @@ -64,7 +64,7 @@ export class MevShareBid {
toConfidentialRequest(): TransactionRequestSuave {
return {
to: this.mevShareContract,
data: this.newBidCalldata(),
data: this.newCalldata(),
type: '0x43',
gas: 500000n,
gasPrice: 1000000000n,
Expand Down
2 changes: 1 addition & 1 deletion examples/suave/contracts/src/ConfidentialWithLogs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ contract ConfidentialWithLogs {
// note: this enables the computation result to be emitted on chain
return bytes.concat(this.emitSimResultEvent.selector, abi.encode(effectiveGasPrice));
}
}
}
2 changes: 1 addition & 1 deletion examples/suave/deployContracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FUNDED_PRV_KEY=0x91ab9a7e53c220e6210460b65a7a3bb2ca181412a8a7b43ff336b3df1737ce1
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/contracts
forge build
createOutput=$(forge create --legacy --private-key $FUNDED_PRV_KEY --chain-id 16813125 -r http://localhost:8545 lib/suave-geth/suave/sol/standard_peekers/bids.sol:MevShareBidContract)
createOutput=$(forge create --legacy --private-key $FUNDED_PRV_KEY --chain-id 16813125 -r http://localhost:8545 lib/suave-geth/suave/sol/standard_peekers/bids.sol:MevShareContract)
deployedAddress=$(echo "$createOutput" | grep 'Deployed to:' | awk '{print $3}')
echo "Deployed to: $deployedAddress"
echo '{"address": ''"'$deployedAddress'"}' > $SCRIPT_DIR/deployedAddress.json
24 changes: 12 additions & 12 deletions examples/suave/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { sleep } from 'bun'
import { http, Address, Hex, createPublicClient, formatEther, isHex } from 'viem'
import { goerli, suaveRigil } from 'viem/chains'
import { TransactionRequestSuave } from 'viem/chains/suave/types'
import { MevShareBid } from 'bids'
import { MevShareRecord } from 'bundles'
import { SuaveProvider, SuaveWallet, getSuaveProvider, getSuaveWallet } from 'viem/chains/utils'
import { HttpTransport } from 'viem'
import BidContractDeployment from './deployedAddress.json'
import MevShareContract from './deployedAddress.json'

const failEnv = (name: string) => {
throw new Error(`missing env var ${name}`)
Expand Down Expand Up @@ -88,17 +88,17 @@ const fundAccount = async (wallet: Address, amount: bigint) => {
* See the [README](./README.md) for instructions.
*/
async function testSuaveBids() {
if (!BidContractDeployment.address) {
if (!MevShareContract.address) {
console.error(
'Need to run the DeployContracts script first. See ./README.md for instructions.',
)
failEnv('BID_CONTRACT_ADDRESS')
failEnv('MEV_SHARE_CONTRACT_ADDRESS')
}
if (!isHex(BidContractDeployment.address)) {
console.error('BID_CONTRACT_ADDRESS is not a hex string')
failEnv('BID_CONTRACT_ADDRESS')
if (!isHex(MevShareContract.address)) {
console.error('MEV_SHARE_CONTRACT_ADDRESS is not a hex string')
failEnv('MEV_SHARE_CONTRACT_ADDRESS')
}
const BID_CONTRACT_ADDRESS = BidContractDeployment.address as Hex
const MEV_SHARE_CONTRACT_ADDRESS = MevShareContract.address as Hex

// fund our test wallet w/ 1 ETH
const fundRes = await fundAccount(
Expand All @@ -118,16 +118,16 @@ async function testSuaveBids() {
}
const signedTx = await wallet.signTransaction(testTx)

// create bid & send ccr
// create data record & send ccr
const block = await goerliProvider.getBlockNumber()
const bid = new MevShareBid(
const dataRecord = new MevShareRecord(
block + 1n,
signedTx,
KETTLE_ADDRESS,
BID_CONTRACT_ADDRESS,
MEV_SHARE_CONTRACT_ADDRESS,
suaveRigil.id,
)
const ccr = bid.toConfidentialRequest()
const ccr = dataRecord.toConfidentialRequest()
const ccrRes = await wallet.sendTransaction(ccr)
console.log('ccrRes', ccrRes)

Expand Down
Loading