-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add temp storage read/writes * Add chained reference detection and key extraction * Add chained reference functions * Add chained references to simple swap * Add Math.abs * Add chained references to batch swap * Add some docs * Remove unnecessary distinction between references and keys * Copy toChainedReference helper * refactor: make _TEMP_STORAGE_PREFIX constant and use as a prefix * fix: revert swapping ref and _TEMP_STORAGE_PREFIX and rename to _TEMP_STORAGE_SUFFIX Swapping the order meant that we were no longer replicating the standard mapping mechanism * revert: change _TEMP_STORAGE_SUFFIX to immutable see: ethereum/solidity#9232 * Add joinPool output chained reference * Add join support * Add more join tests * Add test helpers * Fix linter * Update pkg/standalone-utils/contracts/relayer/VaultActions.sol Co-authored-by: Tom French <[email protected]> * refactor: remove unused imports Co-authored-by: Tom French <[email protected]> Co-authored-by: Tom French <[email protected]>
- Loading branch information
1 parent
4a43dfc
commit cae950f
Showing
14 changed files
with
1,021 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.7.0; | ||
|
||
library VaultHelpers { | ||
/** | ||
* @dev Returns the address of a Pool's contract. | ||
* | ||
* This is the same code the Vault runs in `PoolRegistry._getPoolAddress`. | ||
*/ | ||
function toPoolAddress(bytes32 poolId) internal pure returns (address) { | ||
// 12 byte logical shift left to remove the nonce and specialization setting. We don't need to mask, | ||
// since the logical shift already sets the upper bits to zero. | ||
return address(uint256(poolId) >> (12 * 8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.7.0; | ||
|
||
import "../math/Math.sol"; | ||
|
||
contract MathMock { | ||
function abs(int256 a) public pure returns (uint256) { | ||
return Math.abs(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { Contract } from 'ethers'; | ||
import { deploy } from '@balancer-labs/v2-helpers/src/contract'; | ||
import { MAX_INT256, MIN_INT256 } from '@balancer-labs/v2-helpers/src/constants'; | ||
|
||
describe('Math', () => { | ||
let lib: Contract; | ||
|
||
sharedBeforeEach('deploy lib', async () => { | ||
lib = await deploy('MathMock', { args: [] }); | ||
}); | ||
|
||
it('handles zero', async () => { | ||
expect(await lib.abs(0)).to.equal(0); | ||
}); | ||
|
||
it('handles positive values', async () => { | ||
expect(await lib.abs(42)).to.equal(42); | ||
}); | ||
|
||
it('handles large positive values', async () => { | ||
expect(await lib.abs(MAX_INT256)).to.equal(MAX_INT256); | ||
}); | ||
|
||
it('handles negative values', async () => { | ||
expect(await lib.abs(-3)).to.equal(3); | ||
}); | ||
|
||
it('handles large negative values', async () => { | ||
expect(await lib.abs(MIN_INT256)).to.equal(MIN_INT256.mul(-1)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
pkg/standalone-utils/contracts/test/MockBaseRelayerLibrary.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (C) 2015, 2016, 2017 Dapphub | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.7.0; | ||
|
||
import "../relayer/BaseRelayerLibrary.sol"; | ||
|
||
contract MockBaseRelayerLibrary is BaseRelayerLibrary { | ||
event ChainedReferenceValueRead(uint256 value); | ||
|
||
constructor(IVault vault) BaseRelayerLibrary(vault) {} | ||
|
||
function isChainedReference(uint256 amount) public pure returns (bool) { | ||
return _isChainedReference(amount); | ||
} | ||
|
||
function setChainedReferenceValue(uint256 ref, uint256 value) public returns (uint256) { | ||
_setChainedReferenceValue(ref, value); | ||
} | ||
|
||
function getChainedReferenceValue(uint256 ref) public { | ||
emit ChainedReferenceValueRead(_getChainedReferenceValue(ref)); | ||
} | ||
} |
Oops, something went wrong.