@parifi/sdk
Version:
Parifi SDK with common utility functions
354 lines (353 loc) • 12.5 kB
JavaScript
// src/common/constants.ts
import { Decimal } from "decimal.js";
var PRECISION_MULTIPLIER = new Decimal("10000");
var DEVIATION_PRECISION_MULTIPLIER = new Decimal(10).pow(12);
var SECONDS_IN_A_YEAR = new Decimal(365 * 24 * 60 * 60);
var MAX_FEE = new Decimal(1e7);
var WAD = new Decimal(10).pow(18);
var EMPTY_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
var DECIMAL_10 = new Decimal(10);
var DECIMAL_ZERO = new Decimal(0);
var DEFAULT_BATCH_COUNT = 10;
var BIGINT_ZERO = BigInt(0);
var GAS_LIMIT_SETTLEMENT = 1e7;
var GAS_LIMIT_LIQUIDATION = 15e6;
var ONE_GWEI = 1e9;
var DEFAULT_GAS_PRICE = 2 * ONE_GWEI;
var PYTH_ETH_USD_PRICE_ID_BETA = "0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6";
var PYTH_ETH_USD_PRICE_ID_STABLE = "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace";
var PYTH_USDC_USD_PRICE_ID_BETA = "0x41f3625971ca2ed2263e78573fe5ce23e13d2558ed3f2e47ab0f84fb9e7ae722";
var PYTH_USDC_USD_PRICE_ID_STABLE = "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a";
var FACTORY_ADDRESS_SIMPLE_ACCOUNT = "0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985";
var SUBGRAPH_HELPER_ADDRESS = "0xf012d32505df6853187170F00C7b789A8ecC41c2";
var SYMBOL_TO_PYTH_FEED = /* @__PURE__ */ new Map([
// market
["BTC", "0xc9d8b075a5c69303365ae23633d4e085199bf5c520a3b90fed1322a0342ffc33"],
["SOL", "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"],
["WIF", "0x4ca4beeca86f0d164160323817a4e42b10010a724c2217c6ee41b54cd4cc61fc"],
["ETH", "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"],
["AAVE", "0x2b9ab1e972a281585084148ba1389800799bd4be63b957507db1349314e47445"],
["ADA", "0x2a01deaec9e51a579277b34b122399984d0bbf57e2458a7e42fecd2829867a0d"],
["ARB", "0x3fa4252848f9f0a1480be62745a4629d9eb1322aebab8a791e344b3b9c1adcf5"],
["AVAX", "0x93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7"],
["BCH", "0x3dd2b63686a450ec7290df3a1e0b583c0481f651351edfa7636f39aed55cf8a3"],
["BNB", "0x2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f"],
["CRV", "0xa19d04ac696c7a6616d291c7e5d1377cc8be437c327b75adb5dc1bad745fcae8"],
["DOGE", "0xdcef50dd0a4cd2dcc17e45df1676dcb336a11a61c69df7a0299b0150c672d25c"],
["DYDX", "0x6489800bb8974169adfe35937bf6736507097d13c190d760c557108c7e93a81b"],
["GMX", "0xb962539d0fcb272a494d65ea56f94851c2bcf8823935da05bd628916e2e9edbf"],
["LINK", "0x8ac0c70fff57e9aefdf5edf44b51d62c2d433653cbb2cf5cc06bb115af04d221"],
["LTC", "0x6e3f3fa8253588df9326580180233eb791e03b443a3ba7a1d892e73874e19a54"],
["MKR", "0x9375299e31c0deb9c6bc378e6329aab44cb48ec655552a70d4b9050346a30378"],
["NEAR", "0xc415de8d2eba7db216527dff4b60e8f3a5311c740dadb233e13e12547e226750"],
["OP", "0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf"],
["ORDI", "0x193c739db502aadcef37c2589738b1e37bdb257d58cf1ab3c7ebc8e6df4e3ec0"],
["PEPE", "0xd69731a2e74ac1ce884fc3890f7ee324b6deb66147055249568869ed700882e4"],
["POL", "0xffd11c5a1cfd42f80afb2df4d9f264c15f956d68153335374ec10722edd70472"],
["PYTH", "0x0bbf28e9a841a1cc788f6a361b17ca072d0ea3098a1e5df1c3922d06719579ff"],
["RUNE", "0x5fcf71143bb70d41af4fa9aa1287e2efd3c5911cee59f909f915c9f61baacb1e"],
["SHIB", "0xf0d57deca57b3da2fe63a493f4c25925fdfd8edf834b20f93e1f84dbd1504d4a"],
["STX", "0xec7a775f46379b5e943c3526b1c8d54cd49749176b0b98e02dde68d1bd335c17"],
["TIA", "0x09f7c1d7dfbb7df2b8fe3d3d87ee94a2259d212da4f30c1f0540d066dfa44723"],
["UNI", "0x78d185a741d07edb3412b09008b7c5cfb9bbbd7d568bf00ba737b456ba171501"],
["XLM", "0xb7a8eba68a997cd0210c2e1e4ee811ad2d174b3611c22d9ebf16f4cb7e9ba850"],
["XRP", "0xec5d399846a9209f3fe5881d70aae9268c94339ff9817e8d18ff19fa05eea1c8"],
// collateral
["USDC", "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a"],
["USDE", "0x6ec879b1e9963de5ee97e9c8710b742d6228252a5e2ca12d4ae81d7fe5ee8c5d"],
["DAI", "0xb0948a5e5313200c632b51bb5ca32f6de0d36e9950a942d19751e833f70dabfd"]
]);
var collateralMappingWithRegularSymbol = /* @__PURE__ */ new Map([
["seth", "eth"],
["wbtc", "btc"],
["fbtc", "btc"],
["wsteth", "eth"],
["fdai", "dai"],
["susdc", "usdc"],
["susde", "usde"],
["steth", "eth"],
["fsol", "sol"],
["fusdc", "usdc"],
["fusdt", "usdt"],
["ssol", "sol"],
["sdai", "dai"],
["usdx", "usdc"],
["stbtc", "btc"]
]);
var SUPPORTED_CHAINS = /* @__PURE__ */ ((SUPPORTED_CHAINS2) => {
SUPPORTED_CHAINS2[SUPPORTED_CHAINS2["BASE"] = 8453] = "BASE";
return SUPPORTED_CHAINS2;
})(SUPPORTED_CHAINS || {});
var REWARD_DISTRIBUTOR_ADDRESSES = {
[8453 /* BASE */]: {
esprf: "0x6511718804180CC57833fEA036389A24604Dfc69",
prf: "0x0000000000000000000000000000000000000000",
rt: "0x648d6D711860699A11aBa192E9daBAfb6408af18"
}
};
var REWARD_DISTRIBUTOR_ABI = [
{
inputs: [{ internalType: "contract IERC20", name: "_rewardToken", type: "address" }],
stateMutability: "nonpayable",
type: "constructor"
},
{ inputs: [], name: "AccessControlBadConfirmation", type: "error" },
{
inputs: [
{ internalType: "address", name: "account", type: "address" },
{ internalType: "bytes32", name: "neededRole", type: "bytes32" }
],
name: "AccessControlUnauthorizedAccount",
type: "error"
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "address", name: "user", type: "address" },
{ indexed: false, internalType: "uint256", name: "amount", type: "uint256" }
],
name: "RewardClaimed",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
{ indexed: true, internalType: "bytes32", name: "previousAdminRole", type: "bytes32" },
{ indexed: true, internalType: "bytes32", name: "newAdminRole", type: "bytes32" }
],
name: "RoleAdminChanged",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
{ indexed: true, internalType: "address", name: "account", type: "address" },
{ indexed: true, internalType: "address", name: "sender", type: "address" }
],
name: "RoleGranted",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
{ indexed: true, internalType: "address", name: "account", type: "address" },
{ indexed: true, internalType: "address", name: "sender", type: "address" }
],
name: "RoleRevoked",
type: "event"
},
{
inputs: [],
name: "DEFAULT_ADMIN_ROLE",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "actualRound",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
{
inputs: [
{ internalType: "uint256", name: "_round", type: "uint256" },
{ internalType: "uint256", name: "amount", type: "uint256" },
{ internalType: "bytes32[]", name: "proof", type: "bytes32[]" }
],
name: "claimReward",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "uint256[]", name: "_rounds", type: "uint256[]" },
{ internalType: "uint256[]", name: "amounts", type: "uint256[]" },
{ internalType: "bytes32[][]", name: "proofs", type: "bytes32[][]" }
],
name: "claimRewards",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "uint256", name: "", type: "uint256" },
{ internalType: "address", name: "", type: "address" }
],
name: "claimed",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function"
},
{
inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
name: "getRoleAdmin",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
stateMutability: "view",
type: "function"
},
{
inputs: [
{ internalType: "bytes32", name: "role", type: "bytes32" },
{ internalType: "address", name: "account", type: "address" }
],
name: "grantRole",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "bytes32", name: "role", type: "bytes32" },
{ internalType: "address", name: "account", type: "address" }
],
name: "hasRole",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "view",
type: "function"
},
{
inputs: [
{ internalType: "bytes32", name: "role", type: "bytes32" },
{ internalType: "address", name: "callerConfirmation", type: "address" }
],
name: "renounceRole",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "bytes32", name: "role", type: "bytes32" },
{ internalType: "address", name: "account", type: "address" }
],
name: "revokeRole",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "rewardToken",
outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
stateMutability: "view",
type: "function"
},
{
inputs: [{ internalType: "uint256", name: "_round", type: "uint256" }],
name: "setActualRound",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{ internalType: "uint256", name: "_round", type: "uint256" },
{ internalType: "bytes32", name: "_root", type: "bytes32" }
],
name: "setRootPerRound",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
name: "supportsInterface",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "view",
type: "function"
},
{
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
name: "verifiersPerRound",
outputs: [{ internalType: "contract Verifier", name: "", type: "address" }],
stateMutability: "view",
type: "function"
}
];
// src/common/helpers.ts
import { formatEther, parseEther } from "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(formatEther(amountInWei));
} else if (typeof amountInWei == "string") {
return Number(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 parseEther(amount.toString());
} else if (typeof amount == "string") {
return parseEther(amount);
} else {
throw new Error("Expected string or bigint for conversion");
}
}
export {
BIGINT_ZERO,
DECIMAL_10,
DECIMAL_ZERO,
DEFAULT_BATCH_COUNT,
DEFAULT_GAS_PRICE,
DEVIATION_PRECISION_MULTIPLIER,
EMPTY_BYTES32,
FACTORY_ADDRESS_SIMPLE_ACCOUNT,
GAS_LIMIT_LIQUIDATION,
GAS_LIMIT_SETTLEMENT,
MAX_FEE,
ONE_GWEI,
PRECISION_MULTIPLIER,
PYTH_ETH_USD_PRICE_ID_BETA,
PYTH_ETH_USD_PRICE_ID_STABLE,
PYTH_USDC_USD_PRICE_ID_BETA,
PYTH_USDC_USD_PRICE_ID_STABLE,
REWARD_DISTRIBUTOR_ABI,
REWARD_DISTRIBUTOR_ADDRESSES,
SECONDS_IN_A_YEAR,
SUBGRAPH_HELPER_ADDRESS,
SUPPORTED_CHAINS,
SYMBOL_TO_PYTH_FEED,
WAD,
addDelay,
collateralMappingWithRegularSymbol,
convertEtherToWei,
convertWeiToEther,
getCurrentTimestampInSeconds,
getDiff,
getUniqueValuesFromArray
};
//# sourceMappingURL=index.mjs.map