@streamflow/stream 4.0.0-Alpha.2 → 4.0.0-Alpha.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.
@@ -62,7 +62,7 @@ describe("AptosStreamClient", function () {
62
62
  it("should correctly set passed params", function () {
63
63
  var pid = "PID";
64
64
  var gas = "30";
65
- var instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
65
+ var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
66
66
  expect(instance.getMaxGas()).toEqual({ max_gas_amount: gas });
67
67
  expect(instance.getProgramId()).toBe(pid);
68
68
  });
@@ -70,9 +70,9 @@ describe("AptosStreamClient", function () {
70
70
  describe("create", function () {
71
71
  var pid = "PID";
72
72
  var gas = "30";
73
- var instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
73
+ var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
74
74
  beforeEach(function () {
75
- instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
75
+ instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
76
76
  });
77
77
  test("should create a stream with passed parameters", function () { return __awaiter(void 0, void 0, void 0, function () {
78
78
  var mockSigner, mockWallet, mockRecipient, mockData, mockReturn, result, callParam, args;
@@ -1,17 +1,18 @@
1
1
  import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
3
  import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
4
4
  export default class AptosStreamClient extends BaseStreamClient {
5
5
  private programId;
6
6
  private maxGas;
7
- constructor(cluster?: ICluster, maxGas?: string, programId?: string);
7
+ private client;
8
+ constructor(clusterUrl: string, cluster?: ICluster, maxGas?: string, programId?: string);
8
9
  create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult>;
9
10
  createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<IMultiTransactionResult>;
10
11
  withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
11
12
  cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
12
13
  transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
13
14
  topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
14
- getOne(): Promise<any>;
15
+ getOne({ id }: IGetOneData): Promise<any>;
15
16
  getProgramId(): string;
16
17
  getMaxGas(): {
17
18
  max_gas_amount: string;
@@ -55,14 +55,16 @@ var aptos_1 = require("aptos");
55
55
  var BaseStreamClient_1 = require("../common/BaseStreamClient");
56
56
  var types_1 = require("../common/types");
57
57
  var constants_1 = require("./constants");
58
+ var types_2 = require("./types");
58
59
  var AptosStreamClient = /** @class */ (function (_super) {
59
60
  __extends(AptosStreamClient, _super);
60
- function AptosStreamClient(cluster, maxGas, programId) {
61
+ function AptosStreamClient(clusterUrl, cluster, maxGas, programId) {
61
62
  if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
62
63
  if (maxGas === void 0) { maxGas = "10000"; }
63
64
  var _this = _super.call(this) || this;
64
65
  _this.programId = programId ? programId : constants_1.APTOS_PROGRAM_IDS[cluster];
65
66
  _this.maxGas = maxGas;
67
+ _this.client = new aptos_1.AptosClient(clusterUrl);
66
68
  return _this;
67
69
  }
68
70
  AptosStreamClient.prototype.create = function (streamData, _a) {
@@ -242,10 +244,25 @@ var AptosStreamClient = /** @class */ (function (_super) {
242
244
  });
243
245
  });
244
246
  };
245
- AptosStreamClient.prototype.getOne = function () {
247
+ AptosStreamClient.prototype.getOne = function (_a) {
248
+ var _b;
249
+ var id = _a.id;
246
250
  return __awaiter(this, void 0, void 0, function () {
247
- return __generator(this, function (_a) {
248
- throw new Error("Not implemented.");
251
+ var contractResources, contract, tokenIdMatch, tokenId, data;
252
+ return __generator(this, function (_c) {
253
+ switch (_c.label) {
254
+ case 0: return [4 /*yield*/, this.client.getAccountResources(id)];
255
+ case 1:
256
+ contractResources = _c.sent();
257
+ contract = contractResources.find(function (r) { return r.type.includes("protocol::Contract"); });
258
+ if (!contract) {
259
+ throw new Error("Contract with id ".concat(id, " could not be found!"));
260
+ }
261
+ tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
262
+ tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
263
+ data = contract.data;
264
+ return [2 /*return*/, [id, new types_2.Contract(data, tokenId)]];
265
+ }
249
266
  });
250
267
  });
251
268
  };
@@ -1,2 +1,2 @@
1
- export { default } from "./StreamClient";
1
+ export { default, default as AptosStreamClient } from "./StreamClient";
2
2
  export * from "./types";
@@ -17,7 +17,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.default = void 0;
20
+ exports.AptosStreamClient = exports.default = void 0;
21
21
  var StreamClient_1 = require("./StreamClient");
22
22
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
23
+ Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
23
24
  __exportStar(require("./types"), exports);
@@ -8,12 +8,13 @@ import { ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
8
8
  export interface SolanaStreamClientOptions {
9
9
  chain: IChain.Solana;
10
10
  clusterUrl: string;
11
- commitment?: Commitment | ConnectionConfig;
12
11
  cluster?: ICluster;
13
12
  programId?: string;
13
+ commitment?: Commitment | ConnectionConfig;
14
14
  }
15
15
  export interface AptosStreamClientOptions {
16
16
  chain: IChain.Aptos;
17
+ clusterUrl: string;
17
18
  cluster?: ICluster;
18
19
  programId?: string;
19
20
  maxGas?: string;
@@ -31,7 +31,7 @@ var GenericStreamClient = /** @class */ (function (_super) {
31
31
  _this.nativeStreamClient = new StreamClient_1.default(options.clusterUrl, options.cluster, options.commitment, options.programId);
32
32
  }
33
33
  else {
34
- _this.nativeStreamClient = new StreamClient_2.default(options.cluster, options.maxGas, options.programId);
34
+ _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
35
35
  }
36
36
  return _this;
37
37
  }
@@ -173,7 +173,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
173
173
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
174
174
  }
175
175
  ixs = [];
176
- mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
176
+ mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
177
177
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
178
178
  metadata = web3_js_1.Keypair.generate();
179
179
  return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
@@ -1,4 +1,4 @@
1
- export { default } from "./StreamClient";
1
+ export { default, default as SolanaStreamClient } from "./StreamClient";
2
2
  export * from "./utils";
3
3
  export * from "./types";
4
4
  export * from "./instructions";
@@ -29,9 +29,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.BN = exports.timelockIDL = exports.constants = exports.default = void 0;
32
+ exports.BN = exports.timelockIDL = exports.constants = exports.SolanaStreamClient = exports.default = void 0;
33
33
  var StreamClient_1 = require("./StreamClient");
34
34
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
35
+ Object.defineProperty(exports, "SolanaStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
35
36
  __exportStar(require("./utils"), exports);
36
37
  __exportStar(require("./types"), exports);
37
38
  __exportStar(require("./instructions"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0-Alpha.2",
3
+ "version": "4.0.0-Alpha.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/",