diff --git a/packages/augur-comps/src/apollo/queries.ts b/packages/augur-comps/src/apollo/queries.ts index 1c8ecf25262..71fc7c83c90 100644 --- a/packages/augur-comps/src/apollo/queries.ts +++ b/packages/augur-comps/src/apollo/queries.ts @@ -116,6 +116,7 @@ export const GET_MARKETS = blockNumber => { invalidBalance invalidWeight } + symbols swaps { id sender { diff --git a/packages/augur-comps/src/stores/process-data.ts b/packages/augur-comps/src/stores/process-data.ts index ba479a05192..126918343ce 100644 --- a/packages/augur-comps/src/stores/process-data.ts +++ b/packages/augur-comps/src/stores/process-data.ts @@ -48,6 +48,7 @@ interface GraphMarket { amms: GraphAmmExchange[]; numTicks: string; tradingProceedsClaimed: GraphClaims[]; + symbols: string[]; universe?: { id: string; reportingFee: string; @@ -142,7 +143,8 @@ interface GraphAmmExchange { addLiquidity: GraphAddLiquidity[]; removeLiquidity: GraphRemoveLiquidity[]; totalSupply: string; - invalidPool: GraphInvalidPool + invalidPool: GraphInvalidPool; + symbols: string[]; } interface GraphData { @@ -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, }; }; diff --git a/packages/augur-comps/src/utils/contract-calls.ts b/packages/augur-comps/src/utils/contract-calls.ts index 6a9673414a6..7477e0fee46 100644 --- a/packages/augur-comps/src/utils/contract-calls.ts +++ b/packages/augur-comps/src/utils/contract-calls.ts @@ -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, @@ -52,7 +53,8 @@ export const checkConvertLiquidityProperties = (account: string, marketId: strin fee, amount, priceNo, - priceYes + priceYes, + symbols: amm?.symbols }; } @@ -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 { 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 ); } @@ -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( @@ -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 @@ -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(); diff --git a/packages/augur-comps/src/utils/types.ts b/packages/augur-comps/src/utils/types.ts index 127c28789dc..3f30a94f9c2 100644 --- a/packages/augur-comps/src/utils/types.ts +++ b/packages/augur-comps/src/utils/types.ts @@ -195,6 +195,7 @@ export interface AmmExchange { isAmmMarketInvalid: boolean; invalidPool: InvalidPool; swapInvalidForCashInETH?: string; + symbols: string[]; } export interface Cashes { diff --git a/packages/augur-core/tests/test_amm.py b/packages/augur-core/tests/test_amm.py index f4269312b1e..6da0b8f2b18 100644 --- a/packages/augur-core/tests/test_amm.py +++ b/packages/augur-core/tests/test_amm.py @@ -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: diff --git a/packages/augur-sdk-lite/src/api/AMM.ts b/packages/augur-sdk-lite/src/api/AMM.ts index 34a0eb7e05f..ba4a091c606 100644 --- a/packages/augur-sdk-lite/src/api/AMM.ts +++ b/packages/augur-sdk-lite/src/api/AMM.ts @@ -140,8 +140,8 @@ export class AMM { } } - async doRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string): Promise { - return this.intermediary(paraShareToken).removeLiquidity(market, paraShareToken, fee, lpTokens, symbolRoot); + async doRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbols: string[]): Promise { + return this.intermediary(paraShareToken).removeLiquidity(market, paraShareToken, fee, lpTokens, symbols); } async getRemoveLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber): Promise { diff --git a/packages/augur-sdk-lite/src/api/exchangeIntermediaries/ExchangeCommon.ts b/packages/augur-sdk-lite/src/api/exchangeIntermediaries/ExchangeCommon.ts index 36cf1c0eb66..253d3df7593 100644 --- a/packages/augur-sdk-lite/src/api/exchangeIntermediaries/ExchangeCommon.ts +++ b/packages/augur-sdk-lite/src/api/exchangeIntermediaries/ExchangeCommon.ts @@ -63,8 +63,8 @@ export abstract class ExchangeCommon { } } - async removeLiquidity(market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string): Promise { - 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 { + 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 { diff --git a/packages/augur-sdk-lite/src/api/exchangeIntermediaries/index.ts b/packages/augur-sdk-lite/src/api/exchangeIntermediaries/index.ts index c609d77bfed..6dacdbfceb1 100644 --- a/packages/augur-sdk-lite/src/api/exchangeIntermediaries/index.ts +++ b/packages/augur-sdk-lite/src/api/exchangeIntermediaries/index.ts @@ -36,7 +36,7 @@ export interface ExchangeContractIntermediary { recipient: string): Promise removeLiquidity( - market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbolRoot: string + market: string, paraShareToken: string, fee: BigNumber, lpTokens: BigNumber, symbols: string[] ): Promise rateRemoveLiquidity( diff --git a/packages/augur-simplified/src/modules/modal/modal-add-liquidity.tsx b/packages/augur-simplified/src/modules/modal/modal-add-liquidity.tsx index 63d9de0ea5a..e79054c59e9 100644 --- a/packages/augur-simplified/src/modules/modal/modal-add-liquidity.tsx +++ b/packages/augur-simplified/src/modules/modal/modal-add-liquidity.tsx @@ -337,7 +337,7 @@ const ModalAddLiquidity = ({ properties.marketId, cash, onChainFee, - amount + amount, ); } else { results = await estimateAddLiquidity( @@ -422,10 +422,7 @@ const ModalAddLiquidity = ({ } if (modalType === REMOVE) { doRemoveAmmLiquidity( - properties.marketId, - properties.cash, - properties.fee, - properties.amount + properties ) .then((response) => { const { hash } = response; diff --git a/packages/augur-simplified/src/modules/types.ts b/packages/augur-simplified/src/modules/types.ts index 8fc5157b6e1..fa762224f65 100644 --- a/packages/augur-simplified/src/modules/types.ts +++ b/packages/augur-simplified/src/modules/types.ts @@ -194,6 +194,7 @@ export interface AmmExchange { ammOutcomes: AmmOutcome[]; isAmmMarketInvalid: boolean; invalidPool: InvalidPool; + symbols: string[]; swapInvalidForCashInETH?: string; } diff --git a/packages/augur-test/src/tests/amm/ammErc20.test.ts b/packages/augur-test/src/tests/amm/ammErc20.test.ts index eeae3c81c01..93e6dc8ffcf 100644 --- a/packages/augur-test/src/tests/amm/ammErc20.test.ts +++ b/packages/augur-test/src/tests/amm/ammErc20.test.ts @@ -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; @@ -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); @@ -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); diff --git a/packages/augur-test/src/tests/amm/ammEth.test.ts b/packages/augur-test/src/tests/amm/ammEth.test.ts index 407fdf88289..446a41a0a26 100644 --- a/packages/augur-test/src/tests/amm/ammEth.test.ts +++ b/packages/augur-test/src/tests/amm/ammEth.test.ts @@ -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 @@ -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); @@ -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);