Class: Privy::Services::Earn::Ethereum

Inherits:
Resources::Wallets::Earn::Ethereum show all
Defined in:
lib/privy/public_api/services/earn/ethereum.rb,
lib/privy/public_api/services/earn/ethereum/incentive.rb

Defined Under Namespace

Classes: Incentive

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resources::Wallets::Earn::Ethereum

#_deposit, #_withdraw

Constructor Details

#initialize(client:, privy_client:) ⇒ Ethereum

Returns a new instance of Ethereum.



12
13
14
15
16
17
18
19
# File 'lib/privy/public_api/services/earn/ethereum.rb', line 12

def initialize(client:, privy_client:)
  super(client: client)
  @privy_client = privy_client
  @incentive = Privy::Services::Earn::Ethereum::Incentive.new(
    client: client,
    privy_client: privy_client
  )
end

Instance Attribute Details

#incentivePrivy::Services::Earn::Ethereum::Incentive (readonly)



10
11
12
# File 'lib/privy/public_api/services/earn/ethereum.rb', line 10

def incentive
  @incentive
end

#privy_clientObject (readonly)

Returns the value of attribute privy_client.



7
8
9
# File 'lib/privy/public_api/services/earn/ethereum.rb', line 7

def privy_client
  @privy_client
end

Instance Method Details

#deposit(wallet_id, earn_deposit_params:, authorization_context: nil, idempotency_key: nil, request_expiry: nil, request_options: nil) ⇒ Privy::Models::EarnDepositActionResponse

Deposit assets into an ERC-4626 vault.

Examples:

Deposit by human-readable amount

client.wallets.earn.ethereum.deposit("wallet-id", earn_deposit_params: {
  vault_id: "vault-id",
  amount: "1.5"
}, authorization_context: ctx)

Deposit by raw amount

client.wallets.earn.ethereum.deposit("wallet-id", earn_deposit_params: {
  vault_id: "vault-id",
  raw_amount: "1500000"
})

Parameters:

  • wallet_id (String)

    ID of the wallet to deposit from.

  • earn_deposit_params (Hash)

    Body parameters for the deposit operation.

  • authorization_context (Privy::Authorization::AuthorizationContext, nil) (defaults to: nil)

    Authorization context for owned wallets.

  • idempotency_key (String, nil) (defaults to: nil)

    Ensures the request is executed only once.

  • request_expiry (Integer, nil) (defaults to: nil)

    Absolute Unix-ms timestamp at which the request expires. Defaults to the value computed by the client’s PrivyRequestExpiryOptions.

  • request_options (Privy::RequestOptions, Hash, nil) (defaults to: nil)

    Transport-level config (timeouts, retries).

Options Hash (earn_deposit_params:):

  • :vault_id (String)

    ID of the vault to deposit into.

  • :amount (String, nil)

    Human-readable decimal amount to deposit. Exactly one of :amount or :raw_amount must be provided.

  • :raw_amount (String, nil)

    Amount in the smallest unit to deposit. Exactly one of :amount or :raw_amount must be provided.

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/privy/public_api/services/earn/ethereum.rb', line 50

def deposit(
  wallet_id,
  earn_deposit_params:,
  authorization_context: nil,
  idempotency_key: nil,
  request_expiry: nil,
  request_options: nil
)
  prepared = Privy::Authorization.prepare_request(
    privy_client,
    method: :post,
    url: Privy::Authorization.signed_url(
      privy_client,
      "v1/wallets/#{wallet_id}/earn/ethereum/deposit"
    ),
    body: earn_deposit_params,
    authorization_context: authorization_context,
    idempotency_key: idempotency_key,
    request_expiry: privy_client.compute_request_expiry(request_expiry)
  )
  combined_params = earn_deposit_params.merge(request_options: request_options)
  Privy::Authorization.merge_prepared_headers!(combined_params, prepared.headers)
  _deposit(wallet_id, combined_params)
end

#withdraw(wallet_id, earn_withdraw_params:, authorization_context: nil, idempotency_key: nil, request_expiry: nil, request_options: nil) ⇒ Privy::Models::EarnWithdrawActionResponse

Withdraw assets from an ERC-4626 vault.

Examples:

Withdraw by human-readable amount

client.wallets.earn.ethereum.withdraw("wallet-id", earn_withdraw_params: {
  vault_id: "vault-id",
  amount: "1.5"
}, authorization_context: ctx)

Withdraw by raw amount

client.wallets.earn.ethereum.withdraw("wallet-id", earn_withdraw_params: {
  vault_id: "vault-id",
  raw_amount: "1500000"
})

Parameters:

  • wallet_id (String)

    ID of the wallet to withdraw from.

  • earn_withdraw_params (Hash)

    Body parameters for the withdraw operation.

  • authorization_context (Privy::Authorization::AuthorizationContext, nil) (defaults to: nil)

    Authorization context for owned wallets.

  • idempotency_key (String, nil) (defaults to: nil)

    Ensures the request is executed only once.

  • request_expiry (Integer, nil) (defaults to: nil)

    Absolute Unix-ms timestamp at which the request expires. Defaults to the value computed by the client’s PrivyRequestExpiryOptions.

  • request_options (Privy::RequestOptions, Hash, nil) (defaults to: nil)

    Transport-level config (timeouts, retries).

Options Hash (earn_withdraw_params:):

  • :vault_id (String)

    ID of the vault to withdraw from.

  • :amount (String, nil)

    Human-readable decimal amount to withdraw. Exactly one of :amount or :raw_amount must be provided.

  • :raw_amount (String, nil)

    Amount in the smallest unit to withdraw. Exactly one of :amount or :raw_amount must be provided.

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/privy/public_api/services/earn/ethereum.rb', line 104

def withdraw(
  wallet_id,
  earn_withdraw_params:,
  authorization_context: nil,
  idempotency_key: nil,
  request_expiry: nil,
  request_options: nil
)
  prepared = Privy::Authorization.prepare_request(
    privy_client,
    method: :post,
    url: Privy::Authorization.signed_url(
      privy_client,
      "v1/wallets/#{wallet_id}/earn/ethereum/withdraw"
    ),
    body: earn_withdraw_params,
    authorization_context: authorization_context,
    idempotency_key: idempotency_key,
    request_expiry: privy_client.compute_request_expiry(request_expiry)
  )
  combined_params = earn_withdraw_params.merge(request_options: request_options)
  Privy::Authorization.merge_prepared_headers!(combined_params, prepared.headers)
  _withdraw(wallet_id, combined_params)
end