Skip to content

Commit

Permalink
feat: add bank assets for "cosmos" issuers (currently BLD)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 1, 2021
1 parent d2f719d commit 3148b83
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
16 changes: 14 additions & 2 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,36 @@ scenario2-run-chain:
DEBUG=SwingSet:ls,SwingSet:vat \
$(AGC) `$(BREAK_CHAIN) && echo --inspect-brk` --home=t1/n0 start --log_level=warn

scenario2-reset-client:
rm -rf t1/$(BASE_PORT)
$(AG_SOLO) init t1/$(BASE_PORT) --webport=$(BASE_PORT)
$(MAKE) set-local-gci-ingress

# Provision and start a client.
scenario2-run-client: t1-provision-one-with-powers t1-start-ag-solo

# Provision the ag-solo from an provisionpass-holding address (idempotent).
AGORIC_POWERS = agoric.bankManager,agoric.agoricNamesAdmin,agoric.pegasusConnections,agoric.priceAuthorityAdmin,agoric.treasuryCreator,agoric.vattp
SOLO_COINS = 13000000ubld
t1-provision-one-with-powers:
addr=$$(cat t1/$(BASE_PORT)/ag-cosmos-helper-address); \
$(AGCH) --home=t1/bootstrap query swingset egress $$addr --chain-id=$(CHAIN_ID) || \
{ $(AGCH) --home=t1/bootstrap tx bank send --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
bootstrap $$addr $(SOLO_COINS); \
$(AGCH) --home=t1/bootstrap tx swingset provision-one --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
t1/$(BASE_PORT) $$addr $(AGORIC_POWERS) | tee /dev/stderr | grep -q '"code":0'
t1/$(BASE_PORT) $$addr $(AGORIC_POWERS) | tee /dev/stderr | grep -q '"code":0'; }

t1-provision-one:
addr=$$(cat t1/$(BASE_PORT)/ag-cosmos-helper-address); \
$(AGCH) --home=t1/bootstrap query swingset egress $$addr --chain-id=$(CHAIN_ID) || \
{ $(AGCH) --home=t1/bootstrap tx bank send --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
bootstrap $$addr $(SOLO_COINS); \
$(AGCH) --home=t1/bootstrap tx swingset provision-one --keyring-backend=test --from=bootstrap \
--gas=auto --gas-adjustment=1.2 --broadcast-mode=block --yes --chain-id=$(CHAIN_ID) \
t1/$(BASE_PORT) $$addr | tee /dev/stderr | grep -q '"code":0'
t1/$(BASE_PORT) $$addr | tee /dev/stderr | grep -q '"code":0'; }

# Actually start the ag-solo.
t1-start-ag-solo:
Expand Down
24 changes: 21 additions & 3 deletions packages/vats/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function makeVattpFrom(vats) {
}

export function buildRootObject(vatPowers, vatParameters) {
console.error('%%%HAVE vatParameters', vatParameters);
const { D } = vatPowers;
async function setupCommandDevice(httpVat, cmdDevice, roles) {
await E(httpVat).setCommandDevice(cmdDevice, roles);
Expand Down Expand Up @@ -163,13 +164,15 @@ export function buildRootObject(vatPowers, vatParameters) {
}
const bank = await E(bankManager).getBankForAddress(bootstrapAddress);
const pmt = await E(treasuryCreator).getBootstrapPayment(
amountMath.make(bootstrapValue, centralBrand),
amountMath.make(BigInt(bootstrapValue), centralBrand),
);
const purse = E(bank).getPurse(centralBrand);
await E(purse).deposit(pmt);
}
console.error('have vatParameters', vatParameters);
await payThePiper(vatParameters.bootMsg);
false &&
(await payThePiper(
vatParameters && vatParameters.argv && vatParameters.argv.bootMsg,
));

/** @type {[string, import('./issuers').IssuerInitializationRecord]} */
const CENTRAL_ISSUER_ENTRY = [
Expand Down Expand Up @@ -211,6 +214,21 @@ export function buildRootObject(vatPowers, vatParameters) {
issuerName,
harden({ ...record, brand, issuer }),
);
if (!record.bankDenom || !record.bankPurse) {
return issuer;
}

// We need to obtain the mint in order to mint the tokens when they
// come from the bank.
// FIXME: Be more careful with the mint.
const mint = await E(vats.mints).getMint(issuerName);
const kit = harden({ brand, issuer, mint });
await E(bankManager).addAsset(
record.bankDenom,
issuerName,
record.bankPurse,
kit,
);
return issuer;
}),
);
Expand Down
5 changes: 4 additions & 1 deletion packages/vats/src/issuers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const CENTRAL_ISSUER_NAME = 'RUN';
* @property {Brand} [brand]
* @property {Array<any>} [issuerArgs]
* @property {CollateralConfig} [collateralConfig]
* @property {string} [bankDenom]
* @property {string} [bankPurse]
* @property {Array<[string, Bigish]>} [defaultPurses]
* @property {Array<[Bigish, Bigish]>} [tradesGivenCentral]
*/
Expand Down Expand Up @@ -70,7 +72,8 @@ const fromCosmosIssuerEntries = [
'BLD',
{
issuerArgs: [undefined, { decimalPlaces: 6 }],
defaultPurses: [['Agoric staking token', scaleMicro(73)]],
bankDenom: 'ubld',
bankPurse: 'Agoric staking token',
collateralConfig: {
keyword: 'BLD',
collateralValue: scaleMicro(1000000n),
Expand Down
13 changes: 11 additions & 2 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function buildRootObject(_vatPowers) {
* @typedef {Object} AssetDescriptor
* @property {Brand} brand
* @property {Issuer} issuer
* @property {string} issuerName
* @property {string} denom
* @property {string} proposedName
*/
Expand All @@ -134,11 +135,13 @@ export function buildRootObject(_vatPowers) {
* Add an asset to the bank, and publish it to the subscriptions.
*
* @param {string} denom lower-level denomination string
* @param {string} issuerName
* @param {string} proposedName
* @param {IssuerKit} kit ERTP issuer kit (mint, brand, issuer)
*/
async addAsset(denom, proposedName, kit) {
async addAsset(denom, issuerName, proposedName, kit) {
assert.typeof(denom, 'string');
assert.typeof(issuerName, 'string');
assert.typeof(proposedName, 'string');

const brand = await kit.brand;
Expand All @@ -153,7 +156,13 @@ export function buildRootObject(_vatPowers) {
brandToAssetRecord.init(brand, assetRecord);
denomToAddressUpdater.init(denom, makeStore('address'));
assetPublication.updateState(
harden({ brand, denom, issuer: kit.issuer, proposedName }),
harden({
brand,
denom,
issuerName,
issuer: kit.issuer,
proposedName,
}),
);
},
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/test/test-vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test('communication', async t => {
let itResult;
const p = it.next().then(r => (itResult = r));
t.is(itResult, undefined);
await E(bankMgr).addAsset('ubld', 'BLD Staking Tokens', kit);
await E(bankMgr).addAsset('ubld', 'BLD', 'Staking Tokens', kit);
await p;
t.is(itResult && itResult.done, false);

Expand Down

0 comments on commit 3148b83

Please sign in to comment.