├── .cargo └── audit.toml ├── .github └── workflows │ ├── coverage.yml │ ├── main.yml │ └── scripts.yml ├── .gitignore ├── CHANGELOG.md ├── CODING_GUIDELINES.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── Makefile.toml ├── README.md ├── audit.txt ├── clippy.toml ├── codecov.yml ├── contracts ├── account-nft │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── contract.rs │ │ ├── error.rs │ │ ├── execute.rs │ │ ├── lib.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── query.rs │ │ └── state.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ ├── health_responses.rs │ │ ├── mock_contracts.rs │ │ ├── mock_env.rs │ │ ├── mock_env_builder.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_burn_allowance.rs │ │ ├── test_instantiate.rs │ │ ├── test_migration_v2.rs │ │ ├── test_mint.rs │ │ ├── test_proposed_minter.rs │ │ └── test_update_config.rs ├── address-provider │ ├── Cargo.toml │ ├── README.md │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── contract.rs │ │ ├── error.rs │ │ ├── helpers.rs │ │ ├── key.rs │ │ ├── lib.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ ├── v2_1_0.rs │ │ │ └── v2_1_1.rs │ │ └── state.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_addresses.rs │ │ ├── test_instantiate.rs │ │ ├── test_migration_v2.rs │ │ └── test_update_owner.rs ├── credit-manager │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── borrow.rs │ │ ├── claim_astro_lp_rewards.rs │ │ ├── claim_rewards.rs │ │ ├── contract.rs │ │ ├── deposit.rs │ │ ├── error.rs │ │ ├── execute.rs │ │ ├── health.rs │ │ ├── hls.rs │ │ ├── instantiate.rs │ │ ├── lend.rs │ │ ├── lib.rs │ │ ├── liquidate.rs │ │ ├── liquidate_astro_lp.rs │ │ ├── liquidate_deposit.rs │ │ ├── liquidate_lend.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── query.rs │ │ ├── reclaim.rs │ │ ├── refund.rs │ │ ├── repay.rs │ │ ├── stake_astro_lp.rs │ │ ├── state.rs │ │ ├── swap.rs │ │ ├── unstake_astro_lp.rs │ │ ├── update_coin_balances.rs │ │ ├── update_config.rs │ │ ├── utils.rs │ │ ├── vault │ │ │ ├── enter.rs │ │ │ ├── exit.rs │ │ │ ├── exit_unlocked.rs │ │ │ ├── liquidate_vault.rs │ │ │ ├── mod.rs │ │ │ ├── request_unlock.rs │ │ │ └── utils.rs │ │ ├── withdraw.rs │ │ └── zap.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── files │ │ └── Rover - Dynamic LB & CF test cases v1.1.xlsx │ │ ├── mod.rs │ │ ├── test_borrow.rs │ │ ├── test_claim_astro_lp_rewards.rs │ │ ├── test_claim_rewards.rs │ │ ├── test_coin_balances.rs │ │ ├── test_create_credit_account.rs │ │ ├── test_deposit.rs │ │ ├── test_deposit_cap.rs │ │ ├── test_dispatch.rs │ │ ├── test_enumerate_accounts.rs │ │ ├── test_enumerate_coin_balances.rs │ │ ├── test_enumerate_debt_shares.rs │ │ ├── test_enumerate_total_debt_shares.rs │ │ ├── test_enumerate_vault_positions.rs │ │ ├── test_fund_manager_accounts.rs │ │ ├── test_health.rs │ │ ├── test_hls_accounts.rs │ │ ├── test_instantiate.rs │ │ ├── test_lend.rs │ │ ├── test_liquidate_deposit.rs │ │ ├── test_liquidate_guard.rs │ │ ├── test_liquidate_lend.rs │ │ ├── test_liquidate_staked_astro_lp.rs │ │ ├── test_liquidate_vault.rs │ │ ├── test_liquidation_pricing.rs │ │ ├── test_migration_v2.rs │ │ ├── test_no_health_check.rs │ │ ├── test_reclaim.rs │ │ ├── test_reentrancy_guard.rs │ │ ├── test_refund_balances.rs │ │ ├── test_repay.rs │ │ ├── test_repay_for_recipient.rs │ │ ├── test_repay_from_wallet.rs │ │ ├── test_stake_astro_lp.rs │ │ ├── test_swap.rs │ │ ├── test_unstake_astro_lp.rs │ │ ├── test_update_admin.rs │ │ ├── test_update_config.rs │ │ ├── test_update_credit_account_with_new_acc.rs │ │ ├── test_update_nft_config.rs │ │ ├── test_utilization_query.rs │ │ ├── test_utilizations_all_query.rs │ │ ├── test_vault_enter.rs │ │ ├── test_vault_exit.rs │ │ ├── test_vault_exit_unlocked.rs │ │ ├── test_vault_query_value.rs │ │ ├── test_vault_request_unlock.rs │ │ ├── test_withdraw.rs │ │ ├── test_zap_provide.rs │ │ └── test_zap_withdraw.rs ├── health │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── compute.rs │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── querier.rs │ │ ├── state.rs │ │ └── update_config.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ ├── defaults.rs │ │ ├── mock_contracts.rs │ │ ├── mock_env.rs │ │ ├── mock_env_builder.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_health_state.rs │ │ ├── test_health_values.rs │ │ ├── test_hls.rs │ │ ├── test_instantiate.rs │ │ ├── test_liquidation_pricing.rs │ │ ├── test_migration_v2.rs │ │ └── test_update_config.rs ├── incentives │ ├── Cargo.toml │ ├── README.md │ ├── examples │ │ └── schema.rs │ ├── files │ │ ├── claim.png │ │ ├── stake.png │ │ └── unstake.png │ ├── src │ │ ├── astro_incentives.rs │ │ ├── config.rs │ │ ├── contract.rs │ │ ├── error.rs │ │ ├── helpers.rs │ │ ├── lib.rs │ │ ├── mars_incentives.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── query.rs │ │ └── state.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_admin.rs │ │ ├── test_balance_change.rs │ │ ├── test_claim_astro_lp_rewards.rs │ │ ├── test_claim_rewards.rs │ │ ├── test_indices_usage.rs │ │ ├── test_migration_v2.rs │ │ ├── test_quering.rs │ │ ├── test_set_asset_incentive.rs │ │ ├── test_update_owner.rs │ │ └── test_whitelist.rs ├── mock-astroport-incentives │ ├── Cargo.toml │ └── src │ │ ├── contract.rs │ │ ├── execute.rs │ │ ├── lib.rs │ │ ├── query.rs │ │ └── state.rs ├── mock-credit-manager │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ └── src │ │ ├── contract.rs │ │ ├── execute.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ ├── query.rs │ │ └── state.rs ├── mock-health │ ├── Cargo.toml │ └── src │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs ├── mock-incentives │ ├── Cargo.toml │ └── src │ │ ├── contract.rs │ │ ├── execute.rs │ │ ├── lib.rs │ │ ├── query.rs │ │ └── state.rs ├── mock-oracle │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ └── src │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ └── state.rs ├── mock-pyth │ ├── Cargo.toml │ └── src │ │ ├── contract.rs │ │ └── lib.rs ├── mock-red-bank │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ └── src │ │ ├── contract.rs │ │ ├── execute.rs │ │ ├── helpers.rs │ │ ├── lib.rs │ │ ├── query.rs │ │ └── state.rs ├── mock-vault │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ └── src │ │ ├── contract.rs │ │ ├── deposit.rs │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── msg.rs │ │ ├── query.rs │ │ ├── state.rs │ │ ├── unlock.rs │ │ └── withdraw.rs ├── oracle │ ├── base │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── error.rs │ │ │ ├── lib.rs │ │ │ ├── lp_pricing.rs │ │ │ ├── pyth.rs │ │ │ ├── redemption_rate.rs │ │ │ └── traits.rs │ ├── osmosis │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── examples │ │ │ └── schema.rs │ │ ├── src │ │ │ ├── contract.rs │ │ │ ├── helpers.rs │ │ │ ├── lib.rs │ │ │ ├── migrations │ │ │ │ ├── mod.rs │ │ │ │ └── v2_1_0.rs │ │ │ ├── msg.rs │ │ │ └── price_source.rs │ │ └── tests │ │ │ ├── all_tests.rs │ │ │ └── tests │ │ │ ├── helpers │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── test_admin.rs │ │ │ ├── test_custom_execute.rs │ │ │ ├── test_migration_v2.rs │ │ │ ├── test_price_source_fmt.rs │ │ │ ├── test_query_price.rs │ │ │ ├── test_query_price_for_pyth.rs │ │ │ ├── test_remove_price_source.rs │ │ │ ├── test_set_price_source.rs │ │ │ └── test_update_owner.rs │ └── wasm │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── examples │ │ └── schema.rs │ │ ├── src │ │ ├── astroport_twap.rs │ │ ├── contract.rs │ │ ├── helpers.rs │ │ ├── lib.rs │ │ ├── lp_pricing.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_0_0.rs │ │ ├── price_source.rs │ │ └── state.rs │ │ └── tests │ │ ├── all_tests.rs │ │ ├── astroport-artifacts │ │ ├── astroport_factory.wasm │ │ ├── astroport_generator.wasm │ │ ├── astroport_maker.wasm │ │ ├── astroport_native_coin_registry.wasm │ │ ├── astroport_pair.wasm │ │ ├── astroport_pair_concentrated.wasm │ │ ├── astroport_pair_stable.wasm │ │ ├── astroport_router.wasm │ │ ├── astroport_satellite.wasm │ │ ├── astroport_staking.wasm │ │ ├── astroport_token.wasm │ │ ├── astroport_vesting.wasm │ │ ├── astroport_whitelist.wasm │ │ └── version.md │ │ ├── files │ │ ├── PCL pricing test cases.xlsx │ │ └── SS pricing test cases.xlsx │ │ ├── stride-artifacts │ │ └── ica_oracle.wasm │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── prop_tests.proptest-regressions │ │ ├── prop_tests.rs │ │ ├── test_migration_v2.rs │ │ ├── test_price_source.rs │ │ └── test_update_admin.rs ├── params │ ├── Cargo.toml │ ├── README.md │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── contract.rs │ │ ├── emergency_powers.rs │ │ ├── error.rs │ │ ├── execute.rs │ │ ├── lib.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── query.rs │ │ └── state.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ ├── assertions.rs │ │ ├── contracts.rs │ │ ├── generator.rs │ │ ├── mock_env.rs │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_all_total_deposits_v2.rs │ │ ├── test_asset_validation.rs │ │ ├── test_deposit_cap.rs │ │ ├── test_emergency_powers.rs │ │ ├── test_migration_v2.rs │ │ ├── test_owner.rs │ │ ├── test_query_all_vault_configs_v2.rs │ │ ├── test_target_health_factor.rs │ │ ├── test_update_asset_params.rs │ │ ├── test_update_config.rs │ │ ├── test_vault_validation.rs │ │ └── test_vaults.rs ├── red-bank │ ├── Cargo.toml │ ├── README.md │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── asset.rs │ │ ├── borrow.rs │ │ ├── collateral.rs │ │ ├── config.rs │ │ ├── contract.rs │ │ ├── deposit.rs │ │ ├── error.rs │ │ ├── health.rs │ │ ├── helpers.rs │ │ ├── instantiate.rs │ │ ├── interest_rates.rs │ │ ├── lib.rs │ │ ├── liquidate.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ ├── query.rs │ │ ├── repay.rs │ │ ├── state.rs │ │ ├── user.rs │ │ └── withdraw.rs │ └── tests │ │ ├── all_tests.rs │ │ ├── files │ │ └── Red Bank - Dynamic LB & CF test cases v1.1.xlsx │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_admin.rs │ │ ├── test_borrow.rs │ │ ├── test_credit_accounts.rs │ │ ├── test_deposit.rs │ │ ├── test_health.rs │ │ ├── test_inflated_collateral.rs │ │ ├── test_liquidate.rs │ │ ├── test_migration_v2.rs │ │ ├── test_misc.rs │ │ ├── test_payment.rs │ │ ├── test_query.rs │ │ ├── test_update_owner.rs │ │ └── test_withdraw.rs ├── rewards-collector │ ├── README.md │ ├── base │ │ ├── Cargo.toml │ │ ├── examples │ │ │ └── schema.rs │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── error.rs │ │ │ ├── helpers.rs │ │ │ ├── lib.rs │ │ │ └── traits.rs │ ├── neutron │ │ ├── Cargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── migrations │ │ │ │ ├── mod.rs │ │ │ │ └── v2_0_0.rs │ │ └── tests │ │ │ ├── all_tests.rs │ │ │ └── tests │ │ │ ├── mod.rs │ │ │ └── test_migration_v2.rs │ └── osmosis │ │ ├── Cargo.toml │ │ ├── src │ │ ├── lib.rs │ │ └── migrations │ │ │ ├── mod.rs │ │ │ ├── v2_1_0.rs │ │ │ └── v2_1_1.rs │ │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_admin.rs │ │ ├── test_distribute_rewards.rs │ │ ├── test_migration_v2_1_0_to_v2_1_1.rs │ │ ├── test_swap.rs │ │ ├── test_update_owner.rs │ │ └── test_withdraw.rs ├── swapper │ ├── README.md │ ├── astroport │ │ ├── Cargo.toml │ │ ├── examples │ │ │ └── schema.rs │ │ ├── src │ │ │ ├── config.rs │ │ │ ├── contract.rs │ │ │ ├── helpers.rs │ │ │ ├── lib.rs │ │ │ ├── migrations │ │ │ │ ├── mod.rs │ │ │ │ └── v2_0_0.rs │ │ │ └── route.rs │ │ └── tests │ │ │ ├── all_tests.rs │ │ │ └── tests │ │ │ ├── mod.rs │ │ │ ├── test_config.rs │ │ │ ├── test_migration_v2.rs │ │ │ ├── test_queries.rs │ │ │ ├── test_routes.rs │ │ │ ├── test_swap.rs │ │ │ └── test_transfer_result.rs │ ├── base │ │ ├── Cargo.toml │ │ ├── examples │ │ │ └── schema.rs │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── error.rs │ │ │ ├── lib.rs │ │ │ └── traits.rs │ ├── mock │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── contract.rs │ │ │ └── lib.rs │ └── osmosis │ │ ├── Cargo.toml │ │ ├── examples │ │ └── schema.rs │ │ ├── src │ │ ├── config.rs │ │ ├── contract.rs │ │ ├── helpers.rs │ │ ├── lib.rs │ │ ├── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ └── route.rs │ │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ ├── mod.rs │ │ ├── test_enumerate_routes.rs │ │ ├── test_estimate.rs │ │ ├── test_instantiate.rs │ │ ├── test_migration_v2.rs │ │ ├── test_set_route.rs │ │ ├── test_swap.rs │ │ └── test_update_admin.rs ├── v2-zapper │ ├── astroport │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── lib.rs │ │ │ └── lp_pool.rs │ ├── base │ │ ├── Cargo.toml │ │ ├── examples │ │ │ └── schema.rs │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── error.rs │ │ │ ├── helpers.rs │ │ │ ├── lib.rs │ │ │ └── traits.rs │ ├── mock │ │ ├── Cargo.toml │ │ ├── examples │ │ │ └── schema.rs │ │ └── src │ │ │ ├── contract.rs │ │ │ ├── error.rs │ │ │ ├── execute.rs │ │ │ ├── lib.rs │ │ │ ├── msg.rs │ │ │ ├── query.rs │ │ │ └── state.rs │ └── osmosis │ │ ├── Cargo.toml │ │ ├── src │ │ ├── contract.rs │ │ ├── lib.rs │ │ ├── lp_pool.rs │ │ └── migrations │ │ │ ├── mod.rs │ │ │ └── v2_1_0.rs │ │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ ├── mod.rs │ │ └── utils.rs │ │ ├── mod.rs │ │ ├── test_callback.rs │ │ ├── test_migration_v2.rs │ │ ├── test_provide_liquidity.rs │ │ ├── test_queries.rs │ │ └── test_withdraw_liquidity.rs └── vault │ ├── Cargo.toml │ ├── examples │ └── schema.rs │ ├── src │ ├── contract.rs │ ├── error.rs │ ├── execute.rs │ ├── instantiate.rs │ ├── lib.rs │ ├── msg.rs │ ├── performance_fee.rs │ ├── query.rs │ ├── state.rs │ ├── token_factory.rs │ └── vault_token.rs │ └── tests │ ├── all_tests.rs │ ├── files │ └── Mars - 3rd party Vault - Performance Fee - test cases v1.0.xlsx │ └── tests │ ├── mod.rs │ ├── test_binding.rs │ ├── test_deposit.rs │ ├── test_instantiate.rs │ ├── test_performance_fee.rs │ ├── test_redeem.rs │ ├── test_unlock.rs │ └── vault_helpers.rs ├── coverage_grcov.Makefile.toml ├── files └── types_diff_v1_0_0__mars_v2.txt ├── integration-tests ├── Cargo.toml ├── README.md ├── src │ └── lib.rs └── tests │ ├── cosmos_bank.rs │ ├── files │ ├── Red Bank interest rates.xlsx │ └── stride-artifacts │ │ ├── 151_stride_redemption_rate.wasm │ │ └── version.md │ ├── helpers.rs │ ├── test_astro_lp_incentives.rs │ ├── test_incentives.rs │ ├── test_oracles.rs │ ├── test_rewards_collector.rs │ ├── test_rover_flow.rs │ └── test_user_flow.rs ├── packages ├── chains │ └── osmosis │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ ├── helpers.rs │ │ └── lib.rs ├── health-computer │ ├── Cargo.toml │ ├── examples │ │ └── schema.rs │ ├── src │ │ ├── data_types.rs │ │ ├── health_computer.rs │ │ ├── javascript.rs │ │ └── lib.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── helpers │ │ ├── mock_coin_info.rs │ │ ├── mock_vault_config.rs │ │ ├── mod.rs │ │ ├── prop_test_runner_borrow.rs │ │ ├── prop_test_runner_swap.rs │ │ └── prop_test_strategies.rs │ │ ├── mod.rs │ │ ├── test_health_scenarios.rs │ │ ├── test_hls.rs │ │ ├── test_input_validation.rs │ │ ├── test_max_borrow_deposit.rs │ │ ├── test_max_borrow_prop.rs │ │ ├── test_max_borrow_validation.rs │ │ ├── test_max_borrow_vault.rs │ │ ├── test_max_borrow_wallet.rs │ │ ├── test_max_swap.rs │ │ ├── test_max_swap_prop.rs │ │ ├── test_max_swap_validation.rs │ │ ├── test_max_withdraw.rs │ │ └── test_max_withdraw_prop_test.rs ├── health │ ├── Cargo.toml │ ├── README.md │ ├── src │ │ ├── error.rs │ │ ├── health.rs │ │ ├── lib.rs │ │ └── query.rs │ └── tests │ │ ├── all_tests.rs │ │ └── tests │ │ ├── mod.rs │ │ ├── test_from_coins_to_positions.rs │ │ ├── test_health.rs │ │ └── test_health_from_coins.rs ├── interest-rate │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── liquidation │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── error.rs │ │ ├── lib.rs │ │ └── liquidation.rs ├── testing │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── astroport_incentives_querier.rs │ │ ├── astroport_swapper.rs │ │ ├── cosmwasm_pool_querier.rs │ │ ├── helpers.rs │ │ ├── incentives_querier.rs │ │ ├── integration │ │ ├── helpers.rs │ │ ├── mock_contracts.rs │ │ ├── mock_env.rs │ │ └── mod.rs │ │ ├── lib.rs │ │ ├── mars_mock_querier.rs │ │ ├── mock_address_provider.rs │ │ ├── mocks.rs │ │ ├── multitest │ │ ├── helpers │ │ │ ├── assertions.rs │ │ │ ├── builders.rs │ │ │ ├── contracts.rs │ │ │ ├── mock_entity_info.rs │ │ │ ├── mock_env.rs │ │ │ ├── mod.rs │ │ │ ├── types.rs │ │ │ └── utils.rs │ │ ├── mod.rs │ │ └── modules │ │ │ ├── mod.rs │ │ │ └── token_factory.rs │ │ ├── oracle_querier.rs │ │ ├── osmosis_querier.rs │ │ ├── params_querier.rs │ │ ├── pyth_querier.rs │ │ ├── red_bank_querier.rs │ │ ├── redemption_rate_querier.rs │ │ ├── swapper_querier.rs │ │ ├── test_runner.rs │ │ └── wasm_oracle.rs ├── types │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── account_nft │ │ ├── execute.rs │ │ ├── instantiate.rs │ │ ├── mod.rs │ │ ├── nft_config.rs │ │ └── query.rs │ │ ├── adapters │ │ ├── account_nft.rs │ │ ├── health.rs │ │ ├── incentives.rs │ │ ├── mod.rs │ │ ├── oracle.rs │ │ ├── params.rs │ │ ├── red_bank.rs │ │ ├── rewards_collector.rs │ │ ├── swapper.rs │ │ ├── vault │ │ │ ├── amount.rs │ │ │ ├── base.rs │ │ │ ├── mod.rs │ │ │ ├── position.rs │ │ │ └── update.rs │ │ └── zapper.rs │ │ ├── address_provider.rs │ │ ├── credit_manager │ │ ├── execute.rs │ │ ├── instantiate.rs │ │ ├── migrate.rs │ │ ├── mod.rs │ │ ├── query.rs │ │ └── reply.rs │ │ ├── error.rs │ │ ├── health │ │ ├── account.rs │ │ ├── error.rs │ │ ├── health.rs │ │ ├── mod.rs │ │ └── msg.rs │ │ ├── incentives.rs │ │ ├── keys.rs │ │ ├── lib.rs │ │ ├── oracle │ │ ├── mod.rs │ │ ├── msg.rs │ │ └── wasm_oracle.rs │ │ ├── params │ │ ├── assertions.rs │ │ ├── asset.rs │ │ ├── hls.rs │ │ ├── mod.rs │ │ ├── msg.rs │ │ └── vault.rs │ │ ├── red_bank │ │ ├── interest_rate_model.rs │ │ ├── market.rs │ │ ├── mod.rs │ │ ├── msg.rs │ │ └── types.rs │ │ ├── rewards_collector.rs │ │ ├── swapper.rs │ │ ├── traits.rs │ │ └── zapper.rs └── utils │ ├── Cargo.toml │ ├── README.md │ ├── src │ ├── error.rs │ ├── guard.rs │ ├── helpers.rs │ └── lib.rs │ └── tests │ └── test_denom_validator.rs ├── rustfmt.toml ├── schema.Makefile.toml ├── schemas ├── mars-account-nft │ └── mars-account-nft.json ├── mars-address-provider │ └── mars-address-provider.json ├── mars-credit-manager │ └── mars-credit-manager.json ├── mars-incentives │ └── mars-incentives.json ├── mars-mock-vault │ └── mars-mock-vault.json ├── mars-oracle-osmosis │ └── mars-oracle-osmosis.json ├── mars-oracle-wasm │ └── mars-oracle-wasm.json ├── mars-params │ └── mars-params.json ├── mars-red-bank │ └── mars-red-bank.json ├── mars-rewards-collector-base │ └── mars-rewards-collector-base.json ├── mars-rover-health-computer │ └── mars-rover-health-computer.json ├── mars-rover-health │ └── mars-rover-health.json ├── mars-swapper-astroport │ └── mars-swapper-astroport.json ├── mars-swapper-base │ └── mars-swapper-base.json ├── mars-swapper-osmosis │ └── mars-swapper-osmosis.json ├── mars-vault │ └── mars-vault.json └── mars-zapper-base │ └── mars-zapper-base.json └── scripts ├── .eslintignore ├── .eslintrc.cjs ├── .prettierignore ├── .prettierrc ├── codegen-tsconfig.json ├── codegen ├── index.ts └── insertIgnores.ts ├── deploy ├── addresses │ ├── devnet-deployer-owner.json │ ├── neutron-1-deployer-owner.json │ ├── neutron-1-multisig-owner.json │ ├── osmosis-1-multisig-owner.json │ └── pion-1-deployer-owner.json ├── base │ ├── deployer.ts │ ├── index-only-red-bank.ts │ ├── index.ts │ ├── setup-deployer.ts │ ├── storage.ts │ ├── test-actions-credit-manager.ts │ └── test-actions-red-bank.ts ├── neutron │ ├── devnet-config.ts │ ├── devnet-index.ts │ ├── mainnet-config.ts │ ├── mainnet-index.ts │ ├── record-twap-snapshots.ts │ ├── set-price.ts │ ├── testnet-config.ts │ ├── testnet-index.ts │ └── testnet-multisig-index.ts └── osmosis │ ├── devnet-index.ts │ ├── mainnet-config.ts │ ├── mainnet-index.ts │ ├── testnet-config.ts │ └── testnet-index.ts ├── health └── pkg-web │ ├── index.d.ts │ ├── index.js │ ├── index_bg.wasm │ ├── index_bg.wasm.d.ts │ └── package.json ├── multisig ├── mars │ └── README.md ├── neutron │ └── README.md └── osmosis │ ├── README.md │ ├── multisig-responsibilities.md │ └── multisig-setup.md ├── package.json ├── tsconfig.json ├── types ├── config.ts ├── generated │ ├── mars-account-nft │ │ ├── MarsAccountNft.client.ts │ │ ├── MarsAccountNft.react-query.ts │ │ ├── MarsAccountNft.types.ts │ │ └── bundle.ts │ ├── mars-address-provider │ │ ├── MarsAddressProvider.client.ts │ │ ├── MarsAddressProvider.react-query.ts │ │ ├── MarsAddressProvider.types.ts │ │ └── bundle.ts │ ├── mars-credit-manager │ │ ├── MarsCreditManager.client.ts │ │ ├── MarsCreditManager.react-query.ts │ │ ├── MarsCreditManager.types.ts │ │ └── bundle.ts │ ├── mars-incentives │ │ ├── MarsIncentives.client.ts │ │ ├── MarsIncentives.react-query.ts │ │ ├── MarsIncentives.types.ts │ │ └── bundle.ts │ ├── mars-mock-vault │ │ ├── MarsMockVault.client.ts │ │ ├── MarsMockVault.react-query.ts │ │ ├── MarsMockVault.types.ts │ │ └── bundle.ts │ ├── mars-oracle-osmosis │ │ ├── MarsOracleOsmosis.client.ts │ │ ├── MarsOracleOsmosis.react-query.ts │ │ ├── MarsOracleOsmosis.types.ts │ │ └── bundle.ts │ ├── mars-oracle-wasm │ │ ├── MarsOracleWasm.client.ts │ │ ├── MarsOracleWasm.react-query.ts │ │ ├── MarsOracleWasm.types.ts │ │ └── bundle.ts │ ├── mars-params │ │ ├── MarsParams.client.ts │ │ ├── MarsParams.react-query.ts │ │ ├── MarsParams.types.ts │ │ └── bundle.ts │ ├── mars-red-bank │ │ ├── MarsRedBank.client.ts │ │ ├── MarsRedBank.react-query.ts │ │ ├── MarsRedBank.types.ts │ │ └── bundle.ts │ ├── mars-rewards-collector-base │ │ ├── MarsRewardsCollectorBase.client.ts │ │ ├── MarsRewardsCollectorBase.react-query.ts │ │ ├── MarsRewardsCollectorBase.types.ts │ │ └── bundle.ts │ ├── mars-rover-health-computer │ │ ├── MarsRoverHealthComputer.client.ts │ │ ├── MarsRoverHealthComputer.react-query.ts │ │ ├── MarsRoverHealthComputer.types.ts │ │ └── bundle.ts │ ├── mars-rover-health │ │ ├── MarsRoverHealth.client.ts │ │ ├── MarsRoverHealth.react-query.ts │ │ ├── MarsRoverHealth.types.ts │ │ └── bundle.ts │ ├── mars-swapper-astroport │ │ ├── MarsSwapperAstroport.client.ts │ │ ├── MarsSwapperAstroport.react-query.ts │ │ ├── MarsSwapperAstroport.types.ts │ │ └── bundle.ts │ ├── mars-swapper-base │ │ ├── MarsSwapperBase.client.ts │ │ ├── MarsSwapperBase.react-query.ts │ │ ├── MarsSwapperBase.types.ts │ │ └── bundle.ts │ ├── mars-swapper-osmosis │ │ ├── MarsSwapperOsmosis.client.ts │ │ ├── MarsSwapperOsmosis.react-query.ts │ │ ├── MarsSwapperOsmosis.types.ts │ │ └── bundle.ts │ ├── mars-vault │ │ ├── MarsVault.client.ts │ │ ├── MarsVault.react-query.ts │ │ ├── MarsVault.types.ts │ │ └── bundle.ts │ └── mars-zapper-base │ │ ├── MarsZapperBase.client.ts │ │ ├── MarsZapperBase.react-query.ts │ │ ├── MarsZapperBase.types.ts │ │ └── bundle.ts ├── msgs.ts └── storageItems.ts ├── utils ├── chalk.ts └── environment.ts └── yarn.lock /.cargo/audit.toml: -------------------------------------------------------------------------------- 1 | # Reference: https://github.com/rustsec/rustsec/blob/main/cargo-audit/audit.toml.example 2 | 3 | [advisories] 4 | # Ignore the following advisory IDs. 5 | # Reported vulnerabilities relate to test-tube and cw-it which is only used for testing. 6 | # RUSTSEC-2024-0344 - no newer dependency fixing the issue in cosmwasm 7 | ignore = ["RUSTSEC-2024-0003", "RUSTSEC-2024-0006", "RUSTSEC-2024-0019", "RUSTSEC-2024-0332", "RUSTSEC-2024-0336", "RUSTSEC-2024-0344", "RUSTSEC-2024-0421", "RUSTSEC-2024-0437", "RUSTSEC-2025-0009"] -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Main 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - main 8 | - release/neutron 9 | pull_request: 10 | 11 | env: 12 | RUST_BACKTRACE: 1 13 | CARGO_TERM_COLOR: always 14 | 15 | jobs: 16 | check: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout sources 20 | uses: actions/checkout@v3 21 | 22 | # install a specific version of Go to satisfy osmosis-test-tube 23 | - uses: actions/setup-go@v5 24 | with: 25 | go-version: '1.21.7' 26 | 27 | - name: Install cargo make 28 | uses: davidB/rust-cargo-make@v1 29 | 30 | - name: Install stable Rust 31 | run: cargo make install-stable 32 | 33 | - name: Install nightly Rust 34 | run: cargo make install-nightly 35 | 36 | # selecting a toolchain should happen before the plugin, as the cache uses the current rustc version as its cache key 37 | - name: Cache dependencies 38 | uses: Swatinem/rust-cache@v2 39 | 40 | - name: Format 41 | run: cargo make fmt-check 42 | 43 | - name: Clippy 44 | run: cargo make clippy 45 | 46 | - name: Audit dependencies 47 | run: | 48 | cargo install --locked cargo-audit 49 | cargo make audit 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build results 2 | target/ 3 | build/ 4 | 5 | # Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) 6 | .cargo-ok 7 | 8 | # Text file backups 9 | **/*.rs.bk 10 | 11 | # macOS 12 | .DS_Store 13 | 14 | # IDEs 15 | *.iml 16 | .idea 17 | .vscode/ 18 | 19 | # Environment 20 | *.env 21 | jsconfig.json 22 | 23 | # Scripts 24 | node_modules/ 25 | whitelists/ 26 | 27 | # Artifacts 28 | artifacts/ 29 | 30 | yarn-error.log 31 | 32 | # private scripts that I don't want to commit are prefixed by an underscore 33 | **/_*.js 34 | **/_*.ts 35 | 36 | # proptest generated files 37 | **/*.proptest-regressions 38 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | too-many-arguments-threshold = 10 2 | type-complexity-threshold = 300 3 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | threshold: 0.05% 8 | patch: 9 | default: 10 | threshold: 0.05% 11 | -------------------------------------------------------------------------------- /contracts/account-nft/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-account-nft" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw2 = { workspace = true } 25 | cw721 = { workspace = true } 26 | cw721-base = { workspace = true } 27 | cw-storage-plus = { workspace = true } 28 | mars-types = { workspace = true } 29 | thiserror = { workspace = true } 30 | 31 | [dev-dependencies] 32 | anyhow = { workspace = true } 33 | cw721-base-v16 = { package = "cw721-base", version = "0.16.0" } 34 | cw-multi-test = { workspace = true } 35 | mars-mock-credit-manager = { workspace = true } 36 | mars-mock-rover-health = { workspace = true } 37 | mars-owner = { workspace = true } 38 | mars-testing = { workspace = true } 39 | serde_json = { workspace = true } 40 | -------------------------------------------------------------------------------- /contracts/account-nft/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::account_nft::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/account-nft/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{OverflowError, StdError}; 2 | use cw721_base::ContractError as Base721Error; 3 | use thiserror::Error; 4 | 5 | #[derive(Error, Debug, PartialEq)] 6 | pub enum ContractError { 7 | #[error("{0}")] 8 | Std(#[from] StdError), 9 | 10 | #[error("{0}")] 11 | BaseError(#[from] Base721Error), 12 | 13 | #[error("{0}")] 14 | Overflow(#[from] OverflowError), 15 | 16 | #[error("{reason:?}")] 17 | BurnNotAllowed { 18 | reason: String, 19 | }, 20 | 21 | #[error("Health contract should be added to config before burns are allowed")] 22 | HealthContractNotSet, 23 | 24 | #[error("Credit manager contract should be added to config before burns are allowed")] 25 | CreditManagerContractNotSet, 26 | 27 | #[error("{0}")] 28 | Version(#[from] cw2::VersionError), 29 | } 30 | -------------------------------------------------------------------------------- /contracts/account-nft/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod error; 3 | pub mod execute; 4 | pub mod migrations; 5 | pub mod query; 6 | pub mod state; 7 | -------------------------------------------------------------------------------- /contracts/account-nft/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/account-nft/src/query.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Deps, StdResult}; 2 | use mars_types::account_nft::UncheckedNftConfig; 3 | 4 | use crate::state::{CONFIG, NEXT_ID}; 5 | 6 | pub fn query_config(deps: Deps) -> StdResult { 7 | Ok(CONFIG.load(deps.storage)?.into()) 8 | } 9 | 10 | pub fn query_next_id(deps: Deps) -> StdResult { 11 | Ok(NEXT_ID.load(deps.storage)?.to_string()) 12 | } 13 | -------------------------------------------------------------------------------- /contracts/account-nft/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cw_storage_plus::Item; 3 | use mars_types::account_nft::NftConfig; 4 | 5 | pub const CONFIG: Item = Item::new("config"); 6 | pub const NEXT_ID: Item = Item::new("next_id"); 7 | 8 | /// Helper marker used during burning empty accounts. Used only for v1 -> v2 migration. 9 | #[cw_serde] 10 | pub enum BurningMarker { 11 | StartAfter(String), 12 | Finished, 13 | } 14 | pub const MIGRATION_BURNING_MARKER: Item = Item::new("burning_marker"); 15 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/tests/helpers/health_responses.rs: -------------------------------------------------------------------------------- 1 | use std::ops::Sub; 2 | 3 | use cosmwasm_std::Uint128; 4 | use mars_types::health::HealthValuesResponse; 5 | 6 | pub const MAX_VALUE_FOR_BURN: Uint128 = Uint128::new(1000); 7 | 8 | pub fn generate_health_response(debt_value: u128, collateral_value: u128) -> HealthValuesResponse { 9 | HealthValuesResponse { 10 | total_debt_value: debt_value.into(), 11 | total_collateral_value: collateral_value.into(), 12 | max_ltv_adjusted_collateral: Default::default(), 13 | liquidation_threshold_adjusted_collateral: Default::default(), 14 | max_ltv_health_factor: None, 15 | liquidation_health_factor: None, 16 | liquidatable: false, 17 | above_max_ltv: false, 18 | } 19 | } 20 | 21 | pub fn below_max_for_burn() -> HealthValuesResponse { 22 | HealthValuesResponse { 23 | total_debt_value: Default::default(), 24 | total_collateral_value: MAX_VALUE_FOR_BURN.sub(Uint128::one()), 25 | max_ltv_adjusted_collateral: Default::default(), 26 | liquidation_threshold_adjusted_collateral: Default::default(), 27 | max_ltv_health_factor: None, 28 | liquidation_health_factor: None, 29 | liquidatable: false, 30 | above_max_ltv: false, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/tests/helpers/mock_contracts.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Empty; 2 | use cw_multi_test::{Contract, ContractWrapper}; 3 | 4 | pub fn mock_nft_contract() -> Box> { 5 | let contract = ContractWrapper::new( 6 | mars_account_nft::contract::execute, 7 | mars_account_nft::contract::instantiate, 8 | mars_account_nft::contract::query, 9 | ); 10 | Box::new(contract) 11 | } 12 | 13 | pub fn mock_health_contract() -> Box> { 14 | let contract = ContractWrapper::new( 15 | mars_mock_rover_health::contract::execute, 16 | mars_mock_rover_health::contract::instantiate, 17 | mars_mock_rover_health::contract::query, 18 | ); 19 | Box::new(contract) 20 | } 21 | 22 | pub fn mock_credit_manager_contract() -> Box> { 23 | let contract = ContractWrapper::new( 24 | mars_mock_credit_manager::contract::execute, 25 | mars_mock_credit_manager::contract::instantiate, 26 | mars_mock_credit_manager::contract::query, 27 | ); 28 | Box::new(contract) 29 | } 30 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{health_responses::*, mock_contracts::*, mock_env::*, mock_env_builder::*}; 2 | 3 | mod health_responses; 4 | mod mock_contracts; 5 | mod mock_env; 6 | mod mock_env_builder; 7 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_burn_allowance; 4 | mod test_instantiate; 5 | mod test_migration_v2; 6 | mod test_mint; 7 | mod test_proposed_minter; 8 | mod test_update_config; 9 | -------------------------------------------------------------------------------- /contracts/account-nft/tests/tests/test_instantiate.rs: -------------------------------------------------------------------------------- 1 | use super::helpers::{MockEnv, MAX_VALUE_FOR_BURN}; 2 | 3 | #[test] 4 | fn instantiated_storage_vars() { 5 | let mut mock = MockEnv::new() 6 | .set_minter("spiderman_1337") 7 | .instantiate_with_health_contract(false) 8 | .build() 9 | .unwrap(); 10 | 11 | let config = mock.query_config(); 12 | assert_eq!(config.health_contract_addr, None); 13 | assert_eq!(config.max_value_for_burn, MAX_VALUE_FOR_BURN); 14 | 15 | let ownership = mock.query_ownership(); 16 | assert_eq!("spiderman_1337", ownership.owner.unwrap()); 17 | assert_eq!(None, ownership.pending_owner); 18 | 19 | mock.assert_next_id("1"); 20 | } 21 | 22 | #[test] 23 | fn instantiated_storage_vars_with_health_contract() { 24 | let health_contract = "health_contract_xyz_abc"; 25 | let mut mock = MockEnv::new().set_health_contract(health_contract).build().unwrap(); 26 | 27 | let config = mock.query_config(); 28 | assert_eq!(config.health_contract_addr, Some(health_contract.to_string())); 29 | assert_eq!(config.max_value_for_burn, MAX_VALUE_FOR_BURN); 30 | 31 | mock.assert_next_id("1"); 32 | } 33 | -------------------------------------------------------------------------------- /contracts/address-provider/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-address-provider" 3 | description = "A smart contract that holds addresses of Mars Red Bank contracts" 4 | version = "2.1.1" 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | crate-type = ["cdylib", "rlib"] 15 | doctest = false 16 | 17 | [features] 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | library = [] 21 | 22 | [dependencies] 23 | bech32 = { workspace = true } 24 | cosmwasm-schema = { workspace = true } 25 | cosmwasm-std = { workspace = true } 26 | cw2 = { workspace = true } 27 | cw-storage-plus = { workspace = true } 28 | mars-owner = { workspace = true } 29 | mars-types = { workspace = true } 30 | thiserror = { workspace = true } 31 | 32 | [dev-dependencies] 33 | cosmwasm-schema = { workspace = true } 34 | mars-testing = { workspace = true } 35 | serde = { workspace = true } 36 | -------------------------------------------------------------------------------- /contracts/address-provider/README.md: -------------------------------------------------------------------------------- 1 | # Mars Address Provider 2 | 3 | A smart contract that holds addresses of Mars Red Bank contracts. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /contracts/address-provider/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::address_provider::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/address-provider/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use mars_owner::OwnerError; 3 | use thiserror::Error; 4 | 5 | #[derive(Error, Debug, PartialEq)] 6 | pub enum ContractError { 7 | #[error("{0}")] 8 | Std(#[from] StdError), 9 | 10 | #[error("{0}")] 11 | Owner(#[from] OwnerError), 12 | 13 | #[error("Invalid address: {0}")] 14 | InvalidAddress(String), 15 | 16 | #[error("Invalid chain prefix: {0}")] 17 | InvalidChainPrefix(String), 18 | 19 | #[error("{0}")] 20 | Version(#[from] cw2::VersionError), 21 | } 22 | -------------------------------------------------------------------------------- /contracts/address-provider/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Api; 2 | 3 | use crate::error::ContractError; 4 | 5 | /// Assert an address is valid 6 | /// 7 | /// NOTE: The `deps.api.addr_validate` function can only verify addresses of the current chain, e.g. 8 | /// a contract on Osmosis can only verify addresses with the `osmo1` prefix. If the provided address 9 | /// does not start with this prefix, we use bech32 decoding (valid address should be successfully decoded). 10 | pub(crate) fn assert_valid_addr( 11 | api: &dyn Api, 12 | human: &str, 13 | prefix: &str, 14 | ) -> Result<(), ContractError> { 15 | if human.starts_with(prefix) { 16 | api.addr_validate(human)?; 17 | } else { 18 | bech32::decode(human).map_err(|_| ContractError::InvalidAddress(human.to_string()))?; 19 | } 20 | Ok(()) 21 | } 22 | 23 | /// Prefix should be related to owner address prefix on a specific chain 24 | pub(crate) fn assert_valid_prefix(owner: &str, prefix: &str) -> Result<(), ContractError> { 25 | if !owner.starts_with(prefix) { 26 | return Err(ContractError::InvalidChainPrefix(prefix.to_string())); 27 | } 28 | Ok(()) 29 | } 30 | -------------------------------------------------------------------------------- /contracts/address-provider/src/key.rs: -------------------------------------------------------------------------------- 1 | use std::{convert::TryFrom, str::FromStr}; 2 | 3 | use cosmwasm_std::{StdError, StdResult}; 4 | use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey}; 5 | use mars_types::address_provider::MarsAddressType; 6 | 7 | #[derive(Clone, Debug, PartialEq, Eq)] 8 | pub struct MarsAddressTypeKey(pub Vec); 9 | 10 | impl From for MarsAddressTypeKey { 11 | fn from(address_type: MarsAddressType) -> Self { 12 | Self(address_type.to_string().into_bytes()) 13 | } 14 | } 15 | 16 | impl TryFrom for MarsAddressType { 17 | type Error = StdError; 18 | 19 | fn try_from(key: MarsAddressTypeKey) -> Result { 20 | let s = String::from_utf8(key.0)?; 21 | MarsAddressType::from_str(&s) 22 | } 23 | } 24 | 25 | impl<'a> PrimaryKey<'a> for MarsAddressTypeKey { 26 | type Prefix = (); 27 | type SubPrefix = (); 28 | type Suffix = Self; 29 | type SuperSuffix = Self; 30 | 31 | fn key(&self) -> Vec { 32 | vec![Key::Ref(&self.0)] 33 | } 34 | } 35 | 36 | impl<'a> Prefixer<'a> for MarsAddressTypeKey { 37 | fn prefix(&self) -> Vec { 38 | vec![Key::Ref(&self.0)] 39 | } 40 | } 41 | 42 | impl KeyDeserialize for MarsAddressTypeKey { 43 | type Output = Self; 44 | 45 | #[inline(always)] 46 | fn from_vec(value: Vec) -> StdResult { 47 | Ok(Self(value)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /contracts/address-provider/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod error; 3 | mod helpers; 4 | mod key; 5 | pub mod migrations; 6 | pub mod state; 7 | -------------------------------------------------------------------------------- /contracts/address-provider/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | pub mod v2_1_1; 3 | -------------------------------------------------------------------------------- /contracts/address-provider/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | 4 | use crate::{ 5 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 6 | error::ContractError, 7 | }; 8 | 9 | const FROM_VERSION: &str = "2.0.0"; 10 | 11 | pub fn migrate(deps: DepsMut) -> Result { 12 | // make sure we're migrating the correct contract and from the correct version 13 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 14 | 15 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 16 | 17 | Ok(Response::new() 18 | .add_attribute("action", "migrate") 19 | .add_attribute("from_version", FROM_VERSION) 20 | .add_attribute("to_version", CONTRACT_VERSION)) 21 | } 22 | -------------------------------------------------------------------------------- /contracts/address-provider/src/migrations/v2_1_1.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | 4 | use crate::{ 5 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 6 | error::ContractError, 7 | }; 8 | 9 | const FROM_VERSION: &str = "2.1.0"; 10 | 11 | pub fn migrate(deps: DepsMut) -> Result { 12 | // make sure we're migrating the correct contract and from the correct version 13 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 14 | 15 | // add new address 16 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 17 | 18 | Ok(Response::new() 19 | .add_attribute("action", "migrate") 20 | .add_attribute("from_version", FROM_VERSION) 21 | .add_attribute("to_version", CONTRACT_VERSION)) 22 | } 23 | -------------------------------------------------------------------------------- /contracts/address-provider/src/state.rs: -------------------------------------------------------------------------------- 1 | use cw_storage_plus::{Item, Map}; 2 | use mars_owner::Owner; 3 | use mars_types::address_provider::Config; 4 | 5 | use crate::key::MarsAddressTypeKey; 6 | 7 | pub const OWNER: Owner = Owner::new("owner"); 8 | pub const CONFIG: Item = Item::new("config"); 9 | pub const ADDRESSES: Map = Map::new("addresses"); 10 | -------------------------------------------------------------------------------- /contracts/address-provider/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/address-provider/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | use cosmwasm_std::{ 4 | from_json, 5 | testing::{ 6 | mock_dependencies_with_balance, mock_env, mock_info, MockApi, MockQuerier, MockStorage, 7 | }, 8 | Deps, OwnedDeps, 9 | }; 10 | use mars_address_provider::contract::{instantiate, query}; 11 | use mars_types::address_provider::{InstantiateMsg, QueryMsg}; 12 | 13 | pub fn th_setup() -> OwnedDeps { 14 | let mut deps = mock_dependencies_with_balance(&[]); 15 | 16 | instantiate( 17 | deps.as_mut(), 18 | mock_env(), 19 | mock_info("deployer", &[]), 20 | InstantiateMsg { 21 | owner: "osmo_owner".to_string(), 22 | prefix: "osmo".to_string(), 23 | }, 24 | ) 25 | .unwrap(); 26 | 27 | deps 28 | } 29 | 30 | pub fn th_query(deps: Deps, msg: QueryMsg) -> T { 31 | from_json(query(deps, mock_env(), msg).unwrap()).unwrap() 32 | } 33 | -------------------------------------------------------------------------------- /contracts/address-provider/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_addresses; 4 | mod test_instantiate; 5 | mod test_migration_v2; 6 | mod test_update_owner; 7 | -------------------------------------------------------------------------------- /contracts/address-provider/tests/tests/test_instantiate.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; 2 | use mars_address_provider::{contract::instantiate, error::ContractError}; 3 | use mars_types::address_provider::{ConfigResponse, InstantiateMsg, QueryMsg}; 4 | 5 | use super::helpers::th_query; 6 | 7 | #[test] 8 | fn invalid_chain_prefix() { 9 | let mut deps = mock_dependencies(); 10 | 11 | let err = instantiate( 12 | deps.as_mut(), 13 | mock_env(), 14 | mock_info("deployer", &[]), 15 | InstantiateMsg { 16 | owner: "osmo_owner".to_string(), 17 | prefix: "mars".to_string(), 18 | }, 19 | ) 20 | .unwrap_err(); 21 | assert_eq!(err, ContractError::InvalidChainPrefix("mars".to_string())); 22 | } 23 | 24 | #[test] 25 | fn proper_initialization() { 26 | let mut deps = mock_dependencies(); 27 | 28 | instantiate( 29 | deps.as_mut(), 30 | mock_env(), 31 | mock_info("deployer", &[]), 32 | InstantiateMsg { 33 | owner: "osmo1_owner".to_string(), 34 | prefix: "osmo".to_string(), 35 | }, 36 | ) 37 | .unwrap(); 38 | 39 | let config: ConfigResponse = th_query(deps.as_ref(), QueryMsg::Config {}); 40 | assert_eq!(config.owner, Some("osmo1_owner".to_string())); 41 | assert_eq!(config.proposed_new_owner, None); 42 | assert_eq!(config.prefix, "osmo".to_string()); 43 | } 44 | -------------------------------------------------------------------------------- /contracts/credit-manager/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::credit_manager::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/claim_astro_lp_rewards.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use mars_types::traits::Stringify; 3 | 4 | use crate::{ 5 | error::{ContractError, ContractResult}, 6 | state::INCENTIVES, 7 | utils::increment_coin_balance, 8 | }; 9 | 10 | pub fn claim_lp_rewards( 11 | deps: DepsMut, 12 | account_id: &str, 13 | lp_denom: &str, 14 | ) -> ContractResult { 15 | let incentives = INCENTIVES.load(deps.storage)?; 16 | 17 | // Query rewards user is receiving, update balance 18 | let rewards = incentives.query_staked_astro_lp_rewards(&deps.querier, account_id, lp_denom)?; 19 | if rewards.is_empty() { 20 | return Err(ContractError::NoAmount); 21 | } 22 | 23 | for reward in rewards.iter() { 24 | increment_coin_balance(deps.storage, account_id, reward)?; 25 | } 26 | 27 | let claim_rewards_msg = incentives.claim_staked_astro_lp_rewards_msg(account_id, lp_denom)?; 28 | let res = Response::new() 29 | .add_message(claim_rewards_msg) 30 | .add_attribute("action", "claim_astro_lp_rewards") 31 | .add_attribute("account_id", account_id) 32 | .add_attribute("rewards", rewards.as_slice().to_string()); 33 | 34 | Ok(res) 35 | } 36 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/claim_rewards.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use mars_types::traits::Stringify; 3 | 4 | use crate::{ 5 | error::{ContractError, ContractResult}, 6 | state::INCENTIVES, 7 | utils::increment_coin_balance, 8 | }; 9 | 10 | pub fn claim_rewards(deps: DepsMut, account_id: &str) -> ContractResult { 11 | let incentives = INCENTIVES.load(deps.storage)?; 12 | 13 | let unclaimed_rewards = incentives.query_unclaimed_rewards(&deps.querier, account_id)?; 14 | if unclaimed_rewards.is_empty() { 15 | return Err(ContractError::NoAmount); 16 | } 17 | 18 | for reward in unclaimed_rewards.iter() { 19 | increment_coin_balance(deps.storage, account_id, reward)?; 20 | } 21 | 22 | Ok(Response::new() 23 | .add_message(incentives.claim_rewards_msg(account_id)?) 24 | .add_attribute("action", "claim_rewards") 25 | .add_attribute("account_id", account_id) 26 | .add_attribute("rewards", unclaimed_rewards.as_slice().to_string())) 27 | } 28 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod borrow; 2 | pub mod claim_astro_lp_rewards; 3 | pub mod claim_rewards; 4 | pub mod contract; 5 | pub mod deposit; 6 | pub mod error; 7 | pub mod execute; 8 | pub mod health; 9 | pub mod hls; 10 | pub mod instantiate; 11 | pub mod lend; 12 | pub mod liquidate; 13 | pub mod liquidate_astro_lp; 14 | pub mod liquidate_deposit; 15 | pub mod liquidate_lend; 16 | pub mod migrations; 17 | pub mod query; 18 | pub mod reclaim; 19 | pub mod refund; 20 | pub mod repay; 21 | pub mod stake_astro_lp; 22 | pub mod state; 23 | pub mod swap; 24 | pub mod unstake_astro_lp; 25 | pub mod update_coin_balances; 26 | pub mod update_config; 27 | pub mod utils; 28 | pub mod vault; 29 | pub mod withdraw; 30 | pub mod zap; 31 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | 4 | use crate::{ 5 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 6 | error::ContractError, 7 | }; 8 | 9 | const FROM_VERSION: &str = "2.0.3"; 10 | 11 | pub fn migrate(deps: DepsMut) -> Result { 12 | // make sure we're migrating the correct contract and from the correct version 13 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 14 | 15 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 16 | 17 | Ok(Response::new() 18 | .add_attribute("action", "migrate") 19 | .add_attribute("from_version", FROM_VERSION) 20 | .add_attribute("to_version", CONTRACT_VERSION)) 21 | } 22 | -------------------------------------------------------------------------------- /contracts/credit-manager/src/vault/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{ 2 | enter::*, exit::*, exit_unlocked::*, liquidate_vault::*, request_unlock::*, utils::*, 3 | }; 4 | 5 | mod enter; 6 | mod exit; 7 | mod exit_unlocked; 8 | mod liquidate_vault; 9 | mod request_unlock; 10 | mod utils; 11 | -------------------------------------------------------------------------------- /contracts/credit-manager/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/credit-manager/tests/tests/files/Rover - Dynamic LB & CF test cases v1.1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/credit-manager/tests/tests/files/Rover - Dynamic LB & CF test cases v1.1.xlsx -------------------------------------------------------------------------------- /contracts/health/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::health::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/health/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod compute; 2 | pub mod contract; 3 | pub mod migrations; 4 | pub mod querier; 5 | pub mod state; 6 | pub mod update_config; 7 | -------------------------------------------------------------------------------- /contracts/health/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/health/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_types::health::HealthResult; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "2.0.0"; 8 | 9 | pub fn migrate(deps: DepsMut) -> HealthResult { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/health/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Addr; 2 | use cw_storage_plus::Item; 3 | use mars_owner::Owner; 4 | 5 | pub const OWNER: Owner = Owner::new("owner"); 6 | pub const CREDIT_MANAGER: Item = Item::new("credit_manager"); 7 | -------------------------------------------------------------------------------- /contracts/health/src/update_config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, MessageInfo, Response}; 2 | use mars_types::health::HealthResult; 3 | 4 | use crate::state::{CREDIT_MANAGER, OWNER}; 5 | 6 | pub fn update_config( 7 | deps: DepsMut, 8 | info: MessageInfo, 9 | credit_manager: String, 10 | ) -> HealthResult { 11 | OWNER.assert_owner(deps.storage, &info.sender)?; 12 | 13 | let validated = deps.api.addr_validate(&credit_manager)?; 14 | CREDIT_MANAGER.save(deps.storage, &validated)?; 15 | 16 | Ok(Response::new() 17 | .add_attribute("action", "update_config") 18 | .add_attribute("key", "credit_manager_addr") 19 | .add_attribute("value", credit_manager)) 20 | } 21 | -------------------------------------------------------------------------------- /contracts/health/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/health/tests/tests/helpers/defaults.rs: -------------------------------------------------------------------------------- 1 | use std::str::FromStr; 2 | 3 | use cosmwasm_std::Decimal; 4 | use mars_types::params::{ 5 | AssetParamsUnchecked, CmSettings, HlsParamsUnchecked, LiquidationBonus, RedBankSettings, 6 | }; 7 | 8 | pub fn default_asset_params(denom: &str) -> AssetParamsUnchecked { 9 | AssetParamsUnchecked { 10 | denom: denom.to_string(), 11 | credit_manager: CmSettings { 12 | whitelisted: true, 13 | hls: Some(HlsParamsUnchecked { 14 | max_loan_to_value: Decimal::from_str("0.8").unwrap(), 15 | liquidation_threshold: Decimal::from_str("0.9").unwrap(), 16 | correlations: vec![], 17 | }), 18 | }, 19 | red_bank: RedBankSettings { 20 | deposit_enabled: false, 21 | borrow_enabled: false, 22 | }, 23 | max_loan_to_value: Decimal::from_str("0.4523").unwrap(), 24 | liquidation_threshold: Decimal::from_str("0.5").unwrap(), 25 | liquidation_bonus: LiquidationBonus { 26 | starting_lb: Decimal::percent(1u64), 27 | slope: Decimal::from_atomics(2u128, 0).unwrap(), 28 | min_lb: Decimal::percent(2u64), 29 | max_lb: Decimal::percent(10u64), 30 | }, 31 | protocol_liquidation_fee: Decimal::percent(2u64), 32 | deposit_cap: Default::default(), 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /contracts/health/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{defaults::*, mock_contracts::*, mock_env::*, mock_env_builder::*}; 2 | 3 | mod defaults; 4 | mod mock_contracts; 5 | mod mock_env; 6 | mod mock_env_builder; 7 | -------------------------------------------------------------------------------- /contracts/health/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_health_state; 4 | mod test_health_values; 5 | mod test_hls; 6 | mod test_instantiate; 7 | mod test_liquidation_pricing; 8 | mod test_migration_v2; 9 | mod test_update_config; 10 | -------------------------------------------------------------------------------- /contracts/incentives/README.md: -------------------------------------------------------------------------------- 1 | # Mars Incentives 2 | 3 | A smart contract that manages both MARS incentives for redbank deposits, and Astroport LP incentives for staked LP positions 4 | 5 | ## Astroport 6 | 7 | Astroport requires users to 'stake' their Lp positions in the Astroport incentives 8 | contract in order to accrue externally added incentives for that LP position. 9 | 10 | Mars facilitates the ability for a credit account to stake into this contract via the Mars incentives contract, in order 11 | to accrue these additional rewards whilst using that lp position as collateral in 12 | that credit account. 13 | 14 | The Mars Incentives contract pools all LP positions together in one staked position in Astroport, managing the accounting for each individual user internally. 15 | 16 | Rewards are also pooled, and are distributed to the user based on their LP share amount since their last claim. 17 | Because of this, we must claim rewards for a user each time they update their staked LP balance 18 | 19 | This functionality is exposed through the stake, unstake, and claim actions via credit manager 20 | 21 | ### Stake 22 | ![stake](files/stake.png) 23 | 24 | ### Unstake 25 | ![unstake](files/unstake.png) 26 | 27 | ### Claim Rewards 28 | ![claim rewards](files/claim.png) 29 | 30 | ## License 31 | 32 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 33 | -------------------------------------------------------------------------------- /contracts/incentives/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::incentives::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/incentives/files/claim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/incentives/files/claim.png -------------------------------------------------------------------------------- /contracts/incentives/files/stake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/incentives/files/stake.png -------------------------------------------------------------------------------- /contracts/incentives/files/unstake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/incentives/files/unstake.png -------------------------------------------------------------------------------- /contracts/incentives/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod astro_incentives; 2 | pub mod config; 3 | pub mod contract; 4 | mod error; 5 | pub mod helpers; 6 | pub mod mars_incentives; 7 | pub mod migrations; 8 | pub mod query; 9 | pub mod state; 10 | 11 | pub use error::ContractError; 12 | -------------------------------------------------------------------------------- /contracts/incentives/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/incentives/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/incentives/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_admin; 4 | mod test_balance_change; 5 | mod test_claim_astro_lp_rewards; 6 | mod test_claim_rewards; 7 | mod test_indices_usage; 8 | mod test_migration_v2; 9 | mod test_quering; 10 | mod test_set_asset_incentive; 11 | mod test_update_owner; 12 | mod test_whitelist; 13 | -------------------------------------------------------------------------------- /contracts/mock-astroport-incentives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-astroport-incentives" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | astroport-v5 = { workspace = true } 23 | cosmwasm-schema = { workspace = true } 24 | cosmwasm-std = { workspace = true } 25 | cw-storage-plus = { workspace = true } 26 | cw-utils = { workspace = true } 27 | mars-types = { workspace = true } 28 | thiserror = { workspace = true } -------------------------------------------------------------------------------- /contracts/mock-astroport-incentives/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod execute; 3 | pub mod query; 4 | pub mod state; 5 | -------------------------------------------------------------------------------- /contracts/mock-astroport-incentives/src/state.rs: -------------------------------------------------------------------------------- 1 | use astroport_v5::incentives::IncentivesSchedule; 2 | use cosmwasm_std::Uint128; 3 | use cw_storage_plus::Map; 4 | 5 | // Storage for our mock incentive schedules. Key is lp_denom, reward_asset_denom 6 | pub const INCENTIVE_SCHEDULES: Map<(&str, &str), IncentivesSchedule> = 7 | Map::new("astro_incentive_schedules"); 8 | pub const ASTRO_LP_INCENTIVE_DEPOSITS: Map<(&str, &str), Uint128> = 9 | Map::new("astro_incentive_lp_deposits"); 10 | pub const LAST_CLAIMED_HEIGHT: Map<(&str, &str), u64> = 11 | Map::new("astro_incentive_last_claimed_height"); 12 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-credit-manager" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | mars-types = { workspace = true } 26 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use cosmwasm_std::Empty; 3 | use mars_mock_credit_manager::msg::ExecuteMsg; 4 | use mars_types::credit_manager::QueryMsg; 5 | 6 | fn main() { 7 | write_api! { 8 | instantiate: Empty, 9 | query: QueryMsg, 10 | execute: ExecuteMsg, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/src/execute.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response, StdResult}; 2 | use mars_types::{credit_manager::Positions, health::AccountKind}; 3 | 4 | use crate::state::{ACCOUNT_KINDS, POSITION_RESPONSES}; 5 | 6 | pub fn set_position_response( 7 | deps: DepsMut, 8 | account_id: String, 9 | positions: Positions, 10 | ) -> StdResult { 11 | POSITION_RESPONSES.save(deps.storage, &account_id, &positions)?; 12 | Ok(Response::new()) 13 | } 14 | 15 | pub fn set_account_kind_response( 16 | deps: DepsMut, 17 | account_id: String, 18 | kind: AccountKind, 19 | ) -> StdResult { 20 | ACCOUNT_KINDS.save(deps.storage, &account_id, &kind)?; 21 | Ok(Response::new()) 22 | } 23 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod execute; 3 | pub mod msg; 4 | pub mod query; 5 | pub mod state; 6 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use mars_types::{ 3 | credit_manager::{ConfigResponse, Positions}, 4 | health::AccountKind, 5 | }; 6 | 7 | #[cw_serde] 8 | pub struct InstantiateMsg { 9 | pub config: ConfigResponse, 10 | } 11 | 12 | #[cw_serde] 13 | pub enum ExecuteMsg { 14 | SetPositionsResponse { 15 | account_id: String, 16 | positions: Positions, 17 | }, 18 | SetAccountKindResponse { 19 | account_id: String, 20 | kind: AccountKind, 21 | }, 22 | } 23 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/src/query.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Deps, StdResult}; 2 | use mars_types::{ 3 | credit_manager::{ConfigResponse, Positions}, 4 | health::AccountKind, 5 | }; 6 | 7 | use crate::state::{ACCOUNT_KINDS, CONFIG, POSITION_RESPONSES}; 8 | 9 | pub fn query_positions(deps: Deps, account_id: String) -> StdResult { 10 | POSITION_RESPONSES.load(deps.storage, &account_id) 11 | } 12 | 13 | pub fn query_config(deps: Deps) -> StdResult { 14 | CONFIG.load(deps.storage) 15 | } 16 | 17 | pub fn query_account_kind(deps: Deps, account_id: String) -> StdResult { 18 | Ok(ACCOUNT_KINDS.may_load(deps.storage, &account_id)?.unwrap_or(AccountKind::Default)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/mock-credit-manager/src/state.rs: -------------------------------------------------------------------------------- 1 | use cw_storage_plus::{Item, Map}; 2 | use mars_types::{ 3 | credit_manager::{ConfigResponse, Positions}, 4 | health::AccountKind, 5 | }; 6 | 7 | pub const CONFIG: Item = Item::new("config"); 8 | 9 | pub const POSITION_RESPONSES: Map<&str, Positions> = Map::new("position_responses"); // Map 10 | 11 | pub const ACCOUNT_KINDS: Map<&str, AccountKind> = Map::new("account_types"); 12 | -------------------------------------------------------------------------------- /contracts/mock-health/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-rover-health" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | mars-types = { workspace = true } 26 | -------------------------------------------------------------------------------- /contracts/mock-health/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod msg; 3 | pub mod state; 4 | -------------------------------------------------------------------------------- /contracts/mock-health/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use mars_types::health::{AccountKind, HealthValuesResponse}; 3 | 4 | #[cw_serde] 5 | pub enum ExecuteMsg { 6 | SetHealthResponse { 7 | account_id: String, 8 | kind: AccountKind, 9 | response: HealthValuesResponse, 10 | }, 11 | } 12 | -------------------------------------------------------------------------------- /contracts/mock-health/src/state.rs: -------------------------------------------------------------------------------- 1 | use cw_storage_plus::Map; 2 | use mars_types::health::HealthValuesResponse; 3 | 4 | pub const HEALTH_RESPONSES: Map<(&str, &str), HealthValuesResponse> = Map::new("health_responses"); // Map<(account_id, AccountKind string), HealthResponse> 5 | -------------------------------------------------------------------------------- /contracts/mock-incentives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-incentives" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true } 23 | cw-paginate = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | mars-types = { workspace = true } 26 | -------------------------------------------------------------------------------- /contracts/mock-incentives/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | 3 | pub mod execute; 4 | pub mod query; 5 | pub mod state; 6 | -------------------------------------------------------------------------------- /contracts/mock-incentives/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, Coin, Uint128}; 2 | use cw_storage_plus::Map; 3 | pub const DEFAULT_LIMIT: u32 = 10; 4 | pub const MAX_LIMIT: u32 = 30; 5 | 6 | // Map<(Addr, CmAccountId), Unclaimed Coins> 7 | pub const UNCLAIMED_REWARDS: Map<(Addr, String), Vec> = Map::new("unclaimed_rewards"); 8 | 9 | // Map<(account_id, lp_denom), PendingRewards> 10 | pub const PENDING_ASTRO_REWARDS: Map<(String, String), Vec> = 11 | Map::new("pending_astro_rewards"); 12 | 13 | // Map<(account_id, lp_denom), staked amount> 14 | pub const STAKED_ASTRO_LP_POSITIONS: Map<(String, String), Uint128> = 15 | Map::new("staked_astro_lp_positions"); 16 | -------------------------------------------------------------------------------- /contracts/mock-oracle/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-oracle" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | mars-types = { workspace = true } 26 | -------------------------------------------------------------------------------- /contracts/mock-oracle/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_mock_oracle::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/mock-oracle/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod msg; 3 | pub mod state; 4 | -------------------------------------------------------------------------------- /contracts/mock-oracle/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::{cw_serde, QueryResponses}; 2 | use cosmwasm_std::Decimal; 3 | use mars_types::oracle::ActionKind; 4 | 5 | #[cw_serde] 6 | pub struct CoinPrice { 7 | pub pricing: ActionKind, 8 | pub denom: String, 9 | pub price: Decimal, 10 | } 11 | 12 | #[cw_serde] 13 | pub struct InstantiateMsg { 14 | pub prices: Vec, 15 | } 16 | 17 | #[cw_serde] 18 | pub enum ExecuteMsg { 19 | // Meant to simulate price changes for tests. Not available in prod. 20 | ChangePrice(CoinPrice), 21 | 22 | // Used to remove a price from the store. It can be used to simulate problem with the oracle for example circuit breakers are activated 23 | // for Default pricing. It means that the price is not available and the contract should not allow HF check. 24 | // This message is not available in prod. 25 | RemovePrice { 26 | denom: String, 27 | pricing: ActionKind, 28 | }, 29 | } 30 | 31 | #[cw_serde] 32 | #[derive(QueryResponses)] 33 | pub enum QueryMsg { 34 | #[returns(mars_types::oracle::PriceResponse)] 35 | Price { 36 | denom: String, 37 | kind: Option, 38 | }, 39 | } 40 | -------------------------------------------------------------------------------- /contracts/mock-oracle/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Decimal; 2 | use cw_storage_plus::Map; 3 | 4 | pub const DEFAULT_COIN_PRICE: Map = Map::new("default_coin_price"); 5 | pub const LIQUIDATION_COIN_PRICE: Map = Map::new("liquidation_coin_price"); 6 | -------------------------------------------------------------------------------- /contracts/mock-pyth/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-pyth" 3 | description = "Mocked version of the Pyth oracle contract" 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | license = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | crate-type = ["cdylib", "rlib"] 15 | doctest = false 16 | 17 | [features] 18 | # for quicker tests, cargo test --lib 19 | # for more explicit tests, cargo test --features=backtraces 20 | backtraces = ["cosmwasm-std/backtraces"] 21 | library = [] 22 | 23 | [dependencies] 24 | cosmwasm-std = { workspace = true } 25 | pyth-sdk-cw = { workspace = true } 26 | -------------------------------------------------------------------------------- /contracts/mock-pyth/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | -------------------------------------------------------------------------------- /contracts/mock-red-bank/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-red-bank" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-paginate = { workspace = true } 25 | cw-storage-plus = { workspace = true } 26 | cw-utils = { workspace = true } 27 | mars-types = { workspace = true } 28 | -------------------------------------------------------------------------------- /contracts/mock-red-bank/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use cosmwasm_std::Empty; 3 | use mars_types::red_bank::{ExecuteMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: Empty, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/mock-red-bank/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, StdResult, Storage, Uint128}; 2 | 3 | use crate::state::{COLLATERAL_AMOUNT, COLLATERAL_DENOMS, DEBT_AMOUNT}; 4 | 5 | pub fn load_debt_amount(storage: &dyn Storage, user: &Addr, denom: &str) -> StdResult { 6 | Ok(DEBT_AMOUNT 7 | .may_load(storage, (user.clone(), denom.to_string()))? 8 | .unwrap_or_else(Uint128::zero)) 9 | } 10 | 11 | pub fn load_collateral_amount( 12 | storage: &dyn Storage, 13 | addr: &str, 14 | account_id: &str, 15 | denom: &str, 16 | ) -> StdResult { 17 | Ok(COLLATERAL_AMOUNT 18 | .may_load(storage, (addr.to_string(), account_id.to_string(), denom.to_string()))? 19 | .unwrap_or_else(Uint128::zero)) 20 | } 21 | 22 | pub fn load_collateral_denoms( 23 | storage: &dyn Storage, 24 | addr: &str, 25 | account_id: &str, 26 | ) -> StdResult> { 27 | Ok(COLLATERAL_DENOMS 28 | .may_load(storage, (addr.to_string(), account_id.to_string()))? 29 | .unwrap_or(vec![])) 30 | } 31 | -------------------------------------------------------------------------------- /contracts/mock-red-bank/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | 3 | pub mod execute; 4 | pub mod helpers; 5 | pub mod query; 6 | pub mod state; 7 | -------------------------------------------------------------------------------- /contracts/mock-red-bank/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, Uint128}; 2 | use cw_storage_plus::Map; 3 | use mars_types::red_bank::Market; 4 | 5 | // Map 6 | pub const MARKETS: Map<&str, Market> = Map::new("markets"); 7 | // Map<(DebtHolder, CoinDenom), AmountOfDebt> 8 | pub const DEBT_AMOUNT: Map<(Addr, String), Uint128> = Map::new("debt_amount"); 9 | // Map<(Addr, CmAccountId, CoinDenom), AmountOfCollateral> 10 | pub const COLLATERAL_AMOUNT: Map<(String, String, String), Uint128> = Map::new("collateral_amount"); 11 | // Map<(Addr, CmAccountId), Vec> : Used for tracking total denoms user deposited 12 | pub const COLLATERAL_DENOMS: Map<(String, String), Vec> = Map::new("collateral_denoms"); 13 | -------------------------------------------------------------------------------- /contracts/mock-vault/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-mock-vault" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | cw-utils = { workspace = true } 26 | cw-vault-standard = { workspace = true } 27 | mars-types = { workspace = true } 28 | thiserror = { workspace = true } 29 | -------------------------------------------------------------------------------- /contracts/mock-vault/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_mock_vault::msg::InstantiateMsg; 3 | use mars_types::adapters::vault::{ExecuteMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/mock-vault/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{CheckedMultiplyRatioError, StdError}; 2 | use mars_types::adapters::oracle::OracleError; 3 | use thiserror::Error; 4 | 5 | pub type ContractResult = Result; 6 | 7 | #[derive(Error, Debug, PartialEq)] 8 | pub enum ContractError { 9 | #[error("{0}")] 10 | Std(#[from] StdError), 11 | 12 | #[error("{0}")] 13 | Oracle(#[from] OracleError), 14 | 15 | #[error("{0}")] 16 | CheckedMultiply(#[from] CheckedMultiplyRatioError), 17 | 18 | #[error("Lockup position {0} not found")] 19 | LockupPositionNotFound(u64), 20 | 21 | #[error("Attempting to deposit, but did not sent any tokens")] 22 | NoCoinsSent, 23 | 24 | #[error("This vault is not a locking vault, action not allowed")] 25 | NotLockingVault, 26 | 27 | #[error("Not allowed to perform action")] 28 | Unauthorized, 29 | 30 | #[error("There is more time left on the lock period")] 31 | UnlockNotReady, 32 | 33 | #[error("You must request an unlock first")] 34 | UnlockRequired, 35 | 36 | #[error("Attempting to deposit incorrect denom")] 37 | WrongDenomSent, 38 | 39 | #[error("Vault token not sent")] 40 | VaultTokenNotSent, 41 | } 42 | -------------------------------------------------------------------------------- /contracts/mock-vault/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod deposit; 3 | pub mod error; 4 | pub mod msg; 5 | pub mod query; 6 | pub mod state; 7 | pub mod unlock; 8 | pub mod withdraw; 9 | -------------------------------------------------------------------------------- /contracts/mock-vault/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cw_utils::Duration; 3 | use mars_types::adapters::oracle::OracleUnchecked; 4 | 5 | // Remaining messages in cw-vault-standard 6 | #[cw_serde] 7 | pub struct InstantiateMsg { 8 | /// Denom for vault token 9 | pub vault_token_denom: String, 10 | /// Denom required for entry. Also denom received on withdraw. 11 | pub base_token_denom: String, 12 | /// Duration of unlock period 13 | pub lockup: Option, 14 | pub oracle: OracleUnchecked, 15 | /// Used to simulate a compromised vault that attempts reentrancy 16 | pub is_evil: Option, 17 | } 18 | -------------------------------------------------------------------------------- /contracts/mock-vault/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, Coin, Uint128}; 2 | use cw_storage_plus::{Item, Map}; 3 | use cw_utils::Duration; 4 | use cw_vault_standard::extensions::lockup::UnlockingPosition; 5 | use mars_types::adapters::oracle::Oracle; 6 | 7 | pub const VAULT_TOKEN_DENOM: Item = Item::new("vault_token_denom"); 8 | pub const TOTAL_VAULT_SHARES: Item = Item::new("total_vault_shares"); 9 | pub const LOCKUP_TIME: Item> = Item::new("lockup_time"); 10 | pub const ORACLE: Item = Item::new("oracle"); 11 | 12 | pub const COIN_BALANCE: Item = Item::new("underlying_coin"); 13 | pub const UNLOCKING_POSITIONS: Map> = Map::new("unlocking_positions"); 14 | pub const NEXT_LOCKUP_ID: Item = Item::new("next_lockup_id"); 15 | 16 | // Used to simulate a compromised vault that attempts reentrancy 17 | // String == Credit account evil vault owns 18 | pub const IS_EVIL: Item> = Item::new("is_evil"); 19 | 20 | // Used for mock LP token minting 21 | pub const CHAIN_BANK: Item = Item::new("chain_bank"); 22 | -------------------------------------------------------------------------------- /contracts/oracle/base/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-oracle-base" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | license = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | doctest = false 14 | 15 | [features] 16 | # for more explicit tests, cargo test --features=backtraces 17 | backtraces = ["cosmwasm-std/backtraces"] 18 | 19 | [dependencies] 20 | cosmwasm-schema = { workspace = true } 21 | cosmwasm-std = { workspace = true } 22 | cw2 = { workspace = true } 23 | cw-storage-plus = { workspace = true } 24 | ica-oracle = { workspace = true } 25 | mars-owner = { workspace = true } 26 | mars-utils = { workspace = true } 27 | mars-types = { workspace = true } 28 | pyth-sdk-cw = { workspace = true } 29 | schemars = { workspace = true } 30 | serde = { workspace = true } 31 | thiserror = { workspace = true } 32 | -------------------------------------------------------------------------------- /contracts/oracle/base/README.md: -------------------------------------------------------------------------------- 1 | # Mars Oracle - Base 2 | 3 | Chain-agnostic logics for the oracle contract. To create an oracle contract specific to a chain, create a `{chain-name}PriceSource` object that implements the `PriceSource` trait, which defines methods relevant for acquiring price data on that chain; then, plug it in to the `OracleBase` type. 4 | 5 | Taking the [Osmosis](https://github.com/osmosis-labs/osmosis) chain for example: 6 | 7 | ```rust 8 | use mars_oracle_base::{OracleBase, PriceSource}; 9 | use osmo_bindings::OsmosisQuery; 10 | 11 | enum OsmosisPriceSource { 12 | // ... 13 | } 14 | 15 | impl PriceSource for OsmosisPriceSource { 16 | // ... 17 | } 18 | 19 | type OsmosisOracle<'a> = OracleBase<'a, OsmosisQuery, OsmosisPriceSource>; 20 | ``` 21 | 22 | ## License 23 | 24 | Contents of this crate are open source under [GNU General Public License v3](../../../LICENSE) or later. 25 | -------------------------------------------------------------------------------- /contracts/oracle/base/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod contract; 2 | mod error; 3 | mod traits; 4 | 5 | pub mod lp_pricing; 6 | pub mod pyth; 7 | pub mod redemption_rate; 8 | 9 | pub use contract::*; 10 | pub use error::*; 11 | pub use traits::*; 12 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/README.md: -------------------------------------------------------------------------------- 1 | # Mars Oracle - Osmosis 2 | 3 | A smart contract that provides prices denominated in `uosmo` for assets used in the protocol. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_oracle_osmosis::OsmosisPriceSourceUnchecked; 3 | use mars_types::oracle::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | execute: ExecuteMsg, 9 | query: QueryMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod helpers; 3 | pub mod migrations; 4 | pub mod msg; 5 | mod price_source; 6 | 7 | pub use price_source::{ 8 | DowntimeDetector, OsmosisPriceSourceChecked, OsmosisPriceSourceUnchecked, Twap, TwapKind, 9 | }; 10 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_oracle_base::ContractError; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "2.0.1"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/src/msg.rs: -------------------------------------------------------------------------------- 1 | use mars_types::oracle; 2 | 3 | use crate::price_source::{OsmosisPriceSourceChecked, OsmosisPriceSourceUnchecked}; 4 | 5 | pub type ExecuteMsg = oracle::ExecuteMsg; 6 | pub type PriceSourceResponse = oracle::PriceSourceResponse; 7 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_admin; 4 | mod test_custom_execute; 5 | mod test_migration_v2; 6 | mod test_price_source_fmt; 7 | mod test_query_price; 8 | mod test_query_price_for_pyth; 9 | mod test_remove_price_source; 10 | mod test_set_price_source; 11 | mod test_update_owner; 12 | -------------------------------------------------------------------------------- /contracts/oracle/osmosis/tests/tests/test_custom_execute.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{testing::mock_env, Empty}; 2 | use mars_oracle_base::ContractError; 3 | use mars_oracle_osmosis::contract::entry; 4 | use mars_testing::mock_info; 5 | use mars_types::oracle::ExecuteMsg; 6 | 7 | use super::helpers; 8 | 9 | #[test] 10 | fn custom_execute() { 11 | let mut deps = helpers::setup_test(); 12 | 13 | let msg = ExecuteMsg::Custom(Empty {}); 14 | let info = mock_info("owner"); 15 | let res_err = entry::execute(deps.as_mut(), mock_env(), info, msg).unwrap_err(); 16 | assert_eq!(res_err, ContractError::MissingCustomExecuteParams {}); 17 | } 18 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/README.md: -------------------------------------------------------------------------------- 1 | # Mars Oracle - Wasm Zone 2 | 3 | A smart contract that provides prices for generic CosmWasm chains. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_oracle_wasm::WasmPriceSourceUnchecked; 3 | use mars_types::oracle::{ 4 | ExecuteMsg, InstantiateMsg, QueryMsg, WasmOracleCustomExecuteMsg, WasmOracleCustomInitParams, 5 | }; 6 | 7 | fn main() { 8 | write_api! { 9 | instantiate: InstantiateMsg, 10 | execute: ExecuteMsg, 11 | query: QueryMsg, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod astroport_twap; 2 | pub mod contract; 3 | pub mod helpers; 4 | pub mod lp_pricing; 5 | pub mod migrations; 6 | mod price_source; 7 | mod state; 8 | 9 | pub use price_source::{ 10 | AstroportTwap, WasmPriceSource, WasmPriceSourceChecked, WasmPriceSourceUnchecked, 11 | }; 12 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_0_0; 2 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/src/migrations/v2_0_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_oracle_base::ContractError; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "1.3.0"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Addr; 2 | use cw_storage_plus::{Item, Map}; 3 | use mars_types::oracle::AstroportTwapSnapshot; 4 | 5 | /// The Astroport Factory contract address 6 | pub const ASTROPORT_FACTORY: Item = Item::new("astroport_factory"); 7 | 8 | /// TWAP snapshots indexed by denom 9 | pub const ASTROPORT_TWAP_SNAPSHOTS: Map<&str, Vec> = Map::new("snapshots"); 10 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_factory.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_factory.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_generator.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_generator.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_maker.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_maker.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_native_coin_registry.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_native_coin_registry.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair_concentrated.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair_concentrated.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair_stable.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_pair_stable.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_router.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_router.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_satellite.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_satellite.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_staking.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_staking.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_token.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_token.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_vesting.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_vesting.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/astroport_whitelist.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/astroport-artifacts/astroport_whitelist.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/astroport-artifacts/version.md: -------------------------------------------------------------------------------- 1 | These artifacts were downloaded from Neutron testnet on 2024-01-22 -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/files/PCL pricing test cases.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/files/PCL pricing test cases.xlsx -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/files/SS pricing test cases.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/files/SS pricing test cases.xlsx -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/stride-artifacts/ica_oracle.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/oracle/wasm/tests/stride-artifacts/ica_oracle.wasm -------------------------------------------------------------------------------- /contracts/oracle/wasm/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod prop_tests; 4 | mod test_migration_v2; 5 | mod test_price_source; 6 | mod test_update_admin; 7 | -------------------------------------------------------------------------------- /contracts/params/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-params" 3 | description = "Contract storing the asset params for Credit Manager and Red Bank." 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | license = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | crate-type = ["cdylib", "rlib"] 15 | doctest = false 16 | 17 | [features] 18 | # for quicker tests, cargo test --lib 19 | # for more explicit tests, cargo test --features=backtraces 20 | backtraces = ["cosmwasm-std/backtraces"] 21 | library = [] 22 | 23 | [dependencies] 24 | astroport-v5 = { workspace = true } 25 | cosmwasm-schema = { workspace = true } 26 | cosmwasm-std = { workspace = true } 27 | cw2 = { workspace = true } 28 | cw-paginate = { workspace = true } 29 | cw-storage-plus = { workspace = true } 30 | mars-interest-rate = { workspace = true } 31 | mars-owner = { workspace = true } 32 | mars-types = { workspace = true } 33 | mars-utils = { workspace = true } 34 | thiserror = { workspace = true } 35 | 36 | [dev-dependencies] 37 | anyhow = { workspace = true } 38 | cw-multi-test = { workspace = true } 39 | mars-testing = { workspace = true } 40 | test-case = { workspace = true } 41 | -------------------------------------------------------------------------------- /contracts/params/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::params::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/params/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DecimalRangeExceeded, StdError}; 2 | use cw2::VersionError; 3 | use mars_owner::OwnerError; 4 | use mars_types::error::MarsError; 5 | use mars_utils::error::ValidationError; 6 | use thiserror::Error; 7 | 8 | pub type ContractResult = Result; 9 | 10 | #[derive(Error, Debug, PartialEq)] 11 | pub enum ContractError { 12 | #[error("{0}")] 13 | Std(#[from] StdError), 14 | 15 | #[error("{0}")] 16 | DecimalRangeExceeded(#[from] DecimalRangeExceeded), 17 | 18 | #[error("{0}")] 19 | Owner(#[from] OwnerError), 20 | 21 | #[error("{0}")] 22 | Validation(#[from] ValidationError), 23 | 24 | #[error("{0}")] 25 | Mars(#[from] MarsError), 26 | 27 | #[error("{0}")] 28 | Version(#[from] VersionError), 29 | } 30 | -------------------------------------------------------------------------------- /contracts/params/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod emergency_powers; 3 | pub mod error; 4 | pub mod execute; 5 | pub mod migrations; 6 | pub mod query; 7 | pub mod state; 8 | -------------------------------------------------------------------------------- /contracts/params/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/params/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | 4 | use crate::{ 5 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 6 | error::ContractError, 7 | }; 8 | 9 | const FROM_VERSION: &str = "2.0.1"; 10 | 11 | pub fn migrate(deps: DepsMut) -> Result { 12 | // make sure we're migrating the correct contract and from the correct version 13 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 14 | 15 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 16 | 17 | Ok(Response::new() 18 | .add_attribute("action", "migrate") 19 | .add_attribute("from_version", FROM_VERSION) 20 | .add_attribute("to_version", CONTRACT_VERSION)) 21 | } 22 | -------------------------------------------------------------------------------- /contracts/params/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, Decimal}; 2 | use cw_storage_plus::{Item, Map}; 3 | use mars_owner::Owner; 4 | use mars_types::params::{AssetParams, VaultConfig}; 5 | 6 | pub const OWNER: Owner = Owner::new("owner"); 7 | pub const ADDRESS_PROVIDER: Item = Item::new("address_provider"); 8 | pub const ASSET_PARAMS: Map<&str, AssetParams> = Map::new("asset_params"); 9 | pub const VAULT_CONFIGS: Map<&Addr, VaultConfig> = Map::new("vault_configs"); 10 | pub const TARGET_HEALTH_FACTOR: Item = Item::new("target_health_factor"); 11 | -------------------------------------------------------------------------------- /contracts/params/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/helpers/assertions.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashSet, hash::Hash}; 2 | 3 | use anyhow::Result as AnyResult; 4 | use cw_multi_test::AppResponse; 5 | use mars_params::error::ContractError; 6 | 7 | pub fn assert_err(res: AnyResult, err: ContractError) { 8 | match res { 9 | Ok(_) => panic!("Result was not an error"), 10 | Err(generic_err) => { 11 | let contract_err: ContractError = generic_err.downcast().unwrap(); 12 | assert_eq!(contract_err, err); 13 | } 14 | } 15 | } 16 | 17 | pub fn assert_contents_equal(vec_a: &[T], vec_b: &[T]) 18 | where 19 | T: Eq + Hash, 20 | { 21 | let set_a: HashSet<_> = vec_a.iter().collect(); 22 | let set_b: HashSet<_> = vec_b.iter().collect(); 23 | 24 | assert!(set_a == set_b) 25 | } 26 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/helpers/contracts.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Empty; 2 | use cw_multi_test::{Contract, ContractWrapper}; 3 | 4 | pub fn mock_params_contract() -> Box> { 5 | let contract = ContractWrapper::new( 6 | mars_params::contract::execute, 7 | mars_params::contract::instantiate, 8 | mars_params::contract::query, 9 | ); 10 | Box::new(contract) 11 | } 12 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{assertions::*, generator::*, mock_env::*}; 2 | 3 | mod assertions; 4 | mod contracts; 5 | mod generator; 6 | mod mock_env; 7 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_all_total_deposits_v2; 4 | mod test_asset_validation; 5 | mod test_deposit_cap; 6 | mod test_emergency_powers; 7 | mod test_migration_v2; 8 | mod test_owner; 9 | mod test_query_all_vault_configs_v2; 10 | mod test_target_health_factor; 11 | mod test_update_asset_params; 12 | mod test_update_config; 13 | mod test_vault_validation; 14 | mod test_vaults; 15 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/test_owner.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Addr; 2 | use mars_owner::{OwnerError, OwnerUpdate}; 3 | use mars_params::error::ContractError::Owner; 4 | 5 | use super::helpers::{assert_err, MockEnv}; 6 | 7 | #[test] 8 | fn owner_set_on_init() { 9 | let mock = MockEnv::new().build().unwrap(); 10 | let owner = mock.query_owner(); 11 | assert_eq!("owner", &owner.to_string()) 12 | } 13 | 14 | #[test] 15 | fn only_owner_can_execute_updates() { 16 | let mut mock = MockEnv::new().build().unwrap(); 17 | let bad_guy = Addr::unchecked("doctor_otto_983"); 18 | let res = mock.update_owner( 19 | &bad_guy, 20 | OwnerUpdate::ProposeNewOwner { 21 | proposed: bad_guy.to_string(), 22 | }, 23 | ); 24 | assert_err(res, Owner(OwnerError::NotOwner {})); 25 | } 26 | 27 | #[test] 28 | fn owner_can_execute_updates() { 29 | let mut mock = MockEnv::new().build().unwrap(); 30 | 31 | let ownership = mock.query_ownership(); 32 | assert_eq!(ownership.emergency_owner, None); 33 | 34 | let em_owner = "miles_morales".to_string(); 35 | mock.update_owner( 36 | &mock.query_owner(), 37 | OwnerUpdate::SetEmergencyOwner { 38 | emergency_owner: em_owner.clone(), 39 | }, 40 | ) 41 | .unwrap(); 42 | 43 | let ownership = mock.query_ownership(); 44 | assert_eq!(ownership.emergency_owner, Some(em_owner)); 45 | } 46 | -------------------------------------------------------------------------------- /contracts/params/tests/tests/test_update_config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Addr; 2 | use mars_owner::OwnerError; 3 | use mars_params::error::ContractError::Owner; 4 | 5 | use super::helpers::{assert_err, MockEnv}; 6 | 7 | #[test] 8 | fn address_provider_set_on_init() { 9 | let mock = MockEnv::new().build().unwrap(); 10 | let config = mock.query_config(); 11 | assert_eq!(config.address_provider, "address_provider".to_string()); 12 | } 13 | 14 | #[test] 15 | fn only_owner_can_update_address_provider() { 16 | let mut mock = MockEnv::new().build().unwrap(); 17 | let bad_guy = Addr::unchecked("doctor_otto_983"); 18 | let res = mock.update_config(&bad_guy, Some("new_address".to_string())); 19 | assert_err(res, Owner(OwnerError::NotOwner {})); 20 | } 21 | 22 | #[test] 23 | fn update_address_provider() { 24 | let mut mock = MockEnv::new().build().unwrap(); 25 | let init_config = mock.query_config(); 26 | 27 | // passing None does not change the address provider 28 | mock.update_config(&mock.query_owner(), None).unwrap(); 29 | let current_config = mock.query_config(); 30 | assert_eq!(current_config.address_provider, init_config.address_provider); 31 | 32 | let new_ap = "address_provider_123".to_string(); 33 | mock.update_config(&mock.query_owner(), Some(new_ap.clone())).unwrap(); 34 | let current_config = mock.query_config(); 35 | assert_eq!(current_config.address_provider, new_ap); 36 | } 37 | -------------------------------------------------------------------------------- /contracts/red-bank/README.md: -------------------------------------------------------------------------------- 1 | # Mars Red Bank 2 | 3 | A smart contract that manages asset deposit, borrowing, and liquidations. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /contracts/red-bank/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::red_bank::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/red-bank/src/config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, MessageInfo, Response}; 2 | use mars_owner::OwnerUpdate; 3 | use mars_types::red_bank::CreateOrUpdateConfig; 4 | use mars_utils::helpers::option_string_to_addr; 5 | 6 | use crate::{ 7 | error::ContractError, 8 | state::{CONFIG, OWNER}, 9 | }; 10 | 11 | pub fn update_owner( 12 | deps: DepsMut, 13 | info: MessageInfo, 14 | update: OwnerUpdate, 15 | ) -> Result { 16 | Ok(OWNER.update(deps, info, update)?) 17 | } 18 | 19 | /// Update config 20 | pub fn update_config( 21 | deps: DepsMut, 22 | info: MessageInfo, 23 | new_config: CreateOrUpdateConfig, 24 | ) -> Result { 25 | OWNER.assert_owner(deps.storage, &info.sender)?; 26 | 27 | let mut config = CONFIG.load(deps.storage)?; 28 | 29 | // Destructuring a struct’s fields into separate variables in order to force 30 | // compile error if we add more params 31 | let CreateOrUpdateConfig { 32 | address_provider, 33 | } = new_config; 34 | 35 | // Update config 36 | config.address_provider = 37 | option_string_to_addr(deps.api, address_provider, config.address_provider)?; 38 | 39 | CONFIG.save(deps.storage, &config)?; 40 | 41 | Ok(Response::new().add_attribute("action", "update_config")) 42 | } 43 | -------------------------------------------------------------------------------- /contracts/red-bank/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Coin, Decimal, QuerierWrapper, StdResult}; 2 | use mars_types::params::{AssetParams, QueryMsg}; 3 | 4 | pub fn query_asset_params( 5 | querier: &QuerierWrapper, 6 | params: impl Into, 7 | denom: impl Into, 8 | ) -> StdResult { 9 | querier.query_wasm_smart( 10 | params.into(), 11 | &QueryMsg::AssetParams { 12 | denom: denom.into(), 13 | }, 14 | ) 15 | } 16 | 17 | pub fn query_target_health_factor( 18 | querier: &QuerierWrapper, 19 | params: impl Into, 20 | ) -> StdResult { 21 | querier.query_wasm_smart(params.into(), &QueryMsg::TargetHealthFactor {}) 22 | } 23 | 24 | pub fn query_total_deposit( 25 | querier: &QuerierWrapper, 26 | params: impl Into, 27 | denom: impl Into, 28 | ) -> StdResult { 29 | querier.query_wasm_smart( 30 | params.into(), 31 | &QueryMsg::TotalDeposit { 32 | denom: denom.into(), 33 | }, 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /contracts/red-bank/src/instantiate.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::set_contract_version; 3 | use mars_owner::OwnerInit::SetInitialOwner; 4 | use mars_types::{ 5 | error::MarsError, 6 | red_bank::{Config, CreateOrUpdateConfig, InstantiateMsg}, 7 | }; 8 | use mars_utils::helpers::{option_string_to_addr, zero_address}; 9 | 10 | use crate::{ 11 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 12 | error::ContractError, 13 | state::{CONFIG, OWNER}, 14 | }; 15 | 16 | pub fn instantiate(deps: DepsMut, msg: InstantiateMsg) -> Result { 17 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 18 | 19 | // Destructuring a struct’s fields into separate variables in order to force 20 | // compile error if we add more params 21 | let CreateOrUpdateConfig { 22 | address_provider, 23 | } = msg.config; 24 | 25 | if address_provider.is_none() { 26 | return Err(MarsError::InstantiateParamsUnavailable {}.into()); 27 | }; 28 | 29 | let config = Config { 30 | address_provider: option_string_to_addr(deps.api, address_provider, zero_address())?, 31 | }; 32 | 33 | CONFIG.save(deps.storage, &config)?; 34 | 35 | OWNER.initialize( 36 | deps.storage, 37 | deps.api, 38 | SetInitialOwner { 39 | owner: msg.owner, 40 | }, 41 | )?; 42 | 43 | Ok(Response::default()) 44 | } 45 | -------------------------------------------------------------------------------- /contracts/red-bank/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod asset; 2 | pub mod borrow; 3 | pub mod collateral; 4 | pub mod config; 5 | #[cfg(not(feature = "library"))] 6 | pub mod contract; 7 | pub mod deposit; 8 | pub mod error; 9 | pub mod health; 10 | pub mod instantiate; 11 | pub mod interest_rates; 12 | pub mod liquidate; 13 | pub mod migrations; 14 | pub mod query; 15 | pub mod repay; 16 | pub mod state; 17 | pub mod user; 18 | pub mod withdraw; 19 | 20 | pub mod helpers; 21 | -------------------------------------------------------------------------------- /contracts/red-bank/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/red-bank/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | 4 | use crate::{ 5 | contract::{CONTRACT_NAME, CONTRACT_VERSION}, 6 | error::ContractError, 7 | }; 8 | 9 | const FROM_VERSION: &str = "2.0.1"; 10 | 11 | pub mod v1_state { 12 | use cosmwasm_std::{Addr, DepsMut, Uint128}; 13 | use cw_storage_plus::Map; 14 | 15 | pub const UNCOLLATERALIZED_LOAN_LIMITS: Map<(&Addr, &str), Uint128> = Map::new("limits"); 16 | 17 | /// Clear old state so we can re-use the keys 18 | pub fn clear_state(deps: &mut DepsMut) { 19 | UNCOLLATERALIZED_LOAN_LIMITS.clear(deps.storage); 20 | } 21 | } 22 | 23 | pub fn migrate(mut deps: DepsMut) -> Result { 24 | // Make sure we're migrating the correct contract and from the correct version 25 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 26 | 27 | // Clear old state 28 | v1_state::clear_state(&mut deps); 29 | 30 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 31 | 32 | Ok(Response::new() 33 | .add_attribute("action", "migrate") 34 | .add_attribute("from_version", FROM_VERSION) 35 | .add_attribute("to_version", CONTRACT_VERSION)) 36 | } 37 | -------------------------------------------------------------------------------- /contracts/red-bank/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Addr; 2 | use cw_storage_plus::{Item, Map}; 3 | use mars_owner::Owner; 4 | use mars_types::{ 5 | keys::UserIdKey, 6 | red_bank::{Collateral, Config, Debt, Market}, 7 | }; 8 | use mars_utils::guard::Guard; 9 | 10 | pub const OWNER: Owner = Owner::new("owner"); 11 | pub const CONFIG: Item> = Item::new("config"); 12 | pub const MARKETS: Map<&str, Market> = Map::new("markets"); 13 | pub const COLLATERALS: Map<(&UserIdKey, &str), Collateral> = Map::new("colls"); 14 | pub const DEBTS: Map<(&Addr, &str), Debt> = Map::new("debts"); 15 | 16 | /// Used to mark the contract as locked during migrations 17 | pub const MIGRATION_GUARD: Guard = Guard::new("guard"); 18 | -------------------------------------------------------------------------------- /contracts/red-bank/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/red-bank/tests/files/Red Bank - Dynamic LB & CF test cases v1.1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/red-bank/tests/files/Red Bank - Dynamic LB & CF test cases v1.1.xlsx -------------------------------------------------------------------------------- /contracts/red-bank/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_admin; 4 | mod test_borrow; 5 | mod test_credit_accounts; 6 | mod test_deposit; 7 | mod test_health; 8 | mod test_inflated_collateral; 9 | mod test_liquidate; 10 | mod test_migration_v2; 11 | mod test_misc; 12 | mod test_payment; 13 | mod test_query; 14 | mod test_update_owner; 15 | mod test_withdraw; 16 | -------------------------------------------------------------------------------- /contracts/rewards-collector/README.md: -------------------------------------------------------------------------------- 1 | # Mars Rewards Collector - Base 2 | 3 | Chain-agnostic logics for the rewards collector contract. To create an oracle contract specific to a chain, create a `{chain-name}Route` object that implements and `Route` trait, which defines methods relevant for swapping assets on that chain; then plugin it into the `CollectorBase` type. 4 | 5 | Taking the [Osmosis](https://github.com/osmosis-labs/osmosis) chain for example: 6 | 7 | ```rust 8 | use mars_rewards_collector_base::{CollectorBase, Route}; 9 | use osmo_bindings::{OsmosisMsg, OsmosisQuery, Step}; 10 | 11 | // the route is an array of `Step`s 12 | struct OsmosisRoute(pub Vec); 13 | 14 | impl Route for OsmosisRoute { 15 | // ... 16 | } 17 | 18 | pub type OsmosisCollector<'a> = CollectorBase<'a, OsmosisRoute, OsmosisMsg, OsmosisQuery>; 19 | ``` 20 | 21 | ## License 22 | 23 | Contents of this crate are open source under [GNU General Public License v3](../../../LICENSE) or later. 24 | -------------------------------------------------------------------------------- /contracts/rewards-collector/base/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-rewards-collector-base" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | license = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | doctest = false 15 | 16 | [features] 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | 20 | [dependencies] 21 | cosmwasm-schema = { workspace = true } 22 | cosmwasm-std = { workspace = true, features = ["stargate"] } 23 | cw2 = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | mars-owner = { workspace = true } 26 | mars-types = { workspace = true } 27 | mars-utils = { workspace = true } 28 | schemars = { workspace = true } 29 | serde = { workspace = true } 30 | thiserror = { workspace = true } 31 | -------------------------------------------------------------------------------- /contracts/rewards-collector/base/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/rewards-collector/base/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | mod error; 3 | mod helpers; 4 | mod traits; 5 | 6 | pub use error::*; 7 | pub use traits::*; 8 | -------------------------------------------------------------------------------- /contracts/rewards-collector/neutron/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-rewards-collector-neutron" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | license = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | doctest = false 15 | 16 | [features] 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true, features = ["stargate"] } 23 | cw2 = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | cosmwasm-schema = { workspace = true } 26 | mars-rewards-collector-base = { workspace = true } 27 | mars-types = { workspace = true } 28 | neutron-sdk = { workspace = true } 29 | 30 | [dev-dependencies] 31 | mars-testing = { workspace = true } 32 | -------------------------------------------------------------------------------- /contracts/rewards-collector/neutron/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_0_0; 2 | -------------------------------------------------------------------------------- /contracts/rewards-collector/neutron/src/migrations/v2_0_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_rewards_collector_base::ContractError; 4 | 5 | use crate::entry::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "1.2.0"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/rewards-collector/neutron/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/rewards-collector/neutron/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod test_migration_v2; 2 | -------------------------------------------------------------------------------- /contracts/rewards-collector/osmosis/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-rewards-collector-osmosis" 3 | version = "2.1.1" 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | license = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | doctest = false 15 | 16 | [features] 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true, features = ["stargate"] } 24 | cw2 = { workspace = true } 25 | cw-storage-plus = { workspace = true } 26 | mars-owner = { workspace = true } 27 | mars-rewards-collector-base = { workspace = true } 28 | mars-types = { workspace = true } 29 | 30 | [dev-dependencies] 31 | mars-osmosis = { workspace = true } 32 | mars-owner = { workspace = true } 33 | mars-testing = { workspace = true } 34 | mars-utils = { workspace = true } 35 | osmosis-std = { workspace = true } 36 | serde = { workspace = true } 37 | test-case = { workspace = true } 38 | -------------------------------------------------------------------------------- /contracts/rewards-collector/osmosis/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | pub mod v2_1_1; 3 | -------------------------------------------------------------------------------- /contracts/rewards-collector/osmosis/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_rewards_collector_base::ContractError; 4 | 5 | use crate::entry::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "2.0.1"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/rewards-collector/osmosis/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/rewards-collector/osmosis/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_admin; 4 | mod test_distribute_rewards; 5 | mod test_migration_v2_1_0_to_v2_1_1; 6 | mod test_swap; 7 | mod test_update_owner; 8 | mod test_withdraw; 9 | -------------------------------------------------------------------------------- /contracts/swapper/README.md: -------------------------------------------------------------------------------- 1 | # Mars Swapper 2 | 3 | `mars-swapper-base` contains chain-agnostic logics for the swapper contract. Each chain specific implementation should implement its own route struct that should implement the `mars_swapper_base::Route` trait and then use the `mars_swapper_base::SwapBase` to implement the entry point functions. See `./osmosis/src/contract.rs` for an example. Each chain specific swapper will thus implement the same API. 4 | 5 | The swapper contracts should NEVER hold any funds and any funds sent to the contract except as part of executing the `SwapExactIn` message can be stolen by an attacker. See [Oak Audit 2023-08-01](https://github.com/oak-security/audit-reports/blob/master/Mars/2023-08-01%20Audit%20Report%20-%20Mars%20Red%20Bank%20Updates%20v1.0.pdf) issue 14. 6 | 7 | ## Mars Swapper Mock 8 | 9 | Mock swapper contains a mock swapper contract to be used for testing purposes only. It only implements `ExecuteMsg::SwapExactIn` and `QueryMsg::EstimateExactInSwap`. When calling `ExecuteMsg::SwapExactIn` `denom_out` must be `uosmo` and the resulting amount will always be `1337uosmo`. The contract MUST be prefunded with this amount. 10 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_swapper_astroport::{config::AstroportConfig, route::AstroportRoute}; 3 | use mars_types::swapper::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | execute: ExecuteMsg, 9 | query: QueryMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/src/config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::Api; 3 | use mars_swapper_base::{Config, ContractResult}; 4 | 5 | #[cw_serde] 6 | pub struct AstroportConfig { 7 | /// The astroport router contract address 8 | pub router: String, 9 | /// The astroport factory contract address 10 | pub factory: String, 11 | /// The mars wasm oracle contract address 12 | pub oracle: String, 13 | } 14 | 15 | impl Config for AstroportConfig { 16 | fn validate(&self, api: &dyn Api) -> ContractResult<()> { 17 | api.addr_validate(&self.router)?; 18 | api.addr_validate(&self.factory)?; 19 | api.addr_validate(&self.oracle)?; 20 | 21 | Ok(()) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashSet, hash::Hash}; 2 | 3 | /// Build a hashset from array data 4 | pub(crate) fn hashset(data: &[T]) -> HashSet { 5 | data.iter().cloned().collect() 6 | } 7 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod config; 2 | pub mod contract; 3 | pub mod helpers; 4 | pub mod migrations; 5 | pub mod route; 6 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_0_0; 2 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/src/migrations/v2_0_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_swapper_base::ContractError; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "1.2.0"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod test_config; 2 | mod test_migration_v2; 3 | mod test_queries; 4 | mod test_routes; 5 | mod test_swap; 6 | mod test_transfer_result; 7 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/tests/tests/test_queries.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::coin; 2 | use cw_it::{test_tube::Account, traits::CwItRunner}; 3 | use mars_testing::{astroport_swapper::AstroportSwapperRobot, test_runner::get_test_runner}; 4 | 5 | #[test] 6 | fn query_owner() { 7 | let owned_runner = get_test_runner(); 8 | let runner = owned_runner.as_ref(); 9 | let admin = runner.init_account(&[coin(1000000000000, "uosmo")]).unwrap(); 10 | let robot = AstroportSwapperRobot::new_with_local(&runner, &admin); 11 | 12 | let owner = robot.query_owner().unwrap(); 13 | 14 | assert_eq!(owner, admin.address()); 15 | } 16 | -------------------------------------------------------------------------------- /contracts/swapper/astroport/tests/tests/test_transfer_result.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{coin, Addr}; 2 | use cw_it::{ 3 | test_tube::{Account, Module, Wasm}, 4 | traits::CwItRunner, 5 | }; 6 | use mars_swapper_astroport::{config::AstroportConfig, route::AstroportRoute}; 7 | use mars_testing::{astroport_swapper::AstroportSwapperRobot, test_runner::get_test_runner}; 8 | 9 | #[test] 10 | fn transfer_result_unauthorized() { 11 | let owned_runner = get_test_runner(); 12 | let runner = owned_runner.as_ref(); 13 | let admin = runner.init_account(&[coin(1000000000000, "uosmo")]).unwrap(); 14 | let robot = AstroportSwapperRobot::new_with_local(&runner, &admin); 15 | let denom_in = "uosmo".to_string(); 16 | let denom_out = "usd".to_string(); 17 | 18 | let msg = mars_types::swapper::ExecuteMsg::::TransferResult { 19 | recipient: Addr::unchecked(admin.address()), 20 | denom_in, 21 | denom_out, 22 | }; 23 | 24 | let wasm = Wasm::new(&runner); 25 | assert!(wasm 26 | .execute(&robot.swapper, &msg, &[], &admin) 27 | .unwrap_err() 28 | .to_string() 29 | .contains("is not authorized")); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/swapper/base/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-swapper-base" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | doctest = false 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw2 = { workspace = true } 25 | cw-paginate = { workspace = true } 26 | cw-storage-plus = { workspace = true } 27 | mars-owner = { workspace = true } 28 | mars-types = { workspace = true } 29 | schemars = { workspace = true } 30 | serde = { workspace = true } 31 | thiserror = { workspace = true } 32 | -------------------------------------------------------------------------------- /contracts/swapper/base/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use cosmwasm_std::Empty; 3 | use mars_types::swapper::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | query: QueryMsg, 9 | execute: ExecuteMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/swapper/base/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod contract; 2 | mod error; 3 | mod traits; 4 | 5 | pub use contract::*; 6 | pub use error::*; 7 | pub use traits::*; 8 | -------------------------------------------------------------------------------- /contracts/swapper/mock/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-swapper-mock" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | library = [] 21 | 22 | [dependencies] 23 | cosmwasm-std = { workspace = true } 24 | mars-types = { workspace = true } 25 | 26 | [dev-dependencies] 27 | anyhow = { workspace = true } 28 | cw-multi-test = { workspace = true } 29 | -------------------------------------------------------------------------------- /contracts/swapper/mock/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-swapper-osmosis" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | library = [] 21 | 22 | [dependencies] 23 | cosmwasm-schema = { workspace = true } 24 | cosmwasm-std = { workspace = true } 25 | cw2 = { workspace = true } 26 | cw-storage-plus = { workspace = true } 27 | mars-osmosis = { workspace = true } 28 | mars-owner = { workspace = true } 29 | mars-swapper-base = { workspace = true } 30 | mars-types = { workspace = true } 31 | osmosis-std = { workspace = true } 32 | 33 | [dev-dependencies] 34 | anyhow = { workspace = true } 35 | cw-it = { workspace = true, features = ["osmosis-test-tube"] } 36 | mars-testing = { workspace = true } 37 | serde = { workspace = true } 38 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_swapper_osmosis::{config::OsmosisConfig, route::OsmosisRoute}; 3 | use mars_types::swapper::{ExecuteMsg, InstantiateMsg, QueryMsg}; 4 | 5 | fn main() { 6 | write_api! { 7 | instantiate: InstantiateMsg, 8 | execute: ExecuteMsg, 9 | query: QueryMsg, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/src/config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::Api; 3 | use mars_swapper_base::{Config, ContractResult}; 4 | 5 | #[cw_serde] 6 | pub struct OsmosisConfig {} 7 | 8 | impl Config for OsmosisConfig { 9 | fn validate(&self, _api: &dyn Api) -> ContractResult<()> { 10 | Ok(()) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashSet, hash::Hash}; 2 | 3 | /// Build a hashset from array data 4 | pub(crate) fn hashset(data: &[T]) -> HashSet { 5 | data.iter().cloned().collect() 6 | } 7 | 8 | #[cfg(test)] 9 | mod tests { 10 | use super::*; 11 | 12 | #[test] 13 | fn test_hashset() { 14 | let data = vec![1, 2, 3, 4, 5]; 15 | let set = hashset(&data); 16 | assert_eq!(set.len(), 5); 17 | assert!(set.contains(&1)); 18 | assert!(set.contains(&2)); 19 | assert!(set.contains(&3)); 20 | assert!(set.contains(&4)); 21 | assert!(set.contains(&5)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod config; 2 | pub mod contract; 3 | pub mod helpers; 4 | pub mod migrations; 5 | pub mod route; 6 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_swapper_base::ContractError; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "2.0.3"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/swapper/osmosis/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_enumerate_routes; 4 | mod test_estimate; 5 | mod test_instantiate; 6 | mod test_migration_v2; 7 | mod test_set_route; 8 | mod test_swap; 9 | mod test_update_admin; 10 | -------------------------------------------------------------------------------- /contracts/v2-zapper/astroport/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-zapper-astroport" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | apollo-cw-asset = { workspace = true } 23 | apollo-utils = { workspace = true } 24 | astroport-v5 = { workspace = true } 25 | cosmwasm-std = { workspace = true } 26 | cw2 = { workspace = true } 27 | cw-dex = { workspace = true } 28 | mars-types = { workspace = true } 29 | mars-zapper-base = { workspace = true } 30 | 31 | [dev-dependencies] 32 | anyhow = { workspace = true } 33 | cw-it = { workspace = true, features = ["astroport", "astroport-multi-test"] } 34 | mars-oracle-wasm = { workspace = true } 35 | mars-testing = { workspace = true, features = ["astroport"] } 36 | test-case = { workspace = true } 37 | -------------------------------------------------------------------------------- /contracts/v2-zapper/astroport/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod lp_pool; 3 | -------------------------------------------------------------------------------- /contracts/v2-zapper/base/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-zapper-base" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw2 = { workspace = true } 25 | cw-dex = { workspace = true } 26 | cw-utils = { workspace = true } 27 | mars-types = { workspace = true } 28 | schemars = { workspace = true } 29 | serde = { workspace = true } 30 | thiserror = { workspace = true } 31 | -------------------------------------------------------------------------------- /contracts/v2-zapper/base/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::zapper::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/v2-zapper/base/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{OverflowError, StdError}; 2 | use cw_dex::CwDexError; 3 | use cw_utils::PaymentError; 4 | use thiserror::Error; 5 | 6 | #[derive(Error, Debug, PartialEq)] 7 | pub enum ContractError { 8 | #[error("{0}")] 9 | Std(#[from] StdError), 10 | 11 | #[error("{0}")] 12 | Overflow(#[from] OverflowError), 13 | 14 | #[error("{0}")] 15 | PaymentError(#[from] PaymentError), 16 | 17 | #[error("{0}")] 18 | CwDexError(#[from] CwDexError), 19 | 20 | #[error("Unauthorized")] 21 | Unauthorized {}, 22 | 23 | #[error("{0}")] 24 | Version(#[from] cw2::VersionError), 25 | } 26 | -------------------------------------------------------------------------------- /contracts/v2-zapper/base/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod contract; 2 | mod error; 3 | mod traits; 4 | 5 | pub use contract::*; 6 | pub use error::*; 7 | pub use traits::*; 8 | -------------------------------------------------------------------------------- /contracts/v2-zapper/base/src/traits.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Deps; 2 | use cw_dex::{traits::Pool, CwDexError}; 3 | 4 | pub trait LpPool { 5 | /// Returns the matching pool given a LP token. 6 | /// 7 | /// https://github.com/apollodao/cw-dex uses cargo feature flags for chain specific implementation. 8 | fn get_pool_for_lp_token(deps: Deps, lp_token_denom: &str) 9 | -> Result, CwDexError>; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-zapper-mock" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | cw-utils = { workspace = true } 26 | mars-types = { workspace = true } 27 | thiserror = { workspace = true } 28 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_types::zapper::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | query: QueryMsg, 8 | execute: ExecuteMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{CheckedMultiplyRatioError, StdError}; 2 | use cw_utils::PaymentError; 3 | use mars_types::adapters::oracle::OracleError; 4 | use thiserror::Error; 5 | 6 | pub type ContractResult = Result; 7 | 8 | #[derive(Error, Debug, PartialEq)] 9 | pub enum ContractError { 10 | #[error("{0}")] 11 | Std(#[from] StdError), 12 | 13 | #[error("{0}")] 14 | OracleError(#[from] OracleError), 15 | 16 | #[error("{0}")] 17 | CheckedMultiply(#[from] CheckedMultiplyRatioError), 18 | 19 | #[error("Required minimum received was not met")] 20 | ReceivedBelowMinimum, 21 | 22 | #[error("Could not find coin trying to access")] 23 | CoinNotFound, 24 | 25 | #[error("{0}")] 26 | RequirementsNotMet(String), 27 | 28 | #[error("{0}")] 29 | PaymentError(#[from] PaymentError), 30 | } 31 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod error; 3 | pub mod execute; 4 | pub mod msg; 5 | pub mod query; 6 | pub mod state; 7 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/src/msg.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use mars_types::adapters::oracle::OracleUnchecked; 3 | 4 | #[cw_serde] 5 | pub struct LpConfig { 6 | pub lp_token_denom: String, 7 | pub lp_pair_denoms: (String, String), 8 | } 9 | 10 | #[cw_serde] 11 | pub struct InstantiateMsg { 12 | pub oracle: OracleUnchecked, 13 | pub lp_configs: Vec, 14 | } 15 | -------------------------------------------------------------------------------- /contracts/v2-zapper/mock/src/state.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Uint128; 2 | use cw_storage_plus::{Item, Map}; 3 | use mars_types::adapters::oracle::Oracle; 4 | 5 | pub const ORACLE: Item = Item::new("oracle"); 6 | 7 | pub const LP_TOKEN_SUPPLY: Map<&str, Uint128> = Map::new("lp_token_supply"); // lp token denom -> total lp token supply 8 | pub const COIN_CONFIG: Map<&str, Vec> = Map::new("coin_config"); // lp token denom -> Vec 9 | pub const COIN_BALANCES: Map<(&str, &str), Uint128> = Map::new("coin_balances"); // (lp token denom, underlying) -> amount 10 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-zapper-osmosis" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | license = { workspace = true } 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | homepage = { workspace = true } 9 | documentation = { workspace = true } 10 | keywords = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ["cdylib", "rlib"] 14 | 15 | [features] 16 | # for quicker tests, cargo test --lib 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | library = [] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true } 23 | cw2 = { workspace = true } 24 | cw-dex = { workspace = true } 25 | mars-types = { workspace = true } 26 | mars-zapper-base = { workspace = true } 27 | 28 | [dev-dependencies] 29 | cw-utils = { workspace = true } 30 | mars-testing = { workspace = true } 31 | osmosis-std = { workspace = true } 32 | osmosis-test-tube = { workspace = true } 33 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod contract; 2 | pub mod lp_pool; 3 | pub mod migrations; 4 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/src/lp_pool.rs: -------------------------------------------------------------------------------- 1 | use std::str::FromStr; 2 | 3 | use cosmwasm_std::Deps; 4 | use cw_dex::{osmosis::OsmosisPool, traits::Pool, CwDexError}; 5 | use mars_zapper_base::LpPool; 6 | 7 | pub struct OsmosisLpPool {} 8 | 9 | impl OsmosisLpPool { 10 | /// Returns the matching pool given a LP token. 11 | /// 12 | /// Based on impl from https://github.com/apollodao/cw-dex/blob/develop/src/implementations/pool.rs#L60 13 | pub fn get_pool_for_lp_token( 14 | deps: Deps, 15 | lp_token_denom: &str, 16 | ) -> Result { 17 | // The only Pool implementation that uses native denoms right now is Osmosis 18 | if !lp_token_denom.starts_with("gamm/pool/") { 19 | return Err(CwDexError::NotLpToken {}); 20 | } 21 | 22 | let pool_id_str = 23 | lp_token_denom.strip_prefix("gamm/pool/").ok_or(CwDexError::NotLpToken {})?; 24 | 25 | let pool_id = u64::from_str(pool_id_str).map_err(|_| CwDexError::NotLpToken {})?; 26 | 27 | Ok(OsmosisPool::new(pool_id, deps)?) 28 | } 29 | } 30 | 31 | impl LpPool for OsmosisLpPool { 32 | fn get_pool_for_lp_token( 33 | deps: Deps, 34 | lp_token_denom: &str, 35 | ) -> Result, CwDexError> { 36 | Self::get_pool_for_lp_token(deps, lp_token_denom).map(|p| { 37 | let as_trait: Box = Box::new(p); 38 | as_trait 39 | }) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/src/migrations/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod v2_1_0; 2 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/src/migrations/v2_1_0.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{DepsMut, Response}; 2 | use cw2::{assert_contract_version, set_contract_version}; 3 | use mars_zapper_base::ContractError; 4 | 5 | use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; 6 | 7 | const FROM_VERSION: &str = "2.0.0"; 8 | 9 | pub fn migrate(deps: DepsMut) -> Result { 10 | // make sure we're migrating the correct contract and from the correct version 11 | assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; 12 | 13 | set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; 14 | 15 | Ok(Response::new() 16 | .add_attribute("action", "migrate") 17 | .add_attribute("from_version", FROM_VERSION) 18 | .add_attribute("to_version", CONTRACT_VERSION)) 19 | } 20 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::utils::*; 2 | 3 | mod utils; 4 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_callback; 4 | mod test_migration_v2; 5 | mod test_provide_liquidity; 6 | mod test_queries; 7 | mod test_withdraw_liquidity; 8 | -------------------------------------------------------------------------------- /contracts/v2-zapper/osmosis/tests/tests/test_callback.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{coin, Addr, Coin}; 2 | use mars_types::zapper::{CallbackMsg, ExecuteMsg}; 3 | use mars_zapper_base::ContractError; 4 | use osmosis_test_tube::{Account, Module, OsmosisTestApp, Wasm}; 5 | 6 | use super::helpers::{assert_err, instantiate_contract}; 7 | 8 | #[test] 9 | fn only_contract_itself_can_callback() { 10 | let app = OsmosisTestApp::new(); 11 | let wasm = Wasm::new(&app); 12 | 13 | let accs = app 14 | .init_accounts(&[coin(1_000_000_000_000, "uatom"), coin(1_000_000_000_000, "uosmo")], 2) 15 | .unwrap(); 16 | let owner = &accs[0]; 17 | let user = &accs[1]; 18 | 19 | let contract_addr = instantiate_contract(&wasm, owner); 20 | 21 | let res_err = wasm 22 | .execute( 23 | &contract_addr, 24 | &ExecuteMsg::Callback(CallbackMsg::ReturnCoin { 25 | balance_before: Coin::new(1u128, "gamm/pool/1"), 26 | recipient: Addr::unchecked(user.address()), 27 | }), 28 | &[], 29 | user, 30 | ) 31 | .unwrap_err(); 32 | assert_err(res_err, ContractError::Unauthorized {}); 33 | } 34 | -------------------------------------------------------------------------------- /contracts/vault/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::write_api; 2 | use mars_vault::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; 3 | 4 | fn main() { 5 | write_api! { 6 | instantiate: InstantiateMsg, 7 | execute: ExecuteMsg, 8 | query: QueryMsg, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/vault/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(feature = "library"))] 2 | pub mod contract; 3 | pub mod error; 4 | pub mod execute; 5 | pub mod instantiate; 6 | pub mod msg; 7 | pub mod performance_fee; 8 | pub mod query; 9 | pub mod state; 10 | pub mod token_factory; 11 | pub mod vault_token; 12 | -------------------------------------------------------------------------------- /contracts/vault/src/state.rs: -------------------------------------------------------------------------------- 1 | use cw_storage_plus::{Item, Map}; 2 | use mars_owner::Owner; 3 | 4 | use crate::{ 5 | msg::UnlockState, 6 | performance_fee::{PerformanceFeeConfig, PerformanceFeeState}, 7 | token_factory::TokenFactoryDenom, 8 | }; 9 | 10 | pub const OWNER: Owner = Owner::new("owner"); 11 | 12 | /// The vault token implementation for this vault 13 | pub const VAULT_TOKEN: Item = Item::new("vault_token"); 14 | 15 | /// The token that is depositable to the vault 16 | pub const BASE_TOKEN: Item = Item::new("base_token"); 17 | 18 | pub const CREDIT_MANAGER: Item = Item::new("cm_addr"); 19 | pub const VAULT_ACC_ID: Item = Item::new("vault_acc_id"); 20 | 21 | pub const TITLE: Item = Item::new("title"); 22 | pub const SUBTITLE: Item = Item::new("subtitle"); 23 | pub const DESCRIPTION: Item = Item::new("desc"); 24 | 25 | pub const COOLDOWN_PERIOD: Item = Item::new("cooldown_period"); 26 | pub const UNLOCKS: Map<(&str, u64), UnlockState> = Map::new("unlocks"); 27 | 28 | pub const PERFORMANCE_FEE_CONFIG: Item = Item::new("performance_fee_config"); 29 | pub const PERFORMANCE_FEE_STATE: Item = Item::new("performance_fee_state"); 30 | -------------------------------------------------------------------------------- /contracts/vault/src/vault_token.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{StdError, Uint128}; 2 | 3 | pub const DEFAULT_VAULT_TOKENS_PER_STAKED_BASE_TOKEN: Uint128 = Uint128::new(1_000_000); 4 | 5 | pub fn calculate_vault_tokens( 6 | base_tokens: Uint128, 7 | total_base_tokens: Uint128, 8 | vault_token_supply: Uint128, 9 | ) -> Result { 10 | let vault_tokens = if total_base_tokens.is_zero() { 11 | base_tokens.checked_mul(DEFAULT_VAULT_TOKENS_PER_STAKED_BASE_TOKEN)? 12 | } else { 13 | vault_token_supply.multiply_ratio(base_tokens, total_base_tokens) 14 | }; 15 | 16 | Ok(vault_tokens) 17 | } 18 | 19 | pub fn calculate_base_tokens( 20 | vault_tokens: Uint128, 21 | total_base_tokens: Uint128, 22 | vault_token_supply: Uint128, 23 | ) -> Result { 24 | let base_tokens = if vault_token_supply.is_zero() { 25 | vault_tokens.checked_div(DEFAULT_VAULT_TOKENS_PER_STAKED_BASE_TOKEN)? 26 | } else { 27 | total_base_tokens.multiply_ratio(vault_tokens, vault_token_supply) 28 | }; 29 | 30 | Ok(base_tokens) 31 | } 32 | -------------------------------------------------------------------------------- /contracts/vault/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /contracts/vault/tests/files/Mars - 3rd party Vault - Performance Fee - test cases v1.0.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/contracts/vault/tests/files/Mars - 3rd party Vault - Performance Fee - test cases v1.0.xlsx -------------------------------------------------------------------------------- /contracts/vault/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use mars_testing::multitest::helpers; 2 | 3 | mod vault_helpers; 4 | 5 | mod test_binding; 6 | mod test_deposit; 7 | mod test_instantiate; 8 | mod test_performance_fee; 9 | mod test_redeem; 10 | mod test_unlock; 11 | -------------------------------------------------------------------------------- /integration-tests/README.md: -------------------------------------------------------------------------------- 1 | # Mars Integration Tests 2 | 3 | Contains integration tests for Mars Red Bank and auxiliary contracts. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /integration-tests/src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /integration-tests/tests/files/Red Bank interest rates.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/integration-tests/tests/files/Red Bank interest rates.xlsx -------------------------------------------------------------------------------- /integration-tests/tests/files/stride-artifacts/151_stride_redemption_rate.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/integration-tests/tests/files/stride-artifacts/151_stride_redemption_rate.wasm -------------------------------------------------------------------------------- /integration-tests/tests/files/stride-artifacts/version.md: -------------------------------------------------------------------------------- 1 | These artifacts were downloaded from Osmosis mainnet on 2023-09-25 2 | -------------------------------------------------------------------------------- /packages/chains/osmosis/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-osmosis" 3 | description = "Helpers for the Osmosis chain" 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | doctest = false 15 | 16 | [features] 17 | # for more explicit tests, cargo test --features=backtraces 18 | backtraces = ["cosmwasm-std/backtraces"] 19 | 20 | [dependencies] 21 | cosmwasm-std = { workspace = true } 22 | cosmwasm-schema = { workspace = true } 23 | osmosis-std = { workspace = true } 24 | serde = { workspace = true } 25 | prost = { workspace = true } 26 | -------------------------------------------------------------------------------- /packages/chains/osmosis/README.md: -------------------------------------------------------------------------------- 1 | # Mars Osmosis 2 | 3 | Helpers for the Osmosis chain. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/chains/osmosis/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod helpers; 2 | 3 | pub use osmosis_std::types::osmosis::{ 4 | concentratedliquidity::v1beta1::Pool as ConcentratedLiquidityPool, 5 | gamm::{ 6 | poolmodels::stableswap::v1beta1::Pool as StableSwapPool, v1beta1::Pool as BalancerPool, 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /packages/health-computer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-rover-health-computer" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | documentation = { workspace = true } 7 | keywords = { workspace = true } 8 | 9 | [lib] 10 | crate-type = ["cdylib", "rlib"] 11 | doctest = false 12 | 13 | [features] 14 | backtraces = ["cosmwasm-std/backtraces"] 15 | default = ["console_error_panic_hook"] 16 | javascript = ["tsify", "wasm-bindgen", "mars-types/javascript"] 17 | 18 | [dependencies] 19 | cosmwasm-schema = { workspace = true } 20 | cosmwasm-std = { workspace = true } 21 | mars-types = { workspace = true } 22 | schemars = { workspace = true } 23 | serde_json = { workspace = true } 24 | tsify = { workspace = true, optional = true } 25 | wasm-bindgen = { workspace = true, optional = true } 26 | 27 | # The `console_error_panic_hook` crate provides better debugging of panics by 28 | # logging them with `console.error`. This is great for development, but requires 29 | # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for 30 | # code size when deploying. 31 | console_error_panic_hook = { version = "0.1.7", optional = true } 32 | web-sys = "0.3.64" 33 | 34 | [dev-dependencies] 35 | proptest = { workspace = true } 36 | 37 | -------------------------------------------------------------------------------- /packages/health-computer/examples/schema.rs: -------------------------------------------------------------------------------- 1 | use std::{env::current_dir, fs}; 2 | 3 | use mars_rover_health_computer::HealthComputer; 4 | use schemars::schema_for; 5 | 6 | fn main() -> std::io::Result<()> { 7 | let mut out_dir = current_dir().unwrap(); 8 | out_dir.push("schema"); 9 | fs::create_dir_all(&out_dir).unwrap(); 10 | let path = out_dir.join("mars-rover-health-computer.json"); 11 | 12 | let schema = schema_for!(HealthComputer); 13 | let output = serde_json::to_string_pretty(&schema).unwrap(); 14 | fs::write(path, output)?; 15 | 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /packages/health-computer/src/data_types.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use cosmwasm_schema::cw_serde; 4 | use cosmwasm_std::{Addr, Decimal, Uint128}; 5 | use mars_types::{ 6 | adapters::vault::VaultPositionValue, 7 | params::{AssetParams, VaultConfig}, 8 | }; 9 | 10 | /// Used as storage when trying to compute Health 11 | #[cw_serde] 12 | pub struct CollateralValue { 13 | pub total_collateral_value: Uint128, 14 | pub max_ltv_adjusted_collateral: Uint128, 15 | pub liquidation_threshold_adjusted_collateral: Uint128, 16 | } 17 | 18 | #[cw_serde] 19 | #[derive(Default)] 20 | pub struct DenomsData { 21 | /// Must include data from info.base token for the vaults 22 | pub prices: HashMap, 23 | pub params: HashMap, 24 | } 25 | 26 | #[cw_serde] 27 | #[derive(Default)] 28 | pub struct VaultsData { 29 | /// explain this, unlocked or locked value 30 | /// given the pricing method of vaults, cannot use individual coins 31 | pub vault_values: HashMap, 32 | pub vault_configs: HashMap, 33 | } 34 | -------------------------------------------------------------------------------- /packages/health-computer/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod data_types; 2 | mod health_computer; 3 | pub use self::{data_types::*, health_computer::*}; 4 | 5 | #[cfg(feature = "javascript")] 6 | mod javascript; 7 | #[cfg(feature = "javascript")] 8 | pub use self::javascript::*; 9 | -------------------------------------------------------------------------------- /packages/health-computer/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /packages/health-computer/tests/tests/helpers/mock_vault_config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{coin, Addr, Decimal}; 2 | use mars_types::params::VaultConfig; 3 | 4 | pub fn osmo_atom_1_config() -> VaultConfig { 5 | VaultConfig { 6 | addr: Addr::unchecked("osmoatom1"), 7 | deposit_cap: coin(1000000000000, "uatom"), 8 | max_loan_to_value: Decimal::from_atomics(7u128, 1).unwrap(), 9 | liquidation_threshold: Decimal::from_atomics(74u128, 2).unwrap(), 10 | whitelisted: true, 11 | hls: None, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/health-computer/tests/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{ 2 | mock_coin_info::*, mock_vault_config::*, prop_test_runner_borrow::*, prop_test_runner_swap::*, 3 | prop_test_strategies::*, 4 | }; 5 | 6 | mod mock_coin_info; 7 | mod mock_vault_config; 8 | mod prop_test_runner_borrow; 9 | mod prop_test_runner_swap; 10 | mod prop_test_strategies; 11 | -------------------------------------------------------------------------------- /packages/health-computer/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod helpers; 2 | 3 | mod test_health_scenarios; 4 | mod test_hls; 5 | mod test_input_validation; 6 | mod test_max_borrow_deposit; 7 | mod test_max_borrow_prop; 8 | mod test_max_borrow_validation; 9 | mod test_max_borrow_vault; 10 | mod test_max_borrow_wallet; 11 | mod test_max_swap; 12 | mod test_max_swap_prop; 13 | mod test_max_swap_validation; 14 | mod test_max_withdraw; 15 | mod test_max_withdraw_prop_test; 16 | -------------------------------------------------------------------------------- /packages/health-computer/tests/tests/test_max_borrow_prop.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Addr, Decimal}; 2 | use mars_types::health::BorrowTarget; 3 | 4 | use super::helpers::max_borrow_prop_test_runner; 5 | 6 | #[test] 7 | fn max_borrow_amount_deposit_renders_healthy_max_ltv() { 8 | max_borrow_prop_test_runner(2000, &BorrowTarget::Deposit); 9 | } 10 | 11 | #[test] 12 | fn max_borrow_amount_wallet_renders_healthy_max_ltv() { 13 | max_borrow_prop_test_runner(2000, &BorrowTarget::Wallet); 14 | } 15 | 16 | #[test] 17 | fn max_borrow_amount_vault_renders_healthy_max_ltv() { 18 | max_borrow_prop_test_runner( 19 | 2000, 20 | &BorrowTarget::Vault { 21 | address: Addr::unchecked("123"), 22 | }, 23 | ); 24 | } 25 | 26 | #[test] 27 | fn max_borrow_amount_swap_no_slippage_renders_healthy_max_ltv() { 28 | max_borrow_prop_test_runner( 29 | 2000, 30 | &BorrowTarget::Swap { 31 | denom_out: "abc".to_string(), 32 | slippage: Decimal::zero(), 33 | }, 34 | ); 35 | } 36 | 37 | #[test] 38 | fn max_borrow_amount_swap_renders_healthy_max_ltv() { 39 | max_borrow_prop_test_runner( 40 | 2000, 41 | &BorrowTarget::Swap { 42 | denom_out: "abc".to_string(), 43 | slippage: Decimal::percent(1), 44 | }, 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /packages/health-computer/tests/tests/test_max_swap_prop.rs: -------------------------------------------------------------------------------- 1 | use mars_types::health::SwapKind; 2 | 3 | use super::helpers::max_swap_prop_test_runner; 4 | 5 | #[test] 6 | fn max_swap_amount_default_renders_healthy_max_ltv() { 7 | max_swap_prop_test_runner(2000, &SwapKind::Default); 8 | } 9 | 10 | #[test] 11 | fn max_swap_amount_margin_renders_healthy_max_ltv() { 12 | max_swap_prop_test_runner(2000, &SwapKind::Margin); 13 | } 14 | -------------------------------------------------------------------------------- /packages/health/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-health" 3 | description = "Helper functions to compute the health factor" 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true } 23 | mars-types = { workspace = true } 24 | thiserror = { workspace = true } 25 | 26 | [dev-dependencies] 27 | mars-testing = { workspace = true } 28 | -------------------------------------------------------------------------------- /packages/health/README.md: -------------------------------------------------------------------------------- 1 | # Mars Health 2 | 3 | Functions used for evaluating the health of user positions at Mars Protocol. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/health/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{CheckedFromRatioError, CheckedMultiplyRatioError, StdError}; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum HealthError { 6 | #[error("{0}")] 7 | Std(#[from] StdError), 8 | 9 | #[error("{0}")] 10 | CheckedMultiplyRatio(#[from] CheckedMultiplyRatioError), 11 | 12 | #[error("{0}")] 13 | CheckedFromRatio(#[from] CheckedFromRatioError), 14 | } 15 | -------------------------------------------------------------------------------- /packages/health/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | pub mod health; 3 | pub mod query; 4 | -------------------------------------------------------------------------------- /packages/health/tests/all_tests.rs: -------------------------------------------------------------------------------- 1 | mod tests; 2 | -------------------------------------------------------------------------------- /packages/health/tests/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod test_from_coins_to_positions; 2 | mod test_health; 3 | mod test_health_from_coins; 4 | -------------------------------------------------------------------------------- /packages/interest-rate/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-interest-rate" 3 | description = "Computations related to interest rates" 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true } 23 | mars-types = { workspace = true } 24 | -------------------------------------------------------------------------------- /packages/liquidation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-liquidation" 3 | description = "Helper functions to calculate liquidation amounts" 4 | version = "1.0.0" 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | 21 | [dependencies] 22 | cosmwasm-std = { workspace = true } 23 | mars-health = { workspace = true } 24 | mars-types = { workspace = true } 25 | thiserror = { workspace = true } 26 | -------------------------------------------------------------------------------- /packages/liquidation/README.md: -------------------------------------------------------------------------------- 1 | # Mars Health 2 | 3 | Functions used for evaluating the liquidation of user positions at Mars Protocol. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/liquidation/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{ 2 | CheckedFromRatioError, CheckedMultiplyFractionError, CheckedMultiplyRatioError, OverflowError, 3 | StdError, 4 | }; 5 | use thiserror::Error; 6 | 7 | #[derive(Error, Debug, PartialEq)] 8 | pub enum LiquidationError { 9 | #[error("{0}")] 10 | Std(#[from] StdError), 11 | 12 | #[error("{0}")] 13 | Overflow(#[from] OverflowError), 14 | 15 | #[error("{0}")] 16 | CheckedMultiplyRatio(#[from] CheckedMultiplyRatioError), 17 | 18 | #[error("{0}")] 19 | CheckedMultiplyFraction(#[from] CheckedMultiplyFractionError), 20 | 21 | #[error("{0}")] 22 | CheckedFromRatio(#[from] CheckedFromRatioError), 23 | } 24 | -------------------------------------------------------------------------------- /packages/liquidation/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | pub mod liquidation; 3 | -------------------------------------------------------------------------------- /packages/testing/README.md: -------------------------------------------------------------------------------- 1 | # Mars Testing 2 | 3 | Utilities for testing Red Bank smart contracts. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/testing/src/cosmwasm_pool_querier.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{to_json_binary, Binary, ContractResult, QuerierResult}; 2 | use osmosis_std::types::{ 3 | cosmos::base::v1beta1::Coin, 4 | osmosis::cosmwasmpool::v1beta1::{CalcOutAmtGivenInRequest, CalcOutAmtGivenInResponse}, 5 | }; 6 | 7 | #[derive(Default)] 8 | pub struct CosmWasmPoolQuerier {} 9 | 10 | impl CosmWasmPoolQuerier { 11 | pub fn handle_query(&self, query: CalcOutAmtGivenInRequest) -> QuerierResult { 12 | let res: ContractResult = { 13 | let token_in = query.calc_out_amt_given_in.clone().unwrap().token_in.unwrap(); 14 | let denom_out = query.calc_out_amt_given_in.unwrap().token_out_denom; 15 | 16 | to_json_binary(&CalcOutAmtGivenInResponse { 17 | token_out: Some(Coin { 18 | denom: denom_out, 19 | amount: token_in.amount, 20 | }), 21 | }) 22 | .into() 23 | }; 24 | Ok(res).into() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/testing/src/helpers.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{StdError, StdResult}; 2 | 3 | /// Assert elements in vecs one by one in order to get a more meaningful error 4 | /// when debugging tests 5 | pub fn assert_eq_vec(expected: Vec, actual: Vec) { 6 | assert_eq!(expected.len(), actual.len()); 7 | 8 | for (i, element) in expected.iter().enumerate() { 9 | assert_eq!(*element, actual[i]); 10 | } 11 | } 12 | 13 | /// Assert StdError::GenericErr message with expected_msg 14 | pub fn assert_generic_error_message(response: StdResult, expected_msg: &str) { 15 | match response { 16 | Err(StdError::GenericErr { 17 | msg, 18 | .. 19 | }) => assert_eq!(msg, expected_msg), 20 | Err(other_err) => panic!("Unexpected error: {other_err:?}"), 21 | Ok(_) => panic!("SHOULD NOT ENTER HERE!"), 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/testing/src/integration/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod helpers; 2 | pub mod mock_contracts; 3 | pub mod mock_env; 4 | -------------------------------------------------------------------------------- /packages/testing/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg(not(target_arch = "wasm32"))] 2 | 3 | extern crate core; 4 | 5 | pub mod astroport_incentives_querier; 6 | #[cfg(feature = "astroport")] 7 | pub mod astroport_swapper; 8 | mod cosmwasm_pool_querier; 9 | /// cosmwasm_std::testing overrides and custom test helpers 10 | mod helpers; 11 | mod incentives_querier; 12 | mod mars_mock_querier; 13 | mod mock_address_provider; 14 | mod mocks; 15 | pub mod multitest; 16 | mod oracle_querier; 17 | mod osmosis_querier; 18 | mod params_querier; 19 | mod pyth_querier; 20 | mod red_bank_querier; 21 | mod redemption_rate_querier; 22 | mod swapper_querier; 23 | pub mod test_runner; 24 | #[cfg(feature = "astroport")] 25 | pub mod wasm_oracle; 26 | 27 | pub use helpers::*; 28 | pub use mars_mock_querier::MarsMockQuerier; 29 | pub use mocks::*; 30 | 31 | pub mod integration; 32 | -------------------------------------------------------------------------------- /packages/testing/src/multitest/helpers/assertions.rs: -------------------------------------------------------------------------------- 1 | use std::hash::Hash; 2 | 3 | use anyhow::Result as AnyResult; 4 | use cw_multi_test::AppResponse; 5 | use mars_credit_manager::{error::ContractError, utils::contents_equal}; 6 | 7 | pub fn assert_err(res: AnyResult, err: ContractError) { 8 | match res { 9 | Ok(_) => panic!("Result was not an error"), 10 | Err(generic_err) => { 11 | let contract_err: ContractError = generic_err.downcast().unwrap(); 12 | assert_eq!(contract_err, err); 13 | } 14 | } 15 | } 16 | 17 | pub fn assert_contents_equal(vec_a: &[T], vec_b: &[T]) 18 | where 19 | T: Eq + Hash, 20 | { 21 | assert!(contents_equal(vec_a, vec_b)) 22 | } 23 | -------------------------------------------------------------------------------- /packages/testing/src/multitest/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::{ 2 | assertions::*, builders::*, contracts::*, mock_entity_info::*, mock_env::*, types::*, utils::*, 3 | }; 4 | 5 | mod assertions; 6 | mod builders; 7 | mod contracts; 8 | mod mock_entity_info; 9 | mod mock_env; 10 | mod types; 11 | mod utils; 12 | -------------------------------------------------------------------------------- /packages/testing/src/multitest/helpers/utils.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::Coin; 2 | use mars_types::credit_manager::DebtAmount; 3 | 4 | pub fn get_coin(denom: &str, coins: &[Coin]) -> Coin { 5 | coins.iter().find(|cv| cv.denom == denom).unwrap().clone() 6 | } 7 | 8 | pub fn get_debt(denom: &str, coins: &[DebtAmount]) -> DebtAmount { 9 | coins.iter().find(|coin| coin.denom.as_str() == denom).unwrap().clone() 10 | } 11 | -------------------------------------------------------------------------------- /packages/testing/src/multitest/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod helpers; 2 | pub mod modules; 3 | -------------------------------------------------------------------------------- /packages/testing/src/multitest/modules/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod token_factory; 2 | -------------------------------------------------------------------------------- /packages/testing/src/oracle_querier.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use cosmwasm_std::{to_json_binary, Addr, Binary, ContractResult, Decimal, QuerierResult}; 4 | use mars_types::oracle::{PriceResponse, QueryMsg}; 5 | 6 | #[derive(Default)] 7 | pub struct OracleQuerier { 8 | pub prices: HashMap, 9 | } 10 | 11 | impl OracleQuerier { 12 | pub fn handle_query(&self, _contract_addr: &Addr, query: QueryMsg) -> QuerierResult { 13 | let ret: ContractResult = match query { 14 | QueryMsg::Price { 15 | denom, 16 | kind: _, 17 | } => { 18 | let option_price = self.prices.get(&denom); 19 | 20 | if let Some(price) = option_price { 21 | to_json_binary(&PriceResponse { 22 | denom, 23 | price: *price, 24 | }) 25 | .into() 26 | } else { 27 | Err(format!("[mock]: could not find oracle price for {denom}")).into() 28 | } 29 | } 30 | 31 | _ => Err("[mock]: Unsupported oracle query").into(), 32 | }; 33 | 34 | Ok(ret).into() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/testing/src/pyth_querier.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use cosmwasm_std::{to_json_binary, Addr, Binary, ContractResult, QuerierResult}; 4 | use pyth_sdk_cw::{PriceFeedResponse, PriceIdentifier, QueryMsg}; 5 | 6 | #[derive(Default)] 7 | pub struct PythQuerier { 8 | pub prices: HashMap, 9 | } 10 | 11 | impl PythQuerier { 12 | pub fn handle_query(&self, _contract_addr: &Addr, query: QueryMsg) -> QuerierResult { 13 | let res: ContractResult = match query { 14 | QueryMsg::PriceFeed { 15 | id, 16 | } => { 17 | let option_price = self.prices.get(&id); 18 | 19 | if let Some(price) = option_price { 20 | to_json_binary(price).into() 21 | } else { 22 | Err(format!("[mock]: could not find Pyth price for {id}")).into() 23 | } 24 | } 25 | 26 | _ => Err("[mock]: Unsupported Pyth query").into(), 27 | }; 28 | 29 | Ok(res).into() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/testing/src/redemption_rate_querier.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use cosmwasm_std::{to_json_binary, Binary, ContractResult, QuerierResult}; 4 | use ica_oracle::msg::{QueryMsg, RedemptionRateResponse}; 5 | 6 | #[derive(Default)] 7 | pub struct RedemptionRateQuerier { 8 | pub redemption_rates: HashMap, 9 | } 10 | 11 | impl RedemptionRateQuerier { 12 | pub fn handle_query(&self, query: QueryMsg) -> QuerierResult { 13 | let res: ContractResult = match query { 14 | QueryMsg::RedemptionRate { 15 | denom, 16 | params: _, 17 | } => { 18 | let option_rr = self.redemption_rates.get(&denom); 19 | 20 | if let Some(rr) = option_rr { 21 | to_json_binary(rr).into() 22 | } else { 23 | Err(format!("[mock]: could not find redemption rate for denom {}", denom)) 24 | .into() 25 | } 26 | } 27 | 28 | _ => Err("[mock]: Unsupported Stride query").into(), 29 | }; 30 | 31 | Ok(res).into() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/testing/src/swapper_querier.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use cosmwasm_std::{to_json_binary, Addr, Decimal, QuerierResult}; 4 | use mars_types::swapper::{EstimateExactInSwapResponse, QueryMsg}; 5 | 6 | #[derive(Default)] 7 | pub struct SwapperQuerier { 8 | pub swap_prices: HashMap, 9 | } 10 | 11 | impl SwapperQuerier { 12 | pub fn handle_query(&self, _contract_addr: &Addr, query: QueryMsg) -> QuerierResult { 13 | let ret = match query { 14 | QueryMsg::EstimateExactInSwap { 15 | coin_in, 16 | denom_out, 17 | route: _, 18 | } => { 19 | let denom_in = coin_in.denom.clone(); 20 | let denom_in_price = self.swap_prices.get(&denom_in).unwrap(); 21 | let denom_out_price = self.swap_prices.get(&denom_out).unwrap(); 22 | 23 | let price = denom_in_price / denom_out_price; 24 | let amount = coin_in.amount * price; 25 | to_json_binary(&EstimateExactInSwapResponse { 26 | amount, 27 | }) 28 | .into() 29 | } 30 | _ => Err("[mock]: Unsupported swapper query").into(), 31 | }; 32 | 33 | Ok(ret).into() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/testing/src/test_runner.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "osmosis-test-tube")] 2 | use cw_it::osmosis_test_tube::OsmosisTestApp; 3 | use cw_it::{multi_test::MultiTestRunner, OwnedTestRunner}; 4 | 5 | const DEFAULT_TEST_RUNNER: &str = "multi-test"; 6 | 7 | /// Creates a test runner with the type defined by the TEST_RUNNER environment variable 8 | pub fn get_test_runner<'a>() -> OwnedTestRunner<'a> { 9 | match option_env!("TEST_RUNNER").unwrap_or(DEFAULT_TEST_RUNNER) { 10 | #[cfg(feature = "osmosis-test-tube")] 11 | "osmosis-test-tube" => { 12 | let app = OsmosisTestApp::new(); 13 | OwnedTestRunner::OsmosisTestApp(app) 14 | } 15 | "multi-test" => OwnedTestRunner::MultiTest(MultiTestRunner::new("osmo")), 16 | x => panic!("Unsupported test runner type {} specified", x), 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/types/README.md: -------------------------------------------------------------------------------- 1 | # Mars Types 2 | 3 | Contains messages and types for Mars smart contracts. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/types/src/account_nft/mod.rs: -------------------------------------------------------------------------------- 1 | mod execute; 2 | mod instantiate; 3 | mod nft_config; 4 | mod query; 5 | 6 | pub use execute::*; 7 | pub use instantiate::*; 8 | pub use nft_config::*; 9 | pub use query::*; 10 | -------------------------------------------------------------------------------- /packages/types/src/account_nft/nft_config.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::{Addr, Uint128}; 3 | 4 | #[cw_serde] 5 | pub struct NftConfigBase { 6 | pub max_value_for_burn: Uint128, 7 | pub health_contract_addr: Option, 8 | pub credit_manager_contract_addr: Option, 9 | } 10 | 11 | pub type NftConfig = NftConfigBase; 12 | pub type UncheckedNftConfig = NftConfigBase; 13 | 14 | impl From for UncheckedNftConfig { 15 | fn from(config: NftConfig) -> Self { 16 | Self { 17 | max_value_for_burn: config.max_value_for_burn, 18 | health_contract_addr: config.health_contract_addr.map(Into::into), 19 | credit_manager_contract_addr: config.credit_manager_contract_addr.map(Into::into), 20 | } 21 | } 22 | } 23 | 24 | #[cw_serde] 25 | pub struct NftConfigUpdates { 26 | pub max_value_for_burn: Option, 27 | pub health_contract_addr: Option, 28 | pub credit_manager_contract_addr: Option, 29 | } 30 | -------------------------------------------------------------------------------- /packages/types/src/adapters/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod account_nft; 2 | pub mod health; 3 | pub mod incentives; 4 | pub mod oracle; 5 | pub mod params; 6 | pub mod red_bank; 7 | pub mod rewards_collector; 8 | pub mod swapper; 9 | pub mod vault; 10 | pub mod zapper; 11 | -------------------------------------------------------------------------------- /packages/types/src/adapters/rewards_collector.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | 3 | #[cw_serde] 4 | pub struct RewardsCollector { 5 | pub address: String, 6 | pub account_id: String, 7 | } 8 | -------------------------------------------------------------------------------- /packages/types/src/adapters/vault/mod.rs: -------------------------------------------------------------------------------- 1 | mod amount; 2 | mod base; 3 | mod position; 4 | mod update; 5 | 6 | pub use self::{amount::*, base::*, position::*, update::*}; 7 | -------------------------------------------------------------------------------- /packages/types/src/adapters/vault/update.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::Uint128; 3 | 4 | use crate::adapters::vault::{ 5 | LockingVaultAmount, UnlockingPositions, VaultAmount, VaultPositionAmount, 6 | VaultUnlockingPosition, 7 | }; 8 | 9 | #[cw_serde] 10 | pub enum UpdateType { 11 | Increment(Uint128), 12 | Decrement(Uint128), 13 | } 14 | 15 | #[cw_serde] 16 | pub enum UnlockingChange { 17 | Add(VaultUnlockingPosition), 18 | Decrement { 19 | id: u64, 20 | amount: Uint128, 21 | }, 22 | } 23 | 24 | #[cw_serde] 25 | pub enum VaultPositionUpdate { 26 | Unlocked(UpdateType), 27 | Locked(UpdateType), 28 | Unlocking(UnlockingChange), 29 | } 30 | 31 | impl VaultPositionUpdate { 32 | pub fn default_amount(&self) -> VaultPositionAmount { 33 | match self { 34 | VaultPositionUpdate::Unlocked { 35 | .. 36 | } => VaultPositionAmount::Unlocked(VaultAmount::new(Uint128::zero())), 37 | _ => VaultPositionAmount::Locking(LockingVaultAmount { 38 | locked: VaultAmount::new(Uint128::zero()), 39 | unlocking: UnlockingPositions::new(vec![]), 40 | }), 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/types/src/credit_manager/migrate.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::Decimal; 3 | 4 | use crate::adapters::{ 5 | health::HealthContractUnchecked, incentives::IncentivesUnchecked, params::ParamsUnchecked, 6 | swapper::SwapperUnchecked, 7 | }; 8 | 9 | #[cw_serde] 10 | pub struct V2Updates { 11 | pub health_contract: HealthContractUnchecked, 12 | pub params: ParamsUnchecked, 13 | pub incentives: IncentivesUnchecked, 14 | pub swapper: SwapperUnchecked, 15 | pub max_slippage: Decimal, 16 | } 17 | 18 | #[cw_serde] 19 | pub enum MigrateMsg { 20 | V1_0_0ToV2_0_0(V2Updates), 21 | V2_0_2ToV2_0_3 {}, 22 | } 23 | -------------------------------------------------------------------------------- /packages/types/src/credit_manager/mod.rs: -------------------------------------------------------------------------------- 1 | mod execute; 2 | mod instantiate; 3 | mod migrate; 4 | mod query; 5 | mod reply; 6 | 7 | pub use execute::*; 8 | pub use instantiate::*; 9 | pub use migrate::*; 10 | pub use query::*; 11 | pub use reply::*; 12 | -------------------------------------------------------------------------------- /packages/types/src/health/mod.rs: -------------------------------------------------------------------------------- 1 | mod account; 2 | mod error; 3 | #[allow(clippy::module_inception)] 4 | mod health; 5 | mod msg; 6 | 7 | pub use account::*; 8 | pub use error::*; 9 | pub use health::*; 10 | pub use msg::*; 11 | -------------------------------------------------------------------------------- /packages/types/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod account_nft; 2 | pub mod adapters; 3 | pub mod address_provider; 4 | pub mod credit_manager; 5 | pub mod error; 6 | pub mod health; 7 | pub mod incentives; 8 | pub mod keys; 9 | pub mod oracle; 10 | pub mod params; 11 | pub mod red_bank; 12 | pub mod rewards_collector; 13 | pub mod swapper; 14 | pub mod traits; 15 | pub mod zapper; 16 | -------------------------------------------------------------------------------- /packages/types/src/oracle/mod.rs: -------------------------------------------------------------------------------- 1 | mod msg; 2 | mod wasm_oracle; 3 | 4 | pub use msg::*; 5 | pub use wasm_oracle::*; 6 | -------------------------------------------------------------------------------- /packages/types/src/oracle/wasm_oracle.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::cw_serde; 2 | use cosmwasm_std::Uint128; 3 | 4 | #[cw_serde] 5 | pub struct WasmOracleCustomInitParams { 6 | /// The Astroport factory contract address 7 | pub astroport_factory: String, 8 | } 9 | 10 | #[cw_serde] 11 | pub enum WasmOracleCustomExecuteMsg { 12 | RecordTwapSnapshots { 13 | denoms: Vec, 14 | }, 15 | } 16 | 17 | #[cw_serde] 18 | pub struct AstroportTwapSnapshot { 19 | /// Timestamp of the most recent TWAP data update 20 | pub timestamp: u64, 21 | /// Cumulative price of the asset retrieved by the most recent TWAP data update 22 | pub price_cumulative: Uint128, 23 | } 24 | -------------------------------------------------------------------------------- /packages/types/src/params/mod.rs: -------------------------------------------------------------------------------- 1 | mod assertions; 2 | mod asset; 3 | mod hls; 4 | mod msg; 5 | mod vault; 6 | 7 | pub use asset::*; 8 | pub use hls::*; 9 | pub use msg::*; 10 | pub use vault::*; 11 | -------------------------------------------------------------------------------- /packages/types/src/red_bank/mod.rs: -------------------------------------------------------------------------------- 1 | mod interest_rate_model; 2 | mod market; 3 | mod msg; 4 | mod types; 5 | 6 | pub use interest_rate_model::*; 7 | pub use market::*; 8 | pub use msg::*; 9 | pub use types::*; 10 | -------------------------------------------------------------------------------- /packages/types/src/traits.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::{Coin, Decimal}; 2 | 3 | use crate::credit_manager::ActionCoin; 4 | 5 | pub trait Stringify { 6 | fn to_string(&self) -> String; 7 | } 8 | 9 | impl Stringify for Option { 10 | fn to_string(&self) -> String { 11 | self.map_or_else(|| "None".to_string(), |dec| dec.to_string()) 12 | } 13 | } 14 | 15 | impl Stringify for &[Coin] { 16 | fn to_string(&self) -> String { 17 | self.iter().map(|coin| coin.to_string()).collect::>().join(",") 18 | } 19 | } 20 | 21 | pub trait Denoms { 22 | fn to_denoms(&self) -> Vec<&str>; 23 | } 24 | 25 | impl Denoms for Vec { 26 | fn to_denoms(&self) -> Vec<&str> { 27 | self.iter().map(|c| c.denom.as_str()).collect() 28 | } 29 | } 30 | 31 | impl Denoms for Vec { 32 | fn to_denoms(&self) -> Vec<&str> { 33 | self.iter().map(|c| c.denom.as_str()).collect() 34 | } 35 | } 36 | 37 | pub trait Coins { 38 | fn to_coins(&self) -> Vec; 39 | } 40 | 41 | pub trait FallbackStr { 42 | fn fallback(&self, fallback: &str) -> String; 43 | } 44 | 45 | impl FallbackStr for String { 46 | fn fallback(&self, fallback: &str) -> String { 47 | match self { 48 | s if !s.is_empty() => s.clone(), 49 | _ => fallback.to_string(), 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /packages/types/src/zapper.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_schema::{cw_serde, QueryResponses}; 2 | use cosmwasm_std::{to_json_binary, Addr, Coin, CosmosMsg, Env, StdResult, Uint128, WasmMsg}; 3 | 4 | #[cw_serde] 5 | pub struct InstantiateMsg {} 6 | 7 | #[cw_serde] 8 | pub enum ExecuteMsg { 9 | ProvideLiquidity { 10 | lp_token_out: String, 11 | recipient: Option, 12 | minimum_receive: Uint128, 13 | }, 14 | WithdrawLiquidity { 15 | recipient: Option, 16 | minimum_receive: Vec, 17 | }, 18 | Callback(CallbackMsg), 19 | } 20 | 21 | #[cw_serde] 22 | pub enum CallbackMsg { 23 | ReturnCoin { 24 | balance_before: Coin, 25 | recipient: Addr, 26 | }, 27 | } 28 | 29 | impl CallbackMsg { 30 | pub fn into_cosmos_msg(self, env: &Env) -> StdResult { 31 | Ok(CosmosMsg::Wasm(WasmMsg::Execute { 32 | contract_addr: env.contract.address.to_string(), 33 | msg: to_json_binary(&ExecuteMsg::Callback(self))?, 34 | funds: vec![], 35 | })) 36 | } 37 | } 38 | 39 | #[cw_serde] 40 | #[derive(QueryResponses)] 41 | pub enum QueryMsg { 42 | #[returns(Uint128)] 43 | EstimateProvideLiquidity { 44 | lp_token_out: String, 45 | coins_in: Vec, 46 | }, 47 | #[returns(Vec)] 48 | EstimateWithdrawLiquidity { 49 | coin_in: Coin, 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /packages/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mars-utils" 3 | description = "Helpers for Mars smart contracts" 4 | version = { workspace = true } 5 | authors = { workspace = true } 6 | edition = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | homepage = { workspace = true } 10 | documentation = { workspace = true } 11 | keywords = { workspace = true } 12 | 13 | [lib] 14 | doctest = false 15 | 16 | [features] 17 | # for quicker tests, cargo test --lib 18 | # for more explicit tests, cargo test --features=backtraces 19 | backtraces = ["cosmwasm-std/backtraces"] 20 | 21 | [dependencies] 22 | cosmwasm-schema = { workspace = true } 23 | cosmwasm-std = { workspace = true } 24 | cw-storage-plus = { workspace = true } 25 | thiserror = { workspace = true } -------------------------------------------------------------------------------- /packages/utils/README.md: -------------------------------------------------------------------------------- 1 | # Mars Utils 2 | 3 | Contains helpers for all Mars smart contracts. 4 | 5 | ## License 6 | 7 | Contents of this crate are open source under [GNU General Public License v3](../../LICENSE) or later. 8 | -------------------------------------------------------------------------------- /packages/utils/src/error.rs: -------------------------------------------------------------------------------- 1 | use cosmwasm_std::StdError; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug, PartialEq)] 5 | pub enum ValidationError { 6 | #[error("Invalid param: {param_name} is {invalid_value}, but it should be {predicate}")] 7 | InvalidParam { 8 | param_name: String, 9 | invalid_value: String, 10 | predicate: String, 11 | }, 12 | 13 | #[error("Invalid denom: {reason}")] 14 | InvalidDenom { 15 | reason: String, 16 | }, 17 | } 18 | 19 | #[derive(Error, Debug, PartialEq)] 20 | pub enum GuardError { 21 | #[error("{0}")] 22 | Std(#[from] StdError), 23 | 24 | #[error("Guard is active")] 25 | Active {}, 26 | 27 | #[error("Guard is inactive")] 28 | Inactive {}, 29 | 30 | #[error("Invalid guard state transition")] 31 | InvalidState {}, 32 | } 33 | -------------------------------------------------------------------------------- /packages/utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | pub mod guard; 3 | pub mod helpers; 4 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | group_imports = "StdExternalCrate" # nightly feature 2 | imports_granularity = "Crate" # nightly feature 3 | max_width = 100 4 | use_small_heuristics = "Off" 5 | -------------------------------------------------------------------------------- /scripts/.eslintignore: -------------------------------------------------------------------------------- 1 | # No checking of built files 2 | build/ 3 | 4 | # Automatically generated by ts-codegen 5 | types/generated 6 | -------------------------------------------------------------------------------- /scripts/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | parserOptions: { 5 | tsconfigRootDir: __dirname, 6 | project: ['./tsconfig.json'], 7 | }, 8 | plugins: ['@typescript-eslint'], 9 | extends: [ 10 | 'eslint:recommended', 11 | 'plugin:@typescript-eslint/recommended', 12 | 'plugin:@typescript-eslint/recommended-requiring-type-checking', 13 | 'plugin:@typescript-eslint/strict', 14 | 'prettier', 15 | ], 16 | rules: { 17 | '@typescript-eslint/restrict-template-expressions': 'off', 18 | '@typescript-eslint/no-non-null-assertion': 'off', 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /scripts/.prettierignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /scripts/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "jsxSingleQuote": true, 4 | "semi": false, 5 | "printWidth": 100, 6 | "trailingComma": "all" 7 | } 8 | -------------------------------------------------------------------------------- /scripts/codegen-tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["codegen"], 4 | "exclude": ["deploy", "types", "utils", "build"] 5 | } 6 | -------------------------------------------------------------------------------- /scripts/codegen/index.ts: -------------------------------------------------------------------------------- 1 | import codegen from '@cosmwasm/ts-codegen' 2 | import { join, resolve } from 'path' 3 | import { printGreen, printRed } from '../utils/chalk' 4 | import { readdir } from 'fs/promises' 5 | 6 | void (async function () { 7 | const schemasDir = resolve(join(__dirname, '../../../schemas')) 8 | const schemas = await readdir(schemasDir) 9 | 10 | for (const schema of schemas) { 11 | try { 12 | await codegen({ 13 | contracts: [`${schemasDir}/${schema}`], 14 | outPath: `./types/generated/${schema}`, 15 | options: { 16 | types: { 17 | enabled: true, 18 | }, 19 | client: { 20 | enabled: true, 21 | }, 22 | reactQuery: { 23 | enabled: true, 24 | optionalClient: true, 25 | version: 'v4', 26 | mutations: true, 27 | queryKeys: true, 28 | }, 29 | messageComposer: { 30 | enabled: false, 31 | }, 32 | }, 33 | }) 34 | printGreen(`Success ✨ ${schema} types generated`) 35 | } catch (e) { 36 | printRed(`Error with ${schema}: ${e}`) 37 | } 38 | } 39 | })() 40 | -------------------------------------------------------------------------------- /scripts/codegen/insertIgnores.ts: -------------------------------------------------------------------------------- 1 | import { readdir } from 'fs/promises' 2 | import { join, resolve } from 'path' 3 | import prependFile from 'prepend-file' 4 | 5 | // Unfortunately ts-codegen spits out code that does not compile well with typescript 6 | // This adds an ignore at the top of those files so no compile error is thrown 7 | void (async function () { 8 | const generatedTypesDir = resolve(join(__dirname, '../../types/generated')) 9 | const typeFiles = await getFiles(generatedTypesDir) 10 | for (const file of typeFiles) { 11 | await prependFile(file, '// @ts-nocheck\n') 12 | } 13 | })() 14 | 15 | async function getFiles(dir: string): Promise { 16 | const dirents = await readdir(dir, { withFileTypes: true }) 17 | const files = await Promise.all( 18 | dirents.map((dirent) => { 19 | const res = resolve(dir, dirent.name) 20 | return dirent.isDirectory() ? getFiles(res) : res 21 | }), 22 | ) 23 | return Array.prototype.concat(...files) as string[] 24 | } 25 | -------------------------------------------------------------------------------- /scripts/deploy/addresses/devnet-deployer-owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "address-provider": "osmo1g677w7mfvn78eeudzwylxzlyz69fsgumqrscj6tekhdvs8fye3asufmvxr", 3 | "red-bank": "osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg", 4 | "incentives": "osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm", 5 | "oracle": "osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g", 6 | "rewards-collector": "osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy", 7 | "swapper": "osmo1wee0z8c7tcawyl647eapqs4a88q8jpa7ddy6nn2nrs7t47p2zhxswetwla", 8 | "zapper": "osmo17qwvc70pzc9mudr8t02t3pl74hhqsgwnskl734p4hug3s8mkerdqzduf7c", 9 | "creditManager": "osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf", 10 | "accountNft": "osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09", 11 | "params": "osmo1aye5qcer5n52crrkaf35jprsad2807q6kg3eeeu7k79h4slxfausfqhc9y", 12 | "health": "osmo1kqzkuyh23chjwemve7p9t7sl63v0sxtjh84e95w4fdz3htg8gmgspua7q4" 13 | } 14 | -------------------------------------------------------------------------------- /scripts/deploy/addresses/neutron-1-deployer-owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "addressProvider": "neutron1fg5v00sa0x3avsxa4rft5v9sgktl3s6fvkjwxy03lplcc6hrqxps08u2lc", 3 | "redBank": "neutron1xucw5lg7sh9gmupd90jaeupvq0nm4pj5esu3ff7f64pacy2lyjsqfwft80", 4 | "incentives": "neutron1uf6nclgqvwnqv5lfverunenpzyw556h739sekj75k62h062k9lrqzhm3up", 5 | "oracle": "neutron14rjfsglulewu9narj077ata6p0dkfjjuayguku50f8tg2fyf4ups44a0ww", 6 | "rewardsCollector": "neutron1l0ehl3wptumpyg85csv6n5dky93h4sph4ypfjpztnu4cj7kg9uvstzlwrr", 7 | "swapper": "neutron1t29va54hgzsakwuh2azpr77ty793h57yd978gz0dkekvyqrpcupqhhy6g3", 8 | "params": "neutron102xprj349yslxu5xncpsmv8qk38ryag870xvgxgm5r9dnagvetwszssu59", 9 | "zapper": "neutron16604kpsj3uptdxharvdn5w4ps3j7lydudn0dprwnmg5aj35uhatqse2l37", 10 | "health": "neutron18g6w7vkqwkdkexzl227g5h7464lzx4et4l5w9aawp8j7njf6gjkqrzpuug", 11 | "creditManager": "neutron1eekxmplmetd0eq2fs6lyn5lrds5nwa92gv5nw6ahjjlu8xudm2xs03784t", 12 | "accountNft": "neutron1jdpceeuzrptvrvvln3f72haxwl0w38peg6ux76wrm3d265ghne7se4wug2" 13 | } 14 | -------------------------------------------------------------------------------- /scripts/deploy/addresses/neutron-1-multisig-owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "address-provider": "neutron17yehp4x7n79zq9dlw4g7xmnrvwdjjj2yecq26844sg8yu74knlxqfx5vqv", 3 | "red-bank": "neutron1n97wnm7q6d2hrcna3rqlnyqw2we6k0l8uqvmyqq6gsml92epdu7quugyph", 4 | "incentives": "neutron1aszpdh35zsaz0yj80mz7f5dtl9zq5jfl8hgm094y0j0vsychfekqxhzd39", 5 | "oracle": "neutron1dwp6m7pdrz6rnhdyrx5ha0acsduydqcpzkylvfgspsz60pj2agxqaqrr7g", 6 | "rewards-collector": "neutron1h4l6rvylzcuxwdw3gzkkdzfjdxf4mv2ypfdgvnvag0dtz6x07gps6fl2vm", 7 | "swapper": "neutron1udr9fc3kd743dezrj38v2ac74pxxr6qsx4xt4nfpcfczgw52rvyqyjp5au" 8 | } 9 | -------------------------------------------------------------------------------- /scripts/deploy/addresses/osmosis-1-multisig-owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "address-provider": "osmo1g677w7mfvn78eeudzwylxzlyz69fsgumqrscj6tekhdvs8fye3asufmvxr", 3 | "red-bank": "osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg", 4 | "incentives": "osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm", 5 | "oracle": "osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g", 6 | "rewards-collector": "osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy", 7 | "swapper": "osmo1wee0z8c7tcawyl647eapqs4a88q8jpa7ddy6nn2nrs7t47p2zhxswetwla", 8 | "zapper": "osmo17qwvc70pzc9mudr8t02t3pl74hhqsgwnskl734p4hug3s8mkerdqzduf7c", 9 | "creditManager": "osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf", 10 | "accountNft": "osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09", 11 | "params": "osmo1nlmdxt9ctql2jr47qd4fpgzg84cjswxyw6q99u4y4u4q6c2f5ksq7ysent", 12 | "health": "osmo1pdc49qlyhpkzx4j24uuw97kk6hv7e9xvrdjlww8qj6al53gmu49sge4g79" 13 | } 14 | -------------------------------------------------------------------------------- /scripts/deploy/addresses/pion-1-deployer-owner.json: -------------------------------------------------------------------------------- 1 | { 2 | "addressProvider": "neutron1fq8rzmgn05etecpu2njdm9asqrgpgzw2cxw5lewq47n6y87ggd8qv7f2nm", 3 | "redBank": "neutron1s2vxnxqqjtjekenqmf46467anmz4ee40xz04a0qy743cq040nu6shzfhc2", 4 | "incentives": "neutron1sjhccp8mghedeepeshcmap677l4ytre589ucyep74jnyf4m6hyrqvy5vzd", 5 | "oracle": "neutron1qmkkhu2v6yzhqd2g6jlkegachpmvyzrg2355h0djw2eac5cscp7q83ce3u", 6 | "rewardsCollector": "neutron1rlmuc0xepd0l63jgnnkusskm3xp35mdq9ke3j8w60afj9lnrrztqngdw3t", 7 | "swapper": "neutron1zqhs7txm744466zd4vf9gznp8g2m4yyd28qcymeqpn65mmrj2r4sxlednd", 8 | "params": "neutron137u6mnz7jc7ums5a3efspz3mejas2wut5auuw8ln2pj4t9awhv6sav9ftn", 9 | "zapper": "neutron1thppkzst9x8xj9jwqshpl00q00f0tz7ehsfdh80qsk6dmj4nwrkqe2v9g6", 10 | "health": "neutron16dpjss982zglprngjgjzpkwt6q63326v69frsgrst9jv5d4wnr4slkukjz", 11 | "creditManager": "neutron1psu5z8c4359mz0dpgxzqgxpzfhjgjranktglfv42v5jkt8p56e9syc9nt5", 12 | "accountNft": "neutron1nt0e3p5u7rgukawvha0yfcwl9ytzp3qxjqs4shfkd74r77sw75rq5m0de4" 13 | } 14 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/devnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base/index.js' 2 | import { neutronDevnetConfig } from './devnet-config.js' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: neutronDevnetConfig, 7 | label: 'deployer-owner', 8 | }) 9 | })() 10 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/mainnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { neutronMainnetConfig } from './mainnet-config' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: neutronMainnetConfig, 7 | label: 'multisig-owner', 8 | }) 9 | })() 10 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/record-twap-snapshots.ts: -------------------------------------------------------------------------------- 1 | import { setupDeployer } from '../base/setup-deployer' 2 | import { neutronTestnetConfig } from './testnet-config' 3 | 4 | async function main() { 5 | const deployer = await setupDeployer(neutronTestnetConfig, '') 6 | 7 | await deployer.recordTwapSnapshots(['untrn']) 8 | } 9 | 10 | main() 11 | .then(() => process.exit(0)) 12 | .catch((error) => { 13 | console.error(error) 14 | process.exit(1) 15 | }) 16 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/set-price.ts: -------------------------------------------------------------------------------- 1 | import { setupDeployer } from '../base/setup-deployer' 2 | import { neutronTestnetConfig, atomOracle } from './testnet-config' 3 | 4 | async function main() { 5 | const deployer = await setupDeployer(neutronTestnetConfig, '') 6 | 7 | await deployer.setOracle(atomOracle) 8 | } 9 | 10 | main() 11 | .then(() => process.exit(0)) 12 | .catch((error) => { 13 | console.error(error) 14 | process.exit(1) 15 | }) 16 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/testnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { neutronTestnetConfig } from './testnet-config.js' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: neutronTestnetConfig, 7 | label: 'deployer-owner', 8 | }) 9 | })() 10 | -------------------------------------------------------------------------------- /scripts/deploy/neutron/testnet-multisig-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { neutronTestnetConfig } from './testnet-config' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: { 7 | ...neutronTestnetConfig, 8 | multisigAddr: 'neutron1ltzuv25ltw9mkwuvvmt7e54a6ene283hfj7l0c', 9 | }, 10 | label: 'multisig-owner', 11 | }) 12 | })() 13 | -------------------------------------------------------------------------------- /scripts/deploy/osmosis/devnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { osmo, osmosisMainnetConfig } from './mainnet-config' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: { 7 | ...osmosisMainnetConfig, 8 | mainnet: false, 9 | deployerMnemonic: 'TO BE INSERTED AT TIME OF DEPLOYMENT', 10 | chain: { 11 | baseDenom: osmo, 12 | defaultGasPrice: 0.1, 13 | id: 'devnet', 14 | prefix: 'osmo', 15 | rpcEndpoint: 'https://rpc.devnet.osmosis.zone', 16 | }, 17 | runTests: true, 18 | }, 19 | label: 'deployer-owner', 20 | }) 21 | })() 22 | -------------------------------------------------------------------------------- /scripts/deploy/osmosis/mainnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { osmosisMainnetConfig } from './mainnet-config' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: { 7 | ...osmosisMainnetConfig, 8 | deployerMnemonic: 'TO BE INSERTED AT TIME OF DEPLOYMENT', 9 | multisigAddr: 'osmo14w4x949nwcrqgfe53pxs3k7x53p0gvlrq34l5n', 10 | }, 11 | label: 'multisig-owner', 12 | }) 13 | })() 14 | -------------------------------------------------------------------------------- /scripts/deploy/osmosis/testnet-index.ts: -------------------------------------------------------------------------------- 1 | import { taskRunner } from '../base' 2 | import { osmosisTestnetConfig } from './testnet-config' 3 | 4 | void (async function () { 5 | await taskRunner({ 6 | config: osmosisTestnetConfig, 7 | label: 'deployer-owner', 8 | }) 9 | })() 10 | -------------------------------------------------------------------------------- /scripts/health/pkg-web/index_bg.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mars-protocol/contracts/430d7969d38653df2da8b4a06e83800299f8cff7/scripts/health/pkg-web/index_bg.wasm -------------------------------------------------------------------------------- /scripts/health/pkg-web/index_bg.wasm.d.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | export const memory: WebAssembly.Memory 4 | export function compute_health_js(a: number): number 5 | export function max_withdraw_estimate_js(a: number, b: number, c: number, d: number): void 6 | export function max_borrow_estimate_js(a: number, b: number, c: number, d: number, e: number): void 7 | export function max_swap_estimate_js( 8 | a: number, 9 | b: number, 10 | c: number, 11 | d: number, 12 | e: number, 13 | f: number, 14 | g: number, 15 | h: number, 16 | ): void 17 | export function liquidation_price_js(a: number, b: number, c: number, d: number, e: number): void 18 | export function interface_version_8(): void 19 | export function allocate(a: number): number 20 | export function deallocate(a: number): void 21 | export function requires_stargate(): void 22 | export function requires_iterator(): void 23 | export function __wbindgen_malloc(a: number, b: number): number 24 | export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number 25 | export function __wbindgen_add_to_stack_pointer(a: number): number 26 | export function __wbindgen_free(a: number, b: number, c: number): void 27 | export function __wbindgen_exn_store(a: number): void 28 | -------------------------------------------------------------------------------- /scripts/health/pkg-web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mars-rover-health-computer", 3 | "collaborators": [ 4 | "Gabe R. ", 5 | "Larry Engineer ", 6 | "Piotr B. ", 7 | "Bob v.d. H. ", 8 | "Mark Watney ", 9 | "Spike Spiegel ", 10 | "Brianna M. ", 11 | "Ahmad Kaouk", 12 | "Harry Scholes" 13 | ], 14 | "version": "2.0.0", 15 | "files": [ 16 | "index_bg.wasm", 17 | "index.js", 18 | "index.d.ts" 19 | ], 20 | "module": "index.js", 21 | "types": "index.d.ts", 22 | "sideEffects": [ 23 | "./snippets/*" 24 | ], 25 | "keywords": [ 26 | "mars", 27 | "cosmos", 28 | "cosmwasm" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /scripts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2021", 4 | "lib": ["ES2021"], 5 | "types": ["node"], 6 | "module": "NodeNext", 7 | "declaration": true, 8 | "noImplicitAny": true, 9 | "removeComments": true, 10 | "experimentalDecorators": true, 11 | "outDir": "./build", 12 | "sourceMap": true, 13 | "noEmitOnError": true, 14 | "esModuleInterop": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "strict": true, 17 | "noEmit": false, 18 | "moduleResolution": "NodeNext", 19 | "isolatedModules": true, 20 | "resolveJsonModule": true, 21 | "noUnusedLocals": true, 22 | "noUnusedParameters": true, 23 | "noImplicitReturns": true, 24 | "noImplicitThis": true, 25 | "strictNullChecks": true, 26 | "allowSyntheticDefaultImports": true, 27 | "skipLibCheck": true, 28 | "allowJs": true 29 | }, 30 | "include": ["**/*.ts", "**/*.tsx", "types.d.ts"], 31 | "exclude": ["node_modules", "./build/**/*", "types/generated/**/*"] 32 | } 33 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-account-nft/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _0 from './MarsAccountNft.types' 9 | import * as _1 from './MarsAccountNft.client' 10 | import * as _2 from './MarsAccountNft.react-query' 11 | export namespace contracts { 12 | export const MarsAccountNft = { 13 | ..._0, 14 | ..._1, 15 | ..._2, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-address-provider/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _3 from './MarsAddressProvider.types' 9 | import * as _4 from './MarsAddressProvider.client' 10 | import * as _5 from './MarsAddressProvider.react-query' 11 | export namespace contracts { 12 | export const MarsAddressProvider = { 13 | ..._3, 14 | ..._4, 15 | ..._5, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-credit-manager/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _6 from './MarsCreditManager.types' 9 | import * as _7 from './MarsCreditManager.client' 10 | import * as _8 from './MarsCreditManager.react-query' 11 | export namespace contracts { 12 | export const MarsCreditManager = { 13 | ..._6, 14 | ..._7, 15 | ..._8, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-incentives/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _9 from './MarsIncentives.types' 9 | import * as _10 from './MarsIncentives.client' 10 | import * as _11 from './MarsIncentives.react-query' 11 | export namespace contracts { 12 | export const MarsIncentives = { 13 | ..._9, 14 | ..._10, 15 | ..._11, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-mock-vault/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _12 from './MarsMockVault.types' 9 | import * as _13 from './MarsMockVault.client' 10 | import * as _14 from './MarsMockVault.react-query' 11 | export namespace contracts { 12 | export const MarsMockVault = { 13 | ..._12, 14 | ..._13, 15 | ..._14, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-oracle-osmosis/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _15 from './MarsOracleOsmosis.types' 9 | import * as _16 from './MarsOracleOsmosis.client' 10 | import * as _17 from './MarsOracleOsmosis.react-query' 11 | export namespace contracts { 12 | export const MarsOracleOsmosis = { 13 | ..._15, 14 | ..._16, 15 | ..._17, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-oracle-wasm/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _18 from './MarsOracleWasm.types' 9 | import * as _19 from './MarsOracleWasm.client' 10 | import * as _20 from './MarsOracleWasm.react-query' 11 | export namespace contracts { 12 | export const MarsOracleWasm = { 13 | ..._18, 14 | ..._19, 15 | ..._20, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-params/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _21 from './MarsParams.types' 9 | import * as _22 from './MarsParams.client' 10 | import * as _23 from './MarsParams.react-query' 11 | export namespace contracts { 12 | export const MarsParams = { 13 | ..._21, 14 | ..._22, 15 | ..._23, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-red-bank/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _24 from './MarsRedBank.types' 9 | import * as _25 from './MarsRedBank.client' 10 | import * as _26 from './MarsRedBank.react-query' 11 | export namespace contracts { 12 | export const MarsRedBank = { 13 | ..._24, 14 | ..._25, 15 | ..._26, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-rewards-collector-base/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _27 from './MarsRewardsCollectorBase.types' 9 | import * as _28 from './MarsRewardsCollectorBase.client' 10 | import * as _29 from './MarsRewardsCollectorBase.react-query' 11 | export namespace contracts { 12 | export const MarsRewardsCollectorBase = { 13 | ..._27, 14 | ..._28, 15 | ..._29, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.client.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import { 9 | HlsAssetTypeForAddr, 10 | Addr, 11 | Decimal, 12 | Uint128, 13 | AccountKind, 14 | VaultPositionAmount, 15 | VaultAmount, 16 | VaultAmount1, 17 | UnlockingPositions, 18 | HealthComputer, 19 | DenomsData, 20 | AssetParamsBaseForAddr, 21 | CmSettingsForAddr, 22 | HlsParamsBaseForAddr, 23 | LiquidationBonus, 24 | RedBankSettings, 25 | Positions, 26 | DebtAmount, 27 | Coin, 28 | VaultPosition, 29 | LockingVaultAmount, 30 | VaultUnlockingPosition, 31 | VaultBaseForAddr, 32 | VaultsData, 33 | VaultConfigBaseForAddr, 34 | VaultPositionValue, 35 | CoinValue, 36 | } from './MarsRoverHealthComputer.types' 37 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.react-query.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import { 9 | HlsAssetTypeForAddr, 10 | Addr, 11 | Decimal, 12 | Uint128, 13 | AccountKind, 14 | VaultPositionAmount, 15 | VaultAmount, 16 | VaultAmount1, 17 | UnlockingPositions, 18 | HealthComputer, 19 | DenomsData, 20 | AssetParamsBaseForAddr, 21 | CmSettingsForAddr, 22 | HlsParamsBaseForAddr, 23 | LiquidationBonus, 24 | RedBankSettings, 25 | Positions, 26 | DebtAmount, 27 | Coin, 28 | VaultPosition, 29 | LockingVaultAmount, 30 | VaultUnlockingPosition, 31 | VaultBaseForAddr, 32 | VaultsData, 33 | VaultConfigBaseForAddr, 34 | VaultPositionValue, 35 | CoinValue, 36 | } from './MarsRoverHealthComputer.types' 37 | import './MarsRoverHealthComputer.client' 38 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-rover-health-computer/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _33 from './MarsRoverHealthComputer.types' 9 | import * as _34 from './MarsRoverHealthComputer.client' 10 | import * as _35 from './MarsRoverHealthComputer.react-query' 11 | export namespace contracts { 12 | export const MarsRoverHealthComputer = { 13 | ..._33, 14 | ..._34, 15 | ..._35, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-rover-health/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _30 from './MarsRoverHealth.types' 9 | import * as _31 from './MarsRoverHealth.client' 10 | import * as _32 from './MarsRoverHealth.react-query' 11 | export namespace contracts { 12 | export const MarsRoverHealth = { 13 | ..._30, 14 | ..._31, 15 | ..._32, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-swapper-astroport/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _36 from './MarsSwapperAstroport.types' 9 | import * as _37 from './MarsSwapperAstroport.client' 10 | import * as _38 from './MarsSwapperAstroport.react-query' 11 | export namespace contracts { 12 | export const MarsSwapperAstroport = { 13 | ..._36, 14 | ..._37, 15 | ..._38, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-swapper-base/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _39 from './MarsSwapperBase.types' 9 | import * as _40 from './MarsSwapperBase.client' 10 | import * as _41 from './MarsSwapperBase.react-query' 11 | export namespace contracts { 12 | export const MarsSwapperBase = { 13 | ..._39, 14 | ..._40, 15 | ..._41, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-swapper-osmosis/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _42 from './MarsSwapperOsmosis.types' 9 | import * as _43 from './MarsSwapperOsmosis.client' 10 | import * as _44 from './MarsSwapperOsmosis.react-query' 11 | export namespace contracts { 12 | export const MarsSwapperOsmosis = { 13 | ..._42, 14 | ..._43, 15 | ..._44, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-vault/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _45 from './MarsVault.types' 9 | import * as _46 from './MarsVault.client' 10 | import * as _47 from './MarsVault.react-query' 11 | export namespace contracts { 12 | export const MarsVault = { 13 | ..._45, 14 | ..._46, 15 | ..._47, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-zapper-base/MarsZapperBase.types.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | export interface InstantiateMsg {} 9 | export type ExecuteMsg = 10 | | { 11 | provide_liquidity: { 12 | lp_token_out: string 13 | minimum_receive: Uint128 14 | recipient?: string | null 15 | } 16 | } 17 | | { 18 | withdraw_liquidity: { 19 | minimum_receive: Coin[] 20 | recipient?: string | null 21 | } 22 | } 23 | | { 24 | callback: CallbackMsg 25 | } 26 | export type Uint128 = string 27 | export type CallbackMsg = { 28 | return_coin: { 29 | balance_before: Coin 30 | recipient: Addr 31 | } 32 | } 33 | export type Addr = string 34 | export interface Coin { 35 | amount: Uint128 36 | denom: string 37 | [k: string]: unknown 38 | } 39 | export type QueryMsg = 40 | | { 41 | estimate_provide_liquidity: { 42 | coins_in: Coin[] 43 | lp_token_out: string 44 | } 45 | } 46 | | { 47 | estimate_withdraw_liquidity: { 48 | coin_in: Coin 49 | } 50 | } 51 | export type ArrayOfCoin = Coin[] 52 | -------------------------------------------------------------------------------- /scripts/types/generated/mars-zapper-base/bundle.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | /** 3 | * This file was automatically generated by @cosmwasm/ts-codegen@1.10.0. 4 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, 5 | * and run the @cosmwasm/ts-codegen generate command to regenerate this file. 6 | */ 7 | 8 | import * as _48 from './MarsZapperBase.types' 9 | import * as _49 from './MarsZapperBase.client' 10 | import * as _50 from './MarsZapperBase.react-query' 11 | export namespace contracts { 12 | export const MarsZapperBase = { 13 | ..._48, 14 | ..._49, 15 | ..._50, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/types/storageItems.ts: -------------------------------------------------------------------------------- 1 | export interface StorageItems { 2 | codeIds: { 3 | accountNft?: number 4 | addressProvider?: number 5 | creditManager?: number 6 | health?: number 7 | incentives?: number 8 | mockVault?: number 9 | oracle?: number 10 | params?: number 11 | swapper?: number 12 | redBank?: number 13 | rewardsCollector?: number 14 | zapper?: number 15 | } 16 | 17 | addresses: { 18 | accountNft?: string 19 | addressProvider?: string 20 | creditManager?: string 21 | health?: string 22 | incentives?: string 23 | mockVault?: string 24 | oracle?: string 25 | params?: string 26 | swapper?: string 27 | redBank?: string 28 | rewardsCollector?: string 29 | zapper?: string 30 | } 31 | 32 | actions: { 33 | addressProviderSet: Record 34 | proposedNewOwner?: boolean 35 | acceptedOwnership?: boolean 36 | seedMockVault?: boolean 37 | grantedCreditLines?: boolean 38 | redBankMarketsSet: string[] 39 | assetsSet: string[] 40 | vaultsSet: string[] 41 | oraclePricesSet: string[] 42 | routesSet: string[] 43 | healthContractConfigUpdate?: boolean 44 | creditManagerContractConfigUpdate?: boolean 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /scripts/utils/chalk.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk' 2 | 3 | export const printRed = (text: unknown) => { 4 | console.log(chalk.red(text)) 5 | } 6 | 7 | export const printBlue = (text: string) => { 8 | console.log(chalk.blue(text)) 9 | } 10 | 11 | export const printGreen = (text: string) => { 12 | console.log(chalk.green(text)) 13 | } 14 | 15 | export const printYellow = (text: string) => { 16 | console.log(chalk.yellow(text)) 17 | } 18 | 19 | export const printGray = (text: string) => { 20 | console.log(chalk.gray(text)) 21 | } 22 | -------------------------------------------------------------------------------- /scripts/utils/environment.ts: -------------------------------------------------------------------------------- 1 | import os from 'os' 2 | 3 | // for m1 macs, the binaries should look like: rover-aarch64.wasm vs rover.wasm 4 | export const wasmFile = (contractName: string) => { 5 | let fileStr = contractName 6 | const env = os.arch() 7 | if (env === 'arm64') { 8 | fileStr += '-aarch64' 9 | } 10 | fileStr += '.wasm' 11 | return fileStr 12 | } 13 | --------------------------------------------------------------------------------