From e2da312cfce035e6d5a33f524dd75468a441d66e Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Wed, 9 Oct 2024 11:22:21 +0000 Subject: [PATCH 1/6] Add simple v2 straw --- pkg/bath/stonfi.go | 115 ++++++++++++++++++++++++++++++++++++++ pkg/core/trace.go | 19 ++++++- pkg/litestorage/stonfi.go | 64 +++++++++++++-------- 3 files changed, 173 insertions(+), 25 deletions(-) diff --git a/pkg/bath/stonfi.go b/pkg/bath/stonfi.go index 46dcd873..2a6ff38c 100644 --- a/pkg/bath/stonfi.go +++ b/pkg/bath/stonfi.go @@ -122,6 +122,121 @@ var StonfiSwapStraw = Straw[BubbleJettonSwap]{ }, } +var StonfiV2PTONStraw = Straw[BubbleJettonTransfer]{ + CheckFuncs: []bubbleCheck{IsTx, HasInterface(abi.JettonWallet), HasOperation(abi.JettonTransferMsgOp)}, + Builder: func(newAction *BubbleJettonTransfer, bubble *Bubble) error { + tx := bubble.Info.(BubbleTx) + newAction.master, _ = tx.additionalInfo.JettonMaster(tx.account.Address) + newAction.senderWallet = tx.account.Address + newAction.sender = tx.inputFrom + body := tx.decodedBody.Value.(abi.JettonTransferMsgBody) + newAction.amount = body.Amount + newAction.isWrappedTon = true + recipient, err := ton.AccountIDFromTlb(body.Destination) + if err == nil { + newAction.recipient = &Account{Address: *recipient} + } + return nil + }, + SingleChild: &Straw[BubbleJettonTransfer]{ + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.JettonNotifyMsgOp)}, + Builder: func(newAction *BubbleJettonTransfer, bubble *Bubble) error { + tx := bubble.Info.(BubbleTx) + newAction.success = true + body := tx.decodedBody.Value.(abi.JettonNotifyMsgBody) + newAction.amount = body.Amount + newAction.payload = body.ForwardPayload.Value + newAction.recipient = &tx.account + return nil + }, + }, +} + +var StonfiSwapV2Straw = Straw[BubbleJettonSwap]{ + CheckFuncs: []bubbleCheck{func(bubble *Bubble) bool { + jettonTx, ok := bubble.Info.(BubbleJettonTransfer) + if !ok { + return false + } + if jettonTx.sender == nil { + return false + } + if jettonTx.payload.SumType != abi.StonfiSwapV2JettonOp { + return false + } + swap, ok := jettonTx.payload.Value.(abi.StonfiSwapV2JettonPayload) + if !ok { + return false + } + to, err := ton.AccountIDFromTlb(swap.CrossSwapBody.Receiver) + if err != nil || to == nil { + return false + } + if jettonTx.sender.Address != *to { //protection against invalid swaps + return false + } + return true + }}, + Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { + newAction.Dex = Stonfi + jettonTx := bubble.Info.(BubbleJettonTransfer) + newAction.UserWallet = jettonTx.sender.Address + newAction.In.Amount = big.Int(jettonTx.amount) + newAction.In.IsTon = jettonTx.isWrappedTon + newAction.In.JettonMaster = jettonTx.master + return nil + }, + SingleChild: &Straw[BubbleJettonSwap]{ + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.StonfiSwapV2MsgOp), HasInterface(abi.StonfiPoolV2)}, + Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { + tx := bubble.Info.(BubbleTx) + a, b := tx.additionalInfo.STONfiPool.Token0, tx.additionalInfo.STONfiPool.Token1 + body := tx.decodedBody.Value.(abi.StonfiSwapV2MsgBody) + if body.QueryId > 0 && a.IsZero() && b.IsZero() { + return nil + } + //newAction.Out.Amount = big.Int(body.MinOut) + //s, err := tongo.AccountIDFromTlb(body.SenderAddress) + //if err != nil { + // return err + //} + //if s != nil && *s == b { + // a, b = b, a + //} + //newAction.In.JettonWallet = a + //newAction.Out.JettonWallet = b + //if tx.additionalInfo != nil { + // newAction.In.JettonMaster, _ = tx.additionalInfo.JettonMaster(a) + // newAction.Out.JettonMaster, _ = tx.additionalInfo.JettonMaster(b) + //} + return nil + }, + SingleChild: &Straw[BubbleJettonSwap]{ + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.StonfiPayToV2MsgOp)}, + Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { + tx := bubble.Info.(BubbleTx) + newAction.Router = tx.account.Address + return nil + }, + SingleChild: &Straw[BubbleJettonSwap]{ + CheckFuncs: []bubbleCheck{Is(BubbleJettonTransfer{})}, + Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { + jettonTx := bubble.Info.(BubbleJettonTransfer) + if jettonTx.senderWallet != newAction.Out.JettonWallet { + // operation has failed, + // stonfi's sent jettons back to the user + return nil + } + newAction.Out.Amount = big.Int(jettonTx.amount) + newAction.Out.IsTon = jettonTx.isWrappedTon + newAction.Success = true + return nil + }, + }, + }, + }, +} + // https://dev.tonviewer.com/transaction/e19381edd8f05922eeba3c31f4b8b4b737478b4ca7b37130bdbbfd7bfa773227 // todo: add liquidity (mint lp tokens) var StonfiMintStraw = Straw[BubbleJettonMint]{} diff --git a/pkg/core/trace.go b/pkg/core/trace.go index bb86fb4b..3b499100 100644 --- a/pkg/core/trace.go +++ b/pkg/core/trace.go @@ -101,6 +101,18 @@ type STONfiPool struct { Token1 tongo.AccountID } +type STONfiVersion string + +const ( + STONfiPoolV1 STONfiVersion = "v1" + STONfiPoolV2 STONfiVersion = "v2" +) + +type STONfiPoolID struct { + ID tongo.AccountID + Version STONfiVersion +} + // InformationSource provides methods to construct TraceAdditionalInfo. type InformationSource interface { JettonMastersForWallets(ctx context.Context, wallets []tongo.AccountID) (map[tongo.AccountID]tongo.AccountID, error) @@ -151,7 +163,7 @@ func CollectAdditionalInfo(ctx context.Context, infoSource InformationSource, tr } var jettonWallets []tongo.AccountID var saleContracts []tongo.AccountID - var stonfiPoolIDs []tongo.AccountID + var stonfiPoolIDs []STONfiPoolID Visit(trace, func(trace *Trace) { // when we emulate a trace, // we construct "trace.AdditionalInfo" in emulatedTreeToTrace for all accounts the trace touches. @@ -169,7 +181,10 @@ func CollectAdditionalInfo(ctx context.Context, infoSource InformationSource, tr saleContracts = append(saleContracts, trace.Account) } if hasInterface(trace.AccountInterfaces, abi.StonfiPool) { - stonfiPoolIDs = append(stonfiPoolIDs, trace.Account) + stonfiPoolIDs = append(stonfiPoolIDs, STONfiPoolID{ID: trace.Account, Version: STONfiPoolV1}) + } + if hasInterface(trace.AccountInterfaces, abi.StonfiPoolV2) { + stonfiPoolIDs = append(stonfiPoolIDs, STONfiPoolID{ID: trace.Account, Version: STONfiPoolV2}) } }) stonfiPools, err := infoSource.STONfiPools(ctx, stonfiPoolIDs) diff --git a/pkg/litestorage/stonfi.go b/pkg/litestorage/stonfi.go index edc1ee02..e6f1c426 100644 --- a/pkg/litestorage/stonfi.go +++ b/pkg/litestorage/stonfi.go @@ -8,34 +8,52 @@ import ( "github.com/tonkeeper/tongo/abi" ) -func (s *LiteStorage) STONfiPools(ctx context.Context, poolIDs []tongo.AccountID) (map[tongo.AccountID]core.STONfiPool, error) { +func (s *LiteStorage) STONfiPools(ctx context.Context, poolIDs []core.STONfiPoolID) (map[tongo.AccountID]core.STONfiPool, error) { pools := make(map[tongo.AccountID]core.STONfiPool) for _, poolID := range poolIDs { - _, value, err := abi.GetPoolData(ctx, s.executor, poolID) + _, value, err := abi.GetPoolData(ctx, s.executor, poolID.ID) if err != nil { return nil, err } - result, ok := value.(abi.GetPoolData_StonfiResult) - if !ok { - continue - } - token0, err := tongo.AccountIDFromTlb(result.Token0Address) - if err != nil { - return nil, err - } - if token0 == nil { - continue - } - token1, err := tongo.AccountIDFromTlb(result.Token1Address) - if err != nil { - return nil, err - } - if token1 == nil { - continue - } - pools[poolID] = core.STONfiPool{ - Token0: *token0, - Token1: *token1, + switch result := value.(type) { + case abi.GetPoolData_StonfiResult: + token0, err := tongo.AccountIDFromTlb(result.Token0Address) + if err != nil { + return nil, err + } + if token0 == nil { + continue + } + token1, err := tongo.AccountIDFromTlb(result.Token1Address) + if err != nil { + return nil, err + } + if token1 == nil { + continue + } + pools[poolID.ID] = core.STONfiPool{ + Token0: *token0, + Token1: *token1, + } + case abi.GetPoolData_StonfiV2Result: + token0, err := tongo.AccountIDFromTlb(result.Token0WalletAddress) + if err != nil { + return nil, err + } + if token0 == nil { + continue + } + token1, err := tongo.AccountIDFromTlb(result.Token1WalletAddress) + if err != nil { + return nil, err + } + if token1 == nil { + continue + } + pools[poolID.ID] = core.STONfiPool{ + Token0: *token0, + Token1: *token1, + } } } return pools, nil From 42f0f52c01b4e75556a8d21a24c40da7549cfcf9 Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Wed, 9 Oct 2024 14:50:27 +0000 Subject: [PATCH 2/6] refactor --- pkg/bath/stonfi.go | 28 ++++++++++++++-------------- pkg/bath/straws.go | 1 + pkg/core/trace.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/bath/stonfi.go b/pkg/bath/stonfi.go index 2a6ff38c..8e4f5392 100644 --- a/pkg/bath/stonfi.go +++ b/pkg/bath/stonfi.go @@ -195,20 +195,20 @@ var StonfiSwapV2Straw = Straw[BubbleJettonSwap]{ if body.QueryId > 0 && a.IsZero() && b.IsZero() { return nil } - //newAction.Out.Amount = big.Int(body.MinOut) - //s, err := tongo.AccountIDFromTlb(body.SenderAddress) - //if err != nil { - // return err - //} - //if s != nil && *s == b { - // a, b = b, a - //} - //newAction.In.JettonWallet = a - //newAction.Out.JettonWallet = b - //if tx.additionalInfo != nil { - // newAction.In.JettonMaster, _ = tx.additionalInfo.JettonMaster(a) - // newAction.Out.JettonMaster, _ = tx.additionalInfo.JettonMaster(b) - //} + newAction.Out.Amount = big.Int(body.DexPayload.SwapBody.MinOut) + s, err := tongo.AccountIDFromTlb(body.FromUser) + if err != nil { + return err + } + if s != nil && *s == b { + a, b = b, a + } + newAction.In.JettonWallet = a + newAction.Out.JettonWallet = b + if tx.additionalInfo != nil { + newAction.In.JettonMaster, _ = tx.additionalInfo.JettonMaster(a) + newAction.Out.JettonMaster, _ = tx.additionalInfo.JettonMaster(b) + } return nil }, SingleChild: &Straw[BubbleJettonSwap]{ diff --git a/pkg/bath/straws.go b/pkg/bath/straws.go index 2b13e6d9..7a017c45 100644 --- a/pkg/bath/straws.go +++ b/pkg/bath/straws.go @@ -45,6 +45,7 @@ var DefaultStraws = []Merger{ WtonMintStraw, NftPurchaseStraw, StonfiSwapStraw, + StonfiSwapV2Straw, DedustSwapJettonsStraw, DedustSwapToTONStraw, DedustSwapFromTONStraw, diff --git a/pkg/core/trace.go b/pkg/core/trace.go index 3b499100..9dfa95ef 100644 --- a/pkg/core/trace.go +++ b/pkg/core/trace.go @@ -117,7 +117,7 @@ type STONfiPoolID struct { type InformationSource interface { JettonMastersForWallets(ctx context.Context, wallets []tongo.AccountID) (map[tongo.AccountID]tongo.AccountID, error) NftSaleContracts(ctx context.Context, contracts []tongo.AccountID) (map[tongo.AccountID]NftSaleContract, error) - STONfiPools(ctx context.Context, poolIDs []tongo.AccountID) (map[tongo.AccountID]STONfiPool, error) + STONfiPools(ctx context.Context, poolIDs []STONfiPoolID) (map[tongo.AccountID]STONfiPool, error) } func isDestinationJettonWallet(inMsg *Message) bool { From 051d66816d9af4897e5e7bf04285716a50d8d5e0 Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Wed, 9 Oct 2024 16:02:48 +0000 Subject: [PATCH 3/6] Add PTON straw --- pkg/bath/stonfi.go | 15 ++++++++------- pkg/bath/straws.go | 1 + pkg/core/trace.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/bath/stonfi.go b/pkg/bath/stonfi.go index 8e4f5392..9a40c1fe 100644 --- a/pkg/bath/stonfi.go +++ b/pkg/bath/stonfi.go @@ -1,6 +1,7 @@ package bath import ( + "github.com/tonkeeper/tongo/tlb" "github.com/tonkeeper/tongo/ton" "math/big" @@ -123,16 +124,16 @@ var StonfiSwapStraw = Straw[BubbleJettonSwap]{ } var StonfiV2PTONStraw = Straw[BubbleJettonTransfer]{ - CheckFuncs: []bubbleCheck{IsTx, HasInterface(abi.JettonWallet), HasOperation(abi.JettonTransferMsgOp)}, + CheckFuncs: []bubbleCheck{IsTx, HasInterface(abi.JettonWallet), HasOperation(abi.PtonTonTransferMsgOp)}, Builder: func(newAction *BubbleJettonTransfer, bubble *Bubble) error { tx := bubble.Info.(BubbleTx) newAction.master, _ = tx.additionalInfo.JettonMaster(tx.account.Address) newAction.senderWallet = tx.account.Address newAction.sender = tx.inputFrom - body := tx.decodedBody.Value.(abi.JettonTransferMsgBody) - newAction.amount = body.Amount + body := tx.decodedBody.Value.(abi.PtonTonTransferMsgBody) + newAction.amount = tlb.VarUInteger16(*big.NewInt(int64(body.TonAmount))) newAction.isWrappedTon = true - recipient, err := ton.AccountIDFromTlb(body.Destination) + recipient, err := ton.AccountIDFromTlb(body.RefundAddress) if err == nil { newAction.recipient = &Account{Address: *recipient} } @@ -195,14 +196,14 @@ var StonfiSwapV2Straw = Straw[BubbleJettonSwap]{ if body.QueryId > 0 && a.IsZero() && b.IsZero() { return nil } - newAction.Out.Amount = big.Int(body.DexPayload.SwapBody.MinOut) - s, err := tongo.AccountIDFromTlb(body.FromUser) + s, err := tongo.AccountIDFromTlb(body.DexPayload.TokenWallet1) if err != nil { return err } - if s != nil && *s == b { + if s != nil && *s == a { a, b = b, a } + newAction.In.Amount = big.Int(body.RightAmount) newAction.In.JettonWallet = a newAction.Out.JettonWallet = b if tx.additionalInfo != nil { diff --git a/pkg/bath/straws.go b/pkg/bath/straws.go index 7a017c45..49ead9b1 100644 --- a/pkg/bath/straws.go +++ b/pkg/bath/straws.go @@ -39,6 +39,7 @@ var DefaultStraws = []Merger{ NftTransferStraw, NftTransferNotifyStraw, JettonTransferPTONStraw, + StonfiV2PTONStraw, JettonTransferClassicStraw, JettonTransferMinimalStraw, JettonBurnStraw, diff --git a/pkg/core/trace.go b/pkg/core/trace.go index 9dfa95ef..1f26effa 100644 --- a/pkg/core/trace.go +++ b/pkg/core/trace.go @@ -224,7 +224,7 @@ func CollectAdditionalInfo(ctx context.Context, infoSource InformationSource, tr additionalInfo.NftSaleContract = &sale } } - if hasInterface(trace.AccountInterfaces, abi.StonfiPool) { + if hasInterface(trace.AccountInterfaces, abi.StonfiPool) || hasInterface(trace.AccountInterfaces, abi.StonfiPoolV2) { if pool, ok := stonfiPools[trace.Account]; ok { additionalInfo.STONfiPool = &pool additionalInfo.SetJettonMaster(pool.Token0, masters[pool.Token0]) From 8f00ddce76408b66788205ab9f3d21664fa47cef Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Wed, 9 Oct 2024 20:37:42 +0000 Subject: [PATCH 4/6] add tests --- pkg/bath/bath_test.go | 24 +++- pkg/bath/testdata/stonfi-v2-swap-ref.json | 131 +++++++++++++++++++ pkg/bath/testdata/stonfi-v2-swap-simple.json | 98 ++++++++++++++ 3 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 pkg/bath/testdata/stonfi-v2-swap-ref.json create mode 100644 pkg/bath/testdata/stonfi-v2-swap-simple.json diff --git a/pkg/bath/bath_test.go b/pkg/bath/bath_test.go index 6254e1cc..c593dd80 100644 --- a/pkg/bath/bath_test.go +++ b/pkg/bath/bath_test.go @@ -5,12 +5,12 @@ import ( "context" "encoding/json" "fmt" + "github.com/tonkeeper/opentonapi/internal/g" "os" "sort" "testing" "github.com/stretchr/testify/require" - "github.com/tonkeeper/opentonapi/internal/g" "github.com/tonkeeper/opentonapi/pkg/core" "github.com/tonkeeper/tongo" "github.com/tonkeeper/tongo/liteapi" @@ -57,7 +57,7 @@ func (m *mockInfoSource) JettonMastersForWallets(ctx context.Context, wallets [] return m.OnJettonMastersForWallets(ctx, wallets) } -func (m *mockInfoSource) STONfiPools(ctx context.Context, pools []tongo.AccountID) (map[tongo.AccountID]core.STONfiPool, error) { +func (m *mockInfoSource) STONfiPools(ctx context.Context, pools []core.STONfiPoolID) (map[tongo.AccountID]core.STONfiPool, error) { return map[tongo.AccountID]core.STONfiPool{}, nil } @@ -166,6 +166,16 @@ func TestFindActions(t *testing.T) { tongo.MustParseBlockID("(0,8000000000000000,33600829)"), // failed dedust swap tongo.MustParseBlockID("(0,7000000000000000,45592983)"), + // stonfi v2 swap simple + tongo.MustParseBlockID("(0,6000000000000000,46034062)"), + tongo.MustParseBlockID("(0,e000000000000000,46027828)"), + tongo.MustParseBlockID("(0,9000000000000000,45998794)"), + tongo.MustParseBlockID("(0,6000000000000000,46034070)"), + tongo.MustParseBlockID("(0,6000000000000000,46034067)"), + // stonfi v2 swap with ref + tongo.MustParseBlockID("(0,2000000000000000,46145069)"), + tongo.MustParseBlockID("(0,6000000000000000,46151880)"), + tongo.MustParseBlockID("(0,2000000000000000,46145074)"), }), ) @@ -411,6 +421,16 @@ func TestFindActions(t *testing.T) { hash: "887c7763f41ca4a4b9de28900ab514caabc0c27ed5b41d9918d60f5e7f4a9d96", filenamePrefix: "failed-dedust-swap", }, + { + name: "stonfi v2 swap simple", + hash: "3fa256638e5f6cd356afa70eb37c89de80846973dea0c9c46adf4df5cca39a68", + filenamePrefix: "stonfi-v2-swap-simple", + }, + { + name: "stonfi v2 swap with ref", + hash: "d70fddb4786c04932669bf589ee73c16293115a1927dfbee5b719304232e2e1b", + filenamePrefix: "stonfi-v2-swap-ref", + }, } { t.Run(c.name, func(t *testing.T) { trace, err := storage.GetTrace(context.Background(), tongo.MustParseHash(c.hash)) diff --git a/pkg/bath/testdata/stonfi-v2-swap-ref.json b/pkg/bath/testdata/stonfi-v2-swap-ref.json new file mode 100644 index 00000000..f9211c8e --- /dev/null +++ b/pkg/bath/testdata/stonfi-v2-swap-ref.json @@ -0,0 +1,131 @@ +{ + "Actions": [ + { + "JettonSwap": { + "Dex": "stonfi", + "UserWallet": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80", + "Router": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46", + "In": { + "Amount": 793509017, + "IsTon": true, + "JettonMaster": "0:671963027f7f85659ab55b821671688601cdcf1ee674fc7fbbb1a776a18d34a3", + "JettonWallet": "0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf" + }, + "Out": { + "Amount": 4165614, + "IsTon": false, + "JettonMaster": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "JettonWallet": "0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5" + } + }, + "Success": true, + "Type": "JettonSwap", + "BaseTransactions": [ + "d5f3ba7bdec7c81c39f6944208ad4059990dea6279830b6add7e078789f0fa88", + "135f4d0e0ae8522e90d53f9df8704e10d5c52fcdc59c3b3d0f29d58c4d18c4c8", + "6a264b138e5aa033fa4da2434d10aa18ce1029c82e2bb364c37ee78142890f9a", + "2e29dd132181ab545786cf46b7a11f0a1ce6181e83d38cd7e3e4e286663a539e", + "44fb8b15c09564851dfa7518c0a0151e840fce72d25139afbfc720b1ad0302bd", + "f12140b774c67599c6c8f67880d05c9d4177df5af7ad5275a450be926e9c0993", + "3cb721a7b14724d8acc5fa82e0a735da50cf54bba25e32b4d0f2c142c782ce1e" + ] + }, + { + "SmartContractExec": { + "TonAttached": 36574051, + "Executor": "0:4e7714a51a18f18d5615c22e9b947c5f4b5b56b0e5deb0cac0d67a67ba259e38", + "Contract": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46", + "Operation": "StonfiPayVaultV2", + "Payload": "AdditionalInfo:\n Amount0Out: \"4174\"\n Amount1Out: \"0\"\n Token0Address: 0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5\n Token1Address: 0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf\nExcessesAddress: 0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80\nOwner: 0:b089166b7d44a530cd1dcfe1e6e0a5b522a685cf53f0c60dfeb748d00eddfaa8\nQueryId: 24196457155416\n" + }, + "Success": true, + "Type": "SmartContractExec", + "BaseTransactions": [ + "e7a1470824486dad13292d6f8dd495f1a041c5a5ca04e4e746af79b95df96f2e" + ] + }, + { + "SmartContractExec": { + "TonAttached": 29176851, + "Executor": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46", + "Contract": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831", + "Operation": "StonfiDepositRefFeeV2", + "Payload": "ExcessesAddress: 0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80\nJettonAmount: \"4174\"\nQueryId: 24196457155416\n" + }, + "Success": true, + "Type": "SmartContractExec", + "BaseTransactions": [ + "be717a41e4e2c7870fe0c9104c4789766b382a62ab95dc403012e98609ed48d2" + ] + }, + { + "TonTransfer": { + "Amount": 26388041, + "Comment": null, + "EncryptedComment": null, + "Recipient": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80", + "Sender": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831", + "Refund": null + }, + "Success": true, + "Type": "TonTransfer", + "BaseTransactions": [ + "066e82c2a58b9dacea02d83e6017f002bcd6818f2609e54c3bc319ddd5959a0b" + ] + } + ], + "Accounts": [ + { + "Account": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80", + "Ton": -840494007, + "Fee": 4830408, + "Jettons": [ + { + "Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "Quantity": 4165614 + } + ] + }, + { + "Account": "0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5", + "Ton": -2, + "Fee": 1549602, + "Jettons": null + }, + { + "Account": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46", + "Ton": 0, + "Fee": 22854803, + "Jettons": [ + { + "Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "Quantity": -4165614 + } + ] + }, + { + "Account": "0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf", + "Ton": 793509017, + "Fee": 4381202, + "Jettons": null + }, + { + "Account": "0:4e7714a51a18f18d5615c22e9b947c5f4b5b56b0e5deb0cac0d67a67ba259e38", + "Ton": 0, + "Fee": 9723203, + "Jettons": null + }, + { + "Account": "0:506e1af93741d3a8147ba27ed2bb43e48734e9b1dd56d5a8b5991919138c7dfe", + "Ton": 1170, + "Fee": 855794, + "Jettons": null + }, + { + "Account": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831", + "Ton": 0, + "Fee": 2788810, + "Jettons": null + } + ] + } \ No newline at end of file diff --git a/pkg/bath/testdata/stonfi-v2-swap-simple.json b/pkg/bath/testdata/stonfi-v2-swap-simple.json new file mode 100644 index 00000000..f6f447d4 --- /dev/null +++ b/pkg/bath/testdata/stonfi-v2-swap-simple.json @@ -0,0 +1,98 @@ +{ + "Actions": [ + { + "JettonSwap": { + "Dex": "stonfi", + "UserWallet": "0:68524f62c0ca74e5b7ce11031816b183ce213486cb216049393634164de821fe", + "Router": "0:f0ca38239d35c954f8d78e2dce3ed52295c0a371e19540e2c6c2bf7fb112e322", + "In": { + "Amount": 29592300, + "IsTon": false, + "JettonMaster": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "JettonWallet": "0:f2bd9f9d79482377ef150ad15aa88dfc2505e771beb2dd89308c6fe02765ce5c" + }, + "Out": { + "Amount": 7809813506, + "IsTon": false, + "JettonMaster": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f", + "JettonWallet": "0:9ffcc843698c05629b3f8c7791fd2c3a601107364064f9be6cfde58c35d0bf0f" + } + }, + "Success": true, + "Type": "JettonSwap", + "BaseTransactions": [ + "fc3171638353c317415a3e467ae33ecf01cd0262af5d92527737032f40f95c8e", + "3888fe02c074f4380ec4512b9881d595d7acd8963597f4958017c3dc183d9d79", + "7ccd855d615fb16f5ae1b3b7fc7d7a0fc0080b44c46f3e6c5014bcd6cb01d562", + "5066094bc706f67cf71ccabfc42306bdb6a99ed82771a6ab5da237998d2f99fb", + "650488391db16d8c62103f8a35079fb549935e5200a2aa31969d6fb42cf55648", + "f818a26e94fe3e9333e7e64419be5f45a37698d1044a0a4795a4d2bd0cc52f12", + "881e913f8bb411991ef4db9c54b74b629bd4ec12915dd9a8a8da77f7729b87e3", + "8bee1d42e4ea2fa15afacf2604161a725a5a4120049140bc8543d119f892f8bb", + "91a8f3f529a050adc7823c76c2eb2819041c44ab843aec0595bb8ef078d4c2b6" + ] + } + ], + "Accounts": [ + { + "Account": "0:51aa642c8acb57e3e2976bd5b30a1beb62da3913429eb87b31503c1eeedb12ec", + "Ton": -8, + "Fee": 2140008, + "Jettons": null + }, + { + "Account": "0:5aa3722ccb24812e0ab1831f106f51d0fa2600b49947a4364150a9584850e08c", + "Ton": 11825309, + "Fee": 3574691, + "Jettons": null + }, + { + "Account": "0:68524f62c0ca74e5b7ce11031816b183ce213486cb216049393634164de821fe", + "Ton": -54844851, + "Fee": 4914441, + "Jettons": [ + { + "Address": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f", + "Quantity": 7809813506 + }, + { + "Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "Quantity": -29592300 + } + ] + }, + { + "Account": "0:9ffcc843698c05629b3f8c7791fd2c3a601107364064f9be6cfde58c35d0bf0f", + "Ton": -20, + "Fee": 7669220, + "Jettons": null + }, + { + "Account": "0:f0ca38239d35c954f8d78e2dce3ed52295c0a371e19540e2c6c2bf7fb112e322", + "Ton": 0, + "Fee": 15364406, + "Jettons": [ + { + "Address": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f", + "Quantity": -7809813506 + }, + { + "Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe", + "Quantity": 29592300 + } + ] + }, + { + "Account": "0:f2bd9f9d79482377ef150ad15aa88dfc2505e771beb2dd89308c6fe02765ce5c", + "Ton": 0, + "Fee": 1974403, + "Jettons": null + }, + { + "Account": "0:fd104b6df84fc43ab7044e9d804c6d8252fc03586ff54b32cb3fbd85e9ad74d4", + "Ton": 0, + "Fee": 7382401, + "Jettons": null + } + ] + } \ No newline at end of file From 4bab28c651272030d6b100e1771d62fc18d6f817 Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Thu, 10 Oct 2024 08:05:19 +0000 Subject: [PATCH 5/6] check STONfiPool for nil --- pkg/bath/stonfi.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/bath/stonfi.go b/pkg/bath/stonfi.go index 9a40c1fe..7e8ac292 100644 --- a/pkg/bath/stonfi.go +++ b/pkg/bath/stonfi.go @@ -188,7 +188,16 @@ var StonfiSwapV2Straw = Straw[BubbleJettonSwap]{ return nil }, SingleChild: &Straw[BubbleJettonSwap]{ - CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.StonfiSwapV2MsgOp), HasInterface(abi.StonfiPoolV2)}, + CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.StonfiSwapV2MsgOp), HasInterface(abi.StonfiPoolV2), func(bubble *Bubble) bool { + tx, ok := bubble.Info.(BubbleTx) + if !ok { + return false + } + if tx.additionalInfo.STONfiPool == nil { + return false + } + return true + }}, Builder: func(newAction *BubbleJettonSwap, bubble *Bubble) error { tx := bubble.Info.(BubbleTx) a, b := tx.additionalInfo.STONfiPool.Token0, tx.additionalInfo.STONfiPool.Token1 From 6518ee00af93bad7d8568c723144c80e3f02ae05 Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Thu, 10 Oct 2024 08:35:20 +0000 Subject: [PATCH 6/6] get only amount from transfers --- pkg/bath/stonfi.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/bath/stonfi.go b/pkg/bath/stonfi.go index 7e8ac292..7bfe8be7 100644 --- a/pkg/bath/stonfi.go +++ b/pkg/bath/stonfi.go @@ -212,7 +212,6 @@ var StonfiSwapV2Straw = Straw[BubbleJettonSwap]{ if s != nil && *s == a { a, b = b, a } - newAction.In.Amount = big.Int(body.RightAmount) newAction.In.JettonWallet = a newAction.Out.JettonWallet = b if tx.additionalInfo != nil {