Skip to content

Commit 82374c0

Browse files
add some read functions in SmartWallet (#2374)
1 parent 4405cf9 commit 82374c0

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

packages/hebao_v2/contracts/base/SmartWallet.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ contract SmartWallet is ERC1271
4040
bytes32 public immutable DOMAIN_SEPARATOR;
4141
PriceOracle public immutable priceOracle;
4242

43+
4344
// WARNING: Do not delete wallet state data to make this implementation
4445
// compatible with early versions.
4546
//
@@ -222,6 +223,14 @@ contract SmartWallet is ERC1271
222223
return wallet.isGuardian(addr, includePendingAddition);
223224
}
224225

226+
function guardians(bool includePendingAddition)
227+
public
228+
view
229+
returns (Guardian[] memory )
230+
{
231+
return GuardianLib.guardians(wallet, includePendingAddition);
232+
}
233+
225234
//
226235
// Inheritance
227236
//
@@ -331,6 +340,14 @@ contract SmartWallet is ERC1271
331340
wallet.batchCall(to, data);
332341
}
333342

343+
function getNonce(address relayer)
344+
public
345+
view
346+
returns (uint)
347+
{
348+
return wallet.nonce[relayer];
349+
}
350+
334351
//
335352
// Recover
336353
//
@@ -393,6 +410,15 @@ contract SmartWallet is ERC1271
393410
return wallet.whitelisted[addr];
394411
}
395412

413+
function isWhitelisted(
414+
address addr
415+
)
416+
public
417+
view
418+
returns (bool) {
419+
return wallet.isAddressWhitelisted(addr);
420+
}
421+
396422
//
397423
// ERC20
398424
//

packages/hebao_v2/test/helper/Constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export class Constants {
22
static readonly emptyBytes: any = [];
33
static readonly zeroAddress = "0x" + "00".repeat(20);
44
static readonly emptyBytes32 = "0x" + "00".repeat(32);
5-
static readonly chainId = 31337; // hardhat & ganache default chainId
5+
static readonly chainId = 31337; // hardhat & ganache default chainId
6+
67
// static readonly chainId = 212984383488152; // arbitrum testnet chainId
78
// static readonly chainId = 97; // binance bsc testnet chainId
89
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { expect } from "./setup";
2+
import { signCreateWallet } from "./helper/signatureUtils";
3+
import { sign } from "./helper/Signature";
4+
import {
5+
newWallet,
6+
getFirstEvent,
7+
advanceTime,
8+
getBlockTimestamp
9+
} from "./commons";
10+
// import { /*l2ethers as*/ ethers } from "hardhat";
11+
const { ethers } = require("hardhat");
12+
13+
import { Contract, Signer } from "ethers";
14+
import BN = require("bn.js");
15+
16+
describe("wallet", () => {
17+
let account1: Signer;
18+
let account2: Signer;
19+
let account3: Signer;
20+
21+
let wallet: any;
22+
23+
before(async () => {
24+
[account1, account2, account3] = await ethers.getSigners();
25+
const owner = await account1.getAddress();
26+
const guardians = ["0x" + "11".repeat(20)];
27+
wallet = await newWallet(owner, ethers.constants.AddressZero, 0, guardians);
28+
29+
const quotaAmount = ethers.utils.parseEther("10");
30+
await wallet.changeDailyQuota(quotaAmount);
31+
// const quotaInfo = (await wallet.wallet())["quota"];
32+
});
33+
34+
describe.only("read methods", () => {
35+
it("quota", async () => {
36+
const walletData = await wallet.wallet();
37+
console.log("quota:", walletData["quota"]);
38+
});
39+
40+
it("guardians", async () => {
41+
const guardians = await wallet.guardians(true);
42+
console.log("guardians:", guardians);
43+
});
44+
45+
it("isWhitelisted", async () => {
46+
const isWhitelisted = await wallet.isWhitelisted("0x" + "22".repeat(20));
47+
console.log("isWhitelisted:", isWhitelisted);
48+
});
49+
50+
it("getNonce", async () => {
51+
const nonce = await wallet.getNonce("0x" + "11".repeat(20));
52+
console.log("nonce:", nonce);
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)