Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomir-streamflow committed Sep 11, 2024
1 parent b1f7b91 commit 41e28e1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 56 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ API Documentation available here: [docs site →](https://streamflow-finance.git
## JS SDK to interact with Streamflow protocols

This repo consists of js-sdk to interact with several protocol exposed by streamflow:
- `packages/stream` - core Streamflow Protocol that allows to create a vesting/payment/lock Stream to a Recipient;
- `packages/distributor` - Distirbutor Streamflow Protocol that allows to Airdrop tokens to large amount of Recipients (thousands or even millions);
- `packages/common` - common utilities and types used by Streamflow SDK;
- `packages/stream` - [Core Streamflow Protocol](packages/stream/README.md) that allows to create a vesting/payment/lock Stream to a Recipient;
- `packages/distributor` - [Distirbutor Streamflow Protocol](packages/distributor/README.md) that allows to Airdrop tokens to large amount of Recipients (thousands or even millions);
- `packages/common` - Common utilities and types used by Streamflow SDK;

## Installation

Expand Down
2 changes: 2 additions & 0 deletions packages/distributor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ or
## Documentation
API Documentation available here: [docs site →](https://streamflow-finance.github.io/js-sdk/)

Automated Airdrop Creation: [notion doc →](https://streamflow.notion.site/Automated-Airdrop-Creation-45b84bfd2dda4d7196be5dd02eed29c8)

## Import SDK

Most common imports:
Expand Down
92 changes: 39 additions & 53 deletions packages/stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Most common imports:

```javascript
import { BN } from "bn.js";
import { Types, GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
import { GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
```

_Check the SDK for other types and utility functions._
Expand All @@ -35,10 +35,7 @@ Before creating and manipulating streams chain specific or generic StreamClient
### Solana

```javascript
import {
StreamflowSolana,
Types,
} from "@streamflow/stream";
import { StreamflowSolana } from "@streamflow/stream";

const solanaClient = new StreamflowSolana.SolanaStreamClient(
"https://api.mainnet-beta.solana.com"
Expand All @@ -48,10 +45,7 @@ const solanaClient = new StreamflowSolana.SolanaStreamClient(
### Aptos

```javascript
import {
StreamflowAptos,
Types,
} from "@streamflow/stream";
import { StreamflowAptos } from "@streamflow/stream";

const aptosClient = new StreamflowAptos.AptosStreamClient(
"https://fullnode.mainnet.aptoslabs.com/v1"
Expand All @@ -61,55 +55,43 @@ const aptosClient = new StreamflowAptos.AptosStreamClient(
### Ethereum

```javascript
import {
StreamflowEVM,
Types,
} from "@streamflow/stream";
import { StreamflowEVM } from "@streamflow/stream";

const ethereumClient = new StreamflowEVM.EvmStreamClient(
"YOUR_ETHEREUM_NODE_URL",
Types.IChain.Ethereum,
IChain.Ethereum,
signer // will be sender in a stream and authority for all stream related transactions
);
```

### Polygon

```javascript
import {
StreamflowEVM,
Types,
} from "@streamflow/stream";
import { StreamflowEVM } from "@streamflow/stream";

const polygonClient = new StreamflowEVM.EvmStreamClient(
"YOUR_POLYGON_NODE_URL",
Types.IChain.Polygon,
IChain.Polygon,
signer // will be sender in a stream and authority for all stream related transactions
);
```

### BNB

```javascript
import {
StreamflowEVM,
Types,
} from "@streamflow/stream";
import { StreamflowEVM } from "@streamflow/stream";

const bnbClient = new StreamflowEVM.EvmStreamClient(
"https://bsc-dataseed1.binance.org/",
Types.IChain.BNB,
IChain.BNB,
signer // will be sender in a stream and authority for all stream related transactions
);
```

### Sui

```javascript
import {
StreamflowSui,
Types,
} from "@streamflow/stream";
import { StreamflowSui } from "@streamflow/stream";

const suiClient = new StreamflowSui.SuiStreamClient(
"https://fullnode.testnet.sui.io:443"
Expand All @@ -121,13 +103,13 @@ const suiClient = new StreamflowSui.SuiStreamClient(
GenericStreamClient provides isomorphic interface to work with streams agnostic of chain.

```javascript
import { GenericStreamClient, Types } from "@streamflow/stream";
import { GenericStreamClient } from "@streamflow/stream";

const client =
new GenericStreamClient<Types.IChain.Solana>({
chain: Types.IChain.Solana, // Blockchain
chain: IChain.Solana, // Blockchain
clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
cluster: ICluster.Mainnet, // (optional) (default: Mainnet)
// ...rest chain specific params e.g. commitment for Solana
});
```
Expand All @@ -149,20 +131,20 @@ const createStreamParams: Types.ICreateStreamData = {
cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
name: "Transfer to Jane Doe.", // The stream name or subject.
canTopup: false, // setting to FALSE will effectively create a vesting contract.
canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
cancelableBySender: true, // Whether or not sender can cancel the stream.
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
transferableBySender: true, // Whether or not sender can transfer the stream.
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
partner: null, // (optional) Partner's wallet address (string | null).
partner: undefined, // (optional) Partner's wallet address (string | undefined).
};

const solanaParams = {
sender: wallet, // SignerWalletAdapter or Keypair of Sender account
isNative: false // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
isNative: false // [optional] [WILL CREATE A wSOL STREAM] Whether Stream or Vesting should be paid with Solana native token or not
};

const aptosParams = {
Expand Down Expand Up @@ -194,7 +176,7 @@ const recipients = [
amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
},
];
const createStreamParams: Types.ICreateMultipleStreamData = {
const createMultiStreamsParams: ICreateMultipleStreamData = {
recipients: recipients, // Solana recipient address.
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
Expand All @@ -207,7 +189,7 @@ const createStreamParams: Types.ICreateMultipleStreamData = {
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
partner: null, // (optional) Partner's wallet address (string | null).
partner: undefined, // (optional) Partner's wallet address (string | undefined).
};

const solanaParams = {
Expand Down Expand Up @@ -236,11 +218,11 @@ Please note that transaction fees for the scheduled transfers are paid upfront b

## Identifying created contracts (streams or vesting)

All Stream Clients return `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
All Stream Clients return `ICreateResult` object (`createMultiple` returns an Array) that has the following structure

```javascript
interface ICreateResult {
ixs: (TransactionInstruction | Types.TransactionPayload)[];
ixs: (TransactionInstruction | TransactionPayload)[];
txId: string;
metadataId: MetadataId;
}
Expand All @@ -252,7 +234,7 @@ interface ICreateResult {

```javascript
const withdrawStreamParams: Types.IWithdrawData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be withdrawn from.
amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
};

Expand Down Expand Up @@ -282,14 +264,14 @@ try {
## Topup stream

```javascript
const topupStreamParams: Types.ITopUpData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
const topupStreamParams: ITopUpData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
};

const solanaParams = {
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
isNative: true // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
};

const aptosParams = {
Expand All @@ -314,9 +296,9 @@ try {
## Transfer stream to another recipient

```javascript
const data: Types.ITransferData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
const data: ITransferData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of the stream to be transferred
newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier (address) of a stream to be transferred.
};

const solanaParams = {
Expand Down Expand Up @@ -345,7 +327,7 @@ try {
## Cancel stream

```javascript
const cancelStreamParams: Types.ICancelData = {
const cancelStreamParams: ICancelData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
};

Expand Down Expand Up @@ -375,7 +357,7 @@ try {
## Update a stream

```javascript
const updateStreamParams: Types.IUpdateData = {
const updateStreamParams: IUpdateData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
withdrawFrequency: 60, // [optional], allows to update withdrawal frequency, may result in additional AW fees
Expand Down Expand Up @@ -406,7 +388,7 @@ try {
## Get one stream by its ID

```javascript
const data: Types.IGetOneData = {
const data: IGetOneData = {
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream
};

Expand All @@ -424,8 +406,8 @@ const stream = await client.getOne({
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
});

const unlocked = stream.unlocked(tsInSeconds); // bn amount unlocked at the tsInSeconds
console.log(getNumberFromBN(unlocked, 9));
const unlocked = stream.unlocked(tsInSeconds); // BN amount unlocked at the tsInSeconds
console.log(getNumberFromBN(unlocked, 9));
```

- Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
Expand All @@ -445,10 +427,10 @@ console.log(remaining);
## Get multiple streams for a specific wallet address

```javascript
const data: Types.IGetAllData = {
const data: IGetAllData = {
address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
type: Types.StreamType.All,
direction: Types.StreamDirection.All,
type: StreamType.All, // StreamType.Vesting, StreamType.Lock, StreamType.Payment
direction: StreamDirection.All, // StreamDirection.Outgoing, StreamDirection.Incoming
};

try {
Expand Down Expand Up @@ -499,3 +481,7 @@ E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_00
And `new BN(1_000_000_000)` is used.

Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.

`getBN(1, 9)` is equal to `new BN(1_000_000_000)`

`getNumberFromBN(new BN(1_000_000_000), 9)` will return 1

0 comments on commit 41e28e1

Please sign in to comment.