diff --git a/package-lock.json b/package-lock.json index c5ca888..bd78fb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "ocean-subgraph", "version": "1.2.0", "license": "Apache-2.0", "dependencies": { diff --git a/src/mappings/pool.ts b/src/mappings/pool.ts index 5b972dc..9ed423e 100644 --- a/src/mappings/pool.ts +++ b/src/mappings/pool.ts @@ -23,7 +23,8 @@ import { getPoolShare, getPoolSnapshot, getPoolLpSwapFee, - getPoolPublisherMarketFee + getPoolPublisherMarketFee, + getBalance } from './utils/poolUtils' import { getToken } from './utils/tokenUtils' import { getUser } from './utils/userUtils' @@ -122,16 +123,23 @@ export function handleSwap(event: LOG_SWAP): void { event.params.tokenAmountOut.toBigDecimal(), tokenOut.decimals ) + + const tokenOutNewBalance = getBalance( + event.address, + event.params.tokenOut, + tokenOut.decimals + ) + if (tokenOut.isDatatoken) { poolTx.datatoken = tokenOut.id poolTx.datatokenValue = ammountOut.neg() - pool.datatokenLiquidity = pool.datatokenLiquidity.minus(ammountOut) + pool.datatokenLiquidity = tokenOutNewBalance } else { poolTx.baseToken = tokenOut.id poolTx.baseTokenValue = ammountOut.neg() - pool.baseTokenLiquidity = pool.baseTokenLiquidity.minus(ammountOut) + pool.baseTokenLiquidity = tokenOutNewBalance poolSnapshot.swapVolume = poolSnapshot.swapVolume.plus(ammountOut) addPoolSwap(tokenOut.id, ammountOut) @@ -144,18 +152,21 @@ export function handleSwap(event: LOG_SWAP): void { event.params.tokenAmountIn.toBigDecimal(), tokenIn.decimals ) + const tokenInNewBalance = getBalance( + event.address, + event.params.tokenIn, + tokenIn.decimals + ) if (tokenIn.isDatatoken) { poolTx.datatoken = tokenIn.id poolTx.datatokenValue = ammountIn - pool.datatokenLiquidity = pool.datatokenLiquidity.plus(ammountIn) + pool.datatokenLiquidity = tokenInNewBalance } else { poolTx.baseToken = tokenIn.id poolTx.baseTokenValue = ammountIn - - pool.baseTokenLiquidity = pool.baseTokenLiquidity.plus(ammountIn) + pool.baseTokenLiquidity = tokenInNewBalance poolSnapshot.swapVolume = poolSnapshot.swapVolume.plus(ammountIn) - addLiquidity(tokenIn.id, ammountIn) addPoolSwap(tokenIn.id, ammountIn) } diff --git a/src/mappings/utils/poolUtils.ts b/src/mappings/utils/poolUtils.ts index 47730c3..1161012 100644 --- a/src/mappings/utils/poolUtils.ts +++ b/src/mappings/utils/poolUtils.ts @@ -141,3 +141,14 @@ export function getPoolPublisherMarketFee(poolAddress: Address): BigDecimal { const marketFee = weiToDecimal(marketFeeWei.toBigDecimal(), 18) return marketFee } + +export function getBalance( + poolAddress: Address, + tokenAddress: Address, + tokenDecimals: i32 +): BigDecimal { + const contract = BPool.bind(poolAddress) + const balanceWei = contract.getBalance(tokenAddress) + const balance = weiToDecimal(balanceWei.toBigDecimal(), tokenDecimals) + return balance +} diff --git a/subgraph.yaml b/subgraph.yaml index 4bb6e2d..63fb049 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -8,9 +8,9 @@ dataSources: name: ERC721Factory network: rinkeby source: - address: '0x1b1FE18bE79249AE8A30b3cEef03d70ca299a75b' + address: '0x548fd8639eC4Add192f12FC5c3EF6Dd80e1634ce' abi: ERC721Factory - startBlock: 10182337 + startBlock: 10364536 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -33,9 +33,9 @@ dataSources: name: FactoryRouter network: rinkeby source: - address: '0x6CE85a8B9dF0aEbd6deE3593d4E9cde7398ff842' + address: '0xfe1a9F07718b40071F4c8d0f4bA22121dD5C0559' abi: FactoryRouter - startBlock: 10182337 + startBlock: 10364536 mapping: kind: ethereum/events apiVersion: 0.0.6