UNPKG

@parifi/sdk

Version:

Parifi SDK with common utility functions

112 lines (106 loc) 4.13 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/subgraph/scripts/index.ts var scripts_exports = {}; __export(scripts_exports, { getEstimatedRewardsForUser: () => getEstimatedRewardsForUser }); module.exports = __toCommonJS(scripts_exports); var import_graphql_request2 = __toESM(require("graphql-request")); // src/subgraph/scripts/subgraphQueries.ts var import_graphql_request = require("graphql-request"); var fetchIntegratorFeesWithTimestampQuery = (startTimeStamp, endTimeStamp) => import_graphql_request.gql`{ snxAccounts( first: 1000 where: { type: PERP, totalOrdersCount_gt: 0 }) { id integratorFeesGenerated accountId owner { id } orders( where: { status: SETTLED, createdTimestamp_gt: ${startTimeStamp}, createdTimestamp_lt: ${endTimeStamp} } ) { id referralFees collectedFees } } } `; // src/subgraph/scripts/index.ts var import_decimal2 = require("decimal.js"); // src/common/constants.ts var import_decimal = require("decimal.js"); var PRECISION_MULTIPLIER = new import_decimal.Decimal("10000"); var DEVIATION_PRECISION_MULTIPLIER = new import_decimal.Decimal(10).pow(12); var SECONDS_IN_A_YEAR = new import_decimal.Decimal(365 * 24 * 60 * 60); var MAX_FEE = new import_decimal.Decimal(1e7); var WAD = new import_decimal.Decimal(10).pow(18); var DECIMAL_10 = new import_decimal.Decimal(10); var DECIMAL_ZERO = new import_decimal.Decimal(0); var BIGINT_ZERO = BigInt(0); var ONE_GWEI = 1e9; var DEFAULT_GAS_PRICE = 2 * ONE_GWEI; // src/common/helpers.ts var import_viem = require("viem"); // src/subgraph/scripts/index.ts var getEstimatedRewardsForUser = async (subgraphEndpoint, userAddress, totalRewardsForPeriod, startTimestamp, endTimestamp) => { const response = await (0, import_graphql_request2.default)( subgraphEndpoint, fetchIntegratorFeesWithTimestampQuery(startTimestamp, endTimestamp) ); const feeDetails = response?.snxAccounts ?? []; let totalFeesForPeriod = 0; let userFeesForPeriod = 0; feeDetails.forEach((account) => { account.orders.forEach((order) => { const formattedFees = new import_decimal2.Decimal(order.referralFees).div(WAD); if (account.owner.id == userAddress) { userFeesForPeriod += Number(formattedFees.toString()); } totalFeesForPeriod += Number(formattedFees.toString()); }); }); if (totalFeesForPeriod === 0) { return 0; } const estimatedUserRewards = userFeesForPeriod * totalRewardsForPeriod / totalFeesForPeriod; return estimatedUserRewards; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getEstimatedRewardsForUser }); //# sourceMappingURL=index.js.map