Skip to content

Commit 90ab888

Browse files
committed
feat: have the bank use normal purses when not on chain
1 parent 04b004c commit 90ab888

File tree

7 files changed

+87
-37
lines changed

7 files changed

+87
-37
lines changed

packages/agoric-cli/lib/chain-config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import djson from 'deterministic-json';
22
import TOML from '@iarna/toml';
33

4-
export const MINT_DENOM = 'urun';
4+
export const MINT_DENOM = 'ubld';
55
export const STAKING_DENOM = 'ubld';
66
export const STAKING_MAX_VALIDATORS = 150;
77

8-
export const GOV_DEPOSIT_COINS = [{ amount: '10000000', denom: MINT_DENOM }];
8+
export const GOV_DEPOSIT_COINS = [{ amount: '1000000', denom: MINT_DENOM }];
99

1010
// Can't beat the speed of light, we need 600ms round trip time for the other
1111
// side of Earth, and multiple round trips per block.

packages/cosmic-swingset/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ scenario2-setup-nobuild:
6161
# Create the bootstrap account.
6262
$(AGCH) --home=t1/bootstrap keys add bootstrap --keyring-backend=test
6363
$(AGCH) --home=t1/bootstrap keys show -a bootstrap --keyring-backend=test > t1/bootstrap-address
64-
$(AGCH) --home=t1/n0 add-genesis-account `cat t1/bootstrap-address` 100000000ubld,100provisionpass,100sendpacketpass
64+
$(AGCH) --home=t1/n0 add-genesis-account `cat t1/bootstrap-address` 1000000000000000ubld,100provisionpass,100sendpacketpass
6565
# Create the (singleton) chain node.
66-
$(AGCH) --home=t1/n0 --keyring-dir=t1/bootstrap gentx --keyring-backend=test bootstrap 1000000ubld --chain-id=$(CHAIN_ID)
66+
$(AGCH) --home=t1/n0 --keyring-dir=t1/bootstrap gentx --keyring-backend=test bootstrap 73000000ubld --chain-id=$(CHAIN_ID)
6767
$(AGCH) --home=t1/n0 collect-gentxs
6868
$(AGCH) --home=t1/n0 validate-genesis
6969
../agoric-cli/bin/agoric set-defaults --export-metrics ag-chain-cosmos t1/n0/config

packages/cosmic-swingset/src/sim-chain.js

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
5757
giveMeAllTheAgoricPowers: true,
5858
hardcodedClientAddresses: [bootAddress],
5959
noFakeCurrencies: process.env.NO_FAKE_CURRENCIES,
60+
bootMsg: {
61+
bootstrapAddress: 'agoric1simboot',
62+
bootstrapValue: `${50000n * 10n ** 6n}`,
63+
donationValue: `${5n * 10n ** 6n}`,
64+
},
6065
};
6166
const stateDBdir = path.join(basedir, `fake-chain-${GCI}-state`);
6267
function flushChainSends(replay) {

packages/deployment/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import chalk from 'chalk';
33

44
export const ACCOUNT_JSON = `account.json`;
5-
export const DEFAULT_BOOT_TOKENS = `10000000000000000000000000urun`;
5+
export const DEFAULT_BOOT_TOKENS = `10000000000000000000000000ubld`;
66
export const PLAYBOOK_WRAPPER = `./ansible-playbook.sh`;
77
export const SSH_TYPE = 'ecdsa';
88

packages/vats/src/bootstrap.js

+30-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function buildRootObject(vatPowers, vatParameters) {
7171
zoe,
7272
{ priceAuthority, adminFacet: priceAuthorityAdmin },
7373
] = await Promise.all([
74-
bridgeManager ? E(bankVat).makeBankManager(bridgeManager) : undefined,
74+
E(bankVat).makeBankManager(bridgeManager),
7575
E(vats.sharing).getSharingService(),
7676
E(vats.registrar).getSharedRegistrar(),
7777
E(vats.board).getBoard(),
@@ -161,7 +161,7 @@ export function buildRootObject(vatPowers, vatParameters) {
161161
// We just transfer the bootstrapValue in central tokens to the low-level
162162
// bootstrapAddress.
163163
async function depositCentralBootstrapPayment() {
164-
if (!bankManager || !bootstrapAddress || !bootstrapPaymentValue) {
164+
if (!bootstrapAddress || !bootstrapPaymentValue) {
165165
return;
166166
}
167167
await E(bankManager).addAsset(
@@ -218,7 +218,7 @@ export function buildRootObject(vatPowers, vatParameters) {
218218
issuerName,
219219
harden({ ...record, brand, issuer }),
220220
);
221-
if (!record.bankDenom || !record.bankPurse || !bankManager) {
221+
if (!record.bankDenom || !record.bankPurse) {
222222
return issuer;
223223
}
224224

@@ -466,12 +466,16 @@ export function buildRootObject(vatPowers, vatParameters) {
466466
const mintIssuerNames = [];
467467
const mintPurseNames = [];
468468
const mintValues = [];
469+
const payToBank = [];
469470
issuerNames.forEach(issuerName => {
470471
const record = issuerNameToRecord.get(issuerName);
471472
if (!record.defaultPurses) {
472473
return;
473474
}
474475
record.defaultPurses.forEach(([purseName, value]) => {
476+
// Only pay to the bank if we don't have an actual bridge to the
477+
// underlying chain (from which we'll get the assets).
478+
payToBank.push(!bridgeManager && purseName === record.bankPurse);
475479
mintIssuerNames.push(issuerName);
476480
mintPurseNames.push(purseName);
477481
mintValues.push(value);
@@ -482,17 +486,38 @@ export function buildRootObject(vatPowers, vatParameters) {
482486
mintValues,
483487
);
484488

485-
const paymentInfo = mintIssuerNames.map((issuerName, i) => ({
489+
const allPayments = mintIssuerNames.map((issuerName, i) => ({
486490
issuer: issuerNameToRecord.get(issuerName).issuer,
487491
issuerPetname: issuerName,
488492
payment: payments[i],
493+
brand: issuerNameToRecord.get(issuerName).brand,
489494
pursePetname: mintPurseNames[i],
490495
}));
491496

497+
const bank = await E(bankManager).getBankForAddress(address);
498+
499+
// Separate out the purse-creating payments from the bank payments.
500+
const faucetPaymentInfo = [];
501+
await Promise.all(
502+
allPayments.map(async (record, i) => {
503+
if (!payToBank[i]) {
504+
// Just a faucet payment to be claimed by a wallet.
505+
faucetPaymentInfo.push(record);
506+
return;
507+
}
508+
const { brand, payment } = record;
509+
510+
// Deposit the payment in the bank now.
511+
assert(brand);
512+
const purse = E(bank).getPurse(brand);
513+
await E(purse).deposit(payment);
514+
}),
515+
);
516+
492517
const faucet = Far('faucet', {
493518
// A method to reap the spoils of our on-chain provisioning.
494519
async tapFaucet() {
495-
return paymentInfo;
520+
return faucetPaymentInfo;
496521
},
497522
});
498523

@@ -512,9 +537,6 @@ export function buildRootObject(vatPowers, vatParameters) {
512537
},
513538
};
514539

515-
const bank = await (bankManager &&
516-
E(bankManager).getBankForAddress(address));
517-
518540
/** @param {NatValue} value */
519541
async function donateCentralFromBootstrap(value) {
520542
if (!bank || !centralBootstrapPurse) {

packages/vats/src/issuers.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const fromCosmosIssuerEntries = [
7272
'BLD',
7373
{
7474
issuerArgs: [undefined, { decimalPlaces: 6 }],
75+
defaultPurses: [['Agoric staking token', scaleMicro(62)]],
7576
bankDenom: 'ubld',
7677
bankPurse: 'Agoric staking token',
7778
collateralConfig: {

packages/vats/src/vat-bank.js

+46-24
Original file line numberDiff line numberDiff line change
@@ -85,40 +85,54 @@ const makePurseController = (
8585
export function buildRootObject(_vatPowers) {
8686
return Far('bankMaker', {
8787
/**
88-
* @param {import('./bridge').BridgeManager} bridgeMgr
88+
* @param {import('./bridge').BridgeManager} bridgeManager
8989
*/
90-
async makeBankManager(bridgeMgr) {
91-
const bankCall = obj => E(bridgeMgr).toBridge('bank', obj);
92-
90+
async makeBankManager(bridgeManager) {
9391
/** @type {Store<Brand, AssetRecord>} */
9492
const brandToAssetRecord = makeStore('brand');
93+
9594
/** @type {Store<string, Store<string, (amount: any) => void>>} */
9695
const denomToAddressUpdater = makeStore('denom');
9796

98-
const handler = Far('bankHandler', {
99-
async fromBridge(_srcID, obj) {
100-
switch (obj.type) {
101-
case 'VPURSE_BALANCE_UPDATE': {
102-
for (const update of obj.updated) {
103-
try {
104-
const { address, denom, amount: value } = update;
105-
const addressToUpdater = denomToAddressUpdater.get(denom);
106-
const updater = addressToUpdater.get(address);
107-
108-
updater(value);
109-
} catch (e) {
110-
console.error('Unregistered update', update);
97+
/**
98+
* @param {import('./bridge').BridgeManager} bridgeMgr
99+
*/
100+
async function getRemoteBankCall(bridgeMgr) {
101+
if (!bridgeMgr) {
102+
return undefined;
103+
}
104+
105+
// We need to synchronise with the remote bank.
106+
const handler = Far('bankHandler', {
107+
async fromBridge(_srcID, obj) {
108+
switch (obj.type) {
109+
case 'VPURSE_BALANCE_UPDATE': {
110+
for (const update of obj.updated) {
111+
try {
112+
const { address, denom, amount: value } = update;
113+
const addressToUpdater = denomToAddressUpdater.get(denom);
114+
const updater = addressToUpdater.get(address);
115+
116+
updater(value);
117+
} catch (e) {
118+
console.error('Unregistered update', update);
119+
}
111120
}
121+
break;
112122
}
113-
break;
123+
default:
124+
assert.fail(X`Unrecognized request ${obj.type}`);
114125
}
115-
default:
116-
assert.fail(X`Unrecognized request ${obj.type}`);
117-
}
118-
},
119-
});
126+
},
127+
});
128+
129+
await E(bridgeMgr).register('bank', handler);
130+
131+
// We can only downcall to the bank if there exists a bridge manager.
132+
return obj => E(bridgeMgr).toBridge('bank', obj);
133+
}
120134

121-
await E(bridgeMgr).register('bank', handler);
135+
const bankCall = await getRemoteBankCall(bridgeManager);
122136

123137
/**
124138
* @typedef {Object} AssetDescriptor
@@ -203,7 +217,15 @@ export function buildRootObject(_vatPowers) {
203217
if (brandToVPurse.has(brand)) {
204218
return brandToVPurse.get(brand);
205219
}
220+
206221
const assetRecord = brandToAssetRecord.get(brand);
222+
if (!bankCall) {
223+
// Just emulate with a real purse.
224+
const purse = await E(assetRecord.issuer).makeEmptyPurse();
225+
brandToVPurse.init(brand, purse);
226+
return purse;
227+
}
228+
207229
const addressToUpdater = denomToAddressUpdater.get(
208230
assetRecord.denom,
209231
);

0 commit comments

Comments
 (0)