Skip to content

Commit

Permalink
feat: make enactment optional, add getTrack to referendum.
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Jan 15, 2025
1 parent b585d7e commit 95b4db8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
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

0 comments on commit 95b4db8

Please sign in to comment.