Skip to content

Commit

Permalink
chore: use forge fmt instead of prettier (AztecProtocol#285)
Browse files Browse the repository at this point in the history
* chore: use forge fmt instead of prettier

* fix: circleci + package + minor fixes
  • Loading branch information
LHerskind authored Nov 22, 2022
1 parent e6cf987 commit 828bd28
Show file tree
Hide file tree
Showing 81 changed files with 869 additions and 2,449 deletions.
33 changes: 16 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ jobs:
shell: /bin/bash
command: |
yarn config set script-shell /bin/bash
yarn
yarn install:foundryup
export PATH=/home/circleci/.foundry/bin:$PATH
yarn install:foundry
- run:
name: Build Project
shell: /bin/bash
command: |
export PATH=/home/circleci/.foundry/bin:$PATH
export PATH=/home/circleci/.forge/bin:$PATH
yarn setup:foundry
yarn install:dependencies
yarn build
- run:
name: Check Formatting
shell: /bin/bash
command: |
yarn config set script-shell /bin/bash
export PATH=/home/circleci/.foundry/bin:$PATH
yarn formatting:check
- run:
name: Check Linting Errors in Contracts
Expand All @@ -52,24 +57,14 @@ jobs:
command: |
yarn config set script-shell /bin/bash
export PATH=/home/circleci/.foundry/bin:$PATH
export PATH=/home/circleci/.forge/bin:$PATH
yarn test:contracts
- run:
name: Test Clients
shell: /bin/bash
command: |
yarn config set script-shell /bin/bash
export PATH=/home/circleci/.foundry/bin:$PATH
export PATH=/home/circleci/.forge/bin:$PATH
yarn test:clients
- run:
name: Build
shell: /bin/bash
command: |
yarn config set script-shell /bin/bash
export PATH=/home/circleci/.foundry/bin:$PATH
export PATH=/home/circleci/.forge/bin:$PATH
yarn build
publish:
docker:
- image: "cimg/python:3.10.6"
Expand All @@ -89,15 +84,19 @@ jobs:
export PATH=/home/cicleci/.local/bin:$PATH
vyper --version
- run:
name: Setup Foundry and Build
name: Setup Foundry
shell: /bin/bash
command: |
yarn config set script-shell /bin/bash
yarn
yarn install:foundryup
export PATH=/home/circleci/.foundry/bin:$PATH
yarn install:foundry
- run:
name: Build Project
shell: /bin/bash
command: |
export PATH=/home/circleci/.foundry/bin:$PATH
export PATH=/home/circleci/.forge/bin:$PATH
yarn setup:foundry
yarn install:dependencies
yarn build
- run:
name: Publish
Expand Down
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ ffi = true
optimizer = true
optimizer_runs = 100000

[fmt]
variable_override_spacing=false

# See more config options https://github.com/gakonst/foundry/tree/master/config
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"repository": "[email protected]:AztecProtocol/aztec-connect-bridges.git",
"license": "Apache-2.0",
"scripts": {
"install:foundry": "curl -L https://foundry.paradigm.xyz | bash",
"setup:foundry": "foundryup & git submodule update --init --recursive",
"setup": "yarn && yarn install:foundry && yarn setup:foundry",
"install:foundryup": "curl -L https://foundry.paradigm.xyz | bash",
"install:foundry": "foundryup",
"install:dependencies": "git submodule update --init --recursive && yarn",
"setup": "yarn install:foundryup && yarn install:foundry && yarn",
"clean": "rm -rf ./cache ./dest ./out ./typechain-types ./client-dest",
"compile:typechain": "forge build && typechain --target ethers-v5 --out-dir ./typechain-types './out/!(test*|Test*|*.t.sol|*.s.sol)/*.json'",
"compile:client-dest": "yarn compile:typechain && tsc --project tsconfig.client-dest.json",
Expand All @@ -19,8 +20,8 @@
"test:contracts": "forge test --no-match-contract 'Element' --no-match-test 'testRedistribution' && yarn test:pinned",
"test:clients": "yarn compile:typechain && jest test",
"test": "yarn test:contracts && yarn test:clients",
"formatting": "yarn prettier --write .",
"formatting:check": "prettier --check .",
"formatting": "forge fmt && yarn prettier --write ./src/client/**/*.ts",
"formatting:check": "forge fmt --check && prettier --check ./src/client/**/*.ts",
"lint": "yarn lint:contracts && yarn lint:clients",
"lint:contracts": "solhint --config ./.solhint.json --fix \"src/**/*.sol\"",
"lint:clients": "eslint \"src/**/*.{ts,tsx}\""
Expand All @@ -37,17 +38,15 @@
"typescript": "^4.8.4"
},
"devDependencies": {
"@types/jest": "^29.2.0",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"eslint": "^8.25.0",
"@types/jest": "^29.2.3",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.2.1",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.24",
"solhint": "https://github.com/LHerskind/solhint",
"solhint-plugin-prettier": "^0.0.5",
"ts-jest": "^29.0.3"
},
"jest": {
Expand Down
46 changes: 14 additions & 32 deletions src/aztec/DataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ contract DataProvider is Ownable {
address bridgeAddress = ROLLUP_PROCESSOR.getSupportedBridge(_bridgeAddressId);
bytes32 digest = keccak256(abi.encode(_tag));
bridges.tagToId[digest] = _bridgeAddressId;
bridges.data[_bridgeAddressId] = BridgeData({
bridgeAddress: bridgeAddress,
bridgeAddressId: _bridgeAddressId,
label: _tag
});
bridges.data[_bridgeAddressId] =
BridgeData({bridgeAddress: bridgeAddress, bridgeAddressId: _bridgeAddressId, label: _tag});
}

/**
Expand Down Expand Up @@ -190,15 +187,7 @@ contract DataProvider is Ownable {
* @return The amount of eth claimed at the current gas prices
* @return The number of gas units (eth claimed / basefee)
*/
function getAccumulatedSubsidyAmount(uint256 _bridgeCallData)
public
view
returns (
uint256,
uint256,
uint256
)
{
function getAccumulatedSubsidyAmount(uint256 _bridgeCallData) public view returns (uint256, uint256, uint256) {
AccVal memory vars;

vars.bridgeAddressId = _bridgeCallData & MASK_THIRTY_TWO_BITS;
Expand Down Expand Up @@ -226,12 +215,7 @@ contract DataProvider is Ownable {

(bool success, bytes memory returnData) = vars.bridgeAddress.staticcall(
abi.encodeWithSelector(
BridgeBase.computeCriteria.selector,
inputA,
inputB,
outputA,
outputB,
uint64(auxData)
BridgeBase.computeCriteria.selector, inputA, inputB, outputA, outputB, uint64(auxData)
)
);

Expand All @@ -247,21 +231,19 @@ contract DataProvider is Ownable {

function _aztecAsset(uint256 _assetId) internal view returns (AztecTypes.AztecAsset memory) {
if (_assetId >= VIRTUAL_ASSET_ID_FLAG) {
return
AztecTypes.AztecAsset({
id: _assetId - VIRTUAL_ASSET_ID_FLAG,
erc20Address: address(0),
assetType: AztecTypes.AztecAssetType.VIRTUAL
});
return AztecTypes.AztecAsset({
id: _assetId - VIRTUAL_ASSET_ID_FLAG,
erc20Address: address(0),
assetType: AztecTypes.AztecAssetType.VIRTUAL
});
}

if (_assetId > 0) {
return
AztecTypes.AztecAsset({
id: _assetId,
erc20Address: ROLLUP_PROCESSOR.getSupportedAsset(_assetId),
assetType: AztecTypes.AztecAssetType.ERC20
});
return AztecTypes.AztecAsset({
id: _assetId,
erc20Address: ROLLUP_PROCESSOR.getSupportedAsset(_assetId),
assetType: AztecTypes.AztecAssetType.ERC20
});
}

return AztecTypes.AztecAsset({id: 0, erc20Address: address(0), assetType: AztecTypes.AztecAssetType.ETH});
Expand Down
40 changes: 20 additions & 20 deletions src/aztec/Subsidy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract Subsidy is ISubsidy {
* @param _beneficiary The address of the beneficiary to query
* @return The amount of claimable ETH for `_beneficiary`
*/
function claimableAmount(address _beneficiary) external view override(ISubsidy) returns (uint256) {
function claimableAmount(address _beneficiary) external view override (ISubsidy) returns (uint256) {
return beneficiaries[_beneficiary].claimable;
}

Expand All @@ -82,7 +82,7 @@ contract Subsidy is ISubsidy {
* @param _beneficiary The address of the beneficiary to check
* @return True if the `_beneficiary` is registered, false otherwise
*/
function isRegistered(address _beneficiary) external view override(ISubsidy) returns (bool) {
function isRegistered(address _beneficiary) external view override (ISubsidy) returns (bool) {
return beneficiaries[_beneficiary].registered;
}

Expand All @@ -92,7 +92,12 @@ contract Subsidy is ISubsidy {
* @param _criteria The criteria of the subsidy
* @return The subsidy data object
*/
function getSubsidy(address _bridge, uint256 _criteria) external view override(ISubsidy) returns (Subsidy memory) {
function getSubsidy(address _bridge, uint256 _criteria)
external
view
override (ISubsidy)
returns (Subsidy memory)
{
return subsidies[_bridge][_criteria];
}

Expand All @@ -109,13 +114,13 @@ contract Subsidy is ISubsidy {
uint256[] calldata _criteria,
uint32[] calldata _gasUsage,
uint32[] calldata _minGasPerMinute
) external override(ISubsidy) {
) external override (ISubsidy) {
uint256 criteriasLength = _criteria.length;
if (criteriasLength != _gasUsage.length || criteriasLength != _minGasPerMinute.length) {
revert ArrayLengthsDoNotMatch();
}

for (uint256 i; i < criteriasLength; ) {
for (uint256 i; i < criteriasLength;) {
setGasUsageAndMinGasPerMinute(_criteria[i], _gasUsage[i], _minGasPerMinute[i]);
unchecked {
++i;
Expand All @@ -132,7 +137,7 @@ contract Subsidy is ISubsidy {
* IDefiBridge.convert(...) function to be as predictable as possible. If the cost is too variable users would
* overpay since RollupProcessor works with constant gas limits.
*/
function registerBeneficiary(address _beneficiary) external override(ISubsidy) {
function registerBeneficiary(address _beneficiary) external override (ISubsidy) {
beneficiaries[_beneficiary].registered = true;
emit BeneficiaryRegistered(_beneficiary);
}
Expand All @@ -147,11 +152,7 @@ contract Subsidy is ISubsidy {
* 3) subsidy.gasUsage not set: `subsidy.gasUsage` == 0,
* 4) ETH value sent too low: `msg.value` < `MIN_SUBSIDY_VALUE`.
*/
function subsidize(
address _bridge,
uint256 _criteria,
uint32 _gasPerMinute
) external payable override(ISubsidy) {
function subsidize(address _bridge, uint256 _criteria, uint32 _gasPerMinute) external payable override (ISubsidy) {
if (msg.value < MIN_SUBSIDY_VALUE) {
revert SubsidyTooLow();
}
Expand Down Expand Up @@ -184,7 +185,7 @@ contract Subsidy is ISubsidy {
* @param _criteria A value defining the specific bridge call to subsidize
* @dev Reverts if `available` is 0.
*/
function topUp(address _bridge, uint256 _criteria) external payable override(ISubsidy) {
function topUp(address _bridge, uint256 _criteria) external payable override (ISubsidy) {
// Caching subsidy in order to minimize number of SLOADs and SSTOREs
Subsidy memory sub = subsidies[_bridge][_criteria];

Expand All @@ -206,7 +207,7 @@ contract Subsidy is ISubsidy {
* @param _beneficiary Address which is going to receive the subsidy
* @return subsidy ETH amount which was added to the `_beneficiary` claimable balance
*/
function claimSubsidy(uint256 _criteria, address _beneficiary) external override(ISubsidy) returns (uint256) {
function claimSubsidy(uint256 _criteria, address _beneficiary) external override (ISubsidy) returns (uint256) {
if (_beneficiary == address(0)) {
return 0;
}
Expand Down Expand Up @@ -249,14 +250,14 @@ contract Subsidy is ISubsidy {
* @param _beneficiary Address which is going to receive the subsidy
* @return - ETH amount which was sent to the `_beneficiary`
*/
function withdraw(address _beneficiary) external override(ISubsidy) returns (uint256) {
function withdraw(address _beneficiary) external override (ISubsidy) returns (uint256) {
uint256 withdrawableBalance = beneficiaries[_beneficiary].claimable;
// Immediately updating the balance to avoid re-entrancy attack
beneficiaries[_beneficiary].claimable = 0;

// Sending 30k gas in a call to allow receiver to be a multi-sig and write to storage
/* solhint-disable avoid-low-level-calls */
(bool success, ) = _beneficiary.call{value: withdrawableBalance, gas: 30000}("");
(bool success,) = _beneficiary.call{value: withdrawableBalance, gas: 30000}("");
if (!success) {
revert EthTransferFailed();
}
Expand All @@ -281,11 +282,10 @@ contract Subsidy is ISubsidy {
* @param _gasUsage The gas usage of the subsidized action. Used as upper limit for subsidy.
* @param _minGasPerMinute Minimum amount of gas per minute that subsidizer has to subsidize
*/
function setGasUsageAndMinGasPerMinute(
uint256 _criteria,
uint32 _gasUsage,
uint32 _minGasPerMinute
) public override(ISubsidy) {
function setGasUsageAndMinGasPerMinute(uint256 _criteria, uint32 _gasUsage, uint32 _minGasPerMinute)
public
override (ISubsidy)
{
// Loading `sub` first in order to not overwrite `sub.available` in case this function was already called
// and a subsidy was set.
Subsidy memory sub = subsidies[msg.sender][_criteria];
Expand Down
24 changes: 6 additions & 18 deletions src/aztec/interfaces/IDefiBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ interface IDefiBridge {
* `_interactionNonce` it would simply mean that more of the same virtual asset is minted.
* @dev If this interaction is async the function has to return `(0,0 true)`. Async interaction will be finalised at
* a later time and its output assets will be returned in a `IDefiBridge.finalise(...)` call.
**/
*
*/
function convert(
AztecTypes.AztecAsset calldata _inputAssetA,
AztecTypes.AztecAsset calldata _inputAssetB,
Expand All @@ -41,14 +42,7 @@ interface IDefiBridge {
uint256 _interactionNonce,
uint64 _auxData,
address _rollupBeneficiary
)
external
payable
returns (
uint256 outputValueA,
uint256 outputValueB,
bool isAsync
);
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool isAsync);

/**
* @notice A function that finalises asynchronous interaction.
Expand All @@ -62,20 +56,14 @@ interface IDefiBridge {
* @return outputValueB An amount of `_outputAssetB` returned from this interaction.
* @dev This function should use the `BridgeBase.onlyRollup()` modifier to ensure it can only be called from
* the `RollupProcessor.processAsyncDefiInteraction(uint256 _interactionNonce)` method.
**/
*
*/
function finalise(
AztecTypes.AztecAsset calldata _inputAssetA,
AztecTypes.AztecAsset calldata _inputAssetB,
AztecTypes.AztecAsset calldata _outputAssetA,
AztecTypes.AztecAsset calldata _outputAssetB,
uint256 _interactionNonce,
uint64 _auxData
)
external
payable
returns (
uint256 outputValueA,
uint256 outputValueB,
bool interactionComplete
);
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool interactionComplete);
}
Loading

0 comments on commit 828bd28

Please sign in to comment.