Skip to content

Commit

Permalink
Merge pull request #1194 from airswap/develop
Browse files Browse the repository at this point in the history
Publish to Beta
  • Loading branch information
dmosites authored Sep 18, 2023
2 parents de2f67a + 6e1ebcf commit 4c17d3f
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install
- run: lerna run compile --concurrency=1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install
- run: lerna run compile --concurrency=1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Test using Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
node-version: '18.x'
- run: yarn install
- run: lerna run compile --concurrency=1
- run: lerna run test:ci --concurrency=1
Expand Down
37 changes: 31 additions & 6 deletions source/pool/contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ contract Pool is IPool, Ownable2Step {
emit Enable(_tree, _root);
}

/**
* @notice Set previous claims for migrations
* @param _tree bytes32
* @param _root bytes32
* @param _accounts address[]
* @dev Only owner
*/
function enableAndSetClaimed(
bytes32 _tree,
bytes32 _root,
address[] memory _accounts
) external override multiAdmin {
// Enable the tree if not yet enabled
if (rootsByTree[_tree] == 0) {
rootsByTree[_tree] = _root;
emit Enable(_tree, _root);
}
// Iterate and set as claimed if not yet claimed
for (uint256 i = 0; i < _accounts.length; i++) {
if (claimed[_tree][_accounts[i]] == false) {
claimed[_tree][_accounts[i]] = true;
emit UseClaim(_accounts[i], _tree);
}
}
}

/**
* @notice Withdraw tokens using claims
* @param _claims Claim[] a set of claims
Expand All @@ -141,22 +167,21 @@ contract Pool is IPool, Ownable2Step {

Claim memory _claim;
bytes32 _root;
bytes32[] memory _treeList = new bytes32[](_claims.length);
uint256 _totalValue = 0;

// Iterate through claims to determine total value
for (uint256 i = 0; i < _claims.length; i++) {
_claim = _claims[i];
_root = rootsByTree[_claim.tree];

if (_root == 0) revert TreeDisabled(_claim.tree);
if (claimed[_claim.tree][msg.sender]) revert AlreadyClaimed();
if (_root == 0) revert TreeNotEnabled(_claim.tree);
if (claimed[_claim.tree][msg.sender]) revert ClaimAlreadyUsed();
if (!verify(msg.sender, _root, _claim.value, _claim.proof))
revert ProofInvalid(_claim.tree, _root);

_totalValue = _totalValue + _claim.value;
claimed[_claim.tree][msg.sender] = true;
_treeList[i] = _claim.tree;
emit UseClaim(msg.sender, _claim.tree);
}

// Determine withdrawable amount given total value
Expand All @@ -165,7 +190,7 @@ contract Pool is IPool, Ownable2Step {

// Transfer withdrawable amount to recipient
IERC20(_token).safeTransfer(_recipient, _amount);
emit Withdraw(_treeList, msg.sender, _token, _amount);
emit Withdraw(msg.sender, _recipient, _token, _amount);
}

/**
Expand All @@ -180,7 +205,7 @@ contract Pool is IPool, Ownable2Step {
) public view override returns (uint256) {
uint256 _balance = IERC20(_token).balanceOf(address(this));
uint256 _divisor = (uint256(10) ** scale) + _value;
return (max * _value * _balance) / _divisor / 100;
return (max * _value * _balance) / _divisor / MAX_PERCENTAGE;
}

/**
Expand Down
29 changes: 18 additions & 11 deletions source/pool/contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ interface IPool {
event SetMax(uint256 max);
event SetScale(uint256 scale);
event UnsetAdmin(address admin);

event UseClaim(address account, bytes32 tree);
event Withdraw(
bytes32[] trees,
address account,
address recipient,
address token,
uint256 amount
);

error AddressInvalid(address);
error AdminNotSet(address);
error AlreadyClaimed();
error AmountInsufficient(uint256);
error ClaimAlreadyUsed();
error ClaimsNotProvided();
error MaxTooHigh(uint256);
error ProofInvalid(bytes32, bytes32);
error TreeDisabled(bytes32);
error TreeNotEnabled(bytes32);
error ScaleTooHigh(uint256);
error TokenInvalid(address);
error Unauthorized();

function drainTo(address[] calldata tokens, address dest) external;

function setScale(uint256 _scale) external;

function setMax(uint256 _max) external;
Expand All @@ -42,15 +45,14 @@ interface IPool {

function unsetAdmin(address _admin) external;

function drainTo(address[] calldata tokens, address dest) external;

function getStatus(
address _account,
bytes32[] calldata _trees
) external returns (bool[] memory statuses);

function enable(bytes32 _tree, bytes32 _root) external;

function enableAndSetClaimed(
bytes32 _tree,
bytes32 _root,
address[] memory _accounts
) external;

function withdraw(
Claim[] memory claims,
address token,
Expand All @@ -69,4 +71,9 @@ interface IPool {
uint256 score,
bytes32[] memory proof
) external pure returns (bool valid);

function getStatus(
address _account,
bytes32[] calldata _trees
) external returns (bool[] memory statuses);
}
Loading

0 comments on commit 4c17d3f

Please sign in to comment.