Intent Class

The Intent Class is an interface, to easily express and to structure your desire outcome.

The Intent Class is made out of 3 main components:

  • From

  • To

  • ExtraData

From

The From part, is where you declare the target state that you want to change. It can be anything from choosing one or multiple assets to swap, your staked position, your NFTs, or any other DeFi positions you want to change.

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

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

all the four fields are mandatory.

To

The To part, is the declaration of the desired outcome. How the state will look like, after executing the Intent.

For example, you can declare the token you want to be holding at the end of the Intent execution. Or declare where you want your assets to be deposit or staked too. You can also simply declare Stake, and our solvers will know how to pick the best option for you.

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

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

all the four fields are mandatory.

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

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

In this case, the address and chainId are optional, and if you choose not to declare them, our Solvers will pick the best staking option for you.

ExtraData

Example of using ExtraData:

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

Putting All Togheter

After explaining the From and To concepts, this is an overall example, of how to declare an array of Intents:

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"
            }
        }

    ]

Last updated