project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

Liquidity

Implementation of an Automated Market Maker (AMM) contract using PINT (Programming Intent Notation). Supports providing liquidity, removing liquidity, token swaps, staking LP tokens, and claiming rewards based on staking duration.

Liquidity

Created At

ETHGlobal San Francisco

Winner of

Essential - Best DeFi Application Written in Pint Runners Up

Project Description

This project is an implementation of an Automated Market Maker (AMM) smart contract using PINT (Programming Intent Notation). The contract supports providing liquidity, removing liquidity, token swaps, staking liquidity provider (LP) tokens, and claiming rewards based on staking duration.

Contract Features Provide Liquidity: Users can provide two tokens, Token A and Token B, to a liquidity pool and receive LP tokens representing their share. Remove Liquidity: Users can remove liquidity from the pool by redeeming their LP tokens for Token A and Token B. Swap Tokens: Users can swap between Token A and Token B. A fee is charged on swaps, which is distributed to liquidity providers. Staking Liquidity: Liquidity providers can stake their LP tokens to earn rewards over time. Claiming Rewards: Users who stake their LP tokens can claim rewards based on how long their tokens were staked.

How it's Made

The AMM project is built using a robust and scalable architecture. Here's a deep dive into how it was built:

Smart Contract Layer: The core of the project is the AMM smart contract, implemented using PINT (Programming Intent Notation). PINT allows for a structured representation of contract logic, which enhances the readability and security of the code. The contract includes functions for providing liquidity, removing liquidity, swapping tokens, staking LP tokens, and claiming rewards. PINT's expressiveness allowed us to simplify complex behaviors through macros such as @auth for authorization checks, and @init_once for state consistency.

Backend Infrastructure: The backend, entirely written in Rust, handles off-chain computations and interacts directly with the blockchain. Rust was chosen for its high performance and memory safety, making it ideal for managing critical financial transactions. The backend is responsible for processing requests from users, managing data consistency, and ensuring that all interactions with the blockchain are secure and efficient.

Security Measures: Security is a significant concern for any DeFi project. We employed Secp256k1Signature for signed transactions, a cryptographic algorithm known for its use in blockchain systems like Bitcoin. Additionally, PredicateAddress authorization mechanisms were used to ensure flexible, programmable access control, which makes our solution highly secure while allowing composability with other smart contracts. We also implemented nonce-based replay protection to secure transaction integrity.

Partner Technologies: To facilitate deployment and continuous integration, we used GitHub Actions for automating testing and deployments. This significantly reduced manual errors and ensured a smooth development workflow.

Hacky but Notable Workarounds: One particularly hacky approach worth mentioning is our use of state delta tracking to minimize gas costs during state transitions. Instead of updating the entire state, we track and update only the deltas—what has changed since the last transaction. This optimization led to reduced gas fees and more efficient execution of complex contract operations.

By combining PINT, Rust, and efficient deployment practices, we've built a robust, scalable, and efficient AMM that offers flexibility, security, and a solid user experience. Partner technologies like GitHub Actions enriched the platform, ensuring stability and consistent deployments.

background image mobile

Join the mailing list

Get the latest news and updates