coinbase-sdk 0.10.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coinbase/address/wallet_address.rb +28 -0
- data/lib/coinbase/address.rb +22 -3
- data/lib/coinbase/address_reputation.rb +67 -0
- data/lib/coinbase/balance.rb +1 -1
- data/lib/coinbase/client/api/addresses_api.rb +10 -10
- data/lib/coinbase/client/api/assets_api.rb +2 -2
- data/lib/coinbase/client/api/balance_history_api.rb +2 -2
- data/lib/coinbase/client/api/contract_events_api.rb +2 -2
- data/lib/coinbase/client/api/contract_invocations_api.rb +5 -5
- data/lib/coinbase/client/api/external_addresses_api.rb +246 -5
- data/lib/coinbase/client/api/fund_api.rb +5 -5
- data/lib/coinbase/client/api/{wallet_stake_api.rb → mpc_wallet_stake_api.rb} +24 -24
- data/lib/coinbase/client/api/networks_api.rb +2 -2
- data/lib/coinbase/client/api/onchain_identity_api.rb +2 -2
- data/lib/coinbase/client/api/reputation_api.rb +91 -0
- data/lib/coinbase/client/api/server_signers_api.rb +7 -7
- data/lib/coinbase/client/api/smart_contracts_api.rb +169 -26
- data/lib/coinbase/client/api/stake_api.rb +163 -6
- data/lib/coinbase/client/api/trades_api.rb +5 -5
- data/lib/coinbase/client/api/transaction_history_api.rb +2 -2
- data/lib/coinbase/client/api/transfers_api.rb +14 -14
- data/lib/coinbase/client/api/users_api.rb +1 -1
- data/lib/coinbase/client/api/wallets_api.rb +6 -6
- data/lib/coinbase/client/api/webhooks_api.rb +6 -6
- data/lib/coinbase/client/api_client.rb +1 -1
- data/lib/coinbase/client/api_error.rb +1 -1
- data/lib/coinbase/client/configuration.rb +15 -1
- data/lib/coinbase/client/models/address.rb +1 -1
- data/lib/coinbase/client/models/address_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_historical_balance_list.rb +1 -1
- data/lib/coinbase/client/models/address_list.rb +1 -1
- data/lib/coinbase/client/models/address_reputation.rb +239 -0
- data/lib/coinbase/client/models/address_reputation_metadata.rb +376 -0
- data/lib/coinbase/client/models/address_transaction_list.rb +1 -1
- data/lib/coinbase/client/models/asset.rb +1 -1
- data/lib/coinbase/client/models/balance.rb +1 -1
- data/lib/coinbase/client/models/broadcast_contract_invocation_request.rb +1 -1
- data/lib/coinbase/client/models/{broadcast_transfer_request.rb → broadcast_external_transfer_request.rb} +4 -4
- data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
- data/lib/coinbase/client/models/build_staking_operation_request.rb +2 -1
- data/lib/coinbase/client/models/contract_event.rb +1 -1
- data/lib/coinbase/client/models/contract_event_list.rb +1 -1
- data/lib/coinbase/client/models/contract_invocation.rb +1 -1
- data/lib/coinbase/client/models/contract_invocation_list.rb +1 -1
- data/lib/coinbase/client/models/create_address_request.rb +1 -1
- data/lib/coinbase/client/models/create_contract_invocation_request.rb +1 -1
- data/lib/coinbase/client/models/create_external_transfer_request.rb +273 -0
- data/lib/coinbase/client/models/create_fund_operation_request.rb +2 -2
- data/lib/coinbase/client/models/create_fund_quote_request.rb +2 -2
- data/lib/coinbase/client/models/create_payload_signature_request.rb +1 -1
- data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
- data/lib/coinbase/client/models/create_smart_contract_request.rb +1 -1
- data/lib/coinbase/client/models/create_staking_operation_request.rb +2 -1
- data/lib/coinbase/client/models/create_trade_request.rb +1 -1
- data/lib/coinbase/client/models/create_transfer_request.rb +2 -2
- data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
- data/lib/coinbase/client/models/create_wallet_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/create_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/crypto_amount.rb +1 -1
- data/lib/coinbase/client/models/deploy_smart_contract_request.rb +1 -1
- data/lib/coinbase/client/models/erc20_transfer_event.rb +1 -1
- data/lib/coinbase/client/models/erc721_transfer_event.rb +1 -1
- data/lib/coinbase/client/models/error.rb +1 -1
- data/lib/coinbase/client/models/ethereum_token_transfer.rb +1 -1
- data/lib/coinbase/client/models/ethereum_transaction.rb +15 -5
- data/lib/coinbase/client/models/ethereum_transaction_access.rb +1 -1
- data/lib/coinbase/client/models/ethereum_transaction_access_list.rb +1 -1
- data/lib/coinbase/client/models/ethereum_transaction_flattened_trace.rb +1 -1
- data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
- data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
- data/lib/coinbase/client/models/feature_set.rb +1 -1
- data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
- data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
- data/lib/coinbase/client/models/fiat_amount.rb +1 -1
- data/lib/coinbase/client/models/fund_operation.rb +1 -1
- data/lib/coinbase/client/models/fund_operation_fees.rb +1 -1
- data/lib/coinbase/client/models/fund_operation_list.rb +1 -1
- data/lib/coinbase/client/models/fund_quote.rb +1 -1
- data/lib/coinbase/client/models/get_staking_context_request.rb +2 -1
- data/lib/coinbase/client/models/historical_balance.rb +1 -1
- data/lib/coinbase/client/models/multi_token_contract_options.rb +1 -1
- data/lib/coinbase/client/models/network.rb +1 -1
- data/lib/coinbase/client/models/network_identifier.rb +1 -1
- data/lib/coinbase/client/models/nft_contract_options.rb +1 -1
- data/lib/coinbase/client/models/onchain_name.rb +1 -1
- data/lib/coinbase/client/models/onchain_name_list.rb +1 -1
- data/lib/coinbase/client/models/payload_signature.rb +1 -1
- data/lib/coinbase/client/models/payload_signature_list.rb +1 -1
- data/lib/coinbase/client/models/read_contract_request.rb +1 -1
- data/lib/coinbase/client/models/register_smart_contract_request.rb +252 -0
- data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
- data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/server_signer.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
- data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
- data/lib/coinbase/client/models/server_signer_list.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
- data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
- data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
- data/lib/coinbase/client/models/smart_contract.rb +37 -31
- data/lib/coinbase/client/models/smart_contract_activity_event.rb +386 -0
- data/lib/coinbase/client/models/smart_contract_list.rb +1 -1
- data/lib/coinbase/client/models/smart_contract_options.rb +1 -1
- data/lib/coinbase/client/models/smart_contract_type.rb +3 -2
- data/lib/coinbase/client/models/solidity_value.rb +3 -3
- data/lib/coinbase/client/models/sponsored_send.rb +1 -1
- data/lib/coinbase/client/models/staking_balance.rb +1 -1
- data/lib/coinbase/client/models/staking_context.rb +1 -1
- data/lib/coinbase/client/models/staking_context_context.rb +1 -1
- data/lib/coinbase/client/models/staking_operation.rb +1 -1
- data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
- data/lib/coinbase/client/models/staking_reward.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
- data/lib/coinbase/client/models/staking_reward_usd_value.rb +1 -1
- data/lib/coinbase/client/models/token_contract_options.rb +1 -1
- data/lib/coinbase/client/models/token_transfer_type.rb +1 -1
- data/lib/coinbase/client/models/trade.rb +1 -1
- data/lib/coinbase/client/models/trade_list.rb +1 -1
- data/lib/coinbase/client/models/transaction.rb +1 -1
- data/lib/coinbase/client/models/transaction_content.rb +1 -1
- data/lib/coinbase/client/models/transaction_type.rb +1 -1
- data/lib/coinbase/client/models/transfer.rb +2 -37
- data/lib/coinbase/client/models/transfer_list.rb +1 -1
- data/lib/coinbase/client/models/update_smart_contract_request.rb +245 -0
- data/lib/coinbase/client/models/update_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/user.rb +1 -1
- data/lib/coinbase/client/models/validator.rb +1 -1
- data/lib/coinbase/client/models/validator_details.rb +1 -1
- data/lib/coinbase/client/models/validator_list.rb +1 -1
- data/lib/coinbase/client/models/validator_status.rb +1 -1
- data/lib/coinbase/client/models/wallet.rb +1 -1
- data/lib/coinbase/client/models/wallet_list.rb +1 -1
- data/lib/coinbase/client/models/webhook.rb +1 -1
- data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
- data/lib/coinbase/client/models/webhook_event_type.rb +3 -2
- data/lib/coinbase/client/models/webhook_event_type_filter.rb +2 -1
- data/lib/coinbase/client/models/webhook_list.rb +1 -1
- data/lib/coinbase/client/models/webhook_smart_contract_event_filter.rb +225 -0
- data/lib/coinbase/client/models/webhook_wallet_activity_filter.rb +8 -1
- data/lib/coinbase/client/version.rb +1 -1
- data/lib/coinbase/client.rb +11 -4
- data/lib/coinbase/crypto_amount.rb +62 -0
- data/lib/coinbase/errors.rb +8 -0
- data/lib/coinbase/fiat_amount.rb +40 -0
- data/lib/coinbase/fund_operation.rb +228 -0
- data/lib/coinbase/fund_quote.rb +149 -0
- data/lib/coinbase/smart_contract.rb +337 -244
- data/lib/coinbase/staking_operation.rb +2 -2
- data/lib/coinbase/validator.rb +7 -10
- data/lib/coinbase/version.rb +1 -1
- data/lib/coinbase/wallet/data.rb +6 -4
- data/lib/coinbase/wallet.rb +16 -3
- data/lib/coinbase.rb +6 -1
- metadata +20 -8
- data/lib/coinbase/client/api/validators_api.rb +0 -179
@@ -0,0 +1,228 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'constants'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require 'eth'
|
6
|
+
|
7
|
+
module Coinbase
|
8
|
+
# A representation of a Fund Operation, which buys funds from the Coinbase platform,
|
9
|
+
# and sends then to the developer's address.
|
10
|
+
class FundOperation
|
11
|
+
# A representation of a Fund Operation status.
|
12
|
+
module Status
|
13
|
+
# The Fund Operation is being processed.
|
14
|
+
PENDING = 'pending'
|
15
|
+
|
16
|
+
# The Fund Operation is complete.
|
17
|
+
COMPLETE = 'complete'
|
18
|
+
|
19
|
+
# The Fund Operation has failed for some reason.
|
20
|
+
FAILED = 'failed'
|
21
|
+
|
22
|
+
# The states that are considered terminal on-chain.
|
23
|
+
TERMINAL_STATES = [COMPLETE, FAILED].freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# Creates a new Fund Operation object.
|
28
|
+
# This takes an optional FundQuote object that can be used to lock in the rate and fees.
|
29
|
+
# Without an explicit quote, we will use the current rate and fees.
|
30
|
+
# @param address_id [String] The Address ID of the sending Address
|
31
|
+
# @param wallet_id [String] The Wallet ID of the sending Wallet
|
32
|
+
# @param amount [BigDecimal] The amount of the Asset to send
|
33
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
34
|
+
# @param asset_id [Symbol] The Asset ID of the Asset to send
|
35
|
+
# @param quote [Coinbase::FundQuote, String] The optional FundQuote to use for the Fund Operation
|
36
|
+
# @return [FundOperation] The new pending Fund Operation object
|
37
|
+
# @raise [Coinbase::ApiError] If the Fund Operation fails
|
38
|
+
def create(wallet_id:, address_id:, amount:, asset_id:, network:, quote: nil)
|
39
|
+
network = Coinbase::Network.from_id(network)
|
40
|
+
asset = network.get_asset(asset_id)
|
41
|
+
|
42
|
+
model = Coinbase.call_api do
|
43
|
+
fund_api.create_fund_operation(
|
44
|
+
wallet_id,
|
45
|
+
address_id,
|
46
|
+
{
|
47
|
+
amount: asset.to_atomic_amount(amount).to_i.to_s,
|
48
|
+
asset_id: asset.primary_denomination.to_s,
|
49
|
+
fund_quote_id: quote_id(quote)
|
50
|
+
}.compact
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
new(model)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Enumerates the fund operation for a given address belonging to a wallet.
|
58
|
+
# The result is an enumerator that lazily fetches from the server, and can be iterated over,
|
59
|
+
# converted to an array, etc...
|
60
|
+
# @return [Enumerable<Coinbase::FundOperation>] Enumerator that returns fund operations
|
61
|
+
def list(wallet_id:, address_id:)
|
62
|
+
Coinbase::Pagination.enumerate(
|
63
|
+
->(page) { fetch_page(wallet_id, address_id, page) }
|
64
|
+
) do |fund_operation|
|
65
|
+
new(fund_operation)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def fund_api
|
72
|
+
Coinbase::Client::FundApi.new(Coinbase.configuration.api_client)
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_page(wallet_id, address_id, page)
|
76
|
+
fund_api.list_fund_operations(
|
77
|
+
wallet_id,
|
78
|
+
address_id,
|
79
|
+
limit: DEFAULT_PAGE_LIMIT,
|
80
|
+
page: page
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def quote_id(quote)
|
85
|
+
return nil if quote.nil?
|
86
|
+
return quote.id if quote.is_a?(FundQuote)
|
87
|
+
return quote if quote.is_a?(String)
|
88
|
+
|
89
|
+
raise ArgumentError, 'quote must be a FundQuote object or ID'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns a new Fund Operation object. Do not use this method directly. Instead, use
|
94
|
+
# Wallet#fund or Address#fund.
|
95
|
+
# @param model [Coinbase::Client::FundOperation] The underlying Fund Operation object
|
96
|
+
def initialize(model)
|
97
|
+
raise ArgumentError, 'must be a FundOperation' unless model.is_a?(Coinbase::Client::FundOperation)
|
98
|
+
|
99
|
+
@model = model
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns the Fund Operation ID.
|
103
|
+
# @return [String] The Fund Operation ID
|
104
|
+
def id
|
105
|
+
@model.fund_operation_id
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns the Network of the Fund Operation.
|
109
|
+
# @return [Coinbase::Network] The Network
|
110
|
+
def network
|
111
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Returns the Wallet ID that the fund quote was created for.
|
115
|
+
# @return [String] The Wallet ID
|
116
|
+
def wallet_id
|
117
|
+
@model.wallet_id
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns the Address ID that the fund quote was created for.
|
121
|
+
# @return [String] The Address ID
|
122
|
+
def address_id
|
123
|
+
@model.address_id
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns the Asset of the Fund Operation.
|
127
|
+
# @return [Coinbase::Asset] The Asset
|
128
|
+
def asset
|
129
|
+
amount.asset
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns the amount that the wallet will receive in crypto.
|
133
|
+
# @return [Coinbase::CryptoAmount] The crypto amount
|
134
|
+
def amount
|
135
|
+
@amount ||= CryptoAmount.from_model(@model.crypto_amount)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns the amount that the wallet's owner will pay in fiat.
|
139
|
+
# @return [Coinbase::FiatAmount] The fiat amount
|
140
|
+
def fiat_amount
|
141
|
+
@fiat_amount ||= FiatAmount.from_model(@model.fiat_amount)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Returns the fee that the wallet's owner will pay in fiat.
|
145
|
+
# @return [Coinbase::FiatAmount] The fiat buy fee
|
146
|
+
def buy_fee
|
147
|
+
@buy_fee ||= FiatAmount.from_model(@model.fees.buy_fee)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Returns the fee that the wallet's owner will pay in crypto.
|
151
|
+
# @return [Coinbase::CryptoAmount] The crypto transfer fee
|
152
|
+
def transfer_fee
|
153
|
+
@transfer_fee ||= CryptoAmount.from_model(@model.fees.transfer_fee)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns the status of the Fund Operation.
|
157
|
+
# @return [Symbol] The status
|
158
|
+
def status
|
159
|
+
@model.status
|
160
|
+
end
|
161
|
+
|
162
|
+
# Reload reloads the Transfer model with the latest version from the server side.
|
163
|
+
# @return [Transfer] The most recent version of Transfer from the server.
|
164
|
+
def reload
|
165
|
+
@model = Coinbase.call_api do
|
166
|
+
fund_api.get_fund_operation(wallet_id, address_id, id)
|
167
|
+
end
|
168
|
+
|
169
|
+
self
|
170
|
+
end
|
171
|
+
|
172
|
+
# Waits until the Fund Operation is completed or failed by polling the at the given interval.
|
173
|
+
# @param interval_seconds [Integer] The interval at which to poll the Network, in seconds
|
174
|
+
# @param timeout_seconds [Integer] The maximum amount of time to wait for the Fund Operation to complete, in seconds
|
175
|
+
# @return [Coinbase::FundOperation] The completed or failed Fund Operation object
|
176
|
+
# @raise [Timeout::Error] If the Fund Operation takes longer than the given timeout
|
177
|
+
def wait!(interval_seconds = 1, timeout_seconds = 60)
|
178
|
+
start_time = Time.now
|
179
|
+
|
180
|
+
loop do
|
181
|
+
reload
|
182
|
+
|
183
|
+
return self if terminal_state?
|
184
|
+
|
185
|
+
raise Timeout::Error, 'Fund Operation timed out' if Time.now - start_time > timeout_seconds
|
186
|
+
|
187
|
+
self.sleep interval_seconds
|
188
|
+
end
|
189
|
+
|
190
|
+
self
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns a String representation of the Fund Operation.
|
194
|
+
# @return [String] a String representation of the Fund Operation
|
195
|
+
def to_s
|
196
|
+
Coinbase.pretty_print_object(
|
197
|
+
self.class,
|
198
|
+
id: id,
|
199
|
+
network_id: network.id,
|
200
|
+
wallet_id: wallet_id,
|
201
|
+
address_id: address_id,
|
202
|
+
status: status,
|
203
|
+
crypto_amount: amount,
|
204
|
+
fiat_amount: fiat_amount,
|
205
|
+
buy_fee: buy_fee,
|
206
|
+
transfer_fee: transfer_fee
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
# Same as to_s.
|
211
|
+
# @return [String] a String representation of the Fund Operation.
|
212
|
+
def inspect
|
213
|
+
to_s
|
214
|
+
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
# Returns whether the Fund Operation is in a terminal state.
|
219
|
+
# @return [Boolean] Whether the Fund Operation is in a terminal state
|
220
|
+
def terminal_state?
|
221
|
+
Status::TERMINAL_STATES.include?(status)
|
222
|
+
end
|
223
|
+
|
224
|
+
def fund_api
|
225
|
+
@fund_api ||= Coinbase::Client::FundApi.new(Coinbase.configuration.api_client)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'constants'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require 'eth'
|
6
|
+
|
7
|
+
module Coinbase
|
8
|
+
# A representation of a Fund Operation Quote, which is a quote for a fund operation
|
9
|
+
# that buys funds from the Coinbase platform and sends then to the developer's address.
|
10
|
+
class FundQuote
|
11
|
+
class << self
|
12
|
+
# Creates a new Fund Operation Quote object.
|
13
|
+
# @param address_id [String] The Address ID of the sending Address
|
14
|
+
# @param wallet_id [String] The Wallet ID of the sending Wallet
|
15
|
+
# @param amount [BigDecimal] The amount of the Asset to send
|
16
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
17
|
+
# @param asset_id [Symbol] The Asset ID of the Asset to send
|
18
|
+
# @return [FundQuote] The new Fund Quote object
|
19
|
+
# @raise [Coinbase::ApiError] If the Fund Quote fails
|
20
|
+
def create(wallet_id:, address_id:, amount:, asset_id:, network:)
|
21
|
+
network = Coinbase::Network.from_id(network)
|
22
|
+
asset = network.get_asset(asset_id)
|
23
|
+
|
24
|
+
model = Coinbase.call_api do
|
25
|
+
fund_api.create_fund_quote(
|
26
|
+
wallet_id,
|
27
|
+
address_id,
|
28
|
+
{
|
29
|
+
asset_id: asset.primary_denomination.to_s,
|
30
|
+
amount: asset.to_atomic_amount(amount).to_i.to_s
|
31
|
+
}
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
new(model)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def fund_api
|
41
|
+
Coinbase::Client::FundApi.new(Coinbase.configuration.api_client)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a new Fund Quote object. Do not use this method directly.
|
46
|
+
# Instead, use Wallet#quote_fund or Address#quote_fund.
|
47
|
+
# @param model [Coinbase::Client::FundQuote] The underlying Fund Quote object
|
48
|
+
def initialize(model)
|
49
|
+
raise ArgumentError, 'must be a FundQuote' unless model.is_a?(Coinbase::Client::FundQuote)
|
50
|
+
|
51
|
+
@model = model
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the ID of the Fund Quote.
|
55
|
+
# @return [String] The Fund Quote ID
|
56
|
+
def id
|
57
|
+
@model.fund_quote_id
|
58
|
+
end
|
59
|
+
|
60
|
+
# Executes a fund operation using the quote.
|
61
|
+
# @return [Coinbase::FundOperation] The FundOperation object
|
62
|
+
# @raise [Coinbase::ApiError] If the FundOperation fails
|
63
|
+
def execute!
|
64
|
+
FundOperation.create(
|
65
|
+
wallet_id: wallet_id,
|
66
|
+
address_id: address_id,
|
67
|
+
amount: amount.amount,
|
68
|
+
asset_id: asset.asset_id,
|
69
|
+
network: network.id,
|
70
|
+
quote: self
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the Network the fund quote was created on.
|
75
|
+
# @return [Coinbase::Network] The Network
|
76
|
+
def network
|
77
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the Wallet ID that the fund quote was created for.
|
81
|
+
# @return [String] The Wallet ID
|
82
|
+
def wallet_id
|
83
|
+
@model.wallet_id
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns the Address ID that the fund quote was created for.
|
87
|
+
# @return [String] The Address ID
|
88
|
+
def address_id
|
89
|
+
@model.address_id
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the Asset of the FundOperation.
|
93
|
+
# @return [Coinbase::Asset] The Asset
|
94
|
+
def asset
|
95
|
+
amount.asset
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the amount that the wallet will receive in crypto.
|
99
|
+
# @return [Coinbase::CryptoAmount] The crypto amount
|
100
|
+
def amount
|
101
|
+
@amount ||= CryptoAmount.from_model(@model.crypto_amount)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns the amount that the wallet's owner will pay in fiat.
|
105
|
+
# @return [Coinbase::FiatAmount] The fiat amount
|
106
|
+
def fiat_amount
|
107
|
+
@fiat_amount ||= FiatAmount.from_model(@model.fiat_amount)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns the fee that the wallet's owner will pay in fiat.
|
111
|
+
# @return [Coinbase::FiatAmount] The fiat buy fee
|
112
|
+
def buy_fee
|
113
|
+
@buy_fee ||= FiatAmount.from_model(@model.fees.buy_fee)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns the fee that the wallet's owner will pay in crypto.
|
117
|
+
# @return [Coinbase::CryptoAmount] The crypto transfer fee
|
118
|
+
def transfer_fee
|
119
|
+
@transfer_fee ||= CryptoAmount.from_model(@model.fees.transfer_fee)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns a String representation of the Fund Operation.
|
123
|
+
# @return [String] a String representation of the Fund Operation
|
124
|
+
def to_s
|
125
|
+
Coinbase.pretty_print_object(
|
126
|
+
self.class,
|
127
|
+
network_id: network.id,
|
128
|
+
wallet_id: wallet_id,
|
129
|
+
address_id: address_id,
|
130
|
+
crypto_amount: amount,
|
131
|
+
fiat_amount: fiat_amount,
|
132
|
+
buy_fee: buy_fee,
|
133
|
+
transfer_fee: transfer_fee
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Same as to_s.
|
138
|
+
# @return [String] a String representation of the Transfer
|
139
|
+
def inspect
|
140
|
+
to_s
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def fund_api
|
146
|
+
@fund_api ||= Coinbase::Client::FundApi.new(Coinbase.configuration.api_client)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|