Skip to content

feat: add Machima DEX adapter for KyberSwap onchain execution - #5

Merged
minhtr09 merged 4 commits into
KyberNetwork:mainfrom
MachimaLabs:feat/machima-adapter
Jul 15, 2026
Merged

feat: add Machima DEX adapter for KyberSwap onchain execution#5
minhtr09 merged 4 commits into
KyberNetwork:mainfrom
MachimaLabs:feat/machima-adapter

Conversation

@0xvsr

@0xvsr 0xvsr commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Why did we need it?

On-chain Solidity adapter enabling KyberSwap's router to execute swaps through Machima DEX on Base. Machima is a Uniswap V3 fork with a custom tax layer and authorization system.

The adapter:

  • Receives tokenIn from KyberSwap's router
  • Approves and calls MachimaAggregatorRouter.swap()
  • Handles amountUnused for partial fills (XMA sells that hit the price floor)
  • Returns unused tokens to the caller

Deployed contracts (Base):

Contract Address
MachimaAggregatorRouter 0x566250347E1401615B3e043918fc290B98448578

Companion PR: MachimaLabs/kyberswap-dex-lib (off-chain liquidity source)

Related Issue

N/A — new integration.

Release Note

  • New adapter: MachimaAdapter
  • Targets MachimaAggregatorRouter which wraps the protocol's MachimaSwapAdapter with a standard aggregator interface
  • No special deployment requirements — the adapter is stateless and uses the router address passed via calldata

How Has This Been Tested?

  • Foundry fork tests against Base mainnet (MachimaAdapter.t.sol)
    • Buy path (WETH → XMA): verifies output > 0 and token delivery
    • Sell path (XMA → WETH): verifies output > 0 and token delivery
    • Invalid pair: verifies revert
    • Expired deadline: verifies revert
  • forge build clean

Screenshots (if appropriate):

N/A

Solidity adapter enabling KyberSwap's router to execute swaps through
MachimaAggregatorRouter. Handles token approval, swap execution, and
amountUnused (partial fill) for XMA sell floor scenarios.

Includes fork tests against Base mainnet.

Co-authored-by: Cursor <cursoragent@cursor.com>

@minhtr09 minhtr09 left a comment

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.

Hi @0xvsr, please allow edits by maintainers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@0xvsr

0xvsr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @minhtr09 — enabled 'allow edits by maintainers', and fixed the failing CI (it was forge fmt --check; reformatted the adapter files to the repo's fmt config). Should be green now.

@minhtr09 minhtr09 left a comment

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.

Hi @0xvsr, could you check your tests as well? I saw some failing tests.

…ells

The previous router address predates the _classifyPair fix (rejected
XMA/WETH) and stranded partial-fill residuals in the router; v1.1.0
(0xa25D1158B7Cf373DC3787793A52933dB0A0CaD89) refunds residuals to the
recipient. test_sellXmaForWeth now accepts the SwapFailed() revert that
occurs when the live pool price is pinned at the XMA sell floor — a
legitimate market state the off-chain simulator already skips.

Co-authored-by: Cursor <cursoragent@cursor.com>
@0xvsr

0xvsr commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@minhtr09 Fixed the failing tests — two things were wrong:

  1. The fork test pinned an outdated router deployment. Updated to AggregatorRouter v1.1.0 (0xa25D1158B7Cf373DC3787793A52933dB0A0CaD89, verified on Basescan). Same swap() signature; notable improvement for this adapter: on partial fills at the XMA sell floor, v1.1.0 refunds the unconsumed input to the recipient (the adapter), which is exactly what the amountUnused return value expects.
  2. test_sellXmaForWeth assumed sells always fill, but the XMA pool has an on-chain sell price floor — when the live price is pinned at the floor (as it is at some blocks), every sell reverts with SwapFailed(). The test now accepts that specific revert as valid (asserting the selector), and asserts the normal fill path whenever the floor isn't binding at the forked block.

All 6 tests pass locally against a live Base fork. Note the suite forks https://mainnet.base.org, so CI results can vary with public RPC rate limits — happy to gate the fork tests behind an env var if you'd prefer that for CI stability.

@0xvsr

0xvsr commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Hey @minhtr09 - thanks for the reviews so far, really appreciate the back-and-forth. Just checking in - the test fixes from my last push (3aeae05) address the failing tests you flagged:

  • Router updated to v1.1.0 (verified on Basescan)
  • XMA sell test now correctly handles the floor-pinned state
  • All 6 tests pass on a live Base fork

Happy to gate the fork tests behind an env var for CI stability if that's preferred, just let me know.

Is there anything else blocking approval? The companion off-chain PR (kyberswap-dex-lib#1483) is also ready, so once both land KyberSwap can start routing through Machima pools immediately.

@minhtr09 minhtr09 left a comment

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.

Hi @0xvsr, the CI still failed. Please make sure you use Foundry 1.7.1 and run forge fmt. Also, for the RPC, please read it from the env variable RPC_8453

- Read fork RPC from env variable RPC_8453 per repo convention
- Reformatted MachimaAdapter.sol with forge fmt (Foundry 1.7.1)
- All 6 tests pass

Co-authored-by: Cursor <cursoragent@cursor.com>
@0xvsr

0xvsr commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Hey @minhtr09 — thanks for the quick feedback, really appreciate how responsive you've been throughout this.

Both issues fixed in 34b1e6d:

  1. RPC: Tests now read from RPC_8453 env variable instead of hardcoding
  2. Formatting: Ran forge fmt with Foundry 1.7.1 — reformatted MachimaAdapter.sol

All 6 tests pass locally on a live Base fork. CI should be green now. Let me know if anything else is needed!

@minhtr09
minhtr09 merged commit e225232 into KyberNetwork:main Jul 15, 2026
1 check failed
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.

2 participants