Class: WhopSDK::Resources::Swaps

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/resources/swaps.rb,
sig/whop_sdk/resources/swaps.rbs

Overview

Swaps convert value between supported tokens, chains, or wallet destinations for an account. A swap quote describes the expected output, fees, and approval requirements before you create the swap.

Use the Swaps API to quote a conversion, create the swap, list recent swaps, and retrieve status until the transaction completes.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Swaps

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Swaps.

Parameters:



138
139
140
# File 'lib/whop_sdk/resources/swaps.rb', line 138

def initialize(client:)
  @client = client
end

Instance Method Details

#create(account_id:, amount:, from_token:, to_token:, from_chain: nil, slippage_bps: nil, to_chain: nil, request_options: {}) ⇒ WhopSDK::Models::SwapCreateResponse

Some parameter documentations has been truncated, see Models::SwapCreateParams for more details.

Executes a swap from the account's wallet. Runs asynchronously; poll GET /swaps/id for status.

Parameters:

  • account_id (String)

    Business or user account ID (biz* / user*).

  • amount (String)

    Source token amount.

  • from_token (String)

    Source token contract address or ticker symbol, such as "USDT".

  • to_token (String)

    Destination token contract address or ticker symbol, such as "XAUT".

  • from_chain (String, Integer, nil)

    Source chain name or chain ID. Defaults to the source token's chain when omitted

  • slippage_bps (Integer, nil)

    Maximum slippage tolerance in basis points.

  • to_chain (String, Integer, nil)

    Destination chain name or chain ID. Defaults to the destination token's chain wh

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



39
40
41
42
43
44
45
46
47
48
# File 'lib/whop_sdk/resources/swaps.rb', line 39

def create(params)
  parsed, options = WhopSDK::SwapCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "swaps",
    body: parsed,
    model: WhopSDK::Models::SwapCreateResponse,
    options: options
  )
end

#create_quote(amount:, from_token:, to_token:, from_address: nil, from_chain: nil, metadata: nil, slippage_bps: nil, to_address: nil, to_chain: nil, request_options: {}) ⇒ WhopSDK::Models::SwapCreateQuoteResponse

Some parameter documentations has been truncated, see Models::SwapCreateQuoteParams for more details.

Returns a stateless swap price preview. No funds move and nothing is persisted.

Parameters:

  • amount (String)

    Source token amount.

  • from_token (String)

    Source token contract address or ticker symbol, such as "USDT".

  • to_token (String)

    Destination token contract address or ticker symbol, such as "XAUT".

  • from_address (String, nil)

    Source wallet address used for the quote.

  • from_chain (String, Integer, nil)

    Source chain name or chain ID. Defaults to the source token's chain when omitted

  • metadata (Hash{Symbol=>Object})

    Metadata to include with the quote response.

  • slippage_bps (Integer, nil)

    Maximum slippage tolerance in basis points.

  • to_address (String, nil)

    Destination wallet address used for the quote.

  • to_chain (String, Integer, nil)

    Destination chain name or chain ID. Defaults to the destination token's chain wh

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



124
125
126
127
128
129
130
131
132
133
# File 'lib/whop_sdk/resources/swaps.rb', line 124

def create_quote(params)
  parsed, options = WhopSDK::SwapCreateQuoteParams.dump_request(params)
  @client.request(
    method: :post,
    path: "swaps/quote",
    body: parsed,
    model: WhopSDK::Models::SwapCreateQuoteResponse,
    options: options
  )
end

#list(account_id:, request_options: {}) ⇒ WhopSDK::Models::SwapListResponse

Lists the account's swaps. Currently returns the in-flight or most recent swap, so zero or one rows.

Parameters:

  • account_id (String)

    Business or user account ID (biz* / user*).

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/whop_sdk/resources/swaps.rb', line 82

def list(params)
  parsed, options = WhopSDK::SwapListParams.dump_request(params)
  query = WhopSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "swaps",
    query: query,
    model: WhopSDK::Models::SwapListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ WhopSDK::Models::SwapRetrieveResponse

Returns the status of a specific swap, by the id returned from POST /swaps.

Parameters:

  • id (String)

    Swap ID returned from POST /swaps.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



61
62
63
64
65
66
67
68
# File 'lib/whop_sdk/resources/swaps.rb', line 61

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["swaps/%1$s", id],
    model: WhopSDK::Models::SwapRetrieveResponse,
    options: params[:request_options]
  )
end