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: contract code to mint tickets #8

Merged
merged 26 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d553e19
chore: replace all occurrences of item with ticket in contract code
LuqiPan Feb 8, 2024
11754dd
Merge branch 'main' into 939-mint-tickets
LuqiPan Feb 8, 2024
791417c
chore: remove customTermsShape
LuqiPan Feb 8, 2024
81fcca5
feat: alter the contract terms to contain ticket inventory
LuqiPan Feb 9, 2024
cc658e7
test: update most tests to use inventory as terms and make them pass
LuqiPan Feb 9, 2024
c101065
chore: fix problems from yarn lint
LuqiPan Feb 9, 2024
10388d6
test: make the last test in test-contract.js pass
LuqiPan Feb 9, 2024
f706103
Revert "test: make the last test in test-contract.js pass"
LuqiPan Feb 9, 2024
0332a6e
test: make the last test in test-contract.js pass
LuqiPan Feb 9, 2024
bd8bef9
chore: update JSDoc and make terms with more sense
LuqiPan Feb 9, 2024
d5d5482
feat: mint the whole inventory at contract start
LuqiPan Feb 12, 2024
2bc29bb
chore: fix lint
LuqiPan Feb 12, 2024
5d9e6f8
chore: remove hasInventory helper fuction as it's no longer needed
LuqiPan Feb 13, 2024
0cdb78c
chore: update comments in code files accordingly
LuqiPan Feb 13, 2024
fec0cad
chore: use makeInventory and makeTerms more widely
LuqiPan Feb 13, 2024
8774bd6
chore: use @example tag
LuqiPan Feb 13, 2024
216b293
chore: replace all occurrences of agoric-basics with sell-concert-tic…
LuqiPan Feb 15, 2024
02bde11
feat: check inventory is not empty and has the same brand at contract…
LuqiPan Feb 15, 2024
f828cad
chore: add back customTermsShape
LuqiPan Feb 15, 2024
c5c4b31
workaround: use M.any() to make it pass for now
LuqiPan Feb 16, 2024
4438977
test: add a test case for when Alice wants too many tickets
LuqiPan Feb 16, 2024
9a56f16
test: fix test by getting and handling offer result
LuqiPan Feb 20, 2024
727b350
test: improve the test to handle the error throwing flow better
LuqiPan Feb 21, 2024
1b8a012
chore: update file names for SCRIPT and PERMIT
LuqiPan Feb 21, 2024
5be8bbb
fix: tickets are of semi-fungible asset type
LuqiPan Feb 22, 2024
70a347c
chore(sell): add InventoryShape for use in customTermsShape
dckc Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contract/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
start-agoric-basics-permit.json
start-agoric-basics.js
start-sell-concert-tickets-permit.json
start-sell-concert-tickets.js
bundles/
4 changes: 2 additions & 2 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ print-key: /root/.agoric/user1.key
@agd keys show user1 -a --keyring-backend="test"
@echo

SCRIPT=start-agoric-basics.js
PERMIT=start-agoric-basics-permit.json
SCRIPT=start-sell-concert-tickets.js
PERMIT=start-sell-concert-tickets-permit.json
start-contract: $(SCRIPT) $(PERMIT) install-bundles
scripts/propose-start-contract.sh

Expand Down
2 changes: 1 addition & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dapp-agoric-basics-contract",
"name": "agoric-basics-contract",
"version": "0.1.0",
"private": true,
"description": "Agoric Basics Contract",
Expand Down
21 changes: 12 additions & 9 deletions contract/scripts/build-contract-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
* Creates files for starting an instance of the contract:
* * contract source and instantiation proposal bundles to be published via
* `agd tx swingset install-bundle`
* * start-agoric-basics-permit.json and start-agoric-basics.js to submit the
* * start-sell-concert-tickets-permit.json and start-sell-concert-tickets.js to submit the
* instantiation proposal via `agd tx gov submit-proposal swingset-core-eval`
*
* Usage:
* agoric run build-contract-deployer.js
*/

import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForAgoricBasics } from '../src/agoric-basics-proposal.js';
import { getManifestForSellConcertTickets } from '../src/sell-concert-tickets-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const agoricBasicsProposalBuilder = async ({ publishRef, install }) => {
export const sellConcertTicketsProposalBuilder = async ({
publishRef,
install,
}) => {
return harden({
sourceSpec: '../src/agoric-basics-proposal.js',
sourceSpec: '../src/sell-concert-tickets-proposal.js',
getManifestCall: [
getManifestForAgoricBasics.name,
getManifestForSellConcertTickets.name,
{
agoricBasicsRef: publishRef(
sellConcertTicketsRef: publishRef(
install(
'../src/agoric-basics.contract.js',
'../bundles/bundle-agoric-basics.js',
'../src/sell-concert-tickets.contract.js',
'../bundles/bundle-sell-concert-tickets.js',
{
persist: true,
},
Expand All @@ -38,5 +41,5 @@ export const agoricBasicsProposalBuilder = async ({ publishRef, install }) => {
/** @type {DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('start-agoric-basics', agoricBasicsProposalBuilder);
await writeCoreProposal('start-sell-concert-tickets', sellConcertTicketsProposalBuilder);
};
2 changes: 1 addition & 1 deletion contract/scripts/propose-start-contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PROPOSAL=$(agd query gov proposals --output json | jq -c '.proposals | length |
make fund-acct

agd tx gov submit-proposal swingset-core-eval "$PERMIT" "$SCRIPT" \
--title="Start Agoric Basics Contract" --description="Evaluate $SCRIPT" \
--title="Start Sell Concert Tickets Contract" --description="Evaluate $SCRIPT" \
--deposit=10000000ubld --gas=auto --gas-adjustment=1.2 \
--from user1 --chain-id agoriclocal --keyring-backend=test \
--yes -b block
Expand Down
141 changes: 0 additions & 141 deletions contract/src/agoric-basics.contract.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ const BOARD_AUX = 'boardAux';
const marshalData = makeMarshal(_val => Fail`data only`);

const IST_UNIT = 1_000_000n;
const CENT = IST_UNIT / 100n;

export const makeInventory = (brand, baseUnit) => {
return {
frontRow: {
tradePrice: AmountMath.make(brand, baseUnit * 3n),
maxTickets: 3n,
},
middleRow: {
tradePrice: AmountMath.make(brand, baseUnit * 2n),
maxTickets: 3n,
},
lastRow: {
tradePrice: AmountMath.make(brand, baseUnit * 1n),
maxTickets: 3n,
},
};
};

export const makeTerms = (brand, baseUnit) => {
return {
inventory: makeInventory(brand, baseUnit),
};
};

/**
* Make a storage node for auxilliary data for a value on the board.
Expand Down Expand Up @@ -41,86 +63,89 @@ const publishBrandInfo = async (chainStorage, board, brand) => {
*
* @param {BootstrapPowers} permittedPowers
*/
export const startAgoricBasicsContract = async permittedPowers => {
console.error('startAgoricBasicsContract()...');
export const startSellConcertTicketsContract = async permittedPowers => {
console.error('startSellConcertTicketsContract()...');
const {
consume: { board, chainStorage, startUpgradable, zoe },
brand: {
consume: { IST: istBrandP },
// @ts-expect-error dynamic extension to promise space
produce: { Item: produceItemBrand },
produce: { Ticket: produceTicketBrand },
},
issuer: {
consume: { IST: istIssuerP },
// @ts-expect-error dynamic extension to promise space
produce: { Item: produceItemIssuer },
produce: { Ticket: produceTicketIssuer },
},
installation: {
consume: { agoricBasics: agoricBasicsInstallationP },
consume: { sellConcertTickets: sellConcertTicketsInstallationP },
},
instance: {
// @ts-expect-error dynamic extension to promise space
produce: { agoricBasics: produceInstance },
produce: { sellConcertTickets: produceInstance },
},
} = permittedPowers;

const istIssuer = await istIssuerP;
const istBrand = await istBrandP;

const terms = { tradePrice: AmountMath.make(istBrand, 25n * CENT) };
const terms = makeTerms(istBrand, 1n * IST_UNIT);

// agoricNames gets updated each time; the promise space only once XXXXXXX
const installation = await agoricBasicsInstallationP;
const installation = await sellConcertTicketsInstallationP;

const { instance } = await E(startUpgradable)({
installation,
issuerKeywordRecord: { Price: istIssuer },
label: 'agoricBasics',
label: 'sellConcertTickets',
terms,
});
console.log('CoreEval script: started contract', instance);
const {
brands: { Item: brand },
issuers: { Item: issuer },
brands: { Ticket: brand },
issuers: { Ticket: issuer },
} = await E(zoe).getTerms(instance);

console.log('CoreEval script: share via agoricNames:', brand);

produceInstance.reset();
produceInstance.resolve(instance);

produceItemBrand.reset();
produceItemIssuer.reset();
produceItemBrand.resolve(brand);
produceItemIssuer.resolve(issuer);
produceTicketBrand.reset();
produceTicketIssuer.reset();
produceTicketBrand.resolve(brand);
produceTicketIssuer.resolve(issuer);

await publishBrandInfo(chainStorage, board, brand);
console.log('agoricBasics (re)started');
console.log('sellConcertTickets (re)started');
};

/** @type { import("@agoric/vats/src/core/lib-boot").BootstrapManifest } */
const agoricBasicsManifest = {
[startAgoricBasicsContract.name]: {
const sellConcertTicketsManifest = {
[startSellConcertTicketsContract.name]: {
consume: {
agoricNames: true,
board: true, // to publish boardAux info for NFT brand
chainStorage: true, // to publish boardAux info for NFT brand
startUpgradable: true, // to start contract and save adminFacet
zoe: true, // to get contract terms, including issuer/brand
},
installation: { consume: { agoricBasics: true } },
issuer: { consume: { IST: true }, produce: { Item: true } },
brand: { consume: { IST: true }, produce: { Item: true } },
instance: { produce: { agoricBasics: true } },
installation: { consume: { sellConcertTickets: true } },
issuer: { consume: { IST: true }, produce: { Ticket: true } },
brand: { consume: { IST: true }, produce: { Ticket: true } },
instance: { produce: { sellConcertTickets: true } },
},
};
harden(agoricBasicsManifest);
harden(sellConcertTicketsManifest);

export const getManifestForAgoricBasics = ({ restoreRef }, { agoricBasicsRef }) => {
export const getManifestForSellConcertTickets = (
{ restoreRef },
{ sellConcertTicketsRef },
) => {
return harden({
manifest: agoricBasicsManifest,
manifest: sellConcertTicketsManifest,
installations: {
agoricBasics: restoreRef(agoricBasicsRef),
sellConcertTickets: restoreRef(sellConcertTicketsRef),
},
});
};
Loading
Loading