diff --git a/Cargo.lock b/Cargo.lock index 9bccbc366..73c3bd929 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,9 +87,9 @@ checksum = "9f6b64db6932c7e49332728e3a6bd82c6b7e16016607d20923b537c3bc4c0d5f" [[package]] name = "cosmwasm-crypto" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ddbf475b0e8a9bd813607d59144ad3f71d90dd66c5e975a46ac2b72ce754121" +checksum = "038089cdadfe61e4e85617d91cecec2c49f828db8e5986bb85e29d0b29c59b77" dependencies = [ "digest 0.9.0", "ed25519-zebra", @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e62de21147741486c6d4adc28850b102dcad1888d9fc2d0a200ca423284563" +checksum = "628bf3da935843795a7f52678262ef06398878b0cf4c89b69612d8525ea27b84" dependencies = [ "syn", ] @@ -131,9 +131,19 @@ dependencies = [ [[package]] name = "cosmwasm-schema" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6a9a6a4ca3b4d7b56f943312a65857cdfc84424f9c2773889f4cd17f36fba61" +checksum = "04159eec9b583671db7923ff2b979736dfb8f0152347cab9fd02373c22e1a870" +dependencies = [ + "schemars", + "serde_json", +] + +[[package]] +name = "cosmwasm-schema" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66ae8ed0319a9ae48a18cb00eda7f6b4b5c2d2e1c05b194f9a4eefbb07b3a43" dependencies = [ "schemars", "serde_json", @@ -141,17 +151,18 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db14129579ddb1dbd8a28376673d61090f35c9069978eb875d489c275bb76315" +checksum = "22de097cf4f7e7f575f51a22de7260932756ccfe499e005f98244a3043470e48" dependencies = [ "base64", - "cosmwasm-crypto 0.14.0", - "cosmwasm-derive 0.14.0", + "cosmwasm-crypto 0.14.1", + "cosmwasm-derive 0.14.1", "schemars", "serde", "serde-json-wasm", "thiserror", + "uint", ] [[package]] @@ -171,10 +182,13 @@ dependencies = [ ] [[package]] -name = "cpuid-bool" -version = "0.1.2" +name = "cpufeatures" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +dependencies = [ + "libc", +] [[package]] name = "crunchy" @@ -251,7 +265,7 @@ dependencies = [ name = "cw1" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "schemars", "serde", @@ -261,8 +275,8 @@ dependencies = [ name = "cw1-subkeys" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw1", @@ -277,8 +291,8 @@ dependencies = [ name = "cw1-whitelist" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw1", @@ -292,7 +306,7 @@ dependencies = [ name = "cw1155" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "cw0", "schemars", @@ -303,8 +317,8 @@ dependencies = [ name = "cw1155-base" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw1155", @@ -328,7 +342,7 @@ dependencies = [ name = "cw20" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "cw0", "schemars", @@ -339,8 +353,8 @@ dependencies = [ name = "cw20-atomic-swap" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw2", @@ -356,8 +370,8 @@ dependencies = [ name = "cw20-base" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.15.0", + "cosmwasm-std 0.15.0", "cw-storage-plus", "cw0", "cw2", @@ -371,8 +385,8 @@ dependencies = [ name = "cw20-bonding" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.15.0", + "cosmwasm-std 0.15.0", "cw-storage-plus", "cw0", "cw2", @@ -390,8 +404,8 @@ dependencies = [ name = "cw20-escrow" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-multi-test", "cw-storage-plus", "cw0", @@ -407,8 +421,8 @@ dependencies = [ name = "cw20-ics20" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw2", @@ -422,8 +436,8 @@ dependencies = [ name = "cw20-staking" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-controllers", "cw-storage-plus", "cw0", @@ -439,7 +453,7 @@ dependencies = [ name = "cw3" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "cw0", "schemars", @@ -450,8 +464,8 @@ dependencies = [ name = "cw3-fixed-multisig" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-multi-test", "cw-storage-plus", "cw0", @@ -468,8 +482,8 @@ dependencies = [ name = "cw3-flex-multisig" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-multi-test", "cw-storage-plus", "cw0", @@ -486,7 +500,7 @@ dependencies = [ name = "cw4" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "schemars", "serde", @@ -496,8 +510,8 @@ dependencies = [ name = "cw4-group" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-controllers", "cw-storage-plus", "cw0", @@ -512,8 +526,8 @@ dependencies = [ name = "cw4-stake" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-controllers", "cw-storage-plus", "cw0", @@ -529,7 +543,7 @@ dependencies = [ name = "cw721" version = "0.6.2" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 0.14.1", "cosmwasm-std 0.15.0", "cw0", "schemars", @@ -540,8 +554,8 @@ dependencies = [ name = "cw721-base" version = "0.6.2" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std 0.14.0", + "cosmwasm-schema 0.14.1", + "cosmwasm-std 0.14.1", "cw-storage-plus", "cw0", "cw2", @@ -605,7 +619,7 @@ dependencies = [ "hex 0.4.3", "rand_core", "serde", - "sha2 0.9.3", + "sha2 0.9.5", "thiserror", ] @@ -746,14 +760,14 @@ dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "sha2 0.9.3", + "sha2 0.9.5", ] [[package]] name = "libc" -version = "0.2.93" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "num-traits" @@ -787,9 +801,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -820,9 +834,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.11.1" +version = "1.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca515aafa02c92f4d3c69b2f4c408f839b51b1aa938d00b15e8c0966bd22d73" +checksum = "01127cb8617e5e21bcf2e19b5eb48317735ca677f1d0a94833c21c331c446582" dependencies = [ "arrayvec", "num-traits", @@ -861,9 +875,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" dependencies = [ "serde_derive", ] @@ -879,9 +893,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -924,13 +938,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ "block-buffer 0.9.0", "cfg-if", - "cpuid-bool", + "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -959,9 +973,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -970,18 +984,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" +checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" +checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" dependencies = [ "proc-macro2", "quote", @@ -1008,9 +1022,9 @@ dependencies = [ [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "version_check" diff --git a/contracts/cw20-base/Cargo.toml b/contracts/cw20-base/Cargo.toml index 19f6650c9..fc99e17d4 100644 --- a/contracts/cw20-base/Cargo.toml +++ b/contracts/cw20-base/Cargo.toml @@ -22,10 +22,10 @@ cw0 = { path = "../../packages/cw0", version = "0.6.2" } cw2 = { path = "../../packages/cw2", version = "0.6.2" } cw20 = { path = "../../packages/cw20", version = "0.6.2" } cw-storage-plus = { path = "../../packages/storage-plus", version = "0.6.2", features = ["iterator"] } -cosmwasm-std = { version = "0.14.0", features = ["iterator"] } +cosmwasm-std = { version = "0.15.0", features = ["iterator"] } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.20" } +thiserror = { version = "1.0.23" } [dev-dependencies] -cosmwasm-schema = { version = "0.14.0" } +cosmwasm-schema = { version = "0.15.0" } diff --git a/contracts/cw20-base/schema/all_allowances_response.json b/contracts/cw20-base/schema/all_allowances_response.json index d314820eb..a8a11a557 100644 --- a/contracts/cw20-base/schema/all_allowances_response.json +++ b/contracts/cw20-base/schema/all_allowances_response.json @@ -80,7 +80,7 @@ ] }, "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.", + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ { "$ref": "#/definitions/Uint64" diff --git a/contracts/cw20-base/schema/allowance_response.json b/contracts/cw20-base/schema/allowance_response.json index a05443377..71b49adf1 100644 --- a/contracts/cw20-base/schema/allowance_response.json +++ b/contracts/cw20-base/schema/allowance_response.json @@ -62,7 +62,7 @@ ] }, "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.", + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ { "$ref": "#/definitions/Uint64" diff --git a/contracts/cw20-base/schema/execute_msg.json b/contracts/cw20-base/schema/execute_msg.json index 3f2f5ab73..8a8014a84 100644 --- a/contracts/cw20-base/schema/execute_msg.json +++ b/contracts/cw20-base/schema/execute_msg.json @@ -312,7 +312,7 @@ ] }, "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.", + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ { "$ref": "#/definitions/Uint64" diff --git a/contracts/cw20-base/src/allowances.rs b/contracts/cw20-base/src/allowances.rs index 0db18f0e8..f61d5d76a 100644 --- a/contracts/cw20-base/src/allowances.rs +++ b/contracts/cw20-base/src/allowances.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ attr, Addr, Binary, BlockInfo, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, - Storage, Uint128, + Storage, SubMsg, Uint128, }; use cw20::{AllowanceResponse, Cw20ReceiveMsg, Expiration}; @@ -34,7 +34,6 @@ pub fn execute_increase_allowance( )?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "increase_allowance"), @@ -42,6 +41,7 @@ pub fn execute_increase_allowance( attr("spender", spender), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -78,7 +78,6 @@ pub fn execute_decrease_allowance( } let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "decrease_allowance"), @@ -86,6 +85,7 @@ pub fn execute_decrease_allowance( attr("spender", spender), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -146,7 +146,6 @@ pub fn execute_transfer_from( )?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "transfer_from"), @@ -155,6 +154,7 @@ pub fn execute_transfer_from( attr("by", info.sender), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -188,7 +188,6 @@ pub fn execute_burn_from( })?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "burn_from"), @@ -196,6 +195,7 @@ pub fn execute_burn_from( attr("by", info.sender), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -239,17 +239,19 @@ pub fn execute_send_from( ]; // create a send message - let msg = Cw20ReceiveMsg { - sender: info.sender.into(), - amount, - msg, - } - .into_cosmos_msg(contract)?; + let msg = SubMsg::new( + Cw20ReceiveMsg { + sender: info.sender.into(), + amount, + msg, + } + .into_cosmos_msg(contract)?, + ); let res = Response { - submessages: vec![], messages: vec![msg], attributes: attrs, + events: vec![], data: None, }; Ok(res) @@ -309,14 +311,14 @@ mod tests { let spender = String::from("addr0002"); let info = mock_info(owner.as_ref(), &[]); let env = mock_env(); - do_instantiate(deps.as_mut(), owner.clone(), Uint128(12340000)); + do_instantiate(deps.as_mut(), owner.clone(), Uint128::new(12340000)); // no allowance to start let allowance = query_allowance(deps.as_ref(), owner.clone(), spender.clone()).unwrap(); assert_eq!(allowance, AllowanceResponse::default()); // set allowance with height expiration - let allow1 = Uint128(7777); + let allow1 = Uint128::new(7777); let expires = Expiration::AtHeight(5432); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), @@ -336,7 +338,7 @@ mod tests { ); // decrease it a bit with no expire set - stays the same - let lower = Uint128(4444); + let lower = Uint128::new(4444); let allow2 = allow1.checked_sub(lower).unwrap(); let msg = ExecuteMsg::DecreaseAllowance { spender: spender.clone(), @@ -354,7 +356,7 @@ mod tests { ); // increase it some more and override the expires - let raise = Uint128(87654); + let raise = Uint128::new(87654); let allow3 = allow2 + raise; let new_expire = Expiration::AtTime(Timestamp::from_seconds(8888888888)); let msg = ExecuteMsg::IncreaseAllowance { @@ -375,7 +377,7 @@ mod tests { // decrease it below 0 let msg = ExecuteMsg::DecreaseAllowance { spender: spender.clone(), - amount: Uint128(99988647623876347), + amount: Uint128::new(99988647623876347), expires: None, }; execute(deps.as_mut(), env, info, msg).unwrap(); @@ -392,7 +394,7 @@ mod tests { let spender2 = String::from("addr0003"); let info = mock_info(owner.as_ref(), &[]); let env = mock_env(); - do_instantiate(deps.as_mut(), &owner, Uint128(12340000)); + do_instantiate(deps.as_mut(), &owner, Uint128::new(12340000)); // no allowance to start assert_eq!( @@ -409,7 +411,7 @@ mod tests { ); // set allowance with height expiration - let allow1 = Uint128(7777); + let allow1 = Uint128::new(7777); let expires = Expiration::AtHeight(5432); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), @@ -419,7 +421,7 @@ mod tests { execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); // set other allowance with no expiration - let allow2 = Uint128(87654); + let allow2 = Uint128::new(87654); let msg = ExecuteMsg::IncreaseAllowance { spender: spender2.clone(), amount: allow2, @@ -452,7 +454,7 @@ mod tests { // also allow spender -> spender2 with no interference let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); - let allow3 = Uint128(1821); + let allow3 = Uint128::new(1821); let expires3 = Expiration::AtTime(Timestamp::from_seconds(3767626296)); let msg = ExecuteMsg::IncreaseAllowance { spender: spender2.clone(), @@ -485,12 +487,12 @@ mod tests { let owner = String::from("addr0001"); let info = mock_info(owner.as_ref(), &[]); let env = mock_env(); - do_instantiate(deps.as_mut(), &owner, Uint128(12340000)); + do_instantiate(deps.as_mut(), &owner, Uint128::new(12340000)); // self-allowance let msg = ExecuteMsg::IncreaseAllowance { spender: owner.clone(), - amount: Uint128(7777), + amount: Uint128::new(7777), expires: None, }; let err = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap_err(); @@ -499,7 +501,7 @@ mod tests { // decrease self-allowance let msg = ExecuteMsg::DecreaseAllowance { spender: owner, - amount: Uint128(7777), + amount: Uint128::new(7777), expires: None, }; let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); @@ -513,11 +515,11 @@ mod tests { let spender = String::from("addr0002"); let rcpt = String::from("addr0003"); - let start = Uint128(999999); + let start = Uint128::new(999999); do_instantiate(deps.as_mut(), &owner, start); // provide an allowance - let allow1 = Uint128(77777); + let allow1 = Uint128::new(77777); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), amount: allow1, @@ -528,7 +530,7 @@ mod tests { execute(deps.as_mut(), env, info, msg).unwrap(); // valid transfer of part of the allowance - let transfer = Uint128(44444); + let transfer = Uint128::new(44444); let msg = ExecuteMsg::TransferFrom { owner: owner.clone(), recipient: rcpt.clone(), @@ -558,7 +560,7 @@ mod tests { let msg = ExecuteMsg::TransferFrom { owner: owner.clone(), recipient: rcpt.clone(), - amount: Uint128(33443), + amount: Uint128::new(33443), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -570,7 +572,7 @@ mod tests { let env = mock_env(); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), - amount: Uint128(1000), + amount: Uint128::new(1000), expires: Some(Expiration::AtHeight(env.block.height)), }; execute(deps.as_mut(), env, info, msg).unwrap(); @@ -579,7 +581,7 @@ mod tests { let msg = ExecuteMsg::TransferFrom { owner, recipient: rcpt, - amount: Uint128(33443), + amount: Uint128::new(33443), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -593,11 +595,11 @@ mod tests { let owner = String::from("addr0001"); let spender = String::from("addr0002"); - let start = Uint128(999999); + let start = Uint128::new(999999); do_instantiate(deps.as_mut(), &owner, start); // provide an allowance - let allow1 = Uint128(77777); + let allow1 = Uint128::new(77777); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), amount: allow1, @@ -608,7 +610,7 @@ mod tests { execute(deps.as_mut(), env, info, msg).unwrap(); // valid burn of part of the allowance - let transfer = Uint128(44444); + let transfer = Uint128::new(44444); let msg = ExecuteMsg::BurnFrom { owner: owner.clone(), amount: transfer, @@ -635,7 +637,7 @@ mod tests { // cannot burn more than the allowance let msg = ExecuteMsg::BurnFrom { owner: owner.clone(), - amount: Uint128(33443), + amount: Uint128::new(33443), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -647,7 +649,7 @@ mod tests { let env = mock_env(); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), - amount: Uint128(1000), + amount: Uint128::new(1000), expires: Some(Expiration::AtHeight(env.block.height)), }; execute(deps.as_mut(), env, info, msg).unwrap(); @@ -655,7 +657,7 @@ mod tests { // we should now get the expiration error let msg = ExecuteMsg::BurnFrom { owner, - amount: Uint128(33443), + amount: Uint128::new(33443), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -671,11 +673,11 @@ mod tests { let contract = String::from("cool-dex"); let send_msg = Binary::from(r#"{"some":123}"#.as_bytes()); - let start = Uint128(999999); + let start = Uint128::new(999999); do_instantiate(deps.as_mut(), &owner, start); // provide an allowance - let allow1 = Uint128(77777); + let allow1 = Uint128::new(77777); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), amount: allow1, @@ -686,7 +688,7 @@ mod tests { execute(deps.as_mut(), env, info, msg).unwrap(); // valid send of part of the allowance - let transfer = Uint128(44444); + let transfer = Uint128::new(44444); let msg = ExecuteMsg::SendFrom { owner: owner.clone(), amount: transfer, @@ -709,11 +711,11 @@ mod tests { .unwrap(); assert_eq!( res.messages[0], - CosmosMsg::Wasm(WasmMsg::Execute { + SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract.clone(), msg: binary_msg, - send: vec![], - }) + funds: vec![], + })) ); // make sure money sent @@ -734,7 +736,7 @@ mod tests { // cannot send more than the allowance let msg = ExecuteMsg::SendFrom { owner: owner.clone(), - amount: Uint128(33443), + amount: Uint128::new(33443), contract: contract.clone(), msg: send_msg.clone(), }; @@ -748,7 +750,7 @@ mod tests { let env = mock_env(); let msg = ExecuteMsg::IncreaseAllowance { spender: spender.clone(), - amount: Uint128(1000), + amount: Uint128::new(1000), expires: Some(Expiration::AtHeight(env.block.height)), }; execute(deps.as_mut(), env, info, msg).unwrap(); @@ -756,7 +758,7 @@ mod tests { // we should now get the expiration error let msg = ExecuteMsg::SendFrom { owner, - amount: Uint128(33443), + amount: Uint128::new(33443), contract, msg: send_msg, }; diff --git a/contracts/cw20-base/src/contract.rs b/contracts/cw20-base/src/contract.rs index c10f18f66..50f609617 100644 --- a/contracts/cw20-base/src/contract.rs +++ b/contracts/cw20-base/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ attr, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, - Uint128, + SubMsg, Uint128, }; use cw2::set_contract_version; @@ -140,7 +140,6 @@ pub fn execute_transfer( )?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "transfer"), @@ -148,6 +147,7 @@ pub fn execute_transfer( attr("to", recipient), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -178,13 +178,13 @@ pub fn execute_burn( })?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "burn"), attr("from", info.sender), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -224,13 +224,13 @@ pub fn execute_mint( )?; let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "mint"), attr("to", recipient), attr("amount", amount), ], + events: vec![], data: None, }; Ok(res) @@ -272,17 +272,19 @@ pub fn execute_send( ]; // create a send message - let msg = Cw20ReceiveMsg { - sender: info.sender.into(), - amount, - msg, - } - .into_cosmos_msg(contract)?; + let msg = SubMsg::new( + Cw20ReceiveMsg { + sender: info.sender.into(), + amount, + msg, + } + .into_cosmos_msg(contract)?, + ); let res = Response { - submessages: vec![], messages: vec![msg], attributes: attrs, + events: vec![], data: None, }; Ok(res) @@ -439,15 +441,18 @@ mod tests { total_supply: amount, } ); - assert_eq!(get_balance(deps.as_ref(), "addr0000"), Uint128(11223344)); + assert_eq!( + get_balance(deps.as_ref(), "addr0000"), + Uint128::new(11223344) + ); } #[test] fn instantiate_mintable() { let mut deps = mock_dependencies(&[]); - let amount = Uint128(11223344); + let amount = Uint128::new(11223344); let minter = String::from("asmodat"); - let limit = Uint128(511223344); + let limit = Uint128::new(511223344); let instantiate_msg = InstantiateMsg { name: "Cash Token".to_string(), symbol: "CASH".to_string(), @@ -475,7 +480,10 @@ mod tests { total_supply: amount, } ); - assert_eq!(get_balance(deps.as_ref(), "addr0000"), Uint128(11223344)); + assert_eq!( + get_balance(deps.as_ref(), "addr0000"), + Uint128::new(11223344) + ); assert_eq!( query_minter(deps.as_ref()).unwrap(), Some(MinterResponse { @@ -488,9 +496,9 @@ mod tests { #[test] fn instantiate_mintable_over_cap() { let mut deps = mock_dependencies(&[]); - let amount = Uint128(11223344); + let amount = Uint128::new(11223344); let minter = String::from("asmodat"); - let limit = Uint128(11223300); + let limit = Uint128::new(11223300); let instantiate_msg = InstantiateMsg { name: "Cash Token".to_string(), symbol: "CASH".to_string(), @@ -518,14 +526,14 @@ mod tests { let mut deps = mock_dependencies(&[]); let genesis = String::from("genesis"); - let amount = Uint128(11223344); + let amount = Uint128::new(11223344); let minter = String::from("asmodat"); - let limit = Uint128(511223344); + let limit = Uint128::new(511223344); do_instantiate_with_minter(deps.as_mut(), &genesis, amount, &minter, Some(limit)); // minter can mint coins to some winner let winner = String::from("lucky"); - let prize = Uint128(222_222_222); + let prize = Uint128::new(222_222_222); let msg = ExecuteMsg::Mint { recipient: winner.clone(), amount: prize, @@ -552,7 +560,7 @@ mod tests { // cap is enforced let msg = ExecuteMsg::Mint { recipient: winner, - amount: Uint128(333_222_222), + amount: Uint128::new(333_222_222), }; let info = mock_info(minter.as_ref(), &[]); let env = mock_env(); @@ -566,14 +574,14 @@ mod tests { do_instantiate_with_minter( deps.as_mut(), &String::from("genesis"), - Uint128(1234), + Uint128::new(1234), &String::from("minter"), None, ); let msg = ExecuteMsg::Mint { recipient: String::from("lucky"), - amount: Uint128(222), + amount: Uint128::new(222), }; let info = mock_info("anyone else", &[]); let env = mock_env(); @@ -584,11 +592,11 @@ mod tests { #[test] fn no_one_mints_if_minter_unset() { let mut deps = mock_dependencies(&[]); - do_instantiate(deps.as_mut(), &String::from("genesis"), Uint128(1234)); + do_instantiate(deps.as_mut(), &String::from("genesis"), Uint128::new(1234)); let msg = ExecuteMsg::Mint { recipient: String::from("lucky"), - amount: Uint128(222), + amount: Uint128::new(222), }; let info = mock_info("genesis", &[]); let env = mock_env(); @@ -840,11 +848,11 @@ mod tests { // and this is how it must be wrapped for the vm to process it assert_eq!( res.messages[0], - CosmosMsg::Wasm(WasmMsg::Execute { + SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract.clone(), msg: binary_msg, - send: vec![], - }) + funds: vec![], + })) ); // ensure balance is properly transferred diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index 9056b7407..164410550 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -95,14 +95,14 @@ mod tests { let info = mock_info(owner.as_ref(), &[]); let env = mock_env(); - do_instantiate(deps.as_mut(), &owner, Uint128(12340000)); + do_instantiate(deps.as_mut(), &owner, Uint128::new(12340000)); // no allowance to start let allowances = query_all_allowances(deps.as_ref(), owner.clone(), None, None).unwrap(); assert_eq!(allowances.allowances, vec![]); // set allowance with height expiration - let allow1 = Uint128(7777); + let allow1 = Uint128::new(7777); let expires = Expiration::AtHeight(5432); let msg = ExecuteMsg::IncreaseAllowance { spender: spender1.clone(), @@ -112,7 +112,7 @@ mod tests { execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); // set allowance with no expiration - let allow2 = Uint128(54321); + let allow2 = Uint128::new(54321); let msg = ExecuteMsg::IncreaseAllowance { spender: spender2.clone(), amount: allow2, @@ -158,7 +158,7 @@ mod tests { let acct4 = String::from("aaaardvark"); let expected_order = [acct4.clone(), acct1.clone(), acct3.clone(), acct2.clone()]; - do_instantiate(deps.as_mut(), &acct1, Uint128(12340000)); + do_instantiate(deps.as_mut(), &acct1, Uint128::new(12340000)); // put money everywhere (to create balanaces) let info = mock_info(acct1.as_ref(), &[]); @@ -169,7 +169,7 @@ mod tests { info.clone(), ExecuteMsg::Transfer { recipient: acct2, - amount: Uint128(222222), + amount: Uint128::new(222222), }, ) .unwrap(); @@ -179,7 +179,7 @@ mod tests { info.clone(), ExecuteMsg::Transfer { recipient: acct3, - amount: Uint128(333333), + amount: Uint128::new(333333), }, ) .unwrap(); @@ -189,7 +189,7 @@ mod tests { info, ExecuteMsg::Transfer { recipient: acct4, - amount: Uint128(444444), + amount: Uint128::new(444444), }, ) .unwrap(); diff --git a/contracts/cw20-bonding/Cargo.toml b/contracts/cw20-bonding/Cargo.toml index 643d6f308..7170c6037 100644 --- a/contracts/cw20-bonding/Cargo.toml +++ b/contracts/cw20-bonding/Cargo.toml @@ -25,13 +25,13 @@ cw2 = { path = "../../packages/cw2", version = "0.6.2" } cw20 = { path = "../../packages/cw20", version = "0.6.2" } cw20-base = { path = "../../contracts/cw20-base", version = "0.6.2", features = ["library"] } cw-storage-plus = { path = "../../packages/storage-plus", version = "0.6.2" } -cosmwasm-std = { version = "0.14.0", features = ["staking"] } +cosmwasm-std = { version = "0.15.0", features = ["staking"] } schemars = "0.8.1" serde = { version = "1.0.103", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.20" } -rust_decimal = { version = "1.8.1" } +thiserror = { version = "1.0.23" } +rust_decimal = { version = "1.14.3" } integer-sqrt = { version = "0.1.5" } -integer-cbrt = { version = "0.1" } +integer-cbrt = { version = "0.1.2" } [dev-dependencies] -cosmwasm-schema = { version = "0.14.0" } +cosmwasm-schema = { version = "0.15.0" } diff --git a/contracts/cw20-bonding/schema/allowance_response.json b/contracts/cw20-bonding/schema/allowance_response.json index a05443377..71b49adf1 100644 --- a/contracts/cw20-bonding/schema/allowance_response.json +++ b/contracts/cw20-bonding/schema/allowance_response.json @@ -62,7 +62,7 @@ ] }, "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.", + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ { "$ref": "#/definitions/Uint64" diff --git a/contracts/cw20-bonding/schema/execute_msg.json b/contracts/cw20-bonding/schema/execute_msg.json index 5c299022e..3429cbc89 100644 --- a/contracts/cw20-bonding/schema/execute_msg.json +++ b/contracts/cw20-bonding/schema/execute_msg.json @@ -300,7 +300,7 @@ ] }, "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.", + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ { "$ref": "#/definitions/Uint64" diff --git a/contracts/cw20-bonding/src/contract.rs b/contracts/cw20-bonding/src/contract.rs index c29be5658..749b05876 100644 --- a/contracts/cw20-bonding/src/contract.rs +++ b/contracts/cw20-bonding/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ attr, coins, to_binary, Addr, BankMsg, Binary, Deps, DepsMut, Env, MessageInfo, Response, - StdError, StdResult, Uint128, + StdError, StdResult, SubMsg, Uint128, }; use cw2::set_contract_version; @@ -40,7 +40,7 @@ pub fn instantiate( name: msg.name, symbol: msg.symbol, decimals: msg.decimals, - total_supply: Uint128(0), + total_supply: Uint128::zero(), // set self as minter, so we can properly execute mint and burn mint: Some(MinterData { minter: env.contract.address, @@ -161,7 +161,6 @@ pub fn execute_buy( // bond them to the validator let res = Response { - submessages: vec![], messages: vec![], attributes: vec![ attr("action", "buy"), @@ -169,6 +168,7 @@ pub fn execute_buy( attr("reserve", payment), attr("supply", minted), ], + events: vec![], data: None, }; Ok(res) @@ -256,18 +256,18 @@ fn do_sell( CURVE_STATE.save(deps.storage, &state)?; // now send the tokens to the sender (TODO: for sell_from we do something else, right???) - let msg = BankMsg::Send { + let msg = SubMsg::new(BankMsg::Send { to_address: receiver.to_string(), amount: coins(released.u128(), state.reserve_denom), - }; + }); let res = Response { - submessages: vec![], - messages: vec![msg.into()], + messages: vec![msg], attributes: vec![ attr("from", info.sender), attr("supply", amount), attr("reserve", released), ], + events: vec![], data: None, }; Ok(res) @@ -369,7 +369,7 @@ mod tests { // this matches `linear_curve` test case from curves.rs let creator = String::from("creator"); let curve_type = CurveType::SquareRoot { - slope: Uint128(1), + slope: Uint128::new(1), scale: 1, }; let msg = default_instantiate(2, 8, curve_type.clone()); @@ -384,12 +384,12 @@ mod tests { assert_eq!(&token.name, &msg.name); assert_eq!(&token.symbol, &msg.symbol); assert_eq!(token.decimals, 2); - assert_eq!(token.total_supply, Uint128(0)); + assert_eq!(token.total_supply, Uint128::zero()); // curve state is sensible let state = query_curve_info(deps.as_ref(), curve_type.to_curve_fn()).unwrap(); - assert_eq!(state.reserve, Uint128(0)); - assert_eq!(state.supply, Uint128(0)); + assert_eq!(state.reserve, Uint128::zero()); + assert_eq!(state.supply, Uint128::zero()); assert_eq!(state.reserve_denom.as_str(), DENOM); // spot price 0 as supply is 0 assert_eq!(state.spot_price, Decimal::zero()); @@ -399,14 +399,14 @@ mod tests { assert_eq!(curve_type, curve); // no balance - assert_eq!(get_balance(deps.as_ref(), &creator), Uint128(0)); + assert_eq!(get_balance(deps.as_ref(), &creator), Uint128::zero()); } #[test] fn buy_issues_tokens() { let mut deps = mock_dependencies(&[]); let curve_type = CurveType::Linear { - slope: Uint128(1), + slope: Uint128::new(1), scale: 1, }; setup_test(deps.as_mut(), 2, 8, curve_type.clone()); @@ -417,46 +417,46 @@ mod tests { execute(deps.as_mut(), mock_env(), info, buy.clone()).unwrap(); // bob got 1000 EPOXY (10.00) - assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128(1000)); - assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128(0)); + assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128::new(1000)); + assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128::zero()); // send them all to buyer let info = mock_info(INVESTOR, &[]); let send = ExecuteMsg::Transfer { recipient: BUYER.into(), - amount: Uint128(1000), + amount: Uint128::new(1000), }; execute(deps.as_mut(), mock_env(), info, send).unwrap(); // ensure balances updated - assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128(0)); - assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128(1000)); + assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128::zero()); + assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128::new(1000)); // second stake needs more to get next 1000 EPOXY let info = mock_info(INVESTOR, &coins(1_500_000_000, DENOM)); execute(deps.as_mut(), mock_env(), info, buy).unwrap(); // ensure balances updated - assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128(1000)); - assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128(1000)); + assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128::new(1000)); + assert_eq!(get_balance(deps.as_ref(), BUYER), Uint128::new(1000)); // check curve info updated let curve = query_curve_info(deps.as_ref(), curve_type.to_curve_fn()).unwrap(); - assert_eq!(curve.reserve, Uint128(2_000_000_000)); - assert_eq!(curve.supply, Uint128(2000)); + assert_eq!(curve.reserve, Uint128::new(2_000_000_000)); + assert_eq!(curve.supply, Uint128::new(2000)); assert_eq!(curve.spot_price, Decimal::percent(200)); // check token info updated let token = query_token_info(deps.as_ref()).unwrap(); assert_eq!(token.decimals, 2); - assert_eq!(token.total_supply, Uint128(2000)); + assert_eq!(token.total_supply, Uint128::new(2000)); } #[test] fn bonding_fails_with_wrong_denom() { let mut deps = mock_dependencies(&[]); let curve_type = CurveType::Linear { - slope: Uint128(1), + slope: Uint128::new(1), scale: 1, }; setup_test(deps.as_mut(), 2, 8, curve_type); @@ -482,7 +482,7 @@ mod tests { fn burning_sends_reserve() { let mut deps = mock_dependencies(&[]); let curve_type = CurveType::Linear { - slope: Uint128(1), + slope: Uint128::new(1), scale: 1, }; setup_test(deps.as_mut(), 2, 8, curve_type.clone()); @@ -493,12 +493,12 @@ mod tests { execute(deps.as_mut(), mock_env(), info, buy).unwrap(); // bob got 2000 EPOXY (20.00) - assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128(2000)); + assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128::new(2000)); // cannot burn too much let info = mock_info(INVESTOR, &[]); let burn = ExecuteMsg::Burn { - amount: Uint128(3000), + amount: Uint128::new(3000), }; let err = execute(deps.as_mut(), mock_env(), info, burn).unwrap_err(); assert_eq!( @@ -511,41 +511,40 @@ mod tests { // burn 1000 EPOXY to get back 15BTC (*10^8) let info = mock_info(INVESTOR, &[]); let burn = ExecuteMsg::Burn { - amount: Uint128(1000), + amount: Uint128::new(1000), }; let res = execute(deps.as_mut(), mock_env(), info, burn).unwrap(); // balance is lower - assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128(1000)); + assert_eq!(get_balance(deps.as_ref(), INVESTOR), Uint128::new(1000)); // ensure we got our money back assert_eq!(1, res.messages.len()); assert_eq!( &res.messages[0], - &BankMsg::Send { + &SubMsg::new(BankMsg::Send { to_address: INVESTOR.into(), amount: coins(1_500_000_000, DENOM), - } - .into() + }) ); // check curve info updated let curve = query_curve_info(deps.as_ref(), curve_type.to_curve_fn()).unwrap(); - assert_eq!(curve.reserve, Uint128(500_000_000)); - assert_eq!(curve.supply, Uint128(1000)); + assert_eq!(curve.reserve, Uint128::new(500_000_000)); + assert_eq!(curve.supply, Uint128::new(1000)); assert_eq!(curve.spot_price, Decimal::percent(100)); // check token info updated let token = query_token_info(deps.as_ref()).unwrap(); assert_eq!(token.decimals, 2); - assert_eq!(token.total_supply, Uint128(1000)); + assert_eq!(token.total_supply, Uint128::new(1000)); } #[test] fn cw20_imports_work() { let mut deps = mock_dependencies(&[]); let curve_type = CurveType::Constant { - value: Uint128(15), + value: Uint128::new(15), scale: 1, }; setup_test(deps.as_mut(), 9, 6, curve_type); @@ -560,51 +559,51 @@ mod tests { execute(deps.as_mut(), mock_env(), info, buy).unwrap(); // check balances - assert_eq!(get_balance(deps.as_ref(), bob), Uint128(30_000_000)); - assert_eq!(get_balance(deps.as_ref(), carl), Uint128(0)); + assert_eq!(get_balance(deps.as_ref(), bob), Uint128::new(30_000_000)); + assert_eq!(get_balance(deps.as_ref(), carl), Uint128::zero()); // send coins to carl let bob_info = mock_info(bob, &[]); let transfer = ExecuteMsg::Transfer { recipient: carl.into(), - amount: Uint128(2_000_000), + amount: Uint128::new(2_000_000), }; execute(deps.as_mut(), mock_env(), bob_info.clone(), transfer).unwrap(); - assert_eq!(get_balance(deps.as_ref(), bob), Uint128(28_000_000)); - assert_eq!(get_balance(deps.as_ref(), carl), Uint128(2_000_000)); + assert_eq!(get_balance(deps.as_ref(), bob), Uint128::new(28_000_000)); + assert_eq!(get_balance(deps.as_ref(), carl), Uint128::new(2_000_000)); // allow alice let allow = ExecuteMsg::IncreaseAllowance { spender: alice.into(), - amount: Uint128(35_000_000), + amount: Uint128::new(35_000_000), expires: None, }; execute(deps.as_mut(), mock_env(), bob_info, allow).unwrap(); - assert_eq!(get_balance(deps.as_ref(), bob), Uint128(28_000_000)); - assert_eq!(get_balance(deps.as_ref(), alice), Uint128(0)); + assert_eq!(get_balance(deps.as_ref(), bob), Uint128::new(28_000_000)); + assert_eq!(get_balance(deps.as_ref(), alice), Uint128::zero()); assert_eq!( query_allowance(deps.as_ref(), bob.into(), alice.into()) .unwrap() .allowance, - Uint128(35_000_000) + Uint128::new(35_000_000) ); // alice takes some for herself let self_pay = ExecuteMsg::TransferFrom { owner: bob.into(), recipient: alice.into(), - amount: Uint128(25_000_000), + amount: Uint128::new(25_000_000), }; let alice_info = mock_info(alice, &[]); execute(deps.as_mut(), mock_env(), alice_info, self_pay).unwrap(); - assert_eq!(get_balance(deps.as_ref(), bob), Uint128(3_000_000)); - assert_eq!(get_balance(deps.as_ref(), alice), Uint128(25_000_000)); - assert_eq!(get_balance(deps.as_ref(), carl), Uint128(2_000_000)); + assert_eq!(get_balance(deps.as_ref(), bob), Uint128::new(3_000_000)); + assert_eq!(get_balance(deps.as_ref(), alice), Uint128::new(25_000_000)); + assert_eq!(get_balance(deps.as_ref(), carl), Uint128::new(2_000_000)); assert_eq!( query_allowance(deps.as_ref(), bob.into(), alice.into()) .unwrap() .allowance, - Uint128(10_000_000) + Uint128::new(10_000_000) ); // test burn from works properly (burn tested in burning_sends_reserve) @@ -613,7 +612,7 @@ mod tests { let info = mock_info(alice, &[]); let burn_from = ExecuteMsg::BurnFrom { owner: bob.into(), - amount: Uint128(3_300_000), + amount: Uint128::new(3_300_000), }; let err = execute(deps.as_mut(), mock_env(), info, burn_from).unwrap_err(); assert_eq!( @@ -627,23 +626,22 @@ mod tests { let info = mock_info(alice, &[]); let burn_from = ExecuteMsg::BurnFrom { owner: bob.into(), - amount: Uint128(1_000_000), + amount: Uint128::new(1_000_000), }; let res = execute(deps.as_mut(), mock_env(), info, burn_from).unwrap(); // bob balance is lower, not alice - assert_eq!(get_balance(deps.as_ref(), alice), Uint128(25_000_000)); - assert_eq!(get_balance(deps.as_ref(), bob), Uint128(2_000_000)); + assert_eq!(get_balance(deps.as_ref(), alice), Uint128::new(25_000_000)); + assert_eq!(get_balance(deps.as_ref(), bob), Uint128::new(2_000_000)); // ensure alice got our money back assert_eq!(1, res.messages.len()); assert_eq!( &res.messages[0], - &BankMsg::Send { + &SubMsg::new(BankMsg::Send { to_address: alice.into(), amount: coins(1_500, DENOM), - } - .into() + }) ); } } diff --git a/contracts/cw20-bonding/src/curves.rs b/contracts/cw20-bonding/src/curves.rs index 3b014ff1b..b4617ab99 100644 --- a/contracts/cw20-bonding/src/curves.rs +++ b/contracts/cw20-bonding/src/curves.rs @@ -218,14 +218,14 @@ impl DecimalPlaces { } } - pub fn to_reserve(&self, reserve: Decimal) -> Uint128 { + pub fn to_reserve(self, reserve: Decimal) -> Uint128 { let factor = decimal(10u128.pow(self.reserve), 0); let out = reserve * factor; // TODO: execute overflow better? Result? out.floor().to_u128().unwrap().into() } - pub fn to_supply(&self, supply: Decimal) -> Uint128 { + pub fn to_supply(self, supply: Decimal) -> Uint128 { let factor = decimal(10u128.pow(self.supply), 0); let out = supply * factor; // TODO: execute overflow better? Result? @@ -254,15 +254,18 @@ mod tests { // do some sanity checks.... // spot price is always 1.5 ATOM - assert_eq!(StdDecimal::percent(150), curve.spot_price(Uint128(123))); + assert_eq!( + StdDecimal::percent(150), + curve.spot_price(Uint128::new(123)) + ); // if we have 30 STEP, we should have 45 ATOM - let reserve = curve.reserve(Uint128(30_000_000_000)); - assert_eq!(Uint128(45_000_000), reserve); + let reserve = curve.reserve(Uint128::new(30_000_000_000)); + assert_eq!(Uint128::new(45_000_000), reserve); // if we have 36 ATOM, we should have 24 STEP - let supply = curve.supply(Uint128(36_000_000)); - assert_eq!(Uint128(24_000_000_000), supply); + let supply = curve.supply(Uint128::new(36_000_000)); + assert_eq!(Uint128::new(24_000_000_000), supply); } #[test] @@ -274,27 +277,36 @@ mod tests { // do some sanity checks.... // spot price is 0.1 with 1 USDT supply - assert_eq!(StdDecimal::permille(100), curve.spot_price(Uint128(100))); + assert_eq!( + StdDecimal::permille(100), + curve.spot_price(Uint128::new(100)) + ); // spot price is 1.7 with 17 USDT supply - assert_eq!(StdDecimal::permille(1700), curve.spot_price(Uint128(1700))); + assert_eq!( + StdDecimal::permille(1700), + curve.spot_price(Uint128::new(1700)) + ); // spot price is 0.212 with 2.12 USDT supply - assert_eq!(StdDecimal::permille(212), curve.spot_price(Uint128(212))); + assert_eq!( + StdDecimal::permille(212), + curve.spot_price(Uint128::new(212)) + ); // if we have 10 USDT, we should have 5 BTC - let reserve = curve.reserve(Uint128(1000)); - assert_eq!(Uint128(500_000_000), reserve); + let reserve = curve.reserve(Uint128::new(1000)); + assert_eq!(Uint128::new(500_000_000), reserve); // if we have 20 USDT, we should have 20 BTC - let reserve = curve.reserve(Uint128(2000)); - assert_eq!(Uint128(2_000_000_000), reserve); + let reserve = curve.reserve(Uint128::new(2000)); + assert_eq!(Uint128::new(2_000_000_000), reserve); // if we have 1.25 BTC, we should have 5 USDT - let supply = curve.supply(Uint128(125_000_000)); - assert_eq!(Uint128(500), supply); + let supply = curve.supply(Uint128::new(125_000_000)); + assert_eq!(Uint128::new(500), supply); // test square root rounding // TODO: test when supply has many more decimal places than reserve // if we have 1.11 BTC, we should have 4.7116875957... USDT - let supply = curve.supply(Uint128(111_000_000)); - assert_eq!(Uint128(471), supply); + let supply = curve.supply(Uint128::new(111_000_000)); + assert_eq!(Uint128::new(471), supply); } #[test] @@ -308,37 +320,37 @@ mod tests { // spot price is 0.35 with 1 TREE supply assert_eq!( StdDecimal::percent(35), - curve.spot_price(Uint128(1_000_000)) + curve.spot_price(Uint128::new(1_000_000)) ); // spot price is 3.5 with 100 TREE supply assert_eq!( StdDecimal::percent(350), - curve.spot_price(Uint128(100_000_000)) + curve.spot_price(Uint128::new(100_000_000)) ); // spot price should be 23.478713763747788 with 4500 TREE supply (test rounding and reporting here) // rounds off around 8-9 sig figs (note diff for last points) assert_eq!( StdDecimal::from_ratio(2347871365u128, 100_000_000u128), - curve.spot_price(Uint128(4_500_000_000)) + curve.spot_price(Uint128::new(4_500_000_000)) ); // if we have 1 TREE, we should have 0.2333333333333 CHF - let reserve = curve.reserve(Uint128(1_000_000)); - assert_eq!(Uint128(23), reserve); + let reserve = curve.reserve(Uint128::new(1_000_000)); + assert_eq!(Uint128::new(23), reserve); // if we have 100 TREE, we should have 233.333333333 CHF - let reserve = curve.reserve(Uint128(100_000_000)); - assert_eq!(Uint128(23_333), reserve); + let reserve = curve.reserve(Uint128::new(100_000_000)); + assert_eq!(Uint128::new(23_333), reserve); // test rounding // if we have 235 TREE, we should have 840.5790828021146 CHF - let reserve = curve.reserve(Uint128(235_000_000)); - assert_eq!(Uint128(84_057), reserve); // round down + let reserve = curve.reserve(Uint128::new(235_000_000)); + assert_eq!(Uint128::new(84_057), reserve); // round down // // if we have 0.23 CHF, we should have 0.990453 TREE (round down) - let supply = curve.supply(Uint128(23)); - assert_eq!(Uint128(990_000), supply); + let supply = curve.supply(Uint128::new(23)); + assert_eq!(Uint128::new(990_000), supply); // if we have 840.58 CHF, we should have 235.000170 TREE (round down) - let supply = curve.supply(Uint128(84058)); - assert_eq!(Uint128(235_000_000), supply); + let supply = curve.supply(Uint128::new(84058)); + assert_eq!(Uint128::new(235_000_000), supply); } // Idea: generic test that curve.supply(curve.reserve(supply)) == supply (or within some small rounding margin) diff --git a/contracts/cw20-bonding/src/state.rs b/contracts/cw20-bonding/src/state.rs index 58c6b0fa1..1a54d43de 100644 --- a/contracts/cw20-bonding/src/state.rs +++ b/contracts/cw20-bonding/src/state.rs @@ -25,8 +25,8 @@ pub struct CurveState { impl CurveState { pub fn new(reserve_denom: String, decimals: DecimalPlaces) -> Self { CurveState { - reserve: Uint128(0), - supply: Uint128(0), + reserve: Uint128::zero(), + supply: Uint128::zero(), reserve_denom, decimals, }