@parifi/sdk
Version:
Parifi SDK with common utility functions
85 lines (84 loc) • 2.9 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/common/helpers.ts
var helpers_exports = {};
__export(helpers_exports, {
addDelay: () => addDelay,
convertEtherToWei: () => convertEtherToWei,
convertWeiToEther: () => convertWeiToEther,
getCurrentTimestampInSeconds: () => getCurrentTimestampInSeconds,
getDiff: () => getDiff,
getUniqueValuesFromArray: () => getUniqueValuesFromArray
});
module.exports = __toCommonJS(helpers_exports);
var import_viem = require("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((0, import_viem.formatEther)(amountInWei));
} else if (typeof amountInWei == "string") {
return Number((0, import_viem.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 (0, import_viem.parseEther)(amount.toString());
} else if (typeof amount == "string") {
return (0, import_viem.parseEther)(amount);
} else {
throw new Error("Expected string or bigint for conversion");
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addDelay,
convertEtherToWei,
convertWeiToEther,
getCurrentTimestampInSeconds,
getDiff,
getUniqueValuesFromArray
});
//# sourceMappingURL=helpers.js.map