fix liquidity (#383)

* fix liquidity

* fix lint
This commit is contained in:
mihaisc 2022-03-23 03:55:30 -07:00 committed by GitHub
parent ac9e4832a7
commit 9837a71a27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 12 deletions

1
package-lock.json generated
View File

@ -5,7 +5,6 @@
"requires": true,
"packages": {
"": {
"name": "ocean-subgraph",
"version": "1.2.0",
"license": "Apache-2.0",
"dependencies": {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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