pub struct RelayClient { /* private fields */ }Expand description
Client for interacting with the Polymarket Builder Relayer.
Implementations§
Source§impl RelayClient
impl RelayClient
Sourcepub async fn new(
chain_id: u64,
signer: LocalWallet,
auth: AuthMethod,
tx_type: RelayerTxType,
) -> Result<Self>
pub async fn new( chain_id: u64, signer: LocalWallet, auth: AuthMethod, tx_type: RelayerTxType, ) -> Result<Self>
Create a new RelayClient.
§Arguments
chain_id- Chain ID (137 for Polygon mainnet)signer- Ethers LocalWallet for signing transactionsauth- Authentication method (Builder or RelayerKey)tx_type- Wallet type (Safe or Proxy)
Sourcepub fn set_rpc_url(&mut self, url: String)
pub fn set_rpc_url(&mut self, url: String)
Set an RPC URL for reading the Safe nonce on-chain.
Highly recommended — the relayer API /nonce endpoint can return
stale values (e.g., 0), causing GS026 “Invalid owner” errors because
the EIP-712 hash is computed with the wrong nonce.
When set, get_nonce() reads the nonce directly from the Safe contract
on-chain, falling back to the relayer API only on failure.
Sourcepub fn signer_address(&self) -> Address
pub fn signer_address(&self) -> Address
Get the signer’s EOA address.
Sourcepub fn wallet_address(&self) -> Result<Address>
pub fn wallet_address(&self) -> Result<Address>
Get the derived wallet address (Safe, Proxy, or EOA).
Sourcepub async fn is_deployed(&self) -> Result<bool>
pub async fn is_deployed(&self) -> Result<bool>
Check if the Safe wallet is deployed.
Sourcepub async fn get_nonce(&self) -> Result<u64>
pub async fn get_nonce(&self) -> Result<u64>
Get the current nonce for the wallet.
For Safe wallets: reads from on-chain nonce() if rpc_url is set,
otherwise falls back to the relayer API. The relayer API is known to
return stale nonces (e.g., 0) which causes GS026 errors.
Sourcepub async fn get_transaction(&self, tx_id: &str) -> Result<TxResult>
pub async fn get_transaction(&self, tx_id: &str) -> Result<TxResult>
Get a transaction’s status by ID.
Sourcepub async fn deploy(&self) -> Result<TxResult>
pub async fn deploy(&self) -> Result<TxResult>
Deploy a Safe wallet (one-time, Safe wallet type only).
Sourcepub async fn execute(
&self,
txs: Vec<Transaction>,
description: &str,
) -> Result<TransactionResponseHandle>
pub async fn execute( &self, txs: Vec<Transaction>, description: &str, ) -> Result<TransactionResponseHandle>
Execute one or more transactions through the relayer.
Sourcepub async fn execute_sequential(
&self,
batches: Vec<Vec<Transaction>>,
delay: Option<Duration>,
on_progress: Option<&dyn Fn(usize, usize)>,
) -> Result<Vec<TxResult>>
pub async fn execute_sequential( &self, batches: Vec<Vec<Transaction>>, delay: Option<Duration>, on_progress: Option<&dyn Fn(usize, usize)>, ) -> Result<Vec<TxResult>>
Execute multiple groups of transactions sequentially, waiting for each to confirm before submitting the next.
This avoids nonce collisions when the relay bot (Gelato) cannot handle back-to-back requests for the same proxy wallet.
§Arguments
batches- Each innerVec<Transaction>is submitted as one relay request.delay- Wait time between confirmed batches (default 5s ifNone).on_progress- Optional callback(completed, total)after each batch confirms.
Returns a vec of TxResult, one per batch (in order).
Sourcepub async fn execute_batch(
&self,
txs: Vec<Transaction>,
description: &str,
) -> Result<TxResult>
pub async fn execute_batch( &self, txs: Vec<Transaction>, description: &str, ) -> Result<TxResult>
Execute multiple transactions as a single batched relay request.
All transactions share one nonce and one relay call, completely avoiding nonce collisions. More gas-efficient than sequential execution.
For Proxy wallets, the gas limit scales with the number of transactions:
gas_limit = 150_000 + (extra_txs * 80_000), capped at 400_000.
For Safe wallets, multiple transactions are packed via multiSend
(already handled by build_safe_request).
Sourcepub async fn approve_usdc_for_ctf(&self) -> Result<TransactionResponseHandle>
pub async fn approve_usdc_for_ctf(&self) -> Result<TransactionResponseHandle>
Approve USDC.e for CTF Exchange.
Sourcepub async fn approve_usdc_for_negrisk(
&self,
) -> Result<TransactionResponseHandle>
pub async fn approve_usdc_for_negrisk( &self, ) -> Result<TransactionResponseHandle>
Approve USDC.e for Neg Risk CTF Exchange.
Sourcepub async fn approve_ctf_for_exchange(
&self,
) -> Result<TransactionResponseHandle>
pub async fn approve_ctf_for_exchange( &self, ) -> Result<TransactionResponseHandle>
Approve CTF tokens (ERC1155) for CTF Exchange.
Sourcepub async fn setup_approvals(&self) -> Result<TransactionResponseHandle>
pub async fn setup_approvals(&self) -> Result<TransactionResponseHandle>
Set up all standard approvals in a single batch.
Sourcepub fn derive_deposit_wallet_address(&self) -> Result<Address>
pub fn derive_deposit_wallet_address(&self) -> Result<Address>
Predict the V2 Deposit Wallet address for the current signer EOA.
Pure CREATE2 derivation — does not query the relayer.
Sourcepub async fn deploy_deposit_wallet(&self) -> Result<TxResult>
pub async fn deploy_deposit_wallet(&self) -> Result<TxResult>
Deploy a Deposit Wallet via the relayer (gasless, type WALLET-CREATE).
Idempotent on the relayer side: a second call for an already-deployed
wallet typically returns Invalid. Use is_deposit_wallet_deployed
to gate the call.
Sourcepub async fn is_deposit_wallet_deployed(&self) -> Result<bool>
pub async fn is_deposit_wallet_deployed(&self) -> Result<bool>
Check whether a Deposit Wallet is already deployed at the derived
address, using GET /deployed?address=...&type=WALLET.
Sourcepub async fn get_deposit_wallet_nonce(&self) -> Result<u64>
pub async fn get_deposit_wallet_nonce(&self) -> Result<u64>
Fetch the Deposit Wallet nonce from the relayer (GET /nonce?type=WALLET).
Sourcepub async fn execute_deposit_wallet_batch(
&self,
calls: Vec<DepositWalletCall>,
deposit_wallet_addr: Option<Address>,
deadline: u64,
metadata: Option<&str>,
) -> Result<TransactionResponseHandle>
pub async fn execute_deposit_wallet_batch( &self, calls: Vec<DepositWalletCall>, deposit_wallet_addr: Option<Address>, deadline: u64, metadata: Option<&str>, ) -> Result<TransactionResponseHandle>
Execute a batch of calls through the user’s Deposit Wallet (V2 flow).
Mirrors the TypeScript SDK’s executeDepositWalletBatch:
- Read the WALLET nonce from
/nonce?type=WALLET. - EIP-712-sign the
Batch{wallet, nonce, deadline, calls[]}struct. - POST
/submitwithtype: "WALLET"anddepositWalletParams.
The Deposit Wallet must already be deployed (see
deploy_deposit_wallet). If deposit_wallet is None the address
is derived from the signer.
deadline is a unix timestamp (seconds) after which the batch is
invalid. The TS examples typically use now + 4 minutes.
Sourcepub async fn setup_approvals_v2(&self) -> Result<TransactionResponseHandle>
pub async fn setup_approvals_v2(&self) -> Result<TransactionResponseHandle>
Set up all V2 approvals (pUSD + adapters + V2 exchanges) in one batch.
After the V2 migration (2026-04-28) the user-facing collateral is pUSD, so trading and split/merge require fresh approvals against the new contracts. Includes:
- pUSD → V2 CTF Exchange / V2 Neg Risk Exchange (for orderbook trades)
- pUSD → CtfCollateralAdapter / NegRiskCtfCollateralAdapter (for split)
- CTF (ERC-1155) → V2 exchanges + both collateral adapters (for trades / merge)
- CTF (ERC-1155) → NegRiskAdapter (for neg-risk redeem; unchanged from V1)
Note: for Proxy wallets, this is 9 inner calls and will exceed the
relayer’s per-tx gas budget — call the individual approvals one by one
or use execute_sequential instead. Safe wallets pack these via
MultiSend and submit them as one transaction without issue.
Trait Implementations§
Source§impl Clone for RelayClient
impl Clone for RelayClient
Source§fn clone(&self) -> RelayClient
fn clone(&self) -> RelayClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RelayClient
impl !RefUnwindSafe for RelayClient
impl Send for RelayClient
impl Sync for RelayClient
impl Unpin for RelayClient
impl UnsafeUnpin for RelayClient
impl !UnwindSafe for RelayClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.