Skip to content

The Partisia Blockchain Foundation provides the following reviewed smart contracts, as examples of decentralized finance problems with a blockchain solution.

License

Notifications You must be signed in to change notification settings

partisiablockchain/defi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Partisia Blockchain

DeFi: Smart Contracts for Decentralized Finance

Official Repository | Rustdoc | PBC Documentation

The Partisia Blockchain Foundation provides the following reviewed smart contracts, as examples of decentralized finance problems with a blockchain solution.

The Defi smart contracts repo is created as a collection of complex examples with a mature code base. If you are new to writing smart contracts on Partisia Blockchain we recommend you to visit our documentation and the example contracts.

Contracts Overview

Contracts:

  • token-v2: MPC-20 Token Contract. Basic contract used by most of the below contracts.
  • nft-v2: MPC-721 NFT Contract. Basic contract used by most of the below contracts.
  • liquidity-swap: Automated Market Maker Contract that allows users to exchange tokens, with an automatically selected exchange rate based on the available liquidity in the contract pools.
  • liquidity-swap-lock: Automated Market Maker with support for short-termed Option contract-likes.
  • zk-liquidity-swap: Automated Market Maker Contract with front-running protection, by using secret-sharing for inputs, preventing anyone from seeing the swap until it has been committed to.
  • nft-auction Auction contract that allows deployer to sell an NFT. Both NFT and bids are escrowed.
  • zk-deposit: Deposit smart contract that allows users to transfer token assets to other users using an alternative secret identity, without knowing the user's blockchain identity
  • dex-swap-factory: Deployment contract for liquidity-swap contracts.
  • conditional-escrow-transfer: Contract to facilitate conditional transfer of funds. The contract acts as a trustee in a value transaction with predetermined conditions.
  • liquid-staking: The Liquid Staking Contract allows token holdes to delegate the responsibility for staking to a third party (the staking responsible,) who has a responsibility to select good staking opportunities.
  • mocca: Decentralized Autonomous Organization capable of managing MPC-20 tokens through the use of conditional proposals.
  • swap-router: Routing contract that utilizes the swap lock functionality of the Liquidity Swap Lock Contract to perform swaps between different Tokens, that might not have a direct swap contract between them.
  • zk-order-matching: Order matching contract using secret-sharing to hide orders until a match have been found.
  • call-option: Call option contract allowing a buyer and seller to agree to exchange tokens in the future at a specified price.
  • weighted-voting: An election contract that weighs the vote based on how many tokens they owns. Only compatible with token-v2.

Shared libraries:

  • defi-common: Shared library for common functionality for defi contracts, including:
    • Math library for liquidity swapping.
    • Generalized permission system.
    • Data structures for tracking deposited token balances.
    • Shared logic for implementing tokens.

Deprecated Contracts:

  • token: Legacy MPC-20 Token Contract. Uses an inefficient storage system, which makes it expensive to use.
  • nft: Legacy MPC-721 NFT Contract. Uses an inefficient storage system, which makes it expensive to use.

Use-cases and Constellations

The contracts of this repository can be used for multiple use cases. The commonality is their use of either a token contact, or a NFT contract. Many contracts serve a stand-alone use-case, while others are mainly useful in archtypical constellation of smart contracts.

flowchart TD
 subgraph Common[" "]
        Token["MPC20 Token"]
        NFT["MPC721 NFT Contract"]
  end
 subgraph subGraph1["NFT Auction"]
        Auction["NFT Auction"]
  end
 subgraph subGraph2["Exchange Backend"]
        RoutingContract["Routing Contract"]
        Swap["Liquidity Swap Lock"]
        Deployer["Deployment Contract"]
  end
 subgraph subGraph3["Token-Fund DAO"]
        MOCCA["MOCCA Contract"]
  end
    Auction -- Transfer Token --> Token
    Auction -- Transfers NFT --> NFT
    Deployer -- Deploys --> Swap
    Deployer -- Informs of new Swap --> RoutingContract
    Swap -- Uses --> Token
    RoutingContract -- Routes between --> Swap
    MOCCA -- Manages Tokens Through --> Token

    style Common stroke:#FFFFFF00,fill:#FFFFFF00
Loading

The order matching and token splitter contracts combined allow for an order matching system on either outcome of an event. Here, the MPC20 Token used as the currency token could for example be another token contract.

flowchart TD

    OrderMatchingFalse["Order Matching
(False)"]
FalseToken["MPC20 Token
(False)"]
OriginalToken["Underlying MPC20 Token"]
TokenSplitter["Token Splitter"]
TrueToken["MPC20 Token
(True)"]
OrderMatchingTrue["Order Matching
(True)"]


FalseToken <-- Split/Merge/Redeem --> TokenSplitter
TrueToken <-- Split/Merge/Redeem --> TokenSplitter
FalseToken <-- Trade --> OrderMatchingFalse <-- Trade --> OriginalToken
TokenSplitter <-- Deposit/Withdraw --> OriginalToken
TrueToken <-- Trade --> OrderMatchingTrue <-- Trade --> OriginalToken

click OriginalToken "./rust/token-v2"
click TrueToken "./rust/token-v2"
click FalseToken "./rust/token-v2"
click OrderMatchingTrue "./rust/double-auction-order-matching"
click OrderMatchingFalse "./rust/double-auction-order-matching"
click TokenSplitter "./rust/prediction-market-token-splitter"
Loading

Usage

All smart contracts can be compiled using the Cargo Partisia Contract tool from the rust directory:

cargo pbc build --release

The --release argument ensures that contracts are minimized. Resulting contract .pbc files can be found in the rust/target/wasm32-unknown-unknown/release folder, and can be directly deployed to Partisia Blockchain.

Individual contracts can be compiled directly from the respective contract's directory.

Testing

The smart contract test suite is run by using the following script:

./run-java-tests.sh -bc

The -b argument ensure that contracts are rebuilt, while the -c argument results in a coverage report, located at contract-java-test/target/coverage.

About

The Partisia Blockchain Foundation provides the following reviewed smart contracts, as examples of decentralized finance problems with a blockchain solution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •