{"id":26519776,"url":"https://github.com/tarnadas/simple-amm-near","last_synced_at":"2025-10-09T13:10:00.897Z","repository":{"id":74591669,"uuid":"512463097","full_name":"Tarnadas/simple-amm-near","owner":"Tarnadas","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-13T08:22:28.000Z","size":251,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T01:23:08.527Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tarnadas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-07-10T14:57:32.000Z","updated_at":"2022-07-10T14:57:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ccad992-3307-4236-aaf0-7cc7856e01f0","html_url":"https://github.com/Tarnadas/simple-amm-near","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tarnadas/simple-amm-near","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarnadas%2Fsimple-amm-near","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarnadas%2Fsimple-amm-near/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarnadas%2Fsimple-amm-near/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarnadas%2Fsimple-amm-near/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tarnadas","download_url":"https://codeload.github.com/Tarnadas/simple-amm-near/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarnadas%2Fsimple-amm-near/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001542,"owners_count":26083102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-21T11:31:21.455Z","updated_at":"2025-10-09T13:10:00.891Z","avatar_url":"https://github.com/Tarnadas.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple AMM\n\nThis is a simple Automated Market Maker (AMM) Smart Contract that supports swapping two tokens.\nThe owner of the Smart Contract can add liquidity via sending the appropriate token.\nAll other users can then swap via sending one of the respective token.\n\n## Building\n\n- Install Rust via [Rustup](https://rustup.rs/)\n- Add WebAssembly tookchain: `rustup target add wasm32-unknown-unknown`\n- Compile this Smart Contract: `./build.sh`\n\n## Deployment\n\nMake sure to have [Near CLI](https://github.com/near/near-cli) installed: `npm install -g near-cli`.\nWe will create a subaccount where we deploy the contract.\n\n```bash\n# setup\nNEAR_ENV=testnet # change this to mainnet for prod\nMASTER_ACCOUNT=\nCONTRACT_ID=amm.$MASTER_ACCOUNT\n# the contract owner will be the only one who can add liquidity\nOWNER_ID=\n\n# Login\nnear login\n\n# create subaccount with 10 Near initially\nnear create-account $CONTRACT_ID --masterAccount $MASTER_ACCOUNT --initialBalance 10\n\n# deploy contract\nnear deploy --wasmFile res/orderly_contract.wasm --accountId $CONTRACT_ID\n```\n\n## Test tokens\n\nThere are plenty of test tokens on [Ref Finance](https://testnet.ref.finance/), that you can use.\nIf you want to you can also deploy your own test tokens, which are also used in integration tests.\nWe can also freely mint these tokens, which makes testing easy.\n\n```bash\nTOKEN_ID1=token-a.$MASTER_ACCOUNT\nTOKEN_ID2=token-b.$MASTER_ACCOUNT\n\nnear create-account $TOKEN_ID1 --masterAccount $MASTER_ACCOUNT --initialBalance 2\nnear deploy --wasmFile res/test_token.wasm --accountId $TOKEN_ID1\nnear call $TOKEN_ID1 new '{ \"name\": \"TokenA\", \"symbol\": \"TKNA\" }' --accountId $TOKEN_ID1\nnear call $TOKEN_ID1 mint '{ \"account_id\": \"'$OWNER_ID'\", \"amount\": \"1000000\" }' --accountId $TOKEN_ID1\n\nnear create-account $TOKEN_ID2 --masterAccount $MASTER_ACCOUNT --initialBalance 2\nnear deploy --wasmFile res/test_token.wasm --accountId $TOKEN_ID2\nnear call $TOKEN_ID2 new '{ \"name\": \"TokenB\", \"symbol\": \"TKNB\" }' --accountId $TOKEN_ID2\nnear call $TOKEN_ID2 mint '{ \"account_id\": \"'$OWNER_ID'\", \"amount\": \"1000000\" }' --accountId $TOKEN_ID2\n```\n\n## Initialization\n\n```bash\n# we now initialize amm contract\nnear call $CONTRACT_ID new '{ \"owner\": \"'$OWNER_ID'\" }' --accountId $CONTRACT_ID\n\n# we also need to setup the two tokens, that will be used in the liquidity pool for swapping\nnear call $CONTRACT_ID init '{ \"token_a\": \"'$TOKEN_ID1'\", \"token_b\": \"'$TOKEN_ID2'\" }' --accountId $CONTRACT_ID\n\n# and register contract for these tokens\nnear call $TOKEN_ID1 storage_deposit '{ \"account_id\": \"'$CONTRACT_ID'\" }' --accountId $CONTRACT_ID --deposit 1\nnear call $TOKEN_ID2 storage_deposit '{ \"account_id\": \"'$CONTRACT_ID'\" }' --accountId $CONTRACT_ID --deposit 1\n\n# owner now needs to add liquidity for both tokens\nnear call $TOKEN_ID1 ft_transfer_call '{ \"receiver_id\": \"'$CONTRACT_ID'\", \"amount\": \"1000000\", \"msg\": \"\" }' --accountId $OWNER_ID --depositYocto 1 --gas 300000000000000\nnear call $TOKEN_ID2 ft_transfer_call '{ \"receiver_id\": \"'$CONTRACT_ID'\", \"amount\": \"1000000\", \"msg\": \"\" }' --accountId $OWNER_ID --depositYocto 1 --gas 300000000000000\n```\n\n## Testing\n\nThe contract has various integration tests for testing the cross contract interactions.\nThese can be executed via `cargo test`.\n\nSince we now set up everything, we can also do manual testing of swap:\n\n```bash\n# let's do a quick check, if the contract set up the two tokens\nnear view $CONTRACT_ID get_contract_info\n# it should return metadata about the contract and the tokens with accountId, name, supply, symbol, decimals\n\n# setup swap user\nTEST_USER=user.$MASTER_ACCOUNT\nnear create-account $TEST_USER --masterAccount $MASTER_ACCOUNT --initialBalance 2\nnear call $TOKEN_ID1 mint '{ \"account_id\": \"'$TEST_USER'\", \"amount\": \"1000000\" }' --accountId $TOKEN_ID1\nnear call $TOKEN_ID1 mint '{ \"account_id\": \"'$TEST_USER'\", \"amount\": \"1000000\" }' --accountId $TOKEN_ID2\n\n# swap token-a for token-b\nnear call $TOKEN_ID1 ft_transfer_call '{ \"receiver_id\": \"'$CONTRACT_ID'\", \"amount\": \"1000\", \"msg\": \"\" }' --accountId $TEST_USER --depositYocto 1 --gas 300000000000000\n\n# check token balance\nnear view $TOKEN_ID1 ft_balance_of '{ \"account_id\": \"'$TEST_USER'\" }'\nnear view $TOKEN_ID2 ft_balance_of '{ \"account_id\": \"'$TEST_USER'\" }'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarnadas%2Fsimple-amm-near","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarnadas%2Fsimple-amm-near","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarnadas%2Fsimple-amm-near/lists"}