Skip to content

Commit

Permalink
chore: refine names, add mappedTo in TransferPartRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Feb 15, 2024
1 parent db01640 commit 2c085f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions contract/src/offer-up.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export const start = async zcf => {
const newItems = itemMint.mintGains(want);
const charge = { Price: tradePrice };
atomicRearrange(zcf, [
{ fromSeat: buyerSeat, toSeat: proceeds, fromAmounts: charge },
{ fromSeat: newItems, toSeat: buyerSeat, fromAmounts: want },
{ from: buyerSeat, to: proceeds, amounts: charge },
{ from: newItems, to: buyerSeat, amounts: want },
]);

buyerSeat.exit(true);
Expand Down
23 changes: 14 additions & 9 deletions contract/src/platform-goals/zcfTools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { atomicRearrange as atomicRearrangeTuples } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import { mapKeywords } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';

/** @typedef {import("@agoric/zoe/src/contractSupport/atomicTransfer").TransferPart} TransferPart */

Expand All @@ -10,20 +11,24 @@ import { atomicRearrange as atomicRearrangeTuples } from '@agoric/zoe/src/contra
* @param { Array<TransferPartRecord | TransferPart>} transferParts
*
* @typedef {{
* fromSeat?: ZCFSeat,
* toSeat?: ZCFSeat,
* fromAmounts?: AmountKeywordRecord,
* toAmounts?: AmountKeywordRecord
* from?: ZCFSeat,
* to?: ZCFSeat,
* amounts?: AmountKeywordRecord,
* mappedTo?: KeywordKeywordRecord
* }} TransferPartRecord
*/
export const atomicRearrange = (zcf, transferParts) => {
/** @type {TransferPart[]} */
const tuples = harden(
transferParts.map(part =>
Array.isArray(part)
? part
: [part.fromSeat, part.toSeat, part.fromAmounts, part.toAmounts],
),
transferParts.map(part => {
if (Array.isArray(part)) {
return part;
}
const toAmounts = part.mappedTo
? mapKeywords(part.amounts, part.mappedTo)
: undefined;
return [part.from, part.to, part.amounts, toAmounts];
}),
);
return atomicRearrangeTuples(zcf, tuples);
};

0 comments on commit 2c085f5

Please sign in to comment.