@streamflow/stream 5.5.0 → 5.6.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/README.md +5 -6
- package/dist/aptos/StreamClient.d.ts +1 -0
- package/dist/aptos/StreamClient.js +5 -1
- package/dist/aptos/constants.d.ts +6 -0
- package/dist/aptos/constants.js +17 -1
- package/dist/aptos/utils.d.ts +1 -0
- package/dist/aptos/utils.js +12 -0
- package/dist/aptos/wallet.js +13 -7
- package/dist/common/BaseStreamClient.d.ts +1 -0
- package/dist/common/BaseStreamClient.js +4 -0
- package/dist/common/GenericStreamClient.d.ts +10 -0
- package/dist/common/GenericStreamClient.js +19 -7
- package/dist/common/types.d.ts +103 -0
- package/dist/common/types.js +133 -1
- package/dist/common/utils.d.ts +7 -0
- package/dist/common/utils.js +68 -1
- package/dist/evm/StreamClient.d.ts +1 -0
- package/dist/evm/StreamClient.js +5 -0
- package/dist/evm/constants.d.ts +17 -1
- package/dist/evm/constants.js +17 -1
- package/dist/evm/utils.d.ts +1 -0
- package/dist/evm/utils.js +12 -0
- package/dist/solana/StreamClient.d.ts +1 -0
- package/dist/solana/StreamClient.js +5 -1
- package/dist/solana/constants.d.ts +4 -0
- package/dist/solana/constants.js +27 -1
- package/dist/solana/utils.d.ts +2 -1
- package/dist/solana/utils.js +23 -3
- package/dist/sui/StreamClient.d.ts +2 -1
- package/dist/sui/StreamClient.js +95 -69
- package/dist/sui/constants.d.ts +6 -0
- package/dist/sui/constants.js +20 -1
- package/dist/sui/types.d.ts +10 -0
- package/dist/sui/utils.d.ts +2 -0
- package/dist/sui/utils.js +29 -0
- package/package.json +4 -3
package/dist/evm/StreamClient.js
CHANGED
|
@@ -100,6 +100,7 @@ var abi_1 = __importDefault(require("./abi"));
|
|
|
100
100
|
var ercAbi_1 = __importDefault(require("./ercAbi"));
|
|
101
101
|
var constants_2 = require("../common/constants");
|
|
102
102
|
var types_2 = require("./types");
|
|
103
|
+
var utils_1 = require("./utils");
|
|
103
104
|
var EvmStreamClient = /** @class */ (function (_super) {
|
|
104
105
|
__extends(EvmStreamClient, _super);
|
|
105
106
|
function EvmStreamClient(clusterUrl, chain, signer, cluster, programId) {
|
|
@@ -366,6 +367,10 @@ var EvmStreamClient = /** @class */ (function (_super) {
|
|
|
366
367
|
});
|
|
367
368
|
});
|
|
368
369
|
};
|
|
370
|
+
EvmStreamClient.prototype.extractErrorCode = function (err) {
|
|
371
|
+
var _a;
|
|
372
|
+
return (0, utils_1.extractEvmErrorCode)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
|
|
373
|
+
};
|
|
369
374
|
/**
|
|
370
375
|
* Returns StreamClient protocol program ID.
|
|
371
376
|
*/
|
package/dist/evm/constants.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import { ICluster } from "../common/types";
|
|
1
|
+
import { ContractErrorCode, ICluster } from "../common/types";
|
|
2
2
|
export declare const ETHEREUM_PROGRAM_IDS: Record<ICluster, string>;
|
|
3
3
|
export declare const BNB_PROGRAM_IDS: Record<ICluster, string>;
|
|
4
4
|
export declare const POLYGON_PROGRAM_IDS: Record<ICluster, string>;
|
|
5
|
+
export declare const EVM_ERROR_MATCH_REGEX: RegExp;
|
|
6
|
+
export declare const EVM_ERROR_MAP: {
|
|
7
|
+
ECONTRACT_NOT_INIT: ContractErrorCode;
|
|
8
|
+
EBAD_AMOUNT: ContractErrorCode;
|
|
9
|
+
ENO_PERMISSIONS: ContractErrorCode;
|
|
10
|
+
EBADINPUT: ContractErrorCode;
|
|
11
|
+
ECLOSED: ContractErrorCode;
|
|
12
|
+
EBAD_INPUT_AMOUNT_PER_PERIOD: ContractErrorCode;
|
|
13
|
+
EBAD_INPUT_PAUSABLE: ContractErrorCode;
|
|
14
|
+
EBAD_INPUT_UPDATE_RATE: ContractErrorCode;
|
|
15
|
+
EBAD_INPUT_CLIFF_AMOUNT: ContractErrorCode;
|
|
16
|
+
EBAD_INPUT_PERIOD: ContractErrorCode;
|
|
17
|
+
EBAD_INPUT_START: ContractErrorCode;
|
|
18
|
+
EBAD_INSUFFICIENT_TOKEN_ALLOWANCE: ContractErrorCode;
|
|
19
|
+
EBAD_INSUFFICIENT_WITHDRAWAL_FEES: ContractErrorCode;
|
|
20
|
+
};
|
package/dist/evm/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.POLYGON_PROGRAM_IDS = exports.BNB_PROGRAM_IDS = exports.ETHEREUM_PROGRAM_IDS = void 0;
|
|
4
|
+
exports.EVM_ERROR_MAP = exports.EVM_ERROR_MATCH_REGEX = exports.POLYGON_PROGRAM_IDS = exports.BNB_PROGRAM_IDS = exports.ETHEREUM_PROGRAM_IDS = void 0;
|
|
5
5
|
var types_1 = require("../common/types");
|
|
6
6
|
exports.ETHEREUM_PROGRAM_IDS = (_a = {},
|
|
7
7
|
_a[types_1.ICluster.Mainnet] = "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
|
|
@@ -21,3 +21,19 @@ exports.POLYGON_PROGRAM_IDS = (_c = {},
|
|
|
21
21
|
_c[types_1.ICluster.Testnet] = "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
|
|
22
22
|
_c[types_1.ICluster.Local] = "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
|
|
23
23
|
_c);
|
|
24
|
+
exports.EVM_ERROR_MATCH_REGEX = /execution reverted: ([A-Z_]+)/;
|
|
25
|
+
exports.EVM_ERROR_MAP = {
|
|
26
|
+
ECONTRACT_NOT_INIT: types_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
27
|
+
EBAD_AMOUNT: types_1.ContractErrorCode.EBAD_AMOUNT,
|
|
28
|
+
ENO_PERMISSIONS: types_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
29
|
+
EBADINPUT: types_1.ContractErrorCode.EBADINPUT,
|
|
30
|
+
ECLOSED: types_1.ContractErrorCode.ECLOSED,
|
|
31
|
+
EBAD_INPUT_AMOUNT_PER_PERIOD: types_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
32
|
+
EBAD_INPUT_PAUSABLE: types_1.ContractErrorCode.EBAD_INPUT_PAUSABLE,
|
|
33
|
+
EBAD_INPUT_UPDATE_RATE: types_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
34
|
+
EBAD_INPUT_CLIFF_AMOUNT: types_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
35
|
+
EBAD_INPUT_PERIOD: types_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
36
|
+
EBAD_INPUT_START: types_1.ContractErrorCode.EBAD_INPUT_START,
|
|
37
|
+
EBAD_INSUFFICIENT_TOKEN_ALLOWANCE: types_1.ContractErrorCode.EBAD_INSUFFICIENT_TOKEN_ALLOWANCE,
|
|
38
|
+
EBAD_INSUFFICIENT_WITHDRAWAL_FEES: types_1.ContractErrorCode.EBAD_INSUFFICIENT_WITHDRAWAL_FEES,
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractEvmErrorCode(errorText: string): string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractEvmErrorCode = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
function extractEvmErrorCode(errorText) {
|
|
6
|
+
var match = constants_1.EVM_ERROR_MATCH_REGEX.exec(errorText);
|
|
7
|
+
if (!match) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return match[1];
|
|
11
|
+
}
|
|
12
|
+
exports.extractEvmErrorCode = extractEvmErrorCode;
|
|
@@ -64,6 +64,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
64
64
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
65
65
|
*/
|
|
66
66
|
update(data: IUpdateData, { invoker }: IInteractStreamSolanaExt): Promise<ITransactionResult>;
|
|
67
|
+
extractErrorCode(err: Error): string | null;
|
|
67
68
|
/**
|
|
68
69
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
69
70
|
*/
|
|
@@ -432,7 +432,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
432
432
|
signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.signature; })), false));
|
|
433
433
|
failures = responses
|
|
434
434
|
.filter(function (el) { return el.status === "rejected"; })
|
|
435
|
-
.map(function (el) { return el.reason; });
|
|
435
|
+
.map(function (el) { return (__assign(__assign({}, el.reason), { contractErrorCode: _this.extractErrorCode(el.reason.error) || undefined })); });
|
|
436
436
|
errors.push.apply(errors, __spreadArray([], __read(failures), false));
|
|
437
437
|
metadataIds = metadatas.map(function (pk) { return pk.publicKey.toBase58(); });
|
|
438
438
|
return [2 /*return*/, { txs: signatures, metadatas: metadataIds, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
@@ -835,6 +835,10 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
835
835
|
});
|
|
836
836
|
});
|
|
837
837
|
};
|
|
838
|
+
SolanaStreamClient.prototype.extractErrorCode = function (err) {
|
|
839
|
+
var _a;
|
|
840
|
+
return (0, utils_1.extractSolanaErrorCode)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
|
|
841
|
+
};
|
|
838
842
|
/**
|
|
839
843
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
840
844
|
*/
|
|
@@ -16,3 +16,7 @@ export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
|
|
|
16
16
|
export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
|
|
17
17
|
export declare const AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
18
18
|
export declare const AIRDROP_AMOUNT = 1;
|
|
19
|
+
export declare const SOLANA_ERROR_MATCH_REGEX: RegExp;
|
|
20
|
+
export declare const SOLANA_ERROR_MAP: {
|
|
21
|
+
[key: number]: string;
|
|
22
|
+
};
|
package/dist/solana/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
4
|
+
exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var types_1 = require("../common/types");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
@@ -22,3 +22,29 @@ exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2
|
|
|
22
22
|
exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
|
|
23
23
|
exports.AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
24
24
|
exports.AIRDROP_AMOUNT = 1; // 1 SOL is the cap on the testnet
|
|
25
|
+
exports.SOLANA_ERROR_MATCH_REGEX = /custom program error: (0x\d{2})/;
|
|
26
|
+
exports.SOLANA_ERROR_MAP = {
|
|
27
|
+
0x60: types_1.SolanaContractErrorCode.AccountsNotWritable,
|
|
28
|
+
0x61: types_1.SolanaContractErrorCode.InvalidMetadata,
|
|
29
|
+
0x62: types_1.SolanaContractErrorCode.InvalidMetadataAccount,
|
|
30
|
+
0x63: types_1.SolanaContractErrorCode.MetadataAccountMismatch,
|
|
31
|
+
0x64: types_1.SolanaContractErrorCode.InvalidEscrowAccount,
|
|
32
|
+
0x65: types_1.SolanaContractErrorCode.NotAssociated,
|
|
33
|
+
0x66: types_1.SolanaContractErrorCode.MintMismatch,
|
|
34
|
+
0x67: types_1.SolanaContractErrorCode.TransferNotAllowed,
|
|
35
|
+
0x68: types_1.SolanaContractErrorCode.ContractClosed,
|
|
36
|
+
0x69: types_1.SolanaContractErrorCode.InvalidTreasury,
|
|
37
|
+
0x70: types_1.SolanaContractErrorCode.InvalidTimestamps,
|
|
38
|
+
0x71: types_1.SolanaContractErrorCode.InvalidDepositConfiguration,
|
|
39
|
+
0x72: types_1.SolanaContractErrorCode.AmountIsZero,
|
|
40
|
+
0x73: types_1.SolanaContractErrorCode.AmountMoreThanAvailable,
|
|
41
|
+
0x74: types_1.SolanaContractErrorCode.AmountAvailableIsZero,
|
|
42
|
+
0x80: types_1.SolanaContractErrorCode.ArithmeticError,
|
|
43
|
+
0x81: types_1.SolanaContractErrorCode.InvalidMetadataSize,
|
|
44
|
+
0x82: types_1.SolanaContractErrorCode.UninitializedMetadata,
|
|
45
|
+
0x83: types_1.SolanaContractErrorCode.Unauthorized,
|
|
46
|
+
0x84: types_1.SolanaContractErrorCode.SelfTransfer,
|
|
47
|
+
0x85: types_1.SolanaContractErrorCode.AlreadyPaused,
|
|
48
|
+
0x86: types_1.SolanaContractErrorCode.NotPaused,
|
|
49
|
+
0x87: types_1.SolanaContractErrorCode.MetadataNotRentExempt,
|
|
50
|
+
};
|
package/dist/solana/utils.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const formatDecodedStream: (stream: DecodedStream) => Stream;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
|
|
17
17
|
/**
|
|
18
|
-
* Utility function to check if the transaction initiator is a
|
|
18
|
+
* Utility function to check if the transaction initiator is a Wallet object
|
|
19
19
|
* @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
20
20
|
* @return {boolean} - Returns true if parameter is a Wallet.
|
|
21
21
|
*/
|
|
@@ -41,3 +41,4 @@ export declare function sendAndConfirmStreamRawTransaction(connection: Connectio
|
|
|
41
41
|
* @return {Promise<PublicKey>} - Associated Token Address
|
|
42
42
|
*/
|
|
43
43
|
export declare function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
|
|
44
|
+
export declare function extractSolanaErrorCode(errorText: string): string | null;
|
package/dist/solana/utils.js
CHANGED
|
@@ -50,13 +50,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.isSignerWallet = exports.getProgramAccounts = exports.formatDecodedStream = exports.decodeStream = void 0;
|
|
53
|
+
exports.extractSolanaErrorCode = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.isSignerWallet = exports.getProgramAccounts = exports.formatDecodedStream = exports.decodeStream = void 0;
|
|
54
54
|
var spl_token_1 = require("@solana/spl-token");
|
|
55
55
|
var web3_js_1 = require("@solana/web3.js");
|
|
56
56
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
57
57
|
var bs58_1 = __importDefault(require("bs58"));
|
|
58
58
|
var layout_1 = require("./layout");
|
|
59
59
|
var contractUtils_1 = require("../common/contractUtils");
|
|
60
|
+
var constants_1 = require("./constants");
|
|
60
61
|
var decoder = new TextDecoder("utf-8");
|
|
61
62
|
var LE = "le"; //little endian
|
|
62
63
|
var decodeStream = function (buf) {
|
|
@@ -191,7 +192,7 @@ function getProgramAccounts(connection, wallet, offset, programId) {
|
|
|
191
192
|
}
|
|
192
193
|
exports.getProgramAccounts = getProgramAccounts;
|
|
193
194
|
/**
|
|
194
|
-
* Utility function to check if the transaction initiator is a
|
|
195
|
+
* Utility function to check if the transaction initiator is a Wallet object
|
|
195
196
|
* @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
196
197
|
* @return {boolean} - Returns true if parameter is a Wallet.
|
|
197
198
|
*/
|
|
@@ -199,6 +200,16 @@ function isSignerWallet(walletOrKeypair) {
|
|
|
199
200
|
return walletOrKeypair.signTransaction !== undefined;
|
|
200
201
|
}
|
|
201
202
|
exports.isSignerWallet = isSignerWallet;
|
|
203
|
+
/**
|
|
204
|
+
* Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
|
|
205
|
+
* @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
206
|
+
* @returns {boolean} - Returns true if parameter is a Keypair.
|
|
207
|
+
*/
|
|
208
|
+
function isSignerKeypair(walletOrKeypair) {
|
|
209
|
+
return (walletOrKeypair instanceof web3_js_1.Keypair ||
|
|
210
|
+
walletOrKeypair.constructor === web3_js_1.Keypair ||
|
|
211
|
+
walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
|
|
212
|
+
}
|
|
202
213
|
/**
|
|
203
214
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
204
215
|
* @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
|
|
@@ -211,7 +222,7 @@ function signAllTransactionWithRecipients(sender, items) {
|
|
|
211
222
|
return __generator(this, function (_a) {
|
|
212
223
|
switch (_a.label) {
|
|
213
224
|
case 0:
|
|
214
|
-
isKeypair = sender
|
|
225
|
+
isKeypair = isSignerKeypair(sender);
|
|
215
226
|
isWallet = isSignerWallet(sender);
|
|
216
227
|
if (!isKeypair) return [3 /*break*/, 1];
|
|
217
228
|
return [2 /*return*/, items.map(function (t) {
|
|
@@ -281,3 +292,12 @@ function ata(mint, owner) {
|
|
|
281
292
|
return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
|
|
282
293
|
}
|
|
283
294
|
exports.ata = ata;
|
|
295
|
+
function extractSolanaErrorCode(errorText) {
|
|
296
|
+
var match = constants_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
297
|
+
if (!match) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
var errorCode = Number(match[1]);
|
|
301
|
+
return constants_1.SOLANA_ERROR_MAP[errorCode] || null;
|
|
302
|
+
}
|
|
303
|
+
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
@@ -41,6 +41,7 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
41
41
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
42
42
|
*/
|
|
43
43
|
update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
|
|
44
|
+
extractErrorCode(err: Error): string | null;
|
|
44
45
|
/**
|
|
45
46
|
* Returns StreamClient protocol program ID.
|
|
46
47
|
*/
|
|
@@ -48,7 +49,7 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
48
49
|
/**
|
|
49
50
|
* Utility function to generate Transaction Block to create streams
|
|
50
51
|
*/
|
|
51
|
-
private
|
|
52
|
+
private generateCreateBlock;
|
|
52
53
|
/**
|
|
53
54
|
* Returns all coins owned by a Wallet
|
|
54
55
|
* @param walletAddress wallet address
|
package/dist/sui/StreamClient.js
CHANGED
|
@@ -99,6 +99,7 @@ var types_1 = require("../common/types");
|
|
|
99
99
|
var constants_1 = require("../common/constants");
|
|
100
100
|
var constants_2 = require("./constants");
|
|
101
101
|
var types_2 = require("./types");
|
|
102
|
+
var utils_2 = require("./utils");
|
|
102
103
|
var wallet_1 = require("./wallet");
|
|
103
104
|
var SuiStreamClient = /** @class */ (function (_super) {
|
|
104
105
|
__extends(SuiStreamClient, _super);
|
|
@@ -122,7 +123,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
122
123
|
switch (_d.label) {
|
|
123
124
|
case 0:
|
|
124
125
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
125
|
-
return [4 /*yield*/, this.
|
|
126
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }))];
|
|
126
127
|
case 1:
|
|
127
128
|
_b = __read.apply(void 0, [_d.sent(), 1]), txb = _b[0];
|
|
128
129
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
@@ -148,49 +149,63 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
148
149
|
var _b;
|
|
149
150
|
var senderWallet = _a.senderWallet;
|
|
150
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var wallet,
|
|
152
|
-
return __generator(this, function (
|
|
153
|
-
switch (
|
|
152
|
+
var wallet, _c, txb, firstIndex, txs, metadatas, metadataToRecipient, errors, _d, digest, events_1, effects_1, e_1, errorInfo_1;
|
|
153
|
+
return __generator(this, function (_e) {
|
|
154
|
+
switch (_e.label) {
|
|
154
155
|
case 0:
|
|
155
156
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
156
|
-
return [4 /*yield*/, this.
|
|
157
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, multipleStreamData)];
|
|
157
158
|
case 1:
|
|
158
|
-
|
|
159
|
+
_c = __read.apply(void 0, [_e.sent(), 2]), txb = _c[0], firstIndex = _c[1];
|
|
159
160
|
txs = [];
|
|
160
161
|
metadatas = [];
|
|
161
162
|
metadataToRecipient = {};
|
|
162
163
|
errors = [];
|
|
163
|
-
|
|
164
|
-
_d.label = 2;
|
|
164
|
+
_e.label = 2;
|
|
165
165
|
case 2:
|
|
166
|
-
|
|
167
|
-
txb = transactions[i];
|
|
168
|
-
recipient = multipleStreamData.recipients[i];
|
|
169
|
-
_d.label = 3;
|
|
170
|
-
case 3:
|
|
171
|
-
_d.trys.push([3, 5, , 6]);
|
|
166
|
+
_e.trys.push([2, 4, , 5]);
|
|
172
167
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
173
168
|
transactionBlock: txb,
|
|
174
|
-
options: { showEvents: true },
|
|
169
|
+
options: { showEffects: true, showEvents: true },
|
|
175
170
|
})];
|
|
176
|
-
case
|
|
177
|
-
|
|
171
|
+
case 3:
|
|
172
|
+
_d = _e.sent(), digest = _d.digest, events_1 = _d.events, effects_1 = _d.effects;
|
|
178
173
|
txs.push(digest);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
174
|
+
if (effects_1.status.status === "failure") {
|
|
175
|
+
multipleStreamData.recipients.forEach(function (recipient) {
|
|
176
|
+
var _a;
|
|
177
|
+
errors.push({
|
|
178
|
+
error: (_a = effects_1.status.error) !== null && _a !== void 0 ? _a : "Unknown error!",
|
|
179
|
+
recipient: recipient.recipient,
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
185
|
+
var metadataId = events_1[index].parsedJson.address;
|
|
186
|
+
metadatas.push(metadataId);
|
|
187
|
+
metadataToRecipient[metadataId] = recipient;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return [3 /*break*/, 5];
|
|
191
|
+
case 4:
|
|
192
|
+
e_1 = _e.sent();
|
|
193
|
+
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((_b = e_1.toString()) !== null && _b !== void 0 ? _b : "Unknown error!");
|
|
194
|
+
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
195
|
+
var _a;
|
|
196
|
+
if (errorInfo_1.index === undefined ||
|
|
197
|
+
errorInfo_1.index < index + firstIndex ||
|
|
198
|
+
errorInfo_1.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
199
|
+
errorInfo_1.index === index + firstIndex) {
|
|
200
|
+
errors.push({
|
|
201
|
+
error: errorInfo_1.text,
|
|
202
|
+
recipient: recipient.recipient,
|
|
203
|
+
contractErrorCode: (_a = errorInfo_1.parsed) === null || _a === void 0 ? void 0 : _a.name,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
188
206
|
});
|
|
189
|
-
return [3 /*break*/,
|
|
190
|
-
case
|
|
191
|
-
i++;
|
|
192
|
-
return [3 /*break*/, 2];
|
|
193
|
-
case 7: return [2 /*return*/, {
|
|
207
|
+
return [3 /*break*/, 5];
|
|
208
|
+
case 5: return [2 /*return*/, {
|
|
194
209
|
txs: txs,
|
|
195
210
|
metadatas: metadatas,
|
|
196
211
|
metadataToRecipient: metadataToRecipient,
|
|
@@ -418,6 +433,11 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
418
433
|
});
|
|
419
434
|
});
|
|
420
435
|
};
|
|
436
|
+
SuiStreamClient.prototype.extractErrorCode = function (err) {
|
|
437
|
+
var _a, _b;
|
|
438
|
+
var errorInfo = (0, utils_2.extractSuiErrorInfo)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
|
|
439
|
+
return ((_b = errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.parsed) === null || _b === void 0 ? void 0 : _b.name) || null;
|
|
440
|
+
};
|
|
421
441
|
/**
|
|
422
442
|
* Returns StreamClient protocol program ID.
|
|
423
443
|
*/
|
|
@@ -427,51 +447,57 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
427
447
|
/**
|
|
428
448
|
* Utility function to generate Transaction Block to create streams
|
|
429
449
|
*/
|
|
430
|
-
SuiStreamClient.prototype.
|
|
450
|
+
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData) {
|
|
431
451
|
return __awaiter(this, void 0, void 0, function () {
|
|
432
|
-
var coins;
|
|
452
|
+
var coins, totalAmount, txb, coinObject, firstIndex;
|
|
433
453
|
var _this = this;
|
|
434
454
|
return __generator(this, function (_a) {
|
|
435
455
|
switch (_a.label) {
|
|
436
456
|
case 0: return [4 /*yield*/, this.getAllCoins(walletAddress, multipleStreamData.tokenId)];
|
|
437
457
|
case 1:
|
|
438
458
|
coins = _a.sent();
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
})
|
|
459
|
+
totalAmount = multipleStreamData.recipients
|
|
460
|
+
.map(function (recipiient) { return recipiient.amount; })
|
|
461
|
+
.reduce(function (prev, current) { return current.add(prev); });
|
|
462
|
+
txb = new transactions_1.TransactionBlock();
|
|
463
|
+
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins);
|
|
464
|
+
coins = [coins[0]];
|
|
465
|
+
firstIndex = null;
|
|
466
|
+
multipleStreamData.recipients.forEach(function (recipient) {
|
|
467
|
+
var result = txb.moveCall({
|
|
468
|
+
target: "".concat(_this.programId, "::protocol::create"),
|
|
469
|
+
typeArguments: [multipleStreamData.tokenId],
|
|
470
|
+
arguments: [
|
|
471
|
+
txb.object(_this.configId),
|
|
472
|
+
txb.object(_this.feeTableId),
|
|
473
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
474
|
+
coinObject,
|
|
475
|
+
txb.gas,
|
|
476
|
+
txb.pure(recipient.amount.toString()),
|
|
477
|
+
txb.pure(multipleStreamData.period),
|
|
478
|
+
txb.pure(recipient.amountPerPeriod.toString()),
|
|
479
|
+
txb.pure(multipleStreamData.start),
|
|
480
|
+
txb.pure(recipient.cliffAmount.toString()),
|
|
481
|
+
txb.pure(multipleStreamData.cancelableBySender),
|
|
482
|
+
txb.pure(multipleStreamData.cancelableByRecipient),
|
|
483
|
+
txb.pure(multipleStreamData.transferableBySender),
|
|
484
|
+
txb.pure(multipleStreamData.transferableByRecipient),
|
|
485
|
+
txb.pure(multipleStreamData.canTopup),
|
|
486
|
+
txb.pure(!!multipleStreamData.canPause),
|
|
487
|
+
txb.pure(!!multipleStreamData.canUpdateRate),
|
|
488
|
+
txb.pure(!!multipleStreamData.automaticWithdrawal),
|
|
489
|
+
txb.pure(multipleStreamData.withdrawalFrequency || 0),
|
|
490
|
+
txb.pure(recipient.name),
|
|
491
|
+
txb.pure(recipient.recipient),
|
|
492
|
+
txb.pure(multipleStreamData.partner || walletAddress),
|
|
493
|
+
],
|
|
494
|
+
});
|
|
495
|
+
if (result.kind === "Result" && firstIndex === null) {
|
|
496
|
+
firstIndex = result.index;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
500
|
+
return [2 /*return*/, [txb, firstIndex]];
|
|
475
501
|
}
|
|
476
502
|
});
|
|
477
503
|
});
|
package/dist/sui/constants.d.ts
CHANGED
|
@@ -2,3 +2,9 @@ import { ICluster } from "../common/types";
|
|
|
2
2
|
export declare const SUI_PROGRAM_IDS: Record<ICluster, string>;
|
|
3
3
|
export declare const SUI_CONFIG_IDS: Record<ICluster, string>;
|
|
4
4
|
export declare const SUI_FEE_TABLE_IDS: Record<ICluster, string>;
|
|
5
|
+
export declare const SUI_ERROR_MATCH_REGEX: RegExp;
|
|
6
|
+
export declare const SUI_MODULE_ERROR_MAP: {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
[key: number]: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
package/dist/sui/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
4
|
+
exports.SUI_MODULE_ERROR_MAP = exports.SUI_ERROR_MATCH_REGEX = exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
5
5
|
var types_1 = require("../common/types");
|
|
6
6
|
// TODO: remove Devnet and Local addresses as they are not deployed, they are just a copy Testnet values
|
|
7
7
|
exports.SUI_PROGRAM_IDS = (_a = {},
|
|
@@ -22,3 +22,22 @@ exports.SUI_FEE_TABLE_IDS = (_c = {},
|
|
|
22
22
|
_c[types_1.ICluster.Testnet] = "0xf3661941207b5027fb4b85a74ca5a9fd1389fb57a8f2c57bd312b950e7d48012",
|
|
23
23
|
_c[types_1.ICluster.Local] = "0xf3661941207b5027fb4b85a74ca5a9fd1389fb57a8f2c57bd312b950e7d48012",
|
|
24
24
|
_c);
|
|
25
|
+
exports.SUI_ERROR_MATCH_REGEX = /MoveAbort\(MoveLocation \{ module: ModuleId \{ address: (\w+), name: Identifier\("([\w_]+)"\) }, function: \d+, instruction: \d+, function_name: Some\("([\w_]+)"\) }, (\d+)\) in command (\d+)/;
|
|
26
|
+
exports.SUI_MODULE_ERROR_MAP = {
|
|
27
|
+
protocol: {
|
|
28
|
+
1: types_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
29
|
+
2: types_1.ContractErrorCode.EBAD_AMOUNT,
|
|
30
|
+
3: types_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
31
|
+
4: types_1.ContractErrorCode.EBADINPUT,
|
|
32
|
+
5: types_1.ContractErrorCode.ECLOSED,
|
|
33
|
+
6: types_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
34
|
+
8: types_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
35
|
+
9: types_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
36
|
+
10: types_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
37
|
+
11: types_1.ContractErrorCode.EBAD_INPUT_START,
|
|
38
|
+
13: types_1.ContractErrorCode.EBAD_INSUFFICIENT_WITHDRAWAL_FEES,
|
|
39
|
+
14: types_1.ContractErrorCode.EBAD_INSUFFICIENT_AMOUNT,
|
|
40
|
+
15: types_1.ContractErrorCode.EPAUSED,
|
|
41
|
+
16: types_1.ContractErrorCode.ENOTPAUSED,
|
|
42
|
+
},
|
|
43
|
+
};
|
package/dist/sui/types.d.ts
CHANGED
|
@@ -124,6 +124,16 @@ export declare class Contract implements Stream {
|
|
|
124
124
|
unlocked(currentTimestamp: number): BN;
|
|
125
125
|
remaining(decimals: number): number;
|
|
126
126
|
}
|
|
127
|
+
export interface SuiParsedError {
|
|
128
|
+
module: "protocol" | "admin" | "fee_manager";
|
|
129
|
+
code: number;
|
|
130
|
+
name: string;
|
|
131
|
+
}
|
|
132
|
+
export interface SuiErrorInfo {
|
|
133
|
+
index?: number;
|
|
134
|
+
text: string;
|
|
135
|
+
parsed?: SuiParsedError;
|
|
136
|
+
}
|
|
127
137
|
export interface SuiSignAndExecuteTransactionBlockInput {
|
|
128
138
|
transactionBlock: TransactionBlock;
|
|
129
139
|
requestType?: ExecuteTransactionRequestType;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSuiErrorInfo = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
function extractSuiErrorInfo(errorText) {
|
|
6
|
+
var error = { text: errorText };
|
|
7
|
+
var match = constants_1.SUI_ERROR_MATCH_REGEX.exec(errorText);
|
|
8
|
+
if (!match) {
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
|
+
var moduleName = match[2];
|
|
12
|
+
var errorCode = Number(match[4]);
|
|
13
|
+
var errorName = constants_1.SUI_MODULE_ERROR_MAP[moduleName]
|
|
14
|
+
? constants_1.SUI_MODULE_ERROR_MAP[moduleName][errorCode]
|
|
15
|
+
: undefined;
|
|
16
|
+
var index = Number(match[5]);
|
|
17
|
+
if (index) {
|
|
18
|
+
error.index = index;
|
|
19
|
+
}
|
|
20
|
+
if (errorName) {
|
|
21
|
+
error.parsed = {
|
|
22
|
+
module: moduleName,
|
|
23
|
+
code: errorCode,
|
|
24
|
+
name: errorName,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
exports.extractSuiErrorInfo = extractSuiErrorInfo;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
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
9
|
"build": "rm -rf ./dist && tsc --outDir ./dist --project ../../tsconfig.json",
|
|
10
|
+
"build-docs": "typedoc ./index.ts",
|
|
10
11
|
"test": "jest .",
|
|
11
12
|
"lint": "eslint .",
|
|
12
|
-
"prepublishOnly": "npm
|
|
13
|
+
"prepublishOnly": "npm test && npm run build-docs && npm run build"
|
|
13
14
|
},
|
|
14
15
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
15
16
|
"devDependencies": {
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"@solana/spl-token": "0.3.6",
|
|
36
37
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
37
38
|
"@solana/web3.js": "1.70.1",
|
|
38
|
-
"@suiet/wallet-kit": "
|
|
39
|
+
"@suiet/wallet-kit": "0.2.18",
|
|
39
40
|
"aptos": "1.4.0",
|
|
40
41
|
"bn.js": "5.2.1",
|
|
41
42
|
"bs58": "5.0.0",
|