Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add base_asset to Market structure and make prediction_markets pallet use it instead of Asset::Ztg #894

Merged
merged 34 commits into from Jan 19, 2023

Conversation

vivekvpandya
Copy link
Contributor

@vivekvpandya vivekvpandya commented Dec 1, 2022

Fixes #226

@vivekvpandya vivekvpandya added the s:in-progress The pull requests is currently being worked on label Dec 1, 2022
@vivekvpandya vivekvpandya self-assigned this Dec 1, 2022
@vivekvpandya vivekvpandya added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Dec 6, 2022
@vivekvpandya vivekvpandya marked this pull request as ready for review December 6, 2022 10:14
Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

Essentially this is a great work to allow different base assets in prediction markets. I think about unintended consequences....

zrml/prediction-markets/src/tests.rs Outdated Show resolved Hide resolved
zrml/market-commons/src/migrations.rs Outdated Show resolved Hide resolved
@maltekliemann maltekliemann added the p:high High priority, prioritize the resolution of this issue label Dec 13, 2022
Copy link
Member

@maltekliemann maltekliemann left a comment

Choose a reason for hiding this comment

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

Just passing through and leaving a couple of hopefully useful comments. Do you understand what the purpose of using the __private prefix on the imports in the orml_mock_registry module is?

zrml/prediction-markets/src/lib.rs Outdated Show resolved Hide resolved
zrml/prediction-markets/src/tests.rs Outdated Show resolved Hide resolved
zrml/market-commons/src/migrations.rs Outdated Show resolved Hide resolved
primitives/src/market.rs Outdated Show resolved Hide resolved
primitives/src/types.rs Outdated Show resolved Hide resolved
zrml/prediction-markets/src/mock.rs Outdated Show resolved Hide resolved
zrml/prediction-markets/src/mock.rs Show resolved Hide resolved
@Chralt98 Chralt98 added the i:transactions-changed ⚠️ Implies change in transaction version label Dec 20, 2022
Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

Looks okay, when you ask me. I am waiting until the conversations with Malte are resolved.

primitives/src/types.rs Outdated Show resolved Hide resolved
zrml/market-commons/src/migrations.rs Outdated Show resolved Hide resolved
zrml/prediction-markets/src/lib.rs Outdated Show resolved Hide resolved
@maltekliemann maltekliemann added this to the v0.3.8 milestone Jan 16, 2023
Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

Looks pretty good to allow different assets as the denominator in prediction markets.

"parity-scale-codec/std",
"serde/std",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"serde/std",
"serde?/std",

The package serde has also got optional = true. Am I missing something?

zrml/prediction-markets/src/tests.rs Show resolved Hide resolved
zrml/prediction-markets/src/tests.rs Show resolved Hide resolved
zrml/prediction-markets/src/tests.rs Show resolved Hide resolved
@Chralt98
Copy link
Member

Really great work here Vivek! Love that.

sea212
sea212 previously approved these changes Jan 17, 2023
Copy link
Member

@maltekliemann maltekliemann left a comment

Choose a reason for hiding this comment

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

  • It seems like the CI doesn't run the tests with parachain; it only runs check. I guess you could add

    cargo test -p zrml-prediction-markets --features parachain
    

    to misc.sh (not sure what the exact structure of those scripts is).

  • One test is still failing.

  • Is there a test for create_market failing if an invalid base asset is specified?

  • There are some comments above that are still unaccounted for.

zrml/prediction-markets/src/tests.rs Show resolved Hide resolved
let oracle_bond = <Runtime as Config>::OracleBond::get();
// substract min_liquidity twice, one for buy_complete_set() in
// create_cpmm_market_and_deploy_assets() and one in swaps::create_pool()
// then again substract BASE as buy_complete_set() on line 786
Copy link
Member

Choose a reason for hiding this comment

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

Referring to specific lines in comments is a bad idea.

Comment on lines 1998 to 2009
// check native balance
let bal = Balances::free_balance(&BOB);
assert_eq!(bal, 1_000 * BASE - CENT);

let market_bal = Balances::free_balance(market_account);
assert_eq!(market_bal, CENT);
} else {
let bal = Tokens::free_balance(base_asset, &BOB);
assert_eq!(bal, 1_000 * BASE - CENT);

let market_bal = Tokens::free_balance(base_asset, &market_account);
assert_eq!(market_bal, CENT);
Copy link
Member

Choose a reason for hiding this comment

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

Could have used AssetManager::free_balance and then used base_asset to avoid this if.

@vivekvpandya
Copy link
Contributor Author

  • Is there a test for create_market failing if an invalid base asset is specified?

please check test create_market_with_foreign_assets() it covers to failure where if a FA is not registered in AssetRegistry and if FA is registered but in metadata its not allowed to be used as base_asset.

@codecov-commenter
Copy link

codecov-commenter commented Jan 18, 2023

Codecov Report

Merging #894 (77b78e4) into main (5a7feaf) will decrease coverage by 0.28%.
The diff coverage is 50.58%.

@@            Coverage Diff             @@
##             main     #894      +/-   ##
==========================================
- Coverage   94.70%   94.42%   -0.28%     
==========================================
  Files          92       93       +1     
  Lines       19368    20258     +890     
==========================================
+ Hits        18342    19129     +787     
- Misses       1026     1129     +103     
Flag Coverage Δ
tests 94.42% <50.58%> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
primitives/src/types.rs 3.12% <0.00%> (-30.21%) ⬇️
zrml/authorized/src/mock.rs 37.50% <0.00%> (-3.41%) ⬇️
zrml/court/src/lib.rs 87.71% <ø> (ø)
zrml/court/src/mock.rs 33.33% <0.00%> (-3.51%) ⬇️
zrml/court/src/tests.rs 99.20% <ø> (ø)
zrml/market-commons/src/lib.rs 93.42% <ø> (ø)
zrml/market-commons/src/migrations.rs 0.00% <0.00%> (ø)
zrml/prediction-markets/src/tests.rs 99.29% <ø> (-0.60%) ⬇️
zrml/simple-disputes/src/lib.rs 77.77% <ø> (ø)
zrml/simple-disputes/src/mock.rs 8.69% <0.00%> (-1.31%) ⬇️
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@Chralt98 Chralt98 left a comment

Choose a reason for hiding this comment

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

LGTM

scripts/tests/aux-functions.sh Show resolved Hide resolved
scripts/tests/misc.sh Show resolved Hide resolved
zrml/prediction-markets/src/tests.rs Show resolved Hide resolved
Copy link
Member

@maltekliemann maltekliemann left a comment

Choose a reason for hiding this comment

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

Looks good now.

Just one question (I may have asked this before): Why are we using the parachain feature to begin with? Edit. Seems to me like parachain can be removed from zrml_prediction_markets. Only price to pay is longer compiler times since you need some XCM imports. Seems worth it, though. Am I wrong about this?

@sea212

@vivekvpandya
Copy link
Contributor Author

Looks good now.

Just one question (I may have asked this before): Why are we using the parachain feature to begin with? Edit. Seems to me like parachain can be removed from zrml_prediction_markets. Only price to pay is longer compiler times since you need some XCM imports. Seems worth it, though. Am I wrong about this?

Perhaps it would also bring in some testing time too as there will be XCM tests.
But I think that can be done in separate PR. I think it is better to conclude this PR at this point.

@vivekvpandya vivekvpandya added s:accepted This pull request is ready for merge and removed s:review-needed The pull request requires reviews labels Jan 19, 2023
@vivekvpandya vivekvpandya merged commit b77b5ac into main Jan 19, 2023
@vivekvpandya vivekvpandya deleted the issue-226 branch January 19, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i:transactions-changed ⚠️ Implies change in transaction version p:high High priority, prioritize the resolution of this issue s:accepted This pull request is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PM]PredictionMarkets can use any approved token as a base currency
6 participants