Skip to content

Commit d1e9b09

Browse files
authored
Merge pull request #122 from kaleido-io/factory
Support "config.factoryAddress" to create tokens using a custom factory
2 parents 8d7f695 + 01a28af commit d1e9b09

11 files changed

Lines changed: 89 additions & 124 deletions

.eslintrc.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ module.exports = {
44
project: 'tsconfig.json',
55
sourceType: 'module',
66
},
7-
plugins: [
8-
'@typescript-eslint/eslint-plugin',
9-
'eslint-plugin-import',
10-
],
7+
plugins: ['@typescript-eslint/eslint-plugin', 'eslint-plugin-import'],
118
extends: [
129
'eslint:recommended',
1310
'plugin:@typescript-eslint/recommended',
@@ -27,22 +24,22 @@ module.exports = {
2724
'@typescript-eslint/no-explicit-any': 'off',
2825
'@typescript-eslint/no-floating-promises': 'error',
2926
'@typescript-eslint/require-await': 'error',
30-
'@typescript-eslint/strict-boolean-expressions': 'error',
3127
'@typescript-eslint/unbound-method': 'error',
3228
'@typescript-eslint/no-unsafe-call': 'warn',
3329
'@typescript-eslint/no-unsafe-return': 'warn',
3430
'@typescript-eslint/ban-types': 'warn',
3531
'@typescript-eslint/no-unused-vars': [
36-
'warn', {
37-
'varsIgnorePattern': '^_',
38-
'argsIgnorePattern': '^_',
32+
'warn',
33+
{
34+
varsIgnorePattern: '^_',
35+
argsIgnorePattern: '^_',
3936
},
4037
],
4138
'import/first': 'warn',
4239
'import/no-duplicates': 'warn',
4340
'import/order': 'warn',
44-
'semi': ['warn', 'always'],
45-
'eqeqeq': 'error',
41+
semi: ['warn', 'always'],
42+
eqeqeq: 'error',
4643
'eol-last': 'warn',
4744
'no-trailing-spaces': 'warn',
4845
},

samples/solidity/contracts/ERC20WithData.sol

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ contract ERC20WithData is Context, Ownable, ERC165, ERC20, IERC20WithData {
3131
bytes4 interfaceId
3232
) public view virtual override(ERC165, IERC165) returns (bool) {
3333
return
34-
interfaceId == type(IERC20WithData).interfaceId ||
35-
super.supportsInterface(interfaceId);
34+
interfaceId == type(IERC20WithData).interfaceId || super.supportsInterface(interfaceId);
3635
}
3736

3837
function mintWithData(
3938
address to,
4039
uint256 amount,
4140
bytes calldata data
42-
) external override onlyOwner {
41+
) public virtual onlyOwner {
4342
_mint(to, amount);
4443
}
4544

@@ -48,19 +47,15 @@ contract ERC20WithData is Context, Ownable, ERC165, ERC20, IERC20WithData {
4847
address to,
4948
uint256 amount,
5049
bytes calldata data
51-
) external override {
50+
) public virtual {
5251
if (from == _msgSender()) {
5352
transfer(to, amount);
5453
} else {
5554
transferFrom(from, to, amount);
5655
}
5756
}
5857

59-
function burnWithData(
60-
address from,
61-
uint256 amount,
62-
bytes calldata data
63-
) external override {
58+
function burnWithData(address from, uint256 amount, bytes calldata data) public virtual {
6459
require(from == _msgSender(), 'ERC20WithData: caller is not owner');
6560
_burn(from, amount);
6661
}
@@ -69,7 +64,7 @@ contract ERC20WithData is Context, Ownable, ERC165, ERC20, IERC20WithData {
6964
address spender,
7065
uint256 amount,
7166
bytes calldata data
72-
) external override returns (bool) {
67+
) public virtual returns (bool) {
7368
return approve(spender, amount);
7469
}
7570
}

samples/solidity/contracts/ERC721WithData.sol

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,15 @@ contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
4343
_tokenIdCounter.increment();
4444
}
4545

46-
function supportsInterface(bytes4 interfaceId)
47-
public
48-
view
49-
virtual
50-
override(ERC721, IERC165)
51-
returns (bool)
52-
{
46+
function supportsInterface(
47+
bytes4 interfaceId
48+
) public view virtual override(ERC721, IERC165) returns (bool) {
5349
return
5450
interfaceId == type(IERC721WithData).interfaceId ||
5551
super.supportsInterface(interfaceId);
5652
}
5753

58-
function mintWithData(address to, bytes calldata data) external override onlyOwner {
54+
function mintWithData(address to, bytes calldata data) public virtual onlyOwner {
5955
uint256 tokenId = _tokenIdCounter.current();
6056
_tokenIdCounter.increment();
6157
_safeMint(to, tokenId, data);
@@ -66,7 +62,7 @@ contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
6662
address to,
6763
bytes calldata data,
6864
string memory tokenURI_
69-
) external override onlyOwner {
65+
) public virtual onlyOwner {
7066
uint256 tokenId = _tokenIdCounter.current();
7167
_tokenIdCounter.increment();
7268
_safeMint(to, tokenId, data);
@@ -85,32 +81,24 @@ contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
8581
address to,
8682
uint256 tokenId,
8783
bytes calldata data
88-
) external override {
84+
) public virtual {
8985
safeTransferFrom(from, to, tokenId, data);
9086
}
9187

92-
function burnWithData(
93-
address from,
94-
uint256 tokenId,
95-
bytes calldata data
96-
) external override {
88+
function burnWithData(address from, uint256 tokenId, bytes calldata data) public virtual {
9789
require(from == _msgSender(), 'ERC721WithData: caller is not owner');
9890
_burn(tokenId);
9991
}
10092

101-
function approveWithData(
102-
address to,
103-
uint256 tokenId,
104-
bytes calldata data
105-
) external override {
93+
function approveWithData(address to, uint256 tokenId, bytes calldata data) public virtual {
10694
approve(to, tokenId);
10795
}
10896

10997
function setApprovalForAllWithData(
11098
address operator,
11199
bool approved,
112100
bytes calldata data
113-
) external override {
101+
) public virtual {
114102
setApprovalForAll(operator, approved);
115103
}
116104

samples/solidity/contracts/IERC20WithData.sol

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import '@openzeppelin/contracts/utils/introspection/IERC165.sol';
1212
* other on- and off-chain events.
1313
*/
1414
interface IERC20WithData is IERC165 {
15-
function mintWithData(
16-
address to,
17-
uint256 amount,
18-
bytes calldata data
19-
) external;
15+
function mintWithData(address to, uint256 amount, bytes calldata data) external;
2016

2117
function transferWithData(
2218
address from,
@@ -25,11 +21,7 @@ interface IERC20WithData is IERC165 {
2521
bytes calldata data
2622
) external;
2723

28-
function burnWithData(
29-
address from,
30-
uint256 amount,
31-
bytes calldata data
32-
) external;
24+
function burnWithData(address from, uint256 amount, bytes calldata data) external;
3325

3426
function approveWithData(
3527
address spender,

samples/solidity/contracts/IERC721WithData.sol

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ import '@openzeppelin/contracts/utils/introspection/IERC165.sol';
1212
* other on- and off-chain events.
1313
*/
1414
interface IERC721WithData is IERC165 {
15-
function mintWithData(
16-
address to,
17-
bytes calldata data
18-
) external;
15+
function mintWithData(address to, bytes calldata data) external;
1916

20-
function mintWithURI(
21-
address to,
22-
bytes calldata data,
23-
string memory tokenURI_
24-
) external;
17+
function mintWithURI(address to, bytes calldata data, string memory tokenURI_) external;
2518

2619
function transferWithData(
2720
address from,
@@ -30,23 +23,15 @@ interface IERC721WithData is IERC165 {
3023
bytes calldata data
3124
) external;
3225

33-
function burnWithData(
34-
address from,
35-
uint256 tokenId,
36-
bytes calldata data
37-
) external;
26+
function burnWithData(address from, uint256 tokenId, bytes calldata data) external;
3827

39-
function approveWithData(
40-
address to,
41-
uint256 tokenId,
42-
bytes calldata data
43-
) external;
28+
function approveWithData(address to, uint256 tokenId, bytes calldata data) external;
4429

4530
function setApprovalForAllWithData(
4631
address operator,
4732
bool approved,
4833
bytes calldata data
4934
) external;
5035

51-
function baseTokenUri() external returns(string memory);
36+
function baseTokenUri() external returns (string memory);
5237
}

samples/solidity/contracts/ITokenFactory.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import '@openzeppelin/contracts/utils/introspection/IERC165.sol';
99
*/
1010

1111
interface ITokenFactory is IERC165 {
12-
function create(
13-
string memory name,
14-
string memory symbol,
15-
bool is_fungible,
16-
bytes calldata data,
17-
string memory uri
18-
) external;
19-
}
12+
function create(
13+
string memory name,
14+
string memory symbol,
15+
bool is_fungible,
16+
bytes calldata data,
17+
string memory uri
18+
) external;
19+
}

samples/solidity/hardhat.config.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as dotenv from "dotenv";
1+
import * as dotenv from 'dotenv';
22

3-
import { HardhatUserConfig } from "hardhat/config";
4-
import "@nomiclabs/hardhat-etherscan";
5-
import "@nomiclabs/hardhat-waffle";
6-
import "@typechain/hardhat";
7-
import "hardhat-gas-reporter";
8-
import "solidity-coverage";
3+
import { HardhatUserConfig } from 'hardhat/config';
4+
import '@nomiclabs/hardhat-etherscan';
5+
import '@nomiclabs/hardhat-waffle';
6+
import '@typechain/hardhat';
7+
import 'hardhat-gas-reporter';
8+
import 'solidity-coverage';
99

1010
dotenv.config();
1111

@@ -14,26 +14,26 @@ dotenv.config();
1414

1515
const config: HardhatUserConfig = {
1616
solidity: {
17-
version: "0.8.4",
17+
version: '0.8.17',
1818
settings: {
1919
optimizer: {
2020
enabled: true,
2121
runs: 1000,
2222
},
2323
},
2424
},
25-
defaultNetwork: "firefly",
25+
defaultNetwork: 'firefly',
2626
networks: {
2727
firefly: {
28-
url: "http://127.0.0.1:5100",
28+
url: 'http://127.0.0.1:5100',
2929
},
3030
hardhat: {
3131
allowUnlimitedContractSize: true,
3232
},
3333
},
3434
gasReporter: {
3535
enabled: process.env.REPORT_GAS !== undefined,
36-
currency: "USD",
36+
currency: 'USD',
3737
},
3838
etherscan: {
3939
apiKey: process.env.ETHERSCAN_API_KEY,

src/tokens/tokens.interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export class TokenPoolConfig {
125125
@IsOptional()
126126
address?: string;
127127

128+
@ApiProperty()
129+
@IsOptional()
130+
factoryAddress?: string;
131+
128132
@ApiProperty()
129133
@IsOptional()
130134
blockNumber?: string;

src/tokens/tokens.listener.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ export class TokenListener implements EventListener {
130130
const { data: output } = event;
131131
const decodedData = decodeHex(output.data ?? '');
132132

133-
if (event.address.toLowerCase() !== this.service.factoryAddress) {
134-
this.logger.warn(`Ignoring token pool creation from unknown address: ${event.address}`);
135-
return undefined;
136-
}
137-
138133
const type = output.is_fungible ? TokenType.FUNGIBLE : TokenType.NONFUNGIBLE;
139134
const decimals = output.is_fungible
140135
? await this.mapper.getDecimals(ctx, output.contract_address)

src/tokens/tokens.service.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const APPROVE_ALL_NO_DATA = 'setApprovalForAll';
8383

8484
const MINT_WITH_DATA = 'mintWithData';
8585
const MINT_WITH_URI = 'mintWithURI';
86-
const SUPPORTS_INTERFACE = 'supportsInterface';
8786
const TRANSFER_WITH_DATA = 'transferWithData';
8887
const BURN_WITH_DATA = 'burnWithData';
8988
const APPROVE_WITH_DATA = 'approveWithData';

0 commit comments

Comments
 (0)