-
Notifications
You must be signed in to change notification settings - Fork 22
/
ParameterChangeProposal.ts
174 lines (161 loc) 路 4.46 KB
/
ParameterChangeProposal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { JSONSerializable } from '../../../util/json';
import { ParamChange, ParamChanges } from '../ParamChange';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { ParameterChangeProposal as ParameterChangeProposal_pb } from '@terra-money/terra.proto/cosmos/params/v1beta1/params';
/**
* Describes a proposal for directly altering the value of the module parameters.
* If you want to select a couple parameters to change for your proposal, you'll first
* include the subspace (module it belongs to, such as "oracle" or "distribution"), and
* then just the specific keys that you want to include in your changes as items in a
* JavaScript object.
*
* ```ts
* import {
* Dec,
* MsgSubmitProposal,
* ParameterChangeProposal
* } from "@terra-money/terra.js";
*
* const proposal = new ParameterChangeProposal("title", "description", {
* market: {
* minspread: new Dec(0.25),
* basepool: new Dec(10000000)
* },
* staking: {
* UnbondingTime: 15000000
* }
* });
*
* const msg = new MsgSubmitProposal();
* ```
*/
export class ParameterChangeProposal extends JSONSerializable<
ParameterChangeProposal.Amino,
ParameterChangeProposal.Data,
ParameterChangeProposal.Proto
> {
public changes: ParamChanges;
/**
* @param title proposal's title
* @param description proposal's description
* @param changes an object whose keys are subspace names, and whose values are objects
* with objects having for keys and values, the desired parameter changes.
*/
constructor(
public title: string,
public description: string,
changes: ParamChange.Data[] | ParamChanges
) {
super();
if (Array.isArray(changes)) {
this.changes = ParamChanges.fromData(changes);
} else {
this.changes = changes;
}
}
public static fromAmino(
data: ParameterChangeProposal.Amino,
_?: boolean
): ParameterChangeProposal {
_;
const {
value: { title, description, changes },
} = data;
return new ParameterChangeProposal(
title,
description,
ParamChanges.fromAmino(changes)
);
}
public toAmino(isClassic?: boolean): ParameterChangeProposal.Amino {
const { title, description, changes } = this;
return {
type: isClassic
? 'params/ParameterChangeProposal'
: 'cosmos-sdk/ParameterChangeProposal',
value: {
title,
description,
changes: changes.toAmino(),
},
};
}
public static fromData(
proto: ParameterChangeProposal.Data,
_?: boolean
): ParameterChangeProposal {
_;
const { title, description, changes } = proto;
return new ParameterChangeProposal(
title,
description,
ParamChanges.fromData(changes)
);
}
public toData(_?: boolean): ParameterChangeProposal.Data {
_;
const { title, description, changes } = this;
return {
'@type': '/cosmos.params.v1beta1.ParameterChangeProposal',
title,
description,
changes: changes.toData(),
};
}
public static fromProto(
proto: ParameterChangeProposal.Proto,
_?: boolean
): ParameterChangeProposal {
_;
return new ParameterChangeProposal(
proto.title,
proto.description,
ParamChanges.fromProto(proto.changes)
);
}
public toProto(_?: boolean): ParameterChangeProposal.Proto {
_;
const { title, description, changes } = this;
return ParameterChangeProposal_pb.fromPartial({
changes: changes.toProto(),
description,
title,
});
}
public packAny(isClassic?: boolean): Any {
return Any.fromPartial({
typeUrl: '/cosmos.params.v1beta1.ParameterChangeProposal',
value: ParameterChangeProposal_pb.encode(
this.toProto(isClassic)
).finish(),
});
}
public static unpackAny(
msgAny: Any,
isClassic?: boolean
): ParameterChangeProposal {
return ParameterChangeProposal.fromProto(
ParameterChangeProposal_pb.decode(msgAny.value),
isClassic
);
}
}
export namespace ParameterChangeProposal {
export interface Amino {
type:
| 'params/ParameterChangeProposal'
| 'cosmos-sdk/ParameterChangeProposal';
value: {
title: string;
description: string;
changes: ParamChange.Amino[];
};
}
export interface Data {
'@type': '/cosmos.params.v1beta1.ParameterChangeProposal';
title: string;
description: string;
changes: ParamChange.Data[];
}
export type Proto = ParameterChangeProposal_pb;
}