From 4efcc912902a3553284c39da3b48b82a0fb745b0 Mon Sep 17 00:00:00 2001 From: Eugene Date: Fri, 12 Nov 2021 17:58:59 +0200 Subject: [PATCH] feat: remove init_hook (#20) * feat: remove init_hook * Update schema * update readme files --- contracts/terraswap_factory/README.md | 9 +- .../terraswap_factory/schema/execute_msg.json | 59 +-- .../schema/factory_pair_info.json | 94 +--- .../schema/instantiate_msg.json | 37 +- .../schema/pairs_response.json | 14 +- contracts/terraswap_factory/src/contract.rs | 71 +-- contracts/terraswap_factory/src/testing.rs | 8 - .../terraswap_factory/tests/integration.rs | 3 - contracts/terraswap_pair/README.md | 12 +- .../terraswap_pair/schema/execute_msg.json | 13 - .../schema/instantiate_msg.json | 33 +- .../schema/response_for__empty.json | 411 ++++++++++++++++++ contracts/terraswap_pair/src/contract.rs | 19 +- contracts/terraswap_pair/src/testing.rs | 72 +-- contracts/terraswap_pair/tests/integration.rs | 1 - .../schema/instantiate_msg.json | 33 -- contracts/terraswap_token/src/contract.rs | 11 +- packages/terraswap/examples/schema.rs | 2 - packages/terraswap/src/factory.rs | 4 - packages/terraswap/src/hook.rs | 9 - packages/terraswap/src/lib.rs | 1 - packages/terraswap/src/pair.rs | 3 - packages/terraswap/src/token.rs | 2 - 23 files changed, 488 insertions(+), 433 deletions(-) delete mode 100644 packages/terraswap/src/hook.rs diff --git a/contracts/terraswap_factory/README.md b/contracts/terraswap_factory/README.md index e0eebef..24b278e 100644 --- a/contracts/terraswap_factory/README.md +++ b/contracts/terraswap_factory/README.md @@ -9,10 +9,6 @@ The factory contract can perform creation of terraswap pair contract and also be "pair_code_id": "123", "token_code_id": "123", "owner": "terra...", - "init_hook": { - "msg": "123", - "contract_addr": "terra..." - } } ``` @@ -121,7 +117,6 @@ Register verified pair contract and token contract for pair contract creation. T /// Pair contract code ID, which is used to pub pair_code_id: u64, pub token_code_id: u64, - pub init_hook: Option, } ``` @@ -141,7 +136,7 @@ The factory contract owner can change relevant code IDs for future pair contract ### Create Pair -When a user execute `CreatePair` operation, it creates `Pair` contract and `LP(liquidity provider)` token contract. It also creates not fully initialized `PairInfo`, which will be initialized with `Register` operation from the pair contract's `InitHook`. +When a user execute `CreatePair` operation, it creates `Pair` contract and `LP(liquidity provider)` token contract. It also creates not fully initialized `PairInfo` ```json { @@ -164,7 +159,7 @@ When a user execute `CreatePair` operation, it creates `Pair` contract and `LP(l ### Register -When a user executes `CreatePair` operation, it passes `InitHook` to `Pair` contract and `Pair` contract will invoke passed `InitHook` registering created `Pair` contract to the factory. This operation is only allowed for a pair, which is not fully initialized. +When a user executes `CreatePair` operation, it passes `SubMsg` to `Pair` contract and `Pair` contract will invoke passed `SubMsg` registering created `Pair` contract to the factory. This operation is only allowed for a pair, which is not fully initialized. Once a `Pair` contract invokes it, the sender address is registered as `Pair` contract address for the given asset_infos. diff --git a/contracts/terraswap_factory/schema/execute_msg.json b/contracts/terraswap_factory/schema/execute_msg.json index 43fed0e..a179db0 100644 --- a/contracts/terraswap_factory/schema/execute_msg.json +++ b/contracts/terraswap_factory/schema/execute_msg.json @@ -68,28 +68,20 @@ "minItems": 2 }, "description": { + "description": "Pair description", "type": [ "string", "null" ] }, "end_time": { + "description": "LBP end time", "type": "integer", "format": "uint64", "minimum": 0.0 }, - "init_hook": { - "description": "Init hook for after works", - "anyOf": [ - { - "$ref": "#/definitions/InitHook" - }, - { - "type": "null" - } - ] - }, "start_time": { + "description": "LBP start time", "type": "integer", "format": "uint64", "minimum": 0.0 @@ -99,32 +91,6 @@ }, "additionalProperties": false }, - { - "description": "Register is invoked from created pair contract after initialzation", - "type": "object", - "required": [ - "register" - ], - "properties": { - "register": { - "type": "object", - "required": [ - "asset_infos" - ], - "properties": { - "asset_infos": { - "type": "array", - "items": { - "$ref": "#/definitions/WeightedAssetInfo" - }, - "maxItems": 2, - "minItems": 2 - } - } - } - }, - "additionalProperties": false - }, { "type": "object", "required": [ @@ -200,25 +166,6 @@ } ] }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, - "InitHook": { - "type": "object", - "required": [ - "contract_addr", - "msg" - ], - "properties": { - "contract_addr": { - "$ref": "#/definitions/Addr" - }, - "msg": { - "$ref": "#/definitions/Binary" - } - } - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" diff --git a/contracts/terraswap_factory/schema/factory_pair_info.json b/contracts/terraswap_factory/schema/factory_pair_info.json index 15b6f07..aeb07f2 100644 --- a/contracts/terraswap_factory/schema/factory_pair_info.json +++ b/contracts/terraswap_factory/schema/factory_pair_info.json @@ -3,113 +3,21 @@ "title": "FactoryPairInfo", "type": "object", "required": [ - "asset_infos", "contract_addr", - "end_time", - "liquidity_token", - "owner", - "start_time" + "owner" ], "properties": { - "asset_infos": { - "type": "array", - "items": { - "$ref": "#/definitions/WeightedAssetInfo" - }, - "maxItems": 2, - "minItems": 2 - }, "contract_addr": { "$ref": "#/definitions/Addr" }, - "end_time": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "liquidity_token": { - "$ref": "#/definitions/Addr" - }, "owner": { "$ref": "#/definitions/Addr" - }, - "start_time": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 } }, "definitions": { "Addr": { "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", "type": "string" - }, - "AssetInfo": { - "anyOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "$ref": "#/definitions/Addr" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "WeightedAssetInfo": { - "type": "object", - "required": [ - "end_weight", - "info", - "start_weight" - ], - "properties": { - "end_weight": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - }, - "start_weight": { - "$ref": "#/definitions/Uint128" - } - } } } } diff --git a/contracts/terraswap_factory/schema/instantiate_msg.json b/contracts/terraswap_factory/schema/instantiate_msg.json index 73abbee..15bdb16 100644 --- a/contracts/terraswap_factory/schema/instantiate_msg.json +++ b/contracts/terraswap_factory/schema/instantiate_msg.json @@ -3,19 +3,13 @@ "title": "InstantiateMsg", "type": "object", "required": [ + "owner", "pair_code_id", "token_code_id" ], "properties": { - "init_hook": { - "anyOf": [ - { - "$ref": "#/definitions/InitHook" - }, - { - "type": "null" - } - ] + "owner": { + "type": "string" }, "pair_code_id": { "description": "Pair contract code ID, which is used to", @@ -28,30 +22,5 @@ "format": "uint64", "minimum": 0.0 } - }, - "definitions": { - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, - "InitHook": { - "type": "object", - "required": [ - "contract_addr", - "msg" - ], - "properties": { - "contract_addr": { - "$ref": "#/definitions/Addr" - }, - "msg": { - "$ref": "#/definitions/Binary" - } - } - } } } diff --git a/contracts/terraswap_factory/schema/pairs_response.json b/contracts/terraswap_factory/schema/pairs_response.json index da283e2..4adb29c 100644 --- a/contracts/terraswap_factory/schema/pairs_response.json +++ b/contracts/terraswap_factory/schema/pairs_response.json @@ -9,7 +9,7 @@ "pairs": { "type": "array", "items": { - "$ref": "#/definitions/FactoryPairInfo" + "$ref": "#/definitions/PairInfo" } } }, @@ -62,14 +62,13 @@ } ] }, - "FactoryPairInfo": { + "PairInfo": { "type": "object", "required": [ "asset_infos", "contract_addr", "end_time", "liquidity_token", - "owner", "start_time" ], "properties": { @@ -84,6 +83,12 @@ "contract_addr": { "$ref": "#/definitions/Addr" }, + "description": { + "type": [ + "string", + "null" + ] + }, "end_time": { "type": "integer", "format": "uint64", @@ -92,9 +97,6 @@ "liquidity_token": { "$ref": "#/definitions/Addr" }, - "owner": { - "$ref": "#/definitions/Addr" - }, "start_time": { "type": "integer", "format": "uint64", diff --git a/contracts/terraswap_factory/src/contract.rs b/contracts/terraswap_factory/src/contract.rs index 8e2ec76..ff6ab98 100644 --- a/contracts/terraswap_factory/src/contract.rs +++ b/contracts/terraswap_factory/src/contract.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - attr, entry_point, to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, - ReplyOn, Response, StdError, StdResult, SubMsg, WasmMsg, + attr, entry_point, to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Reply, ReplyOn, + Response, StdError, StdResult, SubMsg, WasmMsg, }; use cw2::set_contract_version; use protobuf::Message; @@ -10,7 +10,6 @@ use terraswap::factory::{ ConfigResponse, ExecuteMsg, FactoryPairInfo, InstantiateMsg, MigrateMsg, PairsResponse, QueryMsg, }; -use terraswap::hook::InitHook; use terraswap::pair::InstantiateMsg as PairInstantiateMsg; use crate::error::ContractError; @@ -41,17 +40,7 @@ pub fn instantiate( }; CONFIG.save(deps.storage, &config)?; - if let Some(hook) = msg.init_hook { - Ok( - Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: hook.contract_addr.to_string(), - msg: hook.msg, - funds: vec![], - })), - ) - } else { - Ok(Response::new()) - } + Ok(Response::new()) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -72,7 +61,6 @@ pub fn execute( start_time, end_time, description, - init_hook, } => try_create_pair( deps, env, @@ -81,7 +69,6 @@ pub fn execute( start_time, end_time, description, - init_hook, ), ExecuteMsg::Unregister { asset_infos } => try_unregister(deps, env, info, asset_infos), } @@ -124,7 +111,6 @@ pub fn try_create_pair( start_time: u64, end_time: u64, description: Option, - init_hook: Option, ) -> Result { let config: Config = CONFIG.load(deps.storage)?; @@ -146,39 +132,26 @@ pub fn try_create_pair( }, )?; - let sub_message: SubMsg = SubMsg { - id: 0, - msg: WasmMsg::Instantiate { - admin: Some(config.owner.to_string()), - code_id: config.pair_code_id, - msg: to_binary(&PairInstantiateMsg { - asset_infos: weighted_asset_infos, - token_code_id: config.token_code_id, - init_hook: None, - start_time, - end_time, - description, - })?, - funds: vec![], - label: "TerraSwap pair".to_string(), - } - .into(), - gas_limit: None, - reply_on: ReplyOn::Success, - }; - - let mut msg: Vec = vec![]; - if let Some(hook) = init_hook { - msg.push(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: hook.contract_addr.to_string(), - msg: hook.msg, - funds: vec![], - })); - } - Ok(Response::new() - .add_submessage(sub_message) - .add_messages(msg) + .add_submessage(SubMsg { + id: 0, + msg: WasmMsg::Instantiate { + admin: Some(config.owner.to_string()), + code_id: config.pair_code_id, + msg: to_binary(&PairInstantiateMsg { + asset_infos: weighted_asset_infos, + token_code_id: config.token_code_id, + start_time, + end_time, + description, + })?, + funds: vec![], + label: "TerraSwap pair".to_string(), + } + .into(), + gas_limit: None, + reply_on: ReplyOn::Success, + }) .add_attributes(vec![ attr("action", "create_pair"), attr("pair", format!("{}-{}", asset_infos[0], asset_infos[1])), diff --git a/contracts/terraswap_factory/src/testing.rs b/contracts/terraswap_factory/src/testing.rs index 1175df4..1fa5789 100644 --- a/contracts/terraswap_factory/src/testing.rs +++ b/contracts/terraswap_factory/src/testing.rs @@ -26,7 +26,6 @@ fn proper_initialization() { pair_code_id: 321u64, token_code_id: 123u64, owner: "owner0000".to_string(), - init_hook: None, }; let env = mock_env(); @@ -50,7 +49,6 @@ fn update_config() { pair_code_id: 321u64, token_code_id: 123u64, owner: "owner0000".to_string(), - init_hook: None, }; let env = mock_env(); @@ -127,7 +125,6 @@ fn create_pair() { pair_code_id: 321u64, token_code_id: 123u64, owner: "owner0000".to_string(), - init_hook: None, }; let env = mock_env(); @@ -158,7 +155,6 @@ fn create_pair() { start_time, end_time, description: Some(String::from("description")), - init_hook: None, }; let env = mock_env(); @@ -180,7 +176,6 @@ fn create_pair() { msg: to_binary(&PairInstantiateMsg { asset_infos: asset_infos.clone(), token_code_id: 123u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -214,7 +209,6 @@ fn register() { pair_code_id: 321u64, token_code_id: 123u64, owner: "owner0000".to_string(), - init_hook: None, }; let env = mock_env(); @@ -240,7 +234,6 @@ fn register() { let msg = ExecuteMsg::CreatePair { asset_infos: asset_infos.clone(), - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -329,7 +322,6 @@ fn register() { let msg = ExecuteMsg::CreatePair { asset_infos: asset_infos_2.clone(), - init_hook: None, start_time, end_time, description: Some(String::from("description")), diff --git a/contracts/terraswap_factory/tests/integration.rs b/contracts/terraswap_factory/tests/integration.rs index f5e03f4..3cc8111 100644 --- a/contracts/terraswap_factory/tests/integration.rs +++ b/contracts/terraswap_factory/tests/integration.rs @@ -75,7 +75,6 @@ fn create_and_register_pair_with_reply() { pair_code_id, token_code_id, owner: owner.to_string(), - init_hook: None, }; // we can just call .unwrap() to assert this was a success @@ -111,7 +110,6 @@ fn create_and_register_pair_with_reply() { asset_infos: asset_infos.clone(), start_time, end_time, - init_hook: None, description: Some(String::from("description")), }; @@ -156,7 +154,6 @@ fn update_config() { pair_code_id, token_code_id, owner: owner.to_string(), - init_hook: None, }; // we can just call .unwrap() to assert this was a success diff --git a/contracts/terraswap_pair/README.md b/contracts/terraswap_pair/README.md index 2bea721..8b9277c 100644 --- a/contracts/terraswap_pair/README.md +++ b/contracts/terraswap_pair/README.md @@ -11,11 +11,15 @@ It creates liquidity token contract as init response, and execute init hook to r ```rust { /// Asset infos - pub asset_infos: [AssetInfo; 2], - /// Token code ID for liqudity token creation + pub asset_infos: [WeightedAssetInfo; 2], + /// Token contract code id for initialization pub token_code_id: u64, - /// Hook for post initialization - pub init_hook: Option, + /// LBP start time + pub start_time: u64, + /// LBP end time + pub end_time: u64, + /// Pair description + pub description: Option, } ``` diff --git a/contracts/terraswap_pair/schema/execute_msg.json b/contracts/terraswap_pair/schema/execute_msg.json index 2aef1bc..a960da6 100644 --- a/contracts/terraswap_pair/schema/execute_msg.json +++ b/contracts/terraswap_pair/schema/execute_msg.json @@ -14,19 +14,6 @@ }, "additionalProperties": false }, - { - "description": "Post initize step to allow user to set controlled contract address after creating it", - "type": "object", - "required": [ - "post_initialize" - ], - "properties": { - "post_initialize": { - "type": "object" - } - }, - "additionalProperties": false - }, { "description": "ProvideLiquidity a user provides pool liquidity", "type": "object", diff --git a/contracts/terraswap_pair/schema/instantiate_msg.json b/contracts/terraswap_pair/schema/instantiate_msg.json index 0193b88..bb98a20 100644 --- a/contracts/terraswap_pair/schema/instantiate_msg.json +++ b/contracts/terraswap_pair/schema/instantiate_msg.json @@ -19,28 +19,20 @@ "minItems": 2 }, "description": { + "description": "Pair description", "type": [ "string", "null" ] }, "end_time": { + "description": "LBP end time", "type": "integer", "format": "uint64", "minimum": 0.0 }, - "init_hook": { - "description": "Hook for post initalization", - "anyOf": [ - { - "$ref": "#/definitions/InitHook" - }, - { - "type": "null" - } - ] - }, "start_time": { + "description": "LBP start time", "type": "integer", "format": "uint64", "minimum": 0.0 @@ -101,25 +93,6 @@ } ] }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, - "InitHook": { - "type": "object", - "required": [ - "contract_addr", - "msg" - ], - "properties": { - "contract_addr": { - "$ref": "#/definitions/Addr" - }, - "msg": { - "$ref": "#/definitions/Binary" - } - } - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" diff --git a/contracts/terraswap_pair/schema/response_for__empty.json b/contracts/terraswap_pair/schema/response_for__empty.json index 8ceb607..25c848b 100644 --- a/contracts/terraswap_pair/schema/response_for__empty.json +++ b/contracts/terraswap_pair/schema/response_for__empty.json @@ -161,6 +161,67 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, { "type": "object", "required": [ @@ -172,6 +233,67 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "additionalProperties": false + } + ] + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "anyOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false } ] }, @@ -200,6 +322,190 @@ } } }, + "GovMsg": { + "anyOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "$ref": "#/definitions/VoteOption" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "anyOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, "ReplyOn": { "description": "Use this to define when the contract gets a response callback. If you only need it for errors or success you can select just those in order to save gas.", "type": "string", @@ -210,6 +516,90 @@ "never" ] }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "anyOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, "SubMsg_for_Empty": { "description": "A submessage that will guarantee a `reply` call on success or error, depending on the `reply_on` setting. If you do not need to process the result, use regular messages instead.\n\nNote: On error the submessage execution will revert any partial state changes due to this message, but not revert any state changes in the calling contract. If this is required, it must be done manually in the `reply` entry point.", "type": "object", @@ -241,10 +631,31 @@ } } }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, "WasmMsg": { "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", "anyOf": [ diff --git a/contracts/terraswap_pair/src/contract.rs b/contracts/terraswap_pair/src/contract.rs index 9e8d58a..51ec890 100644 --- a/contracts/terraswap_pair/src/contract.rs +++ b/contracts/terraswap_pair/src/contract.rs @@ -81,8 +81,8 @@ pub fn instantiate( PAIR_INFO.save(deps.storage, pair_info)?; - // Create LP token - let messages: Vec = vec![SubMsg { + Ok(Response::new().add_submessage(SubMsg { + // Create LP token id: INSTANTIATE_REPLY_ID, msg: WasmMsg::Instantiate { code_id: msg.token_code_id, @@ -95,7 +95,6 @@ pub fn instantiate( minter: env.contract.address.to_string(), cap: None, }), - init_hook: None, })?, funds: vec![], admin: None, @@ -104,19 +103,7 @@ pub fn instantiate( .into(), gas_limit: None, reply_on: ReplyOn::Success, - }]; - - if let Some(hook) = msg.init_hook { - Ok(Response::new() - .add_submessages(messages) - .add_message(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: hook.contract_addr.to_string(), - msg: hook.msg, - funds: vec![], - }))) - } else { - Ok(Response::new().add_submessages(messages)) - } + })) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/terraswap_pair/src/testing.rs b/contracts/terraswap_pair/src/testing.rs index e917598..9330284 100644 --- a/contracts/terraswap_pair/src/testing.rs +++ b/contracts/terraswap_pair/src/testing.rs @@ -17,7 +17,6 @@ use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg, MinterResponse}; use std::str::FromStr; use std::time::{SystemTime, UNIX_EPOCH}; use terraswap::asset::{Asset, AssetInfo, PairInfo, WeightedAsset, WeightedAssetInfo}; -use terraswap::hook::InitHook; use terraswap::pair::{ Cw20HookMsg, ExecuteMsg, InstantiateMsg, PoolResponse, ReverseSimulationResponse, SimulationResponse, @@ -85,10 +84,6 @@ fn proper_initialization() { }, ], token_code_id: 10u64, - init_hook: Some(InitHook { - contract_addr: Addr::unchecked("factory0000"), - msg: to_binary(&Uint128::from(1000000u128)).unwrap(), - }), start_time, end_time, description: Some(String::from("description")), @@ -100,43 +95,29 @@ fn proper_initialization() { let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); assert_eq!( res.messages, - vec![ - SubMsg { - id: 1, - msg: WasmMsg::Instantiate { - admin: None, - code_id: 10u64, - msg: to_binary(&TokenInstantiateMsg { - name: "terraswap liquidity token".to_string(), - symbol: "uLP".to_string(), - decimals: 6, - initial_balances: vec![], - mint: Some(MinterResponse { - minter: MOCK_CONTRACT_ADDR.to_string(), - cap: None, - }), - init_hook: None - }) - .unwrap(), - funds: vec![], - label: String::from("terraswap liquidity token"), - } - .into(), - gas_limit: None, - reply_on: ReplyOn::Success - }, - SubMsg { - id: 0, - msg: WasmMsg::Execute { - contract_addr: "factory0000".to_string(), - msg: to_binary(&Uint128::from(1000000u128)).unwrap(), - funds: vec![], - } - .into(), - gas_limit: None, - reply_on: ReplyOn::Never - }, - ] + vec![SubMsg { + id: 1, + msg: WasmMsg::Instantiate { + admin: None, + code_id: 10u64, + msg: to_binary(&TokenInstantiateMsg { + name: "terraswap liquidity token".to_string(), + symbol: "uLP".to_string(), + decimals: 6, + initial_balances: vec![], + mint: Some(MinterResponse { + minter: MOCK_CONTRACT_ADDR.to_string(), + cap: None, + }), + }) + .unwrap(), + funds: vec![], + label: String::from("terraswap liquidity token"), + } + .into(), + gas_limit: None, + reply_on: ReplyOn::Success + },] ); // store liquidity token @@ -203,7 +184,6 @@ fn provide_liquidity() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -649,7 +629,6 @@ fn withdraw_liquidity() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -792,7 +771,6 @@ fn try_native_to_token() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -999,7 +977,6 @@ fn try_token_to_native() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -1281,7 +1258,6 @@ fn test_spread() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -1439,7 +1415,6 @@ fn test_query_pool() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), @@ -1530,7 +1505,6 @@ fn test_weight_calculations() { }, ], token_code_id: 10u64, - init_hook: None, start_time, end_time, description: Some(String::from("description")), diff --git a/contracts/terraswap_pair/tests/integration.rs b/contracts/terraswap_pair/tests/integration.rs index 9d5a014..7fe6360 100644 --- a/contracts/terraswap_pair/tests/integration.rs +++ b/contracts/terraswap_pair/tests/integration.rs @@ -108,7 +108,6 @@ fn multi_initialize() { }, ], token_code_id, - init_hook: None, start_time, end_time, description: None, diff --git a/contracts/terraswap_token/schema/instantiate_msg.json b/contracts/terraswap_token/schema/instantiate_msg.json index 0c2d58c..cfd29ee 100644 --- a/contracts/terraswap_token/schema/instantiate_msg.json +++ b/contracts/terraswap_token/schema/instantiate_msg.json @@ -15,16 +15,6 @@ "format": "uint8", "minimum": 0.0 }, - "init_hook": { - "anyOf": [ - { - "$ref": "#/definitions/InitHook" - }, - { - "type": "null" - } - ] - }, "initial_balances": { "type": "array", "items": { @@ -49,14 +39,6 @@ } }, "definitions": { - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, "Cw20Coin": { "type": "object", "required": [ @@ -72,21 +54,6 @@ } } }, - "InitHook": { - "type": "object", - "required": [ - "contract_addr", - "msg" - ], - "properties": { - "contract_addr": { - "$ref": "#/definitions/Addr" - }, - "msg": { - "$ref": "#/definitions/Binary" - } - } - }, "MinterResponse": { "type": "object", "required": [ diff --git a/contracts/terraswap_token/src/contract.rs b/contracts/terraswap_token/src/contract.rs index 6b5c60c..4b845aa 100644 --- a/contracts/terraswap_token/src/contract.rs +++ b/contracts/terraswap_token/src/contract.rs @@ -1,6 +1,5 @@ use cosmwasm_std::{ entry_point, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, - WasmMsg, }; use cw2::set_contract_version; @@ -56,15 +55,7 @@ pub fn instantiate( TOKEN_INFO.save(deps.storage, &data)?; - if let Some(hook) = msg.init_hook { - Ok(Response::new().add_message(WasmMsg::Execute { - contract_addr: hook.contract_addr.to_string(), - msg: hook.msg, - funds: vec![], - })) - } else { - Ok(Response::default()) - } + Ok(Response::default()) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/packages/terraswap/examples/schema.rs b/packages/terraswap/examples/schema.rs index 2bf8240..b749a3a 100644 --- a/packages/terraswap/examples/schema.rs +++ b/packages/terraswap/examples/schema.rs @@ -4,7 +4,6 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; use terraswap::asset::{Asset, AssetInfo, PairInfo}; -use terraswap::hook::InitHook; fn main() { let mut out_dir = current_dir().unwrap(); @@ -13,7 +12,6 @@ fn main() { remove_schemas(&out_dir).unwrap(); export_schema(&schema_for!(PairInfo), &out_dir); - export_schema(&schema_for!(InitHook), &out_dir); export_schema(&schema_for!(Asset), &out_dir); export_schema(&schema_for!(AssetInfo), &out_dir); } diff --git a/packages/terraswap/src/factory.rs b/packages/terraswap/src/factory.rs index 98c288e..b9d091b 100644 --- a/packages/terraswap/src/factory.rs +++ b/packages/terraswap/src/factory.rs @@ -2,7 +2,6 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::asset::{AssetInfo, PairInfo, WeightedAssetInfo}; -use crate::hook::InitHook; use cosmwasm_std::Addr; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -11,7 +10,6 @@ pub struct InstantiateMsg { pub pair_code_id: u64, pub token_code_id: u64, pub owner: String, - pub init_hook: Option, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -33,8 +31,6 @@ pub enum ExecuteMsg { end_time: u64, /// Pair description description: Option, - /// Init hook for post initialization - init_hook: Option, }, Unregister { asset_infos: [AssetInfo; 2], diff --git a/packages/terraswap/src/hook.rs b/packages/terraswap/src/hook.rs deleted file mode 100644 index ff1fe28..0000000 --- a/packages/terraswap/src/hook.rs +++ /dev/null @@ -1,9 +0,0 @@ -use cosmwasm_std::{Addr, Binary}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InitHook { - pub msg: Binary, - pub contract_addr: Addr, -} diff --git a/packages/terraswap/src/lib.rs b/packages/terraswap/src/lib.rs index 3af6ee9..33a646e 100644 --- a/packages/terraswap/src/lib.rs +++ b/packages/terraswap/src/lib.rs @@ -1,6 +1,5 @@ pub mod asset; pub mod factory; -pub mod hook; pub mod pair; pub mod querier; pub mod router; diff --git a/packages/terraswap/src/pair.rs b/packages/terraswap/src/pair.rs index caa996a..a665c3f 100644 --- a/packages/terraswap/src/pair.rs +++ b/packages/terraswap/src/pair.rs @@ -2,7 +2,6 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use crate::asset::{Asset, WeightedAsset, WeightedAssetInfo}; -use crate::hook::InitHook; use cosmwasm_std::{Addr, Decimal, Uint128}; use cw20::Cw20ReceiveMsg; @@ -13,8 +12,6 @@ pub struct InstantiateMsg { pub asset_infos: [WeightedAssetInfo; 2], /// Token contract code id for initialization pub token_code_id: u64, - /// Hook for post initialization - pub init_hook: Option, /// LBP start time pub start_time: u64, /// LBP end time diff --git a/packages/terraswap/src/token.rs b/packages/terraswap/src/token.rs index c520545..9ee0e9d 100644 --- a/packages/terraswap/src/token.rs +++ b/packages/terraswap/src/token.rs @@ -1,7 +1,6 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::hook::InitHook; use cosmwasm_std::{StdError, StdResult, Uint128}; use cw20::{Cw20Coin, MinterResponse}; @@ -13,7 +12,6 @@ pub struct InstantiateMsg { pub decimals: u8, pub initial_balances: Vec, pub mint: Option, - pub init_hook: Option, } impl InstantiateMsg {