GEB Docs
Search…
Opening a SAFE
Steps to open a SAFE and withdraw system coins
Import all the necessary dependencies:
1
>>> from web3 import Web3, HTTPProvider
2
>>> from pyflex import Address
3
>>> from pyflex.deployment import GfDeployment
4
>>> from pyflex.keys import register_keys
5
>>> from pyflex.numeric import Wad
Copied!
Connect to an Ethereum node:
1
>>> ETH_RPC_URL = "http://localhost:8545"
2
>>> web3 = Web3(HTTPProvider(endpoint_uri=ETH_RPC_URL, request_kwargs={"timeout": 60}))
Copied!
Set your account and keystore file and then enter your keystore password:
1
>>> web3.eth.defaultAccount ='0xdD1693BD8E307eCfDbe51D246562fc4109f871f8'
2
>>> register_keys(web3, ['key_file=key.json'])
3
Password for key.json:
4
>>>
Copied!
Instantiate an Address object to use later. Then, initialize a GEB object:
1
>>> our_address = Address(web3.eth.defaultAccount)
2
>>> geb = GfDeployment.from_node(web3=web3)
Copied!
Currently ETH-A is the only supported collateral:
1
>>> collateral = geb.collaterals['ETH-A']
Copied!
Setup your approvals in order to join/exit collateral and system coins in and out of the system.
These approve calls only need to be done once per address!
1
>>> collateral.approve(our_address)
2
>>> geb.approve_system_coin(our_address)
Copied!
Set the amount of collateral to deposit and the amount of debt to withdraw:
1
>>> collateral_amount = Wad.from_number(2.0)
2
>>> debt_amount = Wad.from_number(85)
Copied!
deposit collateral and join it into the system:
1
>>> collateral.collateral.deposit(collateral_amount).transact()
2
>>> collateral.adapter.join(our_address, collateral_amount).transact()
Copied!
Open a SAFE depositing the collateral and increasing your system coin balance in the SAFEEngine :
1
>>> geb.safe_engine.modify_safe_collateralization(collateral_type, our_address, delta_collateral=collateral_amount, delta_debt=debt_amount).transact()
Copied!
Check your coin balance in the SAFEEngine :
1
>>> geb.safe_engine.coin_balance(our_address)
2
Rad(85000000000000000000000000000000000000000000)
Copied!
exit system coin in ERC20 form:
1
>>> geb.system_coin_adapter.exit(our_address, debt_amount).transact()
Copied!
Last modified 1yr ago
Copy link