@streamflow/common 7.0.0-alpha.2 → 7.0.0-alpha.20
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/cjs/index.js +2 -1
- package/dist/cjs/lib/assertions.js +13 -0
- package/dist/cjs/lib/utils.js +62 -0
- package/dist/cjs/solana/account-filters.js +19 -0
- package/dist/cjs/solana/index.js +2 -0
- package/dist/cjs/solana/instructions.js +18 -88
- package/dist/cjs/solana/public-key.js +8 -0
- package/dist/cjs/solana/types.js +6 -24
- package/dist/cjs/solana/utils.js +233 -513
- package/dist/cjs/types.js +9 -27
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/lib/assertions.d.ts +1 -0
- package/dist/esm/lib/assertions.js +9 -0
- package/dist/esm/{utils.d.ts → lib/utils.d.ts} +10 -9
- package/dist/esm/{utils.js → lib/utils.js} +17 -13
- package/dist/esm/solana/account-filters.d.ts +2 -0
- package/dist/esm/solana/account-filters.js +15 -0
- package/dist/esm/solana/index.d.ts +2 -0
- package/dist/esm/solana/index.js +2 -0
- package/dist/esm/solana/instructions.d.ts +2 -2
- package/dist/esm/solana/public-key.d.ts +2 -0
- package/dist/esm/solana/public-key.js +4 -0
- package/dist/esm/solana/types.d.ts +4 -0
- package/dist/esm/solana/utils.js +6 -5
- package/package.json +8 -7
- package/dist/cjs/utils.js +0 -102
package/dist/cjs/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types.js"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./lib/assertions.js"), exports);
|
|
19
|
+
__exportStar(require("./lib/utils.js"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.invariant = void 0;
|
|
4
|
+
const prefix = "Assertion failed";
|
|
5
|
+
const invariant = (condition, message) => {
|
|
6
|
+
if (condition) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const provided = typeof message === "function" ? message() : message;
|
|
10
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
11
|
+
throw new Error(value);
|
|
12
|
+
};
|
|
13
|
+
exports.invariant = invariant;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.divCeilN = exports.sleep = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const types_js_1 = require("../types.js");
|
|
9
|
+
/**
|
|
10
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
11
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
12
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
13
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
14
|
+
*/
|
|
15
|
+
const getBN = (value, decimals) => {
|
|
16
|
+
const decimalPart = value - Math.trunc(value);
|
|
17
|
+
const integerPart = new bn_js_1.default(Math.trunc(value));
|
|
18
|
+
const decimalE = new bn_js_1.default(decimalPart * 1e9);
|
|
19
|
+
const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
|
|
20
|
+
const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
|
|
21
|
+
return resultE.div(new bn_js_1.default(1e9));
|
|
22
|
+
};
|
|
23
|
+
exports.getBN = getBN;
|
|
24
|
+
/**
|
|
25
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
26
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
27
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
28
|
+
* @param {number} decimals - Number of decimals the token has.
|
|
29
|
+
*/
|
|
30
|
+
const getNumberFromBN = (value, decimals) => value.gt(new bn_js_1.default(2 ** 53 - 1)) ? value.div(new bn_js_1.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
|
|
31
|
+
exports.getNumberFromBN = getNumberFromBN;
|
|
32
|
+
/**
|
|
33
|
+
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
34
|
+
* @param func function that interacts with the contract
|
|
35
|
+
* @param callback callback that may be used to extract error code
|
|
36
|
+
* @returns {T}
|
|
37
|
+
*/
|
|
38
|
+
async function handleContractError(func, callback) {
|
|
39
|
+
try {
|
|
40
|
+
return await func();
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (err instanceof Error) {
|
|
44
|
+
if (callback) {
|
|
45
|
+
throw new types_js_1.ContractError(err, callback(err));
|
|
46
|
+
}
|
|
47
|
+
throw new types_js_1.ContractError(err);
|
|
48
|
+
}
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.handleContractError = handleContractError;
|
|
53
|
+
/**
|
|
54
|
+
* Pause async function execution for given amount of milliseconds
|
|
55
|
+
* @param ms millisecond to sleep for
|
|
56
|
+
*/
|
|
57
|
+
function sleep(ms) {
|
|
58
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
59
|
+
}
|
|
60
|
+
exports.sleep = sleep;
|
|
61
|
+
const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
|
|
62
|
+
exports.divCeilN = divCeilN;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilters = void 0;
|
|
4
|
+
const getFilters = (criteria, byteOffsets) => {
|
|
5
|
+
return Object.entries(criteria).reduce((acc, [key, value]) => {
|
|
6
|
+
const criteriaKey = key;
|
|
7
|
+
const effectiveByteOffset = byteOffsets[criteriaKey];
|
|
8
|
+
if (criteria[criteriaKey] && effectiveByteOffset) {
|
|
9
|
+
acc.push({
|
|
10
|
+
memcmp: {
|
|
11
|
+
offset: effectiveByteOffset,
|
|
12
|
+
bytes: value.toString(),
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}, []);
|
|
18
|
+
};
|
|
19
|
+
exports.getFilters = getFilters;
|
package/dist/cjs/solana/index.js
CHANGED
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./account-filters.js"), exports);
|
|
17
18
|
__exportStar(require("./instructions.js"), exports);
|
|
19
|
+
__exportStar(require("./public-key.js"), exports);
|
|
18
20
|
__exportStar(require("./types.js"), exports);
|
|
19
21
|
__exportStar(require("./utils.js"), exports);
|
|
@@ -1,92 +1,22 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
-
};
|
|
38
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
3
|
exports.prepareWrappedAccount = void 0;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
fromPubkey: senderAddress,
|
|
84
|
-
toPubkey: tokenAccount,
|
|
85
|
-
lamports: amount.toNumber(),
|
|
86
|
-
}),
|
|
87
|
-
(0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
|
|
88
|
-
], false)];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}); };
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const prepareWrappedAccount = async (connection, senderAddress, amount) => {
|
|
7
|
+
const tokenAccount = await (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, senderAddress, true);
|
|
8
|
+
const accInfo = await connection.getParsedAccountInfo(tokenAccount);
|
|
9
|
+
const instructions = (accInfo.value?.lamports ?? 0) > 0
|
|
10
|
+
? []
|
|
11
|
+
: [(0, spl_token_1.createAssociatedTokenAccountInstruction)(senderAddress, tokenAccount, senderAddress, spl_token_1.NATIVE_MINT)];
|
|
12
|
+
return [
|
|
13
|
+
...instructions,
|
|
14
|
+
web3_js_1.SystemProgram.transfer({
|
|
15
|
+
fromPubkey: senderAddress,
|
|
16
|
+
toPubkey: tokenAccount,
|
|
17
|
+
lamports: amount.toNumber(),
|
|
18
|
+
}),
|
|
19
|
+
(0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
|
|
20
|
+
];
|
|
21
|
+
};
|
|
92
22
|
exports.prepareWrappedAccount = prepareWrappedAccount;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pk = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const pk = (address) => {
|
|
6
|
+
return typeof address === "string" ? new web3_js_1.PublicKey(address) : address;
|
|
7
|
+
};
|
|
8
|
+
exports.pk = pk;
|
package/dist/cjs/solana/types.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.TransactionFailedError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_this.name = "TransactionFailedError";
|
|
25
|
-
return _this;
|
|
4
|
+
class TransactionFailedError extends Error {
|
|
5
|
+
constructor(m) {
|
|
6
|
+
super(m);
|
|
7
|
+
Object.setPrototypeOf(this, TransactionFailedError.prototype);
|
|
8
|
+
this.name = "TransactionFailedError";
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
}(Error));
|
|
10
|
+
}
|
|
29
11
|
exports.TransactionFailedError = TransactionFailedError;
|