Skip to main content

StableSwap Analytics with Python

Project description

stableswappy

Python package for Stableswap V1 modelling

Install

To install package:

> git clone https://github.com/defipy-devs/stableswappy
> pip install .

or

> pip install StableswapPy

Stableswap

from stableswappy import *

user_nm = 'user_test'

user_nm = 'user_test'

AMPL_COEFF = 2000 

amt_dai = 79566307.559825807715868071
decimal_dai = 18

amt_usdc = 81345068.187939
decimal_usdc = 6

amt_usdt = 55663250.772939
decimal_usdt = 6

dai = ERC20("DAI", "0xA0b", decimal_dai)
dai.deposit(None, amt_dai)

usdc = ERC20("USDC", "0xf93", decimal_usdc)
usdc.deposit(None, amt_usdc)

usdt = ERC20("USDT", "0xd7c", decimal_usdt)
usdt.deposit(None, amt_usdt)

sgrp = StableswapVault()
sgrp.add_token(dai)
sgrp.add_token(usdc)
sgrp.add_token(usdt)

sfactory = StableswapFactory("Pool factory", "0x2")
exchg_data = StableswapExchangeData(vault = sgrp, symbol="LP", address="0x011")
lp = sfactory.deploy(exchg_data)

Join().apply(lp, user_nm, AMPL_COEFF)
lp.summary()

OUTPUT:

Stableswap Exchange: DAI-USDC-USDT (LP)
Reserves: DAI = 79566307.55982581, USDC = 81345068.187939, USDT = 55663250.772939
Liquidity: 216573027.91811988

Swap

usdc_before = lp.get_reserve(usdc)
usdt_before = lp.get_reserve(usdt)

amt_tkn_in = 10000
tkn_in = usdc
tkn_out = usdt
res = Swap().apply(lp, tkn_in, tkn_out, user_nm, amt_tkn_in)
lp.summary()

print(f"{amt_tkn_in} {tkn_in.token_name} was swapped for {res['tkn_out_amt']} {tkn_out.token_name}")

OUTPUT:

Stableswap Exchange: DAI-USDC-USDT (LP)
Reserves: DAI = 79566307.55982581, USDC = 81355068.187939, USDT = 55653253.910191
Liquidity: 216573027.91811988

10000 USDC was swapped for 9996.862748 USDT

Swap

usdc_before = lp.get_reserve(usdc)
dai_before = lp.get_reserve(dai)

amt_tkn_in = 10000
tkn_in = usdc
tkn_out = dai
res = Swap().apply(lp, tkn_in, tkn_out, user_nm, amt_tkn_in)
lp.summary()

print(f"{amt_tkn_in} {tkn_in.token_name} was swapped for {res['tkn_out_amt']} {tkn_out.token_name}")

Stableswap Exchange: DAI-USDC-USDT (LP)
Reserves: DAI = 79556308.6645169, USDC = 81365068.187939, USDT = 55653253.910191
Liquidity: 216573027.91811988

10000 USDC was swapped for 9998.895308918858 DAI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stableswappy-1.0.2.tar.gz (18.3 kB view details)

Uploaded Source

File details

Details for the file stableswappy-1.0.2.tar.gz.

File metadata

  • Download URL: stableswappy-1.0.2.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.0rc2

File hashes

Hashes for stableswappy-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ed715aff3b36dfa455e2d075b6830ebba13e22caff3ec0d6858ede577c819af1
MD5 77b9cbee70ca1766cdb7bf8a9cff7a1c
BLAKE2b-256 0aafc2b4e0335654a65b2ecb2f85aa50536e3f70fc92c6780ae13869cc5f35e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page