# AMM-ERC20 Project
### Bounty Program on Testnet
#### Target
The bug bounty program is focused around smart contracts of AMM and is mostly concerned with issues stated in the "Impacts and Level" section.
All bug reports must come with a PoC in order to be considered for a reward, bug reports without a PoC will be rejected.
Critical vulnerabilities for smart contracts are further defined by the following conditions. All need to be met in order to get the classification of critical.
* Allow attacker(s) to take away collateral tokens for at least 10% in dollar value of collateral tokens from the system.
* Are applied to a real situation and triggered through an attack vector rather than theory or hypothesis.
* Occur in operation mode or emergency shutdown mode, excluding those occurring during or shortly after the deployment when the system is yet to become fully activated.
Please note this Bug Bounty Program does not cover vulnerabilities pertaining to 1) protocols built by third-party developers (i.e., smart contract wallet); 2) ownership of an admin key.
Payouts are handled by the dForce team directly and are denominated in DF.
Only the following impacts are accepted within this bug bounty program. All other impacts are not considered as in-scope, even if they affect something in the assets in scope table.
#### Impacts and Level of bugs
* **Smart Contract**
* **Critical: Up to 100,000 DF**
* Direct theft of any user funds, whether at-rest or in-motion
* Permanent freezing of funds
* Protocol Insolvency
* **High: Up to 30,000 DF**
* Temporary freezing of funds
* Smart contract unable to operate due to lack of token funds
* Theft of gas
* **Low: 3,000 DF**
* Contract fails to deliver promised returns, but doesn't lose value
* **UI**
* **Critical: 3,000 DF**
* Direct theft of user funds
* Subdomain takeover with already-connected wallet interaction
---
### Requirement
Build a high-efficiency AMM protocol to support stable and universal assets exchange.
### How-To-Do
Which protocol could be based on, what is the advantages and flaws and how to improve it.
#### 🏈 Velodrome
align protocol emissions with fees generated https://docs.velodrome.finance/
- ***advantages***
1. support veNFT, vote/bribes
2. support stable & variable pools
3. on-chain voting
4. code based on solidly and audited by PeckShield, lots of improvement of solidly, here to refer: https://docs.velodrome.finance/protocol, https://docs.velodrome.finance/security
- ***flaws***
1. less effective on pegged assets and stablecoins
2. UI not open source
- ***how to improve*** (for reference, not decided yet)
1. introduce stable swap algorithm of [curve.fi V1](https://resources.curve.fi/base-features/understanding-curve)
2. support yield token pool [curve-compound](https://etherscan.io/address/0xa2b47e3d5c44877cca798226b7b8118f9bfb7a56) [curve-aave](https://etherscan.io/address/0xdebf20617708857ebe4f679508e7b7863a8a8eee)
3. introduce [Virtual Swap](https://docs.saddle.finance/saddle-faq#what-is-virtual-swap) for 'zero-slippage' exchange of BTC and ETH vs Stablecoins
#### 🏈 Saddle
solidity version of curve.fi V1
- ***advantages***
1. support stable pools with high efficiency
2. support BTCÐ variable pools leveraged by Synthetix's vSynths, named [virtual swap](https://docs.saddle.finance/saddle-faq#what-is-virtual-swap)
3. support veToken to boost LP incentives
4. on-chain voting
5. support flash-loan
6. UI&subgraph open source
7. algorithm based on curve.fi V1 but in Solidity, audited by [Certik/Quantstamp/OpenZepplin](https://docs.saddle.finance/smart-contract-audit)
- ***flaws***
1. do NOT support universal assets swap, such as DF/USX, LINK/USDC
- ***how to improve*** (for reference, not decided yet)
1. introduce one of the universal swap algorithms, such as [curve.if V2](https://resources.curve.fi/base-features/understanding-crypto-pools)/velodrome/uniswapV2
#### 🏈 Uniswap V2
most adopted universal amm, safe/open source and easy to fork
- ***advantages***
1. all-time most forked, simple, safe and well open-sourced(contracts, UI, subgraph)
2. support full-stack type swap
3. on-chain governance
4. support flash-loan
5. universal router support ERC20s and NFTs
6. well-audited
- ***flaws***
1. less effective on stable swap, such as pegged assets and stablecoins
- ***how to improve*** (for reference, not decided yet)
1. introduce stable swap algorithm of [curve.fi V1](https://resources.curve.fi/base-features/understanding-curve)
2. introduce [Virtual Swap](https://docs.saddle.finance/saddle-faq#what-is-virtual-swap) for 'zero-slippage' exchange of BTC and ETH vs Stablecoins
### Known Issues:
[Skyge]
- [When create pair for the type of volatile, can pass more than two tokens. eg: PairFactory.createPair([tokenA,tokenB,tokenC],1,0x)](https://github.com/dforce-network/dforce-amm/issues/1)
- Can set an exist pair type. eg: 1. PairFactory.setPairType(Impl_1) 2. Do step1 again: PairFactory.setPairType(Impl_1)
- `PairFactory.addPairType` can revert earlier.
```
function addPairType(address _impl) external onlyManager {
require(!pairImpls_.contains(_impl), "PairFactory: This pair type already exists");
xxx;
}
```
- When pass an empty array for `Router.getAmountsOutPath()`, e.g. `Router.getAmountsOutPath(100,[])`, it will revert.
- `Router.pairTypes_()` returns `router contract` rather than `pair contract`.
- `_addLiquidity()` can return `_amountA, _amountB and _pair`
### Reference
1. [solidly-ui source code](https://github.com/solidex-fantom/solidly-ui)