Skip to content

Commit 31c0c5a

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
merge from main
2 parents 140e513 + d5bcee2 commit 31c0c5a

File tree

198 files changed

+15518
-3501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+15518
-3501
lines changed

.github/workflows/forge_test.yml renamed to .github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# This is a basic workflow to help you get started with Actions
22

3-
name: Forge Tests
3+
name: Tests
44

55
# Controls when the workflow will run
66
on:
77
# Triggers the workflow on push or pull request events but only for the main branch
88
push:
9-
branches: [ main ]
9+
branches: [main]
1010
pull_request:
11-
branches: [ main ]
11+
branches: [main]
1212

1313
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1414
jobs:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ typechain/
1515
.parcel-cache/
1616

1717
abi/
18+
contracts/abi/
19+
contracts/README.md
1820
artifacts/
1921
artifacts_forge/
2022

README.md

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,126 @@
1-
# Thirdweb Contracts v2
1+
<p align="center">
2+
<br />
3+
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/typescript-sdk/blob/main/logo.svg?raw=true" width="200" alt=""/></a>
4+
<br />
5+
</p>
6+
<h1 align="center">Thirdweb Contracts</h1>
7+
<p align="center">
8+
<a href="https://www.npmjs.com/package/@thirdweb-dev/contracts"><img src="https://img.shields.io/npm/v/@thirdweb-dev/contracts?color=red&logo=npm" alt="npm version"/></a>
9+
<a href="https://github.com/thirdweb-dev/contracts/actions"><img alt="Build Status" src="https://github.com/thirdweb-dev/contracts/actions/workflows/tests.yml/badge.svg"/></a>
10+
<a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a>
211

3-
> [Looking for version 1? Click here!](https://github.com/thirdweb-dev/contracts/tree/v1)
12+
</p>
13+
<p align="center"><strong>Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI</strong></p>
14+
<br />
415

5-
Lets anyone deploy their own copy of the smart contracts on the platform.
16+
## Installation
617

7-
### Deployments
18+
```shell
19+
npm i @thirdweb-dev/contracts
20+
```
21+
22+
## Usage
23+
24+
```solidity
25+
// SPDX-License-Identifier: MIT
26+
pragma solidity ^0.8.4;
27+
28+
import "@thirdweb-dev/contracts/ThirdwebContract.sol";
29+
30+
contract HellowWorldContract is ThirdwebContract {
31+
// your contract code
32+
}
33+
34+
```
35+
36+
By extending `ThirdwebContract` you can use the [thirdeb cli](https://github.com/thirdweb-dev/thirdweb-cli) to publish, deploy and manage your contracts on your [thirdweb dashboard](https://thirdweb.com/dashboard).
37+
38+
## Deployed addresses
39+
40+
### Production
841

942
- `TWRegistry`: [0x7c487845f98938Bb955B1D5AD069d9a30e4131fd](https://blockscan.com/address/0x7c487845f98938Bb955B1D5AD069d9a30e4131fd)
1043

1144
- `TWFactory`: [0x11c34F062Cb10a20B9F463E12Ff9dA62D76FDf65](https://blockscan.com/address/0x11c34F062Cb10a20B9F463E12Ff9dA62D76FDf65)
1245

46+
### Dev - (Mumbai only)
47+
48+
- `TWRegistry`: [0x3F17972CB27506eb4a6a3D59659e0B57a43fd16C](https://blockscan.com/address/0x3F17972CB27506eb4a6a3D59659e0B57a43fd16C#code)
49+
50+
- `ByocRegistry`: [0x61Bb02795b4fF5248169A54D9f149C4557B0B7de](https://mumbai.polygonscan.com/address/0x61Bb02795b4fF5248169A54D9f149C4557B0B7de#code)
51+
52+
- `ByocFactory`: [0x3c3D901Acb5f7746dCf06B26fCe881d21970d2B6](https://mumbai.polygonscan.com/address/0x3c3D901Acb5f7746dCf06B26fCe881d21970d2B6#code)
53+
1354
## Running Tests
55+
1456
1. `yarn`: install contracts dependencies
1557
2. `forge install`: install tests dependencies
1658
3. `forge test`: run the tests
1759

18-
## Feedback
60+
This repository is a hybrid [hardhat](https://hardhat.org/) and [forge](https://github.com/foundry-rs/foundry/tree/master/forge) project.
1961

20-
If you have any feedback, please reach out to us at support@thirdweb.com.
62+
First install the relevant dependencies of the project:
63+
64+
```bash
65+
yarn
66+
67+
forge install
68+
```
69+
70+
To compile contracts, run:
2171

72+
```bash
73+
forge build
74+
```
2275

76+
Or, if you prefer hardhat, you can run:
77+
78+
```bash
79+
npx hardhat compile
80+
```
81+
82+
To run tests:
83+
84+
```bash
85+
forge test
86+
```
87+
88+
To export the ABIs of the contracts in the `/contracts` directory, run:
89+
90+
```
91+
npx hardhat export-abi
92+
```
93+
94+
To run any scripts in the `/scripts` directory, run:
95+
96+
```
97+
npx hardhat run scripts/{path to the script}
98+
```
99+
100+
## Deployments
101+
102+
The thirdweb registry (`TWRegistry`) and factory (`TWFactory`) have been deployed on the following chains:
103+
104+
- [Ethereum mainnet](https://etherscan.io/)
105+
- [Rinkeby](https://rinkeby.etherscan.io/)
106+
- [Goerli](https://goerli.etherscan.io/)
107+
- [Polygon mainnet](https://polygonscan.com/)
108+
- [Polygon Mumbai testnet](https://mumbai.polygonscan.com/)
109+
- [Avalanche mainnet](https://snowtrace.io/)
110+
- [Avalanche Fuji testnet](https://testnet.snowtrace.io/)
111+
- [Fantom mainnet](https://ftmscan.com/)
112+
- [Fantom testnet](https://testnet.ftmscan.com/)
113+
114+
`TWRegistry` is deployed to a common address on all mentioned networks. `TWFactory` is deployed to a common address on all mentioned networks except Fantom mainnet.
115+
116+
- `TWRegistry`: [0x7c487845f98938Bb955B1D5AD069d9a30e4131fd](https://blockscan.com/address/0x7c487845f98938Bb955B1D5AD069d9a30e4131fd)
117+
118+
- `TWFactory`: [0x5DBC7B840baa9daBcBe9D2492E45D7244B54A2A0](https://blockscan.com/address/0x5DBC7B840baa9daBcBe9D2492E45D7244B54A2A0)
119+
- `TWFactory` (Fantom mainnet): [0x97EA0Fcc552D5A8Fb5e9101316AAd0D62Ea0876B](https://blockscan.com/address/0x97EA0Fcc552D5A8Fb5e9101316AAd0D62Ea0876B)
120+
121+
## Feedback
122+
123+
If you have any feedback, please reach out to us at support@thirdweb.com.
23124

24125
## Authors
25126

assets/marketplace-1.png

359 KB
Loading
508 KB
Loading

contracts/ByocFactory.sol

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.11;
3+
4+
// ========== External imports ==========
5+
import "@openzeppelin/contracts/utils/Create2.sol";
6+
import "@openzeppelin/contracts/proxy/Clones.sol";
7+
import "@openzeppelin/contracts/utils/Address.sol";
8+
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
9+
import "@openzeppelin/contracts/metatx/ERC2771Context.sol";
10+
11+
// ========== Internal imports ==========
12+
import { IByocFactory } from "./interfaces/IByocFactory.sol";
13+
import { TWRegistry } from "./TWRegistry.sol";
14+
import "./ThirdwebContract.sol";
15+
16+
contract ByocFactory is IByocFactory, ERC2771Context, AccessControlEnumerable, ThirdwebContract {
17+
/*///////////////////////////////////////////////////////////////
18+
State variables
19+
//////////////////////////////////////////////////////////////*/
20+
21+
/// @dev The main thirdweb registry.
22+
TWRegistry private immutable registry;
23+
24+
/// @dev Whether the registry is paused.
25+
bool public isPaused;
26+
27+
/*///////////////////////////////////////////////////////////////
28+
Constructor + modifiers
29+
//////////////////////////////////////////////////////////////*/
30+
31+
/// @dev Checks whether contract is unpaused or the caller is a contract admin.
32+
modifier onlyUnpausedOrAdmin() {
33+
require(!isPaused || hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "registry paused");
34+
35+
_;
36+
}
37+
38+
constructor(address _twRegistry, address _trustedForwarder) ERC2771Context(_trustedForwarder) {
39+
registry = TWRegistry(_twRegistry);
40+
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
41+
}
42+
43+
/*///////////////////////////////////////////////////////////////
44+
Deploy logic
45+
//////////////////////////////////////////////////////////////*/
46+
47+
/// @notice Deploys an instance of a published contract directly.
48+
function deployInstance(
49+
address _publisher,
50+
bytes memory _contractBytecode,
51+
bytes memory _constructorArgs,
52+
bytes32 _salt,
53+
uint256 _value,
54+
ThirdwebContract.ThirdwebInfo memory _thirdwebInfo
55+
) external onlyUnpausedOrAdmin returns (address deployedAddress) {
56+
require(bytes(_thirdwebInfo.publishMetadataUri).length > 0, "No publish metadata");
57+
58+
bytes memory contractBytecode = abi.encodePacked(_contractBytecode, _constructorArgs);
59+
bytes32 salt = _salt == "" ? keccak256(abi.encodePacked(_msgSender(), block.number)) : _salt;
60+
61+
deployedAddress = Create2.deploy(_value, salt, contractBytecode);
62+
63+
ThirdwebContract(deployedAddress).setThirdwebInfo(_thirdwebInfo);
64+
require(
65+
keccak256(bytes(ThirdwebContract(deployedAddress).getPublishMetadataUri())) ==
66+
keccak256(bytes(_thirdwebInfo.publishMetadataUri)),
67+
"Not a thirdweb contract"
68+
);
69+
70+
registry.add(_publisher, deployedAddress);
71+
72+
emit ContractDeployed(_msgSender(), _publisher, deployedAddress);
73+
}
74+
75+
/// @notice Deploys a clone pointing to an implementation of a published contract.
76+
function deployInstanceProxy(
77+
address _publisher,
78+
address _implementation,
79+
bytes memory _initializeData,
80+
bytes32 _salt,
81+
uint256 _value,
82+
ThirdwebContract.ThirdwebInfo memory _thirdwebInfo
83+
) external onlyUnpausedOrAdmin returns (address deployedAddress) {
84+
bytes32 salt = _salt == "" ? keccak256(abi.encodePacked(_msgSender(), block.number)) : _salt;
85+
deployedAddress = Clones.cloneDeterministic(_implementation, salt);
86+
87+
ThirdwebContract(deployedAddress).setThirdwebInfo(_thirdwebInfo);
88+
require(
89+
keccak256(bytes(ThirdwebContract(deployedAddress).getPublishMetadataUri())) ==
90+
keccak256(bytes(_thirdwebInfo.publishMetadataUri)),
91+
"Not a thirdweb contract"
92+
);
93+
94+
registry.add(_publisher, deployedAddress);
95+
96+
if (_initializeData.length > 0) {
97+
// slither-disable-next-line unused-return
98+
Address.functionCallWithValue(deployedAddress, _initializeData, _value);
99+
}
100+
101+
emit ContractDeployed(_msgSender(), _publisher, deployedAddress);
102+
}
103+
104+
/*///////////////////////////////////////////////////////////////
105+
Miscellaneous
106+
//////////////////////////////////////////////////////////////*/
107+
108+
/// @dev Lets a contract admin pause the registry.
109+
function setPause(bool _pause) external {
110+
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "unapproved caller");
111+
isPaused = _pause;
112+
emit Paused(_pause);
113+
}
114+
115+
function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address sender) {
116+
return ERC2771Context._msgSender();
117+
}
118+
119+
function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) {
120+
return ERC2771Context._msgData();
121+
}
122+
}

0 commit comments

Comments
 (0)