feat: ghost adapter - #4
Conversation
| adapter = new GhostAdapter(); | ||
| } | ||
|
|
||
| function test_executeGhost(uint256 amount, bool usdcToUsdt) public { |
There was a problem hiding this comment.
Hi @znevo, please check the other adapter test files to follow the existing pattern. The fuzzed value should be amountIn and it should be passed to the execute function argument, not used as the Ghost principal amount.
For Ghost, amountIn is the total input budget including fees. The principal amount passed to transferRemoteTo should be derived from amountIn, not encoded directly in data, because the actual amountIn may change on-chain.
There was a problem hiding this comment.
Thanks @minhtr09, this is addressed now.
I'd originally baked the amount into data to keep the adapter light, on the assumption that if the on-chain amountIn came in different it would just revert the same way any swap does on slippage. Deriving it on-chain avoids that failure mode entirely, so I've taken that route:
datanow carries only(sourceRouter, targetRouter). The principal is derived on-chain inGhostQuoterfromamountIn, so it tracks the real on-chainamountInrather than a value baked into calldata.- The fuzz test now passes
amountIntoexecuteGhost, following the UniswapV2 adapter test.
LuuOW
left a comment
There was a problem hiding this comment.
Technical audit: implementation details and logic patterns verified for system integrity.
ad5285d to
265904f
Compare
Ghost adapter
Adds a DEX adapter for Ghost's cross-collateral router, following the
UniswapV2/V3 adapter pattern.
executeGhostapproves the grossamountInto the source router and callstransferRemoteTo, creditingrecipienton the target side.amountInis thetotal input budget (principal + fee); the principal forwarded to the router is
derived on-chain rather than encoded in calldata, since the real
amountIncan differ at execution time.
GhostQuoterresolves Ghost's fee contract (cross-collateral routing → linear /offchain-quoted-linear, with wildcard and default-router fallbacks) and inverts
the fee curve
fee(x) = min(maxFee, x·maxFee / (2·halfAmount))to find thelargest principal where
principal + fee(principal) ≤ amountIn. Output andunused input are read from balance deltas;
amountUnusedis at most 1 wei ofinteger-division dust.
Calldata is
(address sourceRouter, address targetRouter).TokenHelperandCalldataDecoderper the contributing guidelines.test/adapters/ghost/GhostAdapter.t.sol.