import { BN } from "@project-serum/anchor"; import { PublicKey } from "@solana/web3.js"; import { BNIsh } from "."; import { MintWithAmount } from "./"; export type NonSpecificAtionOverride = { minOuts?: BNIsh[]; }; /** * @param minimumOutFraction - a number to multiply the estimate amounts out by to set to the minimum. This * will usually be 0 to 1 * * @param groupActionsTogether - specify action indices where the transaction to process the action * will be grouped together with the rest of the indices in the list into 1 transaction with multiple instructions. i.e. * [[0, 1], [2, 3]] will have 2 separate process tx transactions where 1 will be processing 0 and 1 in a single transaction * and the other 2 and 3 in an other tx */ export type NonSpecificConstructionOpts = { minimumOutToEstimateRatio?: number[]; }; type NextMap = { [actionId: string]: number }; /** * @param nextActions - takes the next action as the key and the * fraction as the value */ export type NonSpecificAction = { actionTypeUID: string; actionPID: string; inputs: any; nextActions: NextMap[]; opts?: NonSpecificConstructionOpts; overrides?: NonSpecificAtionOverride; }; /** * A non specific action filled in with partial info after a build * * @param nextActions - takes the next action as the key and the * fraction as the value */ export interface _NonSpecificActionFilled< PK extends PublicKey | string, BN_T extends BNIsh > extends NonSpecificAction { inMints?: PK[]; inAmounts?: string[]; inEstimates?: MintWithAmount[]; outEstimates?: MintWithAmount[]; outMints?: PK[]; } export const castToStandaloneAction = ( action: NonSpecificConstruction["actionDatas"][string] ): NonSpecificAction => (action as any).action as NonSpecificAction; export const castToActionGroup = ( action: NonSpecificConstruction["actionDatas"][string] ): NonSpecificActionGroup => (action as any).actionGroup as NonSpecificActionGroup; export const isNonSpecificActionGroup = ( action: NonSpecificConstruction["actionDatas"][string] ): boolean => !!(action as any).actionGroup; /** * A group of actions. The actions in the map should only "hit each other" * and then whenever the group is called, the first action is called finishing with the last * * Action groups are meant to be grouped into 1 transaction and thought of as 1 action */ export type NonSpecificActionGroup = { first: string; actions: { [internalActionId: string]: NonSpecificAction; }; }; export type NonSpecificActionFilled = _NonSpecificActionFilled; type NonSpecificActionTypes = | NonSpecificAction | _NonSpecificActionFilled | NonSpecificAction; type NonSpecificActionInternal = { action: NonSpecificAction; }; type NonSpecificActionGroupInternal = { actionGroup: NonSpecificActionGroup; }; type NonSpecificConstructionActionWrapper = | NonSpecificActionInternal | NonSpecificActionGroupInternal; type _NonSpecificConstruction = { actionDatas: NonSpecificConstructionActionDatas; source: { nextActions: NextMap; mints: { [mint: string]: string; }; }; }; /** * The interface necessary to reconstruct a construction given a set of inputs to actions and the "shape" * of the construction * * All types in buildActionInputs should be easily JSON serializable except the provider * * NOTE: all action ids, including ones in action groups, must be unique */ export type NonSpecificConstruction = _NonSpecificConstruction; export type NonSpecificConstructionFilledUnserializable = _NonSpecificConstruction<_NonSpecificActionFilled>; export type NonSpecificConstructionFilled = _NonSpecificConstruction< _NonSpecificActionFilled >; export type NonSpecificConstructionNoInitMints = Omit< NonSpecificConstruction, "source" > & { source: Omit }; export type NonSpecificConstructionActionDatas< T extends NonSpecificActionTypes > = { [actionId: string]: NonSpecificConstructionActionWrapper; };