Skip to content

Instantly share code, notes, and snippets.

@dckc

dckc/fun.md Secret

Last active May 13, 2022 12:59
Show Gist options
  • Save dckc/9c393be1bd5a147f72c6b42ca12a1aa2 to your computer and use it in GitHub Desktop.
Save dckc/9c393be1bd5a147f72c6b42ca12a1aa2 to your computer and use it in GitHub Desktop.

context: Agoric/agoric-sdk#4657

Story: seller1 is a venue with tickets in section1, section2, ... the price for all tickets in section1 is the same but maybe different from the price in section2.

Deploy script:

sequenceDiagram

actor seller1
participant Zoe

seller1 ->> Zoe: install contract
seller1 ->> Zoe: start contract
Zoe -->> seller1: creatorInvitation
Loading

Venue / seller mints, lists tickets:

sequenceDiagram
actor seller1

seller1 ->> Zoe: offer(creatorInvitation, {want: NFT amounts, give: 0})
Zoe -->> seller1: mintSeat
seller1 ->> mintSeat: getPayout("Tickets")
mintSeat -->> seller1: tickets

seller1 ->> mintSeat: getOfferResult
mintSeat -->> seller1: { invitationMakers: { "List": .. }}

dapp ->> walletBridge: continuingOffer(priorOfferId: ...,  description: "List")

seller1 ->> Zoe: offer(listingInvitation1, {want: $10, give: section1NFTx100})
Zoe -->> seller1: section1seat
Loading

Buyer buys ticket:

sequenceDiagram
actor buyer1

buyer1 ->> contract: getBuyerInvitation({ section: 1, qty: 3})
contract -->> buyer1: buyInvitation3

buyer1 ->> Zoe: offer(buyInvitation3, {give: $30, want: makeCopyBag(section1, 3)})
Zoe -->> buyer1: buyerSeat1
buyer1 ->> buyerSeat1: getPayout("Ticket")
buyerSeat1 -->> buyer1: 3 tickets in section1

Loading

Semi-fungible tokens

We're familiar with: AmountMath.make(simoleans, 10)

If you have 100 seats in section1 that you consider equivalent, you can do:

AmountMath.make(seatBrand, makeCopyBag("section1", 100))

Some code suggests that a harden() is needed:

AmountMath.make(seatBrand, harden(makeCopyBag("section1", 100)))

test-attestation has some examples.

Continuing Invitation Pattern

contract part: offer result includes:

    invitationMakers: Far('invitation makers', {
      AdjustBalances: vault.makeAdjustBalancesInvitation,
      CloseVault: vault.makeCloseInvitation,
      TransferVault: vault.makeTransferInvitation,
    }),

https://github.com/Agoric/agoric-sdk/blob/master/packages/run-protocol/src/vaultFactory/vaultKit.js

dapp part: to act on the result of a previous offer:

    continuingInvitation: {
      priorOfferId: vaultToManageId,
      description: 'AdjustBalances',
    },

https://github.com/Agoric/dapp-treasury/blob/main/ui/src/components/vault/VaultManagement/makeAdjustVaultOffer.js

an example of a dapp using an invitationQuery: https://github.com/Agoric/agoric-sdk/blob/104fbfe120990cd9d1f81c436aa176017e7df7f8/packages/wallet/api/test/test-lib-wallet.js#L1148-L1173

sequenceDiagram

deployScript ->> Zoe: startInstance
Zoe -->> wallet: creatorInvitation

dapp ->> bridge: query(creator-like)
user ->> wallet: ok
wallet ->> Zoe: offer(creatorInvitation, {})
Zoe -->> wallet: offerResult with invitationMakers: {makeListingInvitation}
dapp ->> bridge: offerDescription(prevId, description="makeListingInvitation", proposalToSell1) (cont. style)
dapp ->> bridge: offerDescription(prevId, description="makeListingInvitation", proposalToSell2)

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