@agoric/smart-wallet 0.5.4-other-dev-8f8782b.0 → 0.5.4-other-dev-fbe72e7.0.fbe72e7
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 +43 -29
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +6 -0
- package/src/invitations.d.ts +14 -10
- package/src/invitations.d.ts.map +1 -1
- package/src/invitations.js +39 -33
- package/src/marshal-contexts.d.ts +45 -41
- package/src/marshal-contexts.d.ts.map +1 -1
- package/src/marshal-contexts.js +69 -61
- package/src/offerWatcher.d.ts +54 -0
- package/src/offerWatcher.d.ts.map +1 -0
- package/src/offerWatcher.js +343 -0
- package/src/offers.d.ts +60 -30
- package/src/offers.d.ts.map +1 -1
- package/src/offers.js +38 -182
- package/src/proposals/upgrade-wallet-factory2-proposal.js +61 -0
- package/src/proposals/upgrade-walletFactory-proposal.js +46 -23
- package/src/smartWallet.d.ts +132 -68
- package/src/smartWallet.d.ts.map +1 -1
- package/src/smartWallet.js +718 -217
- package/src/typeGuards.d.ts +1 -1
- package/src/typeGuards.js +29 -1
- package/src/types-index.d.ts +2 -0
- package/src/types-index.js +2 -0
- package/src/types.d.ts +36 -41
- package/src/types.d.ts.map +1 -0
- package/src/types.ts +90 -0
- package/src/utils.d.ts +17 -14
- package/src/utils.d.ts.map +1 -1
- package/src/utils.js +19 -6
- package/src/walletFactory.d.ts +24 -78
- package/src/walletFactory.d.ts.map +1 -1
- package/src/walletFactory.js +64 -37
- package/CHANGELOG.md +0 -180
- package/src/payments.d.ts +0 -20
- package/src/payments.d.ts.map +0 -1
- package/src/payments.js +0 -89
- package/src/proposals/upgrade-walletFactory-proposal.d.ts +0 -17
- package/src/proposals/upgrade-walletFactory-proposal.d.ts.map +0 -1
package/src/offers.js
CHANGED
|
@@ -1,198 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/**
|
|
2
|
+
* @import {Proposal} from '@agoric/zoe';
|
|
3
|
+
* @import {Passable} from '@endo/pass-style';
|
|
4
|
+
*/
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {number | string} OfferId
|
|
7
8
|
*/
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {object} ResultPlan
|
|
12
|
+
* @property {string} name by which to save the item
|
|
13
|
+
* @property {boolean} [overwrite=false] whether to overwrite an existing item.
|
|
14
|
+
* If false and there is a conflict, the contract will autogen a similar
|
|
15
|
+
* name.
|
|
16
|
+
*/
|
|
17
|
+
|
|
9
18
|
/**
|
|
10
19
|
* @typedef {{
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
20
|
+
* targetName: string;
|
|
21
|
+
* method: string;
|
|
22
|
+
* args: Passable[];
|
|
23
|
+
* saveResult?: ResultPlan;
|
|
24
|
+
* id?: number | string;
|
|
25
|
+
* }} InvokeEntryMessage
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {{
|
|
30
|
+
* id: OfferId;
|
|
31
|
+
* invitationSpec: import('./invitations.js').InvitationSpec;
|
|
32
|
+
* proposal: Proposal;
|
|
33
|
+
* offerArgs?: any;
|
|
34
|
+
* saveResult?: ResultPlan;
|
|
15
35
|
* }} OfferSpec
|
|
36
|
+
* If `saveResult` is provided, the result of the invocation will be saved to
|
|
37
|
+
* the specified location. Otherwise it will be published directly to vstorage
|
|
38
|
+
* (or 'UNPUBLISHED' if it cannot be).
|
|
16
39
|
*/
|
|
17
40
|
|
|
18
41
|
/** Value for "result" field when the result can't be published */
|
|
19
42
|
export const UNPUBLISHED_RESULT = 'UNPUBLISHED';
|
|
20
43
|
|
|
21
44
|
/**
|
|
22
|
-
* @typedef {
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
45
|
+
* @typedef {OfferSpec & {
|
|
46
|
+
* error?: string;
|
|
47
|
+
* numWantsSatisfied?: number;
|
|
48
|
+
* result?:
|
|
49
|
+
* | unknown
|
|
50
|
+
* | typeof UNPUBLISHED_RESULT
|
|
51
|
+
* | { name: string; passStyle: string };
|
|
52
|
+
* payouts?: AmountKeywordRecord;
|
|
27
53
|
* }} OfferStatus
|
|
28
54
|
*/
|
|
29
|
-
|
|
30
|
-
/* eslint-disable jsdoc/check-param-names -- bug(?) with nested objects */
|
|
31
|
-
/**
|
|
32
|
-
* @param {object} opts
|
|
33
|
-
* @param {ERef<ZoeService>} opts.zoe
|
|
34
|
-
* @param {{ receive: (payment: *) => Promise<Amount> }} opts.depositFacet
|
|
35
|
-
* @param {ERef<Issuer<'set'>>} opts.invitationIssuer
|
|
36
|
-
* @param {object} opts.powers
|
|
37
|
-
* @param {Pick<Console, 'info'| 'error'>} opts.powers.logger
|
|
38
|
-
* @param {(spec: import('./invitations').InvitationSpec) => ERef<Invitation>} opts.powers.invitationFromSpec
|
|
39
|
-
* @param {(brand: Brand) => Promise<import('./types').RemotePurse>} opts.powers.purseForBrand
|
|
40
|
-
* @param {(status: OfferStatus) => void} opts.onStatusChange
|
|
41
|
-
* @param {(offerId: string, invitationAmount: Amount<'set'>, invitationMakers: import('./types').RemoteInvitationMakers, publicSubscribers: import('./types').PublicSubscribers | import('@agoric/zoe/src/contractSupport').TopicsRecord ) => Promise<void>} opts.onNewContinuingOffer
|
|
42
|
-
*/
|
|
43
|
-
export const makeOfferExecutor = ({
|
|
44
|
-
zoe,
|
|
45
|
-
depositFacet,
|
|
46
|
-
invitationIssuer,
|
|
47
|
-
powers,
|
|
48
|
-
onStatusChange,
|
|
49
|
-
onNewContinuingOffer,
|
|
50
|
-
}) => {
|
|
51
|
-
const { invitationFromSpec, logger, purseForBrand } = powers;
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
/**
|
|
55
|
-
* Take an offer description provided in capData, augment it with payments and call zoe.offer()
|
|
56
|
-
*
|
|
57
|
-
* @param {OfferSpec} offerSpec
|
|
58
|
-
* @param {(seatRef: UserSeat) => void} onSeatCreated
|
|
59
|
-
* @returns {Promise<void>} when the offer has been sent to Zoe; payouts go into this wallet's purses
|
|
60
|
-
* @throws if any parts of the offer are determined to be invalid before calling Zoe's `offer()`
|
|
61
|
-
*/
|
|
62
|
-
async executeOffer(offerSpec, onSeatCreated) {
|
|
63
|
-
logger.info('starting executeOffer', offerSpec.id);
|
|
64
|
-
|
|
65
|
-
const paymentsManager = makePaymentsHelper(purseForBrand, depositFacet);
|
|
66
|
-
|
|
67
|
-
/** @type {OfferStatus} */
|
|
68
|
-
let status = {
|
|
69
|
-
...offerSpec,
|
|
70
|
-
};
|
|
71
|
-
/** @param {Partial<OfferStatus>} changes */
|
|
72
|
-
const updateStatus = changes => {
|
|
73
|
-
status = { ...status, ...changes };
|
|
74
|
-
onStatusChange(status);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** @type {UserSeat} */
|
|
78
|
-
let seatRef;
|
|
79
|
-
|
|
80
|
-
const tryBody = async () => {
|
|
81
|
-
// 1. Prepare values and validate synchronously.
|
|
82
|
-
const { id, invitationSpec, proposal, offerArgs } = offerSpec;
|
|
83
|
-
|
|
84
|
-
/** @type {PaymentKeywordRecord | undefined} */
|
|
85
|
-
const paymentKeywordRecord = await (proposal?.give &&
|
|
86
|
-
deeplyFulfilledObject(paymentsManager.withdrawGive(proposal.give)));
|
|
87
|
-
|
|
88
|
-
const invitation = invitationFromSpec(invitationSpec);
|
|
89
|
-
const invitationAmount = await E(invitationIssuer).getAmountOf(
|
|
90
|
-
invitation,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
// 2. Begin executing offer
|
|
94
|
-
// No explicit signal to user that we reached here but if anything above
|
|
95
|
-
// failed they'd get an 'error' status update.
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line @jessie.js/no-nested-await -- unconditional
|
|
98
|
-
seatRef = await E(zoe).offer(
|
|
99
|
-
invitation,
|
|
100
|
-
proposal,
|
|
101
|
-
paymentKeywordRecord,
|
|
102
|
-
offerArgs,
|
|
103
|
-
);
|
|
104
|
-
logger.info(id, 'seated');
|
|
105
|
-
onSeatCreated(seatRef);
|
|
106
|
-
|
|
107
|
-
const publishResult = E.when(E(seatRef).getOfferResult(), result => {
|
|
108
|
-
const passStyle = passStyleOf(result);
|
|
109
|
-
logger.info(id, 'offerResult', passStyle, result);
|
|
110
|
-
// someday can we get TS to type narrow based on the passStyleOf result match?
|
|
111
|
-
switch (passStyle) {
|
|
112
|
-
case 'bigint':
|
|
113
|
-
case 'boolean':
|
|
114
|
-
case 'null':
|
|
115
|
-
case 'number':
|
|
116
|
-
case 'string':
|
|
117
|
-
case 'symbol':
|
|
118
|
-
case 'undefined':
|
|
119
|
-
updateStatus({ result });
|
|
120
|
-
break;
|
|
121
|
-
case 'copyRecord':
|
|
122
|
-
// @ts-expect-error result narrowed by passStyle
|
|
123
|
-
if ('invitationMakers' in result) {
|
|
124
|
-
// save for continuing invitation offer
|
|
125
|
-
void onNewContinuingOffer(
|
|
126
|
-
String(id),
|
|
127
|
-
invitationAmount,
|
|
128
|
-
// @ts-expect-error result narrowed by passStyle
|
|
129
|
-
result.invitationMakers,
|
|
130
|
-
// @ts-expect-error result narrowed by passStyle
|
|
131
|
-
result.publicSubscribers,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
// copyRecord is valid to publish but not safe as it may have private info
|
|
135
|
-
updateStatus({ result: UNPUBLISHED_RESULT });
|
|
136
|
-
break;
|
|
137
|
-
default:
|
|
138
|
-
// drop the result
|
|
139
|
-
updateStatus({ result: UNPUBLISHED_RESULT });
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
const publishWantsSatisfied = E.when(
|
|
144
|
-
E(seatRef).numWantsSatisfied(),
|
|
145
|
-
numSatisfied => {
|
|
146
|
-
logger.info(id, 'numSatisfied', numSatisfied);
|
|
147
|
-
if (numSatisfied === 0) {
|
|
148
|
-
updateStatus({ numWantsSatisfied: 0 });
|
|
149
|
-
}
|
|
150
|
-
updateStatus({
|
|
151
|
-
numWantsSatisfied: numSatisfied,
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
// This will block until all payouts succeed, but user will be updated
|
|
157
|
-
// as each payout will trigger its corresponding purse notifier.
|
|
158
|
-
const publishPayouts = E.when(E(seatRef).getPayouts(), payouts =>
|
|
159
|
-
paymentsManager.depositPayouts(payouts).then(amountsOrDeferred => {
|
|
160
|
-
updateStatus({ payouts: amountsOrDeferred });
|
|
161
|
-
}),
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// The offer is complete when these promises are resolved.
|
|
165
|
-
// If any reject then executeOffer rejects and that must be handled.
|
|
166
|
-
return Promise.all([
|
|
167
|
-
publishResult,
|
|
168
|
-
publishWantsSatisfied,
|
|
169
|
-
publishPayouts,
|
|
170
|
-
]);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
await tryBody().catch(err => {
|
|
174
|
-
logger.error('OFFER ERROR:', err);
|
|
175
|
-
// Notify the user
|
|
176
|
-
updateStatus({ error: err.toString() });
|
|
177
|
-
// Attempt to recover payments
|
|
178
|
-
void paymentsManager.tryReclaimingWithdrawnPayments().then(result => {
|
|
179
|
-
if (result) {
|
|
180
|
-
updateStatus({ result });
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
if (seatRef) {
|
|
184
|
-
void E(seatRef)
|
|
185
|
-
.hasExited()
|
|
186
|
-
.then(hasExited => {
|
|
187
|
-
if (!hasExited) {
|
|
188
|
-
void E(seatRef).tryExit();
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
// propagate to caller
|
|
193
|
-
throw err;
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
harden(makeOfferExecutor);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/// <reference types="@agoric/vats/src/core/types-ambient" />
|
|
3
|
+
|
|
4
|
+
import { E } from '@endo/far';
|
|
5
|
+
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {BootstrapPowers & ChainBootstrapSpace} powers
|
|
9
|
+
* @param {object} options
|
|
10
|
+
* @param {{ walletRef: VatSourceRef }} options.options
|
|
11
|
+
*/
|
|
12
|
+
export const upgradeWalletFactory = async (
|
|
13
|
+
{
|
|
14
|
+
consume: {
|
|
15
|
+
walletFactoryStartResult,
|
|
16
|
+
provisionPoolStartResult,
|
|
17
|
+
chainStorage,
|
|
18
|
+
walletBridgeManager: walletBridgeManagerP,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
options,
|
|
22
|
+
) => {
|
|
23
|
+
const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
|
|
24
|
+
|
|
25
|
+
const { walletRef } = options.options;
|
|
26
|
+
|
|
27
|
+
const [walletBridgeManager, walletStorageNode, ppFacets] = await Promise.all([
|
|
28
|
+
walletBridgeManagerP,
|
|
29
|
+
makeStorageNodeChild(chainStorage, WALLET_STORAGE_PATH_SEGMENT),
|
|
30
|
+
provisionPoolStartResult,
|
|
31
|
+
]);
|
|
32
|
+
const walletReviver = await E(ppFacets.creatorFacet).getWalletReviver();
|
|
33
|
+
|
|
34
|
+
const privateArgs = {
|
|
35
|
+
storageNode: walletStorageNode,
|
|
36
|
+
walletBridgeManager,
|
|
37
|
+
walletReviver,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const { adminFacet } = await walletFactoryStartResult;
|
|
41
|
+
|
|
42
|
+
assert(walletRef.bundleID);
|
|
43
|
+
await E(adminFacet).upgradeContract(walletRef.bundleID, privateArgs);
|
|
44
|
+
|
|
45
|
+
console.log(`Successfully upgraded WalletFactory`);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const getManifestForUpgradeWallet = ({ restoreRef }, { walletRef }) => ({
|
|
49
|
+
manifest: {
|
|
50
|
+
[upgradeWalletFactory.name]: {
|
|
51
|
+
consume: {
|
|
52
|
+
walletFactoryStartResult: 'walletFactoryStartResult',
|
|
53
|
+
provisionPoolStartResult: 'provisionPoolStartResult',
|
|
54
|
+
chainStorage: 'chainStorage',
|
|
55
|
+
walletBridgeManager: 'walletBridgeManager',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
installations: { walletFactory: restoreRef(walletRef) },
|
|
60
|
+
options: { walletRef },
|
|
61
|
+
});
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import { Fail } from '@endo/errors';
|
|
2
3
|
import { E } from '@endo/far';
|
|
3
4
|
import { makeMarshal } from '@endo/marshal';
|
|
4
5
|
import { allValues } from '@agoric/internal';
|
|
5
6
|
|
|
6
7
|
console.warn('upgrade-walletFactory-proposal.js module evaluating');
|
|
7
8
|
|
|
8
|
-
const { Fail } = assert;
|
|
9
|
-
|
|
10
9
|
// vstorage paths under published.*
|
|
10
|
+
const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
|
|
11
11
|
const BOARD_AUX = 'boardAux';
|
|
12
12
|
|
|
13
13
|
const marshalData = makeMarshal(_val => Fail`data only`);
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {
|
|
17
|
-
*
|
|
16
|
+
* @param {BootstrapPowers} powers
|
|
18
17
|
* @param {object} config
|
|
19
18
|
* @param {{ walletFactoryRef: VatSourceRef & { bundleID: string } }} config.options
|
|
20
19
|
*/
|
|
21
20
|
export const upgradeWalletFactory = async (
|
|
22
21
|
{
|
|
23
|
-
consume: {
|
|
22
|
+
consume: {
|
|
23
|
+
contractKits,
|
|
24
|
+
governedContractKits,
|
|
25
|
+
chainStorage,
|
|
26
|
+
walletBridgeManager: walletBridgeManagerP,
|
|
27
|
+
},
|
|
24
28
|
instance: {
|
|
25
|
-
consume: { walletFactory: wfInstanceP },
|
|
29
|
+
consume: { walletFactory: wfInstanceP, provisionPool: ppInstanceP },
|
|
26
30
|
},
|
|
27
31
|
},
|
|
28
32
|
config,
|
|
@@ -30,26 +34,42 @@ export const upgradeWalletFactory = async (
|
|
|
30
34
|
console.log('upgradeWalletFactory: config', config);
|
|
31
35
|
const { walletFactoryRef } = config.options;
|
|
32
36
|
|
|
33
|
-
console.log('upgradeWalletFactory: awaiting
|
|
34
|
-
const wfInstance
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// console.log('upgradeWalletFactory: awaiting instances etc.');
|
|
38
|
+
const { wfInstance, ppInstance, walletBridgeManager, storageNode } =
|
|
39
|
+
await allValues({
|
|
40
|
+
wfInstance: wfInstanceP,
|
|
41
|
+
ppInstance: ppInstanceP,
|
|
42
|
+
walletBridgeManager: walletBridgeManagerP,
|
|
43
|
+
// @ts-expect-error chainStorage is only falsy in testing
|
|
44
|
+
storageNode: E(chainStorage).makeChildNode(WALLET_STORAGE_PATH_SEGMENT),
|
|
45
|
+
});
|
|
46
|
+
// console.log('upgradeWalletFactory: awaiting contract kits');
|
|
47
|
+
const { wfKit, ppKit } = await allValues({
|
|
48
|
+
wfKit: E(contractKits).get(wfInstance),
|
|
49
|
+
ppKit: E(governedContractKits).get(ppInstance),
|
|
39
50
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
// console.log('upgradeWalletFactory: awaiting walletReviver');
|
|
52
|
+
const walletReviver = await E(ppKit.creatorFacet).getWalletReviver();
|
|
53
|
+
const newPrivateArgs = harden({
|
|
54
|
+
storageNode,
|
|
55
|
+
walletBridgeManager,
|
|
56
|
+
walletReviver,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(
|
|
60
|
+
'upgradeWalletFactory: upgrading with newPrivateArgs',
|
|
61
|
+
newPrivateArgs,
|
|
62
|
+
);
|
|
63
|
+
await E(wfKit.adminFacet).upgradeContract(
|
|
64
|
+
walletFactoryRef.bundleID,
|
|
65
|
+
newPrivateArgs,
|
|
66
|
+
);
|
|
47
67
|
console.log('upgradeWalletFactory: done');
|
|
48
68
|
};
|
|
49
69
|
harden(upgradeWalletFactory);
|
|
50
70
|
|
|
51
71
|
/**
|
|
52
|
-
* @param {
|
|
72
|
+
* @param {BootstrapPowers} powers
|
|
53
73
|
*/
|
|
54
74
|
export const publishAgoricBrandsDisplayInfo = async ({
|
|
55
75
|
consume: { agoricNames, board, chainStorage },
|
|
@@ -68,7 +88,7 @@ export const publishAgoricBrandsDisplayInfo = async ({
|
|
|
68
88
|
await E(node).setValue(JSON.stringify(aux));
|
|
69
89
|
};
|
|
70
90
|
|
|
71
|
-
/** @type {ERef<NameHub>} */
|
|
91
|
+
/** @type {ERef<import('@agoric/vats').NameHub>} */
|
|
72
92
|
const brandHub = E(agoricNames).lookup('brand');
|
|
73
93
|
const brands = await E(brandHub).values();
|
|
74
94
|
// tolerate failure; in particular, for the timer brand
|
|
@@ -76,13 +96,16 @@ export const publishAgoricBrandsDisplayInfo = async ({
|
|
|
76
96
|
};
|
|
77
97
|
harden(publishAgoricBrandsDisplayInfo);
|
|
78
98
|
|
|
79
|
-
/** @type {
|
|
99
|
+
/** @type {import('@agoric/vats/src/core/lib-boot').BootstrapManifest} */
|
|
80
100
|
const manifest = {
|
|
81
101
|
[upgradeWalletFactory.name]: {
|
|
82
102
|
// include rationale for closely-held, high authority capabilities
|
|
83
103
|
consume: {
|
|
84
104
|
contractKits: `to upgrade walletFactory using its adminFacet`,
|
|
85
|
-
|
|
105
|
+
governedContractKits:
|
|
106
|
+
'to get walletReviver from provisionPool.creatorFacet',
|
|
107
|
+
chainStorage: 'to allow walletFactory to (continue) write to vstorage',
|
|
108
|
+
walletBridgeManager: 'to handle bridged cosmos SpendAction messages',
|
|
86
109
|
},
|
|
87
110
|
// widely-shared, low authority instance handles need no rationale
|
|
88
111
|
instance: {
|