-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(smart-wallet): trading in non-vbank asset (WIP)
WIP: test part 2: use a real contract WIP: note limitation on depositFacet assetKind chore(smart-wallet): never mind static check for remote presence feat(smart-wallet): purses for well-known brands (WIP) current challenge: "no ordinal" for Place brand agoric-sdk/packages/smart-wallet$ yarn test test/test-addAsset.js -m '*non-vbank*' ... wallet agoric1player1 OFFER ERROR: (Error#1) Error#1: cannot encode Object [Alleged: Place brand] {} as key: no ordinal at encodeRemotable (packages/swingset-liveslots/src/collectionManager.js:284:13) at keyToDBKey (packages/swingset-liveslots/src/collectionManager.js:329:26) at Alleged: mapStore.set (packages/swingset-liveslots/src/collectionManager.js:431:21) at Object.providePurseForWellKnownBrand (.../smart-wallet/src/smartWallet.js:421:15) fixup? MockChainStorage spelling chore: test misc - clarify rpc - clean up makeHandle lint - never mind ignored fromEntries - another MockStorageRoot chore: use side table for new purse storage test: clean up game contract chore: rename to gameAssetContract.js test: fixup test-addAsset (SQUASHME) chore: revert to queue payments for unknown brand (NEEDSTEST) WIP: refine non-vbank asset to tell story in t.log chore: make adding an issuer less specific to agoricNames WIP: toward watching purses; types for brandToPurses
- Loading branch information
Showing
5 changed files
with
524 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** @file illustrates using non-vbank assets */ | ||
|
||
// deep import to avoid dependency on all of ERTP, vat-data | ||
import { AmountMath, AssetKind } from '@agoric/ertp/src/amountMath.js'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { getCopyBagEntries } from '@agoric/store'; | ||
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/index.js'; | ||
import { E, Far } from '@endo/far'; | ||
|
||
const { Fail, quote: q } = assert; | ||
|
||
const trace = makeTracer('Game', true); | ||
|
||
/** @param {Amount<'copyBag'>} amt */ | ||
const totalPlaces = amt => { | ||
/** @type {[unknown, bigint][]} */ | ||
const entries = getCopyBagEntries(amt.value); // XXX getCopyBagEntries returns any??? | ||
const total = entries.reduce((acc, [_place, qty]) => acc + qty, 0n); | ||
return total; | ||
}; | ||
|
||
/** | ||
* @param {ZCF<{joinPrice: Amount}>} zcf | ||
*/ | ||
export const start = async zcf => { | ||
const { joinPrice } = zcf.getTerms(); | ||
const stableIssuer = await E(zcf.getZoeService()).getFeeIssuer(); | ||
zcf.saveIssuer(stableIssuer, 'Price'); | ||
|
||
const { zcfSeat: gameSeat } = zcf.makeEmptySeatKit(); | ||
const mint = await zcf.makeZCFMint('Place', AssetKind.COPY_BAG); | ||
|
||
/** @param {ZCFSeat} playerSeat */ | ||
const joinHook = playerSeat => { | ||
const { give, want } = playerSeat.getProposal(); | ||
trace('join', 'give', give, 'want', want.Places.value); | ||
|
||
AmountMath.isGTE(give.Price, joinPrice) || | ||
Fail`${q(give.Price)} below joinPrice of ${q(joinPrice)}}`; | ||
|
||
totalPlaces(want.Places) <= 3n || Fail`only 3 places allowed when joining`; | ||
|
||
atomicRearrange( | ||
zcf, | ||
harden([ | ||
[playerSeat, gameSeat, give], | ||
[mint.mintGains(want), playerSeat, want], | ||
]), | ||
); | ||
playerSeat.exit(true); | ||
return 'welcome to the game'; | ||
}; | ||
|
||
const publicFacet = Far('API', { | ||
makeJoinInvitation: () => zcf.makeInvitation(joinHook, 'join'), | ||
}); | ||
|
||
return harden({ publicFacet }); | ||
}; | ||
harden(start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.