Skip to content

Commit

Permalink
chore(liquidationVisibility) #4 test multiple vaultManagers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderem49 committed Feb 8, 2024
1 parent 48aaa38 commit 8b2dcd8
Show file tree
Hide file tree
Showing 6 changed files with 562 additions and 39 deletions.
12 changes: 6 additions & 6 deletions packages/inter-protocol/test/liquidationVisibility/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export const assertVaultCurrentDebt = async (t, vault, debt) => {
);
};

export const assertVaultCollateral = async (t, vault, collateralValue) => {
export const assertVaultCollateral = async (t, vault, collateralValue, asset) => {
const collateralAmount = await E(vault).getCollateralAmount();

t.deepEqual(collateralAmount, t.context.aeth.make(collateralValue));
t.deepEqual(collateralAmount, asset.make(collateralValue));
};

export const assertMintedAmount = async (t, vaultSeat, wantMinted) => {
Expand All @@ -94,11 +94,11 @@ export const assertMintedProceeds = async (t, vaultSeat, wantMinted) => {
);
};

export const assertVaultLocked = async (t, vaultNotifier, lockedValue) => {
export const assertVaultLocked = async (t, vaultNotifier, lockedValue, asset) => {
const notification = await E(vaultNotifier).getUpdateSince();
const lockedAmount = notification.value.locked;

t.deepEqual(lockedAmount, t.context.aeth.make(lockedValue));
t.deepEqual(lockedAmount, asset.make(lockedValue));
};

export const assertVaultDebtSnapshot = async (t, vaultNotifier, wantMinted) => {
Expand Down Expand Up @@ -139,15 +139,15 @@ export const assertVaultFactoryRewardAllocation = async (
});
};

export const assertCollateralProceeds = async (t, seat, colWanted) => {
export const assertCollateralProceeds = async (t, seat, colWanted, issuer) => {
const { Collateral: withdrawnCol } = await E(seat).getFinalAllocation();
const proceeds4 = await E(seat).getPayouts();
t.deepEqual(withdrawnCol, colWanted);

const collateralWithdrawn = await proceeds4.Collateral;
t.truthy(
AmountMath.isEqual(
await E(t.context.aeth.issuer).getAmountOf(collateralWithdrawn),
await E(issuer).getAmountOf(collateralWithdrawn),
colWanted,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ const setupBootstrap = async (t, optTimer) => {
* @param {RelativeTime} quoteInterval
* @param {Amount | undefined} unitAmountIn
* @param {Partial<import('../../src/auction/params.js').AuctionParams>} actionParamArgs
* @param {{
* btc: any;
* btcPrice: Ratio;
* btcAmountIn: any;
* } | undefined} extraAssetKit
*/
export const setupElectorateReserveAndAuction = async (
t,
Expand All @@ -461,6 +466,7 @@ export const setupElectorateReserveAndAuction = async (
AuctionStartDelay = 10n,
PriceLockPeriod = 3n,
},
extraAssetKit = undefined,
) => {
const {
zoe,
Expand All @@ -484,21 +490,40 @@ export const setupElectorateReserveAndAuction = async (
// @ts-expect-error scriptedPriceAuthority doesn't actually match this, but manualPriceAuthority does
const aethTestPriceAuthority = Array.isArray(priceOrList)
? makeScriptedPriceAuthority({
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
priceList: priceOrList,
timer,
quoteMint: quoteIssuerKit.mint,
unitAmountIn,
quoteInterval,
})
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
priceList: priceOrList,
timer,
quoteMint: quoteIssuerKit.mint,
unitAmountIn,
quoteInterval,
})
: makeManualPriceAuthority({
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
initialPrice: priceOrList,
timer,
quoteIssuerKit,
});
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
initialPrice: priceOrList,
timer,
quoteIssuerKit,
});

const abtcTestPriceAuthority = extraAssetKit ? (Array.isArray(extraAssetKit.btcPrice)
? makeScriptedPriceAuthority({
actualBrandIn: extraAssetKit.btc.brand,
actualBrandOut: run.brand,
priceList: extraAssetKit.btcPrice,
timer,
quoteMint: quoteIssuerKit.mint,
unitAmountIn: extraAssetKit.btcAmountIn,
quoteInterval,
})
: makeManualPriceAuthority({
actualBrandIn: extraAssetKit.btc.brand,
actualBrandOut: run.brand,
initialPrice: extraAssetKit.btcPrice,
timer,
quoteIssuerKit,
})) : undefined;

const baggage = makeScalarBigMapStore('baggage');
const { priceAuthority: priceAuthorityReg, adminFacet: priceAuthorityAdmin } =
providePriceAuthorityRegistry(baggage);
Expand All @@ -508,6 +533,14 @@ export const setupElectorateReserveAndAuction = async (
run.brand,
);

if (extraAssetKit && abtcTestPriceAuthority) {
await E(priceAuthorityAdmin).registerPriceAuthority(
abtcTestPriceAuthority,
extraAssetKit.btc.brand,
run.brand,
);
}

space.produce.priceAuthority.resolve(priceAuthorityReg);

const auctionParams = {
Expand All @@ -526,5 +559,6 @@ export const setupElectorateReserveAndAuction = async (
priceAuthority: priceAuthorityReg,
priceAuthorityAdmin,
aethTestPriceAuthority,
abtcTestPriceAuthority
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,142 @@ Generated by [AVA](https://avajs.dev).
],
]

## liq-flow-1.1

> Scenario 1.1 Liquidation Visibility Snapshot [Aeth]
> The example below illustrates the schema of the data published there.
>
> See also board marshalling conventions (_to appear_).
[
[
'published.vaultFactory.managers.manager0.liquidations.3600.auctionResult',
{
collateralForReserve: {
brand: Object @Alleged: aEth brand {},
value: 0n,
},
collateralOffered: {
brand: Object @Alleged: aEth brand {},
value: 400n,
},
collateralRemaining: {
brand: Object @Alleged: aEth brand {},
value: 0n,
},
collateralSold: {
brand: Object @Alleged: aEth brand {},
value: 400n,
},
endTime: {
absValue: 3614n,
timerBrand: Object @Alleged: timerBrand {},
},
istTarget: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
mintedProceeds: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
shortfallToReserve: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 0n,
},
},
],
[
'published.vaultFactory.managers.manager0.liquidations.3600.vaults.postAuction',
[],
],
[
'published.vaultFactory.managers.manager0.liquidations.3600.vaults.preAuction',
[
[
'vault0',
{
collateralAmount: {
brand: Object @Alleged: aEth brand {},
value: 400n,
},
debtAmount: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
},
],
],
],
]

> Scenario 1.1 Liquidation Visibility Snapshot [Abtc]
> The example below illustrates the schema of the data published there.
>
> See also board marshalling conventions (_to appear_).
[
[
'published.vaultFactory.managers.manager1.liquidations.3600.auctionResult',
{
collateralForReserve: {
brand: Object @Alleged: aBtc brand {},
value: 0n,
},
collateralOffered: {
brand: Object @Alleged: aBtc brand {},
value: 400n,
},
collateralRemaining: {
brand: Object @Alleged: aBtc brand {},
value: 0n,
},
collateralSold: {
brand: Object @Alleged: aBtc brand {},
value: 400n,
},
endTime: {
absValue: 3614n,
timerBrand: Object @Alleged: timerBrand {},
},
istTarget: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
mintedProceeds: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
shortfallToReserve: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 0n,
},
},
],
[
'published.vaultFactory.managers.manager1.liquidations.3600.vaults.postAuction',
[],
],
[
'published.vaultFactory.managers.manager1.liquidations.3600.vaults.preAuction',
[
[
'vault0',
{
collateralAmount: {
brand: Object @Alleged: aBtc brand {},
value: 400n,
},
debtAmount: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 1680n,
},
},
],
],
],
]

## liq-flow-2a

> Scenario 2 Liquidation Visibility Snapshot
Expand Down
Binary file not shown.
Loading

0 comments on commit 8b2dcd8

Please sign in to comment.