coinbase-sdk 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/external_address.rb +3 -166
  3. data/lib/coinbase/address/wallet_address.rb +44 -0
  4. data/lib/coinbase/address.rb +128 -0
  5. data/lib/coinbase/client/api/addresses_api.rb +1 -1
  6. data/lib/coinbase/client/api/assets_api.rb +3 -3
  7. data/lib/coinbase/client/api/contract_events_api.rb +121 -0
  8. data/lib/coinbase/client/api/external_addresses_api.rb +1 -1
  9. data/lib/coinbase/client/api/server_signers_api.rb +1 -1
  10. data/lib/coinbase/client/api/stake_api.rb +242 -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 +286 -0
  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 +11 -1
  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_list.rb +1 -1
  23. data/lib/coinbase/client/models/asset.rb +1 -1
  24. data/lib/coinbase/client/models/balance.rb +1 -1
  25. data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +239 -0
  26. data/lib/coinbase/client/models/broadcast_trade_request.rb +1 -1
  27. data/lib/coinbase/client/models/broadcast_transfer_request.rb +1 -1
  28. data/lib/coinbase/client/models/build_staking_operation_request.rb +1 -1
  29. data/lib/coinbase/client/models/contract_event.rb +336 -0
  30. data/lib/coinbase/client/models/contract_event_list.rb +259 -0
  31. data/lib/coinbase/client/models/create_address_request.rb +1 -1
  32. data/lib/coinbase/client/models/create_server_signer_request.rb +1 -1
  33. data/lib/coinbase/client/models/create_staking_operation_request.rb +274 -0
  34. data/lib/coinbase/client/models/create_trade_request.rb +1 -1
  35. data/lib/coinbase/client/models/create_transfer_request.rb +1 -1
  36. data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
  37. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +1 -1
  38. data/lib/coinbase/client/models/create_webhook_request.rb +282 -0
  39. data/lib/coinbase/client/models/error.rb +1 -1
  40. data/lib/coinbase/client/models/ethereum_validator_metadata.rb +1 -1
  41. data/lib/coinbase/client/models/faucet_transaction.rb +1 -1
  42. data/lib/coinbase/client/models/feature.rb +1 -1
  43. data/lib/coinbase/client/models/fetch_staking_rewards200_response.rb +1 -1
  44. data/lib/coinbase/client/models/fetch_staking_rewards_request.rb +1 -1
  45. data/lib/coinbase/client/models/get_staking_context_request.rb +1 -1
  46. data/lib/coinbase/client/models/native_eth_staking_context.rb +1 -1
  47. data/lib/coinbase/client/models/partial_eth_staking_context.rb +1 -1
  48. data/lib/coinbase/client/models/seed_creation_event.rb +1 -1
  49. data/lib/coinbase/client/models/seed_creation_event_result.rb +1 -1
  50. data/lib/coinbase/client/models/server_signer.rb +1 -1
  51. data/lib/coinbase/client/models/server_signer_event.rb +1 -1
  52. data/lib/coinbase/client/models/server_signer_event_event.rb +1 -1
  53. data/lib/coinbase/client/models/server_signer_event_list.rb +1 -1
  54. data/lib/coinbase/client/models/server_signer_list.rb +1 -1
  55. data/lib/coinbase/client/models/signature_creation_event.rb +1 -1
  56. data/lib/coinbase/client/models/signature_creation_event_result.rb +1 -1
  57. data/lib/coinbase/client/models/signed_voluntary_exit_message_metadata.rb +1 -1
  58. data/lib/coinbase/client/models/staking_context.rb +1 -1
  59. data/lib/coinbase/client/models/staking_context_context.rb +1 -1
  60. data/lib/coinbase/client/models/staking_operation.rb +16 -6
  61. data/lib/coinbase/client/models/staking_operation_metadata.rb +1 -1
  62. data/lib/coinbase/client/models/staking_reward.rb +1 -1
  63. data/lib/coinbase/client/models/staking_reward_format.rb +1 -1
  64. data/lib/coinbase/client/models/trade.rb +1 -1
  65. data/lib/coinbase/client/models/trade_list.rb +1 -1
  66. data/lib/coinbase/client/models/transaction.rb +1 -1
  67. data/lib/coinbase/client/models/transaction_type.rb +1 -1
  68. data/lib/coinbase/client/models/transfer.rb +5 -93
  69. data/lib/coinbase/client/models/transfer_list.rb +1 -1
  70. data/lib/coinbase/client/models/update_webhook_request.rb +289 -0
  71. data/lib/coinbase/client/models/user.rb +1 -1
  72. data/lib/coinbase/client/models/validator.rb +1 -1
  73. data/lib/coinbase/client/models/validator_details.rb +1 -1
  74. data/lib/coinbase/client/models/validator_list.rb +1 -1
  75. data/lib/coinbase/client/models/wallet.rb +1 -1
  76. data/lib/coinbase/client/models/wallet_list.rb +1 -1
  77. data/lib/coinbase/client/models/webhook.rb +299 -0
  78. data/lib/coinbase/client/models/webhook_event_filter.rb +236 -0
  79. data/lib/coinbase/client/models/webhook_event_type.rb +41 -0
  80. data/lib/coinbase/client/models/webhook_list.rb +244 -0
  81. data/lib/coinbase/client/version.rb +1 -1
  82. data/lib/coinbase/client.rb +13 -1
  83. data/lib/coinbase/middleware.rb +12 -0
  84. data/lib/coinbase/staking_operation.rb +106 -5
  85. data/lib/coinbase/trade.rb +1 -1
  86. data/lib/coinbase/transfer.rb +4 -5
  87. data/lib/coinbase/wallet.rb +76 -0
  88. data/lib/coinbase.rb +2 -1
  89. metadata +28 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ea6f3f49e4b03f6131d891a1e628b9bed3a60b40b0a640358b5cc85ff4075ab
4
- data.tar.gz: 92d2b00b3dac22f12173f9b6a7860889b7d9e64966e55cf7ba175a3728f43be3
3
+ metadata.gz: e6e9201f406c2e00680635ef5a35745b7e0163590ca3f54b0b54e33ef0c6d677
4
+ data.tar.gz: c46b18a0a974942a1b81fb7c0fd240b7e8c5ce9fe4761932866141cc44b26c07
5
5
  SHA512:
6
- metadata.gz: c4a96ebe5f58f569419d2911aab739706d4176fb403b2283d8b44d29f36768bcf2588088f1870cbabc7a7f4941d12a9d796565e60c126014c48b318725fb8d13
7
- data.tar.gz: d97661b3ab9abb774561a307bb228c1d3795077777001ca5b6657f2205cf81f8674f68ef4bb9dff4b01623cfffa5c2835e26e58d26dbbf51a8bfcd70b13edc52
6
+ metadata.gz: b74ce16758ba14308beaf7166ad5162c808d984549cf029084f2b3f2f3758f6a97e3a1be4d619f0cb24002d9ec721754bef4c8a7cb363bf4f7d947bf529b2cc3
7
+ data.tar.gz: c03d22d0685413d4d732f75ef3216132af6ad0d3cd3fa2985378f559637a62c0490310da73f9607961321be4b60effb43d2ff8a063b1fba083f8c7e365322909
@@ -3,171 +3,8 @@
3
3
  require 'date'
4
4
 
5
5
  module Coinbase
6
- # A representation of a blockchain Address that do not belong to a Coinbase::Wallet.
7
- # External addresses can be used to fetch balances, request funds from the faucet, etc...,
6
+ # A representation of a blockchain Address that does not belong to a Coinbase::Wallet.
7
+ # External addresses can be used to fetch balances, request funds from the faucet, etc.,
8
8
  # but cannot be used to sign transactions.
9
- class ExternalAddress < Address
10
- # Builds a stake operation for the supplied asset. The stake operation
11
- # may take a few minutes to complete in the case when infrastructure is spun up.
12
- # @param amount [Integer,String,BigDecimal] The amount of the asset to stake
13
- # @param asset_id [Symbol] The asset to stake
14
- # @param mode [Symbol] The staking mode. Defaults to :default.
15
- # @param options [Hash] Additional options for the stake operation
16
- # @return [Coinbase::StakingOperation] The stake operation
17
- def build_stake_operation(amount, asset_id, mode: :default, options: {})
18
- validate_can_stake!(amount, asset_id, mode, options)
19
-
20
- build_staking_operation(amount, asset_id, 'stake', mode: mode, options: options)
21
- end
22
-
23
- # Builds an unstake operation for the supplied asset.
24
- # @param amount [Integer,String,BigDecimal] The amount of the asset to unstake
25
- # @param asset_id [Symbol] The asset to unstake
26
- # @param mode [Symbol] The staking mode. Defaults to :default.
27
- # @param options [Hash] Additional options for the unstake operation
28
- # @return [Coinbase::StakingOperation] The unstake operation
29
- def build_unstake_operation(amount, asset_id, mode: :default, options: {})
30
- validate_can_unstake!(amount, asset_id, mode, options)
31
-
32
- build_staking_operation(amount, asset_id, 'unstake', mode: mode, options: options)
33
- end
34
-
35
- # Builds an claim_stake operation for the supplied asset.
36
- # @param amount [Integer,String,BigDecimal] The amount of the asset to claim
37
- # @param asset_id [Symbol] The asset to claim
38
- # @param mode [Symbol] The staking mode. Defaults to :default.
39
- # @param options [Hash] Additional options for the claim_stake operation
40
- # @return [Coinbase::StakingOperation] The claim_stake operation
41
- def build_claim_stake_operation(amount, asset_id, mode: :default, options: {})
42
- validate_can_claim_stake!(amount, asset_id, mode, options)
43
-
44
- build_staking_operation(amount, asset_id, 'claim_stake', mode: mode, options: options)
45
- end
46
-
47
- # Retrieves the balances used for staking for the supplied asset.
48
- # @param asset_id [Symbol] The asset to retrieve staking balances for
49
- # @param mode [Symbol] The staking mode. Defaults to :default.
50
- # @param options [Hash] Additional options for the staking operation
51
- # @return [Hash] The staking balances
52
- # @return [BigDecimal] :stakeable_balance The amount of the asset that can be staked
53
- # @return [BigDecimal] :unstakeable_balance The amount of the asset that is currently staked and cannot be unstaked
54
- # @return [BigDecimal] :claimable_balance The amount of the asset that can be claimed
55
- def staking_balances(asset_id, mode: :default, options: {})
56
- context_model = Coinbase.call_api do
57
- stake_api.get_staking_context(
58
- {
59
- asset_id: asset_id,
60
- network_id: Coinbase.normalize_network(network_id),
61
- address_id: id,
62
- options: {
63
- mode: mode
64
- }.merge(options)
65
- }
66
- )
67
- end.context
68
-
69
- {
70
- stakeable_balance: Coinbase::Balance.from_model_and_asset_id(
71
- context_model.stakeable_balance,
72
- asset_id
73
- ).amount,
74
- unstakeable_balance: Coinbase::Balance.from_model_and_asset_id(
75
- context_model.unstakeable_balance,
76
- asset_id
77
- ).amount,
78
- claimable_balance: Coinbase::Balance.from_model_and_asset_id(
79
- context_model.claimable_balance,
80
- asset_id
81
- ).amount
82
- }
83
- end
84
-
85
- # Retrieves the stakeable balance for the supplied asset.
86
- # @param asset_id [Symbol] The asset to retrieve the stakeable balance for
87
- # @param mode [Symbol] The staking mode. Defaults to :default.
88
- # @param options [Hash] Additional options for the staking operation
89
- # @return [BigDecimal] The stakeable balance
90
- def stakeable_balance(asset_id, mode: :default, options: {})
91
- staking_balances(asset_id, mode: mode, options: options)[:stakeable_balance]
92
- end
93
-
94
- # Retrieves the unstakeable balance for the supplied asset.
95
- # @param asset_id [Symbol] The asset to retrieve the unstakeable balance for
96
- # @param mode [Symbol] The staking mode. Defaults to :default.
97
- # @param options [Hash] Additional options for the staking operation
98
- # @return [BigDecimal] The unstakeable balance
99
- def unstakeable_balance(asset_id, mode: :default, options: {})
100
- staking_balances(asset_id, mode: mode, options: options)[:unstakeable_balance]
101
- end
102
-
103
- # Retrieves the claimable balance for the supplied asset.
104
- # @param asset_id [Symbol] The asset to retrieve the claimable balance for
105
- # @param mode [Symbol] The staking mode. Defaults to :default.
106
- # @param options [Hash] Additional options for the staking operation
107
- # @return [BigDecimal] The claimable balance
108
- def claimable_balance(asset_id, mode: :default, options: {})
109
- staking_balances(asset_id, mode: mode, options: options)[:claimable_balance]
110
- end
111
-
112
- # Lists the staking rewards for the address.
113
- # @param asset_id [Symbol] The asset to retrieve staking rewards for
114
- # @param start_time [Time] The start time for the rewards. Defaults to 1 month ago.
115
- # @param end_time [Time] The end time for the rewards. Defaults to the current time.
116
- # @param format [Symbol] The format to return the rewards in. Defaults to :usd.
117
- # @return [Enumerable<Coinbase::StakingReward>] The staking rewards
118
- def staking_rewards(asset_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd)
119
- StakingReward.list(
120
- network_id,
121
- asset_id,
122
- [id],
123
- start_time: start_time,
124
- end_time: end_time,
125
- format: format
126
- )
127
- end
128
-
129
- private
130
-
131
- def validate_can_stake!(amount, asset_id, mode, options)
132
- stakeable_balance = stakeable_balance(asset_id, mode: mode, options: options)
133
-
134
- raise InsufficientFundsError.new(amount, stakeable_balance) unless stakeable_balance >= amount
135
- end
136
-
137
- def validate_can_unstake!(amount, asset_id, mode, options)
138
- unstakeable_balance = unstakeable_balance(asset_id, mode: mode, options: options)
139
-
140
- raise InsufficientFundsError.new(amount, unstakeable_balance) unless unstakeable_balance >= amount
141
- end
142
-
143
- def validate_can_claim_stake!(amount, asset_id, mode, options)
144
- claimable_balance = claimable_balance(asset_id, mode: mode, options: options)
145
-
146
- raise InsufficientFundsError.new(amount, claimable_balance) unless claimable_balance >= amount
147
- end
148
-
149
- def build_staking_operation(amount, asset_id, action, mode: :default, options: {})
150
- operation_model = Coinbase.call_api do
151
- asset = Coinbase::Asset.fetch(network_id, asset_id)
152
- stake_api.build_staking_operation(
153
- {
154
- asset_id: asset.primary_denomination.to_s,
155
- address_id: id,
156
- action: action,
157
- network_id: Coinbase.normalize_network(network_id),
158
- options: {
159
- amount: asset.to_atomic_amount(amount).to_i.to_s,
160
- mode: mode
161
- }.merge(options)
162
- }
163
- )
164
- end
165
-
166
- StakingOperation.new(operation_model)
167
- end
168
-
169
- def stake_api
170
- @stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
171
- end
172
- end
9
+ class ExternalAddress < Address; end
173
10
  end
@@ -92,6 +92,42 @@ module Coinbase
92
92
  trade
93
93
  end
94
94
 
95
+ # Stakes the given amount of the given Asset
96
+ # @param amount [Integer, Float, BigDecimal] The amount of the Asset to stake.
97
+ # @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
98
+ # @param mode [Symbol] The staking mode. Defaults to :default.
99
+ # @param options [Hash] Additional options for the stake operation
100
+ # @return [Coinbase::StakingOperation] The staking operation
101
+ def stake(amount, asset_id, mode: :default, options: {})
102
+ validate_can_perform_staking_action!(amount, asset_id, 'stakeable_balance', mode, options)
103
+
104
+ complete_staking_operation(amount, asset_id, 'stake', mode: mode, options: options)
105
+ end
106
+
107
+ # Unstakes the given amount of the given Asset
108
+ # @param amount [Integer, Float, BigDecimal] The amount of the Asset to unstake.
109
+ # @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
110
+ # @param mode [Symbol] The staking mode. Defaults to :default.
111
+ # @param options [Hash] Additional options for the stake operation
112
+ # @return [Coinbase::StakingOperation] The staking operation
113
+ def unstake(amount, asset_id, mode: :default, options: {})
114
+ validate_can_perform_staking_action!(amount, asset_id, 'unstakeable_balance', mode, options)
115
+
116
+ complete_staking_operation(amount, asset_id, 'unstake', mode: mode, options: options)
117
+ end
118
+
119
+ # Claims the given amount of the given Asset
120
+ # @param amount [Integer, Float, BigDecimal] The amount of the Asset to claim.
121
+ # @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
122
+ # @param mode [Symbol] The staking mode. Defaults to :default.
123
+ # @param options [Hash] Additional options for the stake operation
124
+ # @return [Coinbase::StakingOperation] The staking operation
125
+ def claim_stake(amount, asset_id, mode: :default, options: {})
126
+ validate_can_perform_staking_action!(amount, asset_id, 'claimable_balance', mode, options)
127
+
128
+ complete_staking_operation(amount, asset_id, 'claim_stake', mode: mode, options: options)
129
+ end
130
+
95
131
  # Returns whether the Address has a private key backing it to sign transactions.
96
132
  # @return [Boolean] Whether the Address has a private key backing it to sign transactions.
97
133
  def can_sign?
@@ -144,5 +180,13 @@ module Coinbase
144
180
 
145
181
  raise InsufficientFundsError.new(amount, current_balance)
146
182
  end
183
+
184
+ def complete_staking_operation(amount, asset_id, action, mode: :default, options: {})
185
+ op = StakingOperation.create(amount, network_id, asset_id, id, wallet_id, action, mode, options)
186
+ op.transactions.each do |transaction|
187
+ transaction.sign(@key)
188
+ end
189
+ op.broadcast!
190
+ end
147
191
  end
148
192
  end
@@ -75,10 +75,138 @@ module Coinbase
75
75
  end
76
76
  end
77
77
 
78
+ # Builds a stake operation for the supplied asset. The stake operation
79
+ # may take a few minutes to complete in the case when infrastructure is spun up.
80
+ # @param amount [Integer,String,BigDecimal] The amount of the asset to stake
81
+ # @param asset_id [Symbol] The asset to stake
82
+ # @param mode [Symbol] The staking mode. Defaults to :default.
83
+ # @param options [Hash] Additional options for the stake operation
84
+ # @return [Coinbase::StakingOperation] The stake operation
85
+ def build_stake_operation(amount, asset_id, mode: :default, options: {})
86
+ validate_can_perform_staking_action!(amount, asset_id, 'stakeable_balance', mode, options)
87
+
88
+ StakingOperation.build(amount, network_id, asset_id, id, 'stake', mode, options)
89
+ end
90
+
91
+ # Builds an unstake operation for the supplied asset.
92
+ # @param amount [Integer,String,BigDecimal] The amount of the asset to unstake
93
+ # @param asset_id [Symbol] The asset to unstake
94
+ # @param mode [Symbol] The staking mode. Defaults to :default.
95
+ # @param options [Hash] Additional options for the unstake operation
96
+ # @return [Coinbase::StakingOperation] The unstake operation
97
+ def build_unstake_operation(amount, asset_id, mode: :default, options: {})
98
+ validate_can_perform_staking_action!(amount, asset_id, 'unstakeable_balance', mode, options)
99
+
100
+ StakingOperation.build(amount, network_id, asset_id, id, 'unstake', mode, options)
101
+ end
102
+
103
+ # Builds a claim_stake operation for the supplied asset.
104
+ # @param amount [Integer,String,BigDecimal] The amount of the asset to claim
105
+ # @param asset_id [Symbol] The asset to claim
106
+ # @param mode [Symbol] The staking mode. Defaults to :default.
107
+ # @param options [Hash] Additional options for the claim_stake operation
108
+ # @return [Coinbase::StakingOperation] The claim_stake operation
109
+ def build_claim_stake_operation(amount, asset_id, mode: :default, options: {})
110
+ validate_can_perform_staking_action!(amount, asset_id, 'claimable_balance', mode, options)
111
+
112
+ StakingOperation.build(amount, network_id, asset_id, id, 'claim_stake', mode, options)
113
+ end
114
+
115
+ # Retrieves the balances used for staking for the supplied asset.
116
+ # @param asset_id [Symbol] The asset to retrieve staking balances for
117
+ # @param mode [Symbol] The staking mode. Defaults to :default.
118
+ # @param options [Hash] Additional options for the staking operation
119
+ # @return [Hash] The staking balances
120
+ # @return [BigDecimal] :stakeable_balance The amount of the asset that can be staked
121
+ # @return [BigDecimal] :unstakeable_balance The amount of the asset that is currently staked and cannot be unstaked
122
+ # @return [BigDecimal] :claimable_balance The amount of the asset that can be claimed
123
+ def staking_balances(asset_id, mode: :default, options: {})
124
+ context_model = Coinbase.call_api do
125
+ stake_api.get_staking_context(
126
+ {
127
+ asset_id: asset_id,
128
+ network_id: Coinbase.normalize_network(network_id),
129
+ address_id: id,
130
+ options: {
131
+ mode: mode
132
+ }.merge(options)
133
+ }
134
+ )
135
+ end.context
136
+
137
+ {
138
+ stakeable_balance: Coinbase::Balance.from_model_and_asset_id(
139
+ context_model.stakeable_balance,
140
+ asset_id
141
+ ).amount,
142
+ unstakeable_balance: Coinbase::Balance.from_model_and_asset_id(
143
+ context_model.unstakeable_balance,
144
+ asset_id
145
+ ).amount,
146
+ claimable_balance: Coinbase::Balance.from_model_and_asset_id(
147
+ context_model.claimable_balance,
148
+ asset_id
149
+ ).amount
150
+ }
151
+ end
152
+
153
+ # Retrieves the stakeable balance for the supplied asset.
154
+ # @param asset_id [Symbol] The asset to retrieve the stakeable balance for
155
+ # @param mode [Symbol] The staking mode. Defaults to :default.
156
+ # @param options [Hash] Additional options for the staking operation
157
+ # @return [BigDecimal] The stakeable balance
158
+ def stakeable_balance(asset_id, mode: :default, options: {})
159
+ staking_balances(asset_id, mode: mode, options: options)[:stakeable_balance]
160
+ end
161
+
162
+ # Retrieves the unstakeable balance for the supplied asset.
163
+ # @param asset_id [Symbol] The asset to retrieve the unstakeable balance for
164
+ # @param mode [Symbol] The staking mode. Defaults to :default.
165
+ # @param options [Hash] Additional options for the staking operation
166
+ # @return [BigDecimal] The unstakeable balance
167
+ def unstakeable_balance(asset_id, mode: :default, options: {})
168
+ staking_balances(asset_id, mode: mode, options: options)[:unstakeable_balance]
169
+ end
170
+
171
+ # Retrieves the claimable balance for the supplied asset.
172
+ # @param asset_id [Symbol] The asset to retrieve the claimable balance for
173
+ # @param mode [Symbol] The staking mode. Defaults to :default.
174
+ # @param options [Hash] Additional options for the staking operation
175
+ # @return [BigDecimal] The claimable balance
176
+ def claimable_balance(asset_id, mode: :default, options: {})
177
+ staking_balances(asset_id, mode: mode, options: options)[:claimable_balance]
178
+ end
179
+
180
+ # Lists the staking rewards for the address.
181
+ # @param asset_id [Symbol] The asset to retrieve staking rewards for
182
+ # @param start_time [Time] The start time for the rewards. Defaults to 1 week ago.
183
+ # @param end_time [Time] The end time for the rewards. Defaults to the current time.
184
+ # @param format [Symbol] The format to return the rewards in. Defaults to :usd.
185
+ # @return [Enumerable<Coinbase::StakingReward>] The staking rewards
186
+ def staking_rewards(asset_id, start_time: DateTime.now.prev_week(1), end_time: DateTime.now, format: :usd)
187
+ StakingReward.list(
188
+ network_id,
189
+ asset_id,
190
+ [id],
191
+ start_time: start_time,
192
+ end_time: end_time,
193
+ format: format
194
+ )
195
+ end
196
+
78
197
  private
79
198
 
199
+ def validate_can_perform_staking_action!(amount, asset_id, balance_type, mode, options)
200
+ current_staking_balance = staking_balances(asset_id, mode: mode, options: options)[balance_type.to_sym]
201
+ raise InsufficientFundsError.new(amount, current_staking_balance) unless current_staking_balance >= amount
202
+ end
203
+
80
204
  def addresses_api
81
205
  @addresses_api ||= Coinbase::Client::ExternalAddressesApi.new(Coinbase.configuration.api_client)
82
206
  end
207
+
208
+ def stake_api
209
+ @stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
210
+ end
83
211
  end
84
212
  end
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
7
  Contact: yuga.cohler@coinbase.com
8
8
  Generated by: https://openapi-generator.tech
9
- Generator version: 7.6.0
9
+ Generator version: 7.7.0
10
10
 
11
11
  =end
12
12
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
7
  Contact: yuga.cohler@coinbase.com
8
8
  Generated by: https://openapi-generator.tech
9
- Generator version: 7.6.0
9
+ Generator version: 7.7.0
10
10
 
11
11
  =end
12
12
 
@@ -22,7 +22,7 @@ module Coinbase::Client
22
22
  # Get the asset for the specified asset ID.
23
23
  # Get the asset for the specified asset ID.
24
24
  # @param network_id [String] The ID of the blockchain network
25
- # @param asset_id [String] The ID of the asset to fetch
25
+ # @param asset_id [String] The ID of the asset to fetch. This could be a symbol or an ERC20 contract address.
26
26
  # @param [Hash] opts the optional parameters
27
27
  # @return [Asset]
28
28
  def get_asset(network_id, asset_id, opts = {})
@@ -33,7 +33,7 @@ module Coinbase::Client
33
33
  # Get the asset for the specified asset ID.
34
34
  # Get the asset for the specified asset ID.
35
35
  # @param network_id [String] The ID of the blockchain network
36
- # @param asset_id [String] The ID of the asset to fetch
36
+ # @param asset_id [String] The ID of the asset to fetch. This could be a symbol or an ERC20 contract address.
37
37
  # @param [Hash] opts the optional parameters
38
38
  # @return [Array<(Asset, Integer, Hash)>] Asset data, response status code and response headers
39
39
  def get_asset_with_http_info(network_id, asset_id, opts = {})
@@ -0,0 +1,121 @@
1
+ =begin
2
+ #Coinbase Platform API
3
+
4
+ #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
+
6
+ The version of the OpenAPI document: 0.0.1-alpha
7
+ Contact: yuga.cohler@coinbase.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Coinbase::Client
16
+ class ContractEventsApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Get contract events
23
+ # Retrieve events for a specific contract
24
+ # @param network_id [String] Unique identifier for the blockchain network
25
+ # @param protocol_name [String] Case-sensitive name of the blockchain protocol
26
+ # @param contract_address [String] EVM address of the smart contract (42 characters, including &#39;0x&#39;, in lowercase)
27
+ # @param from_block_height [Integer] Lower bound of the block range to query (inclusive)
28
+ # @param to_block_height [Integer] Upper bound of the block range to query (inclusive)
29
+ # @param [Hash] opts the optional parameters
30
+ # @option opts [String] :contract_name Case-sensitive name of the specific contract within the project
31
+ # @option opts [String] :event_name Case-sensitive name of the event to filter for in the contract&#39;s logs
32
+ # @option opts [String] :next_page Pagination token for retrieving the next set of results
33
+ # @return [ContractEventList]
34
+ def list_contract_events(network_id, protocol_name, contract_address, from_block_height, to_block_height, opts = {})
35
+ data, _status_code, _headers = list_contract_events_with_http_info(network_id, protocol_name, contract_address, from_block_height, to_block_height, opts)
36
+ data
37
+ end
38
+
39
+ # Get contract events
40
+ # Retrieve events for a specific contract
41
+ # @param network_id [String] Unique identifier for the blockchain network
42
+ # @param protocol_name [String] Case-sensitive name of the blockchain protocol
43
+ # @param contract_address [String] EVM address of the smart contract (42 characters, including &#39;0x&#39;, in lowercase)
44
+ # @param from_block_height [Integer] Lower bound of the block range to query (inclusive)
45
+ # @param to_block_height [Integer] Upper bound of the block range to query (inclusive)
46
+ # @param [Hash] opts the optional parameters
47
+ # @option opts [String] :contract_name Case-sensitive name of the specific contract within the project
48
+ # @option opts [String] :event_name Case-sensitive name of the event to filter for in the contract&#39;s logs
49
+ # @option opts [String] :next_page Pagination token for retrieving the next set of results
50
+ # @return [Array<(ContractEventList, Integer, Hash)>] ContractEventList data, response status code and response headers
51
+ def list_contract_events_with_http_info(network_id, protocol_name, contract_address, from_block_height, to_block_height, opts = {})
52
+ if @api_client.config.debugging
53
+ @api_client.config.logger.debug 'Calling API: ContractEventsApi.list_contract_events ...'
54
+ end
55
+ # verify the required parameter 'network_id' is set
56
+ if @api_client.config.client_side_validation && network_id.nil?
57
+ fail ArgumentError, "Missing the required parameter 'network_id' when calling ContractEventsApi.list_contract_events"
58
+ end
59
+ # verify the required parameter 'protocol_name' is set
60
+ if @api_client.config.client_side_validation && protocol_name.nil?
61
+ fail ArgumentError, "Missing the required parameter 'protocol_name' when calling ContractEventsApi.list_contract_events"
62
+ end
63
+ # verify the required parameter 'contract_address' is set
64
+ if @api_client.config.client_side_validation && contract_address.nil?
65
+ fail ArgumentError, "Missing the required parameter 'contract_address' when calling ContractEventsApi.list_contract_events"
66
+ end
67
+ # verify the required parameter 'from_block_height' is set
68
+ if @api_client.config.client_side_validation && from_block_height.nil?
69
+ fail ArgumentError, "Missing the required parameter 'from_block_height' when calling ContractEventsApi.list_contract_events"
70
+ end
71
+ # verify the required parameter 'to_block_height' is set
72
+ if @api_client.config.client_side_validation && to_block_height.nil?
73
+ fail ArgumentError, "Missing the required parameter 'to_block_height' when calling ContractEventsApi.list_contract_events"
74
+ end
75
+ # resource path
76
+ local_var_path = '/v1/networks/{network_id}/smart_contracts/{contract_address}/events'.sub('{' + 'network_id' + '}', CGI.escape(network_id.to_s)).sub('{' + 'contract_address' + '}', CGI.escape(contract_address.to_s))
77
+
78
+ # query parameters
79
+ query_params = opts[:query_params] || {}
80
+ query_params[:'protocol_name'] = protocol_name
81
+ query_params[:'from_block_height'] = from_block_height
82
+ query_params[:'to_block_height'] = to_block_height
83
+ query_params[:'contract_name'] = opts[:'contract_name'] if !opts[:'contract_name'].nil?
84
+ query_params[:'event_name'] = opts[:'event_name'] if !opts[:'event_name'].nil?
85
+ query_params[:'next_page'] = opts[:'next_page'] if !opts[:'next_page'].nil?
86
+
87
+ # header parameters
88
+ header_params = opts[:header_params] || {}
89
+ # HTTP header 'Accept' (if needed)
90
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
91
+
92
+ # form parameters
93
+ form_params = opts[:form_params] || {}
94
+
95
+ # http body (model)
96
+ post_body = opts[:debug_body]
97
+
98
+ # return_type
99
+ return_type = opts[:debug_return_type] || 'ContractEventList'
100
+
101
+ # auth_names
102
+ auth_names = opts[:debug_auth_names] || []
103
+
104
+ new_options = opts.merge(
105
+ :operation => :"ContractEventsApi.list_contract_events",
106
+ :header_params => header_params,
107
+ :query_params => query_params,
108
+ :form_params => form_params,
109
+ :body => post_body,
110
+ :auth_names => auth_names,
111
+ :return_type => return_type
112
+ )
113
+
114
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
115
+ if @api_client.config.debugging
116
+ @api_client.config.logger.debug "API called: ContractEventsApi#list_contract_events\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
117
+ end
118
+ return data, status_code, headers
119
+ end
120
+ end
121
+ end
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
7
  Contact: yuga.cohler@coinbase.com
8
8
  Generated by: https://openapi-generator.tech
9
- Generator version: 7.6.0
9
+ Generator version: 7.7.0
10
10
 
11
11
  =end
12
12
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 0.0.1-alpha
7
7
  Contact: yuga.cohler@coinbase.com
8
8
  Generated by: https://openapi-generator.tech
9
- Generator version: 7.6.0
9
+ Generator version: 7.7.0
10
10
 
11
11
  =end
12
12