Skip to content

Commit

Permalink
Create Dedust straws for swapping jettons and TON
Browse files Browse the repository at this point in the history
  • Loading branch information
erokhinav committed Sep 1, 2024
1 parent 661e733 commit 445df67
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 2 deletions.
133 changes: 132 additions & 1 deletion pkg/bath/dedust.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/tonkeeper/tongo/ton"
)

var DedustSwapStraw = Straw[BubbleJettonSwap]{
var DedustSwapJettonsStraw = Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsJettonTransfer, JettonTransferOperation(abi.DedustSwapJettonOp), func(bubble *Bubble) bool {
transfer := bubble.Info.(BubbleJettonTransfer)
swap, ok := transfer.payload.Value.(abi.DedustSwapJettonPayload)
Expand All @@ -29,6 +29,7 @@ var DedustSwapStraw = Straw[BubbleJettonSwap]{
}},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
transfer := bubble.Info.(BubbleJettonTransfer)
newAction.Success = true
newAction.Dex = Dedust
if transfer.sender != nil {
newAction.UserWallet = transfer.sender.Address
Expand Down Expand Up @@ -66,3 +67,133 @@ var DedustSwapStraw = Straw[BubbleJettonSwap]{
},
},
}

var DedustSwapToTONStraw = Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsJettonTransfer, JettonTransferOperation(abi.DedustSwapJettonOp), func(bubble *Bubble) bool {
transfer := bubble.Info.(BubbleJettonTransfer)
swap, ok := transfer.payload.Value.(abi.DedustSwapJettonPayload)
if !ok {
return false
}
to, err := ton.AccountIDFromTlb(swap.SwapParams.RecipientAddr)
if err != nil {
return false
}
if to == nil {
return true
}
if transfer.sender == nil || transfer.sender.Address != *to {
return false
}
return true
}},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
transfer := bubble.Info.(BubbleJettonTransfer)
newAction.Success = true
newAction.Dex = Dedust
if transfer.sender != nil {
newAction.UserWallet = transfer.sender.Address
}
newAction.In.JettonMaster = transfer.master
newAction.In.JettonWallet = transfer.senderWallet
newAction.In.Amount = big.Int(transfer.amount)
newAction.In.IsTon = transfer.isWrappedTon
if transfer.payload.Value.(abi.DedustSwapJettonPayload).Step.Params.KindOut {
return errors.New("dedust swap: wrong kind of limits") //not supported
}
return nil
},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapExternalMsgOp)},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
newAction.Router = bubble.Info.(BubbleTx).account.Address
return nil
},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustPayoutFromPoolMsgOp)},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation("DedustPayout")},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
transfer := bubble.Info.(BubbleTx)
newAction.Out.IsTon = true
newAction.Out.Amount.SetInt64(transfer.inputAmount)
newAction.Out.JettonWallet = transfer.inputFrom.Address
return nil
},
},
},
},
}

var DedustSwapFromTONStraw = Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapJettonOp), func(bubble *Bubble) bool {
//transfer := bubble.Info.(BubbleJettonTransfer)
//swap, ok := transfer.payload.Value.(abi.DedustSwapJettonPayload)
//if !ok {
// return false
//}
//to, err := ton.AccountIDFromTlb(swap.SwapParams.RecipientAddr)
//if err != nil {
// return false
//}
//if to == nil {
// return true
//}
//if transfer.sender == nil || transfer.sender.Address != *to {
// return false
//}
return true
}},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
transfer := bubble.Info.(BubbleTx)
newAction.Success = true
newAction.Dex = Dedust
if transfer.inputFrom != nil {
newAction.UserWallet = transfer.inputFrom.Address
}
newAction.In.IsTon = true
newAction.In.Amount.SetInt64(transfer.inputAmount)
return nil
},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapExternalMsgOp)},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
newAction.Router = bubble.Info.(BubbleTx).account.Address
return nil
},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustPayoutFromPoolMsgOp)},
SingleChild: &Straw[BubbleJettonSwap]{
CheckFuncs: []bubbleCheck{Or(IsJettonTransfer, IsTx)},
Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error {
if IsJettonTransfer(bubble) {
transfer := bubble.Info.(BubbleJettonTransfer)
newAction.Out.JettonMaster = transfer.master
newAction.Out.Amount = big.Int(transfer.amount)
newAction.Out.JettonWallet = transfer.recipientWallet
} else {
transfer := bubble.Info.(BubbleTx)
newAction.Success = false
newAction.Out.IsTon = true
newAction.Out.Amount.SetInt64(transfer.inputAmount)
newAction.Out.JettonWallet = transfer.inputFrom.Address
}
return nil
},
},
},
},
}

var DedustSwapPeerStraw = Straw[BubbleTx]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapExternalMsgOp)},
Builder: func(newAction *BubbleTx, bubble *Bubble) error {
tx := bubble.Info.(BubbleTx)
newAction.decodedBody = tx.decodedBody
newAction.account.Address = tx.account.Address
return nil
},
SingleChild: &Straw[BubbleTx]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapPeerMsgOp)},
},
}
5 changes: 4 additions & 1 deletion pkg/bath/straws.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ var DefaultStraws = []Merger{
WtonMintStraw,
NftPurchaseStraw,
StonfiSwapStraw,
DedustSwapStraw,
DedustSwapPeerStraw,
DedustSwapJettonsStraw,
DedustSwapToTONStraw,
DedustSwapFromTONStraw,
TgAuctionV1InitialBidStraw,
StrawFindAuctionBidFragmentSimple,
StrawAuctionBigGetgems,
Expand Down

0 comments on commit 445df67

Please sign in to comment.