-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(mintHolder): add mintHolder null upgrade core-eval
- Loading branch information
1 parent
02fde3c
commit 6ef9705
Showing
4 changed files
with
225 additions
and
1 deletion.
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
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,126 @@ | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
import { getManifestForUpgradingMintHolder } from '@agoric/vats/src/proposals/upgrade-mintHolder-proposal.js'; | ||
|
||
const configurations = { | ||
A3P_INTEGRATION: { | ||
labelList: [ | ||
'USDC_axl', | ||
'USDT_grv', | ||
'DAI_axl', | ||
'DAI_grv', | ||
'stATOM', | ||
'USDC_grv', | ||
'ATOM', | ||
'USDT_axl', | ||
'USDC', | ||
'BLD', | ||
], | ||
}, | ||
MAINNET: { | ||
labelList: [ | ||
'USDT', | ||
'USDT_axl', | ||
'USDT_grv', | ||
'USDC', | ||
'USDC_axl', | ||
'USDC_grv', | ||
'DAI_axl', | ||
'DAI_grv', | ||
'ATOM', | ||
'stATOM', | ||
'stkATOM', | ||
'stTIA', | ||
'stOSMO', | ||
], | ||
}, | ||
DEVNET: { | ||
labelList: [ | ||
'stATOM3', | ||
'stATOM', | ||
'dATOM', | ||
'stOSMO', | ||
'stkATOM', | ||
'stATOM2', | ||
'STOSMO', | ||
'stTIA', | ||
'ATOM', | ||
'AUSD', | ||
'USDT_grv', | ||
'USDC_axl', | ||
'USDC_grv', | ||
'USDT_axl', | ||
'BLD', | ||
], | ||
}, | ||
EMERYNET: { | ||
labelList: [ | ||
'ATOM', | ||
'USDT', | ||
'DAI_axl', | ||
'DAI_grv', | ||
'USDC_axl', | ||
'stOSMO', | ||
'stATOM', | ||
'stkATOM', | ||
'stOSMO2', | ||
'ToyUSD', | ||
'BLD', | ||
], | ||
}, | ||
}; | ||
|
||
const { keys } = Object; | ||
const knownVariants = keys(configurations); | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */ | ||
export const defaultProposalBuilder = async ({ publishRef, install }, opts) => { | ||
const config = opts.config || configurations[opts.variant]; | ||
if (!config) { | ||
const error = `Unknown variant "${opts.variant}". Expected one of ${knownVariants.join(', ')}`; | ||
console.error(error); | ||
throw Error(error); | ||
} | ||
const { labelList } = config; | ||
|
||
return harden({ | ||
sourceSpec: '@agoric/vats/src/proposals/upgrade-mintHolder-proposal.js', | ||
getManifestCall: [ | ||
getManifestForUpgradingMintHolder.name, | ||
{ | ||
labelList, | ||
contractRef: publishRef(install('@agoric/vats/src/mintHolder.js')), | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const Usage = `agoric run upgrade-mintHolder.js ${[...knownVariants, '<json-config>'].join(' | ')}`; | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */ | ||
export default async (homeP, endowments) => { | ||
const { scriptArgs } = endowments; | ||
const variantOrConfig = scriptArgs?.[0]; | ||
console.log('upgrade-mintHolder', variantOrConfig); | ||
|
||
const opts = {}; | ||
|
||
if (typeof variantOrConfig === 'string') { | ||
if (variantOrConfig[0] === '{') { | ||
try { | ||
opts.config = JSON.parse(variantOrConfig); | ||
} catch (err) { | ||
throw Error(`Failed to parse config argument ${variantOrConfig}`); | ||
} | ||
} else { | ||
opts.variant = variantOrConfig; | ||
} | ||
} else { | ||
console.error(Usage); | ||
throw Error(Usage); | ||
} | ||
|
||
const { writeCoreEval } = await makeHelpers(homeP, endowments); | ||
await writeCoreEval(`upgrade-mintHolder`, utils => | ||
defaultProposalBuilder(utils, opts), | ||
); | ||
}; |
74 changes: 74 additions & 0 deletions
74
packages/vats/src/proposals/upgrade-mintHolder-proposal.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,74 @@ | ||
import { makeTracer } from '@agoric/internal'; | ||
import { E } from '@endo/far'; | ||
|
||
const trace = makeTracer('upgrade mintHolder', true); | ||
|
||
export const upgradeMintHolder = async ( | ||
{ | ||
consume: { | ||
contractKits: contractKitsP, | ||
instancePrivateArgs: instancePrivateArgsP, | ||
}, | ||
}, | ||
options, | ||
) => { | ||
const { contractRef, labelList } = options.options; | ||
assert(contractRef.bundleID, 'mintHolder bundleID not found'); | ||
assert(labelList, 'mintHolder bank asset label list not found'); | ||
|
||
trace(`Start mintHolder contract upgrade`); | ||
trace(`Assets: `, labelList); | ||
|
||
const [contractKits, instancePrivateArgs] = await Promise.all([ | ||
contractKitsP, | ||
instancePrivateArgsP, | ||
]); | ||
|
||
for (const assetLabel of labelList) { | ||
const mintHolderKit = Array.from(contractKits.values()).find( | ||
kit => kit.label && kit.label === assetLabel, | ||
); | ||
if (!mintHolderKit) { | ||
console.error( | ||
`ERROR: failed to upgrade ${assetLabel} mintHolder, contractKit not found`, | ||
); | ||
continue; | ||
} | ||
|
||
trace(`${assetLabel} mintHolderKit: `, mintHolderKit); | ||
|
||
const { publicFacet, adminFacet, instance } = mintHolderKit; | ||
|
||
/* | ||
* Ensure that publicFacet holds an issuer by verifying that has | ||
* the makeEmptyPurse method. | ||
*/ | ||
await E(publicFacet).makeEmptyPurse(); | ||
|
||
const privateArgs = instancePrivateArgs.get(instance); | ||
|
||
const upgradeResult = await E(adminFacet).upgradeContract( | ||
contractRef.bundleID, | ||
privateArgs, | ||
); | ||
|
||
trace(`${assetLabel} upgrade result: `, upgradeResult); | ||
} | ||
|
||
trace(`Finished mintHolder contract upgrade`); | ||
}; | ||
|
||
export const getManifestForUpgradingMintHolder = ( | ||
_powers, | ||
{ contractRef, labelList }, | ||
) => ({ | ||
manifest: { | ||
[upgradeMintHolder.name]: { | ||
consume: { | ||
contractKits: true, | ||
instancePrivateArgs: true, | ||
}, | ||
}, | ||
}, | ||
options: { contractRef, labelList }, | ||
}); |