Skip to content

Commit

Permalink
feat(PSDK-782): allow users to send sponsored transactions immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRAG committed Jan 14, 2025
1 parent 530e444 commit d9dc139
Show file tree
Hide file tree
Showing 148 changed files with 467 additions and 168 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
- Add `skip_batching` option to `Wallet.transfer` to allow for lower latency gasless transfers.

### Breaking
- Removed support for EOL Ruby v2.7

Expand Down Expand Up @@ -221,4 +224,4 @@ Initial release of the Coinbase Ruby SDK. Purely client-side implementation.
- Wallet creation and export
- Address creation
- Send and receive ETH
- Supported networks: Base Sepolia
- Supported networks: Base Sepolia
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ puts "Wallet successfully created: #{wallet3}"
transfer = wallet1.transfer(0.00001, :usdc, wallet3, gasless: true).wait!
```

By default, gasless transfers are batched with other transfers, and might take longer to submit. If you want to opt out of batching, you can set the `skip_batching` option to `True`, which will submit the transaction immediately.

```ruby
transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless: true, skip_batching: true).wait!
```

## Listing Transfers

```
Expand Down
9 changes: 6 additions & 3 deletions lib/coinbase/address/wallet_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def key=(key)
# default address. If a String, interprets it as the address ID.
# @param gasless [Boolean] Whether gas fee for the transfer should be covered by Coinbase.
# Defaults to false. Check the API documentation for network and asset support.
# Whether the transfer should be gasless. Defaults to false.
# @param skip_batching [Boolean] When true, the Transfer will be submitted immediately.
# Otherwise, the Transfer will be batched.
# Defaults to false. Note: requires gasless option to be set to true.
# @return [Coinbase::Transfer] The Transfer object.
def transfer(amount, asset_id, destination, gasless: false)
def transfer(amount, asset_id, destination, gasless: false, skip_batching: false)
ensure_can_sign!
ensure_sufficient_balance!(amount, asset_id)

Expand All @@ -54,7 +56,8 @@ def transfer(amount, asset_id, destination, gasless: false)
destination: destination,
network: network,
wallet_id: wallet_id,
gasless: gasless
gasless: gasless,
skip_batching: skip_batching
)

# If a server signer is managing keys, it will sign and broadcast the underlying transfer transaction out of band.
Expand Down
3 changes: 2 additions & 1 deletion lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand All @@ -30,6 +30,7 @@
Coinbase::Client.autoload :BroadcastExternalTransferRequest, 'coinbase/client/models/broadcast_external_transfer_request'
Coinbase::Client.autoload :BroadcastStakingOperationRequest, 'coinbase/client/models/broadcast_staking_operation_request'
Coinbase::Client.autoload :BroadcastTradeRequest, 'coinbase/client/models/broadcast_trade_request'
Coinbase::Client.autoload :BroadcastTransferRequest, 'coinbase/client/models/broadcast_transfer_request'
Coinbase::Client.autoload :BuildStakingOperationRequest, 'coinbase/client/models/build_staking_operation_request'
Coinbase::Client.autoload :ContractEvent, 'coinbase/client/models/contract_event'
Coinbase::Client.autoload :ContractEventList, 'coinbase/client/models/contract_event_list'
Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/addresses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/assets_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/balance_history_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/contract_events_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/contract_invocations_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/external_addresses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/fund_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/mpc_wallet_stake_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/networks_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/onchain_identity_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/reputation_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/server_signers_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/smart_contracts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/stake_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/trades_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/transaction_history_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
20 changes: 10 additions & 10 deletions lib/coinbase/client/api/transfers_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand All @@ -24,11 +24,11 @@ def initialize(api_client = ApiClient.default)
# @param wallet_id [String] The ID of the wallet the address belongs to
# @param address_id [String] The ID of the address the transfer belongs to
# @param transfer_id [String] The ID of the transfer to broadcast
# @param broadcast_external_transfer_request [BroadcastExternalTransferRequest]
# @param broadcast_transfer_request [BroadcastTransferRequest]
# @param [Hash] opts the optional parameters
# @return [Transfer]
def broadcast_transfer(wallet_id, address_id, transfer_id, broadcast_external_transfer_request, opts = {})
data, _status_code, _headers = broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_external_transfer_request, opts)
def broadcast_transfer(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts = {})
data, _status_code, _headers = broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts)
data
end

Expand All @@ -37,10 +37,10 @@ def broadcast_transfer(wallet_id, address_id, transfer_id, broadcast_external_tr
# @param wallet_id [String] The ID of the wallet the address belongs to
# @param address_id [String] The ID of the address the transfer belongs to
# @param transfer_id [String] The ID of the transfer to broadcast
# @param broadcast_external_transfer_request [BroadcastExternalTransferRequest]
# @param broadcast_transfer_request [BroadcastTransferRequest]
# @param [Hash] opts the optional parameters
# @return [Array<(Transfer, Integer, Hash)>] Transfer data, response status code and response headers
def broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_external_transfer_request, opts = {})
def broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadcast_transfer_request, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: TransfersApi.broadcast_transfer ...'
end
Expand All @@ -56,9 +56,9 @@ def broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadc
if @api_client.config.client_side_validation && transfer_id.nil?
fail ArgumentError, "Missing the required parameter 'transfer_id' when calling TransfersApi.broadcast_transfer"
end
# verify the required parameter 'broadcast_external_transfer_request' is set
if @api_client.config.client_side_validation && broadcast_external_transfer_request.nil?
fail ArgumentError, "Missing the required parameter 'broadcast_external_transfer_request' when calling TransfersApi.broadcast_transfer"
# verify the required parameter 'broadcast_transfer_request' is set
if @api_client.config.client_side_validation && broadcast_transfer_request.nil?
fail ArgumentError, "Missing the required parameter 'broadcast_transfer_request' when calling TransfersApi.broadcast_transfer"
end
# resource path
local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/transfers/{transfer_id}/broadcast'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'transfer_id' + '}', CGI.escape(transfer_id.to_s))
Expand All @@ -80,7 +80,7 @@ def broadcast_transfer_with_http_info(wallet_id, address_id, transfer_id, broadc
form_params = opts[:form_params] || {}

# http body (model)
post_body = opts[:debug_body] || @api_client.object_to_http_body(broadcast_external_transfer_request)
post_body = opts[:debug_body] || @api_client.object_to_http_body(broadcast_transfer_request)

# return_type
return_type = opts[:debug_return_type] || 'Transfer'
Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/users_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/wallets_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api/webhooks_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/api_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address_balance_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address_reputation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address_reputation_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/address_transaction_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
2 changes: 1 addition & 1 deletion lib/coinbase/client/models/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The version of the OpenAPI document: 0.0.1-alpha
Generated by: https://openapi-generator.tech
Generator version: 7.10.0
Generator version: 7.9.0
=end

Expand Down
Loading

0 comments on commit d9dc139

Please sign in to comment.