Skip to content

Instantly share code, notes, and snippets.

@dckc

dckc/Makefile Secret

Last active May 2, 2022 09:43
Show Gist options
  • Save dckc/9a336a983a30a20751b38380e3308fab to your computer and use it in GitHub Desktop.
Save dckc/9a336a983a30a20751b38380e3308fab to your computer and use it in GitHub Desktop.
sending a payment over IBC to agoricdev-6 from cosmoshub-test

I got my relayer to relay an IBC payment from the cosmos testnet to our devnet!

15.00 Photon in my wallet

Starting a hermes relayer between cosmos and agoric testnets

Grab the Makefile etc. by, for example, cloning this gist. Then:

  1. make task/restore-keys to:
    • build a docker image for the Hermes IBC Relayer CLI (v0.9.0)
    • create a docker volume for the state
    • generate a mnemonic; import ("recover") secrets for accounts on both chains
  2. Update ADDR_AG, ADDR_COSMOS in Makefile with the addresses from step 1.
  3. make task/tap-agoric-faucet; follow instructions to tap the faucet; then touch task/tap-agoric-faucet
  4. make task/create-channel to:
    • tap cosmos faucet
    • create an IBC channel
  5. Take note of the channel ids (details below)
  6. make start or docker-compose up -d to start the relayer.

Creating the IBC channel results in something like this that includes the channel ids:

2021-12-06T21:43:16.791053Z DEBUG ThreadId(01) do_chan_open_finalize for src_channel_id: channel-43, dst_channel_id: channel-3
Success: Channel {
    ordering: Unordered,
    a_side: ChannelSide {
        chain: ProdChainHandle {
            chain_id: ChainId {
                id: "cosmoshub-testnet",
                version: 0,
            },
            runtime_sender: Sender { .. },
        },
        client_id: ClientId(
            "07-tendermint-54",
        ),
        connection_id: ConnectionId(
            "connection-46",
        ),
        port_id: PortId(
            "transfer",
        ),
        channel_id: Some(
            ChannelId(
                "channel-43",
            ),
        ),
    },
    b_side: ChannelSide {
        chain: ProdChainHandle {
            chain_id: ChainId {
                id: "agoricdev-6",
                version: 6,
            },
            runtime_sender: Sender { .. },
        },
        client_id: ClientId(
            "07-tendermint-5",
        ),
        connection_id: ConnectionId(
            "connection-5",
        ),
        port_id: PortId(
            "transfer",
        ),
        channel_id: Some(
            ChannelId(
                "channel-3",
            ),
        ),
    },
    connection_delay: 0ns,
    version: Some(
        "ics20-1",
    ),
}

Provision user account on agorictest-6

Normally Setting up an Agoric Dapp Client with docker compose would suffice, but:

ISSUE: needs home.pegasusConnections special power due to Agoric/agoric-sdk#4153

I don't have good notes on how I did this... agoric start --devnet? Anyway... the address is

agoric18kzgpc36eacsdhx8wrdjywvdu3s6dsg2ae3t54

Create peg and import issuer

Using contract/src/deploy-peg.js based on pegasus/demo.md:

$ agoric deploy contract/src/deploy-peg.js
Open CapTP connection to ws://127.0.0.1:8000/private/captp...o
agoric: deploy: running /home/connolly/projects/agoric/ibc-fun/contract/src/deploy-peg.js
agoric: deploy: Deploy script will run with Node.js ESM
awaiting home...
awaiting pegasusConnections...
pegasusConnections: 11
getting instance, publicFacet
creating peg-channel-10-uphoton from /ibc-port/transfer/unordered/ics20-1/ibc-channel/channel-10
await brand, issuer, board...
{ issuerBoardId: '495234043' } {
  cosmos: { keyword: 'Photon', denom: 'uphoton', decimalPlaces: 6 },
  agoric: { channel: 'channel-10' }
}

mostly follow pegasus/demo.md (IOU details)

create purse

trick: set auto-deposit in REPL

Set up keplr

import both chains using wallet.agoric.app

Send payment with keplr

  • start on cosmos hub testnet
  • ibc transfer
  • create channel to agoricdev-6 (@@src channel from above)
  • payee from agoric wallet

hermes relayer logs say:

2021-12-05T00:20:23.118936Z DEBUG ThreadId(30) [agoricdev-6:transfer/channel-2 -> cosmoshub-testnet] confirmed after 5.102978009s: TxHashes: count=1; 410AD46232C10FB7062B778F94C587238CA45B51EA8BA1A78DD47AC742EF4237
...
2021-12-05T00:20:23.194817Z TRACE ThreadId(24) extracted ibc_client event UpdateClient(UpdateClient { common: Attributes { height: Height { revision: 6, height: 28785 }, client_id: ClientId("07-tendermint-3"), client_type: Tendermint, consensus_height: Height { revision: 0, height: 502622 } }, header: Some(Tendermint( Header {...})) })

We can look at the transaction and see the details:

ag-cosmos-helper --node http://139.59.8.130:26657 query tx 410AD46232C10FB7062B778F94C587238CA45B51EA8BA1A78DD47AC742EF4237 shows:

    - key: packet_data
      value: '{"amount":"16000000","denom":"uphoton","receiver":"agoric18kzgpc36eacsdhx8wrdjywvdu3s6dsg2ae3t54","sender":"cosmos18hcdewnyhl6hj6wkz2dwq8slfh8vrnetzxy33p"}'

Payment shows up in agoric wallet

See screenshot above.

IBC Send using Zoe Offers

$ agoric deploy contract/src/deploy-ibc-send.js
Open CapTP connection to ws://127.0.0.1:8000/private/captp...o
agoric: deploy: running /home/connolly/projects/agoric/ibc-fun/contract/src/deploy-ibc-send.js
agoric: deploy: Deploy script will run with Node.js ESM
awaiting home...
await peg, instance...
await transferInvitation, brand, balance...
await payment... {
  gross: { brand: Object [Alleged: Local10 brand] {}, value: 75000000n },
  amount: { brand: Object [Alleged: Local10 brand] {}, value: 250000n }
}
await result...
{
  result: undefined,
  net: { brand: Object [Alleged: Local10 brand] {}, value: 74750000n }
}

Acknowledgements

most clues are from

import { E } from '@agoric/eventual-send';
const the = harden({
peg: {
name: 'peg-channel-10-uphoton',
},
dest: {
address: 'cosmos18hcdewnyhl6hj6wkz2dwq8slfh8vrnetzxy33p',
},
wallet: {
pursePetName: 'Photon43p',
},
payment: {
value: 1000000n / 4n,
},
});
const deployIBCSend = async (homeP, _powers) => {
console.log('awaiting home...');
const home = await homeP;
const purseP = E(E(home.wallet).getAdminFacet()).getPurse(
the.wallet.pursePetName,
);
console.log('await peg, instance...');
const [peg, instance] = await Promise.all([
E(home.scratch).get(the.peg.name),
E(home.agoricNames).lookup('instance', 'Pegasus'),
]);
const pegPub = E(home.zoe).getPublicFacet(instance);
console.log('await transferInvitation, brand, balance...');
const [transferInvitation, brand, gross] = await Promise.all([
E(pegPub).makeInvitationToTransfer(peg, the.dest.address),
E(purseP).getAllegedBrand(),
E(purseP).getCurrentAmount(),
]);
const amount = harden({ brand, value: the.payment.value });
console.log('await payment...', { gross, amount });
const pmt = await E(purseP).withdraw(amount);
const seatP = E(home.zoe).offer(
transferInvitation,
harden({ give: { Transfer: amount } }),
harden({ Transfer: pmt }),
);
console.log('await result...');
const [result, net] = await Promise.all([
E(seatP).getOfferResult(),
E(purseP).getCurrentAmount(),
]);
console.log({ result, net });
};
harden(deployIBCSend);
export default deployIBCSend;
version: "3.9"
services:
hermes:
build:
context: .
dockerfile: hermes.Dockerfile
args:
TAG: v0.9.0
image: hermes:0.9.0
volumes:
- "hermes-home:/home/hermes"
- ".:/config:ro"
command:
- -c
- /config/hermes.config
- start
volumes:
hermes-home:
external: true
# cribbed from...
# https://github.com/Agoric/agoric-sdk/blob/master/packages/pegasus/demo.md
# but hermes requires a different arrangement now, so I also used...
# https://github.com/informalsystems/ibc-rs/blob/master/config.toml
[global]
# strategy = 'all'
log_level = 'trace'
[mode.clients]
enabled = true
refresh = true
[mode.connections]
enabled = true
[mode.channels]
enabled = true
[mode.packets]
enabled = true
clear_interval = 100
filter = false
[telemetry]
enabled = false
host = '127.0.0.1'
port = 3001
[[chains]]
# see also https://devnet.agoric.net/network-config
id = 'agoricdev-6'
rpc_addr = 'http://46.101.220.43:26657'
grpc_addr = 'http://46.101.220.43:9090'
websocket_addr = 'ws://46.101.220.43:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'agoric'
key_name = 'agdevkey'
store_prefix = 'ibc'
max_gas = 3000000
gas_price = { price = 0.001, denom = 'urun' }
gas_adjustment = 0.1
clock_drift = '5s'
trusting_period = '14days'
[chains.trust_threshold]
numerator = '1'
denominator = '3'
[[chains]]
id = 'cosmoshub-testnet'
rpc_addr = 'https://rpc.testnet.cosmos.network:443'
grpc_addr = 'https://grpc.testnet.cosmos.network:443'
websocket_addr = 'wss://rpc.testnet.cosmos.network:443/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'hubkey'
store_prefix = 'ibc'
max_gas = 3000000
gas_price = { price = 0.001, denom = 'uphoton' }
gas_adjustment = 0.1
clock_drift = '5s'
trusting_period = '14days'
[chains.trust_threshold]
numerator = '1'
denominator = '3'
# informalsystems/hermes image
#
# Used for running hermes in docker containers
#
# Usage:
# docker build . --build-arg TAG=v0.3.0 -t informalsystems/hermes:0.3.0 -f hermes.Dockerfile
FROM rust:1.52-buster AS build-env
ARG TAG
WORKDIR /root
RUN git clone https://github.com/informalsystems/ibc-rs
RUN cd ibc-rs && git checkout $TAG && cargo build --release
FROM debian:buster-slim
LABEL maintainer="hello@informal.systems"
RUN useradd -m hermes -s /bin/bash
WORKDIR /home/hermes
USER hermes:hermes
ENTRYPOINT ["/usr/bin/hermes"]
COPY --chown=0:0 --from=build-env /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1
COPY --chown=0:0 --from=build-env /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
COPY --chown=0:0 --from=build-env /root/ibc-rs/target/release/hermes /usr/bin/hermes
COPY --chown=0:0 --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
CHAIN_AG=agoricdev-6
CHAIN_COSMOS=cosmoshub-testnet
IMAGE_AGORIC=agoric/agoric-sdk:agoricdev-6
HERMES=docker run --rm -vhermes-home:/home/hermes:z -v$$PWD:/config hermes -c /config/hermes.config
KEYFILE=ibc-relay-mnemonic
task/restore-keys: $(KEYFILE) task/hermes-image task/hermes-volume hermes.config
MNEMONIC="$$(cat $(KEYFILE))"; \
echo $$MNEMONIC | sha1sum ; \
$(HERMES) keys restore $(CHAIN_AG) -p "m/44'/564'/0'/0/0" -m "$$MNEMONIC"; \
$(HERMES) keys restore $(CHAIN_COSMOS) -m "$$MNEMONIC"
mkdir -p task && touch $@
# ISSUE: these are the results of task/restore-keys
ADDR_AG=agoric16qj02xh6rag5wscgdc4fd9e8j3cmcren47guwe
ADDR_COSMOS=cosmos1ct7n80pahm0y9tneuhx40vh45yfdcshkwahcfy
start: task/create-channel
docker-compose up -d
task/create-channel: hermes.config task/hermes-image task/hermes-volume \
task/restore-keys task/tap-cosmos-faucet task/tap-agoric-faucet
$(HERMES) create channel $(CHAIN_COSMOS) $(CHAIN_AG) --port-a transfer --port-b transfer -o unordered
mkdir -p task && touch $@
task/hermes-image: docker-compose.yml hermes.Dockerfile
docker-compose build
mkdir -p task && touch $@
$(KEYFILE): task/agoric-image
docker run --rm $(IMAGE_AGORIC) keys mnemonic >$@
chmod -w $@
task/agoric-image:
docker pull $(IMAGE_AGORIC)
mkdir -p task && touch $@
hermes.Dockerfile:
wget https://raw.githubusercontent.com/informalsystems/ibc-rs/master/ci/hermes.Dockerfile
task/hermes-volume:
docker volume create hermes-home
mkdir -p task && touch $@
task/tap-cosmos-faucet: hermes.config
@echo tapping faucet
@echo per https://tutorials.cosmos.network/connecting-to-testnet/using-cli.html#requesting-tokens-from-the-faucet
curl -X POST -d '{"address": "$(ADDR_COSMOS)"}' https://faucet.testnet.cosmos.network
mkdir -p task && touch $@
RPC_AG=http://46.101.220.43:26657
task/tap-agoric-faucet: hermes.config
@echo if the balance below is empty,
@echo visit https://agoric.com/discord
@echo go to the "#faucet" channel
@echo enter: !faucet client $(ADDR_AG)
docker run --rm $(IMAGE_AGORIC) --node $(RPC_AG) query bank balances $(ADDR_AG)
@echo otherwise, touch $@
exit 1
@dckc
Copy link
Author

dckc commented Jan 5, 2022

@dckc
Copy link
Author

dckc commented Feb 2, 2022

p.s. some collaboration with hermes dev: informalsystems/hermes#1801 (comment)

@dckc
Copy link
Author

dckc commented Feb 3, 2022

migrating to https://github.com/dckc/ibc-lab so I can use branches and such...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment