1+ //! A guest program that provides information about asset swaps.
12#![ no_std]
23#![ no_main]
34
5+ /// A guest program that provides information about asset swaps.
46#[ pvq_program:: program]
57mod swap_info {
68
9+ /// Represents a unique identifier for an asset.
710 type AssetId = alloc:: vec:: Vec < u8 > ;
11+ /// Represents the balance of an asset.
812 type Balance = u128 ;
13+ /// Represents information about an asset.
914 #[ derive(
1015 Debug , Clone , PartialEq , Eq , parity_scale_codec:: Encode , parity_scale_codec:: Decode , scale_info:: TypeInfo ,
1116 ) ]
1217 pub struct AssetInfo {
18+ /// The unique identifier of the asset.
1319 pub asset_id : AssetId ,
20+ /// The name of the asset.
1421 pub name : alloc:: vec:: Vec < u8 > ,
22+ /// The symbol of the asset.
1523 pub symbol : alloc:: vec:: Vec < u8 > ,
24+ /// The number of decimals the asset has.
1625 pub decimals : u8 ,
1726 }
1827
28+ /// Get the quote price of `asset1` in terms of `asset2` for a given amount of `asset2`.
29+ ///
30+ /// # Arguments
31+ ///
32+ /// * `asset1`: The identifier of the asset to be quoted.
33+ /// * `asset2`: The identifier of the asset to quote against.
34+ /// * `amount`: The amount of `asset2`.
35+ /// * `include_fee`: Whether to include the fee in the quote.
36+ ///
37+ /// # Returns
38+ ///
39+ /// The quote price of `asset1` in terms of `asset2`, or `None` if the quote is not available.
1940 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 0 ) ]
2041 fn quote_price_tokens_for_exact_tokens (
2142 asset1 : AssetId ,
@@ -25,6 +46,18 @@ mod swap_info {
2546 ) -> Option < Balance > {
2647 }
2748
49+ /// Get the quote price of `asset2` in terms of `asset1` for a given amount of `asset1`.
50+ ///
51+ /// # Arguments
52+ ///
53+ /// * `asset1`: The identifier of the asset to quote against.
54+ /// * `asset2`: The identifier of the asset to be quoted.
55+ /// * `amount`: The amount of `asset1`.
56+ /// * `include_fee`: Whether to include the fee in the quote.
57+ ///
58+ /// # Returns
59+ ///
60+ /// The quote price of `asset2` in terms of `asset1`, or `None` if the quote is not available.
2861 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 1 ) ]
2962 fn quote_price_exact_tokens_for_tokens (
3063 asset1 : AssetId ,
@@ -34,18 +67,58 @@ mod swap_info {
3467 ) -> Option < Balance > {
3568 }
3669
70+ /// Get the liquidity pool of two assets.
71+ ///
72+ /// # Arguments
73+ ///
74+ /// * `asset1`: The identifier of the first asset.
75+ /// * `asset2`: The identifier of the second asset.
76+ ///
77+ /// # Returns
78+ ///
79+ /// A tuple containing the balance of each asset in the liquidity pool, or `None` if the pool does not exist.
3780 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 2 ) ]
3881 fn get_liquidity_pool ( asset1 : AssetId , asset2 : AssetId ) -> Option < ( Balance , Balance ) > { }
3982
83+ /// List all available liquidity pools.
84+ ///
85+ /// # Returns
86+ ///
87+ /// A list of tuples, where each tuple represents a liquidity pool and contains the identifiers of the two assets in the pool.
4088 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 3 ) ]
4189 fn list_pools ( ) -> alloc:: vec:: Vec < ( AssetId , AssetId ) > { }
4290
91+ /// Get information about a specific asset.
92+ ///
93+ /// # Arguments
94+ ///
95+ /// * `asset`: The identifier of the asset.
96+ ///
97+ /// # Returns
98+ ///
99+ /// Information about the asset, or `None` if the asset does not exist.
43100 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 4 ) ]
44101 fn asset_info ( asset : AssetId ) -> Option < AssetInfo > { }
45102
103+ /// Get information about all assets.
104+ ///
105+ /// # Returns
106+ ///
107+ /// A map of asset identifiers to asset information.
46108 #[ program:: extension_fn( extension_id = 15900548380266538526u64 , fn_index = 5 ) ]
47109 fn assets_info ( ) -> alloc:: collections:: BTreeMap < AssetId , AssetInfo > { }
48110
111+ /// Get the quote price of `asset2` in terms of `asset1` for a given amount of `asset1`.
112+ ///
113+ /// # Arguments
114+ ///
115+ /// * `asset1`: The identifier of the asset to quote against.
116+ /// * `asset2`: The identifier of the asset to be quoted.
117+ /// * `amount`: The amount of `asset1`.
118+ ///
119+ /// # Returns
120+ ///
121+ /// The quote price of `asset2` in terms of `asset1`, or `None` if the quote is not available.
49122 #[ program:: entrypoint]
50123 fn entrypoint_quote_price_exact_tokens_for_tokens (
51124 asset1 : AssetId ,
@@ -55,6 +128,17 @@ mod swap_info {
55128 quote_price_exact_tokens_for_tokens ( asset1, asset2, amount, true )
56129 }
57130
131+ /// Get the quote price of `asset1` in terms of `asset2` for a given amount of `asset2`.
132+ ///
133+ /// # Arguments
134+ ///
135+ /// * `asset1`: The identifier of the asset to be quoted.
136+ /// * `asset2`: The identifier of the asset to quote against.
137+ /// * `amount`: The amount of `asset2`.
138+ ///
139+ /// # Returns
140+ ///
141+ /// The quote price of `asset1` in terms of `asset2`, or `None` if the quote is not available.
58142 #[ program:: entrypoint]
59143 fn entrypoint_quote_price_tokens_for_exact_tokens (
60144 asset1 : AssetId ,
@@ -64,11 +148,26 @@ mod swap_info {
64148 quote_price_tokens_for_exact_tokens ( asset1, asset2, amount, true )
65149 }
66150
151+ /// Get the liquidity pool of two assets.
152+ ///
153+ /// # Arguments
154+ ///
155+ /// * `asset1`: The identifier of the first asset.
156+ /// * `asset2`: The identifier of the second asset.
157+ ///
158+ /// # Returns
159+ ///
160+ /// A tuple containing the balance of each asset in the liquidity pool, or `None` if the pool does not exist.
67161 #[ program:: entrypoint]
68162 fn entrypoint_get_liquidity_pool ( asset1 : AssetId , asset2 : AssetId ) -> Option < ( Balance , Balance ) > {
69163 get_liquidity_pool ( asset1, asset2)
70164 }
71165
166+ /// List all available liquidity pools with their asset information.
167+ ///
168+ /// # Returns
169+ ///
170+ /// A list of tuples, where each tuple represents a liquidity pool and contains the information of the two assets in the pool.
72171 #[ program:: entrypoint]
73172 fn entrypoint_list_pools ( ) -> alloc:: vec:: Vec < ( AssetInfo , AssetInfo ) > {
74173 let pools = list_pools ( ) ;
0 commit comments