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

feat: make enactment optional, add getTrack to referendum. #2

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions packages/sdk-governance/src/referenda/referenda-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export function createReferendaSdk(

return confirmationStart + track.confirm_period
},
async getTrack() {
const track = await getTrack(referendum.track)
if (!track) {
// Should never happen
throw new Error("Track not found")
}
return track
},
}
}

Expand Down Expand Up @@ -156,12 +164,18 @@ export function createReferendaSdk(

const createReferenda: ReferendaSdk["createReferenda"] = (
origin,
enactment,
proposal,
options,
) => {
// The pallet already calculates uses the earliest_allowed in case it's too small
const enactment_moment = options?.enactment ?? {
type: "After",
value: 0,
}

if (proposal.asBytes().length <= MAX_INLINE_SIZE) {
return typedApi.tx.Referenda.submit({
enactment_moment: enactment,
enactment_moment,
proposal: {
type: "Inline",
value: proposal,
Expand All @@ -180,7 +194,7 @@ export function createReferendaSdk(
bytes: proposal,
}).decodedCall,
typedApi.tx.Referenda.submit({
enactment_moment: enactment,
enactment_moment,
proposal: {
type: "Lookup",
value: {
Expand All @@ -200,14 +214,7 @@ export function createReferendaSdk(
) => {
const spenderTrack = getSpenderTrack(value)

return createReferenda(
spenderTrack.origin,
{
type: "After",
value: 0,
},
callData,
)
return createReferenda(spenderTrack.origin, callData)
}

const getSubmittedReferendum = (txEvent: TxEvent) =>
Expand Down
5 changes: 4 additions & 1 deletion packages/sdk-governance/src/referenda/sdk-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type OngoingReferendum = Omit<RawOngoingReferendum, "proposal"> & {
getDetails: (apiKey: string) => Promise<ReferendumDetails>
getConfirmationStart: () => Promise<number | null>
getConfirmationEnd: () => Promise<number | null>
getTrack: () => Promise<ReferendaTrack>
}

export interface ReferendaSdkConfig {
Expand Down Expand Up @@ -68,8 +69,10 @@ export interface ReferendaSdk {

createReferenda(
origin: PolkadotRuntimeOriginCaller,
enactment: TraitsScheduleDispatchTime,
proposal: Binary,
options?: Partial<{
enactment: TraitsScheduleDispatchTime
}>,
): Transaction<any, string, string, unknown>
createSpenderReferenda(
callData: Binary,
Expand Down
Loading