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: swap contract #10

Merged
merged 28 commits into from
Mar 12, 2024
Merged

feat: swap contract #10

merged 28 commits into from
Mar 12, 2024

Conversation

dckc
Copy link
Member

@dckc dckc commented Feb 21, 2024

refs #9

This meets all the requirements I know of (oops; save 1... deploying on chain):

  • contract
  • wallet style test to specify the interface with the front end
    • snapshot of offer sent by client
  • factor boot-tools, wallet-tools out of test-swaparoo
  • core eval code
  • Note: deployment to a running chain postponed to tooling to deploy / start multiple contracts #15

from Agoric/documentation#940 :

  • Invitation specs - n/a (client side)
  • Offer shapes - 1 of 3 makeInvitation calls has an offer shape; is that enough?
  • Depends on Client docs - n/a (client side)
  • Lesson plan + video - n/a

It's a minimal effort job. I copied test-swap-wallet.js from dapp-swaparoo, ran it, and then fixed the errors until it passed. In all cases, copying verbatim from dapp-swaparoo sufficed.

Reviewers: please distinguish correctness feedback from style. Here's hoping we find time to make the code exemplary in style as well as correct, but I'm not sure how much of that we should do at this point.

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@dckc dckc changed the base branch from main to 939-mint-tickets February 23, 2024 08:34
@dckc dckc mentioned this pull request Feb 23, 2024
3 tasks
@dckc dckc force-pushed the dc-swap-contract branch 2 times, most recently from a2f3f1a to aa79dc3 Compare March 1, 2024 23:49
@dckc dckc marked this pull request as ready for review March 4, 2024 23:55
@dckc dckc requested a review from Chris-Hibbert March 6, 2024 01:43
Base automatically changed from 939-mint-tickets to main March 6, 2024 04:57
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments and questions. All non blocking.

/** @type { <T extends Record<string, ERef<any>>>(obj: T) => Promise<{ [K in keyof T]: Awaited<T[K]>}> } */
export const allValues = async obj => {
const es = await Promise.all(
entries(obj).map(([k, vp]) => Promise.resolve(vp).then(v => [k, v])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merely a suggestion:

Suggested change
entries(obj).map(([k, vp]) => Promise.resolve(vp).then(v => [k, v])),
entries(obj).map(([k, vp]) => E.when(vp, v => [k, v])),

});
await E(addressAdmin).default(DEPOSIT_FACET_KEY, depositFacet);

const getContractInvitation = invitationSpec => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[style]: would it be helpful to declare a type for invitationSpec?

};

const getPurseInvitation = async invitationSpec => {
// const { instance, description } = invitationSpec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line obsolete?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's sort of part of the todo... which I have just todone

// XXX throwing here is unhandled somehow.
const seat = await E(zoe).offer(invitation, proposal, pmts, offerArgs);
seatById.set(offerSpec.id, seat);
// console.log(address, offerSpec.id, 'got seat');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace() is useful for log messages you don't want to lose.


const { bundleCache } = t.context;
const bundle = await bundleCache.load(assets.swaparoo, contractName);
const bundleID = `b1-${bundle.endoZipBase64Sha512}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw a helper for this, didn't I?


const cowAmount = AmountMath.make(
wellKnown.brand.BLD,
// makeCopyBag([['Milky White', 1n]]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking]: is something broken with non-fungibles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-fungibles (at least: that particular one) aren't conveniently available in an end-to-end testing context (#16)

As I mentioned, I keep moving bits of stuff up and down my stack of PRs... I should think about this one a bit more...

Copy link
Collaborator

@LuqiPan LuqiPan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some non-blocking comments after reading through the contract, I'm reading the tests next.

contract/src/swaparoo.contract.js Show resolved Hide resolved
});
};

const { want, give } = firstSeat.getProposal();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

Rename these to { firstSeatWant, firstSeatGive } so it's a little bit easier to read?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that added a bunch of line wrapping. { want: want1, give: give1 } seems like a happy medium

dckc added 11 commits March 12, 2024 14:20
 - factor our bundle-tools
 - prune boardAux hack
 - move type burden inside contract starters'
 - initialize balances
 - punt chainStorage until we use CapData across vats
 - chore(boot-tools): produce BLD, startUpgradable
 - chore: notifier -> async iterator
 - seatLike: return on payout amounts
 - missing param decl; lint
 - prune unused makeWalletFactory
 - getPayouts -> getPayoutAmounts, with type
 - docs(wallet-tools): invitationSpec types
 - OfferStatus -> offerStatus
 - use seatLike
 - getPayoutAmounts
 - clean up TODO
 - refactor: use wallet-tools
 - refactor: follow x.contract.js pattern
 - refactor: use getBundleId helper
 - refactor: clarify want1, give1
 - style: lint
@dckc dckc merged commit c49ac22 into main Mar 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants