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.
ofThe
Tokentype that will be sent.fromThe address to deduct the funds from.
toThe destination address that will recieve the funds.
Return Value
An array of
Operationsubclasses. -
Create the operations necessary to delegate funds to a baker.
Declaration
Swift
public static func delegateOperation(to: String, from: String) -> [Operation]Parameters
toThe address of the baker to delegate to.
fromThe address that wishes to delegate its funds.
Return Value
An array of
Operationsubclasses. -
Create the operations necessary to stake an amount of XTZ
Declaration
Swift
public static func stakeOperation(from: String, amount: TokenAmount) -> [Operation]Parameters
fromThe address that wishes to stake.
amountThe XTZ amount to stake.
Return Value
An array of
Operationsubclasses. -
Create the operations necessary to unstake an amount of XTZ
Declaration
Swift
public static func unstakeOperation(from: String, amount: TokenAmount) -> [Operation]Parameters
fromThe address that wishes to unstake.
amountThe XTZ amount to unstake.
Return Value
An array of
Operationsubclasses. -
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
withDexEnum controling which dex to use to perform the swap
xtzAmountThe amount of XTZ to be swaped
minTokenAmountThe minimum token amount you will accept
walletThe wallet signing the operation
timeoutMax amount of time to wait before asking the node to cancel the operation
Return Value
An array of
Operationsubclasses.
-
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) -> OperationParameters
tokenAddressThe address of the token contract
spenderAddressThe address that is being given permission to spend the users balance
allowanceThe allowance to set for the given contract
walletThe wallet signing the operation
Return Value
An
OperationTransactionwhich 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) -> OperationParameters
tokenAddressThe address of the token contract
spenderAddressThe address that is being given permission to spend the users balance
allowanceThe allowance to set for the given contract
walletThe wallet signing the operation
Return Value
An
OperationTransactionwhich will invoke a smart contract call -
Return the operation necessary to register an allowance (either calling
apporveorupdate_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) -> OperationParameters
standardThe FA standard that the token conforms too
tokenAddressThe address of the token contract
spenderAddressThe address that is being given permission to spend the users balance
allowanceThe allowance to set for the given contract
walletThe wallet signing the operation
Return Value
An
OperationTransactionwhich 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
withDexDipDupExchangeinstance providing information about the exchangeminXTZThe minimum XTZ to accept in return for the burned amount of Liquidity
minTokenThe minimum Token to accept in return for the burned amount of Liquidity
liquidityToBurnThe amount of Liqudity to burn
walletThe wallet that will sign the operation
timeoutThe timeout in seconds, before the dex contract should cancel the operation
Return Value
An array of
Operationsubclasses. -
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
withDexDipDupExchangeinstance providing information about the exchangewalletThe wallet that will sign the operation
Return Value
An array of
Operationsubclasses.
-
Convert an array of operations into the format expected by the RPC. Will also inject a
OperationRevealif 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) -> OperationPayloadParameters
fromMetadataOperationMeatdatacontaining necessary data to form the object.andOperationsAn array of
Operationsubclasses to send.withWalletThe
Walletinstance that will be responsible for these operations.Return Value
An instance of
OperationPayloadthat can be sent to the RPC -
Dexter requires date strings to act as deadline dates for exchanges. This function takes a
TimeIntervaland uses it to createa date in the future, and returns that as a formatted string.Declaration
Swift
public static func createDexterTimestampString(nowPlusTimeInterval: TimeInterval) -> StringParameters
nowPlusTimeIntervalThe 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
Install in Dash