Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mfig-unhandled-vow-…
Browse files Browse the repository at this point in the history
…rejection
  • Loading branch information
michaelfig committed Dec 17, 2024
2 parents 5b24b3a + bfca51a commit 664c9d3
Show file tree
Hide file tree
Showing 58 changed files with 3,945 additions and 495 deletions.
1 change: 1 addition & 0 deletions a3p-integration/proposals/p:upgrade-19/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ upgradeProvisionPool/
upgradeAgoricNames/
publishTestInfo/
upgrade-mintHolder/
upgradeAssetReserve/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"consume": {
"contractKits": true,
"zoe": true,
"agoricNames": true,
"reserveKit": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @ts-nocheck
/* eslint-disable no-undef */

const addCollateral = async powers => {
const {
consume: {
contractKits: contractKitsP,
reserveKit: reserveKitP,
zoe,
agoricNames,
},
} = powers;

const [contractKits, reserveKit, usdLemonsIssuer, usdLemonsBrand] =
await Promise.all([
contractKitsP,
reserveKitP,
E(agoricNames).lookup('issuer', 'USD_LEMONS'),
E(agoricNames).lookup('brand', 'USD_LEMONS'),
]);

console.log('[CONTRACT_KITS]', contractKits);
console.log('[ISSUER]', usdLemonsIssuer);

const { governorCreatorFacet } = reserveKit;

const arPublicFacet = await E(governorCreatorFacet).getPublicFacet();
const arLimitedFacet = await E(governorCreatorFacet).getCreatorFacet();

let usdLemonsMint;
for (const { publicFacet, creatorFacet: mint } of contractKits.values()) {
if (publicFacet === usdLemonsIssuer) {
usdLemonsMint = mint;
console.log('USD_LEMONS found', mint);
break;
}
}

await E(arLimitedFacet).addIssuer(usdLemonsIssuer, 'USD_LEMONS');

console.log('Minting USD_LEMONS');
const amt = harden({ brand: usdLemonsBrand, value: 500000n });
const helloPayment = await E(usdLemonsMint).mintPayment(amt);

console.log('Adding to the reserve...');

const seat = E(zoe).offer(
E(arPublicFacet).makeAddCollateralInvitation(),
harden({
give: { Collateral: amt },
}),
harden({ Collateral: helloPayment }),
);

console.log(await E(seat).getOfferResult());
console.log('Done.');
};

addCollateral;
92 changes: 92 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/assetReserve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-env node */
/**
* @file The goal of this file is to make sure v36-reserve upgraded.
*
* The test scenario is as follows;
* 1. Add asset USD_LEMONS
* 2. Add collateral to the reserve
* 3. Upgrade reserve
* 4. Ensure that the collateral is still in the reserve
*/

import '@endo/init';
import test from 'ava';
import {
evalBundles,
agd as agdAmbient,
agoric,
getDetailsMatchingVats,
} from '@agoric/synthetic-chain';
import {
makeVstorageKit,
waitUntilContractDeployed,
} from '@agoric/client-utils';

const ADD_PSM_DIR = 'addUsdLemons';
const UPGRADE_AR_DIR = 'upgradeAssetReserve';
const ADD_COLLATERAL = 'addCollateral';

const ambientAuthority = {
query: agdAmbient.query,
follow: agoric.follow,
setTimeout,
log: console.log,
};

/**
* @typedef {import('@agoric/ertp').NatAmount} NatAmount
* @typedef {{
* allocations: { Fee: NatAmount, USD_LEMONS: NatAmount },
* }} ReserveAllocations
*/

test.before(async t => {
const vstorageKit = await makeVstorageKit(
{ fetch },
{ rpcAddrs: ['http://localhost:26657'], chainName: 'agoriclocal' },
);

t.context = {
vstorageKit,
};
});

test.serial('add collatoral to reserve', async t => {
// @ts-expect-error casting
const { vstorageKit } = t.context;

// Introduce USD_LEMONS
await evalBundles(ADD_PSM_DIR);
await waitUntilContractDeployed('psm-IST-USD_LEMONS', ambientAuthority, {
errorMessage: 'psm-IST-USD_LEMONS instance not observed.',
});

await evalBundles(ADD_COLLATERAL);

const metrics = /** @type {ReserveAllocations} */ (
await vstorageKit.readLatestHead('published.reserve.metrics')
);

t.truthy(Object.keys(metrics.allocations).includes('USD_LEMONS'));
t.is(metrics.allocations.USD_LEMONS.value, 500000n);
});

test.serial('upgrade', async t => {
// @ts-expect-error casting
const { vstorageKit } = t.context;

await evalBundles(UPGRADE_AR_DIR);

const vatDetailsAfter = await getDetailsMatchingVats('reserve');
const { incarnation } = vatDetailsAfter.find(vat => vat.vatID === 'v36'); // assetReserve is v36

t.log(vatDetailsAfter);
t.is(incarnation, 1, 'incorrect incarnation');

const metrics = /** @type {ReserveAllocations} */ (
await vstorageKit.readLatestHead('published.reserve.metrics')
);

t.truthy(Object.keys(metrics.allocations).includes('USD_LEMONS'));
t.is(metrics.allocations.USD_LEMONS.value, 500000n);
});
1 change: 1 addition & 0 deletions a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"testing/replace-feeDistributor-short.js replaceFeeDistributor",
"testing/add-USD-LEMONS.js addUsdLemons",
"vats/upgrade-provisionPool.js upgradeProvisionPool",
"vats/upgrade-asset-reserve.js upgradeAssetReserve",
"vats/upgrade-paRegistry.js",
"vats/upgrade-board.js",
"testing/test-upgraded-board.js testUpgradedBoard",
Expand Down
3 changes: 3 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ yarn ava replaceFeeDistributor.test.js
yarn ava upgradedBoard.test.js
yarn ava mintHolder.test.js
yarn ava provisionPool.test.js

yarn ava agoricNames.test.js

yarn ava assetReserve.test.js
2 changes: 2 additions & 0 deletions a3p-integration/proposals/z:acceptance/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ restart-valueVow
start-valueVow
localchaintest-submission
recorded-instances-submission
upgrade-vaultFactory
upgrade-provisionPool
Loading

0 comments on commit 664c9d3

Please sign in to comment.