@streamflow/common 7.0.0-alpha.11 → 7.0.0-alpha.13
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/{utils.js → lib/utils.js} +21 -16
- package/dist/cjs/solana/account-filters.js +19 -0
- package/dist/cjs/solana/index.js +2 -0
- package/dist/cjs/solana/public-key.js +8 -0
- package/dist/cjs/solana/utils.js +1 -1
- 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/utils.js +1 -1
- package/package.json +5 -4
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;
|
|
@@ -3,29 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sleep = exports.handleContractError = exports.
|
|
7
|
-
const
|
|
8
|
-
const types_js_1 = require("
|
|
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
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 BN representation.
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
16
|
-
|
|
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));
|
|
17
22
|
};
|
|
18
|
-
exports.
|
|
23
|
+
exports.getBN = getBN;
|
|
19
24
|
/**
|
|
20
|
-
* Used for
|
|
21
|
-
* Get
|
|
22
|
-
* @param {
|
|
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.
|
|
23
28
|
* @param {number} decimals - Number of decimals the token has.
|
|
24
29
|
*/
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
exports.getScaledBigNumber = getScaledBigNumber;
|
|
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;
|
|
29
32
|
/**
|
|
30
33
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
31
34
|
* @param func function that interacts with the contract
|
|
@@ -55,3 +58,5 @@ function sleep(ms) {
|
|
|
55
58
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
59
|
}
|
|
57
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);
|
|
@@ -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/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const bs58_1 = __importDefault(require("bs58"));
|
|
10
10
|
const p_queue_1 = __importDefault(require("p-queue"));
|
|
11
11
|
const types_js_1 = require("./types.js");
|
|
12
|
-
const utils_js_1 = require("../utils.js");
|
|
12
|
+
const utils_js_1 = require("../lib/utils.js");
|
|
13
13
|
const SIMULATE_TRIES = 3;
|
|
14
14
|
const buildSendThrottler = (sendRate) => {
|
|
15
15
|
return new p_queue_1.default({ concurrency: sendRate, intervalCap: 1, interval: 1000 });
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const invariant: (condition: any, message?: string | (() => string)) => asserts condition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const prefix = "Assertion failed";
|
|
2
|
+
export const invariant = (condition, message) => {
|
|
3
|
+
if (condition) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const provided = typeof message === "function" ? message() : message;
|
|
7
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
8
|
+
throw new Error(value);
|
|
9
|
+
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
/**
|
|
3
|
-
* Used for token amounts
|
|
4
|
-
* Get
|
|
5
|
-
* @param {
|
|
3
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
4
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
5
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
6
6
|
* @param {number} decimals - Number of decimals the token has.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const getBN: (value: number, decimals: number) => BN;
|
|
9
9
|
/**
|
|
10
|
-
* Used for
|
|
11
|
-
* Get
|
|
12
|
-
* @param {
|
|
10
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
11
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
12
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const getNumberFromBN: (value: BN, decimals: number) => number;
|
|
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
|
|
@@ -25,3 +25,4 @@ export declare function handleContractError<T>(func: () => Promise<T>, callback?
|
|
|
25
25
|
* @param ms millisecond to sleep for
|
|
26
26
|
*/
|
|
27
27
|
export declare function sleep(ms: number): Promise<void>;
|
|
28
|
+
export declare const divCeilN: (n: bigint, d: bigint) => bigint;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ContractError } from "
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { ContractError } from "../types.js";
|
|
3
3
|
/**
|
|
4
|
-
* Used for token amounts
|
|
5
|
-
* Get
|
|
6
|
-
* @param {
|
|
4
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
5
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
6
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
7
7
|
* @param {number} decimals - Number of decimals the token has.
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
10
|
-
|
|
9
|
+
export const getBN = (value, decimals) => {
|
|
10
|
+
const decimalPart = value - Math.trunc(value);
|
|
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));
|
|
11
16
|
};
|
|
12
17
|
/**
|
|
13
|
-
* Used for
|
|
14
|
-
* Get
|
|
15
|
-
* @param {
|
|
18
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
19
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
20
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
16
21
|
* @param {number} decimals - Number of decimals the token has.
|
|
17
22
|
*/
|
|
18
|
-
export const
|
|
19
|
-
return new BigNumber(value).times(new BigNumber(10).pow(decimals));
|
|
20
|
-
};
|
|
23
|
+
export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
|
|
21
24
|
/**
|
|
22
25
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
23
26
|
* @param func function that interacts with the contract
|
|
@@ -45,3 +48,4 @@ export async function handleContractError(func, callback) {
|
|
|
45
48
|
export function sleep(ms) {
|
|
46
49
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
50
|
}
|
|
51
|
+
export const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getFilters = (criteria, byteOffsets) => {
|
|
2
|
+
return Object.entries(criteria).reduce((acc, [key, value]) => {
|
|
3
|
+
const criteriaKey = key;
|
|
4
|
+
const effectiveByteOffset = byteOffsets[criteriaKey];
|
|
5
|
+
if (criteria[criteriaKey] && effectiveByteOffset) {
|
|
6
|
+
acc.push({
|
|
7
|
+
memcmp: {
|
|
8
|
+
offset: effectiveByteOffset,
|
|
9
|
+
bytes: value.toString(),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return acc;
|
|
14
|
+
}, []);
|
|
15
|
+
};
|
package/dist/esm/solana/index.js
CHANGED
|
@@ -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 BN from "bn.js";
|
|
3
|
+
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
|
package/dist/esm/solana/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ComputeBudgetProgram, Keypair, TransactionMessage, VersionedTransaction
|
|
|
3
3
|
import bs58 from "bs58";
|
|
4
4
|
import PQueue from "p-queue";
|
|
5
5
|
import { TransactionFailedError, } from "./types.js";
|
|
6
|
-
import { sleep } from "../utils.js";
|
|
6
|
+
import { sleep } from "../lib/utils.js";
|
|
7
7
|
const SIMULATE_TRIES = 3;
|
|
8
8
|
export const buildSendThrottler = (sendRate) => {
|
|
9
9
|
return new PQueue({ concurrency: sendRate, intervalCap: 1, interval: 1000 });
|
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.13",
|
|
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,9 +27,10 @@
|
|
|
27
27
|
"lint-config": "eslint --print-config",
|
|
28
28
|
"prepublishOnly": "npm run lint && npm run build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "1fe1f2d828e28cfd9e842bb4dd47c9756a39404f",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@streamflow/eslint-config": "7.0.0-alpha.
|
|
32
|
+
"@streamflow/eslint-config": "7.0.0-alpha.13",
|
|
33
|
+
"@types/bn.js": "5.1.1",
|
|
33
34
|
"date-fns": "2.28.0",
|
|
34
35
|
"typescript": "^4.9.5"
|
|
35
36
|
},
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
41
42
|
"@solana/web3.js": "1.90.2",
|
|
42
43
|
"aptos": "1.21.0",
|
|
43
|
-
"
|
|
44
|
+
"bn.js": "5.2.1",
|
|
44
45
|
"borsh": "^2.0.0",
|
|
45
46
|
"bs58": "5.0.0",
|
|
46
47
|
"p-queue": "^8.0.1"
|