coinbase 0.0.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of coinbase might be problematic. Click here for more details.

metadata CHANGED
@@ -1,205 +1,172 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.3.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
- - Yuga Cohler
8
+ - Brian Armstrong
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2024-04-19 00:00:00.000000000 Z
12
+ date: 2014-04-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: bigdecimal
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: dotenv
15
+ name: rspec
29
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
30
18
  requirements:
31
- - - '='
19
+ - - ~>
32
20
  - !ruby/object:Gem::Version
33
- version: 2.8.1
34
- type: :runtime
21
+ version: '2.12'
22
+ type: :development
35
23
  prerelease: false
36
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
37
26
  requirements:
38
- - - '='
27
+ - - ~>
39
28
  - !ruby/object:Gem::Version
40
- version: 2.8.1
29
+ version: '2.12'
41
30
  - !ruby/object:Gem::Dependency
42
- name: eth
31
+ name: fakeweb
43
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
44
34
  requirements:
45
- - - ">="
35
+ - - ~>
46
36
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
37
+ version: 1.3.0
38
+ type: :development
49
39
  prerelease: false
50
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
51
42
  requirements:
52
- - - ">="
43
+ - - ~>
53
44
  - !ruby/object:Gem::Version
54
- version: '0'
45
+ version: 1.3.0
55
46
  - !ruby/object:Gem::Dependency
56
- name: jimson
47
+ name: rake
57
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
58
50
  requirements:
59
- - - ">="
51
+ - - ! '>='
60
52
  - !ruby/object:Gem::Version
61
53
  version: '0'
62
- type: :runtime
54
+ type: :development
63
55
  prerelease: false
64
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
65
58
  requirements:
66
- - - ">="
59
+ - - ! '>='
67
60
  - !ruby/object:Gem::Version
68
61
  version: '0'
69
62
  - !ruby/object:Gem::Dependency
70
- name: money-tree
63
+ name: httparty
71
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
72
66
  requirements:
73
- - - ">="
67
+ - - ! '>='
74
68
  - !ruby/object:Gem::Version
75
- version: '0'
69
+ version: 0.8.3
76
70
  type: :runtime
77
71
  prerelease: false
78
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
79
74
  requirements:
80
- - - ">="
75
+ - - ! '>='
81
76
  - !ruby/object:Gem::Version
82
- version: '0'
77
+ version: 0.8.3
83
78
  - !ruby/object:Gem::Dependency
84
- name: securerandom
79
+ name: multi_json
85
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
86
82
  requirements:
87
- - - ">="
83
+ - - ! '>='
88
84
  - !ruby/object:Gem::Version
89
- version: '0'
85
+ version: 1.3.4
90
86
  type: :runtime
91
87
  prerelease: false
92
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
93
90
  requirements:
94
- - - ">="
91
+ - - ! '>='
95
92
  - !ruby/object:Gem::Version
96
- version: '0'
93
+ version: 1.3.4
97
94
  - !ruby/object:Gem::Dependency
98
- name: pry
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop
95
+ name: money
141
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
142
98
  requirements:
143
99
  - - '='
144
100
  - !ruby/object:Gem::Version
145
- version: 1.63.1
146
- type: :development
101
+ version: 5.1.1
102
+ type: :runtime
147
103
  prerelease: false
148
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
149
106
  requirements:
150
107
  - - '='
151
108
  - !ruby/object:Gem::Version
152
- version: 1.63.1
109
+ version: 5.1.1
153
110
  - !ruby/object:Gem::Dependency
154
- name: yard
111
+ name: hashie
155
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
156
114
  requirements:
157
- - - '='
115
+ - - ! '>='
158
116
  - !ruby/object:Gem::Version
159
- version: 0.9.36
160
- type: :development
117
+ version: 1.2.0
118
+ type: :runtime
161
119
  prerelease: false
162
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
163
122
  requirements:
164
- - - '='
123
+ - - ! '>='
165
124
  - !ruby/object:Gem::Version
166
- version: 0.9.36
167
- description: Coinbase Ruby SDK for accessing Coinbase Platform APIs
168
- email: yuga.cohler@coinbase.com
125
+ version: 1.2.0
126
+ description: ! '["An easy way to buy, send, and accept bitcoin."]'
127
+ email:
128
+ - ''
169
129
  executables: []
170
130
  extensions: []
171
131
  extra_rdoc_files: []
172
132
  files:
133
+ - .gitignore
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - coinbase.gemspec
173
140
  - lib/coinbase.rb
174
- - lib/coinbase/address.rb
175
- - lib/coinbase/asset.rb
176
- - lib/coinbase/balance_map.rb
177
- - lib/coinbase/constants.rb
178
- - lib/coinbase/network.rb
179
- - lib/coinbase/transfer.rb
180
- - lib/coinbase/wallet.rb
181
- homepage: https://github.com/coinbase/coinbase-sdk-ruby
182
- licenses:
183
- - Apache-2.0
184
- metadata:
185
- rubygems_mfa_required: 'true'
141
+ - lib/coinbase/ca-coinbase.crt
142
+ - lib/coinbase/client.rb
143
+ - lib/coinbase/money.rb
144
+ - lib/coinbase/version.rb
145
+ - spec/client_spec.rb
146
+ - supported_currencies.json
147
+ homepage: https://coinbase.com/api/doc
148
+ licenses: []
186
149
  post_install_message:
187
150
  rdoc_options: []
188
151
  require_paths:
189
152
  - lib
190
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
191
155
  requirements:
192
- - - ">="
156
+ - - ! '>='
193
157
  - !ruby/object:Gem::Version
194
- version: 2.7.0
158
+ version: '0'
195
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
196
161
  requirements:
197
- - - ">="
162
+ - - ! '>='
198
163
  - !ruby/object:Gem::Version
199
164
  version: '0'
200
165
  requirements: []
201
- rubygems_version: 3.1.6
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.23.2
202
168
  signing_key:
203
- specification_version: 4
204
- summary: Coinbase Ruby SDK
205
- test_files: []
169
+ specification_version: 3
170
+ summary: ! '["An easy way to buy, send, and accept bitcoin."]'
171
+ test_files:
172
+ - spec/client_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA256:
3
- metadata.gz: fd20c87743ea6c8d95575db35841ffd10b1dc87376d9d1e2e08803998b8322e8
4
- data.tar.gz: 475ac4213ae2e15c5ea5002441302faa908524ccb067e7a0ce99194d15c5b049
5
- SHA512:
6
- metadata.gz: 94fadca140def76fb428a824eca188f3eaa77388963f59ec04d70adfc1c1ccf2002c8af791bfc84bb7d83b07753b83fc755cec3af149e6c4549d51c594490ba6
7
- data.tar.gz: 8d04ee71428ee01611445c71f7642a205493e4a12f365826726132fc5fc783015e7aaa7e98e3813da924c914336bc51592198b6e0b3cc77b4e7e0d2226fdc655
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'balance_map'
4
- require_relative 'constants'
5
- require 'bigdecimal'
6
- require 'eth'
7
- require 'jimson'
8
-
9
- module Coinbase
10
- # A representation of a blockchain Address, which is a user-controlled account on a Network. Addresses are used to
11
- # send and receive Assets, and should be created using {link:Wallet#create_address}. Addresses require a
12
- # {link:Eth::Key} to sign transaction data.
13
- class Address
14
- attr_reader :network_id, :address_id, :wallet_id
15
-
16
- # Returns a new Address object.
17
- # @param network_id [Symbol] The ID of the Network on which the Address exists
18
- # @param address_id [String] The ID of the Address. On EVM Networks, for example, this is a hash of the public key.
19
- # @param wallet_id [String] The ID of the Wallet to which the Address belongs
20
- # @param key [Eth::Key] The key backing the Address
21
- # @param client [Jimson::Client] (Optional) The JSON RPC client to use for interacting with the Network
22
- def initialize(network_id, address_id, wallet_id, key,
23
- client: Jimson::Client.new(ENV.fetch('BASE_SEPOLIA_RPC_URL', nil)))
24
- # TODO: Don't require key.
25
- @network_id = network_id
26
- @address_id = address_id
27
- @wallet_id = wallet_id
28
- @key = key
29
- @client = client
30
- end
31
-
32
- # Returns the balances of the Address. Currently only ETH balances are supported.
33
- # @return [BalanceMap] The balances of the Address, keyed by asset ID. Ether balances are denominated
34
- # in ETH.
35
- def list_balances
36
- # TODO: Handle multiple currencies.
37
- eth_balance_in_wei = BigDecimal(@client.eth_getBalance(@address_id, 'latest').to_i(16).to_s)
38
- eth_balance = BigDecimal(eth_balance_in_wei / BigDecimal(Coinbase::WEI_PER_ETHER.to_s))
39
-
40
- BalanceMap.new({ eth: eth_balance })
41
- end
42
-
43
- # Returns the balance of the provided Asset. Currently only ETH is supported.
44
- # @param asset_id [Symbol] The Asset to retrieve the balance for
45
- # @return [BigDecimal] The balance of the Asset
46
- def get_balance(asset_id)
47
- normalized_asset_id = if %i[wei gwei].include?(asset_id)
48
- :eth
49
- else
50
- asset_id
51
- end
52
-
53
- eth_balance = list_balances[normalized_asset_id] || BigDecimal(0)
54
-
55
- case asset_id
56
- when :eth
57
- eth_balance
58
- when :gwei
59
- eth_balance * Coinbase::GWEI_PER_ETHER
60
- when :wei
61
- eth_balance * Coinbase::WEI_PER_ETHER
62
- else
63
- BigDecimal(0)
64
- end
65
- end
66
-
67
- # Transfers the given amount of the given Asset to the given address. Only same-Network Transfers are supported.
68
- # @param amount [Integer, Float, BigDecimal] The amount of the Asset to send.
69
- # @param asset_id [Symbol] The ID of the Asset to send. For Ether, :eth, :gwei, and :wei are supported.
70
- # @param destination [Wallet | Address | String] The destination of the transfer. If a Wallet, sends to the Wallet's
71
- # default address. If a String, interprets it as the address ID.
72
- # @return [String] The hash of the Transfer transaction.
73
- def transfer(amount, asset_id, destination)
74
- # TODO: Handle multiple currencies.
75
- raise ArgumentError, "Unsupported asset: #{asset_id}" unless Coinbase::SUPPORTED_ASSET_IDS[asset_id]
76
-
77
- if destination.is_a?(Wallet)
78
- raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != @network_id
79
-
80
- destination = destination.default_address.address_id
81
- elsif destination.is_a?(Address)
82
- raise ArgumentError, 'Transfer must be on the same Network' if destination.network_id != @network_id
83
-
84
- destination = destination.address_id
85
- end
86
-
87
- current_balance = get_balance(asset_id)
88
- if current_balance < amount
89
- raise ArgumentError, "Insufficient funds: #{amount} requested, but only #{current_balance} available"
90
- end
91
-
92
- transfer = Coinbase::Transfer.new(@network_id, @wallet_id, @address_id, amount, asset_id, destination,
93
- client: @client)
94
-
95
- transaction = transfer.transaction
96
- transaction.sign(@key)
97
- @client.eth_sendRawTransaction("0x#{transaction.hex}")
98
-
99
- transfer
100
- end
101
-
102
- # Returns the address as a string.
103
- # @return [String] The address
104
- def to_s
105
- @address_id
106
- end
107
-
108
- private
109
-
110
- # Normalizes the amount of ETH to send based on the asset ID.
111
- # @param amount [Integer, Float, BigDecimal] The amount to normalize
112
- # @param asset_id [Symbol] The ID of the Asset being transferred
113
- # @return [BigDecimal] The normalized amount in units of ETH
114
- def normalize_eth_amount(amount, asset_id)
115
- case asset_id
116
- when :eth
117
- amount.is_a?(BigDecimal) ? amount : BigDecimal(amount.to_s)
118
- when :gwei
119
- BigDecimal(amount / Coinbase::GWEI_PER_ETHER)
120
- when :wei
121
- BigDecimal(amount / Coinbase::WEI_PER_ETHER)
122
- else
123
- raise ArgumentError, "Unsupported asset: #{asset_id}"
124
- end
125
- end
126
- end
127
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Coinbase
4
- # A representation of an Asset.
5
- class Asset
6
- attr_reader :network_id, :asset_id, :display_name, :address_id
7
-
8
- # Returns a new Asset object.
9
- # @param network_id [Symbol] The ID of the Network to which the Asset belongs
10
- # @param asset_id [Symbol] The Asset ID
11
- # @param display_name [String] The Asset's display name
12
- # @param address_id [String] (Optional) The Asset's address ID, if one exists
13
- def initialize(network_id:, asset_id:, display_name:, address_id: nil)
14
- @network_id = network_id
15
- @asset_id = asset_id
16
- @display_name = display_name
17
- @address_id = address_id
18
- end
19
- end
20
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bigdecimal'
4
-
5
- module Coinbase
6
- # A convenience class for printing out crypto asset balances in a human-readable format.
7
- class BalanceMap < Hash
8
- # Returns a new BalanceMap object.
9
- # @param hash [Map<Symbol, BigDecimal>] The hash to initialize with
10
- def initialize(hash = {})
11
- super()
12
- hash.each do |key, value|
13
- self[key] = value
14
- end
15
- end
16
-
17
- # Returns a string representation of the balance map.
18
- # @return [String] The string representation of the balance
19
- def to_s
20
- to_string
21
- end
22
-
23
- # Returns a string representation of the balance map.
24
- # @return [String] The string representation of the balance
25
- def inspect
26
- to_string
27
- end
28
-
29
- private
30
-
31
- # Returns a string representation of the balance.
32
- # @return [String] The string representation of the balance
33
- def to_string
34
- result = {}
35
-
36
- each do |asset_id, balance|
37
- # Convert to floating-point number (not scientific notation)
38
- str = balance.to_s('F')
39
-
40
- str = balance.to_i.to_s if balance.frac.zero?
41
-
42
- result[asset_id] = str
43
- end
44
-
45
- result
46
- end
47
- end
48
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'asset'
4
- require_relative 'network'
5
-
6
- module Coinbase
7
- # The Assets supported on Base Sepolia by the Coinbase SDK.
8
- ETH = Asset.new(network_id: :base_sepolia, asset_id: :eth, display_name: 'Ether')
9
- USDC = Asset.new(network_id: :base_sepolia, asset_id: :usdc, display_name: 'USD Coin',
10
- address_id: '0x036CbD53842c5426634e7929541eC2318f3dCF7e')
11
-
12
- # The Base Sepolia Network.
13
- BASE_SEPOLIA = Network.new(
14
- network_id: :base_sepolia,
15
- display_name: 'Base Sepolia',
16
- protocol_family: :evm,
17
- is_testnet: true,
18
- assets: [ETH, USDC],
19
- native_asset_id: :eth,
20
- chain_id: 84_532
21
- )
22
-
23
- # The amount of Wei per Ether.
24
- WEI_PER_ETHER = 1_000_000_000_000_000_000
25
-
26
- # The amount of Wei per Gwei.
27
- WEI_PER_GWEI = 1_000_000_000
28
-
29
- # The amount of Gwei per Ether.
30
- GWEI_PER_ETHER = 1_000_000_000
31
-
32
- # A map of supported Asset IDs.
33
- SUPPORTED_ASSET_IDS = {
34
- eth: true, # Ether, the native asset of most EVM networks.
35
- gwei: true, # A medium denomination of Ether, typically used in gas prices.
36
- wei: true # The smallest denomination of Ether.
37
- }.freeze
38
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Coinbase
4
- # A blockchain network.
5
- class Network
6
- attr_reader :chain_id
7
-
8
- # Returns a new Network object.
9
- #
10
- # @param network_id [Symbol] The Network ID
11
- # @param display_name [String] The Network's display name
12
- # @param protocol_family [String] The protocol family to which the Network belongs
13
- # (e.g., "evm")
14
- # @param is_testnet [Boolean] Whether the Network is a testnet
15
- # @param assets [Array<Asset>] The Assets supported by the Network
16
- # @param native_asset_id [String] The ID of the Network's native Asset
17
- # @param chain_id [Integer] The Chain ID of the Network
18
- def initialize(network_id:, display_name:, protocol_family:, is_testnet:, assets:, native_asset_id:, chain_id:)
19
- @network_id = network_id
20
- @display_name = display_name
21
- @protocol_family = protocol_family
22
- @is_testnet = is_testnet
23
- @chain_id = chain_id
24
-
25
- @asset_map = {}
26
- assets.each do |asset|
27
- @asset_map[asset.asset_id] = asset
28
- end
29
-
30
- raise ArgumentError, 'Native Asset not found' unless @asset_map.key?(native_asset_id)
31
-
32
- @native_asset = @asset_map[native_asset_id]
33
- end
34
-
35
- # Lists the Assets supported by the Network.
36
- #
37
- # @return [Array<Asset>] The Assets supported by the Network
38
- def list_assets
39
- @asset_map.values
40
- end
41
-
42
- # Gets the Asset with the given ID.
43
- #
44
- # @param asset_id [Symbol] The ID of the Asset
45
- # @return [Asset] The Asset with the given ID
46
- def get_asset(asset_id)
47
- @asset_map[asset_id]
48
- end
49
-
50
- # Gets the native Asset of the Network.
51
- #
52
- # @return [Asset] The native Asset of the Network
53
- attr_reader :native_asset
54
- end
55
- end