From 17821115f96ac481a1ddd7cd6909deaf7968333f Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 29 Mar 2022 05:59:32 -0700 Subject: [PATCH] fix pool exit values (#392) * fix pool exit values * fix lint --- docker/README.md | 5 +++++ schema.graphql | 4 ++-- src/mappings/pool.ts | 4 ++-- src/mappings/utils/poolUtils.ts | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docker/README.md b/docker/README.md index 9ceb5be..0fc8cbc 100644 --- a/docker/README.md +++ b/docker/README.md @@ -60,6 +60,11 @@ clone this repository and run ```sh docker-compose up ``` +OR + +```sh +docker-compose --env-file .env up | grep -a -E --color 'WARN.*|$' +``` This will start IPFS, Postgres and Graph Node in Docker and create persistent data directories for IPFS and Postgres in `./data/ipfs` and `./data/postgres`. You diff --git a/schema.graphql b/schema.graphql index c381690..c64f9b2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -231,13 +231,13 @@ type PoolTransaction @entity { "base tokens transfered" baseToken: Token - "number of base tokens transfered, if value is negative it means it was removed" + "number of base tokens transfered, for type SWAP if value is negative it means it was removed" baseTokenValue: BigDecimal "datatokens transfered" datatoken: Token - "number of datatokens transfered, if value is negative it means it was removed" + "number of datatokens transfered, for type SWAP if value is negative it means it was removed" datatokenValue: BigDecimal } diff --git a/src/mappings/pool.ts b/src/mappings/pool.ts index 9ed423e..dbbafb0 100644 --- a/src/mappings/pool.ts +++ b/src/mappings/pool.ts @@ -87,12 +87,12 @@ export function handleExit(event: LOG_EXIT): void { ) if (token.isDatatoken) { poolTx.datatoken = token.id - poolTx.datatokenValue = ammount.neg() + poolTx.datatokenValue = ammount pool.datatokenLiquidity = pool.datatokenLiquidity.minus(ammount) } else { poolTx.baseToken = token.id - poolTx.baseTokenValue = ammount.neg() + poolTx.baseTokenValue = ammount pool.baseTokenLiquidity = pool.baseTokenLiquidity.minus(ammount) removeLiquidity(token.id, ammount) diff --git a/src/mappings/utils/poolUtils.ts b/src/mappings/utils/poolUtils.ts index 1161012..8a6f487 100644 --- a/src/mappings/utils/poolUtils.ts +++ b/src/mappings/utils/poolUtils.ts @@ -17,16 +17,27 @@ export function getPoolShareId( return `${poolAddress}-${userAddress}` } +export function getPoolTransactionId( + txHash: string, + userAddress: string +): string { + return `${txHash}-${userAddress}` +} + export function getPoolTransaction( event: ethereum.Event, userAddress: string, type: string ): PoolTransaction { - let poolTx = PoolTransaction.load(event.transaction.hash.toHex()) + const txId = getPoolTransactionId( + event.transaction.hash.toHexString(), + userAddress + ) + let poolTx = PoolTransaction.load(txId) // create pool transaction and fill basic fields if (poolTx === null) { - poolTx = new PoolTransaction(event.transaction.hash.toHex()) + poolTx = new PoolTransaction(txId) poolTx.user = userAddress poolTx.pool = event.address.toHex()