@agoric/inter-protocol 0.16.2-dev-da94029.0 → 0.16.2-dev-43b4090.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/package.json +3 -2
- package/src/reserve/assetReserve.d.ts +7 -0
- package/src/reserve/assetReserve.d.ts.map +1 -1
- package/src/reserve/assetReserve.js +3 -0
- package/src/reserve/assetReserveKit.d.ts +27 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -1
- package/src/reserve/assetReserveKit.js +108 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/inter-protocol",
|
|
3
|
-
"version": "0.16.2-dev-
|
|
3
|
+
"version": "0.16.2-dev-43b4090.0+43b4090",
|
|
4
4
|
"description": "Core cryptoeconomy contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@agoric/base-zone": "workspace:*",
|
|
34
35
|
"@agoric/ertp": "workspace:*",
|
|
35
36
|
"@agoric/governance": "workspace:*",
|
|
36
37
|
"@agoric/internal": "workspace:*",
|
|
@@ -84,5 +85,5 @@
|
|
|
84
85
|
"typeCoverage": {
|
|
85
86
|
"atLeast": 95.72
|
|
86
87
|
},
|
|
87
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "43b409040628dd3706a1279098534d3cf1d18ab7"
|
|
88
89
|
}
|
|
@@ -16,6 +16,11 @@ export function start(zcf: ZCF<GovernanceTerms<{}> & {
|
|
|
16
16
|
increaseLiquidationShortfall(shortfall: Amount<"nat">): void;
|
|
17
17
|
reduceLiquidationShortfall(reduction: Amount<"nat">): void;
|
|
18
18
|
}>, undefined>>;
|
|
19
|
+
makeSingleWithdrawalInvitation(): Promise<globalThis.Invitation<any, undefined>>;
|
|
20
|
+
makeRepeatableWithdrawalInvitation(): Promise<globalThis.Invitation<{
|
|
21
|
+
invitationMakers: Partial<any>;
|
|
22
|
+
}, undefined>>;
|
|
23
|
+
revokeOutstandingWithdrawalInvitations(): void;
|
|
19
24
|
}>>;
|
|
20
25
|
/** @type {GovernedPublicFacet<typeof assetReserveKit.public>} */
|
|
21
26
|
publicFacet: GovernedPublicFacet<import("@endo/exo").Guarded<{
|
|
@@ -43,9 +48,11 @@ export type AssetReservePublicFacet = EReturn<typeof start>["publicFacet"];
|
|
|
43
48
|
* the creator facet for the governor
|
|
44
49
|
*/
|
|
45
50
|
export type AssetReserveCreatorFacet = EReturn<typeof start>["creatorFacet"];
|
|
51
|
+
export type ReserveContract = ContractOf<typeof start>;
|
|
46
52
|
import type { ContractMeta } from '@agoric/zoe';
|
|
47
53
|
import type { FeeMintAccess } from '@agoric/zoe';
|
|
48
54
|
import type { Baggage } from '@agoric/vat-data';
|
|
49
55
|
import type { Allocation } from '@agoric/zoe';
|
|
50
56
|
import type { EReturn } from '@endo/far';
|
|
57
|
+
import type { ContractOf } from '@agoric/zoe/src/zoeService/utils.js';
|
|
51
58
|
//# sourceMappingURL=assetReserve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetReserve.d.ts","sourceRoot":"","sources":["assetReserve.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assetReserve.d.ts","sourceRoot":"","sources":["assetReserve.js"],"names":[],"mappings":"AAkBA,yCAAyC;AACzC,mBADW,aAAa,OAAO,KAAK,CAAC,CAGnC;AAgCK,2BAbI,GAAG,CACT,eAAe,CAAC,EAAE,CAAC,GAAG;IACpB,YAAY,EAAE,CAAC,2BAA2B,CAAC,CAAC;CAC7C,CACF,eACO;IACN,aAAa,EAAE,aAAa,CAAC;IAC7B,sBAAsB,EAAE,UAAU,CAAC;IACnC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7B,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;CAChC,WACO,OAAO;IAoDd,mEAAmE;kBAAxD,oBAAoB;;;;;;;;;;;;OAAgC;IAE/D,iEAAiE;iBAAtD,mBAAmB;;;;;OAA+B;GAKhE;sCArFY;IACR,4BAA4B,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,0BAA0B,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD;;kCAuFU,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI;gCAC3B,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI;;;eAK3B,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI;oBACrC,MAAM,UAAU;sCAChB,MAAM,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;;sCAG5C,QAAQ,OAAO,KAAK,CAAb,CAAe,aAAa,CAAC;;;;uCAErC,QAAQ,OAAO,KAAK,CAAb,CAAe,cAAc,CAAC;8BAIpC,WAAW,OAAO,KAAK,CAAC;kCAvHkC,aAAa;mCAAb,aAAa;6BAkB1D,kBAAkB;gCAlB2B,aAAa;6BAF3D,WAAW;gCACR,qCAAqC"}
|
|
@@ -10,6 +10,7 @@ import { prepareAssetReserveKit } from './assetReserveKit.js';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @import {EReturn} from '@endo/far';
|
|
13
|
+
* @import {ContractOf} from '@agoric/zoe/src/zoeService/utils.js';
|
|
13
14
|
* @import {Allocation, ContractMeta, FeeMintAccess, Installation} from '@agoric/zoe';
|
|
14
15
|
*/
|
|
15
16
|
|
|
@@ -128,3 +129,5 @@ harden(start);
|
|
|
128
129
|
* @typedef {EReturn<typeof start>['creatorFacet']} AssetReserveCreatorFacet
|
|
129
130
|
* the creator facet for the governor
|
|
130
131
|
*/
|
|
132
|
+
|
|
133
|
+
/** @typedef {ContractOf<typeof start>} ReserveContract */
|
|
@@ -21,6 +21,20 @@ export function prepareAssetReserveKit(baggage: import("@agoric/vat-data").Bagga
|
|
|
21
21
|
*/
|
|
22
22
|
burnFeesToReduceShortfall(reduction: Amount<"nat">): void;
|
|
23
23
|
};
|
|
24
|
+
withdrawalHandler: {
|
|
25
|
+
handle(seat: any): Promise<string>;
|
|
26
|
+
};
|
|
27
|
+
withdrawalFacet: {
|
|
28
|
+
Withdraw(): Promise<globalThis.Invitation<any, undefined>>;
|
|
29
|
+
};
|
|
30
|
+
repeatableWithdrawalHandler: {
|
|
31
|
+
/**
|
|
32
|
+
* @param {ZCFSeat} seat
|
|
33
|
+
*/
|
|
34
|
+
handle(seat: ZCFSeat): {
|
|
35
|
+
invitationMakers: Partial<any>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
24
38
|
machine: {
|
|
25
39
|
/**
|
|
26
40
|
* @param {Issuer} issuer
|
|
@@ -35,6 +49,11 @@ export function prepareAssetReserveKit(baggage: import("@agoric/vat-data").Bagga
|
|
|
35
49
|
/** @param {Amount<'nat'>} reduction */
|
|
36
50
|
reduceLiquidationShortfall(reduction: Amount<"nat">): void;
|
|
37
51
|
}>, undefined>>;
|
|
52
|
+
makeSingleWithdrawalInvitation(): Promise<globalThis.Invitation<any, undefined>>;
|
|
53
|
+
makeRepeatableWithdrawalInvitation(): Promise<globalThis.Invitation<{
|
|
54
|
+
invitationMakers: Partial<any>;
|
|
55
|
+
}, undefined>>;
|
|
56
|
+
revokeOutstandingWithdrawalInvitations(): void;
|
|
38
57
|
};
|
|
39
58
|
/**
|
|
40
59
|
* XXX missing governance public methods
|
|
@@ -72,5 +91,13 @@ export type MetricsNotification = {
|
|
|
72
91
|
};
|
|
73
92
|
export type AssetReserveKit = EReturn<EReturn<typeof prepareAssetReserveKit>>;
|
|
74
93
|
import type { ZCFMint } from '@agoric/zoe';
|
|
94
|
+
import type { StorageNode } from '@agoric/internal/src/lib-chainStorage.js';
|
|
95
|
+
import type { ZCF } from '@agoric/zoe';
|
|
96
|
+
import type { Brand } from '@agoric/ertp';
|
|
97
|
+
import type { Keyword } from '@agoric/zoe';
|
|
98
|
+
import type { Amount } from '@agoric/ertp';
|
|
99
|
+
import type { ZCFSeat } from '@agoric/zoe';
|
|
100
|
+
import type { Issuer } from '@agoric/ertp';
|
|
101
|
+
import type { AmountKeywordRecord } from '@agoric/zoe/src/zoeService/types.js';
|
|
75
102
|
import type { EReturn } from '@endo/far';
|
|
76
103
|
//# sourceMappingURL=assetReserveKit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetReserveKit.d.ts","sourceRoot":"","sources":["assetReserveKit.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assetReserveKit.d.ts","sourceRoot":"","sources":["assetReserveKit.js"],"names":[],"mappings":"AAiDO,gDARI,OAAO,kBAAkB,EAAE,OAAO,kDAClC;IACN,OAAO,EAAE,QAAQ,KAAK,CAAC,CAAC;IACxB,eAAe,EAAE,OAAO,6CAA6C,EAAE,eAAe,CAAC;IACvF,WAAW,EAAE,WAAW,CAAC;IACzB,GAAG,EAAE,GAAG,CAAC;CACV;;QA8GI,2BAA2B;kCAAf,KAAK;QAUjB;;;WAGG;gCAFQ,KAAK,WACL,OAAO;;;;QAqBlB;;;WAGG;6CAFQ,OAAO,KAAK,CAAC,GACX,IAAI;;;;;;;;;QAsDjB;;WAEG;qBADQ,OAAO;;;;;QAYlB;;;WAGG;0BAFQ,MAAM,WACN,MAAM;QAmBjB,8DAA8D;;;YA2E9D,uCAAuC;oDAA3B,OAAO,KAAK,CAAC;YAWzB,uCAAuC;kDAA3B,OAAO,KAAK,CAAC;;;;;;;;IArD3B;;;OAGG;;QAED,mDAAmD;;;;;;;QAqCnD,uCAAuC;gDAA3B,OAAO,KAAK,CAAC;QAWzB,uCAAuC;8CAA3B,OAAO,KAAK,CAAC;;KA8BhC;;iBA3Wa,mBAAmB;;;;;sBACnB,OAAO,KAAK,CAAC;;;;oBAEb,OAAO,KAAK,CAAC;;;;oBACb,OAAO,KAAK,CAAC;;8BAyWb,QAAQ,QAAQ,OAAO,sBAAsB,CAAC,CAAC;6BAlXE,aAAa;iCAJ9C,0CAA0C;yBAIT,aAAa;2BAHpC,cAAc;6BAGS,aAAa;4BAHpC,cAAc;6BAGS,aAAa;4BAHpC,cAAc;yCAEhB,qCAAqC;6BALjD,WAAW"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { Fail, q } from '@endo/errors';
|
|
2
3
|
import { AmountMath, AmountShape, IssuerShape } from '@agoric/ertp';
|
|
3
4
|
import { makeTracer } from '@agoric/internal';
|
|
@@ -7,17 +8,25 @@ import {
|
|
|
7
8
|
makeRecorderTopic,
|
|
8
9
|
TopicsRecordShape,
|
|
9
10
|
} from '@agoric/zoe/src/contractSupport/topics.js';
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
AmountKeywordRecordShape,
|
|
13
|
+
OfferHandlerI,
|
|
14
|
+
} from '@agoric/zoe/src/typeGuards.js';
|
|
11
15
|
import { E } from '@endo/eventual-send';
|
|
12
16
|
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
|
|
17
|
+
import { prepareRevocableMakerKit } from '@agoric/base-zone/zone-helpers.js';
|
|
18
|
+
import { makeDurableZone } from '@agoric/zone/durable.js';
|
|
13
19
|
|
|
14
20
|
const trace = makeTracer('ReserveKit', true);
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* @import {EReturn} from '@endo/far';
|
|
18
24
|
* @import {TypedPattern} from '@agoric/internal';
|
|
19
|
-
* @import {
|
|
20
|
-
* @import {
|
|
25
|
+
* @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
|
|
26
|
+
* @import {Amount, Brand, Issuer} from '@agoric/ertp';
|
|
27
|
+
* @import {MapStore, SetStore} from '@agoric/store';
|
|
28
|
+
* @import {AmountKeywordRecord} from '@agoric/zoe/src/zoeService/types.js';
|
|
29
|
+
* @import {ZCF, OfferHandler, Keyword, ZCFMint, ZCFSeat} from '@agoric/zoe';
|
|
21
30
|
*/
|
|
22
31
|
|
|
23
32
|
/**
|
|
@@ -46,6 +55,40 @@ export const prepareAssetReserveKit = async (
|
|
|
46
55
|
const feeKit = feeMint.getIssuerRecord();
|
|
47
56
|
const emptyAmount = AmountMath.makeEmpty(feeKit.brand);
|
|
48
57
|
|
|
58
|
+
const zone = makeDurableZone(baggage);
|
|
59
|
+
|
|
60
|
+
// Durable revocation bookkeeping for the revocable single and repeatable
|
|
61
|
+
// invitations.
|
|
62
|
+
/** @type {SetStore<{ revoke: () => boolean }>} */
|
|
63
|
+
const outstandingRevokers = zone.setStore('outstandingRevokers');
|
|
64
|
+
|
|
65
|
+
const { makeRevocableKit: makeRevocableWithdrawalFacet } =
|
|
66
|
+
prepareRevocableMakerKit(zone, 'WithdrawalFacet', ['Withdraw']);
|
|
67
|
+
|
|
68
|
+
const { makeRevocableKit: makeRevocableWithdrawalHandler } =
|
|
69
|
+
prepareRevocableMakerKit(zone, 'WithdrawalHandler', ['handle'], {
|
|
70
|
+
extraMethods: {
|
|
71
|
+
/**
|
|
72
|
+
* Add some additional cleanup to avoid proliferation of revokers for
|
|
73
|
+
* spent invitations.
|
|
74
|
+
*
|
|
75
|
+
* @param {ZCFSeat} seat
|
|
76
|
+
* @param {never} offerArgs
|
|
77
|
+
*/
|
|
78
|
+
handle(seat, offerArgs) {
|
|
79
|
+
const { revoker } = this.facets;
|
|
80
|
+
// We remove our outstanding revoker because we are consumed by Zoe
|
|
81
|
+
// and cannot be used again.
|
|
82
|
+
if (this.state.underlying === undefined) {
|
|
83
|
+
Fail`${q('WithdrawalHandler_caretaker')} revoked`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
outstandingRevokers.delete(revoker);
|
|
87
|
+
return this.state.underlying.handle(seat, offerArgs);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
49
92
|
const makeAssetReserveKitInternal = prepareExoClassKit(
|
|
50
93
|
baggage,
|
|
51
94
|
'AssetReserveKit',
|
|
@@ -54,10 +97,18 @@ export const prepareAssetReserveKit = async (
|
|
|
54
97
|
governedApis: M.interface('AssetReserve governedApis', {
|
|
55
98
|
burnFeesToReduceShortfall: M.call(AmountShape).returns(),
|
|
56
99
|
}),
|
|
100
|
+
withdrawalFacet: M.interface('AssetReserve withdrawalFacet', {
|
|
101
|
+
Withdraw: M.call().returns(M.promise()),
|
|
102
|
+
}),
|
|
103
|
+
withdrawalHandler: OfferHandlerI,
|
|
104
|
+
repeatableWithdrawalHandler: OfferHandlerI,
|
|
57
105
|
machine: M.interface('AssetReserve machine', {
|
|
58
106
|
addIssuer: M.call(IssuerShape, M.string()).returns(M.promise()),
|
|
59
107
|
getAllocations: M.call().returns(AmountKeywordRecordShape),
|
|
60
108
|
makeShortfallReportingInvitation: M.call().returns(M.promise()),
|
|
109
|
+
makeSingleWithdrawalInvitation: M.call().returns(M.promise()),
|
|
110
|
+
makeRepeatableWithdrawalInvitation: M.call().returns(M.promise()),
|
|
111
|
+
revokeOutstandingWithdrawalInvitations: M.call().returns(),
|
|
61
112
|
}),
|
|
62
113
|
public: M.interface('AssetReserve public', {
|
|
63
114
|
makeAddCollateralInvitation: M.call().returns(M.promise()),
|
|
@@ -166,6 +217,44 @@ export const prepareAssetReserveKit = async (
|
|
|
166
217
|
facets.helper.writeMetrics();
|
|
167
218
|
},
|
|
168
219
|
},
|
|
220
|
+
withdrawalHandler: {
|
|
221
|
+
async handle(seat) {
|
|
222
|
+
const { collateralSeat } = this.state;
|
|
223
|
+
const { helper } = this.facets;
|
|
224
|
+
const { want } = seat.getProposal();
|
|
225
|
+
|
|
226
|
+
// COMMIT POINT
|
|
227
|
+
// UNTIL #10684: ability to terminate an incarnation w/o terminating the contract
|
|
228
|
+
zcf.atomicRearrange(harden([[collateralSeat, seat, want]]));
|
|
229
|
+
|
|
230
|
+
helper.writeMetrics();
|
|
231
|
+
seat.exit();
|
|
232
|
+
|
|
233
|
+
trace('withdrew collateral', want);
|
|
234
|
+
return 'withdrew Collateral from the Reserve';
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
withdrawalFacet: {
|
|
238
|
+
Withdraw() {
|
|
239
|
+
const { revoker, revocable: handler } =
|
|
240
|
+
makeRevocableWithdrawalHandler(this.facets.withdrawalHandler);
|
|
241
|
+
outstandingRevokers.add(revoker);
|
|
242
|
+
// @ts-expect-error Argument of type Guarded<
|
|
243
|
+
return zcf.makeInvitation(handler, 'Withdraw Collateral');
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
repeatableWithdrawalHandler: {
|
|
247
|
+
/**
|
|
248
|
+
* @param {ZCFSeat} seat
|
|
249
|
+
*/
|
|
250
|
+
handle(seat) {
|
|
251
|
+
seat.exit();
|
|
252
|
+
const { revoker, revocable: invitationMakers } =
|
|
253
|
+
makeRevocableWithdrawalFacet(this.facets.withdrawalFacet);
|
|
254
|
+
outstandingRevokers.add(revoker);
|
|
255
|
+
return harden({ invitationMakers });
|
|
256
|
+
},
|
|
257
|
+
},
|
|
169
258
|
machine: {
|
|
170
259
|
// add makeRedeemLiquidityTokensInvitation later. For now just store them
|
|
171
260
|
/**
|
|
@@ -205,6 +294,22 @@ export const prepareAssetReserveKit = async (
|
|
|
205
294
|
'getFacetForReportingShortfalls',
|
|
206
295
|
);
|
|
207
296
|
},
|
|
297
|
+
|
|
298
|
+
makeSingleWithdrawalInvitation() {
|
|
299
|
+
return this.facets.withdrawalFacet.Withdraw();
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
makeRepeatableWithdrawalInvitation() {
|
|
303
|
+
const handler = this.facets.repeatableWithdrawalHandler;
|
|
304
|
+
return zcf.makeInvitation(handler, 'Repeatable Withdraw Collateral');
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
revokeOutstandingWithdrawalInvitations() {
|
|
308
|
+
for (const revoker of outstandingRevokers.keys()) {
|
|
309
|
+
revoker.revoke();
|
|
310
|
+
}
|
|
311
|
+
outstandingRevokers.clear();
|
|
312
|
+
},
|
|
208
313
|
},
|
|
209
314
|
/**
|
|
210
315
|
* XXX missing governance public methods
|