Skip to content

Commit 49ce1c3

Browse files
authored
save gas on balance0/balance1 calls (#422)
1 parent 0f56911 commit 49ce1c3

File tree

3 files changed

+51
-56
lines changed

3 files changed

+51
-56
lines changed

contracts/UniswapV3Pool.sol

+2-7
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,12 @@ contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
140140

141141
/// @dev Get the pool's balance of token0
142142
function balance0() private view returns (uint256) {
143-
return balanceOfToken(token0);
143+
return IERC20Minimal(token0).balanceOf(address(this));
144144
}
145145

146146
/// @dev Get the pool's balance of token1
147147
function balance1() private view returns (uint256) {
148-
return balanceOfToken(token1);
149-
}
150-
151-
/// @dev Get the balance of the token address. Saves bytecode.
152-
function balanceOfToken(address token) private view returns (uint256) {
153-
return IERC20Minimal(token).balanceOf(address(this));
148+
return IERC20Minimal(token1).balanceOf(address(this));
154149
}
155150

156151
/// @inheritdoc IUniswapV3PoolDerivedState
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`UniswapV3Factory #createPool gas 1`] = `4476783`;
3+
exports[`UniswapV3Factory #createPool gas 1`] = `4487020`;
44

5-
exports[`UniswapV3Factory factory bytecode size 1`] = `24162`;
5+
exports[`UniswapV3Factory factory bytecode size 1`] = `24213`;
66

7-
exports[`UniswapV3Factory pool bytecode size 1`] = `21729`;
7+
exports[`UniswapV3Factory pool bytecode size 1`] = `21780`;

test/__snapshots__/UniswapV3Pool.gas.spec.ts.snap

+46-46
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,53 @@ exports[`UniswapV3Pool gas tests fee is off #increaseObservationCardinalityNext
3030

3131
exports[`UniswapV3Pool gas tests fee is off #increaseObservationCardinalityNext no op 1`] = `28299`;
3232

33-
exports[`UniswapV3Pool gas tests fee is off #mint above current price add to position after some time passes 1`] = `102566`;
33+
exports[`UniswapV3Pool gas tests fee is off #mint above current price add to position after some time passes 1`] = `102474`;
3434

35-
exports[`UniswapV3Pool gas tests fee is off #mint above current price add to position existing 1`] = `102566`;
35+
exports[`UniswapV3Pool gas tests fee is off #mint above current price add to position existing 1`] = `102474`;
3636

37-
exports[`UniswapV3Pool gas tests fee is off #mint above current price new position mint first in range 1`] = `170948`;
37+
exports[`UniswapV3Pool gas tests fee is off #mint above current price new position mint first in range 1`] = `170856`;
3838

39-
exports[`UniswapV3Pool gas tests fee is off #mint above current price second position in same range 1`] = `117566`;
39+
exports[`UniswapV3Pool gas tests fee is off #mint above current price second position in same range 1`] = `117474`;
4040

41-
exports[`UniswapV3Pool gas tests fee is off #mint around current price add to position after some time passes 1`] = `148703`;
41+
exports[`UniswapV3Pool gas tests fee is off #mint around current price add to position after some time passes 1`] = `148531`;
4242

43-
exports[`UniswapV3Pool gas tests fee is off #mint around current price add to position existing 1`] = `137895`;
43+
exports[`UniswapV3Pool gas tests fee is off #mint around current price add to position existing 1`] = `137723`;
4444

45-
exports[`UniswapV3Pool gas tests fee is off #mint around current price new position mint first in range 1`] = `297518`;
45+
exports[`UniswapV3Pool gas tests fee is off #mint around current price new position mint first in range 1`] = `297346`;
4646

47-
exports[`UniswapV3Pool gas tests fee is off #mint around current price second position in same range 1`] = `152895`;
47+
exports[`UniswapV3Pool gas tests fee is off #mint around current price second position in same range 1`] = `152723`;
4848

49-
exports[`UniswapV3Pool gas tests fee is off #mint below current price add to position after some time passes 1`] = `103113`;
49+
exports[`UniswapV3Pool gas tests fee is off #mint below current price add to position after some time passes 1`] = `103021`;
5050

51-
exports[`UniswapV3Pool gas tests fee is off #mint below current price add to position existing 1`] = `103113`;
51+
exports[`UniswapV3Pool gas tests fee is off #mint below current price add to position existing 1`] = `103021`;
5252

53-
exports[`UniswapV3Pool gas tests fee is off #mint below current price new position mint first in range 1`] = `274761`;
53+
exports[`UniswapV3Pool gas tests fee is off #mint below current price new position mint first in range 1`] = `274669`;
5454

55-
exports[`UniswapV3Pool gas tests fee is off #mint below current price second position in same range 1`] = `118113`;
55+
exports[`UniswapV3Pool gas tests fee is off #mint below current price second position in same range 1`] = `118021`;
5656

5757
exports[`UniswapV3Pool gas tests fee is off #poke best case 1`] = `43339`;
5858

59-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `101127`;
59+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `101035`;
6060

61-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block with no tick movement 1`] = `83829`;
61+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block with no tick movement 1`] = `83737`;
6262

63-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `103402`;
63+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `103310`;
6464

65-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `118929`;
65+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `118837`;
6666

67-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `113095`;
67+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `113003`;
6868

69-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 large swap crossing several initialized ticks after some time passes (seconds outside is set) 1`] = `133929`;
69+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 large swap crossing several initialized ticks after some time passes (seconds outside is set) 1`] = `133837`;
7070

71-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `193929`;
71+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `193837`;
7272

73-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `101127`;
73+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `101035`;
7474

75-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block with no tick movement 1`] = `83940`;
75+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block with no tick movement 1`] = `83848`;
7676

77-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `91018`;
77+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `90926`;
7878

79-
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `106524`;
79+
exports[`UniswapV3Pool gas tests fee is off #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `106432`;
8080

8181
exports[`UniswapV3Pool gas tests fee is on #burn above current price burn entire position after some time passes 1`] = `55562`;
8282

@@ -108,50 +108,50 @@ exports[`UniswapV3Pool gas tests fee is on #increaseObservationCardinalityNext g
108108

109109
exports[`UniswapV3Pool gas tests fee is on #increaseObservationCardinalityNext no op 1`] = `28299`;
110110

111-
exports[`UniswapV3Pool gas tests fee is on #mint above current price add to position after some time passes 1`] = `102566`;
111+
exports[`UniswapV3Pool gas tests fee is on #mint above current price add to position after some time passes 1`] = `102486`;
112112

113-
exports[`UniswapV3Pool gas tests fee is on #mint above current price add to position existing 1`] = `102566`;
113+
exports[`UniswapV3Pool gas tests fee is on #mint above current price add to position existing 1`] = `102486`;
114114

115-
exports[`UniswapV3Pool gas tests fee is on #mint above current price new position mint first in range 1`] = `170948`;
115+
exports[`UniswapV3Pool gas tests fee is on #mint above current price new position mint first in range 1`] = `170868`;
116116

117-
exports[`UniswapV3Pool gas tests fee is on #mint above current price second position in same range 1`] = `117566`;
117+
exports[`UniswapV3Pool gas tests fee is on #mint above current price second position in same range 1`] = `117486`;
118118

119-
exports[`UniswapV3Pool gas tests fee is on #mint around current price add to position after some time passes 1`] = `148703`;
119+
exports[`UniswapV3Pool gas tests fee is on #mint around current price add to position after some time passes 1`] = `148543`;
120120

121-
exports[`UniswapV3Pool gas tests fee is on #mint around current price add to position existing 1`] = `137895`;
121+
exports[`UniswapV3Pool gas tests fee is on #mint around current price add to position existing 1`] = `137735`;
122122

123-
exports[`UniswapV3Pool gas tests fee is on #mint around current price new position mint first in range 1`] = `297518`;
123+
exports[`UniswapV3Pool gas tests fee is on #mint around current price new position mint first in range 1`] = `297358`;
124124

125-
exports[`UniswapV3Pool gas tests fee is on #mint around current price second position in same range 1`] = `152895`;
125+
exports[`UniswapV3Pool gas tests fee is on #mint around current price second position in same range 1`] = `152735`;
126126

127-
exports[`UniswapV3Pool gas tests fee is on #mint below current price add to position after some time passes 1`] = `103113`;
127+
exports[`UniswapV3Pool gas tests fee is on #mint below current price add to position after some time passes 1`] = `103033`;
128128

129-
exports[`UniswapV3Pool gas tests fee is on #mint below current price add to position existing 1`] = `103113`;
129+
exports[`UniswapV3Pool gas tests fee is on #mint below current price add to position existing 1`] = `103033`;
130130

131-
exports[`UniswapV3Pool gas tests fee is on #mint below current price new position mint first in range 1`] = `274761`;
131+
exports[`UniswapV3Pool gas tests fee is on #mint below current price new position mint first in range 1`] = `274681`;
132132

133-
exports[`UniswapV3Pool gas tests fee is on #mint below current price second position in same range 1`] = `118113`;
133+
exports[`UniswapV3Pool gas tests fee is on #mint below current price second position in same range 1`] = `118033`;
134134

135135
exports[`UniswapV3Pool gas tests fee is on #poke best case 1`] = `43339`;
136136

137-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `107314`;
137+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `107234`;
138138

139-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block with no tick movement 1`] = `89869`;
139+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block with no tick movement 1`] = `89789`;
140140

141-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `109736`;
141+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `109656`;
142142

143-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `125704`;
143+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `125624`;
144144

145-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `119576`;
145+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `119496`;
146146

147-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 large swap crossing several initialized ticks after some time passes (seconds outside is set) 1`] = `140704`;
147+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 large swap crossing several initialized ticks after some time passes (seconds outside is set) 1`] = `140624`;
148148

149-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `200704`;
149+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `200624`;
150150

151-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `107314`;
151+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `107234`;
152152

153-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block with no tick movement 1`] = `89980`;
153+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block with no tick movement 1`] = `89900`;
154154

155-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `97205`;
155+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `97125`;
156156

157-
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `113152`;
157+
exports[`UniswapV3Pool gas tests fee is on #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `113072`;

0 commit comments

Comments
 (0)