-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fees retrieval #114
Add fees retrieval #114
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ import { | |
ICreateResult, | ||
IGetAllData, | ||
Stream, | ||
IFees, | ||
IGetFeesData, | ||
} from "./types"; | ||
import { handleContractError } from "./utils"; | ||
import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos"; | ||
|
@@ -262,4 +264,18 @@ export default class GenericStreamClient<T extends IChain> extends BaseStreamCli | |
this.nativeStreamClient.extractErrorCode | ||
); | ||
} | ||
|
||
/** | ||
* Returns streamflow and partner fees for the specific wallet in % | ||
*/ | ||
public getFees(getFeesData: IGetFeesData): Promise<IFees | null> { | ||
return this.nativeStreamClient.getFees(getFeesData); | ||
} | ||
|
||
/** | ||
* Returns default Streamflow Fee in % | ||
*/ | ||
public getDefaultStreamflowFee(): Promise<number> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move all of this out from StreamClient into some Fees file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's all part of the protocol, like for EVM we interact directly with our program for example. It would be probably better rename streamClient to Protocol Client though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it sounds like a part of bigger rework and I am not sure when we'll get to it (and who will own in). |
||
return this.nativeStreamClient.getDefaultStreamflowFee(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ import { | |
ICreateMultipleStreamData, | ||
ICreateResult, | ||
ICreateStreamData, | ||
IGetFeesData, | ||
IGetAllData, | ||
IGetOneData, | ||
IFees, | ||
IMultiTransactionResult, | ||
IRecipient, | ||
ITopUpData, | ||
|
@@ -26,7 +28,7 @@ import { BNB_PROGRAM_IDS, ETHEREUM_PROGRAM_IDS, POLYGON_PROGRAM_IDS } from "./co | |
import abi from "./abi"; | ||
import ercAbi from "./ercAbi"; | ||
import { BASE_FEE } from "../common/constants"; | ||
import { EvmContract, StreamAbiResult } from "./types"; | ||
import { EvmContract, FeesAbiResult, StreamAbiResult } from "./types"; | ||
import { extractEvmErrorCode } from "./utils"; | ||
|
||
export default class EvmStreamClient extends BaseStreamClient { | ||
|
@@ -251,6 +253,22 @@ export default class EvmStreamClient extends BaseStreamClient { | |
return extractEvmErrorCode(err.toString() ?? "Unknown error!"); | ||
} | ||
|
||
public async getFees({ address }: IGetFeesData): Promise<IFees | null> { | ||
const fees: FeesAbiResult = await this.readContract.getFees(address); | ||
if (!fees.exists) { | ||
return null; | ||
} | ||
return { | ||
streamflow_fee: fees.streamflow_fee.toNumber() / 100, | ||
partner_fee: fees.partner_fee.toNumber() / 100, | ||
}; | ||
} | ||
|
||
public async getDefaultStreamflowFee(): Promise<number> { | ||
const fee = await this.readContract.getStreamflowFees(); | ||
return fee.toNumber() / 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better to divide before moving to number :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would need to add a dependency then, because EVM returns BigNumber |
||
} | ||
|
||
/** | ||
* Returns StreamClient protocol program ID. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, since it's public SDK, we should capitalize S in Streamflow