Skip to content

Commit

Permalink
Fix order risks
Browse files Browse the repository at this point in the history
  • Loading branch information
erokhinav committed Oct 1, 2024
1 parent 1bc669c commit daaca93
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/api/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ func (h *Handler) convertMultisig(ctx context.Context, item core.Multisig) (*oas
for _, account := range order.Signers {
signers = append(signers, account.ToRaw())
}
messages, err := convertMultisigActionsToRawMessages(order.Actions)
if err != nil {
return nil, err
}
risk, err := walletPkg.ExtractRiskFromRawMessages(messages)
risk, err := walletPkg.ExtractRiskFromActions(order.Actions)
if err != nil {
return nil, err
}
Expand Down
50 changes: 50 additions & 0 deletions pkg/wallet/risk.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,53 @@ func ExtractRiskFromRawMessages(rawMessages []tongoWallet.RawMessage) (*Risk, er
}
return &risk, nil
}

func ExtractRiskFromActions(actions []abi.MultisigSendMessageAction) (*Risk, error) {
risk := Risk{
TransferAllRemainingBalance: false,
Jettons: map[tongo.AccountID]big.Int{},
}
for _, action := range actions {
if tongoWallet.IsMessageModeSet(int(action.SendMessage.Field0.Mode), tongoWallet.AttachAllRemainingBalance) {
risk.TransferAllRemainingBalance = true
}
m := action.SendMessage.Field0.Message
tonValue := uint64(m.MessageInternal.Value.Grams)
destination, err := ton.AccountIDFromTlb(m.MessageInternal.Dest)
if err != nil {
return nil, err
}
risk.Ton += tonValue
msgBody := m.MessageInternal.Body.Value.Value
if err != nil {
continue
}
switch x := msgBody.(type) {
case abi.NftTransferMsgBody:
if destination == nil {
continue
}
// here, destination is an NFT
risk.Nfts = append(risk.Nfts, *destination)
case abi.JettonBurnMsgBody:
if destination == nil {
continue
}
// here, destination is a jetton wallet
amount := big.Int(x.Amount)
currentJettons := risk.Jettons[*destination]
var total big.Int
risk.Jettons[*destination] = *total.Add(&currentJettons, &amount)
case abi.JettonTransferMsgBody:
if destination == nil {
continue
}
// here, destination is a jetton wallet
amount := big.Int(x.Amount)
currentJettons := risk.Jettons[*destination]
var total big.Int
risk.Jettons[*destination] = *total.Add(&currentJettons, &amount)
}
}
return &risk, nil
}

0 comments on commit daaca93

Please sign in to comment.