forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After adding a new asset to Vaults, how is the collateral payment extracted from smart wallet when opening a new vault? #32
Comments
Unit test to track bank purse balance during the flow aboveimport { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import {
makeAgoricNamesRemotesFromFakeStorage,
boardSlottingMarshaller,
} from '@agoric/vats/tools/board-utils.js';
import { slotToRemotable } from '@agoric/internal/src/storage-test-utils.js';
import {
ensureVaultCollateral,
LiquidationTestContext,
makeLiquidationTestContext,
} from '../../tools/liquidation.ts';
const test = anyTest as TestFn<LiquidationTestContext>;
const collateralBrandKey = 'STARS';
const setup = {
vaults: [
{
atom: 15,
ist: 100,
debt: 100.5,
},
],
price: {
starting: 12.34,
trigger: 9.99,
},
};
const marshaller = boardSlottingMarshaller(slotToRemotable);
const printAssets = async (EV, bankManager) => {
const assetSubscriber = await EV(bankManager).getAssetSubscription();
const assetIterator = await EV(assetSubscriber)[Symbol.asyncIterator]();
let isDone = false;
while (!isDone) {
const { value, done } = await EV(assetIterator).next();
console.log('LOG: bank assets ', value.issuerName);
if (done) {
isDone = true;
}
}
};
test.before(async t => {
t.context = await makeLiquidationTestContext(t);
});
test.after.always(t => {
return t.context.shutdown && t.context.shutdown();
});
test.serial('display vbank balance', async t => {
const {
runUtils: { EV },
storage,
setupStartingState,
} = t.context;
// consume required modules from bootstrap
const bankManager = await EV.vat('bootstrap').consumeItem('bankManager');
const agoricNames = await EV.vat('bootstrap').consumeItem('agoricNames');
const namesByAddressAdmin = await EV.vat('bootstrap').consumeItem(
'namesByAddressAdmin',
);
const walletFactoryStartResult = await EV.vat('bootstrap').consumeItem(
'walletFactoryStartResult',
);
const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(storage);
printAssets(EV, bankManager);
await ensureVaultCollateral('STARS', t);
// printAssets(EV, bankManager);
// ToDo: the method above fails
// ERROR: db not initialized
// update STARS priceFeed
await setupStartingState({
collateralBrandKey,
managerIndex: 1,
price: setup.price.starting,
});
// create a personal bank and get STARS virtual purse
const starsBrand = await EV(agoricNames).lookup('brand', 'STARS');
const bank = await EV(bankManager).getBankForAddress('agoric1dummy');
const purse = await EV(bank).getPurse(starsBrand);
// create smartWallet
const [walletPresence, isNew] = await EV(
walletFactoryStartResult.creatorFacet,
).provideSmartWallet('agoric1dummy', bank, namesByAddressAdmin);
// print STARS balance from bank purse and smart wallet
console.log('LOG: purse STARS balance ', await EV(purse).getCurrentAmount());
const walletPublisher = await EV(walletPresence).getPublicTopics();
const subscriber = walletPublisher.current.subscriber;
console.log(
'Log: smartWallet purses',
(await EV(subscriber).getUpdateSince()).value.purses,
);
// build offer to open a new STARS vault
const opts = {
offerId: `open-${collateralBrandKey}-vault1}`,
collateralBrandKey,
wantMinted: setup.vaults[0].ist,
giveCollateral: setup.vaults[0].atom,
};
const offer = Offers.vaults.OpenVault(agoricNamesRemotes, opts);
const offerCapData = marshaller.toCapData(
harden({
method: 'executeOffer',
offer,
}),
);
await EV(walletPresence).handleBridgeAction(offerCapData, true);
// verify Vstorage Data
console.log(
'LOG: Vstorage vaults of manager1',
storage.toStorage({
method: 'children',
args: ['published.vaultFactory.managers.manager1.vaults'],
}),
);
console.log(
'LOG: Vstorage metrics of manager1',
storage.toStorage({
method: 'entries',
args: ['published.vaultFactory.managers.manager1.metrics'],
}),
);
t.pass();
});
|
Jorge-Lopes
changed the title
When adding a new asset to Vaults, from were is the payment extracted when opening a new vault?
After adding a new asset to Vaults, how is the collateral payment extracted from smart wallet when opening a new vault?
Mar 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
The purpose of this question is to understand the process of adding a new asset type to the vaults and then opening a new vault of that collateral. More specifically, in the
bootstrap test environment
, how are the smart wallet provisioned with the required amount of collateral to open a new vault?As a guide for this question, lets use the test-liquidation-1.ts as an example, more specifically the last 2 tests related to the collateral
STARS
.Let's follow the execution flow of adding a new collateral to the vaults, and then open a new vault.
Add new collateral.
When the
ensureVaultCollateral('STARS', t)
function is executed in the test environment, theaddSTARsCollateral
function will be invoked. This function aims to build and deploy a proposal to add a new collateral to the vaults.ref: liquidation.ts
The
starsVaultProposalBuilder
import the proposal builder and pass theinterchainAssetOptions
. Note that thedenom
is declared and not theissuerBoardId
. This will be relevant later.ref: add-STARS.js
The
defaultProposalBuilder
imports thegetManifestForAddAssetToVault
and pass the required arguments.ref: add-collateral-core.js
The
getManifestForAddAssetToVault
will assert which manifest should be executed based on theinterchainAssetOptions
, as mentioned above, and in this case, thepublishInterchainAssetFromBank
is the one that we expect to run.NOTE: at the
produce
section we see thatbankMints
andvBankKits
and being produced. I cannot find other references to these capabilities.ref: addAssetToVault.js
The
publishInterchainAssetFromBank
will create a newissuerKit
with themintHolder
contract and pass that kit as argument to theaddAsset
method ofbankManager
ref: addAssetToVault.js
The
addAsset
will create an escrow purse from thekit.issuer
provided above and deposits a payment into it.Note: I cannot identify where was that payment created, and if I try to print its amount it will trigger an error. Although, when I print the purse balance after the deposit, it will show 0 STARS.
The
addAsset
will then declareprivateAssetRecord
andtoPublish
objects. Where they will be used to initialise thebrandToAssetRecord
andbrandToAssetDescriptor
respectively.Note: the
brandToAssetRecord
is used at thegetPurse
method ofbank
.Finally, if there's a nameAdmin, it updates with the settled issuer identity.
ref: vat-bank.js
Open new vault
At the test environment, the
makeLiquidationTestKit
export a method calledsetupVaults
. This method will use the consumedwalletFactoryDriver
to create aSmartWallet
with the address agoric1minter.Then It will use the
executeOfferMaker
method of the smart wallet to give the instructions to open a new vault.Note: for now, lets focus on how did this wallet got the funds to open the vault.
ref: liquidation.ts
The
provideSmartWallet
atdrivers.ts
abank
will be created, passing as argument togetBankForAddress
the wallet address.The getBankForAddress will create a new bank, initialise it in the
addressToBank
and return it.ref: drivers.ts
The method above will call
provideSmartWallet
from thewalletFactory
, which will use the bank object to make a new smart wallet and return it.ref: walletFactory.js
At
makeSmartWallet
, themakeWalletWithResolvedStorageNodes
is anExoClassKit
that holds all the facets belonging to the smart wallet and has stored in its state, thebank
passed before.Note: this function will only return the
self
facet.ref: smartWallet.js
At
provideSmartWallet
, after making the new smart wallet, thepublishDepositFacet
is called. This method will use thenamesByAddressAdmin
passed by thedrivers
to associate the wallet address with itsdeposit
facet.Note: did not identified yet the purpose of this step
ref: walletFactory.js
At the
provideSmartWallet
of drivers.js, after receiving the new smart wallet, the makeWalletDriver method will wrap the wallet around new methods and return it.Note: the only method that seems to be executed in this flow is
executeOfferMaker
getPurse
The text was updated successfully, but these errors were encountered: