@agoric/smart-wallet 0.5.4-dev-dcc80f2.0.dcc80f2 → 0.5.4-dev-a6c0604.0.a6c0604
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 +15 -14
- package/tools/fixtures/gameAssetContract.d.ts +12 -0
- package/tools/fixtures/gameAssetContract.d.ts.map +1 -0
- package/tools/fixtures/gameAssetContract.js +75 -0
- package/tools/fixtures/start-game1-proposal.d.ts +14 -0
- package/tools/fixtures/start-game1-proposal.d.ts.map +1 -0
- package/tools/fixtures/start-game1-proposal.js +122 -0
- package/tools/wf-tools.d.ts +81 -0
- package/tools/wf-tools.d.ts.map +1 -0
- package/tools/wf-tools.js +124 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/smart-wallet",
|
|
3
|
-
"version": "0.5.4-dev-
|
|
3
|
+
"version": "0.5.4-dev-a6c0604.0.a6c0604",
|
|
4
4
|
"description": "Wallet contract",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"lint:eslint": "yarn run -T eslint ."
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@agoric/casting": "0.4.3-dev-
|
|
20
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
21
|
-
"@agoric/swingset-vat": "0.32.3-dev-
|
|
19
|
+
"@agoric/casting": "0.4.3-dev-a6c0604.0.a6c0604",
|
|
20
|
+
"@agoric/cosmic-proto": "0.4.1-dev-a6c0604.0.a6c0604",
|
|
21
|
+
"@agoric/swingset-vat": "0.32.3-dev-a6c0604.0.a6c0604",
|
|
22
22
|
"@endo/bundle-source": "^4.1.2",
|
|
23
23
|
"@endo/captp": "^4.4.8",
|
|
24
24
|
"@endo/init": "^1.1.12",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"import-meta-resolve": "^4.1.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
30
|
-
"@agoric/internal": "0.3.3-dev-
|
|
31
|
-
"@agoric/notifier": "0.6.3-dev-
|
|
32
|
-
"@agoric/store": "0.9.3-dev-
|
|
33
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
34
|
-
"@agoric/vats": "0.15.2-dev-
|
|
35
|
-
"@agoric/vow": "0.1.1-dev-
|
|
36
|
-
"@agoric/zoe": "0.26.3-dev-
|
|
37
|
-
"@agoric/zone": "0.2.3-dev-
|
|
29
|
+
"@agoric/ertp": "0.16.3-dev-a6c0604.0.a6c0604",
|
|
30
|
+
"@agoric/internal": "0.3.3-dev-a6c0604.0.a6c0604",
|
|
31
|
+
"@agoric/notifier": "0.6.3-dev-a6c0604.0.a6c0604",
|
|
32
|
+
"@agoric/store": "0.9.3-dev-a6c0604.0.a6c0604",
|
|
33
|
+
"@agoric/vat-data": "0.5.3-dev-a6c0604.0.a6c0604",
|
|
34
|
+
"@agoric/vats": "0.15.2-dev-a6c0604.0.a6c0604",
|
|
35
|
+
"@agoric/vow": "0.1.1-dev-a6c0604.0.a6c0604",
|
|
36
|
+
"@agoric/zoe": "0.26.3-dev-a6c0604.0.a6c0604",
|
|
37
|
+
"@agoric/zone": "0.2.3-dev-a6c0604.0.a6c0604",
|
|
38
38
|
"@endo/errors": "^1.2.13",
|
|
39
39
|
"@endo/eventual-send": "^1.3.4",
|
|
40
40
|
"@endo/far": "^1.1.14",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"src/",
|
|
48
|
+
"tools/",
|
|
48
49
|
"source-spec-registry.*"
|
|
49
50
|
],
|
|
50
51
|
"keywords": [],
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"engines": {
|
|
77
78
|
"node": "^20.9 || ^22.11"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "a6c06040100171553fdf07d11e906d073c019dee"
|
|
80
81
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function start(zcf: ZCF<{
|
|
2
|
+
joinPrice: Amount;
|
|
3
|
+
}>): Promise<{
|
|
4
|
+
publicFacet: {
|
|
5
|
+
makeJoinInvitation: () => Promise<import("@agoric/zoe").Invitation<string, undefined>>;
|
|
6
|
+
} & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
7
|
+
makeJoinInvitation: () => Promise<import("@agoric/zoe").Invitation<string, undefined>>;
|
|
8
|
+
}>;
|
|
9
|
+
}>;
|
|
10
|
+
import type { Amount } from '@agoric/ertp';
|
|
11
|
+
import type { ZCF } from '@agoric/zoe';
|
|
12
|
+
//# sourceMappingURL=gameAssetContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gameAssetContract.d.ts","sourceRoot":"","sources":["gameAssetContract.js"],"names":[],"mappings":"AA8BO,2BAFI,IAAI;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;;;;;;GA6CpC;4BA3DwB,cAAc;yBAFjB,aAAa"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** @file illustrates using non-vbank assets */
|
|
2
|
+
|
|
3
|
+
// deep import to avoid dependency on all of ERTP, vat-data
|
|
4
|
+
import { Fail, q } from '@endo/errors';
|
|
5
|
+
import { E, Far } from '@endo/far';
|
|
6
|
+
|
|
7
|
+
import { AmountShape } from '@agoric/ertp/src/typeGuards.js';
|
|
8
|
+
import { AmountMath, AssetKind } from '@agoric/ertp/src/amountMath.js';
|
|
9
|
+
import { makeTracer } from '@agoric/internal';
|
|
10
|
+
import { M, getCopyBagEntries } from '@agoric/store';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import {ZCF} from '@agoric/zoe';
|
|
14
|
+
* @import {ZCFSeat} from '@agoric/zoe';
|
|
15
|
+
* @import {Amount} from '@agoric/ertp';
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const trace = makeTracer('Game', true);
|
|
19
|
+
|
|
20
|
+
/** @param {Amount<'copyBag'>} amt */
|
|
21
|
+
const totalPlaces = amt => {
|
|
22
|
+
/** @type {[unknown, bigint][]} */
|
|
23
|
+
const entries = getCopyBagEntries(amt.value); // XXX getCopyBagEntries returns any???
|
|
24
|
+
const total = entries.reduce((acc, [_place, qty]) => acc + qty, 0n);
|
|
25
|
+
return total;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {ZCF<{ joinPrice: Amount }>} zcf
|
|
30
|
+
*/
|
|
31
|
+
export const start = async zcf => {
|
|
32
|
+
const { joinPrice } = zcf.getTerms();
|
|
33
|
+
const stableIssuer = await E(zcf.getZoeService()).getFeeIssuer();
|
|
34
|
+
await zcf.saveIssuer(stableIssuer, 'Price');
|
|
35
|
+
|
|
36
|
+
const { zcfSeat: gameSeat } = zcf.makeEmptySeatKit();
|
|
37
|
+
const mint = await zcf.makeZCFMint('Place', AssetKind.COPY_BAG);
|
|
38
|
+
|
|
39
|
+
const joinShape = harden({
|
|
40
|
+
give: { Price: AmountShape },
|
|
41
|
+
want: { Places: AmountShape },
|
|
42
|
+
exit: M.any(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** @param {ZCFSeat} playerSeat */
|
|
46
|
+
const joinHook = playerSeat => {
|
|
47
|
+
const { give, want } = playerSeat.getProposal();
|
|
48
|
+
trace('join', 'give', give, 'want', want.Places.value);
|
|
49
|
+
|
|
50
|
+
AmountMath.isGTE(give.Price, joinPrice) ||
|
|
51
|
+
Fail`${q(give.Price)} below joinPrice of ${q(joinPrice)}`;
|
|
52
|
+
|
|
53
|
+
totalPlaces(want.Places) <= 3n || Fail`only 3 places allowed when joining`;
|
|
54
|
+
|
|
55
|
+
// We use the deprecated stage/reallocate API
|
|
56
|
+
// so that we can test this with the version of zoe on mainnet1B.
|
|
57
|
+
const tmp = mint.mintGains(want);
|
|
58
|
+
zcf.atomicRearrange(
|
|
59
|
+
harden([
|
|
60
|
+
[playerSeat, gameSeat, give],
|
|
61
|
+
[tmp, playerSeat, want],
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
playerSeat.exit(true);
|
|
65
|
+
return 'welcome to the game';
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const publicFacet = Far('API', {
|
|
69
|
+
makeJoinInvitation: () =>
|
|
70
|
+
zcf.makeInvitation(joinHook, 'join', undefined, joinShape),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return harden({ publicFacet });
|
|
74
|
+
};
|
|
75
|
+
harden(start);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function startGameContract(permittedPowers: BootstrapPowers): Promise<void>;
|
|
2
|
+
export function getManifestForGame1({ restoreRef }: {
|
|
3
|
+
restoreRef: any;
|
|
4
|
+
}, { game1Ref }: {
|
|
5
|
+
game1Ref: any;
|
|
6
|
+
}): {
|
|
7
|
+
manifest: BootstrapManifest;
|
|
8
|
+
installations: {
|
|
9
|
+
game1: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
import type { BootstrapPowers } from '@agoric/vats/src/core/types.js';
|
|
13
|
+
import type { BootstrapManifest } from '@agoric/vats/src/core/lib-boot.js';
|
|
14
|
+
//# sourceMappingURL=start-game1-proposal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-game1-proposal.d.ts","sourceRoot":"","sources":["start-game1-proposal.js"],"names":[],"mappings":"AA+CO,mDAFI,eAAe,iBAiDzB;AAoBM;;;;;;;;;EAON;qCA/GiC,gCAAgC;uCAH9B,mCAAmC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Fail } from '@endo/errors';
|
|
3
|
+
import { E } from '@endo/far';
|
|
4
|
+
import { makeMarshal } from '@endo/marshal';
|
|
5
|
+
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import {BootstrapManifest} from '@agoric/vats/src/core/lib-boot.js';
|
|
9
|
+
* @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
|
|
10
|
+
* @import {ERef} from '@agoric/vow';
|
|
11
|
+
* @import {BootstrapPowers} from '@agoric/vats/src/core/types.js';
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// vstorage paths under published.*
|
|
15
|
+
const BOARD_AUX = 'boardAux';
|
|
16
|
+
|
|
17
|
+
const marshalData = makeMarshal(_val => Fail`data only`);
|
|
18
|
+
|
|
19
|
+
const IST_UNIT = 1_000_000n;
|
|
20
|
+
const CENT = IST_UNIT / 100n;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Make a storage node for auxiliary data for a value on the board.
|
|
24
|
+
*
|
|
25
|
+
* @param {ERef<StorageNode>} chainStorage
|
|
26
|
+
* @param {string} boardId
|
|
27
|
+
*/
|
|
28
|
+
const makeBoardAuxNode = async (chainStorage, boardId) => {
|
|
29
|
+
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
|
|
30
|
+
return E(boardAux).makeChildNode(boardId);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const publishBrandInfo = async (chainStorage, board, brand) => {
|
|
34
|
+
const [id, displayInfo] = await Promise.all([
|
|
35
|
+
E(board).getId(brand),
|
|
36
|
+
E(brand).getDisplayInfo(),
|
|
37
|
+
]);
|
|
38
|
+
const node = makeBoardAuxNode(chainStorage, id);
|
|
39
|
+
const aux = marshalData.toCapData(harden({ displayInfo }));
|
|
40
|
+
await E(node).setValue(JSON.stringify(aux));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Core eval script to start contract
|
|
45
|
+
*
|
|
46
|
+
* @param {BootstrapPowers} permittedPowers
|
|
47
|
+
*/
|
|
48
|
+
export const startGameContract = async permittedPowers => {
|
|
49
|
+
const {
|
|
50
|
+
consume: { agoricNames, board, chainStorage, startUpgradable, zoe },
|
|
51
|
+
brand: {
|
|
52
|
+
// @ts-expect-error dynamic extension to promise space
|
|
53
|
+
produce: { Place: producePlaceBrand },
|
|
54
|
+
},
|
|
55
|
+
issuer: {
|
|
56
|
+
// @ts-expect-error dynamic extension to promise space
|
|
57
|
+
produce: { Place: producePlaceIssuer },
|
|
58
|
+
},
|
|
59
|
+
instance: {
|
|
60
|
+
// @ts-expect-error dynamic extension to promise space
|
|
61
|
+
produce: { game1: produceInstance },
|
|
62
|
+
},
|
|
63
|
+
} = permittedPowers;
|
|
64
|
+
|
|
65
|
+
const istBrand = await E(agoricNames).lookup('brand', 'IST');
|
|
66
|
+
const ist = {
|
|
67
|
+
brand: istBrand,
|
|
68
|
+
};
|
|
69
|
+
// NOTE: joinPrice could be configurable
|
|
70
|
+
const terms = { joinPrice: AmountMath.make(ist.brand, 25n * CENT) };
|
|
71
|
+
|
|
72
|
+
// agoricNames can be updated on each bootstrap run; the promise-space
|
|
73
|
+
// producers resolve only once and then remain fixed.
|
|
74
|
+
const installation = await E(agoricNames).lookup('installation', 'game1');
|
|
75
|
+
|
|
76
|
+
const { instance } = await E(startUpgradable)({
|
|
77
|
+
installation,
|
|
78
|
+
label: 'game1',
|
|
79
|
+
terms,
|
|
80
|
+
});
|
|
81
|
+
const {
|
|
82
|
+
brands: { Place: brand },
|
|
83
|
+
issuers: { Place: issuer },
|
|
84
|
+
} = await E(zoe).getTerms(instance);
|
|
85
|
+
|
|
86
|
+
produceInstance.reset();
|
|
87
|
+
produceInstance.resolve(instance);
|
|
88
|
+
|
|
89
|
+
producePlaceBrand.reset();
|
|
90
|
+
producePlaceIssuer.reset();
|
|
91
|
+
producePlaceBrand.resolve(brand);
|
|
92
|
+
producePlaceIssuer.resolve(issuer);
|
|
93
|
+
|
|
94
|
+
await publishBrandInfo(chainStorage, board, brand);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** @type {BootstrapManifest} */
|
|
98
|
+
const gameManifest = {
|
|
99
|
+
[startGameContract.name]: {
|
|
100
|
+
consume: {
|
|
101
|
+
agoricNames: true,
|
|
102
|
+
board: true, // to publish boardAux info for game NFT
|
|
103
|
+
chainStorage: true, // to publish boardAux info for game NFT
|
|
104
|
+
startUpgradable: true, // to start contract and save adminFacet
|
|
105
|
+
zoe: true, // to get contract terms, including issuer/brand
|
|
106
|
+
},
|
|
107
|
+
installation: { consume: { game1: true } },
|
|
108
|
+
issuer: { produce: { Place: true } },
|
|
109
|
+
brand: { produce: { Place: true } },
|
|
110
|
+
instance: { produce: { game1: true } },
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
harden(gameManifest);
|
|
114
|
+
|
|
115
|
+
export const getManifestForGame1 = ({ restoreRef }, { game1Ref }) => {
|
|
116
|
+
return harden({
|
|
117
|
+
manifest: gameManifest,
|
|
118
|
+
installations: {
|
|
119
|
+
game1: restoreRef(game1Ref),
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export function makeBootstrap({ root }?: {
|
|
2
|
+
root?: string | undefined;
|
|
3
|
+
}): Promise<{
|
|
4
|
+
agoricNames: import("@agoric/vats").NameHub<any>;
|
|
5
|
+
agoricNamesAdmin: import("@agoric/vats").NameAdmin;
|
|
6
|
+
board: import("@endo/exo").Guarded<{
|
|
7
|
+
getId(value: import("@endo/pass-style").RemotableObject): string;
|
|
8
|
+
getValue(id: BoardId): import("@endo/pass-style").RemotableObject;
|
|
9
|
+
lookup(...path: string[]): Promise<any>;
|
|
10
|
+
has(val: import("@endo/pass-style").RemotableObject): boolean;
|
|
11
|
+
ids(): string[];
|
|
12
|
+
getPublishingMarshaller(): import("@endo/exo").Guarded<{
|
|
13
|
+
toCapData(val: any): import("@endo/marshal").CapData<string>;
|
|
14
|
+
fromCapData(data: any): any;
|
|
15
|
+
serialize(data: any): import("@endo/marshal").CapData<string>;
|
|
16
|
+
unserialize(data: any): any;
|
|
17
|
+
}>;
|
|
18
|
+
getReadonlyMarshaller(): import("@endo/exo").Guarded<{
|
|
19
|
+
toCapData(val: any): import("@endo/marshal").CapData<string | null>;
|
|
20
|
+
fromCapData(data: any): any;
|
|
21
|
+
serialize(data: any): import("@endo/marshal").CapData<string | null>;
|
|
22
|
+
unserialize(data: any): any;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
25
|
+
bankManager: import("@endo/exo").Guarded<{
|
|
26
|
+
getAssetSubscription(): import("@agoric/notifier").IterableEachTopic<AssetDescriptor>;
|
|
27
|
+
getRewardDistributorDepositFacet(denom: string, feeKit: AssetIssuerKit): import("@endo/eventual-send").ERef<import("@endo/eventual-send").EOnly<import("@agoric/ertp").DepositFacet>>;
|
|
28
|
+
getModuleAccountAddress(moduleName: string): Promise<string | null>;
|
|
29
|
+
addAsset(denom: string, issuerName: string, proposedName: string, kit: AssetIssuerKit & {
|
|
30
|
+
payment?: import("@endo/eventual-send").ERef<import("@agoric/ertp").Payment<"nat">>;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
getBankForAddress(address: string): Promise<Bank>;
|
|
33
|
+
}>;
|
|
34
|
+
namesByAddress: import("@agoric/vats").NameHub<any>;
|
|
35
|
+
namesByAddressAdmin: import("@agoric/vats").NameAdmin;
|
|
36
|
+
storage: {
|
|
37
|
+
rootNode: import("@endo/exo").Guarded<{
|
|
38
|
+
getPath(): string;
|
|
39
|
+
getStoreKey(): Promise<VStorageKey>;
|
|
40
|
+
makeChildNode(name: string, childNodeOptions?: {
|
|
41
|
+
sequence?: boolean;
|
|
42
|
+
}): StorageNode;
|
|
43
|
+
setValue(value: string): Promise<void>;
|
|
44
|
+
}>;
|
|
45
|
+
data: Map<string, string>;
|
|
46
|
+
updateNewCellBlockHeight: (blockHeight?: number) => void;
|
|
47
|
+
getValues: (path: string) => string[];
|
|
48
|
+
messages: import("@agoric/internal/src/lib-chainStorage.js").StorageMessage[];
|
|
49
|
+
toStorage: ((message: import("@agoric/internal/src/lib-chainStorage.js").StorageMessage) => string | number | true | any[] | {
|
|
50
|
+
storeName: string;
|
|
51
|
+
storeSubkey: string;
|
|
52
|
+
} | null) & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, (message: import("@agoric/internal/src/lib-chainStorage.js").StorageMessage) => string | number | true | any[] | {
|
|
53
|
+
storeName: string;
|
|
54
|
+
storeSubkey: string;
|
|
55
|
+
} | null>;
|
|
56
|
+
};
|
|
57
|
+
zoe: import("@endo/exo").Guarded<import("@agoric/zoe").ZoeService>;
|
|
58
|
+
utils: {
|
|
59
|
+
pourPayment: (amount: import("@agoric/ertp").Amount<"nat">) => Promise<import("@agoric/ertp").Payment<"nat">>;
|
|
60
|
+
bundleAndInstall: (pathOrExports: object, bundleId?: string) => Promise<Installation>;
|
|
61
|
+
readLegible: (path: string) => Promise<{
|
|
62
|
+
structure: any;
|
|
63
|
+
slots: any;
|
|
64
|
+
}>;
|
|
65
|
+
getTestJig: () => any;
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
export function deploy({ boot }?: {
|
|
69
|
+
boot?: typeof makeBootstrap;
|
|
70
|
+
}): Promise<{
|
|
71
|
+
walletFactoryFacets: StartedInstanceKit<wfExports.start>;
|
|
72
|
+
bootstrap: Awaited<ReturnType<typeof makeBootstrap>>;
|
|
73
|
+
provisionSmartWallet: (addr: string) => Promise<[SmartWallet, boolean]>;
|
|
74
|
+
testJig: SmartWalletTestJig;
|
|
75
|
+
}>;
|
|
76
|
+
import type { Installation } from '@agoric/zoe';
|
|
77
|
+
import * as wfExports from '../src/walletFactory.js';
|
|
78
|
+
import type { StartedInstanceKit } from '@agoric/zoe/src/zoeService/utils.js';
|
|
79
|
+
import type { SmartWallet } from '../src/smartWallet.js';
|
|
80
|
+
import type { SmartWalletTestJig } from '../src/smartWallet.js';
|
|
81
|
+
//# sourceMappingURL=wf-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wf-tools.d.ts","sourceRoot":"","sources":["wf-tools.js"],"names":[],"mappings":"AA2BO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAiG6riB,CAAC;;;;;;;;;;;wBAA1he,CAAC;;;;;;;;;;;;;;;;;;;;4BAnE9pE,MAAM;;;;;;GAiBnB;AAWM,kCARI;IAAE,IAAI,CAAC,EAAE,OAAO,aAAa,CAAA;CAAE,GAC7B,OAAO,CAAC;IAChB,mBAAmB,EAAE,mBAAmB,eAAO,CAAC,CAAC;IACjD,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;IACrD,oBAAoB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC,CAwCJ;kCA3G8B,aAAa;2BANjB,yBAAyB;wCAKf,qCAAqC;iCADxB,uBAAuB;wCAAvB,uBAAuB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { VBankAccount } from '@agoric/internal';
|
|
2
|
+
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
|
|
3
|
+
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
|
|
4
|
+
import { makeNameHubKit } from '@agoric/vats';
|
|
5
|
+
import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js';
|
|
6
|
+
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
|
|
7
|
+
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
|
|
8
|
+
import { setUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
|
|
9
|
+
import { E } from '@endo/eventual-send';
|
|
10
|
+
import { passStyleOf } from '@endo/far';
|
|
11
|
+
import * as wfExports from '../src/walletFactory.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import {start as StartFn} from '../src/walletFactory.js';
|
|
15
|
+
* @import {SmartWallet, SmartWalletTestJig} from '../src/smartWallet.js'
|
|
16
|
+
* @import {StartedInstanceKit} from '@agoric/zoe/src/zoeService/utils.js';
|
|
17
|
+
* @import {Installation} from '@agoric/zoe';
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const ROOT_STORAGE_PATH = 'ROOT';
|
|
21
|
+
|
|
22
|
+
const getCapDataStructure = cell => {
|
|
23
|
+
const { body, slots } = JSON.parse(cell);
|
|
24
|
+
const structure = JSON.parse(body.replace(/^#/, ''));
|
|
25
|
+
return { structure, slots };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const makeBootstrap = async ({ root = ROOT_STORAGE_PATH } = {}) => {
|
|
29
|
+
let testJig;
|
|
30
|
+
const setJig = jig => (testJig = jig);
|
|
31
|
+
const getTestJig = () => testJig;
|
|
32
|
+
const { zoe, bundleAndInstall } = await setUpZoeForTest({ setJig });
|
|
33
|
+
|
|
34
|
+
const storage = makeFakeStorageKit(root);
|
|
35
|
+
const board = makeFakeBoard();
|
|
36
|
+
|
|
37
|
+
const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } =
|
|
38
|
+
makeNameHubKit();
|
|
39
|
+
await makeWellKnownSpaces(agoricNamesAdmin);
|
|
40
|
+
const { nameHub: namesByAddress, nameAdmin: namesByAddressAdmin } =
|
|
41
|
+
makeNameHubKit();
|
|
42
|
+
|
|
43
|
+
const bankBridgeMessages = [];
|
|
44
|
+
const { bankManager, pourPayment } = await makeFakeBankManagerKit({
|
|
45
|
+
onToBridge: obj => bankBridgeMessages.push(obj),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const feeIssuer = await E(zoe).getFeeIssuer();
|
|
49
|
+
const feeBrand = await E(feeIssuer).getBrand();
|
|
50
|
+
await E(bankManager).addAsset('uist', 'IST', 'IST', {
|
|
51
|
+
issuer: feeIssuer,
|
|
52
|
+
brand: feeBrand,
|
|
53
|
+
});
|
|
54
|
+
await E(E(agoricNamesAdmin).lookupAdmin('issuer')).update('IST', feeIssuer);
|
|
55
|
+
await E(E(agoricNamesAdmin).lookupAdmin('brand')).update('IST', feeBrand);
|
|
56
|
+
board.getId(feeBrand);
|
|
57
|
+
|
|
58
|
+
/** @param {string} path */
|
|
59
|
+
const readLegible = async path => {
|
|
60
|
+
await eventLoopIteration();
|
|
61
|
+
return getCapDataStructure(storage.getValues(path).at(-1));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
agoricNames,
|
|
66
|
+
agoricNamesAdmin,
|
|
67
|
+
board,
|
|
68
|
+
bankManager,
|
|
69
|
+
namesByAddress,
|
|
70
|
+
namesByAddressAdmin,
|
|
71
|
+
storage,
|
|
72
|
+
zoe,
|
|
73
|
+
utils: { pourPayment, bundleAndInstall, readLegible, getTestJig },
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {{ boot?: typeof makeBootstrap }} param0
|
|
79
|
+
* @returns {Promise<{
|
|
80
|
+
* walletFactoryFacets: StartedInstanceKit<StartFn>;
|
|
81
|
+
* bootstrap: Awaited<ReturnType<typeof makeBootstrap>>;
|
|
82
|
+
* provisionSmartWallet: (addr: string) => Promise<[SmartWallet, boolean]>;
|
|
83
|
+
* testJig: SmartWalletTestJig;
|
|
84
|
+
* }>}
|
|
85
|
+
*/
|
|
86
|
+
export const deploy = async ({ boot = makeBootstrap } = {}) => {
|
|
87
|
+
const bootstrap = await boot();
|
|
88
|
+
const { zoe, utils } = bootstrap;
|
|
89
|
+
|
|
90
|
+
/** @type {Installation<StartFn>} */
|
|
91
|
+
const installation = await utils.bundleAndInstall(wfExports);
|
|
92
|
+
assert.equal(passStyleOf(installation), 'remotable');
|
|
93
|
+
|
|
94
|
+
const { agoricNames, board, bankManager, storage } = bootstrap;
|
|
95
|
+
const storageNode = storage.rootNode.makeChildNode('wallet');
|
|
96
|
+
|
|
97
|
+
const assetPublisher = await bankManager.getBankForAddress(
|
|
98
|
+
VBankAccount.provision.address,
|
|
99
|
+
);
|
|
100
|
+
const walletFactoryFacets = await E(zoe).startInstance(
|
|
101
|
+
installation,
|
|
102
|
+
{},
|
|
103
|
+
{
|
|
104
|
+
agoricNames,
|
|
105
|
+
board,
|
|
106
|
+
assetPublisher,
|
|
107
|
+
},
|
|
108
|
+
{ storageNode },
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const { creatorFacet } = walletFactoryFacets;
|
|
112
|
+
const { namesByAddressAdmin } = bootstrap;
|
|
113
|
+
|
|
114
|
+
/** @param {string} addr */
|
|
115
|
+
const provisionSmartWallet = async addr => {
|
|
116
|
+
const bank = bankManager.getBankForAddress(addr);
|
|
117
|
+
return E(creatorFacet).provideSmartWallet(addr, bank, namesByAddressAdmin);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** @type {SmartWalletTestJig} */
|
|
121
|
+
const testJig = utils.getTestJig();
|
|
122
|
+
|
|
123
|
+
return { walletFactoryFacets, bootstrap, provisionSmartWallet, testJig };
|
|
124
|
+
};
|