Skip to content

Commit

Permalink
Staking
Browse files Browse the repository at this point in the history
  • Loading branch information
grishamsc committed Jul 28, 2024
1 parent fe4f967 commit c48e590
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Source/TonSwift/Stake/StakeDepositMessage.swift
Original file line number Diff line number Diff line change
@@ -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()
)
}
}
66 changes: 66 additions & 0 deletions Source/TonSwift/Stake/StakeWithdrawMessage.swift
Original file line number Diff line number Diff line change
@@ -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()
)
}
}
4 changes: 4 additions & 0 deletions Source/TonSwift/Util/OpCodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c48e590

Please sign in to comment.