Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Jan 17, 2024

Conversation

dckc
Copy link
Contributor

@dckc dckc commented Jan 10, 2024

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
Copy link

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
Copy link
Contributor Author

dckc commented Jan 10, 2024

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 dckc changed the title feat(ag-trade): get local agoric chain node info using cosmos-fetch endo plugin feat(ag-trade): smart wallet offers such as add to reserve Jan 10, 2024
@dckc dckc marked this pull request as ready for review January 10, 2024 07:11
Comment on lines +7 to +11
import {
SigningStargateClient,
assertIsDeliverTxSuccess,
} from '@cosmjs/stargate';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have to be an --UNSAFE plugin -- the network stuff is all in a separate vat -- but I'm struggling to get protobuf stuff to run confined. See:

return Far('HdWallet', methods);
};

export const make = async () => Far('HdWalletMaker', { fromMnemonic });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computing signatures should be able to run in a separate caplet from the rest of the smartWallet code, but we can't marshal byte sequences:

const synthesizeRemotable = (slot, iface) =>
Far(`${(iface ?? '').replace(/^Alleged: /, '')}#${slot}`, {});

export const makeClientMarshaller = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should perhaps be imported from ui-kit, but the version there has an issue:

@dckc dckc changed the base branch from main to dc-playground-equip January 16, 2024 22:33
@dckc dckc force-pushed the dc-ag-trade branch 3 times, most recently from 5e74e29 to 4533681 Compare January 17, 2024 00:12
@dckc
Copy link
Contributor Author

dckc commented Jan 17, 2024

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

$ git -C ../finquick/ log10 packages/ag-trade/src/cosmosFetch.js
2023-12-27 01:35 1851101 chore(cosmosFetch): detect missing fetch function

$ git -C ../finquick/ log10 packages/ag-trade/src/httpClient.js
2023-11-24 21:47 f8b9a5c feat: separate fetch worker from smartWallet worker
NOTE: using the exact versions from finquick worked,
but just doing `yarn add X` for these packages resulted
in

RemoteTypeError(error:captp:Endo#20001)#1: Cannot assign to read only
property 'constructor' of object '[object Object]'

and I couldn't find any more stack info

 - buid(ag-trade): add @endo/far for caplets
 - smartWallet: entries, keys in agoricNames from vstorage
@dckc dckc changed the title feat(ag-trade): smart wallet offers such as add to reserve feat(ag-trade): fetch, (un)marshal, lookup, sign... add to reserve Jan 17, 2024
@dckc dckc merged commit 126e77d into dc-playground-equip Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

caplets for trading with the Agoric smartWallet
2 participants