1
- use cosmwasm_std:: { attr, Addr , BankMsg , CosmosMsg , DepsMut , Env , MessageInfo , Response , Uint128 } ;
1
+ use cosmwasm_std:: { attr, BankMsg , CosmosMsg , DepsMut , Env , MessageInfo , Response , Uint128 } ;
2
2
3
3
use crate :: {
4
4
helpers:: {
@@ -17,6 +17,7 @@ use crate::{
17
17
validate_pot_limit_not_exceeded,
18
18
} ,
19
19
} ,
20
+ msg:: UpdateGameConfig ,
20
21
state:: { GAME_CONFIG , GAME_STATE , PLAYER_ALLOCATIONS , REALLOCATION_FEE_POOL } ,
21
22
ContractError ,
22
23
} ;
@@ -25,72 +26,62 @@ pub fn update_config(
25
26
deps : DepsMut ,
26
27
env : Env ,
27
28
info : MessageInfo ,
28
- fee : Option < u64 > ,
29
- fee_reallocation : Option < u64 > ,
30
- fee_address : Option < Addr > ,
31
- game_denom : Option < String > ,
32
- game_cw721_addrs : Vec < Addr > , // this is the cw721 collection addy we use as optional raffle prize
33
- game_duration : Option < u64 > ,
34
- game_extend : Option < u64 > ,
35
- game_end_threshold : Option < u64 > ,
36
- min_pot_initial_allocation : Option < Uint128 > ,
37
- decay_factor : Option < Uint128 > , // i.e. 95 as 95%
38
- reallocations_limit : Option < u64 > ,
29
+ update_config : UpdateGameConfig ,
39
30
) -> Result < Response , ContractError > {
40
31
validate_is_contract_admin ( & deps. querier , & env, & info. sender ) ?;
41
32
42
33
let mut game_config = GAME_CONFIG . load ( deps. storage ) ?;
43
34
44
- if let Some ( fee) = fee {
35
+ if let Some ( fee) = update_config . fee {
45
36
if fee > 10 {
46
37
return Err ( ContractError :: InvalidInput { } ) ;
47
38
}
48
39
game_config. fee = fee;
49
40
}
50
- if let Some ( fee_reallocation) = fee_reallocation {
41
+ if let Some ( fee_reallocation) = update_config . fee_reallocation {
51
42
if fee_reallocation > 50 {
52
43
return Err ( ContractError :: InvalidInput { } ) ;
53
44
}
54
45
game_config. fee_reallocation = fee_reallocation;
55
46
}
56
- if let Some ( fee_address) = fee_address {
47
+ if let Some ( fee_address) = update_config . fee_address {
57
48
game_config. fee_address = deps. api . addr_validate ( fee_address. as_str ( ) ) ?;
58
49
}
59
- if let Some ( game_denom) = game_denom {
50
+ if let Some ( game_denom) = update_config . game_denom {
60
51
game_config. game_denom = game_denom;
61
52
}
62
53
if !game_config
63
54
. game_cw721_addrs
64
55
. iter ( )
65
- . eq ( game_cw721_addrs. iter ( ) )
56
+ . eq ( update_config . game_cw721_addrs . iter ( ) )
66
57
{
67
- for address in & game_cw721_addrs {
58
+ for address in & update_config . game_cw721_addrs {
68
59
deps. api . addr_validate ( address. as_str ( ) ) ?;
69
60
}
70
- game_config. game_cw721_addrs = game_cw721_addrs;
61
+ game_config. game_cw721_addrs = update_config . game_cw721_addrs ;
71
62
}
72
- if let Some ( game_duration) = game_duration {
63
+ if let Some ( game_duration) = update_config . game_duration {
73
64
game_config. game_duration = game_duration;
74
65
}
75
- if let Some ( game_extend) = game_extend {
66
+ if let Some ( game_extend) = update_config . game_extend {
76
67
if game_extend > game_config. game_duration {
77
68
return Err ( ContractError :: InvalidInput { } ) ;
78
69
}
79
70
game_config. game_extend = game_extend;
80
71
}
81
- if let Some ( game_end_threshold) = game_end_threshold {
72
+ if let Some ( game_end_threshold) = update_config . game_end_threshold {
82
73
game_config. game_end_threshold = game_end_threshold;
83
74
}
84
- if let Some ( min_pot_initial_allocation) = min_pot_initial_allocation {
75
+ if let Some ( min_pot_initial_allocation) = update_config . min_pot_initial_allocation {
85
76
game_config. min_pot_initial_allocation = min_pot_initial_allocation;
86
77
}
87
- if let Some ( decay_factor) = decay_factor {
78
+ if let Some ( decay_factor) = update_config . decay_factor {
88
79
if decay_factor. lt ( & Uint128 :: new ( 50u128 ) ) || decay_factor. gt ( & Uint128 :: new ( 99u128 ) ) {
89
80
return Err ( ContractError :: InvalidInput { } ) ;
90
81
}
91
82
game_config. decay_factor = decay_factor;
92
83
}
93
- if let Some ( reallocations_limit) = reallocations_limit {
84
+ if let Some ( reallocations_limit) = update_config . reallocations_limit {
94
85
game_config. reallocations_limit = reallocations_limit;
95
86
}
96
87
GAME_CONFIG . save ( deps. storage , & game_config) ?;
@@ -223,22 +214,15 @@ pub fn game_end(
223
214
let mut msgs: Vec < CosmosMsg > = vec ! [ ] ;
224
215
225
216
// Process raffle winner and prepare distribution messages
226
- let (
227
- raffle_msgs, // bank sends
228
- raffle_submsgs, // nft transfer
229
- raffle_response_attributes,
230
- new_raffle_denom_amount,
231
- updated_new_raffle_cw721_id,
232
- updated_new_raffle_cw721_addr,
233
- ) = process_raffle_winner (
217
+ let process_raffle_winner_resp = process_raffle_winner (
234
218
& deps. as_ref ( ) ,
235
219
& env,
236
220
& info. funds ,
237
221
& winning_pots,
238
222
new_raffle_cw721_id,
239
223
new_raffle_cw721_addr,
240
224
) ?;
241
- msgs. extend ( raffle_msgs . clone ( ) ) ;
225
+ msgs. extend ( process_raffle_winner_resp . msgs . clone ( ) ) ;
242
226
243
227
// Add messages for redistributing tokens from losing to winning pots
244
228
let ( send_msgs, treasury_outgoing_tokens) =
@@ -248,7 +232,8 @@ pub fn game_end(
248
232
249
233
// Iterate again the msgs generated to know how much tokens effectively we send,
250
234
// as total_losing_tokens contains also next game funds we want to preserve.
251
- let total_outgoing_raffle: Uint128 = raffle_msgs
235
+ let total_outgoing_raffle: Uint128 = process_raffle_winner_resp
236
+ . msgs
252
237
. iter ( )
253
238
. filter_map ( |msg| {
254
239
if let CosmosMsg :: Bank ( BankMsg :: Send { amount, .. } ) = msg {
@@ -279,14 +264,14 @@ pub fn game_end(
279
264
deps,
280
265
& env,
281
266
total_outgoing_tokens,
282
- updated_new_raffle_cw721_id ,
283
- updated_new_raffle_cw721_addr ,
284
- Some ( new_raffle_denom_amount) ,
267
+ process_raffle_winner_resp . new_raffle_cw721_id ,
268
+ process_raffle_winner_resp . new_raffle_cw721_addr ,
269
+ Some ( process_raffle_winner_resp . new_raffle_denom_amount ) ,
285
270
) ?;
286
271
287
272
Ok ( Response :: new ( )
288
273
. add_messages ( msgs)
289
- . add_submessages ( raffle_submsgs )
274
+ . add_submessages ( process_raffle_winner_resp . submsgs )
290
275
. add_attributes ( vec ! [
291
276
attr( "method" , "execute" ) ,
292
277
attr( "action" , "game_end" ) ,
@@ -299,6 +284,6 @@ pub fn game_end(
299
284
) ,
300
285
attr( "treasury_outgoing_tokens" , treasury_outgoing_tokens) ,
301
286
] )
302
- . add_attributes ( raffle_response_attributes ) // this contains the raffle event attributes including the treasury denom fee split, which is not included above
287
+ . add_attributes ( process_raffle_winner_resp . attributes ) // this contains the raffle event attributes including the treasury denom fee split, which is not included above
303
288
. add_attribute ( "total_outgoing_tokens" , total_outgoing_tokens) ) // this is the total of distribution + raffle + treasury
304
289
}
0 commit comments