Skip to content

Commit

Permalink
Fix: ics withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 1, 2024
1 parent 5a44411 commit 7b9dde9
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions pkg/indexer/decode/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func parseIcs20Withdrawal(body *astria.Action_Ics20Withdrawal, from string, heig
if body.Ics20Withdrawal.GetTimeoutTime() > 0 {
action.Data["timeout_time"] = body.Ics20Withdrawal.GetTimeoutTime()
}

returnAddress := body.Ics20Withdrawal.GetReturnAddress().GetBech32M()
if bridge := body.Ics20Withdrawal.GetBridgeAddress().GetBech32M(); bridge != "" {
action.Data["bridge"] = bridge
addr := ctx.Addresses.Set(bridge, height, decAmount.Copy().Neg(), asset, 1, 0)
Expand All @@ -184,6 +186,30 @@ func parseIcs20Withdrawal(body *astria.Action_Ics20Withdrawal, from string, heig
Height: action.Height,
ActionType: action.Type,
})
if returnAddress != bridge {
returnAddr := ctx.Addresses.Set(returnAddress, height, decAmount, asset, 1, 0)
action.Addresses = append(action.Addresses, &storage.AddressAction{
Address: returnAddr,
Action: action,
Time: action.Time,
Height: action.Height,
ActionType: action.Type,
})

action.BalanceUpdates = append(action.BalanceUpdates, storage.BalanceUpdate{
Address: returnAddr,
Height: action.Height,
Currency: body.Ics20Withdrawal.GetDenom(),
Update: decAmount,
})
} else {
action.BalanceUpdates = append(action.BalanceUpdates, storage.BalanceUpdate{
Address: addr,
Height: action.Height,
Currency: body.Ics20Withdrawal.GetDenom(),
Update: decAmount,
})
}
} else {
addr := ctx.Addresses.Set(from, height, decAmount.Copy().Neg(), asset, 1, 0)
action.Addresses = append(action.Addresses, &storage.AddressAction{
Expand All @@ -193,24 +219,30 @@ func parseIcs20Withdrawal(body *astria.Action_Ics20Withdrawal, from string, heig
Height: action.Height,
ActionType: action.Type,
})
if returnAddress != from {
returnAddr := ctx.Addresses.Set(returnAddress, height, decAmount, asset, 1, 0)
action.Addresses = append(action.Addresses, &storage.AddressAction{
Address: returnAddr,
Action: action,
Time: action.Time,
Height: action.Height,
ActionType: action.Type,
})
action.BalanceUpdates = append(action.BalanceUpdates, storage.BalanceUpdate{
Address: returnAddr,
Height: action.Height,
Currency: body.Ics20Withdrawal.GetDenom(),
Update: decAmount,
})
} else {
action.BalanceUpdates = append(action.BalanceUpdates, storage.BalanceUpdate{
Address: addr,
Height: action.Height,
Currency: body.Ics20Withdrawal.GetDenom(),
Update: decAmount,
})
}
}

returnAddress := body.Ics20Withdrawal.GetReturnAddress().GetBech32M()
addr := ctx.Addresses.Set(returnAddress, height, decAmount, asset, 1, 0)
action.Addresses = append(action.Addresses, &storage.AddressAction{
Address: addr,
Action: action,
Time: action.Time,
Height: action.Height,
ActionType: action.Type,
})

action.BalanceUpdates = append(action.BalanceUpdates, storage.BalanceUpdate{
Address: addr,
Height: action.Height,
Currency: body.Ics20Withdrawal.GetDenom(),
Update: decAmount,
})
}
return nil
}
Expand Down

0 comments on commit 7b9dde9

Please sign in to comment.