Skip to main content

The IPOR Fusion SDK for Python

Project description

IPOR Fusion Python SDK

IPOR Fusion Python SDK

ipor_fusion package is the official IPOR Fusion Software Development Kit (SDK) for Python. It allows Python developers to write software, that interacts with IPOR Fusion Plasma Vaults smart contracts deployed on Ethereum Virtual Machine (EVM) blockchains.

ipor-fusion.py repository is maintained by IPOR Labs AG.

Workflow CI CD
Social Chat on Discord X (formerly Twitter) URL IPOR Official Broadcast
Code PyPI version GitHub License Python Version Code style: black

Install dependencies

poetry install

Setup ARBITRUM_PROVIDER_URL environment variable

Some node providers are not supported. It's working with QuickNode but not with Alchemy.

export ARBITRUM_PROVIDER_URL="https://..."

Run tests

poetry run pytest -v -s

Run pylint

poetry run pylint --rcfile=pylintrc.toml --verbose --recursive=y .

Run black

poetry run black ./

Example of usage

ALPHA_WALLET="0x..."

uniswap_v3_swap_fuse = UniswapV3SwapFuse(ARBITRUM.PILOT.V5.UNISWAP_V3_SWAP_FUSE)
ramses_v2_new_position_fuse = RamsesV2NewPositionFuse(ARBITRUM.PILOT.V5.RAMSES_V2_NEW_POSITION_FUSE)
ramses_claim_fuse = RamsesClaimFuse(ARBITRUM.PILOT.V5.RAMSES_CLAIM_FUSE)
plasma_vault = PlasmaVault(ARBITRUM.PILOT.V5.PLASMA_VAULT)
rewards_claim_manager = RewardsClaimManager(ARBITRUM.PILOT.V5.REWARDS_CLAIM_MANAGER)

swap = uniswap_v3_swap_fuse.swap(
    token_in_address=ARBITRUM.USDC,
    token_out_address=ARBITRUM.USDT,
    fee=100,
    token_in_amount=int(500e6),
    min_out_amount=0,
)

new_position = ramses_v2_new_position_fuse.new_position(
    token0=ARBITRUM.USDC,
    token1=ARBITRUM.USDT,
    fee=50,
    tick_lower=-100,
    tick_upper=100,
    amount0_desired=int(499e6),
    amount1_desired=int(499e6),
    amount0_min=0,
    amount1_min=0,
    deadline=int(time.time()) + 100,
    ve_ram_token_id=0,
)

tx_result = plasma_vault.execute([swap, new_position])

(_, new_token_id, _, _, _, _, _, _, _, _,) = ramses_v2_new_position_fuse.extract_data_form_new_position_enter_event(
    tx_result
)

claim_action = ramses_claim_fuse.claim(
    token_ids=[new_token_id],
    token_rewards=[[ARBITRUM.RAMSES.V2.RAM, ARBITRUM.RAMSES.V2.X_REM]],
)

# some time later ... claim RAM rewards
rewards_claim_manager.claim_rewards([claim_action])

ram_after_claim = rewards_claim_manager.balance_of(ARBITRUM.RAMSES.V2.RAM)

assert ram_after_claim > 0

# Transfer REM to ALPHA wallet
rewards_claim_manager.transfer(
    ARBITRUM.RAMSES.V2.RAM, ALPHA_WALLET, ram_after_claim
)

ram_after_transfer = ram.balance_of(ALPHA_WALLET)
assert ram_after_transfer > 0

usdc_before_swap_ram = usdc.balance_of(ALPHA_WALLET)

# swap RAM -> USDC
path = [ARBITRUM.RAMSES.V2.RAM, 10000, ARBITRUM.WETH, 500, ARBITRUM.USDC]
uniswap_v3_universal_router.swap(ARBITRUM.RAMSES.V2.RAM, path, ram_after_transfer)

usdc_after_swap_ram = usdc.balance_of(ALPHA_WALLET)

rewards_in_usdc = usdc_after_swap_ram - usdc_before_swap_ram
assert rewards_in_usdc > 0

# Transfer USDC to rewards_claim_manager
usdc.transfer(to=ARBITRUM.PILOT.V5.REWARDS_CLAIM_MANAGER, amount=rewards_in_usdc)

usdc_after_transfer = usdc.balance_of(ALPHA_WALLET)
assert usdc_after_transfer == 0

# Update balance on rewards_claim_manager
rewards_claim_manager.update_balance()
rewards_claim_manager_balance_before_vesting = rewards_claim_manager.balance_of(
    ARBITRUM.USDC
)
assert rewards_claim_manager_balance_before_vesting > 0

rewards_claim_manager.update_balance()

# One month later
anvil.move_time(DAY)
rewards_claim_manager.update_balance()

rewards_claim_manager_balance_after_vesting = rewards_claim_manager.balance_of(
    ARBITRUM.USDC
)

assert rewards_claim_manager_balance_after_vesting == 0

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

ipor_fusion-0.2.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

ipor_fusion-0.2.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file ipor_fusion-0.2.0.tar.gz.

File metadata

  • Download URL: ipor_fusion-0.2.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ipor_fusion-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0e514705adc4a35ff0b52cd489ffcd012a25e18dab631924b4615d680ea839df
MD5 f0265576b68f3f597f0fc6329444882b
BLAKE2b-256 e63489f85f61bbe31817e2cd3e37eceeb37d3a060d41f278e60d651ff8c83625

See more details on using hashes here.

File details

Details for the file ipor_fusion-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ipor_fusion-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ipor_fusion-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f6f8a0db1f5970b77ebad4204089ad2de1ce6eca28d2784887b61c631319b54
MD5 b6ff2202f074f8758e05c92cb0ecb141
BLAKE2b-256 9bdfd9181f92b8fc33cb568ad53026b44cb80123348512ac80ff7fa43432d722

See more details on using hashes here.

Supported by

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