The LiquidSDK
class is the main entry point for interacting with the Liquid protocol.
constructor(rpcUrl: string, passKeyImpl: PassKeyImplementation)
rpcUrl
: The URL of the Ethereum RPC endpoint to connect to.passKeyImpl
: An implementation of PassKey functions for either web or mobile environments.
import { LiquidSDK, webPassKeys } from '@liquid/sdk';
const sdk = new LiquidSDK('https://mainnet.infura.io/v3/YOUR-PROJECT-ID', webPassKeys);
Creates a new smart account using PassKey authentication.
async createSmartAccount(username: string): Promise<{ address: Address; passKeyId: string }>
username
: A string representing the username for the account.
A Promise that resolves to an object containing:
address
: The address of the newly created smart account.passKeyId
: The ID of the PassKey associated with this account.
- Throws
PassKeyError
if account creation fails.
try {
const { address, passKeyId } = await sdk.createSmartAccount('[email protected]');
console.log(`Smart account created at ${address} with PassKey ID ${passKeyId}`);
} catch (error) {
console.error('Failed to create smart account:', error);
}
Executes a series of actions (swap, deposit, withdraw) on behalf of the account.
async executeStrategy(account: Address, passKeyId: string, actions: Action[]): Promise<string>
account
: The address of the smart account executing the strategy.passKeyId
: The ID of the PassKey associated with the account.actions
: An array ofAction
objects representing the strategy to execute.
A Promise that resolves to the transaction hash of the executed strategy.
- Throws
UserOperationError
if strategy execution fails.
const actions = [
{
type: 'APPROVE',
token: '0x...',
spender: '0x...',
amount: 1000000000000000000n, // 1 TOKEN
},
{
type: 'SWAP',
tokenIn: { address: '0x...', symbol: 'TOKEN_A', decimals: 18 },
tokenOut: { address: '0x...', symbol: 'TOKEN_B', decimals: 18 },
amountIn: 1000000000000000000n, // 1 TOKEN_A
isStable: true,
},
{
type: 'DEPOSIT',
tokenA: { address: '0x...', symbol: 'TOKEN_B', decimals: 18 },
tokenB: { address: '0x...', symbol: 'TOKEN_C', decimals: 18 },
amountA: 500000000000000000n, // 0.5 TOKEN_B
amountB: 1000000000000000000n, // 1 TOKEN_C
isStable: false,
},
];
try {
const txHash = await sdk.executeStrategy(accountAddress, passKeyId, actions);
console.log(`Strategy executed with transaction hash: ${txHash}`);
} catch (error) {
console.error('Failed to execute strategy:', error);
}
Retrieves all liquidity pools that the user has participated in.
async getUserPools(userAddress: Address): Promise<PoolDetails[]>
userAddress
: The address of the user to get pools for.
A Promise that resolves to an array of PoolDetails
objects.
- Throws
AerodromeError
if fetching user pools fails.
try {
const pools = await sdk.getUserPools(accountAddress);
console.log('User pools:', pools);
} catch (error) {
console.error('Failed to get user pools:', error);
}
Gets the balance of a specific token for a given user address.
async getTokenBalance(tokenAddress: Address, userAddress: Address): Promise<string>
tokenAddress
: The address of the token to check the balance for.userAddress
: The address of the user to check the balance of.
A Promise that resolves to a string representing the token balance.
- Throws
SDKError
if fetching token balance fails.
try {
const balance = await sdk.getTokenBalance(tokenAddress, accountAddress);
console.log(`Token balance: ${balance}`);
} catch (error) {
console.error('Failed to get token balance:', error);
}
Retrieves a list of supported tokens.
async getTokenList(): Promise<TokenInfo[]>
A Promise that resolves to an array of TokenInfo
objects.
- Throws
SDKError
if fetching token list fails.
try {
const tokens = await sdk.getTokenList();
console.log('Supported tokens:', tokens);
} catch (error) {
console.error('Failed to get token list:', error);
}
Gets a quote for adding or removing liquidity.
async getQuote(
tokenA: TokenInfo,
tokenB: TokenInfo,
isDeposit: boolean,
amount: string,
isStable: boolean,
): Promise
tokenA
: Information about the first token in the pair.tokenB
: Information about the second token in the pair.isDeposit
: Whether this is a deposit (true) or withdrawal (false).amount
: The amount of tokenA (for deposit) or LP tokens (for withdrawal).isStable
: Whether this is a stable or volatile pool.
A Promise that resolves to an object containing the amounts and liquidity.
- Throws
AerodromeError
if fetching the quote fails.
try {
const quote = await sdk.getQuote(
{ address: '0x...', symbol: 'TOKEN_A', decimals: 18 },
{ address: '0x...', symbol: 'TOKEN_B', decimals: 18 },
true,
'1000000000000000000', // 1 TOKEN_A
true
);
console.log('Quote:', quote);
} catch (error) {
console.error('Failed to get quote:', error);
}
Note: The passkeyId
is crucial for identifying which PassKey to use in future authentications.
It should be stored securely and associated with the user's account. It is not a public key or signature, but rather an identifier for the credential.