Skip to content
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

STREAM-1587: support base #174

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.7",
"version": "6.4.0",
"$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.7",
"version": "6.4.0",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum IChain {
BNB = "BNB",
Polygon = "Polygon",
Sui = "Sui",
Base = "Base",
}

/**
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.7",
"version": "6.4.0",
"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.7",
"version": "6.4.0",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
3 changes: 2 additions & 1 deletion packages/stream/common/GenericStreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface AptosStreamClientOptions {
}

export interface EvmStreamClientOptions {
chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
chain: IChain.Ethereum | IChain.BNB | IChain.Polygon | IChain.Base;
clusterUrl: string;
signer: Signer;
cluster?: ICluster;
Expand Down Expand Up @@ -141,6 +141,7 @@ export default class GenericStreamClient<T extends IChain> extends BaseStreamCli
options.programId,
) as StreamClientType<T>;
break;
case IChain.Base:
case IChain.BNB:
case IChain.Ethereum:
case IChain.Polygon:
Expand Down
63 changes: 27 additions & 36 deletions packages/stream/evm/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
ICancelData,
IChain,
ICluster,
ICreateMultiError,
ICreateMultipleStreamData,
ICreateResult,
ICreateStreamData,
IGetFeesData,
IFees,
IGetAllData,
IGetFeesData,
IGetOneData,
IFees,
IMultiTransactionResult,
IRecipient,
ITopUpData,
Expand All @@ -24,7 +25,7 @@ import {
Stream,
StreamDirection,
} from "../common/types";
import { BNB_PROGRAM_IDS, ETHEREUM_PROGRAM_IDS, POLYGON_PROGRAM_IDS } from "./constants";
import { BASE_PROGRAM_IDS, BNB_PROGRAM_IDS, ETHEREUM_PROGRAM_IDS, POLYGON_PROGRAM_IDS } from "./constants";
import abi from "./abi";
import ercAbi from "./ercAbi";
import { BASE_FEE, WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants";
Expand All @@ -51,10 +52,6 @@ export default class EvmStreamClient extends BaseStreamClient {
) {
super();

if (chain !== IChain.Ethereum && chain !== IChain.BNB && chain !== IChain.Polygon) {
throw new Error("Wrong chain. Supported chains are Ethereum , BNB and Polygon!");
}

if (programId) {
this.programId = programId;
} else {
Expand All @@ -68,6 +65,11 @@ export default class EvmStreamClient extends BaseStreamClient {
case IChain.Polygon:
this.programId = POLYGON_PROGRAM_IDS[cluster];
break;
case IChain.Base:
this.programId = BASE_PROGRAM_IDS[cluster];
break;
default:
throw new Error("Wrong chain. Supported chains are Ethereum , BNB, Base and Polygon!");
}
}

Expand Down Expand Up @@ -123,42 +125,31 @@ export default class EvmStreamClient extends BaseStreamClient {

const creationPromises = args.map((item) => this.writeContract.create(...item, { value: fees.value }));

const signatures: string[] = [];
const results = await Promise.all(creationPromises);
const errors: ICreateMultiError[] = [];
const signatures: string[] = [];
const metadatas: string[] = [];
const metadataToRecipient: { [key: string]: IRecipient } = {};

const confirmations = await Promise.allSettled(results.map((result) => result.wait()));
const successes = confirmations
.filter((el): el is PromiseFulfilledResult<any> => el.status === "fulfilled")
.map((el) => el.value);
signatures.push(...successes.map((el) => el.hash));

const metadatas = confirmations.map((result: PromiseSettledResult<any>) =>
result.status === "fulfilled"
? this.formatMetadataId(
result.value.events!.find((item: ethers.Event) => item.event === "ContractCreated")!.args![0],
)
: null,
);
const metadataToRecipient = metadatas.reduce(
(acc, value, index) => {
if (value) {
acc[value] = multipleStreamData.recipients[index];
}

return acc;
},
{} as Record<string, IRecipient>,
);

const failures = confirmations
.filter((el): el is PromiseRejectedResult => el.status === "rejected")
.map((el) => el.reason);
confirmations.forEach((res: PromiseSettledResult<any>, index: number) => {
if (res.status === "rejected") {
errors.push(res.reason);
return;
}
signatures.push(res.value.transactionHash);
RolginRoman marked this conversation as resolved.
Show resolved Hide resolved
const metadataId = this.formatMetadataId(
res.value.events!.find((item: ethers.Event) => item.event === "ContractCreated")!.args![0],
);
metadatas.push(metadataId);
metadataToRecipient[metadataId] = multipleStreamData.recipients[index];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a falsy value wasn't added previously. How may it affect consumers of this function in this version?

});

return {
txs: signatures,
metadatas: metadatas.filter(Boolean) as string[],
metadatas,
metadataToRecipient,
errors: failures,
errors,
};
}

Expand Down
7 changes: 7 additions & 0 deletions packages/stream/evm/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const POLYGON_PROGRAM_IDS: Record<ICluster, string> = {
[ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
};

export const BASE_PROGRAM_IDS: Record<ICluster, string> = {
[ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
[ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
[ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
[ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
};

export const EVM_ERROR_MATCH_REGEX = /execution reverted: ([A-Z_]+)/;

export const EVM_ERROR_MAP = {
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.7",
"version": "6.4.0",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
Loading