hpl_interface/igp/
core.rs

1use cosmwasm_schema::{cw_serde, QueryResponses};
2use cosmwasm_std::{Addr, HexBinary, Uint256};
3
4use crate::{
5    hook::{HookQueryMsg, PostDispatchMsg},
6    ownable::{OwnableMsg, OwnableQueryMsg},
7    router::{RouterMsg, RouterQuery},
8    Order,
9};
10
11use super::oracle::IgpGasOracleQueryMsg;
12
13#[cw_serde]
14pub struct InstantiateMsg {
15    pub hrp: String,
16    pub owner: String,
17    pub gas_token: String,
18    pub beneficiary: String,
19    pub default_gas_usage: u128,
20}
21
22#[cw_serde]
23pub struct GasOracleConfig {
24    pub remote_domain: u32,
25    pub gas_oracle: String,
26}
27
28impl From<(u32, String)> for GasOracleConfig {
29    fn from((remote_domain, gas_oracle): (u32, String)) -> Self {
30        Self {
31            remote_domain,
32            gas_oracle,
33        }
34    }
35}
36
37impl From<(u32, Addr)> for GasOracleConfig {
38    fn from((remote_domain, gas_oracle): (u32, Addr)) -> Self {
39        Self {
40            remote_domain,
41            gas_oracle: gas_oracle.to_string(),
42        }
43    }
44}
45
46#[cw_serde]
47pub enum ExecuteMsg {
48    // overrides
49    Ownable(OwnableMsg),
50    Router(RouterMsg<Addr>),
51    PostDispatch(PostDispatchMsg),
52
53    // base
54    SetDefaultGas {
55        gas: u128,
56    },
57    SetGasForDomain {
58        config: Vec<(u32, u128)>,
59    },
60    UnsetGasForDomain {
61        domains: Vec<u32>,
62    },
63
64    SetBeneficiary {
65        beneficiary: String,
66    },
67    PayForGas {
68        message_id: HexBinary,
69        dest_domain: u32,
70        gas_amount: Uint256,
71        refund_address: String,
72    },
73    Claim {},
74}
75
76#[cw_serde]
77#[derive(QueryResponses)]
78#[query_responses(nested)]
79pub enum QueryMsg {
80    // overrides
81    Ownable(OwnableQueryMsg),
82    Hook(HookQueryMsg),
83    Router(RouterQuery<Addr>),
84    Oracle(IgpGasOracleQueryMsg),
85
86    // base
87    Igp(IgpQueryMsg),
88}
89
90#[cw_serde]
91#[derive(QueryResponses)]
92pub enum IgpQueryMsg {
93    #[returns(DefaultGasResponse)]
94    DefaultGas {},
95
96    #[returns(GasForDomainResponse)]
97    GasForDomain { domains: Vec<u32> },
98
99    #[returns(GasForDomainResponse)]
100    ListGasForDomains {
101        offset: Option<u32>,
102        limit: Option<u32>,
103        order: Option<Order>,
104    },
105
106    #[returns(BeneficiaryResponse)]
107    Beneficiary {},
108
109    #[returns(QuoteGasPaymentResponse)]
110    QuoteGasPayment {
111        dest_domain: u32,
112        gas_amount: Uint256,
113    },
114}
115
116impl IgpQueryMsg {
117    pub fn wrap(self) -> QueryMsg {
118        QueryMsg::Igp(self)
119    }
120}
121
122#[cw_serde]
123pub struct DefaultGasResponse {
124    pub gas: u128,
125}
126
127#[cw_serde]
128pub struct GasForDomainResponse {
129    pub gas: Vec<(u32, u128)>,
130}
131
132#[cw_serde]
133pub struct BeneficiaryResponse {
134    pub beneficiary: String,
135}
136
137#[cw_serde]
138pub struct QuoteGasPaymentResponse {
139    pub gas_needed: Uint256,
140}
141
142#[cfg(test)]
143mod test {
144    use cosmwasm_std::HexBinary;
145
146    use super::*;
147    use crate::{
148        hook::{ExpectedHookQueryMsg, PostDispatchMsg, QuoteDispatchMsg},
149        msg_checker,
150    };
151
152    #[test]
153    fn test_hook_interface() {
154        let _checked: ExecuteMsg = msg_checker(
155            PostDispatchMsg {
156                metadata: HexBinary::default(),
157                message: HexBinary::default(),
158            }
159            .wrap(),
160        );
161
162        let _checked: QueryMsg = msg_checker(ExpectedHookQueryMsg::Hook(HookQueryMsg::Mailbox {}));
163        let _checked: QueryMsg = msg_checker(
164            QuoteDispatchMsg {
165                metadata: HexBinary::default(),
166                message: HexBinary::default(),
167            }
168            .request(),
169        );
170    }
171}