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

Add on behalf features for farm SC #967

Open
wants to merge 11 commits into
base: rc/v3.0.2
Choose a base branch
from

Conversation

psorinionut
Copy link
Contributor

@psorinionut psorinionut commented Oct 27, 2024

Features:

  • New permissions hub SC
  • On behalf features for Farm, Farm with locked rewards, Farm Staking and Farm Staking Proxy SCs
  • Unit tests for all the contracts

Copy link

github-actions bot commented Oct 27, 2024

Coverage Summary

Totals

Count Covered %
Lines 43403 39514 91.04
Regions 7927 5373 67.78
Functions 3023 2173 71.88
Instantiations 28043 6979 24.89

Files

Expand
File Lines Regions Functions Instantiations
/common/common_structs/src/farm_types.rs 81.48% 48.00% 53.85% 51.38%
/common/common_structs/src/locked_token_types.rs 43.23% 30.38% 37.50% 8.83%
/common/common_structs/src/wrapper_types.rs 46.30% 12.28% 14.29% 4.44%
/common/modules/farm/config/src/config.rs 55.00% 71.43% 75.00% 36.07%
/common/modules/farm/contexts/src/claim_rewards_context.rs 93.55% 77.78% 100.00% 70.59%
/common/modules/farm/contexts/src/enter_farm_context.rs 91.67% 81.82% 100.00% 81.25%
/common/modules/farm/contexts/src/exit_farm_context.rs 95.24% 66.67% 100.00% 76.47%
/common/modules/farm/contexts/src/storage_cache.rs 100.00% 100.00% 100.00% 82.35%
/common/modules/farm/events/src/events.rs 97.01% 51.85% 69.23% 50.40%
/common/modules/farm/farm_base_impl/src/base_farm_init.rs 82.14% 60.00% 100.00% 23.61%
/common/modules/farm/farm_base_impl/src/base_farm_validation.rs 83.33% 57.14% 100.00% 20.83%
/common/modules/farm/farm_base_impl/src/base_traits_impl.rs 84.97% 82.61% 78.57% 69.74%
/common/modules/farm/farm_base_impl/src/claim_rewards.rs 100.00% 80.00% 100.00% 25.58%
/common/modules/farm/farm_base_impl/src/compound_rewards.rs 98.39% 66.67% 100.00% 7.35%
/common/modules/farm/farm_base_impl/src/enter_farm.rs 100.00% 75.00% 100.00% 20.83%
/common/modules/farm/farm_base_impl/src/exit_farm.rs 100.00% 75.00% 100.00% 19.44%
/common/modules/farm/farm_base_impl/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/modules/farm/farm_token/src/farm_token.rs 2.08% 10.53% 10.00% 18.13%
/common/modules/farm/rewards/src/rewards.rs 20.00% 42.86% 66.67% 27.33%
/common/modules/legacy_token_decode_module/src/lib.rs 100.00% 83.33% 100.00% 8.14%
/common/modules/locking_module/src/lock_with_energy_module.rs 100.00% 75.00% 100.00% 20.00%
/common/modules/locking_module/src/locking_module.rs 83.33% 60.00% 71.43% 16.28%
/common/modules/math/src/lib.rs 79.55% 80.00% 75.00% 39.73%
/common/modules/pausable/src/pausable.rs 68.42% 52.94% 75.00% 20.05%
/common/modules/permissions_module/src/permissions.rs 68.42% 66.67% 50.00% 55.38%
/common/modules/permissions_module/src/permissions_module.rs 60.00% 65.22% 66.67% 22.29%
/common/modules/sc_whitelist_module/src/sc_whitelist_module.rs 68.42% 57.14% 66.67% 15.55%
/common/modules/token_merge_helper/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/common/modules/token_send/src/token_send.rs 95.65% 87.50% 100.00% 32.50%
/common/modules/utils/src/lib.rs 96.55% 84.00% 91.67% 40.27%
/common/traits/fixed-supply-token/src/lib.rs 95.00% 85.71% 100.00% 57.14%
/common/traits/mergeable/src/lib.rs 55.88% 47.06% 57.14% 17.70%
/common/traits/unwrappable/src/lib.rs 75.00% 66.67% 50.00% 22.81%
/dex/farm-with-locked-rewards/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/farm-with-locked-rewards/src/external_interaction.rs 93.48% 87.88% 100.00% 10.00%
/dex/farm-with-locked-rewards/src/lib.rs 89.36% 76.92% 75.00% 28.57%
/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/fees_collector_mock.rs 50.00% 50.00% 50.00% 50.00%
/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/farm/src/base_functions.rs 95.28% 87.27% 85.71% 45.18%
/dex/farm/src/exit_penalty.rs 52.17% 23.08% 40.00% 20.77%
/dex/farm/src/external_interaction.rs 100.00% 91.30% 100.00% 9.33%
/dex/farm/src/lib.rs 91.02% 81.48% 80.00% 19.35%
/dex/farm/tests/energy_update_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/tests/external_interaction_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/tests/farm_multi_user_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/tests/farm_review_distribution.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs 96.96% 94.59% 94.12% 15.69%
/dex/farm/tests/farm_setup/multi_user_farm_setup.rs 97.49% 97.97% 96.83% 27.25%
/dex/farm/tests/farm_setup/single_user_farm_setup.rs 89.18% 87.23% 87.50% 14.58%
/dex/farm/tests/farm_single_user_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/farm/tests/total_farm_position_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/fuzz/src/fuzz_data.rs 99.78% 88.89% 92.31% 92.31%
/dex/fuzz/src/fuzz_farm.rs 94.25% 83.78% 100.00% 100.00%
/dex/fuzz/src/fuzz_pair.rs 89.79% 72.55% 100.00% 100.00%
/dex/fuzz/src/fuzz_price_discovery.rs 87.06% 83.33% 100.00% 100.00%
/dex/fuzz/src/fuzz_start.rs 99.51% 95.45% 100.00% 100.00%
/dex/governance/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/governance/src/config.rs 51.67% 72.73% 56.25% 15.00%
/dex/governance/src/events.rs 100.00% 77.78% 100.00% 32.14%
/dex/governance/src/lib.rs 100.00% 91.30% 100.00% 12.90%
/dex/governance/src/proposal.rs 68.12% 33.33% 28.57% 8.33%
/dex/governance/src/validation.rs 85.71% 25.00% 50.00% 8.33%
/dex/governance/src/vote.rs 88.89% 40.74% 58.33% 28.12%
/dex/governance/src/weight.rs 77.42% 58.82% 100.00% 27.59%
/dex/governance/tests/gov_tests.rs 100.00% 100.00% 100.00% 100.00%
/dex/pair-mock/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/pair-mock/src/pair.rs 45.98% 22.22% 75.00% 23.53%
/dex/pair/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/pair/src/amm.rs 100.00% 88.89% 100.00% 28.97%
/dex/pair/src/config.rs 60.00% 60.00% 60.00% 27.20%
/dex/pair/src/contexts/add_liquidity.rs 100.00% 100.00% 100.00% 63.64%
/dex/pair/src/contexts/base.rs 100.00% 100.00% 100.00% 50.65%
/dex/pair/src/contexts/output_builder.rs 100.00% 92.86% 100.00% 34.11%
/dex/pair/src/contexts/remove_liquidity.rs 100.00% 100.00% 100.00% 45.45%
/dex/pair/src/contexts/swap.rs 100.00% 100.00% 100.00% 45.45%
/dex/pair/src/events.rs 76.47% 40.74% 53.85% 30.16%
/dex/pair/src/fee.rs 39.74% 36.19% 48.00% 7.00%
/dex/pair/src/lib.rs 69.39% 55.17% 66.67% 29.41%
/dex/pair/src/liquidity_pool.rs 93.70% 69.57% 100.00% 29.46%
/dex/pair/src/locking_wrapper.rs 94.59% 83.33% 88.89% 9.84%
/dex/pair/src/pair_actions/add_liq.rs 92.50% 66.67% 100.00% 27.54%
/dex/pair/src/pair_actions/common_methods.rs 100.00% 83.33% 100.00% 28.57%
/dex/pair/src/pair_actions/initial_liq.rs 91.23% 65.00% 100.00% 10.45%
/dex/pair/src/pair_actions/remove_liq.rs 92.66% 64.29% 100.00% 17.43%
/dex/pair/src/pair_actions/swap.rs 73.36% 46.38% 45.45% 14.01%
/dex/pair/src/pair_actions/views.rs 75.38% 73.17% 83.33% 6.36%
/dex/pair/src/read_pair_storage.rs 100.00% 88.89% 100.00% 17.95%
/dex/pair/src/safe_price.rs 92.22% 70.18% 70.00% 23.47%
/dex/pair/src/safe_price_view.rs 86.38% 67.39% 84.21% 7.41%
/dex/pair/tests/pair_rs_test.rs 99.93% 95.40% 96.97% 96.97%
/dex/pair/tests/pair_setup/mod.rs 100.00% 100.00% 100.00% 100.00%
/dex/permissions-hub/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/permissions-hub/src/lib.rs 77.78% 66.67% 66.67% 20.88%
/dex/price-discovery/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/price-discovery/src/common_storage.rs 100.00% 33.33% 100.00% 13.04%
/dex/price-discovery/src/events.rs 96.15% 47.62% 70.00% 26.47%
/dex/price-discovery/src/lib.rs 99.00% 91.07% 100.00% 17.11%
/dex/price-discovery/src/phase.rs 93.75% 70.00% 70.00% 17.91%
/dex/price-discovery/src/redeem_token.rs 41.03% 61.54% 75.00% 15.91%
/dex/price-discovery/tests/price_disc_tests.rs 100.00% 100.00% 100.00% 100.00%
/dex/price-discovery/tests/tests_common.rs 100.00% 100.00% 100.00% 50.00%
/dex/proxy-deployer/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/proxy-deployer/src/farm_deploy.rs 0.00% 0.00% 0.00% 0.00%
/dex/proxy-deployer/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/dex/router/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/dex/router/src/config.rs 85.19% 63.64% 60.00% 16.18%
/dex/router/src/contract.rs 53.28% 61.54% 71.43% 14.00%
/dex/router/src/enable_swap_by_user.rs 93.71% 73.08% 87.50% 12.31%
/dex/router/src/events.rs 94.20% 47.83% 70.00% 17.65%
/dex/router/src/factory.rs 62.81% 35.00% 42.11% 11.49%
/dex/router/src/multi_pair_swap.rs 64.52% 60.00% 75.00% 9.09%
/dex/router/tests/router_setup/mod.rs 100.00% 100.00% 100.00% 100.00%
/dex/router/tests/router_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/tests/dex_scenario_go_test.rs 100.00% 100.00% 100.00% 100.00%
/dex/tests/dex_scenario_rs_test.rs 100.00% 100.00% 100.00% 100.00%
/energy-integration/common-modules/energy-query/src/lib.rs 97.78% 88.89% 100.00% 35.51%
/energy-integration/common-modules/week-timekeeping/src/lib.rs 63.16% 45.45% 60.00% 30.85%
/energy-integration/common-modules/weekly-rewards-splitting/src/base_impl.rs 100.00% 93.75% 100.00% 44.68%
/energy-integration/common-modules/weekly-rewards-splitting/src/events.rs 100.00% 87.50% 100.00% 43.65%
/energy-integration/common-modules/weekly-rewards-splitting/src/global_info.rs 100.00% 96.67% 100.00% 42.04%
/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs 80.81% 66.67% 70.00% 16.94%
/energy-integration/common-modules/weekly-rewards-splitting/src/locked_token_buckets.rs 98.81% 90.91% 100.00% 44.25%
/energy-integration/common-modules/weekly-rewards-splitting/src/update_claim_progress_energy.rs 94.12% 90.00% 100.00% 25.55%
/energy-integration/common-types/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/energy-integration/energy-factory-mock/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/energy-integration/energy-factory-mock/src/lib.rs 14.29% 33.33% 40.00% 14.05%
/energy-integration/energy-update/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/energy-integration/energy-update/src/lib.rs 12.50% 14.29% 50.00% 6.45%
/energy-integration/farm-boosted-yields/src/boosted_yields_factors.rs 89.66% 64.52% 70.00% 29.78%
/energy-integration/farm-boosted-yields/src/lib.rs 96.97% 90.16% 100.00% 29.59%
/energy-integration/fees-collector/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/energy-integration/fees-collector/src/additional_locked_tokens.rs 100.00% 77.78% 100.00% 12.00%
/energy-integration/fees-collector/src/config.rs 28.21% 35.71% 33.33% 11.72%
/energy-integration/fees-collector/src/events.rs 100.00% 75.00% 100.00% 18.18%
/energy-integration/fees-collector/src/fees_accumulation.rs 100.00% 93.33% 100.00% 15.71%
/energy-integration/fees-collector/src/lib.rs 95.51% 89.47% 87.50% 16.99%
/energy-integration/fees-collector/tests/fees_collector_rust_test.rs 100.00% 100.00% 100.00% 100.00%
/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs 100.00% 100.00% 100.00% 100.00%
/energy-integration/governance-v2/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/energy-integration/governance-v2/src/configurable.rs 81.13% 70.83% 66.67% 15.38%
/energy-integration/governance-v2/src/events.rs 100.00% 33.33% 100.00% 29.17%
/energy-integration/governance-v2/src/lib.rs 98.01% 88.89% 100.00% 18.18%
/energy-integration/governance-v2/src/proposal.rs 65.00% 29.27% 42.11% 29.41%
/energy-integration/governance-v2/src/proposal_storage.rs 77.78% 32.14% 53.85% 18.00%
/energy-integration/governance-v2/src/views.rs 95.31% 85.19% 88.89% 21.43%
/energy-integration/governance-v2/tests/gov_rust_test.rs 98.14% 84.44% 100.00% 100.00%
/energy-integration/governance-v2/tests/gov_test_setup/mod.rs 99.64% 98.08% 100.00% 100.00%
/farm-staking/farm-staking-proxy/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/farm-staking/farm-staking-proxy/src/dual_yield_token.rs 69.44% 61.11% 75.00% 20.00%
/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs 96.88% 75.00% 100.00% 25.00%
/farm-staking/farm-staking-proxy/src/lib.rs 100.00% 50.00% 100.00% 6.67%
/farm-staking/farm-staking-proxy/src/lp_farm_token.rs 100.00% 50.00% 100.00% 11.11%
/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs 98.41% 40.00% 66.67% 11.11%
/farm-staking/farm-staking-proxy/src/proxy_actions/external_interaction.rs 100.00% 85.71% 100.00% 21.05%
/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs 98.70% 70.00% 66.67% 11.11%
/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs 97.67% 25.00% 50.00% 6.25%
/farm-staking/farm-staking-proxy/src/result_types.rs 60.61% 8.33% 18.75% 11.54%
/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs 100.00% 100.00% 100.00% 100.00%
/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs 100.00% 100.00% 100.00% 100.00%
/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs 100.00% 100.00% 100.00% 100.00%
/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs 100.00% 100.00% 100.00% 100.00%
/farm-staking/farm-staking/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/farm-staking/farm-staking/src/base_impl_wrapper.rs 96.72% 94.74% 92.31% 71.43%
/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs 95.52% 91.89% 100.00% 34.78%
/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs 100.00% 84.62% 100.00% 22.22%
/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs 100.00% 75.00% 100.00% 11.54%
/farm-staking/farm-staking/src/custom_rewards.rs 55.88% 54.55% 50.00% 15.49%
/farm-staking/farm-staking/src/external_interaction.rs 100.00% 88.24% 100.00% 15.15%
/farm-staking/farm-staking/src/farm_token_roles.rs 25.00% 50.00% 50.00% 3.85%
/farm-staking/farm-staking/src/lib.rs 70.00% 71.43% 66.67% 17.71%
/farm-staking/farm-staking/src/stake_farm.rs 100.00% 83.33% 100.00% 24.39%
/farm-staking/farm-staking/src/token_attributes.rs 79.27% 56.00% 52.63% 49.38%
/farm-staking/farm-staking/src/unbond_farm.rs 96.00% 40.00% 50.00% 7.69%
/farm-staking/farm-staking/src/unstake_farm.rs 100.00% 87.50% 100.00% 28.89%
/farm-staking/farm-staking/tests/farm_staking_energy_test.rs 100.00% 100.00% 100.00% 100.00%
/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs 100.00% 100.00% 100.00% 62.28%
/farm-staking/farm-staking/tests/farm_staking_test.rs 100.00% 100.00% 100.00% 100.00%
/legacy-contracts/factory-legacy/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/attr_ex_helper.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/cache.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/events.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/locked_asset.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/factory-legacy/src/migration.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-staking-proxy-v13/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-staking-proxy-v13/src/dual_yield_token.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-staking-proxy-v13/src/external_contracts_interactions.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-staking-proxy-v13/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-staking-proxy-v13/src/lp_farm_token.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v12/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v12/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13-custom-rewards/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13-custom-rewards/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13-locked-rewards/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13-locked-rewards/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/farm-v13/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/locked-asset-distribution/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/locked-asset-distribution/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/metabonding-staking-legacy/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/metabonding-staking-legacy/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/price-discovery-v1/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/price-discovery-v1/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/price-discovery-v2/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/price-discovery-v2/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/energy_update.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/events.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/lib.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/proxy_common.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/proxy-dex-legacy/src/transfer_role.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/simple-lock-legacy/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/legacy-contracts/simple-lock-legacy/src/basic_lock_unlock.rs 93.55% 50.00% 75.00% 11.54%
/legacy-contracts/simple-lock-legacy/src/lib.rs 88.89% 57.14% 100.00% 4.84%
/legacy-contracts/simple-lock-legacy/src/locked_token.rs 50.00% 29.41% 50.00% 11.63%
/legacy-contracts/simple-lock-legacy/src/proxy_farm.rs 89.29% 37.14% 57.14% 12.50%
/legacy-contracts/simple-lock-legacy/src/proxy_lp.rs 91.67% 36.84% 62.50% 10.91%
/legacy-contracts/simple-lock-legacy/tests/rust_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/energy-factory/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/energy-factory/src/energy.rs 98.73% 86.21% 96.30% 47.58%
/locked-asset/energy-factory/src/events.rs 87.50% 41.67% 60.00% 41.82%
/locked-asset/energy-factory/src/extend_lock.rs 100.00% 92.86% 100.00% 25.74%
/locked-asset/energy-factory/src/lib.rs 100.00% 96.67% 100.00% 24.34%
/locked-asset/energy-factory/src/local_roles.rs 10.00% 20.00% 33.33% 4.69%
/locked-asset/energy-factory/src/lock_options.rs 86.49% 61.76% 70.00% 46.59%
/locked-asset/energy-factory/src/lock_options_endpoints.rs 91.84% 86.67% 87.50% 31.67%
/locked-asset/energy-factory/src/locked_token_transfer.rs 72.22% 58.33% 75.00% 10.33%
/locked-asset/energy-factory/src/migration.rs 74.24% 62.22% 70.00% 12.01%
/locked-asset/energy-factory/src/penalty.rs 100.00% 92.86% 100.00% 13.89%
/locked-asset/energy-factory/src/token_merging.rs 96.08% 65.38% 77.78% 15.34%
/locked-asset/energy-factory/src/token_whitelist.rs 100.00% 75.00% 100.00% 29.17%
/locked-asset/energy-factory/src/unlock_with_penalty.rs 99.13% 84.62% 100.00% 10.20%
/locked-asset/energy-factory/src/unstake.rs 100.00% 88.89% 100.00% 14.46%
/locked-asset/energy-factory/src/virtual_lock.rs 100.00% 88.89% 100.00% 20.87%
/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs 99.64% 97.83% 100.00% 41.00%
/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs 100.00% 100.00% 100.00% 50.00%
/locked-asset/energy-factory/tests/old_tokens_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/energy-factory/tests/simple_lock_energy_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/energy-factory/tests/token_merging_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/energy-factory/tests/virtual_lock_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/lkmex-transfer/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/lkmex-transfer/src/energy_transfer.rs 97.67% 82.35% 75.00% 18.75%
/locked-asset/lkmex-transfer/src/events.rs 95.83% 54.55% 83.33% 16.67%
/locked-asset/lkmex-transfer/src/lib.rs 81.58% 42.37% 52.63% 10.12%
/locked-asset/lkmex-transfer/tests/lkmex_transfer_tests.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/locked-token-wrapper/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/locked-token-wrapper/src/lib.rs 100.00% 71.43% 100.00% 5.56%
/locked-asset/locked-token-wrapper/src/wrapped_token.rs 49.21% 36.00% 60.00% 10.53%
/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/proxy_dex/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/proxy_dex/src/energy_update.rs 72.09% 36.84% 80.00% 22.22%
/locked-asset/proxy_dex/src/events.rs 79.31% 41.03% 57.89% 16.36%
/locked-asset/proxy_dex/src/external_merging.rs 100.00% 100.00% 100.00% 41.67%
/locked-asset/proxy_dex/src/farm_interactions.rs 100.00% 66.67% 100.00% 11.11%
/locked-asset/proxy_dex/src/lib.rs 19.67% 10.00% 28.57% 3.57%
/locked-asset/proxy_dex/src/other_sc_whitelist.rs 52.38% 33.33% 42.86% 7.00%
/locked-asset/proxy_dex/src/pair_interactions.rs 100.00% 60.00% 100.00% 15.62%
/locked-asset/proxy_dex/src/proxy_common.rs 58.75% 57.14% 80.00% 16.67%
/locked-asset/proxy_dex/src/proxy_farm.rs 99.69% 91.43% 88.89% 9.52%
/locked-asset/proxy_dex/src/proxy_pair.rs 88.94% 76.92% 85.71% 13.24%
/locked-asset/proxy_dex/src/wrapped_farm_attributes.rs 89.09% 75.00% 83.33% 26.67%
/locked-asset/proxy_dex/src/wrapped_farm_token_merge.rs 96.36% 50.00% 75.00% 7.50%
/locked-asset/proxy_dex/src/wrapped_lp_attributes.rs 97.83% 74.19% 83.33% 31.90%
/locked-asset/proxy_dex/src/wrapped_lp_token_merge.rs 64.58% 37.50% 50.00% 5.00%
/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs 99.31% 97.06% 94.74% 92.11%
/locked-asset/proxy_dex/tests/proxy_farm_test.rs 99.93% 99.26% 100.00% 100.00%
/locked-asset/proxy_dex/tests/proxy_lp_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/simple-lock/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/simple-lock/src/basic_lock_unlock.rs 100.00% 81.25% 100.00% 24.72%
/locked-asset/simple-lock/src/farm_interactions.rs 100.00% 81.82% 100.00% 12.86%
/locked-asset/simple-lock/src/lib.rs 92.31% 75.00% 100.00% 22.16%
/locked-asset/simple-lock/src/locked_token.rs 77.78% 72.50% 72.73% 29.57%
/locked-asset/simple-lock/src/lp_interactions.rs 96.30% 66.67% 100.00% 7.38%
/locked-asset/simple-lock/src/proxy_farm.rs 80.18% 52.86% 57.89% 8.31%
/locked-asset/simple-lock/src/proxy_lp.rs 80.69% 50.94% 75.00% 7.86%
/locked-asset/simple-lock/src/token_attributes.rs 96.43% 75.00% 66.67% 25.30%
/locked-asset/simple-lock/tests/rust_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/tests/distribution_scenario_go_test.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/token-unstake/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/locked-asset/token-unstake/src/cancel_unstake.rs 85.42% 63.64% 50.00% 4.76%
/locked-asset/token-unstake/src/events.rs 100.00% 50.00% 100.00% 21.05%
/locked-asset/token-unstake/src/fees_handler.rs 98.39% 86.67% 100.00% 40.00%
/locked-asset/token-unstake/src/lib.rs 100.00% 80.00% 100.00% 21.05%
/locked-asset/token-unstake/src/tokens_per_user.rs 57.14% 38.89% 57.14% 54.76%
/locked-asset/token-unstake/src/unbond_tokens.rs 100.00% 88.89% 100.00% 25.00%
/locked-asset/token-unstake/tests/token_unstake_setup/fees_collector_mock.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs 93.33% 88.89% 86.36% 63.64%
/locked-asset/token-unstake/tests/token_unstake_test.rs 100.00% 100.00% 100.00% 100.00%
/locked-asset/token-unstake/tests/unlock_early_test.rs 100.00% 100.00% 100.00% 100.00%
/pause-all/meta/src/main.rs 0.00% 0.00% 0.00% 0.00%
/pause-all/src/lib.rs 69.74% 54.55% 75.00% 16.84%
/pause-all/src/ongoing_pause_operation.rs 53.33% 23.53% 40.00% 11.11%
/pause-all/tests/pause_all_test.rs 100.00% 100.00% 100.00% 100.00%

Copy link

github-actions bot commented Oct 27, 2024

Contract comparison - from 79c6016 to 17b9601

Path                                                                                             size                  has-allocator                     has-format
pair-mock.wasm 4379 false without message
pair-mock-dbg.wasm 11450 false without message
price-discovery.wasm 16211 false without message
price-discovery-dbg.wasm 50340 false without message
router-dbg.wasm 71721 false without message
router.wasm 26039 false without message
farm-with-locked-rewards-dbg.wasm 97099 ➡️ 101244 🔴 false without message
farm-with-locked-rewards.wasm 36921 ➡️ 39184 🔴 false without message
proxy-deployer.wasm 4078 false none
proxy-deployer-dbg.wasm 11508 false none
safe-price-view-dbg.wasm 22431 false without message
pair-full-dbg.wasm 83279 false without message
safe-price-view.wasm 8002 false without message
pair-dbg.wasm 80701 false without message
pair-full.wasm 33120 false without message
pair.wasm 31747 false without message
governance.wasm 16275 false without message
governance-dbg.wasm 44907 false without message
farm.wasm 37108 ➡️ 39315 🔴 false without message
farm-dbg.wasm 96371 ➡️ 100187 🔴 false without message
farm-v13-custom-rewards.wasm 3359 false without message
farm-v13-custom-rewards-dbg.wasm 8237 false without message
locked-asset-distribution-dbg.wasm 16011 false without message
locked-asset-distribution.wasm 5633 false without message
proxy-dex-legacy.wasm 18344 false without message
proxy-dex-legacy-dbg.wasm 51071 false without message
farm-v13.wasm 5816 false without message
farm-v13-dbg.wasm 14612 false without message
price-discovery-v1.wasm 3064 false none
price-discovery-v1-dbg.wasm 6997 false none
farm-staking-proxy-v13.wasm 9691 false without message
farm-staking-proxy-v13-dbg.wasm 27671 false without message
metabonding-staking-legacy-dbg.wasm 5314 false none
metabonding-staking-legacy.wasm 2126 false none
factory-legacy.wasm 18051 false without message
factory-legacy-dbg.wasm 51164 false without message
price-discovery-v2-dbg.wasm 7973 false none
price-discovery-v2.wasm 3475 false none
farm-v13-locked-rewards.wasm 5771 false without message
farm-v13-locked-rewards-dbg.wasm 14578 false without message
simple-lock-legacy-dbg.wasm 17298 false without message
simple-lock-legacy.wasm 6225 false without message
farm-v12.wasm 2235 false none
farm-v12-dbg.wasm 5147 false none
token-unstake.wasm 13304 false without message
token-unstake-dbg.wasm 35322 false without message
energy-factory.wasm 34159 false without message
energy-factory-dbg.wasm 85493 false without message
simple-lock-dbg.wasm 66275 false without message
simple-lock.wasm 25233 false without message
proxy_dex.wasm 36268 ➡️ 36263 🟢 false without message
proxy_dex-dbg.wasm 92057 false without message
locked-token-wrapper.wasm 14757 false without message
locked-token-wrapper-dbg.wasm 43761 false without message
lkmex-transfer-dbg.wasm 29657 false without message
lkmex-transfer.wasm 10589 false without message
pause-all-dbg.wasm 14858 false without message
pause-all.wasm 5490 false without message
fees-collector-dbg.wasm 52460 false without message
fees-collector.wasm 18141 false without message
energy-update.wasm 1571 false none
energy-update-dbg.wasm 3925 false none
governance-v2.wasm 15907 false without message
governance-v2-dbg.wasm 44029 false without message
energy-factory-mock.wasm 3672 false without message
energy-factory-mock-dbg.wasm 10517 false without message
farm-staking-proxy.wasm 19197 ➡️ 20658 🔴 false without message
farm-staking-proxy-dbg.wasm 53159 ➡️ 56432 🔴 false without message
farm-staking.wasm 41279 ➡️ 43019 🔴 false without message
farm-staking-dbg.wasm 105710 ➡️ 109512 🔴 false without message

Comment on lines +54 to +56
#[view(getBlacklistedAddresses)]
#[storage_mapper("blacklistedAddresses")]
fn blacklisted_addresses(&self) -> UnorderedSetMapper<ManagedAddress>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you ever need a blacklist if all actions require user to be whitelisted?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've never even seen this blacklist used anywhere in the code, so I'd say just remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The blacklist is used in is_whitelisted view. The blacklist here is design to override the user's whitelist. For example, if the users whitelist an address and that address becomes malicious in any way, we as owners would have a way to block that address generally without clearing it out of everyone's whitelists.

#[upgrade]
fn upgrade(&self) {}

#[endpoint(whitelist)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[endpoint(whitelist)]
#[endpoint]

No need to specify the name if it's the same as the function.

Comment on lines +15 to +26
fn whitelist(&self, address_to_whitelist: ManagedAddress) {
let caller = self.blockchain().get_caller();
self.user_whitelisted_addresses(&caller)
.insert(address_to_whitelist);
}

#[endpoint(removeWhitelist)]
fn remove_whitelist(&self, address_to_remove: ManagedAddress) {
let caller = self.blockchain().get_caller();
self.user_whitelisted_addresses(&caller)
.swap_remove(&address_to_remove);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest taking MultiValueEncoded<ManagedAddress> as argument and add/remove.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e.

let mapper = user_whitelisted_addresses(&caller);
for addr in addresses {
     let _ = mapper.insert(&addr)
}

Similar for remove.

Comment on lines +17 to +18
self.user_whitelisted_addresses(&caller)
.insert(address_to_whitelist);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.user_whitelisted_addresses(&caller)
.insert(address_to_whitelist);
let _ = self.user_whitelisted_addresses(&caller)
.insert(address_to_whitelist);

Comment on lines +24 to +25
self.user_whitelisted_addresses(&caller)
.swap_remove(&address_to_remove);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.user_whitelisted_addresses(&caller)
.swap_remove(&address_to_remove);
let removed = self.user_whitelisted_addresses(&caller)
.swap_remove(&address_to_remove);
require!(removed, "address not in whitelist");

Just for a bit of extra safety.

Comment on lines +77 to +150
fn check_and_return_original_owner(&self) -> ManagedAddress {
let payments = self.call_value().all_esdt_transfers().clone_value();
let farm_token_mapper = self.farm_token();
let mut original_owner = ManagedAddress::zero();
for payment in payments.into_iter() {
let attributes: FarmTokenAttributes<Self::Api> =
farm_token_mapper.get_token_attributes(payment.token_nonce);

if original_owner.is_zero() {
original_owner = attributes.original_owner;
} else {
require!(
original_owner == attributes.original_owner,
"All position must have the same original owner"
);
}
}

require!(
!original_owner.is_zero(),
"Original owner could not be identified"
);

original_owner
}

fn check_additional_payments_original_owner(&self, user: &ManagedAddress) {
let payments = self.call_value().all_esdt_transfers().clone_value();
if payments.len() == 1 {
return;
}

let farm_token_mapper = self.farm_token();
let farm_token_id = farm_token_mapper.get_token_id();
for payment in payments.into_iter() {
if payment.token_identifier != farm_token_id {
continue;
}

let attributes: FarmTokenAttributes<Self::Api> =
farm_token_mapper.get_token_attributes(payment.token_nonce);

require!(
user == &attributes.original_owner,
"Provided address is not the same as the original owner"
);
}
}

fn require_user_whitelisted(&self, user: &ManagedAddress, authorized_address: &ManagedAddress) {
let permissions_hub_address = self.permissions_hub_address().get();
let is_whitelisted: bool = self
.permissions_hub_proxy(permissions_hub_address)
.is_whitelisted(user, authorized_address)
.execute_on_dest_context();

require!(is_whitelisted, "Caller is not whitelisted by the user");
}

#[only_owner]
#[endpoint(setPermissionsHubAddress)]
fn set_permissions_hub_address(&self, address: ManagedAddress) {
self.permissions_hub_address().set(&address);
}

#[proxy]
fn permissions_hub_proxy(
&self,
sc_address: ManagedAddress,
) -> permissions_hub::Proxy<Self::Api>;

#[storage_mapper("permissionsHubAddress")]
fn permissions_hub_address(&self) -> SingleValueMapper<ManagedAddress>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like the fact that this code is duplicated in all the contracts. You can refactor it and put it into the common/modules/farm folder.

For check_and_return_original_owner, take the mapper as argument, and take the attributes type as a trait parameter, i.e.

fn check_and_return_original_owner<T: FarmToken>(&self, mapper: &NonFungibleTokenMapper) -> ManagedAddress {
     //
}

Add a method for fn get_original_owner(&self) -> ManagedAddress in FarmToken trait, since you need that field.

Also, for consistency with the other methods, have the payments as arguments instead.

Similar changes for check_additional_payments_original_owner

Copy link
Contributor

Choose a reason for hiding this comment

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

I've done what you need here, so you can copy that part: https://github.com/multiversx/mx-exchange-sc/pull/968/files

Comment on lines +40 to +75
#[payable("*")]
#[endpoint(enterFarmOnBehalf)]
fn enter_farm_on_behalf(&self, user: ManagedAddress) -> EnterFarmResultType<Self::Api> {
let caller = self.blockchain().get_caller();
self.require_user_whitelisted(&user, &caller);

self.check_additional_payments_original_owner(&user);

let boosted_rewards = self.claim_only_boosted_payment(&user);

let boosted_rewards_payment =
EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards);

let new_farm_token = self.enter_farm::<Wrapper<Self>>(user.clone());
self.send_payment_non_zero(&caller, &new_farm_token);
self.send_payment_non_zero(&user, &boosted_rewards_payment);

self.update_energy_and_progress(&user);

(new_farm_token, boosted_rewards_payment).into()
}

#[payable("*")]
#[endpoint(claimRewardsOnBehalf)]
fn claim_rewards_on_behalf(&self) -> ClaimRewardsResultType<Self::Api> {
let user = self.check_and_return_original_owner();
let caller = self.blockchain().get_caller();
self.require_user_whitelisted(&user, &caller);

let claim_rewards_result = self.claim_rewards::<Wrapper<Self>>(user.clone());

self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token);
self.send_payment_non_zero(&user, &claim_rewards_result.rewards);

claim_rewards_result.into()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These functions can remain here, as they seem to do a lot of different logic.

Comment on lines +86 to +94
let claim_result = ClaimDualYieldResult {
lp_farm_rewards,
staking_farm_rewards,
new_dual_yield_tokens,
};

dual_yield_token_mapper.nft_burn(payment.token_nonce, &payment.amount);

claim_result
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let claim_result = ClaimDualYieldResult {
lp_farm_rewards,
staking_farm_rewards,
new_dual_yield_tokens,
};
dual_yield_token_mapper.nft_burn(payment.token_nonce, &payment.amount);
claim_result
dual_yield_token_mapper.nft_burn(payment.token_nonce, &payment.amount);
ClaimDualYieldResult {
lp_farm_rewards,
staking_farm_rewards,
new_dual_yield_tokens,
}

(virtual_farm_token.payment, claim_result.rewards).into()
}

fn check_and_return_original_owner(&self, payment: &EsdtTokenPayment) -> ManagedAddress {
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated code with farm, farm-staking-proxy, etc.. Can you refactor to avoid code duplication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants