GEB Docs
  • Introduction to GEB
  • Community Resources
  • FLX Mechanics
  • FAQ
  • RAI
    • RAI Use-Cases
    • Multi-chain RAI
    • RAI Integrations
  • The Money God League
    • Intro to The League
  • Ungovernance
    • Governance Minimization Guide
  • Risk
    • GEB Risks
    • PID Failure Modes & Responses
  • Incentives
    • RAI Uniswap V2 Mint + LP Incentives Program
    • RAI Uniswap V3 Mint + LP Incentives Program (Inactive)
    • FLX Staking
    • RAI / ETH Uniswap V3 Oracle LP Incentives Program
  • Contract Variables Translation
    • Core Contracts Naming Transition
    • Governance Contracts Naming Transition
    • SAFE Management Contract Naming Transition
  • System Contracts
    • Core Module
      • SAFE Engine
      • Liquidation Engine
      • Accounting Engine
    • Auction Module
      • English Collateral Auction House
      • Fixed Discount Collateral Auction House
      • Increasing Discount Collateral Auction House
      • Debt Auction House
      • Surplus Auction House
    • Oracle Module
      • Oracle Relayer
      • Medianizer
        • DSValue
        • Governance Led Median
        • Chainlink Median
        • Uniswap V2 Median
      • FSM
        • Oracle Security Module
        • Dampened Security Module
        • FSM Governance Interface
    • Token Module
      • Token Adapters
      • System Coin
      • Protocol Token
      • Protocol Token Authority
      • Protocol Token Printing Permissions
    • Money Market Module
      • Tax Collector
    • Sustainability Module
      • Stability Fee Treasury
      • FSM Wrapper
      • Increasing Treasury Reimbursement
      • Mandatory Fixed Treasury Reimbursement
      • Increasing Reward Relayer
    • Automation Module
      • Collateral Auction Throttler
      • Single Spot Debt Ceiling Setter
      • ESM Threshold Setter
    • Governance Module
      • DSPause
    • Shutdown Module
      • Global Settlement
      • ESM
  • Proxy Infrastructure
    • DSProxy
    • Proxy Registry
  • Helper Contracts
    • SAFE Manager
  • GEB.js
    • Getting Started
    • Global Settlement Guide
    • API Reference
      • Geb
      • Safe
      • Proxy Actions
      • Geb Admin
  • APIs
    • API Endpoints
  • Pyflex
    • Getting Started
      • Configuration
      • GEB Basics
    • SAFE Management
      • Opening a SAFE
      • Closing a SAFE
    • Numerics
  • Keepers
    • Keeper Overview
    • Collateral Auction Keeper
      • Running in Docker
      • Running on a Host
      • Liquidations & Collateral Auctions
      • Collateral Auction Flash Swaps
    • Debt Auction Keeper
      • Running in Docker
      • Running on a Host
    • Staked Token Auction Keeper
      • Running in Docker
      • Running on a Host
    • Surplus Auction Keeper
      • Running in Docker
      • Running on a Host
    • Bidding Models
  • Liquidation Protection
    • SAFE Protection
    • Liquidation Protection Guide
    • Uni-V2 RAI/ETH Savior Details
    • Curve V1 Savior Details
Powered by GitBook
On this page

Was this helpful?

  1. Pyflex
  2. SAFE Management

Opening a SAFE

Steps to open a SAFE and withdraw system coins

Import all the necessary dependencies:

>>> from web3 import Web3, HTTPProvider
>>> from pyflex import Address
>>> from pyflex.deployment import GfDeployment
>>> from pyflex.keys import register_keys
>>> from pyflex.numeric import Wad 

Connect to an Ethereum node:

>>> ETH_RPC_URL = "http://localhost:8545"
>>> web3 = Web3(HTTPProvider(endpoint_uri=ETH_RPC_URL, request_kwargs={"timeout": 60}))

Set your account and keystore file and then enter your keystore password:

>>> web3.eth.defaultAccount ='0xdD1693BD8E307eCfDbe51D246562fc4109f871f8'
>>> register_keys(web3, ['key_file=key.json'])
Password for key.json: 
>>>

Instantiate an Address object to use later. Then, initialize a GEB object:

>>> our_address = Address(web3.eth.defaultAccount)
>>> geb = GfDeployment.from_node(web3=web3)

Currently ETH-A is the only supported collateral:

>>> collateral = geb.collaterals['ETH-A']

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!

>>> collateral.approve(our_address)
>>> geb.approve_system_coin(our_address)

Set the amount of collateral to deposit and the amount of debt to withdraw:

>>> collateral_amount = Wad.from_number(2.0)
>>> debt_amount = Wad.from_number(85)

deposit collateral and join it into the system:

>>> collateral.collateral.deposit(collateral_amount).transact()
>>> collateral.adapter.join(our_address, collateral_amount).transact()

Open a SAFE depositing the collateral and increasing your system coin balance in the SAFEEngine :

>>> geb.safe_engine.modify_safe_collateralization(collateral_type, our_address, delta_collateral=collateral_amount, delta_debt=debt_amount).transact()

Check your coin balance in the SAFEEngine :

>>> geb.safe_engine.coin_balance(our_address)
Rad(85000000000000000000000000000000000000000000)

exit system coin in ERC20 form:

>>> geb.system_coin_adapter.exit(our_address, debt_amount).transact()
PreviousSAFE ManagementNextClosing a SAFE

Last updated 4 years ago

Was this helpful?