Skip to content

Create Contract to send cw20 tokens over ics20 #238

Merged
ethanfrey merged 26 commits intomasterfrom
cw20-ics20-contract
Mar 10, 2021
Merged

Create Contract to send cw20 tokens over ics20 #238
ethanfrey merged 26 commits intomasterfrom
cw20-ics20-contract

Conversation

@ethanfrey
Copy link
Copy Markdown
Contributor

Closes #226

@ethanfrey ethanfrey force-pushed the cw20-ics20-contract branch from aaa5668 to 4480f4b Compare March 9, 2021 13:12
@ethanfrey ethanfrey marked this pull request as ready for review March 9, 2021 16:07
Copy link
Copy Markdown
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No time left for a proper require but I peeked and ❤️ it

let res = IbcReceiveResponse {
acknowledgement: ack_success()?,
messages: vec![msg],
// TODO: similar event messages like ibctransfer module
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following event is emitted:

			types.EventTypePacket,
			sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
			sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
			sdk.NewAttribute(types.AttributeKeyDenom, data.Denom),
			sdk.NewAttribute(types.AttributeKeyAmount, fmt.Sprintf("%d", data.Amount)),
			sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", err != nil)),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh.... this is a very important and very major issue!

packet and acknowledgements are never stored in the iavl tree, but rather their hashes are there and you need to get the preimage from the events.

When we submit SendPacket, this is handled in wasmd and should emit such a packet (need to check). Since the contract cannot create custom event types, we need to also auto-emit such an event in wasmd for acknowledgements. Otherwise we cannot relay such packets.

Copy link
Copy Markdown
Contributor Author

@ethanfrey ethanfrey Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, investigated a bit more. The ChannelKeeper manages all the essential events.

On SendPacket and WriteAcknowledgement

In wasmd, we call SendPacket on receiving the IbcMsg::SendPacket. However, I cannot find where WriteAcknowledgement is called.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: We return the acknowledgement from IbcModule.OnRecvPacket in x/wasm.

That is the same pattern that is used in ibctransfer and when digging deeper, I see that the acknowledgement is written by the ibc msg server.

So, it looks like we don't need to do anything here, but add some app-specific attributes

cur.outstanding = (cur.outstanding - amount)?;
Ok(cur)
},
)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand this block so I may go this wrong. The "no funds" is an IBC application level error that is part of the payload and should not result in an error that reverts the TX in the module.
See https://github.com/cosmos/cosmos-sdk/blob/v0.41.4/proto/ibc/core/channel/v1/channel.proto#L145

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are very correct here.
I made a separate function in 0844e34 so that I can catch the errors and turn them into "acknowledgement messages containing errors".

@ethanfrey ethanfrey force-pushed the cw20-ics20-contract branch from 8289d53 to 704e2af Compare March 10, 2021 15:18
@ethanfrey
Copy link
Copy Markdown
Contributor Author

ethanfrey commented Mar 10, 2021

Rebased with v0.14.0-beta1. Let's see if it passes CI now.

I'd like a review, but I guess I merge if no blockers and test with the relayer.

There will likely be a few more follow up PRs on this anyway, so happy for comments even after a merge

@ethanfrey ethanfrey merged commit 851e3b9 into master Mar 10, 2021
@ethanfrey ethanfrey deleted the cw20-ics20-contract branch March 10, 2021 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cw20-ics20 contract

3 participants