โInstruction Factory
The InstructionFactory component of the SDK is outlined in the interface found here. This component allows the user to craft composable solana instructions that can be executed by wrapping them around a transaction.
Instantiating an InstructionFactory
InstructionFactoryMainnet
import { clusterApiUrl, Connection } from "@solana/web3.js";
import { InstructionFactoryImpl } from "@seabed-labs/pre-authorized-debit";
// You can use any connection object you'd like, this is just an example
const connection = new Connection(clusterApiUrl("mainnet-beta"));
const ixFactory = InstructionFactoryImpl.mainnet(connection);Devnet
import { clusterApiUrl, Connection } from "@solana/web3.js";
import { InstructionFactoryImpl } from "@seabed-labs/pre-authorized-debit";
// You can use any connection object you'd like, this is just an example
const connection = new Connection(clusterApiUrl("devnet"));
const ixFactory = InstructionFactoryImpl.devnet(connection);Custom
Point the instruction factory to a custom deployment on any cluster:
Supported Methods
The instruction factory supports the following methods:
โ ๏ธ NOTE
Not all these instructions map 1:1 to the instructions in the program. For example, pause and unpause are modeled as 2 methods here but utilize the same instruction with different parameters in the program.
Approve smart delegate is an instruction that is sent to the SPL token (or token 2022) program and not the pre-authorized-debit program.
These abstractions will hopefully make the SDK slightly easier to use.
All the methods listed above return the following generic type:
You can run the instruction returned by the methods by wrapping them around a transaction. For example, consider the buildInitSmartDelegateIx method (same approach applies to all methods):
Build InitSmartDelegate instruction
InitSmartDelegate instructionBuilds the init_smart_delegate instruction. While this is available to SDK users, this instruction only needs to be run once and it will likely be run by us for any instances of the program we deploy.
This instruction will initialize the singleton smart_delegate account.
Build InitOneTimePreAuthorization instruction
InitOneTimePreAuthorization instructionBuild the init_pre_authorization instruction with one-time configuration.
This instruction will initialize a pre_authorization account that represents a one-time pre-authorization.
Build InitRecurringPreAuthorization instruction
InitRecurringPreAuthorization instructionBuild the init_pre_authorization instruction with recurring configuration.
This instruction will initialize a pre_authorization account that represents a recurring pre-authorization.
Build PausePreAuthorization instruction
PausePreAuthorization instructionBuild the update_pause_pre_authorization instruction with pause = true configuration.
This instruction will pause a pre_authorization account.
Build UnpausePreAuthorization instruction
UnpausePreAuthorization instructionBuild the update_pause_pre_authorization instruction with pause = false configuration.
This instruction will un-pause a pre_authorization account.
Build ClosePreAuthorizationAsOwner instruction
ClosePreAuthorizationAsOwner instructionBuild the close_pre_authorization instruction with authority as pre-authorization's token account's owner.
This instruction will close a pre_authorization account.
Build ClosePreAuthorizationAsDebitAuthority instruction
ClosePreAuthorizationAsDebitAuthority instructionBuild the close_pre_authorization instruction with authority as pre-authorization's debit authority.
This instruction will close a pre_authorization account.
Build Debit instruction
Debit instructionBuild the debit instruction.
This instruction will debit the token account via the pre-authorization if it is valid.
Build ApproveSmartDelegate instruction
ApproveSmartDelegate instructionBuild the approve instruction (on SPL Token Program or on SPL Token2022 Program) for a given token account to set it's delegate to the smart_delegate account and delegated amount to u64::MAX.
When a pre-authorization account is created, the delegate of the token account is already configured as the smart_delegate and the delegated amount is set to u64::MAX. This instruction can be used to "reset" this delegation so that the token account's associated pre-authorizations are still valid if it was unset by another Dapp. Alternatively, if the delegated amount isn't sufficient anymore, this same method can be used to reset it back to u64::MAX.
โ ๏ธ NOTE
This instruction does not call our pre-authorized-debit-v1 program, it calls the SPL Token/Token2022 program directly.
Last updated