Skip to content

Commit 6af54ba

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
add _thirdwebMsgSender()
1 parent 6225e9e commit 6af54ba

File tree

4 files changed

+35
-185
lines changed

4 files changed

+35
-185
lines changed

contracts/ThirdwebContract.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ contract ThirdwebContract {
55
/// @dev The publish metadata of the contract of which this contract is an instance.
66
string private publishMetadataUri;
77

8+
/// @dev The address of the thirdweb factory.
9+
address private immutable factory;
10+
11+
constructor() {
12+
factory = msg.sender;
13+
}
14+
815
/// @dev Returns the publish metadata for this contract.
916
function getPublishMetadataUri() external view returns (string memory) {
1017
return publishMetadataUri;
@@ -15,4 +22,16 @@ contract ThirdwebContract {
1522
require(bytes(publishMetadataUri).length == 0, "Published metadata already initialized");
1623
publishMetadataUri = uri;
1724
}
25+
26+
/// @dev Returns msg.sender, if caller is not thirdweb factory. Returns the intended msg.sender if caller is factory.
27+
function _thirdwebMsgSender() internal view returns (address sender) {
28+
if (msg.sender == factory) {
29+
// The assembly code is more direct than the Solidity version using `abi.decode`.
30+
assembly {
31+
sender := shr(96, calldataload(sub(calldatasize(), 20)))
32+
}
33+
} else {
34+
sender = msg.sender;
35+
}
36+
}
1837
}

docs/ByocFactory.md

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,10 @@ function DEFAULT_ADMIN_ROLE() external view returns (bytes32)
2727
|---|---|---|
2828
| _0 | bytes32 | undefined
2929

30-
### contractURI
31-
32-
```solidity
33-
function contractURI() external view returns (string)
34-
```
35-
36-
37-
38-
39-
40-
41-
#### Returns
42-
43-
| Name | Type | Description |
44-
|---|---|---|
45-
| _0 | string | undefined
46-
4730
### deployInstance
4831

4932
```solidity
50-
function deployInstance(address _publisher, bytes _contractBytecode, bytes _constructorArgs, bytes32 _salt, uint256 _value, ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable returns (address deployedAddress)
33+
function deployInstance(address _publisher, bytes _contractBytecode, bytes _constructorArgs, bytes32 _salt, uint256 _value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
5134
```
5235

5336
Deploys an instance of a published contract directly.
@@ -63,7 +46,7 @@ Deploys an instance of a published contract directly.
6346
| _constructorArgs | bytes | undefined
6447
| _salt | bytes32 | undefined
6548
| _value | uint256 | undefined
66-
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
49+
| publishMetadataUri | string | undefined
6750

6851
#### Returns
6952

@@ -74,7 +57,7 @@ Deploys an instance of a published contract directly.
7457
### deployInstanceProxy
7558

7659
```solidity
77-
function deployInstanceProxy(address _publisher, address _implementation, bytes _initializeData, bytes32 _salt, uint256 _value, ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable returns (address deployedAddress)
60+
function deployInstanceProxy(address _publisher, address _implementation, bytes _initializeData, bytes32 _salt, uint256 _value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
7861
```
7962

8063
Deploys a clone pointing to an implementation of a published contract.
@@ -90,7 +73,7 @@ Deploys a clone pointing to an implementation of a published contract.
9073
| _initializeData | bytes | undefined
9174
| _salt | bytes32 | undefined
9275
| _value | uint256 | undefined
93-
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
76+
| publishMetadataUri | string | undefined
9477

9578
#### Returns
9679

@@ -261,23 +244,6 @@ function isTrustedForwarder(address forwarder) external view returns (bool)
261244
|---|---|---|
262245
| _0 | bool | undefined
263246

264-
### owner
265-
266-
```solidity
267-
function owner() external view returns (address)
268-
```
269-
270-
271-
272-
273-
274-
275-
#### Returns
276-
277-
| Name | Type | Description |
278-
|---|---|---|
279-
| _0 | address | undefined
280-
281247
### renounceRole
282248

283249
```solidity
@@ -312,38 +278,6 @@ function revokeRole(bytes32 role, address account) external nonpayable
312278
| role | bytes32 | undefined
313279
| account | address | undefined
314280

315-
### setContractURI
316-
317-
```solidity
318-
function setContractURI(string _uri) external nonpayable
319-
```
320-
321-
322-
323-
*Lets a contract admin set the URI for contract-level metadata.*
324-
325-
#### Parameters
326-
327-
| Name | Type | Description |
328-
|---|---|---|
329-
| _uri | string | undefined
330-
331-
### setOwner
332-
333-
```solidity
334-
function setOwner(address _newOwner) external nonpayable
335-
```
336-
337-
338-
339-
*Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.*
340-
341-
#### Parameters
342-
343-
| Name | Type | Description |
344-
|---|---|---|
345-
| _newOwner | address | undefined
346-
347281
### setPause
348282

349283
```solidity
@@ -360,21 +294,21 @@ function setPause(bool _pause) external nonpayable
360294
|---|---|---|
361295
| _pause | bool | undefined
362296

363-
### setThirdwebInfo
297+
### setPublisheMetadataUi
364298

365299
```solidity
366-
function setThirdwebInfo(ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable
300+
function setPublisheMetadataUi(string uri) external nonpayable
367301
```
368302

369303

370304

371-
*Initializes the publish metadata and contract metadata at deploy time.*
305+
*Initializes the publish metadata and at deploy time.*
372306

373307
#### Parameters
374308

375309
| Name | Type | Description |
376310
|---|---|---|
377-
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
311+
| uri | string | undefined
378312

379313
### supportsInterface
380314

@@ -420,23 +354,6 @@ event ContractDeployed(address indexed deployer, address indexed publisher, addr
420354
| publisher `indexed` | address | undefined |
421355
| deployedContract | address | undefined |
422356

423-
### OwnerUpdated
424-
425-
```solidity
426-
event OwnerUpdated(address prevOwner, address newOwner)
427-
```
428-
429-
430-
431-
432-
433-
#### Parameters
434-
435-
| Name | Type | Description |
436-
|---|---|---|
437-
| prevOwner | address | undefined |
438-
| newOwner | address | undefined |
439-
440357
### Paused
441358

442359
```solidity

docs/IByocFactory.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
### deployInstance
1414

1515
```solidity
16-
function deployInstance(address publisher, bytes contractBytecode, bytes constructorArgs, bytes32 salt, uint256 value, ThirdwebContract.ThirdwebInfo thirdwebInfo) external nonpayable returns (address deployedAddress)
16+
function deployInstance(address publisher, bytes contractBytecode, bytes constructorArgs, bytes32 salt, uint256 value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
1717
```
1818

1919
Deploys an instance of a published contract directly.
@@ -29,7 +29,7 @@ Deploys an instance of a published contract directly.
2929
| constructorArgs | bytes | The encoded constructor args to deploy the contract with.
3030
| salt | bytes32 | The salt to use in the CREATE2 contract deployment.
3131
| value | uint256 | The native token value to pass to the contract on deployment.
32-
| thirdwebInfo | ThirdwebContract.ThirdwebInfo | The publish metadata URI and contract URI for the contract to deploy.
32+
| publishMetadataUri | string | The publish metadata URI for the contract to deploy.
3333

3434
#### Returns
3535

@@ -40,7 +40,7 @@ Deploys an instance of a published contract directly.
4040
### deployInstanceProxy
4141

4242
```solidity
43-
function deployInstanceProxy(address publisher, address implementation, bytes initializeData, bytes32 salt, uint256 value, ThirdwebContract.ThirdwebInfo thirdwebInfo) external nonpayable returns (address deployedAddress)
43+
function deployInstanceProxy(address publisher, address implementation, bytes initializeData, bytes32 salt, uint256 value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
4444
```
4545

4646
Deploys a clone pointing to an implementation of a published contract.
@@ -56,7 +56,7 @@ Deploys a clone pointing to an implementation of a published contract.
5656
| initializeData | bytes | The encoded function call to initialize the contract with.
5757
| salt | bytes32 | The salt to use in the CREATE2 contract deployment.
5858
| value | uint256 | The native token value to pass to the contract on deployment.
59-
| thirdwebInfo | ThirdwebContract.ThirdwebInfo | The publish metadata URI and contract URI for the contract to deploy.
59+
| publishMetadataUri | string | The publish metadata URI and for the contract to deploy.
6060

6161
#### Returns
6262

docs/ThirdwebContract.md

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@
1010

1111
## Methods
1212

13-
### contractURI
14-
15-
```solidity
16-
function contractURI() external view returns (string)
17-
```
18-
19-
20-
21-
22-
23-
24-
#### Returns
25-
26-
| Name | Type | Description |
27-
|---|---|---|
28-
| _0 | string | undefined
29-
3013
### getPublishMetadataUri
3114

3215
```solidity
@@ -44,91 +27,22 @@ function getPublishMetadataUri() external view returns (string)
4427
|---|---|---|
4528
| _0 | string | undefined
4629

47-
### owner
48-
49-
```solidity
50-
function owner() external view returns (address)
51-
```
52-
53-
54-
55-
56-
57-
58-
#### Returns
59-
60-
| Name | Type | Description |
61-
|---|---|---|
62-
| _0 | address | undefined
63-
64-
### setContractURI
65-
66-
```solidity
67-
function setContractURI(string _uri) external nonpayable
68-
```
69-
70-
71-
72-
*Lets a contract admin set the URI for contract-level metadata.*
73-
74-
#### Parameters
75-
76-
| Name | Type | Description |
77-
|---|---|---|
78-
| _uri | string | undefined
79-
80-
### setOwner
81-
82-
```solidity
83-
function setOwner(address _newOwner) external nonpayable
84-
```
85-
86-
87-
88-
*Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.*
89-
90-
#### Parameters
91-
92-
| Name | Type | Description |
93-
|---|---|---|
94-
| _newOwner | address | undefined
95-
96-
### setThirdwebInfo
30+
### setPublisheMetadataUi
9731

9832
```solidity
99-
function setThirdwebInfo(ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable
33+
function setPublisheMetadataUi(string uri) external nonpayable
10034
```
10135

10236

10337

104-
*Initializes the publish metadata and contract metadata at deploy time.*
38+
*Initializes the publish metadata and at deploy time.*
10539

10640
#### Parameters
10741

10842
| Name | Type | Description |
10943
|---|---|---|
110-
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
111-
112-
113-
114-
## Events
115-
116-
### OwnerUpdated
117-
118-
```solidity
119-
event OwnerUpdated(address prevOwner, address newOwner)
120-
```
44+
| uri | string | undefined
12145

12246

12347

12448

125-
126-
#### Parameters
127-
128-
| Name | Type | Description |
129-
|---|---|---|
130-
| prevOwner | address | undefined |
131-
| newOwner | address | undefined |
132-
133-
134-

0 commit comments

Comments
 (0)