Agoric / agoric-sdk

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

Make `UserSeat`, `ZCFSeat`, into ownables #9606

Open erights opened 4 months ago

erights commented 4 months ago

https://github.com/Agoric/agoric-sdk/pull/8745 defined Ownables, implemented at https://github.com/Agoric/agoric-sdk/blob/master/packages/zoe/src/contractSupport/prepare-ownable.js with expository example at https://github.com/Agoric/agoric-sdk/blob/master/packages/zoe/test/unitTests/contracts/ownable-counter.js . This is designed so that we can often retrofit existing exos to be ownables.

See #8745 PR comment for best current explanation. In general, if holding an object confers valuable rights to do things, making those objects into ownables may usefully make that value ownable and thereby exclusively tradable, if

https://github.com/Agoric/agoric-sdk/pull/4080 explains a plan to refactor the essence of Zoe to have a separable escrow service into a new Zoe2 design. As applied to current Zoe, we can think of the result of making an offer as creating two distinct bundles of rights:

It is interesting to compare this with "intents", which also try to provide offer-safety constrained order-routing, but without the expressiveness of interacting with behavioral contracts along the way. Hopefully, we can bridge between these two worlds, giving each a window into the other.

dckc commented 5 days ago

Working prototype

As part of #8184, I got something that works in 1 case.

It's lightly tested using manual mutation testing:

diff --git a/packages/zoe/test/z2spec/escrow-exo.test.js b/packages/zoe/test/z2spec/escrow-exo.test.js
index 0806866854..223927377a 100644
--- a/packages/zoe/test/z2spec/escrow-exo.test.js
+++ b/packages/zoe/test/z2spec/escrow-exo.test.js
@@ -59,6 +59,8 @@ test('escrowExchange: Alice and Bob do simpleExchange ', async t => {
       const { seat, resolver } = await ex1.makeEscrowSeatKit(proposal, pmts);
       t.log(name, 'got seat, resolver', seat);

+      await resolver.makeTransferInvitation();
+
       const participate = simpleExchange(resolver);

       const deposit = E.when(seat.getPayouts(), payouts =>

results:

    ℹ REJECTED from ava test("escrowExchange: Alice and Bob do simpleExchange "): (Error#1)
    ℹ Error#1: OwnableSeatResolver_caretaker revoked
    ℹ     at makeError (file:///home/connolly/projects/ag-escrow-formal/node_modules/ses/src/error/assert.js:350:61)
          at fail (file:///home/connolly/projects/ag-escrow-formal/node_modules/ses/src/error/assert.js:482:20)
          at Fail (file:///home/connolly/projects/ag-escrow-formal/node_modules/ses/src/error/assert.js:492:39)
          at Object.readOnly (file:///home/connolly/projects/ag-escrow-formal/packages/base-zone/src/prepare-revocable.js:128:23)
          at In "readOnly" method of (OwnableSeatResolver_caretaker revocable) [as readOnly] (file:///home/connolly/projects/ag-escrow-formal/node_modules/@endo/exo/src/exo-tools.js:171:24)
          at simpleExchange (file:///home/connolly/projects/ag-escrow-formal/packages/zoe/test/z2spec/escrow-exo.test.js:19:35)
          at Object.go (file:///home/connolly/projects/ag-escrow-formal/packages/zoe/test/z2spec/escrow-exo.test.js:64:27)

invoked a la:

$ cd packages/zoe
$ yarn test test/z2spec/