@streamflow/stream 3.0.17 → 3.0.18
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.
- package/dist/__tests__/aptos/streamClient.spec.d.ts +1 -0
- package/dist/__tests__/aptos/streamClient.spec.js +160 -0
- package/dist/aptos/StreamClient.d.ts +49 -0
- package/dist/aptos/StreamClient.js +362 -0
- package/dist/aptos/constants.d.ts +2 -0
- package/dist/aptos/constants.js +12 -0
- package/dist/aptos/index.d.ts +2 -0
- package/dist/aptos/index.js +24 -0
- package/dist/aptos/types.d.ts +145 -0
- package/dist/aptos/types.js +65 -0
- package/dist/common/BaseStreamClient.d.ts +11 -0
- package/dist/common/BaseStreamClient.js +9 -0
- package/dist/common/GenericStreamClient.d.ts +60 -0
- package/dist/common/GenericStreamClient.js +137 -0
- package/dist/common/types.d.ts +71 -0
- package/dist/common/types.js +28 -0
- package/dist/{utils.d.ts → common/utils.d.ts} +0 -4
- package/dist/common/utils.js +31 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.js +19 -10
- package/dist/solana/StreamClient.d.ts +71 -0
- package/dist/{StreamClient.js → solana/StreamClient.js} +303 -396
- package/dist/{constants.d.ts → solana/constants.d.ts} +1 -1
- package/dist/{constants.js → solana/constants.js} +5 -5
- package/dist/solana/index.d.ts +7 -0
- package/dist/solana/index.js +43 -0
- package/dist/solana/instructionTypes.d.ts +86 -0
- package/dist/solana/instructionTypes.js +2 -0
- package/dist/{instructions.d.ts → solana/instructions.d.ts} +8 -2
- package/dist/{instructions.js → solana/instructions.js} +55 -38
- package/dist/solana/layout.d.ts +27 -0
- package/dist/{layout.js → solana/layout.js} +65 -3
- package/dist/{idl/timelock.d.ts → solana/timelockIDL.d.ts} +0 -0
- package/dist/{idl/timelock.js → solana/timelockIDL.js} +0 -0
- package/dist/{types.d.ts → solana/types.d.ts} +37 -34
- package/dist/{types.js → solana/types.js} +3 -20
- package/dist/solana/utils.d.ts +42 -0
- package/dist/solana/utils.js +271 -0
- package/package.json +1 -1
- package/dist/Stream.d.ts +0 -87
- package/dist/Stream.js +0 -503
- package/dist/StreamClient.d.ts +0 -146
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -3
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +0 -67
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +0 -6
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +0 -215
- package/dist/__tests__/test_dependencies/constants/index.d.ts +0 -122
- package/dist/__tests__/test_dependencies/constants/index.js +0 -158
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +0 -27
- package/dist/__tests__/test_dependencies/idl/airdrop.js +0 -171
- package/dist/layout.d.ts +0 -22
- package/dist/utils.js +0 -126
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
};
|
|
86
|
+
mockRecipient = {
|
|
87
|
+
recipient: "0xtest",
|
|
88
|
+
amount: new bn_js_1.BN(1000),
|
|
89
|
+
name: "test name",
|
|
90
|
+
cliffAmount: new bn_js_1.BN(1),
|
|
91
|
+
amountPerPeriod: new bn_js_1.BN(1),
|
|
92
|
+
};
|
|
93
|
+
mockData = {
|
|
94
|
+
period: 100,
|
|
95
|
+
start: 10,
|
|
96
|
+
cliff: 12,
|
|
97
|
+
cancelableBySender: true,
|
|
98
|
+
cancelableByRecipient: false,
|
|
99
|
+
transferableBySender: false,
|
|
100
|
+
transferableByRecipient: true,
|
|
101
|
+
canTopup: true,
|
|
102
|
+
automaticWithdrawal: false,
|
|
103
|
+
withdrawalFrequency: 10,
|
|
104
|
+
tokenId: "0xtest::token::Token",
|
|
105
|
+
canPause: false,
|
|
106
|
+
canUpdateRate: false,
|
|
107
|
+
};
|
|
108
|
+
mockReturn = "hash";
|
|
109
|
+
mockSigner.mockResolvedValue({ hash: mockReturn });
|
|
110
|
+
return [4 /*yield*/, instance.create(__assign(__assign({}, mockData), mockRecipient), { senderWallet: mockWallet })];
|
|
111
|
+
case 1:
|
|
112
|
+
result = _a.sent();
|
|
113
|
+
// Assert
|
|
114
|
+
expect(mockSigner).toHaveBeenCalledTimes(1);
|
|
115
|
+
callParam = mockSigner.mock.calls[0][0];
|
|
116
|
+
args = callParam.arguments;
|
|
117
|
+
delete callParam.arguments;
|
|
118
|
+
args.shift();
|
|
119
|
+
expect(args).toEqual([
|
|
120
|
+
mockRecipient.amount.toString(),
|
|
121
|
+
100,
|
|
122
|
+
mockRecipient.amountPerPeriod.toString(),
|
|
123
|
+
10,
|
|
124
|
+
mockRecipient.cliffAmount.toString(),
|
|
125
|
+
true,
|
|
126
|
+
false,
|
|
127
|
+
false,
|
|
128
|
+
true,
|
|
129
|
+
true,
|
|
130
|
+
false,
|
|
131
|
+
false,
|
|
132
|
+
false,
|
|
133
|
+
10,
|
|
134
|
+
"test name",
|
|
135
|
+
"0xtest",
|
|
136
|
+
]);
|
|
137
|
+
expect(callParam).toEqual({
|
|
138
|
+
function: "PID::protocol::create",
|
|
139
|
+
type: "create",
|
|
140
|
+
type_arguments: ["0xtest::token::Token"],
|
|
141
|
+
});
|
|
142
|
+
expect(result).toEqual({ txId: mockReturn });
|
|
143
|
+
return [2 /*return*/];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}); });
|
|
147
|
+
});
|
|
148
|
+
// describe("createMultiple", () => {
|
|
149
|
+
// });
|
|
150
|
+
// describe("withdraw", () => {
|
|
151
|
+
// });
|
|
152
|
+
// describe("cancel", () => {
|
|
153
|
+
// });
|
|
154
|
+
// describe("transfer", () => {
|
|
155
|
+
// });
|
|
156
|
+
// describe("topup", () => {
|
|
157
|
+
// });
|
|
158
|
+
// describe("getOne", () => {
|
|
159
|
+
// });
|
|
160
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseStreamClient } from "../common/BaseStreamClient";
|
|
2
|
+
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
|
|
3
|
+
import { Contract, ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } 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<ITransactionResult>;
|
|
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
|
+
/**
|
|
38
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
39
|
+
*/
|
|
40
|
+
update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns StreamClient protocol program ID.
|
|
43
|
+
*/
|
|
44
|
+
getProgramId(): string;
|
|
45
|
+
getMaxGas(): {
|
|
46
|
+
max_gas_amount: string;
|
|
47
|
+
};
|
|
48
|
+
private generateMultiPayloads;
|
|
49
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
var aptos_1 = require("aptos");
|
|
55
|
+
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
56
|
+
var types_1 = require("../common/types");
|
|
57
|
+
var constants_1 = require("./constants");
|
|
58
|
+
var types_2 = require("./types");
|
|
59
|
+
var AptosStreamClient = /** @class */ (function (_super) {
|
|
60
|
+
__extends(AptosStreamClient, _super);
|
|
61
|
+
function AptosStreamClient(clusterUrl, cluster, maxGas, programId) {
|
|
62
|
+
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
63
|
+
if (maxGas === void 0) { maxGas = "10000"; }
|
|
64
|
+
var _this = _super.call(this) || this;
|
|
65
|
+
_this.programId = programId ? programId : constants_1.APTOS_PROGRAM_IDS[cluster];
|
|
66
|
+
_this.maxGas = maxGas;
|
|
67
|
+
_this.client = new aptos_1.AptosClient(clusterUrl);
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new stream/vesting contract.
|
|
72
|
+
*/
|
|
73
|
+
AptosStreamClient.prototype.create = function (streamData, _a) {
|
|
74
|
+
var senderWallet = _a.senderWallet;
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var acc, seeds, payload, hash;
|
|
77
|
+
return __generator(this, function (_b) {
|
|
78
|
+
switch (_b.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
acc = new aptos_1.AptosAccount();
|
|
81
|
+
seeds = acc.address().hex();
|
|
82
|
+
payload = {
|
|
83
|
+
type: "create",
|
|
84
|
+
function: "".concat(this.programId, "::protocol::create"),
|
|
85
|
+
type_arguments: [streamData.tokenId],
|
|
86
|
+
arguments: [
|
|
87
|
+
seeds,
|
|
88
|
+
streamData.amount.toString(),
|
|
89
|
+
streamData.period,
|
|
90
|
+
streamData.amountPerPeriod.toString(),
|
|
91
|
+
streamData.start,
|
|
92
|
+
streamData.cliffAmount.toString(),
|
|
93
|
+
streamData.cancelableBySender,
|
|
94
|
+
streamData.cancelableByRecipient,
|
|
95
|
+
streamData.transferableBySender,
|
|
96
|
+
streamData.transferableByRecipient,
|
|
97
|
+
streamData.canTopup,
|
|
98
|
+
streamData.canPause || false,
|
|
99
|
+
streamData.canUpdateRate || false,
|
|
100
|
+
streamData.automaticWithdrawal || false,
|
|
101
|
+
streamData.withdrawalFrequency || 0,
|
|
102
|
+
streamData.name,
|
|
103
|
+
streamData.recipient,
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
107
|
+
case 1:
|
|
108
|
+
hash = (_b.sent()).hash;
|
|
109
|
+
return [2 /*return*/, { txId: hash }];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Creates multiple stream/vesting contracts.
|
|
116
|
+
*/
|
|
117
|
+
AptosStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
118
|
+
var _b;
|
|
119
|
+
var senderWallet = _a.senderWallet;
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var payloads, txs, metadatas, metadataToRecipient, errors, i, payload, recipient, hash, e_1, metadataId;
|
|
122
|
+
return __generator(this, function (_c) {
|
|
123
|
+
switch (_c.label) {
|
|
124
|
+
case 0:
|
|
125
|
+
payloads = this.generateMultiPayloads(multipleStreamData);
|
|
126
|
+
txs = [];
|
|
127
|
+
metadatas = [];
|
|
128
|
+
metadataToRecipient = {};
|
|
129
|
+
errors = [];
|
|
130
|
+
i = 0;
|
|
131
|
+
_c.label = 1;
|
|
132
|
+
case 1:
|
|
133
|
+
if (!(i < payloads.length)) return [3 /*break*/, 7];
|
|
134
|
+
payload = payloads[i];
|
|
135
|
+
recipient = multipleStreamData.recipients[i];
|
|
136
|
+
_c.label = 2;
|
|
137
|
+
case 2:
|
|
138
|
+
_c.trys.push([2, 4, 5, 6]);
|
|
139
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
140
|
+
case 3:
|
|
141
|
+
hash = (_c.sent()).hash;
|
|
142
|
+
txs.push(hash);
|
|
143
|
+
return [3 /*break*/, 6];
|
|
144
|
+
case 4:
|
|
145
|
+
e_1 = _c.sent();
|
|
146
|
+
errors.push({
|
|
147
|
+
error: (_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.toString()) !== null && _b !== void 0 ? _b : "Unkown error!",
|
|
148
|
+
recipient: recipient.recipient,
|
|
149
|
+
});
|
|
150
|
+
return [3 /*break*/, 6];
|
|
151
|
+
case 5:
|
|
152
|
+
metadataId = payload.arguments[0];
|
|
153
|
+
metadatas.push(metadataId);
|
|
154
|
+
metadataToRecipient[metadataId] = recipient;
|
|
155
|
+
return [7 /*endfinally*/];
|
|
156
|
+
case 6:
|
|
157
|
+
i++;
|
|
158
|
+
return [3 /*break*/, 1];
|
|
159
|
+
case 7: return [2 /*return*/, {
|
|
160
|
+
txs: txs,
|
|
161
|
+
metadatas: metadatas,
|
|
162
|
+
metadataToRecipient: metadataToRecipient,
|
|
163
|
+
errors: errors,
|
|
164
|
+
}];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Attempts withdrawing from the specified stream.
|
|
171
|
+
*/
|
|
172
|
+
AptosStreamClient.prototype.withdraw = function (withdrawData, _a) {
|
|
173
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var payload, hash;
|
|
176
|
+
return __generator(this, function (_b) {
|
|
177
|
+
switch (_b.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
payload = {
|
|
180
|
+
type: "withdraw",
|
|
181
|
+
function: "".concat(this.programId, "::protocol::withdraw"),
|
|
182
|
+
type_arguments: [tokenId],
|
|
183
|
+
arguments: [withdrawData.id, withdrawData.amount.toString()],
|
|
184
|
+
};
|
|
185
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
186
|
+
case 1:
|
|
187
|
+
hash = (_b.sent()).hash;
|
|
188
|
+
return [2 /*return*/, { txId: hash }];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Attempts canceling the specified stream.
|
|
195
|
+
*/
|
|
196
|
+
AptosStreamClient.prototype.cancel = function (cancelData, _a) {
|
|
197
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
198
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
199
|
+
var payload, hash;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0:
|
|
203
|
+
payload = {
|
|
204
|
+
type: "cancel",
|
|
205
|
+
function: "".concat(this.programId, "::protocol::cancel"),
|
|
206
|
+
type_arguments: [tokenId],
|
|
207
|
+
arguments: [cancelData.id],
|
|
208
|
+
};
|
|
209
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
210
|
+
case 1:
|
|
211
|
+
hash = (_b.sent()).hash;
|
|
212
|
+
return [2 /*return*/, { txId: hash }];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
219
|
+
*/
|
|
220
|
+
AptosStreamClient.prototype.transfer = function (transferData, _a) {
|
|
221
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
222
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
+
var payload, hash;
|
|
224
|
+
return __generator(this, function (_b) {
|
|
225
|
+
switch (_b.label) {
|
|
226
|
+
case 0:
|
|
227
|
+
payload = {
|
|
228
|
+
type: "transfer",
|
|
229
|
+
function: "".concat(this.programId, "::protocol::transfer"),
|
|
230
|
+
type_arguments: [tokenId],
|
|
231
|
+
arguments: [transferData.id, transferData.newRecipient],
|
|
232
|
+
};
|
|
233
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
234
|
+
case 1:
|
|
235
|
+
hash = (_b.sent()).hash;
|
|
236
|
+
return [2 /*return*/, { txId: hash }];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Tops up stream account with specified amount.
|
|
243
|
+
*/
|
|
244
|
+
AptosStreamClient.prototype.topup = function (topupData, _a) {
|
|
245
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
246
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
+
var payload, hash;
|
|
248
|
+
return __generator(this, function (_b) {
|
|
249
|
+
switch (_b.label) {
|
|
250
|
+
case 0:
|
|
251
|
+
payload = {
|
|
252
|
+
type: "topup",
|
|
253
|
+
function: "".concat(this.programId, "::protocol::topup"),
|
|
254
|
+
type_arguments: [tokenId],
|
|
255
|
+
arguments: [topupData.id, topupData.amount.toString()],
|
|
256
|
+
};
|
|
257
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
258
|
+
case 1:
|
|
259
|
+
hash = (_b.sent()).hash;
|
|
260
|
+
return [2 /*return*/, { txId: hash }];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Fetch stream data by its id (address).
|
|
267
|
+
*/
|
|
268
|
+
AptosStreamClient.prototype.getOne = function (_a) {
|
|
269
|
+
var _b;
|
|
270
|
+
var id = _a.id;
|
|
271
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
272
|
+
var contractResources, contract, tokenIdMatch, tokenId, data;
|
|
273
|
+
return __generator(this, function (_c) {
|
|
274
|
+
switch (_c.label) {
|
|
275
|
+
case 0: return [4 /*yield*/, this.client.getAccountResources(id)];
|
|
276
|
+
case 1:
|
|
277
|
+
contractResources = _c.sent();
|
|
278
|
+
contract = contractResources.find(function (r) { return r.type.includes("protocol::Contract"); });
|
|
279
|
+
if (!contract) {
|
|
280
|
+
throw new Error("Contract with id ".concat(id, " could not be found!"));
|
|
281
|
+
}
|
|
282
|
+
tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
|
|
283
|
+
tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
|
|
284
|
+
data = contract.data;
|
|
285
|
+
return [2 /*return*/, new types_2.Contract(data, tokenId)];
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
292
|
+
*/
|
|
293
|
+
AptosStreamClient.prototype.update = function (updateData, _a) {
|
|
294
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var payload, hash;
|
|
297
|
+
return __generator(this, function (_b) {
|
|
298
|
+
switch (_b.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
payload = {
|
|
301
|
+
type: "update",
|
|
302
|
+
function: "".concat(this.programId, "::protocol::update"),
|
|
303
|
+
type_arguments: [tokenId],
|
|
304
|
+
arguments: [
|
|
305
|
+
updateData.id,
|
|
306
|
+
updateData.enableAutomaticWithdrawal ? [true] : [],
|
|
307
|
+
updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
|
|
308
|
+
updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
312
|
+
case 1:
|
|
313
|
+
hash = (_b.sent()).hash;
|
|
314
|
+
return [2 /*return*/, { txId: hash }];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Returns StreamClient protocol program ID.
|
|
321
|
+
*/
|
|
322
|
+
AptosStreamClient.prototype.getProgramId = function () {
|
|
323
|
+
return this.programId;
|
|
324
|
+
};
|
|
325
|
+
AptosStreamClient.prototype.getMaxGas = function () {
|
|
326
|
+
return { max_gas_amount: this.maxGas };
|
|
327
|
+
};
|
|
328
|
+
// Utility function to prepare transaction payloads for multiple recipients.
|
|
329
|
+
AptosStreamClient.prototype.generateMultiPayloads = function (multipleStreamData) {
|
|
330
|
+
var _this = this;
|
|
331
|
+
return multipleStreamData.recipients.map(function (recipient) {
|
|
332
|
+
var acc = new aptos_1.AptosAccount(); // Generate random address as seeds for derriving "escrow" account
|
|
333
|
+
var seeds = acc.address().hex();
|
|
334
|
+
return {
|
|
335
|
+
type: "create",
|
|
336
|
+
function: "".concat(_this.programId, "::protocol::create"),
|
|
337
|
+
type_arguments: [multipleStreamData.tokenId],
|
|
338
|
+
arguments: [
|
|
339
|
+
seeds,
|
|
340
|
+
recipient.amount.toString(),
|
|
341
|
+
multipleStreamData.period,
|
|
342
|
+
recipient.amountPerPeriod.toString(),
|
|
343
|
+
multipleStreamData.start,
|
|
344
|
+
recipient.cliffAmount.toString(),
|
|
345
|
+
multipleStreamData.cancelableBySender,
|
|
346
|
+
multipleStreamData.cancelableByRecipient,
|
|
347
|
+
multipleStreamData.transferableBySender,
|
|
348
|
+
multipleStreamData.transferableByRecipient,
|
|
349
|
+
multipleStreamData.canTopup,
|
|
350
|
+
multipleStreamData.canPause || false,
|
|
351
|
+
multipleStreamData.canUpdateRate || false,
|
|
352
|
+
multipleStreamData.automaticWithdrawal || false,
|
|
353
|
+
multipleStreamData.withdrawalFrequency || 0,
|
|
354
|
+
recipient.name,
|
|
355
|
+
recipient.recipient,
|
|
356
|
+
],
|
|
357
|
+
};
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
return AptosStreamClient;
|
|
361
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
362
|
+
exports.default = AptosStreamClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
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);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.AptosStreamClient = exports.default = void 0;
|
|
21
|
+
var StreamClient_1 = require("./StreamClient");
|
|
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; } });
|
|
24
|
+
__exportStar(require("./types"), exports);
|