UNPKG

@0xsplits/splits-sdk

Version:

SDK for the 0xSplits protocol

84 lines 5.38 kB
"use strict"; var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.protectedFormatWaterfallModule = exports.formatGqlWaterfallModule = exports.WATERFALL_MODULE_FIELDS_FRAGMENT = void 0; var core_1 = require("@urql/core"); var split_1 = require("./split"); var token_1 = require("./token"); var constants_1 = require("../constants"); var viem_1 = require("viem"); var utils_1 = require("../utils"); var WATERFALL_TRANCHE_FIELDS_FRAGMENT = (0, core_1.gql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n fragment WaterfallTrancheFieldsFragment on WaterfallTranche {\n startAmount\n size\n claimedAmount\n recipient {\n __typename\n id\n ... on Split {\n ...AccountFieldsFragment\n ...SplitFieldsFragment\n }\n }\n }\n ", "\n ", "\n"], ["\n fragment WaterfallTrancheFieldsFragment on WaterfallTranche {\n startAmount\n size\n claimedAmount\n recipient {\n __typename\n id\n ... on Split {\n ...AccountFieldsFragment\n ...SplitFieldsFragment\n }\n }\n }\n ", "\n ", "\n"])), split_1.ACCOUNT_FIELDS_FRAGMENT, split_1.SPLIT_FIELDS_FRAGMENT); exports.WATERFALL_MODULE_FIELDS_FRAGMENT = (0, core_1.gql)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n fragment WaterfallModuleFieldsFragment on WaterfallModule {\n token {\n id\n }\n tranches {\n ...WaterfallTrancheFieldsFragment\n }\n nonWaterfallRecipient {\n id\n }\n }\n\n ", "\n"], ["\n fragment WaterfallModuleFieldsFragment on WaterfallModule {\n token {\n id\n }\n tranches {\n ...WaterfallTrancheFieldsFragment\n }\n nonWaterfallRecipient {\n id\n }\n }\n\n ", "\n"])), WATERFALL_TRANCHE_FIELDS_FRAGMENT); var formatGqlWaterfallTranche = function (gqlWaterfallTranche) { return { startAmount: BigInt(gqlWaterfallTranche.startAmount), size: gqlWaterfallTranche.size ? BigInt(gqlWaterfallTranche.size) : undefined, claimedAmount: BigInt(gqlWaterfallTranche.claimedAmount), fundedAmount: constants_1.ZERO, // To be filled in later recipient: (0, viem_1.getAddress)(gqlWaterfallTranche.recipient.id), }; }; var formatGqlWaterfallModule = function (gqlWaterfallModule) { return { type: 'waterfall', address: (0, viem_1.getAddress)(gqlWaterfallModule.id), chainId: parseInt(gqlWaterfallModule.chainId), distributions: (0, token_1.formatTokenBalances)(gqlWaterfallModule.distributions), balances: {}, distributed: gqlWaterfallModule.distributions ? (0, token_1.formatTokenBalances)(gqlWaterfallModule.distributions) : {}, token: (0, viem_1.getAddress)(gqlWaterfallModule.token.id), splitmainBalances: (0, token_1.formatInternalTokenBalances)(gqlWaterfallModule.internalBalances), warehouseBalances: (0, token_1.formatInternalTokenBalances)(gqlWaterfallModule.warehouseBalances), latestBlock: gqlWaterfallModule.latestBlock, latestActivity: parseInt(gqlWaterfallModule.latestActivity), tranches: gqlWaterfallModule.tranches.map(function (gqlWaterfallTranche) { return formatGqlWaterfallTranche(gqlWaterfallTranche); }), nonWaterfallRecipient: (0, viem_1.getAddress)(gqlWaterfallModule.nonWaterfallRecipient.id), parentEntityType: gqlWaterfallModule.parentEntityType, contractEarnings: (0, token_1.formatGqlContractEarnings)(gqlWaterfallModule.contractEarnings), }; }; exports.formatGqlWaterfallModule = formatGqlWaterfallModule; // Should only be called by formatWaterfallModule on WaterfallClient var protectedFormatWaterfallModule = function (gqlWaterfallModule, tokenSymbol, tokenDecimals) { return { type: 'WaterfallModule', address: (0, viem_1.getAddress)(gqlWaterfallModule.address), token: { address: (0, viem_1.getAddress)(gqlWaterfallModule.token), symbol: tokenSymbol, decimals: tokenDecimals, }, nonWaterfallRecipient: gqlWaterfallModule.nonWaterfallRecipient !== viem_1.zeroAddress ? { address: (0, viem_1.getAddress)(gqlWaterfallModule.nonWaterfallRecipient), } : null, tranches: gqlWaterfallModule.tranches.map(function (tranche) { return formatWaterfallModuleTranche(tranche, tokenDecimals); }), }; }; exports.protectedFormatWaterfallModule = protectedFormatWaterfallModule; var formatWaterfallModuleTranche = function (gqlWaterfallTranche, tokenDecimals) { return { recipient: { address: (0, viem_1.getAddress)(gqlWaterfallTranche.recipient), }, startAmount: parseFloat((0, utils_1.fromBigIntToTokenValue)(gqlWaterfallTranche.startAmount, tokenDecimals)), size: gqlWaterfallTranche.size ? parseFloat((0, utils_1.fromBigIntToTokenValue)(gqlWaterfallTranche.size, tokenDecimals)) : undefined, }; }; var templateObject_1, templateObject_2; //# sourceMappingURL=waterfall.js.map