Skip to content

Commit

Permalink
chore(amm): types
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Apr 16, 2022
1 parent d773ba6 commit cad92bb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/run-protocol/src/vpool-xyk-amm/doublePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const publicPrices = prices => {
* @param {() => bigint} getProtocolFeeBP - retrieve governed protocol fee value
* @param {() => bigint} getPoolFeeBP - retrieve governed pool fee value
* @param {ZCFSeat} feeSeat
* @returns {VPoolWrapper<VPoolInternalFacet>}
* @returns {VPoolWrapper<DoublePoolInternalFacet>}
*/
export const makeDoublePool = (
zcf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const start = async (zcf, privateArgs) => {
/**
* @param {Brand} brandIn
* @param {Brand} brandOut
* @returns {VPoolWrapper<unknown>}
* @returns {VPoolWrapper<DoublePoolInternalFacet>}
*/
const provideVPool = (brandIn, brandOut) => {
if (isSecondary(brandIn) && isSecondary(brandOut)) {
Expand All @@ -193,6 +193,7 @@ const start = async (zcf, privateArgs) => {
}

const pool = isSecondary(brandOut) ? getPool(brandOut) : getPool(brandIn);
// @ts-expect-error cast
return pool.getVPool();
};

Expand Down
7 changes: 1 addition & 6 deletions packages/run-protocol/src/vpool-xyk-amm/swap.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// @ts-check

// @ts-ignore
import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';

import '@agoric/zoe/exported.js';
// @ts-ignore
import { AmountMath } from '@agoric/ertp';

/**
* @param {ZCF} zcf
* @param {(brandIn: Brand, brandOut: Brand) => VPoolWrapper<unknown>} provideVPool
* @param {(brandIn: Brand, brandOut: Brand) => VPoolWrapper<DoublePoolInternalFacet>} provideVPool
*/
export const makeMakeSwapInvitation = (zcf, provideVPool) => {
/**
Expand All @@ -32,16 +30,13 @@ export const makeMakeSwapInvitation = (zcf, provideVPool) => {
const maxOut = args.maxOut;
if (maxOut) {
AmountMath.coerce(amountOut.brand, maxOut);
// @ts-ignore
prices = pool.getPriceForOutput(amountIn, maxOut);
}
if (!prices || !AmountMath.isGTE(prices.swapperGets, maxOut)) {
// `amountIn` is not enough to sell for maxOut so just sell it all
// @ts-ignore
prices = pool.getPriceForInput(amountIn, amountOut);
}
assert(amountIn.brand === prices.swapperGives.brand);
// @ts-ignore
return pool.allocateGainsAndLosses(seat, prices);
};

Expand Down
4 changes: 2 additions & 2 deletions packages/run-protocol/src/vpool-xyk-amm/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
*/

/**
* @typedef {Object} VPoolInternalFacet - virtual pool for price quotes and trading
* @typedef {Object} DoublePoolInternalFacet - virtual pool for price quotes and trading
* @property {GetDoublePoolSwapQuote} getPriceForInput
* @property {GetDoublePoolSwapQuote} getPriceForOutput
* @property {(ZCFSeat, DoublePoolSwapResult) => string} allocateGainsAndLosses
* @property {(seat: ZCFSeat, result: DoublePoolSwapResult) => string} allocateGainsAndLosses
*/

/**
Expand Down

0 comments on commit cad92bb

Please sign in to comment.