Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the typed variants in scrypto lib #1782

Merged
merged 36 commits into from
Jun 18, 2024

Conversation

lrubasze
Copy link
Contributor

@lrubasze lrubasze commented Apr 23, 2024

Summary

Use typed variants in scrypto where possible.
Eg.

  • let claim_royalties() return FungibleBucket instead of Bucket
  • let FungibleVault methods use FungibleBucket
    etc.

Testing

Tests have been updated.

Update Recommendations

For dApp Developers

This is breaking change. Compiler might complain about mismatched types. But in most cases it will also nicely provides a suggested change.
eg.

error[E0308]: mismatched types
  --> radiswap/src/lib.rs:60:13
   |
51 |         ) -> (Bucket, Option<Bucket>) {
   |              ------------------------ expected `(scrypto::prelude::Bucket, std::option::Option<scrypto::prelude::Bucket>)` because of return type
...
60 |             self.pool_component.contribute((resource1, resource2))
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(Bucket, Option<Bucket>)`, found `(FungibleBucket, Option<FungibleBucket>)`
   |
   = note: expected tuple `(scrypto::prelude::Bucket, std::option::Option<scrypto::prelude::Bucket>)`
              found tuple `(scrypto::prelude::FungibleBucket, std::option::Option<scrypto::prelude::FungibleBucket>)`

error[E0308]: mismatched types
   --> radiswap/src/lib.rs:115:51
    |
115 |             self.pool_component.protected_deposit(bucket)
    |                                 ----------------- ^^^^^^ expected `FungibleBucket`, found `Bucket`
    |                                 |
    |                                 arguments to this method are incorrect
    |
note: method defined here
   --> /Users/lukaszrubaszewski/work/radixdlt/radixdlt-scrypto/scrypto/src/component/stubs.rs:315:12
    |
315 |         fn protected_deposit(&mut self, bucket: FungibleBucket);
    |            ^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `scrypto::prelude::FungibleBucket`
    |
115 |             self.pool_component.protected_deposit(scrypto::prelude::FungibleBucket(bucket))
    |                                                   +++++++++++++++++++++++++++++++++      +

error[E0308]: mismatched types
   --> radiswap/src/lib.rs:119:13
    |
118 |           fn withdraw(&mut self, resource_address: ResourceAddress, amount: Decimal) -> Bucket {
    |                                                                                         ------ expected `scrypto::prelude::Bucket` because of return type
119 | /             self.pool_component.protected_withdraw(
120 | |                 resource_address,
121 | |                 amount,
122 | |                 WithdrawStrategy::Rounded(RoundingMode::ToZero),
123 | |             )
    | |_____________^ expected `Bucket`, found `FungibleBucket`
    |
help: call `Into::into` on this expression to convert `scrypto::prelude::FungibleBucket` into `scrypto::prelude::Bucket`
    |
123 |             ).into()
    |              +++++++

Copy link

github-actions bot commented Apr 23, 2024

Docker tags
docker.io/radixdlt/private-scrypto-builder:13df2a3a02

Copy link

github-actions bot commented Apr 23, 2024

Benchmark for 13df2a3

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 65.5±0.13ms 65.5±0.17ms 0.00%
costing::decode_sbor 11.0±0.02µs 10.9±0.01µs -0.91%
costing::decode_sbor_bytes 29.7±0.08µs 30.5±0.19µs +2.69%
costing::deserialize_wasm 1277.1±10.33µs 1278.6±5.52µs +0.12%
costing::instantiate_flash_loan 3.8±0.43ms 3.9±0.74ms +2.63%
costing::instantiate_radiswap 5.9±0.05ms 5.6±0.06ms -5.08%
costing::spin_loop 21.5±0.05ms 23.0±0.03ms +6.98%
costing::validate_sbor_payload 26.1±0.06µs 27.3±0.03µs +4.60%
costing::validate_sbor_payload_bytes 226.9±0.60ns 236.9±0.80ns +4.41%
costing::validate_secp256k1 76.2±0.11µs 76.3±0.13µs +0.13%
costing::validate_wasm 36.3±0.03ms 36.3±0.03ms 0.00%
decimal::add/0 8.4±0.00ns 8.4±0.00ns 0.00%
decimal::add/rust-native 9.8±0.01ns 9.8±0.01ns 0.00%
decimal::add/wasmer 110.9±0.06ns 110.1±0.06ns -0.72%
decimal::add/wasmer-call-native 449.1±0.27ns 451.7±0.61ns +0.58%
decimal::add/wasmi 659.6±2.94ns 762.4±1.00ns +15.59%
decimal::add/wasmi-call-native 5.4±0.01µs 5.6±0.01µs +3.70%
decimal::div/0 191.1±0.25ns 189.8±0.46ns -0.68%
decimal::from_string/0 151.6±0.30ns 151.0±0.16ns -0.40%
decimal::mul/0 142.4±0.25ns 140.3±0.24ns -1.47%
decimal::mul/rust-native 138.0±0.26ns 138.3±0.22ns +0.22%
decimal::mul/wasmer 1525.0±1.03ns 1512.4±1.26ns -0.83%
decimal::mul/wasmer-call-native 580.8±0.43ns 580.4±0.80ns -0.07%
decimal::mul/wasmi 42.2±0.21µs 42.0±0.06µs -0.47%
decimal::mul/wasmi-call-native 5.5±0.00µs 5.6±0.01µs +1.82%
decimal::pow/0 656.5±0.84ns 656.1±0.54ns -0.06%
decimal::pow/rust-native 641.9±0.23ns 630.8±0.56ns -1.73%
decimal::pow/wasmer 6.6±0.01µs 6.7±0.01µs +1.52%
decimal::pow/wasmer-call-native 1030.1±0.43ns 1024.4±1.15ns -0.55%
decimal::pow/wasmi 197.6±0.22µs 201.7±1.10µs +2.07%
decimal::pow/wasmi-call-native 5.3±0.01µs 5.4±0.01µs +1.89%
decimal::root/0 7.9±0.01µs 7.9±0.01µs 0.00%
decimal::sub/0 8.5±0.01ns 8.5±0.01ns 0.00%
decimal::to_string/0 432.6±0.38ns 431.4±1.49ns -0.28%
precise_decimal::add/0 9.5±0.08ns 9.5±0.13ns 0.00%
precise_decimal::add/rust-native 11.4±0.00ns 11.4±0.01ns 0.00%
precise_decimal::add/wasmer 118.5±0.15ns 117.1±0.13ns -1.18%
precise_decimal::add/wasmer-call-native 501.3±0.94ns 501.3±0.27ns 0.00%
precise_decimal::add/wasmi 814.3±1.43ns 839.0±1.29ns +3.03%
precise_decimal::add/wasmi-call-native 7.0±0.01µs 7.0±0.01µs 0.00%
precise_decimal::div/0 314.1±0.31ns 303.3±0.42ns -3.44%
precise_decimal::from_string/0 195.9±0.26ns 195.5±0.25ns -0.20%
precise_decimal::mul/0 344.8±0.57ns 345.5±0.51ns +0.20%
precise_decimal::mul/rust-native 302.3±0.29ns 302.0±0.21ns -0.10%
precise_decimal::mul/wasmer 3.5±0.00µs 3.4±0.00µs -2.86%
precise_decimal::mul/wasmer-call-native 809.0±0.87ns 809.9±0.55ns +0.11%
precise_decimal::mul/wasmi 108.5±0.23µs 109.2±0.16µs +0.65%
precise_decimal::mul/wasmi-call-native 7.4±0.01µs 7.4±0.01µs 0.00%
precise_decimal::pow/0 1863.0±3.10ns 1857.0±3.26ns -0.32%
precise_decimal::pow/rust-native 1461.7±1.96ns 1470.6±3.34ns +0.61%
precise_decimal::pow/wasmer 16.2±0.01µs 16.1±0.01µs -0.62%
precise_decimal::pow/wasmer-call-native 2.1±0.00µs 2.1±0.00µs 0.00%
precise_decimal::pow/wasmi 529.3±0.81µs 529.0±0.38µs -0.06%
precise_decimal::pow/wasmi-call-native 13.3±0.10µs 13.5±0.05µs +1.50%
precise_decimal::root/0 56.4±0.03µs 57.9±0.20µs +2.66%
precise_decimal::sub/0 9.5±0.00ns 9.5±0.01ns 0.00%
precise_decimal::to_string/0 717.4±1.66ns 716.8±0.99ns -0.08%
schema::validate_payload 343.9±0.33µs 343.1±0.63µs -0.23%
transaction::radiswap 5.3±0.02ms 5.3±0.02ms 0.00%
transaction::transfer 1744.2±15.12µs 1746.1±8.55µs +0.11%
transaction_processing::prepare 2.2±0.00ms 2.2±0.00ms 0.00%
transaction_processing::prepare_and_decompile 6.3±0.01ms 6.2±0.02ms -1.59%
transaction_processing::prepare_and_decompile_and_recompile 24.3±0.78ms 24.7±1.22ms +1.65%
transaction_validation::validate_manifest 42.3±0.05µs 42.1±0.07µs -0.47%
transaction_validation::verify_bls_2KB 983.3±22.28µs 1025.9±58.04µs +4.33%
transaction_validation::verify_bls_32B 1033.4±63.40µs 1051.5±69.84µs +1.75%
transaction_validation::verify_ecdsa 74.2±0.07µs 74.3±0.08µs +0.13%
transaction_validation::verify_ed25519 55.0±0.08µs 55.0±0.64µs 0.00%

@lrubasze lrubasze force-pushed the feature/non_fungible_and_fungible_types branch 2 times, most recently from e50c4a4 to 457693b Compare May 1, 2024 13:53
@lrubasze lrubasze force-pushed the feature/non_fungible_and_fungible_types branch from 457693b to a324be3 Compare May 1, 2024 16:11
@lrubasze lrubasze changed the title Feature/non fungible and fungible types Switch to specialised types in scrypto where possible May 1, 2024
@lrubasze lrubasze added the scrypto-lib Any change to the scrypto library label May 1, 2024
@lrubasze lrubasze changed the title Switch to specialised types in scrypto where possible Switch to the typed variants in scrypto lib May 1, 2024
@lrubasze lrubasze force-pushed the feature/non_fungible_and_fungible_types branch from 2ed034b to 220268f Compare May 7, 2024 12:14
@lrubasze lrubasze marked this pull request as ready for review May 7, 2024 12:50
Copy link
Member

@0xOmarA 0xOmarA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

scrypto/src/component/stubs.rs Outdated Show resolved Hide resolved
scrypto/src/component/stubs.rs Show resolved Hide resolved
@lrubasze lrubasze merged commit 927f72e into develop Jun 18, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scrypto-lib Any change to the scrypto library
Development

Successfully merging this pull request may close these issues.

None yet

3 participants