coinbase-sdk 0.0.13 → 0.0.16
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/external_address.rb +3 -166
- data/lib/coinbase/address/wallet_address.rb +51 -4
- data/lib/coinbase/address.rb +164 -0
- data/lib/coinbase/client/api/assets_api.rb +2 -2
- data/lib/coinbase/client/api/contract_events_api.rb +121 -0
- data/lib/coinbase/client/api/external_addresses_api.rb +85 -0
- data/lib/coinbase/client/api/networks_api.rb +85 -0
- data/lib/coinbase/client/api/stake_api.rb +361 -0
- data/lib/coinbase/client/api/webhooks_api.rb +286 -0
- data/lib/coinbase/client/models/address_historical_balance_list.rb +258 -0
- data/lib/coinbase/client/models/broadcast_staking_operation_request.rb +239 -0
- data/lib/coinbase/client/models/contract_event.rb +336 -0
- data/lib/coinbase/client/models/contract_event_list.rb +259 -0
- data/lib/coinbase/client/models/create_staking_operation_request.rb +274 -0
- data/lib/coinbase/client/models/create_transfer_request.rb +14 -4
- data/lib/coinbase/client/models/create_webhook_request.rb +282 -0
- data/lib/coinbase/client/models/ethereum_validator.rb +374 -0
- data/lib/coinbase/client/models/feature_set.rb +307 -0
- data/lib/coinbase/client/models/fetch_historical_staking_balances200_response.rb +258 -0
- data/lib/coinbase/client/models/get_validator200_response.rb +221 -0
- data/lib/coinbase/client/models/get_validator200_response_validator.rb +214 -0
- data/lib/coinbase/client/models/historical_balance.rb +273 -0
- data/lib/coinbase/client/models/network.rb +355 -0
- data/lib/coinbase/client/models/network_identifier.rb +44 -0
- data/lib/coinbase/client/models/sponsored_send.rb +338 -0
- data/lib/coinbase/client/models/staking_balance.rb +289 -0
- data/lib/coinbase/client/models/staking_context_context.rb +222 -74
- data/lib/coinbase/client/models/staking_operation.rb +15 -5
- data/lib/coinbase/client/models/staking_reward.rb +22 -6
- data/lib/coinbase/client/models/staking_reward_format.rb +2 -1
- data/lib/coinbase/client/models/staking_reward_usd_value.rb +257 -0
- data/lib/coinbase/client/models/transaction.rb +2 -2
- data/lib/coinbase/client/models/transaction_type.rb +2 -1
- data/lib/coinbase/client/models/transfer.rb +29 -24
- data/lib/coinbase/client/models/update_webhook_request.rb +289 -0
- data/lib/coinbase/client/models/validator_list_data.rb +216 -0
- data/lib/coinbase/client/models/wallet.rb +13 -16
- data/lib/coinbase/client/models/webhook.rb +299 -0
- data/lib/coinbase/client/models/webhook_event_filter.rb +236 -0
- data/lib/coinbase/client/models/webhook_event_type.rb +42 -0
- data/lib/coinbase/client/models/webhook_list.rb +244 -0
- data/lib/coinbase/client.rb +22 -3
- data/lib/coinbase/errors.rb +7 -0
- data/lib/coinbase/historical_balance.rb +53 -0
- data/lib/coinbase/middleware.rb +12 -0
- data/lib/coinbase/server_signer.rb +14 -3
- data/lib/coinbase/sponsored_send.rb +110 -0
- data/lib/coinbase/staking_balance.rb +86 -0
- data/lib/coinbase/staking_operation.rb +106 -5
- data/lib/coinbase/staking_reward.rb +18 -0
- data/lib/coinbase/trade.rb +1 -1
- data/lib/coinbase/transaction.rb +7 -3
- data/lib/coinbase/transfer.rb +56 -29
- data/lib/coinbase/wallet/data.rb +31 -0
- data/lib/coinbase/wallet.rb +91 -46
- data/lib/coinbase.rb +17 -4
- metadata +74 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: addb2d81db155719e42cf1c4057498fc8094fcf436e3a67276870b3ff77a2d69
|
4
|
+
data.tar.gz: 6e1a0078557be2d0fe83979c66ec9415e77edbef0b6f72ef510d69aaf7580041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22648511bb07f598908f4b81fc87a8d06279e122b809d21a294e38b48cd54c65490a7c5009ebf6e013baffd8de7fba174017dbe6f75777e489646d9b735c885a
|
7
|
+
data.tar.gz: 623ecc923feb473a6a491ae07a536216ac5bf7f5648bf6e9eab8eca956ce88232973d98a376c67a61f71fade05587ba6e07300f7766d7ba3436397fce55ea994
|
@@ -3,171 +3,8 @@
|
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
module Coinbase
|
6
|
-
# A representation of a blockchain Address that
|
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
|
@@ -39,8 +39,11 @@ module Coinbase
|
|
39
39
|
# @param asset_id [Symbol] The ID of the Asset to send. For Ether, :eth, :gwei, and :wei are supported.
|
40
40
|
# @param destination [Wallet | Address | String] The destination of the transfer. If a Wallet, sends to the Wallet's
|
41
41
|
# default address. If a String, interprets it as the address ID.
|
42
|
+
# @param gasless [Boolean] Whether gas fee for the transfer should be covered by Coinbase.
|
43
|
+
# Defaults to false. Check the API documentation for network and asset support.
|
44
|
+
# Whether the transfer should be gasless. Defaults to false.
|
42
45
|
# @return [Coinbase::Transfer] The Transfer object.
|
43
|
-
def transfer(amount, asset_id, destination)
|
46
|
+
def transfer(amount, asset_id, destination, gasless: false)
|
44
47
|
ensure_can_sign!
|
45
48
|
ensure_sufficient_balance!(amount, asset_id)
|
46
49
|
|
@@ -50,14 +53,14 @@ module Coinbase
|
|
50
53
|
asset_id: asset_id,
|
51
54
|
destination: destination,
|
52
55
|
network_id: network_id,
|
53
|
-
wallet_id: wallet_id
|
56
|
+
wallet_id: wallet_id,
|
57
|
+
gasless: gasless
|
54
58
|
)
|
55
59
|
|
56
60
|
# If a server signer is managing keys, it will sign and broadcast the underlying transfer transaction out of band.
|
57
61
|
return transfer if Coinbase.use_server_signer?
|
58
62
|
|
59
|
-
transfer.
|
60
|
-
|
63
|
+
transfer.sign(@key)
|
61
64
|
transfer.broadcast!
|
62
65
|
transfer
|
63
66
|
end
|
@@ -92,6 +95,42 @@ module Coinbase
|
|
92
95
|
trade
|
93
96
|
end
|
94
97
|
|
98
|
+
# Stakes the given amount of the given Asset
|
99
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to stake.
|
100
|
+
# @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
|
101
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
102
|
+
# @param options [Hash] Additional options for the stake operation
|
103
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
104
|
+
def stake(amount, asset_id, mode: :default, options: {})
|
105
|
+
validate_can_perform_staking_action!(amount, asset_id, 'stakeable_balance', mode, options)
|
106
|
+
|
107
|
+
complete_staking_operation(amount, asset_id, 'stake', mode: mode, options: options)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Unstakes the given amount of the given Asset
|
111
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to unstake.
|
112
|
+
# @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
|
113
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
114
|
+
# @param options [Hash] Additional options for the stake operation
|
115
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
116
|
+
def unstake(amount, asset_id, mode: :default, options: {})
|
117
|
+
validate_can_perform_staking_action!(amount, asset_id, 'unstakeable_balance', mode, options)
|
118
|
+
|
119
|
+
complete_staking_operation(amount, asset_id, 'unstake', mode: mode, options: options)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Claims the given amount of the given Asset
|
123
|
+
# @param amount [Integer, Float, BigDecimal] The amount of the Asset to claim.
|
124
|
+
# @param asset_id [Symbol] The ID of the Asset to stake. For Ether, :eth, :gwei, and :wei are supported.
|
125
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
126
|
+
# @param options [Hash] Additional options for the stake operation
|
127
|
+
# @return [Coinbase::StakingOperation] The staking operation
|
128
|
+
def claim_stake(amount, asset_id, mode: :default, options: {})
|
129
|
+
validate_can_perform_staking_action!(amount, asset_id, 'claimable_balance', mode, options)
|
130
|
+
|
131
|
+
complete_staking_operation(amount, asset_id, 'claim_stake', mode: mode, options: options)
|
132
|
+
end
|
133
|
+
|
95
134
|
# Returns whether the Address has a private key backing it to sign transactions.
|
96
135
|
# @return [Boolean] Whether the Address has a private key backing it to sign transactions.
|
97
136
|
def can_sign?
|
@@ -144,5 +183,13 @@ module Coinbase
|
|
144
183
|
|
145
184
|
raise InsufficientFundsError.new(amount, current_balance)
|
146
185
|
end
|
186
|
+
|
187
|
+
def complete_staking_operation(amount, asset_id, action, mode: :default, options: {})
|
188
|
+
op = StakingOperation.create(amount, network_id, asset_id, id, wallet_id, action, mode, options)
|
189
|
+
op.transactions.each do |transaction|
|
190
|
+
transaction.sign(@key)
|
191
|
+
end
|
192
|
+
op.broadcast!
|
193
|
+
end
|
147
194
|
end
|
148
195
|
end
|
data/lib/coinbase/address.rb
CHANGED
@@ -62,6 +62,18 @@ module Coinbase
|
|
62
62
|
Coinbase::Balance.from_model_and_asset_id(response, asset_id).amount
|
63
63
|
end
|
64
64
|
|
65
|
+
# Enumerates the historical balances for a given asset belonging of address.
|
66
|
+
# The result is an enumerator that lazily fetches from the server, and can be iterated over,
|
67
|
+
# converted to an array, etc...
|
68
|
+
# @return [Enumerable<Coinbase::HistoricalBalance>] Enumerator that returns historical_balance
|
69
|
+
def historical_balances(asset_id)
|
70
|
+
Coinbase::Pagination.enumerate(
|
71
|
+
->(page) { list_page(asset_id, page) }
|
72
|
+
) do |historical_balance|
|
73
|
+
Coinbase::HistoricalBalance.from_model(historical_balance)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
# Requests funds for the address from the faucet and returns the faucet transaction.
|
66
78
|
# This is only supported on testnet networks.
|
67
79
|
# @return [Coinbase::FaucetTransaction] The successful faucet transaction
|
@@ -75,10 +87,162 @@ module Coinbase
|
|
75
87
|
end
|
76
88
|
end
|
77
89
|
|
90
|
+
# Builds a stake operation for the supplied asset. The stake operation
|
91
|
+
# may take a few minutes to complete in the case when infrastructure is spun up.
|
92
|
+
# @param amount [Integer,String,BigDecimal] The amount of the asset to stake
|
93
|
+
# @param asset_id [Symbol] The asset to stake
|
94
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
95
|
+
# @param options [Hash] Additional options for the stake operation
|
96
|
+
# @return [Coinbase::StakingOperation] The stake operation
|
97
|
+
def build_stake_operation(amount, asset_id, mode: :default, options: {})
|
98
|
+
validate_can_perform_staking_action!(amount, asset_id, 'stakeable_balance', mode, options)
|
99
|
+
|
100
|
+
StakingOperation.build(amount, network_id, asset_id, id, 'stake', mode, options)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Builds an unstake operation for the supplied asset.
|
104
|
+
# @param amount [Integer,String,BigDecimal] The amount of the asset to unstake
|
105
|
+
# @param asset_id [Symbol] The asset to unstake
|
106
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
107
|
+
# @param options [Hash] Additional options for the unstake operation
|
108
|
+
# @return [Coinbase::StakingOperation] The unstake operation
|
109
|
+
def build_unstake_operation(amount, asset_id, mode: :default, options: {})
|
110
|
+
validate_can_perform_staking_action!(amount, asset_id, 'unstakeable_balance', mode, options)
|
111
|
+
|
112
|
+
StakingOperation.build(amount, network_id, asset_id, id, 'unstake', mode, options)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Builds a claim_stake operation for the supplied asset.
|
116
|
+
# @param amount [Integer,String,BigDecimal] The amount of the asset to claim
|
117
|
+
# @param asset_id [Symbol] The asset to claim
|
118
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
119
|
+
# @param options [Hash] Additional options for the claim_stake operation
|
120
|
+
# @return [Coinbase::StakingOperation] The claim_stake operation
|
121
|
+
def build_claim_stake_operation(amount, asset_id, mode: :default, options: {})
|
122
|
+
validate_can_perform_staking_action!(amount, asset_id, 'claimable_balance', mode, options)
|
123
|
+
|
124
|
+
StakingOperation.build(amount, network_id, asset_id, id, 'claim_stake', mode, options)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Retrieves the balances used for staking for the supplied asset.
|
128
|
+
# @param asset_id [Symbol] The asset to retrieve staking balances for
|
129
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
130
|
+
# @param options [Hash] Additional options for the staking operation
|
131
|
+
# @return [Hash] The staking balances
|
132
|
+
# @return [BigDecimal] :stakeable_balance The amount of the asset that can be staked
|
133
|
+
# @return [BigDecimal] :unstakeable_balance The amount of the asset that is currently staked and cannot be unstaked
|
134
|
+
# @return [BigDecimal] :claimable_balance The amount of the asset that can be claimed
|
135
|
+
def staking_balances(asset_id, mode: :default, options: {})
|
136
|
+
context_model = Coinbase.call_api do
|
137
|
+
stake_api.get_staking_context(
|
138
|
+
{
|
139
|
+
asset_id: asset_id,
|
140
|
+
network_id: Coinbase.normalize_network(network_id),
|
141
|
+
address_id: id,
|
142
|
+
options: {
|
143
|
+
mode: mode
|
144
|
+
}.merge(options)
|
145
|
+
}
|
146
|
+
)
|
147
|
+
end.context
|
148
|
+
|
149
|
+
{
|
150
|
+
stakeable_balance: Coinbase::Balance.from_model_and_asset_id(
|
151
|
+
context_model.stakeable_balance,
|
152
|
+
asset_id
|
153
|
+
).amount,
|
154
|
+
unstakeable_balance: Coinbase::Balance.from_model_and_asset_id(
|
155
|
+
context_model.unstakeable_balance,
|
156
|
+
asset_id
|
157
|
+
).amount,
|
158
|
+
claimable_balance: Coinbase::Balance.from_model_and_asset_id(
|
159
|
+
context_model.claimable_balance,
|
160
|
+
asset_id
|
161
|
+
).amount
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
# Retrieves the stakeable balance for the supplied asset.
|
166
|
+
# @param asset_id [Symbol] The asset to retrieve the stakeable balance for
|
167
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
168
|
+
# @param options [Hash] Additional options for the staking operation
|
169
|
+
# @return [BigDecimal] The stakeable balance
|
170
|
+
def stakeable_balance(asset_id, mode: :default, options: {})
|
171
|
+
staking_balances(asset_id, mode: mode, options: options)[:stakeable_balance]
|
172
|
+
end
|
173
|
+
|
174
|
+
# Retrieves the unstakeable balance for the supplied asset.
|
175
|
+
# @param asset_id [Symbol] The asset to retrieve the unstakeable balance for
|
176
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
177
|
+
# @param options [Hash] Additional options for the staking operation
|
178
|
+
# @return [BigDecimal] The unstakeable balance
|
179
|
+
def unstakeable_balance(asset_id, mode: :default, options: {})
|
180
|
+
staking_balances(asset_id, mode: mode, options: options)[:unstakeable_balance]
|
181
|
+
end
|
182
|
+
|
183
|
+
# Retrieves the claimable balance for the supplied asset.
|
184
|
+
# @param asset_id [Symbol] The asset to retrieve the claimable balance for
|
185
|
+
# @param mode [Symbol] The staking mode. Defaults to :default.
|
186
|
+
# @param options [Hash] Additional options for the staking operation
|
187
|
+
# @return [BigDecimal] The claimable balance
|
188
|
+
def claimable_balance(asset_id, mode: :default, options: {})
|
189
|
+
staking_balances(asset_id, mode: mode, options: options)[:claimable_balance]
|
190
|
+
end
|
191
|
+
|
192
|
+
# Lists the staking rewards for the address.
|
193
|
+
# @param asset_id [Symbol] The asset to retrieve staking rewards for
|
194
|
+
# @param start_time [Time] The start time for the rewards. Defaults to 1 week ago.
|
195
|
+
# @param end_time [Time] The end time for the rewards. Defaults to the current time.
|
196
|
+
# @param format [Symbol] The format to return the rewards in. Defaults to :usd.
|
197
|
+
# @return [Enumerable<Coinbase::StakingReward>] The staking rewards
|
198
|
+
def staking_rewards(asset_id, start_time: DateTime.now.prev_week(1), end_time: DateTime.now, format: :usd)
|
199
|
+
StakingReward.list(
|
200
|
+
network_id,
|
201
|
+
asset_id,
|
202
|
+
[id],
|
203
|
+
start_time: start_time,
|
204
|
+
end_time: end_time,
|
205
|
+
format: format
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Fetches the historical staking balances for the address.
|
210
|
+
# @param asset_id [Symbol] The asset to retrieve staking rewards for
|
211
|
+
# @param start_time [Time] The start time for the rewards. Defaults to 1 week ago.
|
212
|
+
# @param end_time [Time] The end time for the rewards. Defaults to the current time.
|
213
|
+
# @return [Enumerable<Coinbase::StakingBalance>] The staking rewards
|
214
|
+
def historical_staking_balances(asset_id, start_time: DateTime.now.prev_week(1), end_time: DateTime.now)
|
215
|
+
StakingBalance.list(
|
216
|
+
network_id,
|
217
|
+
asset_id,
|
218
|
+
id,
|
219
|
+
start_time: start_time,
|
220
|
+
end_time: end_time
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
78
224
|
private
|
79
225
|
|
226
|
+
def validate_can_perform_staking_action!(amount, asset_id, balance_type, mode, options)
|
227
|
+
current_staking_balance = staking_balances(asset_id, mode: mode, options: options)[balance_type.to_sym]
|
228
|
+
raise InsufficientFundsError.new(amount, current_staking_balance) unless current_staking_balance >= amount
|
229
|
+
end
|
230
|
+
|
80
231
|
def addresses_api
|
81
232
|
@addresses_api ||= Coinbase::Client::ExternalAddressesApi.new(Coinbase.configuration.api_client)
|
82
233
|
end
|
234
|
+
|
235
|
+
def stake_api
|
236
|
+
@stake_api ||= Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client)
|
237
|
+
end
|
238
|
+
|
239
|
+
def list_page(asset_id, page)
|
240
|
+
addresses_api.list_address_historical_balance(
|
241
|
+
Coinbase.normalize_network(network_id),
|
242
|
+
id,
|
243
|
+
Coinbase::Asset.primary_denomination(asset_id).to_s,
|
244
|
+
{ limit: DEFAULT_PAGE_LIMIT, page: page }
|
245
|
+
)
|
246
|
+
end
|
83
247
|
end
|
84
248
|
end
|
@@ -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.6.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 '0x', 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'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 '0x', 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'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
|