Skip to content

Commit

Permalink
Merge branch 'master' into Add-rescan-txs
Browse files Browse the repository at this point in the history
  • Loading branch information
barakfireblocks committed Aug 20, 2024
2 parents 3ed0215 + 1c547be commit 5c7179e
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.9.0
current_version = 2.11.0
commit = false
tag = false

Expand Down
77 changes: 75 additions & 2 deletions fireblocks_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
TokenLinkStatus, \
TokenLinkType, \
ReadCallFunction, \
WriteCallFunction
WriteCallFunction, \
CreateCollectionRequest, \
MintCollectionTokenRequest, \
BurnCollectionTokenRequest
from .sdk_token_provider import SdkTokenProvider


Expand Down Expand Up @@ -405,6 +408,22 @@ def get_supported_assets(self):

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

def set_asset_price(self, id: str, currency: str, price: float):
"""Set asset price
Args:
id (str): The asset ID
currency (str): The currency (according to ISO 4217 currency codes)
price (str): The price in currency
"""

body = {
"currency": currency,
"price": price,
}

return self._post_request(f"/v1/assets/prices/${id}", body)

def get_vault_accounts_with_page_info(
self, paged_vault_accounts_request_filters: PagedVaultAccountsRequestFilters
):
Expand Down Expand Up @@ -2916,6 +2935,19 @@ def link_token(self, type: TokenLinkType, ref_id: str, display_name: Optional[st
"type": type,
"refId": ref_id,
}

if display_name:
body["displayName"] = display_name

return self._post_request(f"/v1/tokenization/tokens/link", body)

def link_contract_by_address(self, type: TokenLinkType, base_asset_id: str, contract_address: str, display_name: Optional[str] = None):
body = {
"type": type,
"baseAssetId": base_asset_id,
"contractAddress": contract_address,
}

if display_name:
body["displayName"] = display_name

Expand All @@ -2924,6 +2956,35 @@ def link_token(self, type: TokenLinkType, ref_id: str, display_name: Optional[st
def unlink_token(self, id: str):
return self._delete_request(f"/v1/tokenization/tokens/{id}")

def create_new_collection(self, request: CreateCollectionRequest):
return self._post_request("/v1/tokenization/collections", request.to_dict())

def get_linked_collections(self, status: Optional[TokenLinkStatus] = None, page_size: Optional[int] = None, page_cursor: Optional[str] = None):
request_filter = {}

if status:
request_filter["status"] = status.value

if page_size:
request_filter["pageSize"] = page_size

if page_cursor:
request_filter["pageCursor"] = page_cursor

return self._get_request("/v1/tokenization/collections", query_params=request_filter)

def get_linked_collection(self, id: str):
return self._get_request(f"/v1/tokenization/collections/{id}")

def unlinked_collection(self, id: str):
return self._delete_request(f"/v1/tokenization/collections/{id}")

def mint_nft(self, request: MintCollectionTokenRequest):
return self._post_request("/v1/tokenization/collections/tokens/mint", request.to_dict())

def burn_nft(self, request: BurnCollectionTokenRequest):
return self._post_request("/v1/tokenization/collections/tokens/burn", request.to_dict())

def get_contract_templates(
self,
initialization_phase: Optional[ContractInitializationPhase] = None,
Expand Down Expand Up @@ -2999,7 +3060,19 @@ def get_contract_by_address(self, base_asset_id: str, contract_address: str):

def get_contract_abi(self, base_asset_id: str, contract_address: str):
return self._get_request(f"/v1/contract_interactions/base_asset_id/{base_asset_id}/contract_address/{contract_address}/functions")


def fetch_or_scrape_abi(self, base_asset_id: str, contract_address: str):
return self._post_request("/v1/contracts/fetch-abi",{
"baseAssetId": base_asset_id,
"contractAddress": contract_address
})

def add_abi(self, base_asset_id: str, contract_address: str):
return self._post_request("/v1/contracts/abi",{
"baseAssetId": base_asset_id,
"contractAddress": contract_address
})

def read_contract_call_function(self, base_asset_id: str, contract_address: str, request: ReadCallFunction):
return self._post_request(f"/v1/contract_interactions/base_asset_id/{base_asset_id}/contract_address/{contract_address}/functions/read", request.to_dict())

Expand Down
48 changes: 48 additions & 0 deletions fireblocks_sdk/tokenization_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from .api_types import convert_class_to_dict

class CollectionLinkType(str, Enum):
NON_FUNGIBLE_TOKEN = "NON_FUNGIBLE_TOKEN"
SEMI_FUNGIBLE_TOKEN = "SEMI_FUNGIBLE_TOKEN"

class BaseDictClass(ABC):
def to_dict(self):
Expand Down Expand Up @@ -80,6 +83,51 @@ def __init__(
self.blockchain_id = blockchain_id
self.display_name = display_name

class CreateCollectionRequest(BaseDictClass):
def __init__(
self,
base_asset_id: str,
vault_account_id: str,
type: CollectionLinkType,
name: str,
admin_address: str,
display_name: Optional[str] = None,
):
self.base_asset_id = base_asset_id
self.vault_account_id = vault_account_id
self.type = type
self.name = name
self.admin_address = admin_address
self.display_name = display_name

class MintCollectionTokenRequest(BaseDictClass):
def __init__(
self,
to: str,
tokenId: str,
vaultAccountId: str,
amount: Optional[str] = None,
metadataURI: Optional[str] = None,
metadata: Optional[str] = None,
):
self.to = to
self.tokenId = tokenId
self.vaultAccountId = vaultAccountId
self.amount = amount
self.metadataURI = metadataURI
self.metadata = metadata


class BurnCollectionTokenRequest(BaseDictClass):
def __init__(
self,
tokenId: str,
vaultAccountId: str,
amount: Optional[str] = None,
):
self.tokenId = tokenId
self.vaultAccountId = vaultAccountId
self.amount = amount

class ContractDeployRequest(BaseDictClass):
def __init__(
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
setup(
name = 'fireblocks_sdk',
packages = ['fireblocks_sdk'],
version = '2.9.0',
version = '2.11.0',
license='MIT',
description = 'Fireblocks python SDK',
long_description="""Fireblocks python SDK""",
long_description_content_type='text/markdown',
url = 'https://github.com/fireblocks/fireblocks-sdk-py',
download_url = 'https://github.com/fireblocks/fireblocks-sdk-py/archive/v2.9.0.tar.gz',
download_url = 'https://github.com/fireblocks/fireblocks-sdk-py/archive/v2.11.0.tar.gz',
keywords = ['Fireblocks', 'SDK'],
install_requires=[
'PyJWT>=2.8.0',
Expand Down

0 comments on commit 5c7179e

Please sign in to comment.