@mapprotocol/common-contracts 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/contracts/factory/Create2Factory.sol/Create2Factory.json +107 -0
- package/contracts/factory/Create2Factory.sol +57 -0
- package/package.json +1 -1
- package/typechain-types/contracts/factory/Create2Factory.ts +174 -0
- package/typechain-types/contracts/factory/index.ts +4 -0
- package/typechain-types/contracts/index.ts +2 -0
- package/typechain-types/factories/contracts/factory/Create2Factory__factory.ts +163 -0
- package/typechain-types/factories/contracts/factory/index.ts +4 -0
- package/typechain-types/factories/contracts/index.ts +1 -0
- package/typechain-types/hardhat.d.ts +18 -0
- package/typechain-types/index.ts +2 -0
- package/utils/addressCodec.ts +12 -7
- package/utils/codeHash.ts +75 -0
- package/utils/deployRecord.ts +117 -0
- package/utils/deployer.ts +123 -0
- package/utils/evmHelper.ts +108 -0
- package/utils/factory.ts +210 -0
- package/utils/index.ts +35 -18
- package/utils/tronHelper.ts +312 -30
- package/utils/verifier.ts +225 -0
- package/utils/deployment.ts +0 -81
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-sol-artifact-1",
|
|
3
|
+
"contractName": "Create2Factory",
|
|
4
|
+
"sourceName": "contracts/factory/Create2Factory.sol",
|
|
5
|
+
"abi": [
|
|
6
|
+
{
|
|
7
|
+
"anonymous": false,
|
|
8
|
+
"inputs": [
|
|
9
|
+
{
|
|
10
|
+
"indexed": true,
|
|
11
|
+
"internalType": "address",
|
|
12
|
+
"name": "addr",
|
|
13
|
+
"type": "address"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"indexed": true,
|
|
17
|
+
"internalType": "bytes32",
|
|
18
|
+
"name": "salt",
|
|
19
|
+
"type": "bytes32"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"name": "Deployed",
|
|
23
|
+
"type": "event"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"inputs": [
|
|
27
|
+
{
|
|
28
|
+
"internalType": "bytes32",
|
|
29
|
+
"name": "salt",
|
|
30
|
+
"type": "bytes32"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"internalType": "bytes",
|
|
34
|
+
"name": "creationCode",
|
|
35
|
+
"type": "bytes"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"internalType": "uint256",
|
|
39
|
+
"name": "value",
|
|
40
|
+
"type": "uint256"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"name": "deploy",
|
|
44
|
+
"outputs": [
|
|
45
|
+
{
|
|
46
|
+
"internalType": "address",
|
|
47
|
+
"name": "addr",
|
|
48
|
+
"type": "address"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"stateMutability": "nonpayable",
|
|
52
|
+
"type": "function"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"inputs": [
|
|
56
|
+
{
|
|
57
|
+
"internalType": "bytes32",
|
|
58
|
+
"name": "salt",
|
|
59
|
+
"type": "bytes32"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"internalType": "bytes32",
|
|
63
|
+
"name": "codeHash",
|
|
64
|
+
"type": "bytes32"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"name": "getAddress",
|
|
68
|
+
"outputs": [
|
|
69
|
+
{
|
|
70
|
+
"internalType": "address",
|
|
71
|
+
"name": "",
|
|
72
|
+
"type": "address"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"stateMutability": "view",
|
|
76
|
+
"type": "function"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"inputs": [
|
|
80
|
+
{
|
|
81
|
+
"internalType": "bytes32",
|
|
82
|
+
"name": "salt",
|
|
83
|
+
"type": "bytes32"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"internalType": "bytes32",
|
|
87
|
+
"name": "codeHash",
|
|
88
|
+
"type": "bytes32"
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"name": "getAddressTron",
|
|
92
|
+
"outputs": [
|
|
93
|
+
{
|
|
94
|
+
"internalType": "address",
|
|
95
|
+
"name": "",
|
|
96
|
+
"type": "address"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"stateMutability": "view",
|
|
100
|
+
"type": "function"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"bytecode": "0x6080604052348015600f57600080fd5b506102f98061001f6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063933559b014610046578063c7aeef0f14610075578063d3a3968614610088575b600080fd5b61005961005436600461018e565b61009b565b6040516001600160a01b03909116815260200160405180910390f35b6100596100833660046101c6565b6100d8565b61005961009636600461018e565b61016c565b6040516000906100b990604160f81b9030908690869060200161028a565b60408051601f1981840301815291905280516020909101209392505050565b60008383516020850184f590506001600160a01b03811661012f5760405162461bcd60e51b815260206004820152600d60248201526c1111541313d657d19052531151609a1b604482015260640160405180910390fd5b60405184906001600160a01b038316907f94bfd9af14ef450884c8a7ddb5734e2e1e14e70a1c84f0801cc5a29e34d2642890600090a39392505050565b6040516000906100b9906001600160f81b03199030908690869060200161028a565b600080604083850312156101a157600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b6000806000606084860312156101db57600080fd5b83359250602084013567ffffffffffffffff808211156101fa57600080fd5b818601915086601f83011261020e57600080fd5b813581811115610220576102206101b0565b604051601f8201601f19908116603f01168101908382118183101715610248576102486101b0565b8160405282815289602084870101111561026157600080fd5b826020860160208301376000602084830101528096505050505050604084013590509250925092565b6001600160f81b031994909416845260609290921b6bffffffffffffffffffffffff19166001840152601583015260358201526055019056fea26469706673582212205fb7d781d8404b93aed56d95e5543997fe78a250c5faf35b40c771504b4c853b64736f6c63430008190033",
|
|
104
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063933559b014610046578063c7aeef0f14610075578063d3a3968614610088575b600080fd5b61005961005436600461018e565b61009b565b6040516001600160a01b03909116815260200160405180910390f35b6100596100833660046101c6565b6100d8565b61005961009636600461018e565b61016c565b6040516000906100b990604160f81b9030908690869060200161028a565b60408051601f1981840301815291905280516020909101209392505050565b60008383516020850184f590506001600160a01b03811661012f5760405162461bcd60e51b815260206004820152600d60248201526c1111541313d657d19052531151609a1b604482015260640160405180910390fd5b60405184906001600160a01b038316907f94bfd9af14ef450884c8a7ddb5734e2e1e14e70a1c84f0801cc5a29e34d2642890600090a39392505050565b6040516000906100b9906001600160f81b03199030908690869060200161028a565b600080604083850312156101a157600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b6000806000606084860312156101db57600080fd5b83359250602084013567ffffffffffffffff808211156101fa57600080fd5b818601915086601f83011261020e57600080fd5b813581811115610220576102206101b0565b604051601f8201601f19908116603f01168101908382118183101715610248576102486101b0565b8160405282815289602084870101111561026157600080fd5b826020860160208301376000602084830101528096505050505050604084013590509250925092565b6001600160f81b031994909416845260609290921b6bffffffffffffffffffffffff19166001840152601583015260358201526055019056fea26469706673582212205fb7d781d8404b93aed56d95e5543997fe78a250c5faf35b40c771504b4c853b64736f6c63430008190033",
|
|
105
|
+
"linkReferences": {},
|
|
106
|
+
"deployedLinkReferences": {}
|
|
107
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title Create2Factory
|
|
6
|
+
* @notice Universal CREATE2 factory — works on both EVM and Tron.
|
|
7
|
+
* @dev Address prediction differs between EVM (0xff prefix) and Tron (0x41 prefix).
|
|
8
|
+
* Use getAddress() on EVM chains, getAddressTron() on Tron.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* // Deploy
|
|
12
|
+
* bytes32 salt = keccak256("my_salt");
|
|
13
|
+
* bytes memory code = abi.encodePacked(type(MyContract).creationCode, abi.encode(arg1));
|
|
14
|
+
* address addr = factory.deploy(salt, code, 0);
|
|
15
|
+
*
|
|
16
|
+
* // Predict address (off-chain or on-chain)
|
|
17
|
+
* bytes32 codeHash = keccak256(code);
|
|
18
|
+
* address predicted = factory.getAddress(salt, codeHash); // EVM
|
|
19
|
+
* address predicted = factory.getAddressTron(salt, codeHash); // Tron
|
|
20
|
+
*/
|
|
21
|
+
contract Create2Factory {
|
|
22
|
+
event Deployed(address indexed addr, bytes32 indexed salt);
|
|
23
|
+
|
|
24
|
+
/// @notice Deploy contract via CREATE2
|
|
25
|
+
/// @param salt Deterministic salt
|
|
26
|
+
/// @param creationCode Contract bytecode + constructor args
|
|
27
|
+
/// @param value Native token value to send to the new contract
|
|
28
|
+
/// @return addr The deployed contract address
|
|
29
|
+
function deploy(bytes32 salt, bytes memory creationCode, uint256 value)
|
|
30
|
+
external returns (address addr)
|
|
31
|
+
{
|
|
32
|
+
assembly {
|
|
33
|
+
addr := create2(value, add(creationCode, 0x20), mload(creationCode), salt)
|
|
34
|
+
}
|
|
35
|
+
require(addr != address(0), "DEPLOY_FAILED");
|
|
36
|
+
emit Deployed(addr, salt);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// @notice Predict CREATE2 address on EVM chains
|
|
40
|
+
/// @param salt The same salt used in deploy()
|
|
41
|
+
/// @param codeHash keccak256(creationCode) — includes constructor args
|
|
42
|
+
function getAddress(bytes32 salt, bytes32 codeHash) external view returns (address) {
|
|
43
|
+
return address(uint160(uint256(keccak256(
|
|
44
|
+
abi.encodePacked(bytes1(0xff), address(this), salt, codeHash)
|
|
45
|
+
))));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// @notice Predict CREATE2 address on Tron
|
|
49
|
+
/// @dev Tron uses 0x41 prefix instead of 0xff, and 21-byte sender (41 + 20-byte address)
|
|
50
|
+
/// @param salt The same salt used in deploy()
|
|
51
|
+
/// @param codeHash keccak256(creationCode) — includes constructor args
|
|
52
|
+
function getAddressTron(bytes32 salt, bytes32 codeHash) external view returns (address) {
|
|
53
|
+
return address(uint160(uint256(keccak256(
|
|
54
|
+
abi.encodePacked(bytes1(0x41), address(this), salt, codeHash)
|
|
55
|
+
))));
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
import type {
|
|
5
|
+
BaseContract,
|
|
6
|
+
BigNumberish,
|
|
7
|
+
BytesLike,
|
|
8
|
+
FunctionFragment,
|
|
9
|
+
Result,
|
|
10
|
+
Interface,
|
|
11
|
+
EventFragment,
|
|
12
|
+
AddressLike,
|
|
13
|
+
ContractRunner,
|
|
14
|
+
ContractMethod,
|
|
15
|
+
Listener,
|
|
16
|
+
} from "ethers";
|
|
17
|
+
import type {
|
|
18
|
+
TypedContractEvent,
|
|
19
|
+
TypedDeferredTopicFilter,
|
|
20
|
+
TypedEventLog,
|
|
21
|
+
TypedLogDescription,
|
|
22
|
+
TypedListener,
|
|
23
|
+
TypedContractMethod,
|
|
24
|
+
} from "../../common";
|
|
25
|
+
|
|
26
|
+
export interface Create2FactoryInterface extends Interface {
|
|
27
|
+
getFunction(
|
|
28
|
+
nameOrSignature: "deploy" | "getAddress" | "getAddressTron"
|
|
29
|
+
): FunctionFragment;
|
|
30
|
+
|
|
31
|
+
getEvent(nameOrSignatureOrTopic: "Deployed"): EventFragment;
|
|
32
|
+
|
|
33
|
+
encodeFunctionData(
|
|
34
|
+
functionFragment: "deploy",
|
|
35
|
+
values: [BytesLike, BytesLike, BigNumberish]
|
|
36
|
+
): string;
|
|
37
|
+
encodeFunctionData(
|
|
38
|
+
functionFragment: "getAddress",
|
|
39
|
+
values: [BytesLike, BytesLike]
|
|
40
|
+
): string;
|
|
41
|
+
encodeFunctionData(
|
|
42
|
+
functionFragment: "getAddressTron",
|
|
43
|
+
values: [BytesLike, BytesLike]
|
|
44
|
+
): string;
|
|
45
|
+
|
|
46
|
+
decodeFunctionResult(functionFragment: "deploy", data: BytesLike): Result;
|
|
47
|
+
decodeFunctionResult(functionFragment: "getAddress", data: BytesLike): Result;
|
|
48
|
+
decodeFunctionResult(
|
|
49
|
+
functionFragment: "getAddressTron",
|
|
50
|
+
data: BytesLike
|
|
51
|
+
): Result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export namespace DeployedEvent {
|
|
55
|
+
export type InputTuple = [addr: AddressLike, salt: BytesLike];
|
|
56
|
+
export type OutputTuple = [addr: string, salt: string];
|
|
57
|
+
export interface OutputObject {
|
|
58
|
+
addr: string;
|
|
59
|
+
salt: string;
|
|
60
|
+
}
|
|
61
|
+
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
|
|
62
|
+
export type Filter = TypedDeferredTopicFilter<Event>;
|
|
63
|
+
export type Log = TypedEventLog<Event>;
|
|
64
|
+
export type LogDescription = TypedLogDescription<Event>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Create2Factory extends BaseContract {
|
|
68
|
+
connect(runner?: ContractRunner | null): Create2Factory;
|
|
69
|
+
waitForDeployment(): Promise<this>;
|
|
70
|
+
|
|
71
|
+
interface: Create2FactoryInterface;
|
|
72
|
+
|
|
73
|
+
queryFilter<TCEvent extends TypedContractEvent>(
|
|
74
|
+
event: TCEvent,
|
|
75
|
+
fromBlockOrBlockhash?: string | number | undefined,
|
|
76
|
+
toBlock?: string | number | undefined
|
|
77
|
+
): Promise<Array<TypedEventLog<TCEvent>>>;
|
|
78
|
+
queryFilter<TCEvent extends TypedContractEvent>(
|
|
79
|
+
filter: TypedDeferredTopicFilter<TCEvent>,
|
|
80
|
+
fromBlockOrBlockhash?: string | number | undefined,
|
|
81
|
+
toBlock?: string | number | undefined
|
|
82
|
+
): Promise<Array<TypedEventLog<TCEvent>>>;
|
|
83
|
+
|
|
84
|
+
on<TCEvent extends TypedContractEvent>(
|
|
85
|
+
event: TCEvent,
|
|
86
|
+
listener: TypedListener<TCEvent>
|
|
87
|
+
): Promise<this>;
|
|
88
|
+
on<TCEvent extends TypedContractEvent>(
|
|
89
|
+
filter: TypedDeferredTopicFilter<TCEvent>,
|
|
90
|
+
listener: TypedListener<TCEvent>
|
|
91
|
+
): Promise<this>;
|
|
92
|
+
|
|
93
|
+
once<TCEvent extends TypedContractEvent>(
|
|
94
|
+
event: TCEvent,
|
|
95
|
+
listener: TypedListener<TCEvent>
|
|
96
|
+
): Promise<this>;
|
|
97
|
+
once<TCEvent extends TypedContractEvent>(
|
|
98
|
+
filter: TypedDeferredTopicFilter<TCEvent>,
|
|
99
|
+
listener: TypedListener<TCEvent>
|
|
100
|
+
): Promise<this>;
|
|
101
|
+
|
|
102
|
+
listeners<TCEvent extends TypedContractEvent>(
|
|
103
|
+
event: TCEvent
|
|
104
|
+
): Promise<Array<TypedListener<TCEvent>>>;
|
|
105
|
+
listeners(eventName?: string): Promise<Array<Listener>>;
|
|
106
|
+
removeAllListeners<TCEvent extends TypedContractEvent>(
|
|
107
|
+
event?: TCEvent
|
|
108
|
+
): Promise<this>;
|
|
109
|
+
|
|
110
|
+
deploy: TypedContractMethod<
|
|
111
|
+
[salt: BytesLike, creationCode: BytesLike, value: BigNumberish],
|
|
112
|
+
[string],
|
|
113
|
+
"nonpayable"
|
|
114
|
+
>;
|
|
115
|
+
|
|
116
|
+
getAddress: TypedContractMethod<
|
|
117
|
+
[salt: BytesLike, codeHash: BytesLike],
|
|
118
|
+
[string],
|
|
119
|
+
"view"
|
|
120
|
+
>;
|
|
121
|
+
|
|
122
|
+
getAddressTron: TypedContractMethod<
|
|
123
|
+
[salt: BytesLike, codeHash: BytesLike],
|
|
124
|
+
[string],
|
|
125
|
+
"view"
|
|
126
|
+
>;
|
|
127
|
+
|
|
128
|
+
getFunction<T extends ContractMethod = ContractMethod>(
|
|
129
|
+
key: string | FunctionFragment
|
|
130
|
+
): T;
|
|
131
|
+
|
|
132
|
+
getFunction(
|
|
133
|
+
nameOrSignature: "deploy"
|
|
134
|
+
): TypedContractMethod<
|
|
135
|
+
[salt: BytesLike, creationCode: BytesLike, value: BigNumberish],
|
|
136
|
+
[string],
|
|
137
|
+
"nonpayable"
|
|
138
|
+
>;
|
|
139
|
+
getFunction(
|
|
140
|
+
nameOrSignature: "getAddress"
|
|
141
|
+
): TypedContractMethod<
|
|
142
|
+
[salt: BytesLike, codeHash: BytesLike],
|
|
143
|
+
[string],
|
|
144
|
+
"view"
|
|
145
|
+
>;
|
|
146
|
+
getFunction(
|
|
147
|
+
nameOrSignature: "getAddressTron"
|
|
148
|
+
): TypedContractMethod<
|
|
149
|
+
[salt: BytesLike, codeHash: BytesLike],
|
|
150
|
+
[string],
|
|
151
|
+
"view"
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
getEvent(
|
|
155
|
+
key: "Deployed"
|
|
156
|
+
): TypedContractEvent<
|
|
157
|
+
DeployedEvent.InputTuple,
|
|
158
|
+
DeployedEvent.OutputTuple,
|
|
159
|
+
DeployedEvent.OutputObject
|
|
160
|
+
>;
|
|
161
|
+
|
|
162
|
+
filters: {
|
|
163
|
+
"Deployed(address,bytes32)": TypedContractEvent<
|
|
164
|
+
DeployedEvent.InputTuple,
|
|
165
|
+
DeployedEvent.OutputTuple,
|
|
166
|
+
DeployedEvent.OutputObject
|
|
167
|
+
>;
|
|
168
|
+
Deployed: TypedContractEvent<
|
|
169
|
+
DeployedEvent.InputTuple,
|
|
170
|
+
DeployedEvent.OutputTuple,
|
|
171
|
+
DeployedEvent.OutputObject
|
|
172
|
+
>;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
import {
|
|
5
|
+
Contract,
|
|
6
|
+
ContractFactory,
|
|
7
|
+
ContractTransactionResponse,
|
|
8
|
+
Interface,
|
|
9
|
+
} from "ethers";
|
|
10
|
+
import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers";
|
|
11
|
+
import type { NonPayableOverrides } from "../../../common";
|
|
12
|
+
import type {
|
|
13
|
+
Create2Factory,
|
|
14
|
+
Create2FactoryInterface,
|
|
15
|
+
} from "../../../contracts/factory/Create2Factory";
|
|
16
|
+
|
|
17
|
+
const _abi = [
|
|
18
|
+
{
|
|
19
|
+
anonymous: false,
|
|
20
|
+
inputs: [
|
|
21
|
+
{
|
|
22
|
+
indexed: true,
|
|
23
|
+
internalType: "address",
|
|
24
|
+
name: "addr",
|
|
25
|
+
type: "address",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
indexed: true,
|
|
29
|
+
internalType: "bytes32",
|
|
30
|
+
name: "salt",
|
|
31
|
+
type: "bytes32",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
name: "Deployed",
|
|
35
|
+
type: "event",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
inputs: [
|
|
39
|
+
{
|
|
40
|
+
internalType: "bytes32",
|
|
41
|
+
name: "salt",
|
|
42
|
+
type: "bytes32",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
internalType: "bytes",
|
|
46
|
+
name: "creationCode",
|
|
47
|
+
type: "bytes",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
internalType: "uint256",
|
|
51
|
+
name: "value",
|
|
52
|
+
type: "uint256",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
name: "deploy",
|
|
56
|
+
outputs: [
|
|
57
|
+
{
|
|
58
|
+
internalType: "address",
|
|
59
|
+
name: "addr",
|
|
60
|
+
type: "address",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
stateMutability: "nonpayable",
|
|
64
|
+
type: "function",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
inputs: [
|
|
68
|
+
{
|
|
69
|
+
internalType: "bytes32",
|
|
70
|
+
name: "salt",
|
|
71
|
+
type: "bytes32",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
internalType: "bytes32",
|
|
75
|
+
name: "codeHash",
|
|
76
|
+
type: "bytes32",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
name: "getAddress",
|
|
80
|
+
outputs: [
|
|
81
|
+
{
|
|
82
|
+
internalType: "address",
|
|
83
|
+
name: "",
|
|
84
|
+
type: "address",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
stateMutability: "view",
|
|
88
|
+
type: "function",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
inputs: [
|
|
92
|
+
{
|
|
93
|
+
internalType: "bytes32",
|
|
94
|
+
name: "salt",
|
|
95
|
+
type: "bytes32",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
internalType: "bytes32",
|
|
99
|
+
name: "codeHash",
|
|
100
|
+
type: "bytes32",
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
name: "getAddressTron",
|
|
104
|
+
outputs: [
|
|
105
|
+
{
|
|
106
|
+
internalType: "address",
|
|
107
|
+
name: "",
|
|
108
|
+
type: "address",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
stateMutability: "view",
|
|
112
|
+
type: "function",
|
|
113
|
+
},
|
|
114
|
+
] as const;
|
|
115
|
+
|
|
116
|
+
const _bytecode =
|
|
117
|
+
"0x6080604052348015600f57600080fd5b506102f98061001f6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063933559b014610046578063c7aeef0f14610075578063d3a3968614610088575b600080fd5b61005961005436600461018e565b61009b565b6040516001600160a01b03909116815260200160405180910390f35b6100596100833660046101c6565b6100d8565b61005961009636600461018e565b61016c565b6040516000906100b990604160f81b9030908690869060200161028a565b60408051601f1981840301815291905280516020909101209392505050565b60008383516020850184f590506001600160a01b03811661012f5760405162461bcd60e51b815260206004820152600d60248201526c1111541313d657d19052531151609a1b604482015260640160405180910390fd5b60405184906001600160a01b038316907f94bfd9af14ef450884c8a7ddb5734e2e1e14e70a1c84f0801cc5a29e34d2642890600090a39392505050565b6040516000906100b9906001600160f81b03199030908690869060200161028a565b600080604083850312156101a157600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b6000806000606084860312156101db57600080fd5b83359250602084013567ffffffffffffffff808211156101fa57600080fd5b818601915086601f83011261020e57600080fd5b813581811115610220576102206101b0565b604051601f8201601f19908116603f01168101908382118183101715610248576102486101b0565b8160405282815289602084870101111561026157600080fd5b826020860160208301376000602084830101528096505050505050604084013590509250925092565b6001600160f81b031994909416845260609290921b6bffffffffffffffffffffffff19166001840152601583015260358201526055019056fea26469706673582212205fb7d781d8404b93aed56d95e5543997fe78a250c5faf35b40c771504b4c853b64736f6c63430008190033";
|
|
118
|
+
|
|
119
|
+
type Create2FactoryConstructorParams =
|
|
120
|
+
| [signer?: Signer]
|
|
121
|
+
| ConstructorParameters<typeof ContractFactory>;
|
|
122
|
+
|
|
123
|
+
const isSuperArgs = (
|
|
124
|
+
xs: Create2FactoryConstructorParams
|
|
125
|
+
): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;
|
|
126
|
+
|
|
127
|
+
export class Create2Factory__factory extends ContractFactory {
|
|
128
|
+
constructor(...args: Create2FactoryConstructorParams) {
|
|
129
|
+
if (isSuperArgs(args)) {
|
|
130
|
+
super(...args);
|
|
131
|
+
} else {
|
|
132
|
+
super(_abi, _bytecode, args[0]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override getDeployTransaction(
|
|
137
|
+
overrides?: NonPayableOverrides & { from?: string }
|
|
138
|
+
): Promise<ContractDeployTransaction> {
|
|
139
|
+
return super.getDeployTransaction(overrides || {});
|
|
140
|
+
}
|
|
141
|
+
override deploy(overrides?: NonPayableOverrides & { from?: string }) {
|
|
142
|
+
return super.deploy(overrides || {}) as Promise<
|
|
143
|
+
Create2Factory & {
|
|
144
|
+
deploymentTransaction(): ContractTransactionResponse;
|
|
145
|
+
}
|
|
146
|
+
>;
|
|
147
|
+
}
|
|
148
|
+
override connect(runner: ContractRunner | null): Create2Factory__factory {
|
|
149
|
+
return super.connect(runner) as Create2Factory__factory;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static readonly bytecode = _bytecode;
|
|
153
|
+
static readonly abi = _abi;
|
|
154
|
+
static createInterface(): Create2FactoryInterface {
|
|
155
|
+
return new Interface(_abi) as Create2FactoryInterface;
|
|
156
|
+
}
|
|
157
|
+
static connect(
|
|
158
|
+
address: string,
|
|
159
|
+
runner?: ContractRunner | null
|
|
160
|
+
): Create2Factory {
|
|
161
|
+
return new Contract(address, _abi, runner) as unknown as Create2Factory;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -89,6 +89,10 @@ declare module "hardhat/types/runtime" {
|
|
|
89
89
|
name: "BaseImplementation",
|
|
90
90
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
91
91
|
): Promise<Contracts.BaseImplementation__factory>;
|
|
92
|
+
getContractFactory(
|
|
93
|
+
name: "Create2Factory",
|
|
94
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
95
|
+
): Promise<Contracts.Create2Factory__factory>;
|
|
92
96
|
|
|
93
97
|
getContractAt(
|
|
94
98
|
name: "AccessManagedUpgradeable",
|
|
@@ -185,6 +189,11 @@ declare module "hardhat/types/runtime" {
|
|
|
185
189
|
address: string | ethers.Addressable,
|
|
186
190
|
signer?: ethers.Signer
|
|
187
191
|
): Promise<Contracts.BaseImplementation>;
|
|
192
|
+
getContractAt(
|
|
193
|
+
name: "Create2Factory",
|
|
194
|
+
address: string | ethers.Addressable,
|
|
195
|
+
signer?: ethers.Signer
|
|
196
|
+
): Promise<Contracts.Create2Factory>;
|
|
188
197
|
|
|
189
198
|
deployContract(
|
|
190
199
|
name: "AccessManagedUpgradeable",
|
|
@@ -262,6 +271,10 @@ declare module "hardhat/types/runtime" {
|
|
|
262
271
|
name: "BaseImplementation",
|
|
263
272
|
signerOrOptions?: ethers.Signer | DeployContractOptions
|
|
264
273
|
): Promise<Contracts.BaseImplementation>;
|
|
274
|
+
deployContract(
|
|
275
|
+
name: "Create2Factory",
|
|
276
|
+
signerOrOptions?: ethers.Signer | DeployContractOptions
|
|
277
|
+
): Promise<Contracts.Create2Factory>;
|
|
265
278
|
|
|
266
279
|
deployContract(
|
|
267
280
|
name: "AccessManagedUpgradeable",
|
|
@@ -358,6 +371,11 @@ declare module "hardhat/types/runtime" {
|
|
|
358
371
|
args: any[],
|
|
359
372
|
signerOrOptions?: ethers.Signer | DeployContractOptions
|
|
360
373
|
): Promise<Contracts.BaseImplementation>;
|
|
374
|
+
deployContract(
|
|
375
|
+
name: "Create2Factory",
|
|
376
|
+
args: any[],
|
|
377
|
+
signerOrOptions?: ethers.Signer | DeployContractOptions
|
|
378
|
+
): Promise<Contracts.Create2Factory>;
|
|
361
379
|
|
|
362
380
|
// default types
|
|
363
381
|
getContractFactory(
|
package/typechain-types/index.ts
CHANGED
|
@@ -44,3 +44,5 @@ export type { AuthorityManager } from "./contracts/AuthorityManager";
|
|
|
44
44
|
export { AuthorityManager__factory } from "./factories/contracts/AuthorityManager__factory";
|
|
45
45
|
export type { BaseImplementation } from "./contracts/base/BaseImplementation";
|
|
46
46
|
export { BaseImplementation__factory } from "./factories/contracts/base/BaseImplementation__factory";
|
|
47
|
+
export type { Create2Factory } from "./contracts/factory/Create2Factory";
|
|
48
|
+
export { Create2Factory__factory } from "./factories/contracts/factory/Create2Factory__factory";
|
package/utils/addressCodec.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-chain address encoding — converts EVM, Tron, and Solana addresses to hex bytes.
|
|
3
|
+
*/
|
|
1
4
|
import bs58 from "bs58";
|
|
5
|
+
import { tronToHex } from "./tronHelper";
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
|
-
* Convert address to hex bytes
|
|
5
|
-
* - EVM address (0x prefix): return as-is
|
|
6
|
-
* - Tron address (T prefix, 34 chars):
|
|
8
|
+
* Convert any address format to hex bytes.
|
|
9
|
+
* - EVM address (0x prefix): return as-is lowercase
|
|
10
|
+
* - Tron address (T prefix, 34 chars, 0x41 byte): convert via tronToHex
|
|
7
11
|
* - Solana/other base58 address: base58 decode to full bytes
|
|
12
|
+
* @param addr - address in any supported format
|
|
8
13
|
*/
|
|
9
14
|
export function addressToHex(addr: string): string {
|
|
10
15
|
if (addr.startsWith("0x")) {
|
|
@@ -12,10 +17,7 @@ export function addressToHex(addr: string): string {
|
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
if (isTronAddress(addr)) {
|
|
15
|
-
|
|
16
|
-
// Tron format: 0x41 (1 byte) + address (20 bytes) + checksum (4 bytes)
|
|
17
|
-
const addressBytes = decoded.slice(1, 21);
|
|
18
|
-
return "0x" + Buffer.from(addressBytes).toString("hex");
|
|
20
|
+
return tronToHex(addr);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
if (isBase58(addr)) {
|
|
@@ -26,6 +28,7 @@ export function addressToHex(addr: string): string {
|
|
|
26
28
|
throw new Error(`Unknown address format: ${addr}`);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
/** Check if a string is valid base58 encoding. */
|
|
29
32
|
export function isBase58(addr: string): boolean {
|
|
30
33
|
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
31
34
|
for (const char of addr) {
|
|
@@ -36,6 +39,7 @@ export function isBase58(addr: string): boolean {
|
|
|
36
39
|
return true;
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
/** Check if address is Tron format (T prefix, 34 chars, 0x41 first byte after decode). */
|
|
39
43
|
export function isTronAddress(addr: string): boolean {
|
|
40
44
|
if (!addr.startsWith("T") || addr.length !== 34 || !isBase58(addr)) return false;
|
|
41
45
|
try {
|
|
@@ -47,6 +51,7 @@ export function isTronAddress(addr: string): boolean {
|
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
|
|
54
|
+
/** Check if chain name is Solana. */
|
|
50
55
|
export function isSolanaChain(chainName: string): boolean {
|
|
51
56
|
return chainName === "Sol" || chainName === "sol_test";
|
|
52
57
|
}
|