Thirdweb PayGateway Contract is used as the entrypoint to thirdweb Pay for swaps and bridges.
This is a forwarder contract that forwards the swap providers transaction (LiFi, Decent, etc) to their contract. Thirdweb PayGateway Contract has the following responsibilities:
- Data Logging - this is essential for attribution and linking on-chain and off-chain data
- Fee Splitting - this allows us to split the fees in-flight and flexibility to change fees on a per client basis
- Data validation - this provides high-security as only thirdweb originated swaps with untampered data can use this contract
- Stateless - this will be deployed on many different chains. We don’t want to have to call addClient, changeFee, addSwapProvider, etc on every single chain for every change. Therefore, this should not rely on data held in the state of the contract, but rather data passed in
-
Event Logging
- TokenPurchaseInitiated logs the necessary events attribution and link off-chain and on-chain through clientId and transactionId. We use bytes32 instead of string for clientId and transactionId (uuid in database) because this allows recovering indexed pre-image
- FeePayout logs the fees distributed among the payees
-
Fee Splitting
- supports many parties for fee payouts (we only expect us and client). It also allows for flexible fees on a per client basis
-
Withdrawals
- some bridges refund the sender if it fails. If this contract ends up with a balance, we need a way to return it to user, so need to support withdrawals preventing lost funds
-
Data verification
- Since we want this to be stateless and secure, we use an operator that signs all transactions created in our backend. This will use engine to sign the transactions.
- We should be able to switch out this operator. Also, the operator (engine) should be able to programmatically withdraw funds so we can build automated customer support tools
$ forge build
$ forge test