Skip to content

Commit

Permalink
Merge pull request #196 from tonkeeper/fix-stonfi-payload
Browse files Browse the repository at this point in the history
Fix STONfi "add_liquidity" jetton payload
  • Loading branch information
mr-tron authored Oct 26, 2023
2 parents 8a256db + 6363003 commit 9372d7c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 45 deletions.
23 changes: 23 additions & 0 deletions abi/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,29 @@ func TestMessageDecoder(t *testing.T) {
},
},

{
name: "stonfi - add liquidity msg",
boc: "te6ccgEBAgEAaQABcQ+KfqUAG7D3vuOIZGBOjTVqXIgA7zuZAqJxsqAciTilI8/iTnGEeq62piAAHtRKd6wOcJwQOAdDAwEAVfz55Y+AAioWoxZMTVqjEz8xEP8QSW4AyorIq+/8UCfgJNM0gMPqAn/Zhg0=",
wantOpName: JettonTransferMsgOp,
wantValue: JettonTransferMsgBody{
QueryId: 7794402477181028,
Amount: tlb.VarUInteger16(*big.NewInt(5398024594888)),
Destination: mustAccountIDToMsgAddress("0:779dcc815138d9500e449c5291e7f12738c23d575b5310000f6a253bd607384e"),
ResponseDestination: tlb.MsgAddress{SumType: "AddrNone"},
ForwardTonAmount: tlb.VarUInteger16(*big.NewInt(235000000)),
ForwardPayload: tlb.EitherRef[JettonPayload]{
IsRight: true,
Value: JettonPayload{
SumType: "StonfiProvideLiquidity",
OpCode: pointer[uint32](4244235663),
Value: StonfiProvideLiquidityJettonPayload{
TokenWallet: mustAccountIDToMsgAddress("0:1150b518b2626ad51899f98887f8824b70065456455f7fe2813f012699a4061f"),
MinLpOut: tlb.VarUInteger16(*big.NewInt(5367448326)),
},
},
},
},
},
{
name: "stonfi swap",
boc: "te6ccgEBAgEAoQABsSWThWEAF9FtgGlyuYAVUoS5uZxArCUbLyf7phLgN5PBW9e9kIid2rJzK9oArXAARULUYsmJq1RiZ+YiH+IJLcAZUVkVff+KBPwEmmaQGH1EVt4eddAYMnVDAQCFgBVShLm5nECsJRsvJ/umEuA3k8Fb172QiJ3asnMr2gCtcAGyO71SfAD9PQh0Amu3lB+P3U1Zntjnpj9CbVcj8DiPLg==",
Expand Down
86 changes: 44 additions & 42 deletions abi/jetton_msg_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package abi

import (
"errors"

"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
)
Expand Down Expand Up @@ -78,10 +79,10 @@ func (j *JettonPayload) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error
j.Value = res
return nil
}
case StofiProvideLiquidityJettonOpCode: // 0xfcf9e58f
var res StofiProvideLiquidityJettonPayload
case StonfiProvideLiquidityJettonOpCode: // 0xfcf9e58f
var res StonfiProvideLiquidityJettonPayload
if err := tlb.Unmarshal(tempCell, &res); err == nil {
j.SumType = StofiProvideLiquidityJettonOp
j.SumType = StonfiProvideLiquidityJettonOp
j.Value = res
return nil
}
Expand All @@ -94,48 +95,48 @@ func (j *JettonPayload) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error
}

const (
TextCommentJettonOp JettonOpName = "TextComment"
TegroJettonSwapJettonOp JettonOpName = "TegroJettonSwap"
EncryptedTextCommentJettonOp JettonOpName = "EncryptedTextComment"
StonfiSwapJettonOp JettonOpName = "StonfiSwap"
TegroAddLiquidityJettonOp JettonOpName = "TegroAddLiquidity"
StonfiSwapOkRefJettonOp JettonOpName = "StonfiSwapOkRef"
StonfiSwapOkJettonOp JettonOpName = "StonfiSwapOk"
DedustSwapJettonOp JettonOpName = "DedustSwap"
StofiProvideLiquidityJettonOp JettonOpName = "StofiProvideLiquidity"

TextCommentJettonOpCode JettonOpCode = 0x00000000
TegroJettonSwapJettonOpCode JettonOpCode = 0x01fb7a25
EncryptedTextCommentJettonOpCode JettonOpCode = 0x2167da4b
StonfiSwapJettonOpCode JettonOpCode = 0x25938561
TegroAddLiquidityJettonOpCode JettonOpCode = 0x287e167a
StonfiSwapOkRefJettonOpCode JettonOpCode = 0x45078540
StonfiSwapOkJettonOpCode JettonOpCode = 0xc64370e5
DedustSwapJettonOpCode JettonOpCode = 0xe3a0d482
StofiProvideLiquidityJettonOpCode JettonOpCode = 0xfcf9e58f
TextCommentJettonOp JettonOpName = "TextComment"
TegroJettonSwapJettonOp JettonOpName = "TegroJettonSwap"
EncryptedTextCommentJettonOp JettonOpName = "EncryptedTextComment"
StonfiSwapJettonOp JettonOpName = "StonfiSwap"
TegroAddLiquidityJettonOp JettonOpName = "TegroAddLiquidity"
StonfiSwapOkRefJettonOp JettonOpName = "StonfiSwapOkRef"
StonfiSwapOkJettonOp JettonOpName = "StonfiSwapOk"
DedustSwapJettonOp JettonOpName = "DedustSwap"
StonfiProvideLiquidityJettonOp JettonOpName = "StonfiProvideLiquidity"

TextCommentJettonOpCode JettonOpCode = 0x00000000
TegroJettonSwapJettonOpCode JettonOpCode = 0x01fb7a25
EncryptedTextCommentJettonOpCode JettonOpCode = 0x2167da4b
StonfiSwapJettonOpCode JettonOpCode = 0x25938561
TegroAddLiquidityJettonOpCode JettonOpCode = 0x287e167a
StonfiSwapOkRefJettonOpCode JettonOpCode = 0x45078540
StonfiSwapOkJettonOpCode JettonOpCode = 0xc64370e5
DedustSwapJettonOpCode JettonOpCode = 0xe3a0d482
StonfiProvideLiquidityJettonOpCode JettonOpCode = 0xfcf9e58f
)

var KnownJettonTypes = map[string]any{
TextCommentJettonOp: TextCommentJettonPayload{},
TegroJettonSwapJettonOp: TegroJettonSwapJettonPayload{},
EncryptedTextCommentJettonOp: EncryptedTextCommentJettonPayload{},
StonfiSwapJettonOp: StonfiSwapJettonPayload{},
TegroAddLiquidityJettonOp: TegroAddLiquidityJettonPayload{},
StonfiSwapOkRefJettonOp: StonfiSwapOkRefJettonPayload{},
StonfiSwapOkJettonOp: StonfiSwapOkJettonPayload{},
DedustSwapJettonOp: DedustSwapJettonPayload{},
StofiProvideLiquidityJettonOp: StofiProvideLiquidityJettonPayload{},
TextCommentJettonOp: TextCommentJettonPayload{},
TegroJettonSwapJettonOp: TegroJettonSwapJettonPayload{},
EncryptedTextCommentJettonOp: EncryptedTextCommentJettonPayload{},
StonfiSwapJettonOp: StonfiSwapJettonPayload{},
TegroAddLiquidityJettonOp: TegroAddLiquidityJettonPayload{},
StonfiSwapOkRefJettonOp: StonfiSwapOkRefJettonPayload{},
StonfiSwapOkJettonOp: StonfiSwapOkJettonPayload{},
DedustSwapJettonOp: DedustSwapJettonPayload{},
StonfiProvideLiquidityJettonOp: StonfiProvideLiquidityJettonPayload{},
}
var jettonOpCodes = map[JettonOpName]JettonOpCode{
TextCommentJettonOp: TextCommentJettonOpCode,
TegroJettonSwapJettonOp: TegroJettonSwapJettonOpCode,
EncryptedTextCommentJettonOp: EncryptedTextCommentJettonOpCode,
StonfiSwapJettonOp: StonfiSwapJettonOpCode,
TegroAddLiquidityJettonOp: TegroAddLiquidityJettonOpCode,
StonfiSwapOkRefJettonOp: StonfiSwapOkRefJettonOpCode,
StonfiSwapOkJettonOp: StonfiSwapOkJettonOpCode,
DedustSwapJettonOp: DedustSwapJettonOpCode,
StofiProvideLiquidityJettonOp: StofiProvideLiquidityJettonOpCode,
TextCommentJettonOp: TextCommentJettonOpCode,
TegroJettonSwapJettonOp: TegroJettonSwapJettonOpCode,
EncryptedTextCommentJettonOp: EncryptedTextCommentJettonOpCode,
StonfiSwapJettonOp: StonfiSwapJettonOpCode,
TegroAddLiquidityJettonOp: TegroAddLiquidityJettonOpCode,
StonfiSwapOkRefJettonOp: StonfiSwapOkRefJettonOpCode,
StonfiSwapOkJettonOp: StonfiSwapOkJettonOpCode,
DedustSwapJettonOp: DedustSwapJettonOpCode,
StonfiProvideLiquidityJettonOp: StonfiProvideLiquidityJettonOpCode,
}

type TextCommentJettonPayload struct {
Expand Down Expand Up @@ -176,6 +177,7 @@ type DedustSwapJettonPayload struct {
SwapParams DedustSwapParams `tlb:"^"`
}

type StofiProvideLiquidityJettonPayload struct {
MinLpOut tlb.VarUInteger16
type StonfiProvideLiquidityJettonPayload struct {
TokenWallet tlb.MsgAddress
MinLpOut tlb.VarUInteger16
}
4 changes: 2 additions & 2 deletions abi/schemas/ston-fi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<jetton_payload name="stonfi_swap" >
swap#25938561 token_wallet:MsgAddress min_out:(VarUInteger 16) to_address:MsgAddress referral_address:(Maybe MsgAddress) = JettonPayload;
</jetton_payload>
<jetton_payload name="stofi_provide_liquidity">
provide_liquidity#fcf9e58f min_lp_out:(VarUInteger 16) = JettonPayload;
<jetton_payload name="stonfi_provide_liquidity">
provide_liquidity#fcf9e58f token_wallet:MsgAddress min_lp_out:(VarUInteger 16) = JettonPayload;
</jetton_payload>
<jetton_payload name="stonfi_swap_ok" fixed_lengt="true">
swap_success#c64370e5 = JettonPayload;
Expand Down
6 changes: 5 additions & 1 deletion boc/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,13 @@ func (c *Cell) CopyRemaining() *Cell {
for c.RefsAvailableForRead() > 0 {
ref, err := c.NextRef()
if err != nil {
// this should never happen but anyway
panic(err)
}
if err := c2.AddRef(ref); err != nil {
// this should never happen but anyway
panic(err)
}
c2.AddRef(ref)
}
c.refCursor = refCursor
return c2
Expand Down

0 comments on commit 9372d7c

Please sign in to comment.