Package Exports
- @concrete-xyz/sdk
Readme
@concrete-xyz/sdk
SDK for interacting with vault contracts on multiple EVM networks.
⚠️ Beta Warning: This package is currently in closed beta. If you encounter any issues, please contact us for support.
Installation
npm install @concrete-xyz/sdkQuick Start
Basic Usage
import { getVault } from '@concrete-xyz/sdk';
import { ethers } from 'ethers';
// Create provider
const provider = new ethers.JsonRpcProvider('YOUR_RPC_URL');
// Create vault instance
const vault = getVault(
'0x15cE9bE6609db102b70D68ca75a39c555bEa5Fac', // vault address
'Ethereum', // network name
provider // ContractRunner instance
);
// Get vault details
const vaultDetails = await vault.getVaultDetails();
console.log('Vault Symbol:', vaultDetails.symbolDetails);React + Wagmi Integration
For React applications using Wagmi, you can adapt the provider following the Wagmi documentation.
Note: Check the official Wagmi documentation for proper integration patterns and examples.
Examples
1. Get Vault Data
import { getVault } from '@concrete-xyz/sdk';
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('YOUR_RPC_URL');
const vault = getVault('0x15cE9bE6609db102b70D68ca75a39c555bEa5Fac', 'Ethereum', provider);
// Get complete vault information
const vaultDetails = await vault.getVaultDetails();
console.log('Vault Symbol:', vaultDetails.vaultAsset.symbol);
console.log('Underlying Asset:', vaultDetails.underlaying.symbol);2. Preview Deposit
// Preview conversion before depositing
const depositAmount = BigInt(1 * 10 ** Number(await vault.getUnderlyingDecimals())); // 18 decimals token
const preview = await vault.previewConversion(depositAmount);
console.log(`Input: ${depositAmount} ${vaultDetails.underlaying.symbol}`);
console.log(`Output: ${preview.vaultTokensReciving} ${vaultDetails.vaultAsset.symbol}`);3. Execute Deposit
// You need a signer for write operations
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
const vaultWithSigner = getVault('0x15cE9bE6609db102b70D68ca75a39c555bEa5Fac', 'Ethereum', provider, signer);
// Approve tokens first
const approveTx = await vaultWithSigner.approve(vaultWithSigner.getAddress(), depositAmount);
await approveTx.wait();
// Execute deposit
const depositTx = await vaultWithSigner.deposit(depositAmount);
const receipt = await depositTx.wait();
console.log('Deposit successful:', receipt);4. Execute Withdrawal
// Preview withdrawal
const withdrawAmount = BigInt(1 * 10 ** Number(await vault.decimals())); // 18 decimals underlying token + 9 decimal offset
const withdrawalPreview = await vault.previewConversion(withdrawAmount);
console.log(`Input: ${withdrawAmount} ${vaultDetails.vaultAsset.symbol}`);
console.log(`Output: ${withdrawalPreview.underlyingReciving} ${vaultDetails.underlaying.symbol}`);
// Execute withdrawal (using the same signer from previous example)
const withdrawTx = await vaultWithSigner.redeem(withdrawAmount);
const receipt = await withdrawTx.wait();
console.log('Withdrawal successful:', receipt);Supported Networks
The SDK supports multiple EVM networks including: Ethereum, Arbitrum, Corn, Morph, Berachain, and Katana.
Note: Network support may vary based on your specific deployment.
API Reference
getVault(address, network, clientProvider, signerProvider?)
Creates a new Vault instance for interacting with vault contracts.
Parameters:
address(string): The vault contract addressnetwork(EnabledNetwork): The blockchain network nameclientProvider(ContractRunner): Provider for read operationssignerProvider(JsonRpcSigner, optional): Signer for write operations
Returns: Vault instance
Vault Methods
The vault is an abstraction of a ERC-4626 Tokenized Vault, which in turn is an ERC-20 token that represents shares of underlying assets.
Technically, all ERC-4626 vault methods are available, but the SDK provides a simplified interface focusing on the most commonly used operations. Some less frequently used methods may not be directly exposed through the SDK wrapper.
Commonly used methods (examples):
getVaultDetails(): Get complete vault informationpreviewConversion(amount): Preview deposit/withdrawal conversiondeposit(amount): Deposit underlying tokens for vault tokensredeem(amount): Redeem vault tokens for underlying tokensapprove(spender, amount): Approve token spendingtotalAssets(): Get total assets in vaultsymbol(): Get vault symbol
Using ABI Directly
The SDK also provides access to both human-readable and raw ABI files for advanced use cases:
import abi from "@concrete-xyz/sdk/dist/src/core/contracts/abi/vault.json";
import rawAbi from "@concrete-xyz/sdk/dist/src/core/contracts/raw-abi/vault.json";
// Use vault human readable ABI
console.log(abi);
// Use vault raw ABI
console.log(rawAbi);This allows you to create custom contract instances or integrate with other libraries while maintaining access to the standardized vault interfaces.