@streamflow/stream 4.1.0-beta.1 → 4.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ export interface AptosStreamClientOptions {
22
22
  maxGas?: string;
23
23
  }
24
24
  export interface EvmStreamClientOptions {
25
- chain: IChain.Etherium | IChain.BSC;
25
+ chain: IChain.Etherium | IChain.BNB | IChain.Polygon;
26
26
  clusterUrl: string;
27
27
  signer: Signer;
28
28
  cluster?: ICluster;
@@ -35,8 +35,9 @@ var GenericStreamClient = /** @class */ (function (_super) {
35
35
  case types_1.IChain.Aptos:
36
36
  _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
37
37
  break;
38
- case types_1.IChain.BSC:
38
+ case types_1.IChain.BNB:
39
39
  case types_1.IChain.Etherium:
40
+ case types_1.IChain.Polygon:
40
41
  _this.nativeStreamClient = new evm_1.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
41
42
  break;
42
43
  }
@@ -95,6 +95,7 @@ export declare enum IChain {
95
95
  Solana = "Solana",
96
96
  Aptos = "Aptos",
97
97
  Etherium = "Etherium",
98
- BSC = "BSC"
98
+ BNB = "BNB",
99
+ Polygon = "Polygon"
99
100
  }
100
101
  export {};
@@ -26,5 +26,6 @@ var IChain;
26
26
  IChain["Solana"] = "Solana";
27
27
  IChain["Aptos"] = "Aptos";
28
28
  IChain["Etherium"] = "Etherium";
29
- IChain["BSC"] = "BSC";
29
+ IChain["BNB"] = "BNB";
30
+ IChain["Polygon"] = "Polygon";
30
31
  })(IChain = exports.IChain || (exports.IChain = {}));
@@ -105,15 +105,24 @@ var EvmStreamClient = /** @class */ (function (_super) {
105
105
  function EvmStreamClient(clusterUrl, chain, signer, cluster, programId) {
106
106
  if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
107
107
  var _this = _super.call(this) || this;
108
- if (chain !== types_1.IChain.Etherium && chain !== types_1.IChain.BSC) {
109
- throw new Error("Wrong chain. Supported chains are Etherium and BSC");
108
+ if (chain !== types_1.IChain.Etherium && chain !== types_1.IChain.BNB && chain !== types_1.IChain.Polygon) {
109
+ throw new Error("Wrong chain. Supported chains are Etherium , BNB and Polygon!");
110
110
  }
111
111
  if (programId) {
112
112
  _this.programId = programId;
113
113
  }
114
114
  else {
115
- _this.programId =
116
- chain === types_1.IChain.Etherium ? constants_1.ETHERIUM_PROGRAM_IDS[cluster] : constants_1.BSC_PROGRAM_IDS[cluster];
115
+ switch (chain) {
116
+ case types_1.IChain.Etherium:
117
+ _this.programId = constants_1.ETHERIUM_PROGRAM_IDS[cluster];
118
+ break;
119
+ case types_1.IChain.BNB:
120
+ _this.programId = constants_1.BNB_PROGRAM_IDS[cluster];
121
+ break;
122
+ case types_1.IChain.Polygon:
123
+ _this.programId = constants_1.POLYGON_PROGRAM_IDS[cluster];
124
+ break;
125
+ }
117
126
  }
118
127
  _this.provider = new ethers_1.ethers.providers.JsonRpcProvider(clusterUrl);
119
128
  _this.signer = signer;
@@ -260,7 +269,7 @@ var EvmStreamClient = /** @class */ (function (_super) {
260
269
  var result;
261
270
  return __generator(this, function (_a) {
262
271
  switch (_a.label) {
263
- case 0: return [4 /*yield*/, this.writeContract.cancel(transferData.id, transferData.newRecipient)];
272
+ case 0: return [4 /*yield*/, this.writeContract.transfer(transferData.id, transferData.newRecipient)];
264
273
  case 1:
265
274
  result = _a.sent();
266
275
  return [2 /*return*/, {
@@ -273,16 +282,27 @@ var EvmStreamClient = /** @class */ (function (_super) {
273
282
  };
274
283
  EvmStreamClient.prototype.topup = function (topupData) {
275
284
  return __awaiter(this, void 0, void 0, function () {
276
- var fees, result;
285
+ var fees, sum, stream, tokenContract, approvalTx, result;
277
286
  return __generator(this, function (_a) {
278
287
  switch (_a.label) {
279
288
  case 0: return [4 /*yield*/, this.readContract.getTopUpWithdrawalFees(topupData.id, topupData.amount.toString())];
280
289
  case 1:
281
290
  fees = _a.sent();
282
- return [4 /*yield*/, this.writeContract.create(topupData.id, topupData.amount.toString(), {
291
+ sum = topupData.amount.mul(new bn_js_1.BN(constants_2.BASE_FEE)).div(new bn_js_1.BN(1000000));
292
+ return [4 /*yield*/, this.getOne({ id: topupData.id })];
293
+ case 2:
294
+ stream = _a.sent();
295
+ tokenContract = new ethers_1.ethers.Contract(stream.mint, ercAbi_1.default, this.signer);
296
+ return [4 /*yield*/, tokenContract.approve(this.programId, sum.toString())];
297
+ case 3:
298
+ approvalTx = _a.sent();
299
+ return [4 /*yield*/, approvalTx.wait()];
300
+ case 4:
301
+ _a.sent();
302
+ return [4 /*yield*/, this.writeContract.topUp(topupData.id, topupData.amount.toString(), {
283
303
  value: fees.value,
284
304
  })];
285
- case 2:
305
+ case 5:
286
306
  result = _a.sent();
287
307
  return [2 /*return*/, {
288
308
  ixs: [],
@@ -412,7 +432,8 @@ var EvmStreamClient = /** @class */ (function (_super) {
412
432
  ];
413
433
  };
414
434
  EvmStreamClient.prototype.formatMetadataId = function (id) {
415
- return (0, ethereum_checksum_address_1.toChecksumAddress)("0x".concat(id.replace(/^0x0+/, "")));
435
+ // 40 chars is etherium address size
436
+ return (0, ethereum_checksum_address_1.toChecksumAddress)("0x".concat(id.slice(-40)));
416
437
  };
417
438
  return EvmStreamClient;
418
439
  }(BaseStreamClient_1.BaseStreamClient));
@@ -1,3 +1,4 @@
1
1
  import { ICluster } from "../common/types";
2
2
  export declare const ETHERIUM_PROGRAM_IDS: Record<ICluster, string>;
3
- export declare const BSC_PROGRAM_IDS: Record<ICluster, string>;
3
+ export declare const BNB_PROGRAM_IDS: Record<ICluster, string>;
4
+ export declare const POLYGON_PROGRAM_IDS: Record<ICluster, string>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- var _a, _b;
2
+ var _a, _b, _c;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BSC_PROGRAM_IDS = exports.ETHERIUM_PROGRAM_IDS = void 0;
4
+ exports.POLYGON_PROGRAM_IDS = exports.BNB_PROGRAM_IDS = exports.ETHERIUM_PROGRAM_IDS = void 0;
5
5
  var types_1 = require("../common/types");
6
6
  exports.ETHERIUM_PROGRAM_IDS = (_a = {},
7
7
  _a[types_1.ICluster.Mainnet] = "0x35fC2D13D97c13d6697Dc273fEDF93eBC92B7743",
@@ -9,9 +9,15 @@ exports.ETHERIUM_PROGRAM_IDS = (_a = {},
9
9
  _a[types_1.ICluster.Testnet] = "0x35fC2D13D97c13d6697Dc273fEDF93eBC92B7743",
10
10
  _a[types_1.ICluster.Local] = "0x35fC2D13D97c13d6697Dc273fEDF93eBC92B7743",
11
11
  _a);
12
- exports.BSC_PROGRAM_IDS = (_b = {},
12
+ exports.BNB_PROGRAM_IDS = (_b = {},
13
13
  _b[types_1.ICluster.Mainnet] = "0xb09702834cba4c4BDb03CC7F0Fef48490a44BB50",
14
14
  _b[types_1.ICluster.Devnet] = "0xb09702834cba4c4BDb03CC7F0Fef48490a44BB50",
15
15
  _b[types_1.ICluster.Testnet] = "0xb09702834cba4c4BDb03CC7F0Fef48490a44BB50",
16
16
  _b[types_1.ICluster.Local] = "0xb09702834cba4c4BDb03CC7F0Fef48490a44BB50",
17
17
  _b);
18
+ exports.POLYGON_PROGRAM_IDS = (_c = {},
19
+ _c[types_1.ICluster.Mainnet] = "0x96C1A4347ed2C833C58B2B1ad6B616B4d3013C43",
20
+ _c[types_1.ICluster.Devnet] = "0x96C1A4347ed2C833C58B2B1ad6B616B4d3013C43",
21
+ _c[types_1.ICluster.Testnet] = "0x96C1A4347ed2C833C58B2B1ad6B616B4d3013C43",
22
+ _c[types_1.ICluster.Local] = "0x96C1A4347ed2C833C58B2B1ad6B616B4d3013C43",
23
+ _c);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.1.0-beta.1",
3
+ "version": "4.1.0-beta.3",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",