Skip to content

Commit

Permalink
Add remaining to base Stream type (#109)
Browse files Browse the repository at this point in the history
* add remaining to base stream type, make abstract method non protected
  • Loading branch information
Yolley authored Nov 27, 2023
1 parent d096953 commit c226049
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 85 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.6.4",
"version": "5.6.5",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
33 changes: 9 additions & 24 deletions packages/stream/common/BaseStreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,32 @@ import {
} from "./types";

export abstract class BaseStreamClient {
protected abstract create(
streamData: ICreateStreamData,
chainSpecificParams: any
): Promise<ICreateResult>;
abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;

protected abstract createMultiple(
abstract createMultiple(
multipleStreamData: ICreateMultipleStreamData,
chainSpecificParams: any
): Promise<IMultiTransactionResult>;

protected abstract withdraw(
abstract withdraw(
withdrawData: IWithdrawData,
chainSpecificParams: any
): Promise<ITransactionResult>;

protected abstract cancel(
cancelData: ICancelData,
chainSpecificParams: any
): Promise<ITransactionResult>;
abstract cancel(cancelData: ICancelData, chainSpecificParams: any): Promise<ITransactionResult>;

protected abstract transfer(
abstract transfer(
transferData: ITransferData,
chainSpecificParams: any
): Promise<ITransactionResult>;

protected abstract topup(
topupData: ITopUpData,
chainSpecificParams: any
): Promise<ITransactionResult>;
abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<ITransactionResult>;

protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;

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<ITransactionResult>;
abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
extractErrorCode(err: Error): string | null {
Expand Down
2 changes: 2 additions & 0 deletions packages/stream/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export interface Stream {
type: StreamType;

unlocked(currentTimestamp: number): BN;

remaining(decimals: number): number;
}

/**
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.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/",
Expand Down
58 changes: 0 additions & 58 deletions packages/stream/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
}
}

0 comments on commit c226049

Please sign in to comment.