Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokenization and contract registry endpoints #127

Merged
merged 11 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## About
This repository contains the official Python SDK for Fireblocks API.
For the complete API reference, go to the [API reference](https://docs.fireblocks.com/api).
For the complete API reference, go to the [API reference](https://developers.fireblocks.com/).

## Usage
### Before You Begin
Expand Down
156 changes: 133 additions & 23 deletions fireblocks_sdk/api_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from enum import Enum
from typing import Optional, List, Union

from typing import Optional, List, Union, Dict

def snake_to_camel(snake_case: str):
words = snake_case.split('_')
Expand All @@ -9,13 +8,13 @@ def snake_to_camel(snake_case: str):

def convert_class_to_dict(class_dict: dict):
output_dict = {}
for key, value in class_dict.items():
for key, value in class_dict.items:
if isinstance(value, list):
output_dict[snake_to_camel(key)] = [item.to_dict() if hasattr(item, 'to_dict') else item for item
in value]
elif hasattr(value, 'to_dict') and callable(getattr(value, 'to_dict')):
output_dict[snake_to_camel(key)] = value.to_dict()
else:
elif value is not None:
output_dict[snake_to_camel(key)] = value
return output_dict

Expand Down Expand Up @@ -387,30 +386,141 @@ class TimePeriod(str, Enum):
DAY = "DAY"
WEEK = "WEEK"

class StellarRippleCreateParams:
def __init__(
self,
issuerAddress: Optional[str] = None
):
self.issuerAddress = issuerAddress

class IssueTokenRequest:
symbol: str
name: str
blockchain_id: str
eth_contract_address: Optional[str]
issuer_address: Optional[str]
decimals: int
def to_dict(self):
return convert_class_to_dict(self.__dict__)

def serialize(self) -> dict:
obj = {
'symbol': self.symbol,
'name': self.name,
'blockchainId': self.blockchain_id,
'decimals': self.decimals,
}
class Parameter:
aviba marked this conversation as resolved.
Show resolved Hide resolved
def __init__(
self,
name: str,
type: str,
internalType: str,
description: Optional[str] = None,
components: Optional[List['Parameter']] = None
):
self.name = name
self.type = type
self.internalType = internalType
self.description = description
self.components = components

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

class ParameterWithValue(Parameter):
def __init__(
self,
name: str,
type: str,
internalType: str,
value: Union[str, int, float, bool],
description: Optional[str] = None,
components: Optional[List['Parameter']] = None
):
super().__init__(name, type, internalType, description, components)
self.value = value

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

class EVMTokenCreateParams:
def __init__(
self,
contractId: str,
constructorParams: Optional[List[ParameterWithValue]] = None
):
self.contractId = contractId
self.constructorParams = constructorParams

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

class CreateTokenRequest:
def __init__(
self,
symbol: str,
name: str,
blockchainId: str,
vaultAccountId: str,
createParams: Union[EVMTokenCreateParams, StellarRippleCreateParams]
):
self.symbol = symbol
self.name = name
self.blockchainId = blockchainId
self.vaultAccountId = vaultAccountId
self.createParams = createParams

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

class ContractDeployRequest:
def __init__(
self,
asset_id: str,
vault_account_id: str,
constructorParameters: Optional[List[ParameterWithValue]] = None
):
self.asset_id = asset_id
self.vault_account_id = vault_account_id
self.constructorParameters = constructorParameters

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

class AbiFunction:
def __init__(
self,
name: str,
type: str,
stateMutability: str,
inputs: List[Parameter],
outputs: Optional[List[Parameter]] = None,
description: Optional[str] = None,
returns: Optional[Dict[str, str]] = None
):
self.name = name
self.type = type
self.stateMutability = stateMutability
self.inputs = inputs
self.outputs = outputs
self.description = description
self.returns = returns

if self.eth_contract_address:
obj.update({'ethContractAddress': self.eth_contract_address})
def to_dict(self):
return convert_class_to_dict(self.__dict__)

if self.issuer_address:
obj.update({'issuerAddress': self.issuer_address})
class ContractUploadRequest:
def __init__(
self,
name: str,
description: str,
bytecode: str,
sourcecode: str,
abi: Optional[List[AbiFunction]] = None,
vendorId: Optional[str] = None,
compilerOutputMetadata: Optional[object] = None,
docs: Optional[object] = None,
attributes: Optional[Dict[str, str]] = None,
):
self.name = name
self.description = description
self.bytecode = bytecode
self.sourcecode = sourcecode
self.abi = abi
self.vendorId = vendorId
self.compilerOutputMetadata = compilerOutputMetadata
self.docs = docs
self.attributes = attributes

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

class PolicyTransactionType(str, Enum):
ANY = "*"
Expand Down
39 changes: 31 additions & 8 deletions fireblocks_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@
FEE_LEVEL,
PagedVaultAccountsRequestFilters,
TransactionDestination,
NFTOwnershipStatusValues,
IssueTokenRequest,
GetAssetWalletsFilters,
TimePeriod,
GetOwnedCollectionsSortValue,
GetOwnedNftsSortValues,
GetNftsSortValues,
OrderValues,
GetOwnedAssetsSortValues,
PolicyRule,
GetSmartTransferFilters,
NFTOwnershipStatusValues,
GetOwnedNftsSortValues,
GetNftsSortValues,
NFTsWalletTypeValues,
NFTOwnershipStatusUpdatedPayload,
CreateTokenRequest,
ContractUploadRequest,
ContractDeployRequest,
PagedExchangeAccountRequestFilters,
)
from .sdk_token_provider import SdkTokenProvider
Expand Down Expand Up @@ -98,11 +100,10 @@ def __init__(

def get_linked_tokens(self, limit: int = 100, offset: int = 0):
request_filter = {"limit": limit, "offset": offset}
url = f"/v1/tokenization/tokens"
return self._get_request(url, query_params=request_filter)
return self._get_request(f"/v1/tokenization/tokens", query_params=request_filter)

def issue_new_token(self, request: IssueTokenRequest):
return self._post_request("/v1/tokenization/tokens", request.serialize())
def issue_new_token(self, request: CreateTokenRequest):
return self._post_request("/v1/tokenization/tokens", request)

def get_linked_token(self, asset_id: str):
return self._get_request(f"/v1/tokenization/tokens/{asset_id}")
Expand Down Expand Up @@ -148,6 +149,28 @@ def approve_staking_provider(self, validator_provider_id: int):
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_nft(self, id: str):
url = "/v1/nfts/tokens/" + id

Expand Down
Loading