Skip to content

Instantly share code, notes, and snippets.

View ethanfrey's full-sized avatar

Ethan Frey ethanfrey

View GitHub Profile
@ethanfrey
ethanfrey / send_packets.js
Created January 29, 2022 08:48
CW20 IBC transfer
#!/usr/bin/env node
/*jshint esversion: 8 */
/* eslint-disable @typescript-eslint/naming-convention */
const { toBase64, toUtf8 } = require('@cosmjs/encoding');
const axios = require('axios');
const { SigningCosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const { GasPrice } = require('@cosmjs/stargate');
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
@ethanfrey
ethanfrey / PoE-Contracts.svg
Created January 12, 2022 19:09
PoE Contracts Basic
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ethanfrey
ethanfrey / ibc_reply.rs
Created November 3, 2021 19:56
IBC Reply Error Handling
#[entry_point]
pub fn ibc_packet_receive(
deps: DepsMut,
_env: Env,
msg: IbcPacketReceiveMsg,
) -> Result<IbcReceiveResponse, Never> {
// other parse code here...
let msg = Cw20ExecuteMsg::Transfer {
recipient,
@ethanfrey
ethanfrey / migrate.rs
Created November 3, 2021 19:46
Basic migration skeleton
const CONTRACT_NAME: &str = "crates.io:my-crate-name";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
#[entry_point]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let ver = cw2::get_contract_version(deps.storage)?;
// ensure we are migrating from an allowed contract
if ver.contract != CONTRACT_NAME {
return Err(StdError::generic_err("Can only upgrade from same type").into());
}
@ethanfrey
ethanfrey / sudo.rs
Created October 27, 2021 17:59
Example sudo
#[entry_point]
pub fn sudo(_deps: DepsMut, _env: Env, msg: SudoMsg) -> Result<Response, HackError> {
match msg {
// you certainly don't want just anyone calling this
SudoMsg::TakeFunds { recipient, amount } => {
let msg = BankMsg::Send {
to_address: recipient,
amount,
};
Ok(Response::new().add_message(msg))
@ethanfrey
ethanfrey / parse_reply.rs
Created October 27, 2021 17:24
Parse Instantiation Address on Reply
use cw0::parse_reply_instantiate_data;
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
let res = parse_reply_instantiate_data(msg)?;
let child_contract = deps.api.addr_validate(res.contract_address)?;
// store this where it belongs...
}
@ethanfrey
ethanfrey / query_whitelist.rs
Created October 27, 2021 17:04
Query Trusted Circle Whitelist
use cosmwasm_std::{Addr, QuerierWrapper};
use cw4::Cw4Contract;
fn assert_membership(querier: &QuerierWrapper, contract: &Addr, account: &Addr) -> StdResult<()> {
let contract = Cw4Contract(addr.clone());
if whitelist.is_member(&deps.querier, sender)?.is_none() {
return Err(StdError::generic("unauthorized"));
}
Ok(())
}
@ethanfrey
ethanfrey / query.rs
Last active October 14, 2021 15:47
Query Description
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, StdError> {
/* your implementation here */
}
@ethanfrey
ethanfrey / execute.rs
Created October 14, 2021 15:20
Execute Prototype
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
/* your implementation here */
}
@ethanfrey
ethanfrey / CLA.md
Created July 24, 2020 11:38
Contributor License Agreement for CosmWasm

Contributor License Agreement

The following terms are used throughout this agreement:

  • You - the person or legal entity including its affiliates asked to accept this agreement. An affiliate is any entity that controls or is controlled by the legal entity, or is under common control with it.
  • Project - is an umbrella term that refers to any and all Confio OÜ open source projects.
  • Contribution - any type of work that is submitted to a Project, including any modifications or additions to existing work.
  • Submitted - conveyed to a Project via a pull request, commit, issue, or any form of electronic, written, or verbal communication with Confio OÜ, contributors or maintainers.

1. Grant of Copyright License.