@molecularlabs/nucleus-frontend
Version:
Nucleus BoringVault Frontend SDK
94 lines • 2.75 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);
var erc20_exports = {};
__export(erc20_exports, {
getErc20Allowance: () => getErc20Allowance,
getErc20AllowanceWithDecimals: () => getErc20AllowanceWithDecimals,
getErc20Balance: () => getErc20Balance,
getErc20Decimals: () => getErc20Decimals
});
module.exports = __toCommonJS(erc20_exports);
var import_viem = require("viem");
var import_client = require("../lib/client");
const getErc20Balance = async ({
chainId,
tokenAddress,
userAddress
}) => {
const client = await (0, import_client.getClient)(chainId);
const balance = await client.readContract({
abi: import_viem.erc20Abi,
address: tokenAddress,
functionName: "balanceOf",
args: [userAddress]
});
return balance;
};
const getErc20Decimals = async ({
chainId,
tokenAddress
}) => {
const client = await (0, import_client.getClient)(chainId);
const balance = await client.readContract({
abi: import_viem.erc20Abi,
address: tokenAddress,
functionName: "decimals"
});
return balance;
};
const getErc20Allowance = async ({
chainId,
tokenAddress,
userAddress,
spenderAddress
}) => {
const client = await (0, import_client.getClient)(chainId);
const allowance = await client.readContract({
abi: import_viem.erc20Abi,
address: tokenAddress,
functionName: "allowance",
args: [userAddress, spenderAddress]
});
return allowance;
};
const getErc20AllowanceWithDecimals = async ({
chainId,
tokenAddress,
userAddress,
spenderAddress
}) => {
const client = await (0, import_client.getClient)(chainId);
const allowance = await client.multicall({
contracts: [
{
abi: import_viem.erc20Abi,
address: tokenAddress,
functionName: "allowance",
args: [userAddress, spenderAddress]
},
{
abi: import_viem.erc20Abi,
address: tokenAddress,
functionName: "decimals"
}
]
});
return allowance;
};
//# sourceMappingURL=erc20.js.map