cosmos / ibc

Interchain Standards (ICS) for the Cosmos network & interchain ecosystem.
Other
929 stars 383 forks source link

ICS20-2: Add Token Forwarding ability to ICS20-2 #1090

Closed AdityaSripal closed 3 months ago

AdityaSripal commented 6 months ago

Allows users to atomically route their tokens through a series of paths with a single packet.

Desired properties:

Special thanks to the @strangelove-ventures team for working on the PFM middleware which serves as a precursor to this feature

jtieri commented 6 months ago

One important aspect of PFM is the ability to compose more complex user experiences by integrating multiple middleware in the stack together, so that you can essentially receive an ICS-20 transfer, perform some action on the intermediate chain, and then forward tokens to the destination

Example: A user wants to send tokens from a source chain to an intermediate chain. On the intermediate chain the funds will be received via OnRecvPacket, now that the funds are in the user account the tokens will be swapped in a liquidity pool for a new asset. If the swap is successful, forward the tokens received from the swap to a different account on a destination chain

With middleware this flow would involve wiring up the stack like this:

channel.OnRecvPacket
swap.OnRecvPacket
forward.OnRecvPacket
transfer.OnRecvPacket

Then when a packet comes in for an ICS-20 transfer, the swap middleware would call into the underlying app and that call would fall through to the transfer module so that the appropriate bookkeeping could take place to get funds into the user controlled account. Control would then be passed back up to the swap middleware where the swap could take place, the middleware would mutate the FungibleTokenPacketData so that the token denom and amount refer to the token that was received from the swap. Then control is passed to the forward middleware to initiate the forward.

Swap middleware

Bringing token forwarding into the ICS-20 protocol is amazing to hear, but I think preserving this type of composability for developers to build these more complicated experiences is an important aspect; otherwise, it becomes a bit less appealing.