@ssv-labs/bapps-sdk
Version:
ssv labs based apps sdk
2,384 lines (2,383 loc) • 260 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const tryCatch$1 = require("./try-catch-CqimbFJS.js");
const viem = require("viem");
const BAppABI = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor"
},
{
inputs: [
{
internalType: "address",
name: "target",
type: "address"
}
],
name: "AddressEmptyCode",
type: "error"
},
{
inputs: [],
name: "BAppAlreadyOptedIn",
type: "error"
},
{
inputs: [],
name: "BAppAlreadyRegistered",
type: "error"
},
{
inputs: [],
name: "BAppNotOptedIn",
type: "error"
},
{
inputs: [],
name: "DelegationAlreadyExists",
type: "error"
},
{
inputs: [],
name: "DelegationDoesNotExist",
type: "error"
},
{
inputs: [],
name: "DelegationExistsWithSameValue",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "implementation",
type: "address"
}
],
name: "ERC1967InvalidImplementation",
type: "error"
},
{
inputs: [],
name: "ERC1967NonPayable",
type: "error"
},
{
inputs: [],
name: "EmptyTokenList",
type: "error"
},
{
inputs: [],
name: "ExceedingPercentageUpdate",
type: "error"
},
{
inputs: [],
name: "FailedCall",
type: "error"
},
{
inputs: [],
name: "FeeAlreadySet",
type: "error"
},
{
inputs: [],
name: "InsufficientBalance",
type: "error"
},
{
inputs: [],
name: "InvalidAmount",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "caller",
type: "address"
},
{
internalType: "address",
name: "expectedOwner",
type: "address"
}
],
name: "InvalidBAppOwner",
type: "error"
},
{
inputs: [],
name: "InvalidInitialization",
type: "error"
},
{
inputs: [],
name: "InvalidMaxFeeIncrement",
type: "error"
},
{
inputs: [],
name: "InvalidPercentage",
type: "error"
},
{
inputs: [],
name: "InvalidPercentageIncrement",
type: "error"
},
{
inputs: [],
name: "InvalidStrategyFee",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "caller",
type: "address"
},
{
internalType: "address",
name: "expectedOwner",
type: "address"
}
],
name: "InvalidStrategyOwner",
type: "error"
},
{
inputs: [],
name: "InvalidToken",
type: "error"
},
{
inputs: [],
name: "LengthsNotMatching",
type: "error"
},
{
inputs: [],
name: "NoPendingFeeUpdate",
type: "error"
},
{
inputs: [],
name: "NoPendingObligationUpdate",
type: "error"
},
{
inputs: [],
name: "NoPendingWithdrawal",
type: "error"
},
{
inputs: [],
name: "NoPendingWithdrawalETH",
type: "error"
},
{
inputs: [],
name: "NotInitializing",
type: "error"
},
{
inputs: [],
name: "ObligationAlreadySet",
type: "error"
},
{
inputs: [],
name: "ObligationHasNotBeenCreated",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "owner",
type: "address"
}
],
name: "OwnableInvalidOwner",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address"
}
],
name: "OwnableUnauthorizedAccount",
type: "error"
},
{
inputs: [],
name: "ReentrancyGuardReentrantCall",
type: "error"
},
{
inputs: [],
name: "RequestTimeExpired",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "SafeERC20FailedOperation",
type: "error"
},
{
inputs: [],
name: "SharedRiskLevelAlreadySet",
type: "error"
},
{
inputs: [],
name: "TimelockNotElapsed",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "TokenAlreadyAddedToBApp",
type: "error"
},
{
inputs: [],
name: "TokenIsUsedByTheBApp",
type: "error"
},
{
inputs: [
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "TokenNoTSupportedByBApp",
type: "error"
},
{
inputs: [],
name: "UUPSUnauthorizedCallContext",
type: "error"
},
{
inputs: [
{
internalType: "bytes32",
name: "slot",
type: "bytes32"
}
],
name: "UUPSUnsupportedProxiableUUID",
type: "error"
},
{
inputs: [],
name: "ZeroAddressNotAllowed",
type: "error"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: false,
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "AccountMetadataURIUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "bAppAddress",
type: "address"
},
{
indexed: false,
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "BAppMetadataURIUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "bApp",
type: "address"
},
{
indexed: false,
internalType: "bytes",
name: "data",
type: "bytes"
},
{
indexed: false,
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
indexed: false,
internalType: "uint32[]",
name: "obligationPercentages",
type: "uint32[]"
}
],
name: "BAppOptedInByStrategy",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "bAppAddress",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: false,
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
indexed: false,
internalType: "uint32[]",
name: "sharedRiskLevel",
type: "uint32[]"
},
{
indexed: false,
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "BAppRegistered",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "bAppAddress",
type: "address"
},
{
indexed: false,
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
indexed: false,
internalType: "uint32[]",
name: "sharedRiskLevels",
type: "uint32[]"
}
],
name: "BAppTokensCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "bAppAddress",
type: "address"
},
{
indexed: false,
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
indexed: false,
internalType: "uint32[]",
name: "sharedRiskLevels",
type: "uint32[]"
}
],
name: "BAppTokensUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "delegator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "receiver",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "DelegationCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "delegator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "receiver",
type: "address"
}
],
name: "DelegationRemoved",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "delegator",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "receiver",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "DelegationUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint64",
name: "version",
type: "uint64"
}
],
name: "Initialized",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint32",
name: "newMaxFeeIncrement",
type: "uint32"
}
],
name: "MaxFeeIncrementSet",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "bApp",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "ObligationCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "bApp",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "ObligationUpdateProposed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "bApp",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "percentage",
type: "uint32"
},
{
indexed: false,
internalType: "bool",
name: "isFast",
type: "bool"
}
],
name: "ObligationUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "OwnershipTransferred",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "fee",
type: "uint32"
},
{
indexed: false,
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "StrategyCreated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "StrategyDeposit",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: false,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "proposedFee",
type: "uint32"
},
{
indexed: false,
internalType: "uint32",
name: "fee",
type: "uint32"
}
],
name: "StrategyFeeUpdateProposed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: false,
internalType: "address",
name: "owner",
type: "address"
},
{
indexed: false,
internalType: "uint32",
name: "fee",
type: "uint32"
},
{
indexed: false,
internalType: "uint32",
name: "oldFee",
type: "uint32"
}
],
name: "StrategyFeeUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: false,
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "StrategyMetadataURIUpdated",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
indexed: false,
internalType: "bool",
name: "isFast",
type: "bool"
}
],
name: "StrategyWithdrawal",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
indexed: true,
internalType: "address",
name: "account",
type: "address"
},
{
indexed: false,
internalType: "address",
name: "token",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "StrategyWithdrawalProposed",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "implementation",
type: "address"
}
],
name: "Upgraded",
type: "event"
},
{
inputs: [],
name: "ETH_ADDRESS",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "FEE_EXPIRE_TIME",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "FEE_TIMELOCK_PERIOD",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "MAX_PERCENTAGE",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "OBLIGATION_EXPIRE_TIME",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "OBLIGATION_TIMELOCK_PERIOD",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "UPGRADE_INTERFACE_VERSION",
outputs: [
{
internalType: "string",
name: "",
type: "string"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "WITHDRAWAL_EXPIRE_TIME",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "WITHDRAWAL_TIMELOCK_PERIOD",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address"
},
{
internalType: "address",
name: "bApp",
type: "address"
}
],
name: "accountBAppStrategy",
outputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
internalType: "uint32[]",
name: "sharedRiskLevels",
type: "uint32[]"
}
],
name: "addTokensToBApp",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
}
],
name: "bAppOwners",
outputs: [
{
internalType: "address",
name: "owner",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "bAppTokens",
outputs: [
{
internalType: "uint32",
name: "value",
type: "uint32"
},
{
internalType: "bool",
name: "isSet",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "uint32",
name: "obligationPercentage",
type: "uint32"
}
],
name: "createObligation",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "fee",
type: "uint32"
},
{
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "createStrategy",
outputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address"
},
{
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "delegateBalance",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "delegator",
type: "address"
},
{
internalType: "address",
name: "account",
type: "address"
}
],
name: "delegations",
outputs: [
{
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "contract IERC20",
name: "token",
type: "address"
},
{
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "depositERC20",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
name: "depositETH",
outputs: [],
stateMutability: "payable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "uint32",
name: "obligationPercentage",
type: "uint32"
}
],
name: "fastUpdateObligation",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "contract IERC20",
name: "token",
type: "address"
},
{
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "fastWithdrawERC20",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "fastWithdrawETH",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
name: "finalizeFeeUpdate",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "finalizeUpdateObligation",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "contract IERC20",
name: "token",
type: "address"
}
],
name: "finalizeWithdrawal",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
name: "finalizeWithdrawalETH",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "owner",
type: "address"
},
{
internalType: "uint32",
name: "_maxFeeIncrement",
type: "uint32"
}
],
name: "initialize",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "maxFeeIncrement",
outputs: [
{
internalType: "uint32",
name: "",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "address",
name: "bApp",
type: "address"
}
],
name: "obligationRequests",
outputs: [
{
internalType: "uint32",
name: "percentage",
type: "uint32"
},
{
internalType: "uint32",
name: "requestTime",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "obligations",
outputs: [
{
internalType: "uint32",
name: "percentage",
type: "uint32"
},
{
internalType: "bool",
name: "isSet",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
internalType: "uint32[]",
name: "obligationPercentages",
type: "uint32[]"
},
{
internalType: "bytes",
name: "data",
type: "bytes"
}
],
name: "optInToBApp",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "uint32",
name: "proposedFee",
type: "uint32"
}
],
name: "proposeFeeUpdate",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "uint32",
name: "obligationPercentage",
type: "uint32"
}
],
name: "proposeUpdateObligation",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "token",
type: "address"
},
{
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "proposeWithdrawal",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "uint256",
name: "amount",
type: "uint256"
}
],
name: "proposeWithdrawalETH",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "proxiableUUID",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
internalType: "uint32[]",
name: "sharedRiskLevels",
type: "uint32[]"
},
{
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "registerBApp",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address"
}
],
name: "removeDelegatedBalance",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [],
name: "renounceOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
}
],
name: "strategies",
outputs: [
{
internalType: "address",
name: "owner",
type: "address"
},
{
internalType: "uint32",
name: "fee",
type: "uint32"
},
{
internalType: "uint32",
name: "feeProposed",
type: "uint32"
},
{
internalType: "uint32",
name: "feeRequestTime",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "account",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "strategyTokenBalances",
outputs: [
{
internalType: "uint256",
name: "balance",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "delegator",
type: "address"
}
],
name: "totalDelegatedPercentage",
outputs: [
{
internalType: "uint32",
name: "totalPercentage",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address"
}
],
name: "transferOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "updateAccountMetadataURI",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "updateBAppMetadataURI",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "bApp",
type: "address"
},
{
internalType: "address[]",
name: "tokens",
type: "address[]"
},
{
internalType: "uint32[]",
name: "sharedRiskLevels",
type: "uint32[]"
}
],
name: "updateBAppTokens",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address"
},
{
internalType: "uint32",
name: "percentage",
type: "uint32"
}
],
name: "updateDelegatedBalance",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "string",
name: "metadataURI",
type: "string"
}
],
name: "updateStrategyMetadataURI",
outputs: [],
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "newImplementation",
type: "address"
},
{
internalType: "bytes",
name: "data",
type: "bytes"
}
],
name: "upgradeToAndCall",
outputs: [],
stateMutability: "payable",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "usedTokens",
outputs: [
{
internalType: "uint32",
name: "bAppsCounter",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "uint32",
name: "strategyId",
type: "uint32"
},
{
internalType: "address",
name: "account",
type: "address"
},
{
internalType: "address",
name: "token",
type: "address"
}
],
name: "withdrawalRequests",
outputs: [
{
internalType: "uint256",
name: "amount",
type: "uint256"
},
{
internalType: "uint32",
name: "requestTime",
type: "uint32"
}
],
stateMutability: "view",
type: "function"
}
];
var symbolTag = "[object Symbol]";
function isSymbol(value) {
return typeof value == "symbol" || tryCatch$1.isObjectLike(value) && tryCatch$1.baseGetTag(value) == symbolTag;
}
var reWhitespace = /\s/;
function trimmedEndIndex(string) {
var index = string.length;
while (index-- && reWhitespace.test(string.charAt(index))) {
}
return index;
}
var reTrimStart = /^\s+/;
function baseTrim(string) {
return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
}
var NAN = 0 / 0;
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
var reIsBinary = /^0b[01]+$/i;
var reIsOctal = /^0o[0-7]+$/i;
var freeParseInt = parseInt;
function toNumber(value) {
if (typeof value == "number") {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (tryCatch$1.isObject(value)) {
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
value = tryCatch$1.isObject(other) ? other + "" : other;
}
if (typeof value != "string") {
return value === 0 ? value : +value;
}
value = baseTrim(value);
var isBinary = reIsBinary.test(value);
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
}
var INFINITY = 1 / 0, MAX_INTEGER = 17976931348623157e292;
function toFinite(value) {
if (!value) {
return value === 0 ? value : 0;
}
value = toNumber(value);
if (value === INFINITY || value === -INFINITY) {
var sign = value < 0 ? -1 : 1;
return sign * MAX_INTEGER;
}
return value === value ? value : 0;
}
function toInteger(value) {
var result = toFinite(value), remainder = result % 1;
return result === result ? remainder ? result - remainder : result : 0;
}
function baseSlice(array, start, end) {
var index = -1, length = array.length;
if (start < 0) {
start = -start > length ? 0 : length + start;
}
end = end > length ? length : end;
if (end < 0) {
end += length;
}
length = start > end ? 0 : end - start >>> 0;
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
}
var nativeCeil = Math.ceil, nativeMax = Math.max;
function chunk(array, size, guard) {
if (size === void 0) {
size = 1;
} else {
size = nativeMax(toInteger(size), 0);
}
var length = array == null ? 0 : array.length;
if (!length || size < 1) {
return [];
}
var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
while (index < length) {
result[resIndex++] = baseSlice(array, index, index += size);
}
return result;
}
const getValidatorsBalance = async (apis, args) => {
const validators = await apis.bam.getValidatorsByAccount(args);
if (!validators.length)
return {
account: args.account,
validators: [],
balance: "0"
};
const chunks = chunk(validators, 500);
const results = await Promise.all(
chunks.map(
(chunk2) => apis.beacon.getValidatorBalances({
stateId: "head",
validatorIds: chunk2
})
)
);
const data = results.flatMap((v) => v.data);
const totalBalance = viem.parseGwei(
data.reduce((acc, v) => {
return acc + BigInt(v.balance);
}, 0n).toString()
);
return {
account: args.account,
validators,
balance: totalBalance
};
};
const getParticipantWeights = async (apis, args) => {
const bAppData = await apis.bam.getParticipantWeightInput(args);
if (!bAppData) {
throw new Error("bApp not found");
}
const strategyWeightsMap = /* @__PURE__ */ new Map();
const riskByTokenAndStrategy = /* @__PURE__ */ new Map();
for (const strategyData of bAppData.strategies) {
const strategy = strategyData.strategy;
strategyWeightsMap.set(strategy.id, {
id: strategy.id,
tokenWeights: []
});
const tokenRisks = /* @__PURE__ */ new Map();
for (const obligation of strategyData.obligations) {
const token = obligation.token.toLowerCase();
const currentRisk = tokenRisks.get(token) ?? 0;
tokenRisks.set(token, currentRisk + Number(obligation.percentage) / 1e4);
}
for (const [token, risk] of tokenRisks) {
if (!riskByTokenAndStrategy.has(token)) {
riskByTokenAndStrategy.set(token, /* @__PURE__ */ new Map());
}
riskByTokenAndStrategy.get(token).set(strategy.id, risk);
}
}
for (const bAppToken of bAppData.bAppTokens) {
const token = bAppToken.token;
const tokenLower = token.toLowerCase();
const beta = Number(bAppToken.sharedRiskLevel) / 1e4;
const totalObligatedBalance = BigInt(bAppToken.totalObligatedBalance);
if (totalObligatedBalance === 0n) continue;
let normalizationDenominator = 0;
const tempWeights = [];
for (const strategyData of bAppData.strategies) {
const strategy = strategyData.strategy;
const strategyId = strategy.id;
const obligation = strategyData.obligations.find(
(ob) => ob.token.toLowerCase() === tokenLower
);
if (!obligation) continue;
const balance = strategy.balances.find((bal) => bal.token.toLowerCase() === tokenLower);
if (!balance) continue;
const obligatedBalance = BigInt(obligation.obligatedBalance);
const risk = Math.max(1, riskByTokenAndStrategy.get(tokenLower)?.get(strategyId) ?? 0);
const exponentialTerm = Math.exp(-beta * risk);
const term = Number(obligatedBalance) / Number(totalObligatedBalance) * exponentialTerm;
normalizationDenominator += term;
tempWeights.push({
strategyId,
weight: term
});
}
const cToken = normalizationDenominator === 0 ? 0 : 1 / normalizationDenominator;
for (const { strategyId, weight } of tempWeights) {
const strategyWeight = strategyWeightsMap.get(strategyId);
if (strategyWeight) {
strategyWeight.tokenWeights.push({
token,
weight: weight * cToken
});
}
}
}
const delegatedBalances = /* @__PURE__ */ new Map();
let totalBAppBalance = 0;
for (const strategyData of bAppData.strategies) {
const strategy = strategyData.strategy;
if (!strategy.owner.delegators.length) continue;
const balances = await Promise.all(
strategy.owner.delegators.filter((d) => Number(d.percentage) > 0).map(async (delegator) => {
const response = await getValidatorsBalance(apis, {
account: delegator.delegator.id
});
return {
delegated: Number(response.balance) * Number(delegator.percentage) / 1e4
};
})
);
const delegatedBalance = balances.reduce((acc, balance) => acc + balance.delegated, 0);
delegatedBalances.set(strategy.id, delegatedBalance);
totalBAppBalance += delegatedBalance;
}
for (const [strategyId, delegatedBalance] of delegatedBalances.entries()) {
const strategyWeight = strategyWeightsMap.get(strategyId);
if (strategyWeight) {
strategyWeight.validatorBalanceWeight = Number(delegatedBalance) / Number(totalBAppBalance);
}
}
return Array.from(strategyWeightsMap.values());
};
const getDelegatedBalances = async (apis, args) => {
const bAppDelegators = await apis.bam.getBAppDelegators(args);
if (!bAppDelegators)
return {
bAppTotalDelegatedBalance: 0n,
bAppTotalDelegatedBalances: []
};
const bAppTotalDelegatedBalances = await Promise.all(
bAppDelegators.strategies.map(async (strategy) => {
const delegation = (await Promise.all(
strategy.strategy.owner.delegators.map(
(d) => getValidatorsBalance(apis, {
account: d.delegator.id
})
)
)).reduce((acc, balance) => acc + BigInt(balance.balance), 0n);
return {
strategyId: strategy.strategy.id,
delegation
};
})
);
const bAppTotalDelegatedBalance = bAppTotalDelegatedBalances.reduce(
(acc, balance) => acc + balance.delegation,
0n
);
return {
bAppTotalDelegatedBalance,
bAppTotalDelegatedBalances
};
};
const getObligatedBalances$1 = async (apis, args) => {
const bAppObligations = await apis.bam.getObligatedBalances(args);
if (!bAppObligations) return [];
return bAppObligations;
};
const getBasedAppsAPI = (apis) => {
return {
getValidatorsBalance: getValidatorsBalance.bind(null, apis),
getParticipantWeights: getParticipantWeights.bind(null, apis),
getDelegatedBalances: getDelegatedBalances.bind(null, apis),
getObligatedBalances: getObligatedBalances$1.bind(null, apis)
};
};
function normalize(strArray) {
const resultArray = [];
if (strArray.length === 0) {
return "";
}
strArray = strArray.filter((part) => part !== "");
if (typeof strArray[0] !== "string") {
throw new TypeError("Url must be a string. Received " + strArray[0]);
}
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
strArray[0] = strArray.shift() + strArray[0];
}
if (strArray[0] === "/" && strArray.length > 1) {
strArray[0] = strArray.shift() + strArray[0];
}
if (strArray[0].match(/^file:\/\/\//)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
} else if (!strArray[0].match(/^\[.*:.*\]/)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
}
for (let i = 0; i < strArray.length; i++) {
let component = strArray[i];
if (typeof component !== "string") {
throw new TypeError("Url must be a string. Received " + component);
}
if (i > 0) {
component = component.replace(/^[\/]+/, "");
}
if (i < strArray.length - 1) {
component = component.replace(/[\/]+$/, "");
} else {
component = component.replace(/[\/]+$/, "/");
}
if (component === "") {
continue;
}
resultArray.push(component);
}
let str = "";
for (let i = 0; i < resultArray.length; i++) {
const part = resultArray[i];
if (i === 0) {
str += part;
continue;
}
const prevPart = resultArray[i - 1];
if (prevPart && prevPart.endsWith("?") || prevPart.endsWith("#")) {
str += part;
continue;
}
str += "/" + part;
}
str = str.replace(/\/(\?|&|#[^!])/g, "$1");
const [beforeHash, afterHash] = str.split("#");
const parts = beforeHash.split(/(?:\?|&)+/).filter(Boolean);
str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&") + (afterHash && afterHash.length > 0 ? "#" + afterHash : "");
return str;
}
function urlJoin(...args) {
const parts = Array.from(Array.isArray(args[0]) ? args[0] : args);
return normalize(parts);
}
const getValidatorBalances = (baseApi, args) => {
return fetch(urlJoin(baseApi, `/eth/v1/beacon/states/${args.stateId}/validator_balances`), {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(args.validatorIds)
}).then((res) => res.json());
};
const getBeaconChainAPI = (endpoint) => {
return {
getValidatorBalances: getValidatorBalances.bind(null, endpoint)
};
};
const checkOperatorDKGEnabled = (baseApi, dkgAddresses) => {
return fetch(urlJoin(baseApi, `/operators/dkg_health_check`), {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
dkgAddresses
})
}).then(
(res) => res.json()
);
};
const getSSVAPI = (endpoint) => {
return {
checkOperatorDKGEnabled: checkOperatorDKGEnabled.bind(null, endpoint)
};
};
const GetStrategyBAppOptInsDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
name: { kind: "Name", value: "GetStrategyBAppOptIns" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: { kind: "Variable", name: { kind: "Name", value: "bAppId" } },
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "Bytes" } }
}
}
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "strategyBAppOptIns" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "where" },
value: {
kind: "ObjectValue",
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "bApp_" },
value: {
kind: "ObjectValue",
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "id" },
value: { kind: "Variable", name: { kind: "Name", value: "bAppId" } }
}
]
}
}
]
}
}
],
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
{
kind: "Field",
name: { kind: "Name", value: "strategy" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "balances" },
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "token" } },
{ kind: "Field", name: { kind: "Name", value: "balance" } }
]
}
}
]
}
},
{
kind: "Field",
name: { kind: "Name", value: "obligations" },
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "token" } },
{ kind: "Field", name: { kind: "Name", value: "percentage" } }
]
}
}
]
}
}
]
}
}
]
};
const GetParticipantWeightInputDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
name: { kind: "Name", value: "GetParticipantWeightInput" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: { kind: "Variable", name: { kind: "Name", value: "bAppId" } },
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "ID" } }