Skip to content

Commit cbb9e0d

Browse files
authored
vip: add querier for weight vote and vip (#82)
* add querier for weight vote and vip * precompile * fix typo and add stage_period * remove redundant
1 parent b548337 commit cbb9e0d

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

precompile/binaries/stdlib/vip.mv

291 Bytes
Binary file not shown.
236 Bytes
Binary file not shown.

precompile/modules/initia_stdlib/sources/vip/vip.move

+53
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module initia_std::vip {
6161
const DEFAULT_PROPORTION_RATIO: vector<u8> = b"0.5";
6262
const DEFAULT_USER_VESTING_PERIOD: u64 = 52; // 52 times
6363
const DEFAULT_OPERATOR_VESTING_PERIOD: u64 = 52;
64+
const DEFAULT_STAGE_PERIOD: u64 = 604800; // 1 week
6465
const DEFAULT_MINIMUM_ELIGIBLE_TVL: u64 = 0;
6566
const DEFAULT_MAXIMUM_TVL_RATIO: vector<u8> = b"1";
6667
const DEFAULT_MAXIMUM_WEIGHT_RATIO: vector<u8> = b"1";
@@ -70,6 +71,7 @@ module initia_std::vip {
7071
// global stage
7172
stage: u64,
7273
// governance-defined vesting period in stage unit
74+
stage_period: u64,
7375
// the number of times vesting is divided
7476
user_vesting_period: u64,
7577
operator_vesting_period: u64,
@@ -95,6 +97,7 @@ module initia_std::vip {
9597
}
9698

9799
struct StageData has store {
100+
stage_period: u64,
98101
pool_split_ratio: Decimal256,
99102
total_operator_funded_reward: u64,
100103
total_user_funded_reward: u64,
@@ -133,6 +136,7 @@ module initia_std::vip {
133136

134137
struct ModuleResponse has drop {
135138
stage: u64,
139+
stage_period: u64,
136140
agent: address,
137141
proportion: Decimal256,
138142
pool_split_ratio: Decimal256,
@@ -148,6 +152,7 @@ module initia_std::vip {
148152
}
149153

150154
struct StageDataResponse has drop {
155+
stage_period: u64,
151156
pool_split_ratio: Decimal256,
152157
total_operator_funded_reward: u64,
153158
total_user_funded_reward: u64,
@@ -181,6 +186,7 @@ module initia_std::vip {
181186
#[event]
182187
struct StageAdvanceEvent has drop, store {
183188
stage: u64,
189+
stage_period: u64,
184190
pool_split_ratio: Decimal256,
185191
total_operator_funded_reward: u64,
186192
total_user_funded_reward: u64,
@@ -207,6 +213,7 @@ module initia_std::vip {
207213
chain,
208214
ModuleStore {
209215
stage: DEFAULT_VIP_START_STAGE,
216+
stage_period: DEFAULT_STAGE_PERIOD,
210217
user_vesting_period: DEFAULT_USER_VESTING_PERIOD,
211218
operator_vesting_period: DEFAULT_OPERATOR_VESTING_PERIOD,
212219
proportion: decimal256::from_string(
@@ -1008,6 +1015,7 @@ module initia_std::vip {
10081015
&mut module_store.stage_data,
10091016
table_key::encode_u64(stage),
10101017
StageData {
1018+
stage_period: module_store.stage_period,
10111019
pool_split_ratio: module_store.pool_split_ratio,
10121020
total_operator_funded_reward,
10131021
total_user_funded_reward,
@@ -1023,6 +1031,7 @@ module initia_std::vip {
10231031
event::emit(
10241032
StageAdvanceEvent {
10251033
stage,
1034+
stage_period: module_store.stage_period,
10261035
pool_split_ratio: module_store.pool_split_ratio,
10271036
total_operator_funded_reward,
10281037
total_user_funded_reward,
@@ -1244,6 +1253,19 @@ module initia_std::vip {
12441253
validate_vip_weights(module_store);
12451254
}
12461255

1256+
public entry fun update_stage_period(
1257+
chain: &signer,
1258+
stage_period: u64,
1259+
) acquires ModuleStore {
1260+
check_chain_permission(chain);
1261+
let module_store = borrow_global_mut<ModuleStore>(signer::address_of(chain));
1262+
assert!(
1263+
stage_period > 0,
1264+
error::invalid_argument(EINVALID_VEST_PERIOD)
1265+
);
1266+
module_store.stage_period = stage_period;
1267+
}
1268+
12471269
public entry fun update_vesting_period(
12481270
chain: &signer,
12491271
user_vesting_period: u64,
@@ -1490,6 +1512,7 @@ module initia_std::vip {
14901512
);
14911513

14921514
StageDataResponse {
1515+
stage_period: stage_data.stage_period,
14931516
pool_split_ratio: stage_data.pool_split_ratio,
14941517
total_operator_funded_reward: stage_data.total_operator_funded_reward,
14951518
total_user_funded_reward: stage_data.total_user_funded_reward,
@@ -1515,6 +1538,35 @@ module initia_std::vip {
15151538
}
15161539
}
15171540

1541+
#[view]
1542+
public fun get_bridge_infos(): vector<BridgeResponse> acquires ModuleStore {
1543+
let module_store = borrow_global<ModuleStore>(@initia_std);
1544+
let iter = table::iter(
1545+
&module_store.bridges,
1546+
option::none(),
1547+
option::none(),
1548+
1
1549+
);
1550+
1551+
let bridge_infos = vector::empty<BridgeResponse>();
1552+
loop {
1553+
if (!table::prepare<vector<u8>, Bridge>(iter)) { break };
1554+
let (_, bridge) = table::next<vector<u8>, Bridge>(iter);
1555+
vector::push_back(
1556+
&mut bridge_infos,
1557+
BridgeResponse {
1558+
bridge_addr: bridge.bridge_addr,
1559+
operator_addr: bridge.operator_addr,
1560+
vip_weight: bridge.vip_weight,
1561+
user_reward_store_addr: bridge.user_reward_store_addr,
1562+
operator_reward_store_addr: bridge.operator_reward_store_addr,
1563+
}
1564+
);
1565+
};
1566+
1567+
bridge_infos
1568+
}
1569+
15181570
#[view]
15191571
public fun get_whitelisted_bridge_ids(): vector<u64> acquires ModuleStore {
15201572
let module_store = borrow_global<ModuleStore>(@initia_std);
@@ -1568,6 +1620,7 @@ module initia_std::vip {
15681620

15691621
ModuleResponse {
15701622
stage: module_store.stage,
1623+
stage_period: module_store.stage_period,
15711624
agent: module_store.agent,
15721625
proportion: module_store.proportion,
15731626
pool_split_ratio: module_store.pool_split_ratio,

precompile/modules/initia_stdlib/sources/vip/weight_vote.move

+45-3
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ module initia_std::vip_weight_vote {
639639
// if user already voted, remove former vote
640640
if (table::contains(&challenge.votes, addr)) {
641641
let Vote {voting_power, vote_option} = table::remove(&mut challenge.votes, addr);
642-
apply_challge_vote(
642+
apply_challenge_vote(
643643
challenge,
644644
vote_option,
645645
voting_power,
@@ -655,7 +655,7 @@ module initia_std::vip_weight_vote {
655655
Vote {voting_power, vote_option,}
656656
);
657657

658-
apply_challge_vote(
658+
apply_challenge_vote(
659659
challenge,
660660
vote_option,
661661
voting_power,
@@ -945,7 +945,7 @@ module initia_std::vip_weight_vote {
945945
};
946946
}
947947

948-
fun apply_challge_vote(
948+
fun apply_challenge_vote(
949949
challenge: &mut Challenge,
950950
vote_option: bool,
951951
voting_power: u64,
@@ -1177,6 +1177,48 @@ module initia_std::vip_weight_vote {
11771177
}
11781178
}
11791179

1180+
#[view]
1181+
public fun get_challenge_by_stage(stage: u64): vector<ChallengeResponse> acquires ModuleStore {
1182+
let module_store = borrow_global<ModuleStore>(@initia_std);
1183+
let iter = table::iter(
1184+
&module_store.challenges,
1185+
option::none(),
1186+
option::none(),
1187+
1
1188+
);
1189+
1190+
let challenge_responses = vector::empty<ChallengeResponse>();
1191+
loop {
1192+
if (!table::prepare<vector<u8>, Challenge>(iter)) { break };
1193+
let (_, challenge) = table::next<vector<u8>, Challenge>(iter);
1194+
if (challenge.stage == stage) {
1195+
vector::push_back(
1196+
&mut challenge_responses,
1197+
ChallengeResponse {
1198+
title: challenge.title,
1199+
summary: challenge.summary,
1200+
api_uri: challenge.api_uri,
1201+
stage: challenge.stage,
1202+
challenger: challenge.challenger,
1203+
voting_power_stage: challenge.voting_power_stage,
1204+
new_submitter: challenge.new_submitter,
1205+
merkle_root: challenge.merkle_root,
1206+
snapshot_height: challenge.snapshot_height,
1207+
yes_tally: challenge.yes_tally,
1208+
no_tally: challenge.no_tally,
1209+
quorum: challenge.quorum,
1210+
voting_end_time: challenge.voting_end_time,
1211+
min_voting_end_time: challenge.min_voting_end_time,
1212+
deposit_amount: challenge.deposit_amount,
1213+
is_executed: challenge.is_executed,
1214+
}
1215+
);
1216+
};
1217+
};
1218+
1219+
challenge_responses
1220+
}
1221+
11801222
#[view]
11811223
public fun get_proposal(stage: u64): ProposalResponse acquires ModuleStore {
11821224
let module_store = borrow_global<ModuleStore>(@initia_std);

0 commit comments

Comments
 (0)