From 057dc44363c8ff4275301f2e1c3316bd36374f38 Mon Sep 17 00:00:00 2001 From: Denis Subbotin Date: Mon, 29 Jan 2024 21:12:38 +0300 Subject: [PATCH] improve tonstakers messages --- abi/generated_test.go | 59 +++++++++++++++++++++++++++++++-- abi/messages.md | 2 ++ abi/messages_generated.go | 47 ++++++++++++++++++++++---- abi/schemas/liquid_stacking.xml | 16 +++++---- abi/types.go | 1 - 5 files changed, 109 insertions(+), 16 deletions(-) diff --git a/abi/generated_test.go b/abi/generated_test.go index bceab089..d58f2155 100644 --- a/abi/generated_test.go +++ b/abi/generated_test.go @@ -1,6 +1,7 @@ package abi import ( + "bytes" "context" "encoding/hex" "encoding/json" @@ -828,6 +829,46 @@ func TestMessageDecoder(t *testing.T) { }, }, }, + { + name: "tonstake_pool_request_loan", + boc: "b5ee9c720101030100d200013ce642c9650000000065b6cf3b70110d9316ec000703ad53b757b0000013a90101d1000000019ffaeafb5c0a05c3cadf83c1b6bf92b8c4f1a1ed6cc85cb06966db625a3e5497a35002916c5fca10248a6de0d838ca41083c4f93f883e435f8afe312b19c0c96788bea004493230238b92a02599a423d9af26e70ff08bf68245f1e6313e2bfc57e94622640020085801828c8392b8937d23ca78d0868ca0b40108579448b2bb5616d3619b098252b3d1002ce8bb0922c22eefb1db577f26b5a7fc6747009655af89d6b3bb6c11ec785d7de", + wantOpName: TonstakePoolRequestLoanMsgOp, + wantValue: TonstakePoolRequestLoanMsgBody{ //not full body scheme described in xml + QueryId: 1706479419, + MinLoan: 300000000000000, + MaxLoan: 1035000000000000, + MaxInterest: 5033, + }, + }, + { + name: "tonstakers deposit with ref", + boc: "b5ee9c7201010101001600002847d54391000b9b404b36b1bb000000000005b7ce", + wantOpName: TonstakePoolDepositMsgOp, + wantValue: TonstakePoolDepositMsgBody{ + QueryId: 0x000B9B404B36B1BB, + Referral: tlb.Any(mustHexToCell("b5ee9c7201010101000a000010000000000005b7ce")), + }, + }, + { + name: "tonstakers deposit without ref", + boc: "b5ee9c7201010101000e00001847d543910000000000000026", + wantOpName: TonstakePoolDepositMsgOp, + wantValue: TonstakePoolDepositMsgBody{ + QueryId: 38, + Referral: tlb.Any{}, + }, + }, + { + name: "tonstakers mint payout", + boc: "b5ee9c7201010101003b0000711674b0a000000000000000268009c314b9687e078372b58521f361c0ce20ea31bec6111dd3293eeeb3112f4972ecbdc9fd867cbc80bebc2001", + wantOpName: TonstakePayoutMintJettonsMsgOp, + wantValue: TonstakePayoutMintJettonsMsgBody{ + QueryId: 38, + Destination: mustAccountIDToMsgAddress("0:4e18a5cb43f03c1b95ac290f9b0e067107518df63088ee9949f77598897a4b97"), + Amount: 104337619762782, + Notification: 100000000, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -850,13 +891,27 @@ func TestMessageDecoder(t *testing.T) { tt.wantValidate(t, value) return } - if !reflect.DeepEqual(tt.wantValue, value) { - t.Fatalf("want value: \n%v\n, got: \n%v", tt.wantValue, value) + b1, err1 := json.Marshal(value) + b2, err2 := json.Marshal(tt.wantValue) + if err1 != nil || err2 != nil { + t.Fatal(err1, err2) + } + if !bytes.Equal(b1, b2) { + t.Fatalf("want value: \n%v\n, got: \n%v", string(b1), string(b2)) } }) } } +func mustHexToCell(s string) boc.Cell { + c, err := boc.DeserializeBocHex(s) + if err != nil { + panic(err) + } + return *c[0] + +} + func TestImplements(t *testing.T) { cases := []struct { iface ContractInterface diff --git a/abi/messages.md b/abi/messages.md index a7faf211..f47b6f63 100644 --- a/abi/messages.md +++ b/abi/messages.md @@ -94,6 +94,7 @@ The list below contains the supported message operations, their names and opcode | TonstakeControllerApprove| 0x7b4b42e6 | | TonstakeControllerCredit| 0x1690c604 | | TonstakeControllerDisapprove| 0xe8a0abfe | +| TonstakeControllerNewStake| 0xe0505d0e | | TonstakeControllerPoolHalt| 0x139a1b4e | | TonstakeControllerPoolSendMessage| 0x270695fb | | TonstakeControllerPoolSetSudoer| 0x79e7c016 | @@ -115,6 +116,7 @@ The list below contains the supported message operations, their names and opcode | TonstakeNftBurnNotification| 0xed58b0b2 | | TonstakeNftInit| 0x132f9a45 | | TonstakeNftPayout| 0xdb3b8abd | +| TonstakePayoutMintJettons| 0x1674b0a0 | | TonstakePoolDeployController| 0xb27edcad | | TonstakePoolDeposit| 0x47d54391 | | TonstakePoolLoanRepayment| 0xdfdca27b | diff --git a/abi/messages_generated.go b/abi/messages_generated.go index 09754d88..a5e1eb55 100644 --- a/abi/messages_generated.go +++ b/abi/messages_generated.go @@ -33,6 +33,8 @@ var ( decodeFuncTonstakeControllerPoolHaltMsgBody = decodeMsg(tlb.Tag{Val: 0x139a1b4e, Len: 32}, TonstakeControllerPoolHaltMsgOp, TonstakeControllerPoolHaltMsgBody{}) // 0x1596920c decodeFuncWhalesNominatorsForceKickMsgBody = decodeMsg(tlb.Tag{Val: 0x1596920c, Len: 32}, WhalesNominatorsForceKickMsgOp, WhalesNominatorsForceKickMsgBody{}) + // 0x1674b0a0 + decodeFuncTonstakePayoutMintJettonsMsgBody = decodeMsg(tlb.Tag{Val: 0x1674b0a0, Len: 32}, TonstakePayoutMintJettonsMsgOp, TonstakePayoutMintJettonsMsgBody{}) // 0x1690c604 decodeFuncTonstakeControllerCreditMsgBody = decodeMsg(tlb.Tag{Val: 0x1690c604, Len: 32}, TonstakeControllerCreditMsgOp, TonstakeControllerCreditMsgBody{}) // 0x178d4519 @@ -213,6 +215,8 @@ var ( decodeFuncChannelClosedMsgBody = decodeMsg(tlb.Tag{Val: 0xdddc88ba, Len: 32}, ChannelClosedMsgOp, ChannelClosedMsgBody{}) // 0xdfdca27b decodeFuncTonstakePoolLoanRepaymentMsgBody = decodeMsg(tlb.Tag{Val: 0xdfdca27b, Len: 32}, TonstakePoolLoanRepaymentMsgOp, TonstakePoolLoanRepaymentMsgBody{}) + // 0xe0505d0e + decodeFuncTonstakeControllerNewStakeMsgBody = decodeMsg(tlb.Tag{Val: 0xe0505d0e, Len: 32}, TonstakeControllerNewStakeMsgOp, TonstakeControllerNewStakeMsgBody{}) // 0xe4737472 decodeFuncWalletPluginDestructResponseMsgBody = decodeMsg(tlb.Tag{Val: 0xe4737472, Len: 32}, WalletPluginDestructResponseMsgOp, WalletPluginDestructResponseMsgBody{}) // 0xe4748df1 @@ -286,6 +290,9 @@ var opcodedMsgInDecodeFunctions = map[uint32]msgDecoderFunc{ // 0x1596920c WhalesNominatorsForceKickMsgOpCode: decodeFuncWhalesNominatorsForceKickMsgBody, + // 0x1674b0a0 + TonstakePayoutMintJettonsMsgOpCode: decodeFuncTonstakePayoutMintJettonsMsgBody, + // 0x1690c604 TonstakeControllerCreditMsgOpCode: decodeFuncTonstakeControllerCreditMsgBody, @@ -557,6 +564,9 @@ var opcodedMsgInDecodeFunctions = map[uint32]msgDecoderFunc{ // 0xdfdca27b TonstakePoolLoanRepaymentMsgOpCode: decodeFuncTonstakePoolLoanRepaymentMsgBody, + // 0xe0505d0e + TonstakeControllerNewStakeMsgOpCode: decodeFuncTonstakeControllerNewStakeMsgBody, + // 0xe4737472 WalletPluginDestructResponseMsgOpCode: decodeFuncWalletPluginDestructResponseMsgBody, @@ -617,6 +627,7 @@ const ( TonstakeNftInitMsgOp MsgOpName = "TonstakeNftInit" TonstakeControllerPoolHaltMsgOp MsgOpName = "TonstakeControllerPoolHalt" WhalesNominatorsForceKickMsgOp MsgOpName = "WhalesNominatorsForceKick" + TonstakePayoutMintJettonsMsgOp MsgOpName = "TonstakePayoutMintJettons" TonstakeControllerCreditMsgOp MsgOpName = "TonstakeControllerCredit" JettonInternalTransferMsgOp MsgOpName = "JettonInternalTransfer" WhalesNominatorsWithdrawUnownedResponseMsgOp MsgOpName = "WhalesNominatorsWithdrawUnownedResponse" @@ -707,6 +718,7 @@ const ( TonstakeNftPayoutMsgOp MsgOpName = "TonstakeNftPayout" ChannelClosedMsgOp MsgOpName = "ChannelClosed" TonstakePoolLoanRepaymentMsgOp MsgOpName = "TonstakePoolLoanRepayment" + TonstakeControllerNewStakeMsgOp MsgOpName = "TonstakeControllerNewStake" WalletPluginDestructResponseMsgOp MsgOpName = "WalletPluginDestructResponse" DeployStorageContractMsgOp MsgOpName = "DeployStorageContract" TonstakePoolRequestLoanMsgOp MsgOpName = "TonstakePoolRequestLoan" @@ -738,6 +750,7 @@ const ( TonstakeNftInitMsgOpCode MsgOpCode = 0x132f9a45 TonstakeControllerPoolHaltMsgOpCode MsgOpCode = 0x139a1b4e WhalesNominatorsForceKickMsgOpCode MsgOpCode = 0x1596920c + TonstakePayoutMintJettonsMsgOpCode MsgOpCode = 0x1674b0a0 TonstakeControllerCreditMsgOpCode MsgOpCode = 0x1690c604 JettonInternalTransferMsgOpCode MsgOpCode = 0x178d4519 WhalesNominatorsWithdrawUnownedResponseMsgOpCode MsgOpCode = 0x1d1715bf @@ -828,6 +841,7 @@ const ( TonstakeNftPayoutMsgOpCode MsgOpCode = 0xdb3b8abd ChannelClosedMsgOpCode MsgOpCode = 0xdddc88ba TonstakePoolLoanRepaymentMsgOpCode MsgOpCode = 0xdfdca27b + TonstakeControllerNewStakeMsgOpCode MsgOpCode = 0xe0505d0e WalletPluginDestructResponseMsgOpCode MsgOpCode = 0xe4737472 DeployStorageContractMsgOpCode MsgOpCode = 0xe4748df1 TonstakePoolRequestLoanMsgOpCode MsgOpCode = 0xe642c965 @@ -933,6 +947,14 @@ type WhalesNominatorsForceKickMsgBody struct { QueryId int64 } +type TonstakePayoutMintJettonsMsgBody struct { + QueryId uint64 + Destination tlb.MsgAddress + Amount tlb.Grams + Notification tlb.Grams + Forward tlb.Grams +} + type TonstakeControllerCreditMsgBody struct { QueryId uint64 Amount tlb.Grams @@ -1065,7 +1087,8 @@ type ElectorRecoverStakeRequestMsgBody struct { } type TonstakePoolDepositMsgBody struct { - QueryId uint64 + QueryId uint64 + Referral tlb.Any } type TeleitemStartAuctionMsgBody struct { @@ -1447,6 +1470,16 @@ type TonstakePoolLoanRepaymentMsgBody struct { QueryId uint64 } +type TonstakeControllerNewStakeMsgBody struct { + QueryId uint64 + Value tlb.Grams + ValidatorPubkey tlb.Uint256 + StakeAt uint32 + MaxFactor uint32 + AdnlAddr tlb.Uint256 + Signature tlb.Bits512 `tlb:"^"` +} + type WalletPluginDestructResponseMsgBody struct{} type DeployStorageContractMsgBody struct { @@ -1458,12 +1491,10 @@ type DeployStorageContractMsgBody struct { } type TonstakePoolRequestLoanMsgBody struct { - QueryId uint64 - MinLoan tlb.Grams - MaxLoan tlb.Grams - MaxInterest uint16 - ControllerId uint32 - Validator tlb.MsgAddress + QueryId uint64 + MinLoan tlb.Grams + MaxLoan tlb.Grams + MaxInterest tlb.Uint24 } type TonstakeControllerDisapproveMsgBody struct { @@ -1535,6 +1566,7 @@ var KnownMsgInTypes = map[string]any{ TonstakeNftInitMsgOp: TonstakeNftInitMsgBody{}, TonstakeControllerPoolHaltMsgOp: TonstakeControllerPoolHaltMsgBody{}, WhalesNominatorsForceKickMsgOp: WhalesNominatorsForceKickMsgBody{}, + TonstakePayoutMintJettonsMsgOp: TonstakePayoutMintJettonsMsgBody{}, TonstakeControllerCreditMsgOp: TonstakeControllerCreditMsgBody{}, JettonInternalTransferMsgOp: JettonInternalTransferMsgBody{}, WhalesNominatorsWithdrawUnownedResponseMsgOp: WhalesNominatorsWithdrawUnownedResponseMsgBody{}, @@ -1625,6 +1657,7 @@ var KnownMsgInTypes = map[string]any{ TonstakeNftPayoutMsgOp: TonstakeNftPayoutMsgBody{}, ChannelClosedMsgOp: ChannelClosedMsgBody{}, TonstakePoolLoanRepaymentMsgOp: TonstakePoolLoanRepaymentMsgBody{}, + TonstakeControllerNewStakeMsgOp: TonstakeControllerNewStakeMsgBody{}, WalletPluginDestructResponseMsgOp: WalletPluginDestructResponseMsgBody{}, DeployStorageContractMsgOp: DeployStorageContractMsgBody{}, TonstakePoolRequestLoanMsgOp: TonstakePoolRequestLoanMsgBody{}, diff --git a/abi/schemas/liquid_stacking.xml b/abi/schemas/liquid_stacking.xml index 8b653564..b280659e 100644 --- a/abi/schemas/liquid_stacking.xml +++ b/abi/schemas/liquid_stacking.xml @@ -105,10 +105,10 @@ validator_withdrawal#30026327 query_id:uint64 amount:Coins = InternalMsgBody; - - - - + + new_stake#e0505d0e query_id:uint64 value:Coins validator_pubkey:uint256 stake_at:uint32 max_factor:uint32 + adnl_addr:uint256 signature:^(bits512) = InternalMsgBody; + send_request_loan#6335b11a query_id:uint64 min_loan:Coins max_loan:Coins max_interst:uint16 = InternalMsgBody; @@ -121,13 +121,13 @@ - request_loan#e642c965 query_id:uint64 min_loan:Coins max_loan:Coins max_interest:uint16 controller_id:uint32 validator:MsgAddress = InternalMsgBody; + request_loan#e642c965 query_id:uint64 min_loan:Coins max_loan:Coins max_interest:uint24 = InternalMsgBody; loan_repayment#dfdca27b query_id:uint64 = InternalMsgBody; - deposit#47d54391 query_id:uint64 = InternalMsgBody; + deposit#47d54391 query_id:uint64 referral:Cell = InternalMsgBody; touch#4bc7c2df query_id:uint64 = InternalMsgBody; @@ -204,4 +204,8 @@ tonstake_nft_payout#db3b8abd query_id:uint64 = InternalMsgBody; + + + mint#1674b0a0 query_id:uint64 destination:MsgAddress amount:Coins notification:Coins forward:Coins = InternalMsgBody; + \ No newline at end of file diff --git a/abi/types.go b/abi/types.go index b3fa0a99..0a1fede8 100644 --- a/abi/types.go +++ b/abi/types.go @@ -5,7 +5,6 @@ package abi import ( "encoding/json" "fmt" - "github.com/tonkeeper/tongo/tlb" )