Skip to content

Commit

Permalink
#41 #43 Implemented base contract code for package-3.
Browse files Browse the repository at this point in the history
  • Loading branch information
anilhelvaci committed Nov 29, 2022
1 parent f141c52 commit 96afb17
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
63 changes: 54 additions & 9 deletions contract/src/lendingPool/lendingPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { AmountMath, AssetKind } from '@agoric/ertp';
import { makeTracer } from '@agoric/inter-protocol/src/makeTracer.js';
import { makeScalarMap } from '@agoric/store';
import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
import { makeRatioFromAmounts } from '@agoric/zoe/src/contractSupport/ratio.js';
import {
ceilMultiplyBy,
floorMultiplyBy,
makeRatio,
makeRatioFromAmounts,
} from '@agoric/zoe/src/contractSupport/ratio.js';
import { Far } from '@endo/marshal';
import { LARGE_DENOMINATOR } from '../interest.js';
import { makePoolManager } from './poolManager.js';
Expand Down Expand Up @@ -86,15 +91,49 @@ export const start = async (zcf, privateArgs) => {
liquidationInstall,
loanTimingParams,
compareCurrencyBrand,
governance: {
keyword,
units,
decimals,
committeeSize
},
} = terms;

const { initialPoserInvitation, storageNode, marshaller } = privateArgs;
const electorateParamManager = await makeElectorateParamManager(
E(zcf).getZoeService(),
storageNode,
marshaller,
initialPoserInvitation,
);
const [govMint, electorateParamManager] = await Promise.all([
zcf.makeZCFMint(keyword, AssetKind.NAT, { decimalPlaces: decimals }),
makeElectorateParamManager(
E(zcf).getZoeService(),
storageNode,
marshaller,
initialPoserInvitation,
)
]);

const { brand: govBrand, issuer: govIssuer } = govMint.getIssuerRecord();
const { zcfSeat: govSeat } = zcf.makeEmptySeatKit();
const totalSupply = AmountMath.make(govBrand, units * 10n ** decimals);
const proposalThreshold = ceilMultiplyBy(totalSupply, makeRatio(2n, govBrand));
govMint.mintGains({ [keyword]: totalSupply }, govSeat);
const supplyRatio = makeRatio(1n, govBrand, committeeSize, govBrand);

const makeFetchGovInvitation = () => {
/** @type OfferHandler */
const govFaucet = (committeeMemberSeat) => {
const memberShareAmount = floorMultiplyBy(totalSupply, supplyRatio);
committeeMemberSeat.incrementBy(
govSeat.decrementBy(
harden({ [keyword]: memberShareAmount })
)
);
zcf.reallocate(committeeMemberSeat, govSeat);
committeeMemberSeat.exit();
};

return zcf.makeInvitation(govFaucet, 'Governance Faucet');
};

const governanceInvitations = harden([...Array(committeeSize)].map(makeFetchGovInvitation));

trace('Bootstrap', {
priceManager,
Expand Down Expand Up @@ -316,6 +355,11 @@ export const start = async (zcf, privateArgs) => {
makeDepositInvitation,
getMarkets,
getPoolNotifier: () => poolNotifier,
getGovernanceBrand: () => govBrand,
getGovernanceIssuer: () => govIssuer,
getGovernanceKeyword: () => keyword,
getTotalSupply: () => totalSupply,
getProposalTreshold: () => proposalThreshold,
});

const getParamMgrRetriever = () =>
Expand All @@ -333,13 +377,14 @@ export const start = async (zcf, privateArgs) => {
const lendingPool = Far('lendingPool machine', {
helloFromCreator: () => 'Hello From the creator',
addPoolType,
getGovernanceInvitation: index => governanceInvitations[index],
});

const lendingPoolWrapper = Far('powerful lendingPool wrapper', {
getParamMgrRetriever,
getLimitedCreatorFacet: () => lendingPool,
getGovernedApis: () => harden({}),
getGovernedApiNames: () => harden({}),
getGovernedApis: () => harden({ addPoolType }),
getGovernedApiNames: () => harden(['addPoolType']),
});

return harden({
Expand Down
6 changes: 6 additions & 0 deletions contract/src/lendingPool/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
* @property {Installation} liquidationInstall
* @property {Object} loanTimingParams
* @property {Brand} compareCurrencyBrand
* @property {{
* keyword: String,
* units: BigInt,
* decimals: BigInt,
* committeeSize: BigInt
* }} governance
*/

// Loan
Expand Down

0 comments on commit 96afb17

Please sign in to comment.