LogoLogo
Swivel v2.0.0
Swivel v2.0.0
  • Swivel Finance Documentation
  • Litepaper
    • zcTokens
      • Exiting/Selling zcTokens
      • Secondary AMM's
    • nTokens
      • Exiting/Selling nTokens
    • AMM vs. Orderbook
  • Swivel Exchange
    • Testnet Setup
    • Exchange Functions
      • Fixed-Yield Lending
      • Purchasing nTokens
      • Selling zcTokens
      • Selling nTokens
      • Splitting/Combining Tokens
      • Redeeming Tokens/Interest
    • Maturity
    • Liquidity Incentives
    • Minimums, Rate Limits & Fees
    • Retroactive Distribution
    • How to Claim SWIV Tokens
  • Developers
    • Exchange API
      • GET
        • Orderbook
        • Get Order
        • OHCLV (Candles)
        • Get Effective Price (Preview Market Order)
        • Get Order History
        • Get Last Trade Info
        • Get Markets
      • POST
        • Order
    • Swivel.js
      • API
        • Swivel
        • MarketPlace
        • VaultTracker
    • Swivel.py
      • swivel
        • swivel.abstracts
          • swivel.abstracts.deployed
          • swivel.abstracts.market_place
          • swivel.abstracts.swivel
          • swivel.abstracts.vault_tracker
        • swivel.contracts
          • swivel.contracts.market_place
          • swivel.contracts.swivel
          • swivel.contracts.vault_tracker
        • swivel.vendors
          • swivel.vendors.signer
          • swivel.vendors.w3
    • Scrivel (Python Examples)
    • Contracts Overview
      • Contracts
        • Swivel
        • MarketPlace
        • VaultTracker
    • Ubiquitous Language V2
      • Shared Language
      • UI Language
      • Technical Language
      • Compound Language
      • Finance Terms
  • Community & Media
  • Other Resources
    • Institutions
      • Rate Profile Optimization
        • Instruments and Participants
        • Market Opportunities and Pricing
        • Counterparty Risk Management
        • Benefits and drawbacks of standardization
        • User Needs
          • Corporate Treasury and Funding
          • Institutional Investors and Asset Managers
          • Speculators and Proprietary Trading Functions
          • Brokers and Market Makers
          • Liquidity Management, Funding and Resource Management
          • Risk Management and Insurance
          • Smaller Institutions and Individuals
      • Swivel for Enterprise
        • Overview
        • How Swivel works
        • Flexible Order Book
        • Future Developments
      • Delegated Credit
        • Challenges of Delegated Credit
          • Credit Pools
          • Intermediating Trust in Credit Delegation
Powered by GitBook
On this page
  • installation
  • run the examples
  • todo
  1. Developers

Scrivel (Python Examples)

Scripting the Swivel Finance Protocol with Python

Previousswivel.vendors.w3NextContracts Overview

Last updated 2 years ago

PSA

We suggest you create a virtual environment for this and every python project.

Install/ensure compatable python version

This is a python project, i'm just going to assume you have a python available. If not, do that first. Scrivel expects at least a Python version of 3.7.3

Assure you have pip available

which pip. Depending on your system it may be aliased with ...3 so, which pip3. If not present install it.

With virtualenv

Once you have pip available use pip install --upgrade virtualenv (sudo it if you must...).

Now you are free to place the virtual environment for this project anywhere you want. This author uses a ~/python/ top level directory to house all virtualenvs (which this author makes for each python project).

virtualenv -p python3 ~/python/scrivel

With the env made, source it.

source ~/python/scrivel/bin/activate

Now you can move to installing things...

installation

Clone the , cd into the rood dir, (activate your virtual env if you have not) then

pip install -r requirements.txt

before you run the examples

Each of the files in /scrivel/examples needs its shebang modified to point to the python executable you created with virtualenv. For example if you followed the path above

#!/home/<your_user_name>/python/scrivel/bin/python

If not, just make it match wherever you put it.

private key

If you are performing transactions via the Swivel.py Vendor a private key is expected to be available in the shell environment as PRIVATE_KEY. This will be used to sign offline, your private key is never exposed or broadcast in any way.

Constants

You'll need to modify the constants located in /scrivel/constants/__init__.py:

  • HTTP_PROVIDER: (string) A suitable URL for a Web3.py HTTP Provider

  • WS_PROVIDER: (string) A suitable URL for a Web3.py WSS Provider

  • PUB_KEY: (string) Your public key you wish to use

  • MARKET_PLACE_ADDRESS: (string) The address of the deployed MarketPlace smart contract you want to interct with

  • SWIVEL_ADDRESS: (string) The address of the deployed Swivel smart contract you want to interct with

  • DAI_UNDERLYING: (string) Address for the underlying token of an active DAI market

  • DAI_MATURITY: (int) Maturity timestap (unix epoch in seconds) for the above active DAI market

  • VAULT_ADDRESS: (string) Address of the vault associated with the above active DAI market

note on the above DAI market

As an example, you could use the addresses from the currently deployed contracts on Rinkeby:

DAI_UNDERLYING = '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa'
DAI_MATURITY = 1669957199
VAULT_ADDRESS = '0xaEC3322CE4092a45b3B1B999c79B9F780E057BA5'

This is just one example market, it could, of course, be any other active market. USDC, etc... Feel free to make any constants you want for others obviously.

run the examples

python scrivel/examples/<foo>_<bar>.py

todo

Profit.

The example files can then be run by (assuming you are in the root dir)

repo
repo