https://github.com/drmick/near-amm-smart-contract
This contract shows the logic of the exchange tokens using AMM Liquidity pool
https://github.com/drmick/near-amm-smart-contract
amm blockchain defi near near-blockchain smart-contract
Last synced: over 1 year ago
JSON representation
This contract shows the logic of the exchange tokens using AMM Liquidity pool
- Host: GitHub
- URL: https://github.com/drmick/near-amm-smart-contract
- Owner: drmick
- Created: 2022-02-17T16:22:35.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-14T08:23:28.000Z (over 4 years ago)
- Last Synced: 2025-02-10T02:41:27.521Z (over 1 year ago)
- Topics: amm, blockchain, defi, near, near-blockchain, smart-contract
- Language: Rust
- Homepage:
- Size: 1.37 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Near AMM contract
#### This contract shows the logic of the exchange of tokens using AMM
#### You can see an example of how contracts work in [simulation tests](tests/sim)
#### Build
```
rustup target add wasm32-unknown-unknown
./build.sh
```
#### First you need to deploy FT tokens (example: deploy_ft_a.sh, deploy_ft_b.sh)
#### Next you need to setup FT and get tokens
```
export ID =
# Create contract with default meta
near call token_a.$ID new_default_meta '{"owner_id": "token_a.","total_supply": "1000000"}' --accountId $ID;
# Set storage deposit
near call token_a.$ID storage_deposit '{"account_id": "alice."}' --accountId $ID --deposit 1 --gas 25000000000000;
near call token_a.$ID storage_deposit '{"account_id": "amm."}' --accountId $ID --deposit 1 --gas 25000000000000;
# Send tokens to Alice
near call token_a.$ID ft_transfer '{"receiver_id": "alice.", "amount": "500000"}' --accountId token_a.$ID --depositYocto 1;
# For contract B, do the same
```
#### Next, you need to deploy and setup the AMM contract
```
# Init contract
near call amm.$ID new '{
"token_a_contract": "token_a.",
"token_b_contract": "token_b.",
"token_a_metadata": {
"spec": "ft-1.0.0",
"name": "Token A",
"symbol": "A",
"icon": null,
"reference": null,
"reference_hash": null,
"decimals": 4
},
"token_b_metadata": {
"spec": "ft-1.0.0",
"name": "Token B",
"symbol": "B",
"icon": null,
"reference": null,
"reference_hash": null,
"decimals": 4
}
}' --accountId amm.$ID;
# Set storage deposit to Alice
near call amm.$ID storage_deposit '{"token_name":"token_a.","account_id": "alice."}' --accountId amm.$ID --deposit 1 --gas 25000000000000;
```
For send tokens from FT to AMM use FT.ft_transfer_call
For add tokens to pool use AMM.add_tokens_to_pool
For exclude tokens from pool use AMM.exclude_tokens_from_pool
For swap tokens use AMM.swap
For withdraw tokens use AMM.withdraw_tokens
## Test
```
cargo test --all
```
## Problems
Floating point calculation not implemented. Rounding in Swap does not work correctly
cargo test not working on Mac M1 (wasmer error)