Description
We added swap_received() and deposit() to TinyAMM to solve the Soroban nested auth problem (contracts calling contracts that call require_auth). These functions accept pre-transferred tokens and don't require caller auth.
Changes made (in /tmp/tinyamm, not committed upstream)
swap.rs: Added swap_received(sell_token, sell_amount, min_buy, recipient) — same math as swap_exact_in but no require_auth, no transfer(from=trader), just sends output to recipient
lib.rs: Added deposit(to, amount0, amount1) — same LP math as add_liquidity but no require_auth, no token transfers (tokens already in contract)
Why
TinyAMM's swap_exact_in calls trader.require_auth() then token.transfer(trader, self, amount). When the Campaign Manager is the trader, it can't authorize these nested calls cleanly via authorize_as_current_contract(). The _received variants follow the same pattern as Hoops adapters (shallow-auth: pre-transfer then operate).
Action items
Description
We added
swap_received()anddeposit()to TinyAMM to solve the Soroban nested auth problem (contracts calling contracts that callrequire_auth). These functions accept pre-transferred tokens and don't require caller auth.Changes made (in /tmp/tinyamm, not committed upstream)
swap.rs: Addedswap_received(sell_token, sell_amount, min_buy, recipient)— same math asswap_exact_inbut norequire_auth, notransfer(from=trader), just sends output to recipientlib.rs: Addeddeposit(to, amount0, amount1)— same LP math asadd_liquiditybut norequire_auth, no token transfers (tokens already in contract)Why
TinyAMM's
swap_exact_incallstrader.require_auth()thentoken.transfer(trader, self, amount). When the Campaign Manager is the trader, it can't authorize these nested calls cleanly viaauthorize_as_current_contract(). The_receivedvariants follow the same pattern as Hoops adapters (shallow-auth: pre-transfer then operate).Action items
swap_receivedanddepositswap_receivedhas no auth — anyone can trigger a swap using tokens already in the contract. This is safe because you'd need to transfer tokens first, but document it.lp_transferauth — currently has norequire_authwhich is a security issue