diff --git a/pkg/bath/bath_test.go b/pkg/bath/bath_test.go index 3fb75a70..3da4d8c2 100644 --- a/pkg/bath/bath_test.go +++ b/pkg/bath/bath_test.go @@ -118,6 +118,21 @@ func TestFindActions(t *testing.T) { tongo.MustParseBlockID("(0,8000000000000000,38474426)"), // dedust swap tongo.MustParseBlockID("(0,8000000000000000,38293409)"), + // dedust swap from TON + tongo.MustParseBlockID("(0,a000000000000000,45489132)"), + tongo.MustParseBlockID("(0,d000000000000000,45499358)"), + tongo.MustParseBlockID("(0,a000000000000000,45489138)"), + tongo.MustParseBlockID("(0,6000000000000000,45501242)"), + tongo.MustParseBlockID("(0,f000000000000000,45499384)"), + tongo.MustParseBlockID("(0,2000000000000000,45500261)"), + tongo.MustParseBlockID("(0,a000000000000000,45489148)"), + // dedust swap to TON + tongo.MustParseBlockID("(0,2000000000000000,45500987)"), + tongo.MustParseBlockID("(0,d000000000000000,45500297)"), + tongo.MustParseBlockID("(0,2000000000000000,45500992)"), + tongo.MustParseBlockID("(0,9000000000000000,45489907)"), + tongo.MustParseBlockID("(0,d000000000000000,45500305)"), + tongo.MustParseBlockID("(0,2000000000000000,45500998)"), // wton mint tongo.MustParseBlockID("(0,8000000000000000,38493203)"), // buy nft on fragment @@ -282,9 +297,19 @@ func TestFindActions(t *testing.T) { filenamePrefix: "tonstake-withdraw", }, { - name: "dedust swap", + name: "dedust swap jettons", hash: "831c7f1efaef9ac58fd39981468cea2bbd9c86a1bb72fc425cfc7734ae4a282f", - filenamePrefix: "dedust-swap", + filenamePrefix: "dedust-swap-jettons", + }, + { + name: "dedust swap from TON", + hash: "05536d0c200ac0d02f93e369fe29571c13b734b7f741c9fb366786d8144f1430", + filenamePrefix: "dedust-swap-from-ton", + }, + { + name: "dedust swap to TON", + hash: "d2249d07091e57c43bcc6978db643dc6af14755e115ac48f6630a315b5e53498", + filenamePrefix: "dedust-swap-to-ton", }, { name: "wton mint", diff --git a/pkg/bath/dedust.go b/pkg/bath/dedust.go index 4721dedc..e7f6d582 100644 --- a/pkg/bath/dedust.go +++ b/pkg/bath/dedust.go @@ -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) @@ -22,6 +22,7 @@ var DedustSwapStraw = Straw[BubbleJettonSwap]{ if to == nil { return true } + // A Dedust user may specify different address to receive resulting jettons. In that case it is not a swap. if transfer.sender == nil || transfer.sender.Address != *to { return false } @@ -29,6 +30,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 @@ -50,7 +52,7 @@ var DedustSwapStraw = Straw[BubbleJettonSwap]{ return nil }, SingleChild: &Straw[BubbleJettonSwap]{ - CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustPayoutFromPoolMsgOp)}, + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustPayoutFromPoolMsgOp), HasInterface(abi.DedustVault)}, SingleChild: &Straw[BubbleJettonSwap]{ CheckFuncs: []bubbleCheck{IsJettonTransfer}, Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { @@ -66,3 +68,103 @@ 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 + } + // A Dedust user may specify different address to receive resulting TON. In that case it is not a swap. + 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), HasInterface(abi.DedustVault)}, + 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) + return nil + }, + }, + }, + }, +} + +var DedustSwapFromTONStraw = Straw[BubbleJettonSwap]{ + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DedustSwapJettonOp)}, + 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), HasInterface(abi.DedustPool)}, + 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), HasInterface(abi.DedustVault)}, + 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 + }, + }, + }, + }, +} diff --git a/pkg/bath/straws.go b/pkg/bath/straws.go index ce03ad04..07864a05 100644 --- a/pkg/bath/straws.go +++ b/pkg/bath/straws.go @@ -44,7 +44,9 @@ var DefaultStraws = []Merger{ WtonMintStraw, NftPurchaseStraw, StonfiSwapStraw, - DedustSwapStraw, + DedustSwapJettonsStraw, + DedustSwapToTONStraw, + DedustSwapFromTONStraw, TgAuctionV1InitialBidStraw, StrawFindAuctionBidFragmentSimple, StrawAuctionBigGetgems, diff --git a/pkg/bath/testdata/dedust-swap-from-ton.json b/pkg/bath/testdata/dedust-swap-from-ton.json new file mode 100644 index 00000000..f001ef42 --- /dev/null +++ b/pkg/bath/testdata/dedust-swap-from-ton.json @@ -0,0 +1,82 @@ +{ + "Actions": [ + { + "JettonSwap": { + "Dex": "dedust", + "UserWallet": "0:bbf975f899fa1eda3f233f0d3748e5cfa7ee2abd69033514373dad3f0286f625", + "Router": "0:82b093867547521aad1a99b245812a6d7477c33e469094a94b20a4eab5ace185", + "In": { + "Amount": 40300000000, + "IsTon": true, + "JettonMaster": "0:0000000000000000000000000000000000000000000000000000000000000000", + "JettonWallet": "0:0000000000000000000000000000000000000000000000000000000000000000" + }, + "Out": { + "Amount": 5340025692789, + "IsTon": false, + "JettonMaster": "0:74d8327471d503e2240345b06fe1a606de1b5e3c70512b5b46791b429dab5eb1", + "JettonWallet": "0:32c573568c839e4309a5d69a5dd742ee33460a2f7d6ceba9336c294ea69ebdf9" + } + }, + "Success": true, + "Type": "JettonSwap", + "BaseTransactions": [ + "c85ebd3043603612af808ab874ac1d19d1a68725afc3c4a78589ed5e88372b21", + "bdef4c941f1f311c7de9badebc71464752c6599ae7cdcf514cd449726d750dd6", + "bd2a3aace72bd31cfc340e6e007cde55c56762de6c3e5c0140dfa9888cd14c78", + "31ce388c6c96285a1f9b879519a8a37901c328501e67d332accca09b78da3697", + "c165515aa665f4a9f828736ba86f067e44433b670d8f82502afb7026c00d4b44", + "e45386d6e4f8e5b6889c6035ef244976d6f467ca2b02d5443ebffd49d8e86761", + "eff450ffcaa225eceb6b9ee2232671ac7e671a5d1103ea25b9dcf986387553e5" + ] + } + ], + "Accounts": [ + { + "Account": "0:32c573568c839e4309a5d69a5dd742ee33460a2f7d6ceba9336c294ea69ebdf9", + "Ton": 14397830, + "Fee": 5178203, + "Jettons": null + }, + { + "Account": "0:7fd1999f57c6c5866fc9ff6b5c36f753b8e0864f68bfb7816b4c0ad9857cb18b", + "Ton": 66800, + "Fee": 4378960, + "Jettons": [ + { + "Address": "0:74d8327471d503e2240345b06fe1a606de1b5e3c70512b5b46791b429dab5eb1", + "Quantity": -5340025692789 + } + ] + }, + { + "Account": "0:82b093867547521aad1a99b245812a6d7477c33e469094a94b20a4eab5ace185", + "Ton": 0, + "Fee": 8334039, + "Jettons": null + }, + { + "Account": "0:bbf975f899fa1eda3f233f0d3748e5cfa7ee2abd69033514373dad3f0286f625", + "Ton": -40046881588, + "Fee": 3857353, + "Jettons": [ + { + "Address": "0:74d8327471d503e2240345b06fe1a606de1b5e3c70512b5b46791b429dab5eb1", + "Quantity": 5340025692789 + } + ] + }, + { + "Account": "0:dae153a74d894bbc32748198cd626e4f5df4a69ad2fa56ce80fc2644b5708d20", + "Ton": 39999832000, + "Fee": 3151203, + "Jettons": null + }, + { + "Account": "0:e5345c28217c39fe412761ae8a5d8149a88d1cffbba5eefd4458a75fd53dc9cb", + "Ton": -556, + "Fee": 7685756, + "Jettons": null + } + ] + } \ No newline at end of file diff --git a/pkg/bath/testdata/dedust-swap.json b/pkg/bath/testdata/dedust-swap-jettons.json similarity index 100% rename from pkg/bath/testdata/dedust-swap.json rename to pkg/bath/testdata/dedust-swap-jettons.json diff --git a/pkg/bath/testdata/dedust-swap-to-ton.json b/pkg/bath/testdata/dedust-swap-to-ton.json new file mode 100644 index 00000000..062a3d89 --- /dev/null +++ b/pkg/bath/testdata/dedust-swap-to-ton.json @@ -0,0 +1,82 @@ +{ + "Actions": [ + { + "JettonSwap": { + "Dex": "dedust", + "UserWallet": "0:24dcbb2b93e27696c3ecf97c7aa46f9bf308dc67da12b04e7d413a99a4fe3b4d", + "Router": "0:948673a596fc6d2c3123dfff64d3231e4d0e16bfaac506d5ebdb09f32b3b9c65", + "In": { + "Amount": 4300989738, + "IsTon": false, + "JettonMaster": "0:2f956143c461769579baef2e32cc2d7bc18283f40d20bb03e432cd603ac33ffc", + "JettonWallet": "0:ce2dcf83c904e25ea4e92f253bd25d811f418450e37dd6fabafc46aa9ab7a1f4" + }, + "Out": { + "Amount": 90997458, + "IsTon": true, + "JettonMaster": "0:0000000000000000000000000000000000000000000000000000000000000000", + "JettonWallet": "0:0000000000000000000000000000000000000000000000000000000000000000" + } + }, + "Success": true, + "Type": "JettonSwap", + "BaseTransactions": [ + "bba7985c6b547c2bce3a2979b41bf5b0c5bf5a399bcbee69a80572039147ce4d", + "93a65eccc2922a64274a090e52973ff9ddd26b86d6458ab2bed36ed3c051ec59", + "7b5190653d6c6aa0992a6382030cc4967d3a5a49f147e060c2c3f305739e4fc6", + "1d2278233670b2a1198d9dca1d88a2e6da50efd03466c5f77d890fd9a36b4bb1", + "25293707e72391b75d835b0d498a70279bb772259d8f33463ed89f9ab4e74751", + "8440c612cc62c2e77e05cd323938bfd37a1973a37c6cc6de200c792161ee7fac", + "0c8dfa6ffc53fcee21ef4a1402850b7a59d2b3a8c94836c67bc5016c7ff7eead" + ] + } + ], + "Accounts": [ + { + "Account": "0:09c5b9b0870270f85a26165b75458ba475e4e5b620a65a5b2ead0b1031126165", + "Ton": 0, + "Fee": 4230411, + "Jettons": [ + { + "Address": "0:2f956143c461769579baef2e32cc2d7bc18283f40d20bb03e432cd603ac33ffc", + "Quantity": 4300989738 + } + ] + }, + { + "Account": "0:24dcbb2b93e27696c3ecf97c7aa46f9bf308dc67da12b04e7d413a99a4fe3b4d", + "Ton": -23549928, + "Fee": 4225786, + "Jettons": [ + { + "Address": "0:2f956143c461769579baef2e32cc2d7bc18283f40d20bb03e432cd603ac33ffc", + "Quantity": -4300989738 + } + ] + }, + { + "Account": "0:948673a596fc6d2c3123dfff64d3231e4d0e16bfaac506d5ebdb09f32b3b9c65", + "Ton": 0, + "Fee": 8425049, + "Jettons": null + }, + { + "Account": "0:ce2dcf83c904e25ea4e92f253bd25d811f418450e37dd6fabafc46aa9ab7a1f4", + "Ton": -26, + "Fee": 5002426, + "Jettons": null + }, + { + "Account": "0:d10fa4fa26903310e34d971e93dc7388135ca8b8a9e85b11c132445f6ce307a3", + "Ton": -4, + "Fee": 5319204, + "Jettons": null + }, + { + "Account": "0:dae153a74d894bbc32748198cd626e4f5df4a69ad2fa56ce80fc2644b5708d20", + "Ton": -6924118, + "Fee": 3271200, + "Jettons": null + } + ] + } \ No newline at end of file