Skip to content

Commit 16f6011

Browse files
Hebaov2 proxy call (#2571)
* [hebaov2] add some test for proxy call * revert mainnet contract addresses
1 parent fe1f69c commit 16f6011

File tree

7 files changed

+114
-10
lines changed

7 files changed

+114
-10
lines changed

packages/hebao_v2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ artifacts/
66
cache/
77
build/
88
ABI/
9+
libraries.js

packages/hebao_v2/contracts/price/UniswapV2PriceOracle.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ contract UniswapV2PriceOracle is PriceOracle
1414
{
1515
using MathUint for uint;
1616

17-
IUniswapV2Factory public immutable factory;
17+
IUniswapV2Factory public factory;
1818
address public immutable wethAddress;
1919

2020
constructor(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
// Copyright 2017 Loopring Technology Limited.
3+
pragma solidity ^0.7.0;
4+
5+
import "../iface/PriceOracle.sol";
6+
7+
/// @title PriceOracle
8+
contract PriceOracleDelegate is PriceOracle
9+
{
10+
PriceOracle public immutable priceOracle;
11+
12+
constructor(
13+
PriceOracle _priceOracle
14+
)
15+
{
16+
priceOracle = _priceOracle;
17+
}
18+
19+
function tokenValue(address token, uint amount)
20+
public
21+
view
22+
override
23+
returns (uint value)
24+
{
25+
return priceOracle.tokenValue(token, amount);
26+
}
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
// Copyright 2017 Loopring Technology Limited.
3+
pragma solidity ^0.7.0;
4+
5+
/// @title PriceOracle
6+
contract TestUniswapV2Factory
7+
{
8+
mapping(address => mapping(address => address)) public getPair;
9+
}

packages/hebao_v2/deployment-mainnet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
## Ethereum mainnet
44

55
- deployer: 0x4374D3d032B3c96785094ec9f384f07077792768
6-
- priceOracle: 0x8fD3D838ffCEeB4FF4Dd5B0221A99C3B1dDB9aC9
6+
- priceOracle: 0xb124190942976431d8181fbe183e44584253da68
77
- blankOwner: 0xb7390a217cee03545b5e2b33c6f6ce6012d9b9bd
8-
- smartWallet(masterCopy): 0x4cEEd96D7F3e327AaBC0d282231A406a19c52098
9-
- walletFactory: 0x73d969CeDfdf97767427Bd58809757235c532fD5
8+
- smartWallet(masterCopy): 0x5fC8A17DdED0a4dA0f9a1E44E6C26F80Aa514145
9+
- walletFactory: 0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f
1010
- officialGuardian: 0xa4803058963e1314a938dbB4D9027D156e034f6f
1111

1212
## Arbitrum

packages/hebao_v2/script/parse-data.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,23 @@ async function decodeResult() {
6767
console.log("decoded:", decoded);
6868
}
6969

70+
function decodeWithABI(abi: string, input: string) {
71+
const abiJson = JSON.parse(abi);
72+
const iface = new ethers.utils.Interface(abiJson);
73+
74+
const res = iface.parseTransaction({ data: input, value: "0" });
75+
console.log("res:", res);
76+
return res;
77+
}
78+
7079
async function decodeWalletInput(input: string) {
7180
// const iface = new ethers.utils.Interface([
7281
// "function executeMetaTx(address to, uint256 nonce, address gasToken, uint256 gasPrice, uint256 gasLimit, uint256 gasOverhead, bool requiresSuccess, bytes data, bytes signature)"
7382
// ]);
7483

7584
const iface = await getWalletIface();
7685
const res = iface.parseTransaction({ data: input, value: "0" });
77-
// console.log("res:", res);
86+
console.log("res:", res);
7887
return res;
7988
}
8089

@@ -91,7 +100,7 @@ export async function decodeMetaTx(input: string) {
91100

92101
const innerTx = await decodeWalletInput(metaTx.args.data);
93102

94-
// console.log("innerTx:", innerTx.args.approval);
103+
console.log("innerTx:", innerTx.args.approval);
95104
return innerTx;
96105
}
97106

@@ -174,14 +183,19 @@ async function main() {
174183
// await signMetaTxTest();
175184
// await decodeResult();
176185

177-
await decodeWalletFactoryInput(
178-
"0xd92d1f5600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e20cf871f1646d8651ee9dc95aab1d93160b34670000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017b5dc97cfc000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042e58444e3f0638209443306de7cc6cf89ba107939b191cbd407e7422eef1830eb6c118a3592c5dc53966573b52f24b32d476e36e948bf19aa209a9873e3bc9d4b1c02000000000000000000000000000000000000000000000000000000000000"
179-
);
186+
// await decodeWalletFactoryInput(
187+
// "0xd92d1f5600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e20cf871f1646d8651ee9dc95aab1d93160b34670000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017b5dc97cfc000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042e58444e3f0638209443306de7cc6cf89ba107939b191cbd407e7422eef1830eb6c118a3592c5dc53966573b52f24b32d476e36e948bf19aa209a9873e3bc9d4b1c02000000000000000000000000000000000000000000000000000000000000"
188+
// );
180189

181190
// await decodeMetaTx(
182-
// "0x09779927000000000000000000000000acba35c89046f6083bbd6bf6d6e88b438c9b1a1b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dfa9b2ab43b881430b6f52122618cc6b8f3a2c90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000002249a792d4600000000000000000000000000000000000000000000000000000000000000600000000000000000000000002efc7efa9b179b4a176e2418e63b53c66a8a8c9c00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000006130c75e000000000000000000000000acba35c89046f6083bbd6bf6d6e88b438c9b1a1b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d5535729714618e57c42a072b8d56e72517f380000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004245d2d657baa5c0549a4256e3d59a0518b849713cf302d03169cd40f33190043a2d9ff034f18417cb23fb6158877e0ff125e360422d6ffe1870543feb35bd848c1c020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d5535729714618e57c42a072b8d56e72517f38000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000426109caa55149334d33c052b2ea2802ba7be56b9b59f2f990970d3d57f954edb778aafae94d433816ae1eee14dee6146fc254dfeacb01f62e067ce71d36d318681c02000000000000000000000000000000000000000000000000000000000000"
191+
// "0x09779927000000000000000000000000f9bd8230650e9a956a7003f211c1fd6e0884ee160000000000000000000000000000000000000000000000000000017be7bec2010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000edee915ae45cc4b2fdd1ce12a2f70dca0b2ad9e500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000001042e9feb790000000000000000000000000baba1ad5be3a5c0a66e7ac838a129bf948f1ea40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044d59acd25000000000000000000000000f9bd8230650e9a956a7003f211c1fd6e0884ee1631062154e712224164f51d1eb7d4b173ce9cf017aab0db00ba5068f10f523770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000428a7872f8cd82f511fae63e754c6554c970a3b9de5ea82f13fb62e6a213b53a0815e818fd5c0347867a8e6f021a94f0494a3aafb55f76f184ce3e0044fafc8caa1b02000000000000000000000000000000000000000000000000000000000000"
183192
// );
184193

194+
decodeWithABI(
195+
'[{"inputs":[{"internalType":"contract IUniswapV2Factory","name":"_factory","type":"address"},{"internalType":"address","name":"_wethAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"tokenValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]',
196+
"0xf18217830000000000000000000000000baba1ad5be3a5c0a66e7ac838a129bf948f1ea40000000000000000000000000000000000000000000000000de0b6b3a7640000"
197+
);
198+
185199
// signTest();
186200
// recoverSignature(
187201
// "0xE20cF871f1646d8651ee9dC95AAB1d93160b3467",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { expect } from "./setup";
2+
const { ethers } = require("hardhat");
3+
4+
import { Contract, Signer } from "ethers";
5+
import BN = require("bn.js");
6+
7+
describe("proxy", () => {
8+
before(async () => {});
9+
10+
describe("fallback call", () => {
11+
it.only("proxy revert when proxy call returns 0", async () => {
12+
const factory = await (await ethers.getContractFactory(
13+
"TestUniswapV2Factory"
14+
)).deploy();
15+
const wethAddr = "0x" + "01".repeat(20);
16+
const uniswapV2PriceOracle = await (await ethers.getContractFactory(
17+
"UniswapV2PriceOracle"
18+
)).deploy(factory.address, wethAddr);
19+
const priceOracleDelegate = await (await ethers.getContractFactory(
20+
"PriceOracleDelegate"
21+
)).deploy(uniswapV2PriceOracle.address);
22+
23+
const proxy = await (await ethers.getContractFactory(
24+
"OwnedUpgradeabilityProxy"
25+
)).deploy();
26+
const proxyPriceOracle = await (await ethers.getContractFactory(
27+
"UniswapV2PriceOracle"
28+
)).attach(proxy.address);
29+
30+
await proxy.upgradeTo(uniswapV2PriceOracle.address);
31+
try {
32+
const tokenValue2 = await proxyPriceOracle.tokenValue(
33+
"0x" + "11".repeat(20),
34+
1000
35+
);
36+
console.log("tokenValue2:", tokenValue2.toString());
37+
} catch (err) {
38+
console.log("err:", err);
39+
expect(err.message.includes("revert"));
40+
}
41+
42+
await proxy.upgradeTo(priceOracleDelegate.address);
43+
const proxyDelegateOracle = await (await ethers.getContractFactory(
44+
"PriceOracleDelegate"
45+
)).attach(proxy.address);
46+
const tokenValue3 = await proxyDelegateOracle.tokenValue(
47+
"0x" + "11".repeat(20),
48+
1000
49+
);
50+
console.log("tokenValue3:", tokenValue3.toString());
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)