Router

The single entry point for users to interact with. The Router forwards the data to an Agent when executing a transaction.

Execute Transactions

The Router provides a single entry point for users to operate protocols in an intuitive and concise manner. Within the Router, users can execute operations by calling the execute() function.

function execute(
    bytes[] calldata permit2Datas,
    DataType.Logic[] calldata logics,
    address[] calldata tokensReturn
) external payable {}

The execute() function serves as the core interface for users to execute transactions. It requires three parameters:

  • permit2Datas: The Permit2 data for pulling tokens from the user address.

  • logics: The operations for Protocolink to interact with other protocols.

  • tokensReturn: The specified tokens should be sent back to the user address at the end of the transaction.

Native tokens should be sent by users to the Router in msg.value.

Protocolink charges fees in the execute() function. Check more details of the Fees

Execute Transactions with API Data

Though Protocolink provides the Execute Transactions for users to operate protocols in a single transaction, it would take users a bunch of time to build the parameters. To solve this issue, Protocolink provides the executeWithSignerFee() function.

function executeWithSignerFee(
    bytes[] calldata permit2Datas,
    DataType.LogicBatch calldata logicBatch,
    address signer,
    bytes calldata signature,
    address[] calldata tokensReturn
) external payable {}

The executeWithSignerFee() function serves as the core interface for users to execute transactions with Protocolink API data. It requires five parameters:

  • permit2Datas: The Permit2 data for pulling tokens from the user address.

  • logicBatch: The operations for Protocolink to interact with other protocols.

  • signer: The address that signed the logicBatch.

  • signature: The hash value of the signed logicBatch.

  • tokensReturn: The specified tokens should be sent back to the user address at the end of the transaction.

Execute Transactions with Delegations

Users (aka. delegators) can delegate their Agent to other users (aka. delegatee). When an Agent is delegated, the delegatee is allowed to send transactions on the delegator's behalf by calling the executeFor() function.

function executeFor(
    address user,
    bytes[] calldata permit2Datas,
    DataType.Logic[] calldata logics,
    address[] calldata tokensReturn
) external payable {}

The executeFor() function serves as the core interface for delegatees to execute transactions. It requires four parameters:

  • user: The delegator address.

  • permit2Datas: The Permit2 data for pulling tokens from the user address.

  • logics: The operations for Protocolink to interact with other protocols.

  • tokensReturn: The specified tokens should be sent back to the user address at the end of the transaction.

To delegate their Agent, delegators need to allow the delegatee with an expiry value. The expiry value ensures that the Agent is delegated within a period.

function allow(address delegatee, uint128 expiry) public {
    delegations[msg.sender][delegatee].expiry = expiry;
    emit Delegated(msg.sender, delegatee, expiry);
}

If users want to revoke the delegation from a delegatee before the expiry, users need to provide the delegatee address to the disallow() function.

function disallow(address delegatee) external {
    allow(delegatee, 0);
}

With Delegations and API Data

Same as Execute Transactions with API Data, delegatees can call the Router contract with API data by using the executeForWithSignerFee() function.

function executeForWithSignerFee(
    address user,
    bytes[] calldata permit2Datas,
    DataType.LogicBatch calldata logicBatch,
    address signer,
    bytes calldata signature,
    address[] calldata tokensReturn
) external payable {}

The executeForWithSignerFee() function serves as the core interface for delegatees to execute transactions with API data. It requires six parameters:

  • user: The delegator address.

  • permit2Datas: The Permit2 data for pulling tokens from the user address.

  • logicBatch: The operations for Protocolink to interact with other protocols.

  • signer: The address that signed the logicBatch.

  • signature: The hash value of the signed logicBatch.

  • tokensReturn: The specified tokens should be sent back to the user address at the end of the transaction.

Execute Transactions with Signatures

If users do not require a standalone delegatee, they can share their signature instead. A signature is signed by a delegator and it represents the hash value of the details. The details includes a nonce value to ensure it can only be used once before the deadline. Now, anyone with a signature can call the executeBySig() function to send a transaction on behalf of the delegator.

function executeBySig(
    DataType.ExecutionDetails calldata details,
    address user,
    bytes calldata signature
) external payable {}

The executeBySig() function serves as the core interface for anyone to execute transactions with signatures. It requires three parameters:

  • details: The operations for Protocolink to interact with other protocols.

  • user: The delegator address.

  • signature: The hash value of the signed logicBatch.

With Signatures and API Data

Same as Execute Transactions with API Data, anyone can call the Router contract with a signature and API data by using the executeBySigWithSignerFee() function.

function executeBySigWithSignerFee(
    DataType.ExecutionBatchDetails calldata details,
    address user,
    bytes calldata userSignature,
    address signer,
    bytes calldata signerSignature
) external payable {}

The executeBySigWithSignerFee() function serves as the core interface for anyone to execute a transaction with the signatures and API data. It requires five parameters:

  • details: The operations for Protocolink to interact with other protocols.

  • user: The delegator address.

  • userSignature: The hash value of the signed details.

  • signer: The address that signed the logicBatch from the details.

  • signerSignature: The hash value of the signed logicBatch.

Last updated