@@ -6,7 +6,8 @@ use crate::{
6
6
} ;
7
7
use anyhow:: anyhow;
8
8
use cardano_serialization_lib:: {
9
- ExUnits , JsError , PlutusScriptSource , PlutusWitness , Redeemer , RedeemerTag , TxInputsBuilder ,
9
+ BigInt , ExUnits , JsError , PlutusData , PlutusScriptSource , PlutusWitness , Redeemer , RedeemerTag ,
10
+ TxInputsBuilder ,
10
11
} ;
11
12
use init:: find_script_utxo;
12
13
use ogmios_client:: { query_ledger_state:: QueryLedgerState , types:: OgmiosUtxo } ;
@@ -26,6 +27,7 @@ pub(crate) struct ReserveData {
26
27
pub ( crate ) auth_policy_version_utxo : OgmiosUtxo ,
27
28
pub ( crate ) validator_version_utxo : OgmiosUtxo ,
28
29
pub ( crate ) illiquid_circulation_supply_validator_version_utxo : OgmiosUtxo ,
30
+ pub ( crate ) illiquid_circulation_supply_authority_token_policy_version_utxo : OgmiosUtxo ,
29
31
}
30
32
31
33
#[ derive( Clone , Debug ) ]
@@ -75,12 +77,23 @@ impl ReserveData {
75
77
. ok_or_else ( || {
76
78
anyhow ! ( "Illiquid Circulation Supply Validator Version Utxo not found, is the Reserve Token Management initialized?" )
77
79
} ) ?;
80
+ let illiquid_circulation_supply_authority_token_policy_version_utxo = find_script_utxo (
81
+ raw_scripts:: ScriptId :: IlliquidCirculationSupplyAuthorityTokenPolicy as u32 ,
82
+ & version_oracle,
83
+ ctx,
84
+ client,
85
+ )
86
+ . await ?
87
+ . ok_or_else ( || {
88
+ anyhow ! ( "Illiquid Circulation Supply Authority Token Policy Version Utxo not found, is the Reserve Token Management initialized?" )
89
+ } ) ?;
78
90
let scripts = scripts_data:: reserve_scripts ( genesis_utxo, ctx. network ) ?;
79
91
Ok ( ReserveData {
80
92
scripts,
81
93
auth_policy_version_utxo,
82
94
validator_version_utxo,
83
95
illiquid_circulation_supply_validator_version_utxo,
96
+ illiquid_circulation_supply_authority_token_policy_version_utxo,
84
97
} )
85
98
}
86
99
@@ -113,6 +126,33 @@ impl ReserveData {
113
126
114
127
Ok ( ReserveUtxo { utxo : reserve_utxo, datum : reserve_settings } )
115
128
}
129
+
130
+ pub ( crate ) async fn get_illiquid_circulation_supply_utxo < T : QueryLedgerState > (
131
+ & self ,
132
+ ctx : & TransactionContext ,
133
+ client : & T ,
134
+ ) -> Result < OgmiosUtxo , anyhow:: Error > {
135
+ let validator_address = self
136
+ . scripts
137
+ . illiquid_circulation_supply_validator
138
+ . address ( ctx. network )
139
+ . to_bech32 ( None ) ?;
140
+ let validator_utxos = client. query_utxos ( & [ validator_address] ) . await ?;
141
+
142
+ let auth_token_asset_id = AssetId {
143
+ policy_id : self . scripts . illiquid_circulation_supply_auth_token_policy . policy_id ( ) ,
144
+ asset_name : AssetName :: empty ( ) ,
145
+ } ;
146
+
147
+ let ics_utxo = validator_utxos
148
+ . into_iter ( )
149
+ . find ( |utxo| utxo. get_asset_amount ( & auth_token_asset_id) == 1u64 )
150
+ . ok_or_else ( || {
151
+ anyhow ! ( "Could not find any UTXO with ICS Auth token at ICS Validator, is the Reserve Token Management initialized?" )
152
+ } ) ?;
153
+
154
+ Ok ( ics_utxo. clone ( ) )
155
+ }
116
156
}
117
157
118
158
pub ( crate ) struct TokenAmount {
@@ -127,6 +167,23 @@ pub(crate) fn reserve_utxo_input_with_validator_script_reference(
127
167
cost : & ExUnits ,
128
168
) -> Result < TxInputsBuilder , JsError > {
129
169
let mut inputs = TxInputsBuilder :: new ( ) ;
170
+ add_reserve_utxo_input_with_validator_script_reference (
171
+ & mut inputs,
172
+ reserve_utxo,
173
+ reserve,
174
+ redeemer,
175
+ cost,
176
+ ) ?;
177
+ Ok ( inputs)
178
+ }
179
+
180
+ pub ( crate ) fn add_reserve_utxo_input_with_validator_script_reference (
181
+ inputs : & mut TxInputsBuilder ,
182
+ reserve_utxo : & OgmiosUtxo ,
183
+ reserve : & ReserveData ,
184
+ redeemer : ReserveRedeemer ,
185
+ cost : & ExUnits ,
186
+ ) -> Result < ( ) , JsError > {
130
187
let input = reserve_utxo. to_csl_tx_input ( ) ;
131
188
let amount = reserve_utxo. value . to_csl ( ) ?;
132
189
let script = & reserve. scripts . validator ;
@@ -140,5 +197,32 @@ pub(crate) fn reserve_utxo_input_with_validator_script_reference(
140
197
& Redeemer :: new ( & RedeemerTag :: new_spend ( ) , & 0u32 . into ( ) , & redeemer. into ( ) , cost) ,
141
198
) ;
142
199
inputs. add_plutus_script_input ( & witness, & input, & amount) ;
143
- Ok ( inputs)
200
+ Ok ( ( ) )
201
+ }
202
+
203
+ pub ( crate ) fn add_ics_utxo_input_with_validator_script_reference (
204
+ inputs : & mut TxInputsBuilder ,
205
+ ics_utxo : & OgmiosUtxo ,
206
+ reserve : & ReserveData ,
207
+ cost : & ExUnits ,
208
+ ) -> Result < ( ) , JsError > {
209
+ let input = ics_utxo. to_csl_tx_input ( ) ;
210
+ let amount = ics_utxo. value . to_csl ( ) ?;
211
+ let script = & reserve. scripts . illiquid_circulation_supply_validator ;
212
+ let witness = PlutusWitness :: new_with_ref_without_datum (
213
+ & PlutusScriptSource :: new_ref_input (
214
+ & script. csl_script_hash ( ) ,
215
+ & reserve. illiquid_circulation_supply_validator_version_utxo . to_csl_tx_input ( ) ,
216
+ & script. language ,
217
+ script. bytes . len ( ) ,
218
+ ) ,
219
+ & Redeemer :: new (
220
+ & RedeemerTag :: new_spend ( ) ,
221
+ & 0u32 . into ( ) ,
222
+ & PlutusData :: new_integer ( & BigInt :: zero ( ) ) ,
223
+ cost,
224
+ ) ,
225
+ ) ;
226
+ inputs. add_plutus_script_input ( & witness, & input, & amount) ;
227
+ Ok ( ( ) )
144
228
}
0 commit comments