Skip to content

Commit 4e58060

Browse files
committed
Update iguWallet
1 parent 0bc59da commit 4e58060

File tree

4 files changed

+140
-32
lines changed

4 files changed

+140
-32
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ https://bscscan.com/address/0xb085320eaBC561506E818CE1BFc35347076c1184
100100

101101
#### IGU Wallet
102102

103-
```0xaf759Af05f4a03B3ff42F86Be58C4CD651542242```
103+
```0x4C63e0d152aC4149E0d501ace532a12B0f553416```
104104

105105
https://bscscan.com/address/0xaf759Af05f4a03B3ff42F86Be58C4CD651542242
106106

contracts/wallet/IguWallet.sol

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,29 @@ contract IguWallet is Ownable, EIP712 {
4343
uint256 amount,
4444
uint256 fee,
4545
uint256 nonce,
46+
uint256 deadline,
4647
bytes memory signature
4748
) external {
4849
require(
4950
!isNonceUsed[nonce],
5051
"IguWallet: Nonce already used"
5152
);
53+
require(deadline>block.timestamp, "IguWallet: Transaction overdue");
5254
isNonceUsed[nonce] = true;
5355
bytes32 typedHash = _hashTypedDataV4(
5456
keccak256(
5557
abi.encode(
5658
keccak256(
57-
"WithdrawData(address walletAddress,uint256 amount,uint256 fee,uint256 nonce)"
59+
"WithdrawData(address walletAddress,uint256 amount,uint256 fee,uint256 nonce,uint256 deadline)"
5860
),
5961
walletAddress,
6062
amount,
6163
fee,
62-
nonce
64+
nonce,
65+
deadline
6366
)
6467
)
65-
);
68+
);
6669
require(
6770
ECDSA.recover(typedHash, signature) == signer,
6871
"IguWallet: Signature Mismatch"

deployments/bsc/IguWallet.json

+33-28
Large diffs are not rendered by default.

test/iguWallet.ts

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import {
2+
ContractReceipt,
3+
ContractTransaction,
4+
} from "@ethersproject/contracts/src.ts/index";
5+
import { Network } from "@ethersproject/networks";
6+
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
7+
import { expect } from "chai";
8+
import { BigNumber } from "ethers";
9+
import { ethers } from "hardhat";
10+
import { IguToken, IguWallet, Iguverse } from "../typechain-types";
11+
import { deployContract, txExec } from "./helpers/utils";
12+
13+
describe("Iguverse", function () {
14+
let owner: SignerWithAddress;
15+
let signer: SignerWithAddress;
16+
let bob: SignerWithAddress;
17+
let alice: SignerWithAddress;
18+
19+
let iguToken: IguToken;
20+
let iguWallet: IguWallet;
21+
22+
let network: Network;
23+
24+
beforeEach(async () => {
25+
[owner, signer, bob, alice] = await ethers.getSigners();
26+
network = await ethers.provider.getNetwork();
27+
28+
iguToken = await deployContract("IguToken");
29+
iguWallet = await deployContract(
30+
"IguWallet",
31+
iguToken.address,
32+
owner.address,
33+
owner.address
34+
);
35+
36+
await iguToken
37+
.connect(owner)
38+
.approve(iguWallet.address, ethers.utils.parseEther("100"));
39+
40+
await iguWallet.deposit(ethers.utils.parseEther("100"));
41+
});
42+
43+
describe("Signatures", () => {
44+
let tx: ContractTransaction;
45+
let recipt: ContractReceipt;
46+
let balanceBefore: BigNumber;
47+
48+
beforeEach(async () => {
49+
const domainData = {
50+
name: "Iguverse",
51+
version: "1",
52+
chainId: network.chainId,
53+
verifyingContract: iguWallet.address,
54+
};
55+
56+
const types = {
57+
WithdrawData: [
58+
{ name: "walletAddress", type: "address" },
59+
{ name: "amount", type: "uint256" },
60+
{ name: "fee", type: "uint256" },
61+
{ name: "nonce", type: "uint256" },
62+
{ name: "deadline", type: "uint256" },
63+
],
64+
};
65+
66+
const value = {
67+
walletAddress: owner.address,
68+
amount: ethers.utils.parseEther("50"),
69+
fee: ethers.utils.parseEther("10"),
70+
nonce: "123",
71+
deadline: "1000000000000"
72+
};
73+
74+
balanceBefore = await ethers.provider.getBalance(alice.address);
75+
76+
const signature = await owner._signTypedData(domainData, types, value);
77+
78+
[tx, recipt] = await txExec(
79+
iguWallet.connect(owner)
80+
.withdraw(
81+
value.walletAddress,
82+
value.amount,
83+
value.fee,
84+
value.nonce,
85+
value.deadline,
86+
signature
87+
)
88+
);
89+
});
90+
91+
it("Should emit IguToken Transfer event", async () => {
92+
await expect(tx)
93+
.to.emit(iguToken, "Transfer")
94+
.withArgs(iguWallet.address, owner.address, ethers.utils.parseEther("50"));
95+
await expect(tx)
96+
.to.emit(iguToken, "Transfer")
97+
.withArgs(iguWallet.address, owner.address, ethers.utils.parseEther("10"));
98+
});
99+
});
100+
});

0 commit comments

Comments
 (0)