Skip to content

Commit

Permalink
Update nns governance did (+request, response converters)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrasinskis committed Jul 28, 2023
1 parent e3e964f commit 325dabc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 3 deletions.
18 changes: 18 additions & 0 deletions packages/nns/candid/governance.certified.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,24 @@ export const idlFactory = ({ IDL }) => {
'dissolve_delay_interval' : IDL.Opt(Duration),
'count' : IDL.Opt(IDL.Nat64),
});
const GlobalTimeOfDay = IDL.Record({
'seconds_after_utc_midnight' : IDL.Opt(IDL.Nat64),
});
const Countries = IDL.Record({ 'iso_codes' : IDL.Vec(IDL.Text) });
const SwapParameters = IDL.Record({
'minimum_participants' : IDL.Opt(IDL.Nat64),
'duration' : IDL.Opt(Duration),
'neuron_basket_construction_parameters' : IDL.Opt(
NeuronBasketConstructionParameters
),
'confirmation_text' : IDL.Opt(IDL.Text),
'maximum_participant_icp' : IDL.Opt(Tokens),
'neurons_fund_investment' : IDL.Opt(Tokens),
'minimum_icp' : IDL.Opt(Tokens),
'minimum_participant_icp' : IDL.Opt(Tokens),
'start_time' : IDL.Opt(GlobalTimeOfDay),
'maximum_icp' : IDL.Opt(Tokens),
'restricted_countries' : IDL.Opt(Countries),
});
const SwapDistribution = IDL.Record({ 'total' : IDL.Opt(Tokens) });
const NeuronDistribution = IDL.Record({
Expand Down Expand Up @@ -906,15 +915,24 @@ export const init = ({ IDL }) => {
'dissolve_delay_interval' : IDL.Opt(Duration),
'count' : IDL.Opt(IDL.Nat64),
});
const GlobalTimeOfDay = IDL.Record({
'seconds_after_utc_midnight' : IDL.Opt(IDL.Nat64),
});
const Countries = IDL.Record({ 'iso_codes' : IDL.Vec(IDL.Text) });
const SwapParameters = IDL.Record({
'minimum_participants' : IDL.Opt(IDL.Nat64),
'duration' : IDL.Opt(Duration),
'neuron_basket_construction_parameters' : IDL.Opt(
NeuronBasketConstructionParameters
),
'confirmation_text' : IDL.Opt(IDL.Text),
'maximum_participant_icp' : IDL.Opt(Tokens),
'neurons_fund_investment' : IDL.Opt(Tokens),
'minimum_icp' : IDL.Opt(Tokens),
'minimum_participant_icp' : IDL.Opt(Tokens),
'start_time' : IDL.Opt(GlobalTimeOfDay),
'maximum_icp' : IDL.Opt(Tokens),
'restricted_countries' : IDL.Opt(Countries),
});
const SwapDistribution = IDL.Record({ 'total' : IDL.Opt(Tokens) });
const NeuronDistribution = IDL.Record({
Expand Down
11 changes: 11 additions & 0 deletions packages/nns/candid/governance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export interface Committed {
export interface Configure {
operation: [] | [Operation];
}
export interface Countries {
iso_codes: Array<string>;
}
export interface CreateServiceNervousSystem {
url: [] | [string];
governance_parameters: [] | [GovernanceParameters];
Expand Down Expand Up @@ -175,6 +178,9 @@ export interface Follow {
export interface Followees {
followees: Array<NeuronId>;
}
export interface GlobalTimeOfDay {
seconds_after_utc_midnight: [] | [bigint];
}
export interface Governance {
default_followees: Array<[number, Followees]>;
most_recent_monthly_node_provider_rewards:
Expand Down Expand Up @@ -566,13 +572,18 @@ export interface SwapDistribution {
}
export interface SwapParameters {
minimum_participants: [] | [bigint];
duration: [] | [Duration];
neuron_basket_construction_parameters:
| []
| [NeuronBasketConstructionParameters];
confirmation_text: [] | [string];
maximum_participant_icp: [] | [Tokens];
neurons_fund_investment: [] | [Tokens];
minimum_icp: [] | [Tokens];
minimum_participant_icp: [] | [Tokens];
start_time: [] | [GlobalTimeOfDay];
maximum_icp: [] | [Tokens];
restricted_countries: [] | [Countries];
}
export interface Tally {
no: bigint;
Expand Down
9 changes: 8 additions & 1 deletion packages/nns/candid/governance.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from IC repo commit b9fc66eafca530e997313aa68aaac31d41e6a875 'rs/nns/governance/canister/governance.did' by import-candid
// Generated from IC repo commit 509bc5a87192031915768db6e24647cc26f86069 'rs/nns/governance/canister/governance.did' by import-candid
type AccountIdentifier = record { hash : vec nat8 };
type Action = variant {
RegisterKnownNeuron : KnownNeuron;
Expand Down Expand Up @@ -98,6 +98,7 @@ type Command_2 = variant {
};
type Committed = record { sns_governance_canister_id : opt principal };
type Configure = record { operation : opt Operation };
type Countries = record { iso_codes : vec text };
type CreateServiceNervousSystem = record {
url : opt text;
governance_parameters : opt GovernanceParameters;
Expand Down Expand Up @@ -136,6 +137,7 @@ type Duration = record { seconds : opt nat64 };
type ExecuteNnsFunction = record { nns_function : int32; payload : vec nat8 };
type Follow = record { topic : int32; followees : vec NeuronId };
type Followees = record { followees : vec NeuronId };
type GlobalTimeOfDay = record { seconds_after_utc_midnight : opt nat64 };
type Governance = record {
default_followees : vec record { int32; Followees };
most_recent_monthly_node_provider_rewards : opt MostRecentMonthlyNodeProviderRewards;
Expand Down Expand Up @@ -475,11 +477,16 @@ type SwapBackgroundInformation = record {
type SwapDistribution = record { total : opt Tokens };
type SwapParameters = record {
minimum_participants : opt nat64;
duration : opt Duration;
neuron_basket_construction_parameters : opt NeuronBasketConstructionParameters;
confirmation_text : opt text;
maximum_participant_icp : opt Tokens;
neurons_fund_investment : opt Tokens;
minimum_icp : opt Tokens;
minimum_participant_icp : opt Tokens;
start_time : opt GlobalTimeOfDay;
maximum_icp : opt Tokens;
restricted_countries : opt Countries;
};
type Tally = record {
no : nat64;
Expand Down
18 changes: 18 additions & 0 deletions packages/nns/candid/governance.idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,24 @@ export const idlFactory = ({ IDL }) => {
'dissolve_delay_interval' : IDL.Opt(Duration),
'count' : IDL.Opt(IDL.Nat64),
});
const GlobalTimeOfDay = IDL.Record({
'seconds_after_utc_midnight' : IDL.Opt(IDL.Nat64),
});
const Countries = IDL.Record({ 'iso_codes' : IDL.Vec(IDL.Text) });
const SwapParameters = IDL.Record({
'minimum_participants' : IDL.Opt(IDL.Nat64),
'duration' : IDL.Opt(Duration),
'neuron_basket_construction_parameters' : IDL.Opt(
NeuronBasketConstructionParameters
),
'confirmation_text' : IDL.Opt(IDL.Text),
'maximum_participant_icp' : IDL.Opt(Tokens),
'neurons_fund_investment' : IDL.Opt(Tokens),
'minimum_icp' : IDL.Opt(Tokens),
'minimum_participant_icp' : IDL.Opt(Tokens),
'start_time' : IDL.Opt(GlobalTimeOfDay),
'maximum_icp' : IDL.Opt(Tokens),
'restricted_countries' : IDL.Opt(Countries),
});
const SwapDistribution = IDL.Record({ 'total' : IDL.Opt(Tokens) });
const NeuronDistribution = IDL.Record({
Expand Down Expand Up @@ -918,15 +927,24 @@ export const init = ({ IDL }) => {
'dissolve_delay_interval' : IDL.Opt(Duration),
'count' : IDL.Opt(IDL.Nat64),
});
const GlobalTimeOfDay = IDL.Record({
'seconds_after_utc_midnight' : IDL.Opt(IDL.Nat64),
});
const Countries = IDL.Record({ 'iso_codes' : IDL.Vec(IDL.Text) });
const SwapParameters = IDL.Record({
'minimum_participants' : IDL.Opt(IDL.Nat64),
'duration' : IDL.Opt(Duration),
'neuron_basket_construction_parameters' : IDL.Opt(
NeuronBasketConstructionParameters
),
'confirmation_text' : IDL.Opt(IDL.Text),
'maximum_participant_icp' : IDL.Opt(Tokens),
'neurons_fund_investment' : IDL.Opt(Tokens),
'minimum_icp' : IDL.Opt(Tokens),
'minimum_participant_icp' : IDL.Opt(Tokens),
'start_time' : IDL.Opt(GlobalTimeOfDay),
'maximum_icp' : IDL.Opt(Tokens),
'restricted_countries' : IDL.Opt(Countries),
});
const SwapDistribution = IDL.Record({ 'total' : IDL.Opt(Tokens) });
const NeuronDistribution = IDL.Record({
Expand Down
21 changes: 19 additions & 2 deletions packages/nns/src/canisters/governance/request.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import type {
By as RawBy,
Change as RawChange,
Command as RawCommand,
Countries as RawCountries,
CreateServiceNervousSystem as RawCreateServiceNervousSystem,
DeveloperDistribution as RawDeveloperDistribution,
Duration as RawDuration,
GlobalTimeOfDay as RawGlobalTimeOfDay,
Followees as RawFollowees,
GovernanceParameters as RawGovernanceParameters,
Image as RawImage,
Expand Down Expand Up @@ -40,12 +42,12 @@ import type {
By,
Change,
ClaimOrRefreshNeuronRequest,
Command,
Command, Countries,
CreateServiceNervousSystem,
DeveloperDistribution,
DisburseToNeuronRequest,
Duration,
FollowRequest,
FollowRequest, GlobalTimeOfDay,
GovernanceParameters,
Image,
InitialTokenDistribution,
Expand Down Expand Up @@ -102,6 +104,14 @@ const fromDuration = (duration: Duration): RawDuration =>
? { seconds: [duration.seconds] }
: { seconds: [] };

const fromGlobalTimeOfDay = (time: GlobalTimeOfDay): RawGlobalTimeOfDay =>
time.secondsAfterUtcMidnight !== undefined
? { seconds_after_utc_midnight: [time.secondsAfterUtcMidnight] }
: { seconds_after_utc_midnight: [] };

const fromCountries = (countries: Countries): RawCountries =>
({ iso_codes: countries.isoCodes });

const fromTokens = (tokens: Tokens): RawTokens =>
tokens.e8s !== undefined ? { e8s: [tokens.e8s] } : { e8s: [] };

Expand Down Expand Up @@ -155,6 +165,7 @@ const fromSwapParameters = (
swapParameters.minimumParticipants !== undefined
? [swapParameters.minimumParticipants]
: [],
duration: swapParameters.duration !== undefined ? [fromDuration(swapParameters.duration)] : [],
neuron_basket_construction_parameters:
swapParameters.neuronBasketConstructionParameters !== undefined
? [
Expand All @@ -163,10 +174,12 @@ const fromSwapParameters = (
),
]
: [],
confirmation_text: swapParameters.confirmationText !== undefined ? [swapParameters.confirmationText] : [],
maximum_participant_icp:
swapParameters.maximumParticipantIcp !== undefined
? [fromTokens(swapParameters.maximumParticipantIcp)]
: [],
neurons_fund_investment: swapParameters.neuronsFundInvestment !== undefined ? [fromTokens(swapParameters.neuronsFundInvestment)] : [],
minimum_icp:
swapParameters.minimumIcp !== undefined
? [fromTokens(swapParameters.minimumIcp)]
Expand All @@ -175,10 +188,14 @@ const fromSwapParameters = (
swapParameters.minimumParticipantIcp !== undefined
? [fromTokens(swapParameters.minimumParticipantIcp)]
: [],
start_time: swapParameters.startTime !== undefined ? [fromGlobalTimeOfDay(swapParameters.startTime)] : [],
maximum_icp:
swapParameters.maximumIcp !== undefined
? [fromTokens(swapParameters.maximumIcp)]
: [],
restricted_countries: swapParameters.restrictedCountries !== undefined
? [fromCountries(swapParameters.restrictedCountries)]
: [],
});

const fromNeuronBasketConstructionParameters = (
Expand Down
29 changes: 29 additions & 0 deletions packages/nns/src/canisters/governance/response.converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type {
DeveloperDistribution as RawDeveloperDistribution,
DissolveState as RawDissolveState,
Duration as RawDuration,
GlobalTimeOfDay as RawGlobalTimeOfDay,
Countries as RawCountries,
Followees as RawFollowees,
GovernanceParameters as RawGovernanceParameters,
Image as RawImage,
Expand Down Expand Up @@ -71,6 +73,8 @@ import type {
DeveloperDistribution,
DissolveState,
Duration,
GlobalTimeOfDay,
Countries,
Followees,
GovernanceParameters,
Image,
Expand Down Expand Up @@ -994,6 +998,26 @@ const toDuration = (
};
};

const toGlobalTimeOfDay = (
time: RawGlobalTimeOfDay | undefined,
): GlobalTimeOfDay | undefined => {
return time === undefined
? undefined
: {
secondsAfterUtcMidnight: fromNullable(time.seconds_after_utc_midnight),
};
};

const toCountries = (
countries: RawCountries | undefined,
): Countries | undefined => {
return countries === undefined
? undefined
: {
isoCodes: countries.iso_codes,
} as Countries;
};

const toTokens = (tokens: RawTokens | undefined): Tokens | undefined => {
return tokens === undefined
? undefined
Expand Down Expand Up @@ -1122,18 +1146,23 @@ const toSwapParameters = (
? undefined
: {
minimumParticipants: fromNullable(swapParameters.minimum_participants),
duration: toDuration(fromNullable(swapParameters.duration)),
neuronBasketConstructionParameters:
toNeuronBasketConstructionParameters(
fromNullable(swapParameters.neuron_basket_construction_parameters),
),
confirmationText: fromNullable(swapParameters.confirmation_text),
maximumParticipantIcp: toTokens(
fromNullable(swapParameters.maximum_participant_icp),
),
neuronsFundInvestment: toTokens(fromNullable(swapParameters.neurons_fund_investment)),
minimumIcp: toTokens(fromNullable(swapParameters.minimum_icp)),
minimumParticipantIcp: toTokens(
fromNullable(swapParameters.minimum_participant_icp),
),
startTime: toGlobalTimeOfDay(fromNullable(swapParameters.start_time)),
maximumIcp: toTokens(fromNullable(swapParameters.maximum_icp)),
restrictedCountries: toCountries(fromNullable(swapParameters.restricted_countries)),
};
};

Expand Down
13 changes: 13 additions & 0 deletions packages/nns/src/types/governance_converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ export interface Duration {
seconds?: bigint;
}

export interface GlobalTimeOfDay {
secondsAfterUtcMidnight?: bigint;
}

export interface Countries {
isoCodes: Array<string>;
}

export interface Tokens {
e8s?: bigint;
}
Expand Down Expand Up @@ -542,11 +550,16 @@ export interface NeuronBasketConstructionParameters {
}
export interface SwapParameters {
minimumParticipants?: bigint;
duration?: Duration;
neuronBasketConstructionParameters?: NeuronBasketConstructionParameters;
confirmationText?: string;
maximumParticipantIcp?: Tokens;
neuronsFundInvestment?: Tokens;
minimumIcp?: Tokens;
minimumParticipantIcp?: Tokens;
startTime?: GlobalTimeOfDay;
maximumIcp?: Tokens;
restrictedCountries?: Countries;
}

export interface SwapDistribution {
Expand Down

0 comments on commit 325dabc

Please sign in to comment.