npm package: @malloc-protocol/spl
Description: Malloc SPL contains standard actions, such as swapping, LP depositing, farming, and lending, which integrate with Malloc.
Latest version: 1.0.17

# Malloc SPL

Malloc SPL contains standard actions, such as swapping, LP depositing, farming, and lending,
which integrate with Malloc.

## Installation
```
yarn add @malloc-protocol/spl
```

## General Usage
Usage, all that needs to be done to use the SPL is to pass in 
`MallocSPLBuildActionMap` to the malloc sdk when building and compiling.
So, for example:
```typescript
import { MallocSPLBuildActionMap } from '@malloc-protocol/spl'

// Do some stuff here like define the construction and creating malloc

await malloc.build(<myConstruction>, MallocSPLBuildActionMap, <opts>)
```

Then, when building your construction actions, you would want to use
`splConstants` to get the UIDs and PIDs. The current `splConstants` map looks
like 
```typescript
const splConstants = {
  BUILD_ACTION_UIDS: {
    TRANSFER: TransferAction.actionTypeUID,
    RAYDIUM_SWAP: RaydiumSwapAction.actionTypeUID,
    RAYDIUM_LP_DEPOSIT: RaydiumLPDepositAction.actionTypeUID,
    RAYDIUM_LP_STAKE: RaydiumLPStakeAction.actionTypeUID,
    SOLEND_LP_DEPOSIT: SolendLpDepositAction.actionTypeUID,
  },
  HELPER_UIDS: {
    RAYDIUM_SWAP: RaydiumSwapAction,
  },
  PIDS: {
    DEVNET: { CPI_ACTION: CPI_ACTION_PID },
    MAINNET: {
      CPI_ACTION: CPI_ACTION_PID,
      RAYDIUM_SWAP: CPI_ACTION_PID,
      RAYDIUM_LP_DEPOSIT: CPI_ACTION_PID,
      RAYDIUM_LP_STAKE: CPI_ACTION_PID,
      SOLEND_LP_DEPOSIT: CPI_ACTION_PID,
    },
  },
};
```

So, say you wanted to build a swap action, you would do,
```typescript
action: {
	actionPID: splConstants.PIDS.MAINNET.CPI_ACTION,
	actionTypeUID: splConstants.BUILD_ACTION_UIDS.RAYDIUM_LP_DEPOSIT,
	inputs: {
		// some input here
	},
	nextActions: yourNextActions,
},
```

# Action Details
| Action Type | Number of expected in mints | number of out mints |
| --- | --- | ----------- |
| RAYDIUM_SWAP | 1 (a token to swap from) | 1 (a token to swap to) |
| RAYDIUM_LP_DEPOSIT | 2 (the tokens in the LP) | 1 (the LP's share token) |
| RAYDIUM_LP_STAKE (farming) | 1 (a LP's share tokens) | 0 |
| SOLEND_LP_DEPOSIT | 1 (the input token into the liquidity pool) | 1 (the LP's share tokens) |
| TRANSFER | 1 (the token to be transferred) | 0 |

## Raydium Swapping
A raydium swap expects one type of token to be inputted (i.e. the actions pointing to a swap must all share the same mint). It outputs 1 token.

The expected input is one of the following
```typescript
{
	outMint: PublicKey | string
}
```
In this case, the action will attempt to find a liquidity pool which across the input mint to the output mint.

The other options is to specify a liquidity pool.

```typescript
{
	liquidityPool: LiquidityPoolKeys
}
```
`LiquidityPoolKeys` is defined in the typescript package `@raydium-io/raydium-sdk` which can be used to select specific liquidity pools to swap across.

## Raydium LP Depositing
A raydium LP deposit expects two different distinct prior token types: 1 for each side of
the LP pool. The action outputs 1 token -- the Liquidity Pool Token.

The input can be `{hasFarm?: boolean}`. In this case, the action will attempt to
find a liquidity pool. If `hasFarm` is true, then it will only look for LPs with an
associated farm.

Otherwise, the liquidity pool can be specified by passing in 
```typescript
{
	liquidityPool: LiquidityPoolKeys
}
```
See the section on Raydium Swaps for more information on `LiquidityPoolKeys`

## Raydium LP Staking/ farming
A raydium LP farm action expects 1 prior token, the liquidity pool token. It does not
output any tokens. The action will default to reward accounts being the derived token
account. If these token accounts do not yet exist, Malloc will create them.

The input can either be empty, in which the action attempts to find a farm for the 
input token LP account. Otherwise 
```typescript
{ farmPoolKeys: FarmPoolKeys }
``` 
can be specified.
Again, `FarmPoolKeys` is defined in the typescript package `@raydium-io/raydium-sdk` which can be used to select a specific farm.

### Specifying Reward Accounts
```typescript 
{ rewardTokenAccounts: (PublicKey | string)[] }
``` 
can also be specified to overwrite the
default token accounts for rewards.


## Solend Liquidity Depositing
Solend liquidity depositing expects 1 prior token. It outputs 1 token corresponding
to the LP share token.
The action expects no input and automatically attempts to find the market associated
to the input token.

## Transferring Fungible Tokens
Transferring expects 1 input token type. The input is expected to be
```typescript
{ recipientWallet: string | PublicKey }
```
The transfer action then transfers tokens to the account associated with the 
recipient and the input token mint. If an associated account does not yet exist,
Malloc will create one for the recipient.


## Interested in creating an action or want to request an action?
Reach out to us on our [Discord](https://discord.gg/ewMFvqKz)