Skip to content

Add SuiDex - DEX on Sui#18758

Open
CryptoMischief wants to merge 1 commit intoDefiLlama:mainfrom
CryptoMischief:add-suidex
Open

Add SuiDex - DEX on Sui#18758
CryptoMischief wants to merge 1 commit intoDefiLlama:mainfrom
CryptoMischief:add-suidex

Conversation

@CryptoMischief
Copy link
Copy Markdown

@CryptoMischief CryptoMischief commented Apr 15, 2026

SuiDex

SuiDex is a Uniswap V2-style AMM DEX on Sui with 54 active trading pairs, yield farming (SuiFarm), and a VICTORY token locker.

Website: https://suidex.org
Contracts: https://gitlab.com/test-sm/suidex_contract

TVL Methodology

  • DEX TVL: Reads all pair object IDs from Factory.all_pairs on-chain array, batch-fetches Pair objects, sums reserve0 + reserve1 for each pool.
  • Staking: Reads locked VICTORY token balance from the Token Locker vault (LockedTokenVault.locked_balance).
  • Farm staked LP is NOT additive — actual token reserves remain in the Pair objects; LP tokens are receipts.

Contract Addresses

Object Address
Package 0xbfac5e1c6bf6ef29b12f7723857695fd2f4da9a11a7d88162c15e9124c243a4a
Factory 0x81c286135713b4bf2e78c548f5643766b5913dcd27a8e76469f146ab811e922d
Token Locker Vault 0x3632b8acce355fc8237998d44f1a68e58baac95f199714cdef5736d580dc6bf1

Test Output

------ TVL ------
sui                       206.27 k
total                     206.27 k

Adapter discovers all 54 pools and correctly prices 15 tokens (SUI, USDC, SUITRUMP, USDT, stSUI, wBTC, TRUTH, xBTC, WAL, BLUB, etc.).

Summary by CodeRabbit

  • New Features
    • Added SuiDex protocol support for tracking Total Value Locked (TVL) in liquidity pools and staking metrics for locked tokens.

SuiDex is a Uniswap V2-style AMM DEX on Sui with 54 active trading pairs,
yield farming (SuiFarm), and a VICTORY token locker.

TVL: Reads all pair IDs from Factory.all_pairs on-chain registry,
sums reserve0/reserve1 from each Pair object.

Staking: Reads locked VICTORY balance from the Token Locker vault.
Farm staked LP is not additive (reserves remain in pool objects).

Website: https://suidex.org
Contracts: https://gitlab.com/test-sm/suidex_contract
Factory: 0x81c286135713b4bf2e78c548f5643766b5913dcd27a8e76469f146ab811e922d
Package: 0xbfac5e1c6bf6ef29b12f7723857695fd2f4da9a11a7d88162c15e9124c243a4a
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

A new SuiDex module is introduced with TVL and staking functions. The TVL function fetches pools from a factory contract, parses token types, and accumulates reserves. The staking function fetches a locked token vault and accumulates locked balances for the VICTORY token type.

Changes

Cohort / File(s) Summary
SuiDex Module
projects/suidex/index.js
New module implementing TVL calculation via factory pool discovery and token reserve accumulation, plus staking logic for locked VICTORY tokens in a vault. Exports configuration with timetravel: false, methodology description, and async tvl and staking functions.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Module as SuiDex Module
    participant API
    participant Factory
    participant Pairs as Pair Contracts
    participant Accumulator

    Caller->>Module: tvl(api)
    Module->>API: getObject(FACTORY_ID)
    API->>Factory: fetch factory data
    Factory-->>API: factory object with all_pairs
    API-->>Module: factory data
    Module->>Module: extract pool IDs from all_pairs
    Module->>API: batchGetObjects(pair_ids)
    API->>Pairs: fetch all pairs
    Pairs-->>API: pair objects with types & reserves
    API-->>Module: batch pair data
    loop For each pair
        Module->>Module: parse token types from generic string
        Module->>Accumulator: addTokenReserves(token0, token1, amounts)
    end
    Accumulator-->>Caller: TVL accumulated
Loading
sequenceDiagram
    participant Caller
    participant Module as SuiDex Module
    participant API
    participant Vault
    participant Accumulator

    Caller->>Module: staking(api)
    Module->>API: getObject(VAULT_ID)
    API->>Vault: fetch vault data
    Vault-->>API: vault object with locked_balance
    API-->>Module: vault data
    Module->>Accumulator: addTokenBalance(VICTORY_TYPE, locked_balance)
    Accumulator-->>Caller: Staking accumulated
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A SuiDex treasure gleams so bright,
With pools and vaults in pooled delight!
TVL flows like carrots through the chain,
While VICTORY tokens in vaults remain,
One hop, two hops—our reserves align! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add SuiDex - DEX on Sui' clearly and concisely summarizes the main change: adding a new adapter for the SuiDex decentralized exchange on the Sui blockchain.
Description check ✅ Passed The pull request description comprehensively covers the project overview, TVL methodology, contract addresses, and test output, though it does not fill all optional template fields that would apply to a new listing submission.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

The adapter at projects/suidex exports TVL:

sui                       206.24 k
sui-staking               0.00
staking                   0.00

total                    206.24 k 

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@projects/suidex/index.js`:
- Around line 25-30: The pools.forEach destructuring can throw if an item is
undefined and the type string parsing is brittle; update the iteration over
pools so you skip falsy entries (check the item before destructuring) and add
null guards for fields (use optional chaining like fields?.reserve0 ??
fields?.reserve_0). Replace the fragile type parsing in the block that extracts
token types (currently using type.replace(">", "").split("<")[1].split(", "))
with a robust extractor (e.g., use a RegExp to capture the contents between
angle brackets and then split on comma, trimming results) and handle the case
where the regex fails by skipping the pool or logging a warning; ensure you
reference the same symbols (pools.forEach, type, fields, api.add) when making
these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 23f7b402-fa10-4300-aa10-ee7e5d1de2fd

📥 Commits

Reviewing files that changed from the base of the PR and between f4c0bef and 673fc25.

📒 Files selected for processing (1)
  • projects/suidex/index.js

Comment thread projects/suidex/index.js
Comment on lines +25 to +30
pools.forEach(({ type, fields }) => {
// Pair type: 0xPKG::pair::Pair<Token0Type, Token1Type>
const [token0, token1] = type.replace(">", "").split("<")[1].split(", ");
api.add(token0, fields.reserve0 ?? fields.reserve_0);
api.add(token1, fields.reserve1 ?? fields.reserve_1);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify helper return-shape assumptions used by this adapter
HELPER_FILE="$(fd -i 'sui.js' projects/helper/chain | head -n 1)"
echo "Sui helper file: ${HELPER_FILE}"

# Inspect getObject/getObjects implementations and any filtering/normalization
rg -n -A30 -B5 'getObject|getObjects|transform|map\(|filter\(' "${HELPER_FILE}"

# Compare how other Sui adapters parse generic Pair/Pool type strings
rg -n -C3 --type=js 'Pair<|Pool<|split\(", "\)|match\(/.*Pair<|match\(/.*Pool<' projects

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 17010


Harden pair parsing and pool iteration to prevent crashes on missing objects.

Line 27's string parsing is fragile (replace(">", "").split("<")[1].split(", ") assumes rigid format), and Line 25's destructuring ({ type, fields }) lacks null guards. If getObjects() returns any undefined items (possible when objectIds aren't found), the forEach crashes with TypeError.

🔧 Proposed fix
-  pools.forEach(({ type, fields }) => {
-    // Pair type: 0xPKG::pair::Pair<Token0Type, Token1Type>
-    const [token0, token1] = type.replace(">", "").split("<")[1].split(", ");
-    api.add(token0, fields.reserve0 ?? fields.reserve_0);
-    api.add(token1, fields.reserve1 ?? fields.reserve_1);
-  });
+  for (const pool of pools) {
+    if (!pool?.type || !pool?.fields) continue;
+    // Pair type: 0xPKG::pair::Pair<Token0Type, Token1Type>
+    const match = pool.type.match(/::pair::Pair<(.+?),\s*(.+)>$/);
+    if (!match) continue;
+
+    const [, token0, token1] = match;
+    const reserve0 = pool.fields.reserve0 ?? pool.fields.reserve_0;
+    const reserve1 = pool.fields.reserve1 ?? pool.fields.reserve_1;
+    if (reserve0 == null || reserve1 == null) continue;
+
+    api.add(token0.trim(), reserve0);
+    api.add(token1.trim(), reserve1);
+  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/suidex/index.js` around lines 25 - 30, The pools.forEach
destructuring can throw if an item is undefined and the type string parsing is
brittle; update the iteration over pools so you skip falsy entries (check the
item before destructuring) and add null guards for fields (use optional chaining
like fields?.reserve0 ?? fields?.reserve_0). Replace the fragile type parsing in
the block that extracts token types (currently using type.replace(">",
"").split("<")[1].split(", ")) with a robust extractor (e.g., use a RegExp to
capture the contents between angle brackets and then split on comma, trimming
results) and handle the case where the regex fails by skipping the pool or
logging a warning; ensure you reference the same symbols (pools.forEach, type,
fields, api.add) when making these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant