{"id":13408546,"url":"https://github.com/ashswap/ash-aggregator-sc","last_synced_at":"2025-03-14T13:31:35.638Z","repository":{"id":181670961,"uuid":"645175391","full_name":"ashswap/ash-aggregator-sc","owner":"ashswap","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-22T11:20:32.000Z","size":252,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-31T20:31:14.323Z","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/ashswap.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":"2023-05-25T04:56:47.000Z","updated_at":"2024-07-22T11:20:36.000Z","dependencies_parsed_at":"2023-07-16T19:34:29.618Z","dependency_job_id":"88ccf4a9-ac82-4e63-b957-f517b9de0487","html_url":"https://github.com/ashswap/ash-aggregator-sc","commit_stats":null,"previous_names":["ashswap/ash-aggregator-sc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashswap%2Fash-aggregator-sc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashswap%2Fash-aggregator-sc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashswap%2Fash-aggregator-sc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashswap%2Fash-aggregator-sc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashswap","download_url":"https://codeload.github.com/ashswap/ash-aggregator-sc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221472584,"owners_count":16828234,"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":[],"created_at":"2024-07-30T20:00:53.562Z","updated_at":"2024-10-25T23:31:01.566Z","avatar_url":"https://github.com/ashswap.png","language":"Rust","funding_links":[],"categories":["MultiversX community"],"sub_categories":["Smart contracts"],"readme":"# AshSwap Aggregator Smart Contract\n\nThis repository contains the Aggregator smart contract in AshSwap.\n\n## Overview\nAn aggregator service on the MultiversX blockchain, which facilitates the exchange of tokens across different liquidity pools. It handles the collection of fees for the protocol and a swap service (Ashswap), and allows users to claim these fees. The contract also supports the aggregation of ESDT tokens and EGLD, the native cryptocurrency.\n\n## State Variables\n- `protocol_fee`: A map storing the fees accumulated per protocol.\n- `ashswap_fee`: A map storing the fees accumulated for Ashswap.\n- `protocol_fee_percent`: The fee percentage for a given protocol.\n- `ashswap_fee_percent`: The fee percentage for Ashswap.\n- `ashswap_fee_address`: The address to which Ashswap fees are sent.\n\n## Flow Diagrams\n```mermaid\nsequenceDiagram\n    participant U as User\n    participant SC as Smart Contract\n    participant P as Protocol\n    participant A as Ashswap\n    U-\u003e\u003eSC: aggregateEgld(steps, limits, protocol)\n    alt EGLD aggregation\n        SC-\u003e\u003eSC: Wrap EGLD\n    end\n    U-\u003e\u003eSC: aggregateEsdt(steps, limits, protocol)\n    alt ESDT aggregation\n        SC-\u003e\u003eSC: Receive ESDT\n    end\n    SC-\u003e\u003eSC: Calculate fees\n    SC-\u003e\u003eP: Deduct protocol fees\n    SC-\u003e\u003eA: Deduct Ashswap fees\n    SC-\u003e\u003eSC: Execute token exchanges\n    SC-\u003e\u003eU: Send out token payments\n    SC-\u003e\u003eSC: Emit aggregate_event\n```\n\n## Functions Description\n\n- `init`: Initializes the contract with the EGLD wrapper address and wrapped token identifier.\n  ```mermaid\n  sequenceDiagram\n    participant User\n    participant Contract\n    User-\u003e\u003eContract: init(egld_wrapper_address, egld_wrapped_token_id)\n    Contract-\u003e\u003eContract: Store EGLD wrapper address\n    Contract-\u003e\u003eContract: Store EGLD wrapped token ID\n\n  ```\n- `_find_token_in_vault`: Searches for a token in the vault and returns its index.\n  ```mermaid\n  sequenceDiagram\n    participant Contract\n    Contract-\u003e\u003eContract: _find_token_in_vault(tokens, token_id)\n    loop Each Token in Vault\n        Contract-\u003e\u003eContract: Check if token_id matches\n    end\n    Contract-\u003e\u003eContract: Return index or None\n  ```\n- `_upsert_vaults`: Updates or inserts a token amount in the vault.\n  ```mermaid\n    sequenceDiagram\n    participant Contract\n    Contract-\u003e\u003eContract: _upsert_vaults(vaults, token_id, amount)\n    alt Token Found in Vault\n        Contract-\u003e\u003eContract: Update existing token amount\n    else Token Not Found\n        Contract-\u003e\u003eContract: Add new token with amount\n    end\n  ```\n- `_exchange`: Handles the exchange of tokens using a provided liquidity pool and updates the vaults accordingly.\n  ```mermaid\n  sequenceDiagram\n    participant Contract\n    participant Pool as Liquidity Pool\n    Contract-\u003e\u003eContract: _exchange(vaults, step)\n    Contract-\u003e\u003eContract: Validate token and amount\n    Contract-\u003e\u003ePool: Send token_in, execute exchange\n    Pool--\u003e\u003eContract: Return token_out\n    Contract-\u003e\u003eContract: Update vaults with token_out\n  ```\n- `_aggregate`: Aggregates multiple token exchanges and fee deductions, returns the final token payments.\n  ```mermaid\n    sequenceDiagram\n    participant Contract\n    Contract-\u003e\u003eContract: _aggregate(payments, steps, limits, protocol)\n    Contract-\u003e\u003eContract: Process incoming payments\n    Contract-\u003e\u003eContract: Deduct fees (if protocol provided)\n    loop Each Step\n        Contract-\u003e\u003eContract: Execute _exchange\n    end\n    Contract-\u003e\u003eContract: Enforce limits, prepare results\n  ```\n- `aggregate_egld`: Handles the aggregation operation when EGLD is involved.\n  ```mermaid\n    sequenceDiagram\n        participant User\n        participant Contract\n        User-\u003e\u003eContract: aggregateEgld(steps, limits, protocol)\n        Contract-\u003e\u003eContract: Wrap received EGLD\n        Contract-\u003e\u003eContract: Call _aggregate\n        Contract-\u003e\u003eUser: Send result tokens\n        Contract-\u003e\u003eContract: Emit aggregate_event\n  ```\n- `aggregate_esdt`: Handles the aggregation operation for ESDT tokens, with the option to return EGLD.\n  ```mermaid\n    sequenceDiagram\n        participant User\n        participant Contract\n        User-\u003e\u003eContract: aggregateEsdt(steps, limits, egld_return, protocol)\n        Contract-\u003e\u003eContract: Receive ESDT tokens\n        Contract-\u003e\u003eContract: Call _aggregate\n        alt egld_return is true\n            Contract-\u003e\u003eContract: Convert to EGLD if needed\n        end\n        Contract-\u003e\u003eUser: Send result tokens\n        Contract-\u003e\u003eContract: Emit aggregate_event\n  ```\n- `aggregate`: General aggregation endpoint for ESDT tokens.\n  ```mermaid\n  sequenceDiagram\n    participant User\n    participant Contract\n    User-\u003e\u003eContract: aggregate(steps, limits)\n    Contract-\u003e\u003eContract: Receive ESDT tokens\n    Contract-\u003e\u003eContract: Call _aggregate\n    Contract-\u003e\u003eUser: Send result tokens\n    Contract-\u003e\u003eContract: Emit aggregate_event\n    ```\n- `aggregate_event`: Emits an event after an aggregation operation.\n- `get_claimable_protocol_fee`: Retrieves claimable fees for a protocol in batches to avoid memory overflow.\n  ```mermaid\n  sequenceDiagram\n    participant Owner\n    participant Contract\n    Owner-\u003e\u003eContract: claimProtocolFee(protocol) / claimAshswapFee()\n    Contract-\u003e\u003eContract: Retrieve fee amounts in batches\n    Contract-\u003e\u003eOwner: Send claimed fees\n    ```\n- `register_protocol_fee`: Registers the fee percentage and address for a protocol.\n  ```mermaid\n  sequenceDiagram\n    participant Owner\n    participant Contract\n    Owner-\u003e\u003eContract: registerProtocolFee(fee_percent, whitelist_address) / registerAshswapFee(fee_percent, whitelist_address)\n    Contract-\u003e\u003eContract: Store fee percent and whitelist address\n    ```\n- `get_claimable_ashswap_fee`: Retrieves claimable Ashswap fees in batches.\n  ```mermaid\n  sequenceDiagram\n    participant Owner\n    participant Contract\n    Owner-\u003e\u003eContract: claimProtocolFee(protocol) / claimAshswapFee()\n    Contract-\u003e\u003eContract: Retrieve fee amounts in batches\n    Contract-\u003e\u003eOwner: Send claimed fees\n    ```\n- `register_ashswap_fee`: Registers the fee percentage and address for Ashswap.\n  ```mermaid\n  sequenceDiagram\n    participant Owner\n    participant Contract\n    Owner-\u003e\u003eContract: registerProtocolFee(fee_percent, whitelist_address) / registerAshswapFee(fee_percent, whitelist_address)\n    Contract-\u003e\u003eContract: Store fee percent and whitelist address\n    ```\n- `claim_protocol_fee`: Allows the protocol to claim their accumulated fees.\n- `claim_protocol_fee_by_tokens`: Allows the protocol to claim fees for specific tokens.\n- `claim_ashswap_fee`: Allows Ashswap to claim their accumulated fees.\n- `claim_ashswap_fee_by_tokens`: Allows Ashswap to claim fees for specific tokens.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashswap%2Fash-aggregator-sc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashswap%2Fash-aggregator-sc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashswap%2Fash-aggregator-sc/lists"}