Permit

For swaps from supported EIP-2616 tokens, the `permit` parameter allows swapping without an approval transaction beforehand.

Specification

Refer to EVM Swaps for details on where permitcan be used

EIP-2612 tokens can be swapped directly without an initial approval transaction. The client needs to provide an abi-encoded permit function calldata (without selector) as a parameter to EVM Swaps API call. Refer to the EIP-2612 specification for how to sign and encode this call. permit function ABI is provided below for reference:

function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external
  • owner: the swap's token sender

  • spender: the KyberSwap router address as returned by the GET-route API

  • value: the amount of token to be swapped

  • deadline: deadline by which the permit is valid

  • v, r, s: a valid secp256k1 signature from the swap's token sender for the following typed message:

const domain = {
  name,
  version,
  chainId,
  verifyingContract: await token.getAddress(),
};

const types = {
  Permit: [
    { name: "owner", type: "address" },
    { name: "spender", type: "address" },
    { name: "value", type: "uint256" },
    { name: "nonce", type: "uint256" },
    { name: "deadline", type: "uint256" },
  ],
};

const message = {
  owner,
  spender,
  value,
  nonce,
  deadline,
};

Example

Last updated

Was this helpful?