Skip to content

Commit

Permalink
improve tonstakers messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Jan 29, 2024
1 parent 23b8386 commit 057dc44
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 16 deletions.
59 changes: 57 additions & 2 deletions abi/generated_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package abi

import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions abi/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down
47 changes: 40 additions & 7 deletions abi/messages_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -286,6 +290,9 @@ var opcodedMsgInDecodeFunctions = map[uint32]msgDecoderFunc{
// 0x1596920c
WhalesNominatorsForceKickMsgOpCode: decodeFuncWhalesNominatorsForceKickMsgBody,

// 0x1674b0a0
TonstakePayoutMintJettonsMsgOpCode: decodeFuncTonstakePayoutMintJettonsMsgBody,

// 0x1690c604
TonstakeControllerCreditMsgOpCode: decodeFuncTonstakeControllerCreditMsgBody,

Expand Down Expand Up @@ -557,6 +564,9 @@ var opcodedMsgInDecodeFunctions = map[uint32]msgDecoderFunc{
// 0xdfdca27b
TonstakePoolLoanRepaymentMsgOpCode: decodeFuncTonstakePoolLoanRepaymentMsgBody,

// 0xe0505d0e
TonstakeControllerNewStakeMsgOpCode: decodeFuncTonstakeControllerNewStakeMsgBody,

// 0xe4737472
WalletPluginDestructResponseMsgOpCode: decodeFuncWalletPluginDestructResponseMsgBody,

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1065,7 +1087,8 @@ type ElectorRecoverStakeRequestMsgBody struct {
}

type TonstakePoolDepositMsgBody struct {
QueryId uint64
QueryId uint64
Referral tlb.Any
}

type TeleitemStartAuctionMsgBody struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -1535,6 +1566,7 @@ var KnownMsgInTypes = map[string]any{
TonstakeNftInitMsgOp: TonstakeNftInitMsgBody{},
TonstakeControllerPoolHaltMsgOp: TonstakeControllerPoolHaltMsgBody{},
WhalesNominatorsForceKickMsgOp: WhalesNominatorsForceKickMsgBody{},
TonstakePayoutMintJettonsMsgOp: TonstakePayoutMintJettonsMsgBody{},
TonstakeControllerCreditMsgOp: TonstakeControllerCreditMsgBody{},
JettonInternalTransferMsgOp: JettonInternalTransferMsgBody{},
WhalesNominatorsWithdrawUnownedResponseMsgOp: WhalesNominatorsWithdrawUnownedResponseMsgBody{},
Expand Down Expand Up @@ -1625,6 +1657,7 @@ var KnownMsgInTypes = map[string]any{
TonstakeNftPayoutMsgOp: TonstakeNftPayoutMsgBody{},
ChannelClosedMsgOp: ChannelClosedMsgBody{},
TonstakePoolLoanRepaymentMsgOp: TonstakePoolLoanRepaymentMsgBody{},
TonstakeControllerNewStakeMsgOp: TonstakeControllerNewStakeMsgBody{},
WalletPluginDestructResponseMsgOp: WalletPluginDestructResponseMsgBody{},
DeployStorageContractMsgOp: DeployStorageContractMsgBody{},
TonstakePoolRequestLoanMsgOp: TonstakePoolRequestLoanMsgBody{},
Expand Down
16 changes: 10 additions & 6 deletions abi/schemas/liquid_stacking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@
<internal name="tonstake_controller_validator_withdrawal">
validator_withdrawal#30026327 query_id:uint64 amount:Coins = InternalMsgBody;
</internal>
<!-- <internal name="tonstake_controller_new_stake"> TODO: fix conflict with another new_stake (i che ya etim hotel skazat? v upor ne pomnyu)-->
<!-- new_stake#e0505d0e query_id:uint64 value:Coins validator_pubkey:uint256 stake_at:uint32 max_factor:uint32-->
<!-- adnl_addr:uint256 signature:^(bits512) = InternalMsgBody;-->
<!-- </internal>-->
<internal name="tonstake_controller_new_stake">
new_stake#e0505d0e query_id:uint64 value:Coins validator_pubkey:uint256 stake_at:uint32 max_factor:uint32
adnl_addr:uint256 signature:^(bits512) = InternalMsgBody;
</internal>
<internal name="tonstake_controller_send_request_loan">
send_request_loan#6335b11a query_id:uint64 min_loan:Coins max_loan:Coins max_interst:uint16 = InternalMsgBody;
</internal>
Expand All @@ -121,13 +121,13 @@

<!-- TonStake messages to pool -->
<internal name="tonstake_pool_request_loan">
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;
</internal>
<internal name="tonstake_pool_loan_repayment">
loan_repayment#dfdca27b query_id:uint64 = InternalMsgBody;
</internal>
<internal name="tonstake_pool_deposit">
deposit#47d54391 query_id:uint64 = InternalMsgBody;
deposit#47d54391 query_id:uint64 referral:Cell = InternalMsgBody;
</internal>
<internal name="tonstake_pool_touch">
touch#4bc7c2df query_id:uint64 = InternalMsgBody;
Expand Down Expand Up @@ -204,4 +204,8 @@
tonstake_nft_payout#db3b8abd query_id:uint64 = InternalMsgBody;
</internal>


<internal name="tonstake_payout_mint_jettons">
mint#1674b0a0 query_id:uint64 destination:MsgAddress amount:Coins notification:Coins forward:Coins = InternalMsgBody;
</internal>
</abi>
1 change: 0 additions & 1 deletion abi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package abi
import (
"encoding/json"
"fmt"

"github.com/tonkeeper/tongo/tlb"
)

Expand Down

0 comments on commit 057dc44

Please sign in to comment.