coinbase-sdk 0.7.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/address.rb +8 -3
- 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 +79 -1
- data/lib/coinbase/client/api/fund_api.rb +336 -0
- 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 +108 -0
- 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 +81 -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 +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 +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 +249 -0
- data/lib/coinbase/client/models/create_fund_quote_request.rb +239 -0
- 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 +2 -2
- data/lib/coinbase/client/models/create_webhook_request.rb +1 -1
- data/lib/coinbase/client/models/crypto_amount.rb +239 -0
- 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 +327 -0
- data/lib/coinbase/client/models/ethereum_transaction.rb +13 -2
- 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 +21 -5
- 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 +240 -0
- data/lib/coinbase/client/models/fund_operation.rb +373 -0
- data/lib/coinbase/client/models/fund_operation_fees.rb +238 -0
- data/lib/coinbase/client/models/fund_operation_list.rb +275 -0
- data/lib/coinbase/client/models/fund_quote.rb +339 -0
- 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 +357 -0
- data/lib/coinbase/client/models/onchain_name_list.rb +262 -0
- 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 +249 -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 +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 +287 -0
- 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 +43 -0
- 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 -8
- 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 +23 -3
- data/lib/coinbase/crypto_amount.rb +62 -0
- data/lib/coinbase/faucet_transaction.rb +64 -4
- 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 +95 -0
- data/lib/coinbase/staking_operation.rb +2 -2
- data/lib/coinbase/transaction.rb +8 -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 +27 -4
- data/lib/coinbase/client/api/validators_api.rb +0 -179
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coinbase
|
4
|
+
# A representation of a FiatAmount that includes the amount and fiat.
|
5
|
+
class FiatAmount
|
6
|
+
# Converts a Coinbase::Client::FiatAmount model to a Coinbase::FiatAmount
|
7
|
+
# @param model [Coinbase::Client::FiatAmount] The crypto amount from the API.
|
8
|
+
# @return [FiatAmount] The converted FiatAmount object.
|
9
|
+
def self.from_model(model)
|
10
|
+
unless model.is_a?(Coinbase::Client::FiatAmount)
|
11
|
+
raise ArgumentError,
|
12
|
+
'model must be a Coinbase::Client::FiatAmount'
|
13
|
+
end
|
14
|
+
|
15
|
+
new(amount: model.amount, currency: model.currency)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a new FiatAmount object.
|
19
|
+
# @param amount [BigDecimal, String] The amount of the Fiat Currency
|
20
|
+
# @param currency [Symbol, String] The currency of the Fiat Amount
|
21
|
+
def initialize(amount:, currency:)
|
22
|
+
@amount = BigDecimal(amount)
|
23
|
+
@currency = Coinbase.to_sym(currency)
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :amount, :currency
|
27
|
+
|
28
|
+
# Returns a string representation of the FiatAmount.
|
29
|
+
# @return [String] a string representation of the FiatAmount
|
30
|
+
def to_s
|
31
|
+
Coinbase.pretty_print_object(self.class, amount: amount.to_s('F'), currency: currency)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Same as to_s.
|
35
|
+
# @return [String] a string representation of the FiatAmount
|
36
|
+
def inspect
|
37
|
+
to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -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
|
@@ -105,6 +105,12 @@ module Coinbase
|
|
105
105
|
new(contract)
|
106
106
|
end
|
107
107
|
|
108
|
+
# Creates a new ERC1155 multi-token contract, that can subsequently be deployed to
|
109
|
+
# the blockchain.
|
110
|
+
# @param address_id [String] The address ID of deployer
|
111
|
+
# @param wallet_id [String] The wallet ID of the deployer
|
112
|
+
# @param uri [String] The URI for the token metadata
|
113
|
+
# @return [SmartContract] The new ERC1155 Multi-Token SmartContract object
|
108
114
|
def self.create_multi_token_contract(
|
109
115
|
address_id:,
|
110
116
|
wallet_id:,
|
@@ -126,6 +132,95 @@ module Coinbase
|
|
126
132
|
new(contract)
|
127
133
|
end
|
128
134
|
|
135
|
+
# Reads data from a deployed smart contract.
|
136
|
+
#
|
137
|
+
# @param network [Coinbase::Network, Symbol] The Network or Network ID of the Asset
|
138
|
+
# @param contract_address [String] The address of the deployed contract
|
139
|
+
# @param method [String] The name of the method to call on the contract
|
140
|
+
# @param abi [Array, nil] The ABI of the contract. If nil, the method will attempt to use a cached ABI
|
141
|
+
# @param args [Hash] The arguments to pass to the contract method.
|
142
|
+
# The keys should be the argument names, and the values should be the argument values.
|
143
|
+
# @return [Object] The result of the contract call, converted to an appropriate Ruby type
|
144
|
+
# @raise [Coinbase::ApiError] If there's an error in the API call
|
145
|
+
def self.read(
|
146
|
+
contract_address:,
|
147
|
+
method:,
|
148
|
+
network: Coinbase.default_network,
|
149
|
+
abi: nil,
|
150
|
+
args: {}
|
151
|
+
)
|
152
|
+
network = Coinbase::Network.from_id(network)
|
153
|
+
|
154
|
+
response = Coinbase.call_api do
|
155
|
+
smart_contracts_api.read_contract(
|
156
|
+
network.normalized_id,
|
157
|
+
contract_address,
|
158
|
+
{
|
159
|
+
method: method,
|
160
|
+
args: (args || {}).to_json,
|
161
|
+
abi: abi&.to_json
|
162
|
+
}.compact
|
163
|
+
)
|
164
|
+
end
|
165
|
+
|
166
|
+
convert_solidity_value(response)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Converts a Solidity value to an appropriate Ruby type.
|
170
|
+
#
|
171
|
+
# @param solidity_value [Coinbase::Client::SolidityValue] The Solidity value to convert
|
172
|
+
# @return [Object] The converted Ruby value
|
173
|
+
# @raise [ArgumentError] If an unsupported Solidity type is encountered
|
174
|
+
#
|
175
|
+
# This method handles the following Solidity types:
|
176
|
+
# - Integers (uint8, uint16, uint32, uint64, uint128, uint256, int8, int16, int32, int64, int128, int256)
|
177
|
+
# - Address
|
178
|
+
# - String
|
179
|
+
# - Bytes (including fixed-size byte arrays)
|
180
|
+
# - Boolean
|
181
|
+
# - Array
|
182
|
+
# - Tuple (converted to a Hash)
|
183
|
+
#
|
184
|
+
# For complex types like arrays and tuples, the method recursively converts nested values.
|
185
|
+
def self.convert_solidity_value(solidity_value)
|
186
|
+
return nil if solidity_value.nil?
|
187
|
+
|
188
|
+
type = solidity_value.type
|
189
|
+
value = solidity_value.value
|
190
|
+
values = solidity_value.values
|
191
|
+
|
192
|
+
case type
|
193
|
+
when 'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
194
|
+
'int8', 'int16', 'int32', 'int64', 'int128', 'int256'
|
195
|
+
value&.to_i
|
196
|
+
when 'address', 'string', /^bytes/
|
197
|
+
value
|
198
|
+
when 'bool'
|
199
|
+
if value.is_a?(String)
|
200
|
+
value == 'true'
|
201
|
+
else
|
202
|
+
!value.nil?
|
203
|
+
end
|
204
|
+
when 'array'
|
205
|
+
values ? values.map { |v| convert_solidity_value(v) } : []
|
206
|
+
when 'tuple'
|
207
|
+
if values
|
208
|
+
result = {}
|
209
|
+
values.each do |v|
|
210
|
+
raise ArgumentError, 'Error: Tuple value without a name' unless v.respond_to?(:name)
|
211
|
+
|
212
|
+
result[v.name] = convert_solidity_value(v)
|
213
|
+
end
|
214
|
+
result
|
215
|
+
else
|
216
|
+
{}
|
217
|
+
end
|
218
|
+
else
|
219
|
+
raise ArgumentError, "Unsupported Solidity type: #{type}"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
private_class_method :convert_solidity_value
|
223
|
+
|
129
224
|
def self.contract_events_api
|
130
225
|
Coinbase::Client::ContractEventsApi.new(Coinbase.configuration.api_client)
|
131
226
|
end
|
@@ -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/transaction.rb
CHANGED
@@ -41,6 +41,12 @@ module Coinbase
|
|
41
41
|
@model = model
|
42
42
|
end
|
43
43
|
|
44
|
+
# Returns the Network of the Transaction.
|
45
|
+
# @return [Coinbase::Network] The Network
|
46
|
+
def network
|
47
|
+
@network ||= Coinbase::Network.from_id(@model.network_id)
|
48
|
+
end
|
49
|
+
|
44
50
|
# Returns the Unsigned Payload of the Transaction.
|
45
51
|
# @return [String] The Unsigned Payload
|
46
52
|
def unsigned_payload
|
@@ -101,8 +107,8 @@ module Coinbase
|
|
101
107
|
@model.transaction_link
|
102
108
|
end
|
103
109
|
|
104
|
-
# Returns
|
105
|
-
# @return [
|
110
|
+
# Returns detailed content the Transaction.
|
111
|
+
# @return [EthereumTransaction] The transaction content
|
106
112
|
def content
|
107
113
|
@model.content
|
108
114
|
end
|
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'
|