Agoric / agoric-sdk

monorepo for the Agoric Javascript smart contract platform
Apache License 2.0
327 stars 206 forks source link

Smart wallet equivalent to suggestIssuer(petname, issuerBoardId) #7226

Open carlos-kryha opened 1 year ago

carlos-kryha commented 1 year ago

What is the Problem Being Solved?

In order for the agoric web wallet to handle arbitrary ERTP assets, we've been using the following frontend code when running a local sim-chain + ag-solo

const {
        abort: ctpAbort,
        dispatch: ctpDispatch,
        getBootstrap,
      } = makeCapTP("CB", (obj: any) => socket.send(JSON.stringify(obj)), otherSide);

      const walletP = getBootstrap();
      E(walletP).suggestIssuer("TOKEN", TOKEN_ISSUER_BOARD_ID)

With ag-solo out of the picture in mainnet 2, how would we go about letting the wallet know about ERPT assets created in our contracts? Assuming we have the asset's issuer boardId readily availble

Description of the Design

Task list that was here was actually addressing a different scope: #8156

Security Considerations

Scaling Considerations

Test Plan

ivanlei commented 1 year ago

Related PR: https://github.com/Agoric/agoric-sdk/pull/5946

dckc commented 1 year ago

Story: Alice joins a Monopoly Game

updated for "use well-known agoricNames" approach, which is actually more relevant to #8156

In a monopoly-like game dapp, players can trade real estate assets. To join the game, Alice will buy a few pieces of real estate for 0.25 IST.

The game was launched thru chain-wide (BLD staker) governance. In the process, a new "Game Real Estate" issuer and brand were registered as well-known (via agoricNames.issuer, agoricNames.brand). Likewise the game instance is registered in agoricNames.instance.

Alice chooses a few pieces of real-estate using the game UI. The game UI proposes an offer to the game contract of 0.25 for these pieces of real-estate. Alice signs the offer and receives the real estate NFTs.

Details/questions:

cc @otoole-brendan @turadg

Design Sketch for addIssuer flow

outdated

Details ``` agoric-sdk/packages/smart-wallet$ yarn test test/test-walletFactory.js -m '*add issuers' ✔ [expected fail] wallet owners can add issuers ℹ dapp suggests issuer: { issuer: Object @Alleged: SEVERED: Game Real Estate Issuer {}, name: 'Game Real Estate', } ℹ agoric1addIssuer agrees to action: { issuer: Object @Alleged: SEVERED: Game Real Estate Issuer {}, method: 'addIssuer', name: 'Game Real Estate', } ℹ new issuer reflected in wallet status update: { status: { error: 'invalid handle bridge action {"issuer":"[Alleged: Game Real Estate IssuerHandle]","method":"addIssuer","name":"Game Real Estate"}', }, updated: 'walletAction', } ``` code: ```js test.failing('wallet owners can add issuers', async t => { let ids = {}; const onChain = async () => { const kit = { issuer: makeHandle('Game Real Estate Issuer'), brand: makeHandle('Game Real Estate Brand'), }; const board = await t.context.consume.board; ids = { issuer: board.getId(kit.issuer), brand: board.getId(kit.brand), }; }; await onChain(); // From vstorage, a dapp might get issuer info such as: const refData = { body: `#${JSON.stringify({ name: 'Game Real Estate', issuer: '$0.Alleged: Game Real Estate Issuer', brand: '$1.Alleged: Game Real Estate Brand', })}`, slots: [ids.issuer, ids.brand], }; const ctx = makeImportContext(); const ref = ctx.fromBoard.fromCapData(refData); t.log('dapp suggests issuer:', { issuer: ref.issuer, name: ref.name }); const owner = 'agoric1addIssuer'; const updates = await E( t.context.simpleProvideWallet(owner) ).getUpdatesSubscriber(); const action = harden({ method: 'addIssuer', issuer: ref.issuer, name: ref.name, }); t.log(owner, 'agrees to action:', action); const actionEncoding = ctx.fromBoard.toCapData(action); const addIssuerMsg = { type: ActionType.WALLET_SPEND_ACTION, owner, spendAction: JSON.stringify(actionEncoding), blockTime: 0, blockHeight: 0, }; assert(t.context.sendToBridge); await t.context.sendToBridge(addIssuerMsg); const update = await headValue(updates); t.log('new issuer reflected in wallet status update:', update); t.deepEqual(update, { updated: 'addIssuer', status: { name: 'Game Real Estate', brand: ref.brand, }, }); }); ```

todo: review

Related work: petnames

see

dckc commented 1 year ago

based on the alternative flow where BLD stakers agree to add to agoricNames.issuer in the same core eval script where they start a permissioned contract, I filled in some more detail in a test:

dckc commented 1 year ago

The current work in progress addresses a different scope; I made a new issue to represent it:

dckc commented 9 months ago

some brainstorming in this area: