https://github.com/clean-423/amm-twamm-contract
AMM Smart Contract that implemented the TWAMM protocol
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.0%) to scientific vocabulary
Keywords
Repository
AMM Smart Contract that implemented the TWAMM protocol
Basic Info
- Host: GitHub
- Owner: clean-423
- License: gpl-3.0
- Language: Solidity
- Default Branch: main_confirmed
- Homepage: https://pulsarswap.com/
- Size: 20.9 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
- Releases: 0
Topics
Metadata Files
README.md
Pulsar TWAMM
Introduction
Time-Weighted Average Market Maker (TWAMM) is a new on-chain market making model, designed by @_Dave__White_, @danrobinson and @haydenzadams. TWAMM allows market participants to efficiently execute large orders over multiple blocks on Ethereum.
Pulsar TWAMM is the first implementation of TWAMM. The math involved in TWAMM can be found in this article: https://hackmd.io/@luffy/SJxSsOH1Y
Implementation Notes
Overview
TWAMM.sol directly implements most of the standard AMM functionality (liquidity provision, liquidity removal, and swapping). The logic for execution of long term orders is split across two libraries, OrderPool.sol and LongTermOrders.sol.
Order Pool
The main abstraction for implementing long term orders is the Order Pool. The order pool represents a set of long term orders, which sell a given token to the embedded AMM at a constant rate. The token pool also handles the logic for the distribution of sales proceeds to the owners of the long term orders.
The distribution of rewards is done through a modified version of algorithm from Scalable Reward Distribution on the Ethereum Blockchain. Since order expiries are decopuled from reward distribution in the TWAMM model, the modified algorithm needs to keep track of additional parameters to compute rewards correctly.
Long Term Orders
In addition to the order pools, the LongTermOrders struct keep the state of the virtual order execution. Most importantly, it keep track of the last block where virtual orders were executed. Before every interaction with the embedded AMM, the state of virtual order execution is brought forward to the present block. We can do this efficiently because only certain blocks are eligible for virtual order expiry. Thus, we can advance the state by a full block interval in a single computation. Crucially, advancing the state of long term order execution is linear only in the number of block intervals since the last interaction with TWAMM, not linear in the number of orders.
Fixed Point Math
This implementation uses the PRBMath Library for fixed point arithmetic, in order to implement the closed form solution to settling long term trades. Efforts were made to make the computation numerically stable, but there's remaining work to be done here in order to ensure that the computation is correct for the full set of expected inputs.
How to run
```bash
Install dependencies
npm install
Compile contracts with hardhat
npx hardhat compile
Test contracts with hardhat
npx hardhat test ```
Contract Address
Mainnet
Factory:
TWAMM:
Ropsten
Factory:
TWAMM:
Owner
- Login: clean-423
- Kind: user
- Repositories: 1
- Profile: https://github.com/clean-423
GitHub Events
Total
- Push event: 1
- Pull request event: 10
- Create event: 33
Last Year
- Push event: 1
- Pull request event: 10
- Create event: 33
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 7 minutes
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 7 minutes
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- clean-423 (16)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- 1605 dependencies
- @nomiclabs/hardhat-ethers ^2.0.5 development
- @nomiclabs/hardhat-etherscan ^3.0.3 development
- @nomiclabs/hardhat-solhint ^2.0.0 development
- @nomiclabs/hardhat-waffle ^2.0.3 development
- @openzeppelin/contracts ^4.3.2 development
- @openzeppelin/contracts-upgradeable ^4.5.2 development
- chai ^4.3.6 development
- eslint ^7.32.0 development
- eslint-config-prettier ^8.5.0 development
- eslint-config-standard ^16.0.3 development
- eslint-plugin-import ^2.26.0 development
- eslint-plugin-node ^11.1.0 development
- eslint-plugin-prettier ^3.4.1 development
- eslint-plugin-promise ^5.2.0 development
- ethereum-waffle ^3.4.4 development
- ethers ^5.6.2 development
- hardhat ^2.9.3 development
- hardhat-gas-reporter ^1.0.8 development
- mocha ^9.2.1 development
- prb-math ^2.4.0 development
- prettier ^2.6.2 development
- prettier-plugin-solidity ^1.0.0-beta.18 development
- solhint ^3.3.7 development
- solidity-coverage ^0.7.20 development
- ts-node ^10.7.0 development
- typescript ^4.6.2 development
- @rari-capital/solmate ^6.2.0
- dotenv ^10.0.0
- hardhat-deploy ^0.9.4
- 1447 dependencies