@@ -23,7 +23,8 @@ import {
23
23
getPoolShare ,
24
24
getPoolSnapshot ,
25
25
getPoolLpSwapFee ,
26
- getPoolPublisherMarketFee
26
+ getPoolPublisherMarketFee ,
27
+ getBalance
27
28
} from './utils/poolUtils'
28
29
import { getToken } from './utils/tokenUtils'
29
30
import { getUser } from './utils/userUtils'
@@ -122,16 +123,23 @@ export function handleSwap(event: LOG_SWAP): void {
122
123
event . params . tokenAmountOut . toBigDecimal ( ) ,
123
124
tokenOut . decimals
124
125
)
126
+
127
+ const tokenOutNewBalance = getBalance (
128
+ event . address ,
129
+ event . params . tokenOut ,
130
+ tokenOut . decimals
131
+ )
132
+
125
133
if ( tokenOut . isDatatoken ) {
126
134
poolTx . datatoken = tokenOut . id
127
135
poolTx . datatokenValue = ammountOut . neg ( )
128
136
129
- pool . datatokenLiquidity = pool . datatokenLiquidity . minus ( ammountOut )
137
+ pool . datatokenLiquidity = tokenOutNewBalance
130
138
} else {
131
139
poolTx . baseToken = tokenOut . id
132
140
poolTx . baseTokenValue = ammountOut . neg ( )
133
141
134
- pool . baseTokenLiquidity = pool . baseTokenLiquidity . minus ( ammountOut )
142
+ pool . baseTokenLiquidity = tokenOutNewBalance
135
143
poolSnapshot . swapVolume = poolSnapshot . swapVolume . plus ( ammountOut )
136
144
137
145
addPoolSwap ( tokenOut . id , ammountOut )
@@ -144,18 +152,21 @@ export function handleSwap(event: LOG_SWAP): void {
144
152
event . params . tokenAmountIn . toBigDecimal ( ) ,
145
153
tokenIn . decimals
146
154
)
155
+ const tokenInNewBalance = getBalance (
156
+ event . address ,
157
+ event . params . tokenIn ,
158
+ tokenIn . decimals
159
+ )
147
160
if ( tokenIn . isDatatoken ) {
148
161
poolTx . datatoken = tokenIn . id
149
162
poolTx . datatokenValue = ammountIn
150
163
151
- pool . datatokenLiquidity = pool . datatokenLiquidity . plus ( ammountIn )
164
+ pool . datatokenLiquidity = tokenInNewBalance
152
165
} else {
153
166
poolTx . baseToken = tokenIn . id
154
167
poolTx . baseTokenValue = ammountIn
155
-
156
- pool . baseTokenLiquidity = pool . baseTokenLiquidity . plus ( ammountIn )
168
+ pool . baseTokenLiquidity = tokenInNewBalance
157
169
poolSnapshot . swapVolume = poolSnapshot . swapVolume . plus ( ammountIn )
158
-
159
170
addLiquidity ( tokenIn . id , ammountIn )
160
171
addPoolSwap ( tokenIn . id , ammountIn )
161
172
}
0 commit comments