diff --git a/res/tonic-dex.wasm b/res/tonic-dex.wasm index 44142b5..8d8fcf2 100644 Binary files a/res/tonic-dex.wasm and b/res/tonic-dex.wasm differ diff --git a/tonic-dex/src/lib.rs b/tonic-dex/src/lib.rs index d3ad24d..055eda5 100644 --- a/tonic-dex/src/lib.rs +++ b/tonic-dex/src/lib.rs @@ -28,6 +28,7 @@ mod settlement; mod storage; mod storage_manager; mod swap_order; +mod upgrade; mod views; pub use crate::account::*; diff --git a/tonic-dex/src/upgrade.rs b/tonic-dex/src/upgrade.rs new file mode 100644 index 0000000..f3e41e9 --- /dev/null +++ b/tonic-dex/src/upgrade.rs @@ -0,0 +1,34 @@ +use near_sdk::{Gas, Promise}; + +use crate::*; + +#[near_bindgen] +impl Contract { + pub fn version(&self) -> String { + format!("{}:{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")) + } + + #[private] + #[init(ignore_state)] + pub fn migrate() -> Self { + let contract: Contract = env::state_read().expect("Contract is not initialized"); + contract + } + + pub fn upgrade(&self) -> Promise { + self.assert_is_owner(); + + const CALL_GAS: Gas = Gas(200_000_000_000_000); // 200 TGAS + const NO_ARGS: Vec = vec![]; + + // Receive the code directly from the input to avoid the + // GAS overhead of deserializing parameters + let code = env::input().expect("Error: No input").to_vec(); + + // Deploy the contract on self + Promise::new(env::current_account_id()) + .deploy_contract(code) + .function_call("migrate".to_string(), NO_ARGS, 0, CALL_GAS) + .as_return() + } +}