An open API service indexing awesome lists of open source software.

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

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)