Skip to content

Commit

Permalink
feat: remove init_hook (#20)
Browse files Browse the repository at this point in the history
* feat: remove init_hook

* Update schema

* update readme files
  • Loading branch information
wedancedalot authored Nov 12, 2021
1 parent 4aeee4d commit 4efcc91
Show file tree
Hide file tree
Showing 23 changed files with 488 additions and 433 deletions.
9 changes: 2 additions & 7 deletions contracts/terraswap_factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
}
}
```

Expand Down Expand Up @@ -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<InitHook>,
}
```

Expand All @@ -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
{
Expand All @@ -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.

Expand Down
59 changes: 3 additions & 56 deletions contracts/terraswap_factory/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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": [
Expand Down Expand Up @@ -200,25 +166,6 @@
}
]
},
"Binary": {
"description": "Binary is a wrapper around Vec<u8> 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<u8>",
"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"
Expand Down
94 changes: 1 addition & 93 deletions contracts/terraswap_factory/schema/factory_pair_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
37 changes: 3 additions & 34 deletions contracts/terraswap_factory/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<u8> 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<u8>",
"type": "string"
},
"InitHook": {
"type": "object",
"required": [
"contract_addr",
"msg"
],
"properties": {
"contract_addr": {
"$ref": "#/definitions/Addr"
},
"msg": {
"$ref": "#/definitions/Binary"
}
}
}
}
}
14 changes: 8 additions & 6 deletions contracts/terraswap_factory/schema/pairs_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"pairs": {
"type": "array",
"items": {
"$ref": "#/definitions/FactoryPairInfo"
"$ref": "#/definitions/PairInfo"
}
}
},
Expand Down Expand Up @@ -62,14 +62,13 @@
}
]
},
"FactoryPairInfo": {
"PairInfo": {
"type": "object",
"required": [
"asset_infos",
"contract_addr",
"end_time",
"liquidity_token",
"owner",
"start_time"
],
"properties": {
Expand All @@ -84,6 +83,12 @@
"contract_addr": {
"$ref": "#/definitions/Addr"
},
"description": {
"type": [
"string",
"null"
]
},
"end_time": {
"type": "integer",
"format": "uint64",
Expand All @@ -92,9 +97,6 @@
"liquidity_token": {
"$ref": "#/definitions/Addr"
},
"owner": {
"$ref": "#/definitions/Addr"
},
"start_time": {
"type": "integer",
"format": "uint64",
Expand Down
Loading

0 comments on commit 4efcc91

Please sign in to comment.