Skip to content

Commit

Permalink
add docs for update method and expose update on solana properly (#185)
Browse files Browse the repository at this point in the history
* add docs for update method and expose update on solana properly
  • Loading branch information
Yolley committed Aug 2, 2024
1 parent 9e892b3 commit b1f7b91
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 8 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": "6.3.8",
"version": "6.3.9",
"$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": "6.3.8",
"version": "6.3.9",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/distributor",
"version": "6.3.8",
"version": "6.3.9",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
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": "6.3.8",
"version": "6.3.9",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
34 changes: 33 additions & 1 deletion packages/stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const createStreamParams: Types.ICreateStreamData = {
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.
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.
Expand All @@ -161,7 +162,7 @@ const createStreamParams: Types.ICreateStreamData = {

const solanaParams = {
sender: wallet, // SignerWalletAdapter or Keypair of Sender account
isNative: // [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] Wether Stream or Vesting should be paid with Solana native token or not
};

const aptosParams = {
Expand Down Expand Up @@ -371,6 +372,37 @@ try {
}
```

## Update a stream

```javascript
const updateStreamParams: Types.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
amountPerPeriod: getBN(10, 9), // [optional], allows to update release amount effective on next unlock
}

const solanaParams = {
invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
};

const aptosParams = {
senderWallet: wallet, // AptosWalletAdapter Wallet of wallet signing the transaction
};

const suiParams = {
senderWallet: wallet, // WalletContextState | Keypair
};

const ethereumParams = undefined;

try {
const { ixs, tx } = await client.update(updateStreamParams, solanaParams);
} catch (exception) {
// handle exception
}
```

## Get one stream by its ID

```javascript
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/stream",
"version": "6.3.8",
"version": "6.3.9",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
12 changes: 12 additions & 0 deletions packages/stream/solana/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
cliffAmount,
amountPerPeriod,
name,
canPause,
canUpdateRate,
canTopup,
cancelableBySender,
cancelableByRecipient,
Expand Down Expand Up @@ -245,6 +247,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
transferableBySender,
transferableByRecipient,
canTopup,
canUpdateRate: !!canUpdateRate,
canPause: !!canPause,
name,
withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
},
Expand Down Expand Up @@ -324,6 +328,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
amountPerPeriod,
name,
canTopup,
canUpdateRate,
canPause,
cancelableBySender,
cancelableByRecipient,
transferableBySender,
Expand Down Expand Up @@ -389,6 +395,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
transferableBySender,
transferableByRecipient,
canTopup,
canUpdateRate: !!canUpdateRate,
canPause: !!canPause,
name,
withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
recipient: recipientPublicKey,
Expand Down Expand Up @@ -986,6 +994,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
period,
cliff,
canTopup,
canUpdateRate,
canPause,
cancelableBySender,
cancelableByRecipient,
transferableBySender,
Expand Down Expand Up @@ -1035,6 +1045,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
transferableBySender,
transferableByRecipient,
canTopup,
canUpdateRate: !!canUpdateRate,
canPause: !!canPause,
name: recipient.name,
withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
},
Expand Down
12 changes: 10 additions & 2 deletions packages/stream/solana/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface CreateStreamData {
transferableBySender: boolean;
transferableByRecipient: boolean;
canTopup: boolean;
canUpdateRate: boolean;
canPause: boolean;
name: string;
withdrawFrequency: BN;
}
Expand Down Expand Up @@ -100,6 +102,10 @@ export const createStreamInstruction = (
transferable_by_sender: Number(data.transferableBySender),
transferable_by_recipient: Number(data.transferableByRecipient),
can_topup: Number(data.canTopup),
_pausable_discriminator: 1,
can_update_rate: Number(data.canUpdateRate),
_can_update_rate_discriminator: 1,
pausable: Number(data.canPause),
stream_name: streamNameBuffer,
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
};
Expand Down Expand Up @@ -127,6 +133,8 @@ interface CreateUncheckedStreamData {
transferableBySender: boolean;
transferableByRecipient: boolean;
canTopup: boolean;
canUpdateRate: boolean;
canPause: boolean;
name: string;
withdrawFrequency: BN;
recipient: PublicKey;
Expand Down Expand Up @@ -197,8 +205,8 @@ export const createUncheckedStreamInstruction = (
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
recipient: data.recipient.toBuffer(),
partner: data.partner.toBuffer(),
pausable: 1,
can_update_rate: 1,
pausable: Number(data.canPause),
can_update_rate: Number(data.canUpdateRate),
};
const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
bufferData = bufferData.slice(0, encodeLength);
Expand Down
6 changes: 6 additions & 0 deletions packages/stream/solana/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export const createStreamLayout: BufferLayout.Structure<ICreateStreamLayout> = B
BufferLayout.u8("can_topup"),
BufferLayout.blob(64, "stream_name"),
BufferLayout.blob(8, "withdraw_frequency"),
// discriminator for optional field
BufferLayout.u8("_pausable_discriminator"),
BufferLayout.u8("pausable"),
// discriminator for optional field
BufferLayout.u8("_can_update_rate_discriminator"),
BufferLayout.u8("can_update_rate"),
]);

/**
Expand Down

0 comments on commit b1f7b91

Please sign in to comment.