Skip to content

Commit

Permalink
TokenAgentFactory v0.8.2 deployed to Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Sep 10, 2024
1 parent c98f2a0 commit ad4def7
Show file tree
Hide file tree
Showing 5 changed files with 1,181 additions and 138 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Your newly deployed Token Agent should appear
##### Deployments to Sepolia
* v0.8.0 template [TokenAgent](https://sepolia.etherscan.io/address/0x0514e4402fe93b6ba0b014b30e5b715ed0943c25#code) and [TokenAgentFactory](https://sepolia.etherscan.io/address/0x598b17e44c3e8894dfcc9aaec16dad81756f5651#code) using [WETH](https://sepolia.etherscan.io/address/0x07391dbE03e7a0DEa0fce6699500da081537B6c3#code) - [deployed/TokenAgentFactorysol v0.8.0](deployed/TokenAgentFactory_v0.8.0_Sepolia_0x598b17E44c3e8894DfcC9aAec16DaD81756F5651.sol)
* v0.8.1 template [TokenAgent](https://sepolia.etherscan.io/address/0x35e401362D24a2243b9a441542a4D4FFe50db1bF#code) and [TokenAgentFactory](https://sepolia.etherscan.io/address/0x81c9d0d4c60e6Ec7bb13879f703b113c930Cd914#code) using [WETH](https://sepolia.etherscan.io/address/0x07391dbE03e7a0DEa0fce6699500da081537B6c3#code) - [deployed/TokenAgentFactorysol v0.8.1](deployed/TokenAgentFactory_v0.8.1_Sepolia_0x81c9d0d4c60e6Ec7bb13879f703b113c930Cd914.sol)
* v0.8.1 template [TokenAgent](https://sepolia.etherscan.io/address/0x5446e959103b19e983848FB53d9fbD096eDb21A9#code) and [TokenAgentFactory](https://sepolia.etherscan.io/address/0xB6426d5E4B6515E627Ff510424978eBe223c39C4#code) using [WETH](https://sepolia.etherscan.io/address/0x07391dbE03e7a0DEa0fce6699500da081537B6c3#code) - [deployed/TokenAgentFactorysol v0.8.2](deployed/TokenAgentFactory_v0.8.2_Sepolia_0xB6426d5E4B6515E627Ff510424978eBe223c39C4.sol)

##### Notes
This project is currently heavily under development. Clear your browser's LocalStorage and IndexedDB if this dapp is not operating as expected as the configuration data may have a new format.
Expand Down
52 changes: 43 additions & 9 deletions contracts/TokenAgentFactory.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
*Submitted for verification at Etherscan.io on 2024-09-10
*/

pragma solidity ^0.8.27;

// ----------------------------------------------------------------------------
Expand All @@ -7,8 +11,8 @@ pragma solidity ^0.8.27;
//
// Deployed to Sepolia
// - WETH 0x07391dbE03e7a0DEa0fce6699500da081537B6c3
// - TokenAgent template
// - TokenAgentFactory
// - TokenAgent template 0x5446e959103b19e983848FB53d9fbD096eDb21A9
// - TokenAgentFactory 0xB6426d5E4B6515E627Ff510424978eBe223c39C4
//
// TODO:
// - FILL for ERC-721/1155?
Expand Down Expand Up @@ -258,12 +262,41 @@ contract NonReentrancy {

/// @notice Token information
contract TokenInfo {
mapping(Token => TokenType) tokenTypes;

function _supportsInterface(Token token, bytes4 _interface) internal view returns (bool b) {
try IERC165(Token.unwrap(token)).supportsInterface(_interface) returns (bool _b) {
b = _b;
} catch {
bytes4 constant InvalidID = 0xffffffff;
bytes4 constant ERC165ID = 0x01ffc9a7;

function doesContractImplementInterface(address _contract, bytes4 _interfaceId) internal view returns (bool) {
uint success;
uint result;
(success, result) = _noThrowCall(_contract, ERC165ID);
if ((success == 0) || (result == 0)) {
return false;
}
(success, result) = _noThrowCall(_contract, InvalidID);
if ((success == 0) || (result !=0 )) {
return false;
}
(success, result) = _noThrowCall(_contract, _interfaceId);
if ((success == 1) && (result == 1)) {
return true;
}
return false;
}
function _noThrowCall(address _contract, bytes4 _interfaceId) view internal returns (uint success, uint result) {
bytes4 erc165ID = ERC165ID;
assembly {
let x := mload(0x40) // Find empty storage location using "free memory pointer"
mstore(x, erc165ID) // Place signature at beginning of empty storage
mstore(add(x, 0x04), _interfaceId) // Place first argument directly next to signature
success := staticcall(
30000, // 30k gas
_contract, // To addr
x, // Inputs are stored at location x
0x24, // Inputs are 36 bytes long
x, // Store output over input (saves space)
0x20) // Outputs are 32 bytes long
result := mload(x) // Load the result
}
}
function _decimals(Token token) internal view returns (uint8 __d) {
Expand All @@ -279,9 +312,9 @@ contract TokenInfo {
}
function _getTokenType(Token token) internal view returns (TokenType _tokenType) {
if (Token.unwrap(token).code.length > 0) {
if (_supportsInterface(token, ERC721_INTERFACE)) {
if (doesContractImplementInterface(Token.unwrap(token), ERC721_INTERFACE)) {
_tokenType = TokenType.ERC721;
} else if (_supportsInterface(token, ERC1155_INTERFACE)) {
} else if (doesContractImplementInterface(Token.unwrap(token), ERC1155_INTERFACE)) {
_tokenType = TokenType.ERC1155;
} else {
if (_decimals(token) != type(uint8).max) {
Expand Down Expand Up @@ -359,6 +392,7 @@ contract TokenAgent is TokenInfo, Owned, NonReentrancy {

WETH public weth;
Nonce public nonce;
mapping(Token => TokenType) tokenTypes;
Offer[] public offers;

event InternalTransfer(address indexed from, address indexed to, uint ethers, Unixtime timestamp);
Expand Down
Loading

0 comments on commit ad4def7

Please sign in to comment.