Below is my understanding on how Metamask swap works:
- User approves the Metaswap contract for their tokens they wanna swap
- When the user proceeds to execute the Metamask swap it calls the
_swap()
function which transfers the approved user's token to the Spender: - The user already provides the
adapterId
which makes adelegatecall
to the Adapter (1InchRouter, etc) where the actual swap happens: - The Adapter receives the swapped
tokenOut
which is "somehow" splits into the Metamask fees and sends the remaining to the user, DS Proxy which receives the fees:
I'm confused about the 4th step where is the logic for sending the funds to the suer and the DS Proxy?
Also why is the result of the delegatecall
not used in the Spender's swap()?