Skip to content

Commit

Permalink
#41 #42 Test setup for integrating governance to the existing Lending…
Browse files Browse the repository at this point in the history
…Pool protocol is done.
  • Loading branch information
anilhelvaci committed Nov 30, 2022
1 parent 8218d9b commit 3d463f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 23 deletions.
1 change: 0 additions & 1 deletion contract/src/governance/lendingPoolElectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const start = async (zcf, privateArgs) => {
} = await E(zoe).startInstance(
governedContractInstallation,
governedIssuerKeywordRecord,
// @ts-expect-error XXX governance types
augmentedTerms,
privateArgs.governed,
);
Expand Down
67 changes: 47 additions & 20 deletions contract/test/lendingPool/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const CONTRACT_ROOTS = {
LendingPool: '../../src/lendingPool/lendingPool.js',
amm: '@agoric/inter-protocol/src/vpool-xyk-amm/multipoolMarketMaker.js',
reserve: '@agoric/inter-protocol/src/reserve/assetReserve.js',
lendingPoolElectorate: '../../src/governance/lendingPoolElectorate.js',
lendingPoolElectionManager: '../../src/governance/lendingPoolElectionManager.js',
};

/**
Expand Down Expand Up @@ -98,6 +100,11 @@ export const setupServices = async (
} = space;
iProduce.LendingPool.resolve(t.context.installations.LendingPool);
iProduce.liquidate.resolve(t.context.installations.liquidate);
iProduce.lendingPoolElectorate.resolve(t.context.installations.lendingPoolElectorate);
iProduce.lendingPoolElectionManager.resolve(t.context.installations.lendingPoolElectionManager);

await setupLendinPoolElectorate(space);

/** @type PriceManager*/
const priceManager = makePriceManager({});
produce.priceManager.resolve(priceManager);
Expand Down Expand Up @@ -171,15 +178,15 @@ export const startLendingPool = async (
chainTimerService,
priceManager: priceManagerP,
zoe,
economicCommitteeCreatorFacet: electorateCreatorFacet,
lendingPoolElectorateCreatorFacet, // lendingPoolElectorate
},
produce, // { loanFactoryCreator }
brand: {
consume: { [COMPARE_CURRENCY_ISSUER_NAME]: compareBrandP },
},
instance,
installation: {
consume: { LendingPool, liquidate, contractGovernor },
consume: { LendingPool, liquidate, lendingPoolElectionManager },
},
},
{
Expand All @@ -198,7 +205,7 @@ export const startLendingPool = async (
liquidate,
});

const poserInvitationP = E(electorateCreatorFacet).getPoserInvitation();
const poserInvitationP = E(lendingPoolElectorateCreatorFacet).getElectorateFacetInvitation();
const [initialPoserInvitation, invitationAmount] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
Expand All @@ -223,12 +230,12 @@ export const startLendingPool = async (

const [
ammInstance,
electorateInstance,
contractGovernorInstall,
lendingPoolElectorateInstance,
lendingPoolElectionManagerInstall,
] = await Promise.all([
instance.consume.amm,
instance.consume.economicCommittee,
contractGovernor,
instance.consume.lendingPoolElectorate, // lendingPoolElectorate
lendingPoolElectionManager, // lendingPoolElectionManager
]);

const ammPublicFacet = await E(zoe).getPublicFacet(ammInstance);
Expand Down Expand Up @@ -257,41 +264,36 @@ export const startLendingPool = async (

const governorTerms = harden({
timer,
electorateInstance,
lendingPoolElectorateInstance,
governedContractInstallation: installations.LendingPool,
governed: {
terms: loanFactoryTerms,
issuerKeywordRecord: {},
},
});
const { creatorFacet: governorCreatorFacet, instance: governorInstance } =
const { creatorFacet: lendingPoolElectionMgrCreatorFacet, instance: lendingPoolElectionMgrInstance } =
await E(zoe).startInstance(
contractGovernorInstall,
lendingPoolElectionManagerInstall,
undefined,
governorTerms,
harden({
electorateCreatorFacet, governed: {
governed: {
initialPoserInvitation, storageNode, marshaller,
},
}),
);

const [lendingPoolInstance, lendingPoolCreator] = await Promise.all([
E(governorCreatorFacet).getInstance(),
E(governorCreatorFacet).getCreatorFacet(),
E(lendingPoolElectionMgrCreatorFacet).getInstance(),
E(lendingPoolElectionMgrCreatorFacet).getCreatorFacet(),
]);

const voteCreator = Far('lendingPool vote creator', {
voteOnParamChanges: E(governorCreatorFacet).voteOnParamChanges,
});

produce.lendingPoolCreator.resolve(lendingPoolCreator);
produce.lendingPoolGovernorCreator.resolve(governorCreatorFacet);
produce.lendingPoolVoteCreator.resolve(voteCreator);
produce.lendingPoolGovernorCreator.resolve(lendingPoolElectionMgrCreatorFacet);

// Advertise the installations, instances in agoricNames.
instance.produce.lendingPool.resolve(lendingPoolInstance);
instance.produce.lendingPoolGovernor.resolve(governorInstance);
instance.produce.lendingPoolGovernor.resolve(lendingPoolElectionMgrInstance);
};

harden(startLendingPool)
Expand Down Expand Up @@ -390,6 +392,31 @@ export const setupAmmAndElectorate = async (

harden(setupAmmAndElectorate);

const setupLendinPoolElectorate = async (
{
consume: {
zoe,
},
produce,
installation: {
consume: { lendingPoolElectorate },
},
instance: {
produce: instanceProduce
}
}) => {

const {
creatorFacet: lendingPoolElectorateCreatorFacet,
instance: lendingPoolElectorateInstance
} = await E(zoe).startInstance(lendingPoolElectorate);

instanceProduce.lendingPoolElectorate.resolve(lendingPoolElectorateInstance);
produce.lendingPoolElectorateCreatorFacet.resolve(lendingPoolElectorateCreatorFacet);


};

/**
*
* @param t
Expand Down
12 changes: 10 additions & 2 deletions contract/test/lendingPool/test-expandedLendingPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test.before(async t => {
LendingPool: bundleCache.load(await getPath(CONTRACT_ROOTS.LendingPool), 'lendingPool'),
amm: bundleCache.load(await getPath(CONTRACT_ROOTS.amm), 'amm'),
reserve: bundleCache.load(await getPath(CONTRACT_ROOTS.reserve), 'reserve'),
lendingPoolElectorate: bundleCache.load(await getPath(CONTRACT_ROOTS.lendingPoolElectorate), 'lendingPoolElectorate'),
lendingPoolElectionManager: bundleCache.load(await getPath(CONTRACT_ROOTS.lendingPoolElectionManager), 'lendingPoolElectionManager'),
});
const installations = objectMap(bundles, bundle => E(farZoeKit.zoe).install(bundle));

Expand Down Expand Up @@ -100,7 +102,7 @@ test('initial', async t => {
});

/**
* Scenario - 1
* Governance Token
* - Start the contract with the contract with the gov token data in the terms
* - Check govSeat allocations
* - Alice uses inv 0 to fetch some gov tokens. Assert;
Expand All @@ -112,7 +114,7 @@ test('initial', async t => {
* Try to get an invitation with an index greater than the committee size. Assert;
* - Should throw
*/
test('scenario-1', async t => {
test('governance-token', async t => {
const {
lendingPool: {
lendingPoolPublicFacet,
Expand Down Expand Up @@ -177,3 +179,9 @@ test('scenario-1', async t => {

});

test('add-new-pool-with-governance-voting', async t => {
const services = await setupServices(t);
console.log('services', services);
t.is('is', 'is');
});

0 comments on commit 3d463f2

Please sign in to comment.