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.
-
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 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 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.
-
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 QuipuSwapDeclaration
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 QuipuSwapDeclaration
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
orupdate_operators
) depending on the token standard version. Removing the need to check manually Used when interacting with smart contract applications like Dexter or QuipuSwapDeclaration
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
-
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 exchangeminXTZ
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 exchangewallet
The wallet that will sign the operation
Return Value
An array of
Operation
subclasses.
-
Convert an array of operations into the format expected by the RPC. Will also inject a
OperationReveal
if the sender has not yet revealed their public key.Declaration
Swift
public static func operationPayload(fromMetadata metadata: OperationMetadata, andOperations operations: [Operation], walletAddress: String, base58EncodedPublicKey: String) -> OperationPayload
Parameters
fromMetadata
OperationMeatdata
containing necessary data to form the object.andOperations
An array of
Operation
subclasses to send.withWallet
The
Wallet
instance that will be responsible for these operations.Return Value
An instance of
OperationPayload
that can be sent to the RPC -
Dexter requires date strings to act as deadline dates for exchanges. This function takes a
TimeInterval
and uses it to createa date in the future, and returns that as a formatted string.Declaration
Swift
public static func createDexterTimestampString(nowPlusTimeInterval: TimeInterval) -> String
Parameters
nowPlusTimeInterval
The amount of time in the future the date string should represent.
Return Value
A formatted date
String
-
Declaration
Swift
public static func sendTokenMichelson(forFaVersion faVersion: FaVersion, tokenAmount: TokenAmount, tokenId: Decimal, to: String, from: String) -> [String : Any]
-
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 moreDeclaration
Swift
public struct Extractor