Skip to content

Commit

Permalink
Merge pull request #18 from tonkeeper/feature/support-jetton-custom-p…
Browse files Browse the repository at this point in the history
…ayload

Support custom_payload for jetton transfer
  • Loading branch information
grishamsc authored Aug 13, 2024
2 parents ae84c28 + 6e489cf commit 947f77d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Source/TonSwift/Jettons/JettonTransferData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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)
try builder.store(uint: queryId, bits: 64)
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)
}
Expand All @@ -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()

Expand All @@ -43,6 +44,8 @@ public struct JettonTransferData: CellCodable {
toAddress: toAddress,
responseAddress: responseAddress,
forwardAmount: forwardAmount,
forwardPayload: forwardPayload)
forwardPayload: forwardPayload,
customPayload: customPayload
)
}
}
9 changes: 7 additions & 2 deletions Source/TonSwift/Jettons/JettonTransferMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
)
}
Expand Down
3 changes: 2 additions & 1 deletion Source/TonSwift/StonfiSwap/StonfiSwapMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 947f77d

Please sign in to comment.