Skip to content

Commit

Permalink
Launchpad integration, update aligned vesting idls (#234)
Browse files Browse the repository at this point in the history
* launchpad integration, update aligned vesting idls
  • Loading branch information
Yolley authored Nov 21, 2024
1 parent 2e468ce commit 2e32c2f
Show file tree
Hide file tree
Showing 24 changed files with 3,517 additions and 151 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "7.0.3",
"version": "7.1.0-alpha.1",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/common",
"version": "7.0.3",
"version": "7.1.0-alpha.1",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "./dist/esm/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/distributor",
"version": "7.0.3",
"version": "7.1.0-alpha.1",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"typescript": "^5.6.3"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.0",
"@coral-xyz/anchor": "^0.30.1",
"@coral-xyz/borsh": "0.30.1",
"@solana/buffer-layout": "4.0.1",
"@solana/spl-token": "0.4.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/eslint-config",
"version": "7.0.3",
"version": "7.1.0-alpha.1",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions packages/launchpad/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@streamflow/eslint-config"
]
}
4 changes: 4 additions & 0 deletions packages/launchpad/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!dist/**/*
!package.json
!README.md
2 changes: 2 additions & 0 deletions packages/launchpad/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
coverage
175 changes: 175 additions & 0 deletions packages/launchpad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Streamflow Launchpad

## JS SDk to interact with the Launchpad Protocol

This package exposes several instruction needed by both Launchpad creator and depositors:
- `create new Launchpad`;
- `fund launchpad`;
- `deposit into launchpad`;
- `claim deposited tokens`;
- `claim allocated tokens`;

Each Launchpad consist of multiple configuration options:
- **Base Mint** - mint that users will be buying - Launchpad should be funded with enough tokens prior to users claiming their allocations;
- **Quote Mint** - mint that users will deposit and in which price of the **Base Mint** will be denominated - Launchpad authority will be able to claim deposited tokens after depositting period ends;
- **Price** - price of the 1 **Base Mint** in **Quote Mint** tokens;
- **Periods** - there are Depositing period and Vesting period needed to be configured;
- **Vesting Configuration** - dynamic vesting will be used, so Launchpad creator should provide various configuration options for it;

## API Reference

API Documentation available here: [docs site →](https://streamflow-finance.github.io/js-sdk/)

## Installation

Install the sdk with npm

```npm
npm install @streamflow/launchpad
```
```yarn
yarn install @streamflow/launchpad
```
```pnpm
pnpm add @streamflow/launchpad
```

## Usage/Examples

### Initiate the client
```typescript
const client = new SolanaLaunchpadClient({
clusterUrl: "https://api.mainnet-beta.solana.com",
cluster: ICluster.Mainnet
});
```

> [!WARNING]
> All operations expect ATAs to be created at the moment of execution and don't add these instructions.
> - Claim Deposits - Receiver token account that will be used to claim deposited tokens;
> - Claim Allocation - Token account for the `Base Mint` should be created prior to Depositor claiming their allocation;

### Read operations

```typescript

await client.searchLaunchpad({ baseMint, quoteMint }) // both mint parameters are optional.

await client.getLaunchpad(id) // fetch specific Launchpad by its ID.

await client.getDepositAccount(id) // fetch specific Deposit Account by its ID.
```

### Create new Launchpad
import { getBN } from "@streamflow/common";

```typescript
const { txId: createSig, metadataId } = await client.createLaunchpad({
baseMint, // Mint that users will be buying
quoteMint, // Mint that users will deposit
receiver, // [optional] Token account that should receive deposits once deposit period is ended
priceOracle, // [optional] Price Oracle address that will be used in dynamic vesting
nonce: 1, // Nonce value, Launchpad PDA will be derived from nonce + baseMint
price: getBN(0.15, QUOTE_MINT_DECIMALS), // Price per 1 `baseMint` whole token denominated in `quoteMint` tokens
individualDepositingCap: getBN(1_000, QUOTE_MINT_DECIMALS), // Max Cap per User of `quoteMint` tokens to deposit
maxDepositingCap: getBN(1_000_000, QUOTE_MINT_DECIMALS), // Max global Cap of `quoteMint` tokens to deposit
depositingStartTs, // Timestamp when depositing should start
depositingEndTs, // Timestamp when depositing should end
vestingStartTs, // Timestamp when vesting should start
vestingEndTs, // Timestamp when vesting should end initially
vestingPeriod, // Period in seconds of vesting and dynamic vesting unlock updates, should be at least 30
oracleType: "test", // [optional] Type the Price Oracle, should be aligned with the provided `priceOracle`
minPrice: 0.05, // Min Price for dynamic vesting
maxPrice: 1, // Max Price for dynamic vesting
minPercentage: 1, // Min Percentage for dynamic vesting - will be used if current price <= `minPrice`
maxPercentage: 1000, // Max Percentage for dynamic vesting - will be used if current price >= `maxPrice`
tickSize: 1, // Tick size for percentages in dynamic vesting - will be used in case minPrice < current price < maxPrice
skipInitial: false, // Whether to skip initial unlock amount update when dynamic vesting is initiated
isMemoRequired: false, // Whether to require special Memo instruction on deposit
tokenProgramId: TOKEN_PROGRAM_ID // [optional] SPL Token Program to use
},
{ invoker: authority }
);
```

### Deposit tokens

```typescript
const { txId: depositSig } = await client.deposit(
{
launchpad: metadataId, // Id of the Launchpad to deposit tokens into
quoteMint, // [optional] Mint Id, if not provided it will be fetched from the Laucnhpad
amount: getBN(100.15, QUOTE_MINT_DECIMALS), // Amount of `quoteMint` tokens to deposit,
autoCap: true, // [opional] Whether to automatically cap deposited tokens in case user deposited more than `maxDepositingCap`
memo: "I don't reside in a sanctioned country.", // [optional] Text for memo instruction
owner: user1.publicKey, // [optional] Deposit owner in case it differs from the invoker
tokenProgramId: TOKEN_PROGRAM_ID // [optional] SPL Token Program to use
},
{ invoker: user1 }
);
```

User can deposit tokens however many times they want if both individual and max Depositing caps are respected.

> [!Warning]
> It's not possible to withdraw deposited tokens currently.
### Fund Launchpad

```typescript
const { txId: fundLaunchpadSig } = await client.fundLaunchpad(
{
launchpad: metadataId, // Id of the Launchpad to fund
baseMint, // [optional] Mint Id, if not provided it will be fetched from the Laucnhpad
amount: getBN(6_666_666, BASE_MINT_DECIMALS), // Amount of base tokens to funds Laucnhpad by
tokenProgramId: TOKEN_PROGRAM_ID // [optional] SPL Token Program to use
},
{ invoker: authority }
);
```

> [!Note]
> Client just uses spl transfer instruction, so technically anyone can fund a Launchpad.
### Claim deposited tokens

```typescript
const { txId: claimDepositsSig } = await client.claimDeposits(
{
launchpad: metadataId, // Id of the Launchpad to claim deposited tokens from
quoteMint, // [optional] Mint Id, if not provided it will be fetched from the Laucnhpad
tokenProgramId: TOKEN_PROGRAM_ID // [optional] SPL Token Program to use
},
{ invoker: authority }
);
```

> [!Warning]
> Claiming of Deposited tokens is possible only after Deposit period has ended.
### Claim token allocation

```typescript
const { txId: claimAllocatedSig } = await client.claimAllocatedVested(
{
launchpad: metadataId, // Id of the Launchpad to claimed allocation from
baseMint, // [optional] Mint Id, if not provided it will be fetched from the Laucnhpad
owner: user1.publicKey, // [optional] Deposit owner in case it differs from the invoker
tokenProgramId: TOKEN_PROGRAM_ID // [optional] SPL Token Program to use
},
{ invoker: user1 }
);
```

> [!Note]
> Anyone can call this action on behalf of the Deposit after Deposit period has ended.
>
> This action will essentially create a Streamflow Dynamic vesting contract where:
> - total depostted amount will be equal to the Depositor token allocation;
> - initial vesting start and end time will be set according to the vesting configuration
> - in case `skipInitial` was not disabled, vesting schedule may differ depending on current price of the token;

> [!Warning]
> This action should be done prior to Vesting Start Time - as dynamic vesting will be used and dynamic vesting can not have any cliff amount.
4 changes: 4 additions & 0 deletions packages/launchpad/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { SolanaLaunchpadClient } from "./solana/client.js";
export * from "./solana/types.js";
export * from "./solana/lib/derive-accounts.js";
export * as constants from "./solana/constants.js";
49 changes: 49 additions & 0 deletions packages/launchpad/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@streamflow/launchpad",
"version": "7.1.0-alpha.1",
"description": "JavaScript SDK to interact with Streamflow Launchpad protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/esm/index.d.ts"
},
"./solana": {
"import": "./dist/esm/solana/index.js",
"require": "./dist/cjs/solana/index.js",
"types": "./dist/esm/solana/index.d.ts"
}
},
"scripts": {
"build:cjs": "rm -rf dist/cjs; tsc -p tsconfig.cjs.json",
"build:esm": "rm -rf dist/esm; tsc -p tsconfig.esm.json",
"build": "rm -rf dist; pnpm run build:cjs && pnpm run build:esm",
"pack": "pnpm build && pnpm pack",
"lint": "eslint --fix .",
"prepublishOnly": "npm run lint && npm run build"
},
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
"devDependencies": {
"@streamflow/eslint-config": "workspace:*",
"@types/bn.js": "5.1.1",
"typescript": "^5.6.3"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@coral-xyz/borsh": "^0.30.1",
"@solana/buffer-layout": "4.0.1",
"@solana/spl-token": "0.4.9",
"@solana/wallet-adapter-base": "0.9.19",
"@solana/web3.js": "1.95.4",
"@streamflow/common": "workspace:*",
"@streamflow/stream": "workspace:*",
"bn.js": "5.2.1",
"borsh": "^2.0.0",
"bs58": "5.0.0",
"p-queue": "^8.0.1"
}
}
Loading

0 comments on commit 2e32c2f

Please sign in to comment.