Class: Privy::Resources::Wallets::Swap

Inherits:
Object
  • Object
show all
Defined in:
lib/privy/resources/wallets/swap.rb

Overview

Operations for swapping tokens within wallets

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Swap

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 Swap.

Parameters:



99
100
101
# File 'lib/privy/resources/wallets/swap.rb', line 99

def initialize(client:)
  @client = client
end

Instance Method Details

#execute(wallet_id, base_amount:, destination:, source:, amount_type: nil, fee_configuration: nil, slippage_bps: nil, privy_authorization_signature: nil, privy_idempotency_key: nil, request_options: {}) ⇒ Privy::Models::SwapActionResponse

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

Execute a token swap within a wallet.

Parameters:

  • wallet_id (String)

    Path param: ID of the wallet.

  • base_amount (String)

    Body param: Amount in base units (e.g., wei for ETH). Must be a non-negative int

  • destination (Privy::Models::SwapDestination)

    Body param: The output side of a swap execution request.

  • source (Privy::Models::SwapSource)

    Body param: The input side of a swap request, including token and chain.

  • amount_type (Symbol, Privy::Models::AmountType)

    Body param: Whether the amount refers to the input token or output token.

  • fee_configuration (Privy::Models::FeeConfiguration)

    Body param: Total fees assessed on a transfer, in BPS

  • slippage_bps (Float)

    Body param: Maximum slippage tolerance in basis points (e.g., 50 for 0.5%).

  • privy_authorization_signature (String)

    Header param: Request authorization signature. If multiple signatures are requir

  • privy_idempotency_key (String)

    Header param: Idempotency keys ensure API requests are executed only once within

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

Returns:

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/privy/resources/wallets/swap.rb', line 38

def execute(wallet_id, params)
  parsed, options = Privy::Wallets::SwapExecuteParams.dump_request(params)
  header_params =
    {
      privy_authorization_signature: "privy-authorization-signature",
      privy_idempotency_key: "privy-idempotency-key"
    }
  @client.request(
    method: :post,
    path: ["v1/wallets/%1$s/swap", wallet_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Privy::SwapActionResponse,
    options: options
  )
end

#quote(wallet_id, base_amount:, destination:, source:, amount_type: nil, fee_configuration: nil, slippage_bps: nil, privy_authorization_signature: nil, request_options: {}) ⇒ Privy::Models::SwapQuoteResponse

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

Get a price quote for swapping tokens within a wallet.

Parameters:

  • wallet_id (String)

    Path param: ID of the wallet.

  • base_amount (String)

    Body param: Amount in base units (e.g., wei for ETH). Must be a non-negative int

  • destination (Privy::Models::SwapQuoteDestination)

    Body param: The output side of a swap quote request.

  • source (Privy::Models::SwapSource)

    Body param: The input side of a swap request, including token and chain.

  • amount_type (Symbol, Privy::Models::AmountType)

    Body param: Whether the amount refers to the input token or output token.

  • fee_configuration (Privy::Models::FeeConfiguration)

    Body param: Total fees assessed on a transfer, in BPS

  • slippage_bps (Float)

    Body param: Maximum slippage tolerance in basis points (e.g., 50 for 0.5%). If o

  • privy_authorization_signature (String)

    Header param: Request authorization signature. If multiple signatures are requir

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

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/privy/resources/wallets/swap.rb', line 83

def quote(wallet_id, params)
  parsed, options = Privy::Wallets::SwapQuoteParams.dump_request(params)
  header_params = {privy_authorization_signature: "privy-authorization-signature"}
  @client.request(
    method: :post,
    path: ["v1/wallets/%1$s/swap/quote", wallet_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Privy::SwapQuoteResponse,
    options: options
  )
end