-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbids.ts
69 lines (64 loc) · 1.82 KB
/
bids.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
Address,
Hex,
encodeAbiParameters,
encodeFunctionData,
} from '@flashbots/suave-viem'
import { TransactionRequestSuave } from '@flashbots/suave-viem/chains/utils'
import OFAContract from './contracts/out/OFA.sol/OFAPrivate.json'
/** Factory class to create MEV-Share bids on SUAVE. */
export class OFAOrder {
blockNumber: bigint
signedTx: Hex
OFAContract: Address
kettle: Address
constructor(
blockNumber: bigint,
signedTx: Hex,
kettle: Address,
OFAContract: Address,
) {
this.blockNumber = blockNumber
this.signedTx = signedTx
this.kettle = kettle
this.OFAContract = OFAContract
}
/** Encodes calldata to call the `newOrder` function. */
private newOrderCalldata() {
return encodeFunctionData({
abi: OFAContract.abi,
functionName: 'newOrder',
args: [this.blockNumber],
})
}
/** Wraps `signedTx` in a bundle, then ABI-encodes it as bytes for `confidentialInputs`. */
private confidentialInputsBytes(): Hex {
return encodeAbiParameters([
{
components: [
{ type: 'uint64', name: 'blockNumber' },
{ type: 'uint64', name: 'minTimestamp' },
{ type: 'uint64', name: 'maxTimestamp' },
{ type: 'bytes[]', name: 'txns' },
],
name: 'BundleObj',
type: 'tuple',
}] as const, [{
blockNumber: this.blockNumber,
minTimestamp: 0n,
maxTimestamp: 0n,
txns: [this.signedTx]
}])
}
/** Encodes this bid as a ConfidentialComputeRequest, which can be sent to SUAVE. */
toConfidentialRequest(isEIP712?: boolean): TransactionRequestSuave {
return {
to: this.OFAContract,
data: this.newOrderCalldata(),
isEIP712,
gas: 10000000n,
kettleAddress: this.kettle,
confidentialInputs: this.confidentialInputsBytes(),
}
}
}