@streamflow/common 7.0.0-alpha.1 → 7.0.0-alpha.10
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/solana/instructions.js +18 -88
- 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/cjs/utils.js +28 -78
- package/dist/esm/solana/instructions.d.ts +2 -2
- package/dist/esm/solana/types.d.ts +4 -0
- package/dist/esm/solana/utils.js +5 -4
- package/dist/esm/utils.d.ts +9 -9
- package/dist/esm/utils.js +12 -15
- package/package.json +7 -8
package/dist/cjs/types.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
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.ContractError = exports.IChain = exports.ICluster = void 0;
|
|
19
4
|
// Utility types
|
|
@@ -36,23 +21,20 @@ var IChain;
|
|
|
36
21
|
/**
|
|
37
22
|
* Error wrapper for calls made to the contract on chain
|
|
38
23
|
*/
|
|
39
|
-
|
|
40
|
-
__extends(ContractError, _super);
|
|
24
|
+
class ContractError extends Error {
|
|
41
25
|
/**
|
|
42
26
|
* Constructs the Error Wrapper
|
|
43
27
|
* @param error Original error raised probably by the chain SDK
|
|
44
28
|
* @param code extracted code from the error if managed to parse it
|
|
45
29
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
constructor(error, code, description) {
|
|
31
|
+
super(error.message); // Call the base class constructor with the error message
|
|
32
|
+
this.contractErrorCode = code ?? null;
|
|
33
|
+
this.description = description ?? null;
|
|
50
34
|
// Copy properties from the original error
|
|
51
|
-
Object.setPrototypeOf(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return _this;
|
|
35
|
+
Object.setPrototypeOf(this, ContractError.prototype);
|
|
36
|
+
this.name = "ContractError"; // Set the name property
|
|
37
|
+
this.stack = error.stack;
|
|
55
38
|
}
|
|
56
|
-
|
|
57
|
-
}(Error));
|
|
39
|
+
}
|
|
58
40
|
exports.ContractError = ContractError;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,100 +1,50 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.sleep = exports.handleContractError = exports.
|
|
43
|
-
|
|
44
|
-
|
|
6
|
+
exports.sleep = exports.handleContractError = exports.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
45
9
|
/**
|
|
46
|
-
* Used for
|
|
47
|
-
* Get
|
|
48
|
-
* @param {
|
|
10
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
11
|
+
* Get value in the highest units from BigNumber representation of the same value in the smallest units.
|
|
12
|
+
* @param {BigNumber} value - Big Number representation of value in the smallest units.
|
|
49
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
50
14
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var integerPart = new bn_js_1.default(Math.trunc(value));
|
|
54
|
-
var decimalE = new bn_js_1.default(decimalPart * 1e9);
|
|
55
|
-
var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
|
|
56
|
-
var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
|
|
57
|
-
return resultE.div(new bn_js_1.default(1e9));
|
|
15
|
+
const getNumberFromBigNumber = (bigNum, decimals) => {
|
|
16
|
+
return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
|
|
58
17
|
};
|
|
59
|
-
exports.
|
|
18
|
+
exports.getNumberFromBigNumber = getNumberFromBigNumber;
|
|
60
19
|
/**
|
|
61
|
-
* Used for token amounts
|
|
62
|
-
* Get
|
|
63
|
-
* @param {
|
|
20
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
21
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
22
|
+
* @param {number} value - Number of tokens you want to convert to its BigNumber representation.
|
|
64
23
|
* @param {number} decimals - Number of decimals the token has.
|
|
65
24
|
*/
|
|
66
|
-
|
|
67
|
-
return
|
|
25
|
+
const getScaledBigNumber = (value, decimals) => {
|
|
26
|
+
return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
|
|
68
27
|
};
|
|
69
|
-
exports.
|
|
28
|
+
exports.getScaledBigNumber = getScaledBigNumber;
|
|
70
29
|
/**
|
|
71
30
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
72
31
|
* @param func function that interacts with the contract
|
|
73
32
|
* @param callback callback that may be used to extract error code
|
|
74
33
|
* @returns {T}
|
|
75
34
|
*/
|
|
76
|
-
function handleContractError(func, callback) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
85
|
-
case 2:
|
|
86
|
-
err_1 = _a.sent();
|
|
87
|
-
if (err_1 instanceof Error) {
|
|
88
|
-
if (callback) {
|
|
89
|
-
throw new types_js_1.ContractError(err_1, callback(err_1));
|
|
90
|
-
}
|
|
91
|
-
throw new types_js_1.ContractError(err_1);
|
|
92
|
-
}
|
|
93
|
-
throw err_1;
|
|
94
|
-
case 3: return [2 /*return*/];
|
|
35
|
+
async function handleContractError(func, callback) {
|
|
36
|
+
try {
|
|
37
|
+
return await func();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (err instanceof Error) {
|
|
41
|
+
if (callback) {
|
|
42
|
+
throw new types_js_1.ContractError(err, callback(err));
|
|
95
43
|
}
|
|
96
|
-
|
|
97
|
-
|
|
44
|
+
throw new types_js_1.ContractError(err);
|
|
45
|
+
}
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
98
48
|
}
|
|
99
49
|
exports.handleContractError = handleContractError;
|
|
100
50
|
/**
|
|
@@ -102,6 +52,6 @@ exports.handleContractError = handleContractError;
|
|
|
102
52
|
* @param ms millisecond to sleep for
|
|
103
53
|
*/
|
|
104
54
|
function sleep(ms) {
|
|
105
|
-
return new Promise(
|
|
55
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
106
56
|
}
|
|
107
57
|
exports.sleep = sleep;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import
|
|
3
|
-
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount:
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BigNumber) => Promise<TransactionInstruction[]>;
|
|
@@ -30,6 +30,10 @@ export interface ThrottleParams {
|
|
|
30
30
|
sendRate?: number;
|
|
31
31
|
sendThrottler?: PQueue;
|
|
32
32
|
}
|
|
33
|
+
export interface IProgramAccount<T> {
|
|
34
|
+
publicKey: PublicKey;
|
|
35
|
+
account: T;
|
|
36
|
+
}
|
|
33
37
|
export declare class TransactionFailedError extends Error {
|
|
34
38
|
constructor(m: string);
|
|
35
39
|
}
|
package/dist/esm/solana/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ export const buildSendThrottler = (sendRate) => {
|
|
|
17
17
|
* @return {Promise<Account[]>} - Array of resulting accounts.
|
|
18
18
|
*/
|
|
19
19
|
export async function getProgramAccounts(connection, wallet, offset, programId) {
|
|
20
|
-
|
|
20
|
+
const programAccounts = await connection?.getProgramAccounts(programId, {
|
|
21
21
|
filters: [
|
|
22
22
|
{
|
|
23
23
|
memcmp: {
|
|
@@ -27,6 +27,7 @@ export async function getProgramAccounts(connection, wallet, offset, programId)
|
|
|
27
27
|
},
|
|
28
28
|
],
|
|
29
29
|
});
|
|
30
|
+
return [...programAccounts];
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Utility function to check if the transaction initiator is a Wallet object
|
|
@@ -243,11 +244,11 @@ export async function simulateTransaction(connection, tx) {
|
|
|
243
244
|
* @returns Transaction Status
|
|
244
245
|
*/
|
|
245
246
|
export async function confirmAndEnsureTransaction(connection, signature, ignoreError) {
|
|
246
|
-
const response = await connection.
|
|
247
|
-
if (!response) {
|
|
247
|
+
const response = await connection.getSignatureStatuses([signature]);
|
|
248
|
+
if (!response || response.value.length === 0 || response.value[0] === null) {
|
|
248
249
|
return null;
|
|
249
250
|
}
|
|
250
|
-
const
|
|
251
|
+
const value = response.value[0];
|
|
251
252
|
if (!value) {
|
|
252
253
|
return null;
|
|
253
254
|
}
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
/**
|
|
3
|
-
* Used for
|
|
4
|
-
* Get
|
|
5
|
-
* @param {
|
|
3
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
4
|
+
* Get value in the highest units from BigNumber representation of the same value in the smallest units.
|
|
5
|
+
* @param {BigNumber} value - Big Number representation of value in the smallest units.
|
|
6
6
|
* @param {number} decimals - Number of decimals the token has.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const getNumberFromBigNumber: (bigNum: BigNumber, decimals: number) => number;
|
|
9
9
|
/**
|
|
10
|
-
* Used for token amounts
|
|
11
|
-
* Get
|
|
12
|
-
* @param {
|
|
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 BigNumber representation.
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const getScaledBigNumber: (value: number | string | BigNumber, decimals: number) => BigNumber;
|
|
16
16
|
/**
|
|
17
17
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
18
18
|
* @param func function that interacts with the contract
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
2
|
import { ContractError } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
* Used for
|
|
5
|
-
* Get
|
|
6
|
-
* @param {
|
|
4
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
5
|
+
* Get value in the highest units from BigNumber representation of the same value in the smallest units.
|
|
6
|
+
* @param {BigNumber} value - Big Number representation of value in the smallest units.
|
|
7
7
|
* @param {number} decimals - Number of decimals the token has.
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
const integerPart = new BN(Math.trunc(value));
|
|
12
|
-
const decimalE = new BN(decimalPart * 1e9);
|
|
13
|
-
const sum = integerPart.mul(new BN(1e9)).add(decimalE);
|
|
14
|
-
const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
|
|
15
|
-
return resultE.div(new BN(1e9));
|
|
9
|
+
export const getNumberFromBigNumber = (bigNum, decimals) => {
|
|
10
|
+
return bigNum.div(BigNumber(10).pow(decimals)).toNumber();
|
|
16
11
|
};
|
|
17
12
|
/**
|
|
18
|
-
* Used for token amounts
|
|
19
|
-
* Get
|
|
20
|
-
* @param {
|
|
13
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
14
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
15
|
+
* @param {number} value - Number of tokens you want to convert to its BigNumber representation.
|
|
21
16
|
* @param {number} decimals - Number of decimals the token has.
|
|
22
17
|
*/
|
|
23
|
-
export const
|
|
18
|
+
export const getScaledBigNumber = (value, decimals) => {
|
|
19
|
+
return new BigNumber(value).times(new BigNumber(10).pow(decimals));
|
|
20
|
+
};
|
|
24
21
|
/**
|
|
25
22
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
26
23
|
* @param func function that interacts with the contract
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.10",
|
|
4
4
|
"description": "Common utilities and types used by streamflow packages.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -27,21 +27,20 @@
|
|
|
27
27
|
"lint-config": "eslint --print-config",
|
|
28
28
|
"prepublishOnly": "npm run lint && npm run build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "263638b9fd29395dcb64c33dfc2197df47f526af",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@streamflow/eslint-config": "7.0.0-alpha.
|
|
33
|
-
"@types/bn.js": "5.1.1",
|
|
32
|
+
"@streamflow/eslint-config": "7.0.0-alpha.10",
|
|
34
33
|
"date-fns": "2.28.0",
|
|
35
34
|
"typescript": "^4.9.5"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@coral-xyz/borsh": "
|
|
37
|
+
"@coral-xyz/borsh": "0.30.1",
|
|
39
38
|
"@solana/buffer-layout": "4.0.1 ",
|
|
40
39
|
"@solana/spl-token": "0.3.6",
|
|
41
40
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
42
|
-
"@solana/web3.js": "1.
|
|
43
|
-
"aptos": "1.
|
|
44
|
-
"
|
|
41
|
+
"@solana/web3.js": "1.90.2",
|
|
42
|
+
"aptos": "1.21.0",
|
|
43
|
+
"bignumber.js": "^9.1.2",
|
|
45
44
|
"borsh": "^2.0.0",
|
|
46
45
|
"bs58": "5.0.0",
|
|
47
46
|
"p-queue": "^8.0.1"
|