@streamflow/common 8.8.0 → 8.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -2
- package/dist/cjs/solana/index.cjs +4 -0
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +3 -1
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +3 -1
- package/dist/esm/solana/index.js +4 -0
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -239,7 +239,9 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
|
|
|
239
239
|
* @param payer - optional payer account, will be used instead of invoker as `source`
|
|
240
240
|
* @returns Array of Transaction Instructions that should be added to a transaction
|
|
241
241
|
*/
|
|
242
|
-
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker:
|
|
242
|
+
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: {
|
|
243
|
+
publicKey: PublicKey | null;
|
|
244
|
+
}, programId?: PublicKey, payer?: PublicKey): Promise<TransactionInstruction[]>;
|
|
243
245
|
/**
|
|
244
246
|
* Create Base instructions for Solana
|
|
245
247
|
* - sets compute price if `computePrice` is provided. If `computePrice` is a function, it will be ignored (the value must be resolved before calling this function).
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionInstruction } from '@solana/web3.js';
|
|
1
|
+
import { TransactionInstruction, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
3
|
|
|
4
4
|
interface ITransactionResult {
|
|
@@ -34,6 +34,11 @@ declare class ContractError extends Error {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
declare const invariant: (condition: any, message?: string | (() => string)) => asserts condition;
|
|
37
|
+
declare function assertHasPublicKey<T extends {
|
|
38
|
+
publicKey?: PublicKey | null;
|
|
39
|
+
}>(value: T, message?: string | (() => string)): asserts value is T & {
|
|
40
|
+
publicKey: PublicKey;
|
|
41
|
+
};
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* Used for conversion of token amounts to their Big Number representation.
|
|
@@ -63,4 +68,4 @@ declare function handleContractError<T>(func: () => Promise<T>, callback?: (err:
|
|
|
63
68
|
declare function sleep(ms: number): Promise<void>;
|
|
64
69
|
declare const divCeilN: (n: bigint, d: bigint) => bigint;
|
|
65
70
|
|
|
66
|
-
export { ContractError, IChain, ICluster, type ITransactionResult, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
|
|
71
|
+
export { ContractError, IChain, ICluster, type ITransactionResult, assertHasPublicKey, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
|
package/dist/esm/index.js
CHANGED
|
@@ -44,6 +44,9 @@ var invariant = (condition, message) => {
|
|
|
44
44
|
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
45
45
|
throw new Error(value);
|
|
46
46
|
};
|
|
47
|
+
function assertHasPublicKey(value, message) {
|
|
48
|
+
invariant(value.publicKey, message ?? "publicKey is missing");
|
|
49
|
+
}
|
|
47
50
|
var getBN = (value, decimals) => {
|
|
48
51
|
const decimalPart = value - Math.trunc(value);
|
|
49
52
|
const integerPart = new BN(Math.trunc(value));
|
|
@@ -71,6 +74,6 @@ function sleep(ms) {
|
|
|
71
74
|
}
|
|
72
75
|
var divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
|
|
73
76
|
|
|
74
|
-
export { ContractError, IChain, ICluster, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
|
|
77
|
+
export { ContractError, IChain, ICluster, assertHasPublicKey, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
|
|
75
78
|
//# sourceMappingURL=index.js.map
|
|
76
79
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../types.ts","../../lib/assertions.ts","../../lib/utils.ts"],"names":["ICluster","IChain"],"mappings":";;;;AAQY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,OAAQ,CAAA,GAAA,OAAA;AAJE,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,MAAA,qBAAAC,OAAL,KAAA;AACL,EAAAA,QAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,QAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,QAAA,UAAW,CAAA,GAAA,UAAA;AACX,EAAAA,QAAA,KAAM,CAAA,GAAA,KAAA;AACN,EAAAA,QAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,QAAA,KAAM,CAAA,GAAA,KAAA;AANI,EAAAA,OAAAA,OAAAA;AAAA,CAAA,EAAA,MAAA,IAAA,EAAA;AAYC,IAAA,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvC,WAAA,CAAY,KAAc,EAAA,IAAA,EAAsB,WAA6B,EAAA;AAC3E,IAAA,KAAA,CAAM,KAAM,CAAA,OAAA,EAAS,EAAE,KAAA,EAAO,OAAO,CAAA;AACrC,IAAA,IAAA,CAAK,oBAAoB,IAAQ,IAAA,IAAA;AACjC,IAAA,IAAA,CAAK,cAAc,WAAe,IAAA,IAAA;AAElC,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,cAAA,CAAc,SAAS,CAAA;AACnD,IAAA,IAAA,CAAK,IA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,KAAA,EAAW,QACzC,KAAA,KAAA,CAAM,EAAG,CAAA,IAAI,EAAG,CAAA,CAAA,IAAK,EAAK,GAAA,CAAC,CAAC,CAAA,GAAI,MAAM,GAAI,CAAA,IAAI,EAAG,CAAA,EAAA,IAAM,QAAQ,CAAC,CAAE,CAAA,QAAA,EAAa,GAAA,KAAA,CAAM,QAAS,EAAA,GAAI,EAAM,IAAA;AAQ1G,eAAsB,mBAAA,CACpB,MACA,QACY,EAAA;AACZ,EAAI,IAAA;AACF,IAAA,OAAO,MAAM,IAAK,EAAA;AAAA,WAEX,GAAU,EAAA;AACjB,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,MAAM,IAAI,aAAA,CAAc,GAAK,EAAA,QAAA,CAAS,GAAG,CAAC,CAAA;AAAA;AAE5C,MAAM,MAAA,IAAI,cAAc,GAAG,CAAA;AAAA;AAE7B,IAAM,MAAA,GAAA;AAAA;AAEV;AAMO,SAAS,MAAM,EAA2B,EAAA;AAC/C,EAAA,OAAO,IAAI,OAAQ,CAAA,CAAC,YAAY,UAAW,CAAA,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD;AAEO,IAAM,QAAW,GAAA,CAAC,CAAW,EAAA,CAAA,KAAsB,CAAI,GAAA,CAAA,IAAK,CAAI,GAAA,CAAA,GAAI,MAAO,CAAA,CAAC,CAAI,GAAA,MAAA,CAAO,CAAC,CAAA","file":"index.js","sourcesContent":["import { type TransactionInstruction } from \"@solana/web3.js\";\n\nexport interface ITransactionResult {\n ixs: TransactionInstruction[];\n txId: string;\n}\n\n// Utility types\nexport enum ICluster {\n Mainnet = \"mainnet\",\n Devnet = \"devnet\",\n Testnet = \"testnet\",\n Local = \"local\",\n}\n\nexport enum IChain {\n Solana = \"Solana\",\n Aptos = \"Aptos\",\n Ethereum = \"Ethereum\",\n BNB = \"BNB\",\n Polygon = \"Polygon\",\n Sui = \"Sui\",\n}\n\n/**\n * Error wrapper for calls made to the contract on chain\n */\nexport class ContractError extends Error {\n public contractErrorCode: string | null;\n\n public description: string | null;\n\n /**\n * Constructs the Error Wrapper\n * @param error Original error raised probably by the chain SDK\n * @param code extracted code from the error if managed to parse it\n */\n constructor(error: Error, code?: string | null, description?: string | null) {\n super(error.message, { cause: error }); // Call the base class constructor with the error message\n this.contractErrorCode = code ?? null;\n this.description = description ?? null;\n // Copy properties from the original error\n Object.setPrototypeOf(this, ContractError.prototype);\n this.name = \"ContractError\"; // Set the name property\n this.stack = error.stack;\n }\n}\n","import type { PublicKey } from \"@solana/web3.js\";\n\nconst prefix = \"Assertion failed\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const invariant: (condition: any, message?: string | (() => string)) => asserts condition = (\n condition,\n message,\n) => {\n if (condition) {\n return;\n }\n const provided: string | undefined = typeof message === \"function\" ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n};\n\nexport function assertHasPublicKey<T extends { publicKey?: PublicKey | null }>(\n value: T,\n message?: string | (() => string),\n): asserts value is T & { publicKey: PublicKey } {\n invariant(value.publicKey, message ?? \"publicKey is missing\");\n}\n\n","import BN from \"bn.js\";\n\nimport { ContractError } from \"../types.js\";\n\n/**\n * Used for conversion of token amounts to their Big Number representation.\n * Get Big Number representation in the smallest units from the same value in the highest units.\n * @param {number} value - Number of tokens you want to convert to its BN representation.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getBN = (value: number, decimals: number): BN => {\n const decimalPart = value - Math.trunc(value);\n const integerPart = new BN(Math.trunc(value));\n\n const decimalE = new BN(decimalPart * 1e9);\n\n const sum = integerPart.mul(new BN(1e9)).add(decimalE);\n const resultE = sum.mul(new BN(10).pow(new BN(decimals)));\n return resultE.div(new BN(1e9));\n};\n\n/**\n * Used for token amounts conversion from their Big Number representation to number.\n * Get value in the highest units from BN representation of the same value in the smallest units.\n * @param {BN} value - Big Number representation of value in the smallest units.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getNumberFromBN = (value: BN, decimals: number): number =>\n value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;\n\n/**\n * Used to make on chain calls to the contract and wrap raised errors if any\n * @param func function that interacts with the contract\n * @param callback callback that may be used to extract error code\n * @returns {T}\n */\nexport async function handleContractError<T>(\n func: () => Promise<T>,\n callback?: (err: Error) => string | null,\n): Promise<T> {\n try {\n return await func();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n if (err instanceof Error) {\n if (callback) {\n throw new ContractError(err, callback(err));\n }\n throw new ContractError(err);\n }\n throw err;\n }\n}\n\n/**\n * Pause async function execution for given amount of milliseconds\n * @param ms millisecond to sleep for\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport const divCeilN = (n: bigint, d: bigint): bigint => n / d + (n % d ? BigInt(1) : BigInt(0));\n"]}
|
|
@@ -239,7 +239,9 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
|
|
|
239
239
|
* @param payer - optional payer account, will be used instead of invoker as `source`
|
|
240
240
|
* @returns Array of Transaction Instructions that should be added to a transaction
|
|
241
241
|
*/
|
|
242
|
-
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker:
|
|
242
|
+
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: {
|
|
243
|
+
publicKey: PublicKey | null;
|
|
244
|
+
}, programId?: PublicKey, payer?: PublicKey): Promise<TransactionInstruction[]>;
|
|
243
245
|
/**
|
|
244
246
|
* Create Base instructions for Solana
|
|
245
247
|
* - sets compute price if `computePrice` is provided. If `computePrice` is a function, it will be ignored (the value must be resolved before calling this function).
|
package/dist/esm/solana/index.js
CHANGED
|
@@ -713,6 +713,9 @@ var invariant = (condition, message) => {
|
|
|
713
713
|
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
714
714
|
throw new Error(value);
|
|
715
715
|
};
|
|
716
|
+
function assertHasPublicKey(value, message) {
|
|
717
|
+
invariant(value.publicKey, message);
|
|
718
|
+
}
|
|
716
719
|
|
|
717
720
|
// solana/utils.ts
|
|
718
721
|
var SIMULATE_TRIES = 3;
|
|
@@ -970,6 +973,7 @@ async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate
|
|
|
970
973
|
return signAndExecuteTransaction(connection, invoker, tx, { hash, context, commitment }, { sendRate: rate });
|
|
971
974
|
}
|
|
972
975
|
async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId, payer) {
|
|
976
|
+
assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
973
977
|
const ixs = [];
|
|
974
978
|
if (!programId) {
|
|
975
979
|
programId = (await getMintAndProgram(connection, mint)).tokenProgramId;
|