@streamflow/stream 5.0.1 → 5.1.0
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/aptos/types.d.ts +1 -45
- package/dist/aptos/types.js +12 -1
- package/dist/common/BaseStreamClient.d.ts +1 -2
- package/dist/common/GenericStreamClient.d.ts +16 -11
- package/dist/common/GenericStreamClient.js +14 -56
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +4 -0
- package/dist/common/contractUtils.d.ts +13 -1
- package/dist/common/contractUtils.js +2 -1
- package/dist/common/types.d.ts +45 -0
- package/dist/evm/StreamClient.d.ts +1 -2
- package/dist/evm/StreamClient.js +1 -1
- package/dist/evm/types.d.ts +1 -45
- package/dist/evm/types.js +12 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/solana/StreamClient.d.ts +4 -4
- package/dist/solana/constants.d.ts +0 -1
- package/dist/solana/constants.js +1 -2
- package/dist/solana/instructions.js +1 -1
- package/dist/solana/types.d.ts +1 -46
- package/dist/solana/types.js +12 -1
- package/dist/solana/utils.d.ts +2 -1
- package/dist/sui/StreamClient.d.ts +78 -0
- package/dist/sui/StreamClient.js +542 -0
- package/dist/sui/constants.d.ts +4 -0
- package/dist/sui/constants.js +23 -0
- package/dist/sui/index.d.ts +2 -0
- package/dist/sui/index.js +23 -0
- package/dist/sui/types.d.ts +137 -0
- package/dist/sui/types.js +163 -0
- package/package.json +4 -1
|
@@ -0,0 +1,78 @@
|
|
|
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, ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters } from "./types";
|
|
4
|
+
export default class SuiStreamClient extends BaseStreamClient {
|
|
5
|
+
private programId;
|
|
6
|
+
private configId;
|
|
7
|
+
private feeTableId;
|
|
8
|
+
private client;
|
|
9
|
+
constructor(clusterUrl: string, cluster?: ICluster, ids?: ISuiIdParameters);
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new stream/vesting contract.
|
|
12
|
+
*/
|
|
13
|
+
create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamSuiExt): Promise<ICreateResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates multiple stream/vesting contracts.
|
|
16
|
+
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
17
|
+
*/
|
|
18
|
+
createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamSuiExt): Promise<IMultiTransactionResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Attempts withdrawing from the specified stream.
|
|
21
|
+
*/
|
|
22
|
+
withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Attempts canceling the specified stream.
|
|
25
|
+
*/
|
|
26
|
+
cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
29
|
+
*/
|
|
30
|
+
transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Tops up stream account with specified amount.
|
|
33
|
+
*/
|
|
34
|
+
topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Fetch stream data by its id (address).
|
|
37
|
+
*/
|
|
38
|
+
getOne({ id }: IGetOneData): Promise<Contract>;
|
|
39
|
+
get(): Promise<[string, Contract][]>;
|
|
40
|
+
/**
|
|
41
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
42
|
+
*/
|
|
43
|
+
update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns StreamClient protocol program ID.
|
|
46
|
+
*/
|
|
47
|
+
getProgramId(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Utility function to generate Transaction Block to create streams
|
|
50
|
+
*/
|
|
51
|
+
private generateCreateTransactions;
|
|
52
|
+
/**
|
|
53
|
+
* Returns all coins owned by a Wallet
|
|
54
|
+
* @param walletAddress wallet address
|
|
55
|
+
* @param coinType coin type
|
|
56
|
+
* @returns Array of Coin Structs
|
|
57
|
+
*/
|
|
58
|
+
private getAllCoins;
|
|
59
|
+
/**
|
|
60
|
+
* Utility function to split Coin object and use splitted object for stream operations.
|
|
61
|
+
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
62
|
+
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
63
|
+
* @param txb current transanction block
|
|
64
|
+
* @param amount minimal amount of coins requried
|
|
65
|
+
* @param coinType coin type
|
|
66
|
+
* @param coins array of owned coins of the same type
|
|
67
|
+
* @returns Coin Object to use in a Move Call
|
|
68
|
+
*/
|
|
69
|
+
private splitCoinObjectForAmount;
|
|
70
|
+
/**
|
|
71
|
+
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
72
|
+
* @param txb current transanction block
|
|
73
|
+
* @param coinType coin type
|
|
74
|
+
* @param coinObject splitted object
|
|
75
|
+
* @param coins array of objects used in
|
|
76
|
+
*/
|
|
77
|
+
private returnSplittedCoinObject;
|
|
78
|
+
}
|
|
@@ -0,0 +1,542 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
81
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
82
|
+
if (ar || !(i in from)) {
|
|
83
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
84
|
+
ar[i] = from[i];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
88
|
+
};
|
|
89
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
90
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
91
|
+
};
|
|
92
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
|
+
var client_1 = require("@mysten/sui.js/client");
|
|
95
|
+
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
96
|
+
var utils_1 = require("@mysten/sui.js/utils");
|
|
97
|
+
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
98
|
+
var types_1 = require("../common/types");
|
|
99
|
+
var constants_1 = require("../common/constants");
|
|
100
|
+
var constants_2 = require("./constants");
|
|
101
|
+
var types_2 = require("./types");
|
|
102
|
+
var SuiStreamClient = /** @class */ (function (_super) {
|
|
103
|
+
__extends(SuiStreamClient, _super);
|
|
104
|
+
function SuiStreamClient(clusterUrl, cluster, ids) {
|
|
105
|
+
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
106
|
+
var _this = _super.call(this) || this;
|
|
107
|
+
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program : constants_2.SUI_PROGRAM_IDS[cluster];
|
|
108
|
+
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config : constants_2.SUI_CONFIG_IDS[cluster];
|
|
109
|
+
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_2.SUI_FEE_TABLE_IDS[cluster];
|
|
110
|
+
_this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
111
|
+
return _this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new stream/vesting contract.
|
|
115
|
+
*/
|
|
116
|
+
SuiStreamClient.prototype.create = function (streamData, _a) {
|
|
117
|
+
var senderWallet = _a.senderWallet;
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var wallet, _b, txb, _c, digest, events;
|
|
120
|
+
return __generator(this, function (_d) {
|
|
121
|
+
switch (_d.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
124
|
+
return [4 /*yield*/, this.generateCreateTransactions(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }))];
|
|
125
|
+
case 1:
|
|
126
|
+
_b = __read.apply(void 0, [_d.sent(), 1]), txb = _b[0];
|
|
127
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
128
|
+
transactionBlock: txb,
|
|
129
|
+
options: { showEvents: true },
|
|
130
|
+
})];
|
|
131
|
+
case 2:
|
|
132
|
+
_c = _d.sent(), digest = _c.digest, events = _c.events;
|
|
133
|
+
return [2 /*return*/, {
|
|
134
|
+
ixs: [],
|
|
135
|
+
txId: digest,
|
|
136
|
+
metadataId: events[0].parsedJson.address,
|
|
137
|
+
}];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates multiple stream/vesting contracts.
|
|
144
|
+
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
145
|
+
*/
|
|
146
|
+
SuiStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
147
|
+
var _b;
|
|
148
|
+
var senderWallet = _a.senderWallet;
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var wallet, transactions, txs, metadatas, metadataToRecipient, errors, i, txb, recipient, _c, digest, events, metadataId, e_1;
|
|
151
|
+
return __generator(this, function (_d) {
|
|
152
|
+
switch (_d.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
155
|
+
return [4 /*yield*/, this.generateCreateTransactions(wallet.address, multipleStreamData)];
|
|
156
|
+
case 1:
|
|
157
|
+
transactions = _d.sent();
|
|
158
|
+
txs = [];
|
|
159
|
+
metadatas = [];
|
|
160
|
+
metadataToRecipient = {};
|
|
161
|
+
errors = [];
|
|
162
|
+
i = 0;
|
|
163
|
+
_d.label = 2;
|
|
164
|
+
case 2:
|
|
165
|
+
if (!(i < transactions.length)) return [3 /*break*/, 7];
|
|
166
|
+
txb = transactions[i];
|
|
167
|
+
recipient = multipleStreamData.recipients[i];
|
|
168
|
+
_d.label = 3;
|
|
169
|
+
case 3:
|
|
170
|
+
_d.trys.push([3, 5, , 6]);
|
|
171
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
172
|
+
transactionBlock: txb,
|
|
173
|
+
options: { showEvents: true },
|
|
174
|
+
})];
|
|
175
|
+
case 4:
|
|
176
|
+
_c = _d.sent(), digest = _c.digest, events = _c.events;
|
|
177
|
+
txs.push(digest);
|
|
178
|
+
metadataId = events[0].parsedJson.address;
|
|
179
|
+
metadatas.push(metadataId);
|
|
180
|
+
metadataToRecipient[metadataId] = recipient;
|
|
181
|
+
return [3 /*break*/, 6];
|
|
182
|
+
case 5:
|
|
183
|
+
e_1 = _d.sent();
|
|
184
|
+
errors.push({
|
|
185
|
+
error: (_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.toString()) !== null && _b !== void 0 ? _b : "Unkown error!",
|
|
186
|
+
recipient: recipient.recipient,
|
|
187
|
+
});
|
|
188
|
+
return [3 /*break*/, 6];
|
|
189
|
+
case 6:
|
|
190
|
+
i++;
|
|
191
|
+
return [3 /*break*/, 2];
|
|
192
|
+
case 7: return [2 /*return*/, {
|
|
193
|
+
txs: txs,
|
|
194
|
+
metadatas: metadatas,
|
|
195
|
+
metadataToRecipient: metadataToRecipient,
|
|
196
|
+
errors: errors,
|
|
197
|
+
}];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Attempts withdrawing from the specified stream.
|
|
204
|
+
*/
|
|
205
|
+
SuiStreamClient.prototype.withdraw = function (withdrawData, _a) {
|
|
206
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var wallet, txb, digest;
|
|
209
|
+
return __generator(this, function (_b) {
|
|
210
|
+
switch (_b.label) {
|
|
211
|
+
case 0:
|
|
212
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
213
|
+
txb = new transactions_1.TransactionBlock();
|
|
214
|
+
txb.moveCall({
|
|
215
|
+
target: "".concat(this.programId, "::protocol::withdraw"),
|
|
216
|
+
typeArguments: [tokenId],
|
|
217
|
+
arguments: [
|
|
218
|
+
txb.object(withdrawData.id),
|
|
219
|
+
txb.object(this.configId),
|
|
220
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
221
|
+
txb.pure(withdrawData.amount),
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
225
|
+
transactionBlock: txb,
|
|
226
|
+
})];
|
|
227
|
+
case 1:
|
|
228
|
+
digest = (_b.sent()).digest;
|
|
229
|
+
return [2 /*return*/, {
|
|
230
|
+
ixs: [],
|
|
231
|
+
txId: digest,
|
|
232
|
+
}];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Attempts canceling the specified stream.
|
|
239
|
+
*/
|
|
240
|
+
SuiStreamClient.prototype.cancel = function (cancelData, _a) {
|
|
241
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
var wallet, txb, digest;
|
|
244
|
+
return __generator(this, function (_b) {
|
|
245
|
+
switch (_b.label) {
|
|
246
|
+
case 0:
|
|
247
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
248
|
+
txb = new transactions_1.TransactionBlock();
|
|
249
|
+
txb.moveCall({
|
|
250
|
+
target: "".concat(this.programId, "::protocol::cancel"),
|
|
251
|
+
typeArguments: [tokenId],
|
|
252
|
+
arguments: [
|
|
253
|
+
txb.object(cancelData.id),
|
|
254
|
+
txb.object(this.configId),
|
|
255
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
259
|
+
transactionBlock: txb,
|
|
260
|
+
})];
|
|
261
|
+
case 1:
|
|
262
|
+
digest = (_b.sent()).digest;
|
|
263
|
+
return [2 /*return*/, {
|
|
264
|
+
ixs: [],
|
|
265
|
+
txId: digest,
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
273
|
+
*/
|
|
274
|
+
SuiStreamClient.prototype.transfer = function (transferData, _a) {
|
|
275
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var wallet, txb, digest;
|
|
278
|
+
return __generator(this, function (_b) {
|
|
279
|
+
switch (_b.label) {
|
|
280
|
+
case 0:
|
|
281
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
282
|
+
txb = new transactions_1.TransactionBlock();
|
|
283
|
+
txb.moveCall({
|
|
284
|
+
target: "".concat(this.programId, "::protocol::transfer"),
|
|
285
|
+
typeArguments: [tokenId],
|
|
286
|
+
arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
|
|
287
|
+
});
|
|
288
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
289
|
+
transactionBlock: txb,
|
|
290
|
+
})];
|
|
291
|
+
case 1:
|
|
292
|
+
digest = (_b.sent()).digest;
|
|
293
|
+
return [2 /*return*/, {
|
|
294
|
+
ixs: [],
|
|
295
|
+
txId: digest,
|
|
296
|
+
}];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Tops up stream account with specified amount.
|
|
303
|
+
*/
|
|
304
|
+
SuiStreamClient.prototype.topup = function (topupData, _a) {
|
|
305
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
306
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
+
var wallet, txb, coins, coinObject, digest;
|
|
308
|
+
return __generator(this, function (_b) {
|
|
309
|
+
switch (_b.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
312
|
+
txb = new transactions_1.TransactionBlock();
|
|
313
|
+
return [4 /*yield*/, this.getAllCoins(wallet.address, tokenId)];
|
|
314
|
+
case 1:
|
|
315
|
+
coins = _b.sent();
|
|
316
|
+
coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins);
|
|
317
|
+
txb.moveCall({
|
|
318
|
+
target: "".concat(this.programId, "::protocol::topup"),
|
|
319
|
+
typeArguments: [tokenId],
|
|
320
|
+
arguments: [
|
|
321
|
+
txb.object(topupData.id),
|
|
322
|
+
txb.object(this.configId),
|
|
323
|
+
coinObject,
|
|
324
|
+
txb.gas,
|
|
325
|
+
txb.pure(topupData.amount),
|
|
326
|
+
],
|
|
327
|
+
});
|
|
328
|
+
this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
|
|
329
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
330
|
+
transactionBlock: txb,
|
|
331
|
+
})];
|
|
332
|
+
case 2:
|
|
333
|
+
digest = (_b.sent()).digest;
|
|
334
|
+
return [2 /*return*/, {
|
|
335
|
+
ixs: [],
|
|
336
|
+
txId: digest,
|
|
337
|
+
}];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Fetch stream data by its id (address).
|
|
344
|
+
*/
|
|
345
|
+
SuiStreamClient.prototype.getOne = function (_a) {
|
|
346
|
+
var id = _a.id;
|
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
+
var response, content;
|
|
349
|
+
return __generator(this, function (_b) {
|
|
350
|
+
switch (_b.label) {
|
|
351
|
+
case 0: return [4 /*yield*/, this.client.getObject({
|
|
352
|
+
id: id,
|
|
353
|
+
options: {
|
|
354
|
+
showContent: true,
|
|
355
|
+
},
|
|
356
|
+
})];
|
|
357
|
+
case 1:
|
|
358
|
+
response = _b.sent();
|
|
359
|
+
if (!response.data) {
|
|
360
|
+
throw new Error("Contract with id ".concat(id, " could not be found!"));
|
|
361
|
+
}
|
|
362
|
+
content = response.data.content;
|
|
363
|
+
if (content.dataType !== "moveObject") {
|
|
364
|
+
throw new Error("Not a Move Object!");
|
|
365
|
+
}
|
|
366
|
+
return [2 /*return*/, new types_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT")];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
SuiStreamClient.prototype.get = function () {
|
|
372
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
throw new Error("Get all method is not supported for Sui chain!");
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
380
|
+
*/
|
|
381
|
+
SuiStreamClient.prototype.update = function (updateData, _a) {
|
|
382
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
383
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
384
|
+
var wallet, txb, digest;
|
|
385
|
+
return __generator(this, function (_b) {
|
|
386
|
+
switch (_b.label) {
|
|
387
|
+
case 0:
|
|
388
|
+
wallet = new types_2.SuiWalletWrapper(senderWallet, this.client);
|
|
389
|
+
txb = new transactions_1.TransactionBlock();
|
|
390
|
+
txb.moveCall({
|
|
391
|
+
target: "".concat(this.programId, "::protocol::update"),
|
|
392
|
+
typeArguments: [tokenId],
|
|
393
|
+
arguments: [
|
|
394
|
+
txb.object(updateData.id),
|
|
395
|
+
txb.object(this.configId),
|
|
396
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
397
|
+
txb.gas,
|
|
398
|
+
txb.pure(updateData.enableAutomaticWithdrawal !== undefined
|
|
399
|
+
? [updateData.enableAutomaticWithdrawal]
|
|
400
|
+
: [], "vector<bool>"),
|
|
401
|
+
txb.pure(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency] : [], "vector<u64>"),
|
|
402
|
+
txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod] : [], "vector<u64>"),
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
406
|
+
transactionBlock: txb,
|
|
407
|
+
})];
|
|
408
|
+
case 1:
|
|
409
|
+
digest = (_b.sent()).digest;
|
|
410
|
+
return [2 /*return*/, {
|
|
411
|
+
ixs: [],
|
|
412
|
+
txId: digest,
|
|
413
|
+
}];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Returns StreamClient protocol program ID.
|
|
420
|
+
*/
|
|
421
|
+
SuiStreamClient.prototype.getProgramId = function () {
|
|
422
|
+
return this.programId;
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* Utility function to generate Transaction Block to create streams
|
|
426
|
+
*/
|
|
427
|
+
SuiStreamClient.prototype.generateCreateTransactions = function (walletAddress, multipleStreamData) {
|
|
428
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
429
|
+
var coins;
|
|
430
|
+
var _this = this;
|
|
431
|
+
return __generator(this, function (_a) {
|
|
432
|
+
switch (_a.label) {
|
|
433
|
+
case 0: return [4 /*yield*/, this.getAllCoins(walletAddress, multipleStreamData.tokenId)];
|
|
434
|
+
case 1:
|
|
435
|
+
coins = _a.sent();
|
|
436
|
+
return [2 /*return*/, multipleStreamData.recipients.map(function (recipient) {
|
|
437
|
+
var txb = new transactions_1.TransactionBlock();
|
|
438
|
+
var coinObject = _this.splitCoinObjectForAmount(txb, recipient.amount, multipleStreamData.tokenId, coins);
|
|
439
|
+
// Overwrite coins because after first split we merge all existing object to the first coin
|
|
440
|
+
coins = [coins[0]];
|
|
441
|
+
txb.moveCall({
|
|
442
|
+
target: "".concat(_this.programId, "::protocol::create"),
|
|
443
|
+
typeArguments: [multipleStreamData.tokenId],
|
|
444
|
+
arguments: [
|
|
445
|
+
txb.object(_this.configId),
|
|
446
|
+
txb.object(_this.feeTableId),
|
|
447
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
448
|
+
coinObject,
|
|
449
|
+
txb.gas,
|
|
450
|
+
txb.pure(recipient.amount),
|
|
451
|
+
txb.pure(multipleStreamData.period),
|
|
452
|
+
txb.pure(recipient.amountPerPeriod),
|
|
453
|
+
txb.pure(multipleStreamData.start),
|
|
454
|
+
txb.pure(recipient.cliffAmount),
|
|
455
|
+
txb.pure(multipleStreamData.cancelableBySender),
|
|
456
|
+
txb.pure(multipleStreamData.cancelableByRecipient),
|
|
457
|
+
txb.pure(multipleStreamData.cancelableBySender),
|
|
458
|
+
txb.pure(multipleStreamData.cancelableByRecipient),
|
|
459
|
+
txb.pure(multipleStreamData.canTopup),
|
|
460
|
+
txb.pure(!!multipleStreamData.canPause),
|
|
461
|
+
txb.pure(!!multipleStreamData.canUpdateRate),
|
|
462
|
+
txb.pure(!!multipleStreamData.automaticWithdrawal),
|
|
463
|
+
txb.pure(multipleStreamData.withdrawalFrequency || 0),
|
|
464
|
+
txb.pure(recipient.name),
|
|
465
|
+
txb.pure(recipient.recipient),
|
|
466
|
+
txb.pure(multipleStreamData.partner || walletAddress),
|
|
467
|
+
],
|
|
468
|
+
});
|
|
469
|
+
_this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
470
|
+
return txb;
|
|
471
|
+
})];
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Returns all coins owned by a Wallet
|
|
478
|
+
* @param walletAddress wallet address
|
|
479
|
+
* @param coinType coin type
|
|
480
|
+
* @returns Array of Coin Structs
|
|
481
|
+
*/
|
|
482
|
+
SuiStreamClient.prototype.getAllCoins = function (walletAddress, coinType) {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
484
|
+
var coinsResponse, coins;
|
|
485
|
+
return __generator(this, function (_a) {
|
|
486
|
+
switch (_a.label) {
|
|
487
|
+
case 0: return [4 /*yield*/, this.client.getCoins({
|
|
488
|
+
owner: walletAddress,
|
|
489
|
+
coinType: coinType,
|
|
490
|
+
})];
|
|
491
|
+
case 1:
|
|
492
|
+
coinsResponse = _a.sent();
|
|
493
|
+
coins = coinsResponse.data;
|
|
494
|
+
_a.label = 2;
|
|
495
|
+
case 2:
|
|
496
|
+
if (!coinsResponse.hasNextPage) return [3 /*break*/, 4];
|
|
497
|
+
return [4 /*yield*/, this.client.getCoins({
|
|
498
|
+
owner: walletAddress,
|
|
499
|
+
coinType: coinType,
|
|
500
|
+
cursor: coinsResponse.nextCursor,
|
|
501
|
+
})];
|
|
502
|
+
case 3:
|
|
503
|
+
coinsResponse = _a.sent();
|
|
504
|
+
coins.push.apply(coins, __spreadArray([], __read(coinsResponse.data), false));
|
|
505
|
+
return [3 /*break*/, 2];
|
|
506
|
+
case 4: return [2 /*return*/, coins];
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Utility function to split Coin object and use splitted object for stream operations.
|
|
513
|
+
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
514
|
+
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
515
|
+
* @param txb current transanction block
|
|
516
|
+
* @param amount minimal amount of coins requried
|
|
517
|
+
* @param coinType coin type
|
|
518
|
+
* @param coins array of owned coins of the same type
|
|
519
|
+
* @returns Coin Object to use in a Move Call
|
|
520
|
+
*/
|
|
521
|
+
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins) {
|
|
522
|
+
var coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
523
|
+
if (coins.length > 1) {
|
|
524
|
+
txb.mergeCoins(coinObject, coins.slice(1).map(function (item) { return txb.object(item.coinObjectId); }));
|
|
525
|
+
}
|
|
526
|
+
var sum = amount.mul(new bn_js_1.default(constants_1.BASE_FEE)).div(new bn_js_1.default(1000000));
|
|
527
|
+
return txb.splitCoins(coinObject, [txb.pure(sum)])[0];
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
530
|
+
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
531
|
+
* @param txb current transanction block
|
|
532
|
+
* @param coinType coin type
|
|
533
|
+
* @param coinObject splitted object
|
|
534
|
+
* @param coins array of objects used in
|
|
535
|
+
*/
|
|
536
|
+
SuiStreamClient.prototype.returnSplittedCoinObject = function (txb, coinType, coins, coinObject) {
|
|
537
|
+
var firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
538
|
+
txb.mergeCoins(firstCoinObject, [coinObject]);
|
|
539
|
+
};
|
|
540
|
+
return SuiStreamClient;
|
|
541
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
542
|
+
exports.default = SuiStreamClient;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
5
|
+
var types_1 = require("../common/types");
|
|
6
|
+
exports.SUI_PROGRAM_IDS = (_a = {},
|
|
7
|
+
_a[types_1.ICluster.Mainnet] = "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2",
|
|
8
|
+
_a[types_1.ICluster.Devnet] = "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2",
|
|
9
|
+
_a[types_1.ICluster.Testnet] = "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2",
|
|
10
|
+
_a[types_1.ICluster.Local] = "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2",
|
|
11
|
+
_a);
|
|
12
|
+
exports.SUI_CONFIG_IDS = (_b = {},
|
|
13
|
+
_b[types_1.ICluster.Mainnet] = "0xb235494fd29ad70647bfb15c18d0b9ca2aa568ab94ec27fd53a43715775dd5d8",
|
|
14
|
+
_b[types_1.ICluster.Devnet] = "0xb235494fd29ad70647bfb15c18d0b9ca2aa568ab94ec27fd53a43715775dd5d8",
|
|
15
|
+
_b[types_1.ICluster.Testnet] = "0xb235494fd29ad70647bfb15c18d0b9ca2aa568ab94ec27fd53a43715775dd5d8",
|
|
16
|
+
_b[types_1.ICluster.Local] = "0xb235494fd29ad70647bfb15c18d0b9ca2aa568ab94ec27fd53a43715775dd5d8",
|
|
17
|
+
_b);
|
|
18
|
+
exports.SUI_FEE_TABLE_IDS = (_c = {},
|
|
19
|
+
_c[types_1.ICluster.Mainnet] = "0x321175a859a97c2ade153d302d3c777247f24a3836c84d2d1fb78369c1403d81",
|
|
20
|
+
_c[types_1.ICluster.Devnet] = "0x321175a859a97c2ade153d302d3c777247f24a3836c84d2d1fb78369c1403d81",
|
|
21
|
+
_c[types_1.ICluster.Testnet] = "0x321175a859a97c2ade153d302d3c777247f24a3836c84d2d1fb78369c1403d81",
|
|
22
|
+
_c[types_1.ICluster.Local] = "0x321175a859a97c2ade153d302d3c777247f24a3836c84d2d1fb78369c1403d81",
|
|
23
|
+
_c);
|