Skip to content

Commit

Permalink
Merge pull request #5614 from Agoric/5513-brand-mismatch
Browse files Browse the repository at this point in the history
fix(priceAuthorityTransform): mutable case missed scaleQuote
  • Loading branch information
mergify[bot] committed Jun 16, 2022
2 parents 986ae7f + e4df90f commit 373fe5d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
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,
},
]);
});

0 comments on commit 373fe5d

Please sign in to comment.