@parifi/sdk
Version:
Parifi SDK with common utility functions
55 lines • 1.58 kB
JavaScript
// src/common/helpers.ts
import { formatEther, parseEther } from "viem";
var getDiff = (a, b) => {
return a.gt(b) ? a.minus(b) : b.minus(a);
};
var addDelay = async (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
var getCurrentTimestampInSeconds = () => {
return Math.floor(Date.now() / 1e3);
};
var getUniqueValuesFromArray = (originalArray) => {
const uniqueArray = [];
const seenValues = /* @__PURE__ */ new Set();
originalArray.forEach((item) => {
if (!seenValues.has(item)) {
uniqueArray.push(item);
seenValues.add(item);
}
});
return uniqueArray;
};
function convertWeiToEther(amountInWei) {
if (amountInWei == void 0) {
throw new Error("Invalid amount received during conversion: undefined");
}
if (typeof amountInWei == "bigint") {
return Number(formatEther(amountInWei));
} else if (typeof amountInWei == "string") {
return Number(formatEther(BigInt(amountInWei)));
} else {
throw new Error("Expected string or bigint for conversion");
}
}
function convertEtherToWei(amount) {
if (amount == void 0) {
throw new Error("Invalid amount received during conversion: undefined");
}
if (typeof amount == "number") {
return parseEther(amount.toString());
} else if (typeof amount == "string") {
return parseEther(amount);
} else {
throw new Error("Expected string or bigint for conversion");
}
}
export {
addDelay,
convertEtherToWei,
convertWeiToEther,
getCurrentTimestampInSeconds,
getDiff,
getUniqueValuesFromArray
};
//# sourceMappingURL=helpers.mjs.map