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
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
e656baa
➕ add cw20 to workspace cargo.toml
NotJeremyLiu Aug 24, 2023
6ee9ce4
➕ add cw20 to packages cargo.toml
NotJeremyLiu Aug 24, 2023
9ba0df9
✨ implement ability for entrypoint to receive cw20 token and dispatch…
NotJeremyLiu Aug 24, 2023
a9a2dc5
✨ Implement basic Asset type
NotJeremyLiu Aug 24, 2023
e2cd249
✨ Implement sent asset validation, transfer_partial, and add sent ass…
NotJeremyLiu Aug 31, 2023
c656fc6
Add todos in entry point execute.rs for cw-20 support
NotJeremyLiu Aug 31, 2023
25623d6
🚧 Add swap adapter todos for cw-20 support
NotJeremyLiu Aug 31, 2023
b8bbd4b
✅ Add asset tests
NotJeremyLiu Sep 1, 2023
926078e
⚡️ Add nonpayable to sent cw20 token validate
NotJeremyLiu Sep 7, 2023
1950df4
✅ Add invalid tests to asset validation
NotJeremyLiu Sep 7, 2023
c844357
✅ add more than one coin test to asset validation, run make fmt
NotJeremyLiu Sep 7, 2023
beca6b3
✨ implement sub method
NotJeremyLiu Sep 7, 2023
6ac9ca2
♻️ convert remaining_coin to asset in entry point contract
NotJeremyLiu Sep 7, 2023
1271a0c
✨ Implement swap method on asset type
NotJeremyLiu Sep 7, 2023
e2b2e5e
✨ Implement astroport swap operation conversion with cw20 support
NotJeremyLiu Sep 7, 2023
2b575de
✨ Update astroport swap contract for cw20 support
NotJeremyLiu Sep 7, 2023
8f67726
✨ Update osmosis swap adapter to support Asset type in query messages
NotJeremyLiu Sep 7, 2023
e2ff5e4
⚡️ reduce unnecessary code in cw20 validation
NotJeremyLiu Sep 8, 2023
45f421f
✨ implement more functionality onto Asset type
NotJeremyLiu Sep 8, 2023
3e31f2b
♻️ Change min_coin to min_asset
NotJeremyLiu Sep 8, 2023
0453c42
✨ Update swap methods for cw20 support
NotJeremyLiu Sep 8, 2023
44bb0a8
✨ Update entry point contract for cw20 support
NotJeremyLiu Sep 8, 2023
6e11d24
✨ Update swap adapter contracts for cw20 support
NotJeremyLiu Sep 8, 2023
a6e4160
Update user_swap_tests for cw20 support
NotJeremyLiu Sep 8, 2023
93f4384
✅ update execute swap and action test for asset type
NotJeremyLiu Sep 8, 2023
f0119ae
✅ update execute post swap action tests for asset type
NotJeremyLiu Sep 8, 2023
170edbc
🎨 run make fmt
NotJeremyLiu Sep 8, 2023
f693cc5
✅ Update osmosis swap adapter tests for asset type
NotJeremyLiu Sep 8, 2023
f2b05d4
✅ Update astroport swap adapter tests for asset type
NotJeremyLiu Sep 8, 2023
e52f405
✅ update user swap tests for asset type
NotJeremyLiu Sep 8, 2023
a5ff1c5
⬆️ run make update
NotJeremyLiu Sep 8, 2023
57e3e99
⬆️ run make upgrade
NotJeremyLiu Sep 8, 2023
2ee5801
📝 Update schemas
NotJeremyLiu Sep 8, 2023
4bb6490
🐛 add .PHONY to makefile
NotJeremyLiu Sep 8, 2023
206e828
🐛 properly query cw20 balance in post swap logic
NotJeremyLiu Sep 11, 2023
9b8a414
✨ Add receive entrypoint to astroport swap adapter
NotJeremyLiu Sep 11, 2023
ee6169a
✨ add Asset::new() method
NotJeremyLiu Sep 12, 2023
aacafe6
✅ add get_current_asset_available test
NotJeremyLiu Sep 12, 2023
a81a63c
⚡️ Consolidate the diff type into_wasm_msg methods into a single method
NotJeremyLiu Sep 12, 2023
94c48fd
♻️ reduce re-written code
NotJeremyLiu Sep 12, 2023
2f14ba2
🔥 only have a transfer method on asset, removed unused method
NotJeremyLiu Sep 12, 2023
8b05d6f
♻️ Have new Asset method take in Api instead of DepsMut
NotJeremyLiu Sep 12, 2023
44dee55
♻️ use new Asset method in astroport swap adapter contract
NotJeremyLiu Sep 12, 2023
808c043
✨ Update osmosis swap adapter for queries to return asset type
NotJeremyLiu Sep 12, 2023
438857e
✨ add into_astroport_asset method for Asset and use in astro swap ada…
NotJeremyLiu Sep 12, 2023
8f181b8
🔥 Remove todo
NotJeremyLiu Sep 12, 2023
7889a03
♻️ Rename NeutronInstantiateMsg to AstroportInstantiateMsg
NotJeremyLiu Sep 12, 2023
c134ad3
♻️ Use Asset::new in transfer_funds_back function
NotJeremyLiu Sep 12, 2023
c716a1d
⚡️ Remove need for sent_asset in entry point contract call
NotJeremyLiu Sep 12, 2023
f7e8047
⚡️ Set entry point contract address as sender on cw20 receive in astr…
NotJeremyLiu Sep 12, 2023
84c8c9a
⚡️ Remove required sent_asset param to swap adapters
NotJeremyLiu Sep 12, 2023
0e4b1fe
✏️ small clean up
NotJeremyLiu Sep 12, 2023
b76dd1c
Merge branch 'main' into jl/cw20-support
NotJeremyLiu Sep 22, 2023
e8a6db7
🚀 Update deployed contracts: neutron testnet
NotJeremyLiu Sep 24, 2023
7ca5cc8
🚀 Update deployed contracts: neutron mainnet
NotJeremyLiu Sep 24, 2023
6adaf9a
🚀 Update deployed contracts: osmosis testnet
NotJeremyLiu Sep 24, 2023
39eaf6c
🚀 Update deployed contracts: osmosis mainnet
NotJeremyLiu Sep 24, 2023
4dff128
🚀 Update deployed contracts: terra testnet
NotJeremyLiu Sep 24, 2023
be75827
🚀 Update deployed contracts: terra mainnet
NotJeremyLiu Sep 24, 2023
a9100fc
Merge branch 'main' into jl/cw20-support
NotJeremyLiu Nov 3, 2023
0299869
change recover entrypoint to use min_asset
NotJeremyLiu Nov 6, 2023
89dc508
Support cw20 swap and action with recover entry point
NotJeremyLiu Nov 6, 2023
d37aa31
refactor execute_swap_and_action_with_recover tests
NotJeremyLiu Nov 7, 2023
ef4d59f
run make fmt
NotJeremyLiu Nov 7, 2023
a807336
refactor test_reply
NotJeremyLiu Nov 7, 2023
b3889a2
add comment on test cases
NotJeremyLiu Nov 7, 2023
61c5455
run make fmt
NotJeremyLiu Nov 7, 2023
2ae53ee
use coin::default for asset::default_native
NotJeremyLiu Nov 7, 2023
b992da9
add comment
NotJeremyLiu Nov 7, 2023
62dbfdb
change namings of Coin to Asset where applicable
NotJeremyLiu Nov 7, 2023
b0cb192
Change BankSend name to Transfer
NotJeremyLiu Nov 7, 2023
76038ef
update schemas
NotJeremyLiu Nov 7, 2023
5af9958
add sent_asset as a param into non-cw20 entry points
NotJeremyLiu Nov 7, 2023
c8f92b6
update schema
NotJeremyLiu Nov 7, 2023
5cdd3cc
add test files for receive entrypoint
NotJeremyLiu Nov 7, 2023
7a7dbf5
add CW20 Asset tests for swap and action
NotJeremyLiu Nov 8, 2023
be4f1fb
delete repeated test
NotJeremyLiu Nov 8, 2023
e86822b
Add cw20 tests to swap and action with recover
NotJeremyLiu Nov 8, 2023
1c7bfe6
Add cw20 asset tests to test_reply
NotJeremyLiu Nov 8, 2023
f908986
add cw20 asset tests to post swap action
NotJeremyLiu Nov 8, 2023
c0f809d
add cw20 tests to test user swap
NotJeremyLiu Nov 8, 2023
845f8de
fix bug in swap adapter contract and add tests
NotJeremyLiu Nov 8, 2023
26cd1cb
Update deploy.py to be more robust and wait longer
NotJeremyLiu Nov 8, 2023
8402d40
update neutron testnet deployed contracts
NotJeremyLiu Nov 8, 2023
a7c2775
update neutron mainnet contracts
NotJeremyLiu Nov 8, 2023
36d91a0
update deploy script to use /cosmos/tx/v1beta1/txs
NotJeremyLiu Nov 8, 2023
3ff62ef
update deployed terra testnet contracts
NotJeremyLiu Nov 8, 2023
aeb3f18
update terra mainnet deployed contracts
NotJeremyLiu Nov 8, 2023
feb8981
update osmosis testnet deployed contracts
NotJeremyLiu Nov 8, 2023
de72360
update osmosis mainnet deployed contracts
NotJeremyLiu Nov 8, 2023
9d91139
update chain config urls
NotJeremyLiu Nov 8, 2023
f3a67aa
Merge branch 'main' into jl/cw20-support
NotJeremyLiu Nov 14, 2023
dbc5dfd
update tests
NotJeremyLiu Nov 14, 2023
cc51e5c
run make fmt
NotJeremyLiu Nov 14, 2023
e09d571
update deployed terra contracts
NotJeremyLiu Nov 15, 2023
dd592e3
update neutron deployed contracts
NotJeremyLiu Nov 15, 2023
3221835
add salt to deployed contracts output
NotJeremyLiu Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✅ Add asset tests
NotJeremyLiu committed Sep 1, 2023
commit b8bbd4bffbbe27332af3842fbb53843e2cfb5e1a
189 changes: 189 additions & 0 deletions packages/skip/src/asset.rs
Original file line number Diff line number Diff line change
@@ -123,3 +123,192 @@ impl Asset {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::{
testing::{mock_dependencies_with_balances, mock_env, mock_info},
ContractResult, QuerierResult, SystemResult, WasmQuery,
};
use cw20::BalanceResponse;

#[test]
fn test_asset_native() {
let asset = Asset::Native(Coin {
denom: "uatom".to_string(),
amount: Uint128::new(100),
});

assert_eq!(asset.denom(), "uatom");
assert_eq!(asset.amount(), Uint128::new(100));
}

#[test]
fn test_asset_cw20() {
let asset = Asset::Cw20(Cw20Coin {
address: "asset".to_string(),
amount: Uint128::new(100),
});

assert_eq!(asset.denom(), "asset");
assert_eq!(asset.amount(), Uint128::new(100));
}

#[test]
fn test_asset_transfer_full_native() {
let asset = Asset::Native(Coin {
denom: "uatom".to_string(),
amount: Uint128::new(100),
});

let msg = asset.transfer_full("addr".to_string());

match msg {
CosmosMsg::Bank(BankMsg::Send { to_address, amount }) => {
assert_eq!(to_address, "addr");
assert_eq!(amount.len(), 1);
assert_eq!(amount[0].denom, "uatom");
assert_eq!(amount[0].amount, Uint128::new(100));
}
_ => panic!("Unexpected message type"),
}
}

#[test]
fn test_asset_transfer_full_cw20() {
let asset = Asset::Cw20(Cw20Coin {
address: "asset".to_string(),
amount: Uint128::new(100),
});

let msg = asset.transfer_full("addr".to_string());

match msg {
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr,
msg,
funds,
}) => {
assert_eq!(contract_addr, "asset");
assert_eq!(
msg,
to_binary(&Cw20ExecuteMsg::Transfer {
recipient: "addr".to_string(),
amount: Uint128::new(100),
})
.unwrap()
);
assert_eq!(funds.len(), 0);
}
_ => panic!("Unexpected message type"),
}
}

#[test]
fn test_asset_transfer_partial_native() {
let mut asset = Asset::Native(Coin {
denom: "uatom".to_string(),
amount: Uint128::new(100),
});

let msg = asset.transfer_partial("addr".to_string(), Uint128::new(20));

match msg {
CosmosMsg::Bank(BankMsg::Send { to_address, amount }) => {
assert_eq!(to_address, "addr");
assert_eq!(amount.len(), 1);
assert_eq!(amount[0].denom, "uatom");
assert_eq!(amount[0].amount, Uint128::new(20));
}
_ => panic!("Unexpected message type"),
}

assert_eq!(asset.amount(), Uint128::new(80));
}

#[test]
fn test_asset_transfer_partial_cw20() {
let mut asset = Asset::Cw20(Cw20Coin {
address: "asset".to_string(),
amount: Uint128::new(100),
});

let msg = asset.transfer_partial("addr".to_string(), Uint128::new(20));

match msg {
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr,
msg,
funds,
}) => {
assert_eq!(contract_addr, "asset");
assert_eq!(
msg,
to_binary(&Cw20ExecuteMsg::Transfer {
recipient: "addr".to_string(),
amount: Uint128::new(20),
})
.unwrap()
);
assert_eq!(funds.len(), 0);
}
_ => panic!("Unexpected message type"),
}

assert_eq!(asset.amount(), Uint128::new(80));
}

#[test]
fn test_validate_native() {
let asset = Asset::Native(Coin {
denom: "uatom".to_string(),
amount: Uint128::new(100),
});

let mut deps = mock_dependencies_with_balances(&[("entry_point", &[])]);

let env = mock_env();

let info = mock_info(
"sender",
&[Coin {
denom: "uatom".to_string(),
amount: Uint128::new(100),
}],
);

assert!(asset.validate(&deps.as_mut(), &env, &info).is_ok());
}

#[test]
fn test_validate_cw20() {
let asset = Asset::Cw20(Cw20Coin {
address: "asset".to_string(),
amount: Uint128::new(100),
});

// Create mock wasm handler to handle the cw20 balance query
let wasm_handler = |query: &WasmQuery| -> QuerierResult {
match query {
WasmQuery::Smart { .. } => SystemResult::Ok(ContractResult::Ok(
to_binary(&BalanceResponse {
balance: Uint128::from(100u128),
})
.unwrap(),
)),
_ => panic!("Unsupported query: {:?}", query),
}
};

let mut deps = mock_dependencies_with_balances(&[("entry_point", &[])]);

deps.querier.update_wasm(wasm_handler);

let env = mock_env();

let info = mock_info("sender", &[]);

assert!(asset.validate(&deps.as_mut(), &env, &info).is_ok());
}
}