endojs / playground

Experimental caplets and plugins for the Endo Pet Dæmon
0 stars 2 forks source link

feat(ag-trade): fetch, (un)marshal, lookup, sign... add to reserve #2

Closed dckc closed 6 months ago

dckc commented 6 months ago

fixes #1

After setting up lint/test devtools and such (#6), I'm migrating stuff from finquick and swaparoo.

A hello-world chain interaction works:

~/projects/playground/packages/ag-trade$ make clean
endo reset

~/projects/playground/packages/ag-trade$ make node-info
++ install cosmos fetch plugin
endo make --UNSAFE src/cosmosFetch.js -n cosmos-fetch
Object [Alleged: CosmosFetch] {}

endo make src/net-local.js -n local -p cosmos-fetch
{ lcd: Object [Alleged: LCD] {}, rpc: Object [Alleged: RpcClient] {} }

endo eval "E(local.lcd).getJSON('/node_info').then(i => i.node_info)" local
{
  channels: '40202122233038606100',
  id: '8da5e462e560eb951e2c6d8ad2f9ce50c58a0be6',
  listen_addr: 'tcp://0.0.0.0:26656',
  moniker: 'localnet',
  network: 'agoriclocal',
  other: { rpc_address: 'tcp://0.0.0.0:26657', tx_index: 'on' },
  protocol_version: { app: '0', block: '11', p2p: '8' },
  version: '0.34.23'
}

cc @tgrecojs @kriskowal

tgrecojs commented 6 months ago

great hello, world @dckc!

I had to remove shell from line 1 so that it would work on MacOS (shown below)

STATE=$(endo where state)

This took a whopping ~5 seconds.... aaand voila! 🪄

ss_01102024_000093

🚀 amazing way to break ground on (what i expect to be the) safest adult playground to ever grace the interwebs 😎

dckc commented 6 months ago

smart wallet offers such as add to reserve

Prerequisite: ALICE_SECRET env has the 24 words corresponding to an account with a smart wallet already provisioned a la agoric-3-proposals as used in Your First Agoric Dapp

$ direnv allow
direnv: loading ~/projects/playground/.envrc
direnv: export +ALICE_SECRET +JACK_SECRET ~PATH

Then:

~/projects/playground/packages/ag-trade$ make clean
endo reset

~/projects/playground/packages/ag-trade$ make reserve-add
++ install cosmos fetch plugin
endo make --UNSAFE src/cosmosFetch.js -n cosmos-fetch
Object [Alleged: CosmosFetch] {}

endo make src/net-local.js -n local -p cosmos-fetch
{ lcd: Object [Alleged: LCD] {}, rpc: Object [Alleged: RpcClient] {} }

++ start smart wallet caplet -- TODO: should not need UNSAFE
endo make --UNSAFE src/smartWallet.js -n client-maker
Object [Alleged: SmartWalletFactory] {}
endo eval "E(wf).makeWalletKit('survey thank ...', local.rpc, local.lcd)" \
        local wf:client-maker -n alice-wk
{
  query: Object [Alleged: QueryTool] {},
  smartWallet: Object [Alleged: SmartWallet] {},
  tx: Object [Alleged: SigningClient] {}
}

endo make --UNSAFE src/fresh-id.js -n fresh
Object [Alleged: FreshMaker] {}

endo eval "E(fresh).start('trade-')" fresh -n fresh-trade-id
Object [Alleged: Fresh] {}

endo mkguest alice
Object [Alleged: EndoGuest] {}

endo send alice @wallet:alice-wk
endo send alice @fresh:fresh-trade-id
endo inbox --as alice
0. "HOST" sent "@wallet" at "2024-01-10T07:00:27.268Z"
1. "HOST" sent "@fresh" at "2024-01-10T07:00:27.362Z"
# these 0/1 message numbers are fragile
endo adopt 0 wallet --as alice
endo adopt 1 fresh --as alice

endo run src/reserve-add.js 1 IST -p alice
{
  status: {
    id: 'trade-0700.0',
    invitationSpec: {
      callPipe: [Array],
      instancePath: [Array],
      source: 'agoricContract'
    },
    numWantsSatisfied: 1,
    payouts: { Collateral: [Object] },
    proposal: { give: [Object] },
    result: 'added Collateral to the Reserve'
  },
  tx: {
    height: 26737,
    transactionHash: '937A033D429EF5E00774C2A94109E7627C784115BF0EB57BA4C9B91E86D6D5CA'
  }
}
dckc commented 6 months ago

Goal: PetName interop

While working on some prototypes Agoric dapps in an internal hackathon, we had agoric1... addresses on the screen here and there. Even form fields where the user entered and address. I thought to myself:

  1. There's got to be a better way. We should be using petnames.
  2. Spritely has some petname stuff. I wonder if it helps?
  3. Using Spritely stuff directly in Agoric apps seems like a stretch.
  4. In OCapN discussions, we've talked about an CapTP bridge between Spritely/OCapN stuff and endo.
  5. I've done endo plug-ins for key management, Google Sheets, etc. ... why not the Agoric chain?

rest of details moved to README