AMM now uses custom allocator to work around re-entrancy issues.