Skip to content

Commit

Permalink
add _thirdwebMsgSender()
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishang Nadgauda authored and Krishang Nadgauda committed May 10, 2022
1 parent 6225e9e commit 6af54ba
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 185 deletions.
19 changes: 19 additions & 0 deletions contracts/ThirdwebContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ contract ThirdwebContract {
/// @dev The publish metadata of the contract of which this contract is an instance.
string private publishMetadataUri;

/// @dev The address of the thirdweb factory.
address private immutable factory;

constructor() {
factory = msg.sender;
}

/// @dev Returns the publish metadata for this contract.
function getPublishMetadataUri() external view returns (string memory) {
return publishMetadataUri;
Expand All @@ -15,4 +22,16 @@ contract ThirdwebContract {
require(bytes(publishMetadataUri).length == 0, "Published metadata already initialized");
publishMetadataUri = uri;
}

/// @dev Returns msg.sender, if caller is not thirdweb factory. Returns the intended msg.sender if caller is factory.
function _thirdwebMsgSender() internal view returns (address sender) {
if (msg.sender == factory) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
sender = msg.sender;
}
}
}
99 changes: 8 additions & 91 deletions docs/ByocFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,10 @@ function DEFAULT_ADMIN_ROLE() external view returns (bytes32)
|---|---|---|
| _0 | bytes32 | undefined

### contractURI

```solidity
function contractURI() external view returns (string)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | string | undefined

### deployInstance

```solidity
function deployInstance(address _publisher, bytes _contractBytecode, bytes _constructorArgs, bytes32 _salt, uint256 _value, ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable returns (address deployedAddress)
function deployInstance(address _publisher, bytes _contractBytecode, bytes _constructorArgs, bytes32 _salt, uint256 _value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
```

Deploys an instance of a published contract directly.
Expand All @@ -63,7 +46,7 @@ Deploys an instance of a published contract directly.
| _constructorArgs | bytes | undefined
| _salt | bytes32 | undefined
| _value | uint256 | undefined
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
| publishMetadataUri | string | undefined

#### Returns

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

```solidity
function deployInstanceProxy(address _publisher, address _implementation, bytes _initializeData, bytes32 _salt, uint256 _value, ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable returns (address deployedAddress)
function deployInstanceProxy(address _publisher, address _implementation, bytes _initializeData, bytes32 _salt, uint256 _value, string publishMetadataUri) external nonpayable returns (address deployedAddress)
```

Deploys a clone pointing to an implementation of a published contract.
Expand All @@ -90,7 +73,7 @@ Deploys a clone pointing to an implementation of a published contract.
| _initializeData | bytes | undefined
| _salt | bytes32 | undefined
| _value | uint256 | undefined
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
| publishMetadataUri | string | undefined

#### Returns

Expand Down Expand Up @@ -261,23 +244,6 @@ function isTrustedForwarder(address forwarder) external view returns (bool)
|---|---|---|
| _0 | bool | undefined

### owner

```solidity
function owner() external view returns (address)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined

### renounceRole

```solidity
Expand Down Expand Up @@ -312,38 +278,6 @@ function revokeRole(bytes32 role, address account) external nonpayable
| role | bytes32 | undefined
| account | address | undefined

### setContractURI

```solidity
function setContractURI(string _uri) external nonpayable
```



*Lets a contract admin set the URI for contract-level metadata.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _uri | string | undefined

### setOwner

```solidity
function setOwner(address _newOwner) external nonpayable
```



*Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _newOwner | address | undefined

### setPause

```solidity
Expand All @@ -360,21 +294,21 @@ function setPause(bool _pause) external nonpayable
|---|---|---|
| _pause | bool | undefined

### setThirdwebInfo
### setPublisheMetadataUi

```solidity
function setThirdwebInfo(ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable
function setPublisheMetadataUi(string uri) external nonpayable
```



*Initializes the publish metadata and contract metadata at deploy time.*
*Initializes the publish metadata and at deploy time.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined
| uri | string | undefined

### supportsInterface

Expand Down Expand Up @@ -420,23 +354,6 @@ event ContractDeployed(address indexed deployer, address indexed publisher, addr
| publisher `indexed` | address | undefined |
| deployedContract | address | undefined |

### OwnerUpdated

```solidity
event OwnerUpdated(address prevOwner, address newOwner)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| prevOwner | address | undefined |
| newOwner | address | undefined |

### Paused

```solidity
Expand Down
8 changes: 4 additions & 4 deletions docs/IByocFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
### deployInstance

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

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

#### Returns

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

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

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

#### Returns

Expand Down
94 changes: 4 additions & 90 deletions docs/ThirdwebContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@

## Methods

### contractURI

```solidity
function contractURI() external view returns (string)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | string | undefined

### getPublishMetadataUri

```solidity
Expand All @@ -44,91 +27,22 @@ function getPublishMetadataUri() external view returns (string)
|---|---|---|
| _0 | string | undefined

### owner

```solidity
function owner() external view returns (address)
```






#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined

### setContractURI

```solidity
function setContractURI(string _uri) external nonpayable
```



*Lets a contract admin set the URI for contract-level metadata.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _uri | string | undefined

### setOwner

```solidity
function setOwner(address _newOwner) external nonpayable
```



*Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _newOwner | address | undefined

### setThirdwebInfo
### setPublisheMetadataUi

```solidity
function setThirdwebInfo(ThirdwebContract.ThirdwebInfo _thirdwebInfo) external nonpayable
function setPublisheMetadataUi(string uri) external nonpayable
```



*Initializes the publish metadata and contract metadata at deploy time.*
*Initializes the publish metadata and at deploy time.*

#### Parameters

| Name | Type | Description |
|---|---|---|
| _thirdwebInfo | ThirdwebContract.ThirdwebInfo | undefined



## Events

### OwnerUpdated

```solidity
event OwnerUpdated(address prevOwner, address newOwner)
```
| uri | string | undefined





#### Parameters

| Name | Type | Description |
|---|---|---|
| prevOwner | address | undefined |
| newOwner | address | undefined |



0 comments on commit 6af54ba

Please sign in to comment.