SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
3.0 KB · 79 lines swift
Raw Blame History
1import Foundation23public struct TransferFeeConfigExtensionState: Token2022ExtensionState {4    public struct TransferFee: BorshCodable, Codable, Equatable, Hashable {5        public let epoch: UInt646        public let maximumFee: UInt647        public let transferFeeBasisPoints: UInt1689        public init(from reader: inout BinaryReader) throws {10            epoch = try UInt64(from: &reader)11            maximumFee = try UInt64(from: &reader)12            transferFeeBasisPoints = try UInt16(from: &reader)13        }1415        public func serialize(to data: inout Data) throws {16            try epoch.serialize(to: &data)17            try maximumFee.serialize(to: &data)18            try transferFeeBasisPoints.serialize(to: &data)19        }2021        init(22            epoch: UInt64,23            maximumFee: UInt64,24            transferFeeBasisPoints: UInt1625        ) {26            self.epoch = epoch27            self.maximumFee = maximumFee28            self.transferFeeBasisPoints = transferFeeBasisPoints29        }30    }3132    public let length: UInt1633    /// Optional authority to set the fee34    public let transferFeeConfigAuthority: PublicKey35    /// Withdraw from mint instructions must be signed by this key36    public let withdrawWithHeldAuthority: PublicKey37    /// Withheld transfer fee tokens that have been moved to the mint for38    /// withdrawal39    public let withheldAmount: UInt6440    /// Older transfer fee, used if the current epoch < new_transfer_fee.epoch41    public let olderTransferFee: TransferFee42    /// Newer transfer fee, used if the current epoch >= new_transfer_fee.epoch43    public let newerTransferFee: TransferFee4445    public init(from reader: inout BinaryReader) throws {46        length = try UInt16(from: &reader)47        transferFeeConfigAuthority = try PublicKey(from: &reader)48        withdrawWithHeldAuthority = try PublicKey(from: &reader)49        withheldAmount = try UInt64(from: &reader)50        olderTransferFee = try TransferFee(from: &reader)51        newerTransferFee = try TransferFee(from: &reader)52    }5354    public func serialize(to data: inout Data) throws {55        try length.serialize(to: &data)56        try transferFeeConfigAuthority.serialize(to: &data)57        try withdrawWithHeldAuthority.serialize(to: &data)58        try withheldAmount.serialize(to: &data)59        try olderTransferFee.serialize(to: &data)60        try newerTransferFee.serialize(to: &data)61    }6263    init(64        length: UInt16,65        transferFeeConfigAuthority: PublicKey,66        withdrawWithHeldAuthority: PublicKey,67        withheldAmount: UInt64,68        olderTransferFee: TransferFeeConfigExtensionState.TransferFee,69        newerTransferFee: TransferFeeConfigExtensionState.TransferFee70    ) {71        self.length = length72        self.transferFeeConfigAuthority = transferFeeConfigAuthority73        self.withdrawWithHeldAuthority = withdrawWithHeldAuthority74        self.withheldAmount = withheldAmount75        self.olderTransferFee = olderTransferFee76        self.newerTransferFee = newerTransferFee77    }78}79