Skip to content

Commit

Permalink
Checkpoint (#10799)
Browse files Browse the repository at this point in the history
Update middleware signatures
  • Loading branch information
justinbarry authored Mar 9, 2021
1 parent f9e5b20 commit 7fe766f
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/augur-comps/src/apollo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const GET_MARKETS = blockNumber => {
invalidBalance
invalidWeight
}
symbols
swaps {
id
sender {
Expand Down
7 changes: 5 additions & 2 deletions packages/augur-comps/src/stores/process-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface GraphMarket {
amms: GraphAmmExchange[];
numTicks: string;
tradingProceedsClaimed: GraphClaims[];
symbols: string[];
universe?: {
id: string;
reportingFee: string;
Expand Down Expand Up @@ -142,7 +143,8 @@ interface GraphAmmExchange {
addLiquidity: GraphAddLiquidity[];
removeLiquidity: GraphRemoveLiquidity[];
totalSupply: string;
invalidPool: GraphInvalidPool
invalidPool: GraphInvalidPool;
symbols: string[];
}

interface GraphData {
Expand Down Expand Up @@ -430,7 +432,8 @@ const shapeAmmExchange = (
apy,
ammOutcomes,
isAmmMarketInvalid: false, // this will be calc by process
invalidPool: amm?.invalidPool
invalidPool: amm?.invalidPool,
symbols: amm.symbols,
};
};

Expand Down
21 changes: 10 additions & 11 deletions packages/augur-comps/src/utils/contract-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface LiquidityProperties {
fee: string,
amount: string,
priceNo: string,
priceYes: string
priceYes: string,
symbols: string[]
}

export const checkConvertLiquidityProperties = (account: string, marketId: string,
Expand All @@ -52,7 +53,8 @@ export const checkConvertLiquidityProperties = (account: string, marketId: strin
fee,
amount,
priceNo,
priceYes
priceYes,
symbols: amm?.symbols
};
}

Expand Down Expand Up @@ -215,23 +217,20 @@ export async function getRemoveLiquidity(
};
}

export function doRemoveAmmLiquidity(
marketId: string,
cash: Cash,
fee: string,
lpTokenBalance: string,
export function doRemoveAmmLiquidity({ marketId, cash, fee, amount, symbols }: { marketId: string, cash: Cash, fee: string, amount: string, symbols: string[] },
): Promise<TransactionResponse | null> {
const augurClient = augurSdkLite.get();
if (!augurClient || !marketId || !cash?.shareToken || !fee) {
console.error('doRemoveLiquidity: augurClient is null or no amm address');
return null;
}
const balance = convertDisplayShareAmountToOnChainShareAmount(lpTokenBalance, cash?.decimals);
const balance = convertDisplayShareAmountToOnChainShareAmount(amount, cash?.decimals);
return augurClient.amm.doRemoveLiquidity(
marketId,
cash.shareToken,
new BN(fee),
new BN(balance),
symbols
);
}

Expand Down Expand Up @@ -596,7 +595,7 @@ export const getUserBalances = async (
balananceCalls
);

for(let i = 0; i < Object.keys(balanceResult.results).length; i++) {
for (let i = 0; i < Object.keys(balanceResult.results).length; i++) {
const key = Object.keys(balanceResult.results)[i];
const value = String(
new BN(
Expand Down Expand Up @@ -740,7 +739,7 @@ export const getMarketInvalidity = async (
contractLpBalanceCall
);

for(let i = 0; i < Object.keys(balanceResult.results).length; i++) {
for (let i = 0; i < Object.keys(balanceResult.results).length; i++) {
const key = Object.keys(balanceResult.results)[i];
const method = String(
balanceResult.results[key].originalContractCallContext.calls[0].methodName
Expand All @@ -750,7 +749,7 @@ export const getMarketInvalidity = async (
const context = balanceResult.results[key].originalContractCallContext.calls[0].context;
const rawBalance = new BN(balanceValue.hex).toFixed();

if (method === CALC_OUT_GIVEN_IN) {
if (method === CALC_OUT_GIVEN_IN) {
const amm = ammExchanges[context.ammExchangeId];
const ouputCash = convertOnChainCashAmountToDisplayCashAmount(new BN(rawBalance), amm?.cash?.decimals);
amm.swapInvalidForCashInETH = ouputCash.toFixed();
Expand Down
1 change: 1 addition & 0 deletions packages/augur-comps/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export interface AmmExchange {
isAmmMarketInvalid: boolean;
invalidPool: InvalidPool;
swapInvalidForCashInETH?: string;
symbols: string[];
}

export interface Cashes {
Expand Down
8 changes: 1 addition & 7 deletions packages/augur-core/tests/test_amm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ def test_calc_gas_costs(contractsFixture, market, shareToken, factory, account0,
cash.faucet(cost)
cash.approve(factory.address, 2**256-1)

ammAddress = ""
with PrintGasUsed(contractsFixture, "createAMM", 0):
ammAddress = factory.createAMM(market.address, shareToken.address, FEE)

cash.transfer(factory.address, cost)

with PrintGasUsed(contractsFixture, "createBPool", 0):
factory.createBPool(ammAddress, shareToken.address, market.address, FEE, account0, SYMBOLS)
factory.addAMMWithLiquidity(market.address, shareToken.address, FEE, cost, RATIO_50_50, True, account0, SYMBOLS)

def test_amm_add_additional_liquidity(contractsFixture, market, cash, shareToken, factory, account0, account1):
if not contractsFixture.paraAugur:
Expand Down
4 changes: 2 additions & 2 deletions packages/augur-sdk-lite/src/api/AMM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export class AMM {
}
}

async doRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string): Promise<TransactionResponse> {
return this.intermediary(paraShareToken).removeLiquidity(market, paraShareToken, fee, lpTokens, symbolRoot);
async doRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbols: string[]): Promise<TransactionResponse> {
return this.intermediary(paraShareToken).removeLiquidity(market, paraShareToken, fee, lpTokens, symbols);
}

async getRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber): Promise<RemoveLiquidityRate> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export abstract class ExchangeCommon {
}
}

async removeLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string): Promise<TransactionResponse> {
return this.factory.removeLiquidity(market, paraShareToken, fee.toFixed(), lpTokens.toFixed(), generateSymbols(symbolRoot));
async removeLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbols:string[]): Promise<TransactionResponse> {
return this.factory.removeLiquidity(market, paraShareToken, fee.toFixed(), lpTokens.toFixed(), symbols);
}

async swap(market: string, paraShareToken: string, fee: BigNumber, inputShares: BigNumber, outputLong: Boolean, minShares: BigNumber): Promise<TransactionResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ExchangeContractIntermediary {
recipient: string): Promise<BigNumber>

removeLiquidity(
market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string
market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbols: string[]
): Promise<TransactionResponse>

rateRemoveLiquidity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const ModalAddLiquidity = ({
properties.marketId,
cash,
onChainFee,
amount
amount,
);
} else {
results = await estimateAddLiquidity(
Expand Down Expand Up @@ -422,10 +422,7 @@ const ModalAddLiquidity = ({
}
if (modalType === REMOVE) {
doRemoveAmmLiquidity(
properties.marketId,
properties.cash,
properties.fee,
properties.amount
properties
)
.then((response) => {
const { hash } = response;
Expand Down
1 change: 1 addition & 0 deletions packages/augur-simplified/src/modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export interface AmmExchange {
ammOutcomes: AmmOutcome[];
isAmmMarketInvalid: boolean;
invalidPool: InvalidPool;
symbols: string[];
swapInvalidForCashInETH?: string;
}

Expand Down
9 changes: 7 additions & 2 deletions packages/augur-test/src/tests/amm/ammErc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe('AMM Middleware for ERC20', () => {
const INCLUDE_FEE = true;
const EXCLUDE_FEE = false;
const SYMBOL_ROOT = 'symbol';
const SYMBOLS = [
`i${SYMBOL_ROOT}`,
`n${SYMBOL_ROOT}`,
`y${SYMBOL_ROOT}`
];

function makeAMMMiddleware(user: TestContractAPI): AMM {
const wethParaShareTokenAddress = config?.paraDeploys[config.addresses.WETH9]?.addresses.ShareToken;
Expand Down Expand Up @@ -238,7 +243,7 @@ describe('AMM Middleware for ERC20', () => {
});

console.log('Selling 1/3rd of LP tokens via removeLiquidity, then selling the resulting shares');
await middleware.doRemoveLiquidity(market.address, usdtParaShare.address, fee, lpTokensToBurn, SYMBOL_ROOT);
await middleware.doRemoveLiquidity(market.address, usdtParaShare.address, fee, lpTokensToBurn, SYMBOLS);

const postInvalid = await usdtParaShare.balanceOf_(mary.account.address, INVALID);
const postNo = await usdtParaShare.balanceOf_(mary.account.address, NO);
Expand Down Expand Up @@ -272,7 +277,7 @@ describe('AMM Middleware for ERC20', () => {
});

console.log('Removing remaining liquidity without selling any received shares')
await middleware.doRemoveLiquidity(market.address, usdtParaShare.address, fee, lpTokens, SYMBOL_ROOT);
await middleware.doRemoveLiquidity(market.address, usdtParaShare.address, fee, lpTokens, SYMBOLS);

const postInvalid = await usdtParaShare.balanceOf_(mary.account.address, INVALID);
const postNo = await usdtParaShare.balanceOf_(mary.account.address, NO);
Expand Down
9 changes: 7 additions & 2 deletions packages/augur-test/src/tests/amm/ammEth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe('AMM Middleware for ETH', () => {
const INCLUDE_FEE = true;
const EXCLUDE_FEE = false;
const SYMBOL_ROOT = 'symbol';
const SYMBOLS = [
`i${SYMBOL_ROOT}`,
`n${SYMBOL_ROOT}`,
`y${SYMBOL_ROOT}`
];

const ONE_ETH = bn(1000).times(1e18); // 1000 ETH

Expand Down Expand Up @@ -307,7 +312,7 @@ describe('AMM Middleware for ETH', () => {
});

console.log('Selling 1/3rd of LP tokens via removeLiquidity, then selling the resulting shares');
await middleware.doRemoveLiquidity(market.address, wethParaShare.address, fee, lpTokensToBurn, SYMBOL_ROOT);
await middleware.doRemoveLiquidity(market.address, wethParaShare.address, fee, lpTokensToBurn, SYMBOLS);

const postInvalid = await wethParaShare.balanceOf_(mary.account.address, INVALID);
const postNo = await wethParaShare.balanceOf_(mary.account.address, NO);
Expand Down Expand Up @@ -341,7 +346,7 @@ describe('AMM Middleware for ETH', () => {
});

console.log('Removing remaining liquidity without selling any received shares')
await middleware.doRemoveLiquidity(market.address, wethParaShare.address, fee, lpTokens, SYMBOL_ROOT);
await middleware.doRemoveLiquidity(market.address, wethParaShare.address, fee, lpTokens, SYMBOLS);

const postInvalid = await wethParaShare.balanceOf_(mary.account.address, INVALID);
const postNo = await wethParaShare.balanceOf_(mary.account.address, NO);
Expand Down

0 comments on commit 7fe766f

Please sign in to comment.