Skip to content

Instantly share code, notes, and snippets.

View larry0x's full-sized avatar
🇵🇹
PT

Larry larry0x

🇵🇹
PT
View GitHub Profile
@larry0x
larry0x / json-raw-message-to-sdk-msg.go
Created June 16, 2023 03:37
json.RawMessage to sdk.Msg
package main
import (
"encoding/json"
"fmt"
"reflect"
"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
//! ```cargo
//! [dependencies]
//! bech32 = "0.9"
//! bip32 = "0.5"
//! dialoguer = "0.10"
//! hex = "0.4"
//! k256 = "0.13"
//! ripemd = "0.1"
//! thiserror = "1"
//! ```

The data field in cosmwasm_std::Response is underused. We should use it more! Here's why.

Often we want to program contracts that do this:

  1. call another contract
  2. after the call is completed, handle the response and do some extra actions

For example,

  1. swap some token A to token B at Astroport
[global]
log_level = 'info'
[mode]
[mode.clients]
enabled = true
refresh = true
misbehaviour = false
# ---------------------------------- method 1 ----------------------------------
git clone https://github.com/cosmos/cosmos-sdk.git
git clone https://github.com/larry0x/simapp.git
cd cosmos-sdk
git checkout v0.47.2
git subtree split -P simapp -b split
cd ../simapp
// This script generates a v1 TextProposal, that is, a v1 proposal with no
// message.
const mrc = 23;
const title = "Add WBTC/OSMO 14d vault tokens as a collateral asset in Mars Farm";
//------------------------------------------------------------------------------
const fs = require("fs");

Set token creation fee to zero; introduce an alternative spam-prevention mechanism

Background

In Cosmos ecosystem there are two prevailing fungible token standards, the native token and the CW20. Osmosis is equipped with a “tokenfactory” module which allows anyone (human users or smart contracts) to mint native tokens. This is a much desired feature, as native token is superior than CW20 for many reasons which I will not cover here.

Given that Osmosis currently has a very low gas price, tokenfactory needs a mechanism to deter spamming, meaning an attacker creating a massive amount of new tokens that take up nodes’ storage space. It does this by charging a fee, currently set at 10 OSMO, whenever a new token is created. This is known as the denom_creation_fee in the code.

ics title stage category author created modified
999
One Channel
draft
IBC/APP
Larry Engineer <[email protected]>
2023-03-02
2023-03-02
@larry0x
larry0x / .bashrc
Last active February 24, 2023 03:05
Set up a Ubuntu server
# ls
alias ls="ls -avhl --color=auto --group-directories-first"
# systemd
alias start="sudo systemctl start"
alias stop="sudo systemctl stop"
alias restart="sudo systemctl restart"
# ports
alias ports="netstat -tulpn | sort -t: -k2 -n"
#!/bin/zsh
set -e
# change this to your address!
delegator="mars1..."
append-msg() {
tx=$1
msgs=$(echo $tx | jq ".body.messages")