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

✨ [API-1723] Add CW20 Support #67

Merged
merged 97 commits into from
Nov 15, 2023
Merged

✨ [API-1723] Add CW20 Support #67

merged 97 commits into from
Nov 15, 2023

Conversation

NotJeremyLiu
Copy link
Member

@NotJeremyLiu NotJeremyLiu commented Sep 12, 2023

Background

  • Skip API Contracts currently only supports native coin types, not cw20 tokens for cosmwasm-enabled chains.

This PR

This PR adds support for CW20 tokens:

  1. Creates a new Asset type that handles cases for both native coins and cw20 tokens, implementing many helper methods to convert the asset into required types, do accounting, and handle validation.
  2. Replaces all the places in the entry point and swap adapter contracts that need to support both native coins and cw20 with the Asset type (instead of the Coin type).
  3. Adds cw20 receive entry points in entry point and swap adapter contracts to accept cw20 send messages from cw20 contracts.
  4. Adds tests for the Asset type
  5. Updates existing tests

How to Review

  1. First review the new asset.rs file in the skip packages folder, this is the main type implemented to handle cw20 token support and where all the methods of conversion are (unit tests are in the same file)
  2. Then review the entry point contract and adapters. The change in entry point and swap adapter are largely the new receive function to accept cw20 send messages, and then replacing everywhere where it could be cw20 or native from a Coin type into an Asset type, and using the methods on Asset to convert.

Interface Breaking Changes

  1. The min_coin param (type: Coin) sent with the swap_and_action entry point contract calls has been changed to a min_asset param (type: Asset).

Rust types:

#[cw_serde]
pub enum Asset {
    Native(Coin),
    Cw20(Cw20Coin),
}

pub struct Coin {
    pub denom: String,
    pub amount: Uint128,
}

pub struct Cw20Coin {
    pub address: String,
    pub amount: Uint128,
}

Json format of native coin:

{
    "native": {
        "denom": "ibc/C4C...",
        "amount": "10"
}

Json format of cw20 token:

{
    "cw20": {
        "address": "neutron123...",
        "amount": "10"
}
  1. The PostSwapAction::BankSend enum variant has been changed to PostSwapAction::Transfer to be inclusive of both coins and cw20 token transfers.
  2. The non-cw20 entrypoints now require a sent_asset param, where the caller must specify what asset they sent to the contract (which gets validated).
  3. There is now a cw20 entry point following the cw20 standard

- also runs make update and make upgrade
- No changes made to the ExecuteMsg::Swap since Osmosis does not support cw-20 tokens
@NotJeremyLiu NotJeremyLiu changed the title ✨ Add CW20 Support ✨ [API-1723] Add CW20 Support Nov 8, 2023
@NotJeremyLiu NotJeremyLiu merged commit 08771a9 into main Nov 15, 2023
5 checks passed
@NotJeremyLiu NotJeremyLiu deleted the jl/cw20-support branch November 15, 2023 02:00
@NotJeremyLiu NotJeremyLiu restored the jl/cw20-support branch November 15, 2023 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interface-breaking changes that break the user-facing interface to call the contract
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants