Skip to content

Commit

Permalink
chore(mintHolder): add mintHolder null upgrade core-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Lopes committed Dec 12, 2024
1 parent 02fde3c commit 6ef9705
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 1 deletion.
2 changes: 1 addition & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"vats/upgrade-agoricNames.js agoricNamesCoreEvals/upgradeAgoricNames",
"testing/add-USD-OLIVES.js agoricNamesCoreEvals/addUsdOlives",
"testing/publish-test-info.js agoricNamesCoreEvals/publishTestInfo",
"vats/upgrade-mintHolder.js upgrade-mintHolder USDC_axl USDT_grv DAI_axl DAI_grv stATOM USDC_grv ATOM USDT_axl USDC BLD IST"
"vats/upgrade-mintHolder.js upgrade-mintHolder A3P_INTEGRATION"
]
},
"type": "module",
Expand Down
24 changes: 24 additions & 0 deletions golang/cosmos/app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ func replacePriceFeedsCoreProposal(upgradeName string) (vm.CoreProposalStep, err
)
}

// func upgradeMintHolderCoreProposal(upgradeName string) (vm.CoreProposalStep, error) {
// variant := getVariantFromUpgradeName(upgradeName)

// if variant == "" {
// return nil, nil
// }

// return buildProposalStepWithArgs(
// "@agoric/builders/scripts/vats/upgrade-mintHolder.js",
// "defaultProposalBuilder",
// map[string]any{
// "variant": variant,
// },
// )
// }

// unreleasedUpgradeHandler performs standard upgrade actions plus custom actions for the unreleased upgrade.
func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
Expand Down Expand Up @@ -216,6 +232,14 @@ func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Conte

// CoreProposals for Upgrade 19. These should not be introduced
// before upgrade 18 is done because they would be run in n:upgrade-next
//
// upgradeMintHolderStep, err := upgradeMintHolderCoreProposal(targetUpgrade)
// if err != nil {
// return nil, err
// } else if upgradeMintHolderStep != nil {
// CoreProposalSteps = append(CoreProposalSteps, upgradeMintHolderStep)
// }
//
// CoreProposalSteps = append(CoreProposalSteps,
// vm.CoreProposalStepForModules(
// "@agoric/builders/scripts/inter-protocol/replace-feeDistributor.js",
Expand Down
126 changes: 126 additions & 0 deletions packages/builders/scripts/vats/upgrade-mintHolder.js
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 packages/vats/src/proposals/upgrade-mintHolder-proposal.js
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 },
});

0 comments on commit 6ef9705

Please sign in to comment.