utils sub-class
The following readme describes all the functions and their parameters exposed by the utils
class of the Stakehouse SDK.
checkKeystorePass function
This function allows to validate the password being provided to with the keystore file.
Input Parameters
password: String provided by the user for the keystore file
Using checkKeystorePass function
await sdk.utils.checkKeystorePass(password);
Return Parameter
Returns boolean values. If the password is valid, it returns true, otherwise false.
add0x function
add0x
function checks if a parameter has 0x
in front, if not, then it adds it.
Input Parameters
data: String, Buffer or Object where 0x
may be needed
Using add0x function
await sdk.utils.add0x(data);
Return Parameter
Returns data with 0x
in front.
remove0x function
remove0x
function checks if a parameter has 0x
in front, if yes, then it removes it.
Input Parameters
data: String, Buffer or Object where 0x
shouldn't be
Using remove0x function
await sdk.utils.remove0x(data);
Return Parameter
Returns data without 0x
in front.
getPersonalSignInitials function
It is used to sign a message containing blsPublicKey
, blsSignature
, lifecycleStatus
and deadline
which makes sure that that the message signer is the owner or the representative of the provided blsPublicKey
. This method is a crucial step for the deposit router to stake and create a validator.
Input Parameters
blsPublicKey: BLS Public Key of user
blsSignature: BLS Signature corresponding to the BLS Public Key
account: ETH1 account address corresponding to the BLS Public Key
Using getPersonalSignInitials function
await sdk.utils.getPersonalSignInitials(blsPublicKey, blsSignature, account);
Return Parameter
Returns a JSON data comprising of JSON message, hex of the JSON message, and signature of the hex.
generateCredentials function
It is used to generate BLS credentials (deposit data file and the keystore) protected by the user provided password. It also provides an option to store the generated files in the user provided location. It is an optional feature to write the generated BLS keystore to a specific location on the file system. However, such a feature is not available from the browser.
Input Parameters
password: User's password
Using generateCredentials function
await sdk.utils.generateCredentials(password);
Return Parameter
Returns a JSON data comprising of depositObject and keystore.
{
"depositObject": [
{
"pubkey": "9584423b45c1d8919fdc0caec208b72a11ee0582790a49f97364fb6...",
"withdrawal_credentials": "010000000000000000000000f847b44695d33e9...",
"amount": 32000000000,
"signature": "a531bf2f681a442df6cfb72999534af919fef5af51f4c29e8905...",
"deposit_message_root": "3805f963284b308fc274fed64062c61995113feb3...",
"deposit_data_root": "25aa910ceb901858c76add081c3aa45fb60414e7ea99...",
"fork_version": "00001020",
"eth2_network_name": "prater",
"deposit_cli_version": "1.2.0"
}
],
"keystore": {
"version": 4,
"uuid": "c7534e8b-445e-4697-a554-125af3354e6d",
"path": "m/12381/60/0/0",
"pubkey": "9584423b45c1d8919fdc0caec208b72a11ee0582790a49f97364fb650...",
"crypto": {
"kdf": {
"function": "pbkdf2",
"params": {
"dklen": 32,
"c": 262144,
"prf": "hmac-sha256",
"salt": "81c430ea7f43ee3a527d8282e758a01545902842849e637f27770..."
},
"message": ""
},
"checksum": {
"function": "sha256",
"params": {},
"message": "e4180d47bd4de58452189048e4d1862eb8a2c98fabcad1acb5a7..."
},
"cipher": {
"function": "aes-128-ctr",
"params": {
"iv": "4379bdef0f24af9a12f9e071c6db60e3"
},
"message": "ed1e79d52b7aaa22965158deb330f57b21a8f7bcbeb3752b2a73..."
}
}
}
}
getValidatorLifecycleStatus function
It returns the lifecycle status of the validator.
Input Parameters
blsPublicKey: BLS Public Key of the Validator
Using getValidatorLifecycleStatus function
await sdk.utils.getValidatorLifecycleStatus(blsPublicKey);
Return Parameter
Returns lifecycle status of the validator which can range from 0 to 4.
- UNBEGUN = 0
- INITIALS_REGISTERED = 1
- DEPOSIT_COMPLETED = 2
- TOKENS_MINTED = 3
- EXITED = 4
formDepositDataRoot function
It is used to form DepositData SSZ object required by Ethereum Foundation deposit contract. The exact fields are specified in the Beacon Chain spec found here.
Input Parameters
blsPublicKey: BLS Public Key
blsSignature: BLS Signature
Using formDepositDataRoot function
await sdk.utils.formDepositDataRoot(blsPublicKey, blsSignature);
Return Parameter
Returns depositData.
getLastDepositIndex function
It is used to get the last deposit Index.
Input Parameters
blsPublicKey: BLS Public Key of the Validator
Using getLastDepositIndex function
await sdk.utils.getLastDepositIndex(blsPublicKey);
Return Parameter
Returns the last deposit index.
getDETHBalanceInIndex function
This function allows users to fetch their dETH balance in the Index.
Input Parameters
blsPublicKey: BLS Public Key
Using getDETHBalanceInIndex function
await sdk.utils.getDETHBalanceInIndex(blsPublicKey);
Return Parameter
Returns the dETH balance
getSLOTBalanceInVault function
This function allows users to fetch their collateralised SLOT balance.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
userAddress: Ethereum execution layer address of the user
blsPublicKey: BLS Public Key of the KNOT
Using getSLOTBalanceInVault function
await sdk.utils.getSLOTBalanceInVault(stakehouseAddress, userAddress, blsPublicKey);
Return Parameter
Returns the collateralised SLOT balance in Big Numbers
getsETHAddress function
This function allows users to get the sETH token address. sETH address differs for every Stakehouse.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
Using getsETHAddress function
await sdk.utils.getsETHAddress(stakehouseAddress);
Return Parameter
Returns the sETH address.
getsETHBalance function
This function allows users to fetch their sETH balance.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
userAddress: Ethereum execution layer address of the user
Using getsETHBalance function
await sdk.utils.getsETHBalance(stakehouseAddress, userAddress);
Return Parameter
Returns the sETH balance in Big Numbers
getGenericERC20WalletBalance function
This function allows users to get the balance of any ERC-20 token they hold in their wallet.
Input Parameters
tokenAddress: ERC-20 token address
userAddress: Ethereum execution layer address of the user
Using getGenericERC20WalletBalance function
await sdk.utils.getGenericERC20WalletBalance(tokenAddress, userAddress);
Return Parameter
Returns the ERC-20 balance for a particular token that the user hold.
currentSlashedAmountOfSLOTForKnot function
This function allows users to know the amount of SLOTs slashed for a particular KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using currentSlashedAmountOfSLOTForKnot function
await sdk.utils.currentSlashedAmountOfSLOTForKnot(blsPublicKey);
Return Parameter
Returns the amount of SLOTs slashed for a particular KNOT.
calculateExitFee function
This function allows users to know the amount of ETH required to exit the Stakehouse.
Input Parameters
authenticatedReport: Report returned by the authenticateReport
function
Using calculateExitFee function
await sdk.utils.calculateExitFee(authenticatedReport);
Return Parameter
Returns the exit fees in Big Numbers.
getNumberOfCollateralisedSlotOwnersForKnot function
This function allows users to know the number of collateralised owners for a KNOT. If a KNOT has been slashed and some other user tops up this KNOT, then the other user becomes a collateralised owner of this KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using getNumberOfCollateralisedSlotOwnersForKnot function
await sdk.utils.getNumberOfCollateralisedSlotOwnersForKnot(blsPublicKey);
Return Parameter
Returns the number of owners for a KNOT in Big Numbers.
getStakehouseRedemptionRate function
This function allows users to fetch the redemption rate for any Stakehouse. Learn more about SLOT tokens (sETH) here.
Input Parameters
stakehouseAddress: Stakehouse address for which the user wants to know the redemption rate of
Using getStakehouseRedemptionRate function
await sdk.utils.getStakehouseRedemptionRate(stakehouseAddress);
Return Parameter
Returns the redemption rate for a stakehouse.
getStakehouseExchangeRate function
This function allows users to get the exchange rate for a Stakehouse. The exchange rate works between sETH and SLOT. Learn more about SLOT tokens (sETH) here.
Input Parameters
stakehouseAddress: Stakehouse address that the user wants to get the exchange rate of
Using getStakehouseExchangeRate function
await sdk.utils.getStakehouseExchangeRate(stakehouseAddress);
Return Parameter
Returns the exchange rate of a stakehouse.
getStakehouseSETHRedemptionThreshold function
This function allows users to get the redemption threshold for sETH for a particular Stakehouse. The redemption threshold is the total number of collateralised sETH a user must hold across all KNOTs in a house in order to Rage Quit. It is equal to 4 SLOT * redemption rate.
Input Parameters
stakehouseAddress: Stakehouse address
Using getStakehouseSETHRedemptionThreshold function
await sdk.utils.getStakehouseSETHRedemptionThreshold(stakehouseAddress);
Return Parameter
Returns the sETH redemption threshold.
getTotalUserCollateralisedSETHBalanceInHouse function
This function allows users to fetch the collateralised sETH balance for a Stakehouse.
Input Parameters
stakehouseAddress: Stakehouse address
userAddress: Ethereum execution layer address
Using getTotalUserCollateralisedSETHBalanceInHouse function
await sdk.utils.getTotalUserCollateralisedSETHBalanceInHouse(stakehouseAddress, userAddress);
Return Parameter
Returns the sETH balance for the Stakehouse.
totalFundsInKNOTQueue function
This function allows users to fetch the ETH amount in the queue. The queue will have a non zero amount of ETH for a given knot if SLOT has been topped up and the aggregate of the top ups are less than 1 ETH.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using totalFundsInKNOTQueue function
await sdk.utils.totalFundsInKNOTQueue(blsPublicKey);
Return Parameter
Returns the balance in Big Numbers.
associatedIndexIdForKnot function
This function allows users to find the primary index for a KNOT.
Input Parameters
blsPublicKey: BLS Public of the KNOT
Using associatedIndexIdForKnot function
await sdk.utils.associatedIndexIdForKnot(blsPublicKey);
Return Parameter
Returns the index ID for the KNOT in Big Numbers.
rageQuitChecks function
This function allows users to check if a particular KNOT is eligible to Rage Quit.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
userAddress: Ethereum execution layer address of the user (to whom the KNOT belongs)
authenticatedReport: report returned by the authenticateReport
function
Using rageQuitChecks function
await sdk.utils.rageQuitChecks(stakehouseAddress, userAddress, authenticatedReport);
Return Parameter
Returns true
if the KNOT is eligible to Rage Quit. Otherwise, it throws an error.
indexIdToOwner function
This function allows the user to fetch the owner of an index.
Input Parameters
indexID: savETH index ID
Using indexIdToOwner function
await sdk.utils.indexIdToOwner(indexID);
Return Parameter
Returns index owner's address.
isBalanceLower function
This function allows the user to check if the KNOT's balance is below the last known balance.
Input Parameters
beaconNodeURL: Beacon Node URL
blsPublicKey: BLS Public Key of the KNOT
Using isBalanceLower function
await sdk.utils.isBalanceLower(beaconNodeURL, blsPublicKey);
Return Parameter
Returns an object which contains result
, metadata
and report
.
result
: boolean. true
if the balance is lower and false
otherwise
metadata
: object containing the last known balance and current balance
report
: authenticated balance report.
dETHToSavETH function
This function allows the users to find the equivalent amount of savETH for their dETH tokens.
Input Parameters
amount: amount of dETH tokens
Using dETHToSavETH function
await sdk.utils.dETHToSavETH(amount);
Return Parameter
Returns the equivalent amount of savETH in Big Numbers.
savETHToDETH function
This function allows the user to get the equivalent amount of dETH for their savETH.
Input Parameters
amount: amount of savETH tokens
Using savETHToDETH function
await sdk.utils.savETHToDETH(amount);
Return Parameter
Returns the savETH amount in Big Numbers.
dETHRewardsMintedForKNOT function
This function allows user to fetch the dETH rewards for a particular KNOT
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using dETHRewardsMintedForKNOT function
await sdk.utils.dETHRewardsMintedForKNOT(blsPublicKey);
Return Parameter
Returns the amount of dETH rewards minted in Big Numbers.
dETHRequiredForIsolation function
This function helps the user to calculate the dETH required to isolate the KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using dETHRequiredForIsolation function
await sdk.utils.dETHRequiredForIsolation(blsPublicKey);
Return Parameter
Returns the dETH amount in Big Numbers.
savETHRequiredForIsolation function
This function allows users to calculate the amount of savETH required to isolate a KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using savETHRequiredForIsolation function
await sdk.utils.savETHRequiredForIsolation(blsPublicKey);
Return Parameter
Returns the amount in Big Numbers.
getKNOTNonce function
This function allows users to get the nonce for a KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using getKNOTNonce function
await sdk.utils.getKNOTNonce(blsPublicKey);
Return Parameter
Returns the nonce.
getLastKnownReportForKNOT function
This function allows users to get the last Balance Report for a KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
Using getLastKnownReportForKNOT function
await sdk.utils.getLastKnownReportForKNOT(blsPublicKey);
Return Parameter
Returns the Balance Report object.
updateSavETHIndexName function
This function allows the user to update the name of their savETH index.
Input Parameters
indexID: index ID of user's index
name: new name for the index
Using updateSavETHIndexName function
await sdk.utils.updateSavETHIndexName(indexID, name);
Return Parameter
Returns the transaction data
topUpSlashedSlot function
This function allows users to top-up a KNOT that has been leaking.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
blsPublicKey: BLS Public Key of the KNOT
recipient: Ethereum execution layer address of the recipient of the collateralised SLOT
amount: number of slashed SLOTs to top-up. (0 < amount <= slashed SLOTs)
ethValue: ETH to be provided to the function.
Using topUpSlashedSlot function
await sdk.utils.topUpSlashedSlot(stakehouseAddress, blsPublicKey, recipient, amount, ethValue);
Return Parameter
Returns the transaction data
topUpSlashedSlotWithOneEth function
This function allows users to top-up slashed KNOTs with 1 ETH.
Input Parameters
stakehouseAddress: Stakehouse address of the KNOT
blsPublicKey: BLS Public Key of the KNOT
recipient: Ethereum execution layer address of the depositor of KNOT
Using topUpSlashedSlotWithOneEth function
await sdk.utils.topUpSlashedSlotWithOneEth(stakehouseAddress, blsPublicKey, recipient);
Return Parameter
Returns the transaction data.
topUpKNOT function
This function allows users to top-up any KNOT.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT
ethValue: amount of ETH to top-up the KNOT
Using topUpKNOT function
await sdk.utils.topUpKNOT(blsPublicKey, ethValue);
Return Parameter
Returns the transaction data.
topUpKNOTWithOneEth function
This function allows users to top-up any KNOT with 1 ETH.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT.
Using topUpKNOTWithOneEth function
await sdk.utils.topUpKNOTWithOneEth(blsPublicKey);
Return Parameter
Returns the transaction data.
dETHMetadata function
This function allows the users to get the metadata related to dETH such as dETH in circulation and dETH in Open Index.
Using dETHMetadata function
await sdk.utils.dETHMetadata();
Return Parameter
Returns the metadata.
getStakehouse function
This function allows users to fetch the Stakehouse address for any KNOT
Input Parameters
blsPublicKey: BLS Public Key of the KNOT.
Using getStakehouse function
await sdk.utils.getStakehouse(blsPublicKey)
Return Parameter
Returns the Stakehouse address if the KNOT exists in the Stakehouse Universe. Otherwise, zero address is returned.
isPartOfStakehouse function
This function allows users to check if the KNOT is a part of Stakehouse universe or not.
Input Parameters
blsPublicKey: BLS Public Key of the KNOT.
Using isPartOfStakehouse function
await sdk.utils.isPartOfStakehouse(blsPublicKey)
Return Parameter
Returns boolean. true
if the KNOT exists, false
otherwise.