Documentation
¶
Overview ¶
Package relayer provides a client for the Polymarket Relayer API.
Overview ¶
The Relayer API submits EIP-712 signed transactions to the Polygon blockchain on behalf of users. It handles nonce management and transaction ordering.
Authentication ¶
Uses RELAYER_API_KEY and RELAYER_API_KEY_ADDRESS headers, or POLY_BUILDER_* headers for builder-authenticated requests.
Usage ¶
client := relayer.New(relayer.Config{
Credentials: &relayer.Credentials{
APIKey: "your-relayer-api-key",
Address: "0xYourAddress",
},
})
// Submit a signed transaction
var resp relayer.SubmitTransactionResponse
err := client.SubmitTransaction(ctx, relayer.SubmitTransactionRequest{...}, &resp)
// Check transaction status
tx := relayer.Transaction{TransactionID: "tx-id"}
err = client.GetTransaction(ctx, &tx)
// Get recent transactions
txs, err := client.GetRecentTransactions(ctx)
Index ¶
- Constants
- func CalculateProxyGasLimit(transactionCount int) string
- func DeriveProxyWalletAddress(owner common.Address) common.Address
- func DeriveSafeAddress(owner common.Address, chainID int64) (common.Address, error)
- func EncodeProxyTransactionData(txs []ProxyTransaction) (string, error)
- func WalletCreateSubmitTransactionRequest(signer *polyauth.Signer, args *WalletCreateSubmitTransactionArgs, ...) error
- type APIKey
- type BuilderCredentials
- type CallType
- type Client
- func (c *Client) DeployDepositWallet(ctx context.Context, signer *polyauth.Signer, ...) error
- func (c *Client) GetAPIKeys(ctx context.Context) ([]APIKey, error)
- func (c *Client) GetNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
- func (c *Client) GetRecentTransactions(ctx context.Context, _ ...string) ([]Transaction, error)
- func (c *Client) GetRelayPayload(ctx context.Context, out *NonceResponse, nonceType NonceType) error
- func (c *Client) GetRelayerNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
- func (c *Client) GetTransaction(ctx context.Context, out *Transaction) error
- func (c *Client) Host() string
- func (c *Client) IsSafeDeployed(ctx context.Context, out *SafeDeployedResponse) error
- func (c *Client) ProxySubmitTransactionRequest(ctx context.Context, signer *polyauth.Signer, req *ProxySubmitTransactionArgs, ...) error
- func (c *Client) SafeSubmitTransactionRequest(ctx context.Context, signer *polyauth.Signer, req *SafeSubmitTransactionArgs, ...) error
- func (c *Client) SubmitTransaction(ctx context.Context, req *SubmitTransactionRequest, ...) error
- func (c *Client) WalletCreateSubmitTransactionRequest(_ context.Context, signer *polyauth.Signer, ...) error
- type Config
- type Credentials
- type DepositWalletCall
- type DepositWalletParams
- type NonceResponse
- type NonceType
- type OperationType
- type ProxySubmitTransactionArgs
- type ProxyTransaction
- type SafeDeployedResponse
- type SafeSubmitTransactionArgs
- type SafeTransaction
- type SignatureParams
- type SubmitTransactionRequest
- type SubmitTransactionResponse
- type Transaction
- type WalletCreateSubmitTransactionArgs
Constants ¶
const DefaultHost = "https://relayer-v2.polymarket.com"
DefaultHost is the production Polymarket Relayer API host.
Variables ¶
This section is empty.
Functions ¶
func CalculateProxyGasLimit ¶ added in v1.1.4
CalculateProxyGasLimit mirrors the official proxy relayer example gas limit heuristic.
func DeriveProxyWalletAddress ¶ added in v1.1.4
DeriveProxyWalletAddress derives the Polymarket proxy wallet address for a signer.
This mirrors the proxy-wallet flow used by Polymarket Magic users.
func DeriveSafeAddress ¶ added in v1.1.4
func EncodeProxyTransactionData ¶ added in v1.1.4
func EncodeProxyTransactionData(txs []ProxyTransaction) (string, error)
EncodeProxyTransactionData encodes a PROXY transaction batch. It corresponds to the official TS client path where generic Transaction[] is converted to ProxyTransaction[] and passed through encodeProxyTransactionData.
func WalletCreateSubmitTransactionRequest ¶ added in v1.1.5
func WalletCreateSubmitTransactionRequest( signer *polyauth.Signer, args *WalletCreateSubmitTransactionArgs, out *SubmitTransactionRequest, ) error
WalletCreateSubmitTransactionRequest builds a WALLET-CREATE relayer submit request.
WALLET-CREATE deploys a deterministic deposit wallet and does not require nonce, user signature, signatureParams, proxyWallet, or calldata.
Types ¶
type APIKey ¶
type APIKey struct {
// Key is the API key.
Key string `json:"apiKey"`
// Address is the owner address.
Address string `json:"address"`
// CreatedAt is the key creation timestamp.
CreatedAt pmtypes.Time `json:"createdAt"`
// UpdatedAt is the key update timestamp.
UpdatedAt pmtypes.Time `json:"updatedAt"`
}
APIKey describes a relayer API key.
type BuilderCredentials ¶
type BuilderCredentials struct {
// APIKey is the builder API key.
APIKey string
// Secret is the URL-safe base64 builder API secret.
Secret string
// Passphrase is the builder API passphrase.
Passphrase string
}
BuilderCredentials contains builder-key authentication material for relayer requests.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Polymarket Relayer API client.
func (*Client) DeployDepositWallet ¶ added in v1.1.5
func (c *Client) DeployDepositWallet( ctx context.Context, signer *polyauth.Signer, args *WalletCreateSubmitTransactionArgs, out *SubmitTransactionResponse, ) error
DeployDepositWallet submits a WALLET-CREATE request through the relayer.
func (*Client) GetAPIKeys ¶
GetAPIKeys returns all relayer API keys available to the authenticated caller.
func (*Client) GetRecentTransactions ¶
GetRecentTransactions returns recent transactions owned by the authenticated address.
func (*Client) GetRelayPayload ¶
func (c *Client) GetRelayPayload(ctx context.Context, out *NonceResponse, nonceType NonceType) error
GetRelayPayload writes the relayer address and nonce for out.Address into out.
func (*Client) GetRelayerNonce ¶
func (c *Client) GetRelayerNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
GetRelayerNonce writes the relayer address and nonce for out.Address into out.
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(ctx context.Context, out *Transaction) error
GetTransaction writes a relayer transaction by out.TransactionID into out.
func (*Client) IsSafeDeployed ¶
func (c *Client) IsSafeDeployed(ctx context.Context, out *SafeDeployedResponse) error
IsSafeDeployed writes whether out.Address is deployed into out.
func (*Client) ProxySubmitTransactionRequest ¶ added in v1.1.5
func (c *Client) ProxySubmitTransactionRequest( ctx context.Context, signer *polyauth.Signer, req *ProxySubmitTransactionArgs, out *SubmitTransactionRequest, ) error
ProxySubmitTransactionRequest builds and signs a PROXY relayer submit request.
func (*Client) SafeSubmitTransactionRequest ¶ added in v1.1.5
func (c *Client) SafeSubmitTransactionRequest( ctx context.Context, signer *polyauth.Signer, req *SafeSubmitTransactionArgs, out *SubmitTransactionRequest, ) error
SafeSubmitTransactionRequest builds and signs a SAFE relayer submit request.
func (*Client) SubmitTransaction ¶
func (c *Client) SubmitTransaction(ctx context.Context, req *SubmitTransactionRequest, out *SubmitTransactionResponse) error
SubmitTransaction submits a signed transaction to the relayer and writes the response into out.
func (*Client) WalletCreateSubmitTransactionRequest ¶ added in v1.1.5
func (c *Client) WalletCreateSubmitTransactionRequest( _ context.Context, signer *polyauth.Signer, args *WalletCreateSubmitTransactionArgs, out *SubmitTransactionRequest, ) error
WalletCreateSubmitTransactionRequest builds a WALLET-CREATE relayer submit request.
type Config ¶
type Config struct {
// Host is the Relayer API host.
Host string
// HTTPClient is the client used for HTTP requests.
HTTPClient *http.Client
// UserAgent sets the User-Agent header.
UserAgent string
// Credentials configures Relayer API-key authentication.
Credentials *Credentials
// BuilderCredentials configures builder-key authentication.
BuilderCredentials *BuilderCredentials
}
Config configures a Relayer API client.
type Credentials ¶
type Credentials struct {
// APIKey is the relayer API key.
APIKey string
// Address is the owner address for APIKey.
Address string
}
Credentials contains Relayer API-key authentication headers.
type DepositWalletCall ¶ added in v1.1.5
type DepositWalletCall struct {
// Target is the contract address to call.
Target string `json:"target"`
// Value is the native token value for the call.
Value string `json:"value"`
// Data is 0x-prefixed calldata.
Data string `json:"data"`
}
DepositWalletCall is one call in a deposit-wallet batch.
type DepositWalletParams ¶ added in v1.1.5
type DepositWalletParams struct {
// DepositWallet is the deterministic deposit wallet address.
DepositWallet string `json:"depositWallet"`
// Deadline is the Unix timestamp after which the batch is invalid.
Deadline string `json:"deadline"`
// Calls are the wallet calls executed by the batch.
Calls []DepositWalletCall `json:"calls"`
}
DepositWalletParams contains the relayer payload for WALLET batch transactions.
type NonceResponse ¶
type NonceResponse struct {
// Nonce is the current relayer nonce.
Nonce pmtypes.String `json:"nonce"`
// Address is the associated relayer or user address when present.
Address string `json:"address,omitempty"`
}
NonceResponse is returned by nonce endpoints.
type NonceType ¶
type NonceType string
NonceType identifies the relayer nonce domain to query.
const ( // NonceTypeProxy selects the proxy-wallet nonce. NonceTypeProxy NonceType = "PROXY" // NonceTypeSafe selects the Safe-wallet nonce. NonceTypeSafe NonceType = "SAFE" // NonceTypeWallet selects the deposit-wallet batch nonce. NonceTypeWallet NonceType = "WALLET" // NonceTypeWalletCreate selects deposit-wallet deployment. NonceTypeWalletCreate NonceType = "WALLET-CREATE" )
type OperationType ¶ added in v1.1.4
type OperationType uint8
const ( OperationCall OperationType = 0 OperationDelegateCall OperationType = 1 )
type ProxySubmitTransactionArgs ¶ added in v1.1.4
type ProxySubmitTransactionArgs struct {
// From is the EOA signer address. If empty, signer.Address() is used.
From string
// ProxyWallet is the user's Polymarket proxy wallet / funder address.
// Required. Do not derive it unless the official CREATE2 formula is fully verified.
ProxyWallet string
// Data is encoded proxy transaction batch calldata.
Data string
// Metadata is optional relayer metadata.
Metadata string
// GasLimit optionally overrides the computed proxy gas limit.
GasLimit string
}
type ProxyTransaction ¶ added in v1.1.4
type SafeDeployedResponse ¶
type SafeDeployedResponse struct {
// Address is the Safe wallet address queried.
Address string `json:"address,omitempty"`
// Deployed is true when the Safe is deployed.
Deployed bool `json:"deployed"`
}
SafeDeployedResponse reports whether a Safe wallet is deployed.
type SafeSubmitTransactionArgs ¶ added in v1.1.4
type SafeSubmitTransactionArgs struct {
// From is the EOA signer address. If empty, signer.Address() is used.
From string
// ProxyWallet is the Safe wallet address. If empty, it is derived from From.
ProxyWallet string
// ChainID is the EIP-712 chain id.
ChainID int64
// Transactions are Safe transactions. Multiple transactions are wrapped in MultiSend.
Transactions []SafeTransaction
// Metadata is optional caller-provided relayer metadata.
Metadata string
}
SafeSubmitTransactionArgs contains input for building a signed SAFE submit request.
type SafeTransaction ¶ added in v1.1.4
type SafeTransaction struct {
To string `json:"to"`
Operation OperationType `json:"operation"`
Data string `json:"data"`
Value string `json:"value"`
}
func CreateSafeMultiSendTransaction ¶ added in v1.1.4
func CreateSafeMultiSendTransaction(txs []SafeTransaction, safeMultisend common.Address) (SafeTransaction, error)
CreateSafeMultiSendTransaction creates a Safe DelegateCall transaction to MultiSend.
type SignatureParams ¶
type SignatureParams struct {
// Existing SAFE fields.
// GasPrice is the Safe gas price parameter.
GasPrice string `json:"gasPrice,omitempty"`
// Operation is the Safe operation parameter.
Operation string `json:"operation,omitempty"`
// SafeTxGas is the Safe transaction gas parameter.
SafeTxGas string `json:"safeTxnGas,omitempty"`
// BaseGas is the Safe base gas parameter.
BaseGas string `json:"baseGas,omitempty"`
// GasToken is the token used for gas refunds.
GasToken string `json:"gasToken,omitempty"`
// RefundReceiver is the address receiving gas refunds.
RefundReceiver string `json:"refundReceiver,omitempty"`
// PROXY fields.
GasLimit string `json:"gasLimit,omitempty"`
RelayerFee string `json:"relayerFee,omitempty"`
RelayHub string `json:"relayHub,omitempty"`
Relay string `json:"relay,omitempty"`
}
SignatureParams contains Safe transaction signature parameters.
type SubmitTransactionRequest ¶
type SubmitTransactionRequest struct {
// From is the signer/owner address.
From string `json:"from"`
// To is the target contract address.
// For WALLET-CREATE this is the deposit wallet factory.
To string `json:"to"`
// ProxyWallet is the user's Polymarket proxy/safe wallet for legacy relayer flows.
ProxyWallet string `json:"proxyWallet,omitempty"`
// Data is 0x-prefixed encoded transaction calldata for legacy relayer flows.
Data string `json:"data,omitempty"`
// Nonce is the relayer transaction nonce.
Nonce string `json:"nonce,omitempty"`
// Signature is the 0x-prefixed transaction signature.
// WALLET-CREATE does not require a user signature.
Signature string `json:"signature,omitempty"`
// SignatureParams are Safe/proxy transaction parameters.
SignatureParams *SignatureParams `json:"signatureParams,omitempty"`
// Type is the transaction type: SAFE, PROXY, WALLET, or WALLET-CREATE.
Type NonceType `json:"type"`
// DepositWalletParams contains WALLET batch payload details.
DepositWalletParams *DepositWalletParams `json:"depositWalletParams,omitempty"`
// Metadata is optional caller-provided transaction metadata.
Metadata string `json:"metadata,omitempty"`
// Value is the native token value for the call when required.
Value string `json:"value,omitempty"`
}
SubmitTransactionRequest is the request body for POST /submit.
type SubmitTransactionResponse ¶
type SubmitTransactionResponse struct {
// TransactionID is the relayer transaction identifier.
TransactionID string `json:"transactionID"`
// State is the current relayer state.
State string `json:"state"`
}
SubmitTransactionResponse is returned immediately after a transaction is accepted.
type Transaction ¶
type Transaction struct {
// TransactionID is the relayer transaction identifier.
TransactionID string `json:"transactionID"`
// State is the current relayer state.
State string `json:"state"`
// TransactionHash is the on-chain hash after broadcast.
TransactionHash string `json:"transactionHash"`
// From is the signer address.
From string `json:"from"`
// To is the target contract address.
To string `json:"to"`
// ProxyWallet is the user's Polymarket proxy wallet.
ProxyWallet string `json:"proxyWallet"`
// Data is the 0x-prefixed calldata submitted to the relayer.
Data string `json:"data"`
// Nonce is the transaction nonce.
Nonce pmtypes.String `json:"nonce"`
// Value is the transaction value.
Value pmtypes.String `json:"value"`
// Signature is the 0x-prefixed transaction signature.
Signature string `json:"signature"`
// Type is the transaction type.
Type NonceType `json:"type"`
// Owner is the transaction owner.
Owner string `json:"owner"`
// Metadata is the transaction metadata.
Metadata string `json:"metadata"`
// CreatedAt is the creation timestamp.
CreatedAt pmtypes.Time `json:"createdAt"`
// UpdatedAt is the last update timestamp.
UpdatedAt pmtypes.Time `json:"updatedAt"`
}
Transaction describes a relayer transaction.