@@ -24,15 +24,18 @@ pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
24
24
25
25
const REPLY_ID_INSTANTIATE : u64 = 1 ;
26
26
27
- #[ cfg( not( any( test, feature = "mt" ) ) ) ]
28
- pub type ConverterCustomMsg = cosmwasm_std:: Empty ;
29
- #[ cfg( any( test, feature = "mt" ) ) ]
30
- pub type ConverterCustomMsg = mesh_bindings:: VirtualStakeCustomMsg ;
31
-
32
- #[ cfg( not( any( test, feature = "mt" ) ) ) ]
33
- pub type ConverterCustomQuery = cosmwasm_std:: Empty ;
34
- #[ cfg( any( test, feature = "mt" ) ) ]
35
- pub type ConverterCustomQuery = mesh_bindings:: VirtualStakeCustomQuery ;
27
+ #[ cfg( not( feature = "fake-custom" ) ) ]
28
+ pub mod custom {
29
+ pub type ConverterMsg = cosmwasm_std:: Empty ;
30
+ pub type ConverterQuery = cosmwasm_std:: Empty ;
31
+ pub type Response = cosmwasm_std:: Response < cosmwasm_std:: Empty > ;
32
+ }
33
+ #[ cfg( feature = "fake-custom" ) ]
34
+ pub mod custom {
35
+ pub type ConverterMsg = mesh_bindings:: VirtualStakeCustomMsg ;
36
+ pub type ConverterQuery = mesh_bindings:: VirtualStakeCustomQuery ;
37
+ pub type Response = cosmwasm_std:: Response < ConverterMsg > ;
38
+ }
36
39
37
40
pub struct ConverterContract < ' a > {
38
41
pub config : Item < ' a , Config > ,
@@ -44,7 +47,7 @@ pub struct ConverterContract<'a> {
44
47
#[ sv:: error( ContractError ) ]
45
48
#[ sv:: messages( converter_api as ConverterApi ) ]
46
49
/// Workaround for lack of support in communication `Empty` <-> `Custom` Contracts.
47
- #[ sv:: custom( query=ConverterCustomQuery , msg=ConverterCustomMsg ) ]
50
+ #[ sv:: custom( query=custom :: ConverterQuery , msg=custom :: ConverterMsg ) ]
48
51
impl ConverterContract < ' _ > {
49
52
pub const fn new ( ) -> Self {
50
53
Self {
@@ -63,13 +66,13 @@ impl ConverterContract<'_> {
63
66
#[ sv:: msg( instantiate) ]
64
67
pub fn instantiate (
65
68
& self ,
66
- ctx : InstantiateCtx < ConverterCustomQuery > ,
69
+ ctx : InstantiateCtx < custom :: ConverterQuery > ,
67
70
price_feed : String ,
68
71
discount : Decimal ,
69
72
remote_denom : String ,
70
73
virtual_staking_code_id : u64 ,
71
74
admin : Option < String > ,
72
- ) -> Result < Response , ContractError > {
75
+ ) -> Result < custom :: Response , ContractError > {
73
76
nonpayable ( & ctx. info ) ?;
74
77
// validate args
75
78
if discount >= Decimal :: one ( ) {
@@ -108,9 +111,9 @@ impl ConverterContract<'_> {
108
111
#[ sv:: msg( reply) ]
109
112
fn reply (
110
113
& self ,
111
- ctx : ReplyCtx < ConverterCustomQuery > ,
114
+ ctx : ReplyCtx < custom :: ConverterQuery > ,
112
115
reply : Reply ,
113
- ) -> Result < Response , ContractError > {
116
+ ) -> Result < custom :: Response , ContractError > {
114
117
match reply. id {
115
118
REPLY_ID_INSTANTIATE => self . reply_init_callback ( ctx. deps , reply. result . unwrap ( ) ) ,
116
119
_ => Err ( ContractError :: InvalidReplyId ( reply. id ) ) ,
@@ -120,9 +123,9 @@ impl ConverterContract<'_> {
120
123
/// Store virtual staking address
121
124
fn reply_init_callback (
122
125
& self ,
123
- deps : DepsMut < ConverterCustomQuery > ,
126
+ deps : DepsMut < custom :: ConverterQuery > ,
124
127
reply : SubMsgResponse ,
125
- ) -> Result < Response , ContractError > {
128
+ ) -> Result < custom :: Response , ContractError > {
126
129
let init_data = parse_instantiate_response_data ( & reply. data . unwrap ( ) ) ?;
127
130
let virtual_staking = Addr :: unchecked ( init_data. contract_address ) ;
128
131
self . virtual_stake . save ( deps. storage , & virtual_staking) ?;
@@ -134,10 +137,10 @@ impl ConverterContract<'_> {
134
137
#[ sv:: msg( exec) ]
135
138
fn test_stake (
136
139
& self ,
137
- ctx : ExecCtx < ConverterCustomQuery > ,
140
+ ctx : ExecCtx < custom :: ConverterQuery > ,
138
141
validator : String ,
139
142
stake : Coin ,
140
- ) -> Result < Response , ContractError > {
143
+ ) -> Result < custom :: Response , ContractError > {
141
144
#[ cfg( any( test, feature = "mt" ) ) ]
142
145
{
143
146
// This can only ever be called in tests
@@ -155,10 +158,10 @@ impl ConverterContract<'_> {
155
158
#[ sv:: msg( exec) ]
156
159
fn test_unstake (
157
160
& self ,
158
- ctx : ExecCtx < ConverterCustomQuery > ,
161
+ ctx : ExecCtx < custom :: ConverterQuery > ,
159
162
validator : String ,
160
163
unstake : Coin ,
161
- ) -> Result < Response , ContractError > {
164
+ ) -> Result < custom :: Response , ContractError > {
162
165
#[ cfg( any( test, feature = "mt" ) ) ]
163
166
{
164
167
// This can only ever be called in tests
@@ -176,10 +179,10 @@ impl ConverterContract<'_> {
176
179
#[ sv:: msg( exec) ]
177
180
fn test_burn (
178
181
& self ,
179
- ctx : ExecCtx < ConverterCustomQuery > ,
182
+ ctx : ExecCtx < custom :: ConverterQuery > ,
180
183
validators : Vec < String > ,
181
184
burn : Coin ,
182
- ) -> Result < Response , ContractError > {
185
+ ) -> Result < custom :: Response , ContractError > {
183
186
#[ cfg( any( test, feature = "mt" ) ) ]
184
187
{
185
188
// This can only ever be called in tests
@@ -193,7 +196,10 @@ impl ConverterContract<'_> {
193
196
}
194
197
195
198
#[ sv:: msg( query) ]
196
- fn config ( & self , ctx : QueryCtx < ConverterCustomQuery > ) -> Result < ConfigResponse , ContractError > {
199
+ fn config (
200
+ & self ,
201
+ ctx : QueryCtx < custom:: ConverterQuery > ,
202
+ ) -> Result < ConfigResponse , ContractError > {
197
203
let config = self . config . load ( ctx. deps . storage ) ?;
198
204
let virtual_staking = self . virtual_stake . load ( ctx. deps . storage ) ?. into_string ( ) ;
199
205
Ok ( ConfigResponse {
@@ -207,10 +213,10 @@ impl ConverterContract<'_> {
207
213
/// It is pulled out into a method, so it can also be called by test_stake for testing
208
214
pub ( crate ) fn stake (
209
215
& self ,
210
- deps : DepsMut < ConverterCustomQuery > ,
216
+ deps : DepsMut < custom :: ConverterQuery > ,
211
217
validator : String ,
212
218
stake : Coin ,
213
- ) -> Result < Response , ContractError > {
219
+ ) -> Result < custom :: Response , ContractError > {
214
220
let amount = self . normalize_price ( deps. as_ref ( ) , stake) ?;
215
221
216
222
let event = Event :: new ( "mesh-bond" )
@@ -231,10 +237,10 @@ impl ConverterContract<'_> {
231
237
/// It is pulled out into a method, so it can also be called by test_unstake for testing
232
238
pub ( crate ) fn unstake (
233
239
& self ,
234
- deps : DepsMut < ConverterCustomQuery > ,
240
+ deps : DepsMut < custom :: ConverterQuery > ,
235
241
validator : String ,
236
242
unstake : Coin ,
237
- ) -> Result < Response , ContractError > {
243
+ ) -> Result < custom :: Response , ContractError > {
238
244
let amount = self . normalize_price ( deps. as_ref ( ) , unstake) ?;
239
245
240
246
let event = Event :: new ( "mesh-unbond" )
@@ -255,10 +261,10 @@ impl ConverterContract<'_> {
255
261
/// It is pulled out into a method, so it can also be called by test_burn for testing
256
262
pub ( crate ) fn burn (
257
263
& self ,
258
- deps : DepsMut < ConverterCustomQuery > ,
264
+ deps : DepsMut < custom :: ConverterQuery > ,
259
265
validators : & [ String ] ,
260
266
burn : Coin ,
261
- ) -> Result < Response , ContractError > {
267
+ ) -> Result < custom :: Response , ContractError > {
262
268
let amount = self . normalize_price ( deps. as_ref ( ) , burn) ?;
263
269
264
270
let event = Event :: new ( "mesh-burn" )
@@ -280,7 +286,7 @@ impl ConverterContract<'_> {
280
286
281
287
fn normalize_price (
282
288
& self ,
283
- deps : Deps < ConverterCustomQuery > ,
289
+ deps : Deps < custom :: ConverterQuery > ,
284
290
amount : Coin ,
285
291
) -> Result < Coin , ContractError > {
286
292
let config = self . config . load ( deps. storage ) ?;
@@ -298,10 +304,13 @@ impl ConverterContract<'_> {
298
304
// also see https://github.com/CosmWasm/sylvia/issues/181 to just store Remote in state
299
305
use price_feed_api:: sv:: Querier ;
300
306
use sylvia:: types:: Remote ;
301
- // NOTE: Jan, this feels hacky... I'm not sure if this is the right way to do it
302
- // Also, I am sticking in a random error type here, not what I will get (which is unknown)
303
- let remote =
304
- Remote :: < & dyn price_feed_api:: PriceFeedApi < Error = StdError > > :: new ( config. price_feed ) ;
307
+ let remote = Remote :: <
308
+ dyn price_feed_api:: PriceFeedApi <
309
+ Error = StdError ,
310
+ ExecC = custom:: ConverterMsg ,
311
+ QueryC = custom:: ConverterQuery ,
312
+ > ,
313
+ > :: new ( config. price_feed ) ;
305
314
let price = remote. querier ( & deps. querier ) . price ( ) ?. native_per_foreign ;
306
315
let converted = ( amount. amount * price) * config. price_adjustment ;
307
316
@@ -313,7 +322,7 @@ impl ConverterContract<'_> {
313
322
314
323
fn invert_price (
315
324
& self ,
316
- deps : Deps < ConverterCustomQuery > ,
325
+ deps : Deps < custom :: ConverterQuery > ,
317
326
amount : Coin ,
318
327
) -> Result < Coin , ContractError > {
319
328
let config = self . config . load ( deps. storage ) ?;
@@ -330,10 +339,14 @@ impl ConverterContract<'_> {
330
339
// also see https://github.com/CosmWasm/sylvia/issues/181 to just store Remote in state
331
340
use price_feed_api:: sv:: Querier ;
332
341
use sylvia:: types:: Remote ;
333
- // NOTE: Jan, this feels hacky... I'm not sure if this is the right way to do it
334
- // Also, I am sticking in a random error type here, not what I will get (which is unknown)
335
- let remote =
336
- Remote :: < & dyn price_feed_api:: PriceFeedApi < Error = StdError > > :: new ( config. price_feed ) ;
342
+ // Note: it doesn't seem to matter which error type goes here...
343
+ let remote = Remote :: <
344
+ dyn price_feed_api:: PriceFeedApi <
345
+ Error = StdError ,
346
+ ExecC = custom:: ConverterMsg ,
347
+ QueryC = custom:: ConverterQuery ,
348
+ > ,
349
+ > :: new ( config. price_feed ) ;
337
350
let price = remote. querier ( & deps. querier ) . price ( ) ?. native_per_foreign ;
338
351
let converted = ( amount. amount * price. inv ( ) . ok_or ( ContractError :: InvalidPrice { } ) ?)
339
352
* config
@@ -349,10 +362,10 @@ impl ConverterContract<'_> {
349
362
350
363
pub ( crate ) fn transfer_rewards (
351
364
& self ,
352
- deps : Deps < ConverterCustomQuery > ,
365
+ deps : Deps < custom :: ConverterQuery > ,
353
366
recipient : String ,
354
367
rewards : Coin ,
355
- ) -> Result < CosmosMsg , ContractError > {
368
+ ) -> Result < CosmosMsg < custom :: ConverterMsg > , ContractError > {
356
369
// ensure the address is proper
357
370
let recipient = deps. api . addr_validate ( & recipient) ?;
358
371
@@ -377,7 +390,7 @@ impl ConverterContract<'_> {
377
390
378
391
fn ensure_authorized (
379
392
& self ,
380
- deps : & DepsMut < ConverterCustomQuery > ,
393
+ deps : & DepsMut < custom :: ConverterQuery > ,
381
394
info : & MessageInfo ,
382
395
) -> Result < ( ) , ContractError > {
383
396
let virtual_stake = self . virtual_stake . load ( deps. storage ) ?;
@@ -389,14 +402,16 @@ impl ConverterContract<'_> {
389
402
390
403
impl ConverterApi for ConverterContract < ' _ > {
391
404
type Error = ContractError ;
405
+ type ExecC = custom:: ConverterMsg ;
406
+ type QueryC = custom:: ConverterQuery ;
392
407
393
408
/// Rewards tokens (in native staking denom) are sent alongside the message, and should be distributed to all
394
409
/// stakers who staked on this validator. This is tracked on the provider, so we send an IBC packet there.
395
410
fn distribute_reward (
396
411
& self ,
397
- mut ctx : ExecCtx < ConverterCustomQuery > ,
412
+ mut ctx : ExecCtx < custom :: ConverterQuery > ,
398
413
validator : String ,
399
- ) -> Result < Response , Self :: Error > {
414
+ ) -> Result < custom :: Response , Self :: Error > {
400
415
self . ensure_authorized ( & ctx. deps , & ctx. info ) ?;
401
416
402
417
let config = self . config . load ( ctx. deps . storage ) ?;
@@ -419,9 +434,9 @@ impl ConverterApi for ConverterContract<'_> {
419
434
/// in the native staking denom.
420
435
fn distribute_rewards (
421
436
& self ,
422
- mut ctx : ExecCtx < ConverterCustomQuery > ,
437
+ mut ctx : ExecCtx < custom :: ConverterQuery > ,
423
438
payments : Vec < RewardInfo > ,
424
- ) -> Result < Response , Self :: Error > {
439
+ ) -> Result < custom :: Response , Self :: Error > {
425
440
self . ensure_authorized ( & ctx. deps , & ctx. info ) ?;
426
441
427
442
let config = self . config . load ( ctx. deps . storage ) ?;
@@ -459,15 +474,15 @@ impl ConverterApi for ConverterContract<'_> {
459
474
#[ allow( clippy:: too_many_arguments) ]
460
475
fn valset_update (
461
476
& self ,
462
- ctx : ExecCtx < ConverterCustomQuery > ,
477
+ ctx : ExecCtx < custom :: ConverterQuery > ,
463
478
additions : Vec < Validator > ,
464
479
removals : Vec < String > ,
465
480
updated : Vec < Validator > ,
466
481
jailed : Vec < String > ,
467
482
unjailed : Vec < String > ,
468
483
tombstoned : Vec < String > ,
469
484
mut slashed : Vec < ValidatorSlashInfo > ,
470
- ) -> Result < Response , Self :: Error > {
485
+ ) -> Result < custom :: Response , Self :: Error > {
471
486
self . ensure_authorized ( & ctx. deps , & ctx. info ) ?;
472
487
473
488
// Send over IBC to the Consumer
0 commit comments