terra: migrations for cw20
Change-Id: I201021ed763e8b94a2d029d79ba5ce7e3d3868e3
This commit is contained in:
parent
ff4cbf474e
commit
e2a16b6756
|
@ -164,6 +164,9 @@ pub fn execute(
|
|||
} => Ok(execute_send_from(
|
||||
deps, env, info, owner, contract, amount, msg,
|
||||
)?),
|
||||
ExecuteMsg::UpdateMetadata { name, symbol } => {
|
||||
Ok(execute_update_metadata(deps, env, info, name, symbol)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,6 +186,26 @@ fn execute_mint_wrapped(
|
|||
Ok(execute_mint(deps, env, info, recipient, amount)?)
|
||||
}
|
||||
|
||||
fn execute_update_metadata(
|
||||
deps: DepsMut,
|
||||
_env: Env,
|
||||
info: MessageInfo,
|
||||
name: String,
|
||||
symbol: String,
|
||||
) -> Result<Response, ContractError> {
|
||||
// Only bridge can update.
|
||||
let wrapped_info = wrapped_asset_info_read(deps.storage).load()?;
|
||||
if wrapped_info.bridge != deps.api.addr_canonicalize(&info.sender.as_str())? {
|
||||
return Err(ContractError::Unauthorized {});
|
||||
}
|
||||
|
||||
let mut state = TOKEN_INFO.load(deps.storage)?;
|
||||
state.name = name;
|
||||
state.symbol = symbol;
|
||||
TOKEN_INFO.save(deps.storage, &state)?;
|
||||
Ok(Response::default())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "library"), entry_point)]
|
||||
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||
match msg {
|
||||
|
|
|
@ -93,6 +93,8 @@ pub enum ExecuteMsg {
|
|||
},
|
||||
/// Implements CW20 "approval" extension. Destroys tokens forever
|
||||
BurnFrom { owner: HumanAddr, amount: Uint128 },
|
||||
/// Extend Interface with the ability to update token metadata.
|
||||
UpdateMetadata { name: String, symbol: String },
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
|
|
|
@ -108,7 +108,19 @@ const CHAIN_ID: u16 = 3;
|
|||
const WRAPPED_ASSET_UPDATING: &str = "updating";
|
||||
|
||||
#[cfg_attr(not(feature = "library"), entry_point)]
|
||||
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
|
||||
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
|
||||
// Switch CW20 Code ID to include assets with updatable metadata.
|
||||
let mut state = config(deps.storage).load()?;
|
||||
state.wrapped_asset_code_id = 0;
|
||||
config(deps.storage).save(&state)?;
|
||||
|
||||
// Remove registered asset with old code ID.
|
||||
let asset_id = build_asset_id(
|
||||
1,
|
||||
&hex::decode("069b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001").unwrap(),
|
||||
);
|
||||
wrapped_asset(deps.storage).remove(&asset_id);
|
||||
assert!(wrapped_asset(deps.storage).load(&asset_id).is_err());
|
||||
Ok(Response::default())
|
||||
}
|
||||
|
||||
|
@ -292,7 +304,7 @@ fn handle_attest_meta(
|
|||
|
||||
Ok(
|
||||
Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Instantiate {
|
||||
admin: None,
|
||||
admin: Some(env.contract.address.to_string()),
|
||||
code_id: cfg.wrapped_asset_code_id,
|
||||
msg: to_binary(&WrappedInit {
|
||||
name: get_string_from_32(&meta.name)?,
|
||||
|
|
|
@ -2,12 +2,15 @@ use cosmwasm_std::{
|
|||
Binary,
|
||||
Uint128,
|
||||
};
|
||||
use terraswap::asset::{Asset, AssetInfo};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{
|
||||
Deserialize,
|
||||
Serialize,
|
||||
};
|
||||
use terraswap::asset::{
|
||||
Asset,
|
||||
AssetInfo,
|
||||
};
|
||||
|
||||
type HumanAddr = String;
|
||||
|
||||
|
@ -33,7 +36,6 @@ pub enum ExecuteMsg {
|
|||
asset: AssetInfo,
|
||||
},
|
||||
|
||||
|
||||
InitiateTransfer {
|
||||
asset: Asset,
|
||||
recipient_chain: u16,
|
||||
|
@ -54,8 +56,7 @@ pub enum ExecuteMsg {
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct MigrateMsg {
|
||||
}
|
||||
pub struct MigrateMsg {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
|
|
@ -252,9 +252,7 @@ impl UpgradeContract {
|
|||
pub fn deserialize(data: &Vec<u8>) -> StdResult<Self> {
|
||||
let data = data.as_slice();
|
||||
let new_contract = data.get_u64(24);
|
||||
Ok(UpgradeContract {
|
||||
new_contract,
|
||||
})
|
||||
Ok(UpgradeContract { new_contract })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue