@streamflow/stream 5.9.10 → 5.10.1
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/index.d.ts +2 -0
- package/dist/aptos/index.js +15 -1
- package/dist/common/BaseStreamClient.d.ts +9 -2
- package/dist/common/BaseStreamClient.js +58 -0
- package/dist/common/utils.d.ts +10 -0
- package/dist/common/utils.js +18 -1
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.js +15 -1
- package/dist/solana/StreamClient.d.ts +0 -1
- package/dist/solana/StreamClient.js +31 -60
- package/dist/solana/instructions.js +1 -6
- package/dist/solana/types.d.ts +4 -0
- package/dist/solana/utils.d.ts +45 -3
- package/dist/solana/utils.js +187 -1
- package/dist/sui/StreamClient.js +50 -41
- package/dist/sui/index.d.ts +2 -0
- package/dist/sui/index.js +15 -1
- package/package.json +3 -3
package/dist/aptos/index.d.ts
CHANGED
package/dist/aptos/index.js
CHANGED
|
@@ -10,15 +10,29 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
30
|
};
|
|
19
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AptosStreamClient = exports.default = void 0;
|
|
32
|
+
exports.constants = exports.AptosStreamClient = exports.default = void 0;
|
|
21
33
|
var StreamClient_1 = require("./StreamClient");
|
|
22
34
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
23
35
|
Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
36
|
+
__exportStar(require("./utils"), exports);
|
|
24
37
|
__exportStar(require("./types"), exports);
|
|
38
|
+
exports.constants = __importStar(require("./constants"));
|
|
@@ -9,7 +9,14 @@ export declare abstract class BaseStreamClient {
|
|
|
9
9
|
abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
|
|
10
10
|
abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>;
|
|
11
11
|
abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
12
|
-
abstract getFees(getFeesData: IGetFeesData, chainSpecificParams
|
|
13
|
-
abstract getDefaultStreamflowFee(chainSpecificParams
|
|
12
|
+
abstract getFees(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<IFees | null>;
|
|
13
|
+
abstract getDefaultStreamflowFee(chainSpecificParams?: any): Promise<number>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns total fee percent, streamflow fees + partner fees
|
|
16
|
+
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
17
|
+
* @param chainSpecificParams additional parameters required by chain client
|
|
18
|
+
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
19
|
+
*/
|
|
20
|
+
getTotalFee(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<number>;
|
|
14
21
|
extractErrorCode(err: Error): string | null;
|
|
15
22
|
}
|
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.BaseStreamClient = void 0;
|
|
4
40
|
var BaseStreamClient = /** @class */ (function () {
|
|
5
41
|
function BaseStreamClient() {
|
|
6
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns total fee percent, streamflow fees + partner fees
|
|
45
|
+
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
46
|
+
* @param chainSpecificParams additional parameters required by chain client
|
|
47
|
+
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
48
|
+
*/
|
|
49
|
+
BaseStreamClient.prototype.getTotalFee = function (getFeesData, chainSpecificParams) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var fees;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, this.getFees(getFeesData, chainSpecificParams)];
|
|
55
|
+
case 1:
|
|
56
|
+
fees = _a.sent();
|
|
57
|
+
if (fees) {
|
|
58
|
+
return [2 /*return*/, fees.partnerFee + fees.streamflowFee];
|
|
59
|
+
}
|
|
60
|
+
return [2 /*return*/, this.getDefaultStreamflowFee(chainSpecificParams)];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
7
65
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
66
|
BaseStreamClient.prototype.extractErrorCode = function (err) {
|
|
9
67
|
return null;
|
package/dist/common/utils.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ export declare const getBN: (value: number, decimals: number) => BN;
|
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
15
|
export declare const getNumberFromBN: (value: BN, decimals: number) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate total amount of a Contract including all fees.
|
|
18
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
19
|
+
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
20
|
+
* to receive a total number and not percentage of depositedAmount
|
|
21
|
+
* @param depositedAmount deposited raw tokens
|
|
22
|
+
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
23
|
+
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
24
|
+
*/
|
|
25
|
+
export declare const calculateTotalAmountToDeposit: (depositedAmount: BN, totalFee: number) => BN;
|
|
16
26
|
/**
|
|
17
27
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
18
28
|
* @param func function that interacts with the contract
|
package/dist/common/utils.js
CHANGED
|
@@ -39,9 +39,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.normalizeAptosAddress = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
|
|
42
|
+
exports.normalizeAptosAddress = exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
|
|
43
43
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
44
44
|
var types_1 = require("./types");
|
|
45
|
+
var FEE_PRECISION = 4;
|
|
46
|
+
var FEE_NORMALIZER = Math.pow(10, FEE_PRECISION);
|
|
47
|
+
var FEE_MULTIPLIER = new bn_js_1.default(Math.pow(10, 6));
|
|
45
48
|
/**
|
|
46
49
|
* Used for conversion of token amounts to their Big Number representation.
|
|
47
50
|
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
@@ -69,6 +72,20 @@ var getNumberFromBN = function (value, decimals) {
|
|
|
69
72
|
: value.toNumber() / Math.pow(10, decimals);
|
|
70
73
|
};
|
|
71
74
|
exports.getNumberFromBN = getNumberFromBN;
|
|
75
|
+
/**
|
|
76
|
+
* Calculate total amount of a Contract including all fees.
|
|
77
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
78
|
+
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
79
|
+
* to receive a total number and not percentage of depositedAmount
|
|
80
|
+
* @param depositedAmount deposited raw tokens
|
|
81
|
+
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
82
|
+
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
83
|
+
*/
|
|
84
|
+
var calculateTotalAmountToDeposit = function (depositedAmount, totalFee) {
|
|
85
|
+
var totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
|
|
86
|
+
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
87
|
+
};
|
|
88
|
+
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
72
89
|
/**
|
|
73
90
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
74
91
|
* @param func function that interacts with the contract
|
package/dist/evm/index.d.ts
CHANGED
package/dist/evm/index.js
CHANGED
|
@@ -10,15 +10,29 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
30
|
};
|
|
19
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.EvmStreamClient = exports.default = void 0;
|
|
32
|
+
exports.constants = exports.EvmStreamClient = exports.default = void 0;
|
|
21
33
|
var StreamClient_1 = require("./StreamClient");
|
|
22
34
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
23
35
|
Object.defineProperty(exports, "EvmStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
36
|
+
__exportStar(require("./utils"), exports);
|
|
24
37
|
__exportStar(require("./types"), exports);
|
|
38
|
+
exports.constants = __importStar(require("./constants"));
|
|
@@ -59,7 +59,6 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
59
59
|
* Streams are sorted by start time in ascending order.
|
|
60
60
|
*/
|
|
61
61
|
get({ address, type, direction, }: IGetAllData): Promise<[string, Stream][]>;
|
|
62
|
-
private sign;
|
|
63
62
|
/**
|
|
64
63
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
65
64
|
*/
|
|
@@ -127,7 +127,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
127
127
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
128
128
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
129
129
|
var buffer_1 = require("buffer");
|
|
130
|
-
var bs58_1 = __importDefault(require("bs58"));
|
|
131
130
|
var spl_token_1 = require("@solana/spl-token");
|
|
132
131
|
var web3_js_1 = require("@solana/web3.js");
|
|
133
132
|
var spl_token_2 = require("@solana/spl-token");
|
|
@@ -138,6 +137,7 @@ var constants_1 = require("./constants");
|
|
|
138
137
|
var instructions_1 = require("./instructions");
|
|
139
138
|
var types_2 = require("../common/types");
|
|
140
139
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
140
|
+
var utils_2 = require("../common/utils");
|
|
141
141
|
var METADATA_ACC_SIZE = 1104;
|
|
142
142
|
var SolanaStreamClient = /** @class */ (function (_super) {
|
|
143
143
|
__extends(SolanaStreamClient, _super);
|
|
@@ -169,10 +169,10 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
169
169
|
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
170
170
|
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
171
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
-
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens,
|
|
173
|
-
var
|
|
174
|
-
return __generator(this, function (
|
|
175
|
-
switch (
|
|
172
|
+
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l, commitment, hash, tx, signature;
|
|
173
|
+
var _m;
|
|
174
|
+
return __generator(this, function (_o) {
|
|
175
|
+
switch (_o.label) {
|
|
176
176
|
case 0:
|
|
177
177
|
if (!sender.publicKey) {
|
|
178
178
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -184,27 +184,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
184
184
|
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
185
185
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
186
186
|
case 1:
|
|
187
|
-
senderTokens =
|
|
187
|
+
senderTokens = _o.sent();
|
|
188
188
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
189
189
|
case 2:
|
|
190
|
-
recipientTokens =
|
|
190
|
+
recipientTokens = _o.sent();
|
|
191
191
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
192
192
|
case 3:
|
|
193
|
-
streamflowTreasuryTokens =
|
|
193
|
+
streamflowTreasuryTokens = _o.sent();
|
|
194
194
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
195
195
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
196
196
|
case 4:
|
|
197
|
-
partnerTokens =
|
|
198
|
-
if (!isNative) return [3 /*break*/,
|
|
199
|
-
return [4 /*yield*/, (0
|
|
197
|
+
partnerTokens = _o.sent();
|
|
198
|
+
if (!isNative) return [3 /*break*/, 7];
|
|
199
|
+
return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
200
200
|
case 5:
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
totalFee = _o.sent();
|
|
202
|
+
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
203
|
+
_j = (_h = ixs.push).apply;
|
|
204
|
+
_k = [ixs];
|
|
205
|
+
_l = [[]];
|
|
206
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
203
207
|
case 6:
|
|
204
|
-
_h
|
|
205
|
-
|
|
208
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_o.sent())]), false]))]));
|
|
209
|
+
_o.label = 7;
|
|
206
210
|
case 7:
|
|
207
|
-
nativeInstructions = _h;
|
|
208
211
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
209
212
|
start: new bn_js_1.default(start),
|
|
210
213
|
depositedAmount: depositedAmount,
|
|
@@ -243,18 +246,18 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
243
246
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
244
247
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
245
248
|
case 8:
|
|
246
|
-
hash =
|
|
247
|
-
tx = (
|
|
249
|
+
hash = _o.sent();
|
|
250
|
+
tx = (_m = new web3_js_1.Transaction({
|
|
248
251
|
feePayer: sender.publicKey,
|
|
249
252
|
blockhash: hash.blockhash,
|
|
250
253
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
251
|
-
})).add.apply(
|
|
254
|
+
})).add.apply(_m, __spreadArray([], __read(ixs), false));
|
|
252
255
|
if (metadata) {
|
|
253
256
|
tx.partialSign(metadata);
|
|
254
257
|
}
|
|
255
|
-
return [4 /*yield*/, this.
|
|
258
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
256
259
|
case 9:
|
|
257
|
-
signature =
|
|
260
|
+
signature = _o.sent();
|
|
258
261
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
259
262
|
}
|
|
260
263
|
});
|
|
@@ -353,7 +356,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
353
356
|
if (metadata) {
|
|
354
357
|
tx.partialSign(metadata);
|
|
355
358
|
}
|
|
356
|
-
return [4 /*yield*/, this.
|
|
359
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
357
360
|
case 7:
|
|
358
361
|
signature = _k.sent();
|
|
359
362
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
@@ -546,7 +549,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
546
549
|
blockhash: hash.blockhash,
|
|
547
550
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
548
551
|
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
549
|
-
return [4 /*yield*/, this.
|
|
552
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
550
553
|
case 6:
|
|
551
554
|
signature = _d.sent();
|
|
552
555
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
@@ -611,7 +614,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
611
614
|
blockhash: hash.blockhash,
|
|
612
615
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
613
616
|
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
614
|
-
return [4 /*yield*/, this.
|
|
617
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
615
618
|
case 6:
|
|
616
619
|
signature = _d.sent();
|
|
617
620
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
@@ -669,7 +672,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
669
672
|
blockhash: hash.blockhash,
|
|
670
673
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
671
674
|
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
672
|
-
return [4 /*yield*/, this.
|
|
675
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
673
676
|
case 4:
|
|
674
677
|
signature = _d.sent();
|
|
675
678
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
@@ -740,7 +743,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
740
743
|
blockhash: hash.blockhash,
|
|
741
744
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
742
745
|
})).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
743
|
-
return [4 /*yield*/, this.
|
|
746
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
744
747
|
case 8:
|
|
745
748
|
signature = _f.sent();
|
|
746
749
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
@@ -815,38 +818,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
815
818
|
});
|
|
816
819
|
});
|
|
817
820
|
};
|
|
818
|
-
SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
|
|
819
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
820
|
-
var signedTx, rawTx, confirmationStrategy, signature;
|
|
821
|
-
return __generator(this, function (_a) {
|
|
822
|
-
switch (_a.label) {
|
|
823
|
-
case 0:
|
|
824
|
-
if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
|
|
825
|
-
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
826
|
-
case 1:
|
|
827
|
-
signedTx = _a.sent();
|
|
828
|
-
return [3 /*break*/, 3];
|
|
829
|
-
case 2:
|
|
830
|
-
tx.partialSign(invoker);
|
|
831
|
-
signedTx = tx;
|
|
832
|
-
_a.label = 3;
|
|
833
|
-
case 3:
|
|
834
|
-
rawTx = signedTx.serialize();
|
|
835
|
-
if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
|
|
836
|
-
throw Error("Error with transaction parameters.");
|
|
837
|
-
confirmationStrategy = {
|
|
838
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
839
|
-
signature: bs58_1.default.encode(signedTx.signature),
|
|
840
|
-
blockhash: hash.blockhash,
|
|
841
|
-
};
|
|
842
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
|
|
843
|
-
case 4:
|
|
844
|
-
signature = _a.sent();
|
|
845
|
-
return [2 /*return*/, signature];
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
};
|
|
850
821
|
/**
|
|
851
822
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
852
823
|
*/
|
|
@@ -882,7 +853,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
882
853
|
blockhash: hash.blockhash,
|
|
883
854
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
884
855
|
}).add(updateIx);
|
|
885
|
-
return [4 /*yield*/, this.
|
|
856
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
886
857
|
case 3:
|
|
887
858
|
signature = _b.sent();
|
|
888
859
|
return [2 /*return*/, {
|
|
@@ -1047,7 +1018,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1047
1018
|
response = _b.sent();
|
|
1048
1019
|
for (i = 0; i < response.length; i++) {
|
|
1049
1020
|
if (!response[i]) {
|
|
1050
|
-
ixs.push((0, spl_token_2.createAssociatedTokenAccountInstruction)(invoker.publicKey, accountArrays[i][1], accountArrays[i][0], data.mint
|
|
1021
|
+
ixs.push((0, spl_token_2.createAssociatedTokenAccountInstruction)(invoker.publicKey, accountArrays[i][1], accountArrays[i][0], data.mint));
|
|
1051
1022
|
}
|
|
1052
1023
|
}
|
|
1053
1024
|
return [2 /*return*/];
|
|
@@ -83,18 +83,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
83
83
|
}
|
|
84
84
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
85
|
};
|
|
86
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
-
};
|
|
89
86
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
87
|
exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
91
88
|
var buffer_1 = require("buffer");
|
|
92
89
|
var web3_js_1 = require("@solana/web3.js");
|
|
93
|
-
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
90
|
var js_sha256_1 = require("js-sha256");
|
|
95
91
|
var spl_token_1 = require("@solana/spl-token");
|
|
96
92
|
var Layout = __importStar(require("./layout"));
|
|
97
|
-
var constants_1 = require("../common/constants");
|
|
98
93
|
var createStreamInstruction = function (data, programId, accounts) {
|
|
99
94
|
var keys = [
|
|
100
95
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
@@ -397,7 +392,7 @@ var prepareWrappedAccount = function (connection, senderAddress, amount) { retur
|
|
|
397
392
|
web3_js_1.SystemProgram.transfer({
|
|
398
393
|
fromPubkey: senderAddress,
|
|
399
394
|
toPubkey: tokenAccount,
|
|
400
|
-
lamports: amount.
|
|
395
|
+
lamports: amount.toNumber(),
|
|
401
396
|
}),
|
|
402
397
|
(0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
|
|
403
398
|
], false)];
|
package/dist/solana/types.d.ts
CHANGED
|
@@ -302,4 +302,8 @@ export interface BatchItemSuccess extends BatchItem {
|
|
|
302
302
|
export interface BatchItemError extends BatchItem {
|
|
303
303
|
error: string;
|
|
304
304
|
}
|
|
305
|
+
export interface AtaParams {
|
|
306
|
+
mint: PublicKey;
|
|
307
|
+
owner: PublicKey;
|
|
308
|
+
}
|
|
305
309
|
export declare type BatchItemResult = BatchItemSuccess | BatchItemError;
|
package/dist/solana/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
3
|
-
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
4
|
-
import { DecodedStream, Account, BatchItem, BatchItemResult } from "./types";
|
|
3
|
+
import { Connection, Keypair, PublicKey, Transaction, BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
|
|
4
|
+
import { AtaParams, DecodedStream, Account, BatchItem, BatchItemResult } from "./types";
|
|
5
5
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
6
6
|
/**
|
|
7
7
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
@@ -17,7 +17,14 @@ export declare function getProgramAccounts(connection: Connection, wallet: Publi
|
|
|
17
17
|
* @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
18
18
|
* @return {boolean} - Returns true if parameter is a Wallet.
|
|
19
19
|
*/
|
|
20
|
-
export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter):
|
|
20
|
+
export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
|
|
21
|
+
/**
|
|
22
|
+
* Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
|
|
23
|
+
* @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
24
|
+
* @returns {boolean} - Returns true if parameter is a Keypair.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
|
|
27
|
+
export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
|
|
21
28
|
/**
|
|
22
29
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
23
30
|
* @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
|
|
@@ -25,6 +32,15 @@ export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAd
|
|
|
25
32
|
* @return {BatchItem[]} - Returns items with signatures.
|
|
26
33
|
*/
|
|
27
34
|
export declare function signAllTransactionWithRecipients(sender: Keypair | SignerWalletAdapter, items: BatchItem[]): Promise<BatchItem[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Signs, sends and confirms Transaction
|
|
37
|
+
* @param connection - Solana client connection
|
|
38
|
+
* @param invoker - Keypair used as signer
|
|
39
|
+
* @param tx - Transaction instance
|
|
40
|
+
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
41
|
+
* @returns Transaction signature
|
|
42
|
+
*/
|
|
43
|
+
export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
|
|
28
44
|
/**
|
|
29
45
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
30
46
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -39,4 +55,30 @@ export declare function sendAndConfirmStreamRawTransaction(connection: Connectio
|
|
|
39
55
|
* @return {Promise<PublicKey>} - Associated Token Address
|
|
40
56
|
*/
|
|
41
57
|
export declare function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
|
|
58
|
+
/**
|
|
59
|
+
* Function that checks whether ATA exists for each provided owner
|
|
60
|
+
* @param connection - Solana client connection
|
|
61
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
62
|
+
* @returns Array of boolean where each members corresponds to owners member
|
|
63
|
+
*/
|
|
64
|
+
export declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a Transaction to create ATA for an array of owners
|
|
67
|
+
* @param connection - Solana client connection
|
|
68
|
+
* @param payer - Transaction invoker, should be a signer
|
|
69
|
+
* @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
|
|
70
|
+
* @returns Unsigned Transaction with create ATA instructions
|
|
71
|
+
*/
|
|
72
|
+
export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[]): Promise<{
|
|
73
|
+
tx: Transaction;
|
|
74
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates ATA for an array of owners
|
|
78
|
+
* @param connection - Solana client connection
|
|
79
|
+
* @param invoker - Transaction invoker and payer
|
|
80
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
81
|
+
* @returns Transaction signature
|
|
82
|
+
*/
|
|
83
|
+
export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[]): Promise<string>;
|
|
42
84
|
export declare function extractSolanaErrorCode(errorText: string): string | null;
|
package/dist/solana/utils.js
CHANGED
|
@@ -46,11 +46,36 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
49
74
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
75
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
76
|
};
|
|
52
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.extractSolanaErrorCode = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.isSignerWallet = exports.getProgramAccounts = exports.decodeStream = void 0;
|
|
78
|
+
exports.extractSolanaErrorCode = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAndExecuteTransaction = exports.signAllTransactionWithRecipients = exports.signTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = exports.decodeStream = void 0;
|
|
54
79
|
var spl_token_1 = require("@solana/spl-token");
|
|
55
80
|
var web3_js_1 = require("@solana/web3.js");
|
|
56
81
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -151,6 +176,28 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
151
176
|
walletOrKeypair.constructor === web3_js_1.Keypair ||
|
|
152
177
|
walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
|
|
153
178
|
}
|
|
179
|
+
exports.isSignerKeypair = isSignerKeypair;
|
|
180
|
+
function signTransaction(invoker, tx) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
+
var signedTx;
|
|
183
|
+
return __generator(this, function (_a) {
|
|
184
|
+
switch (_a.label) {
|
|
185
|
+
case 0:
|
|
186
|
+
if (!isSignerWallet(invoker)) return [3 /*break*/, 2];
|
|
187
|
+
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
188
|
+
case 1:
|
|
189
|
+
signedTx = _a.sent();
|
|
190
|
+
return [3 /*break*/, 3];
|
|
191
|
+
case 2:
|
|
192
|
+
tx.partialSign(invoker);
|
|
193
|
+
signedTx = tx;
|
|
194
|
+
_a.label = 3;
|
|
195
|
+
case 3: return [2 /*return*/, signedTx];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
exports.signTransaction = signTransaction;
|
|
154
201
|
/**
|
|
155
202
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
156
203
|
* @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
|
|
@@ -184,6 +231,39 @@ function signAllTransactionWithRecipients(sender, items) {
|
|
|
184
231
|
});
|
|
185
232
|
}
|
|
186
233
|
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
234
|
+
/**
|
|
235
|
+
* Signs, sends and confirms Transaction
|
|
236
|
+
* @param connection - Solana client connection
|
|
237
|
+
* @param invoker - Keypair used as signer
|
|
238
|
+
* @param tx - Transaction instance
|
|
239
|
+
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
240
|
+
* @returns Transaction signature
|
|
241
|
+
*/
|
|
242
|
+
function signAndExecuteTransaction(connection, invoker, tx, hash) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
+
var signedTx, rawTx, confirmationStrategy, signature;
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
|
|
248
|
+
case 1:
|
|
249
|
+
signedTx = _a.sent();
|
|
250
|
+
rawTx = signedTx.serialize();
|
|
251
|
+
if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
|
|
252
|
+
throw Error("Error with transaction parameters.");
|
|
253
|
+
confirmationStrategy = {
|
|
254
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
255
|
+
signature: bs58_1.default.encode(signedTx.signature),
|
|
256
|
+
blockhash: hash.blockhash,
|
|
257
|
+
};
|
|
258
|
+
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
|
|
259
|
+
case 2:
|
|
260
|
+
signature = _a.sent();
|
|
261
|
+
return [2 /*return*/, signature];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
exports.signAndExecuteTransaction = signAndExecuteTransaction;
|
|
187
267
|
/**
|
|
188
268
|
* Sign passed BatchItems with wallet request or KeyPair
|
|
189
269
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -233,6 +313,112 @@ function ata(mint, owner) {
|
|
|
233
313
|
return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
|
|
234
314
|
}
|
|
235
315
|
exports.ata = ata;
|
|
316
|
+
/**
|
|
317
|
+
* Function that checks whether ATA exists for each provided owner
|
|
318
|
+
* @param connection - Solana client connection
|
|
319
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
320
|
+
* @returns Array of boolean where each members corresponds to owners member
|
|
321
|
+
*/
|
|
322
|
+
function ataBatchExist(connection, paramsBatch) {
|
|
323
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
324
|
+
var tokenAccounts, response;
|
|
325
|
+
var _this = this;
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
|
|
329
|
+
var mint = _a.mint, owner = _a.owner;
|
|
330
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
331
|
+
var pubkey;
|
|
332
|
+
return __generator(this, function (_b) {
|
|
333
|
+
switch (_b.label) {
|
|
334
|
+
case 0: return [4 /*yield*/, ata(mint, owner)];
|
|
335
|
+
case 1:
|
|
336
|
+
pubkey = _b.sent();
|
|
337
|
+
return [2 /*return*/, pubkey];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}))];
|
|
342
|
+
case 1:
|
|
343
|
+
tokenAccounts = _a.sent();
|
|
344
|
+
return [4 /*yield*/, connection.getMultipleAccountsInfo(tokenAccounts)];
|
|
345
|
+
case 2:
|
|
346
|
+
response = _a.sent();
|
|
347
|
+
return [2 /*return*/, response.map(function (accInfo) { return !!accInfo; })];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
exports.ataBatchExist = ataBatchExist;
|
|
353
|
+
/**
|
|
354
|
+
* Generates a Transaction to create ATA for an array of owners
|
|
355
|
+
* @param connection - Solana client connection
|
|
356
|
+
* @param payer - Transaction invoker, should be a signer
|
|
357
|
+
* @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
|
|
358
|
+
* @returns Unsigned Transaction with create ATA instructions
|
|
359
|
+
*/
|
|
360
|
+
function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
+
var ixs, hash, tx;
|
|
363
|
+
var _a;
|
|
364
|
+
var _this = this;
|
|
365
|
+
return __generator(this, function (_b) {
|
|
366
|
+
switch (_b.label) {
|
|
367
|
+
case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
|
|
368
|
+
var mint = _a.mint, owner = _a.owner;
|
|
369
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
370
|
+
var _b, _c;
|
|
371
|
+
return __generator(this, function (_d) {
|
|
372
|
+
switch (_d.label) {
|
|
373
|
+
case 0:
|
|
374
|
+
_b = spl_token_1.createAssociatedTokenAccountInstruction;
|
|
375
|
+
_c = [payer];
|
|
376
|
+
return [4 /*yield*/, ata(mint, owner)];
|
|
377
|
+
case 1: return [2 /*return*/, _b.apply(void 0, _c.concat([_d.sent(), owner, mint]))];
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}))];
|
|
382
|
+
case 1:
|
|
383
|
+
ixs = _b.sent();
|
|
384
|
+
return [4 /*yield*/, connection.getLatestBlockhash()];
|
|
385
|
+
case 2:
|
|
386
|
+
hash = _b.sent();
|
|
387
|
+
tx = (_a = new web3_js_1.Transaction({
|
|
388
|
+
feePayer: payer,
|
|
389
|
+
blockhash: hash.blockhash,
|
|
390
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
391
|
+
})).add.apply(_a, __spreadArray([], __read(ixs), false));
|
|
392
|
+
return [2 /*return*/, { tx: tx, hash: hash }];
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|
|
398
|
+
/**
|
|
399
|
+
* Creates ATA for an array of owners
|
|
400
|
+
* @param connection - Solana client connection
|
|
401
|
+
* @param invoker - Transaction invoker and payer
|
|
402
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
403
|
+
* @returns Transaction signature
|
|
404
|
+
*/
|
|
405
|
+
function createAtaBatch(connection, invoker, paramsBatch) {
|
|
406
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
407
|
+
var _a, tx, hash, signature;
|
|
408
|
+
return __generator(this, function (_b) {
|
|
409
|
+
switch (_b.label) {
|
|
410
|
+
case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
|
|
411
|
+
case 1:
|
|
412
|
+
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
413
|
+
return [4 /*yield*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
|
|
414
|
+
case 2:
|
|
415
|
+
signature = _b.sent();
|
|
416
|
+
return [2 /*return*/, signature];
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
exports.createAtaBatch = createAtaBatch;
|
|
236
422
|
function extractSolanaErrorCode(errorText) {
|
|
237
423
|
var match = constants_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
|
|
238
424
|
if (!match) {
|
package/dist/sui/StreamClient.js
CHANGED
|
@@ -86,29 +86,25 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
86
86
|
}
|
|
87
87
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
88
88
|
};
|
|
89
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
90
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
91
|
-
};
|
|
92
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
-
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
90
|
var client_1 = require("@mysten/sui.js/client");
|
|
95
91
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
96
92
|
var utils_1 = require("@mysten/sui.js/utils");
|
|
97
93
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
98
94
|
var types_1 = require("../common/types");
|
|
99
|
-
var constants_1 = require("
|
|
100
|
-
var constants_2 = require("./constants");
|
|
95
|
+
var constants_1 = require("./constants");
|
|
101
96
|
var types_2 = require("./types");
|
|
102
97
|
var utils_2 = require("./utils");
|
|
103
98
|
var wallet_1 = require("./wallet");
|
|
99
|
+
var utils_3 = require("../common/utils");
|
|
104
100
|
var SuiStreamClient = /** @class */ (function (_super) {
|
|
105
101
|
__extends(SuiStreamClient, _super);
|
|
106
102
|
function SuiStreamClient(clusterUrl, cluster, ids) {
|
|
107
103
|
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
108
104
|
var _this = _super.call(this) || this;
|
|
109
|
-
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program :
|
|
110
|
-
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config :
|
|
111
|
-
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable :
|
|
105
|
+
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program : constants_1.SUI_PROGRAM_IDS[cluster];
|
|
106
|
+
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config : constants_1.SUI_CONFIG_IDS[cluster];
|
|
107
|
+
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_1.SUI_FEE_TABLE_IDS[cluster];
|
|
112
108
|
_this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
113
109
|
return _this;
|
|
114
110
|
}
|
|
@@ -116,22 +112,26 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
116
112
|
* Creates a new stream/vesting contract.
|
|
117
113
|
*/
|
|
118
114
|
SuiStreamClient.prototype.create = function (streamData, _a) {
|
|
115
|
+
var _b;
|
|
119
116
|
var senderWallet = _a.senderWallet;
|
|
120
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var wallet,
|
|
122
|
-
return __generator(this, function (
|
|
123
|
-
switch (
|
|
118
|
+
var wallet, totalFee, _c, txb, _d, digest, events;
|
|
119
|
+
return __generator(this, function (_e) {
|
|
120
|
+
switch (_e.label) {
|
|
124
121
|
case 0:
|
|
125
122
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
126
|
-
return [4 /*yield*/, this.
|
|
123
|
+
return [4 /*yield*/, this.getTotalFee({ address: (_b = streamData.partner) !== null && _b !== void 0 ? _b : wallet.address })];
|
|
127
124
|
case 1:
|
|
128
|
-
|
|
125
|
+
totalFee = _e.sent();
|
|
126
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }), totalFee)];
|
|
127
|
+
case 2:
|
|
128
|
+
_c = __read.apply(void 0, [_e.sent(), 1]), txb = _c[0];
|
|
129
129
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
130
130
|
transactionBlock: txb,
|
|
131
131
|
options: { showEvents: true },
|
|
132
132
|
})];
|
|
133
|
-
case
|
|
134
|
-
|
|
133
|
+
case 3:
|
|
134
|
+
_d = _e.sent(), digest = _d.digest, events = _d.events;
|
|
135
135
|
return [2 /*return*/, {
|
|
136
136
|
ixs: [],
|
|
137
137
|
txId: digest,
|
|
@@ -146,30 +146,35 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
146
146
|
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
147
147
|
*/
|
|
148
148
|
SuiStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
149
|
-
var _b;
|
|
149
|
+
var _b, _c;
|
|
150
150
|
var senderWallet = _a.senderWallet;
|
|
151
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var wallet,
|
|
153
|
-
return __generator(this, function (
|
|
154
|
-
switch (
|
|
152
|
+
var wallet, totalFee, _d, txb, firstIndex, txs, metadatas, metadataToRecipient, errors, _e, digest, events_1, effects_1, e_1, errorInfo_1;
|
|
153
|
+
return __generator(this, function (_f) {
|
|
154
|
+
switch (_f.label) {
|
|
155
155
|
case 0:
|
|
156
156
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
157
|
-
return [4 /*yield*/, this.
|
|
157
|
+
return [4 /*yield*/, this.getTotalFee({
|
|
158
|
+
address: (_b = multipleStreamData.partner) !== null && _b !== void 0 ? _b : wallet.address,
|
|
159
|
+
})];
|
|
158
160
|
case 1:
|
|
159
|
-
|
|
161
|
+
totalFee = _f.sent();
|
|
162
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, multipleStreamData, totalFee)];
|
|
163
|
+
case 2:
|
|
164
|
+
_d = __read.apply(void 0, [_f.sent(), 2]), txb = _d[0], firstIndex = _d[1];
|
|
160
165
|
txs = [];
|
|
161
166
|
metadatas = [];
|
|
162
167
|
metadataToRecipient = {};
|
|
163
168
|
errors = [];
|
|
164
|
-
|
|
165
|
-
case
|
|
166
|
-
|
|
169
|
+
_f.label = 3;
|
|
170
|
+
case 3:
|
|
171
|
+
_f.trys.push([3, 5, , 6]);
|
|
167
172
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
168
173
|
transactionBlock: txb,
|
|
169
174
|
options: { showEffects: true, showEvents: true },
|
|
170
175
|
})];
|
|
171
|
-
case
|
|
172
|
-
|
|
176
|
+
case 4:
|
|
177
|
+
_e = _f.sent(), digest = _e.digest, events_1 = _e.events, effects_1 = _e.effects;
|
|
173
178
|
txs.push(digest);
|
|
174
179
|
if (effects_1.status.status === "failure") {
|
|
175
180
|
multipleStreamData.recipients.forEach(function (recipient) {
|
|
@@ -187,10 +192,10 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
187
192
|
metadataToRecipient[metadataId] = recipient;
|
|
188
193
|
});
|
|
189
194
|
}
|
|
190
|
-
return [3 /*break*/,
|
|
191
|
-
case
|
|
192
|
-
e_1 =
|
|
193
|
-
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((
|
|
195
|
+
return [3 /*break*/, 6];
|
|
196
|
+
case 5:
|
|
197
|
+
e_1 = _f.sent();
|
|
198
|
+
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((_c = e_1.toString()) !== null && _c !== void 0 ? _c : "Unknown error!");
|
|
194
199
|
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
195
200
|
var _a;
|
|
196
201
|
if (errorInfo_1.index === undefined ||
|
|
@@ -204,8 +209,8 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
204
209
|
});
|
|
205
210
|
}
|
|
206
211
|
});
|
|
207
|
-
return [3 /*break*/,
|
|
208
|
-
case
|
|
212
|
+
return [3 /*break*/, 6];
|
|
213
|
+
case 6: return [2 /*return*/, {
|
|
209
214
|
txs: txs,
|
|
210
215
|
metadatas: metadatas,
|
|
211
216
|
metadataToRecipient: metadataToRecipient,
|
|
@@ -320,7 +325,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
320
325
|
SuiStreamClient.prototype.topup = function (topupData, _a) {
|
|
321
326
|
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
322
327
|
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
-
var wallet, txb, coins, coinObject, digest;
|
|
328
|
+
var wallet, txb, coins, stream, totalFee, coinObject, digest;
|
|
324
329
|
return __generator(this, function (_b) {
|
|
325
330
|
switch (_b.label) {
|
|
326
331
|
case 0:
|
|
@@ -329,7 +334,11 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
329
334
|
return [4 /*yield*/, this.getAllCoins(wallet.address, tokenId)];
|
|
330
335
|
case 1:
|
|
331
336
|
coins = _b.sent();
|
|
332
|
-
|
|
337
|
+
return [4 /*yield*/, this.getOne({ id: topupData.id })];
|
|
338
|
+
case 2:
|
|
339
|
+
stream = _b.sent();
|
|
340
|
+
totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
341
|
+
coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
|
|
333
342
|
txb.moveCall({
|
|
334
343
|
target: "".concat(this.programId, "::protocol::topup"),
|
|
335
344
|
typeArguments: [tokenId],
|
|
@@ -345,7 +354,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
345
354
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
346
355
|
transactionBlock: txb,
|
|
347
356
|
})];
|
|
348
|
-
case
|
|
357
|
+
case 3:
|
|
349
358
|
digest = (_b.sent()).digest;
|
|
350
359
|
return [2 /*return*/, {
|
|
351
360
|
ixs: [],
|
|
@@ -519,7 +528,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
519
528
|
/**
|
|
520
529
|
* Utility function to generate Transaction Block to create streams
|
|
521
530
|
*/
|
|
522
|
-
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData) {
|
|
531
|
+
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData, totalFee) {
|
|
523
532
|
return __awaiter(this, void 0, void 0, function () {
|
|
524
533
|
var coins, totalAmount, txb, coinObject, firstIndex;
|
|
525
534
|
var _this = this;
|
|
@@ -532,7 +541,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
532
541
|
.map(function (recipiient) { return recipiient.amount; })
|
|
533
542
|
.reduce(function (prev, current) { return current.add(prev); });
|
|
534
543
|
txb = new transactions_1.TransactionBlock();
|
|
535
|
-
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins);
|
|
544
|
+
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
536
545
|
coins = [coins[0]];
|
|
537
546
|
firstIndex = null;
|
|
538
547
|
multipleStreamData.recipients.forEach(function (recipient) {
|
|
@@ -619,13 +628,13 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
619
628
|
* @param coins array of owned coins of the same type
|
|
620
629
|
* @returns Coin Object to use in a Move Call
|
|
621
630
|
*/
|
|
622
|
-
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins) {
|
|
631
|
+
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins, totalFee) {
|
|
623
632
|
var coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
624
633
|
if (coins.length > 1) {
|
|
625
634
|
txb.mergeCoins(coinObject, coins.slice(1).map(function (item) { return txb.object(item.coinObjectId); }));
|
|
626
635
|
}
|
|
627
|
-
var
|
|
628
|
-
return txb.splitCoins(coinObject, [txb.pure(
|
|
636
|
+
var totalAmount = (0, utils_3.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
637
|
+
return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
|
|
629
638
|
};
|
|
630
639
|
/**
|
|
631
640
|
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
package/dist/sui/index.d.ts
CHANGED
package/dist/sui/index.js
CHANGED
|
@@ -10,14 +10,28 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
30
|
};
|
|
19
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.SuiStreamClient = void 0;
|
|
32
|
+
exports.constants = exports.SuiStreamClient = void 0;
|
|
21
33
|
var StreamClient_1 = require("./StreamClient");
|
|
22
34
|
Object.defineProperty(exports, "SuiStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
35
|
+
__exportStar(require("./utils"), exports);
|
|
23
36
|
__exportStar(require("./types"), exports);
|
|
37
|
+
exports.constants = __importStar(require("./constants"));
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.1",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rm -rf dist; tsc -p tsconfig.json",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lint": "eslint .",
|
|
12
12
|
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "1cf6009bd62ccc6d141f45caa14ee58ae4a541d9",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
17
|
"@types/ethereum-checksum-address": "^0.0.0",
|