Skip to content

Commit b54ae53

Browse files
authored
[protocol 3.6] Bridge and Converter (#2218)
1 parent c3a2d89 commit b54ae53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4981
-788
lines changed

packages/hebao_v2/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
_[hebao]_(荷包)means wallet in China -- see https://www.pinterest.com/pin/373376625330954965 for examples.
44

55
# Build
6+
67
```
78
yarn install
89
yarn compile
910
```
1011

1112
# Run test
13+
1214
```
1315
yarn test
1416
```
1517

1618
# Deploy contract to arbitrum:
19+
1720
```
1821
npx hardhat run --network arbitrum scripts/deploy-arbitrum.ts
1922
```

packages/hebao_v2/hardhat.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export default {
6868
gasMultiplier: 1,
6969
timeout: 20000,
7070
httpHeaders: undefined,
71-
accounts: loadTestAccounts().map(item => item.privateKey).slice()
71+
accounts: loadTestAccounts()
72+
.map(item => item.privateKey)
73+
.slice()
7274
}
7375
},
7476

packages/hebao_v2/script/deploy-arbitrum.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const hre = require("hardhat");
22
const ethers = hre.ethers;
3-
import {
4-
newWalletImpl,
5-
newWalletFactoryContract
6-
} from "../test/commons";
3+
import { newWalletImpl, newWalletFactoryContract } from "../test/commons";
74
import { signCreateWallet } from "../test/helper/signatureUtils";
85
import BN = require("bn.js");
96

@@ -37,17 +34,19 @@ async function newWallet() {
3734
signature: Buffer.from(signature.txSignature.slice(2), "hex")
3835
};
3936

40-
const walletFactory = await (await ethers.getContractFactory(
41-
"WalletFactory"
42-
)).attach(walletFactoryAddress);
37+
const walletFactory = await (
38+
await ethers.getContractFactory("WalletFactory")
39+
).attach(walletFactoryAddress);
4340

4441
const walletAddrComputed = await walletFactory.computeWalletAddress(
4542
ownerAddr,
4643
salt
4744
);
4845
console.log("walletAddrcomputed:", walletAddrComputed);
4946

50-
const tx = await walletFactory.createWallet(walletConfig, salt, { gasLimit:10000000 });
47+
const tx = await walletFactory.createWallet(walletConfig, salt, {
48+
gasLimit: 10000000
49+
});
5150
console.log("tx:", tx);
5251
const receipt = await tx.wait();
5352
console.log("receipt:", receipt);

packages/hebao_v2/test/callContract.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ describe("wallet", () => {
2323
account2
2424
);
2525
LRC = await (await ethers.getContractFactory("LRC")).deploy();
26-
TestContract = await (await ethers.getContractFactory(
27-
"TestTargetContract"
28-
)).deploy();
26+
TestContract = await (
27+
await ethers.getContractFactory("TestTargetContract")
28+
).deploy();
2929
});
3030

3131
describe("callContract", () => {

packages/hebao_v2/test/commons.ts

Lines changed: 132 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,61 @@ import BN = require("bn.js");
77
import { signCreateWallet } from "./helper/signatureUtils";
88

99
export async function newWalletImpl() {
10-
const ERC1271Lib = await (await ethers.getContractFactory(
11-
"ERC1271Lib"
12-
)).deploy();
10+
const ERC1271Lib = await (
11+
await ethers.getContractFactory("ERC1271Lib")
12+
).deploy();
1313
const ERC20Lib = await (await ethers.getContractFactory("ERC20Lib")).deploy();
14-
const GuardianLib = await (await ethers.getContractFactory(
15-
"GuardianLib"
16-
)).deploy();
17-
const InheritanceLib = await (await ethers.getContractFactory(
18-
"InheritanceLib"
19-
)).deploy();
20-
const LockLib = await (await ethers.getContractFactory("LockLib", {
21-
libraries: {
22-
GuardianLib: GuardianLib.address
23-
}
24-
})).deploy();
25-
const MetaTxLib = await (await ethers.getContractFactory("MetaTxLib", {
26-
libraries: {
27-
ERC20Lib: ERC20Lib.address
28-
}
29-
})).deploy();
14+
const GuardianLib = await (
15+
await ethers.getContractFactory("GuardianLib")
16+
).deploy();
17+
const InheritanceLib = await (
18+
await ethers.getContractFactory("InheritanceLib")
19+
).deploy();
20+
const LockLib = await (
21+
await ethers.getContractFactory("LockLib", {
22+
libraries: {
23+
GuardianLib: GuardianLib.address
24+
}
25+
})
26+
).deploy();
27+
const MetaTxLib = await (
28+
await ethers.getContractFactory("MetaTxLib", {
29+
libraries: {
30+
ERC20Lib: ERC20Lib.address
31+
}
32+
})
33+
).deploy();
3034
const QuotaLib = await (await ethers.getContractFactory("QuotaLib")).deploy();
31-
const RecoverLib = await (await ethers.getContractFactory("RecoverLib", {
32-
libraries: {
33-
GuardianLib: GuardianLib.address
34-
}
35-
})).deploy();
36-
const UpgradeLib = await (await ethers.getContractFactory(
37-
"UpgradeLib"
38-
)).deploy();
39-
const WhitelistLib = await (await ethers.getContractFactory(
40-
"WhitelistLib"
41-
)).deploy();
35+
const RecoverLib = await (
36+
await ethers.getContractFactory("RecoverLib", {
37+
libraries: {
38+
GuardianLib: GuardianLib.address
39+
}
40+
})
41+
).deploy();
42+
const UpgradeLib = await (
43+
await ethers.getContractFactory("UpgradeLib")
44+
).deploy();
45+
const WhitelistLib = await (
46+
await ethers.getContractFactory("WhitelistLib")
47+
).deploy();
4248

43-
const smartWallet = await (await ethers.getContractFactory("SmartWallet", {
44-
libraries: {
45-
ERC1271Lib: ERC1271Lib.address,
46-
ERC20Lib: ERC20Lib.address,
47-
GuardianLib: GuardianLib.address,
48-
InheritanceLib: InheritanceLib.address,
49-
LockLib: LockLib.address,
50-
MetaTxLib: MetaTxLib.address,
51-
QuotaLib: QuotaLib.address,
52-
RecoverLib: RecoverLib.address,
53-
UpgradeLib: UpgradeLib.address,
54-
WhitelistLib: WhitelistLib.address
55-
}
56-
})).deploy(ethers.constants.AddressZero);
49+
const smartWallet = await (
50+
await ethers.getContractFactory("SmartWallet", {
51+
libraries: {
52+
ERC1271Lib: ERC1271Lib.address,
53+
ERC20Lib: ERC20Lib.address,
54+
GuardianLib: GuardianLib.address,
55+
InheritanceLib: InheritanceLib.address,
56+
LockLib: LockLib.address,
57+
MetaTxLib: MetaTxLib.address,
58+
QuotaLib: QuotaLib.address,
59+
RecoverLib: RecoverLib.address,
60+
UpgradeLib: UpgradeLib.address,
61+
WhitelistLib: WhitelistLib.address
62+
}
63+
})
64+
).deploy(ethers.constants.AddressZero);
5765

5866
return smartWallet;
5967
}
@@ -63,62 +71,70 @@ export async function newWalletFactoryContract(deployer?: string) {
6371
let smartWallet: Contract;
6472
let walletFactory: Contract;
6573

66-
testPriceOracle = await (await ethers.getContractFactory(
67-
"TestPriceOracle"
68-
)).deploy();
74+
testPriceOracle = await (
75+
await ethers.getContractFactory("TestPriceOracle")
76+
).deploy();
6977

70-
const ERC1271Lib = await (await ethers.getContractFactory(
71-
"ERC1271Lib"
72-
)).deploy();
78+
const ERC1271Lib = await (
79+
await ethers.getContractFactory("ERC1271Lib")
80+
).deploy();
7381
const ERC20Lib = await (await ethers.getContractFactory("ERC20Lib")).deploy();
74-
const GuardianLib = await (await ethers.getContractFactory(
75-
"GuardianLib"
76-
)).deploy();
77-
const InheritanceLib = await (await ethers.getContractFactory(
78-
"InheritanceLib"
79-
)).deploy();
80-
const LockLib = await (await ethers.getContractFactory("LockLib", {
81-
libraries: {
82-
GuardianLib: GuardianLib.address
83-
}
84-
})).deploy();
85-
const MetaTxLib = await (await ethers.getContractFactory("MetaTxLib", {
86-
libraries: {
87-
ERC20Lib: ERC20Lib.address
88-
}
89-
})).deploy();
82+
const GuardianLib = await (
83+
await ethers.getContractFactory("GuardianLib")
84+
).deploy();
85+
const InheritanceLib = await (
86+
await ethers.getContractFactory("InheritanceLib")
87+
).deploy();
88+
const LockLib = await (
89+
await ethers.getContractFactory("LockLib", {
90+
libraries: {
91+
GuardianLib: GuardianLib.address
92+
}
93+
})
94+
).deploy();
95+
const MetaTxLib = await (
96+
await ethers.getContractFactory("MetaTxLib", {
97+
libraries: {
98+
ERC20Lib: ERC20Lib.address
99+
}
100+
})
101+
).deploy();
90102
const QuotaLib = await (await ethers.getContractFactory("QuotaLib")).deploy();
91-
const RecoverLib = await (await ethers.getContractFactory("RecoverLib", {
92-
libraries: {
93-
GuardianLib: GuardianLib.address
94-
}
95-
})).deploy();
96-
const UpgradeLib = await (await ethers.getContractFactory(
97-
"UpgradeLib"
98-
)).deploy();
99-
const WhitelistLib = await (await ethers.getContractFactory(
100-
"WhitelistLib"
101-
)).deploy();
103+
const RecoverLib = await (
104+
await ethers.getContractFactory("RecoverLib", {
105+
libraries: {
106+
GuardianLib: GuardianLib.address
107+
}
108+
})
109+
).deploy();
110+
const UpgradeLib = await (
111+
await ethers.getContractFactory("UpgradeLib")
112+
).deploy();
113+
const WhitelistLib = await (
114+
await ethers.getContractFactory("WhitelistLib")
115+
).deploy();
102116

103-
smartWallet = await (await ethers.getContractFactory("SmartWallet", {
104-
libraries: {
105-
ERC1271Lib: ERC1271Lib.address,
106-
ERC20Lib: ERC20Lib.address,
107-
GuardianLib: GuardianLib.address,
108-
InheritanceLib: InheritanceLib.address,
109-
LockLib: LockLib.address,
110-
MetaTxLib: MetaTxLib.address,
111-
QuotaLib: QuotaLib.address,
112-
RecoverLib: RecoverLib.address,
113-
UpgradeLib: UpgradeLib.address,
114-
WhitelistLib: WhitelistLib.address
115-
}
116-
})).deploy(ethers.constants.AddressZero /*testPriceOracle.address*/);
117+
smartWallet = await (
118+
await ethers.getContractFactory("SmartWallet", {
119+
libraries: {
120+
ERC1271Lib: ERC1271Lib.address,
121+
ERC20Lib: ERC20Lib.address,
122+
GuardianLib: GuardianLib.address,
123+
InheritanceLib: InheritanceLib.address,
124+
LockLib: LockLib.address,
125+
MetaTxLib: MetaTxLib.address,
126+
QuotaLib: QuotaLib.address,
127+
RecoverLib: RecoverLib.address,
128+
UpgradeLib: UpgradeLib.address,
129+
WhitelistLib: WhitelistLib.address
130+
}
131+
})
132+
).deploy(ethers.constants.AddressZero /*testPriceOracle.address*/);
117133
console.log("smartWallet address:", smartWallet.address);
118134

119-
walletFactory = await (await ethers.getContractFactory(
120-
"WalletFactory"
121-
)).deploy(smartWallet.address);
135+
walletFactory = await (
136+
await ethers.getContractFactory("WalletFactory")
137+
).deploy(smartWallet.address);
122138

123139
await walletFactory.deployed();
124140

@@ -171,29 +187,28 @@ export async function newWallet(
171187
// const allEvents = await getAllEvent(walletFactory, tx.blockNumber);
172188
// console.log(allEvents);
173189

174-
const smartWallet = await (await ethers.getContractFactory("SmartWallet", {
175-
libraries: {
176-
ERC1271Lib: ethers.constants.AddressZero,
177-
ERC20Lib: ethers.constants.AddressZero,
178-
GuardianLib: ethers.constants.AddressZero,
179-
InheritanceLib: ethers.constants.AddressZero,
180-
LockLib: ethers.constants.AddressZero,
181-
MetaTxLib: ethers.constants.AddressZero,
182-
QuotaLib: ethers.constants.AddressZero,
183-
RecoverLib: ethers.constants.AddressZero,
184-
UpgradeLib: ethers.constants.AddressZero,
185-
WhitelistLib: ethers.constants.AddressZero
186-
}
187-
})).attach(walletAddrComputed);
190+
const smartWallet = await (
191+
await ethers.getContractFactory("SmartWallet", {
192+
libraries: {
193+
ERC1271Lib: ethers.constants.AddressZero,
194+
ERC20Lib: ethers.constants.AddressZero,
195+
GuardianLib: ethers.constants.AddressZero,
196+
InheritanceLib: ethers.constants.AddressZero,
197+
LockLib: ethers.constants.AddressZero,
198+
MetaTxLib: ethers.constants.AddressZero,
199+
QuotaLib: ethers.constants.AddressZero,
200+
RecoverLib: ethers.constants.AddressZero,
201+
UpgradeLib: ethers.constants.AddressZero,
202+
WhitelistLib: ethers.constants.AddressZero
203+
}
204+
})
205+
).attach(walletAddrComputed);
188206

189207
// console.log("SmartWallet:", smartWallet);
190208
return smartWallet;
191209
}
192210

193-
export async function getAllEvent(
194-
contract: any,
195-
fromBlock: number
196-
) {
211+
export async function getAllEvent(contract: any, fromBlock: number) {
197212
const events = await contract.queryFilter(
198213
{ address: contract.address },
199214
fromBlock
@@ -250,9 +265,12 @@ export async function getContractABI(contractName: string) {
250265
});
251266
}
252267

253-
export function sortSignersAndSignatures(signers: string[], signatures: Buffer[]) {
268+
export function sortSignersAndSignatures(
269+
signers: string[],
270+
signatures: Buffer[]
271+
) {
254272
const sigMap = new Map();
255-
signers.forEach(function(signer, i){
273+
signers.forEach(function(signer, i) {
256274
sigMap.set(signer, signatures[i]);
257275
});
258276

packages/hebao_v2/test/helper/signatureUtils.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,13 @@ export function signChangeMasterCopy(
7979
signer: string
8080
) {
8181
const domainSeprator = eip712.hash("LoopringWallet", "2.0.0", masterCopy);
82-
const TYPE_STR = "changeMasterCopy(address wallet,uint256 validUntil,address masterCopy)";
82+
const TYPE_STR =
83+
"changeMasterCopy(address wallet,uint256 validUntil,address masterCopy)";
8384
const CREATE_WALLET_TYPEHASH = ethUtil.keccak(Buffer.from(TYPE_STR));
8485

8586
const encodedRequest = ethAbi.encodeParameters(
86-
[
87-
"bytes32",
88-
"address",
89-
"uint256",
90-
"address"
91-
],
92-
[
93-
CREATE_WALLET_TYPEHASH,
94-
walletAddress,
95-
validUntil,
96-
newMasterCopy
97-
]
87+
["bytes32", "address", "uint256", "address"],
88+
[CREATE_WALLET_TYPEHASH, walletAddress, validUntil, newMasterCopy]
9889
);
9990

10091
const hash = eip712.hashPacked(domainSeprator, encodedRequest);

0 commit comments

Comments
 (0)