diff --git a/packages/deploy-script-support/test/unitTests/test-startInstance.js b/packages/deploy-script-support/test/unitTests/test-startInstance.js index 43059473921..fd048dcb50f 100644 --- a/packages/deploy-script-support/test/unitTests/test-startInstance.js +++ b/packages/deploy-script-support/test/unitTests/test-startInstance.js @@ -35,6 +35,8 @@ test('startInstance', async t => { const zoeInvitationIssuer = E(zoe).getInvitationIssuer(); const zoeInvitationPurse = E(zoeInvitationIssuer).makeEmptyPurse(); + /** @type {import('../../src/startInstance.js').IssuerManager} */ + // @ts-expect-error cast mock const issuerManager = { get: petname => { if (petname === MOOLA_BRAND_PETNAME) { @@ -47,10 +49,15 @@ test('startInstance', async t => { }, }; + /** @type {Petname=} */ let addedPetname; + /** @type {import('../../src/startInstance.js').InstanceManager} */ + // @ts-expect-error cast mock const instanceManager = { - add: (petname, _instance) => (addedPetname = petname), + add: async (petname, _instance) => { + addedPetname = petname; + }, }; const startInstance = makeStartInstance( diff --git a/packages/run-protocol/src/proposals/econ-behaviors.js b/packages/run-protocol/src/proposals/econ-behaviors.js index b9896c8ed71..501fd24a654 100644 --- a/packages/run-protocol/src/proposals/econ-behaviors.js +++ b/packages/run-protocol/src/proposals/econ-behaviors.js @@ -601,7 +601,7 @@ export const startRewardDistributor = async ({ brand: centralBrand, }) .catch(e => { - console.log('Cannot create fee collector deposit facet', e); + console.error('Cannot create fee collector deposit facet', e); return undefined; }); diff --git a/packages/run-protocol/src/runStake/runStakeManager.js b/packages/run-protocol/src/runStake/runStakeManager.js index ba7cf8d3505..d4a2c70558d 100644 --- a/packages/run-protocol/src/runStake/runStakeManager.js +++ b/packages/run-protocol/src/runStake/runStakeManager.js @@ -6,7 +6,7 @@ import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js'; import { fit, getCopyBagEntries, M } from '@agoric/store'; import { makeNotifierKit, observeNotifier } from '@agoric/notifier'; import { E } from '@endo/far'; -import { defineKindMulti, partialAssign } from '@agoric/vat-data'; +import { defineKindMulti } from '@agoric/vat-data'; import { makeTracer } from '../makeTracer.js'; import { chargeInterest } from '../interest.js'; import { ManagerKW as KW } from './constants.js'; @@ -162,7 +162,9 @@ const helper = { }, updateTime, ); - partialAssign(state, changes); + state.compoundedInterest = changes.compoundedInterest; + state.latestInterestUpdate = changes.latestInterestUpdate; + state.totalDebt = changes.totalDebt; const payload = harden({ compoundedInterest: state.compoundedInterest, diff --git a/packages/run-protocol/src/vaultFactory/liquidation.js b/packages/run-protocol/src/vaultFactory/liquidation.js index cd92db128ff..b3089d7605c 100644 --- a/packages/run-protocol/src/vaultFactory/liquidation.js +++ b/packages/run-protocol/src/vaultFactory/liquidation.js @@ -8,25 +8,6 @@ import { makeTracer } from '../makeTracer.js'; const trace = makeTracer('LIQ', false); -/** - * - * @param {Amount<'nat'>} debt - * @param {Amount<'nat'>} proceeds - */ -const discrepancy = (debt, proceeds) => { - if (AmountMath.isGTE(debt, proceeds)) { - return { - overage: AmountMath.makeEmptyFromAmount(debt), - shortfall: AmountMath.subtract(debt, proceeds), - }; - } else { - return { - overage: AmountMath.subtract(proceeds, debt), - shortfall: AmountMath.makeEmptyFromAmount(debt), - }; - } -}; - /** * Liquidates a Vault, using the strategy to parameterize the particular * contract being used. The strategy provides a KeywordMapping and proposal @@ -86,7 +67,15 @@ const liquidate = async ( ]); // NB: all the proceeds from AMM sale are on the vault seat instead of a staging seat - const { shortfall, overage } = discrepancy(debt, proceeds.RUN); + const [overage, shortfall] = AmountMath.isGTE(debt, proceeds.RUN) + ? [ + AmountMath.makeEmptyFromAmount(debt), + AmountMath.subtract(debt, proceeds.RUN), + ] + : [ + AmountMath.subtract(proceeds.RUN, debt), + AmountMath.makeEmptyFromAmount(debt), + ]; const runToBurn = AmountMath.min(proceeds.RUN, debt); trace('before burn', { debt, proceeds, overage, shortfall, runToBurn }); diff --git a/packages/run-protocol/src/vaultFactory/prioritizedVaults.js b/packages/run-protocol/src/vaultFactory/prioritizedVaults.js index 7fb472c6b31..43a2228dbd5 100644 --- a/packages/run-protocol/src/vaultFactory/prioritizedVaults.js +++ b/packages/run-protocol/src/vaultFactory/prioritizedVaults.js @@ -8,6 +8,9 @@ import { Far } from '@endo/marshal'; import { keyEQ, keyLT } from '@agoric/store'; import { makeOrderedVaultStore } from './orderedVaultStore.js'; import { toVaultKey } from './storeUtils.js'; +import { makeTracer } from '../makeTracer.js'; + +const trace = makeTracer('PV'); /** @typedef {import('./vault').Vault} Vault */ @@ -99,7 +102,7 @@ export const makePrioritizedVaults = (reschedulePriceCheck = () => {}) => { // don't call reschedulePriceCheck, but do reset the highest. // This could be expensive if we delete individual entries in // order. Will know once we have perf data. - console.log('removeVault', firstKey, key); + trace('removeVault', firstKey, key); if (keyEQ(key, firstKey)) { const [secondKey] = vaults.keys(); firstKey = secondKey; @@ -125,7 +128,7 @@ export const makePrioritizedVaults = (reschedulePriceCheck = () => {}) => { */ const addVault = (vaultId, vault) => { const key = vaults.addVault(vaultId, vault); - console.log('addVault', firstKey, key); + trace('addVault', firstKey, key); if (!firstKey || keyLT(key, firstKey)) { firstKey = key; reschedulePriceCheck(); diff --git a/packages/run-protocol/src/vaultFactory/vaultManager.js b/packages/run-protocol/src/vaultFactory/vaultManager.js index 8b54142aeb1..ca07a14eb01 100644 --- a/packages/run-protocol/src/vaultFactory/vaultManager.js +++ b/packages/run-protocol/src/vaultFactory/vaultManager.js @@ -21,7 +21,7 @@ import { } from '@agoric/notifier'; import { AmountMath } from '@agoric/ertp'; -import { defineKindMulti, partialAssign, pickFacet } from '@agoric/vat-data'; +import { defineKindMulti, pickFacet } from '@agoric/vat-data'; import { makeVault } from './vault.js'; import { makePrioritizedVaults } from './prioritizedVaults.js'; import { liquidate } from './liquidation.js'; @@ -232,7 +232,7 @@ const helperBehavior = { // Update state with the results of charging interest - const stateUpdates = chargeInterest( + const changes = chargeInterest( { mint: state.debtMint, mintAndReallocateWithFee: state.factoryPowers.mintAndReallocate, @@ -255,7 +255,11 @@ const helperBehavior = { }, updateTime, ); - partialAssign(state, stateUpdates); + + state.compoundedInterest = changes.compoundedInterest; + state.latestInterestUpdate = changes.latestInterestUpdate; + state.totalDebt = changes.totalDebt; + facets.helper.assetNotify(); trace('chargeAllVaults complete'); facets.helper.reschedulePriceCheck(); @@ -326,7 +330,7 @@ const helperBehavior = { // eslint-disable-next-line consistent-return return facets.helper .processLiquidations() - .catch(e => console.log('Liquidator failed', e)) + .catch(e => console.error('Liquidator failed', e)) .finally(() => { liquidationInProgress = false; }); @@ -426,7 +430,6 @@ const helperBehavior = { factoryPowers.getGovernedParams().getLiquidationPenalty(), ) .then(accounting => { - console.log('liquidateAndRemove accounting', accounting); state.totalProceedsReceived = AmountMath.add( state.totalProceedsReceived, accounting.proceeds, diff --git a/packages/run-protocol/test/supports.js b/packages/run-protocol/test/supports.js index c10b401f477..b5a5fb2c0f7 100644 --- a/packages/run-protocol/test/supports.js +++ b/packages/run-protocol/test/supports.js @@ -14,6 +14,7 @@ import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; import { makeLoopback } from '@endo/captp'; import { E } from '@endo/far'; +import { makeTracer } from '../src/makeTracer.js'; /** * @param {*} t @@ -60,7 +61,8 @@ export const setUpZoeForTest = (setJig = () => {}) => { harden(setUpZoeForTest); export const setupBootstrap = (t, optTimer = undefined) => { - const space = /** @type {any} */ (makePromiseSpace(t.log)); + const trace = makeTracer('PromiseSpace'); + const space = /** @type {any} */ (makePromiseSpace(trace)); const { produce, consume } = /** @type { import('../src/proposals/econ-behaviors.js').EconomyBootstrapPowers & BootstrapPowers } */ ( space diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index 623bd3b4812..c7d87abfdeb 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -168,3 +168,6 @@ const makeZoeKit = ( }; export { makeZoeKit }; +/** + * @typedef {ReturnType} ZoeKit + */