Skip to content

Commit 23f55c6

Browse files
authored
cosmwasm-* 1.1.0 migration (#24)
* cw20-atomic-swap migration to cosmwasm-* 1.1.0 * cw20-bonding migration to cosmwasm-* 1.1.0 * cw20-escrow migration to cosmwasm-* 1.1.0 * cw20-merkle-airdrop migration to cosmwasm-* 1.1.0 * cw20-staking migration to cosmwasm-* 1.1.0 * cw20-streams migration to cosmwasm-* 1.1.0 * Make linter happy * Make linter happy - 2 * Bump contract versions
1 parent c3ea040 commit 23f55c6

File tree

29 files changed

+306
-389
lines changed

29 files changed

+306
-389
lines changed

Cargo.lock

+84-76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/cw20-atomic-swap/Cargo.toml

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cw20-atomic-swap"
3-
version = "0.12.1"
3+
version = "0.13.1"
44
authors = ["Mauro Lacy <[email protected]>"]
55
edition = "2018"
66
description = "Implementation of Atomic Swaps"
@@ -18,16 +18,15 @@ backtraces = ["cosmwasm-std/backtraces"]
1818
library = []
1919

2020
[dependencies]
21-
cw-utils = "0.13.2"
22-
cw2 = "0.13.2"
23-
cw20 = "0.13.2"
24-
cosmwasm-std = "1.0.0"
25-
cw-storage-plus = "0.13.2"
26-
schemars = "0.8.10"
27-
serde = { version = "1.0", default-features = false, features = ["derive"] }
21+
cw-utils = "0.13.4"
22+
cw2 = "0.13.4"
23+
cw20 = "0.13.4"
24+
cosmwasm-schema = "1.1.0"
25+
cosmwasm-std = "1.1.0"
26+
cw-storage-plus = "0.13.4"
2827
thiserror = "1.0.31"
2928
hex = "0.3.2"
3029
sha2 = "0.8.2"
3130

3231
[dev-dependencies]
33-
cosmwasm-schema = "1.0.0"
32+
+6-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
use std::env::current_dir;
2-
use std::fs::create_dir_all;
3-
4-
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
5-
6-
use cw20_atomic_swap::msg::DetailsResponse;
1+
use cosmwasm_schema::write_api;
72
use cw20_atomic_swap::msg::ExecuteMsg;
83
use cw20_atomic_swap::msg::InstantiateMsg;
9-
use cw20_atomic_swap::msg::ListResponse;
104
use cw20_atomic_swap::msg::QueryMsg;
115

126
fn main() {
13-
let mut out_dir = current_dir().unwrap();
14-
out_dir.push("schema");
15-
create_dir_all(&out_dir).unwrap();
16-
remove_schemas(&out_dir).unwrap();
17-
18-
export_schema(&schema_for!(InstantiateMsg), &out_dir);
19-
export_schema(&schema_for!(ExecuteMsg), &out_dir);
20-
export_schema(&schema_for!(QueryMsg), &out_dir);
21-
export_schema(&schema_for!(ListResponse), &out_dir);
22-
export_schema(&schema_for!(DetailsResponse), &out_dir);
7+
write_api! {
8+
instantiate: InstantiateMsg,
9+
query: QueryMsg,
10+
execute: ExecuteMsg,
11+
}
2312
}

contracts/cw20-atomic-swap/src/msg.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use schemars::JsonSchema;
2-
use serde::{Deserialize, Serialize};
1+
use cosmwasm_schema::{cw_serde, QueryResponses};
32

43
use cosmwasm_std::Coin;
54
use cw20::{Cw20Coin, Cw20ReceiveMsg, Expiration};
65

7-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
6+
#[cw_serde]
87
pub struct InstantiateMsg {}
98

10-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
11-
#[serde(rename_all = "snake_case")]
9+
#[cw_serde]
1210
pub enum ExecuteMsg {
1311
Create(CreateMsg),
1412
/// Release sends all tokens to the recipient.
@@ -26,13 +24,12 @@ pub enum ExecuteMsg {
2624
Receive(Cw20ReceiveMsg),
2725
}
2826

29-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
30-
#[serde(rename_all = "snake_case")]
27+
#[cw_serde]
3128
pub enum ReceiveMsg {
3229
Create(CreateMsg),
3330
}
3431

35-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
32+
#[cw_serde]
3633
pub struct CreateMsg {
3734
/// id is a human-readable name for the swap to use later.
3835
/// 3-20 bytes of utf-8 text
@@ -54,26 +51,28 @@ pub fn is_valid_name(name: &str) -> bool {
5451
true
5552
}
5653

57-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
58-
#[serde(rename_all = "snake_case")]
54+
#[cw_serde]
55+
#[derive(QueryResponses)]
5956
pub enum QueryMsg {
6057
/// Show all open swaps. Return type is ListResponse.
58+
#[returns(ListResponse)]
6159
List {
6260
start_after: Option<String>,
6361
limit: Option<u32>,
6462
},
6563
/// Returns the details of the named swap, error if not created.
6664
/// Return type: DetailsResponse.
65+
#[returns(DetailsResponse)]
6766
Details { id: String },
6867
}
6968

70-
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
69+
#[cw_serde]
7170
pub struct ListResponse {
7271
/// List all open swap ids
7372
pub swaps: Vec<String>,
7473
}
7574

76-
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
75+
#[cw_serde]
7776
pub struct DetailsResponse {
7877
/// Id of this swap
7978
pub id: String,
@@ -89,7 +88,7 @@ pub struct DetailsResponse {
8988
pub balance: BalanceHuman,
9089
}
9190

92-
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
91+
#[cw_serde]
9392
pub enum BalanceHuman {
9493
Native(Vec<Coin>),
9594
Cw20(Cw20Coin),

contracts/cw20-atomic-swap/src/state.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use schemars::JsonSchema;
2-
use serde::{Deserialize, Serialize};
1+
use cosmwasm_schema::cw_serde;
32

43
use cosmwasm_std::{Addr, Binary, BlockInfo, Order, StdResult, Storage};
54
use cw_storage_plus::{Bound, Map};
65

76
use cw20::{Balance, Expiration};
87

9-
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
8+
#[cw_serde]
109
pub struct AtomicSwap {
1110
/// This is the sha-256 hash of the preimage
1211
pub hash: Binary,

contracts/cw20-bonding/Cargo.toml

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cw20-bonding"
3-
version = "0.12.1"
3+
version = "0.13.1"
44
authors = ["Ethan Frey <[email protected]>"]
55
edition = "2018"
66
description = "Implement basic bonding curve to issue cw20 tokens"
@@ -20,18 +20,17 @@ backtraces = ["cosmwasm-std/backtraces"]
2020
library = []
2121

2222
[dependencies]
23-
cw-utils = "0.13.2"
24-
cw2 = "0.13.2"
25-
cw20 = "0.13.2"
26-
cw20-base = { version = "0.13.2", features = ["library"] }
27-
cw-storage-plus = "0.13.2"
28-
cosmwasm-std = { version = "1.0.0", default-features = false, features = ["staking"] }
29-
schemars = "0.8.1"
30-
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
31-
thiserror = "1.0.23"
23+
cw-utils = "0.13.4"
24+
cw2 = "0.13.4"
25+
cw20 = "0.13.4"
26+
cw20-base ={version = "0.13.4", features = ["library"]}
27+
cw-storage-plus = "0.13.4"
28+
cosmwasm-std = "1.1.0"
29+
cosmwasm-schema = "1.1.0"
30+
thiserror = "1.0.31"
3231
rust_decimal = "1.14.3"
3332
integer-sqrt = "0.1.5"
3433
integer-cbrt = "0.1.2"
3534

3635
[dev-dependencies]
37-
cosmwasm-schema = "1.0.0"
36+
+7-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
use std::env::current_dir;
2-
use std::fs::create_dir_all;
1+
use cosmwasm_schema::write_api;
32

4-
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
5-
6-
use cw20::{AllowanceResponse, BalanceResponse, TokenInfoResponse};
7-
use cw20_bonding::msg::{CurveInfoResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
3+
use cw20_bonding::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
84

95
fn main() {
10-
let mut out_dir = current_dir().unwrap();
11-
out_dir.push("schema");
12-
create_dir_all(&out_dir).unwrap();
13-
remove_schemas(&out_dir).unwrap();
14-
15-
export_schema(&schema_for!(InstantiateMsg), &out_dir);
16-
export_schema(&schema_for!(ExecuteMsg), &out_dir);
17-
export_schema(&schema_for!(QueryMsg), &out_dir);
18-
export_schema(&schema_for!(AllowanceResponse), &out_dir);
19-
export_schema(&schema_for!(BalanceResponse), &out_dir);
20-
export_schema(&schema_for!(CurveInfoResponse), &out_dir);
21-
export_schema(&schema_for!(TokenInfoResponse), &out_dir);
6+
write_api! {
7+
instantiate: InstantiateMsg,
8+
query: QueryMsg,
9+
execute: ExecuteMsg,
10+
}
2211
}

contracts/cw20-bonding/src/contract.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn execute_buy(
143143
let payment = must_pay(&info, &state.reserve_denom)?;
144144

145145
// calculate how many tokens can be purchased with this and mint them
146-
let curve = curve_fn(state.decimals);
146+
let curve = curve_fn(state.clone().decimals);
147147
state.reserve += payment;
148148
let new_supply = curve.supply(state.reserve);
149149
let minted = new_supply
@@ -236,7 +236,7 @@ fn do_sell(
236236

237237
// calculate how many tokens can be purchased with this and mint them
238238
let mut state = CURVE_STATE.load(deps.storage)?;
239-
let curve = curve_fn(state.decimals);
239+
let curve = curve_fn(state.clone().decimals);
240240
state.supply = state
241241
.supply
242242
.checked_sub(amount)

contracts/cw20-bonding/src/curves.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use cosmwasm_schema::cw_serde;
12
use integer_cbrt::IntegerCubeRoot;
23
use integer_sqrt::IntegerSquareRoot;
34
use rust_decimal::prelude::ToPrimitive;
45
use rust_decimal::Decimal;
5-
use schemars::JsonSchema;
6-
use serde::{Deserialize, Serialize};
76
use std::str::FromStr;
87

98
use cosmwasm_std::{Decimal as StdDecimal, Uint128};
@@ -85,13 +84,13 @@ impl Curve for Constant {
8584
fn reserve(&self, supply: Uint128) -> Uint128 {
8685
// f(x) = supply * self.value
8786
let reserve = self.normalize.from_supply(supply) * self.value;
88-
self.normalize.to_reserve(reserve)
87+
self.normalize.clone().to_reserve(reserve)
8988
}
9089

9190
fn supply(&self, reserve: Uint128) -> Uint128 {
9291
// f(x) = reserve / self.value
9392
let supply = self.normalize.from_reserve(reserve) / self.value;
94-
self.normalize.to_supply(supply)
93+
self.normalize.clone().to_supply(supply)
9594
}
9695
}
9796

@@ -120,15 +119,15 @@ impl Curve for Linear {
120119
let square = normalized * normalized;
121120
// Note: multiplying by 0.5 is much faster than dividing by 2
122121
let reserve = square * self.slope * Decimal::new(5, 1);
123-
self.normalize.to_reserve(reserve)
122+
self.normalize.clone().to_reserve(reserve)
124123
}
125124

126125
fn supply(&self, reserve: Uint128) -> Uint128 {
127126
// f(x) = (2 * reserve / self.slope) ^ 0.5
128127
// note: use addition here to optimize 2* operation
129128
let square = self.normalize.from_reserve(reserve + reserve) / self.slope;
130129
let supply = square_root(square);
131-
self.normalize.to_supply(supply)
130+
self.normalize.clone().to_supply(supply)
132131
}
133132
}
134133

@@ -157,15 +156,15 @@ impl Curve for SquareRoot {
157156
let normalized = self.normalize.from_supply(supply);
158157
let root = square_root(normalized);
159158
let reserve = self.slope * normalized * root / Decimal::new(15, 1);
160-
self.normalize.to_reserve(reserve)
159+
self.normalize.clone().to_reserve(reserve)
161160
}
162161

163162
fn supply(&self, reserve: Uint128) -> Uint128 {
164163
// f(x) = (1.5 * reserve / self.slope) ^ (2/3)
165164
let base = self.normalize.from_reserve(reserve) * Decimal::new(15, 1) / self.slope;
166165
let squared = base * base;
167166
let supply = cube_root(squared);
168-
self.normalize.to_supply(supply)
167+
self.normalize.clone().to_supply(supply)
169168
}
170169
}
171170

@@ -202,7 +201,7 @@ fn cube_root(cube: Decimal) -> Decimal {
202201
}
203202

204203
/// DecimalPlaces should be passed into curve constructors
205-
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, JsonSchema, Default)]
204+
#[cw_serde]
206205
pub struct DecimalPlaces {
207206
/// Number of decimal places for the supply token (this is what was passed in cw20-base instantiate
208207
pub supply: u32,

contracts/cw20-bonding/src/msg.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use schemars::JsonSchema;
2-
use serde::{Deserialize, Serialize};
1+
use cosmwasm_schema::{cw_serde, QueryResponses};
32

43
use crate::curves::{decimal, Constant, Curve, DecimalPlaces, Linear, SquareRoot};
54
use cosmwasm_std::{Binary, Decimal, Uint128};
5+
use cw20::AllowanceResponse as Cw20AllowanceResponse;
6+
use cw20::BalanceResponse as Cw20BalanceResponse;
67
use cw20::Expiration;
8+
use cw20::TokenInfoResponse as Cw20TokenInfoResponse;
79

8-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10+
#[cw_serde]
911
pub struct InstantiateMsg {
1012
/// name of the supply token
1113
pub name: String,
@@ -30,8 +32,7 @@ pub struct InstantiateMsg {
3032

3133
pub type CurveFn = Box<dyn Fn(DecimalPlaces) -> Box<dyn Curve>>;
3234

33-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
34-
#[serde(rename_all = "snake_case")]
35+
#[cw_serde]
3536
pub enum CurveType {
3637
/// Constant always returns `value * 10^-scale` as spot price
3738
Constant { value: Uint128, scale: u32 },
@@ -66,8 +67,7 @@ impl CurveType {
6667
}
6768
}
6869

69-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
70-
#[serde(rename_all = "snake_case")]
70+
#[cw_serde]
7171
pub enum ExecuteMsg {
7272
/// Buy will attempt to purchase as many supply tokens as possible.
7373
/// You must send only reserve tokens in that message
@@ -119,22 +119,25 @@ pub enum ExecuteMsg {
119119
BurnFrom { owner: String, amount: Uint128 },
120120
}
121121

122-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
123-
#[serde(rename_all = "snake_case")]
122+
#[cw_serde]
123+
#[derive(QueryResponses)]
124124
pub enum QueryMsg {
125125
/// Returns the reserve and supply quantities, as well as the spot price to buy 1 token
126+
#[returns(CurveInfoResponse)]
126127
CurveInfo {},
127-
128128
/// Implements CW20. Returns the current balance of the given address, 0 if unset.
129+
#[returns(Cw20BalanceResponse)]
129130
Balance { address: String },
130131
/// Implements CW20. Returns metadata on the contract - name, decimals, supply, etc.
132+
#[returns(Cw20TokenInfoResponse)]
131133
TokenInfo {},
132134
/// Implements CW20 "allowance" extension.
133135
/// Returns how much spender can use from owner account, 0 if unset.
136+
#[returns(Cw20AllowanceResponse)]
134137
Allowance { owner: String, spender: String },
135138
}
136139

137-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
140+
#[cw_serde]
138141
pub struct CurveInfoResponse {
139142
// how many reserve tokens have been received
140143
pub reserve: Uint128,

contracts/cw20-bonding/src/state.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use schemars::JsonSchema;
2-
use serde::{Deserialize, Serialize};
1+
use cosmwasm_schema::cw_serde;
32

43
use cosmwasm_std::Uint128;
54
use cw_storage_plus::Item;
@@ -8,7 +7,7 @@ use crate::curves::DecimalPlaces;
87
use crate::msg::CurveType;
98

109
/// Supply is dynamic and tracks the current supply of staked and ERC20 tokens.
11-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Default)]
10+
#[cw_serde]
1211
pub struct CurveState {
1312
/// reserve is how many native tokens exist bonded to the validator
1413
pub reserve: Uint128,

0 commit comments

Comments
 (0)