Skip to content

Commit

Permalink
Merge pull request #26 from terraswap/feat/classic-base-token-tax
Browse files Browse the repository at this point in the history
Apply BASE token tax
  • Loading branch information
jbamlee authored Feb 21, 2024
2 parents da28529 + 7f316c0 commit 940997b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/collector/indexer/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EntityManager } from 'typeorm'
import { isNative } from 'lib/utils'
import { isClassic } from 'lib/terra'
import { baseCurrency } from 'lib/terraswap'
import { PairDayDataEntity, PairHourDataEntity, PairInfoEntity, TokenInfoEntity } from 'orm'
import { PairDataEntity, PairDayDataEntity, PairHourDataEntity, PairInfoEntity, TokenInfoEntity } from 'orm'
import { ExchangeRate } from 'types'
import { num } from 'lib/num'
import { lcd } from 'lib/terra/lcd'
Expand Down Expand Up @@ -140,7 +140,7 @@ async function _mainnetTokenPrice(manager: EntityManager,

while (tokenQueue.length > 0) {
const target = tokenQueue.shift();
paths.get(target)?.forEach(p => {
paths.get(target)?.forEach(p => {
const other = p.assets[0].token === target ? p.assets[1].token : p.assets[0].token;
const otherPrice = _calculatePrice(p.assets, target, price[target].price);
if (!price[other] || num(price[other].liquidity).lt(num(p.liquidity))) {
Expand Down Expand Up @@ -169,7 +169,7 @@ function _calculatePrice(assets: Asset[], target: string, targetPrice: string):

export async function comparePairReserve(height: number, em: EntityManager): Promise<void> {

const compare = async (pds: PairDayDataEntity[]) => {
const compare = async (pds: PairDataEntity[]) => {
const pdPromises = pds.map(async (pd) => {
let poolInfo;
try {
Expand All @@ -186,13 +186,13 @@ export async function comparePairReserve(height: number, em: EntityManager): Pro
}
const lpAmount = poolInfo.total_share
if (pd.token0Reserve !== token0Amount) {
throw new Error(`pool ${pd.pair} different token_0_reserve ${pd.token0Reserve} ${token0Amount}`)
throw new Error(`pool ${pd.pair} different token_0(${pd.token0}) actual(${pd.token0Reserve}) expected(${token0Amount}) at height ${height}`)
}
if (pd.token1Reserve !== token1Amount) {
throw new Error(`pool ${pd.pair} different token_1_reserve ${pd.token1Reserve} ${token1Amount}`)
throw new Error(`pool ${pd.pair} different token_1(${pd.token1}) actual(${pd.token1Reserve}) expected(${token1Amount}) at height ${height}`)
}
if (pd.totalLpTokenShare !== lpAmount) {
throw new Error(`pool ${pd.pair} different lp ${pd.totalLpTokenShare} ${lpAmount}`)
throw new Error(`pool ${pd.pair} different lp actual(${pd.totalLpTokenShare}) expected(${lpAmount}) at height ${height}`)
}
return pd
})
Expand Down
12 changes: 10 additions & 2 deletions src/collector/log-finder/nonnativeTransferLF.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Attributes, createReturningLogFinder, ReturningLogFinderMapper } from '@terra-money/log-finder'
import { NonnativeTransferTransformed } from 'types'
import logRules from './log-rules'
import { num } from 'lib/num'
import { BigNumber, num } from 'lib/num'
import { isClassic, isColumbus4 } from 'lib/terra'
import { ClassicReceiverFeeAppliedTokenSet, ClassicReceiverFeeAppliedPairSet } from 'lib/terraswap/classic.consts'
import { ClassicReceiverFeeAppliedTokenSet, ClassicReceiverFeeAppliedPairSet, ClassicOddTokenHandlerMap } from 'lib/terraswap/classic.consts'


const FEE_AMOUNT_KEY = 'fee_amount'
Expand Down Expand Up @@ -38,6 +38,14 @@ function createClassicLogFinder(height?: number) {
transformed.assets.amount = num(transformed.assets.amount).plus(num(feeAmount)).toString()
}

const oddTokenHandlingInfo = ClassicOddTokenHandlerMap.get(transformed.assets.token)
if (
oddTokenHandlingInfo?.action(match?.find(m => m.key === "action")?.value) &&
height && height >= oddTokenHandlingInfo?.appliedHeight
) {
transformed.assets.amount = num(transformed.assets.amount).multipliedBy(num("1").minus(num(oddTokenHandlingInfo.feeRate))).integerValue(BigNumber.ROUND_FLOOR).toString()
}

return transformed
})
}
Expand Down
18 changes: 16 additions & 2 deletions src/lib/terraswap/classic.consts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
export const ClassicReceiverFeeAppliedTokenSet: Set<string> = new Set([
"terra1zkhwtm4a559emekwj7z4vklzqupgjyad8ncpwvav38y5ef6g5tjse7ceus",
"terra1naaldj58aerjvqzulrnfpeph60pjqlyp60gqryup8g4djy4cn4nqwm08c3"
"terra1zkhwtm4a559emekwj7z4vklzqupgjyad8ncpwvav38y5ef6g5tjse7ceus",
"terra1naaldj58aerjvqzulrnfpeph60pjqlyp60gqryup8g4djy4cn4nqwm08c3"
])

export const ClassicReceiverFeeAppliedPairSet: Set<string> = new Set([
"terra15ukfg2wy9xd4g8hd5nl2rdyn7arlwk4l9u6kalwmg0pew5pjlpgskydg2a",
"terra1anwgp97zfn6zsz9t5vgtan4s09n24khx0twu3a550m4dsxj699pq8mg5yz",
"terra17tq86waugtxrupjp3yz2fran6ghfcsdt35j257dk7tznljlkm9rq49j7ap"
])

interface OddTokenHandlingInfo {
feeRate: string
appliedHeight: number
action: (a: string)=> boolean
}

const CLASSIC_BASE_TOKEN = "terra1uewxz67jhhhs2tj97pfm2egtk7zqxuhenm4y4m"
const APPLIED_HEIGHT = 16746830
export const ClassicOddTokenHandlerMap: Map<string, OddTokenHandlingInfo> = new Map([[CLASSIC_BASE_TOKEN, {
feeRate: "0.048",
appliedHeight: APPLIED_HEIGHT,
action: (a: string) => a === "send"
}]])

0 comments on commit 940997b

Please sign in to comment.