Skip to content

Commit 2c93449

Browse files
hacpyAAweidai
andauthored
Upgrade dola_protocol to v1.0.9 (#244)
* Add protocol version 1.0.9 * Fix note * Add proposal * Fix config * Fix liquidate whitelist * Fix script --------- Co-authored-by: AAweidai <[email protected]>
1 parent 371b5ae commit 2c93449

File tree

12 files changed

+308
-14
lines changed

12 files changed

+308
-14
lines changed

sui/brownie-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ networks:
5757
v_1_0_6: '0x887f9ce74da0675c053a050cc9d6039dc8cae5c047d98d3601d6bcccd245ba76'
5858
v_1_0_7: '0x2c674f67f73bb32ea94123e4a0c509de9f529a2423818b275d9a9019ad83cd04'
5959
v_1_0_8: '0x1f61d9c4a266a24cd53fabd902c3e012e221c2a223bbb0532229af3b8ac8ca65'
60-
latest: '0x1f61d9c4a266a24cd53fabd902c3e012e221c2a223bbb0532229af3b8ac8ca65'
61-
external_interfaces: '0xb1fa071638678747b97bb09a42ce74da8c62ca2daf8b13fd85aa2838ea60106e'
60+
v_1_0_9: '0xc26491612cdb386cb943ae92764d94d85f1f2c6fb1890ab6a2d5687521626c21'
61+
latest: '0xc26491612cdb386cb943ae92764d94d85f1f2c6fb1890ab6a2d5687521626c21'
62+
external_interfaces: '0x6c3367d4eac668f8a7944b65f5185804c9573e15594e6198ef67b1c8e8fc0e54'
6263
genesis_proposal: '0x693828fbf1322d43f23ad365ab27b7d6f6649133aa3761ff55be6380e53c1b70'
6364
pyth: '0x00b53b0f4174108627fbee72e2498b58d6a2714cded53fac537034c220d26302'
6465
reserve_proposal: '0xb62cbf8e23b5c02bdb822f68e549d5c8abf609f0d477c8200197718f045d4741'

sui/dola_protocol/Move.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "DolaProtocol"
33
version = "1.0.2"
4-
published-at = "0xbebebe327aa02f9709a0eab48f03e54edffee6ae8c0de49032e2b9e17c4e568b"
4+
published-at = "0x1f61d9c4a266a24cd53fabd902c3e012e221c2a223bbb0532229af3b8ac8ca65"
55

66
[addresses]
77
dola_protocol = "0x0"

sui/dola_protocol/sources/governance/genesis.move

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ module dola_protocol::genesis {
110110
Version_1_0_8 {}
111111
}
112112

113+
/// Version 1.0.9
114+
struct Version_1_0_9 has store, drop, copy {}
115+
116+
public fun get_version_1_0_9(): Version_1_0_9 {
117+
Version_1_0_9 {}
118+
}
119+
113120
/// Add a new version structure when upgrading, and upgrade
114121
/// the version through version migration.
115122
///
@@ -125,8 +132,8 @@ module dola_protocol::genesis {
125132
/// Note: Update the function to set the version limit.
126133
public fun check_latest_version(genesis: &GovernanceGenesis) {
127134
assert!(
128-
dynamic_field::exists_with_type<Version, Version_1_0_7>(&genesis.id, Version {}) ||
129-
dynamic_field::exists_with_type<Version, Version_1_0_8>(&genesis.id, Version {}),
135+
dynamic_field::exists_with_type<Version, Version_1_0_8>(&genesis.id, Version {}) ||
136+
dynamic_field::exists_with_type<Version, Version_1_0_9>(&genesis.id, Version {}),
130137
E_NOT_LATEST_VERISON
131138
);
132139
}

sui/dola_protocol/sources/oracle/oracle.move

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ module dola_protocol::oracle {
256256
let pyth_price_identifier = price_info::get_price_identifier(&price_info);
257257
assert!(price_identifier == &pyth_price_identifier, EWRONG_FEED_TOKEN);
258258

259-
// get the ema price
259+
// get the latest price
260260
let price_feed = price_info::get_price_feed(&price_info);
261261
let pyth_price = price_feed::get_price(price_feed);
262262

@@ -308,7 +308,7 @@ module dola_protocol::oracle {
308308
let price_oracles = &mut price_oracle.price_oracles;
309309
let price = table::borrow_mut(price_oracles, dola_pool_id);
310310

311-
// get the ema price
311+
// get the latest price
312312
let price_info = price_info::get_price_info_from_price_info_object(price_info_object);
313313
let price_feed = price_info::get_price_feed(&price_info);
314314
let pyth_price = price_feed::get_price(price_feed);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# @generated by Move, please check-in and do not edit manually.
2+
3+
[move]
4+
version = 0
5+
6+
dependencies = [
7+
{ name = "DolaProtocol" },
8+
{ name = "Sui" },
9+
]
10+
11+
[[move.package]]
12+
name = "DolaProtocol"
13+
source = { local = "../../../dola_protocol" }
14+
15+
dependencies = [
16+
{ name = "Pyth" },
17+
{ name = "Sui" },
18+
{ name = "Wormhole" },
19+
]
20+
21+
[[move.package]]
22+
name = "MoveStdlib"
23+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/move-stdlib" }
24+
25+
[[move.package]]
26+
name = "Pyth"
27+
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", rev = "7dab308f961746890faf1ac0b52e283b31112bf6", subdir = "target_chains/sui/contracts" }
28+
29+
dependencies = [
30+
{ name = "Sui" },
31+
{ name = "Wormhole" },
32+
]
33+
34+
[[move.package]]
35+
name = "Sui"
36+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/sui-framework" }
37+
38+
dependencies = [
39+
{ name = "MoveStdlib" },
40+
]
41+
42+
[[move.package]]
43+
name = "Wormhole"
44+
source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "fcfe551da0f46b704b76b09ae11dca3dd9387837", subdir = "sui/wormhole" }
45+
46+
dependencies = [
47+
{ name = "Sui" },
48+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "MigrateVersionProposal"
3+
version = "0.0.1"
4+
5+
[addresses]
6+
migrate_version_proposal = "0x0"
7+
dola_proposal = "0x0"
8+
9+
[dependencies.Sui]
10+
git = "https://github.com/MystenLabs/sui.git"
11+
subdir = "crates/sui-framework/packages/sui-framework"
12+
rev = "09b2081498366df936abae26eea4b2d5cafb2788"
13+
14+
[dependencies.DolaProtocol]
15+
local = "../../../dola_protocol"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module migrate_version_proposal::proposal {
2+
use std::option;
3+
4+
use dola_protocol::genesis::{Self, GovernanceGenesis, Version_1_0_8, Version_1_0_9};
5+
use dola_protocol::governance_v1::{Self, GovernanceInfo, Proposal};
6+
use sui::tx_context::TxContext;
7+
use std::ascii::String;
8+
use std::ascii;
9+
use std::vector;
10+
use sui::address;
11+
use sui::object;
12+
13+
/// Errors
14+
15+
const GOVERNANCE_INFO: vector<u8> = x"79d7106ea18373fc7542b0849d5ebefc3a9daf8b664a4f82d9b35bbd0c22042d";
16+
17+
const GOVERNANCE_GENESIS: vector<u8> = x"42ef90066e649215e6ab91399a83e1a5467fd7cc436e8b83adb8743a0efba621";
18+
19+
20+
struct ProposalDesc has store {
21+
// Description of proposal content
22+
description: String,
23+
// Params of `vote_porposal`
24+
vote_porposal: vector<address>
25+
}
26+
27+
/// To prove that this is a proposal, make sure that the `certificate` in the proposal will only flow to
28+
/// governance contract.
29+
struct Certificate has store, drop {}
30+
31+
32+
public entry fun create_proposal(governance_info: &mut GovernanceInfo, ctx: &mut TxContext) {
33+
governance_v1::create_proposal_with_history<Certificate>(governance_info, Certificate {}, ctx)
34+
}
35+
36+
public entry fun add_description_for_proposal(
37+
proposal: &mut Proposal<Certificate>,
38+
ctx: &mut TxContext
39+
) {
40+
let description: String = ascii::string(b"Migrate version from v_1_0_8 to v_1_0_9");
41+
42+
let vote_porposal = vector::empty<address>();
43+
vector::push_back(&mut vote_porposal, address::from_bytes(GOVERNANCE_INFO));
44+
vector::push_back(&mut vote_porposal, address::from_bytes(GOVERNANCE_GENESIS));
45+
vector::push_back(&mut vote_porposal, object::id_to_address(&object::id(proposal)));
46+
47+
let proposal_desc = ProposalDesc {
48+
description,
49+
vote_porposal,
50+
};
51+
52+
governance_v1::add_description_for_proposal<Certificate, ProposalDesc>(proposal, proposal_desc, ctx);
53+
}
54+
55+
public entry fun vote_porposal(
56+
governance_info: &GovernanceInfo,
57+
proposal: &mut Proposal<Certificate>,
58+
gov_genesis: &mut GovernanceGenesis,
59+
ctx: &mut TxContext
60+
) {
61+
let governance_cap = governance_v1::vote_proposal(governance_info, Certificate {}, proposal, true, ctx);
62+
if (option::is_some(&governance_cap)) {
63+
let cap = option::extract(&mut governance_cap);
64+
let new_version = genesis::get_version_1_0_9();
65+
genesis::migrate_version<Version_1_0_8, Version_1_0_9>(&cap, gov_genesis, new_version);
66+
governance_v1::destroy_governance_cap(cap);
67+
};
68+
option::destroy_none(governance_cap)
69+
}
70+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# @generated by Move, please check-in and do not edit manually.
2+
3+
[move]
4+
version = 0
5+
6+
dependencies = [
7+
{ name = "DolaProtocol" },
8+
{ name = "Sui" },
9+
]
10+
11+
[[move.package]]
12+
name = "DolaProtocol"
13+
source = { local = "../../../dola_protocol" }
14+
15+
dependencies = [
16+
{ name = "Pyth" },
17+
{ name = "Sui" },
18+
{ name = "Wormhole" },
19+
]
20+
21+
[[move.package]]
22+
name = "MoveStdlib"
23+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/move-stdlib" }
24+
25+
[[move.package]]
26+
name = "Pyth"
27+
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", rev = "7dab308f961746890faf1ac0b52e283b31112bf6", subdir = "target_chains/sui/contracts" }
28+
29+
dependencies = [
30+
{ name = "Sui" },
31+
{ name = "Wormhole" },
32+
]
33+
34+
[[move.package]]
35+
name = "Sui"
36+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/sui-framework" }
37+
38+
dependencies = [
39+
{ name = "MoveStdlib" },
40+
]
41+
42+
[[move.package]]
43+
name = "Wormhole"
44+
source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "fcfe551da0f46b704b76b09ae11dca3dd9387837", subdir = "sui/wormhole" }
45+
46+
dependencies = [
47+
{ name = "Sui" },
48+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "UpgradeProposal"
3+
version = "0.0.1"
4+
5+
[addresses]
6+
upgrade_proposal = "0x0"
7+
dola_protocol = "0x826915f8ca6d11597dfe6599b8aa02a4c08bd8d39674855254a06ee83fe7220e"
8+
sui = "0x2"
9+
10+
[dependencies.Sui]
11+
git = "https://github.com/MystenLabs/sui.git"
12+
subdir = "crates/sui-framework/packages/sui-framework"
13+
rev = "09b2081498366df936abae26eea4b2d5cafb2788"
14+
15+
[dependencies.DolaProtocol]
16+
local = "../../../dola_protocol"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module upgrade_proposal::proposal {
2+
use std::option;
3+
4+
use dola_protocol::genesis::{Self, GovernanceGenesis};
5+
use dola_protocol::governance_v1::{Self, GovernanceInfo, Proposal};
6+
use sui::package::{UpgradeReceipt, UpgradeTicket};
7+
use sui::tx_context::TxContext;
8+
use std::ascii::String;
9+
use std::vector;
10+
use sui::address;
11+
use std::ascii;
12+
use sui::object;
13+
14+
/// The digest of the new contract
15+
const DIGEST: vector<u8> = x"b022f71b3d152b21c8f06f7651cc835e32cb0f4a1aeff1d68e6d65d84d13c2b2";
16+
const POLICY: u8 = 0;
17+
18+
/// Errors
19+
const ENOT_FINAL_VOTE: u64 = 0;
20+
21+
const EIS_FINAL_VOTE: u64 = 0;
22+
23+
const GOVERNANCE_INFO: vector<u8> = x"79d7106ea18373fc7542b0849d5ebefc3a9daf8b664a4f82d9b35bbd0c22042d";
24+
25+
struct ProposalDesc has store {
26+
// Description of proposal content
27+
description: String,
28+
// Params of `vote_porposal`
29+
vote_porposal: vector<address>
30+
}
31+
32+
/// To prove that this is a proposal, make sure that the `certificate` in the proposal will only flow to
33+
/// governance contract.
34+
struct Certificate has store, drop {}
35+
36+
public entry fun create_proposal(governance_info: &mut GovernanceInfo, ctx: &mut TxContext) {
37+
governance_v1::create_proposal_with_history<Certificate>(governance_info, Certificate {}, ctx)
38+
}
39+
40+
public entry fun add_description_for_proposal(
41+
proposal: &mut Proposal<Certificate>,
42+
ctx: &mut TxContext
43+
) {
44+
let description: String = ascii::string(b"Upgrade version from v_1_0_8 to v_1_0_9");
45+
46+
let vote_porposal = vector::empty<address>();
47+
vector::push_back(&mut vote_porposal, address::from_bytes(GOVERNANCE_INFO));
48+
vector::push_back(&mut vote_porposal, object::id_to_address(&object::id(proposal)));
49+
50+
let proposal_desc = ProposalDesc {
51+
description,
52+
vote_porposal,
53+
};
54+
55+
governance_v1::add_description_for_proposal<Certificate, ProposalDesc>(proposal, proposal_desc, ctx);
56+
}
57+
58+
public entry fun vote_porposal(
59+
governance_info: &GovernanceInfo,
60+
proposal: &mut Proposal<Certificate>,
61+
ctx: &mut TxContext
62+
) {
63+
let governance_cap = governance_v1::vote_proposal(governance_info, Certificate {}, proposal, true, ctx);
64+
assert!(option::is_none(&governance_cap), EIS_FINAL_VOTE);
65+
option::destroy_none(governance_cap)
66+
}
67+
68+
public fun vote_proposal_final(
69+
governance_info: &GovernanceInfo,
70+
proposal: &mut Proposal<Certificate>,
71+
gov_genesis: &mut GovernanceGenesis,
72+
ctx: &mut TxContext
73+
): UpgradeTicket {
74+
let governance_cap = governance_v1::vote_proposal(governance_info, Certificate {}, proposal, true, ctx);
75+
assert!(option::is_some(&governance_cap), ENOT_FINAL_VOTE);
76+
let cap = option::extract(&mut governance_cap);
77+
let ticket = genesis::authorize_upgrade(&cap, gov_genesis, POLICY, DIGEST);
78+
governance_v1::destroy_governance_cap(cap);
79+
option::destroy_none(governance_cap);
80+
ticket
81+
}
82+
83+
public fun commit_upgrade(
84+
gov_genesis: &mut GovernanceGenesis,
85+
receipt: UpgradeReceipt,
86+
) {
87+
genesis::commit_upgrade(gov_genesis, receipt)
88+
}
89+
}

0 commit comments

Comments
 (0)