-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: prepare a3p test for vault upgrade
- Loading branch information
1 parent
356e189
commit 6815cce
Showing
10 changed files
with
252 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ | ||
export const defaultProposalBuilder = async ({ publishRef, install }) => | ||
harden({ | ||
sourceSpec: '@agoric/inter-protocol/src/proposals/upgrade-vaults.js', | ||
getManifestCall: [ | ||
'getManifestForUpgradeVaults', | ||
{ | ||
vaultsRef: publishRef( | ||
install( | ||
'@agoric/inter-protocol/src/vaultFactory/vaultFactory.js', | ||
'../bundles/bundle-vaultFactory.js', | ||
), | ||
), | ||
}, | ||
], | ||
}); | ||
|
||
export default async (homeP, endowments) => { | ||
const { writeCoreProposal } = await makeHelpers(homeP, endowments); | ||
await writeCoreProposal('upgrade-vaults', defaultProposalBuilder); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
packages/inter-protocol/src/proposals/upgrade-vaults.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { E } from '@endo/far'; | ||
import { makeNotifierFromAsyncIterable } from '@agoric/notifier'; | ||
import { AmountMath } from '@agoric/ertp/src/index.js'; | ||
import { makeScalarMapStore } from '@agoric/store/src/index.js'; | ||
|
||
// stand-in for Promise.any() which isn't available at this point. | ||
const any = promises => | ||
new Promise((resolve, reject) => { | ||
for (const promise of promises) { | ||
promise.then(resolve); | ||
} | ||
void Promise.allSettled(promises).then(results => { | ||
const rejects = results.filter(({ status }) => status === 'rejected'); | ||
if (rejects.length === results.length) { | ||
// @ts-expect-error TypeScript doesn't know enough | ||
const messages = rejects.map(({ message }) => message); | ||
const aggregate = new Error(messages.join(';')); | ||
// @ts-expect-error TypeScript doesn't know enough | ||
aggregate.errors = rejects.map(({ reason }) => reason); | ||
reject(aggregate); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* @param {import('../../src/proposals/econ-behaviors').EconomyBootstrapPowers} powers | ||
* @param {{ options: { vaultsRef: { bundleID: string } } }} options | ||
*/ | ||
export const upgradeVaults = async (powers, { options }) => { | ||
const { | ||
consume: { | ||
agoricNamesAdmin, | ||
auctioneerKit: auctioneerKitP, | ||
priceAuthority, | ||
vaultFactoryKit, | ||
zoe, | ||
economicCommitteeCreatorFacet: electorateCreatorFacet, | ||
reserveKit, | ||
}, | ||
} = powers; | ||
const { vaultsRef } = options; | ||
const kit = await vaultFactoryKit; | ||
const auctioneerKit = await auctioneerKitP; | ||
const { instance: directorInstance } = kit; | ||
const allBrands = await E(zoe).getBrands(directorInstance); | ||
const { Minted: istBrand, ...vaultBrands } = allBrands; | ||
|
||
const bundleID = vaultsRef.bundleID; | ||
console.log(`upgradeVaults: bundleId`, bundleID); | ||
let installationP; | ||
await null; | ||
if (vaultsRef) { | ||
if (bundleID) { | ||
installationP = E(zoe).installBundleID(bundleID); | ||
await E.when( | ||
installationP, | ||
installation => | ||
E(E(agoricNamesAdmin).lookupAdmin('installation')).update( | ||
'vaultFactory', | ||
installation, | ||
), | ||
err => | ||
console.error(`🚨 failed to update vaultFactory installation`, err), | ||
); | ||
} | ||
} | ||
|
||
const readManagerParams = async () => { | ||
const { publicFacet: directorPF } = kit; | ||
|
||
await null; | ||
|
||
const params = {}; | ||
for (const kwd of Object.keys(vaultBrands)) { | ||
const b = vaultBrands[kwd]; | ||
const subscription = E(directorPF).getSubscription({ | ||
collateralBrand: b, | ||
}); | ||
const notifier = makeNotifierFromAsyncIterable(subscription); | ||
const { value } = await notifier.getUpdateSince(); | ||
params[kwd] = harden({ | ||
brand: b, | ||
debtLimit: value.current.DebtLimit.value, | ||
interestRate: value.current.InterestRate.value, | ||
liquidationMargin: value.current.LiquidationMargin.value, | ||
liquidationPadding: value.current.LiquidationPadding.value, | ||
liquidationPenalty: value.current.LiquidationPenalty.value, | ||
mintFee: value.current.MintFee.value, | ||
}); | ||
} | ||
return params; | ||
}; | ||
const managerParamValues = await readManagerParams(); | ||
|
||
// upgrade the vaultFactory | ||
const upgradeVaultFactory = async () => { | ||
// @ts-expect-error cast XXX privateArgs missing from type | ||
const { privateArgs } = kit; | ||
|
||
const shortfallInvitation = await E( | ||
E.get(reserveKit).creatorFacet, | ||
).makeShortfallReportingInvitation(); | ||
|
||
const poserInvitation = await E( | ||
electorateCreatorFacet, | ||
).getPoserInvitation(); | ||
/** @type {import('../../src/vaultFactory/vaultFactory').VaultFactoryContract['privateArgs']} */ | ||
const newPrivateArgs = harden({ | ||
...privateArgs, | ||
auctioneerInstance: auctioneerKit.instance, | ||
initialPoserInvitation: poserInvitation, | ||
initialShortfallInvitation: shortfallInvitation, | ||
managerParams: managerParamValues, | ||
}); | ||
|
||
const upgradeResult = await E(kit.adminFacet).upgradeContract( | ||
bundleID, | ||
newPrivateArgs, | ||
); | ||
|
||
console.log('upgraded vaultFactory.', upgradeResult); | ||
}; | ||
|
||
// Wait for at least one new price feed to be ready before upgrading Vaults | ||
void E.when( | ||
any( | ||
Object.values(vaultBrands).map(brand => | ||
E(priceAuthority).quoteGiven(AmountMath.make(brand, 10n), istBrand), | ||
), | ||
), | ||
() => upgradeVaultFactory(), | ||
); | ||
|
||
console.log(`upgradeVaults scheduled; waiting for priceFeeds`); | ||
}; | ||
|
||
const t = 'upgradeVaults'; | ||
/** | ||
* Return the manifest, installations, and options for upgrading Vaults. | ||
* | ||
* @param {object} _ign | ||
* @param {any} vaultUpgradeOptions | ||
*/ | ||
export const getManifestForUpgradeVaults = async ( | ||
_ign, | ||
vaultUpgradeOptions, | ||
) => ({ | ||
manifest: { | ||
[upgradeVaults.name]: { | ||
consume: { | ||
agoricNamesAdmin: t, | ||
auctioneerKit: t, | ||
economicCommitteeCreatorFacet: t, | ||
priceAuthority: t, | ||
reserveKit: t, | ||
vaultFactoryKit: t, | ||
board: t, | ||
zoe: t, | ||
}, | ||
}, | ||
}, | ||
options: { ...vaultUpgradeOptions }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.