Skip to content

Commit

Permalink
GIX-1937: Use min max direct participation fields from aggregator (#3551
Browse files Browse the repository at this point in the history
)

# Motivation

Add functionality after Neurons' Fund enhancements.

In this PR, we use the new fields from the SNS Aggregator when we
convert the data to SnsSummary.

# Changes

* Populate new fields `min_direct_participation_icp_e8s` and
`max_direct_participation_icp_e8s` from the different places into the
SnsSummary. Those fields are in the `Init` from `get_init`, but they are
also in the `init` inside the `swap` and also in the `params` of the
`swap`.

# Tests

* Add the fields in the test case for the NF's enhancements fields. The
other tests have those fields not populated and are converted to `[]` as
it was hardcoded before.

# Todos

- [ ] Add entry to changelog (if necessary).
Not yet necessary.
  • Loading branch information
lmuntaner authored Oct 13, 2023
1 parent 191a21c commit 53a2827
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 4 additions & 0 deletions frontend/src/lib/types/sns-aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export type CachedSwapParamsDto = {
dissolve_delay_interval_seconds: number;
};
sale_delay_seconds?: number;
min_direct_participation_icp_e8s?: number | null;
max_direct_participation_icp_e8s?: number | null;
};

interface CachedLinearScalingCoefficient {
Expand Down Expand Up @@ -116,6 +118,8 @@ export type CachedSwapInitParamsDto = {
confirmation_text?: string | undefined;
restricted_countries?: CachedCountriesDto | undefined;
neurons_fund_participation_constraints?: CachedNeuronsFundParticipationConstraints | null;
min_direct_participation_icp_e8s?: number | null;
max_direct_participation_icp_e8s?: number | null;
};

export type CachedSnsSwapDto = {
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/lib/utils/sns-aggregator-converters.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ const convertSwapInitParams = (
)
)
: [],
min_direct_participation_icp_e8s: [],
max_direct_participation_icp_e8s: [],
min_direct_participation_icp_e8s: toNullable(
convertOptionalNumToBigInt(init.min_direct_participation_icp_e8s)
),
max_direct_participation_icp_e8s: toNullable(
convertOptionalNumToBigInt(init.max_direct_participation_icp_e8s)
),
}
: undefined;

Expand All @@ -233,8 +237,12 @@ const convertSwapParams = (params: CachedSwapParamsDto): SnsParams => ({
sale_delay_seconds: toNullable(
convertOptionalNumToBigInt(params.sale_delay_seconds)
),
min_direct_participation_icp_e8s: [],
max_direct_participation_icp_e8s: [],
min_direct_participation_icp_e8s: toNullable(
convertOptionalNumToBigInt(params.min_direct_participation_icp_e8s)
),
max_direct_participation_icp_e8s: toNullable(
convertOptionalNumToBigInt(params.max_direct_participation_icp_e8s)
),
});

const convertSwap = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ describe("sns aggregator converters utils", () => {
).toBeUndefined();
});

it("converts fields related to NF participation", () => {
it("converts fields related to NF participation enhancements", () => {
const aggregatorNFAndDirectParticipationFields: CachedSnsDto = {
...mockData,
swap_state: {
Expand All @@ -484,6 +484,11 @@ describe("sns aggregator converters utils", () => {
...mockData.swap_state.swap,
direct_participation_icp_e8s: 300000000000000,
neurons_fund_participation_icp_e8s: 100000000000000,
params: {
...mockData.swap_state.swap.params,
min_direct_participation_icp_e8s: 300000000000,
max_direct_participation_icp_e8s: 3000000000000,
},
init: {
...mockData.swap_state.swap.init,
neurons_fund_participation_constraints: {
Expand All @@ -499,6 +504,8 @@ describe("sns aggregator converters utils", () => {
max_neurons_fund_participation_icp_e8s: 300000000000,
min_direct_participation_threshold_icp_e8s: 10000000000,
},
min_direct_participation_icp_e8s: 300000000000,
max_direct_participation_icp_e8s: 3000000000000,
},
},
derived: {
Expand All @@ -512,6 +519,13 @@ describe("sns aggregator converters utils", () => {
direct_participation_icp_e8s: 300000000000000,
neurons_fund_participation_icp_e8s: 100000000000000,
},
init: {
init: {
...mockData.init.init,
min_direct_participation_icp_e8s: 300000000000,
max_direct_participation_icp_e8s: 3000000000000,
},
},
};

const summaryMockData = convertDtoToSnsSummary(mockData);
Expand All @@ -521,6 +535,11 @@ describe("sns aggregator converters utils", () => {
...summaryMockData,
swap: {
...summaryMockData.swap,
params: {
...summaryMockData.swap.params,
min_direct_participation_icp_e8s: [300000000000n],
max_direct_participation_icp_e8s: [3000000000000n],
},
init: [
{
...summaryMockData.swap.init[0],
Expand All @@ -539,6 +558,8 @@ describe("sns aggregator converters utils", () => {
min_direct_participation_threshold_icp_e8s: [10000000000n],
},
],
min_direct_participation_icp_e8s: [300000000000n],
max_direct_participation_icp_e8s: [3000000000000n],
},
],
direct_participation_icp_e8s: [300000000000000n],
Expand All @@ -549,6 +570,11 @@ describe("sns aggregator converters utils", () => {
direct_participation_icp_e8s: [300000000000000n],
neurons_fund_participation_icp_e8s: [100000000000000n],
},
init: {
...summaryMockData.init,
min_direct_participation_icp_e8s: [300000000000n],
max_direct_participation_icp_e8s: [3000000000000n],
},
});
});
});
Expand Down

0 comments on commit 53a2827

Please sign in to comment.