LogoLogo
  • Introduction
    • Get started
  • Kiln Products
    • Overview
    • 🧱Validators
      • ⛓️Protocols
        • Algorand (ALGO)
        • Aptos (APT)
        • Avalanche (AVAX)
        • Babylon (BABY)
        • Bittensor (TAO)
        • Cardano (ADA)
        • Celestia (TIA)
        • CoreChain (CORE)
        • Cosmos (ATOM)
        • Cronos (CRO)
        • DyDx (DYDX)
        • Ethereum (ETH)
        • Eigenlayer (EIGEN)
        • Fetch.ai (FET)
        • Flare (FLR)
        • Harmony (ONE)
        • Injective (INJ)
        • Iota (IOTA)
        • Kava (KAVA)
        • Kusama (KSM)
        • Mantra (OM)
        • MultiversX (EGLD)
        • Near (NEAR)
        • Oasis (ROSE)
        • Osmosis (OSMO)
        • Peaq (PEAQ)
        • Polkadot (DOT)
        • Polygon (POL - ex MATIC)
        • Sei (SEI)
        • Solana (SOL)
        • Stacks (STX)
        • Starknet (STRK)
        • Story(IP)
        • Sui (SUI)
        • Symbiotic (SYM)
        • Tezos (XTZ)
        • The Open Network (TON)
        • Tron (TRX)
        • Zetachain (ZETA)
    • 🎆Connect
      • Accessing Kiln Connect
      • API specs
      • Postman Demo
      • SDK
        • Getting started
        • How to find Kiln's validators
        • Upgrade guide from v2 to v3
      • Tutorials
        • SOL - Tag a stake
        • DYDX - How to bridge your rewards
      • Kiln Connect FAQs
    • 🚀Dashboard
      • Architecture
      • Staking
        • Cardano (ADA)
        • Celestia (TIA)
        • Cosmos (ATOM)
        • Cronos (CRO)
        • DYDX (DYDX)
        • Ethereum (ETH)
          • Native EigenLayer Restaking
          • Deposit into compounding validators
          • Convert skimming validators to compounding validators
        • Fetch.ai (FET)
        • Injective (INJ)
        • Kava (KAVA)
        • Kusama (KSM)
        • Mantra (OM)
        • Near (NEAR)
        • Osmosis (OSMO)
        • Polkadot (DOT)
        • Polygon (POL)
        • Solana (SOL)
        • Tezos (XTZ)
        • The Open Network (TON)
        • TRON (TRX)
        • ZetaChain (ZETA)
      • Reporting
        • Cardano (ADA)
        • Celestia (TIA)
        • Cosmos (ATOM)
        • Cronos (CRO)
        • DYDX (DYDX)
        • Ethereum (ETH)
        • Fetch.ai (FET)
        • Injective (INJ)
        • Kava (KAVA)
        • Kusama (KSM)
        • Mantra (OM)
        • Near (NEAR)
        • Osmosis (OSMO)
        • Polkadot (DOT)
        • Polygon (POL)
        • Solana (SOL)
        • Tezos (XTZ)
        • The Open Network (TON)
        • Tron (TRX)
        • ZetaChain (ZETA)
      • Unstaking
        • Cardano (ADA)
        • Celestia (TIA)
        • Cosmos (ATOM)
        • Cronos (CRO)
        • DYDX (DYDX)
        • Ethereum (ETH)
          • Native EigenLayer Withdraw Flow
          • Partial withdraw liquidity
        • Fetch.ai (FET)
        • Injective (INJ)
        • Kava (KAVA)
        • Kusama (KSM)
        • Mantra (OM)
        • Near (NEAR)
        • Osmosis (OSMO)
        • Polkadot (DOT)
        • Polygon (POL)
        • Solana (SOL)
          • Deactivate
          • Merge
          • Split
          • Withdraw
        • Tezos (XTZ)
        • Tron (TRX)
        • The Open Network (TON)
        • ZetaChain (ZETA)
      • Import stakes
      • Move stakes
      • Invite a user to your organization
      • Troubleshooting
      • 🎓Tutorials
        • Cosmos Chains - Auto-compound a stake
      • Dashboard FAQs
    • 📥dApp
      • ETH staking
      • EigenLayer
        • Operator delegation
        • Native restaking
        • Liquid restaking
      • 🔒Security
      • Kiln dApp FAQ
    • ⛓️Onchain
      • 🙋‍♀️Dedicated Validators
        • Key concepts
          • Deposit Flow
          • Rewards Management
          • Unstaking
        • How to integrate
          • 1. Contract Interactions
          • 2. Administration
      • 🤽‍♂️Pooled Staking
        • Key concepts
          • Staking Positions
          • Oracle Reports
          • Exit & Withdrawal
        • How to integrate
          • 🐎Getting Started
          • 🏗️Architecture overview
          • 😊User experience
          • 📃Integration contract
          • ⛑️Contract governance
          • ℹ️Contract ABI
          • 📥Using TheGraph
          • 🥩Staking Interactions
            • Staking
            • Rewards
            • Unstaking & Withdrawals
      • 🎡Tokenized Validators
      • 🎩Node Operators: how to integrate
        • Dedicated Validators (v1)
          • Manage Validators
        • Pooled Staking
          • 1. Using TheGraph for Setup
          • 2. Deploying vPool
          • 3. Key Provisioning in vFactory
          • 4. Oracle Daemon
          • 5. Depositing via Integration Contracts
          • 6. Exit Daemon
          • 7. Deploy Integration Contract (optional)
      • 🔓Security
        • Staking Risks
        • Audits & Bug Bounties
        • Business Continuity
        • Source code
    • 💰DeFi
      • 🦋Morpho via Kiln DeFi
      • 💻How to integrate?
        • Smart contract interactions
        • Governance
        • Reporting data
        • Administration
        • Supported DeFi Protocols
        • Additional Rewards Management
      • 🔓Security
        • Risks
        • Audits & Bug Bounty
        • Pause
        • Source code
        • Compliance Features
      • Kiln DeFi FAQ
    • 🪄Widget
      • 🧑‍🎨Customize - Widget Editor
      • ☄️Integrate - No/Low Code
    • 🛠️More Tools
      • ETH Batch Deposit Contract
      • Safe CD
  • Integrations
    • 🔭Plan your integration
    • 🔌Integrate Kiln products
    • 📱Wallets
      • Stake from Ledger Live
        • Direct Staking
        • Using Kiln Widget
          • DeFi Lending in Ledger Live
        • Using Kiln dApp
          • Dedicated Validators
          • Pooled Staking
          • EigenLayer Restaking
      • Stake from Safe{Wallet}
        • How to stake ETH on Safe & FAQ
        • DeFi Lending in Safe{Wallet}
        • Using Kiln dApp
      • Stake from Squads
    • 🏢Custody platforms
      • Stake from Anchorage
      • Stake from Bitgo
      • Stake from Coinbase Custody/Prime
      • Stake from Copper
      • Stake from Cordial Systems
      • Stake from DFNS
      • Stake from Finoa
      • Stake from Fireblocks
      • Stake from Fordefi
      • Stake from Hex Safe
      • Stake from Ledger Enterprise
      • Stake from Metamask Institutional
      • Stake from Rakkar
      • Stake from Taurus
      • Stake from Utila
      • Stake with Zodia
  • Working with Kiln
    • ☑️Staking & DeFi Track Record
    • ✅Security & Insurances
    • ☎️Support
      • FAQs
        • Enzyme FAQ
        • EigenLayer FAQ
        • Kiln x Safe{Wallet} FAQ
        • Ledger Live FAQ
Powered by GitBook
On this page
  • 1. Depositing
  • 2. Get the balance in assets
  • 3. Exiting a position

Was this helpful?

Export as PDF
  1. Kiln Products
  2. DeFi
  3. How to integrate?

Smart contract interactions

PreviousHow to integrate?NextGovernance

Last updated 2 months ago

Was this helpful?

Kiln DeFi smart contracts integrate the on all chains where it's available. The oracle actively monitors and screens addresses against up-to-date sanctions lists, ensuring that any sanctioned addresses are automatically restricted from interacting with Kiln DeFi vaults.

Kiln DeFi Vault smart contracts adhere to the standard, making integration straightforward. When users deposit tokens, they receive shares representing their position. For a better user experience, we recommend abstracting any asset-to-share conversions and always displaying asset amounts on the UI instead of share amounts.

Here is the ABI of the Vault contract:

1. Depositing

Before depositing 'x' assets, ensure the user has approved the vault to spend 'x' on their behalf via the asset contract.

  • Check Allowance: Call the allowance(address owner, address spender) → uint256 function on the ERC20 asset contract.

  • Increase Allowance: Use the approve(address spender, uint256 amount) → bool function on the ERC20 asset contract to increase the allowance to the desired deposit amount.

Before depositing X assets, you must make sure the user approved the vault to spend X on its behalf on the asset contract.

Note: Only have the user approve the exact amount they intend to deposit into the vault.

To deposit an amount of the vault's ERC20, the transaction sender must call the deposit(uint256 assets, address receiver) function, where assets is the amount of ERC20 to deposit in the strategy, and receiver is the address that should own the deposited position.

(Optional) If you need to compute the amount of shares the user will receive before making a deposit, you can preview the amount by calling previewDeposit(uint256 assets), where assets is the amount of ERC20 to deposit.

2. Get the balance in assets

Using the reporting API
curl https://api.kiln.fi/v1/defi/v1/stakes?users=$ADDRESS1&vaults=$VAULT1,$VAULT2 \
   -H "Authorization: Bearer $API_TOKEN"

200
{
  "stakes": [
    {
      "current_balance": 1880000,
      "asset": "0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8",
      "total_rewards": 42000,
      "asset_symbol": "USDC",
      "total_deposited_amount": 1980000,
      "total_withdrawn_amount": 100000,
      "vault": "0x9aB5F9101a3C1B868e2c422E294cc2ee685551D5",
      "chain": "ethereum"
    },
    {
      "current_balance": 1880000,
      "asset": "0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8",
      "total_rewards": 1330,
      "asset_symbol": "USDC",
      "total_deposited_amount": 1980000,
      "total_withdrawn_amount": 100000,
      "vault": "0x8aB6F9101a3C1B868e2c422E294cc2ee686662Ab",
      "chain": "ethereum"
    }
  ]
}
Using contract view functions
  1. To check the position balance in shares, call the balanceOf(address owner) function, where owner is the address of the position owner.

  2. To determine the amount of ERC20 the position is worth, call the previewRedeem(uint256 shares) function, where shares is the amount of shares to redeem. This will return the equivalent amount of ERC20.

3. Exiting a position

Case 1: exit part of a position

In this case, we expect the user to input the amount of ERC20 they want to withdraw and then call the withdraw(uint256 assets, address receiver, address owner) function. Here:

  • assets is the amount of ERC20 to withdraw.

  • receiver is the address that will receive the redeemed ERC20.

  • owner is the address of the position owner (the same as the transaction sender).

Case 2: exit a position fully

To exit the entire position, the best approach is to determine the user's share amount and redeem it. Follow these steps:

  1. Retrieve the share amount of the user's position using the balanceOf(address owner) function, where owner is the address of the position owner.

  2. Redeem the shares by calling the redeem(uint256 shares, address receiver, address owner) function, where:

    • shares is the amount of shares to redeem.

    • receiver is the address that will receive the redeemed ERC20.

    • owner is the address of the position owner (the same as the transaction sender).

Using the withdraw function instead of the redeem function may prevent the user from fully exiting their position, as the shares-to-assets rate might change between the input and the actual block when the transaction is included.

💰
💻
⚠️
Chainalysis Oracle for sanctions screening
ERC4626
28KB
vault.abi.json
User deposits ERC20 and receives shares
Withdraw ERC20 value using assets as input value
Redeem ERC20 value using shares as input value