Smart Contract SDK

Getting Started

Openflow Smart Contract SDK is the recommended way for most smart contracts to integrate with Openflow.

The SDK is designed for ease of use and flexibility and provides mechanisms for creating swaps and managing orders.

The SDK utilizes a factory pattern where integrators simply create a new SDK instance, configure the SDK and then start using the SDK to submit and manager orders.

This pattern allows order managers to manage all their orders for an instance in one place, making it easy to keep track of your orders on-chain.

By isolating swap logic from core contract the entire SDK instance is encapsulated into a clean singleton where swap configuration and methods do not pollute the global namespace

Basic Example

To get started immediately load the sample project in remix.

For current SDK factory address see:

Deployed Contracts

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "openflow-contracts@0.0.1/src/interfaces/IERC20.sol";
import "openflow-contracts@0.0.1/src/interfaces/IOpenflow.sol";

contract SdkIntegrationExample {
    /// @notice Initialize SDK instance variable.
    IOpenflowSdk public sdk;

    /// @notice Create a new SDK instance.
    constructor(address _openflowFactory) {
        address sdkInstanceManager = msg.sender;
        sdk = IOpenflowFactory(_openflowFactory).newSdkInstance(
            sdkInstanceManager
        );
    }

    /// @notice Execute a basic swap.
    function swap(address fromToken, address toToken) external {
        IERC20(fromToken).approve(address(sdk), type(uint256).max);
        sdk.swap(fromToken, toToken);
    }
}

Detailed Example

Initialize the SDK

Configure the SDK

Submit an Order

Invalidating Orders

Last updated