Andromeda
Search
⌃K

CW20 Exchange

Introduction

The CW20 Exchange ADO is used to sell CW20 tokens for other assets. The token to be sold is specified at instantiation, and then sales can be started on the token by the contract owner by sending them to this ADO. Each sale has an "asset" to purchase the tokens with. This asset can be:
  • CW20
  • Native
Users can then purchase the CW20 token being sold by sending the required asset to the contract.
Multiple sales can take place at the same time but no two sales can have the same purchasing asset.

InstantiateMsg

Rust
JSON
pub struct InstantiateMsg {
pub token_address: AndrAddress,
}
{
"token_address":{
"identifier":"andr1..."
}
}
Name
Type
Description
token_address
Contract address of the CW20 token to be sold.

ExecuteMsg

Receive

Receives CW20 tokens sent from the token_address contract by performing a Send. These tokens can be set for sale or used to purchase other CW20 tokens. This depends on the attached hook message.
Rust
pub enum ExecuteMsg {
Receive(Cw20ReceiveMsg),
}

Cw20ReceiveMsg

pub struct Cw20ReceiveMsg {
pub sender: String,
pub amount: Uint128,
pub msg: Binary,
}
The msg in the Cw20ReceiveMsgshould be a base64 encoded Cw20HookMsg.

Cw20HookMsg

The CW20 tokens sent with StartSale should come from the contract address specified at instantiation.
The CW20 tokens sent with Purchase should be the same as the defined Asset from StartSale message.

StartSale

Only available to the contract owner.
Starts a sale on the CW20 tokens sent. This is attached as a msg when sending the CW20 tokens to the Exchange ADO.
Rust
JSON
pub enum Cw20HookMsg {
StartSale {
asset: AssetInfo,
exchange_rate: Uint128,
recipient: Option<String>,
}
}
{
"start_sale":{
"asset":{
"cw20":"andr1..."
},
"exchange_rate":"5"
}
}
Name
Type
Description
asset
AssetInfo
The asset that may be used to purchase the token.
exchange_rate
Uint128
The amount of the above asset required to purchase a single token.
recipient
Option<String>
The recipient of the sale proceeds. Defaults to the sender if not specified.

AssetInfo

/// Represents an **asset info** instance containing only verified data;
///to be saved in contract storage
pub type AssetInfo = AssetInfoBase<Addr>;
pub enum AssetInfoBase<T> {
Native(String),
Cw20(T),
}
  • Native SDK coins: To create an asset info instance of this type, provide the denomination
  • CW20 tokens: To create an asset info instance of this type, provide the contract address

Purchase

Purchase tokens using the CW20 tokens sent. This is attached as a msg when sending the CW20 tokens to the Exchange ADO.
You need to send an amount wich will get you a whole number in exchange. For example if the exchange rate is 5, then you need to send a multiple of 5 and nothing in between.
Rust
JSON
pub enum Cw20HookMsg {
Purchase {
recipient: Option<String>,
}
}
{
"purchase":{
"recipient":"andr1..."
}
}
Name
Type
Description
recipient
Option<String>
Optional recipient of the purchased CW20 tokens. If not set, defaults to the sender.

CancelSale

Only available for the contract owner.
Cancels an ongoing sale.
Rust
JSON
pub enum ExecuteMsg {
CancelSale {
asset: AssetInfo
}
}
{
"cancel_sale":{
"asset":{
"cw20":"andr1..."
}
}
}
Name
Type
Description
asset
AssetInfo
The purchasing asset of the sale to cancel.

Purchase

Purchase tokens with native funds.
Rust
JSON
pub enum ExecuteMsg {
Purchase {
recipient: Option<String>
}
}
{
"purchase":{
"recipient":"andr1..."
}
}
Name
Type
Description
recipient
Option<String>
Optional recipient to receive the purchased tokens. Defaults to the sender if not specified.

AndrReceive

The rest of the executes can be found in the AndrReceive section.

QueryMsg

Sale

Queries the sale info for the specified asset.
Rust
JSON
pub enum QueryMsg {
#[returns(SaleResponse)]
Sale { asset: AssetInfo }
}
{
"sale":{
"asset":{
"cw20":"andr1..."
}
}
}
Name
Type
Description
asset
AssetInfo
The asset of the sale to get info for.

SaleResponse

Rust
pub struct SaleResponse {
pub sale: Option<Sale>,
}
Name
Type
Description
sale
Option<Sale>
The sale data if it exists.

Sale

pub struct Sale {
pub exchange_rate: Uint128,
pub amount: Uint128,
pub recipient: String,
}
Name
Type
Description
exchange_rate
Uint128
The amount of exchange asset needed to purchase one token.
amount
Uint128
The amount of tokens for sale at the specified exchange_rate.
recipient
String
The recipient of the sale proceeds.

TokenAddress

Queries the contract address of the token being purchased.
Rust
JSON
pub enum QueryMsg {
#[returns(TokenAddressResponse)]
TokenAddress {}
}
{
"token_address":{}
}

TokenAddressResponse

The address of the token being sold.
pub struct TokenAddressResponse {
pub address: String,
}

SaleAssets

Queries the different assets of the sale.
Rust
JSON
pub enum QueryMsg {
#[returns(SaleAssetsResponse)]
SaleAssets {
start_after: Option<String>,
limit: Option<u32>,
}
}
{
"sale_assets":{
"start_after":"token8",
"limit": 67
}
}
Name
Type
Description
start_after
Option<String>
An optional address for which to start after, used for pagination.
limit
Option<u32>
Optional limit to the number of assets that are returned. Default limit is 50 and the max limit is 100.

SaleAssetsResponse

A vec of string containing each of the assets.
pub struct SaleAssetsResponse {
pub assets: Vec<String>,
}

AndrQuery

A set of base queries common to all Andromeda ADOs. Check AndrQuery.