diff --git a/Source/TonSwift/Stake/StakeDepositMessage.swift b/Source/TonSwift/Stake/StakeDepositMessage.swift new file mode 100644 index 0000000..438ad71 --- /dev/null +++ b/Source/TonSwift/Stake/StakeDepositMessage.swift @@ -0,0 +1,55 @@ +import Foundation +import BigInt + +public struct StakeDepositMessage { + public static func whalesInternalMessage(queryId: BigUInt, + poolAddress: Address, + amount: BigUInt, + forwardAmount: BigUInt, + bounce: Bool = true) throws -> MessageRelaxed { + let body = Builder() + try body.store(uint: OpCodes.WHALES_DEPOSIT, bits: 32) + try body.store(uint: queryId, bits: 64) + try body.store(coins: Coins(forwardAmount.magnitude)) + + return MessageRelaxed.internal( + to: poolAddress, + value: amount, + bounce: bounce, + body: try body.asCell() + ) + } + + public static func liquidTFInternalMessage(queryId: BigUInt, + poolAddress: Address, + amount: BigUInt, + bounce: Bool = true) throws -> MessageRelaxed { + let body = Builder() + try body.store(uint: OpCodes.LIQUID_TF_DEPOSIT, bits: 32) + try body.store(uint: queryId, bits: 64) + try body.store(uint: 0x000000000005b7ce, bits: 64) + + return MessageRelaxed.internal( + to: poolAddress, + value: amount, + bounce: bounce, + body: try body.asCell() + ) + } + + public static func tfInternalMessage(queryId: BigUInt, + poolAddress: Address, + amount: BigUInt, + bounce: Bool = true) throws -> MessageRelaxed { + let body = Builder() + try body.store(uint: 0, bits: 32) + try body.writeSnakeData(Data("d".utf8)) + + return MessageRelaxed.internal( + to: poolAddress, + value: amount, + bounce: bounce, + body: try body.asCell() + ) + } +} diff --git a/Source/TonSwift/Stake/StakeWithdrawMessage.swift b/Source/TonSwift/Stake/StakeWithdrawMessage.swift new file mode 100644 index 0000000..9d55ecd --- /dev/null +++ b/Source/TonSwift/Stake/StakeWithdrawMessage.swift @@ -0,0 +1,66 @@ +import Foundation +import BigInt + +public struct StakeWithdrawMessage { + public static func whalesInternalMessage(queryId: BigUInt, + poolAddress: Address, + amount: BigUInt, + withdrawFee: BigUInt, + forwardAmount: BigUInt, + bounce: Bool = true) throws -> MessageRelaxed { + let body = Builder() + try body.store(uint: OpCodes.WHALES_WITHDRAW, bits: 32) + try body.store(uint: queryId, bits: 64) + try body.store(coins: Coins(forwardAmount.magnitude)) + try body.store(coins: Coins(amount.magnitude)) + + return MessageRelaxed.internal( + to: poolAddress, + value: withdrawFee, + bounce: bounce, + body: try body.asCell() + ) + } + + public static func liquidTFInternalMessage(queryId: BigUInt, + amount: BigUInt, + withdrawFee: BigUInt, + jettonWalletAddress: Address, + responseAddress: Address, + bounce: Bool = true) throws -> MessageRelaxed { + let customPayload = Builder() + try customPayload.store(uint: 1, bits: 1) + try customPayload.store(uint: 0, bits: 1) + + let body = Builder() + try body.store(uint: OpCodes.LIQUID_TF_BURN, bits: 32) + try body.store(uint: queryId, bits: 64) + try body.store(coins: Coins(amount.magnitude)) + try body.store(AnyAddress(responseAddress)) + try body.storeMaybe(ref: customPayload.endCell()) + + return MessageRelaxed.internal( + to: jettonWalletAddress, + value: withdrawFee, + bounce: bounce, + body: try body.asCell() + ) + } + + public static func tfInternalMessage(queryId: BigUInt, + poolAddress: Address, + amount: BigUInt, + withdrawFee: BigUInt, + bounce: Bool = true) throws -> MessageRelaxed { + let body = Builder() + try body.store(uint: 0, bits: 32) + try body.writeSnakeData(Data("w".utf8)) + + return MessageRelaxed.internal( + to: poolAddress, + value: withdrawFee, + bounce: bounce, + body: try body.asCell() + ) + } +} diff --git a/Source/TonSwift/Util/OpCodes.swift b/Source/TonSwift/Util/OpCodes.swift index 1b4df1b..a911a71 100644 --- a/Source/TonSwift/Util/OpCodes.swift +++ b/Source/TonSwift/Util/OpCodes.swift @@ -6,4 +6,8 @@ public enum OpCodes { public static var NFT_TRANSFER: Int32 = 0x5fcc3d14 public static var STONFI_SWAP: Int32 = 0x25938561 public static var CHANGE_DNS_RECORD: Int32 = 0x4eb1f0f9 + public static var LIQUID_TF_DEPOSIT: Int32 = 0x47d54391 + public static var LIQUID_TF_BURN: Int32 = 0x595f07bc + public static var WHALES_DEPOSIT: Int32 = 2077040623 + public static var WHALES_WITHDRAW: UInt32 = 3665837821 }