# @malloc-protocol/spl

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

Latest version **1.0.17** (published 2021-12-22) · 0 weekly downloads

## Install

```sh
npm install @malloc-protocol/spl
pnpm add @malloc-protocol/spl
yarn add @malloc-protocol/spl
bun add @malloc-protocol/spl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.17 |
| Published | 2021-12-22 |
| First published | 2021-12-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 62.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | allyouneedislev |

## Links

- npm: https://www.npmjs.com/package/@malloc-protocol/spl
- npm.io page: https://npm.io/package/@malloc-protocol/spl

## Dependencies (19)

- [add](https://npm.io/package/add.md) ^2.0.6
- [borsh](https://npm.io/package/borsh.md) ^0.6.0
- [big-number](https://npm.io/package/big-number.md) ^2.0.0
- [decimal.js](https://npm.io/package/decimal.js.md) ^10.3.1
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.1.4
- [@orca-so/sdk](https://npm.io/package/@orca-so/sdk.md) ^1.1.6
- [@solana/web3.js](https://npm.io/package/@solana/web3.js.md) ^1.29.2
- [@solana/spl-token](https://npm.io/package/@solana/spl-token.md) ^0.1.8
- [@project-serum/swap](https://npm.io/package/@project-serum/swap.md) ^0.1.0-alpha.32
- [@malloc-protocol/sdk](https://npm.io/package/@malloc-protocol/sdk.md) ^1.0.30
- [@project-serum/borsh](https://npm.io/package/@project-serum/borsh.md) ^0.2.2
- [@project-serum/serum](https://npm.io/package/@project-serum/serum.md) ^0.13.59
- [@project-serum/anchor](https://npm.io/package/@project-serum/anchor.md) npm:@malloc-protocol/anchor
- [@solendprotocol/common](https://npm.io/package/@solendprotocol/common.md) ^1.1.32
- [@dbricks/dbricks-solend](https://npm.io/package/@dbricks/dbricks-solend.md) ^0.0.6
- [@malloc-protocol/anchor](https://npm.io/package/@malloc-protocol/anchor.md) ^0.13.2
- [@raydium-io/raydium-sdk](https://npm.io/package/@raydium-io/raydium-sdk.md) ^1.0.1-beta.11
- [@solana/spl-token-lending](https://npm.io/package/@solana/spl-token-lending.md) ^0.3.6
- [@solana/spl-token-registry](https://npm.io/package/@solana/spl-token-registry.md) ^0.2.247

## Recent versions

- 1.0.17 (latest) — 2021-12-22
- 1.0.16 — 2021-12-19
- 1.0.15 — 2021-12-19
- 1.0.14 — 2021-12-17
- 1.0.13 — 2021-12-15
- 1.0.12 — 2021-12-15
- 1.0.11 — 2021-12-14
- 1.0.10 — 2021-12-13
- 1.0.8 — 2021-12-12
- 1.0.7 — 2021-12-08
- 1.0.6 — 2021-12-08
- 1.0.5 — 2021-12-08
- 1.0.4 — 2021-12-08
- 1.0.3 — 2021-12-08
- 1.0.2 — 2021-12-08
- … 2 more at https://npm.io/package/@malloc-protocol/spl/versions

## README

# 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)

---
_Source: https://npm.io/package/@malloc-protocol/spl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
