@streamflow/stream 5.6.0 → 5.6.2

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.
Files changed (74) hide show
  1. package/LICENSE +674 -0
  2. package/package.json +5 -6
  3. package/dist/__tests__/aptos/streamClient.spec.d.ts +0 -1
  4. package/dist/__tests__/aptos/streamClient.spec.js +0 -161
  5. package/dist/aptos/StreamClient.d.ts +0 -51
  6. package/dist/aptos/StreamClient.js +0 -387
  7. package/dist/aptos/constants.d.ts +0 -8
  8. package/dist/aptos/constants.js +0 -28
  9. package/dist/aptos/index.d.ts +0 -2
  10. package/dist/aptos/index.js +0 -24
  11. package/dist/aptos/types.d.ts +0 -97
  12. package/dist/aptos/types.js +0 -76
  13. package/dist/aptos/utils.d.ts +0 -1
  14. package/dist/aptos/utils.js +0 -12
  15. package/dist/aptos/wallet.d.ts +0 -9
  16. package/dist/aptos/wallet.js +0 -89
  17. package/dist/common/BaseStreamClient.d.ts +0 -13
  18. package/dist/common/BaseStreamClient.js +0 -13
  19. package/dist/common/GenericStreamClient.d.ts +0 -93
  20. package/dist/common/GenericStreamClient.js +0 -114
  21. package/dist/common/constants.d.ts +0 -1
  22. package/dist/common/constants.js +0 -4
  23. package/dist/common/contractUtils.d.ts +0 -47
  24. package/dist/common/contractUtils.js +0 -55
  25. package/dist/common/types.d.ts +0 -252
  26. package/dist/common/types.js +0 -165
  27. package/dist/common/utils.d.ts +0 -22
  28. package/dist/common/utils.js +0 -101
  29. package/dist/evm/StreamClient.d.ts +0 -30
  30. package/dist/evm/StreamClient.js +0 -461
  31. package/dist/evm/abi.d.ts +0 -111
  32. package/dist/evm/abi.js +0 -1257
  33. package/dist/evm/constants.d.ts +0 -20
  34. package/dist/evm/constants.js +0 -39
  35. package/dist/evm/ercAbi.d.ts +0 -39
  36. package/dist/evm/ercAbi.js +0 -224
  37. package/dist/evm/index.d.ts +0 -2
  38. package/dist/evm/index.js +0 -24
  39. package/dist/evm/types.d.ts +0 -93
  40. package/dist/evm/types.js +0 -75
  41. package/dist/evm/utils.d.ts +0 -1
  42. package/dist/evm/utils.js +0 -12
  43. package/dist/index.d.ts +0 -8
  44. package/dist/index.js +0 -41
  45. package/dist/solana/StreamClient.d.ts +0 -72
  46. package/dist/solana/StreamClient.js +0 -927
  47. package/dist/solana/constants.d.ts +0 -22
  48. package/dist/solana/constants.js +0 -50
  49. package/dist/solana/index.d.ts +0 -7
  50. package/dist/solana/index.js +0 -43
  51. package/dist/solana/instructionTypes.d.ts +0 -96
  52. package/dist/solana/instructionTypes.js +0 -2
  53. package/dist/solana/instructions.d.ts +0 -139
  54. package/dist/solana/instructions.js +0 -407
  55. package/dist/solana/layout.d.ts +0 -27
  56. package/dist/solana/layout.js +0 -170
  57. package/dist/solana/timelockIDL.d.ts +0 -22
  58. package/dist/solana/timelockIDL.js +0 -422
  59. package/dist/solana/types.d.ts +0 -292
  60. package/dist/solana/types.js +0 -81
  61. package/dist/solana/utils.d.ts +0 -44
  62. package/dist/solana/utils.js +0 -303
  63. package/dist/sui/StreamClient.d.ts +0 -79
  64. package/dist/sui/StreamClient.js +0 -571
  65. package/dist/sui/constants.d.ts +0 -10
  66. package/dist/sui/constants.js +0 -43
  67. package/dist/sui/index.d.ts +0 -2
  68. package/dist/sui/index.js +0 -23
  69. package/dist/sui/types.d.ts +0 -141
  70. package/dist/sui/types.js +0 -102
  71. package/dist/sui/utils.d.ts +0 -2
  72. package/dist/sui/utils.js +0 -29
  73. package/dist/sui/wallet.d.ts +0 -11
  74. package/dist/sui/wallet.js +0 -75
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.6.0",
3
+ "version": "5.6.2",
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/",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
- "build": "rm -rf ./dist && tsc --outDir ./dist --project ../../tsconfig.json",
10
- "build-docs": "typedoc ./index.ts",
9
+ "build": "rm -rf dist; tsc -p tsconfig.json",
11
10
  "test": "jest .",
12
11
  "lint": "eslint .",
13
- "prepublishOnly": "npm test && npm run build-docs && npm run build"
12
+ "prepublishOnly": "npm run lint && npm test && npm run build"
14
13
  },
15
- "gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
14
+ "gitHead": "eea3fb583ee99bcd754da11186dd2558bcea2eeb",
16
15
  "devDependencies": {
17
16
  "@types/bn.js": "5.1.1",
18
17
  "@types/ethereum-checksum-address": "^0.0.0",
@@ -44,4 +43,4 @@
44
43
  "ethers": "5.7.2",
45
44
  "js-sha256": "0.9.0"
46
45
  }
47
- }
46
+ }
@@ -1 +0,0 @@
1
- export {};
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var bn_js_1 = require("bn.js");
54
- var StreamClient_1 = __importDefault(require("../../aptos/StreamClient"));
55
- var types_1 = require("../../common/types");
56
- describe("AptosStreamClient", function () {
57
- describe("coreClient", function () {
58
- it("should succesfully create AptosStreamInstance", function () {
59
- var instance = new StreamClient_1.default(types_1.ICluster.Devnet);
60
- expect(instance).toBeInstanceOf(StreamClient_1.default);
61
- });
62
- it("should correctly set passed params", function () {
63
- var pid = "PID";
64
- var gas = "30";
65
- var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
66
- expect(instance.getMaxGas()).toEqual({ max_gas_amount: gas });
67
- expect(instance.getProgramId()).toBe(pid);
68
- });
69
- });
70
- describe("create", function () {
71
- var pid = "PID";
72
- var gas = "30";
73
- var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
74
- beforeEach(function () {
75
- instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
76
- });
77
- test("should create a stream with passed parameters", function () { return __awaiter(void 0, void 0, void 0, function () {
78
- var mockSigner, mockWallet, mockRecipient, mockData, mockReturn, result, callParam, args;
79
- return __generator(this, function (_a) {
80
- switch (_a.label) {
81
- case 0:
82
- mockSigner = jest.fn();
83
- mockWallet = {
84
- signAndSubmitTransaction: mockSigner,
85
- account: { address: "" },
86
- };
87
- mockRecipient = {
88
- recipient: "0xtest",
89
- amount: new bn_js_1.BN(1000),
90
- name: "test name",
91
- cliffAmount: new bn_js_1.BN(1),
92
- amountPerPeriod: new bn_js_1.BN(1),
93
- };
94
- mockData = {
95
- period: 100,
96
- start: 10,
97
- cliff: 12,
98
- cancelableBySender: true,
99
- cancelableByRecipient: false,
100
- transferableBySender: false,
101
- transferableByRecipient: true,
102
- canTopup: true,
103
- automaticWithdrawal: false,
104
- withdrawalFrequency: 10,
105
- tokenId: "0xtest::token::Token",
106
- canPause: false,
107
- canUpdateRate: false,
108
- };
109
- mockReturn = "hash";
110
- mockSigner.mockResolvedValue({ hash: mockReturn });
111
- return [4 /*yield*/, instance.create(__assign(__assign({}, mockData), mockRecipient), { senderWallet: mockWallet })];
112
- case 1:
113
- result = _a.sent();
114
- // Assert
115
- expect(mockSigner).toHaveBeenCalledTimes(1);
116
- callParam = mockSigner.mock.calls[0][0];
117
- args = callParam.arguments;
118
- delete callParam.arguments;
119
- args.shift();
120
- expect(args).toEqual([
121
- mockRecipient.amount.toString(),
122
- 100,
123
- mockRecipient.amountPerPeriod.toString(),
124
- 10,
125
- mockRecipient.cliffAmount.toString(),
126
- true,
127
- false,
128
- false,
129
- true,
130
- true,
131
- false,
132
- false,
133
- false,
134
- 10,
135
- "test name",
136
- "0xtest",
137
- ]);
138
- expect(callParam).toEqual({
139
- function: "PID::protocol::create",
140
- type: "create",
141
- type_arguments: ["0xtest::token::Token"],
142
- });
143
- expect(result.txId).toEqual(mockReturn);
144
- return [2 /*return*/];
145
- }
146
- });
147
- }); });
148
- });
149
- // describe("createMultiple", () => {
150
- // });
151
- // describe("withdraw", () => {
152
- // });
153
- // describe("cancel", () => {
154
- // });
155
- // describe("transfer", () => {
156
- // });
157
- // describe("topup", () => {
158
- // });
159
- // describe("getOne", () => {
160
- // });
161
- });
@@ -1,51 +0,0 @@
1
- import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
3
- import { Contract, ICreateStreamAptosExt, ITransactionAptosExt } from "./types";
4
- export default class AptosStreamClient extends BaseStreamClient {
5
- private programId;
6
- private maxGas;
7
- private client;
8
- constructor(clusterUrl: string, cluster?: ICluster, maxGas?: string, programId?: string);
9
- /**
10
- * Creates a new stream/vesting contract.
11
- */
12
- create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ICreateResult>;
13
- /**
14
- * Creates multiple stream/vesting contracts.
15
- */
16
- createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<IMultiTransactionResult>;
17
- /**
18
- * Attempts withdrawing from the specified stream.
19
- */
20
- withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
21
- /**
22
- * Attempts canceling the specified stream.
23
- */
24
- cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
25
- /**
26
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
27
- */
28
- transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
29
- /**
30
- * Tops up stream account with specified amount.
31
- */
32
- topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
33
- /**
34
- * Fetch stream data by its id (address).
35
- */
36
- getOne({ id }: IGetOneData): Promise<Contract>;
37
- get(): Promise<[string, Contract][]>;
38
- /**
39
- * Attempts updating the stream auto withdrawal params and amount per period
40
- */
41
- update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
42
- extractErrorCode(err: Error): string | null;
43
- /**
44
- * Returns StreamClient protocol program ID.
45
- */
46
- getProgramId(): string;
47
- getMaxGas(): {
48
- max_gas_amount: string;
49
- };
50
- private generateMultiPayloads;
51
- }
@@ -1,387 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __read = (this && this.__read) || function (o, n) {
65
- var m = typeof Symbol === "function" && o[Symbol.iterator];
66
- if (!m) return o;
67
- var i = m.call(o), r, ar = [], e;
68
- try {
69
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
- }
71
- catch (error) { e = { error: error }; }
72
- finally {
73
- try {
74
- if (r && !r.done && (m = i["return"])) m.call(i);
75
- }
76
- finally { if (e) throw e.error; }
77
- }
78
- return ar;
79
- };
80
- Object.defineProperty(exports, "__esModule", { value: true });
81
- var aptos_1 = require("aptos");
82
- var BaseStreamClient_1 = require("../common/BaseStreamClient");
83
- var types_1 = require("../common/types");
84
- var constants_1 = require("./constants");
85
- var types_2 = require("./types");
86
- var wallet_1 = require("./wallet");
87
- var utils_1 = require("./utils");
88
- var AptosStreamClient = /** @class */ (function (_super) {
89
- __extends(AptosStreamClient, _super);
90
- function AptosStreamClient(clusterUrl, cluster, maxGas, programId) {
91
- if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
92
- if (maxGas === void 0) { maxGas = "10000"; }
93
- var _this = _super.call(this) || this;
94
- _this.programId = programId ? programId : constants_1.APTOS_PROGRAM_IDS[cluster];
95
- _this.maxGas = maxGas;
96
- _this.client = new aptos_1.AptosClient(clusterUrl);
97
- return _this;
98
- }
99
- /**
100
- * Creates a new stream/vesting contract.
101
- */
102
- AptosStreamClient.prototype.create = function (streamData, _a) {
103
- var senderWallet = _a.senderWallet;
104
- return __awaiter(this, void 0, void 0, function () {
105
- var wallet, _b, metadataId, payload, hash;
106
- return __generator(this, function (_c) {
107
- switch (_c.label) {
108
- case 0:
109
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
110
- _b = __read(this.generateMultiPayloads(__assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }), wallet)[0], 2), metadataId = _b[0], payload = _b[1];
111
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
112
- case 1:
113
- hash = _c.sent();
114
- return [2 /*return*/, { ixs: [payload], txId: hash, metadataId: metadataId }];
115
- }
116
- });
117
- });
118
- };
119
- /**
120
- * Creates multiple stream/vesting contracts.
121
- */
122
- AptosStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
123
- var _b;
124
- var senderWallet = _a.senderWallet;
125
- return __awaiter(this, void 0, void 0, function () {
126
- var wallet, payloads, txs, metadatas, metadataToRecipient, errors, i, _c, metadataId, payload, recipient, hash, e_1;
127
- return __generator(this, function (_d) {
128
- switch (_d.label) {
129
- case 0:
130
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
131
- payloads = this.generateMultiPayloads(multipleStreamData, wallet);
132
- txs = [];
133
- metadatas = [];
134
- metadataToRecipient = {};
135
- errors = [];
136
- i = 0;
137
- _d.label = 1;
138
- case 1:
139
- if (!(i < payloads.length)) return [3 /*break*/, 7];
140
- _c = __read(payloads[i], 2), metadataId = _c[0], payload = _c[1];
141
- recipient = multipleStreamData.recipients[i];
142
- _d.label = 2;
143
- case 2:
144
- _d.trys.push([2, 4, 5, 6]);
145
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
146
- case 3:
147
- hash = _d.sent();
148
- txs.push(hash);
149
- return [3 /*break*/, 6];
150
- case 4:
151
- e_1 = _d.sent();
152
- errors.push({
153
- error: (_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.toString()) !== null && _b !== void 0 ? _b : "Unknown error!",
154
- recipient: recipient.recipient,
155
- });
156
- return [3 /*break*/, 6];
157
- case 5:
158
- metadatas.push(metadataId);
159
- metadataToRecipient[metadataId] = recipient;
160
- return [7 /*endfinally*/];
161
- case 6:
162
- i++;
163
- return [3 /*break*/, 1];
164
- case 7: return [2 /*return*/, {
165
- txs: txs,
166
- metadatas: metadatas,
167
- metadataToRecipient: metadataToRecipient,
168
- errors: errors,
169
- }];
170
- }
171
- });
172
- });
173
- };
174
- /**
175
- * Attempts withdrawing from the specified stream.
176
- */
177
- AptosStreamClient.prototype.withdraw = function (withdrawData, _a) {
178
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
179
- return __awaiter(this, void 0, void 0, function () {
180
- var payload, wallet, hash;
181
- return __generator(this, function (_b) {
182
- switch (_b.label) {
183
- case 0:
184
- payload = {
185
- type: "withdraw",
186
- function: "".concat(this.programId, "::protocol::withdraw"),
187
- type_arguments: [tokenId],
188
- arguments: [withdrawData.id, withdrawData.amount.toString()],
189
- };
190
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
191
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
192
- case 1:
193
- hash = _b.sent();
194
- return [2 /*return*/, { ixs: [payload], txId: hash }];
195
- }
196
- });
197
- });
198
- };
199
- /**
200
- * Attempts canceling the specified stream.
201
- */
202
- AptosStreamClient.prototype.cancel = function (cancelData, _a) {
203
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
204
- return __awaiter(this, void 0, void 0, function () {
205
- var payload, wallet, hash;
206
- return __generator(this, function (_b) {
207
- switch (_b.label) {
208
- case 0:
209
- payload = {
210
- type: "cancel",
211
- function: "".concat(this.programId, "::protocol::cancel"),
212
- type_arguments: [tokenId],
213
- arguments: [cancelData.id],
214
- };
215
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
216
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
217
- case 1:
218
- hash = _b.sent();
219
- return [2 /*return*/, { ixs: [payload], txId: hash }];
220
- }
221
- });
222
- });
223
- };
224
- /**
225
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
226
- */
227
- AptosStreamClient.prototype.transfer = function (transferData, _a) {
228
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
229
- return __awaiter(this, void 0, void 0, function () {
230
- var payload, wallet, hash;
231
- return __generator(this, function (_b) {
232
- switch (_b.label) {
233
- case 0:
234
- payload = {
235
- type: "transfer",
236
- function: "".concat(this.programId, "::protocol::transfer"),
237
- type_arguments: [tokenId],
238
- arguments: [transferData.id, transferData.newRecipient],
239
- };
240
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
241
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
242
- case 1:
243
- hash = _b.sent();
244
- return [2 /*return*/, { ixs: [payload], txId: hash }];
245
- }
246
- });
247
- });
248
- };
249
- /**
250
- * Tops up stream account with specified amount.
251
- */
252
- AptosStreamClient.prototype.topup = function (topupData, _a) {
253
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
254
- return __awaiter(this, void 0, void 0, function () {
255
- var payload, wallet, hash;
256
- return __generator(this, function (_b) {
257
- switch (_b.label) {
258
- case 0:
259
- payload = {
260
- type: "topup",
261
- function: "".concat(this.programId, "::protocol::topup"),
262
- type_arguments: [tokenId],
263
- arguments: [topupData.id, topupData.amount.toString()],
264
- };
265
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
266
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
267
- case 1:
268
- hash = _b.sent();
269
- return [2 /*return*/, { ixs: [payload], txId: hash }];
270
- }
271
- });
272
- });
273
- };
274
- /**
275
- * Fetch stream data by its id (address).
276
- */
277
- AptosStreamClient.prototype.getOne = function (_a) {
278
- var _b;
279
- var id = _a.id;
280
- return __awaiter(this, void 0, void 0, function () {
281
- var contractResources, contract, tokenIdMatch, tokenId, data;
282
- return __generator(this, function (_c) {
283
- switch (_c.label) {
284
- case 0: return [4 /*yield*/, this.client.getAccountResources(id)];
285
- case 1:
286
- contractResources = _c.sent();
287
- contract = contractResources.find(function (r) { return r.type.includes("protocol::Contract"); });
288
- if (!contract) {
289
- throw new Error("Contract with id ".concat(id, " could not be found!"));
290
- }
291
- tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
292
- tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
293
- data = contract.data;
294
- return [2 /*return*/, new types_2.Contract(data, tokenId)];
295
- }
296
- });
297
- });
298
- };
299
- AptosStreamClient.prototype.get = function () {
300
- return __awaiter(this, void 0, void 0, function () {
301
- return __generator(this, function (_a) {
302
- throw new Error("Get all method is not supported for Aptos chain!");
303
- });
304
- });
305
- };
306
- /**
307
- * Attempts updating the stream auto withdrawal params and amount per period
308
- */
309
- AptosStreamClient.prototype.update = function (updateData, _a) {
310
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
311
- return __awaiter(this, void 0, void 0, function () {
312
- var wallet, payload, hash;
313
- return __generator(this, function (_b) {
314
- switch (_b.label) {
315
- case 0:
316
- wallet = new wallet_1.AptosWalletWrapper(senderWallet, this.client);
317
- payload = {
318
- type: "update",
319
- function: "".concat(this.programId, "::protocol::update"),
320
- type_arguments: [tokenId],
321
- arguments: [
322
- updateData.id,
323
- updateData.enableAutomaticWithdrawal ? [true] : [],
324
- updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
325
- updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
326
- ],
327
- };
328
- return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
329
- case 1:
330
- hash = _b.sent();
331
- return [2 /*return*/, { ixs: [payload], txId: hash }];
332
- }
333
- });
334
- });
335
- };
336
- AptosStreamClient.prototype.extractErrorCode = function (err) {
337
- var _a;
338
- return (0, utils_1.extractAptosErrorCode)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
339
- };
340
- /**
341
- * Returns StreamClient protocol program ID.
342
- */
343
- AptosStreamClient.prototype.getProgramId = function () {
344
- return this.programId;
345
- };
346
- AptosStreamClient.prototype.getMaxGas = function () {
347
- return { max_gas_amount: this.maxGas };
348
- };
349
- // Utility function to prepare transaction payloads for multiple recipients.
350
- AptosStreamClient.prototype.generateMultiPayloads = function (multipleStreamData, wallet) {
351
- var _this = this;
352
- return multipleStreamData.recipients.map(function (recipient) {
353
- var acc = new aptos_1.AptosAccount(); // Generate random address as seeds for deriving "escrow" account
354
- var seeds = acc.address();
355
- var metadataId = aptos_1.AptosAccount.getResourceAccountAddress(wallet.address, seeds.toUint8Array());
356
- return [
357
- metadataId.toString(),
358
- {
359
- type: "create",
360
- function: "".concat(_this.programId, "::protocol::create"),
361
- type_arguments: [multipleStreamData.tokenId],
362
- arguments: [
363
- seeds.toUint8Array(),
364
- recipient.amount.toString(),
365
- multipleStreamData.period,
366
- recipient.amountPerPeriod.toString(),
367
- multipleStreamData.start,
368
- recipient.cliffAmount.toString(),
369
- multipleStreamData.cancelableBySender,
370
- multipleStreamData.cancelableByRecipient,
371
- multipleStreamData.transferableBySender,
372
- multipleStreamData.transferableByRecipient,
373
- multipleStreamData.canTopup,
374
- multipleStreamData.canPause || false,
375
- multipleStreamData.canUpdateRate || false,
376
- multipleStreamData.automaticWithdrawal || false,
377
- multipleStreamData.withdrawalFrequency || 0,
378
- recipient.name,
379
- recipient.recipient,
380
- ],
381
- },
382
- ];
383
- });
384
- };
385
- return AptosStreamClient;
386
- }(BaseStreamClient_1.BaseStreamClient));
387
- exports.default = AptosStreamClient;
@@ -1,8 +0,0 @@
1
- import { ICluster } from "../common/types";
2
- export declare const APTOS_PROGRAM_IDS: Record<ICluster, string>;
3
- export declare const APTOS_ERROR_MATCH_REGEX: RegExp;
4
- export declare const APTOS_MODULE_ERROR_MAP: {
5
- [key: string]: {
6
- [key: number]: string;
7
- };
8
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.APTOS_MODULE_ERROR_MAP = exports.APTOS_ERROR_MATCH_REGEX = exports.APTOS_PROGRAM_IDS = void 0;
5
- var types_1 = require("../common/types");
6
- exports.APTOS_PROGRAM_IDS = (_a = {},
7
- _a[types_1.ICluster.Mainnet] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
8
- // TODO: Add a correct programID for Test net
9
- _a[types_1.ICluster.Devnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
10
- _a[types_1.ICluster.Testnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
11
- _a[types_1.ICluster.Local] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
12
- _a);
13
- exports.APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
14
- exports.APTOS_MODULE_ERROR_MAP = {
15
- protocol: {
16
- 1: types_1.ContractErrorCode.ECONTRACT_NOT_INIT,
17
- 2: types_1.ContractErrorCode.EBAD_AMOUNT,
18
- 3: types_1.ContractErrorCode.ENO_PERMISSIONS,
19
- 4: types_1.ContractErrorCode.EBADINPUT,
20
- 5: types_1.ContractErrorCode.ECLOSED,
21
- 6: types_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
22
- 8: types_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
23
- 9: types_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
24
- 10: types_1.ContractErrorCode.EBAD_INPUT_PERIOD,
25
- 11: types_1.ContractErrorCode.EBAD_INPUT_START,
26
- 12: types_1.ContractErrorCode.ENO_RECIPIENT_COIN_ADDRESS,
27
- },
28
- };
@@ -1,2 +0,0 @@
1
- export { default, default as AptosStreamClient } from "./StreamClient";
2
- export * from "./types";