@agoric/zoe 0.26.3-dev-5eb596e.0 → 0.26.3-dev-cc54325.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/bundle-contractFacet-js-meta.json +88 -80
- package/bundles/bundle-contractFacet.js +1 -1
- package/package.json +11 -10
- package/src/contractFacet/reallocate.d.ts +3 -0
- package/src/contractFacet/reallocate.d.ts.map +1 -0
- package/src/contractFacet/reallocate.js +94 -0
- package/src/contractFacet/types.d.ts +10 -0
- package/src/contractFacet/types.d.ts.map +1 -1
- package/src/contractFacet/types.js +12 -0
- package/src/contractFacet/zcfSeat.d.ts.map +1 -1
- package/src/contractFacet/zcfSeat.js +104 -3
- package/src/contractFacet/zcfZygote.d.ts.map +1 -1
- package/src/contractFacet/zcfZygote.js +1 -0
- package/src/contractSupport/atomicTransfer.d.ts +0 -6
- package/src/contractSupport/atomicTransfer.d.ts.map +1 -1
- package/src/contractSupport/atomicTransfer.js +5 -90
- package/src/contractSupport/zoeHelpers.d.ts.map +1 -1
- package/src/contractSupport/zoeHelpers.js +3 -10
- package/src/contracts/auction/firstPriceLogic.d.ts.map +1 -1
- package/src/contracts/auction/firstPriceLogic.js +1 -3
- package/src/contracts/auction/secondPriceLogic.d.ts.map +1 -1
- package/src/contracts/auction/secondPriceLogic.js +1 -3
- package/src/contracts/autoswap.d.ts.map +1 -1
- package/src/contracts/autoswap.js +3 -7
- package/src/contracts/barterExchange.d.ts.map +1 -1
- package/src/contracts/barterExchange.js +2 -3
- package/src/contracts/callSpread/fundedCallSpread.d.ts.map +1 -1
- package/src/contracts/callSpread/fundedCallSpread.js +1 -3
- package/src/contracts/callSpread/pricedCallSpread.d.ts.map +1 -1
- package/src/contracts/callSpread/pricedCallSpread.js +1 -3
- package/src/contracts/loan/borrow.d.ts.map +1 -1
- package/src/contracts/loan/borrow.js +1 -3
- package/src/contracts/loan/close.d.ts.map +1 -1
- package/src/contracts/loan/close.js +2 -6
- package/src/contracts/sellItems.d.ts.map +1 -1
- package/src/contracts/sellItems.js +1 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/zoe",
|
|
3
|
-
"version": "0.26.3-dev-
|
|
3
|
+
"version": "0.26.3-dev-cc54325.0+cc54325",
|
|
4
4
|
"description": "Zoe: the Smart Contract Framework for Offer Enforcement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/zoeService/zoe.js",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@agoric/assert": "0.6.1-dev-
|
|
47
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
48
|
-
"@agoric/internal": "0.3.3-dev-
|
|
49
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
50
|
-
"@agoric/store": "0.9.3-dev-
|
|
51
|
-
"@agoric/swingset-vat": "0.32.3-dev-
|
|
52
|
-
"@agoric/time": "0.3.3-dev-
|
|
53
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
46
|
+
"@agoric/assert": "0.6.1-dev-cc54325.0+cc54325",
|
|
47
|
+
"@agoric/ertp": "0.16.3-dev-cc54325.0+cc54325",
|
|
48
|
+
"@agoric/internal": "0.3.3-dev-cc54325.0+cc54325",
|
|
49
|
+
"@agoric/notifier": "0.6.3-dev-cc54325.0+cc54325",
|
|
50
|
+
"@agoric/store": "0.9.3-dev-cc54325.0+cc54325",
|
|
51
|
+
"@agoric/swingset-vat": "0.32.3-dev-cc54325.0+cc54325",
|
|
52
|
+
"@agoric/time": "0.3.3-dev-cc54325.0+cc54325",
|
|
53
|
+
"@agoric/vat-data": "0.5.3-dev-cc54325.0+cc54325",
|
|
54
54
|
"@endo/bundle-source": "^2.5.2",
|
|
55
55
|
"@endo/captp": "^3.1.2",
|
|
56
56
|
"@endo/eventual-send": "^0.17.3",
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"test/unitTests/zcf/test-reallocate-empty.js",
|
|
105
105
|
"test/unitTests/zcf/test-zoeHelpersWZcf.js",
|
|
106
106
|
"test/unitTests/zcf/test-reallocateForZCFMint.js",
|
|
107
|
+
"test/unitTests/zcf/test-atomicRearrange.js",
|
|
107
108
|
"test/unitTests/zcf/test-zcf.js",
|
|
108
109
|
"test/unitTests/zcf/test-allStagedSeatsUsed.js",
|
|
109
110
|
"# ManualTimer.setWakeup: no function",
|
|
@@ -127,5 +128,5 @@
|
|
|
127
128
|
"publishConfig": {
|
|
128
129
|
"access": "public"
|
|
129
130
|
},
|
|
130
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "cc543255026eb4aa3c8e0ad97ef7b572871063cd"
|
|
131
132
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reallocate.d.ts","sourceRoot":"","sources":["reallocate.js"],"names":[],"mappings":"AAiBO,6CAHI,mBAAmB,GACjB,CAAC,OAAO,EAAE,mBAAmB,CAAC,EAAE,CA8E5C;8BAtFa,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { makeScalarMapStore } from '@agoric/vat-data';
|
|
2
|
+
|
|
3
|
+
import { assertRightsConserved } from './rightsConservation.js';
|
|
4
|
+
import { addToAllocation, subtractFromAllocation } from './allocationMath.js';
|
|
5
|
+
|
|
6
|
+
const { Fail } = assert;
|
|
7
|
+
|
|
8
|
+
/** @typedef {Array<AmountKeywordRecord>} TransactionList */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convert from a list of transfer descriptions ([fromSeat, toSeat, fromAmount,
|
|
12
|
+
* toAmount], with many parts optional) to a list of resulting allocations for
|
|
13
|
+
* each of the seats mentioned.
|
|
14
|
+
*
|
|
15
|
+
* @param {Array<TransferPart>} transfers
|
|
16
|
+
* @returns {[ZCFSeat, AmountKeywordRecord][]}
|
|
17
|
+
*/
|
|
18
|
+
export const makeAllocationMap = transfers => {
|
|
19
|
+
/** @type {MapStore<ZCFSeat, [TransactionList, TransactionList]>} */
|
|
20
|
+
const allocations = makeScalarMapStore();
|
|
21
|
+
|
|
22
|
+
const getAllocations = seat => {
|
|
23
|
+
if (allocations.has(seat)) {
|
|
24
|
+
return allocations.get(seat);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @type {[TransactionList, TransactionList]} */
|
|
28
|
+
const pair = [[], []];
|
|
29
|
+
allocations.init(seat, pair);
|
|
30
|
+
return pair;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const decrementAllocation = (seat, decrement) => {
|
|
34
|
+
const [incr, decr] = getAllocations(seat);
|
|
35
|
+
|
|
36
|
+
const newDecr = [...decr, decrement];
|
|
37
|
+
allocations.set(seat, [incr, newDecr]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const incrementAllocation = (seat, increment) => {
|
|
41
|
+
const [incr, decr] = getAllocations(seat);
|
|
42
|
+
|
|
43
|
+
const newIncr = [...incr, increment];
|
|
44
|
+
allocations.set(seat, [newIncr, decr]);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
for (const [fromSeat, toSeat, fromAmounts, toAmounts] of transfers) {
|
|
48
|
+
if (fromSeat) {
|
|
49
|
+
if (!fromAmounts) {
|
|
50
|
+
throw Fail`Transfer from ${fromSeat} must say how much`;
|
|
51
|
+
}
|
|
52
|
+
decrementAllocation(fromSeat, fromAmounts);
|
|
53
|
+
if (toSeat) {
|
|
54
|
+
// Conserved transfer between seats
|
|
55
|
+
if (toAmounts) {
|
|
56
|
+
// distinct amounts, so we check conservation.
|
|
57
|
+
assertRightsConserved(
|
|
58
|
+
Object.values(fromAmounts),
|
|
59
|
+
Object.values(toAmounts),
|
|
60
|
+
);
|
|
61
|
+
incrementAllocation(toSeat, toAmounts);
|
|
62
|
+
} else {
|
|
63
|
+
// fromAmounts will be used for toAmounts as well
|
|
64
|
+
incrementAllocation(toSeat, fromAmounts);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
// Transfer only from fromSeat
|
|
68
|
+
!toAmounts ||
|
|
69
|
+
Fail`Transfer without toSeat cannot have toAmounts ${toAmounts}`;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
toSeat || Fail`Transfer must have at least one of fromSeat or toSeat`;
|
|
73
|
+
// Transfer only to toSeat
|
|
74
|
+
!fromAmounts ||
|
|
75
|
+
Fail`Transfer without fromSeat cannot have fromAmounts ${fromAmounts}`;
|
|
76
|
+
toAmounts || Fail`Transfer to ${toSeat} must say how much`;
|
|
77
|
+
incrementAllocation(toSeat, toAmounts);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @type {[ZCFSeat,AmountKeywordRecord][]} */
|
|
82
|
+
const resultingAllocations = [];
|
|
83
|
+
for (const [seat, [incrList, decrList]] of allocations.entries()) {
|
|
84
|
+
let newAlloc = seat.getCurrentAllocation();
|
|
85
|
+
for (const incr of incrList) {
|
|
86
|
+
newAlloc = addToAllocation(newAlloc, incr);
|
|
87
|
+
}
|
|
88
|
+
for (const decr of decrList) {
|
|
89
|
+
newAlloc = subtractFromAllocation(newAlloc, decr);
|
|
90
|
+
}
|
|
91
|
+
resultingAllocations.push([seat, newAlloc]);
|
|
92
|
+
}
|
|
93
|
+
return resultingAllocations;
|
|
94
|
+
};
|
|
@@ -14,6 +14,10 @@ type ZCFMakeEmptySeatKit = (exit?: ExitRule | undefined) => ZcfSeatKit;
|
|
|
14
14
|
* in code as zcf.
|
|
15
15
|
*/
|
|
16
16
|
type ZCF<CT extends unknown = Record<string, unknown>> = {
|
|
17
|
+
/**
|
|
18
|
+
* - atomically reallocate amounts among seats.
|
|
19
|
+
*/
|
|
20
|
+
atomicRearrange: (transfers: TransferPart[]) => void;
|
|
17
21
|
/**
|
|
18
22
|
* - reallocate amounts among seats.
|
|
19
23
|
* Deprecated: Use atomicRearrange instead.
|
|
@@ -71,6 +75,12 @@ type ZCF<CT extends unknown = Record<string, unknown>> = {
|
|
|
71
75
|
* effect offer safety for seats whose allocations change.
|
|
72
76
|
*/
|
|
73
77
|
type Reallocate = (seat1: ZCFSeat, seat2: ZCFSeat, ...seatRest: Array<ZCFSeat>) => void;
|
|
78
|
+
type TransferPart = [
|
|
79
|
+
fromSeat?: ZCFSeat,
|
|
80
|
+
toSeat?: ZCFSeat,
|
|
81
|
+
fromAmounts?: AmountKeywordRecord,
|
|
82
|
+
toAmounts?: AmountKeywordRecord
|
|
83
|
+
];
|
|
74
84
|
/**
|
|
75
85
|
* Informs Zoe about an issuer and returns a promise for acknowledging
|
|
76
86
|
* when the issuer is added and ready.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"2BAIc,OAAO,cAAc,EAAE,mBAAmB;;;;kBAI3C,GAAG;4DAOH,UAAU
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"2BAIc,OAAO,cAAc,EAAE,mBAAmB;;;;kBAI3C,GAAG;4DAOH,UAAU;;;;;;;;;;;;;;iCAaG,cAAc,KAAK,IAAI;;;;;gBACnC,UAAU;;;;;;mCAEA,OAAO,KAAK,IAAI;;;;;;gBAG1B,UAAU;oBAGV,cAAc;2BACD,UAAU,KAAK,IAAI;yBAChC,mBAAmB;mBACnB,MAAM,KAAK,UAAU,CAAC;yBACtB,MAAM,OAAO,KAAK,CAAC;cACnB,MAAM,aAAa,GAAG,EAAE;;;kBAGxB,mBAAmB;0DAEnB,OAAO,6CAEF,qBAAqB,YACzB,mBAAmB;qBAEpB,kBAAkB;sBAClB,mBAAmB;gBACnB,UAAU;yBACV,MAAM,QAAQ,IAAI,CAAC;8BACT,MAAM,MAAM,CAAC,KAAK,QAAQ,IAAI,CAAC;oBACzC,MAAM,QAAQ,MAAM,MAAM,CAAC,CAAC;iBAC5B,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;0BAMP,OAAO,SAAS,OAAO,eAC3C,MAAQ,OAAO,CAAC,KAAK,IAAI;oBAwBb;IACZ,QAAY,CAAC,EAAE,OAAO;IACtB,MAAU,CAAC,EAAE,OAAO;IACpB,WAAe,CAAC,EAAE,mBAAmB;IACrC,SAAa,CAAC,EAAE,mBAAmB;CAChC;;;;;4BASO,KAAK,MAAM,CAAC,WACZ,OAAO,KACL,QAAQ,iBAAe,CAAC;;;;;;;;;;;gFAMnB,MAAM,kBACH,MAAM,kBACN,OAAO;oCAgBjB,OAAO,wBACP,aAAa,KAEX,QAAQ,QAAQ,KAAK,CAAC,CAAC;;;;;;;;;;;;;;;2BAkBzB,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,KAC3B,IAAI;;qBAMH,MAAM,aAAa,CAAC,CAAC;;;;;;;;;;;;uBACb,mBAAmB,YAAY,OAAO,KAAK,OAAO;;;;;;;;;yBAWjD,mBAAmB,WAClB,OAAO,KACZ,IAAI;;;;;;4BAcZ,OAAO,KACL,KAAK;;;;;uCAOP,OAAO,2CAEL,OAAO,GAAG,CAAC;;wBAKI,UAAU,KAAK,IAAI;UACjC,WAAW;mBACX,MAAM,QAAQ,WAAW,UAAU,CAAC,CAAC;eACrC,MAAM,OAAO;iBACb,MAAM,cAAc;wBACpB,qBAAqB;0BACrB,MAAM,UAAU;;;;yBAChB,MAAM,UAAU;;;;yBAEhB,MAAM,OAAO;iCAEG,UAAU,KAAK,OAAO;;;;uCAChB,mBAAmB,KAAK,mBAAmB;;;;uCAE3C,mBAAmB,KAAK,mBAAmB;;;;WAEjE,MAAM,IAAI;;kBAKX;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC,CAAA;CAAC;8CAKtC,OAAO,cAAc,MAAM,KAAK,EAAE;kDAKzC,YAAY,EAAE,CAAC,GAAG;IAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;CAAE;;;;;;;;;;;qIAsB/C,IAAI,EAAE,CAAC,eACP,EAAE,+CAEA,sBAAsB,EAAE,EAAE,EAAE,CAAC;;iBAO5B,EAAE;kBACF,EAAE;;;qBAMH,OAAO,qBAAqB,EAAE,UAAU,CAAC,CAAC,CAAC;kBAI3C,OAAO,qBAAqB,EAAE,UAAU"}
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* synchronously from within the contract, and usually is referred to
|
|
27
27
|
* in code as zcf.
|
|
28
28
|
*
|
|
29
|
+
* @property {(transfers: TransferPart[]) => void} atomicRearrange - atomically reallocate amounts among seats.
|
|
29
30
|
* @property {Reallocate} reallocate - reallocate amounts among seats.
|
|
30
31
|
* Deprecated: Use atomicRearrange instead.
|
|
31
32
|
* @property {(keyword: Keyword) => void} assertUniqueKeyword - check
|
|
@@ -59,6 +60,8 @@
|
|
|
59
60
|
*/
|
|
60
61
|
|
|
61
62
|
/**
|
|
63
|
+
* @deprecated reallocate(). Use zcf.atomicRearrange() instead
|
|
64
|
+
*
|
|
62
65
|
* @typedef {(seat1: ZCFSeat, seat2: ZCFSeat, ...seatRest:
|
|
63
66
|
* Array<ZCFSeat>) => void} Reallocate
|
|
64
67
|
*
|
|
@@ -83,6 +86,15 @@
|
|
|
83
86
|
* effect offer safety for seats whose allocations change.
|
|
84
87
|
*/
|
|
85
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @typedef {[
|
|
91
|
+
* fromSeat?: ZCFSeat,
|
|
92
|
+
* toSeat?: ZCFSeat,
|
|
93
|
+
* fromAmounts?: AmountKeywordRecord,
|
|
94
|
+
* toAmounts?: AmountKeywordRecord
|
|
95
|
+
* ]} TransferPart
|
|
96
|
+
*/
|
|
97
|
+
|
|
86
98
|
/**
|
|
87
99
|
* @callback SaveIssuer
|
|
88
100
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zcfSeat.d.ts","sourceRoot":"","sources":["zcfSeat.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zcfSeat.d.ts","sourceRoot":"","sources":["zcfSeat.js"],"names":[],"mappings":"AA0BA,gCAAgC;AAChC,gCADW,iBAAiB,CAyd1B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
makeScalarBigWeakMapStore,
|
|
3
|
-
|
|
4
|
-
provideDurableWeakMapStore,
|
|
3
|
+
prepareExoClass,
|
|
5
4
|
prepareExoClassKit,
|
|
6
5
|
provide,
|
|
7
|
-
|
|
6
|
+
provideDurableMapStore,
|
|
7
|
+
provideDurableWeakMapStore,
|
|
8
8
|
} from '@agoric/vat-data';
|
|
9
9
|
import { E } from '@endo/eventual-send';
|
|
10
10
|
import { AmountMath } from '@agoric/ertp';
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
SeatDataShape,
|
|
20
20
|
SeatShape,
|
|
21
21
|
} from '../typeGuards.js';
|
|
22
|
+
import { makeAllocationMap } from './reallocate.js';
|
|
23
|
+
import { TransferPartShape } from '../contractSupport/atomicTransfer.js';
|
|
22
24
|
|
|
23
25
|
const { Fail } = assert;
|
|
24
26
|
|
|
@@ -214,6 +216,10 @@ export const createSeatManager = (
|
|
|
214
216
|
|
|
215
217
|
return isOfferSafe(state.proposal, reallocation);
|
|
216
218
|
},
|
|
219
|
+
/**
|
|
220
|
+
* @deprecated switch to zcf.atomicRearrange()
|
|
221
|
+
* @param {AmountKeywordRecord} amountKeywordRecord
|
|
222
|
+
*/
|
|
217
223
|
incrementBy(amountKeywordRecord) {
|
|
218
224
|
const { self } = this;
|
|
219
225
|
assertActive(self);
|
|
@@ -227,6 +233,10 @@ export const createSeatManager = (
|
|
|
227
233
|
);
|
|
228
234
|
return amountKeywordRecord;
|
|
229
235
|
},
|
|
236
|
+
/**
|
|
237
|
+
* @deprecated switch to zcf.atomicRearrange()
|
|
238
|
+
* @param {AmountKeywordRecord} amountKeywordRecord
|
|
239
|
+
*/
|
|
230
240
|
decrementBy(amountKeywordRecord) {
|
|
231
241
|
const { self } = this;
|
|
232
242
|
assertActive(self);
|
|
@@ -265,6 +275,7 @@ export const createSeatManager = (
|
|
|
265
275
|
const ZcfSeatManagerIKit = harden({
|
|
266
276
|
seatManager: M.interface('ZcfSeatManager', {
|
|
267
277
|
makeZCFSeat: M.call(SeatDataShape).returns(M.remotable('zcfSeat')),
|
|
278
|
+
atomicRearrange: M.call(M.arrayOf(TransferPartShape)).returns(),
|
|
268
279
|
reallocate: M.call(M.remotable('zcfSeat'), M.remotable('zcfSeat'))
|
|
269
280
|
.rest(M.arrayOf(M.remotable('zcfSeat')))
|
|
270
281
|
.returns(),
|
|
@@ -289,6 +300,96 @@ export const createSeatManager = (
|
|
|
289
300
|
return zcfSeat;
|
|
290
301
|
},
|
|
291
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Rearrange the allocations according to the transfer descriptions.
|
|
305
|
+
* This is a set of changes to allocations that must satisfy several
|
|
306
|
+
* constraints. If these constraints are all met, then the reallocation
|
|
307
|
+
* happens atomically. Otherwise, it does not happen at all.
|
|
308
|
+
*
|
|
309
|
+
* The conditions
|
|
310
|
+
* * All the mentioned seats are still live,
|
|
311
|
+
* * No outstanding stagings for any of the mentioned seats. Stagings
|
|
312
|
+
* have been deprecated in favor or atomicRearrange. To prevent
|
|
313
|
+
* confusion, for each reallocation, it can only be expressed in
|
|
314
|
+
* the old way or the new way, but not a mixture.
|
|
315
|
+
* * Offer safety
|
|
316
|
+
* * Overall conservation
|
|
317
|
+
*
|
|
318
|
+
* The overall transfer is expressed as an array of `TransferPart`. Each
|
|
319
|
+
* individual `TransferPart` is one of
|
|
320
|
+
* - A transfer from a `fromSeat` to a `toSeat`. Specify both toAmount
|
|
321
|
+
* and fromAmount to change keywords, otherwise only fromAmount is required.
|
|
322
|
+
* - A taking from a `fromSeat`'s allocation. See the `fromOnly` helper.
|
|
323
|
+
* - A giving into a `toSeat`'s allocation. See the `toOnly` helper.
|
|
324
|
+
*
|
|
325
|
+
* @param {TransferPart[]} transfers
|
|
326
|
+
*/
|
|
327
|
+
atomicRearrange(transfers) {
|
|
328
|
+
const newAllocations = makeAllocationMap(transfers);
|
|
329
|
+
|
|
330
|
+
// ////// All Seats are active /////////////////////////////////
|
|
331
|
+
for (const [seat] of newAllocations) {
|
|
332
|
+
assertActive(seat);
|
|
333
|
+
!seat.hasStagedAllocation() ||
|
|
334
|
+
Fail`Cannot mix atomicRearrange with seat stagings: ${seat}`;
|
|
335
|
+
zcfSeatToSeatHandle.has(seat) ||
|
|
336
|
+
Fail`The seat ${seat} was not recognized`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ////// Ensure that rights are conserved overall /////////////
|
|
340
|
+
|
|
341
|
+
// convert array of keywordAmountRecords to 1-level array of Amounts
|
|
342
|
+
const flattenAmounts = allocations =>
|
|
343
|
+
allocations.flatMap(Object.values);
|
|
344
|
+
const previousAmounts = flattenAmounts(
|
|
345
|
+
newAllocations.map(([seat]) => seat.getCurrentAllocation()),
|
|
346
|
+
);
|
|
347
|
+
const newAmounts = flattenAmounts(
|
|
348
|
+
newAllocations.map(([_, allocation]) => allocation),
|
|
349
|
+
);
|
|
350
|
+
assertRightsConserved(previousAmounts, newAmounts);
|
|
351
|
+
|
|
352
|
+
// ////// Ensure that offer safety holds ///////////////////////
|
|
353
|
+
for (const [seat, allocation] of newAllocations) {
|
|
354
|
+
isOfferSafe(seat.getProposal(), allocation) ||
|
|
355
|
+
Fail`Offer safety was violated by the proposed allocation: ${allocation}. Proposal was ${seat.getProposal()}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const seatHandleAllocations = newAllocations.map(
|
|
359
|
+
([seat, allocation]) => {
|
|
360
|
+
const seatHandle = zcfSeatToSeatHandle.get(seat);
|
|
361
|
+
return { allocation, seatHandle };
|
|
362
|
+
},
|
|
363
|
+
);
|
|
364
|
+
try {
|
|
365
|
+
// No side effects above. All conditions checked which could have
|
|
366
|
+
// caused us to reject this reallocation. Notice that the current
|
|
367
|
+
// allocations are captured in seatHandleAllocations, so there must
|
|
368
|
+
// be no awaits between that assignment and here.
|
|
369
|
+
//
|
|
370
|
+
// COMMIT POINT
|
|
371
|
+
//
|
|
372
|
+
// The effects must succeed atomically. The call to
|
|
373
|
+
// replaceAllocations() will be processed in the order of updates
|
|
374
|
+
// from ZCF to Zoe. Its effects must occur immediately in Zoe on
|
|
375
|
+
// reception, and must not fail.
|
|
376
|
+
//
|
|
377
|
+
// Commit the new allocations (currentAllocation is replaced
|
|
378
|
+
// for each of the seats) and inform Zoe of the new allocation.
|
|
379
|
+
|
|
380
|
+
for (const [seat, allocation] of newAllocations) {
|
|
381
|
+
activeZCFSeats.set(seat, allocation);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// we don't wait for the results here. As described in
|
|
385
|
+
// docs/zoe-zcf.md, The initial allocation to a seat originates with
|
|
386
|
+
// Zoe, but *all subsequent updates come from ZCF to Zoe*.
|
|
387
|
+
void E(zoeInstanceAdmin).replaceAllocations(seatHandleAllocations);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
shutdownWithFailure(err);
|
|
390
|
+
throw err;
|
|
391
|
+
}
|
|
392
|
+
},
|
|
292
393
|
reallocate(/** @type {ZCFSeat[]} */ ...seats) {
|
|
293
394
|
seats.forEach(assertActive);
|
|
294
395
|
seats.forEach(assertStagedAllocation);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zcfZygote.d.ts","sourceRoot":"","sources":["zcfZygote.js"],"names":[],"mappings":"AAiDO,sCARI,SAAS,cACT,KAAK,UAAU,CAAC,oBAChB,OAAO,KAAK,CAAC,iBACb,aAAa,qBACb,SAAS,2CAEP,QAAQ,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"zcfZygote.d.ts","sourceRoot":"","sources":["zcfZygote.js"],"names":[],"mappings":"AAiDO,sCARI,SAAS,cACT,KAAK,UAAU,CAAC,oBAChB,OAAO,KAAK,CAAC,iBACb,aAAa,qBACb,SAAS,2CAEP,QAAQ,SAAS,CAAC,CAka9B;kCAjba,OAAO,cAAc,EAAE,mBAAmB"}
|
|
@@ -251,6 +251,7 @@ export const makeZCFZygote = async (
|
|
|
251
251
|
// accept raw functions. assert cannot be a valid passable! (It's a function
|
|
252
252
|
// and has members.)
|
|
253
253
|
const zcf = Remotable('Alleged: zcf', undefined, {
|
|
254
|
+
atomicRearrange: transfers => seatManager.atomicRearrange(transfers),
|
|
254
255
|
reallocate: (...seats) => seatManager.reallocate(...seats),
|
|
255
256
|
assertUniqueKeyword: kwd => getInstanceRecHolder().assertUniqueKeyword(kwd),
|
|
256
257
|
saveIssuer: async (issuerP, keyword) => {
|
|
@@ -3,10 +3,4 @@ export function atomicRearrange(zcf: ZCF, transfers: TransferPart[]): void;
|
|
|
3
3
|
export function fromOnly(fromSeat: ZCFSeat, fromAmounts: AmountKeywordRecord): TransferPart;
|
|
4
4
|
export function toOnly(toSeat: ZCFSeat, toAmounts: AmountKeywordRecord): TransferPart;
|
|
5
5
|
export function atomicTransfer(zcf: ZCF, fromSeat?: ZCFSeat | undefined, toSeat?: ZCFSeat | undefined, fromAmounts?: AmountKeywordRecord | undefined, toAmounts?: AmountKeywordRecord | undefined): void;
|
|
6
|
-
export type TransferPart = [
|
|
7
|
-
fromSeat?: ZCFSeat,
|
|
8
|
-
toSeat?: ZCFSeat,
|
|
9
|
-
fromAmounts?: AmountKeywordRecord,
|
|
10
|
-
toAmounts?: AmountKeywordRecord
|
|
11
|
-
];
|
|
12
6
|
//# sourceMappingURL=atomicTransfer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomicTransfer.d.ts","sourceRoot":"","sources":["atomicTransfer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atomicTransfer.d.ts","sourceRoot":"","sources":["atomicTransfer.js"],"names":[],"mappings":"AAGA,iEAGE;AAyCK,qCAHI,GAAG,aACH,cAAc,QAIxB;AAcM,mCAJI,OAAO,eACP,mBAAmB,gBAIc;AAcrC,+BAJI,OAAO,aACP,mBAAmB,gBAIqB;AAW5C,oCANI,GAAG,kKAYgE"}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { assertRightsConserved } from '../contractFacet/rightsConservation.js';
|
|
1
|
+
import { M } from '@agoric/store';
|
|
3
2
|
import { AmountKeywordRecordShape, SeatShape } from '../typeGuards.js';
|
|
4
3
|
|
|
5
|
-
const { Fail, quote: q } = assert;
|
|
6
|
-
|
|
7
4
|
export const TransferPartShape = M.splitArray(
|
|
8
5
|
harden([M.opt(SeatShape), M.opt(SeatShape), M.opt(AmountKeywordRecordShape)]),
|
|
9
6
|
harden([M.opt(AmountKeywordRecordShape)]),
|
|
10
7
|
);
|
|
11
8
|
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {[
|
|
14
|
-
* fromSeat?: ZCFSeat,
|
|
15
|
-
* toSeat?: ZCFSeat,
|
|
16
|
-
* fromAmounts?: AmountKeywordRecord,
|
|
17
|
-
* toAmounts?: AmountKeywordRecord
|
|
18
|
-
* ]} TransferPart
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
9
|
/**
|
|
22
10
|
* Asks Zoe (via zcf) to rearrange the allocations among the seats
|
|
23
11
|
* mentioned. This is a set of changes to allocations that must satisfy
|
|
@@ -52,86 +40,13 @@ export const TransferPartShape = M.splitArray(
|
|
|
52
40
|
* which will remain helpers. These helper are for convenience
|
|
53
41
|
* in expressing atomic rearrangements clearly.
|
|
54
42
|
*
|
|
43
|
+
* @deprecated use the zcf builtin instead
|
|
44
|
+
*
|
|
55
45
|
* @param {ZCF} zcf
|
|
56
46
|
* @param {TransferPart[]} transfers
|
|
57
47
|
*/
|
|
58
48
|
export const atomicRearrange = (zcf, transfers) => {
|
|
59
|
-
|
|
60
|
-
const uniqueSeatSet = new Set();
|
|
61
|
-
for (const [
|
|
62
|
-
fromSeat = undefined,
|
|
63
|
-
toSeat = undefined,
|
|
64
|
-
fromAmounts = undefined,
|
|
65
|
-
toAmounts = undefined,
|
|
66
|
-
] of transfers) {
|
|
67
|
-
if (fromSeat) {
|
|
68
|
-
if (!fromAmounts) {
|
|
69
|
-
throw Fail`Transfer from ${fromSeat} must say how much`;
|
|
70
|
-
}
|
|
71
|
-
uniqueSeatSet.add(fromSeat);
|
|
72
|
-
if (toSeat) {
|
|
73
|
-
// Conserved transfer between seats
|
|
74
|
-
if (toAmounts) {
|
|
75
|
-
// distinct amounts, so we check conservation.
|
|
76
|
-
assertRightsConserved(
|
|
77
|
-
Object.values(fromAmounts),
|
|
78
|
-
Object.values(toAmounts),
|
|
79
|
-
);
|
|
80
|
-
} // else fromAmounts will be used as toAmounts
|
|
81
|
-
uniqueSeatSet.add(toSeat);
|
|
82
|
-
} else {
|
|
83
|
-
// Transfer only from fromSeat
|
|
84
|
-
!toAmounts ||
|
|
85
|
-
Fail`Transfer without toSeat cannot have toAmounts ${toAmounts}`;
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
toSeat || Fail`Transfer must have at least one of fromSeat or toSeat`;
|
|
89
|
-
// Transfer only to toSeat
|
|
90
|
-
!fromAmounts ||
|
|
91
|
-
Fail`Transfer without fromSeat cannot have fromAmounts ${fromAmounts}`;
|
|
92
|
-
toAmounts || Fail`Transfer to ${toSeat} must say how much`;
|
|
93
|
-
uniqueSeatSet.add(toSeat);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const uniqueSeats = harden([...uniqueSeatSet.keys()]);
|
|
98
|
-
for (const seat of uniqueSeats) {
|
|
99
|
-
!seat.hasStagedAllocation() ||
|
|
100
|
-
Fail`Cannot mix atomicRearrange with seat stagings: ${seat}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// At this point the basic shape has been validated
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
for (const [
|
|
107
|
-
fromSeat = undefined,
|
|
108
|
-
toSeat = undefined,
|
|
109
|
-
fromAmounts = undefined,
|
|
110
|
-
toAmounts = toSeat && fromAmounts,
|
|
111
|
-
] of transfers) {
|
|
112
|
-
if (fromSeat && fromAmounts) {
|
|
113
|
-
// testing both just to satisfy the type checker
|
|
114
|
-
fromSeat.decrementBy(fromAmounts);
|
|
115
|
-
}
|
|
116
|
-
if (toSeat && toAmounts) {
|
|
117
|
-
// testing both just to satisfy the type checker
|
|
118
|
-
toSeat.incrementBy(toAmounts);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Perhaps deprecate this >= 2 restriction?
|
|
123
|
-
uniqueSeats.length >= 2 ||
|
|
124
|
-
Fail`Can only commit a reallocation among at least 2 seats: ${q(
|
|
125
|
-
uniqueSeats.length,
|
|
126
|
-
)}`;
|
|
127
|
-
// Take it apart and put it back together to satisfy the type checker
|
|
128
|
-
const [seat0, seat1, ...restSeats] = uniqueSeats;
|
|
129
|
-
zcf.reallocate(seat0, seat1, ...restSeats);
|
|
130
|
-
} finally {
|
|
131
|
-
for (const seat of uniqueSeats) {
|
|
132
|
-
seat.clear();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
49
|
+
zcf.atomicRearrange(transfers);
|
|
135
50
|
};
|
|
136
51
|
|
|
137
52
|
/**
|
|
@@ -179,4 +94,4 @@ export const atomicTransfer = (
|
|
|
179
94
|
toSeat = undefined,
|
|
180
95
|
fromAmounts = undefined,
|
|
181
96
|
toAmounts = undefined,
|
|
182
|
-
) => atomicRearrange(
|
|
97
|
+
) => zcf.atomicRearrange(harden([[fromSeat, toSeat, fromAmounts, toAmounts]]));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zoeHelpers.d.ts","sourceRoot":"","sources":["zoeHelpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zoeHelpers.d.ts","sourceRoot":"","sources":["zoeHelpers.js"],"names":[],"mappings":"AAQA,iIAAkI;AAM3H,oEAON;AAuBM,+BALI,GAAG,QACH,cAAc,UACd,mBAAmB,GACjB,CAAC,GAAC,CAAC,CAOf;AAED,mBAAmB;AACnB,mBADW,IAAI,CAkBb;AAEF,wBAAwB;AACxB,wBADW,SAAS,CAqBlB;AAiBK,uCAHI,OAAO,iBACP,OAAO,QAIgD;AAsB3D,0CAHI,OAAO,YACP,cAAc,QA+BxB;AAGM,+DAGN;AAED,6EAA8E;AAavE,mCANI,GAAG,iBACH,OAAO,WACP,mBAAmB,YACnB,qBAAqB,GACnB,QAAQ,MAAM,CAAC,CA8B3B;AAYM,sCALI,GAAG,QACH,OAAO,WACP,mBAAmB,GACjB,QAAQ,qBAAqB,CAAC,CAQ1C;AAWM,oCAJI,GAAG,wBACH,mBAAmB,8CAgB7B;AAED,0BAA0B;AAC1B,0BADW,WAAW,CAYpB;AAiDK,2EAjCI,GAAG,sDAMH,oBAAoB,GAAG,SAAS,YAKhC,QAAQ,YAGR,OAAO;;eAU2D,QAAQ,mBAAmB,CAAC;GA+DxG;;iBAzVa,MAAM,cAAc;0BACpB,MAAM,UAAU"}
|
|
@@ -4,12 +4,7 @@ import { makePromiseKit } from '@endo/promise-kit';
|
|
|
4
4
|
import { AssetKind } from '@agoric/ertp';
|
|
5
5
|
import { fromUniqueEntries } from '@agoric/internal';
|
|
6
6
|
import { satisfiesWant } from '../contractFacet/offerSafety.js';
|
|
7
|
-
import {
|
|
8
|
-
atomicRearrange,
|
|
9
|
-
atomicTransfer,
|
|
10
|
-
fromOnly,
|
|
11
|
-
toOnly,
|
|
12
|
-
} from './atomicTransfer.js';
|
|
7
|
+
import { atomicTransfer, fromOnly, toOnly } from './atomicTransfer.js';
|
|
13
8
|
|
|
14
9
|
export const defaultAcceptanceMsg = `The offer has been accepted. Once the contract has been completed, please check your payout`;
|
|
15
10
|
|
|
@@ -57,8 +52,7 @@ export const satisfies = (zcf, seat, update) => {
|
|
|
57
52
|
/** @type {Swap} */
|
|
58
53
|
export const swap = (zcf, leftSeat, rightSeat) => {
|
|
59
54
|
try {
|
|
60
|
-
atomicRearrange(
|
|
61
|
-
zcf,
|
|
55
|
+
zcf.atomicRearrange(
|
|
62
56
|
harden([
|
|
63
57
|
[rightSeat, leftSeat, leftSeat.getProposal().want],
|
|
64
58
|
[leftSeat, rightSeat, rightSeat.getProposal().want],
|
|
@@ -78,8 +72,7 @@ export const swap = (zcf, leftSeat, rightSeat) => {
|
|
|
78
72
|
/** @type {SwapExact} */
|
|
79
73
|
export const swapExact = (zcf, leftSeat, rightSeat) => {
|
|
80
74
|
try {
|
|
81
|
-
atomicRearrange(
|
|
82
|
-
zcf,
|
|
75
|
+
zcf.atomicRearrange(
|
|
83
76
|
harden([
|
|
84
77
|
fromOnly(rightSeat, rightSeat.getProposal().give),
|
|
85
78
|
fromOnly(leftSeat, leftSeat.getProposal().give),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firstPriceLogic.d.ts","sourceRoot":"","sources":["firstPriceLogic.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"firstPriceLogic.d.ts","sourceRoot":"","sources":["firstPriceLogic.js"],"names":[],"mappings":"AAOO,wCAJI,GAAG,YACH,OAAO,YACP,MAAM,OAAO,CAAC,QAoDxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AmountMath } from '@agoric/ertp';
|
|
2
|
-
import { atomicRearrange } from '../../contractSupport/index.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @param {ZCF} zcf
|
|
@@ -42,8 +41,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
|
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
// Everyone else gets a refund so their values remain the same.
|
|
45
|
-
atomicRearrange(
|
|
46
|
-
zcf,
|
|
44
|
+
zcf.atomicRearrange(
|
|
47
45
|
harden([
|
|
48
46
|
[highestBidSeat, sellSeat, { Bid: highestBid }, { Ask: highestBid }],
|
|
49
47
|
[sellSeat, highestBidSeat, { Asset: assetAmount }],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secondPriceLogic.d.ts","sourceRoot":"","sources":["secondPriceLogic.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secondPriceLogic.d.ts","sourceRoot":"","sources":["secondPriceLogic.js"],"names":[],"mappings":"AAOO,wCAJI,GAAG,YACH,OAAO,YACP,MAAM,OAAO,CAAC,QA+DxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AmountMath } from '@agoric/ertp';
|
|
2
|
-
import { atomicRearrange } from '../../contractSupport/index.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @param {ZCF} zcf
|
|
@@ -48,8 +47,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
// Everyone else gets a refund so their values remain the same.
|
|
51
|
-
atomicRearrange(
|
|
52
|
-
zcf,
|
|
50
|
+
zcf.atomicRearrange(
|
|
53
51
|
harden([
|
|
54
52
|
[
|
|
55
53
|
highestBidSeat,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoswap.d.ts","sourceRoot":"","sources":["autoswap.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"autoswap.d.ts","sourceRoot":"","sources":["autoswap.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,2BAFW,GAAG;;GAoVb"}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
assertProposalShape,
|
|
12
12
|
assertNatAssetKind,
|
|
13
13
|
calcSecondaryRequired,
|
|
14
|
-
atomicRearrange,
|
|
15
14
|
} from '../contractSupport/index.js';
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -88,8 +87,7 @@ const start = async zcf => {
|
|
|
88
87
|
};
|
|
89
88
|
|
|
90
89
|
function consummate(tradeAmountIn, tradeAmountOut, swapSeat) {
|
|
91
|
-
atomicRearrange(
|
|
92
|
-
zcf,
|
|
90
|
+
zcf.atomicRearrange(
|
|
93
91
|
harden([
|
|
94
92
|
[
|
|
95
93
|
swapSeat,
|
|
@@ -205,8 +203,7 @@ const start = async zcf => {
|
|
|
205
203
|
Central: AmountMath.make(brands.Central, centralIn),
|
|
206
204
|
Secondary: secondaryAmount,
|
|
207
205
|
};
|
|
208
|
-
atomicRearrange(
|
|
209
|
-
zcf,
|
|
206
|
+
zcf.atomicRearrange(
|
|
210
207
|
harden([
|
|
211
208
|
[seat, poolSeat, liquidityDeposited],
|
|
212
209
|
[poolSeat, seat, { Liquidity: liquidityAmountOut }],
|
|
@@ -308,8 +305,7 @@ const start = async zcf => {
|
|
|
308
305
|
Secondary: newUserSecondaryAmount,
|
|
309
306
|
};
|
|
310
307
|
|
|
311
|
-
atomicRearrange(
|
|
312
|
-
zcf,
|
|
308
|
+
zcf.atomicRearrange(
|
|
313
309
|
harden([
|
|
314
310
|
[removeLiqSeat, poolSeat, { Liquidity: userAllocation.Liquidity }],
|
|
315
311
|
[poolSeat, removeLiqSeat, liquidityRemoved],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barterExchange.d.ts","sourceRoot":"","sources":["barterExchange.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,2BAFW,GAAG;;;;;;
|
|
1
|
+
{"version":3,"file":"barterExchange.d.ts","sourceRoot":"","sources":["barterExchange.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,2BAFW,GAAG;;;;;;EA+Gb"}
|