@agoric/orchestration 0.1.1-dev-9cdb01d.0 → 0.1.1-dev-3e9ff43.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 +16 -16
- package/src/examples/send-anywhere.contract.js +1 -1
- package/src/examples/send-anywhere.flows.d.ts +3 -3
- package/src/examples/send-anywhere.flows.d.ts.map +1 -1
- package/src/examples/send-anywhere.flows.js +20 -11
- package/src/examples/staking-combinations.flows.d.ts.map +1 -1
- package/src/examples/staking-combinations.flows.js +5 -4
- package/src/utils/start-helper.d.ts +11 -2
- package/src/utils/start-helper.d.ts.map +1 -1
- package/src/utils/start-helper.js +1 -3
- package/src/utils/zoe-tools.d.ts +5 -8
- package/src/utils/zoe-tools.d.ts.map +1 -1
- package/src/utils/zoe-tools.js +135 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/orchestration",
|
|
3
|
-
"version": "0.1.1-dev-
|
|
3
|
+
"version": "0.1.1-dev-3e9ff43.0+3e9ff43",
|
|
4
4
|
"description": "Chain abstraction for Agoric's orchestration clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@agoric/async-flow": "0.1.1-dev-
|
|
37
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
38
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
39
|
-
"@agoric/internal": "0.3.3-dev-
|
|
40
|
-
"@agoric/network": "0.1.1-dev-
|
|
41
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
42
|
-
"@agoric/store": "0.9.3-dev-
|
|
43
|
-
"@agoric/time": "0.3.3-dev-
|
|
44
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
45
|
-
"@agoric/vats": "0.15.2-dev-
|
|
46
|
-
"@agoric/vow": "0.1.1-dev-
|
|
47
|
-
"@agoric/zoe": "0.26.3-dev-
|
|
48
|
-
"@agoric/zone": "0.2.3-dev-
|
|
36
|
+
"@agoric/async-flow": "0.1.1-dev-3e9ff43.0+3e9ff43",
|
|
37
|
+
"@agoric/cosmic-proto": "0.4.1-dev-3e9ff43.0+3e9ff43",
|
|
38
|
+
"@agoric/ertp": "0.16.3-dev-3e9ff43.0+3e9ff43",
|
|
39
|
+
"@agoric/internal": "0.3.3-dev-3e9ff43.0+3e9ff43",
|
|
40
|
+
"@agoric/network": "0.1.1-dev-3e9ff43.0+3e9ff43",
|
|
41
|
+
"@agoric/notifier": "0.6.3-dev-3e9ff43.0+3e9ff43",
|
|
42
|
+
"@agoric/store": "0.9.3-dev-3e9ff43.0+3e9ff43",
|
|
43
|
+
"@agoric/time": "0.3.3-dev-3e9ff43.0+3e9ff43",
|
|
44
|
+
"@agoric/vat-data": "0.5.3-dev-3e9ff43.0+3e9ff43",
|
|
45
|
+
"@agoric/vats": "0.15.2-dev-3e9ff43.0+3e9ff43",
|
|
46
|
+
"@agoric/vow": "0.1.1-dev-3e9ff43.0+3e9ff43",
|
|
47
|
+
"@agoric/zoe": "0.26.3-dev-3e9ff43.0+3e9ff43",
|
|
48
|
+
"@agoric/zone": "0.2.3-dev-3e9ff43.0+3e9ff43",
|
|
49
49
|
"@endo/base64": "^1.0.7",
|
|
50
50
|
"@endo/errors": "^1.2.5",
|
|
51
51
|
"@endo/far": "^1.1.5",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@noble/hashes": "^1.5.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
57
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-3e9ff43.0+3e9ff43",
|
|
58
58
|
"@chain-registry/client": "^1.47.4",
|
|
59
59
|
"@cosmjs/amino": "^0.32.3",
|
|
60
60
|
"@cosmjs/proto-signing": "^0.32.3",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"typeCoverage": {
|
|
95
95
|
"atLeast": 97.6
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "3e9ff4365c55c19a4b40d2d2741ac791fa287851"
|
|
98
98
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export function sendIt(orch: Orchestrator, { contractState, localTransfer }: {
|
|
1
|
+
export function sendIt(orch: Orchestrator, { contractState, zoeTools: { localTransfer, withdrawToSeat } }: {
|
|
2
2
|
contractState: {
|
|
3
3
|
localAccount?: OrchestrationAccountI & LocalAccountMethods;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
zoeTools: GuestInterface<ZoeTools>;
|
|
6
6
|
}, seat: ZCFSeat, offerArgs: {
|
|
7
7
|
chainName: string;
|
|
8
8
|
destAddr: string;
|
|
@@ -11,5 +11,5 @@ import type { Orchestrator } from '../types.js';
|
|
|
11
11
|
import type { OrchestrationAccountI } from '../types.js';
|
|
12
12
|
import type { LocalAccountMethods } from '../types.js';
|
|
13
13
|
import type { ZoeTools } from '../utils/zoe-tools.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type { GuestInterface } from '@agoric/async-flow';
|
|
15
15
|
//# sourceMappingURL=send-anywhere.flows.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-anywhere.flows.d.ts","sourceRoot":"","sources":["send-anywhere.flows.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"send-anywhere.flows.d.ts","sourceRoot":"","sources":["send-anywhere.flows.js"],"names":[],"mappings":"AAwBO,6BAPI,YAAY,kEAEpB;IAA4E,aAAa,EAAjF;QAAE,YAAY,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAA;KAAE;IAChC,QAAQ,EAAtC,eAAe,QAAQ,CAAC;CAChC,QAAQ,OAAO,aACP;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,iBAiDjD;kCAhE6F,aAAa;2CAAb,aAAa;yCAAb,aAAa;8BADhF,uBAAuB;oCADjB,oBAAoB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { NonNullish } from '@agoric/internal';
|
|
2
|
+
import { makeError, q } from '@endo/errors';
|
|
2
3
|
import { M, mustMatch } from '@endo/patterns';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* @import {
|
|
6
|
+
* @import {GuestInterface} from '@agoric/async-flow';
|
|
6
7
|
* @import {ZoeTools} from '../utils/zoe-tools.js';
|
|
7
8
|
* @import {Orchestrator, LocalAccountMethods, OrchestrationAccountI, OrchestrationFlow} from '../types.js';
|
|
8
9
|
*/
|
|
@@ -17,13 +18,13 @@ const { entries } = Object;
|
|
|
17
18
|
* @param {Orchestrator} orch
|
|
18
19
|
* @param {object} ctx
|
|
19
20
|
* @param {{ localAccount?: OrchestrationAccountI & LocalAccountMethods }} ctx.contractState
|
|
20
|
-
* @param {
|
|
21
|
+
* @param {GuestInterface<ZoeTools>} ctx.zoeTools
|
|
21
22
|
* @param {ZCFSeat} seat
|
|
22
23
|
* @param {{ chainName: string; destAddr: string }} offerArgs
|
|
23
24
|
*/
|
|
24
25
|
export const sendIt = async (
|
|
25
26
|
orch,
|
|
26
|
-
{ contractState, localTransfer },
|
|
27
|
+
{ contractState, zoeTools: { localTransfer, withdrawToSeat } },
|
|
27
28
|
seat,
|
|
28
29
|
offerArgs,
|
|
29
30
|
) => {
|
|
@@ -51,14 +52,22 @@ export const sendIt = async (
|
|
|
51
52
|
|
|
52
53
|
await localTransfer(seat, contractState.localAccount, give);
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
try {
|
|
56
|
+
await contractState.localAccount.transfer(
|
|
57
|
+
{ denom, value: amt.value },
|
|
58
|
+
{
|
|
59
|
+
value: destAddr,
|
|
60
|
+
encoding: 'bech32',
|
|
61
|
+
chainId,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
await withdrawToSeat(contractState.localAccount, seat, give);
|
|
66
|
+
const errorMsg = `IBC Transfer failed ${q(e)}`;
|
|
67
|
+
seat.exit(errorMsg);
|
|
68
|
+
throw makeError(errorMsg);
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
seat.exit();
|
|
63
72
|
};
|
|
64
73
|
harden(sendIt);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking-combinations.flows.d.ts","sourceRoot":"","sources":["staking-combinations.flows.js"],"names":[],"mappings":"AA2BO,kCATI,YAAY,OACZ;IACN,2BAA2B,EAAE,2BAA2B,CAAC;IACzD,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,gBAAgB,CAAC;CAC9D,SACO,OAAO,iBACP;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnB,OAAO,CAAC,qBAAqB,CAAC,CAkB1C;AAcM,yCATI,YAAY,+BAEpB;IAA4E,aAAa,EAAjF;QAAE,YAAY,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAA;KAAE;IAChC,QAAQ,EAAtC,eAAe,QAAQ,CAAC;CAChC,WAAQ,eAAe,0BAA0B,CAAC,QAC1C,OAAO,aACP,sBAAsB,GACpB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"staking-combinations.flows.d.ts","sourceRoot":"","sources":["staking-combinations.flows.js"],"names":[],"mappings":"AA2BO,kCATI,YAAY,OACZ;IACN,2BAA2B,EAAE,2BAA2B,CAAC;IACzD,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,gBAAgB,CAAC;CAC9D,SACO,OAAO,iBACP;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnB,OAAO,CAAC,qBAAqB,CAAC,CAkB1C;AAcM,yCATI,YAAY,+BAEpB;IAA4E,aAAa,EAAjF;QAAE,YAAY,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAA;KAAE;IAChC,QAAQ,EAAtC,eAAe,QAAQ,CAAC;CAChC,WAAQ,eAAe,0BAA0B,CAAC,QAC1C,OAAO,aACP,sBAAsB,GACpB,OAAO,CAAC,IAAI,CAAC,CA8BzB;AAcM,4CATI,YAAY,OACZ,MAAM,WACN,eAAe,0BAA0B,CAAC,gCAC1C;IACN,WAAW,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,SAAS,EAAE,sBAAsB,CAAA;KAAE,EAAE,CAAC;IACxE,WAAW,EAAE,YAAY,CAAC;CAC3B,GACS,OAAO,CAAC,IAAI,CAAC,CAYzB;kCA3G8I,aAAa;iDAE9G,sCAAsC;sCAD1B,mCAAmC;2CAAnC,mCAAmC;2CADkD,aAAa;yCAAb,aAAa;8BAIjI,uBAAuB;oCALjB,oBAAoB;gDAIR,yCAAyC;4CAHyD,aAAa;+BAAb,aAAa;kCAAb,aAAa"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { mustMatch } from '@endo/patterns';
|
|
11
|
-
import { makeError } from '@endo/errors';
|
|
11
|
+
import { makeError, q } from '@endo/errors';
|
|
12
12
|
import { makeTracer } from '@agoric/internal';
|
|
13
13
|
import { ChainAddressShape } from '../typeGuards.js';
|
|
14
14
|
|
|
@@ -76,9 +76,10 @@ export const depositAndDelegate = async (
|
|
|
76
76
|
try {
|
|
77
77
|
await contractState.localAccount.transfer(give.Stake, address);
|
|
78
78
|
} catch (cause) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
await zoeTools.withdrawToSeat(contractState.localAccount, seat, give);
|
|
80
|
+
const errMsg = makeError(`ibc transfer failed ${q(cause)}`);
|
|
81
|
+
seat.exit(errMsg);
|
|
82
|
+
throw errMsg;
|
|
82
83
|
}
|
|
83
84
|
seat.exit();
|
|
84
85
|
await account.delegate(validator, give.Stake);
|
|
@@ -23,7 +23,15 @@ export function provideOrchestration(zcf: ZCF, baggage: Baggage, remotePowers: O
|
|
|
23
23
|
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
24
24
|
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
|
|
25
25
|
makeVowKit: <T>() => import("@agoric/vow").VowKit<T>;
|
|
26
|
-
|
|
26
|
+
all: (maybeVows: unknown[]) => import("@agoric/vow").Vow<any[]>;
|
|
27
|
+
allVows: (maybeVows: unknown[]) => import("@agoric/vow").Vow<any[]>;
|
|
28
|
+
allSettled: (maybeVows: unknown[]) => import("@agoric/vow").Vow<({
|
|
29
|
+
status: "fulfilled";
|
|
30
|
+
value: any;
|
|
31
|
+
} | {
|
|
32
|
+
status: "rejected";
|
|
33
|
+
reason: any;
|
|
34
|
+
})[]>;
|
|
27
35
|
asVow: <T extends unknown>(fn: (...args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | import("@agoric/vow").PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
|
|
28
36
|
asPromise: import("@agoric/vow").AsPromiseFunction;
|
|
29
37
|
retriable: <F extends (...args: any[]) => Promise<any>>(fnZone: Zone, name: string, fn: F) => F extends (...args: infer Args) => Promise<infer R> ? (...args: Args) => import("@agoric/vow").Vow<R> : never;
|
|
@@ -62,7 +70,8 @@ export function provideOrchestration(zcf: ZCF, baggage: Baggage, remotePowers: O
|
|
|
62
70
|
prepareEndowment: (zone: Zone, tag: string, e: unknown) => any;
|
|
63
71
|
};
|
|
64
72
|
zoeTools: {
|
|
65
|
-
localTransfer: (srcSeat: ZCFSeat, localAccount: import("../cosmos-api.js").LocalAccountMethods,
|
|
73
|
+
localTransfer: (srcSeat: ZCFSeat, localAccount: import("../cosmos-api.js").LocalAccountMethods, amounts: AmountKeywordRecord) => import("@agoric/vow").Vow<void>;
|
|
74
|
+
withdrawToSeat: (localAccount: import("../cosmos-api.js").LocalAccountMethods, destSeat: ZCFSeat, amounts: AmountKeywordRecord) => import("@agoric/vow").Vow<void>;
|
|
66
75
|
};
|
|
67
76
|
zone: Zone;
|
|
68
77
|
orchestrate: <HC, GF extends import("../orchestration-api.js").OrchestrationFlow<import("@agoric/async-flow").GuestInterface<HC>>>(durableName: string, hostCtx: HC, guestFn: GF) => HostForGuest<GF>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-helper.d.ts","sourceRoot":"","sources":["start-helper.js"],"names":[],"mappings":"AA6CO,0CANI,GAAG,WACH,OAAO,gBACP,mBAAmB,cACnB,UAAU;+
|
|
1
|
+
{"version":3,"file":"start-helper.d.ts","sourceRoot":"","sources":["start-helper.js"],"names":[],"mappings":"AA6CO,0CANI,GAAG,WACH,OAAO,gBACP,mBAAmB,cACnB,UAAU;+BAmGR,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAjEM,GAAG;;+BAhDV,GAAG,+EAMoD,GAAG,yCAG9D,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkId;AA8BM,kCAdgC,EAAE,SAA3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAE,EAGhC,EAAE,SAFM,mBAAmB,GAAG;IAC/B,UAAU,EAAE,UAAU,CAAC;CACvB,EACQ,CAAC,cACH,CACN,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EACZ,WAAW,EAAE,EAAE,EACf,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,kBAAkB,KACtB,OAAO,CAAC,CAAC,CAAC,GACL,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAYzE;kCAtLU;IACR,UAAU,EAAE,OAAO,UAAU,CAAC,CAAC;IAC/B,oBAAoB,EAAE,OAAO,uBAAuB,CAAC,CAAC;IACtD,WAAW,EAAE,OAAO,WAAW,CAAC,CAAC;IACjC,YAAY,EAAE,OAAO,YAAY,CAAC,CAAC;IACnC,WAAW,EAAE,OAAO,OAAO,CAAC,CAAC;CAC9B;iCA4IU,IAAI,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,EAAE,MAAM,CAAC;6BA1JzC,kBAAkB;0BAGrB,cAAc;gCALR,gCAAgC;4BAIpC,aAAa;6CAEI,2BAA2B;kCAL1B,cAAc;6BAE/B,cAAc"}
|
|
@@ -63,8 +63,6 @@ export const provideOrchestration = (
|
|
|
63
63
|
orchestration: zone.subZone('orchestration'),
|
|
64
64
|
/** system names for vows */
|
|
65
65
|
vows: zone.subZone('vows'),
|
|
66
|
-
/** system names for zoe */
|
|
67
|
-
zoe: zone.subZone('zoe'),
|
|
68
66
|
/** contract-provided names, and subzones */
|
|
69
67
|
contract: zone.subZone('contract'),
|
|
70
68
|
};
|
|
@@ -76,7 +74,7 @@ export const provideOrchestration = (
|
|
|
76
74
|
|
|
77
75
|
const chainHub = makeChainHub(agoricNames, vowTools);
|
|
78
76
|
|
|
79
|
-
const zoeTools = makeZoeTools(
|
|
77
|
+
const zoeTools = makeZoeTools(zcf, vowTools);
|
|
80
78
|
|
|
81
79
|
const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller);
|
|
82
80
|
const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit(
|
package/src/utils/zoe-tools.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
export function makeZoeTools(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}): {
|
|
5
|
-
localTransfer: (srcSeat: ZCFSeat, localAccount: LocalAccountMethods, give: AmountKeywordRecord) => Vow<void>;
|
|
1
|
+
export function makeZoeTools(zcf: ZCF, { when, allVows, allSettled, asVow }: VowTools): {
|
|
2
|
+
localTransfer: (srcSeat: ZCFSeat, localAccount: LocalAccountMethods, amounts: AmountKeywordRecord) => import("@agoric/vow").Vow<void>;
|
|
3
|
+
withdrawToSeat: (localAccount: LocalAccountMethods, destSeat: ZCFSeat, amounts: AmountKeywordRecord) => import("@agoric/vow").Vow<void>;
|
|
6
4
|
};
|
|
7
5
|
export type ResolvedContinuingOfferResult = {
|
|
8
6
|
invitationMakers: InvitationMakers;
|
|
9
7
|
publicSubscribers: Record<string, ResolvedPublicTopic<any>>;
|
|
10
8
|
};
|
|
11
|
-
export type LocalTransfer = (srcSeat: ZCFSeat, localAccount: LocalAccountMethods,
|
|
9
|
+
export type LocalTransfer = (srcSeat: ZCFSeat, localAccount: LocalAccountMethods, amounts: AmountKeywordRecord) => Promise<void>;
|
|
10
|
+
export type WithdrawToSeat = (localAccount: LocalAccountMethods, destSeat: ZCFSeat, amounts: AmountKeywordRecord) => Promise<void>;
|
|
12
11
|
export type ZoeTools = ReturnType<typeof makeZoeTools>;
|
|
13
|
-
import type { Zone } from '@agoric/zone';
|
|
14
12
|
import type { VowTools } from '@agoric/vow';
|
|
15
13
|
import type { LocalAccountMethods } from '../types.js';
|
|
16
|
-
import type { Vow } from '@agoric/vow';
|
|
17
14
|
import type { InvitationMakers } from '@agoric/smart-wallet/src/types.js';
|
|
18
15
|
import type { ResolvedPublicTopic } from '@agoric/zoe/src/contractSupport/topics.js';
|
|
19
16
|
//# sourceMappingURL=zoe-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zoe-tools.d.ts","sourceRoot":"","sources":["zoe-tools.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zoe-tools.d.ts","sourceRoot":"","sources":["zoe-tools.js"],"names":[],"mappings":"AA4DO,kCAHI,GAAG,wCACH,QAAQ;;;EA6HlB;4CAvJY;IACR,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,CAAC,CAAC,CAAC;CAC7D;4BAMS,CACR,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,mBAAmB,KACzB,OAAO,CAAC,IAAI,CAAC;6BAIR,CACR,YAAY,EAAE,mBAAmB,EACjC,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,mBAAmB,KACzB,OAAO,CAAC,IAAI,CAAC;uBAoIP,UAAU,CAAC,OAAO,YAAY,CAAC;8BA9JlB,aAAa;yCACF,aAAa;sCAHhB,mCAAmC;yCAChC,2CAA2C"}
|
package/src/utils/zoe-tools.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Helper functions for transferring payments between a LocalChainAccount
|
|
3
|
+
* and a ZCFSeat.
|
|
4
|
+
*
|
|
5
|
+
* Maintainers: This exists as an endowment for orchestrated async-flows so we
|
|
6
|
+
* can make use of E and promises. The logic for recovering partial failures
|
|
7
|
+
* is also an added convenience for developers.
|
|
8
|
+
*
|
|
9
|
+
* Functions are written using `asVow` and non-resumable promises as we expect
|
|
10
|
+
* each invocation to resolve promptly - there are no timers or interchain
|
|
11
|
+
* network calls.
|
|
12
|
+
*
|
|
13
|
+
* A promise resolved promptly is currently safe from being severed by an
|
|
14
|
+
* upgrade because we only trigger vat upgrades as the result of network
|
|
15
|
+
* input.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { makeError, q, Fail } from '@endo/errors';
|
|
19
|
+
import { depositToSeat } from '@agoric/zoe/src/contractSupport/index.js';
|
|
3
20
|
import { E } from '@endo/far';
|
|
4
21
|
|
|
22
|
+
const { assign, keys, values } = Object;
|
|
23
|
+
|
|
5
24
|
/**
|
|
25
|
+
* @import {HostOf} from '@agoric/async-flow';
|
|
6
26
|
* @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js';
|
|
7
27
|
* @import {ResolvedPublicTopic} from '@agoric/zoe/src/contractSupport/topics.js';
|
|
8
|
-
* @import {
|
|
9
|
-
* @import {Zone} from '@agoric/zone';
|
|
10
|
-
* @import {OrchestrationAccount} from '../orchestration-api.js'
|
|
28
|
+
* @import {VowTools} from '@agoric/vow';
|
|
11
29
|
* @import {LocalAccountMethods} from '../types.js';
|
|
12
30
|
*/
|
|
13
31
|
|
|
@@ -24,31 +42,38 @@ import { E } from '@endo/far';
|
|
|
24
42
|
* @typedef {(
|
|
25
43
|
* srcSeat: ZCFSeat,
|
|
26
44
|
* localAccount: LocalAccountMethods,
|
|
27
|
-
*
|
|
45
|
+
* amounts: AmountKeywordRecord,
|
|
28
46
|
* ) => Promise<void>} LocalTransfer
|
|
29
47
|
*/
|
|
30
48
|
|
|
31
49
|
/**
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
50
|
+
* @typedef {(
|
|
51
|
+
* localAccount: LocalAccountMethods,
|
|
52
|
+
* destSeat: ZCFSeat,
|
|
53
|
+
* amounts: AmountKeywordRecord,
|
|
54
|
+
* ) => Promise<void>} WithdrawToSeat
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {ZCF} zcf
|
|
59
|
+
* @param {VowTools} vowTools
|
|
34
60
|
*/
|
|
35
|
-
export const makeZoeTools = (
|
|
61
|
+
export const makeZoeTools = (zcf, { when, allVows, allSettled, asVow }) => {
|
|
36
62
|
/**
|
|
37
|
-
* Transfer the `
|
|
63
|
+
* Transfer the `amounts` from `srcSeat` to `localAccount`. If any of the
|
|
64
|
+
* deposits fail, everything will be rolled back to the `srcSeat`. Supports
|
|
65
|
+
* multiple items in the `amounts` {@link AmountKeywordRecord}.
|
|
66
|
+
*
|
|
67
|
+
* @type {HostOf<LocalTransfer>}
|
|
38
68
|
*/
|
|
39
|
-
const localTransfer =
|
|
40
|
-
|
|
41
|
-
'localTransfer',
|
|
42
|
-
/**
|
|
43
|
-
* @type {LocalTransfer}
|
|
44
|
-
*/
|
|
45
|
-
async (srcSeat, localAccount, give) => {
|
|
69
|
+
const localTransfer = (srcSeat, localAccount, amounts) =>
|
|
70
|
+
asVow(async () => {
|
|
46
71
|
!srcSeat.hasExited() || Fail`The seat cannot have exited.`;
|
|
47
72
|
const { zcfSeat: tempSeat, userSeat: userSeatP } = zcf.makeEmptySeatKit();
|
|
48
73
|
const userSeat = await userSeatP;
|
|
49
|
-
|
|
74
|
+
zcf.atomicRearrange(harden([[srcSeat, tempSeat, amounts]]));
|
|
50
75
|
tempSeat.exit();
|
|
51
|
-
// TODO get the userSeat into baggage so it's at least recoverable
|
|
76
|
+
// TODO (#9541) get the userSeat into baggage so it's at least recoverable
|
|
52
77
|
// const userSeat = await subzone.makeOnce(
|
|
53
78
|
// 'localTransferHelper',
|
|
54
79
|
// async () => {
|
|
@@ -56,28 +81,106 @@ export const makeZoeTools = (zone, { zcf, vowTools }) => {
|
|
|
56
81
|
// zcf.makeEmptySeatKit();
|
|
57
82
|
// const uSeat = await userSeatP;
|
|
58
83
|
// // TODO how do I store in the place for this retriable?
|
|
59
|
-
// atomicTransfer(zcf, srcSeat, tempSeat,
|
|
84
|
+
// atomicTransfer(zcf, srcSeat, tempSeat, amounts);
|
|
60
85
|
// tempSeat.exit();
|
|
61
86
|
// return uSeat;
|
|
62
87
|
// },
|
|
63
88
|
// );
|
|
64
89
|
|
|
65
|
-
// Now all the `
|
|
90
|
+
// Now all the `amounts` are accessible, so we can move them to the localAccount
|
|
91
|
+
const payments = await Promise.all(
|
|
92
|
+
keys(amounts).map(kw => E(userSeat).getPayout(kw)),
|
|
93
|
+
);
|
|
94
|
+
const settleDeposits = await when(
|
|
95
|
+
allSettled(payments.map(pmt => E(localAccount).deposit(pmt))),
|
|
96
|
+
);
|
|
97
|
+
// if any of the deposits to localAccount failed, unwind all of the allocations
|
|
98
|
+
if (settleDeposits.find(x => x.status === 'rejected')) {
|
|
99
|
+
const amts = values(amounts);
|
|
100
|
+
const errors = [];
|
|
101
|
+
// withdraw the successfully deposited payments
|
|
102
|
+
const paymentsOrWithdrawVs = settleDeposits.map((x, i) => {
|
|
103
|
+
if (x.status === 'rejected') {
|
|
104
|
+
errors.push(x.reason);
|
|
105
|
+
return payments[i];
|
|
106
|
+
}
|
|
107
|
+
return E(localAccount).withdraw(amts[i]);
|
|
108
|
+
});
|
|
66
109
|
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
110
|
+
// return all payments to the srcSeat
|
|
111
|
+
const paymentsToReturn = await when(allVows(paymentsOrWithdrawVs));
|
|
112
|
+
const paymentKwr = harden(
|
|
113
|
+
keys(amounts).reduce(
|
|
114
|
+
(kwr, kw, i) => assign(kwr, { [kw]: paymentsToReturn[i] }),
|
|
115
|
+
{},
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
const depositResponse = await depositToSeat(
|
|
119
|
+
zcf,
|
|
120
|
+
srcSeat,
|
|
121
|
+
amounts,
|
|
122
|
+
paymentKwr,
|
|
123
|
+
);
|
|
124
|
+
console.debug(depositResponse);
|
|
125
|
+
throw makeError(`One or more deposits failed ${q(errors)}`);
|
|
126
|
+
}
|
|
127
|
+
// TODO #9541 remove userSeat from baggage
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Transfer the `amounts` from a `localAccount` to the `recipientSeat`. If any
|
|
132
|
+
* of the withdrawals fail, everything will be rolled back to the
|
|
133
|
+
* `srcLocalAccount`. Supports multiple items in the `amounts`
|
|
134
|
+
* {@link PaymentKeywordRecord}
|
|
135
|
+
*
|
|
136
|
+
* @type {HostOf<WithdrawToSeat>}
|
|
137
|
+
*/
|
|
138
|
+
const withdrawToSeat = (localAccount, destSeat, amounts) =>
|
|
139
|
+
asVow(async () => {
|
|
140
|
+
!destSeat.hasExited() || Fail`The seat cannot have exited.`;
|
|
141
|
+
|
|
142
|
+
const settledWithdrawals = await when(
|
|
143
|
+
allSettled(values(amounts).map(amt => E(localAccount).withdraw(amt))),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// if any of the withdrawals were rejected, unwind the successful ones
|
|
147
|
+
if (settledWithdrawals.find(x => x.status === 'rejected')) {
|
|
148
|
+
const returnPaymentVs = [];
|
|
149
|
+
const errors = [];
|
|
150
|
+
for (const result of settledWithdrawals) {
|
|
151
|
+
if (result.status === 'fulfilled') {
|
|
152
|
+
returnPaymentVs.push(E(localAccount).deposit(result.value));
|
|
153
|
+
} else {
|
|
154
|
+
errors.push(result.reason);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
await when(allVows(returnPaymentVs));
|
|
158
|
+
throw makeError(`One or more withdrawals failed ${q(errors)}`);
|
|
159
|
+
}
|
|
160
|
+
// successfully withdrew payments from srcLocalAccount, deposit to recipientSeat
|
|
161
|
+
const paymentKwr = harden(
|
|
162
|
+
keys(amounts).reduce(
|
|
163
|
+
(acc, kw, i) =>
|
|
164
|
+
assign(acc, {
|
|
165
|
+
[kw]: /** @type {{ value: Amount }[]} */ (settledWithdrawals)[i]
|
|
166
|
+
.value,
|
|
167
|
+
}),
|
|
168
|
+
{},
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
const depositResponse = await depositToSeat(
|
|
172
|
+
zcf,
|
|
173
|
+
destSeat,
|
|
174
|
+
amounts,
|
|
175
|
+
paymentKwr,
|
|
176
|
+
);
|
|
177
|
+
console.debug(depositResponse);
|
|
178
|
+
});
|
|
78
179
|
|
|
79
180
|
return harden({
|
|
80
181
|
localTransfer,
|
|
182
|
+
withdrawToSeat,
|
|
81
183
|
});
|
|
82
184
|
};
|
|
185
|
+
|
|
83
186
|
/** @typedef {ReturnType<typeof makeZoeTools>} ZoeTools */
|