Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(priceAuthorityTransform): mutable case missed scaleQuote #5614

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const makePriceAuthorityTransform = async ({
makeSourceAmountOut(newAmountOutLimit),
);
},
getPromise: () => E(sourceMutableQuote).getPromise(),
getPromise: () => E(sourceMutableQuote).getPromise().then(scaleQuote),
});
return mutableQuote;
};
Expand Down
81 changes: 81 additions & 0 deletions packages/zoe/test/unitTests/contracts/test-scaledPriceAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,84 @@ test('scaled price authority', /** @param {ExecutionContext} t */ async t => {
},
]);
});

test('mutableQuoteWhenLT: brands in/out match', /** @param {ExecutionContext} t */ async t => {
const timer = buildManualTimer(t.log);
const makeSourcePrice = (valueIn, valueOut) =>
makeRatio(valueOut, t.context.usdBrand, valueIn, t.context.atomBrand);
const sourcePriceAuthority = makeManualPriceAuthority({
actualBrandIn: t.context.atomBrand,
actualBrandOut: t.context.usdBrand,
initialPrice: makeSourcePrice(10n ** 5n, 35_6100n),
timer,
});

const scaledPrice = await E(t.context.zoe).startInstance(
t.context.scaledPriceInstallation,
undefined,
{
sourcePriceAuthority,
scaleIn: makeRatio(
10n ** 5n,
t.context.atomBrand,
10n ** 6n,
t.context.ibcAtom.brand,
),
scaleOut: makeRatio(
10n ** 4n,
t.context.usdBrand,
10n ** 6n,
t.context.run.brand,
),
},
);

const pa = await E(scaledPrice.publicFacet).getPriceAuthority();

const mutableQuote = E(pa).mutableQuoteWhenLT(
AmountMath.make(t.context.ibcAtom.brand, 10n ** 6n),
AmountMath.make(t.context.run.brand, 32_430_100n),
);
const sourceNotifier = E(sourcePriceAuthority).makeQuoteNotifier(
AmountMath.make(t.context.atomBrand, 10n ** 5n),
t.context.usdBrand,
);

const {
value: { quoteAmount: sqa1 },
updateCount: suc1,
} = await E(sourceNotifier).getUpdateSince();
t.deepEqual(sqa1.value, [
{
amountIn: { brand: t.context.atomBrand, value: 10n ** 5n },
amountOut: { brand: t.context.usdBrand, value: 35_6100n },
timer,
timestamp: 0n,
},
]);

await E(timer).tick();
sourcePriceAuthority.setPrice(makeSourcePrice(10n ** 5n, 30_4301n));
const { quoteAmount: qa2 } = await E(mutableQuote).getPromise();
t.deepEqual(qa2.value, [
{
amountIn: { brand: t.context.ibcAtom.brand, value: 1_000_000n },
amountOut: { brand: t.context.run.brand, value: 30_430_100n },
timer,
timestamp: 1n,
},
]);

// check source quote
const {
value: { quoteAmount: sqa2 },
} = await E(sourceNotifier).getUpdateSince(suc1);
t.deepEqual(sqa2.value, [
{
amountIn: { brand: t.context.atomBrand, value: 1_00000n },
amountOut: { brand: t.context.usdBrand, value: 30_4301n },
timer,
timestamp: 1n,
},
]);
});