From c226049186636b6819b13ac894d33f5b7795e663 Mon Sep 17 00:00:00 2001 From: Yolley Date: Tue, 28 Nov 2023 01:00:54 +0900 Subject: [PATCH] Add `remaining` to base Stream type (#109) * add remaining to base stream type, make abstract method non protected --- lerna.json | 2 +- packages/stream/common/BaseStreamClient.ts | 33 ++++-------- packages/stream/common/types.ts | 2 + packages/stream/package.json | 2 +- packages/stream/solana/utils.ts | 58 ---------------------- packages/stream/tsconfig.json | 2 +- 6 files changed, 14 insertions(+), 85 deletions(-) diff --git a/lerna.json b/lerna.json index 395a6395..c3743f1f 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,6 @@ "packages": [ "packages/*" ], - "version": "5.6.4", + "version": "5.6.5", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } \ No newline at end of file diff --git a/packages/stream/common/BaseStreamClient.ts b/packages/stream/common/BaseStreamClient.ts index 2cc6b6c9..3e000574 100644 --- a/packages/stream/common/BaseStreamClient.ts +++ b/packages/stream/common/BaseStreamClient.ts @@ -15,47 +15,32 @@ import { } from "./types"; export abstract class BaseStreamClient { - protected abstract create( - streamData: ICreateStreamData, - chainSpecificParams: any - ): Promise; + abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise; - protected abstract createMultiple( + abstract createMultiple( multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any ): Promise; - protected abstract withdraw( + abstract withdraw( withdrawData: IWithdrawData, chainSpecificParams: any ): Promise; - protected abstract cancel( - cancelData: ICancelData, - chainSpecificParams: any - ): Promise; + abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise; - protected abstract transfer( + abstract transfer( transferData: ITransferData, chainSpecificParams: any ): Promise; - protected abstract topup( - topupData: ITopUpData, - chainSpecificParams: any - ): Promise; + abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise; - protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise; + abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise; - protected abstract get( - getAllData: IGetAllData, - chainSpecificParams: any - ): Promise<[string, Stream][]>; + abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>; - protected abstract update( - updateData: IUpdateData, - chainSpecificParams: any - ): Promise; + abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise; // eslint-disable-next-line @typescript-eslint/no-unused-vars extractErrorCode(err: Error): string | null { diff --git a/packages/stream/common/types.ts b/packages/stream/common/types.ts index 17dbee7f..01198c42 100644 --- a/packages/stream/common/types.ts +++ b/packages/stream/common/types.ts @@ -263,6 +263,8 @@ export interface Stream { type: StreamType; unlocked(currentTimestamp: number): BN; + + remaining(decimals: number): number; } /** diff --git a/packages/stream/package.json b/packages/stream/package.json index 2769fc5f..cfd58dde 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/stream", - "version": "5.6.4", + "version": "5.6.5", "description": "JavaScript SDK to interact with Streamflow protocol.", "main": "dist/index.js", "homepage": "https://github.com/streamflow-finance/js-sdk/", diff --git a/packages/stream/solana/utils.ts b/packages/stream/solana/utils.ts index 7230af74..98e65060 100644 --- a/packages/stream/solana/utils.ts +++ b/packages/stream/solana/utils.ts @@ -12,8 +12,6 @@ import bs58 from "bs58"; import { streamLayout } from "./layout"; import { DecodedStream, Account, BatchItem, BatchItemResult } from "./types"; -import { Stream } from "../common/types"; -import { buildStreamType } from "../common/contractUtils"; import { SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX } from "./constants"; const decoder = new TextDecoder("utf-8"); @@ -67,62 +65,6 @@ export const decodeStream = (buf: Buffer): DecodedStream => { fundsUnlockedAtLastRateChange: new BN(raw.funds_unlocked_at_last_rate_change, LE), }; }; -// DeprecationWarning: This object will be deprecated starting from the version 4.0.0. Use -// types/Contract instead -export const formatDecodedStream = (stream: DecodedStream): Stream => { - const resp = { - magic: stream.magic.toNumber(), - version: stream.version.toNumber(), - createdAt: stream.createdAt.toNumber(), - withdrawnAmount: stream.withdrawnAmount, - canceledAt: stream.canceledAt.toNumber(), - end: stream.end.toNumber(), - lastWithdrawnAt: stream.lastWithdrawnAt.toNumber(), - sender: stream.sender.toBase58(), - senderTokens: stream.senderTokens.toBase58(), - recipient: stream.recipient.toBase58(), - recipientTokens: stream.recipientTokens.toBase58(), - mint: stream.mint.toBase58(), - escrowTokens: stream.escrowTokens.toBase58(), - streamflowTreasury: stream.streamflowTreasury.toBase58(), - streamflowTreasuryTokens: stream.streamflowTreasuryTokens.toBase58(), - streamflowFeeTotal: stream.streamflowFeeTotal, - streamflowFeeWithdrawn: stream.streamflowFeeWithdrawn, - streamflowFeePercent: stream.streamflowFeePercent.toNumber(), - partnerFeeTotal: stream.partnerFeeTotal, - partnerFeeWithdrawn: stream.partnerFeeWithdrawn, - partnerFeePercent: stream.partnerFeePercent.toNumber(), - partner: stream.partner.toBase58(), - partnerTokens: stream.partnerTokens?.toBase58(), - start: stream.start.toNumber(), - depositedAmount: stream.depositedAmount, - period: stream.period.toNumber(), - amountPerPeriod: stream.amountPerPeriod, - cliff: stream.cliff.toNumber(), - cliffAmount: stream.cliffAmount, - cancelableBySender: stream.cancelableBySender, - cancelableByRecipient: stream.cancelableByRecipient, - automaticWithdrawal: stream.automaticWithdrawal, - transferableBySender: stream.transferableBySender, - transferableByRecipient: stream.transferableByRecipient, - canTopup: stream.canTopup, - name: stream.name, - withdrawalFrequency: stream.withdrawFrequency.toNumber(), - closed: stream.closed, - currentPauseStart: stream.currentPauseStart.toNumber(), - pauseCumulative: stream.pauseCumulative, - lastRateChangeTime: stream.lastRateChangeTime.toNumber(), - fundsUnlockedAtLastRateChange: stream.fundsUnlockedAtLastRateChange, - type: buildStreamType(stream), - unlocked: function () { - return new BN(0); - }, //phantom method to preserve partial support of this object - withdrawn: function () { - return new BN(0); - }, //phantom method to preserve partial support of this object - }; - return resp; -}; /** * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface diff --git a/packages/stream/tsconfig.json b/packages/stream/tsconfig.json index d6d5ed31..67523c9c 100644 --- a/packages/stream/tsconfig.json +++ b/packages/stream/tsconfig.json @@ -2,5 +2,5 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "./dist" - }, + } } \ No newline at end of file