radix_engine/blueprints/pool/v1/
package.rs

1#![allow(clippy::let_unit_value)]
2
3use super::constants::*;
4use super::substates::multi_resource_pool::*;
5use super::substates::one_resource_pool::*;
6use super::substates::two_resource_pool::*;
7use crate::internal_prelude::*;
8use crate::*;
9use radix_engine_interface::blueprints::package::*;
10use radix_engine_interface::blueprints::pool::*;
11use radix_engine_interface::prelude::*;
12
13/// The minor version of the Pool V1 package
14#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Sbor)]
15pub enum PoolV1MinorVersion {
16    Zero,
17    One,
18}
19
20pub struct PoolNativePackage;
21impl PoolNativePackage {
22    pub fn invoke_export<Y: SystemApi<RuntimeError>>(
23        export_name: &str,
24        input: &IndexedScryptoValue,
25        minor_version: PoolV1MinorVersion,
26        api: &mut Y,
27    ) -> Result<IndexedScryptoValue, RuntimeError> {
28        match export_name {
29            ONE_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME => {
30                let OneResourcePoolInstantiateInput {
31                    resource_address,
32                    pool_manager_rule,
33                    owner_role,
34                    address_reservation,
35                } = input.as_typed().map_err(|e| {
36                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
37                })?;
38                let rtn = match minor_version {
39                    PoolV1MinorVersion::Zero => super::v1_0::OneResourcePoolBlueprint::instantiate(
40                        resource_address,
41                        owner_role,
42                        pool_manager_rule,
43                        address_reservation,
44                        api,
45                    )?,
46                    PoolV1MinorVersion::One => super::v1_1::OneResourcePoolBlueprint::instantiate(
47                        resource_address,
48                        owner_role,
49                        pool_manager_rule,
50                        address_reservation,
51                        api,
52                    )?,
53                };
54
55                Ok(IndexedScryptoValue::from_typed(&rtn))
56            }
57
58            ONE_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME => {
59                let OneResourcePoolContributeInput { bucket } = input.as_typed().map_err(|e| {
60                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
61                })?;
62                let rtn = match minor_version {
63                    PoolV1MinorVersion::Zero => {
64                        super::v1_0::OneResourcePoolBlueprint::contribute(bucket, api)?
65                    }
66                    PoolV1MinorVersion::One => {
67                        super::v1_1::OneResourcePoolBlueprint::contribute(bucket, api)?
68                    }
69                };
70                Ok(IndexedScryptoValue::from_typed(&rtn))
71            }
72
73            ONE_RESOURCE_POOL_REDEEM_EXPORT_NAME => {
74                let OneResourcePoolRedeemInput { bucket } = input.as_typed().map_err(|e| {
75                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
76                })?;
77                let rtn = match minor_version {
78                    PoolV1MinorVersion::Zero => {
79                        super::v1_0::OneResourcePoolBlueprint::redeem(bucket, api)?
80                    }
81                    PoolV1MinorVersion::One => {
82                        super::v1_1::OneResourcePoolBlueprint::redeem(bucket, api)?
83                    }
84                };
85                Ok(IndexedScryptoValue::from_typed(&rtn))
86            }
87
88            ONE_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME => {
89                let OneResourcePoolProtectedDepositInput { bucket } =
90                    input.as_typed().map_err(|e| {
91                        RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
92                    })?;
93                let rtn = match minor_version {
94                    PoolV1MinorVersion::Zero => {
95                        super::v1_0::OneResourcePoolBlueprint::protected_deposit(bucket, api)?
96                    }
97                    PoolV1MinorVersion::One => {
98                        super::v1_1::OneResourcePoolBlueprint::protected_deposit(bucket, api)?
99                    }
100                };
101                Ok(IndexedScryptoValue::from_typed(&rtn))
102            }
103
104            ONE_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME => {
105                let OneResourcePoolProtectedWithdrawInput {
106                    amount,
107                    withdraw_strategy,
108                } = input.as_typed().map_err(|e| {
109                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
110                })?;
111                let rtn = match minor_version {
112                    PoolV1MinorVersion::Zero => {
113                        super::v1_0::OneResourcePoolBlueprint::protected_withdraw(
114                            amount,
115                            withdraw_strategy,
116                            api,
117                        )?
118                    }
119                    PoolV1MinorVersion::One => {
120                        super::v1_1::OneResourcePoolBlueprint::protected_withdraw(
121                            amount,
122                            withdraw_strategy,
123                            api,
124                        )?
125                    }
126                };
127                Ok(IndexedScryptoValue::from_typed(&rtn))
128            }
129
130            ONE_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME => {
131                let OneResourcePoolGetRedemptionValueInput {
132                    amount_of_pool_units,
133                } = input.as_typed().map_err(|e| {
134                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
135                })?;
136                let rtn = match minor_version {
137                    PoolV1MinorVersion::Zero => {
138                        super::v1_0::OneResourcePoolBlueprint::get_redemption_value(
139                            amount_of_pool_units,
140                            api,
141                        )?
142                    }
143                    PoolV1MinorVersion::One => {
144                        super::v1_1::OneResourcePoolBlueprint::get_redemption_value(
145                            amount_of_pool_units,
146                            api,
147                        )?
148                    }
149                };
150                Ok(IndexedScryptoValue::from_typed(&rtn))
151            }
152
153            ONE_RESOURCE_POOL_GET_VAULT_AMOUNT_EXPORT_NAME => {
154                let OneResourcePoolGetVaultAmountInput {} = input.as_typed().map_err(|e| {
155                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
156                })?;
157                let rtn = match minor_version {
158                    PoolV1MinorVersion::Zero => {
159                        super::v1_0::OneResourcePoolBlueprint::get_vault_amount(api)?
160                    }
161                    PoolV1MinorVersion::One => {
162                        super::v1_1::OneResourcePoolBlueprint::get_vault_amount(api)?
163                    }
164                };
165                Ok(IndexedScryptoValue::from_typed(&rtn))
166            }
167
168            TWO_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME => {
169                let TwoResourcePoolInstantiateInput {
170                    resource_addresses,
171                    pool_manager_rule,
172                    owner_role,
173                    address_reservation,
174                } = input.as_typed().map_err(|e| {
175                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
176                })?;
177                let rtn = match minor_version {
178                    PoolV1MinorVersion::Zero => super::v1_0::TwoResourcePoolBlueprint::instantiate(
179                        resource_addresses,
180                        owner_role,
181                        pool_manager_rule,
182                        address_reservation,
183                        api,
184                    )?,
185                    PoolV1MinorVersion::One => super::v1_1::TwoResourcePoolBlueprint::instantiate(
186                        resource_addresses,
187                        owner_role,
188                        pool_manager_rule,
189                        address_reservation,
190                        api,
191                    )?,
192                };
193
194                Ok(IndexedScryptoValue::from_typed(&rtn))
195            }
196
197            TWO_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME => {
198                let TwoResourcePoolContributeInput { buckets } = input.as_typed().map_err(|e| {
199                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
200                })?;
201                let rtn = match minor_version {
202                    PoolV1MinorVersion::Zero => {
203                        super::v1_0::TwoResourcePoolBlueprint::contribute(buckets, api)?
204                    }
205                    PoolV1MinorVersion::One => {
206                        super::v1_1::TwoResourcePoolBlueprint::contribute(buckets, api)?
207                    }
208                };
209                Ok(IndexedScryptoValue::from_typed(&rtn))
210            }
211
212            TWO_RESOURCE_POOL_REDEEM_EXPORT_NAME => {
213                let TwoResourcePoolRedeemInput { bucket } = input.as_typed().map_err(|e| {
214                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
215                })?;
216                let rtn = match minor_version {
217                    PoolV1MinorVersion::Zero => {
218                        super::v1_0::TwoResourcePoolBlueprint::redeem(bucket, api)?
219                    }
220                    PoolV1MinorVersion::One => {
221                        super::v1_1::TwoResourcePoolBlueprint::redeem(bucket, api)?
222                    }
223                };
224                Ok(IndexedScryptoValue::from_typed(&rtn))
225            }
226
227            TWO_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME => {
228                let TwoResourcePoolProtectedDepositInput { bucket } =
229                    input.as_typed().map_err(|e| {
230                        RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
231                    })?;
232                let rtn = match minor_version {
233                    PoolV1MinorVersion::Zero => {
234                        super::v1_0::TwoResourcePoolBlueprint::protected_deposit(bucket, api)?
235                    }
236                    PoolV1MinorVersion::One => {
237                        super::v1_1::TwoResourcePoolBlueprint::protected_deposit(bucket, api)?
238                    }
239                };
240                Ok(IndexedScryptoValue::from_typed(&rtn))
241            }
242
243            TWO_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME => {
244                let TwoResourcePoolProtectedWithdrawInput {
245                    amount,
246                    resource_address,
247                    withdraw_strategy,
248                } = input.as_typed().map_err(|e| {
249                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
250                })?;
251                let rtn = match minor_version {
252                    PoolV1MinorVersion::Zero => {
253                        super::v1_0::TwoResourcePoolBlueprint::protected_withdraw(
254                            resource_address,
255                            amount,
256                            withdraw_strategy,
257                            api,
258                        )?
259                    }
260                    PoolV1MinorVersion::One => {
261                        super::v1_1::TwoResourcePoolBlueprint::protected_withdraw(
262                            resource_address,
263                            amount,
264                            withdraw_strategy,
265                            api,
266                        )?
267                    }
268                };
269                Ok(IndexedScryptoValue::from_typed(&rtn))
270            }
271
272            TWO_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME => {
273                let TwoResourcePoolGetRedemptionValueInput {
274                    amount_of_pool_units,
275                } = input.as_typed().map_err(|e| {
276                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
277                })?;
278                let rtn = match minor_version {
279                    PoolV1MinorVersion::Zero => {
280                        super::v1_0::TwoResourcePoolBlueprint::get_redemption_value(
281                            amount_of_pool_units,
282                            api,
283                        )?
284                    }
285                    PoolV1MinorVersion::One => {
286                        super::v1_1::TwoResourcePoolBlueprint::get_redemption_value(
287                            amount_of_pool_units,
288                            api,
289                        )?
290                    }
291                };
292                Ok(IndexedScryptoValue::from_typed(&rtn))
293            }
294
295            TWO_RESOURCE_POOL_GET_VAULT_AMOUNTS_EXPORT_NAME => {
296                let TwoResourcePoolGetVaultAmountsInput {} = input.as_typed().map_err(|e| {
297                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
298                })?;
299                let rtn = match minor_version {
300                    PoolV1MinorVersion::Zero => {
301                        super::v1_0::TwoResourcePoolBlueprint::get_vault_amounts(api)?
302                    }
303                    PoolV1MinorVersion::One => {
304                        super::v1_1::TwoResourcePoolBlueprint::get_vault_amounts(api)?
305                    }
306                };
307                Ok(IndexedScryptoValue::from_typed(&rtn))
308            }
309
310            MULTI_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME => {
311                let MultiResourcePoolInstantiateInput {
312                    resource_addresses,
313                    owner_role,
314                    pool_manager_rule,
315                    address_reservation,
316                } = input.as_typed().map_err(|e| {
317                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
318                })?;
319                let rtn = match minor_version {
320                    PoolV1MinorVersion::Zero => {
321                        super::v1_0::MultiResourcePoolBlueprint::instantiate(
322                            resource_addresses,
323                            owner_role,
324                            pool_manager_rule,
325                            address_reservation,
326                            api,
327                        )?
328                    }
329                    PoolV1MinorVersion::One => {
330                        super::v1_1::MultiResourcePoolBlueprint::instantiate(
331                            resource_addresses,
332                            owner_role,
333                            pool_manager_rule,
334                            address_reservation,
335                            api,
336                        )?
337                    }
338                };
339
340                Ok(IndexedScryptoValue::from_typed(&rtn))
341            }
342
343            MULTI_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME => {
344                let MultiResourcePoolContributeInput { buckets } =
345                    input.as_typed().map_err(|e| {
346                        RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
347                    })?;
348                let rtn = match minor_version {
349                    PoolV1MinorVersion::Zero => {
350                        super::v1_0::MultiResourcePoolBlueprint::contribute(buckets, api)?
351                    }
352                    PoolV1MinorVersion::One => {
353                        super::v1_1::MultiResourcePoolBlueprint::contribute(buckets, api)?
354                    }
355                };
356                Ok(IndexedScryptoValue::from_typed(&rtn))
357            }
358
359            MULTI_RESOURCE_POOL_REDEEM_EXPORT_NAME => {
360                let MultiResourcePoolRedeemInput { bucket } = input.as_typed().map_err(|e| {
361                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
362                })?;
363                let rtn = match minor_version {
364                    PoolV1MinorVersion::Zero => {
365                        super::v1_0::MultiResourcePoolBlueprint::redeem(bucket, api)?
366                    }
367                    PoolV1MinorVersion::One => {
368                        super::v1_1::MultiResourcePoolBlueprint::redeem(bucket, api)?
369                    }
370                };
371                Ok(IndexedScryptoValue::from_typed(&rtn))
372            }
373
374            MULTI_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME => {
375                let MultiResourcePoolProtectedDepositInput { bucket } =
376                    input.as_typed().map_err(|e| {
377                        RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
378                    })?;
379                let rtn = match minor_version {
380                    PoolV1MinorVersion::Zero => {
381                        super::v1_0::MultiResourcePoolBlueprint::protected_deposit(bucket, api)?
382                    }
383                    PoolV1MinorVersion::One => {
384                        super::v1_1::MultiResourcePoolBlueprint::protected_deposit(bucket, api)?
385                    }
386                };
387                Ok(IndexedScryptoValue::from_typed(&rtn))
388            }
389
390            MULTI_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME => {
391                let MultiResourcePoolProtectedWithdrawInput {
392                    amount,
393                    resource_address,
394                    withdraw_strategy,
395                } = input.as_typed().map_err(|e| {
396                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
397                })?;
398                let rtn = match minor_version {
399                    PoolV1MinorVersion::Zero => {
400                        super::v1_0::MultiResourcePoolBlueprint::protected_withdraw(
401                            resource_address,
402                            amount,
403                            withdraw_strategy,
404                            api,
405                        )?
406                    }
407                    PoolV1MinorVersion::One => {
408                        super::v1_1::MultiResourcePoolBlueprint::protected_withdraw(
409                            resource_address,
410                            amount,
411                            withdraw_strategy,
412                            api,
413                        )?
414                    }
415                };
416                Ok(IndexedScryptoValue::from_typed(&rtn))
417            }
418
419            MULTI_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME => {
420                let MultiResourcePoolGetRedemptionValueInput {
421                    amount_of_pool_units,
422                } = input.as_typed().map_err(|e| {
423                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
424                })?;
425                let rtn = match minor_version {
426                    PoolV1MinorVersion::Zero => {
427                        super::v1_0::MultiResourcePoolBlueprint::get_redemption_value(
428                            amount_of_pool_units,
429                            api,
430                        )?
431                    }
432                    PoolV1MinorVersion::One => {
433                        super::v1_1::MultiResourcePoolBlueprint::get_redemption_value(
434                            amount_of_pool_units,
435                            api,
436                        )?
437                    }
438                };
439                Ok(IndexedScryptoValue::from_typed(&rtn))
440            }
441
442            MULTI_RESOURCE_POOL_GET_VAULT_AMOUNTS_EXPORT_NAME => {
443                let MultiResourcePoolGetVaultAmountsInput {} = input.as_typed().map_err(|e| {
444                    RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
445                })?;
446                let rtn = match minor_version {
447                    PoolV1MinorVersion::Zero => {
448                        super::v1_0::MultiResourcePoolBlueprint::get_vault_amounts(api)?
449                    }
450                    PoolV1MinorVersion::One => {
451                        super::v1_1::MultiResourcePoolBlueprint::get_vault_amounts(api)?
452                    }
453                };
454                Ok(IndexedScryptoValue::from_typed(&rtn))
455            }
456
457            _ => Err(RuntimeError::ApplicationError(
458                ApplicationError::ExportDoesNotExist(export_name.to_string()),
459            )),
460        }
461    }
462
463    pub fn definition(minor_version: PoolV1MinorVersion) -> PackageDefinition {
464        let blueprints = indexmap!(
465            ONE_RESOURCE_POOL_BLUEPRINT_IDENT.to_string()
466                => Self::one_resource_pool_blueprint_definition(minor_version),
467            TWO_RESOURCE_POOL_BLUEPRINT_IDENT.to_string()
468                => Self::two_resource_pool_blueprint_definition(minor_version),
469            MULTI_RESOURCE_POOL_BLUEPRINT_IDENT.to_string()
470                => Self::multi_resource_pool_blueprint_definition(minor_version),
471        );
472
473        PackageDefinition { blueprints }
474    }
475
476    pub fn one_resource_pool_blueprint_definition(
477        _minor_version: PoolV1MinorVersion,
478    ) -> BlueprintDefinitionInit {
479        let mut aggregator = TypeAggregator::<ScryptoCustomTypeKind>::new();
480        let feature_set = OneResourcePoolFeatureSet::all_features();
481        let state = OneResourcePoolStateSchemaInit::create_schema_init(&mut aggregator);
482        let mut functions = index_map_new();
483
484        functions.insert(
485            ONE_RESOURCE_POOL_INSTANTIATE_IDENT.to_string(),
486            FunctionSchemaInit {
487                receiver: None,
488                input: TypeRef::Static(
489                    aggregator.add_child_type_and_descendents::<OneResourcePoolInstantiateInput>(),
490                ),
491                output: TypeRef::Static(
492                    aggregator.add_child_type_and_descendents::<OneResourcePoolInstantiateOutput>(),
493                ),
494                export: ONE_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME.to_string(),
495            },
496        );
497
498        functions.insert(
499            ONE_RESOURCE_POOL_CONTRIBUTE_IDENT.to_string(),
500            FunctionSchemaInit {
501                receiver: Some(ReceiverInfo::normal_ref_mut()),
502                input: TypeRef::Static(
503                    aggregator.add_child_type_and_descendents::<OneResourcePoolContributeInput>(),
504                ),
505                output: TypeRef::Static(
506                    aggregator.add_child_type_and_descendents::<OneResourcePoolContributeOutput>(),
507                ),
508                export: ONE_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME.to_string(),
509            },
510        );
511
512        functions.insert(
513            ONE_RESOURCE_POOL_REDEEM_IDENT.to_string(),
514            FunctionSchemaInit {
515                receiver: Some(ReceiverInfo::normal_ref_mut()),
516                input: TypeRef::Static(
517                    aggregator.add_child_type_and_descendents::<OneResourcePoolRedeemInput>(),
518                ),
519                output: TypeRef::Static(
520                    aggregator.add_child_type_and_descendents::<OneResourcePoolRedeemOutput>(),
521                ),
522                export: ONE_RESOURCE_POOL_REDEEM_EXPORT_NAME.to_string(),
523            },
524        );
525
526        functions.insert(
527            ONE_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT.to_string(),
528            FunctionSchemaInit {
529                receiver: Some(ReceiverInfo::normal_ref_mut()),
530                input: TypeRef::Static(
531                    aggregator
532                        .add_child_type_and_descendents::<OneResourcePoolProtectedDepositInput>(),
533                ),
534                output: TypeRef::Static(
535                    aggregator
536                        .add_child_type_and_descendents::<OneResourcePoolProtectedDepositOutput>(),
537                ),
538                export: ONE_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME.to_string(),
539            },
540        );
541
542        functions.insert(
543            ONE_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT.to_string(),
544            FunctionSchemaInit {
545                receiver: Some(ReceiverInfo::normal_ref_mut()),
546                input: TypeRef::Static(
547                    aggregator
548                        .add_child_type_and_descendents::<OneResourcePoolProtectedWithdrawInput>(),
549                ),
550                output: TypeRef::Static(
551                    aggregator
552                        .add_child_type_and_descendents::<OneResourcePoolProtectedWithdrawOutput>(),
553                ),
554                export: ONE_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME.to_string(),
555            },
556        );
557
558        functions.insert(
559            ONE_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT.to_string(),
560            FunctionSchemaInit {
561                receiver: Some(ReceiverInfo::normal_ref()),
562                input: TypeRef::Static(
563                    aggregator
564                        .add_child_type_and_descendents::<OneResourcePoolGetRedemptionValueInput>(),
565                ),
566                output: TypeRef::Static(
567                    aggregator
568                        .add_child_type_and_descendents::<OneResourcePoolGetRedemptionValueOutput>(
569                        ),
570                ),
571                export: ONE_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME.to_string(),
572            },
573        );
574
575        functions.insert(
576            ONE_RESOURCE_POOL_GET_VAULT_AMOUNT_IDENT.to_string(),
577            FunctionSchemaInit {
578                receiver: Some(ReceiverInfo::normal_ref()),
579                input: TypeRef::Static(
580                    aggregator
581                        .add_child_type_and_descendents::<OneResourcePoolGetVaultAmountInput>(),
582                ),
583                output: TypeRef::Static(
584                    aggregator
585                        .add_child_type_and_descendents::<OneResourcePoolGetVaultAmountOutput>(),
586                ),
587                export: ONE_RESOURCE_POOL_GET_VAULT_AMOUNT_EXPORT_NAME.to_string(),
588            },
589        );
590
591        let event_schema = event_schema! {
592            aggregator,
593            [
594                super::events::one_resource_pool::ContributionEvent,
595                super::events::one_resource_pool::RedemptionEvent,
596                super::events::one_resource_pool::WithdrawEvent,
597                super::events::one_resource_pool::DepositEvent
598            ]
599        };
600
601        let schema = generate_full_schema(aggregator);
602
603        BlueprintDefinitionInit {
604            blueprint_type: BlueprintType::default(),
605            is_transient: false,
606            dependencies: indexset!(),
607            feature_set,
608
609            schema: BlueprintSchemaInit {
610                generics: vec![],
611                schema,
612                state,
613                events: event_schema,
614                types: BlueprintTypeSchemaInit::default(),
615                functions: BlueprintFunctionsSchemaInit { functions },
616                hooks: BlueprintHooksInit::default(),
617            },
618
619            royalty_config: PackageRoyaltyConfig::default(),
620            auth_config: AuthConfig {
621                function_auth: FunctionAuth::AllowAll,
622                method_auth: MethodAuthTemplate::StaticRoleDefinition(roles_template! {
623                    roles {
624                        POOL_MANAGER_ROLE;
625                    },
626                    methods {
627                        // Main Module rules
628                        ONE_RESOURCE_POOL_REDEEM_IDENT => MethodAccessibility::Public;
629                        ONE_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT => MethodAccessibility::Public;
630                        ONE_RESOURCE_POOL_GET_VAULT_AMOUNT_IDENT => MethodAccessibility::Public;
631                        ONE_RESOURCE_POOL_CONTRIBUTE_IDENT => [POOL_MANAGER_ROLE];
632                        ONE_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT => [POOL_MANAGER_ROLE];
633                        ONE_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT => [POOL_MANAGER_ROLE];
634                    }
635                }),
636            },
637        }
638    }
639
640    pub fn two_resource_pool_blueprint_definition(
641        _minor_version: PoolV1MinorVersion,
642    ) -> BlueprintDefinitionInit {
643        let mut aggregator = TypeAggregator::<ScryptoCustomTypeKind>::new();
644        let feature_set = TwoResourcePoolFeatureSet::all_features();
645        let state = TwoResourcePoolStateSchemaInit::create_schema_init(&mut aggregator);
646
647        let mut functions = index_map_new();
648
649        functions.insert(
650            TWO_RESOURCE_POOL_INSTANTIATE_IDENT.to_string(),
651            FunctionSchemaInit {
652                receiver: None,
653                input: TypeRef::Static(
654                    aggregator.add_child_type_and_descendents::<TwoResourcePoolInstantiateInput>(),
655                ),
656                output: TypeRef::Static(
657                    aggregator.add_child_type_and_descendents::<TwoResourcePoolInstantiateOutput>(),
658                ),
659                export: TWO_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME.to_string(),
660            },
661        );
662
663        functions.insert(
664            TWO_RESOURCE_POOL_CONTRIBUTE_IDENT.to_string(),
665            FunctionSchemaInit {
666                receiver: Some(ReceiverInfo::normal_ref_mut()),
667                input: TypeRef::Static(
668                    aggregator.add_child_type_and_descendents::<TwoResourcePoolContributeInput>(),
669                ),
670                output: TypeRef::Static(
671                    aggregator.add_child_type_and_descendents::<TwoResourcePoolContributeOutput>(),
672                ),
673                export: TWO_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME.to_string(),
674            },
675        );
676
677        functions.insert(
678            TWO_RESOURCE_POOL_REDEEM_IDENT.to_string(),
679            FunctionSchemaInit {
680                receiver: Some(ReceiverInfo::normal_ref_mut()),
681                input: TypeRef::Static(
682                    aggregator.add_child_type_and_descendents::<TwoResourcePoolRedeemInput>(),
683                ),
684                output: TypeRef::Static(
685                    aggregator.add_child_type_and_descendents::<TwoResourcePoolRedeemOutput>(),
686                ),
687                export: TWO_RESOURCE_POOL_REDEEM_EXPORT_NAME.to_string(),
688            },
689        );
690
691        functions.insert(
692            TWO_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT.to_string(),
693            FunctionSchemaInit {
694                receiver: Some(ReceiverInfo::normal_ref_mut()),
695                input: TypeRef::Static(
696                    aggregator
697                        .add_child_type_and_descendents::<TwoResourcePoolProtectedDepositInput>(),
698                ),
699                output: TypeRef::Static(
700                    aggregator
701                        .add_child_type_and_descendents::<TwoResourcePoolProtectedDepositOutput>(),
702                ),
703                export: TWO_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME.to_string(),
704            },
705        );
706
707        functions.insert(
708            TWO_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT.to_string(),
709            FunctionSchemaInit {
710                receiver: Some(ReceiverInfo::normal_ref_mut()),
711                input: TypeRef::Static(
712                    aggregator
713                        .add_child_type_and_descendents::<TwoResourcePoolProtectedWithdrawInput>(),
714                ),
715                output: TypeRef::Static(
716                    aggregator
717                        .add_child_type_and_descendents::<TwoResourcePoolProtectedWithdrawOutput>(),
718                ),
719                export: TWO_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME.to_string(),
720            },
721        );
722
723        functions.insert(
724            TWO_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT.to_string(),
725            FunctionSchemaInit {
726                receiver: Some(ReceiverInfo::normal_ref()),
727                input: TypeRef::Static(
728                    aggregator
729                        .add_child_type_and_descendents::<TwoResourcePoolGetRedemptionValueInput>(),
730                ),
731                output: TypeRef::Static(
732                    aggregator
733                        .add_child_type_and_descendents::<TwoResourcePoolGetRedemptionValueOutput>(
734                        ),
735                ),
736                export: TWO_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME.to_string(),
737            },
738        );
739
740        functions.insert(
741            TWO_RESOURCE_POOL_GET_VAULT_AMOUNTS_IDENT.to_string(),
742            FunctionSchemaInit {
743                receiver: Some(ReceiverInfo::normal_ref()),
744                input: TypeRef::Static(
745                    aggregator
746                        .add_child_type_and_descendents::<TwoResourcePoolGetVaultAmountsInput>(),
747                ),
748                output: TypeRef::Static(
749                    aggregator
750                        .add_child_type_and_descendents::<TwoResourcePoolGetVaultAmountsOutput>(),
751                ),
752                export: TWO_RESOURCE_POOL_GET_VAULT_AMOUNTS_EXPORT_NAME.to_string(),
753            },
754        );
755
756        let event_schema = event_schema! {
757            aggregator,
758            [
759                super::events::two_resource_pool::ContributionEvent,
760                super::events::two_resource_pool::RedemptionEvent,
761                super::events::two_resource_pool::WithdrawEvent,
762                super::events::two_resource_pool::DepositEvent
763            ]
764        };
765
766        let schema = generate_full_schema(aggregator);
767
768        BlueprintDefinitionInit {
769            blueprint_type: BlueprintType::default(),
770            is_transient: false,
771            dependencies: indexset!(),
772            feature_set,
773
774            schema: BlueprintSchemaInit {
775                generics: vec![],
776                schema,
777                state,
778                events: event_schema,
779                types: BlueprintTypeSchemaInit::default(),
780                functions: BlueprintFunctionsSchemaInit { functions },
781                hooks: BlueprintHooksInit::default(),
782            },
783
784            royalty_config: PackageRoyaltyConfig::default(),
785            auth_config: AuthConfig {
786                function_auth: FunctionAuth::AllowAll,
787                method_auth: MethodAuthTemplate::StaticRoleDefinition(roles_template! {
788                    roles {
789                        POOL_MANAGER_ROLE;
790                    },
791                    methods {
792                        // Main Module rules
793                        TWO_RESOURCE_POOL_REDEEM_IDENT => MethodAccessibility::Public;
794                        TWO_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT => MethodAccessibility::Public;
795                        TWO_RESOURCE_POOL_GET_VAULT_AMOUNTS_IDENT => MethodAccessibility::Public;
796                        TWO_RESOURCE_POOL_CONTRIBUTE_IDENT => [POOL_MANAGER_ROLE];
797                        TWO_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT => [POOL_MANAGER_ROLE];
798                        TWO_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT => [POOL_MANAGER_ROLE];
799                    }
800                }),
801            },
802        }
803    }
804
805    pub fn multi_resource_pool_blueprint_definition(
806        _minor_version: PoolV1MinorVersion,
807    ) -> BlueprintDefinitionInit {
808        let mut aggregator = TypeAggregator::<ScryptoCustomTypeKind>::new();
809
810        let feature_set = MultiResourcePoolFeatureSet::all_features();
811        let state = MultiResourcePoolStateSchemaInit::create_schema_init(&mut aggregator);
812
813        let mut functions = index_map_new();
814
815        functions.insert(
816            MULTI_RESOURCE_POOL_INSTANTIATE_IDENT.to_string(),
817            FunctionSchemaInit {
818                receiver: None,
819                input: TypeRef::Static(
820                    aggregator
821                        .add_child_type_and_descendents::<MultiResourcePoolInstantiateInput>(),
822                ),
823                output: TypeRef::Static(
824                    aggregator
825                        .add_child_type_and_descendents::<MultiResourcePoolInstantiateOutput>(),
826                ),
827                export: MULTI_RESOURCE_POOL_INSTANTIATE_EXPORT_NAME.to_string(),
828            },
829        );
830
831        functions.insert(
832            MULTI_RESOURCE_POOL_CONTRIBUTE_IDENT.to_string(),
833            FunctionSchemaInit {
834                receiver: Some(ReceiverInfo::normal_ref_mut()),
835                input: TypeRef::Static(
836                    aggregator.add_child_type_and_descendents::<MultiResourcePoolContributeInput>(),
837                ),
838                output: TypeRef::Static(
839                    aggregator
840                        .add_child_type_and_descendents::<MultiResourcePoolContributeOutput>(),
841                ),
842                export: MULTI_RESOURCE_POOL_CONTRIBUTE_EXPORT_NAME.to_string(),
843            },
844        );
845
846        functions.insert(
847            MULTI_RESOURCE_POOL_REDEEM_IDENT.to_string(),
848            FunctionSchemaInit {
849                receiver: Some(ReceiverInfo::normal_ref_mut()),
850                input: TypeRef::Static(
851                    aggregator.add_child_type_and_descendents::<MultiResourcePoolRedeemInput>(),
852                ),
853                output: TypeRef::Static(
854                    aggregator.add_child_type_and_descendents::<MultiResourcePoolRedeemOutput>(),
855                ),
856                export: MULTI_RESOURCE_POOL_REDEEM_EXPORT_NAME.to_string(),
857            },
858        );
859
860        functions.insert(
861            MULTI_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT.to_string(),
862            FunctionSchemaInit {
863                receiver: Some(ReceiverInfo::normal_ref_mut()),
864                input: TypeRef::Static(
865                    aggregator
866                        .add_child_type_and_descendents::<MultiResourcePoolProtectedDepositInput>(),
867                ),
868                output: TypeRef::Static(
869                    aggregator
870                        .add_child_type_and_descendents::<MultiResourcePoolProtectedDepositOutput>(
871                        ),
872                ),
873                export: MULTI_RESOURCE_POOL_PROTECTED_DEPOSIT_EXPORT_NAME.to_string(),
874            },
875        );
876
877        functions.insert(
878            MULTI_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT.to_string(),
879            FunctionSchemaInit {
880                receiver: Some(ReceiverInfo::normal_ref_mut()),
881                input: TypeRef::Static(
882                    aggregator
883                        .add_child_type_and_descendents::<MultiResourcePoolProtectedWithdrawInput>(
884                        ),
885                ),
886                output: TypeRef::Static(
887                    aggregator
888                        .add_child_type_and_descendents::<MultiResourcePoolProtectedWithdrawOutput>(
889                        ),
890                ),
891                export: MULTI_RESOURCE_POOL_PROTECTED_WITHDRAW_EXPORT_NAME.to_string(),
892            },
893        );
894
895        functions.insert(
896            MULTI_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT.to_string(),
897            FunctionSchemaInit {
898                receiver: Some(ReceiverInfo::normal_ref()),
899                input: TypeRef::Static(aggregator
900                    .add_child_type_and_descendents::<MultiResourcePoolGetRedemptionValueInput>(
901                    )),
902                output: TypeRef::Static(aggregator
903                    .add_child_type_and_descendents::<MultiResourcePoolGetRedemptionValueOutput>(
904                    )),
905                export: MULTI_RESOURCE_POOL_GET_REDEMPTION_VALUE_EXPORT_NAME.to_string(),
906            },
907        );
908
909        functions.insert(
910            MULTI_RESOURCE_POOL_GET_VAULT_AMOUNTS_IDENT.to_string(),
911            FunctionSchemaInit {
912                receiver: Some(ReceiverInfo::normal_ref()),
913                input: TypeRef::Static(
914                    aggregator
915                        .add_child_type_and_descendents::<MultiResourcePoolGetVaultAmountsInput>(),
916                ),
917                output: TypeRef::Static(
918                    aggregator
919                        .add_child_type_and_descendents::<MultiResourcePoolGetVaultAmountsOutput>(),
920                ),
921                export: MULTI_RESOURCE_POOL_GET_VAULT_AMOUNTS_EXPORT_NAME.to_string(),
922            },
923        );
924
925        let event_schema = event_schema! {
926            aggregator,
927            [
928                super::events::multi_resource_pool::ContributionEvent,
929                super::events::multi_resource_pool::RedemptionEvent,
930                super::events::multi_resource_pool::WithdrawEvent,
931                super::events::multi_resource_pool::DepositEvent
932            ]
933        };
934
935        let schema = generate_full_schema(aggregator);
936
937        BlueprintDefinitionInit {
938            blueprint_type: BlueprintType::default(),
939            is_transient: false,
940            dependencies: indexset!(),
941            feature_set,
942
943            schema: BlueprintSchemaInit {
944                generics: vec![],
945                schema,
946                state,
947                events: event_schema,
948                types: BlueprintTypeSchemaInit::default(),
949                functions: BlueprintFunctionsSchemaInit { functions },
950                hooks: BlueprintHooksInit::default(),
951            },
952            royalty_config: PackageRoyaltyConfig::default(),
953            auth_config: AuthConfig {
954                function_auth: FunctionAuth::AllowAll,
955                method_auth: MethodAuthTemplate::StaticRoleDefinition(roles_template! {
956                    roles {
957                        POOL_MANAGER_ROLE;
958                    },
959                    methods {
960                        MULTI_RESOURCE_POOL_REDEEM_IDENT => MethodAccessibility::Public;
961                        MULTI_RESOURCE_POOL_GET_REDEMPTION_VALUE_IDENT => MethodAccessibility::Public;
962                        MULTI_RESOURCE_POOL_GET_VAULT_AMOUNTS_IDENT => MethodAccessibility::Public;
963                        MULTI_RESOURCE_POOL_CONTRIBUTE_IDENT => [POOL_MANAGER_ROLE];
964                        MULTI_RESOURCE_POOL_PROTECTED_DEPOSIT_IDENT => [POOL_MANAGER_ROLE];
965                        MULTI_RESOURCE_POOL_PROTECTED_WITHDRAW_IDENT => [POOL_MANAGER_ROLE];
966                    }
967                }),
968            },
969        }
970    }
971}