From 6e489cf08f4dc5537df500b9889744ab4d72abab Mon Sep 17 00:00:00 2001 From: Max Voloshinskii Date: Tue, 13 Aug 2024 13:51:47 +0300 Subject: [PATCH] Support custom_payload for jetton transfer --- Source/TonSwift/Jettons/JettonTransferData.swift | 9 ++++++--- Source/TonSwift/Jettons/JettonTransferMessage.swift | 9 +++++++-- Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/TonSwift/Jettons/JettonTransferData.swift b/Source/TonSwift/Jettons/JettonTransferData.swift index a2e1937..3a5112f 100644 --- a/Source/TonSwift/Jettons/JettonTransferData.swift +++ b/Source/TonSwift/Jettons/JettonTransferData.swift @@ -15,6 +15,7 @@ public struct JettonTransferData: CellCodable { public let responseAddress: Address public let forwardAmount: BigUInt public let forwardPayload: Cell? + public var customPayload: Cell? public func storeTo(builder: Builder) throws { try builder.store(uint: OpCodes.JETTON_TRANSFER, bits: 32) @@ -22,7 +23,7 @@ public struct JettonTransferData: CellCodable { try builder.store(coins: Coins(amount.magnitude)) try builder.store(AnyAddress(toAddress)) try builder.store(AnyAddress(responseAddress)) - try builder.store(bit: false) + try builder.storeMaybe(ref: customPayload) try builder.store(coins: Coins(forwardAmount.magnitude)) try builder.storeMaybe(ref: forwardPayload) } @@ -33,7 +34,7 @@ public struct JettonTransferData: CellCodable { let amount = try slice.loadCoins().amount let toAddress: Address = try slice.loadType() let responseAddress: Address = try slice.loadType() - try slice.skip(1) + let customPayload = try slice.loadMaybeRef() let forwardAmount = try slice.loadCoins().amount let forwardPayload = try slice.loadMaybeRef() @@ -43,6 +44,8 @@ public struct JettonTransferData: CellCodable { toAddress: toAddress, responseAddress: responseAddress, forwardAmount: forwardAmount, - forwardPayload: forwardPayload) + forwardPayload: forwardPayload, + customPayload: customPayload + ) } } diff --git a/Source/TonSwift/Jettons/JettonTransferMessage.swift b/Source/TonSwift/Jettons/JettonTransferMessage.swift index 371e8f9..a14497d 100644 --- a/Source/TonSwift/Jettons/JettonTransferMessage.swift +++ b/Source/TonSwift/Jettons/JettonTransferMessage.swift @@ -14,7 +14,10 @@ public struct JettonTransferMessage { bounce: Bool, to: Address, from: Address, - comment: String? = nil) throws -> MessageRelaxed { + comment: String? = nil, + customPayload: Cell? = nil, + stateInit: StateInit? = nil + ) throws -> MessageRelaxed { let forwardAmount = BigUInt(stringLiteral: "1") let jettonTransferAmount = BigUInt(stringLiteral: "640000000") let queryId = UInt64(Date().timeIntervalSince1970) @@ -29,12 +32,14 @@ public struct JettonTransferMessage { toAddress: to, responseAddress: from, forwardAmount: forwardAmount, - forwardPayload: commentCell) + forwardPayload: commentCell, + customPayload: customPayload) return MessageRelaxed.internal( to: jettonAddress, value: jettonTransferAmount, bounce: bounce, + stateInit: stateInit, body: try Builder().store(jettonTransferData).endCell() ) } diff --git a/Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift b/Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift index 6487d06..c02931a 100644 --- a/Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift +++ b/Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift @@ -24,7 +24,8 @@ public struct StonfiSwapMessage { toAddress: try! Address.parse(STONFI_CONSTANTS.RouterAddress), responseAddress: userWalletAddress, forwardAmount: forwardAmount, - forwardPayload: stonfiSwapCell + forwardPayload: stonfiSwapCell, + customPayload: nil ) return MessageRelaxed.internal(