Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
74d16f2
generate relayer config
salman01zp Jan 6, 2023
5c163ad
create2 deployment script and typechain fixes
salman01zp Jan 9, 2023
68b0a5a
typechain fixes
salman01zp Jan 9, 2023
8b51c08
Merge branch 'main' into salman/generate-relayer-config
salman01zp Jan 9, 2023
48c2b41
update deployment script and add logs
salman01zp Jan 11, 2023
7608ed8
Add lower level initializer
drewstone Jan 11, 2023
eb0a8b7
Merge branch 'salman/generate-relayer-config' of https://github.com/w…
drewstone Jan 11, 2023
d7fc30b
Update token contracts for create2/admin related purposes
drewstone Jan 11, 2023
c564e11
Ups
drewstone Jan 13, 2023
5941508
Merge main and work on errors
drewstone Jan 13, 2023
6df9ae4
Ups
drewstone Jan 13, 2023
7d2a0f0
revert deployer changes and fix contract package build
salman01zp Jan 13, 2023
beaee7d
Merge remote-tracking branch 'origin/main' into salman/generate-relay…
salman01zp Jan 13, 2023
d47eef9
fix ts-check errors
salman01zp Jan 13, 2023
ca53b96
remove logs
salman01zp Jan 13, 2023
12a73c5
fix test
salman01zp Jan 13, 2023
3908d8d
Merge remote-tracking branch 'origin/salman/generate-relayer-config' …
salman01zp Jan 13, 2023
1dffa80
make token contracts build again
semaraugusto Jan 17, 2023
ed1dcfc
fix syntax errors on tests
semaraugusto Jan 17, 2023
378c9f1
fix syntax error for identityVAnchor.test.ts
semaraugusto Jan 17, 2023
ac8d74a
Fmt
drewstone Jan 17, 2023
d9b76a2
Merge branch 'main' into drew/create2-updates
drewstone Jan 17, 2023
c38bba2
Attempt ts-check fix
drewstone Jan 17, 2023
5dfaa14
Merge branch 'drew/create2-updates' of https://github.com/webb-tools/…
drewstone Jan 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
"build": "yarn compile && yarn build:packages",
"setup": "yarn compile && yarn build:circuits && yarn build:ptau",
"test": "yarn workspace @webb-tools/contracts run test",
"fast": "yarn workspace @webb-tools/contracts run fast",
"fast": "yarn workspace @webb-tools/contracts run test:parallel",
"build:circuits": "./scripts/bash/build_circuits.sh",
"build:packages": "lerna run build",
"build:ptau": "./scripts/bash/generate_phase1_ptau.sh",
"clean": "rm -rf artifacts typechain && yarn clean:packages",
"clean:packages": "lerna run clean",
"fetch:fixtures": "cd packages/contracts/solidity-fixtures && dvc pull && cd ../../../",
"prettier": "prettier -c .",
"prettier:write": "prettier -w .",
"publish:packages": "lerna run compile && lerna publish",
"setup:groth16:vanchor2": "./scripts/bash/groth16/vanchor/phase2_poseidon_vanchor2.sh",
"setup:groth16:vanchor8": "./scripts/bash/groth16/vanchor/phase2_poseidon_vanchor8.sh",
Expand All @@ -34,20 +33,20 @@
"setup:plonk:identity-vanchor8": "./scripts/bash/plonk/identity_vanchor/phase2_identity_vanchor8.sh",
"setup:plonk": "./scripts/bash/setup_verifiers_plonk.sh",
"ts-check": "tsc --noEmit -p ./tsconfig.json",
"format": "prettier --write \"packages/**/*.{ts,js,jsx,tsx}\""
"format": "prettier -w ."
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@webb-tools/anchors": "^0.5.3",
"@webb-tools/bridges": "^0.5.3",
"@webb-tools/contracts": "^0.5.3",
"@webb-tools/evm-test-utils": "^0.5.3",
"@webb-tools/interfaces": "^0.5.3",
"@webb-tools/tokens": "^0.5.3",
"@webb-tools/utils": "^0.5.3",
"@webb-tools/vbridge": "^0.5.3",
"@webb-tools/anchors": "^0.5",
"@webb-tools/bridges": "^0.5",
"@webb-tools/contracts": "^0.5",
"@webb-tools/evm-test-utils": "^0.5",
"@webb-tools/interfaces": "^0.5",
"@webb-tools/tokens": "^0.5",
"@webb-tools/utils": "^0.5",
"@webb-tools/vbridge": "^0.5",
"copyfiles": "^2.4.1",
"eth-proof": "~2.1.6",
"ethers": "5.7.0",
Expand Down
62 changes: 61 additions & 1 deletion packages/contracts/contracts/DeterministicDeployFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
contract DeterministicDeployFactory {
event Deploy(address addr);

function deploy(bytes memory bytecode, uint _salt) external {
function deploy(bytes memory bytecode, uint _salt) external returns (address) {
address addr;
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
Expand All @@ -14,5 +14,65 @@ contract DeterministicDeployFactory {
}

emit Deploy(addr);
return addr;
}

/**
@notice Deploy a fungible token
@param bytecode The bytecode of the contract
@param _salt The salt for the contract
@param _feePercentage The fee percentage for wrapping
@param _feeRecipient The recipient for fees from wrapping.
@param _handler The address of the handler
@param _limit The maximum amount of tokens that can be wrapped
@param _isNativeAllowed Whether or not native tokens are allowed to be wrapped
*/
function deployFungibleToken(
bytes memory bytecode,
uint _salt,
uint16 _feePercentage,
address _feeRecipient,
address _handler,
uint256 _limit,
bool _isNativeAllowed
) external {
address c = this.deploy(bytecode, _salt);
// delegate call initialize the contract created with the msg.sender
(bool success, bytes memory data) = c.call(
abi.encodeWithSignature(
"initialize(uint16,address,address,uint256,bool)",
_feePercentage,
_feeRecipient,
_handler,
_limit,
_isNativeAllowed
)
);
require(success, string(data));
}

/**
@notice Deploy a VAnchor
@param bytecode The bytecode of the contract
@param _salt The salt for the contract
@param _minimalWithdrawalAmount The minimal withdrawal amount
@param _maximumDepositAmount The maximum deposit amount
*/
function deployVAnchor(
bytes memory bytecode,
uint _salt,
uint256 _minimalWithdrawalAmount,
uint256 _maximumDepositAmount
) external {
address c = this.deploy(bytecode, _salt);
// delegate call initialize the contract created with the msg.sender
(bool success, bytes memory data) = c.call(
abi.encodeWithSignature(
"initialize(uint256,uint256)",
_minimalWithdrawalAmount,
_maximumDepositAmount
)
);
require(success, string(data));
}
}
16 changes: 8 additions & 8 deletions packages/contracts/contracts/anchors/LinkableAnchor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ abstract contract LinkableAnchor is
event EdgeAddition(uint256 chainID, uint256 latestLeafIndex, uint256 merkleRoot);
event EdgeUpdate(uint256 chainID, uint256 latestLeafIndex, uint256 merkleRoot);

/**
@notice Checks the sender is the AnchorHandler configured on this contract
*/
modifier onlyHandler() {
require(msg.sender == handler, "sender is not the handler");
_;
}

/**
@notice The LinkableAnchor constructor
@param _handler The address of the `AnchorHandler` contract
Expand Down Expand Up @@ -227,14 +235,6 @@ abstract contract LinkableAnchor is
return true;
}

/**
@notice Checks the sender is the AnchorHandler configured on this contract
*/
modifier onlyHandler() {
require(msg.sender == handler, "sender is not the handler");
_;
}

/**
@notice Checks the `_chainID` has an edge on this contract
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface IMultiTokenManager {
@param _limit The maximum amount of tokens that can be wrapped
@param _feePercentage The fee percentage for wrapping
@param _isNativeAllowed Whether or not native tokens are allowed to be wrapped
@param _admin The address of the admin who will receive minting rights and admin role
*/
function registerToken(
address _handler,
Expand All @@ -34,7 +35,8 @@ interface IMultiTokenManager {
bytes32 _salt,
uint256 _limit,
uint16 _feePercentage,
bool _isNativeAllowed
bool _isNativeAllowed,
address _admin
) external returns (address);

/**
Expand Down
23 changes: 11 additions & 12 deletions packages/contracts/contracts/tokens/AaveTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ contract AaveTokenWrapper is FungibleTokenWrapper, IAaveTokenWrapper {
string memory _name,
string memory _symbol,
address _aaveLendingPool
) FungibleTokenWrapper(_name, _symbol) {
aaveLendingPool = IAaveLendingPool(_aaveLendingPool);
}
) FungibleTokenWrapper(_name, _symbol) {}

/**
@notice AaveTokenWrapper initializer
@param _feeRecipient The recipient for fees from wrapping
@param _governor The address of the governor
@param _feePercentage The fee percentage for wrapping
@param _feeRecipient The recipient for fees from wrapping.
@param _handler The address of the handler
@param _limit The maximum amount of tokens that can be wrapped
@param _isNativeAllowed Whether or not native tokens are allowed to be wrapped
@param _admin The address of the admin who will receive minting rights and admin role
@param _aaveLendingPool The address of the Aave lending pool
*/
function initialize(
uint16 _feePercentage,
address _feeRecipient,
address _governor,
address _handler,
uint256 _limit,
bool _isNativeAllowed,
address _admin,
address _aaveLendingPool
) public {
require(!initialized, "Contract already initialized");
feeRecipient = payable(_feeRecipient);
wrappingLimit = _limit;
isNativeAllowed = _isNativeAllowed;
initialized = true;
) public onlyUninitialized {
super.initialize(_feePercentage, _feeRecipient, _handler, _limit, _isNativeAllowed, _admin);
aaveLendingPool = IAaveLendingPool(_aaveLendingPool);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/contracts/contracts/tokens/FungibleTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import "../utils/ProposalNonceTracker.sol";
TokenHandler contract.
*/
contract FungibleTokenWrapper is
TokenWrapper,
Initialized,
TokenWrapper,
IFungibleTokenWrapper,
ProposalNonceTracker
{
Expand Down Expand Up @@ -48,14 +48,17 @@ contract FungibleTokenWrapper is
@param _handler The address of the handler
@param _limit The maximum amount of tokens that can be wrapped
@param _isNativeAllowed Whether or not native tokens are allowed to be wrapped
@param _admin The address of the admin who will receive minting rights and admin role
*/
function initialize(
uint16 _feePercentage,
address _feeRecipient,
address _handler,
uint256 _limit,
bool _isNativeAllowed
bool _isNativeAllowed,
address _admin
) public onlyUninitialized {
super._initialize(_admin);
initialized = true;
feePercentage = _feePercentage;
feeRecipient = payable(_feeRecipient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract MultiFungibleTokenManager is MultiTokenManagerBase {
@param _limit The maximum amount of tokens that can be wrapped
@param _feePercentage The fee percentage for wrapping
@param _isNativeAllowed Whether or not native tokens are allowed to be wrapped
@param _admin The address of the admin who will receive minting rights and admin role
*/
function registerToken(
address _handler,
Expand All @@ -33,7 +34,8 @@ contract MultiFungibleTokenManager is MultiTokenManagerBase {
bytes32 _salt,
uint256 _limit,
uint16 _feePercentage,
bool _isNativeAllowed
bool _isNativeAllowed,
address _admin
) external override onlyRegistry onlyInitialized returns (address) {
FungibleTokenWrapper token = new FungibleTokenWrapper{ salt: _salt }(_name, _symbol);

Expand All @@ -42,7 +44,8 @@ contract MultiFungibleTokenManager is MultiTokenManagerBase {
payable(masterFeeRecipient),
_handler,
_limit,
_isNativeAllowed
_isNativeAllowed,
_admin
);

wrappedTokens.push(address(token));
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/contracts/tokens/MultiNftTokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ contract MultiNftTokenManager is MultiTokenManagerBase {
bytes32,
uint256,
uint16,
bool
bool,
address
) public view override onlyRegistry onlyInitialized returns (address) {
revert();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/contracts/tokens/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ contract Registry is Initialized, IRegistry, ProposalNonceTracker {
_salt,
_limit,
_feePercentage,
_isNativeAllowed
_isNativeAllowed,
maspVAnchor
);
emit TokenRegistered(token, _tokenHandler, _assetIdentifier);
idToWrappedAsset[_assetIdentifier] = token;
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts/contracts/tokens/TokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper {
return _amountToWrap.mul(feePercentage).div(10000);
}

/**
@notice Get the fee for a target amount to wrap
@param _admin the address for granting minting, pausing and admin roles at initialization
*/
function _initialize(address _admin) internal returns (uint256) {
_setupRole(MINTER_ROLE, _admin);
_setupRole(DEFAULT_ADMIN_ROLE, _admin);
_setupRole(PAUSER_ROLE, _admin);
}

/**
@notice Get the amount to wrap for a target `_deposit` amount
@param _deposit The deposit amount
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/contracts/vanchors/base/VAnchorBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ abstract contract VAnchorBase is LinkableAnchor {
function configureMinimalWithdrawalLimit(
uint256 _minimalWithdrawalAmount,
uint32 _nonce
) public override onlyHandler onlyIncrementingByOne(_nonce) {
) public override onlyHandler onlyIncrementingByOne(_nonce) onlyInitialized {
_configureMinimalWithdrawalLimit(_minimalWithdrawalAmount);
}

function configureMaximumDepositLimit(
uint256 _maximumDepositAmount,
uint32 _nonce
) public override onlyHandler onlyIncrementingByOne(_nonce) {
) public override onlyHandler onlyIncrementingByOne(_nonce) onlyInitialized {
_configureMaximumDepositLimit(_maximumDepositAmount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,8 @@ describe('IdentityVAnchor for 2 max edges', () => {
dummyFeeRecipient,
alice.address,
'10000000000000000000000000',
true
true,
wallet.address
);
await wrappedToken.add(token.address, (await wrappedToken.proposalNonce()).add(1));
const groupId = BigNumber.from(99); // arbitrary
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/test/token/MultiTokenManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ describe('MultiFungibleTokenManager', () => {
salt,
limit,
feePercentage,
true
true,
sender.address
);
await tx.wait();
const wrappedTokenAddress = await multiTokenMgr.contract.wrappedTokens(0);
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/test/token/Registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe('Registry', () => {
salt,
limit,
feePercentage,
true
true,
sender.address
)
).to.be.revertedWith('MultiTokenManagerBase: Only registry can call this function');
});
Expand Down
Loading