Skip to content

Commit

Permalink
Revert "Staking sdk"
Browse files Browse the repository at this point in the history
  • Loading branch information
YoavBZ authored Nov 20, 2023
1 parent 40e632d commit f1044c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 129 deletions.
74 changes: 6 additions & 68 deletions fireblocks_sdk/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def __init__(self, name_prefix=None, name_suffix=None, min_amount_threshold=None
self.before = before
self.after = after


class PagedExchangeAccountRequestFilters(object):
""" Optional filters to apply for request
Expand All @@ -272,10 +271,9 @@ class PagedExchangeAccountRequestFilters(object):
"""

def __init__(self, limit=None, before=None, after=None):
self.limit = limit
self.before = before
self.after = after

self.limit = limit
self.before = before
self.after = after

class GetAssetWalletsFilters(object):
""" Optional filters to apply for request
Expand Down Expand Up @@ -565,7 +563,6 @@ class PolicyTransactionType(str, Enum):
STAKE = "STAKE"
TYPED_MESSAGE = "TYPED_MESSAGE"


class PolicySrcOrDestType(str, Enum):
EXCHANGE = "EXCHANGE"
UNMANAGED = "UNMANAGED"
Expand All @@ -576,45 +573,37 @@ class PolicySrcOrDestType(str, Enum):
ONE_TIME_ADDRESS = "ONE_TIME_ADDRESS"
ANY = "*"


class PolicyType(str, Enum):
TRANSFER = "TRANSFER"


class PolicyAction(str, Enum):
ALLOW = "ALLOW"
BLOCK = "BLOCK"
TWO_TIER = "2-TIER"


class PolicyDestAddressType(str, Enum):
ANY = "*"
WHITELISTED = "WHITELISTED"
ONE_TIME = "ONE_TIME"


class PolicyAmountScope(str, Enum):
SINGLE_TX = "SINGLE_TX"
TIMEFRAME = "TIMEFRAME"


class PolicySrcOrDestSubType(str, Enum):
ANY = "*"
EXTERNAL = "EXTERNAL"
INTERNAL = "INTERNAL"
CONTRACT = "CONTRACT"
EXCHANGETEST = "EXCHANGETEST"


class Wildcard(str, Enum):
WILDCARD = "*"


class AuthorizationLogic(str, Enum):
AND = "AND"
OR = "OR"


class AuthorizationGroup:
def __init__(self, users: Optional[List[str]] = None, users_groups: Optional[List[str]] = None, th: int = 0):
if users:
Expand All @@ -626,10 +615,8 @@ def __init__(self, users: Optional[List[str]] = None, users_groups: Optional[Lis
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class PolicyAuthorizationGroups:
def __init__(self, logic: AuthorizationLogic, allow_operator_as_authorizer: Optional[bool] = None,
groups: List[AuthorizationGroup] = []):
def __init__(self, logic: AuthorizationLogic, allow_operator_as_authorizer: Optional[bool] = None, groups: List[AuthorizationGroup] = []):
self.logic = logic
if allow_operator_as_authorizer:
self.allow_operator_as_authorizer = allow_operator_as_authorizer
Expand All @@ -638,10 +625,8 @@ def __init__(self, logic: AuthorizationLogic, allow_operator_as_authorizer: Opti
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class Operators:
def __init__(self, wildcard: Optional[Wildcard] = None, users: Optional[List[str]] = None,
users_groups: Optional[List[str]] = None, services: Optional[List[str]] = None):
def __init__(self, wildcard: Optional[Wildcard] = None, users: Optional[List[str]] = None, users_groups: Optional[List[str]] = None, services: Optional[List[str]] = None):
if wildcard:
self.wildcard = wildcard
if users:
Expand All @@ -654,7 +639,6 @@ def __init__(self, wildcard: Optional[Wildcard] = None, users: Optional[List[str
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class DesignatedSigners:
def __init__(self, users: Optional[List[str]] = None, users_groups: Optional[List[str]] = None):
if users:
Expand All @@ -665,7 +649,6 @@ def __init__(self, users: Optional[List[str]] = None, users_groups: Optional[Lis
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class SrcDst:
def __init__(self, ids: Optional[List[List[Union[str, PolicySrcOrDestType, PolicySrcOrDestSubType]]]] = None):
if ids:
Expand All @@ -674,7 +657,6 @@ def __init__(self, ids: Optional[List[List[Union[str, PolicySrcOrDestType, Polic
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class AmountAggregation:
def __init__(self, operators: str, src_transfer_peers: str, dst_transfer_peers: str):
self.operators = operators
Expand All @@ -684,15 +666,13 @@ def __init__(self, operators: str, src_transfer_peers: str, dst_transfer_peers:
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class DerivationPath:
def __init__(self, path: List[int]):
self.path = path

def to_dict(self):
return convert_class_to_dict(self.__dict__)


class RawMessageSigning:
def __init__(self, derivation_path: DerivationPath, algorithm: str):
self.derivation_path = derivation_path
Expand All @@ -701,7 +681,6 @@ def __init__(self, derivation_path: DerivationPath, algorithm: str):
def to_dict(self):
return convert_class_to_dict(self.__dict__)


class PolicyRule:
def __init__(self,
type: PolicyType,
Expand Down Expand Up @@ -749,7 +728,7 @@ def __init__(self,
if transaction_type:
self.transaction_type = transaction_type
if operator_services:
self.operator_services = operator_services
self.operator_services = operator_services
if designated_signer:
self.designated_signer = designated_signer
if designated_signers:
Expand Down Expand Up @@ -789,44 +768,3 @@ def __init__(self,

def to_dict(self):
return convert_class_to_dict(self.__dict__)


class StakeRequestDto:
def __init__(self,
vault_account_id: str,
provider_id: str,
stake_amount: str,
tx_note: str = None,
fee: str = None,
fee_level: str = None):
self.vault_account_id = vault_account_id
self.provider_id = provider_id
self.stake_amount = stake_amount
self.tx_note = tx_note
self.fee = fee
self.fee_level = fee_level

def to_dict(self):
return convert_class_to_dict(self.__dict__)


class UnstakeRequestDto:
def __init__(self, id: str, fee: str = None, fee_level: str = None, tx_note: str = None):
self.id = id
self.fee = fee
self.fee_level = fee_level
self.tx_note = tx_note

def to_dict(self):
return convert_class_to_dict(self.__dict__)


class WithdrawRequestDto:
def __init__(self, id: str, fee: str = None, fee_level: str = None, tx_note: str = None):
self.id = id
self.fee = fee
self.fee_level = fee_level
self.tx_note = tx_note

def to_dict(self):
return convert_class_to_dict(self.__dict__)
118 changes: 57 additions & 61 deletions fireblocks_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import urllib
from importlib.metadata import version
from operator import attrgetter
from typing import Any, Dict, Optional, List, Union
from typing import Any, Dict, Optional, List

import requests

Expand Down Expand Up @@ -37,7 +37,7 @@
ContractDeployRequest,
ReadCallFunction,
WriteCallFunction,
PagedExchangeAccountRequestFilters, StakeRequestDto, UnstakeRequestDto, WithdrawRequestDto,
PagedExchangeAccountRequestFilters,
)
from .sdk_token_provider import SdkTokenProvider

Expand Down Expand Up @@ -118,42 +118,75 @@ def unlink_token(self, asset_id: str):

def get_staking_chains(self):
"""Get all staking chains."""
return self._get_request("/v1/staking/chains")
return self._get_request(f"/v1/staking/chains")

def get_staking_chain_info(self, chain_descriptor: str):
"""Get chain info."""
return self._get_request(f"/v1/staking/chains/{chain_descriptor}/chainInfo")

def get_staking_positions_summary(self):
def get_staking_positions_summary(self, by_vault: bool = None):
"""Get staking positions summary."""
return self._get_request(f"/v1/staking/positions/summary")
return self._get_request(f"/v1/staking/positions/summary",
query_params={"byVault": "true"} if by_vault else None)

def get_staking_positions_summary_by_vault(self):
"""Get staking positions summary by vault."""
return self._get_request("/v1/staking/positions/summary/vaults")

def execute_staking_action(self, chain_descriptor: str, action_id: str,
request_body: Union[StakeRequestDto, UnstakeRequestDto, WithdrawRequestDto]):
"""Execute staking action on a chain.
"""
return self._post_request(f"/v1/staking/chains/{chain_descriptor}/{action_id}", request_body.to_dict())
def execute_staking_action(self, chain_descriptor: str, action_id: str, request_body):
"""Execute staking action on a chain."""
return self._post_request(f"/v1/staking/chains/{chain_descriptor}/{action_id}", request_body)

def get_staking_positions(self, chain_descriptor: str = None):
"""Get all staking positions, optionally filtered by chain."""
return self._get_request("/v1/staking/positions",
return self._get_request(f"/v1/staking/positions",
query_params={"chainDescriptor": chain_descriptor} if chain_descriptor else None)

def get_staking_position(self, position_id: str):
"""Get a staking position by id."""
return self._get_request(f"/v1/staking/positions/{position_id}")

def get_staking_providers(self):
"""Get all staking providers."""
return self._get_request(f"/v1/staking/providers")
def get_staking_validators(self, chain_descriptor: str):
"""Get all staking validators, filtered by chain."""
return self._get_request(f"/v1/staking/validators/{chain_descriptor}")

def approve_staking_provider_terms_of_service(self, provider_id: str):
def approve_staking_provider(self, validator_provider_id: int):
"""Approve staking provider terms of service."""
return self._post_request(f"/v1/staking/providers/{provider_id}/approveTermsOfService")
return self._post_request(f"/v1/staking/providers/approveTermsOfService",
body={"validatorProviderId": validator_provider_id})

def get_contract_templates(self, limit: int = 100, offset: int = 0):
request_filter = {
"limit": limit,
"offset": offset
}
return self._get_request(f"/v1/contract-registry/contracts", query_params=request_filter)

def upload_contract_template(self, request: ContractUploadRequest):
return self._post_request(f"/v1/contract-registry/contracts", request.serialize())

def get_contract_template(self, contract_id: str):
return self._get_request(f"/v1/contract-registry/contracts/{contract_id}")

def get_contract_template_constructor(self, contract_id: str, with_docs: bool=False):
return self._get_request(f"/v1/contract-registry/contracts/{contract_id}/constructor?withDocs=${with_docs}`")

def delete_contract_template(self, contract_id: str):
return self._delete_request(f"/v1/contract-registry/contracts/{contract_id}")

def deploy_contract(self, contract_id: str, request: ContractDeployRequest):
return self._post_request(f"/v1/contract-registry/contracts/{contract_id}/deploy", request.serialize())

def get_contracts_by_filter(self, templateId: str, blockchainId: str = None):
return self._get_request(f"/v1/contract-service/contract?templateId={templateId}&blockchainId={blockchainId}")

def get_contract_by_address(self, blockchainId: str, contractAddress: str):
return self._get_request(f"/v1/contract-service/contract/{blockchainId}/{contractAddress}")

def get_contract_abi(self, blockchainId: str, contractAddress: str):
return self._get_request(f"/v1/contract-service/contract/{blockchainId}/{contractAddress}/abi")

def read_contract_call_function(self, blockchainId: str, contractAddress: str, payload: ReadCallFunction):
return self._post_request(f"/v1/contract-service/contract/{blockchainId}/{contractAddress}/function/read", payload)

def write_contract_call_function(self, blockchainId: str, contractAddress: str, payload: WriteCallFunction):
return self._post_request(f"/v1/contract-service/contract/{blockchainId}/{contractAddress}/function/write", payload)

def get_nft(self, id: str):
url = "/v1/nfts/tokens/" + id
Expand Down Expand Up @@ -227,8 +260,7 @@ def refresh_nft_ownership_by_vault(
return self._put_request(url, query_params=params)

def get_owned_nfts(self, blockchain_descriptor: str, vault_account_ids: List[str] = None, ids: List[str] = None,
collection_ids: List[str] = None, page_cursor: str = '', page_size: int = 100,
sort: List[GetOwnedNftsSortValues] = None,
collection_ids: List[str] = None, page_cursor: str = '', page_size: int = 100, sort: List[GetOwnedNftsSortValues] = None,
order: OrderValues = None, status: NFTOwnershipStatusValues = None, search: str = None,
ncw_account_ids: List[str] = None, ncw_id: str = None, wallet_type: NFTsWalletTypeValues = None):
"""
Expand Down Expand Up @@ -348,6 +380,7 @@ def list_owned_assets(self, search: str = None, status: NFTOwnershipStatusValues
params["sort"] = ",".join(sort)

if order:

params['order'] = order

return self._get_request(url, query_params=params)
Expand Down Expand Up @@ -378,43 +411,6 @@ def get_supported_assets(self):

return self._get_request("/v1/supported_assets")

def get_vault_accounts(
self,
name_prefix=None,
name_suffix=None,
min_amount_threshold=None,
assetId=None,
):
"""Gets all vault accounts for your tenant
Args:
name_prefix (string, optional): Vault account name prefix
name_suffix (string, optional): Vault account name suffix
min_amount_threshold (number, optional): The minimum amount for asset to have in order to be included in the results
assetId (string, optional): The asset symbol
"""

url = f"/v1/vault/accounts"

params = {}

if name_prefix:
params["namePrefix"] = name_prefix

if name_suffix:
params["nameSuffix"] = name_suffix

if min_amount_threshold is not None:
params["minAmountThreshold"] = min_amount_threshold

if assetId is not None:
params["assetId"] = assetId

if params:
url = url + "?" + urllib.parse.urlencode(params)

return self._get_request(url)

def get_vault_accounts_with_page_info(
self, paged_vault_accounts_request_filters: PagedVaultAccountsRequestFilters
):
Expand Down Expand Up @@ -783,6 +779,7 @@ def get_exchange_accounts_paged(self, paged_exchange_accounts_request_filters: P

params = {}


if limit is not None:
params['limit'] = limit

Expand Down Expand Up @@ -2197,8 +2194,7 @@ def create_user_group(self, group_name: str, member_ids: Optional[List[str]] = N

return self._post_request(url, body)

def update_user_group(self, id: str, group_name: Optional[str] = None, member_ids: Optional[List[str]] = None) -> \
Dict[str, Any]:
def update_user_group(self, id: str, group_name: Optional[str] = None, member_ids: Optional[List[str]] = None) -> Dict[str, Any]:
"""
Updates a Users Group
@param id: The ID of the Users Group
Expand Down

0 comments on commit f1044c0

Please sign in to comment.