Skip to main content

Euler SDK

The Euler SDK is a developer toolkit designed to simplify integration with the Euler protocol. It provides off-chain utilities for interacting with Euler’s on-chain smart contracts, enabling developers to efficiently query data, manage positions, compute sub-account addresses, and execute transactions.

Computing sub-account addresses

Euler’s sub-accounts are computed using a bitwise XOR (^) operation between the owner's Ethereum address and the sub-account ID. Below is a JavaScript implementation to compute sub-account addresses off-chain.

JavaScript implementation

const { ethers } = require("ethers");

/**
* @notice Computes the sub-account address for a given owner and sub-account ID.
* @param {string} owner - The Ethereum address of the main account.
* @param {number} subAccountId - The sub-account ID (must be >= 0 and <= 255).
* @return {string} The computed sub-account address.
*/
function getEulerSubAccount(owner, subAccountId) {
if (subAccountId === 0) return owner; // Main account remains unchanged
return ethers.utils.getAddress(
ethers.BigNumber.from(owner).xor(subAccountId).toHexString()
);
}

// Example usage:
const owner = "0xYourEthereumAddressHere";
console.log(getEulerSubAccount(owner, 1)); // Get Sub-Account Address