Skip to content

Commit

Permalink
feat: create feePurse in bootstrap and import to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 17, 2021
1 parent 57815b8 commit 4e9d5b0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default async function deployWallet(
// Claim the payments.
const issuerToPetname = new Map();
const issuerToPursePetnameP = new Map();
const wallet = E(walletVat).getWallet(bank);
const wallet = E(walletVat).getWallet(bank, E(faucet).getFeePurse());
const walletAdmin = E(wallet).getAdminFacet();
await Promise.all(
paymentInfo.map(async ({ issuerPetname, issuer }) => {
Expand Down
32 changes: 23 additions & 9 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ export function makeWallet({
const { brand } = await recP;
if (!issuerToBoardId.has(issuer)) {
const issuerBoardId = await E(board).getId(issuer);
issuerToBoardId.init(issuer, issuerBoardId);
if (!issuerToBoardId.has(issuer)) {
issuerToBoardId.init(issuer, issuerBoardId);
}
}
const addBrandPetname = () => {
let p;
Expand All @@ -603,11 +605,12 @@ export function makeWallet({
} else {
p = Promise.resolve();
}
return p.then(
_ => `issuer ${q(petnameForBrand)} successfully added to wallet`,
);
return p.then(_ => petnameForBrand);
};
return addBrandPetname().then(updateAllIssuersState);
return addBrandPetname().then(async brandName => {
await updateAllIssuersState();
return brandName;
});
};

const publishIssuer = async brand => {
Expand All @@ -616,7 +619,9 @@ export function makeWallet({
return issuerToBoardId.get(issuer);
}
const issuerBoardId = await E(board).getId(issuer);
issuerToBoardId.init(issuer, issuerBoardId);
if (!issuerToBoardId.has(issuer)) {
issuerToBoardId.init(issuer, issuerBoardId);
}
updateAllIssuersState();
return issuerBoardId;
};
Expand Down Expand Up @@ -1439,7 +1444,9 @@ export function makeWallet({
const { brand, issuer } = await brandTable.initIssuer(issuerP);
if (!issuerToBoardId.has(issuer)) {
const issuerBoardId = await E(board).getId(issuer);
issuerToBoardId.init(issuer, issuerBoardId);
if (!issuerToBoardId.has(issuer)) {
issuerToBoardId.init(issuer, issuerBoardId);
}
}
brandMapping.suggestPetname(petname, brand);
await updateAllIssuersState();
Expand Down Expand Up @@ -1613,11 +1620,11 @@ export function makeWallet({
// We don't want to expose this mechanism to the user, in case they shoot
// themselves in the foot with it by importing an asset/virtual purse they
// don't really trust.
const importBankAssets = async bank => {
const importBankAssets = async (bank, feePurseP) => {
observeIteration(E(bank).getAssetSubscription(), {
async updateState({ proposedName, issuerName, issuer, brand }) {
try {
await addIssuer(issuerName, issuer);
issuerName = await addIssuer(issuerName, issuer);
const purse = await E(bank).getPurse(brand);
// We can import this purse, because we trust the bank.
await internalUnsafeImportPurse(
Expand All @@ -1636,6 +1643,13 @@ export function makeWallet({
}
},
}).finally(() => console.error('/// This is the end of the bank assets'));
if (!feePurseP) {
return;
}
const feePurse = await feePurseP;
const feeIssuer = await E(zoe).getFeeIssuer();
const issuerName = await addIssuer('RUN', feeIssuer);
await internalUnsafeImportPurse(issuerName, 'Zoe fees', false, feePurse);
};
return { admin: wallet, initialized: initialize(), importBankAssets };
}
6 changes: 2 additions & 4 deletions packages/dapp-svelte-wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,8 @@ export function buildRootObject(_vatPowers) {
});
harden(preapprovedBridge);

async function getWallet(bank) {
if (bank) {
walletRoot.importBankAssets(bank);
}
async function getWallet(bank, feePurse) {
await walletRoot.importBankAssets(bank, feePurse);

/**
* This is the complete wallet, including the means to get the
Expand Down
20 changes: 13 additions & 7 deletions packages/vats/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function buildRootObject(vatPowers, vatParameters) {
E(vats.priceAuthority).makePriceAuthority(),
]);

const zoeWPurse = E(zoe).bindDefaultFeePurse(feeCollectionPurse);
const zoeWUnlimitedPurse = E(zoe).bindDefaultFeePurse(feeCollectionPurse);

const {
nameHub: agoricNames,
Expand Down Expand Up @@ -161,7 +161,7 @@ export function buildRootObject(vatPowers, vatParameters) {
chainTimerService,
nameAdmins,
priceAuthority,
zoeWPurse,
zoeWPurse: zoeWUnlimitedPurse,
bootstrapPaymentValue,
feeMintAccess,
}),
Expand All @@ -170,7 +170,7 @@ export function buildRootObject(vatPowers, vatParameters) {
board,
nameAdmins,
namesByAddress,
zoeWPurse,
zoeWPurse: zoeWUnlimitedPurse,
}),
]);
return treasuryCreator;
Expand Down Expand Up @@ -232,7 +232,7 @@ export function buildRootObject(vatPowers, vatParameters) {
E(vats.distributeFees)
.buildDistributor(
E(vats.distributeFees).makeTreasuryFeeCollector(
zoeWPurse,
zoeWUnlimitedPurse,
treasuryCreator,
),
feeCollectorDepositFacet,
Expand Down Expand Up @@ -393,7 +393,7 @@ export function buildRootObject(vatPowers, vatParameters) {
const paymentKeywords = harden({
Collateral: payment,
});
const seat = E(zoeWPurse).offer(
const seat = E(zoeWUnlimitedPurse).offer(
addTypeInvitation,
proposal,
paymentKeywords,
Expand Down Expand Up @@ -430,7 +430,7 @@ export function buildRootObject(vatPowers, vatParameters) {

const [ammPublicFacet, pegasus] = await Promise.all(
[ammInstance, pegasusInstance].map(instance =>
E(zoeWPurse).getPublicFacet(instance),
E(zoeWUnlimitedPurse).getPublicFacet(instance),
),
);
await addAllCollateral();
Expand Down Expand Up @@ -658,11 +658,17 @@ export function buildRootObject(vatPowers, vatParameters) {
}),
);

const userFeePurse = await E(zoe).makeFeePurse();
const zoeWUserFeePurse = await E(zoe).bindDefaultFeePurse(userFeePurse);

const faucet = Far('faucet', {
// A method to reap the spoils of our on-chain provisioning.
async tapFaucet() {
return faucetPaymentInfo;
},
getFeePurse() {
return userFeePurse;
},
});

// Create a name hub for this address.
Expand Down Expand Up @@ -693,7 +699,7 @@ export function buildRootObject(vatPowers, vatParameters) {
namesByAddress,
priceAuthority,
board,
zoe,
zoe: zoeWUserFeePurse,
});

return bundle;
Expand Down

0 comments on commit 4e9d5b0

Please sign in to comment.