OperationFactory

public class OperationFactory

Class responsible for creating operations necessary to perform a given action, and converting those operations into the single payload expected by the RPC. Although not every action requires more than one operation, all functions will return an array, for consistency.

Operation Builders

  • Create the operations necessary to send an amount of a token to a destination address.

    Declaration

    Swift

    public static func sendOperation(_ tokenAmount: TokenAmount, of token: Token, from: String, to: String) -> [Operation]

    Parameters

    _

    The amount of the given token to send.

    of

    The Token type that will be sent.

    from

    The address to deduct the funds from.

    to

    The destination address that will recieve the funds.

    Return Value

    An array of Operation subclasses.

  • Create the operations necessary to send aan NFT

    Declaration

    Swift

    public static func sendOperation(_ amount: Decimal, ofNft nft: NFT, from: String, to: String) -> [Operation]

    Parameters

    ofNft

    The NFT type that will be sent.

    from

    The address to deduct the funds from.

    to

    The destination address that will recieve the funds.

    Return Value

    An array of Operation subclasses.

  • Create the operations necessary to delegate funds to a baker.

    Declaration

    Swift

    public static func delegateOperation(to: String, from: String) -> [Operation]

    Parameters

    to

    The address of the baker to delegate to.

    from

    The address that wishes to delegate its funds.

    Return Value

    An array of Operation subclasses.

  • Create the operations necessary to remove the current delegate from an address.

    Declaration

    Swift

    public static func undelegateOperation(address: String) -> [Operation]

    Parameters

    address

    The address that wishes to remove its delegate.

    Return Value

    An array of Operation subclasses.

  • Create the operations necessary to perform an exchange of XTZ for a given FA token, using a given dex

    Declaration

    Swift

    public static func swapXtzToToken(withDex dex: DipDupExchange, xtzAmount: XTZAmount, minTokenAmount: TokenAmount, walletAddress: String, timeout: TimeInterval) -> [Operation]

    Parameters

    withDex

    Enum controling which dex to use to perform the swap

    xtzAmount

    The amount of XTZ to be swaped

    minTokenAmount

    The minimum token amount you will accept

    wallet

    The wallet signing the operation

    timeout

    Max amount of time to wait before asking the node to cancel the operation

    Return Value

    An array of Operation subclasses.

Allowance (approve, update_operators)

  • Create an operation to call the entrypoint approve, to allow another address to spend some of your token (only FA1.2) Used when interacting with smart contract applications like Dexter or QuipuSwap

    Declaration

    Swift

    public static func approveOperation(tokenAddress: String, spenderAddress: String, allowance: TokenAmount, walletAddress: String) -> Operation

    Parameters

    tokenAddress

    The address of the token contract

    spenderAddress

    The address that is being given permission to spend the users balance

    allowance

    The allowance to set for the given contract

    wallet

    The wallet signing the operation

    Return Value

    An OperationTransaction which will invoke a smart contract call

  • Create an operation to call the entrypoint update_operators, to allow another address to spend some of your token (only FA2) Used when interacting with smart contract applications like Dexter or QuipuSwap

    Declaration

    Swift

    public static func updateOperatorsOperation(tokenAddress: String, tokenId: String, spenderAddress: String, walletAddress: String) -> Operation

    Parameters

    tokenAddress

    The address of the token contract

    spenderAddress

    The address that is being given permission to spend the users balance

    allowance

    The allowance to set for the given contract

    wallet

    The wallet signing the operation

    Return Value

    An OperationTransaction which will invoke a smart contract call

  • Return the operation necessary to register an allowance (either calling apporve or update_operators) depending on the token standard version. Removing the need to check manually Used when interacting with smart contract applications like Dexter or QuipuSwap

    Declaration

    Swift

    public static func allowanceOperation(standard: DipDupTokenStandard, tokenAddress: String, tokenId: String?, spenderAddress: String, allowance: TokenAmount, walletAddress: String) -> Operation

    Parameters

    standard

    The FA standard that the token conforms too

    tokenAddress

    The address of the token contract

    spenderAddress

    The address that is being given permission to spend the users balance

    allowance

    The allowance to set for the given contract

    wallet

    The wallet signing the operation

    Return Value

    An OperationTransaction which will invoke a smart contract call

Dex functions

  • Create the operations necessary to remove liquidity from a dex contract, also withdraw pending rewards if applicable. Use DexCalculationService to figure out the numbers required

    Declaration

    Swift

    public static func removeLiquidity(withDex dex: DipDupExchange, minXTZ: XTZAmount, minToken: TokenAmount, liquidityToBurn: TokenAmount, walletAddress: String, timeout: TimeInterval) -> [Operation]

    Parameters

    withDex

    DipDupExchange instance providing information about the exchange

    minXTZ

    The minimum XTZ to accept in return for the burned amount of Liquidity

    minToken

    The minimum Token to accept in return for the burned amount of Liquidity

    liquidityToBurn

    The amount of Liqudity to burn

    wallet

    The wallet that will sign the operation

    timeout

    The timeout in seconds, before the dex contract should cancel the operation

    Return Value

    An array of Operation subclasses.

  • Create the operations necessary to withdraw rewards from a dex contract. For example in quipuswap, XTZ provided as liquidity will earn baking rewards. This can been withdrawn at any time while leaving liquidity in palce

    Declaration

    Swift

    public static func withdrawRewards(withDex dex: DipDupExchange, walletAddress: String) -> [Operation]

    Parameters

    withDex

    DipDupExchange instance providing information about the exchange

    wallet

    The wallet that will sign the operation

    Return Value

    An array of Operation subclasses.

Utilities

Extractors

  • Internal Struct to encapsulate helpers methods needed to extract critical information from an array of operations, needed for processing decisions like “do i display a send token screen, or a send NFt screen”, fetching total XTZ sent in 1 action etc

    See more

    Declaration

    Swift

    public struct Extractor