Conversation
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
📝 WalkthroughWalkthroughA 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
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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
The adapter at projects/suidex exports TVL: |
There was a problem hiding this comment.
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
| 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); | ||
| }); |
There was a problem hiding this comment.
🧩 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<' projectsRepository: 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.
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
Factory.all_pairson-chain array, batch-fetches Pair objects, sumsreserve0+reserve1for each pool.LockedTokenVault.locked_balance).Contract Addresses
0xbfac5e1c6bf6ef29b12f7723857695fd2f4da9a11a7d88162c15e9124c243a4a0x81c286135713b4bf2e78c548f5643766b5913dcd27a8e76469f146ab811e922d0x3632b8acce355fc8237998d44f1a68e58baac95f199714cdef5736d580dc6bf1Test Output
Adapter discovers all 54 pools and correctly prices 15 tokens (SUI, USDC, SUITRUMP, USDT, stSUI, wBTC, TRUTH, xBTC, WAL, BLUB, etc.).
Summary by CodeRabbit