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

Feat: missing tokenfactory bindings #128

Merged
merged 1 commit into from
Feb 13, 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
121 changes: 121 additions & 0 deletions packages/neutron-sdk/schema/neutron_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,99 @@
},
"additionalProperties": false
},
{
"description": "TokenFactoryMessage Contracts can force specified `amount` of an existing factory denom that they are admin of to a `transfer_to_address` from a `transfer_from_address`.",
"type": "object",
"required": [
"force_transfer"
],
"properties": {
"force_transfer": {
"type": "object",
"required": [
"amount",
"denom",
"transfer_from_address",
"transfer_to_address"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"type": "string"
},
"transfer_from_address": {
"type": "string"
},
"transfer_to_address": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "TokenFactoryMessage Contracts can set a metadata for of an existing factory denom that they are admin of.",
"type": "object",
"required": [
"set_denom_metadata"
],
"properties": {
"set_denom_metadata": {
"type": "object",
"required": [
"base",
"denom_units",
"description",
"display",
"name",
"symbol",
"uri",
"uri_hash"
],
"properties": {
"base": {
"description": "*base** represents the base denom (should be the DenomUnit with exponent = 0).",
"type": "string"
},
"denom_units": {
"description": "*denom_units** represents the list of DenomUnit's for a given coin",
"type": "array",
"items": {
"$ref": "#/definitions/DenomUnit"
}
},
"description": {
"description": "*description** description of a token",
"type": "string"
},
"display": {
"description": "**display** indicates the suggested denom that should be displayed in clients.",
"type": "string"
},
"name": {
"description": "*name** defines the name of the token (eg: Cosmos Atom)",
"type": "string"
},
"symbol": {
"description": "**symbol** is the token symbol usually shown on exchanges (eg: ATOM). This can be the same as the display.",
"type": "string"
},
"uri": {
"description": "*uri** to a document (on or off-chain) that contains additional information. Optional.",
"type": "string"
},
"uri_hash": {
"description": "**uri_hash** is a sha256 hash of a document pointed by URI. It's used to verify that the document didn't change. Optional.",
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "AddSchedule adds new schedule with a given `name`. Until schedule is removed it will execute all `msgs` every `period` blocks. First execution is at least on `current_block + period` block. [Permissioned - DAO Only]",
"type": "object",
Expand Down Expand Up @@ -751,6 +844,34 @@
}
}
},
"DenomUnit": {
"description": "**DenomUnit** represents a struct that describes a given denomination unit of the basic token.",
"type": "object",
"required": [
"aliases",
"denom",
"exponent"
],
"properties": {
"aliases": {
"description": "*aliases** is a list of string aliases for the given denom",
"type": "array",
"items": {
"type": "string"
}
},
"denom": {
"description": "*denom** represents the string name of the given denom unit (e.g uatom).",
"type": "string"
},
"exponent": {
"description": "**exponent** represents power of 10 exponent that one must raise the base_denom to in order to equal the given DenomUnit's denom 1 denom = 10^exponent base_denom (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with exponent = 6, thus: 1 atom = 10^6 uatom).",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"IbcFee": {
"description": "IbcFee defines struct for fees that refund the relayer for `SudoMsg` messages submission. Unused fee kind will be returned back to message sender. Please refer to these links for more information: IBC transaction structure - <https://docs.neutron.org/neutron/interchain-txs/messages/#msgsubmittx> General mechanics of fee payments - <https://docs.neutron.org/neutron/feerefunder/overview/#general-mechanics>",
"type": "object",
Expand Down
134 changes: 111 additions & 23 deletions packages/neutron-sdk/src/bindings/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
NeutronError, NeutronResult,
};

use cosmwasm_std::{Binary, Coin, CosmosMsg, CustomMsg, StdError, Uint128};
use cosmwasm_std::{Binary, Coin, CosmosMsg, CustomMsg, DenomUnit, StdError, Uint128};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json_wasm::to_string;
Expand Down Expand Up @@ -169,6 +169,41 @@ pub enum NeutronMsg {
contract_addr: String,
},

/// TokenFactoryMessage
/// Contracts can force specified `amount` of an existing factory denom
/// that they are admin of to a `transfer_to_address` from a `transfer_from_address`.
ForceTransfer {
denom: String,
amount: Uint128,
transfer_from_address: String,
transfer_to_address: String,
},

/// TokenFactoryMessage
/// Contracts can set a metadata for of an existing factory denom
/// that they are admin of.
SetDenomMetadata {
/// **description** description of a token
description: String,
/// **denom_units** represents the list of DenomUnit's for a given coin
denom_units: Vec<DenomUnit>,
/// **base** represents the base denom (should be the DenomUnit with exponent = 0).
base: String,
/// **display** indicates the suggested denom that should be
/// displayed in clients.
display: String,
/// **name** defines the name of the token (eg: Cosmos Atom)
name: String,
/// **symbol** is the token symbol usually shown on exchanges (eg: ATOM). This can
/// be the same as the display.
symbol: String,
/// **uri** to a document (on or off-chain) that contains additional information. Optional.
uri: String,
/// **uri_hash** is a sha256 hash of a document pointed by URI. It's used to verify that
/// the document didn't change. Optional.
uri_hash: String,
},

/// AddSchedule adds new schedule with a given `name`.
/// Until schedule is removed it will execute all `msgs` every `period` blocks.
/// First execution is at least on `current_block + period` block.
Expand Down Expand Up @@ -345,17 +380,17 @@ impl NeutronMsg {
}
}

// Basic helper to build create denom message passed to TokenFactory module:
// * **subdenom** is a subdenom name for denom to be created.
/// Basic helper to build create denom message passed to TokenFactory module:
/// * **subdenom** is a subdenom name for denom to be created.
pub fn submit_create_denom(subdenom: impl Into<String>) -> Self {
NeutronMsg::CreateDenom {
subdenom: subdenom.into(),
}
}

// Basic helper to define change of admin for a token passed to TokenFactory module:
// * **denom** is a name of the denom to change an admin for;
// * **new_admin_address** is a new admin address for a denom.
/// Basic helper to define change of admin for a token passed to TokenFactory module:
/// * **denom** is a name of the denom to change an admin for;
/// * **new_admin_address** is a new admin address for a denom.
pub fn submit_change_admin(
denom: impl Into<String>,
new_admin_address: impl Into<String>,
Expand All @@ -366,10 +401,10 @@ impl NeutronMsg {
}
}

// Basic helper to define mint tokens passed to TokenFactory module:
// * **denom** is a name of the denom;
// * **amount** is an amount of tokens to mint;
// * **mint_to_address** is an address that will receive minted tokens.
/// Basic helper to define mint tokens passed to TokenFactory module:
/// * **denom** is a name of the denom;
/// * **amount** is an amount of tokens to mint;
/// * **mint_to_address** is an address that will receive minted tokens.
pub fn submit_mint_tokens(
denom: impl Into<String>,
amount: Uint128,
Expand All @@ -382,9 +417,9 @@ impl NeutronMsg {
}
}

// Basic helper to define burn tokens passed to TokenFactory module:
// * **denom** is a name of the denom;
// * **amount** is an amount of tokens to burn.
/// Basic helper to define burn tokens passed to TokenFactory module:
/// * **denom** is a name of the denom;
/// * **amount** is an amount of tokens to burn.
pub fn submit_burn_tokens(denom: impl Into<String>, amount: Uint128) -> Self {
NeutronMsg::BurnTokens {
denom: denom.into(),
Expand All @@ -393,8 +428,8 @@ impl NeutronMsg {
}
}

// Basic helper to create set before send hook message passed to TokenFactory module:
// * **denom** is a name for denom for hook to be created.
/// Basic helper to create set before send hook message passed to TokenFactory module:
/// * **denom** is a name for denom for hook to be created.
pub fn submit_set_before_send_hook(
denom: impl Into<String>,
contract_addr: impl Into<String>,
Expand All @@ -405,22 +440,75 @@ impl NeutronMsg {
}
}

// Basic helper to define add schedule passed to Cron module:
// * **name** is a name of the schedule;
// * **period** is a period of schedule execution in blocks;
// * **msgs** is the messages that will be executed.
/// Basic helper to create force transfer message passed to TokenFactory module:
/// * **denom** is a name for a denom to transfer;
/// * **amount** is an amount of **denom** tokens to transfer;
/// * **from_address** is from which address to transfer tokens;
/// * **to_address** is where to transfer tokens.
pub fn submit_force_transfer(
denom: impl Into<String>,
amount: Uint128,
from_address: impl Into<String>,
to_address: impl Into<String>,
) -> Self {
NeutronMsg::ForceTransfer {
denom: denom.into(),
amount,
transfer_from_address: from_address.into(),
transfer_to_address: to_address.into(),
}
}
/// Basic helper to create a set denom metadata message passed to TokenFactory module:
/// * **description** description of a token;
/// * **denom_units** represents the list of DenomUnit's for a given coin;
/// * **base** represents the base denom (should be the DenomUnit with exponent = 0);
/// * **display** indicates the suggested denom that should be
/// displayed in clients;
/// * **name** defines the name of the token (eg: Cosmos Atom);
/// * **symbol** is the token symbol usually shown on exchanges (eg: ATOM). This can
/// be the same as the display;
/// * **uri** to a document (on or off-chain) that contains additional information. Optional;
/// * **uri_hash** is a sha256 hash of a document pointed by URI. It's used to verify that
/// the document didn't change. Optional.
#[allow(clippy::too_many_arguments)]
pub fn submit_set_denom_metadata(
description: String,
denom_units: Vec<DenomUnit>,
base: String,
display: String,
name: String,
symbol: String,
uri: String,
uri_hash: String,
) -> Self {
NeutronMsg::SetDenomMetadata {
description,
denom_units,
base,
display,
name,
symbol,
uri,
uri_hash,
}
}

/// Basic helper to define add schedule passed to Cron module:
/// * **name** is a name of the schedule;
/// * **period** is a period of schedule execution in blocks;
/// * **msgs** is the messages that will be executed.
pub fn submit_add_schedule(name: String, period: u64, msgs: Vec<MsgExecuteContract>) -> Self {
NeutronMsg::AddSchedule { name, period, msgs }
}

// Basic helper to define remove schedule passed to Cron module:
// * **name** is a name of the schedule to be removed.
/// Basic helper to define remove schedule passed to Cron module:
/// * **name** is a name of the schedule to be removed.
pub fn submit_remove_schedule(name: String) -> Self {
NeutronMsg::RemoveSchedule { name }
}

// Basic helper to define resubmit failure passed to Contractmanager module:
// * **failure_id** is an id of the failure to be resubmitted.
/// Basic helper to define resubmit failure passed to Contractmanager module:
/// * **failure_id** is an id of the failure to be resubmitted.
pub fn submit_resubmit_failure(failure_id: u64) -> Self {
NeutronMsg::ResubmitFailure { failure_id }
}
Expand Down
Loading