Skip to content

Commit

Permalink
Updated files
Browse files Browse the repository at this point in the history
  • Loading branch information
yanlevi committed Apr 27, 2023
1 parent c8671f5 commit 99803cb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
FILE_PATH, MODE = "some/path/to/my/contract", "r"

if __name__ == "__main__":
# We start by building a bridge to the Ropsten network, including initiating a CustomToken object which will
# We start by building a bridge to the Goerli network, including initiating a CustomToken object which will
# represent our custom contract. In order to initiate a CustomToken, we will need a contract ABI. This can be read
# from another file, passed as a variable declared locally, or fetched from EtherScan using fetch_abi(address). We
# will use the first.
ropsten_bridge = Web3Bridge(SDK, VAULT_ID, CONTRACT_ADDRESS, Chain.ROPSTEN, WHITELISTED_CONTRACT_UUID)
goerli_bridge = Web3Bridge(SDK, VAULT_ID, Chain.GOERLI, CONTRACT_ADDRESS, WHITELISTED_CONTRACT_UUID)
with open(FILE_PATH, MODE) as file:
contract_abi = file.read()
custom_contract_bridge = CustomToken(ropsten_bridge, contract_abi)
custom_contract_bridge = CustomToken(goerli_bridge, contract_abi)

# Let's assume our ABI holds a transferOwnership write function, and a contractOwner function (returning a boolean).
# We will first validate we own the contract and then transfer it to another vault in our account.
checked_address = custom_contract_bridge.web_provider.to_checksum_address(custom_contract_bridge.wallet_address)
if custom_contract_bridge.call_read_function("contractOwner", checked_address):
# We will initiate another bridge, as we will need the wallet address, and we will later on transfer it back.
secondary_ropsten_bridge = Web3Bridge(SDK, SECONDARY_VAULT_ID, CONTRACT_ADDRESS, Chain.ROPSTEN,
WHITELISTED_CONTRACT_UUID)
secondary_contract_bridge = CustomToken(secondary_ropsten_bridge, contract_abi)
secondary_goerli_brdige = Web3Bridge(SDK, SECONDARY_VAULT_ID, Chain.GOERLI, CONTRACT_ADDRESS,
WHITELISTED_CONTRACT_UUID)
secondary_contract_bridge = CustomToken(secondary_goerli_brdige, contract_abi)
building_params = {"from": checked_address}
secondary_address = secondary_contract_bridge.web_provider.to_checksum_address(
secondary_contract_bridge.wallet_address)
Expand All @@ -40,7 +40,7 @@
building_params=building_params)

transfer_ownership_transaction = custom_contract_bridge.submit_transaction(transfer_ownership_raw_transaction)
if ropsten_bridge.check_tx_is_completed(transfer_ownership_transaction['id']) == TRANSACTION_STATUS_COMPLETED:
if goerli_bridge.check_tx_is_completed(transfer_ownership_transaction['id']) == TRANSACTION_STATUS_COMPLETED:
print("Successfully transferred ownership from first wallet to the second one.")
# We will now transfer the ownership back to our original wallet.
building_params['from'] = secondary_address
Expand All @@ -49,7 +49,7 @@
checked_address,
building_params=building_params)
ownership_transaction = secondary_contract_bridge.submit_transaction(ownership_raw_transaction, "Returning")
if secondary_ropsten_bridge.check_tx_is_completed(ownership_transaction['id']) == \
if secondary_goerli_brdige.check_tx_is_completed(ownership_transaction['id']) == \
TRANSACTION_STATUS_COMPLETED:
print("Successfully transferred ownership from second wallet to the first one.")
else:
Expand Down
10 changes: 5 additions & 5 deletions fireblocks_defi_sdk_py/tokenization/examples/erc20_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
TOKEN_AMOUNT = 10

if __name__ == "__main__":
# We start by building a bridge to the Ropsten network, including initiating a CustomToken object which will
# We start by building a bridge to the Goerli network, including initiating a CustomToken object which will
# represent our ERC20 contract. In order to initiate a CustomToken, we will need a contract ABI. This can be read
# from another file, passed as a variable declared locally, or fetched from EtherScan using fetch_abi(address). We
# will use the latter.
ropsten_bridge = Web3Bridge(SDK, VAULT_ID, CONTRACT_ADDRESS, Chain.ROPSTEN)
goerli_bridge = Web3Bridge(SDK, VAULT_ID, Chain.GOERLI, CONTRACT_ADDRESS)
contract_abi = fetch_abi(CONTRACT_ADDRESS)
erc20_contract_bridge = CustomToken(ropsten_bridge, contract_abi)
erc20_contract_bridge = CustomToken(goerli_bridge, contract_abi)

# We build functions through passing the function name exactly as it appears on the ABI, following by its arguments.
# It's important to differentiate between a read (view) and write function. We will demonstrate both.
Expand All @@ -39,15 +39,15 @@
building_params=building_params)
# We will now submit the transaction to Fireblocks.
mint_transaction = erc20_contract_bridge.submit_transaction(mint_raw_transaction)
if ropsten_bridge.check_tx_is_completed(mint_transaction['id']) == TRANSACTION_STATUS_COMPLETED:
if goerli_bridge.check_tx_is_completed(mint_transaction['id']) == TRANSACTION_STATUS_COMPLETED:
print(f"Successfully minted {TOKEN_AMOUNT} to {erc20_contract_bridge.wallet_address}")
transfer_raw_transaction = erc20_contract_bridge.call_write_function("transferFrom",
checked_address,
RECEIVER_ADDRESS, TOKEN_AMOUNT,
building_params=building_params)
transfer_transaction = erc20_contract_bridge.submit_transaction(transfer_raw_transaction,
"Transferring 10 minted tokens.")
if ropsten_bridge.check_tx_is_completed(transfer_transaction['id']):
if goerli_bridge.check_tx_is_completed(transfer_transaction['id']):
print(
f"Successfully transferred {TOKEN_AMOUNT} from {erc20_contract_bridge.wallet_address} to "
f"{RECEIVER_ADDRESS}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
TOKEN_IDS = [1, 2]

if __name__ == "__main__":
# We start by building a bridge to the Kovan network, including initiating a ERC1155 object.
kovan_bridge = Web3Bridge(SDK, VAULT_ID, CONTRACT, Chain.KOVAN)
multi_token_contract_bridge = ERC1155(kovan_bridge)
# We start by building a bridge to the Goerli network, including initiating a ERC1155 object.
goerli_bridge = Web3Bridge(SDK, VAULT_ID, Chain.GOERLI, CONTRACT)
multi_token_contract_bridge = ERC1155(goerli_bridge)

# ERC1155 implements all the basic capabilities mentioned in ERC721:
# https://ethereum.org/en/developers/docs/standards/tokens/erc-1155/
Expand All @@ -31,7 +31,7 @@
transfer_tokens = multi_token_contract_bridge.safe_batch_transfer_from(RECEIVER_ADDRESSES, TOKEN_IDS,
tokens_balance,
note="Transfer to another vault.")
transfer_result = kovan_bridge.check_tx_is_completed(transfer_tokens['id'])
transfer_result = goerli_bridge.check_tx_is_completed(transfer_tokens['id'])

if transfer_result == TRANSACTION_STATUS_COMPLETED:
print(f"{RECEIVER_ADDRESSES} now owns {tokens_balance} of tokens: {TOKEN_IDS}")
Expand Down
8 changes: 4 additions & 4 deletions fireblocks_defi_sdk_py/tokenization/examples/nft_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
TOKEN_ID = 1

if __name__ == "__main__":
# We start by building a bridge to the Ropsten network, including initiating a ERC721 object.
ropsten_bridge = Web3Bridge(SDK, VAULT_ID, CONTRACT_ADDRESS, Chain.ROPSTEN)
nft_contract_bridge = ERC721(ropsten_bridge)
# We start by building a bridge to the Goerli network, including initiating a ERC721 object.
goerli_bridge = Web3Bridge(SDK, VAULT_ID, Chain.GOERLI, CONTRACT_ADDRESS)
nft_contract_bridge = ERC721(goerli_bridge)

# ERC721 implements all the basic capabilities mentioned in ERC721:
# https://ethereum.org/en/developers/docs/standards/tokens/erc-721/
Expand All @@ -40,7 +40,7 @@
receiver_initial_balance = nft_contract_bridge.balance_of(RECEIVER_ADDRESS)
# safe_transfer_from returns a dictionary with a status and id.
transaction = nft_contract_bridge.safe_transfer_from(RECEIVER_ADDRESS, TOKEN_ID)
transaction_result = ropsten_bridge.check_tx_is_completed(transaction['id'])
transaction_result = goerli_bridge.check_tx_is_completed(transaction['id'])

if transaction_result == TRANSACTION_STATUS_COMPLETED:
# After the transaction has been completed we check whether the balance of the receiver has been updated
Expand Down
4 changes: 2 additions & 2 deletions fireblocks_defi_sdk_py/tokenization/tokens/base_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def call_write_function(self, abi_function: str, *args, building_params: dict =
"""
if not building_params:
building_params = {}
return self.contract.get_function_by_name(abi_function)(*args).buildTransaction(building_params)
return self.contract.get_function_by_name(abi_function)(*args).build_transaction(building_params)

def submit_transaction(self, transaction: dict, note: str = "") -> dict:
"""
Takes a ready transaction after being built (using web3 buildTransaction()) and transmits it to Fireblocks.
Takes a ready transaction after being built (using web3 build_transaction()) and transmits it to Fireblocks.
:param note:
:param transaction:
:return:
Expand Down
4 changes: 2 additions & 2 deletions fireblocks_defi_sdk_py/tokenization/tokens/erc1155.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def safe_transfer_from(self, to_address: str, token_id: int, amount: int, from_a
token_id,
amount,
data
).buildTransaction(address_dict)
).build_transaction(address_dict)

return self.submit_transaction(transaction, note)

Expand Down Expand Up @@ -83,7 +83,7 @@ def safe_batch_transfer_from(self, to_address: str, token_ids: List[int], values
token_ids,
values,
data
).buildTransaction(address_dict)
).build_transaction(address_dict)

return self.submit_transaction(transaction, note)

Expand Down
4 changes: 2 additions & 2 deletions fireblocks_defi_sdk_py/tokenization/tokens/erc721.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def safe_transfer_from(self, to_address: str, token_id: int, from_address: str =
checked_to_adr,
token_id,
data
).buildTransaction(address_dict)
).build_transaction(address_dict)

else:
transaction = self.contract.functions.safeTransferFrom(
checked_from_adr,
checked_to_adr,
token_id
).buildTransaction(address_dict)
).build_transaction(address_dict)

return self.submit_transaction(transaction, note)

Expand Down
2 changes: 1 addition & 1 deletion fireblocks_defi_sdk_py/web3_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, fb_api_client: FireblocksSDK,

def send_transaction(self, transaction: dict, note="") -> dict:
"""
Takes a ready transaction after being built (using web3 buildTransaction()) and transmits it to Fireblocks.
Takes a ready transaction after being built (using web3 build_transaction()) and transmits it to Fireblocks.
:param transaction: A transaction object (dict) to submit to the blockchain.
:param note: (Optional) A note to submit with the transaction.
:return:
Expand Down

0 comments on commit 99803cb

Please sign in to comment.