@0xsplits/splits-sdk
Version:
SDK for the 0xSplits protocol
62 lines • 5.5 kB
JavaScript
"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.formatGqlPassThroughWallet = exports.PASS_THROUGH_WALLET_FIELDS_FRAGMENT = void 0;
var token_1 = require("./token");
var split_1 = require("./split");
var swapper_1 = require("./swapper");
var core_1 = require("@urql/core");
var viem_1 = require("viem");
var PASS_THROUGH_WALLET_SWAP_BALANCE_FRAGMENT = (0, core_1.gql)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n fragment PassThroughWalletSwapBalanceFragment on PassThroughWalletSwapBalance {\n inputToken {\n id\n symbol\n decimals\n }\n inputAmount\n outputs {\n token {\n id\n symbol\n decimals\n }\n amount\n }\n }\n"], ["\n fragment PassThroughWalletSwapBalanceFragment on PassThroughWalletSwapBalance {\n inputToken {\n id\n symbol\n decimals\n }\n inputAmount\n outputs {\n token {\n id\n symbol\n decimals\n }\n amount\n }\n }\n"])));
exports.PASS_THROUGH_WALLET_FIELDS_FRAGMENT = (0, core_1.gql)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n fragment PassThroughWalletFieldsFragment on PassThroughWallet {\n owner {\n id\n }\n paused\n passThroughAccount {\n id\n ... on Split {\n ...AccountFieldsFragment\n ...SplitFieldsFragment\n recipients {\n ...RecipientFieldsFragment\n account {\n id\n ... on Swapper {\n ...AccountFieldsFragment\n ...SwapperFieldsFragment\n }\n }\n }\n }\n }\n passThroughSwapBalances: swapBalances {\n ...PassThroughWalletSwapBalanceFragment\n }\n }\n\n ", "\n ", "\n ", "\n ", "\n ", "\n"], ["\n fragment PassThroughWalletFieldsFragment on PassThroughWallet {\n owner {\n id\n }\n paused\n passThroughAccount {\n id\n ... on Split {\n ...AccountFieldsFragment\n ...SplitFieldsFragment\n recipients {\n ...RecipientFieldsFragment\n account {\n id\n ... on Swapper {\n ...AccountFieldsFragment\n ...SwapperFieldsFragment\n }\n }\n }\n }\n }\n passThroughSwapBalances: swapBalances {\n ...PassThroughWalletSwapBalanceFragment\n }\n }\n\n ", "\n ", "\n ", "\n ", "\n ", "\n"])), split_1.ACCOUNT_FIELDS_FRAGMENT, split_1.SPLIT_FIELDS_FRAGMENT, split_1.RECIPIENT_FIELDS_FRAGMENT, swapper_1.SWAPPER_FIELDS_FRAGMENT, PASS_THROUGH_WALLET_SWAP_BALANCE_FRAGMENT);
var formatPassThroughWalletSwapBalances = function (gqlPassThroughWaleltSwapBalances) {
return gqlPassThroughWaleltSwapBalances.reduce(function (acc, passThroughWalletSwapBalance) {
var inputToken = (0, viem_1.getAddress)(passThroughWalletSwapBalance.inputToken.id);
var inputAmount = BigInt(passThroughWalletSwapBalance.inputAmount);
var outputs = passThroughWalletSwapBalance.outputs.reduce(function (outputAcc, passThroughWalletSwapBalanceOutput) {
var token = (0, viem_1.getAddress)(passThroughWalletSwapBalanceOutput.token.id);
var amount = BigInt(passThroughWalletSwapBalanceOutput.amount);
var symbol = passThroughWalletSwapBalanceOutput.token.symbol;
var decimals = passThroughWalletSwapBalanceOutput.token.decimals;
outputAcc[token] = {
amount: amount,
symbol: symbol,
decimals: decimals,
};
return outputAcc;
}, {});
acc[inputToken] = {
inputAmount: inputAmount,
outputs: outputs,
};
return acc;
}, {});
};
var formatGqlPassThroughWallet = function (gqlPassThroughWallet) {
return {
type: 'passThroughWallet',
chainId: parseInt(gqlPassThroughWallet.chainId),
distributions: (0, token_1.formatTokenBalances)(gqlPassThroughWallet.distributions),
address: (0, viem_1.getAddress)(gqlPassThroughWallet.id),
balances: {},
balanceQuoteAmounts: {},
splitmainBalances: (0, token_1.formatInternalTokenBalances)(gqlPassThroughWallet.internalBalances),
warehouseBalances: (0, token_1.formatInternalTokenBalances)(gqlPassThroughWallet.warehouseBalances),
latestBlock: gqlPassThroughWallet.latestBlock,
latestActivity: parseInt(gqlPassThroughWallet.latestActivity),
parentEntityType: gqlPassThroughWallet.parentEntityType,
owner: (0, viem_1.getAddress)(gqlPassThroughWallet.owner.id),
paused: gqlPassThroughWallet.paused,
passThroughAccount: (0, viem_1.getAddress)(gqlPassThroughWallet.passThroughAccount.id),
// TODO: remove?
passThroughBalances: (0, token_1.formatTokenBalances)(gqlPassThroughWallet.distributions),
swapBalances: formatPassThroughWalletSwapBalances(gqlPassThroughWallet.passThroughSwapBalances),
contractEarnings: (0, token_1.formatGqlContractEarnings)(gqlPassThroughWallet.contractEarnings),
};
};
exports.formatGqlPassThroughWallet = formatGqlPassThroughWallet;
var templateObject_1, templateObject_2;
//# sourceMappingURL=pass-through-wallet.js.map