cdp-sdk 0.12.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cdp/__init__.py +42 -0
- cdp/__version__.py +1 -0
- cdp/address.py +142 -0
- cdp/api_clients.py +252 -0
- cdp/asset.py +165 -0
- cdp/balance.py +79 -0
- cdp/balance_map.py +75 -0
- cdp/cdp.py +136 -0
- cdp/cdp_api_client.py +247 -0
- cdp/client/__init__.py +167 -0
- cdp/client/api/__init__.py +24 -0
- cdp/client/api/addresses_api.py +2683 -0
- cdp/client/api/assets_api.py +313 -0
- cdp/client/api/balance_history_api.py +363 -0
- cdp/client/api/contract_events_api.py +416 -0
- cdp/client/api/contract_invocations_api.py +1262 -0
- cdp/client/api/external_addresses_api.py +1222 -0
- cdp/client/api/fund_api.py +1248 -0
- cdp/client/api/mpc_wallet_stake_api.py +951 -0
- cdp/client/api/networks_api.py +298 -0
- cdp/client/api/onchain_identity_api.py +366 -0
- cdp/client/api/reputation_api.py +589 -0
- cdp/client/api/server_signers_api.py +1729 -0
- cdp/client/api/smart_contracts_api.py +1824 -0
- cdp/client/api/stake_api.py +2186 -0
- cdp/client/api/trades_api.py +1262 -0
- cdp/client/api/transaction_history_api.py +348 -0
- cdp/client/api/transfers_api.py +1262 -0
- cdp/client/api/users_api.py +281 -0
- cdp/client/api/validators_api.py +653 -0
- cdp/client/api/wallet_stake_api.py +945 -0
- cdp/client/api/wallets_api.py +1390 -0
- cdp/client/api/webhooks_api.py +1431 -0
- cdp/client/api_client.py +797 -0
- cdp/client/api_response.py +21 -0
- cdp/client/configuration.py +450 -0
- cdp/client/exceptions.py +199 -0
- cdp/client/models/__init__.py +131 -0
- cdp/client/models/abi.py +89 -0
- cdp/client/models/address.py +95 -0
- cdp/client/models/address_balance_list.py +101 -0
- cdp/client/models/address_historical_balance_list.py +99 -0
- cdp/client/models/address_list.py +101 -0
- cdp/client/models/address_reputation.py +93 -0
- cdp/client/models/address_reputation_metadata.py +105 -0
- cdp/client/models/address_risk.py +87 -0
- cdp/client/models/address_transaction_list.py +99 -0
- cdp/client/models/asset.py +93 -0
- cdp/client/models/balance.py +93 -0
- cdp/client/models/broadcast_contract_invocation_request.py +87 -0
- cdp/client/models/broadcast_staking_operation_request.py +89 -0
- cdp/client/models/broadcast_trade_request.py +89 -0
- cdp/client/models/broadcast_transfer_request.py +87 -0
- cdp/client/models/build_staking_operation_request.py +95 -0
- cdp/client/models/contract_event.py +112 -0
- cdp/client/models/contract_event_list.py +99 -0
- cdp/client/models/contract_invocation.py +109 -0
- cdp/client/models/contract_invocation_list.py +101 -0
- cdp/client/models/create_address_request.py +91 -0
- cdp/client/models/create_contract_invocation_request.py +95 -0
- cdp/client/models/create_fund_operation_request.py +91 -0
- cdp/client/models/create_fund_quote_request.py +89 -0
- cdp/client/models/create_payload_signature_request.py +89 -0
- cdp/client/models/create_server_signer_request.py +91 -0
- cdp/client/models/create_smart_contract_request.py +94 -0
- cdp/client/models/create_staking_operation_request.py +93 -0
- cdp/client/models/create_trade_request.py +91 -0
- cdp/client/models/create_transfer_request.py +95 -0
- cdp/client/models/create_wallet_request.py +91 -0
- cdp/client/models/create_wallet_request_wallet.py +89 -0
- cdp/client/models/create_wallet_webhook_request.py +89 -0
- cdp/client/models/create_webhook_request.py +110 -0
- cdp/client/models/crypto_amount.py +93 -0
- cdp/client/models/deploy_smart_contract_request.py +87 -0
- cdp/client/models/erc20_transfer_event.py +112 -0
- cdp/client/models/erc721_transfer_event.py +112 -0
- cdp/client/models/error.py +92 -0
- cdp/client/models/ethereum_token_transfer.py +100 -0
- cdp/client/models/ethereum_transaction.py +144 -0
- cdp/client/models/ethereum_transaction_access.py +89 -0
- cdp/client/models/ethereum_transaction_access_list.py +95 -0
- cdp/client/models/ethereum_transaction_flattened_trace.py +123 -0
- cdp/client/models/ethereum_validator_metadata.py +110 -0
- cdp/client/models/faucet_transaction.py +95 -0
- cdp/client/models/feature_set.py +97 -0
- cdp/client/models/fetch_historical_staking_balances200_response.py +99 -0
- cdp/client/models/fetch_staking_rewards200_response.py +99 -0
- cdp/client/models/fetch_staking_rewards_request.py +99 -0
- cdp/client/models/fiat_amount.py +89 -0
- cdp/client/models/fund_operation.py +120 -0
- cdp/client/models/fund_operation_fees.py +97 -0
- cdp/client/models/fund_operation_list.py +101 -0
- cdp/client/models/fund_quote.py +114 -0
- cdp/client/models/get_staking_context_request.py +93 -0
- cdp/client/models/historical_balance.py +97 -0
- cdp/client/models/multi_token_contract_options.py +87 -0
- cdp/client/models/network.py +117 -0
- cdp/client/models/network_identifier.py +43 -0
- cdp/client/models/nft_contract_options.py +91 -0
- cdp/client/models/onchain_name.py +106 -0
- cdp/client/models/onchain_name_list.py +101 -0
- cdp/client/models/onchain_name_text_records_inner.py +89 -0
- cdp/client/models/payload_signature.py +104 -0
- cdp/client/models/payload_signature_list.py +101 -0
- cdp/client/models/read_contract_request.py +91 -0
- cdp/client/models/read_smart_contract_request.py +91 -0
- cdp/client/models/seed_creation_event.py +89 -0
- cdp/client/models/seed_creation_event_result.py +93 -0
- cdp/client/models/server_signer.py +91 -0
- cdp/client/models/server_signer_event.py +93 -0
- cdp/client/models/server_signer_event_event.py +137 -0
- cdp/client/models/server_signer_event_list.py +101 -0
- cdp/client/models/server_signer_list.py +101 -0
- cdp/client/models/signature_creation_event.py +102 -0
- cdp/client/models/signature_creation_event_result.py +98 -0
- cdp/client/models/signed_voluntary_exit_message_metadata.py +91 -0
- cdp/client/models/smart_contract.py +114 -0
- cdp/client/models/smart_contract_activity_event.py +122 -0
- cdp/client/models/smart_contract_list.py +99 -0
- cdp/client/models/smart_contract_options.py +151 -0
- cdp/client/models/smart_contract_type.py +39 -0
- cdp/client/models/solidity_value.py +109 -0
- cdp/client/models/sponsored_send.py +106 -0
- cdp/client/models/staking_balance.py +103 -0
- cdp/client/models/staking_context.py +91 -0
- cdp/client/models/staking_context_context.py +101 -0
- cdp/client/models/staking_operation.py +118 -0
- cdp/client/models/staking_operation_metadata.py +127 -0
- cdp/client/models/staking_reward.py +110 -0
- cdp/client/models/staking_reward_format.py +37 -0
- cdp/client/models/staking_reward_usd_value.py +92 -0
- cdp/client/models/token_contract_options.py +91 -0
- cdp/client/models/token_transfer_type.py +39 -0
- cdp/client/models/trade.py +119 -0
- cdp/client/models/trade_list.py +101 -0
- cdp/client/models/transaction.py +118 -0
- cdp/client/models/transaction_content.py +123 -0
- cdp/client/models/transaction_type.py +36 -0
- cdp/client/models/transfer.py +137 -0
- cdp/client/models/transfer_list.py +101 -0
- cdp/client/models/update_webhook_request.py +103 -0
- cdp/client/models/user.py +89 -0
- cdp/client/models/validator.py +100 -0
- cdp/client/models/validator_details.py +123 -0
- cdp/client/models/validator_list.py +99 -0
- cdp/client/models/validator_status.py +48 -0
- cdp/client/models/wallet.py +113 -0
- cdp/client/models/wallet_list.py +101 -0
- cdp/client/models/webhook.py +117 -0
- cdp/client/models/webhook_event_filter.py +91 -0
- cdp/client/models/webhook_event_type.py +40 -0
- cdp/client/models/webhook_event_type_filter.py +137 -0
- cdp/client/models/webhook_list.py +99 -0
- cdp/client/models/webhook_smart_contract_event_filter.py +87 -0
- cdp/client/models/webhook_wallet_activity_filter.py +89 -0
- cdp/client/py.typed +0 -0
- cdp/client/rest.py +257 -0
- cdp/constants.py +4 -0
- cdp/contract_invocation.py +350 -0
- cdp/crypto_amount.py +116 -0
- cdp/errors.py +376 -0
- cdp/faucet_transaction.py +133 -0
- cdp/fiat_amount.py +69 -0
- cdp/fund_operation.py +247 -0
- cdp/fund_quote.py +199 -0
- cdp/hash_utils.py +40 -0
- cdp/historical_balance.py +131 -0
- cdp/payload_signature.py +228 -0
- cdp/py.typed +0 -0
- cdp/smart_contract.py +439 -0
- cdp/sponsored_send.py +164 -0
- cdp/trade.py +276 -0
- cdp/transaction.py +227 -0
- cdp/transfer.py +325 -0
- cdp/wallet.py +843 -0
- cdp/wallet_address.py +414 -0
- cdp/wallet_data.py +73 -0
- cdp/webhook.py +207 -0
- cdp_sdk-0.12.0.dist-info/LICENSE.md +15 -0
- cdp_sdk-0.12.0.dist-info/METADATA +296 -0
- cdp_sdk-0.12.0.dist-info/RECORD +182 -0
- cdp_sdk-0.12.0.dist-info/WHEEL +4 -0
cdp/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from cdp.__version__ import __version__
|
|
2
|
+
from cdp.address import Address
|
|
3
|
+
from cdp.asset import Asset
|
|
4
|
+
from cdp.balance import Balance
|
|
5
|
+
from cdp.balance_map import BalanceMap
|
|
6
|
+
from cdp.cdp import Cdp
|
|
7
|
+
from cdp.contract_invocation import ContractInvocation
|
|
8
|
+
from cdp.faucet_transaction import FaucetTransaction
|
|
9
|
+
from cdp.hash_utils import hash_message, hash_typed_data_message
|
|
10
|
+
from cdp.payload_signature import PayloadSignature
|
|
11
|
+
from cdp.smart_contract import SmartContract
|
|
12
|
+
from cdp.sponsored_send import SponsoredSend
|
|
13
|
+
from cdp.trade import Trade
|
|
14
|
+
from cdp.transaction import Transaction
|
|
15
|
+
from cdp.transfer import Transfer
|
|
16
|
+
from cdp.wallet import Wallet
|
|
17
|
+
from cdp.wallet_address import WalletAddress
|
|
18
|
+
from cdp.wallet_data import WalletData
|
|
19
|
+
from cdp.webhook import Webhook
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"__version__",
|
|
23
|
+
"Cdp",
|
|
24
|
+
"ContractInvocation",
|
|
25
|
+
"Wallet",
|
|
26
|
+
"WalletAddress",
|
|
27
|
+
"WalletData",
|
|
28
|
+
"Webhook",
|
|
29
|
+
"Asset",
|
|
30
|
+
"Transfer",
|
|
31
|
+
"Address",
|
|
32
|
+
"Transaction",
|
|
33
|
+
"Balance",
|
|
34
|
+
"BalanceMap",
|
|
35
|
+
"FaucetTransaction",
|
|
36
|
+
"Trade",
|
|
37
|
+
"SponsoredSend",
|
|
38
|
+
"PayloadSignature",
|
|
39
|
+
"SmartContract",
|
|
40
|
+
"hash_message",
|
|
41
|
+
"hash_typed_data_message",
|
|
42
|
+
]
|
cdp/__version__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.12.0"
|
cdp/address.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from decimal import Decimal
|
|
3
|
+
|
|
4
|
+
from cdp.asset import Asset
|
|
5
|
+
from cdp.balance import Balance
|
|
6
|
+
from cdp.balance_map import BalanceMap
|
|
7
|
+
from cdp.cdp import Cdp
|
|
8
|
+
from cdp.faucet_transaction import FaucetTransaction
|
|
9
|
+
from cdp.historical_balance import HistoricalBalance
|
|
10
|
+
from cdp.transaction import Transaction
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Address:
|
|
14
|
+
"""A class representing an address."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, network_id: str, address_id: str) -> None:
|
|
17
|
+
"""Initialize the Address class.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
network_id (str): The network ID.
|
|
21
|
+
address_id (str): The address ID.
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
self._network_id = network_id
|
|
25
|
+
self._id = address_id
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def address_id(self) -> str:
|
|
29
|
+
"""Get the address ID.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
str: The address ID.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
return self._id
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def network_id(self) -> str:
|
|
39
|
+
"""Get the network ID.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
str: The network ID.
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
return self._network_id
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def can_sign(self) -> bool:
|
|
49
|
+
"""Get whether the address can sign.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
bool: Whether the address can sign.
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
def faucet(self, asset_id=None) -> FaucetTransaction:
|
|
58
|
+
"""Request faucet funds.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
asset_id (str): The asset ID.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
FaucetTransaction: The faucet transaction object.
|
|
65
|
+
|
|
66
|
+
"""
|
|
67
|
+
model = Cdp.api_clients.external_addresses.request_external_faucet_funds(
|
|
68
|
+
network_id=self.network_id,
|
|
69
|
+
address_id=self.address_id,
|
|
70
|
+
asset_id=asset_id,
|
|
71
|
+
skip_wait=True,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
return FaucetTransaction(model)
|
|
75
|
+
|
|
76
|
+
def balance(self, asset_id) -> Decimal:
|
|
77
|
+
"""Get the balance of the address.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
asset_id (str): The asset ID.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Decimal: The balance of the address.
|
|
84
|
+
|
|
85
|
+
"""
|
|
86
|
+
model = Cdp.api_clients.external_addresses.get_external_address_balance(
|
|
87
|
+
network_id=self.network_id,
|
|
88
|
+
address_id=self.address_id,
|
|
89
|
+
asset_id=Asset.primary_denomination(asset_id),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return Decimal(0) if model is None else Balance.from_model(model, asset_id).amount
|
|
93
|
+
|
|
94
|
+
def balances(self):
|
|
95
|
+
"""List balances of the address.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
BalanceMap: The balances of the address, keyed by asset ID. Ether balances are denominated in ETH.
|
|
99
|
+
|
|
100
|
+
"""
|
|
101
|
+
response = Cdp.api_clients.external_addresses.list_external_address_balances(
|
|
102
|
+
network_id=self.network_id, address_id=self.address_id
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return BalanceMap.from_models(response.data)
|
|
106
|
+
|
|
107
|
+
def historical_balances(self, asset_id) -> Iterator[HistoricalBalance]:
|
|
108
|
+
"""List historical balances.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
asset_id (str): The asset ID.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Iterator[HistoricalBalance]: An iterator of HistoricalBalance objects.
|
|
115
|
+
|
|
116
|
+
Raises:
|
|
117
|
+
Exception: If there's an error listing the historical balances.
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
return HistoricalBalance.list(
|
|
121
|
+
network_id=self.network_id, address_id=self.address_id, asset_id=asset_id
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def transactions(self) -> Iterator[Transaction]:
|
|
125
|
+
"""List transactions of the address.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
Iterator[Transaction]: An iterator of Transaction objects.
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
Exception: If there's an error listing the transactions.
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
return Transaction.list(network_id=self.network_id, address_id=self.address_id)
|
|
135
|
+
|
|
136
|
+
def __str__(self) -> str:
|
|
137
|
+
"""Return a string representation of the Address."""
|
|
138
|
+
return f"Address: (address_id: {self.address_id}, network_id: {self.network_id})"
|
|
139
|
+
|
|
140
|
+
def __repr__(self) -> str:
|
|
141
|
+
"""Return a string representation of the Address."""
|
|
142
|
+
return str(self)
|
cdp/api_clients.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
from cdp.cdp_api_client import CdpApiClient
|
|
2
|
+
from cdp.client.api.addresses_api import AddressesApi
|
|
3
|
+
from cdp.client.api.assets_api import AssetsApi
|
|
4
|
+
from cdp.client.api.balance_history_api import BalanceHistoryApi
|
|
5
|
+
from cdp.client.api.contract_invocations_api import ContractInvocationsApi
|
|
6
|
+
from cdp.client.api.external_addresses_api import ExternalAddressesApi
|
|
7
|
+
from cdp.client.api.fund_api import FundApi
|
|
8
|
+
from cdp.client.api.networks_api import NetworksApi
|
|
9
|
+
from cdp.client.api.smart_contracts_api import SmartContractsApi
|
|
10
|
+
from cdp.client.api.trades_api import TradesApi
|
|
11
|
+
from cdp.client.api.transaction_history_api import TransactionHistoryApi
|
|
12
|
+
from cdp.client.api.transfers_api import TransfersApi
|
|
13
|
+
from cdp.client.api.wallets_api import WalletsApi
|
|
14
|
+
from cdp.client.api.webhooks_api import WebhooksApi
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ApiClients:
|
|
18
|
+
"""A container class for all API clients used in the Coinbase SDK.
|
|
19
|
+
|
|
20
|
+
This class provides lazy-loaded access to various API clients, ensuring
|
|
21
|
+
that each client is only instantiated when it's first accessed.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
_cdp_client (CdpApiClient): The CDP API client used to initialize individual API clients.
|
|
25
|
+
_wallets (Optional[WalletsApi]): The WalletsApi client instance.
|
|
26
|
+
_webhooks (Optional[WebhooksApi]): The WebhooksApi client instance.
|
|
27
|
+
_addresses (Optional[AddressesApi]): The AddressesApi client instance.
|
|
28
|
+
_external_addresses (Optional[ExternalAddressesApi]): The ExternalAddressesApi client instance.
|
|
29
|
+
_transfers (Optional[TransfersApi]): The TransfersApi client instance.
|
|
30
|
+
_networks (Optional[NetworksApi]): The NetworksApi client instance.
|
|
31
|
+
_assets (Optional[AssetsApi]): The AssetsApi client instance.
|
|
32
|
+
_trades (Optional[TradesApi]): The TradesApi client instance.
|
|
33
|
+
_contract_invocations (Optional[ContractInvocationsApi]): The ContractInvocationsApi client instance.
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, cdp_client: CdpApiClient) -> None:
|
|
38
|
+
"""Initialize the ApiClients instance.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
cdp_client (CdpApiClient): The CDP API client to use for initializing individual API clients.
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
self._cdp_client: CdpApiClient = cdp_client
|
|
45
|
+
self._wallets: WalletsApi | None = None
|
|
46
|
+
self._webhooks: WebhooksApi | None = None
|
|
47
|
+
self._addresses: AddressesApi | None = None
|
|
48
|
+
self._external_addresses: ExternalAddressesApi | None = None
|
|
49
|
+
self._transfers: TransfersApi | None = None
|
|
50
|
+
self._networks: NetworksApi | None = None
|
|
51
|
+
self._assets: AssetsApi | None = None
|
|
52
|
+
self._trades: TradesApi | None = None
|
|
53
|
+
self._contract_invocations: ContractInvocationsApi | None = None
|
|
54
|
+
self._smart_contracts: SmartContractsApi | None = None
|
|
55
|
+
self._balance_history: BalanceHistoryApi | None = None
|
|
56
|
+
self._transaction_history: TransactionHistoryApi | None = None
|
|
57
|
+
self._fund: FundApi | None = None
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def wallets(self) -> WalletsApi:
|
|
61
|
+
"""Get the WalletsApi client instance.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
WalletsApi: The WalletsApi client instance.
|
|
65
|
+
|
|
66
|
+
Note:
|
|
67
|
+
This property lazily initializes the WalletsApi client on first access.
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
if self._wallets is None:
|
|
71
|
+
self._wallets = WalletsApi(api_client=self._cdp_client)
|
|
72
|
+
return self._wallets
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def webhooks(self) -> WebhooksApi:
|
|
76
|
+
"""Get the WebhooksApi client instance.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
WebhooksApi: The WebhooksApi client instance.
|
|
80
|
+
|
|
81
|
+
Note:
|
|
82
|
+
This property lazily initializes the WebhooksApi client on first access.
|
|
83
|
+
|
|
84
|
+
"""
|
|
85
|
+
if self._webhooks is None:
|
|
86
|
+
self._webhooks = WebhooksApi(api_client=self._cdp_client)
|
|
87
|
+
return self._webhooks
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def addresses(self) -> AddressesApi:
|
|
91
|
+
"""Get the AddressesApi client instance.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
AddressesApi: The AddressesApi client instance.
|
|
95
|
+
|
|
96
|
+
Note:
|
|
97
|
+
This property lazily initializes the AddressesApi client on first access.
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
if self._addresses is None:
|
|
101
|
+
self._addresses = AddressesApi(api_client=self._cdp_client)
|
|
102
|
+
return self._addresses
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def external_addresses(self) -> ExternalAddressesApi:
|
|
106
|
+
"""Get the ExternalAddressesApi client instance.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
ExternalAddressesApi: The ExternalAddressesApi client instance.
|
|
110
|
+
|
|
111
|
+
Note:
|
|
112
|
+
This property lazily initializes the ExternalAddressesApi client on first access.
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
if self._external_addresses is None:
|
|
116
|
+
self._external_addresses = ExternalAddressesApi(api_client=self._cdp_client)
|
|
117
|
+
return self._external_addresses
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def transfers(self) -> TransfersApi:
|
|
121
|
+
"""Get the TransfersApi client instance.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
TransfersApi: The TransfersApi client instance.
|
|
125
|
+
|
|
126
|
+
Note:
|
|
127
|
+
This property lazily initializes the TransfersApi client on first access.
|
|
128
|
+
|
|
129
|
+
"""
|
|
130
|
+
if self._transfers is None:
|
|
131
|
+
self._transfers = TransfersApi(api_client=self._cdp_client)
|
|
132
|
+
return self._transfers
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def networks(self) -> NetworksApi:
|
|
136
|
+
"""Get the NetworksApi client instance.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
NetworksApi: The NetworksApi client instance.
|
|
140
|
+
|
|
141
|
+
Note:
|
|
142
|
+
This property lazily initializes the NetworksApi client on first access.
|
|
143
|
+
|
|
144
|
+
"""
|
|
145
|
+
if self._networks is None:
|
|
146
|
+
self._networks = NetworksApi(api_client=self._cdp_client)
|
|
147
|
+
return self._networks
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def assets(self) -> AssetsApi:
|
|
151
|
+
"""Get the AssetsApi client instance.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
AssetsApi: The AssetsApi client instance.
|
|
155
|
+
|
|
156
|
+
Note:
|
|
157
|
+
This property lazily initializes the AssetsApi client on first access.
|
|
158
|
+
|
|
159
|
+
"""
|
|
160
|
+
if self._assets is None:
|
|
161
|
+
self._assets = AssetsApi(api_client=self._cdp_client)
|
|
162
|
+
return self._assets
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def trades(self) -> TradesApi:
|
|
166
|
+
"""Get the TradesApi client instance.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
TradesApi: The TradesApi client instance.
|
|
170
|
+
|
|
171
|
+
Note:
|
|
172
|
+
This property lazily initializes the TradesApi client on first access.
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
if self._trades is None:
|
|
176
|
+
self._trades = TradesApi(api_client=self._cdp_client)
|
|
177
|
+
return self._trades
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def contract_invocations(self) -> ContractInvocationsApi:
|
|
181
|
+
"""Get the ContractInvocationsApi client instance.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
ContractInvocationsApi: The ContractInvocationsApi client instance.
|
|
185
|
+
|
|
186
|
+
Note:
|
|
187
|
+
This property lazily initializes the ContractInvocationsApi client on first access.
|
|
188
|
+
|
|
189
|
+
"""
|
|
190
|
+
if self._contract_invocations is None:
|
|
191
|
+
self._contract_invocations = ContractInvocationsApi(api_client=self._cdp_client)
|
|
192
|
+
return self._contract_invocations
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def balance_history(self) -> BalanceHistoryApi:
|
|
196
|
+
"""Get the BalanceHistoryApi client instance.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
BalanceHistoryApi: The BalanceHistoryApi client instance.
|
|
200
|
+
|
|
201
|
+
Note:
|
|
202
|
+
This property lazily initializes the BalanceHistoryApi client on first access.
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
if self._balance_history is None:
|
|
206
|
+
self._balance_history = BalanceHistoryApi(api_client=self._cdp_client)
|
|
207
|
+
return self._balance_history
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def smart_contracts(self) -> SmartContractsApi:
|
|
211
|
+
"""Get the SmartContractsApi client instance.
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
SmartContractsApi: The SmartContractsApi client instance.
|
|
215
|
+
|
|
216
|
+
Note:
|
|
217
|
+
This property lazily initializes the SmartContractsApi client on first access.
|
|
218
|
+
|
|
219
|
+
"""
|
|
220
|
+
if self._smart_contracts is None:
|
|
221
|
+
self._smart_contracts = SmartContractsApi(api_client=self._cdp_client)
|
|
222
|
+
return self._smart_contracts
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def transaction_history(self) -> TransactionHistoryApi:
|
|
226
|
+
"""Get the TransactionHistoryApi client instance.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
TransactionHistoryApi: The TransactionHistoryApi client instance.
|
|
230
|
+
|
|
231
|
+
Note:
|
|
232
|
+
This property lazily initializes the TransactionHistoryApi client on first access.
|
|
233
|
+
|
|
234
|
+
"""
|
|
235
|
+
if self._transaction_history is None:
|
|
236
|
+
self._transaction_history = TransactionHistoryApi(api_client=self._cdp_client)
|
|
237
|
+
return self._transaction_history
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def fund(self) -> FundApi:
|
|
241
|
+
"""Get the FundApi client instance.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
FundApi: The FundApi client instance.
|
|
245
|
+
|
|
246
|
+
Note:
|
|
247
|
+
This property lazily initializes the FundApi client on first access.
|
|
248
|
+
|
|
249
|
+
"""
|
|
250
|
+
if self._fund is None:
|
|
251
|
+
self._fund = FundApi(api_client=self._cdp_client)
|
|
252
|
+
return self._fund
|
cdp/asset.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
from cdp.cdp import Cdp
|
|
4
|
+
from cdp.client.models.asset import Asset as AssetModel
|
|
5
|
+
|
|
6
|
+
# TODO: Move to constants.py
|
|
7
|
+
GWEI_DECIMALS = 9
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Asset:
|
|
11
|
+
"""A class representing an asset."""
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self, network_id: str, asset_id: str, contract_address: str, decimals: int
|
|
15
|
+
) -> None:
|
|
16
|
+
"""Initialize the Asset class.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
network_id (str): The network ID.
|
|
20
|
+
asset_id (str): The asset ID.
|
|
21
|
+
contract_address (str): The contract address.
|
|
22
|
+
decimals (int): The number of decimals.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
self._network_id = network_id
|
|
26
|
+
self._asset_id = asset_id
|
|
27
|
+
self._contract_address = contract_address
|
|
28
|
+
self._decimals = decimals
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_model(cls, model: AssetModel, asset_id: str | None = None) -> "Asset":
|
|
32
|
+
"""Create an Asset instance from a model.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
model (AssetModel): The model representing the asset.
|
|
36
|
+
asset_id (Optional[str]): The asset ID.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Asset: The Asset instance.
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
decimals = model.decimals
|
|
43
|
+
|
|
44
|
+
if asset_id and asset_id != model.asset_id:
|
|
45
|
+
match asset_id:
|
|
46
|
+
case "gwei":
|
|
47
|
+
decimals = GWEI_DECIMALS
|
|
48
|
+
case "wei":
|
|
49
|
+
decimals = 0
|
|
50
|
+
case _:
|
|
51
|
+
raise ValueError(f"Unsupported asset ID: {asset_id}")
|
|
52
|
+
|
|
53
|
+
return cls(
|
|
54
|
+
network_id=model.network_id,
|
|
55
|
+
asset_id=asset_id or model.asset_id,
|
|
56
|
+
contract_address=model.contract_address,
|
|
57
|
+
decimals=decimals,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def fetch(cls, network_id: str, asset_id: str) -> "Asset":
|
|
62
|
+
"""Fetch an asset from the API.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
network_id (str): The network ID.
|
|
66
|
+
asset_id (str): The asset ID.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
Asset: The fetched Asset instance.
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
primary_denomination_asset_id = cls.primary_denomination(asset_id)
|
|
73
|
+
|
|
74
|
+
model = Cdp.api_clients.assets.get_asset(
|
|
75
|
+
network_id=network_id, asset_id=primary_denomination_asset_id
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return cls.from_model(model, asset_id=asset_id)
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def primary_denomination(asset_id: str) -> str:
|
|
82
|
+
"""Get the primary denomination for a given asset ID.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
asset_id (str): The asset ID.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
str: The primary denomination of the asset.
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
if asset_id in ["wei", "gwei"]:
|
|
92
|
+
return "eth"
|
|
93
|
+
return asset_id
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def decimals(self) -> int:
|
|
97
|
+
"""Get the number of decimals for the asset.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
int: The number of decimals.
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
return self._decimals
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def asset_id(self) -> str:
|
|
107
|
+
"""Get the asset ID.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
str: The asset ID.
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
return self._asset_id
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def contract_address(self) -> str:
|
|
117
|
+
"""Get the contract address.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
str: The contract address.
|
|
121
|
+
|
|
122
|
+
"""
|
|
123
|
+
return self._contract_address
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def network_id(self) -> str:
|
|
127
|
+
"""Get the network ID.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
str: The network ID.
|
|
131
|
+
|
|
132
|
+
"""
|
|
133
|
+
return self._network_id
|
|
134
|
+
|
|
135
|
+
def from_atomic_amount(self, atomic_amount: Decimal) -> Decimal:
|
|
136
|
+
"""Convert an atomic amount to a whole amount.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
atomic_amount (Decimal): The atomic amount.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
Decimal: The whole amount.
|
|
143
|
+
|
|
144
|
+
"""
|
|
145
|
+
return Decimal(atomic_amount) / Decimal(10) ** (self.decimals)
|
|
146
|
+
|
|
147
|
+
def to_atomic_amount(self, whole_amount: Decimal) -> Decimal:
|
|
148
|
+
"""Convert a whole amount to an atomic amount.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
whole_amount (Decimal): The whole amount.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
Decimal: The atomic amount.
|
|
155
|
+
|
|
156
|
+
"""
|
|
157
|
+
return whole_amount * Decimal(10) ** (self.decimals)
|
|
158
|
+
|
|
159
|
+
def __str__(self) -> str:
|
|
160
|
+
"""Return a string representation of the Asset."""
|
|
161
|
+
return f"Asset: (asset_id: {self.asset_id}, network_id: {self.network_id}, contract_address: {self.contract_address}, decimals: {self.decimals})"
|
|
162
|
+
|
|
163
|
+
def __repr__(self) -> str:
|
|
164
|
+
"""Return a string representation of the Asset."""
|
|
165
|
+
return str(self)
|
cdp/balance.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
from cdp.asset import Asset
|
|
4
|
+
from cdp.client.models.balance import Balance as BalanceModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Balance:
|
|
8
|
+
"""A class representing a balance."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, amount: Decimal, asset: Asset, asset_id: str | None = None):
|
|
11
|
+
"""Initialize the Balance class.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
amount (Decimal): The amount.
|
|
15
|
+
asset (Asset): The asset.
|
|
16
|
+
asset_id (Optional[str]): The asset ID.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
self._amount = amount
|
|
20
|
+
self._asset = asset
|
|
21
|
+
self._asset_id = asset_id if asset_id is not None else asset.asset_id
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def from_model(model: BalanceModel, asset_id: str | None = None) -> "Balance":
|
|
25
|
+
"""Create a Balance instance from a model.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
model (BalanceModel): The model representing the balance.
|
|
29
|
+
asset_id (Optional[str]): The asset ID.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Balance: The Balance instance.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
asset = Asset.from_model(model.asset, asset_id=asset_id)
|
|
36
|
+
|
|
37
|
+
return Balance(
|
|
38
|
+
amount=asset.from_atomic_amount(model.amount),
|
|
39
|
+
asset=asset,
|
|
40
|
+
asset_id=asset_id,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def amount(self) -> Decimal:
|
|
45
|
+
"""Get the amount.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Decimal: The amount.
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
return self._amount
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def asset(self) -> Asset:
|
|
55
|
+
"""Get the asset.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Asset: The asset.
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
return self._asset
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def asset_id(self) -> str:
|
|
65
|
+
"""Get the asset ID.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
str: The asset ID.
|
|
69
|
+
|
|
70
|
+
"""
|
|
71
|
+
return self._asset_id
|
|
72
|
+
|
|
73
|
+
def __str__(self) -> str:
|
|
74
|
+
"""Return a string representation of the Balance."""
|
|
75
|
+
return f"Balance: (amount: {self.amount}, asset: {self.asset})"
|
|
76
|
+
|
|
77
|
+
def __repr__(self) -> str:
|
|
78
|
+
"""Return a string representation of the Balance."""
|
|
79
|
+
return str(self)
|