Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom_payload for jetton transfer #18

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading