coinbase-sdk 0.0.14 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +7 -4
  3. data/lib/coinbase/address.rb +36 -0
  4. data/lib/coinbase/client/api/addresses_api.rb +1 -1
  5. data/lib/coinbase/client/api/assets_api.rb +1 -1
  6. data/lib/coinbase/client/api/contract_events_api.rb +1 -1
  7. data/lib/coinbase/client/api/external_addresses_api.rb +86 -1
  8. data/lib/coinbase/client/api/networks_api.rb +85 -0
  9. data/lib/coinbase/client/api/server_signers_api.rb +1 -1
  10. data/lib/coinbase/client/api/stake_api.rb +121 -1
  11. data/lib/coinbase/client/api/trades_api.rb +1 -1
  12. data/lib/coinbase/client/api/transfers_api.rb +1 -1
  13. data/lib/coinbase/client/api/users_api.rb +1 -1
  14. data/lib/coinbase/client/api/validators_api.rb +1 -1
  15. data/lib/coinbase/client/api/wallets_api.rb +1 -1
  16. data/lib/coinbase/client/api/webhooks_api.rb +1 -1
  17. data/lib/coinbase/client/api_client.rb +1 -1
  18. data/lib/coinbase/client/api_error.rb +1 -1
  19. data/lib/coinbase/client/configuration.rb +1 -11
  20. data/lib/coinbase/client/models/address.rb +1 -1
  21. data/lib/coinbase/client/models/address_balance_list.rb +1 -1
  22. data/lib/coinbase/client/models/address_historical_balance_list.rb +258 -0
  23. data/lib/coinbase/client/models/address_list.rb +1 -1
  24. data/lib/coinbase/client/models/asset.rb +1 -1
  25. data/lib/coinbase/client/models/balance.rb +1 -1
  26. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +1 -1
  27. data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
  28. data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
  29. data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
  30. data/lib/coinbase/client/models/contract_event.rb +1 -1
  31. data/lib/coinbase/client/models/contract_event_list.rb +1 -1
  32. data/lib/coinbase/client/models/create_address_request.rb +1 -1
  33. data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
  34. data/lib/coinbase/client/models/create_staking_operation_request.rb +1 -1
  35. data/lib/coinbase/client/models/create_trade_request.rb +1 -1
  36. data/lib/coinbase/client/models/create_transfer_request.rb +15 -5
  37. data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
  38. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
  39. data/lib/coinbase/client/models/create_webhook_request.rb +1 -1
  40. data/lib/coinbase/client/models/error.rb +1 -1
  41. data/lib/coinbase/client/models/ethereum_validator.rb +374 -0
  42. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
  43. data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
  44. data/lib/coinbase/client/models/feature.rb +1 -1
  45. data/lib/coinbase/client/models/feature_set.rb +307 -0
  46. data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +258 -0
  47. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
  48. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
  49. data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
  50. data/lib/coinbase/client/models/get_validator200_response.rb +221 -0
  51. data/lib/coinbase/client/models/get_validator200_response_validator.rb +214 -0
  52. data/lib/coinbase/client/models/historical_balance.rb +273 -0
  53. data/lib/coinbase/client/models/native_eth_staking_context.rb +1 -1
  54. data/lib/coinbase/client/models/network.rb +355 -0
  55. data/lib/coinbase/client/models/network_identifier.rb +44 -0
  56. data/lib/coinbase/client/models/partial_eth_staking_context.rb +1 -1
  57. data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
  58. data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
  59. data/lib/coinbase/client/models/server_signer.rb +1 -1
  60. data/lib/coinbase/client/models/server_signer_event.rb +1 -1
  61. data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
  62. data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
  63. data/lib/coinbase/client/models/server_signer_list.rb +1 -1
  64. data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
  65. data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
  66. data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
  67. data/lib/coinbase/client/models/sponsored_send.rb +338 -0
  68. data/lib/coinbase/client/models/staking_balance.rb +289 -0
  69. data/lib/coinbase/client/models/staking_context.rb +1 -1
  70. data/lib/coinbase/client/models/staking_context_context.rb +223 -75
  71. data/lib/coinbase/client/models/staking_operation.rb +3 -3
  72. data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
  73. data/lib/coinbase/client/models/staking_reward.rb +23 -7
  74. data/lib/coinbase/client/models/staking_reward_format.rb +3 -2
  75. data/lib/coinbase/client/models/staking_reward_usd_value.rb +257 -0
  76. data/lib/coinbase/client/models/trade.rb +1 -1
  77. data/lib/coinbase/client/models/trade_list.rb +1 -1
  78. data/lib/coinbase/client/models/transaction.rb +3 -3
  79. data/lib/coinbase/client/models/transaction_type.rb +3 -2
  80. data/lib/coinbase/client/models/transfer.rb +102 -9
  81. data/lib/coinbase/client/models/transfer_list.rb +1 -1
  82. data/lib/coinbase/client/models/update_webhook_request.rb +1 -1
  83. data/lib/coinbase/client/models/user.rb +1 -1
  84. data/lib/coinbase/client/models/validator.rb +1 -1
  85. data/lib/coinbase/client/models/validator_details.rb +1 -1
  86. data/lib/coinbase/client/models/validator_list.rb +1 -1
  87. data/lib/coinbase/client/models/validator_list_data.rb +216 -0
  88. data/lib/coinbase/client/models/wallet.rb +14 -17
  89. data/lib/coinbase/client/models/wallet_list.rb +1 -1
  90. data/lib/coinbase/client/models/webhook.rb +1 -1
  91. data/lib/coinbase/client/models/webhook_event_filter.rb +1 -1
  92. data/lib/coinbase/client/models/webhook_event_type.rb +3 -2
  93. data/lib/coinbase/client/models/webhook_list.rb +1 -1
  94. data/lib/coinbase/client/version.rb +1 -1
  95. data/lib/coinbase/client.rb +11 -4
  96. data/lib/coinbase/errors.rb +7 -0
  97. data/lib/coinbase/historical_balance.rb +53 -0
  98. data/lib/coinbase/server_signer.rb +14 -3
  99. data/lib/coinbase/sponsored_send.rb +110 -0
  100. data/lib/coinbase/staking_balance.rb +86 -0
  101. data/lib/coinbase/staking_reward.rb +18 -0
  102. data/lib/coinbase/transaction.rb +7 -3
  103. data/lib/coinbase/transfer.rb +56 -28
  104. data/lib/coinbase/wallet/data.rb +31 -0
  105. data/lib/coinbase/wallet.rb +15 -46
  106. data/lib/coinbase.rb +15 -3
  107. metadata +48 -2
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Coinbase
6
+ # A representation of a staking balance on a network for a given asset.
7
+ class StakingBalance
8
+ # Returns a list of StakingBalance for the provided network, asset, and addresses.
9
+ # @param network_id [Symbol] The network ID
10
+ # @param asset_id [Symbol] The asset ID
11
+ # @param address_id [String] The address ID
12
+ # @param start_time [Time] The start time. Defaults to one month ago.
13
+ # @param end_time [Time] The end time. Defaults to the current time.
14
+ # @return [Enumerable<Coinbase::StakingBalance>] The staking balances
15
+ def self.list(network_id, asset_id, address_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now)
16
+ Coinbase::Pagination.enumerate(
17
+ ->(page) { list_page(network_id, asset_id, address_id, start_time, end_time, page) }
18
+ ) do |staking_balance|
19
+ new(staking_balance)
20
+ end
21
+ end
22
+
23
+ # Returns a new StakingBalance object.
24
+ # @param model [Coinbase::Client::StakingBalance] The underlying StakingBalance object
25
+ def initialize(model)
26
+ @model = model
27
+ end
28
+
29
+ # Returns the date of the StakingBalance.
30
+ # @return [Time] The date
31
+ def date
32
+ @model.date
33
+ end
34
+
35
+ # Returns the onchain address of the StakingBalance.
36
+ # @return [Time] The onchain address
37
+ def address
38
+ @model.address
39
+ end
40
+
41
+ # Returns the bonded stake as a Balance
42
+ # @return [Balance] The bonded stake
43
+ def bonded_stake
44
+ @bonded_stake ||= Balance.from_model(@model.bonded_stake)
45
+ end
46
+
47
+ # Returns the unbonded balance as a Balance
48
+ # @return [Balance] The unbonded balance
49
+ def unbonded_balance
50
+ @unbonded_balance ||= Balance.from_model(@model.unbonded_balance)
51
+ end
52
+
53
+ # Returns the participant type of the StakingBalance.
54
+ # @return [String] The participant type
55
+ def participant_type
56
+ @model.participant_type
57
+ end
58
+
59
+ # Returns a string representation of the StakingBalance.
60
+ # @return [String] a string representation of the StakingBalance
61
+ def to_s
62
+ "Coinbase::StakingBalance{date: '#{date}' address: '#{address}'}"
63
+ end
64
+
65
+ # Same as to_s.
66
+ # @return [String] a string representation of the StakingBalance
67
+ def inspect
68
+ to_s
69
+ end
70
+
71
+ def self.stake_api
72
+ Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
73
+ end
74
+
75
+ def self.list_page(network_id, asset_id, address_id, start_time, end_time, page)
76
+ stake_api.fetch_historical_staking_balances(
77
+ Coinbase.normalize_network(network_id),
78
+ asset_id,
79
+ address_id,
80
+ start_time.iso8601,
81
+ end_time.iso8601,
82
+ { next_page: page }
83
+ )
84
+ end
85
+ end
86
+ end
@@ -53,6 +53,24 @@ module Coinbase
53
53
  @model.address_id
54
54
  end
55
55
 
56
+ # Returns the USD value of the StakingReward.
57
+ # @return [BigDecimal] The USD value
58
+ def usd_value
59
+ BigDecimal(@model.usd_value.amount.to_i) / BigDecimal(100)
60
+ end
61
+
62
+ # Returns the USD conversion price of the StakingReward.
63
+ # @return [BigDecimal] The USD conversion price
64
+ def usd_conversion_price
65
+ BigDecimal(@model.usd_value.conversion_price.to_i) / BigDecimal(100)
66
+ end
67
+
68
+ # Returns the USD conversion time of the StakingReward.
69
+ # @return [Time] The USD conversion time
70
+ def usd_conversion_time
71
+ @model.usd_value.conversion_time
72
+ end
73
+
56
74
  # Returns a string representation of the StakingReward.
57
75
  # @return [String] a string representation of the StakingReward
58
76
  def to_s
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'constants'
4
- require 'bigdecimal'
5
3
  require 'eth'
6
4
  require 'json'
7
5
 
@@ -113,12 +111,18 @@ module Coinbase
113
111
  @raw = Eth::Tx::Eip1559.new(Eth::Tx.validate_eip1559_params(params))
114
112
  end
115
113
 
114
+ # Returns the signature of the Transaction.
115
+ # @return [String] The hex-encode signature
116
+ def signature
117
+ raw.hex
118
+ end
119
+
116
120
  # Signs the Transaction with the provided key and returns the hex signing payload.
117
121
  # @return [String] The hex-encoded signed payload
118
122
  def sign(key)
119
123
  raw.sign(key)
120
124
 
121
- raw.hex
125
+ signature
122
126
  end
123
127
 
124
128
  # Returns whether the Transaction has been signed.
@@ -3,7 +3,6 @@
3
3
  require_relative 'constants'
4
4
  require 'bigdecimal'
5
5
  require 'eth'
6
- require 'json'
7
6
 
8
7
  module Coinbase
9
8
  # A representation of a Transfer, which moves an amount of an Asset from
@@ -25,7 +24,7 @@ module Coinbase
25
24
  # @param wallet_id [String] The Wallet ID of the sending Wallet
26
25
  # @return [Transfer] The new pending Transfer object
27
26
  # @raise [Coinbase::ApiError] If the Transfer fails
28
- def create(address_id:, amount:, asset_id:, destination:, network_id:, wallet_id:)
27
+ def create(address_id:, amount:, asset_id:, destination:, network_id:, wallet_id:, gasless: false)
29
28
  asset = Asset.fetch(network_id, asset_id)
30
29
 
31
30
  model = Coinbase.call_api do
@@ -36,7 +35,8 @@ module Coinbase
36
35
  amount: asset.to_atomic_amount(amount).to_i.to_s,
37
36
  asset_id: asset.primary_denomination.to_s,
38
37
  destination: Coinbase::Destination.new(destination, network_id: network_id).address_id,
39
- network_id: Coinbase.normalize_network(network_id)
38
+ network_id: Coinbase.normalize_network(network_id),
39
+ gasless: gasless
40
40
  }
41
41
  )
42
42
  end
@@ -122,40 +122,52 @@ module Coinbase
122
122
  BigDecimal(@model.amount) / BigDecimal(10).power(@model.asset.decimals)
123
123
  end
124
124
 
125
- # Returns the link to the transaction on the blockchain explorer.
126
- # @return [String] The link to the transaction on the blockchain explorer
127
- def transaction_link
128
- transaction.transaction_link
129
- end
125
+ # Signs the Transfer with the given key. This is required before broadcasting the Transfer.
126
+ # @param key [Eth::Key] The key to sign the Transfer with
127
+ # @raise [RuntimeError] If the key is not an Eth::Key
128
+ # @return [Transfer] The Transfer object
129
+ def sign(key)
130
+ raise unless key.is_a?(Eth::Key)
130
131
 
131
- # Returns the Unsigned Payload of the Transfer.
132
- # @return [String] The Unsigned Payload
133
- def unsigned_payload
134
- transaction.unsigned_payload
135
- end
132
+ unless sponsored_send.nil?
133
+ sponsored_send.sign(key)
134
+
135
+ return
136
+ end
136
137
 
137
- # Returns the Signed Payload of the Transfer.
138
- # @return [String] The Signed Payload
139
- def signed_payload
140
- transaction.signed_payload
138
+ transaction.sign(key)
139
+
140
+ self
141
141
  end
142
142
 
143
143
  # Returns the Transfer transaction.
144
144
  # @return [Coinbase::Transaction] The Transfer transaction
145
145
  def transaction
146
- @transaction ||= Coinbase::Transaction.new(@model.transaction)
146
+ @transaction ||= @model.transaction.nil? ? nil : Coinbase::Transaction.new(@model.transaction)
147
147
  end
148
148
 
149
- # Returns the Transaction Hash of the Transfer.
150
- # @return [String] The Transaction Hash
151
- def transaction_hash
152
- transaction.transaction_hash
149
+ # Returns the SponsoredSend of the Transfer, if the transfer is gasless.
150
+ # @return [Coinbase::SponsoredSend] The SponsoredSend object
151
+ def sponsored_send
152
+ @sponsored_send ||= @model.sponsored_send.nil? ? nil : Coinbase::SponsoredSend.new(@model.sponsored_send)
153
153
  end
154
154
 
155
155
  # Returns the status of the Transfer.
156
156
  # @return [Symbol] The status
157
157
  def status
158
- transaction.status
158
+ send_tx_delegate.status
159
+ end
160
+
161
+ # Returns the link to the transaction on the blockchain explorer.
162
+ # @return [String] The link to the transaction on the blockchain explorer
163
+ def transaction_link
164
+ send_tx_delegate.transaction_link
165
+ end
166
+
167
+ # Returns the Transaction Hash of the Transfer.
168
+ # @return [String] The Transaction Hash
169
+ def transaction_hash
170
+ send_tx_delegate.transaction_hash
159
171
  end
160
172
 
161
173
  # Broadcasts the Transfer to the Network.
@@ -163,18 +175,19 @@ module Coinbase
163
175
  # @raise [RuntimeError] If the Transfer is not signed
164
176
  # @return [Transfer] The Transfer object
165
177
  def broadcast!
166
- raise TransactionNotSignedError unless transaction.signed?
178
+ raise TransactionNotSignedError unless send_tx_delegate.signed?
167
179
 
168
180
  @model = Coinbase.call_api do
169
181
  transfers_api.broadcast_transfer(
170
182
  wallet_id,
171
183
  from_address_id,
172
184
  id,
173
- { signed_payload: transaction.raw.hex }
185
+ { signed_payload: send_tx_delegate.signature }
174
186
  )
175
187
  end
176
188
 
177
- update_transaction(@model)
189
+ update_transaction(@model) unless @model.transaction.nil?
190
+ update_sponsored_send(@model) unless @model.sponsored_send.nil?
178
191
 
179
192
  self
180
193
  end
@@ -186,7 +199,8 @@ module Coinbase
186
199
  transfers_api.get_transfer(wallet_id, from_address_id, id)
187
200
  end
188
201
 
189
- update_transaction(@model)
202
+ update_transaction(@model) unless @model.transaction.nil?
203
+ update_sponsored_send(@model) unless @model.sponsored_send.nil?
190
204
 
191
205
  self
192
206
  end
@@ -202,7 +216,7 @@ module Coinbase
202
216
  loop do
203
217
  reload
204
218
 
205
- return self if transaction.terminal_state?
219
+ return self if terminal_state?
206
220
 
207
221
  raise Timeout::Error, 'Transfer timed out' if Time.now - start_time > timeout_seconds
208
222
 
@@ -229,6 +243,16 @@ module Coinbase
229
243
 
230
244
  private
231
245
 
246
+ def terminal_state?
247
+ send_tx_delegate.terminal_state?
248
+ end
249
+
250
+ def send_tx_delegate
251
+ return sponsored_send unless sponsored_send.nil?
252
+
253
+ transaction
254
+ end
255
+
232
256
  def transfers_api
233
257
  @transfers_api ||= Coinbase::Client::TransfersApi.new(Coinbase.configuration.api_client)
234
258
  end
@@ -236,5 +260,9 @@ module Coinbase
236
260
  def update_transaction(model)
237
261
  @transaction = Coinbase::Transaction.new(model.transaction)
238
262
  end
263
+
264
+ def update_sponsored_send(model)
265
+ @sponsored_send = Coinbase::SponsoredSend.new(model.sponsored_send)
266
+ end
239
267
  end
240
268
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ class Wallet
5
+ # The data required to recreate a Wallet.
6
+ class Data
7
+ attr_reader :wallet_id, :seed
8
+
9
+ # Returns a new Data object.
10
+ # @param wallet_id [String] The ID of the Wallet
11
+ # @param seed [String] The seed of the Wallet
12
+ def initialize(wallet_id:, seed:)
13
+ @wallet_id = wallet_id
14
+ @seed = seed
15
+ end
16
+
17
+ # Converts the Data object to a Hash.
18
+ # @return [Hash] The Hash representation of the Data object
19
+ def to_hash
20
+ { wallet_id: wallet_id, seed: seed }
21
+ end
22
+
23
+ # Creates a Data object from the given Hash.
24
+ # @param data [Hash] The Hash to create the Data object from
25
+ # @return [Data] The new Data object
26
+ def self.from_hash(data)
27
+ Data.new(wallet_id: data['wallet_id'], seed: data['seed'])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -5,6 +5,8 @@ require 'json'
5
5
  require 'money-tree'
6
6
  require 'securerandom'
7
7
 
8
+ require_relative 'wallet/data'
9
+
8
10
  module Coinbase
9
11
  # A representation of a Wallet. Wallets come with a single default Address, but can expand to have a set of Addresses,
10
12
  # each of which can hold a balance of one or more Assets. Wallets can create new Addresses, list their addresses,
@@ -13,17 +15,6 @@ module Coinbase
13
15
  # The maximum number of addresses in a Wallet.
14
16
  MAX_ADDRESSES = 20
15
17
 
16
- # A representation of ServerSigner status in a Wallet.
17
- module ServerSignerStatus
18
- # The Wallet is awaiting seed creation by the ServerSigner. At this point,
19
- # the Wallet cannot create addresses or sign transactions.
20
- PENDING = 'pending_seed_creation'
21
-
22
- # The Wallet has an associated seed created by the ServerSigner. It is ready
23
- # to create addresses and sign transactions.
24
- ACTIVE = 'active_seed'
25
- end
26
-
27
18
  class << self
28
19
  # Imports a Wallet from previously exported wallet data.
29
20
  # @param data [Coinbase::Wallet::Data] the Wallet data to import
@@ -43,7 +34,7 @@ module Coinbase
43
34
  # converted to an array, etc...
44
35
  # @return [Enumerable<Coinbase::Wallet>] Enumerator that returns wallets
45
36
  def list
46
- Coinbase::Pagination.enumerate(lambda(&method(:fetch_wallets_page))) do |wallet|
37
+ Coinbase::Pagination.enumerate(method(:fetch_wallets_page)) do |wallet|
47
38
  Coinbase::Wallet.new(wallet, seed: '')
48
39
  end
49
40
  end
@@ -107,7 +98,7 @@ module Coinbase
107
98
  wallets_api.get_wallet(wallet_id)
108
99
  end
109
100
 
110
- return self if model.server_signer_status == ServerSignerStatus::ACTIVE
101
+ return self if model.server_signer_status == ServerSigner::Status::ACTIVE
111
102
 
112
103
  if Time.now - start_time > timeout_seconds
113
104
  raise Timeout::Error, 'Wallet creation timed out. Check status of your Server-Signer'
@@ -278,9 +269,15 @@ module Coinbase
278
269
  # @param asset_id [Symbol] The ID of the Asset to send
279
270
  # @param destination [Wallet | Address | String] The destination of the transfer. If a Wallet, sends to the Wallet's
280
271
  # default address. If a String, interprets it as the address ID.
272
+ # @param gasless [Boolean] Whether gas fee for the transfer should be covered by Coinbase.
273
+ # Defaults to false. Check the API documentation for network and asset support.
281
274
  # @return [Coinbase::Transfer] The Transfer object.
282
- def transfer(amount, asset_id, destination)
283
- default_address.transfer(amount, asset_id, destination)
275
+ def transfer(amount, asset_id, destination, options = {})
276
+ # For ruby 2.7 compatibility we cannot pass in keyword args when the create wallet
277
+ # options is empty
278
+ return default_address.transfer(amount, asset_id, destination) if options.empty?
279
+
280
+ default_address.transfer(amount, asset_id, destination, **options)
284
281
  end
285
282
 
286
283
  # Trades the given amount of the given Asset for another Asset.
@@ -371,7 +368,7 @@ module Coinbase
371
368
  end
372
369
 
373
370
  # Exports the Wallet's data to a Data object.
374
- # @return [Data] The Wallet data
371
+ # @return [Coinbase::Wallet::Data] The Wallet data
375
372
  def export
376
373
  # TODO: Improve this check by relying on the backend data to decide whether a wallet is server-signer backed.
377
374
  raise 'Cannot export data for Server-Signer backed Wallet' if Coinbase.use_server_signer?
@@ -433,9 +430,7 @@ module Coinbase
433
430
  iv: iv
434
431
  }
435
432
 
436
- File.open(file_path, 'w') do |file|
437
- file.write(JSON.pretty_generate(existing_seeds_in_store))
438
- end
433
+ File.write(file_path, JSON.pretty_generate(existing_seeds_in_store))
439
434
 
440
435
  "Successfully saved seed for wallet #{id} to #{file_path}."
441
436
  end
@@ -492,32 +487,6 @@ module Coinbase
492
487
  to_s
493
488
  end
494
489
 
495
- # The data required to recreate a Wallet.
496
- class Data
497
- attr_reader :wallet_id, :seed
498
-
499
- # Returns a new Data object.
500
- # @param wallet_id [String] The ID of the Wallet
501
- # @param seed [String] The seed of the Wallet
502
- def initialize(wallet_id:, seed:)
503
- @wallet_id = wallet_id
504
- @seed = seed
505
- end
506
-
507
- # Converts the Data object to a Hash.
508
- # @return [Hash] The Hash representation of the Data object
509
- def to_hash
510
- { wallet_id: wallet_id, seed: seed }
511
- end
512
-
513
- # Creates a Data object from the given Hash.
514
- # @param data [Hash] The Hash to create the Data object from
515
- # @return [Data] The new Data object
516
- def self.from_hash(data)
517
- Data.new(wallet_id: data['wallet_id'], seed: data['seed'])
518
- end
519
- end
520
-
521
490
  private
522
491
 
523
492
  # Reloads the Wallet with the latest data.
@@ -540,7 +509,7 @@ module Coinbase
540
509
  def address_path_prefix
541
510
  # TODO: Push this logic to the backend.
542
511
  @address_path_prefix ||= case network_id.to_s.split('_').first
543
- when 'base', 'ethereum'
512
+ when 'base', 'ethereum', 'polygon'
544
513
  "m/44'/60'/0'/0"
545
514
  else
546
515
  raise ArgumentError, "Unsupported network ID: #{network_id}"
data/lib/coinbase.rb CHANGED
@@ -7,6 +7,7 @@ require_relative 'coinbase/asset'
7
7
  require_relative 'coinbase/authenticator'
8
8
  require_relative 'coinbase/balance'
9
9
  require_relative 'coinbase/balance_map'
10
+ require_relative 'coinbase/historical_balance'
10
11
  require_relative 'coinbase/client'
11
12
  require_relative 'coinbase/constants'
12
13
  require_relative 'coinbase/destination'
@@ -21,6 +22,8 @@ require_relative 'coinbase/transaction'
21
22
  require_relative 'coinbase/user'
22
23
  require_relative 'coinbase/wallet'
23
24
  require_relative 'coinbase/server_signer'
25
+ require_relative 'coinbase/sponsored_send'
26
+ require_relative 'coinbase/staking_balance'
24
27
  require_relative 'coinbase/staking_operation'
25
28
  require_relative 'coinbase/staking_reward'
26
29
  require_relative 'coinbase/validator'
@@ -111,7 +114,7 @@ module Coinbase
111
114
  # @param network_sym [Symbol] the network symbol to convert
112
115
  # @return [String] the converted string
113
116
  def self.normalize_network(network_sym)
114
- network_sym.to_s.gsub(/_/, '-')
117
+ network_sym.to_s.gsub('_', '-')
115
118
  end
116
119
 
117
120
  # Loads the default user.
@@ -128,8 +131,17 @@ module Coinbase
128
131
  yield
129
132
  rescue Coinbase::Client::ApiError => e
130
133
  raise Coinbase::APIError.from_error(e), cause: nil
131
- rescue StandardError => e
132
- raise e
134
+ end
135
+
136
+ # Returns a pretty-printed object string that contains the object's class name and
137
+ # the details of the object, filtering out nil values.
138
+ # @param klass [Class] the class of the object
139
+ # @param details [Hash] the details of the object
140
+ # @return [String] the pretty-printed object string
141
+ def self.pretty_print_object(klass, **details)
142
+ filtered_details = details.filter { |_, v| !v.nil? }.map { |k, v| "#{k}: '#{v}'" }
143
+
144
+ "#{klass}{#{filtered_details.join(', ')}}"
133
145
  end
134
146
 
135
147
  # Returns whether to use a server signer to manage private keys.
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.0.14
4
+ version: 0.0.16
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-08-05 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: factory_bot
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: pry
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,20 @@ dependencies:
192
206
  - - '='
193
207
  - !ruby/object:Gem::Version
194
208
  version: 1.63.1
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop-rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
195
223
  - !ruby/object:Gem::Dependency
196
224
  name: simplecov
197
225
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +281,7 @@ files:
253
281
  - lib/coinbase/client/api/assets_api.rb
254
282
  - lib/coinbase/client/api/contract_events_api.rb
255
283
  - lib/coinbase/client/api/external_addresses_api.rb
284
+ - lib/coinbase/client/api/networks_api.rb
256
285
  - lib/coinbase/client/api/server_signers_api.rb
257
286
  - lib/coinbase/client/api/stake_api.rb
258
287
  - lib/coinbase/client/api/trades_api.rb
@@ -266,6 +295,7 @@ files:
266
295
  - lib/coinbase/client/configuration.rb
267
296
  - lib/coinbase/client/models/address.rb
268
297
  - lib/coinbase/client/models/address_balance_list.rb
298
+ - lib/coinbase/client/models/address_historical_balance_list.rb
269
299
  - lib/coinbase/client/models/address_list.rb
270
300
  - lib/coinbase/client/models/asset.rb
271
301
  - lib/coinbase/client/models/balance.rb
@@ -284,13 +314,21 @@ files:
284
314
  - lib/coinbase/client/models/create_wallet_request_wallet.rb
285
315
  - lib/coinbase/client/models/create_webhook_request.rb
286
316
  - lib/coinbase/client/models/error.rb
317
+ - lib/coinbase/client/models/ethereum_validator.rb
287
318
  - lib/coinbase/client/models/ethereum_validator_metadata.rb
288
319
  - lib/coinbase/client/models/faucet_transaction.rb
289
320
  - lib/coinbase/client/models/feature.rb
321
+ - lib/coinbase/client/models/feature_set.rb
322
+ - lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb
290
323
  - lib/coinbase/client/models/fetch_staking_rewards200_response.rb
291
324
  - lib/coinbase/client/models/fetch_staking_rewards_request.rb
292
325
  - lib/coinbase/client/models/get_staking_context_request.rb
326
+ - lib/coinbase/client/models/get_validator200_response.rb
327
+ - lib/coinbase/client/models/get_validator200_response_validator.rb
328
+ - lib/coinbase/client/models/historical_balance.rb
293
329
  - lib/coinbase/client/models/native_eth_staking_context.rb
330
+ - lib/coinbase/client/models/network.rb
331
+ - lib/coinbase/client/models/network_identifier.rb
294
332
  - lib/coinbase/client/models/partial_eth_staking_context.rb
295
333
  - lib/coinbase/client/models/seed_creation_event.rb
296
334
  - lib/coinbase/client/models/seed_creation_event_result.rb
@@ -302,12 +340,15 @@ files:
302
340
  - lib/coinbase/client/models/signature_creation_event.rb
303
341
  - lib/coinbase/client/models/signature_creation_event_result.rb
304
342
  - lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb
343
+ - lib/coinbase/client/models/sponsored_send.rb
344
+ - lib/coinbase/client/models/staking_balance.rb
305
345
  - lib/coinbase/client/models/staking_context.rb
306
346
  - lib/coinbase/client/models/staking_context_context.rb
307
347
  - lib/coinbase/client/models/staking_operation.rb
308
348
  - lib/coinbase/client/models/staking_operation_metadata.rb
309
349
  - lib/coinbase/client/models/staking_reward.rb
310
350
  - lib/coinbase/client/models/staking_reward_format.rb
351
+ - lib/coinbase/client/models/staking_reward_usd_value.rb
311
352
  - lib/coinbase/client/models/trade.rb
312
353
  - lib/coinbase/client/models/trade_list.rb
313
354
  - lib/coinbase/client/models/transaction.rb
@@ -319,6 +360,7 @@ files:
319
360
  - lib/coinbase/client/models/validator.rb
320
361
  - lib/coinbase/client/models/validator_details.rb
321
362
  - lib/coinbase/client/models/validator_list.rb
363
+ - lib/coinbase/client/models/validator_list_data.rb
322
364
  - lib/coinbase/client/models/wallet.rb
323
365
  - lib/coinbase/client/models/wallet_list.rb
324
366
  - lib/coinbase/client/models/webhook.rb
@@ -330,10 +372,13 @@ files:
330
372
  - lib/coinbase/destination.rb
331
373
  - lib/coinbase/errors.rb
332
374
  - lib/coinbase/faucet_transaction.rb
375
+ - lib/coinbase/historical_balance.rb
333
376
  - lib/coinbase/middleware.rb
334
377
  - lib/coinbase/network.rb
335
378
  - lib/coinbase/pagination.rb
336
379
  - lib/coinbase/server_signer.rb
380
+ - lib/coinbase/sponsored_send.rb
381
+ - lib/coinbase/staking_balance.rb
337
382
  - lib/coinbase/staking_operation.rb
338
383
  - lib/coinbase/staking_reward.rb
339
384
  - lib/coinbase/trade.rb
@@ -342,6 +387,7 @@ files:
342
387
  - lib/coinbase/user.rb
343
388
  - lib/coinbase/validator.rb
344
389
  - lib/coinbase/wallet.rb
390
+ - lib/coinbase/wallet/data.rb
345
391
  homepage: https://github.com/coinbase/coinbase-sdk-ruby
346
392
  licenses:
347
393
  - Apache-2.0