Skip to main content

RelayClient

Struct RelayClient 

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

Client for submitting gasless transactions through Polymarket’s relayer service.

Supports both Safe and Proxy wallet types. Handles EIP-712 transaction signing, nonce management, and multi-send batching automatically.

Implementations§

Source§

impl RelayClient

Source

pub fn new( private_key: impl Into<String>, config: Option<BuilderConfig>, ) -> Result<Self, RelayError>

Create a new Relay client with authentication

Source

pub fn builder() -> Result<RelayClientBuilder, RelayError>

Create a new Relay client builder

Source

pub fn default_builder() -> Result<RelayClientBuilder, RelayError>

Create a new Relay client builder pulling settings from environment

Source

pub fn from_account(account: BuilderAccount) -> Result<Self, RelayError>

Create a new Relay client from a BuilderAccount

Source

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

Returns the signer’s Ethereum address, or None if no account is configured.

Source

pub async fn ping(&self) -> Result<Duration, RelayError>

Measure the round-trip time (RTT) to the Relay API.

Makes a GET request to the API base URL and returns the latency.

§Example
use polyoxide_relay::RelayClient;

let client = RelayClient::builder()?.build()?;
let latency = client.ping().await?;
println!("API latency: {}ms", latency.as_millis());
Source

pub async fn get_nonce(&self, address: Address) -> Result<u64, RelayError>

Fetch the current transaction nonce for an address from the relayer.

Source

pub async fn get_transaction( &self, transaction_id: &str, ) -> Result<TransactionStatusResponse, RelayError>

Query the status of a previously submitted relay transaction.

Source

pub async fn get_deployed( &self, safe_address: Address, ) -> Result<bool, RelayError>

Check whether a Safe wallet has been deployed on-chain.

Source

pub fn get_expected_safe(&self) -> Result<Address, RelayError>

Derive the expected Safe wallet address for the configured account via CREATE2.

Source

pub fn get_expected_proxy_wallet(&self) -> Result<Address, RelayError>

Derive the expected Proxy wallet address for the configured account via CREATE2.

Source

pub async fn get_relay_payload( &self, address: Address, ) -> Result<(Address, u64), RelayError>

Get relay payload for PROXY wallets (returns relay address and nonce)

Source

pub async fn execute( &self, transactions: Vec<SafeTransaction>, metadata: Option<String>, ) -> Result<RelayerTransactionResponse, RelayError>

Sign and submit transactions through the relayer with default gas settings.

Source

pub async fn execute_with_gas( &self, transactions: Vec<SafeTransaction>, metadata: Option<String>, gas_limit: Option<u64>, ) -> Result<RelayerTransactionResponse, RelayError>

Sign and submit transactions through the relayer with an optional gas limit override.

For Safe wallets, transactions are batched via MultiSend. For Proxy wallets, they are encoded into the proxy’s calldata format.

Source

pub async fn estimate_redemption_gas( &self, condition_id: [u8; 32], index_sets: Vec<U256>, ) -> Result<u64, RelayError>

Estimate gas required for a redemption transaction.

Returns the estimated gas limit with relayer overhead and safety buffer included. Uses the default RPC URL configured for the current chain.

§Arguments
  • condition_id - The condition ID to redeem
  • index_sets - The index sets to redeem
§Example
use polyoxide_relay::{RelayClient, BuilderAccount, BuilderConfig, WalletType};
use alloy::primitives::{U256, hex};

let builder_config = BuilderConfig::new(
    "key".to_string(),
    "secret".to_string(),
    None,
);
let account = BuilderAccount::new("0x...", Some(builder_config))?;
let client = RelayClient::builder()?
    .with_account(account)
    .wallet_type(WalletType::Proxy)
    .build()?;

let condition_id = [0u8; 32];
let index_sets = vec![U256::from(1)];
let estimated_gas = client
    .estimate_redemption_gas(condition_id, index_sets)
    .await?;
println!("Estimated gas: {}", estimated_gas);
Source

pub async fn submit_gasless_redemption( &self, condition_id: [u8; 32], index_sets: Vec<U256>, ) -> Result<RelayerTransactionResponse, RelayError>

Submit a gasless CTF position redemption without gas estimation.

Source

pub async fn submit_gasless_redemption_with_gas_estimation( &self, condition_id: [u8; 32], index_sets: Vec<U256>, estimate_gas: bool, ) -> Result<RelayerTransactionResponse, RelayError>

Submit a gasless CTF position redemption, optionally estimating gas first.

When estimate_gas is true, simulates the redemption against the configured RPC endpoint to determine a safe gas limit before submission.

Trait Implementations§

Source§

impl Clone for RelayClient

Source§

fn clone(&self) -> RelayClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RelayClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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