coinbase-sdk 0.10.0 → 0.11.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/balance.rb +1 -1
- data/lib/coinbase/client/api/addresses_api.rb +1 -1
- data/lib/coinbase/client/api/assets_api.rb +1 -1
- data/lib/coinbase/client/api/balance_history_api.rb +1 -1
- data/lib/coinbase/client/api/contract_events_api.rb +1 -1
- data/lib/coinbase/client/api/contract_invocations_api.rb +1 -1
- data/lib/coinbase/client/api/external_addresses_api.rb +1 -1
- data/lib/coinbase/client/api/fund_api.rb +1 -1
- data/lib/coinbase/client/api/{wallet_stake_api.rb → mpc_wallet_stake_api.rb} +21 -21
- data/lib/coinbase/client/api/networks_api.rb +1 -1
- data/lib/coinbase/client/api/onchain_identity_api.rb +1 -1
- data/lib/coinbase/client/api/reputation_api.rb +160 -0
- data/lib/coinbase/client/api/server_signers_api.rb +1 -1
- data/lib/coinbase/client/api/smart_contracts_api.rb +1 -1
- data/lib/coinbase/client/api/stake_api.rb +158 -1
- data/lib/coinbase/client/api/trades_api.rb +1 -1
- data/lib/coinbase/client/api/transaction_history_api.rb +1 -1
- data/lib/coinbase/client/api/transfers_api.rb +1 -1
- data/lib/coinbase/client/api/users_api.rb +1 -1
- data/lib/coinbase/client/api/wallets_api.rb +1 -1
- data/lib/coinbase/client/api/webhooks_api.rb +1 -1
- data/lib/coinbase/client/api_client.rb +1 -1
- data/lib/coinbase/client/api_error.rb +1 -1
- data/lib/coinbase/client/configuration.rb +1 -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 +232 -0
- data/lib/coinbase/client/models/address_reputation_metadata.rb +376 -0
- data/lib/coinbase/client/models/address_risk.rb +223 -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_staking_operation_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
- data/lib/coinbase/client/models/broadcast_transfer_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_fund_operation_request.rb +1 -1
- data/lib/coinbase/client/models/create_fund_quote_request.rb +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/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 +1 -1
- 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 +1 -1
- 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 +1 -1
- data/lib/coinbase/client/models/transfer_list.rb +1 -1
- 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 +1 -1
- data/lib/coinbase/client/models/webhook_event_type_filter.rb +1 -1
- data/lib/coinbase/client/models/webhook_list.rb +1 -1
- data/lib/coinbase/client/models/webhook_wallet_activity_filter.rb +1 -1
- data/lib/coinbase/client/version.rb +1 -1
- data/lib/coinbase/client.rb +6 -3
- data/lib/coinbase/crypto_amount.rb +62 -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 +2 -2
- 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.rb +13 -1
- data/lib/coinbase.rb +4 -0
- metadata +11 -4
- 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
|
@@ -143,9 +143,9 @@ module Coinbase
|
|
143
143
|
# @return [Object] The result of the contract call, converted to an appropriate Ruby type
|
144
144
|
# @raise [Coinbase::ApiError] If there's an error in the API call
|
145
145
|
def self.read(
|
146
|
-
network:,
|
147
146
|
contract_address:,
|
148
147
|
method:,
|
148
|
+
network: Coinbase.default_network,
|
149
149
|
abi: nil,
|
150
150
|
args: {}
|
151
151
|
)
|
@@ -159,7 +159,7 @@ module Coinbase
|
|
159
159
|
method: method,
|
160
160
|
args: (args || {}).to_json,
|
161
161
|
abi: abi&.to_json
|
162
|
-
}
|
162
|
+
}.compact
|
163
163
|
)
|
164
164
|
end
|
165
165
|
|
@@ -107,7 +107,7 @@ module Coinbase
|
|
107
107
|
private_class_method :stake_api
|
108
108
|
|
109
109
|
def self.wallet_stake_api
|
110
|
-
Coinbase::Client::
|
110
|
+
Coinbase::Client::MPCWalletStakeApi.new(Coinbase.configuration.api_client)
|
111
111
|
end
|
112
112
|
|
113
113
|
private_class_method :wallet_stake_api
|
@@ -324,7 +324,7 @@ module Coinbase
|
|
324
324
|
end
|
325
325
|
|
326
326
|
def wallet_stake_api
|
327
|
-
@wallet_stake_api ||= Coinbase::Client::
|
327
|
+
@wallet_stake_api ||= Coinbase::Client::MPCWalletStakeApi.new(Coinbase.configuration.api_client)
|
328
328
|
end
|
329
329
|
|
330
330
|
def update_transactions(transactions)
|
data/lib/coinbase/validator.rb
CHANGED
@@ -33,12 +33,9 @@ module Coinbase
|
|
33
33
|
network = Coinbase::Network.from_id(network)
|
34
34
|
|
35
35
|
validator = Coinbase.call_api do
|
36
|
-
|
37
|
-
network.normalized_id,
|
38
|
-
asset_id,
|
39
|
-
validator_id
|
40
|
-
)
|
36
|
+
stake_api.get_validator(network.normalized_id, asset_id, validator_id)
|
41
37
|
end
|
38
|
+
|
42
39
|
new(validator)
|
43
40
|
end
|
44
41
|
|
@@ -57,7 +54,7 @@ module Coinbase
|
|
57
54
|
# Returns a string representation of the Validator.
|
58
55
|
# @return [String] a string representation of the Validator
|
59
56
|
def to_s
|
60
|
-
|
57
|
+
Coinbase.pretty_print_object(self, validator_id: validator_id, status: status)
|
61
58
|
end
|
62
59
|
|
63
60
|
# Same as to_s.
|
@@ -68,7 +65,7 @@ module Coinbase
|
|
68
65
|
|
69
66
|
def self.list_page(network, asset_id, status, page)
|
70
67
|
Coinbase.call_api do
|
71
|
-
|
68
|
+
stake_api.list_validators(
|
72
69
|
network.normalized_id,
|
73
70
|
asset_id,
|
74
71
|
{
|
@@ -81,10 +78,10 @@ module Coinbase
|
|
81
78
|
|
82
79
|
private_class_method :list_page
|
83
80
|
|
84
|
-
def self.
|
85
|
-
Coinbase::Client::
|
81
|
+
def self.stake_api
|
82
|
+
Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
86
83
|
end
|
87
84
|
|
88
|
-
private_class_method :
|
85
|
+
private_class_method :stake_api
|
89
86
|
end
|
90
87
|
end
|
data/lib/coinbase/version.rb
CHANGED
data/lib/coinbase/wallet.rb
CHANGED
@@ -258,9 +258,21 @@ module Coinbase
|
|
258
258
|
# @return [Coinbase::SmartContract] The deployed multi-token contract.
|
259
259
|
# @raise [AddressCannotSignError] if the Address does not have a private key backing it.
|
260
260
|
|
261
|
+
# @!method quote_fund
|
262
|
+
# Gets a quote for a fund operation to fund the address from your Coinbase platform,
|
263
|
+
# account for the amount of the specified Asset.
|
264
|
+
# @param asset_id [Symbol] The ID of the Asset to trade from. For Ether, :eth, :gwei, and :wei are supported.
|
265
|
+
# @return [Coinbase::FundQuote] The FundQuote object.
|
266
|
+
|
267
|
+
# @!method fund
|
268
|
+
# Funds the address from your account on the Coinbase Platform for the given amount of the given Asset.
|
269
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to fund the wallet with.
|
270
|
+
# @param asset_id [Symbol] The ID of the Asset to trade from. For Ether, :eth, :gwei, and :wei are supported.
|
271
|
+
# @return [Coinbase::FundOperation] The FundOperation object.
|
272
|
+
|
261
273
|
def_delegators :default_address, :transfer, :trade, :faucet, :stake, :unstake, :claim_stake, :staking_balances,
|
262
274
|
:stakeable_balance, :unstakeable_balance, :claimable_balance, :sign_payload, :invoke_contract,
|
263
|
-
:deploy_token, :deploy_nft, :deploy_multi_token
|
275
|
+
:deploy_token, :deploy_nft, :deploy_multi_token, :quote_fund, :fund
|
264
276
|
|
265
277
|
# Returns the addresses belonging to the Wallet.
|
266
278
|
# @return [Array<Coinbase::WalletAddress>] The addresses belonging to the Wallet
|
data/lib/coinbase.rb
CHANGED
@@ -13,11 +13,15 @@ require_relative 'coinbase/client'
|
|
13
13
|
require_relative 'coinbase/constants'
|
14
14
|
require_relative 'coinbase/contract_event'
|
15
15
|
require_relative 'coinbase/contract_invocation'
|
16
|
+
require_relative 'coinbase/crypto_amount'
|
16
17
|
require_relative 'coinbase/destination'
|
17
18
|
require_relative 'coinbase/errors'
|
18
19
|
require_relative 'coinbase/faucet_transaction'
|
20
|
+
require_relative 'coinbase/fiat_amount'
|
19
21
|
require_relative 'coinbase/middleware'
|
20
22
|
require_relative 'coinbase/network'
|
23
|
+
require_relative 'coinbase/fund_operation'
|
24
|
+
require_relative 'coinbase/fund_quote'
|
21
25
|
require_relative 'coinbase/pagination'
|
22
26
|
require_relative 'coinbase/payload_signature'
|
23
27
|
require_relative 'coinbase/trade'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinbase-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuga Cohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -284,8 +284,10 @@ files:
|
|
284
284
|
- lib/coinbase/client/api/contract_invocations_api.rb
|
285
285
|
- lib/coinbase/client/api/external_addresses_api.rb
|
286
286
|
- lib/coinbase/client/api/fund_api.rb
|
287
|
+
- lib/coinbase/client/api/mpc_wallet_stake_api.rb
|
287
288
|
- lib/coinbase/client/api/networks_api.rb
|
288
289
|
- lib/coinbase/client/api/onchain_identity_api.rb
|
290
|
+
- lib/coinbase/client/api/reputation_api.rb
|
289
291
|
- lib/coinbase/client/api/server_signers_api.rb
|
290
292
|
- lib/coinbase/client/api/smart_contracts_api.rb
|
291
293
|
- lib/coinbase/client/api/stake_api.rb
|
@@ -293,8 +295,6 @@ files:
|
|
293
295
|
- lib/coinbase/client/api/transaction_history_api.rb
|
294
296
|
- lib/coinbase/client/api/transfers_api.rb
|
295
297
|
- lib/coinbase/client/api/users_api.rb
|
296
|
-
- lib/coinbase/client/api/validators_api.rb
|
297
|
-
- lib/coinbase/client/api/wallet_stake_api.rb
|
298
298
|
- lib/coinbase/client/api/wallets_api.rb
|
299
299
|
- lib/coinbase/client/api/webhooks_api.rb
|
300
300
|
- lib/coinbase/client/api_client.rb
|
@@ -304,6 +304,9 @@ files:
|
|
304
304
|
- lib/coinbase/client/models/address_balance_list.rb
|
305
305
|
- lib/coinbase/client/models/address_historical_balance_list.rb
|
306
306
|
- lib/coinbase/client/models/address_list.rb
|
307
|
+
- lib/coinbase/client/models/address_reputation.rb
|
308
|
+
- lib/coinbase/client/models/address_reputation_metadata.rb
|
309
|
+
- lib/coinbase/client/models/address_risk.rb
|
307
310
|
- lib/coinbase/client/models/address_transaction_list.rb
|
308
311
|
- lib/coinbase/client/models/asset.rb
|
309
312
|
- lib/coinbase/client/models/balance.rb
|
@@ -414,9 +417,13 @@ files:
|
|
414
417
|
- lib/coinbase/contract_event.rb
|
415
418
|
- lib/coinbase/contract_invocation.rb
|
416
419
|
- lib/coinbase/correlation.rb
|
420
|
+
- lib/coinbase/crypto_amount.rb
|
417
421
|
- lib/coinbase/destination.rb
|
418
422
|
- lib/coinbase/errors.rb
|
419
423
|
- lib/coinbase/faucet_transaction.rb
|
424
|
+
- lib/coinbase/fiat_amount.rb
|
425
|
+
- lib/coinbase/fund_operation.rb
|
426
|
+
- lib/coinbase/fund_quote.rb
|
420
427
|
- lib/coinbase/historical_balance.rb
|
421
428
|
- lib/coinbase/middleware.rb
|
422
429
|
- lib/coinbase/network.rb
|