Skip to main content

OrderBuilder

Struct OrderBuilder 

Source
pub struct OrderBuilder { /* private fields */ }
Expand description

Main OrderBuilder struct for creating and signing orders

This is the primary interface for interact with predict.fun’s CTF Exchange

Implementations§

Source§

impl OrderBuilder

Source

pub fn new( chain_id: ChainId, signer: Option<PrivateKeySigner>, options: Option<OrderBuilderOptions>, ) -> Result<Self>

Create a new OrderBuilder

§Arguments
  • chain_id - The chain ID (BNB Mainnet or Testnet)
  • signer - Optional signer for signing orders
  • options - Optional configuration options
§Returns

A new OrderBuilder instance

Source

pub fn with_predict_account( chain_id: ChainId, signer: PrivateKeySigner, predict_account: &str, options: Option<OrderBuilderOptions>, ) -> Result<Self>

Create a new OrderBuilder with Predict Account support

Use this constructor when trading via a Predict Smart Wallet (Kernel-based). The predict_account address will be used as the order maker, and signatures will use Kernel EIP-712 wrapping.

§Arguments
  • chain_id - The chain ID (BNB Mainnet or Testnet)
  • signer - The Privy private key signer
  • predict_account - The Predict Account (smart wallet) address
  • options - Optional configuration options
§Returns

A new OrderBuilder instance configured for Predict Account signing

Source

pub fn uses_predict_account(&self) -> bool

Check if this OrderBuilder uses Predict Account signing

Source

pub fn predict_account(&self) -> Option<Address>

Get the Predict Account address if set

Source

pub fn signer_address(&self) -> Result<Address>

Get the signer address

§Returns

The signer address, or an error if no signer is configured

Source

pub fn signer(&self) -> Option<PrivateKeySigner>

Get a clone of the signer (for on-chain operations)

§Returns

A clone of the signer, or None if no signer is configured

Source

pub fn get_limit_order_amounts( &self, data: LimitOrderData, ) -> Result<LimitOrderAmounts>

Helper function to calculate the amounts for a LIMIT strategy order

§Arguments
  • data - The limit order data (side, price, quantity)
§Returns

Order amounts including maker/taker amounts and price per share

§Errors

Returns an error if the quantity is too small (< 1e16)

Source

pub fn build_order( &self, strategy: OrderStrategy, input: BuildOrderInput, ) -> Result<Order>

Build an order struct

§Arguments
  • strategy - The order strategy (MARKET or LIMIT)
  • input - The order input data
§Returns

A constructed Order ready for signing

§Errors

Returns an error if the input data is invalid or expiration is in the past

Source

pub fn get_verifying_contract( &self, is_neg_risk: bool, is_yield_bearing: bool, ) -> Address

Build EIP-712 typed data for an order

§Arguments
  • order - The order to build typed data for
  • is_neg_risk - Whether this is a neg risk market (winner takes all)
  • is_yield_bearing - Whether this market has yield enabled
§Returns

The verifying contract address

Source

pub fn build_typed_data_hash( &self, order: &Order, is_neg_risk: bool, is_yield_bearing: bool, ) -> Result<String>

Build the EIP-712 typed data hash for an order

§Arguments
  • order - The order to hash
  • is_neg_risk - Whether this is a neg risk market
  • is_yield_bearing - Whether this market has yield enabled
§Returns

The hash to be signed

§Errors

Returns an error if the order data is invalid

Source

pub async fn sign_typed_data_order( &self, order: Order, is_neg_risk: bool, is_yield_bearing: bool, ) -> Result<SignedOrder>

Sign an order using EIP-712

This method automatically uses the appropriate signing method:

  • For regular EOA wallets: Standard EIP-712 signing
  • For Predict Account (Kernel): Kernel-wrapped EIP-712 signing
§Arguments
  • order - The order to sign
  • is_neg_risk - Whether this is a neg risk market
  • is_yield_bearing - Whether this market has yield enabled
§Returns

A signed order with signature

§Errors

Returns an error if no signer is configured or signing fails

Source

pub async fn sign_typed_data_order_eoa( &self, order: Order, is_neg_risk: bool, is_yield_bearing: bool, ) -> Result<SignedOrder>

Sign an order using standard EOA EIP-712 (never Kernel-wrapped)

This is used for REST API order placement, where the server does plain ecrecover to verify the signature. Kernel-wrapped signatures are only needed for on-chain settlement, which the platform handles internally.

Source

pub fn signer_address_string(&self) -> Result<String>

Get the EOA signer address as a formatted string

Source

pub fn chain_id(&self) -> ChainId

Get the chain ID

Source

pub fn addresses(&self) -> &Addresses

Get the addresses

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more