Skip to content

About Agreement Forwarders

Didi edited this page Oct 4, 2023 · 3 revisions

Agreement forwarders are contracts providing a simple and intuitive API for an agreement's functionality.
They aren't part of the core protocol, but have privileged access through the Trusted Forwarder mechanism.

The agreement forwarder contracts are:

Simplified API

This is what creating a flow looks like without the forwarder contract, using ethers.js:

const cfaV1Type = ethers.utils.keccak256(
    ethers.utils.toUtf8Bytes("org.superfluid-finance.agreements.ConstantFlowAgreement.v1")
);
const cfaV1Addr = await host.getAgreementClass(cfaV1Type);
const res = await host.callAgreement(
    cfaV1Addr,
    cfaV1.interface.encodeFunctionData(
        "createFlow", [tokenAddr, receiverAddr, flowRate, "0x"],
    ),
    "0x"
);

With the CFAv1Forwarder, this could become:

const res = await cfaFwd.setFlowrate(superTokenAddr, receiverAddr, flowrate);

Explorer Readability

An added benefit of using agreement forwarders is improved transaction readability in Explorers.
If the initial contract invoked by a transaction is verified, explorers usually show the method invoked and the arguments provided in the transaction detail page. Example tx: image

After clicking "Decode Input Data", this becomes: image

Towards Token Centric API (TCI)

The API provided by agreement forwarders can also be considered a preview of a future Token Centric API, where all functionality is made available by the token contract itself, similar to how ERC20 contracts expose transfer for moving tokens.
The forwarder contracts can't fully approximate such an API, instead they take the token address as first argument.
If you're using the Solidity API from other Solidity contracts, you can instead use SuperTokenV1Library, this allows you to use the API as if it were part of the SuperToken interface itself (thanks to Solidity's using for feature).

Deployments

You can find up to date agreement forwarder addresses for supported networks in metadata/networks.json.

Clone this wiki locally