Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨[API-2348] Make Contracts Upgradeable #81

Merged
merged 14 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
]

[workspace.package]
version = "0.2.1"
version = "0.3.0"
authors = ["Skip"]
edition = "2021"
rust-version = "1.71.0"
Expand All @@ -35,7 +35,7 @@ osmosis-std = "0.15.3"
prost = "0.11"
serde-cw-value = "0.7.0"
serde-json-wasm = "0.5.1"
skip = { version = "0.2.0", path = "./packages/skip" }
skip = { version = "0.3.0", path = "./packages/skip" }
test-case = "3.1.0"
thiserror = "1"

Expand Down
1 change: 1 addition & 0 deletions contracts/adapters/ibc/ibc-hooks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ library = []
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
ibc-proto = { workspace = true }
prost = { workspace = true }
Expand Down
19 changes: 18 additions & 1 deletion contracts/adapters/ibc/ibc-hooks/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,46 @@ use cosmwasm_std::{
entry_point, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Reply, Response, SubMsg, SubMsgResult,
};
use cw2::set_contract_version;
use ibc_proto::ibc::applications::transfer::v1::{MsgTransfer, MsgTransferResponse};
use prost::Message;
use serde_cw_value::Value;
use skip::{
ibc::{AckID, ExecuteMsg, IbcInfo, IbcLifecycleComplete, InstantiateMsg, QueryMsg},
ibc::{AckID, ExecuteMsg, IbcInfo, IbcLifecycleComplete, InstantiateMsg, MigrateMsg, QueryMsg},
proto_coin::ProtoCoin,
sudo::{OsmosisSudoMsg as SudoMsg, SudoType},
};

const IBC_MSG_TRANSFER_TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
const REPLY_ID: u64 = 1;

///////////////
/// MIGRATE ///
///////////////

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not block the upgrade by panicking? Don't you want to just return successfully here?

Copy link
Member Author

@NotJeremyLiu NotJeremyLiu Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations work using the migration code of the new contract you are migrating to, not of the deployed contract. So when we instantiate all the contracts currently in the repo, they will all deploy without ever calling their migrate functions. But then if we want to upgrade a contract in the future, we will do so by implementing that contract's migrate function, store that code on chain, and then submit the MigrateMsg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr: we only implement the migrate function when we are doing a migration/upgrade, but can keep them unimplemented on normal deploys.

}
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved

///////////////////
/// INSTANTIATE ///
///////////////////

// Contract name and version used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
// Set contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// Validate entry point contract address
let checked_entry_point_contract_address =
deps.api.addr_validate(&msg.entry_point_contract_address)?;
Expand Down
1 change: 1 addition & 0 deletions contracts/adapters/ibc/neutron-transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ library = []
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
neutron-proto = { workspace = true }
neutron-sdk = { workspace = true }
Expand Down
19 changes: 18 additions & 1 deletion contracts/adapters/ibc/neutron-transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,45 @@ use cosmwasm_std::{
entry_point, to_binary, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Reply,
Response, SubMsg, SubMsgResult,
};
use cw2::set_contract_version;
use neutron_proto::neutron::transfer::{MsgTransfer, MsgTransferResponse};
use neutron_sdk::sudo::msg::{RequestPacket, TransferSudoMsg};
use prost::Message;
use skip::{
ibc::{AckID, ExecuteMsg, IbcInfo, InstantiateMsg, QueryMsg},
ibc::{AckID, ExecuteMsg, IbcInfo, InstantiateMsg, MigrateMsg, QueryMsg},
proto_coin::ProtoCoin,
sudo::SudoType,
};

const REPLY_ID: u64 = 1;

///////////////
/// MIGRATE ///
///////////////

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
}
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved

///////////////////
/// INSTANTIATE ///
///////////////////

// Contract name and version used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
// Set contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// Validate entry point contract address
let checked_entry_point_contract_address =
deps.api.addr_validate(&msg.entry_point_contract_address)?;
Expand Down
1 change: 1 addition & 0 deletions contracts/adapters/swap/astroport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ library = []
astroport = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
Expand Down
21 changes: 19 additions & 2 deletions contracts/adapters/swap/astroport/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,45 @@ use cosmwasm_std::{
entry_point, from_binary, to_binary, Addr, Api, Binary, Decimal, Deps, DepsMut, Env,
MessageInfo, Response, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw20::{Cw20Coin, Cw20ReceiveMsg};
use cw_utils::one_coin;
use skip::{
asset::Asset,
swap::{
execute_transfer_funds_back, AstroportInstantiateMsg as InstantiateMsg, Cw20HookMsg,
ExecuteMsg, QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse,
SwapOperation,
ExecuteMsg, MigrateMsg, QueryMsg, SimulateSwapExactAssetInResponse,
SimulateSwapExactAssetOutResponse, SwapOperation,
},
};

///////////////
/// MIGRATE ///
///////////////

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
}
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved

///////////////////
/// INSTANTIATE ///
///////////////////

// Contract name and version used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
// Set contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// Validate entry point contract address
let checked_entry_point_contract_address =
deps.api.addr_validate(&msg.entry_point_contract_address)?;
Expand Down
1 change: 1 addition & 0 deletions contracts/adapters/swap/lido-satellite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ library = []
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
lido-satellite = { workspace = true }
Expand Down
19 changes: 18 additions & 1 deletion contracts/adapters/swap/lido-satellite/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,44 @@ use cosmwasm_std::{
entry_point, to_binary, Binary, Coin, Decimal, Deps, DepsMut, Env, MessageInfo, Response,
WasmMsg,
};
use cw2::set_contract_version;
use cw_utils::one_coin;
use skip::{
asset::Asset,
swap::{
execute_transfer_funds_back, ExecuteMsg, LidoSatelliteInstantiateMsg as InstantiateMsg,
QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse,
MigrateMsg, QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse,
SwapOperation,
},
};

///////////////
/// MIGRATE ///
///////////////

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved
}

///////////////////
/// INSTANTIATE ///
///////////////////

// Contract name and version used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
// Set contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// Validate entry point contract address
let checked_entry_point_contract_address =
deps.api.addr_validate(&msg.entry_point_contract_address)?;
Expand Down
1 change: 1 addition & 0 deletions contracts/adapters/swap/osmosis-poolmanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ library = []
[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
osmosis-std = { workspace = true }
Expand Down
19 changes: 18 additions & 1 deletion contracts/adapters/swap/osmosis-poolmanager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cosmwasm_std::{
entry_point, to_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Empty, Env,
MessageInfo, Response, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_utils::one_coin;
use osmosis_std::types::osmosis::poolmanager::v1beta1::{
EstimateSwapExactAmountInResponse, EstimateSwapExactAmountOutResponse, MsgSwapExactAmountIn,
Expand All @@ -15,24 +16,40 @@ use skip::{
asset::Asset,
proto_coin::ProtoCoin,
swap::{
convert_swap_operations, execute_transfer_funds_back, ExecuteMsg,
convert_swap_operations, execute_transfer_funds_back, ExecuteMsg, MigrateMsg,
OsmosisInstantiateMsg as InstantiateMsg, QueryMsg, SimulateSwapExactAssetInResponse,
SimulateSwapExactAssetOutResponse, SwapOperation,
},
};
use std::str::FromStr;

///////////////
/// MIGRATE ///
///////////////

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult<Response> {
unimplemented!()
}
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved

///////////////////
/// INSTANTIATE ///
///////////////////

// Contract name and version used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
// Set contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// Validate entry point contract address
let checked_entry_point_contract_address =
deps.api.addr_validate(&msg.entry_point_contract_address)?;
Expand Down
Loading