Skip to content

Commit

Permalink
Add extrinsics for editing markets (#834)
Browse files Browse the repository at this point in the history
* Add extrinsics for editing markets

* Minor fixes after review

* Address review comments

* More changes as per reviews

* Fix format

* Address review comments

* Address review comments

* Update changelog_for_devs.md

* Address review comments

* Fix time complexity of edit market in comment
  • Loading branch information
vivekvpandya committed Oct 31, 2022
1 parent fce4636 commit 01f4fbf
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 131 deletions.
9 changes: 9 additions & 0 deletions docs/changelog_for_devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
`Vec<u8>`. The config constant `MaxRejectReasonLen` defines maximum length of
above parameter. `MarketRejected` event also contains `reject_reason` so that
it can be cached for market creator.
- `request_edit` extrinsic added, which enables a user satisfying
`RequestEditOrigin` to request edit in market with `Proposed` state, when
successful it emits `MarketRequestedEdit` event. `request_edit` requires
`edit_reason` parameter which is `Vec<u8>`. The config constant
`MaxEditReasonLen` defines maximum length of above parameter. The
`MarketRequestedEdit` event also contains `edit_reason`.
- `edit_market` extrinsic added, which enables creator of the market to edit
market. It has same parameters as `create_market` except market_creation, on
success it returns `MarketEdited` event.

# v0.3.6

Expand Down
1 change: 1 addition & 0 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ parameter_types! {
pub const MaxDisputeDuration: BlockNumber = 5;
pub const MaxGracePeriod: BlockNumber = 2;
pub const MaxOracleDuration: BlockNumber = 3;
pub const MaxEditReasonLen: u32 = 1024;
pub const MaxRejectReasonLen: u32 = 1024;
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ parameter_types! {
/// (Slashable) A bond for creation markets that do not require approval. Slashed in case
/// the market is forcefully destroyed.
pub const ValidityBond: Balance = 50 * CENT;
/// Maximum string length for edit reason.
pub const MaxEditReasonLen: u32 = 1024;
/// Maximum string length allowed for reject reason.
pub const MaxRejectReasonLen: u32 = 1024;

Expand Down
5 changes: 5 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,11 +947,16 @@ macro_rules! impl_config_traits {
type MaxMarketPeriod = MaxMarketPeriod;
type MinCategories = MinCategories;
type MinSubsidyPeriod = MinSubsidyPeriod;
type MaxEditReasonLen = MaxEditReasonLen;
type MaxRejectReasonLen = MaxRejectReasonLen;
type OracleBond = OracleBond;
type PalletId = PmPalletId;
type RejectOrigin = EnsureRootOrHalfAdvisoryCommittee;
type ReportingPeriod = ReportingPeriod;
type RequestEditOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureMember<AccountId, AdvisoryCommitteeInstance>,
>;
type ResolveOrigin = EnsureRoot<AccountId>;
type AssetManager = AssetManager;
type SimpleDisputes = SimpleDisputes;
Expand Down
2 changes: 2 additions & 0 deletions runtime/zeitgeist/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ parameter_types! {
/// (Slashable) A bond for creation markets that do not require approval. Slashed in case
/// the market is forcefully destroyed.
pub const ValidityBond: Balance = 1_000 * BASE;
/// Maximum string length for edit reason.
pub const MaxEditReasonLen: u32 = 1024;
/// Maximum string length allowed for reject reason.
pub const MaxRejectReasonLen: u32 = 1024;

Expand Down
68 changes: 67 additions & 1 deletion zrml/prediction-markets/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,20 @@ benchmarks! {
let call = Call::<T>::approve_market { market_id };
}: { call.dispatch_bypass_filter(approve_origin)? }

request_edit {
let r in 0..<T as Config>::MaxEditReasonLen::get();
let (_, market_id) = create_market_common::<T>(
MarketCreation::Advised,
MarketType::Categorical(T::MaxCategories::get()),
ScoringRule::CPMM,
None,
)?;

let approve_origin = T::ApproveOrigin::successful_origin();
let edit_reason = vec![0_u8; r as usize];
let call = Call::<T>::request_edit{ market_id, edit_reason };
}: { call.dispatch_bypass_filter(approve_origin)? }

buy_complete_set {
let a in (T::MinCategories::get().into())..T::MaxCategories::get().into();
let (caller, market_id) = create_market_common::<T>(
Expand Down Expand Up @@ -599,7 +613,59 @@ benchmarks! {
MarketType::Categorical(T::MaxCategories::get()),
MarketDisputeMechanism::SimpleDisputes,
ScoringRule::CPMM
)
)

edit_market {
let m in 0..63;

let market_type = MarketType::Categorical(T::MaxCategories::get());
let dispute_mechanism = MarketDisputeMechanism::SimpleDisputes;
let scoring_rule = ScoringRule::CPMM;
let range_start: MomentOf<T> = 100_000u64.saturated_into();
let range_end: MomentOf<T> = 1_000_000u64.saturated_into();
let period = MarketPeriod::Timestamp(range_start..range_end);
let (caller, oracle, deadlines, metadata, creation) =
create_market_common_parameters::<T>(MarketCreation::Advised)?;
Call::<T>::create_market {
oracle: oracle.clone(),
period: period.clone(),
deadlines,
metadata: metadata.clone(),
creation,
market_type: market_type.clone(),
dispute_mechanism: dispute_mechanism.clone(),
scoring_rule,
}
.dispatch_bypass_filter(RawOrigin::Signed(caller.clone()).into())?;
let market_id = T::MarketCommons::latest_market_id()?;

let approve_origin = T::ApproveOrigin::successful_origin();
let edit_reason = vec![0_u8; 1024];
Call::<T>::request_edit{ market_id, edit_reason }
.dispatch_bypass_filter(approve_origin)?;

for i in 0..m {
MarketIdsPerCloseTimeFrame::<T>::try_mutate(
Pallet::<T>::calculate_time_frame_of_moment(range_end),
|ids| ids.try_push(i.into()),
).unwrap();
}
let new_deadlines = Deadlines::<T::BlockNumber> {
grace_period: 2_u32.into(),
oracle_duration: T::MinOracleDuration::get(),
dispute_duration: T::MinDisputeDuration::get(),
};
}: _(
RawOrigin::Signed(caller),
market_id,
oracle,
period,
new_deadlines,
metadata,
market_type,
dispute_mechanism,
scoring_rule
)

deploy_swap_pool_for_market_future_pool {
let a in (T::MinCategories::get().into())..T::MaxCategories::get().into();
Expand Down
Loading

0 comments on commit 01f4fbf

Please sign in to comment.