Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swap): add an option not to withdraw swapped ZRC20 #96

Closed
wants to merge 3 commits into from

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 14, 2023

No description provided.

@fadeev
Copy link
Member Author

fadeev commented Nov 14, 2023

@andresaiello this is a proposal to extend the swap example to handle a scenario where a user wants to keep the swapped ZRC-20 asset instead of immediatly withdrawing it. This might seem odd, but I'm building an example frontend where I want users to be able to transfer/swap/withdraw/deposit all tokens to all other tokens. One of the few operations left is "deposit and swap":

Screenshot 2023-11-14 at 13 03 43

Want to know your opinion on this. Even though not withdrawing might seem odd (most users will want to withdraw), having this swap component talk to this example contract would make it component also a demo of the example contract.

@fadeev
Copy link
Member Author

fadeev commented Nov 14, 2023

@andresaiello another question I have is adapting bytesToAddress function to work with bytes memory:

function bytesToAddress(
bytes memory data,
uint256 offset
) internal pure returns (address output) {
bytes memory b = new bytes(20);
for (uint256 i = 0; i < 20; i++) {
b[i] = data[i + offset];
}
assembly {
output := mload(add(b, 20))
}
}

Of course, we already have a helper for this, but it's only for calldata, not memory:

https://github.com/zeta-chain/toolkit/blob/a902bea0581b284a59d66a2c9ae547d3b0cdc93c/contracts/BytesHelperLib.sol#L15-L23

Would it be a good idea to add the bytes memory version as another helper (if so, do you have any suggestions on the name), and if not, what's the better way to handle this.

@andresaiello
Copy link
Collaborator

bytesToAddress

good idea. I didn't need it yet but looks like someone may need it. Let's just call it bytesMemoryToAddress

@fadeev
Copy link
Member Author

fadeev commented Nov 21, 2023

@andresaiello wdyt about the changes to contract in general? The ability to not withdraw tokens during swap may seem a bit niche, but it has a few advantages: it matches the requirements of the example frontend (to be able to swap gas/ERC-20 to ZRC-20 without withdrawing) and uses the same pattern of action as in staking. Maybe this means we even need to change the default template to use action, because it might be common for omnichain contracts to be able to execute different logic from the same onCrossChainCall.

@fadeev
Copy link
Member Author

fadeev commented Feb 19, 2024

We need to update this PR to be compatible with the code as it is in the main branch.

@fadeev
Copy link
Member Author

fadeev commented May 9, 2024

Going to implement this next as a third part of the swap tutorial:

  • Basic
  • With ZETA
  • With not withdrawals

To simplify things I'm probably not going to use an action integer prefix, but add it as an optional last argument in the message.

@fadeev fadeev closed this May 9, 2024
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.

2 participants