Skip to content

Commit 2288e60

Browse files
committed
feat: integrate the economy's central token in chain bootstrap
1 parent 90a28c9 commit 2288e60

File tree

5 files changed

+72
-46
lines changed

5 files changed

+72
-46
lines changed

packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js

+62-21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from '@agoric/swingset-vat/src/vats/network';
77
import { E } from '@agoric/eventual-send';
88
import { Far } from '@agoric/marshal';
9+
import { makeStore } from '@agoric/store';
10+
import { installOnChain as installEconomyOnChain } from '@agoric/treasury/bundles/install-on-chain';
911

1012
// this will return { undefined } until `ag-solo set-gci-ingress`
1113
// has been run to update gci.js
@@ -66,25 +68,73 @@ export function buildRootObject(vatPowers, vatParameters) {
6668
E(vats.priceAuthority).makePriceAuthority(),
6769
]);
6870

71+
const {
72+
nameHub: agoricNames,
73+
nameAdmin: agoricNamesAdmin,
74+
} = makeNameHubKit();
75+
const {
76+
nameHub: namesByAddress,
77+
nameAdmin: namesByAddressAdmin,
78+
} = makeNameHubKit();
79+
80+
async function installEconomy() {
81+
// Create a mapping from all the nameHubs we create to their corresponding
82+
// nameAdmin.
83+
const nameAdmins = makeStore();
84+
await Promise.all(
85+
['brand', 'installation', 'issuer', 'instance', 'uiConfig'].map(
86+
async nm => {
87+
const { nameHub, nameAdmin } = makeNameHubKit();
88+
await E(agoricNamesAdmin).update(nm, nameHub);
89+
nameAdmins.init(nameHub, nameAdmin);
90+
},
91+
),
92+
);
93+
94+
// Install the economy, giving it access to the name admins we made.
95+
await installEconomyOnChain({
96+
agoricNames,
97+
board,
98+
chainTimerService,
99+
nameAdmins,
100+
priceAuthority,
101+
zoe,
102+
});
103+
}
104+
105+
// Now we can bootstrap the economy!
106+
await installEconomy();
107+
const centralIssuer = await E(agoricNames).lookup('issuer', 'Moe');
108+
109+
const CENTRAL_ISSUER_ENTRY = [
110+
CENTRAL_ISSUER_NAME,
111+
{
112+
issuer: centralIssuer,
113+
mintValue: 0,
114+
pursePetname: 'Local currency',
115+
fakeTradesGivenCentral: [[1, 1]],
116+
},
117+
];
118+
69119
const issuerNameToRecord = noFakeCurrencies
70120
? new Map()
71121
: fakeIssuerNameToRecord;
122+
issuerNameToRecord.set(...CENTRAL_ISSUER_ENTRY);
123+
72124
const issuerNames = [...issuerNameToRecord.keys()];
73-
const centralIssuerIndex = issuerNames.findIndex(
74-
issuerName => issuerName === CENTRAL_ISSUER_NAME,
75-
);
76-
// Make the other demo mints
77125
const issuers = await Promise.all(
78-
issuerNames.map(issuerName =>
79-
E(vats.mints).makeMintAndIssuer(
126+
issuerNames.map(issuerName => {
127+
const record = issuerNameToRecord.get(issuerName);
128+
if (record.issuer !== undefined) {
129+
return record.issuer;
130+
}
131+
return E(vats.mints).makeMintAndIssuer(
80132
issuerName,
81-
...(issuerNameToRecord.get(issuerName).issuerArgs || []),
82-
),
83-
),
133+
...(record.issuerArgs || []),
134+
);
135+
}),
84136
);
85137

86-
const centralIssuer = issuers[centralIssuerIndex];
87-
88138
/**
89139
* @param {ERef<Issuer>} issuerIn
90140
* @param {ERef<Issuer>} issuerOut
@@ -112,7 +162,7 @@ export function buildRootObject(vatPowers, vatParameters) {
112162
};
113163
await Promise.all(
114164
issuers.map(async (issuer, i) => {
115-
// Create priceAuthority pairs for centralIssuerIndex based on the
165+
// Create priceAuthority pairs for centralIssuer based on the
116166
// FakePriceAuthority.
117167
console.debug(`Creating ${issuerNames[i]}-${CENTRAL_ISSUER_NAME}`);
118168
const { fakeTradesGivenCentral } = issuerNameToRecord.get(
@@ -135,15 +185,6 @@ export function buildRootObject(vatPowers, vatParameters) {
135185
}),
136186
);
137187

138-
const {
139-
nameHub: agoricNames,
140-
nameAdmin: agoricNamesAdmin,
141-
} = makeNameHubKit();
142-
const {
143-
nameHub: namesByAddress,
144-
nameAdmin: namesByAddressAdmin,
145-
} = makeNameHubKit();
146-
147188
return Far('chainBundler', {
148189
async createUserBundle(_nickname, address, powerFlags = []) {
149190
// Bind to some fresh ports (unspecified name) on the IBC implementation

packages/cosmic-swingset/lib/ag-solo/vats/issuers.js

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// @ts-check
22

3-
export const CENTRAL_ISSUER_NAME = 'Testnet.$USD';
3+
export const CENTRAL_ISSUER_NAME = 'MOE';
44

55
/**
66
* @typedef {Object} IssuerInitializationRecord
7+
* @property {Issuer} [issuer]
78
* @property {Array<any>} [issuerArgs]
89
* @property {string} pursePetname
910
* @property {number} mintValue
@@ -14,16 +15,7 @@ export const CENTRAL_ISSUER_NAME = 'Testnet.$USD';
1415
export const fakeIssuerNameToRecord = new Map(
1516
harden([
1617
[
17-
CENTRAL_ISSUER_NAME,
18-
{
19-
issuerArgs: [undefined, { decimalPlaces: 3 }],
20-
mintValue: 20000,
21-
pursePetname: 'Local currency',
22-
fakeTradesGivenCentral: [[1, 1]],
23-
},
24-
],
25-
[
26-
'Testnet.$LINK',
18+
'$LINK',
2719
{
2820
issuerArgs: [undefined, { decimalPlaces: 6 }],
2921
mintValue: 7 * 10 ** 6,
@@ -49,20 +41,6 @@ export const fakeIssuerNameToRecord = new Map(
4941
],
5042
},
5143
],
52-
[
53-
'MOE',
54-
{
55-
mintValue: 0,
56-
pursePetname: 'MOE funds',
57-
fakeTradesGivenCentral: [
58-
[10, 15],
59-
[13, 9],
60-
[12, 13],
61-
[18, 15],
62-
[15, 17],
63-
],
64-
},
65-
],
6644
[
6745
'simolean',
6846
{

packages/cosmic-swingset/lib/ag-solo/vats/vat-mints.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export function buildRootObject(_vatPowers) {
3232
return issuer;
3333
},
3434
mintInitialPayment: (issuerName, value) => {
35+
if (!mintsAndMath.has(issuerName)) {
36+
return undefined;
37+
}
3538
const { mint, amountMath } = mintsAndMath.get(issuerName);
3639
const amount = amountMath.make(value);
3740
return mint.mintPayment(amount);

packages/cosmic-swingset/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@agoric/swing-store-simple": "^0.3.4",
5050
"@agoric/swingset-vat": "^0.14.0",
5151
"@agoric/transform-eventual-send": "^1.4.4",
52+
"@agoric/treasury": "^0.1.1",
5253
"@agoric/zoe": "^0.13.1",
5354
"@babel/generator": "^7.6.4",
5455
"@iarna/toml": "^2.2.3",

packages/dapp-svelte-wallet/api/deploy.js

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ export default async function deployWallet(
103103
),
104104
);
105105
}
106+
if (!payment) {
107+
return;
108+
}
106109
pursePetname = await issuerToPursePetnameP.get(issuer);
107110

108111
// Deposit payment.

0 commit comments

Comments
 (0)