REST API

The signature for creating an order can be either from an EVM or a Bitcoin wallet, regardless of the assets being traded. However, before an order containing a Bitcoin asset can be placed, a Bitcoin wallet must have been authorized; conversely, before an order containing an EVM asset can be placed, an EVM wallet must have been authorized. See the Authorize wallet API call below.

When signing an order with a fixed amount with an EVM wallet, create the signature by signing this EIP-712 message:

const message = {
  sender: address,
  baseChainId: baseChainId,
  baseToken: baseTokenAddress,
  quoteChainId: quoteChainId,
  quoteToken: quoteTokenAddress,
  amount: amount,
  price: price,
  nonce: Date.now()
}
const eip712 = {
  domain: {
    name: 'funkybit',
    chainId: chainId
  },
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'chainId', type: 'uint32' }
    ],
    'Order': [
      { name: 'sender', type: 'address' },
      { name: 'baseChainId', type: 'uint256' },
      { name: 'baseToken', type: 'address' },
      { name: 'quoteChainId', type: 'uint256' },
      { name: 'quoteToken', type: 'address' },
      { name: 'amount', type: 'int256' },
      { name: 'price', type: 'uint256' },
      { name: 'nonce', type: 'int256' }
    ]
  },
  message: message,
  primaryType: 'Order'
}

When signing an order with a percentage amount with an EVM wallet, create the signature by signing this EIP-712 message:

const message = {
  sender: address,
  baseChainId: baseChainId,
  baseToken: baseTokenAddress,
  quoteChainId: quoteChainId,
  quoteToken: quoteTokenAddress,
  percentage: percentage,
  price: price,
  nonce: Date.now()
}
const eip712 = {
  domain: {
    name: 'funkybit',
    chainId: chainId
  },
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'chainId', type: 'uint32' }
    ],
    'Order': [
      { name: 'sender', type: 'address' },
      { name: 'baseChainId', type: 'uint256' },
      { name: 'baseToken', type: 'address' },
      { name: 'quoteChainId', type: 'uint256' },
      { name: 'quoteToken', type: 'address' },
      { name: 'percentage', type: 'int256' },
      { name: 'price', type: 'uint256' },
      { name: 'nonce', type: 'int256' }
    ]
  },
  message: message,
  primaryType: 'Order'
}

When signing an order with a Bitcoin wallet, create the signature by signing a message constructed as follows:

const amountDescription = isPercentage ? `${amount}% of your` : amount
const swapDescription = isBuy ? `Swap ${amountDescription} ${quoteSymbol} for ${baseSymbol}` : `Swap ${amountDescription} ${baseSymbol} for ${quoteSymbol}`
const priceDescription = isLimit ? `Price: ${price}` : `Price: Market`
const message = `[funkybit] Please sign this message to authorize a swap. This action will not cost any gas fees.\n${swapDescription}\n${priceDescription}\nAddress: ${address}, Nonce: ${nonce}`

The bitcoin signature should be created following the same rules as for authentication.

The signature for cancelling an order can be either from an EVM or a Bitcoin wallet, regardless of the assets being traded.

When signing an order cancellation with an EVM wallet, create the signature by signing this EIP-712 message:

const message = {
  sender: address,
  marketId: marketId,
  amount: amount,
  nonce: Date.now()
}
const eip712 = {
  domain: {
    name: 'funkybit',
    chainId: chainId
  },
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'chainId', type: 'uint32' }
    ],
    'CancelOrder': [
      { name: 'sender', type: 'address' },
      { name: 'marketId', type: 'string' },
      { name: 'amount', type: 'int256' },
      { name: 'nonce', type: 'int256' }
    ]
  },
  message: message,
  primaryType: 'CancelOrder'
}

When signing an order cancellation with a Bitcoin wallet, create the signature by signing a message constructed as follows:

const swapDescription = isBuy ? `Swap ${amount} ${quoteSymbol} for ${baseSymbol}` : `Swap ${amount} ${baseSymbol} for ${quoteSymbol}`
const message = `[funkybit] Please sign this message to authorize order cancellation. This action will not cost any gas fees.\n${swapDescription}\nAddress: ${address}, Nonce: ${nonce}`

The bitcoin signature should be created following the same rules as for authentication.

When withdrawing an EVM asset, create the signature by signing this EIP-712 message (the chainId must be the correct one for the token being withdrawn):

const message = {
  sender: address,
  token: tokenAddress,
  amount: amount,
  nonce: Date.now()
}
const eip712 = {
  domain: {
    name: 'funkybit',
    chainId: chainId
  },
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'chainId', type: 'uint32' }
    ],
    'Withdraw': [
      { name: 'sender', type: 'address' },
      { name: 'token', type: 'address' },
      { name: 'amount', type: 'uint256' },
      { name: 'nonce', type: 'uint64' }
    ]
  },
  message: message,
  primaryType: 'Withdraw'
}

When withdrawing a Bitcoin asset, create the signature by signing this message:

const message = `[funkybit] Please sign this message to authorize withdrawal of ${amountInSats} ${symbol} from the exchange to your wallet.\nAddress: ${address}, Timestamp: ${new Date().toISOString()}`

The bitcoin signature should be created following the same rules as for authentication.

This is used to authorize a Bitcoin wallet for an existing EVM account, or to authorize an EVM wallet for an existing Bitcoin account. A given account can have at most 1 Bitcoin wallet and 1 EVM wallet. The wallet being added must not have already been added as either a primary or an additional wallet.

To authorize a Bitcoin wallet for an existing EVM wallet, sign this EIP-712 message (any valid chain id can be used):

const message = {
  message: `[funkybit] Please sign this message to authorize Bitcoin wallet ${authorizedAddress}. This action will not cost any gas fees.`,
  address: address.toLowercase(),
  authorizedAddress: authorizedAddress,
  chainId: chainId,
  timestamp: new Date().toISOString(),
}
const eip712 = {
  domain: {
    name: 'funkybit',
    chainId: chainId
  },
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'chainId', type: 'uint32' }
    ],
    'Authorize': [
      { name: 'message', type: 'string' },
      { name: 'address', type: 'string' },
      { name: 'authorizedAddress', type: 'string' },
      { name: 'chainId', type: 'uint32' },
      { name: 'timestamp', type: 'string' }
    ]
  },
  message: message,
  primaryType: 'Authorize'
}

To authorize an EVM wallet for an existing Bitcoin wallet, sign this message:

const message = `[funkybit] Please sign this message to authorize EVM wallet ${authorizedAddress.toLowerCase()}. This action will not cost any gas fees.\nAddress: ${address}, Timestamp: ${new Date().toISOString()}`

The bitcoin signature should be created following the same rules as for authentication.

Last updated