Add dlmm start and end bin
This commit is contained in:
@@ -506,6 +506,7 @@ func metaoradlmmSwapParser(tx *Tx, instruction Instruction, innerInstructions In
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
ActiveBinId: swapEvent.EndBinId,
|
||||
StartBinId: swapEvent.StartBinId,
|
||||
EndBinId: swapEvent.EndBinId,
|
||||
}
|
||||
@@ -699,6 +700,7 @@ func metaoradlmmAddLiquidityParser(tx *Tx, instruction Instruction, innerInstruc
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
ActiveBinId: addEvent.ActiveBinId,
|
||||
StartBinId: startBinId,
|
||||
EndBinId: endBinId,
|
||||
BinChanges: binChanges,
|
||||
@@ -731,6 +733,7 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
binChanges []DlmmBinLiquidityChange
|
||||
startBinId int32
|
||||
endBinId int32
|
||||
removeBp int32
|
||||
)
|
||||
|
||||
switch discriminator {
|
||||
@@ -741,6 +744,7 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
}
|
||||
binChanges = dlmmBinChangesFromReduction(args.BinLiquidityRemoval)
|
||||
startBinId, endBinId = dlmmMinMaxBinIdFromReduction(args.BinLiquidityRemoval)
|
||||
removeBp = dlmmCommonRemoveBp(args.BinLiquidityRemoval)
|
||||
case meteoraDlmmRemoveLiquidity2Discriminator:
|
||||
var args dlmmRemoveLiquidity2Args
|
||||
if err := agbinary.NewBorshDecoder(decode[8:]).Decode(&args); err != nil {
|
||||
@@ -748,6 +752,7 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
}
|
||||
binChanges = dlmmBinChangesFromReduction(args.BinLiquidityRemoval)
|
||||
startBinId, endBinId = dlmmMinMaxBinIdFromReduction(args.BinLiquidityRemoval)
|
||||
removeBp = dlmmCommonRemoveBp(args.BinLiquidityRemoval)
|
||||
case meteoraDlmmRemoveLiquidityByRangeDiscriminator:
|
||||
var args dlmmRemoveLiquidityByRangeArgs
|
||||
if err := agbinary.NewBorshDecoder(decode[8:]).Decode(&args); err != nil {
|
||||
@@ -755,6 +760,7 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
}
|
||||
startBinId = args.FromBinId
|
||||
endBinId = args.ToBinId
|
||||
removeBp = int32(args.BpsToRemove)
|
||||
binChanges = dlmmBinChangesFromRange(startBinId, endBinId, args.BpsToRemove)
|
||||
case meteoraDlmmRemoveLiquidityByRange2Discriminator:
|
||||
var args dlmmRemoveLiquidityByRange2Args
|
||||
@@ -763,6 +769,7 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
}
|
||||
startBinId = args.FromBinId
|
||||
endBinId = args.ToBinId
|
||||
removeBp = int32(args.BpsToRemove)
|
||||
binChanges = dlmmBinChangesFromRange(startBinId, endBinId, args.BpsToRemove)
|
||||
default:
|
||||
return nil, increaseOffset(offset), InstructionIgnoredError
|
||||
@@ -867,8 +874,10 @@ func metaoradlmmRemoveLiquidityParser(tx *Tx, instruction Instruction, innerInst
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
ActiveBinId: removeEvent.ActiveBinId,
|
||||
StartBinId: startBinId,
|
||||
EndBinId: endBinId,
|
||||
RemoveBp: removeBp,
|
||||
BinChanges: binChanges,
|
||||
}
|
||||
|
||||
@@ -987,6 +996,7 @@ func metaoradlmmClaimFeeParser(tx *Tx, instruction Instruction, innerInstruction
|
||||
EntryContract: entryContract,
|
||||
}
|
||||
if claimEvent.HasActiveBin {
|
||||
swap.ActiveBinId = claimEvent.ActiveBinId
|
||||
swap.StartBinId = claimEvent.ActiveBinId
|
||||
swap.EndBinId = claimEvent.ActiveBinId
|
||||
}
|
||||
@@ -1107,6 +1117,7 @@ func metaoradlmmRebalanceLiquidityParser(tx *Tx, instruction Instruction, innerI
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
ActiveBinId: event.ActiveBinId,
|
||||
StartBinId: event.OldMinBinId,
|
||||
EndBinId: event.OldMaxBinId,
|
||||
BinChanges: dlmmBinChangesFromRange(event.OldMinBinId, event.OldMaxBinId, 0),
|
||||
@@ -1131,6 +1142,7 @@ func metaoradlmmRebalanceLiquidityParser(tx *Tx, instruction Instruction, innerI
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
ActiveBinId: event.ActiveBinId,
|
||||
StartBinId: event.NewMinBinId,
|
||||
EndBinId: event.NewMaxBinId,
|
||||
BinChanges: dlmmBinChangesFromRange(event.NewMinBinId, event.NewMaxBinId, 0),
|
||||
@@ -1706,6 +1718,19 @@ func dlmmBinChangesFromRange(startBinId, endBinId int32, bpsToRemove uint16) []D
|
||||
return changes
|
||||
}
|
||||
|
||||
func dlmmCommonRemoveBp(reduction []dlmmBinLiquidityReduction) int32 {
|
||||
if len(reduction) == 0 {
|
||||
return 0
|
||||
}
|
||||
bpsToRemove := reduction[0].BpsToRemove
|
||||
for _, item := range reduction[1:] {
|
||||
if item.BpsToRemove != bpsToRemove {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
return int32(bpsToRemove)
|
||||
}
|
||||
|
||||
func dlmmMinMaxBinIdFromDistribution(dist []dlmmBinLiquidityDistribution) (int32, int32) {
|
||||
if len(dist) == 0 {
|
||||
return 0, 0
|
||||
|
||||
Reference in New Issue
Block a user