Intent Class

The Intent Class interface lets you easily define and structure your desired outcomes for DeFi operations.

The Intent Class consists of 3 main components:

  1. From

  2. To

  3. ExtraData

From

The From section defines the current state you want to change. This can include any DeFi position, such as swapping tokens, unstaking assets, or moving NFTs.

This is an example for declaring a From of type "Token":

from: {
    type: "TOKEN",
    address: "ERC20 Address",
    amount: Number_Amount,
    chainId: BigNumber.from("ChainID")
},

Note, that all four fields—type, address, amount, and chainId—are required.

To

The To section specifies the desired outcome after executing the intent.

For example, you can declare the token you want to hold at the end of the execution or specify where you want your assets to be deposited or staked. You can also simply declare a "Stake" type, and our solvers will automatically select the best staking option for you.

Here is an example for declaring a To of type "Token":

to: {
    type: "TOKEN",
    address: "ERC20_Address",
    amount: Number_Amount,
    chainId: BigNumber.from("ChainID")
},

Note that all four fields—type, address, amount, and chainId—are required.

Here is an example for declaring a To of type "Stake":

to: {
    type: "STAKE",
    address: "Staking_Service_Address",
    chainId: BigNumber.from("ChainID")
},

In this staking example, the address and chainIdare optional. If you omit them, our solvers will select the best staking option for you.

ExtraData

The ExtraData section allows you to define additional parameters like expiration dates or the type of action (buy, sell, stake). Here’s an example:

extraData: {
    expirationDate: Date, 
    kind: "buy" | "sell" | "stake"
}

Creating Intents

Once you've defined the From, To, and ExtraData, you can structure an array of intents like this:

let intents: Intent[] =
    [
        {
            from: {
                type: "TOKEN",
                address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
                amount: 2300,
                chainId: BigNumber.from("1")
            },
            to: {
                type: "TOKEN",
                address: "NATIVE", // ETH
                amount: 1,
                chainId: BigNumber.from("1")
            },
            extraData: {
                expirationDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), //24h
                partiallyFillable: false,
                kind: "sell"
            }
        },
        {
            from: {
                type: "TOKEN",
                address: "NATIVE", // ETH
                amount: 2300,
                chainId: BigNumber.from("1"),
            },
            to: {
                type: "STAKE",
                address: Projects.Staking.Lido
            },
            extraData: {
                expirationDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), //24h
                kind: "stake"
            }
        }

    ]

This structure allows you to declare multiple intents in an organized and efficient way.

Last updated