Singularity
  • START HERE
    • Introduction
    • 🚀Mission
    • Supporters
    • The Team
    • 🎯Target User(s)
      • 📊Funds
      • DeFi Applications
      • L1 and L2s
  • The Singularity Solution
    • Protocol Overview
    • Core ZK-Infrastructure
  • CORE USE-CASES
    • Unified Cross-Chain Compliance Oracle
    • Private OTC Settlement
    • 🌑Dark pool (Orderbook & Private AMM)
    • Vesting in Stealth
      • Vesting in Stealth Guide
        • (Projects) Confidential Vesting Streams Guide
        • (Projects) Transfer Confidential Vesting Streams Guide
        • (Recipients) Receive Confidential Vesting or Vested Tokens
        • (Recipients) Check & Claim Confidential Vested Tokens
    • Private Payments
    • Swaps
    • Liquidity Provisioning
  • HOW TO GET STARTED?
    • Onboard in 4 easy steps...
    • 🏛️KYC/KYB Guide
      • KYC (Keyring Network)
      • KYB (Keyring Network)
      • KYC (zkMe) for accessing Arbitrum
    • On-Chain Singularity Actions
      • Deposit
      • Withdraw
      • Swaps
      • LP (Adding Liquidity)
      • LP (Removing Liquidity)
      • LP (Collect Fees)
      • Internal Transfer
      • Compliant Staking
        • Staking via Direct Deposit
        • Staking via Private Notes
  • Welcome to the Singularity Service (Hint: Points Points)
    • Page
    • Introduction to the Singularity Secret Service
    • 📜High-level overview Singularity Season 2 (SS2) Guideline
    • How to get started and qualify
    • Discuss roles
    • Dashboard
    • Burning mechanism
    • leveling up and each role
    • OG points vs OG Tokens
    • Partner Campaigns
    • Mission 1 Guideline Overview
      • Mission 1 Guideline with zkMe!
        • How to Deposit on Singularity: Step-by-Step Guide
    • 🕵️ SS2 - Singularity
      • ⁉️ How and where to get started?
      • 🖥️ Season 2 Dashboard
      • 👨‍🚀 CORE GAME PLAY
      • 💵 Earning Mechanism
        • 🖼️ OG POINTs
        • 🤖 OG points <> $OG
  • HOW TO EARN POINTS & YIELD?
    • ⭐Compliant Staking Overview
    • How to participate?
    • Staking via Direct Deposit
    • Staking via Private Notes
    • How to Withdraw?
    • Redeem (i.e sgETH->ETH)
    • sgToken Partners
    • FAQs
  • FOR DEVELOPERS
    • Custom SDK Integration
      • Bridging Smart Contract
      • Front-End
    • Singularity's Architecture
    • Native Transactions
    • DeFi Integrations
      • Uniswap V3
      • Curve Finance
    • The Relayer
    • Smart Contract Addresses
    • Smart Contracts (Compliant Staking)
  • SINGULARITY MISCELLANEOUS
    • 🚨Protocol Security
    • 🪙Tokenomics
    • FAQ
  • 🕶️The Darkpool
    • Darkpool Overview (Testnet)
      • About Sepolia ETH
      • Earning and Tracking Points
      • How to Make a Trade on Testnet
    • Darkpool FAQs
      • Trading Details
      • Security and Compliance
      • Technology Overview
      • Benefits of Trading in a Darkpool
Powered by GitBook
On this page
  1. FOR DEVELOPERS
  2. Custom SDK Integration

Bridging Smart Contract

PreviousCustom SDK IntegrationNextFront-End

Last updated 9 months ago

In order to integrate your DeFi protocol, you’ll need to implement an adapter in the form of a bridging contract. For example, MockDexSingularityBridge.sol is used as the bridging contract for handling interactions between our Mock DeFi exchange and The Singularity.

There is a hard constraint imposed that limits each DeFi interaction with the Singularity to spending up to 4 notes at once. Similarly, up to 4 notes may be created as a result of a single transaction.

Take the following MockDex.sol contract as an example:

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.20;

interface IMockDex {
    
    function getAssets() external returns (address[4] memory assets);
    function swap(uint256 amountIn, uint256 minAmount, address caller) 
        external payable returns (uint256);
}

The swap method in our example takes an amountIn qty worth of ETH in exchange for minAmount qty worth of WETH. For this interaction, a single note (containing ETH) gets spent in exchange for a single newly created note (containing WETH) which the user receives.

When a user of your protocol wants to interact via the Singularity, they’ll invoke a method The defiCall method will be invoked by _defiCall via GeneralDefiIntegrationAssetManager.sol that subsequently calls the defiCall method in the bridging contract you write. Let’s convey this in code through the implementation of the defiCall method definition within the MockDexSingularityBridge.sol contract.

    function defiCall(
        uint256[] calldata amountsOrNftIds,
        string calldata defiParameters
    )
        external
        payable
        returns (address[] memory assets, uint256[] memory outAmounts)
    {
        (uint256 amountIn, uint256 minAmountOut) = _decodeDefiParameters(
            defiParameters
        );
        uint256 swapOut = _mockDex.swap{value: amountsOrNftIds[0]}(amountsOrNftIds[0], minAmountOut, address(this));
        IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).forceApprove(msg.sender, swapOut);
        IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).safeTransfer(msg.sender, swapOut);
        assets = new address[](4);
        assets[0] = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
        assets[1] = address(0);
        assets[2] = address(0);
        assets[3] = address(0);
        outAmounts = new uint256[](4);
        outAmounts[0] = swapOut;
        outAmounts[1] = 0;
        outAmounts[2] = 0;
        outAmounts[3] = 0;
    }

In the case of MockDex, the assets and outAmounts arrays each consist of one item indicative of the assets being spent and received by the user.

NOTE: It’s important to reference values from defiParameters that’s passed.

Once you've implemented the smart contract bridging contract, it's onto integrating your Dapp with the frontend interface for the contract.

Mock smart contract integration diagram
Mock smart contract integration diagram