Skip to content

Commit

Permalink
STREAM-1269, STREAM-1270: prepare ixs methods, support computePrice (#…
Browse files Browse the repository at this point in the history
…138)

* STREAM-1269, STREAM-1270: prepare ixs methods, support computePrice
  • Loading branch information
Yolley authored Mar 12, 2024
1 parent 6391e45 commit 67681d9
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 183 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": "5.10.4",
"version": "5.11.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/stream/aptos/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "./types";
import { AptosWalletWrapper } from "./wallet";
import { extractAptosErrorCode } from "./utils";
import { WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants";

export default class AptosStreamClient extends BaseStreamClient {
private programId: string;
Expand Down Expand Up @@ -120,14 +121,14 @@ export default class AptosStreamClient extends BaseStreamClient {
* Attempts withdrawing from the specified stream.
*/
public async withdraw(
withdrawData: IWithdrawData,
{ id, amount = WITHDRAW_AVAILABLE_AMOUNT }: IWithdrawData,
{ senderWallet, tokenId }: ITransactionAptosExt
): Promise<ITransactionResult> {
const payload = {
type: "withdraw",
function: `${this.programId}::protocol::withdraw`,
type_arguments: [tokenId],
arguments: [withdrawData.id, withdrawData.amount.toString()],
arguments: [id, amount.toString()],
};
const wallet = new AptosWalletWrapper(senderWallet, this.client);

Expand Down
5 changes: 3 additions & 2 deletions packages/stream/common/GenericStreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ITopUpStreamSolanaExt,
} from "../solana";
import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
import { WITHDRAW_AVAILABLE_AMOUNT } from "./constants";

export interface SolanaStreamClientOptions {
chain: IChain.Solana;
Expand Down Expand Up @@ -190,11 +191,11 @@ export default class GenericStreamClient<T extends IChain> extends BaseStreamCli
* Attempts withdrawing from the specified stream.
*/
public withdraw(
withdrawData: IWithdrawData,
{ id, amount = WITHDRAW_AVAILABLE_AMOUNT }: IWithdrawData,
chainSpecificParams?: InteractSpecificParams<T>
): Promise<ITransactionResult> {
return handleContractError(
() => this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams as any),
() => this.nativeStreamClient.withdraw({ id, amount }, chainSpecificParams as any),
this.nativeStreamClient.extractErrorCode
);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/stream/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import BN from "bn.js";

export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
24 changes: 10 additions & 14 deletions packages/stream/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,31 @@ export type ICreateMultipleStreamData = IStreamConfig & {
recipients: IRecipient[];
};

export interface IWithdrawData {
export interface IInteractData {
id: string;
amount: BN;
}

export interface IUpdateData {
id: string;
export interface IWithdrawData extends IInteractData {
amount?: BN;
}

export interface IUpdateData extends IInteractData {
enableAutomaticWithdrawal?: boolean;
withdrawFrequency?: BN;
amountPerPeriod?: BN;
}

export interface ICancelData {
id: string;
}
export type ICancelData = IInteractData;

export interface ITransferData {
id: string;
export interface ITransferData extends IInteractData {
newRecipient: string;
}

export interface ITopUpData {
id: string;
export interface ITopUpData extends IInteractData {
amount: BN;
}

export interface IGetOneData {
id: string;
}
export type IGetOneData = IInteractData;

export interface IGetFeesData {
address: string;
Expand Down
12 changes: 6 additions & 6 deletions packages/stream/evm/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { BNB_PROGRAM_IDS, ETHEREUM_PROGRAM_IDS, POLYGON_PROGRAM_IDS } from "./constants";
import abi from "./abi";
import ercAbi from "./ercAbi";
import { BASE_FEE } from "../common/constants";
import { BASE_FEE, WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants";
import { EvmContract, FeesAbiResult, StreamAbiResult } from "./types";
import { extractEvmErrorCode } from "./utils";

Expand Down Expand Up @@ -164,11 +164,11 @@ export default class EvmStreamClient extends BaseStreamClient {
};
}

public async withdraw(withdrawData: IWithdrawData): Promise<ITransactionResult> {
const result = await this.writeContract.withdraw(
withdrawData.id,
withdrawData.amount.toString()
);
public async withdraw({
id,
amount = WITHDRAW_AVAILABLE_AMOUNT,
}: IWithdrawData): Promise<ITransactionResult> {
const result = await this.writeContract.withdraw(id, amount.toString());
return {
ixs: [],
txId: result.hash,
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": "5.10.4",
"version": "5.11.0",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
Loading

0 comments on commit 67681d9

Please sign in to comment.