Skip to content

Commit

Permalink
Merge pull request #8 from thirdweb-dev/yash/modular-pay-gateway
Browse files Browse the repository at this point in the history
Modular pay gateway + audit fixes
  • Loading branch information
kumaryash90 authored Oct 15, 2024
2 parents f2db1bf + 1c5644e commit 618e1b2
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 307 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/modular-contracts"]
path = lib/modular-contracts
url = https://github.com/thirdweb-dev/modular-contracts
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
## **Thirdweb Gateway Contract**
## **Thirdweb PayGateway Contract**

Thirdweb Gateway Contract is used as the entrypoint to thirdweb Pay for swaps and bridges.
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 Gateway Contract has the following responsibilities:
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
- exit point for contract calls - for LiFi, they can only guarantee toAmount for contract calls. This allows use to add a contract call to transferEnd that forwards the end funds to the user
- 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

[Gateway Reference](img/gateway.png)

[Gateway With Transfer End](img/gateway-transfer-end.png)
[PayGateway Reference](img/gateway.png)

## Features

- Event Logging
- TransferStart 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
- TransferEnd logs the transfer end in case of a contract call and can be used for indexing bridge transactions by just listening to our Thirdweb Gateway deployments
- 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
Expand Down
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test = 'test'
out = 'artifacts_forge'
libs = ["lib"]
remappings = [
'@openzeppelin/contracts=lib/openzeppelin-contracts/contracts',
'@ds-test=lib/ds-test/src/',
'@std=lib/forge-std/src/',
]
Expand Down
31 changes: 10 additions & 21 deletions gasreport.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
No files changed, compilation skipped

Running 2 tests for test/benchmarks/BenchmarkPaymentsGatewaySplit.t.sol:BenchmarkPaymentsGatewaySplitTest
[PASS] test_startTransfer_erc20() (gas: 131301)
[PASS] test_startTransfer_nativeToken() (gas: 141479)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 1.69ms
Ran 2 tests for test/benchmarks/BenchmarkModularPaymentsGateway.t.sol:BenchmarkModularPaymentsGatewayTest
[PASS] test_initiateTokenPurchase_erc20() (gas: 181350)
[PASS] test_initiateTokenPurchase_nativeToken() (gas: 246176)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 1.83ms (777.63µs CPU time)

Running 2 tests for test/benchmarks/BenchmarkPaymentsGateway.t.sol:BenchmarkPaymentsGatewayTest
[PASS] test_startTransfer_erc20() (gas: 158244)
[PASS] test_startTransfer_nativeToken() (gas: 183194)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 1.94ms
Ran 2 tests for test/benchmarks/BenchmarkPaymentsGateway.t.sol:BenchmarkPaymentsGatewayTest
[PASS] test_initiateTokenPurchase_erc20() (gas: 150635)
[PASS] test_initiateTokenPurchase_nativeToken() (gas: 209936)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 1.83ms (1.01ms CPU time)

Running 2 tests for test/benchmarks/BenchmarkPaymentsGatewayPull.t.sol:BenchmarkPaymentsGatewayPullTest
[PASS] test_startTransfer_erc20() (gas: 184188)
[PASS] test_startTransfer_nativeToken() (gas: 181962)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 1.81ms


Ran 3 test suites: 6 tests passed, 0 failed, 0 skipped (6 total tests)
test_startTransfer_erc20() (gas: 0 (0.000%))
test_startTransfer_nativeToken() (gas: 0 (0.000%))
test_startTransfer_erc20() (gas: 0 (0.000%))
test_startTransfer_nativeToken() (gas: 0 (0.000%))
test_startTransfer_erc20() (gas: 0 (0.000%))
test_startTransfer_nativeToken() (gas: 0 (0.000%))
Overall gas change: 0 (0.000%)
Ran 2 test suites in 2.70ms (3.65ms CPU time): 4 tests passed, 0 failed, 0 skipped (4 total tests)
Overall gas change: 0 (NaN%)
Binary file removed img/gateway-transfer-end.png
Binary file not shown.
1 change: 1 addition & 0 deletions lib/modular-contracts
Submodule modular-contracts added at 99e6e5
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from 01ef44
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at a1f9be
23 changes: 23 additions & 0 deletions src/PayGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import { ModularCore } from "lib/modular-contracts/src/ModularCore.sol";

contract PayGateway is ModularCore {
constructor(address _owner, address[] memory _modules, bytes[] memory _moduleInstallData) {
_initializeOwner(_owner);

// Install and initialize modules
require(_modules.length == _moduleInstallData.length);
for (uint256 i = 0; i < _modules.length; i++) {
_installModule(_modules[i], _moduleInstallData[i]);
}
}

function getSupportedCallbackFunctions()
public
pure
override
returns (SupportedCallbackFunction[] memory supportedCallbackFunctions)
{}
}
Loading

0 comments on commit 618e1b2

Please sign in to comment.