Skip to content

Latest commit

 

History

History
618 lines (487 loc) · 11.8 KB

Cookbook.md

File metadata and controls

618 lines (487 loc) · 11.8 KB

Contracts Cookbook

This file describes the different messages that can be sent as queries or transactions to the contracts of this repository with a description of the expected behavior.

Core shifter

Shifter is a simple contract that can execute peg and depth shift to any markets in the x/perp module of Nibiru. The contract holds a whitelist of addressses that are allowed to execute the shift.

Instantiate

The instantiation defines just the onwer of the contract, who wil be able to add and remove addresses from the whitelist, and execute the shifts.

{"owner": "cosmos1..."}

Execute

  • ShiftSwapInvariant executes a depth shift in a market.
{
  "shift_swap_invariant": {
    "pair": "uusd:usdr",
    "new_swap_invariant": "1000000"
  }
}
  • ShiftPegMultiplier executes a depth shift on a market. It can be executed by anyone.
{
  "shift_peg_multiplier": {
    "pair": "ubtc:unusd",
    "new_peg_mult": "20420.69"
  }
}
  • EditOpers adds or removes addresses from the whitelist. It can be executed by the owner.
{
  "edit_opers": {
    "add_oper": {"addr": "cosmos1..."},
    "remove_oper": {"addr": "cosmos1..."},
  }
}

Query

The queries have to do with checking permissions of addresses.

  • HasPerms checks if an address has permissions to execute shifts.
{
  "has_perms": {
    "address": "cosmos1..."
  }
}
  • Perms query the contract owner and set of operators.
{
  "perms": {},
}

Core token vesting

This contract implements vesting accounts for the CW20 and native tokens.

Instantiate

There's no instantiation message.

{
}

Execute

  • Receive
{
  "receive": {
    "sender": "cosmos1...",
    "amount": "1000000",
    "msg": "eyJ2ZXN0X2lkIjoxLCJ2ZXN0X3R5cGUiOiJ2ZXN0In0=",
  }
}
  • RegisterVestingAccount registers a vesting account
{
  "register_vesting_account": {
    "address": "cosmos1...",
    "master_address": "cosmos1...",
    "vesting_schedule": {
      "linear_vesting": {
        "start_time": "1703772805",
        "end_time": "1703872805",
        "vesting_amount": "1000000"
      }
    }
  }
}
  • DeregisterVestingAccount deregisters a vesting account
{
  "deregister_vesting_account": {
    "address": "cosmos1...",
    "denom": "uusd",
    "vested_token_recipient": "cosmos1...", // address that will receive the vested tokens after deregistration. If None, tokens are received by the owner address.
    "left_vested_token_recipient": "cosmos1...", // address that will receive the left vesting tokens after deregistration.
  }
}
  • Claim allows to claim vested tokens
{
  "claim": {
    "denom": "uusd",
    "recipient": "cosmos1...",
  }
}

Query

  • VestingAccount returns the vesting account details for a given address.
{
  "vesting_account": {
    "address": "cosmos1...",
  }
}

4. Nibi Stargate

This smart contract showcases usage examples for certain Nibiru-specific and Cosmos-SDK-specific.

4.1 Instantiate

There's no instantiation message.

{
}

4.2 Execute

  • CreateDenom creates a new denom
{
  "create_denom": { "subdenom": "zzz" }
}
  • Mint mints tokens
{
  "mint": {
    "coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
    "mint_to": "[mint-to-addr]"
  }
}
  • Burn burns tokens
{
  "burn": {
    "coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
    "burn_from": "[burn-from-addr]"
  }
}
  • ChangeAdmin changes the admin of a denom
{
  "change_admin": {
    "denom": "tf/[contract-addr]/[subdenom]",
    "new_admin": "[ADDR]"
  }
}

5. Nibi Stargate Perp

This smart contract showcases usage examples for certain Nibiru-specific for the perp market.

5.1 Instantiate

The instantiation defines the owner of the contract, who will be able to add and remove addresses from the whitelist, and execute the shifts.

{
  "admin": "cosmos1...",
}

5.2 Execute

  • MarketOrder places a market order for a specified trading pair. pair indicates the trading pair, is_long determines if it's a long or short order, quote_amount is the amount in the quote currency, leverage specifies the leverage to apply, and base_amount_limit sets a limit for the amount in the base currency.
{
  "market_order": {
    "pair": "BTC/USDT",
    "is_long": true,
    "quote_amount": "1000000",
    "leverage": "2.0",
    "base_amount_limit": "5000000"
  }
}
  • ClosePosition closes an open position for a specified trading pair.
{
  "close_position": {
    "pair": "BTC/USDT"
  }
}
  • AddMargin adds margin to an existing position for a specified trading pair. margin is the amount of additional margin to add.
{
  "add_margin": {
    "pair": "BTC/USDT",
    "margin": {"denom": "usdt", "amount": "100000"}
  }
}
  • RemoveMargin removes margin from an existing position for a specified trading pair. margin is the amount of margin to remove.
{
  "remove_margin": {
    "pair": "BTC/USDT",
    "margin": {"denom": "usdt", "amount": "50000"}
  }
}
  • MultiLiquidate triggers multiple liquidations based on the provided arguments. liquidations is a list of liquidation arguments specifying the details for each liquidation.
{
  "multi_liquidate": {
    "liquidations": [
      {
        "pair": "BTC/USDT",
        "trader": "cosmos1...",
      },
      {
        "pair": "BTC/USDT",
        "trader": "cosmos1...",
      }
    ]
  }
}
  • DonateToInsuranceFund allows donation to the insurance fund. donation is the coin and amount to donate.
{
  "donate_to_insurance_fund": {
    "donation": {"denom": "usdt", "amount": "100000"}
  }
}
  • Claim facilitates the claiming of funds. funds is an optional field specifying a particular coin and amount to claim, claim_all is an optional flag to claim all funds, and to is the address to which the funds will be sent.
{
  "claim": {
    "funds": {"denom": "usdt", "amount": "100000"},
    "claim_all": true,
    "to": "cosmos1..."
  }
}

This format aligns with the style of your previous documentation, ensuring consistency and clarity in the explanation of each function and its parameters.

6. Nusd Valuator

This smart contract is a simple valuator for the nusd token, which takes one collateral.

6.1 Instantiate

The owner is the only one who can execute messages in the contract

{
  "owner": "cosmos1...",
  "accepted_denoms": "uusdc",
}

6.2 Execute

  • ChangeDenom updates the accepted denoms
{
  "change_denom": {
    "from: "uusdc",
    "to": "uusd",
  }
}
  • AddDenom adds a new accepted denom
{
  "add_denom": {
    "denom": "uusd",
  }
}
  • RemoveDenom removes an accepted denom
{
  "remove_denom": {
    "denom": "uusd",
  }
}

6.3 Query

  • Mintable queries the amount of μNUSD that can be minted in exchange for the specified set of from_coins.
{
  "mintable": {
    "from_coins": ["BTC", "ETH"]
  }
}
  • Redeemable calculates the amount of a specified to_denom currency that is redeemable for a given redeem_amount of μNUSD.
{
  "redeemable": {
    "redeem_amount": "1000000",
    "to_denom": "usdt"
  }
}
  • AcceptedDenoms retrieves the set of token denominations that are accepted as collateral.
{
  "accepted_denoms": {}
}
  • RedeemableChoices provides a set of possible redeemable coin options that could be received when redeeming a specified redeem_amount of μNUSD.
{
  "redeemable_choices": {
    "redeem_amount": "1000000"
  }
}

7. Airdrop token vesting

This contract implements vesting accounts for the native tokens.

7.1 Instantiate

We need to specify admin and managers

{
  "admin": "cosmos1...",
  "managers": ["cosmos1...", "cosmos1..."]
}

7.2 Execute

  • RewardUsers registers several vesting contracts
{
  "reward_users": {
    "rewards": [
      {
        "user_address": "cosmos1...",
        "vesting_amount": "1000000",
        "cliff_amount": "100000", // Only needed if vesting schedule is linear with cliff
      }
    ],
    "vesting_schedule": {
      "linear_vesting": {
        "start_time": "1703772805",
        "end_time": "1703872805",
        "vesting_amount": "0" // This amount does not matter
      }
    }
  }
}
  • DeregisterVestingAccount deregisters a vesting account
{
  "deregister_vesting_account": {
    "address": "cosmos1...",
    "vested_token_recipient": "cosmos1...", // address that will receive the vested tokens after deregistration. If None, tokens are received by the owner address.
    "left_vested_token_recipient": "cosmos1...", // address that will receive the left vesting tokens after deregistration.
  }
}
  • Claim allows to claim vested tokens
{
  "claim": {
    "recipient": "cosmos1...",
  }
}

7.3 Query

  • VestingAccount returns the vesting account details for a given address.
{
  "vesting_account": {
    "address": "cosmos1...",
  }
}

8. Auto compounder

This contract manages staking re-delegation processes securely, allowing for auto-compounding of staked funds.

8.1 Instantiate

We need to specify admin and managers

{
  "admin": "cosmos1...",
  "managers": ["cosmos1...", "cosmos1..."]
}

8.2 Execute

Admin functions

  • SetAutoCompounderMode sets the auto compounder mode
{
  "set_auto_compounder_mode": {
    "mode": "true" // true or false
  }
}
  • Withdraw allows to withdraw the funds from the contract

    {
      "withdraw": {
        "amount": "1000000"
        "recipient": "cosmos1..."
      }
    }
  • unstakes allows to unstake the funds from the contract

    {
      "unstake": {
        "unstake_msgs": [
          {
            "validator": "cosmosvaloper1...",
            "amount": "1000000"
          },
          {
            "validator": "cosmosvaloper1...",
            "amount": "1000000"
          }
        ]
      }
    }
  • update managers allows to update the managers of the contract

{
  "update_managers": {
    "managers": ["cosmos1...", "cosmos1..."]
  }
}

Manager functions

  • stake allows to stake the funds from the contract. The shares are normalized
{
  "stake": {
    "stake_msgs": [
      {
        "validator": "cosmosvaloper1...",
        "share": "1000000"
      },
      {
        "validator": "cosmosvaloper1...",
        "share": "1000000"
      }
    ]
  },
  "amount": "1000000"
}

8.3 Query

  • auto compounder mode returns wether the auto compounder mode is enabled or not
{
  "auto_compounder_mode": {}
}
  • AdminAndManagers returns the admin and managers of the contract
{
  "admin_and_managers": {}
}