{"id":25198183,"url":"https://github.com/drmick/near-amm-smart-contract","last_synced_at":"2025-04-04T17:20:47.436Z","repository":{"id":81250524,"uuid":"460513967","full_name":"drmick/near-amm-smart-contract","owner":"drmick","description":"This contract shows the logic of the exchange tokens using AMM Liquidity pool","archived":false,"fork":false,"pushed_at":"2022-03-14T08:23:28.000Z","size":1435,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T02:41:27.521Z","etag":null,"topics":["amm","blockchain","defi","near","near-blockchain","smart-contract"],"latest_commit_sha":null,"homepage":"","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/drmick.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}},"created_at":"2022-02-17T16:22:35.000Z","updated_at":"2022-03-17T18:58:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"cabf9b5e-3646-4f96-bf12-4dcb7b3ee9ab","html_url":"https://github.com/drmick/near-amm-smart-contract","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drmick%2Fnear-amm-smart-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drmick%2Fnear-amm-smart-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drmick%2Fnear-amm-smart-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drmick%2Fnear-amm-smart-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drmick","download_url":"https://codeload.github.com/drmick/near-amm-smart-contract/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217203,"owners_count":20903009,"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","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":["amm","blockchain","defi","near","near-blockchain","smart-contract"],"created_at":"2025-02-10T02:41:12.149Z","updated_at":"2025-04-04T17:20:47.431Z","avatar_url":"https://github.com/drmick.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Near AMM contract\n\n#### This contract shows the logic of the exchange of tokens using AMM\n#### You can see an example of how contracts work in [simulation tests](tests/sim)\n#### Build\n```\nrustup target add wasm32-unknown-unknown\n\n./build.sh\n```\n\n#### First you need to deploy FT tokens (example: deploy_ft_a.sh, deploy_ft_b.sh)\n\n#### Next you need to setup FT and get tokens\n\n```\nexport ID = \u003cyour root account ID\u003e\n\n# Create contract with default meta\nnear call token_a.$ID new_default_meta '{\"owner_id\": \"token_a.\u003cID\u003e\",\"total_supply\": \"1000000\"}' --accountId $ID;\n\n# Set storage deposit\nnear call token_a.$ID storage_deposit '{\"account_id\": \"alice.\u003cID\u003e\"}' --accountId $ID --deposit 1 --gas 25000000000000;\nnear call token_a.$ID storage_deposit '{\"account_id\": \"amm.\u003cID\u003e\"}' --accountId $ID --deposit 1 --gas 25000000000000;\n\n# Send tokens to Alice\nnear call token_a.$ID ft_transfer '{\"receiver_id\": \"alice.\u003cID\u003e\", \"amount\": \"500000\"}' --accountId token_a.$ID --depositYocto 1;\n\n# For contract B, do the same\n```\n#### Next, you need to deploy and setup the AMM contract\n\n```\n# Init contract \nnear call amm.$ID new '{\n    \"token_a_contract\": \"token_a.\u003cID\u003e\",\n    \"token_b_contract\": \"token_b.\u003cID\u003e\",\n    \"token_a_metadata\": {\n                          \"spec\": \"ft-1.0.0\",\n                          \"name\": \"Token A\",\n                          \"symbol\": \"A\",\n                          \"icon\": null,\n                          \"reference\": null,\n                          \"reference_hash\": null,\n                          \"decimals\": 4\n                        },\n\n    \"token_b_metadata\": {\n                          \"spec\": \"ft-1.0.0\",\n                          \"name\": \"Token B\",\n                          \"symbol\": \"B\",\n                          \"icon\": null,\n                          \"reference\": null,\n                          \"reference_hash\": null,\n                          \"decimals\": 4\n                        }\n            }' --accountId amm.$ID;\n\n\n# Set storage deposit to Alice\nnear call amm.$ID storage_deposit '{\"token_name\":\"token_a.\u003cID\u003e\",\"account_id\": \"alice.\u003cID\u003e\"}' --accountId amm.$ID --deposit 1 --gas 25000000000000;\n```\n\n\nFor send tokens from FT to AMM use FT.ft_transfer_call\n\nFor add tokens to pool use AMM.add_tokens_to_pool\n\nFor exclude tokens from pool use AMM.exclude_tokens_from_pool\n\nFor swap tokens use AMM.swap\n\nFor withdraw tokens use AMM.withdraw_tokens\n\n\n## Test\n```\ncargo test --all\n```\n\n## Problems\nFloating point calculation not implemented. Rounding in Swap does not work correctly\n\ncargo test not working on Mac M1 (wasmer error)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrmick%2Fnear-amm-smart-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrmick%2Fnear-amm-smart-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrmick%2Fnear-amm-smart-contract/lists"}