fix all linting errors
This commit is contained in:
parent
371eae73ed
commit
7713f396fa
|
@ -29,8 +29,8 @@ export function handleTransfer(event: Transfer): void {
|
|||
let oldBalanceFrom = BigDecimal.fromString('0.0')
|
||||
let oldBalanceTo = BigDecimal.fromString('0.0')
|
||||
|
||||
const isMint = tokenShareFrom == ZERO_ADDRESS
|
||||
const isBurn = tokenShareTo == ZERO_ADDRESS
|
||||
const isMint = tokenShareFrom === ZERO_ADDRESS
|
||||
const isBurn = tokenShareTo === ZERO_ADDRESS
|
||||
|
||||
const datatoken = Datatoken.load(tokenId)
|
||||
|
||||
|
@ -115,7 +115,7 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||
order.timestamp = event.params.timestamp.toI32()
|
||||
if (
|
||||
event.params.mrktFeeCollector != null &&
|
||||
event.params.mrktFeeCollector.toHex() != ZERO_ADDRESS
|
||||
event.params.mrktFeeCollector.toHex() !== ZERO_ADDRESS
|
||||
) {
|
||||
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ export const ENABLE_DEBUG = false
|
|||
const network = dataSource.network()
|
||||
|
||||
export const OCEAN: string =
|
||||
network == 'mainnet'
|
||||
network === 'mainnet'
|
||||
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
|
||||
|
||||
|
@ -105,6 +105,13 @@ export function updatePoolTokenBalance(
|
|||
poolToken.balance = balance
|
||||
}
|
||||
|
||||
export function createUserEntity(address: string): void {
|
||||
if (User.load(address) == null) {
|
||||
const user = new User(address)
|
||||
user.save()
|
||||
}
|
||||
}
|
||||
|
||||
export function createPoolShareEntity(
|
||||
id: string,
|
||||
pool: string,
|
||||
|
@ -168,7 +175,7 @@ export function updatePoolTransactionToken(
|
|||
|
||||
ptxTokenValues.save()
|
||||
|
||||
if (ptxTokenValues.tokenAddress == OCEAN) {
|
||||
if (ptxTokenValues.tokenAddress === OCEAN) {
|
||||
ptx.oceanReserve = ptxTokenValues.tokenReserve
|
||||
pool.oceanReserve = ptxTokenValues.tokenReserve
|
||||
} else {
|
||||
|
@ -188,8 +195,43 @@ export function updatePoolTransactionToken(
|
|||
pool.save()
|
||||
}
|
||||
|
||||
export function calcSpotPrice(
|
||||
balanceIn: BigDecimal,
|
||||
wIn: BigDecimal,
|
||||
balanceOut: BigDecimal,
|
||||
wOut: BigDecimal,
|
||||
swapFee: BigDecimal
|
||||
): BigDecimal {
|
||||
if (balanceIn <= ZERO_BD || balanceOut <= ZERO_BD) return MINUS_1_BD
|
||||
debuglog('################ calcSpotPrice', null, [
|
||||
balanceIn.toString(),
|
||||
wIn.toString(),
|
||||
balanceOut.toString(),
|
||||
wOut.toString(),
|
||||
swapFee.toString()
|
||||
])
|
||||
|
||||
const numer = balanceIn.div(wIn)
|
||||
const denom = balanceOut.div(wOut)
|
||||
if (denom <= ZERO_BD) return MINUS_1_BD
|
||||
|
||||
const ratio = numer.div(denom)
|
||||
const scale = ONE_BD.div(ONE_BD.minus(swapFee))
|
||||
const price = ratio.times(scale)
|
||||
price.truncate(18)
|
||||
debuglog('################ calcSpotPrice values:', null, [
|
||||
numer.toString(),
|
||||
denom.toString(),
|
||||
ratio.toString(),
|
||||
scale.toString(),
|
||||
price.toString()
|
||||
])
|
||||
return price
|
||||
}
|
||||
|
||||
export function createPoolTransaction(
|
||||
event: ethereum.Event,
|
||||
// eslint-disable-next-line camelcase
|
||||
event_type: string,
|
||||
userAddress: string
|
||||
): void {
|
||||
|
@ -279,6 +321,7 @@ export function createPoolTransaction(
|
|||
)
|
||||
|
||||
poolTx.tx = event.transaction.hash
|
||||
// eslint-disable-next-line camelcase
|
||||
poolTx.event = event_type
|
||||
poolTx.block = event.block.number.toI32()
|
||||
poolTx.timestamp = event.block.timestamp.toI32()
|
||||
|
@ -294,40 +337,6 @@ export function createPoolTransaction(
|
|||
poolTx.save()
|
||||
}
|
||||
|
||||
export function calcSpotPrice(
|
||||
balanceIn: BigDecimal,
|
||||
wIn: BigDecimal,
|
||||
balanceOut: BigDecimal,
|
||||
wOut: BigDecimal,
|
||||
swapFee: BigDecimal
|
||||
): BigDecimal {
|
||||
if (balanceIn <= ZERO_BD || balanceOut <= ZERO_BD) return MINUS_1_BD
|
||||
debuglog('################ calcSpotPrice', null, [
|
||||
balanceIn.toString(),
|
||||
wIn.toString(),
|
||||
balanceOut.toString(),
|
||||
wOut.toString(),
|
||||
swapFee.toString()
|
||||
])
|
||||
|
||||
const numer = balanceIn.div(wIn)
|
||||
const denom = balanceOut.div(wOut)
|
||||
if (denom <= ZERO_BD) return MINUS_1_BD
|
||||
|
||||
const ratio = numer.div(denom)
|
||||
const scale = ONE_BD.div(ONE_BD.minus(swapFee))
|
||||
const price = ratio.times(scale)
|
||||
price.truncate(18)
|
||||
debuglog('################ calcSpotPrice values:', null, [
|
||||
numer.toString(),
|
||||
denom.toString(),
|
||||
ratio.toString(),
|
||||
scale.toString(),
|
||||
price.toString()
|
||||
])
|
||||
return price
|
||||
}
|
||||
|
||||
export function decrPoolCount(finalized: boolean): void {
|
||||
const factory = PoolFactory.load('1')
|
||||
factory.poolCount -= 1
|
||||
|
@ -361,13 +370,6 @@ export function saveTokenTransaction(
|
|||
createUserEntity(userAddress)
|
||||
}
|
||||
|
||||
export function createUserEntity(address: string): void {
|
||||
if (User.load(address) == null) {
|
||||
const user = new User(address)
|
||||
user.save()
|
||||
}
|
||||
}
|
||||
|
||||
export function updateTokenBalance(
|
||||
id: string,
|
||||
token: string,
|
||||
|
|
|
@ -59,7 +59,7 @@ export function handleSetController(event: LOG_CALL): void {
|
|||
export function handleSetPublicSwap(event: LOG_CALL): void {
|
||||
const poolId = event.address.toHex()
|
||||
const pool = Pool.load(poolId)
|
||||
pool.publicSwap = event.params.data.toHexString().slice(-1) == '1'
|
||||
pool.publicSwap = event.params.data.toHexString().slice(-1) === '1'
|
||||
pool.save()
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,60 @@ export function handleFinalize(event: LOG_CALL): void {
|
|||
factory.save()
|
||||
}
|
||||
|
||||
export function _handleRebind(
|
||||
event: LOG_CALL,
|
||||
poolId: string,
|
||||
tokenAddress: string,
|
||||
balanceStr: string,
|
||||
denormWeightStr: string
|
||||
): void {
|
||||
const pool = Pool.load(poolId)
|
||||
const decimals = BigInt.fromI32(18).toI32()
|
||||
|
||||
if (tokenAddress !== OCEAN) {
|
||||
pool.datatokenAddress = tokenAddress
|
||||
}
|
||||
pool.tokenCount += BigInt.fromI32(1)
|
||||
const address = Address.fromString(tokenAddress)
|
||||
const denormWeight = hexToDecimal(denormWeightStr, decimals)
|
||||
const poolTokenId = poolId.concat('-').concat(address.toHexString())
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken == null) {
|
||||
createPoolTokenEntity(poolTokenId, poolId, address.toHexString())
|
||||
poolToken = PoolToken.load(poolTokenId)
|
||||
pool.totalWeight += denormWeight
|
||||
} else {
|
||||
const oldWeight = poolToken.denormWeight
|
||||
if (denormWeight > oldWeight) {
|
||||
pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight)
|
||||
} else {
|
||||
pool.totalWeight = pool.totalWeight - (oldWeight - denormWeight)
|
||||
}
|
||||
}
|
||||
|
||||
poolToken.denormWeight = denormWeight
|
||||
const balance = hexToDecimal(balanceStr, decimals)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
|
||||
|
||||
poolToken.save()
|
||||
if (balance.equals(ZERO_BD)) {
|
||||
decrPoolCount(pool.finalized)
|
||||
pool.active = false
|
||||
}
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function handleRebind(event: LOG_CALL): void {
|
||||
const poolId = event.address.toHex()
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
event.params.data.toHexString().slice(34, 74),
|
||||
event.params.data.toHexString().slice(74, 138),
|
||||
event.params.data.toHexString().slice(138)
|
||||
)
|
||||
}
|
||||
|
||||
export function handleSetup(event: LOG_CALL): void {
|
||||
const poolId = event.address.toHex()
|
||||
debuglog('handleSetup: ', event, [])
|
||||
|
@ -142,60 +196,6 @@ export function handleSetup(event: LOG_CALL): void {
|
|||
)
|
||||
}
|
||||
|
||||
export function _handleRebind(
|
||||
event: LOG_CALL,
|
||||
poolId: string,
|
||||
tokenAddress: string,
|
||||
balanceStr: string,
|
||||
denormWeightStr: string
|
||||
): void {
|
||||
const pool = Pool.load(poolId)
|
||||
const decimals = BigInt.fromI32(18).toI32()
|
||||
|
||||
if (tokenAddress !== OCEAN) {
|
||||
pool.datatokenAddress = tokenAddress
|
||||
}
|
||||
pool.tokenCount += BigInt.fromI32(1)
|
||||
const address = Address.fromString(tokenAddress)
|
||||
const denormWeight = hexToDecimal(denormWeightStr, decimals)
|
||||
const poolTokenId = poolId.concat('-').concat(address.toHexString())
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken == null) {
|
||||
createPoolTokenEntity(poolTokenId, poolId, address.toHexString())
|
||||
poolToken = PoolToken.load(poolTokenId)
|
||||
pool.totalWeight += denormWeight
|
||||
} else {
|
||||
const oldWeight = poolToken.denormWeight
|
||||
if (denormWeight > oldWeight) {
|
||||
pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight)
|
||||
} else {
|
||||
pool.totalWeight = pool.totalWeight - (oldWeight - denormWeight)
|
||||
}
|
||||
}
|
||||
|
||||
poolToken.denormWeight = denormWeight
|
||||
const balance = hexToDecimal(balanceStr, decimals)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
|
||||
|
||||
poolToken.save()
|
||||
if (balance.equals(ZERO_BD)) {
|
||||
decrPoolCount(pool.finalized)
|
||||
pool.active = false
|
||||
}
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function handleRebind(event: LOG_CALL): void {
|
||||
const poolId = event.address.toHex()
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
event.params.data.toHexString().slice(34, 74),
|
||||
event.params.data.toHexString().slice(74, 138),
|
||||
event.params.data.toHexString().slice(138)
|
||||
)
|
||||
}
|
||||
|
||||
/************************************
|
||||
********** JOINS & EXITS ***********
|
||||
************************************/
|
||||
|
@ -204,7 +204,7 @@ export function handleJoinPool(event: LOG_JOIN): void {
|
|||
const poolId = event.address.toHex()
|
||||
|
||||
const pool = Pool.load(poolId)
|
||||
if (pool.finalized == false) {
|
||||
if (pool.finalized === false) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue