Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridging #21

Merged
merged 229 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
3630194
exploring bridgin
RomanHiden Jul 9, 2024
abdc56b
adding function setL2Farm to the interface
RomanHiden Jul 9, 2024
60420ea
script to build merkle tree
RomanHiden Jul 16, 2024
0e2ce3d
renamed merkle generating file
RomanHiden Jul 16, 2024
a1d6870
improved interface. L2Farm
RomanHiden Jul 18, 2024
7fd7de4
L2 contract
RomanHiden Jul 18, 2024
ea79736
Merge branch 'main' into bridgin
RomanHiden Jul 18, 2024
d18ec25
Merge branch 'main' into bridgin
RomanHiden Aug 8, 2024
ecdedbf
sync with feat/SOP-12
RomanHiden Aug 8, 2024
9014018
copy L1 to L2 with removing obsolete functions for L2
RomanHiden Aug 9, 2024
4491d2a
adding missing function
RomanHiden Aug 9, 2024
28a1c21
merge main
RomanHiden Aug 9, 2024
c043db2
multiple POC scripts for L1 and L2 deployment
RomanHiden Aug 12, 2024
90a92e4
updates
RomanHiden Aug 12, 2024
be90fe4
moved scripts
RomanHiden Aug 13, 2024
b30159c
updates for sophon testnet deployment
RomanHiden Aug 13, 2024
45e7564
working on merkle proof userinof
RomanHiden Aug 14, 2024
a6121d7
merkle tree works!
RomanHiden Aug 20, 2024
2fe1b8e
merkle tree works!
RomanHiden Aug 20, 2024
f05b918
merkle tree works!
RomanHiden Aug 20, 2024
914039e
merged main
RomanHiden Aug 22, 2024
551049c
very draft vSOPH
RomanHiden Aug 22, 2024
21c7738
added global start time
RomanHiden Aug 22, 2024
b408cc9
UUPSUpgradeable
RomanHiden Aug 22, 2024
60a5127
added minter role, TODO bug
RomanHiden Aug 23, 2024
12b54aa
changed according to latest requirements
RomanHiden Aug 26, 2024
5d9c6d9
wip airdrop + vSOPH + SF_L2
RomanHiden Aug 26, 2024
6c6f19d
admin claim
RomanHiden Aug 26, 2024
7911fe8
implementing _pendingPoints on merke fork calculating reward
RomanHiden Aug 27, 2024
07c5499
scripts for building tree
RomanHiden Sep 3, 2024
1ed81bd
new python scripts
RomanHiden Sep 9, 2024
0abeee9
scripts to update pool-info user-info and generate merkle tree
RomanHiden Sep 10, 2024
8e0989b
merged with latest
RomanHiden Sep 10, 2024
8c0432e
removed obsolete files
RomanHiden Sep 10, 2024
3414af0
fixing some TODOs
RomanHiden Sep 11, 2024
5e422c5
adding readme
RomanHiden Sep 11, 2024
747b2d0
feat(farming): multiple updates including vSOPH
RomanHiden Sep 19, 2024
b241ce9
feat(merkleTree): multiple claim times but once for the same pid
RomanHiden Sep 19, 2024
cdb01b5
feat(merkleTree): udpated_calculateReward to be dynamic
RomanHiden Sep 19, 2024
a8b4153
feat(README): updated done tasks
RomanHiden Sep 20, 2024
79fa478
feat
RomanHiden Sep 20, 2024
0ca3cfb
feat(SophonFarming): improved and optimized some logic
RomanHiden Sep 25, 2024
bcb48d7
feat(MerkleAirdrop): zeroing out L2 rewards after claiming
RomanHiden Oct 1, 2024
91a5912
feat(MerkleAirdrop): fixed compile error
RomanHiden Oct 2, 2024
e08472b
add index todo
RomanHiden Oct 22, 2024
4d66fbc
adding proper dai address
RomanHiden Oct 22, 2024
a5ba1fc
feat(chore): fix compiling
RomanHiden Oct 31, 2024
86ebe5a
feat(chore): fixed build
RomanHiden Oct 31, 2024
2730c13
feat(chore): remove transferFunction untill functionality stabilizes
RomanHiden Oct 31, 2024
31adf36
feat(chore): simplified vSOPH vesting
RomanHiden Oct 31, 2024
11f45cb
feat(chore): full vSOPH rework
RomanHiden Nov 4, 2024
5143265
feat(chore): implement suggestions; fix integration
RomanHiden Nov 5, 2024
f105b01
feat(chore): renamed paymaster; configurable penalty
RomanHiden Nov 5, 2024
6ac7283
feat(chore): renamed paymaster; configurable penalty
RomanHiden Nov 5, 2024
e99a2a4
feat(chore): refactor
RomanHiden Nov 5, 2024
68911c6
feat(chore): fixing corner cases with startDate
RomanHiden Nov 5, 2024
172be6d
feat(chore): fixing corner cases with startDate
RomanHiden Nov 5, 2024
35ec7c3
feat(chore): fixing corner cases
RomanHiden Nov 5, 2024
0fc3118
feat(chore): organizing
RomanHiden Nov 5, 2024
5f78b64
feat(chore): adding admin address in initialize
RomanHiden Nov 6, 2024
e3c4197
removing startDate requirement
RomanHiden Nov 6, 2024
264880f
vsoph
RomanHiden Nov 7, 2024
ae29ac9
vesting schedule new
RomanHiden Nov 7, 2024
f3fbe82
transfer functionality
RomanHiden Nov 8, 2024
9046a91
non zero destination
RomanHiden Nov 8, 2024
196f230
removed unused function
RomanHiden Nov 8, 2024
4fcb931
fixed claimSpecificSchedulesWithPenalty
RomanHiden Nov 8, 2024
0678249
Merge pull request #31 from sophon-org/vsoph
RomanHiden Nov 8, 2024
f8c6989
small fix
RomanHiden Nov 14, 2024
b07f549
test
RomanHiden Nov 18, 2024
9e6f168
adding tests for vSOPH + TODO for farming
RomanHiden Nov 18, 2024
c46eec4
fixing bad mergee
RomanHiden Nov 18, 2024
623d2d2
Merge branch 'main' into bridgin
RomanHiden Nov 25, 2024
b6347e4
feat(sepolia): deployed OPN on sepolia
RomanHiden Nov 25, 2024
38196b0
feat(bridge): beam/eth wont have a special handling
RomanHiden Nov 25, 2024
eb360b4
feat(bridge): change of plans. bridge beam/eth normally
RomanHiden Nov 25, 2024
3a4dc5a
feat(chore): revert gitignore
RomanHiden Nov 25, 2024
8361b69
removing stAethir exception
RomanHiden Nov 26, 2024
13ad358
USDC bridging
RomanHiden Nov 26, 2024
9c1f376
burn before transfer
RomanHiden Nov 26, 2024
bc3d88c
feat(vSOPH): proper transfer
RomanHiden Nov 27, 2024
db4468e
feat(chore): udpated contract to latest requirements
RomanHiden Dec 3, 2024
bf96a90
feat(chore): udpated contract to latest requirements
RomanHiden Dec 3, 2024
4c4ff00
feat(chore): udpated contract to latest requirements
RomanHiden Dec 3, 2024
4231a74
Using USD price feeds to balance pool emissions
CryptoMan0x Dec 3, 2024
f71ffa1
added emissionsMultiplier
CryptoMan0x Dec 3, 2024
7954276
added emissionsMultiplier
CryptoMan0x Dec 3, 2024
9a56d72
balance changes to any pool updates all pools
CryptoMan0x Dec 3, 2024
0a73d7e
small update
CryptoMan0x Dec 4, 2024
82be9ed
built merkel tree
RomanHiden Dec 4, 2024
8ab163e
updated readme
RomanHiden Dec 4, 2024
7dd3c38
moar updates; poolInfo array fix
RomanHiden Dec 5, 2024
91754cb
more code
RomanHiden Dec 5, 2024
41c17c7
Integrated Stork price feeds
CryptoMan0x Dec 6, 2024
43436dc
fix bug
RomanHiden Dec 6, 2024
5401f59
updated interface
RomanHiden Dec 6, 2024
2281323
tests: update farming tests and all farmingL2
federava Dec 6, 2024
23589c4
Merge branch 'bridgin' into feat/usd-based-weightings
RomanHiden Dec 8, 2024
4fc4ee9
feat(chore): initialize dynamic array before use
RomanHiden Dec 8, 2024
711f304
feat(fix): changed to mapping
RomanHiden Dec 8, 2024
187610e
Merge pull request #34 from sophon-org/feat/usd-based-weightings-arra…
RomanHiden Dec 8, 2024
86c73aa
Merge pull request #33 from sophon-org/feat/usd-based-weightings
RomanHiden Dec 8, 2024
59a77f0
minor changes
RomanHiden Dec 8, 2024
47b64bc
reset points; corner cases
RomanHiden Dec 8, 2024
55a6b2a
udpated logic per Tom
RomanHiden Dec 8, 2024
e1673ba
minor changes
RomanHiden Dec 9, 2024
42b307f
don't reset points
RomanHiden Dec 9, 2024
f579255
Merge pull request #35 from sophon-org/bridgin-updates
RomanHiden Dec 9, 2024
7ef1435
simulate complete withdraw point wise
RomanHiden Dec 9, 2024
a2e5935
wip
RomanHiden Dec 9, 2024
2498be4
updates to updateUserInfo
CryptoMan0x Dec 10, 2024
91f8054
backdated rewards
RomanHiden Dec 10, 2024
ec09dde
backdated rewards
RomanHiden Dec 10, 2024
2450efc
feat(chore): fixing rewards and accruing rewards
RomanHiden Dec 11, 2024
85cb618
feat(audit): fixing discrepancies with regards to the Solidity version
RomanHiden Dec 17, 2024
8645841
feat(audit): MAP-01S
RomanHiden Dec 17, 2024
3b6a65d
feat(audit): SFG-01S: Illegible Numeric Value Representations
RomanHiden Dec 17, 2024
8508c42
SFG-02S: Inexistent Sanitization of Input Addresses
RomanHiden Dec 17, 2024
3467983
SFL-01S: Illegible Numeric Value Representations
RomanHiden Dec 17, 2024
5d208e3
SFL-02S: Inexistent Sanitization of Input Address
RomanHiden Dec 17, 2024
ea29ee3
SFL-04M: Inexistent Update of Pool State
RomanHiden Dec 17, 2024
37b206b
SFL-05M: Inexistent Validation of Pool ID Existence
RomanHiden Dec 17, 2024
2530722
MAP-01C: Inefficient Logic Import
RomanHiden Dec 17, 2024
3e61a63
MAP-02C: Inefficient mapping Lookups
RomanHiden Dec 17, 2024
5d73e25
MAP-03C: Non-Standard Usage of Library
RomanHiden Dec 17, 2024
3a0dfae
SFG-01C: Deprecated Representation of Maximum
RomanHiden Dec 17, 2024
2aeb1f2
SFG-02C: Duplication of Restrictions
RomanHiden Dec 17, 2024
75c687c
SFG-03C: Generic Typographic Mistakes
RomanHiden Dec 17, 2024
5063e49
SFG-04C: Incorrect Error
RomanHiden Dec 17, 2024
c9a8cfa
SFG-07C: Inefficient Conditional Structures
RomanHiden Dec 17, 2024
efebb5f
Revert "SFG-07C: Inefficient Conditional Structures"
RomanHiden Dec 17, 2024
87cca28
SFG-07C: Inefficient Conditional Structures
RomanHiden Dec 17, 2024
a028889
SFG-07C: Inefficient Conditional Structures
RomanHiden Dec 17, 2024
20ea06e
SFG-08C: Inefficient mapping Lookups
RomanHiden Dec 17, 2024
63aa85d
SFL-01C: Deprecated Revert Pattern
RomanHiden Dec 17, 2024
8d0c13e
SFL-05C: Inefficient mapping Lookups
RomanHiden Dec 17, 2024
0e852f3
SFG-06M: Incorrect & Deprecated Approval Increase
RomanHiden Dec 17, 2024
c6e62fe
Merge pull request #57 from sophon-org/feat/SFG-06M
CryptoMan0x Dec 18, 2024
2c34f27
feat(audit): wrong pendle pool
RomanHiden Dec 18, 2024
f61f984
fixed typo
CryptoMan0x Dec 20, 2024
a5ae54e
SFL-06M: Incorrect Pool Update Mechanisms
CryptoMan0x Dec 22, 2024
6343253
Merge pull request #38 from sophon-org/feat/unifying-solc-version
CryptoMan0x Dec 22, 2024
2ea0277
Merge pull request #39 from sophon-org/feat/MAP-01S
CryptoMan0x Dec 22, 2024
1645132
Merge pull request #40 from sophon-org/feat/SFG-01S
CryptoMan0x Dec 22, 2024
cde296f
Merge pull request #41 from sophon-org/feat/SFG-02S
CryptoMan0x Dec 22, 2024
30bc60f
Merge pull request #42 from sophon-org/feat/SFL-01S
CryptoMan0x Dec 22, 2024
a026754
Merge pull request #43 from sophon-org/feat/SFL-02S
CryptoMan0x Dec 22, 2024
1a3db97
Update SophonFarmingL2.sol
CryptoMan0x Dec 22, 2024
c9b98e4
Merge pull request #44 from sophon-org/feat/SFL-04M
CryptoMan0x Dec 22, 2024
905462e
Merge pull request #45 from sophon-org/feat/SFL-05M
CryptoMan0x Dec 22, 2024
379a389
Merge pull request #47 from sophon-org/feat/MAP-02C
CryptoMan0x Dec 22, 2024
d3bbb52
Merge pull request #48 from sophon-org/feat/MAP-03C
CryptoMan0x Dec 22, 2024
a9d23b5
Merge pull request #49 from sophon-org/feat/SFG-01C
CryptoMan0x Dec 22, 2024
c8ad55d
Merge pull request #50 from sophon-org/feat/SFG-02C
CryptoMan0x Dec 22, 2024
d37c9b3
Merge branch 'bridgin' into feat/SFG-03C
CryptoMan0x Dec 22, 2024
02e2763
Merge pull request #51 from sophon-org/feat/SFG-03C
CryptoMan0x Dec 22, 2024
9898626
Merge pull request #52 from sophon-org/feat/SFG-04C
CryptoMan0x Dec 22, 2024
6e30123
small fixes
CryptoMan0x Dec 22, 2024
ed4d9f9
Merge pull request #53 from sophon-org/feat/SFG-07C
CryptoMan0x Dec 22, 2024
7a09bb8
Merge pull request #54 from sophon-org/feat/SFG-08C
CryptoMan0x Dec 22, 2024
f822711
additional update
CryptoMan0x Dec 22, 2024
ea53458
Merge pull request #60 from sophon-org/feat/SFG-08C
CryptoMan0x Dec 22, 2024
87d8433
Merge pull request #55 from sophon-org/feat/SFL-01C
CryptoMan0x Dec 22, 2024
aebe95f
Merge branch 'bridgin' into feat/SFL-05C
CryptoMan0x Dec 22, 2024
c027a83
Merge pull request #56 from sophon-org/feat/SFL-05C
CryptoMan0x Dec 22, 2024
fcab1d7
Merge branch 'bridgin' into feat/tom-audit
CryptoMan0x Dec 22, 2024
bb661e0
Merge pull request #58 from sophon-org/feat/tom-audit
CryptoMan0x Dec 22, 2024
c836fb6
allow PENDLE_EXCEPTION to withdraw past withdrawal period ended
RomanHiden Dec 23, 2024
1cf2fd3
Merge branch 'feat/tom-audit' of github.com:sophon-org/farming-contra…
RomanHiden Dec 23, 2024
81f5bbd
Merge pull request #61 from sophon-org/feat/tom-audit
CryptoMan0x Dec 23, 2024
6f93fd9
SFG-01M: Unknown System Integration
RomanHiden Dec 23, 2024
85ecb18
resolved merge conflict
RomanHiden Dec 23, 2024
edcdb07
added deposit lock
CryptoMan0x Dec 23, 2024
46deb25
SFL-03M: Inexistent Sanitization of Pool Overwrite
RomanHiden Dec 23, 2024
7dd97f0
Merge branch 'bridgin' into feat/SFL-06M
RomanHiden Dec 23, 2024
1f8cf8e
Merge pull request #62 from sophon-org/feat/SFG-01M
CryptoMan0x Dec 23, 2024
7cc0b5f
Merge pull request #64 from sophon-org/feat/SFL-03M
CryptoMan0x Dec 23, 2024
06a5599
Update MerkleAirdrop.sol
CryptoMan0x Dec 23, 2024
d19e988
Merge pull request #46 from sophon-org/feat/MAP-01C
CryptoMan0x Dec 23, 2024
f279990
updated license
CryptoMan0x Dec 26, 2024
71cf363
Merge branch 'bridgin' into feat/SFL-06M
CryptoMan0x Dec 26, 2024
7624118
feat: add function to withdraw held proceeds
RomanHiden Dec 26, 2024
0aa3bdf
added PriceFeeds contract
CryptoMan0x Dec 26, 2024
2027b77
setStorkFeedData is converted to a batch function
CryptoMan0x Dec 26, 2024
548c277
updated interface
RomanHiden Dec 26, 2024
ed99b72
event update
CryptoMan0x Dec 26, 2024
6a2cbd2
small fix
CryptoMan0x Dec 27, 2024
f50c739
update to L1 bridging code
CryptoMan0x Dec 27, 2024
57315aa
Merge branch 'bridgin' into feat/SFL-06M
CryptoMan0x Dec 27, 2024
d61facf
small update
CryptoMan0x Dec 27, 2024
323d43b
Merge branch 'bridgin' into feat/SFL-06M
CryptoMan0x Dec 27, 2024
27ba55e
added PriceFeedsProxy
CryptoMan0x Dec 27, 2024
a66262d
Merge pull request #59 from sophon-org/feat/SFL-06M
CryptoMan0x Dec 27, 2024
aba04fb
merging bridgin
CryptoMan0x Dec 27, 2024
9344f5a
Merge pull request #63 from sophon-org/feat/deposit-lock
CryptoMan0x Dec 27, 2024
f8f79e0
Merge pull request #65 from sophon-org/feat/held-proceeds-withdraw
CryptoMan0x Dec 27, 2024
48246ac
small update
CryptoMan0x Dec 27, 2024
60ad14f
removing lock functionality
CryptoMan0x Dec 27, 2024
b7094c9
feat: updated scripts
RomanHiden Dec 27, 2024
2761283
Merge branch 'bridgin' into feat/collect-info-build-merkle
RomanHiden Dec 27, 2024
98a706c
sophon mainnet env file
RomanHiden Dec 27, 2024
5694131
script updates
CryptoMan0x Dec 27, 2024
5ea6a03
event update
CryptoMan0x Dec 27, 2024
4d905d5
adding OPN
RomanHiden Dec 27, 2024
78088e1
pushed into this branch feat/collect-info-build-merkle added OPN to t…
RomanHiden Dec 27, 2024
188850e
msig proposal
RomanHiden Dec 27, 2024
d766a0f
small fix
CryptoMan0x Dec 27, 2024
3dc5389
Merge branch 'bridgin' into feat/collect-info-build-merkle
CryptoMan0x Dec 27, 2024
7b26f97
calculating rewardsSettled
RomanHiden Dec 27, 2024
c2f7b52
Merge branch 'feat/collect-info-build-merkle' of github.com:sophon-or…
RomanHiden Dec 27, 2024
be51d8e
result
RomanHiden Dec 27, 2024
3fbb105
script updates
CryptoMan0x Dec 28, 2024
d65f830
updated addPool
RomanHiden Dec 28, 2024
feeb01d
multiple updates regarding total rewards
RomanHiden Dec 28, 2024
524ccde
safety checks improve
RomanHiden Dec 28, 2024
4a0d2fa
generate new proof
RomanHiden Dec 28, 2024
082d766
only backdated rewards pass to L2
RomanHiden Dec 28, 2024
e7548d9
zero out new_rewardDebt
RomanHiden Dec 28, 2024
3c413e6
zero out new_rewardDebt
RomanHiden Dec 28, 2024
569cf09
script update
CryptoMan0x Dec 28, 2024
0ae03e9
script update
CryptoMan0x Dec 28, 2024
631d461
Merge pull request #66 from sophon-org/feat/collect-info-build-merkle
CryptoMan0x Dec 28, 2024
4695399
small update
CryptoMan0x Dec 28, 2024
90d52ce
fixes
CryptoMan0x Dec 28, 2024
161b625
propose msig scripts to update
RomanHiden Dec 29, 2024
608b66e
feat(chore): adming claming with custom receiver
RomanHiden Jan 4, 2025
0477825
adding setStorkFeedsData
RomanHiden Jan 6, 2025
58f3f02
revert to original
RomanHiden Jan 6, 2025
7138558
Merge pull request #67 from sophon-org/feat/admin-claim-01
CryptoMan0x Jan 6, 2025
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
2 changes: 1 addition & 1 deletion brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ networks:
compiler:
evm_version: shanghai
solc:
version: null
version: 0.8.26
optimizer:
enabled: true
runs: 200
Expand Down
121 changes: 121 additions & 0 deletions contracts/airdrop/MerkleAirdrop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "contracts/token/LinearVestingWithPenalty.sol";
import "contracts/farm/SophonFarmingL2.sol";

contract MerkleAirdrop is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
SophonFarmingL2 public SF_L2;
bytes32 public merkleRoot;

// Changed mapping to track claims per user per PID
mapping(address => mapping(uint256 => bool)) public hasClaimed;


event Claimed(address indexed account, uint256 pid);
event MerkleRootUpdated(bytes32 newMerkleRoot);

error AlreadyClaimed();
error InvalidMerkleProof();
error NotAuthorized();
error InvalidInputLengths();

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(address _SF_L2) public initializer {
SF_L2 = SophonFarmingL2(_SF_L2);

__AccessControl_init();
__UUPSUpgradeable_init();

_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ADMIN_ROLE, msg.sender);
}

/**
* @dev Sets the Merkle root for the airdrop.
* @param _merkleRoot The new Merkle root.
*/
function setMerkleRoot(bytes32 _merkleRoot) external onlyRole(ADMIN_ROLE) {
merkleRoot = _merkleRoot;
emit MerkleRootUpdated(_merkleRoot);
}


function claim(address _user, address _customReceiver, uint256 _pid, SophonFarmingState.UserInfo memory _userInfo, bytes32[] calldata _merkleProof) external onlyRole(ADMIN_ROLE) {
_claim(_user, _customReceiver, _pid, _userInfo, _merkleProof);
}

/**
* @dev Allows users to claim their tokens if they are part of the Merkle tree.
* @param _user The address of the user that is participating.
* @param _pid The pool ID that the user is participating in.
* @param _userInfo The `UserInfo` struct containing the user's info.
* @param _merkleProof The Merkle proof to verify the user's inclusion in the tree.
*/
function claim(address _user, uint256 _pid, SophonFarmingState.UserInfo memory _userInfo, bytes32[] calldata _merkleProof) external {
if (msg.sender != _user) revert NotAuthorized();
_claim(_user, _user, _pid, _userInfo, _merkleProof);
}

/**
* @dev Allows users to claim multiple tokens if they are part of the Merkle tree.
* @param _user The address of the user that is participating.
* @param _pids An array of pool IDs that the user is participating in.
* @param _userInfos An array of `UserInfo` structs containing the user's info for each pool.
* @param _merkleProofs An array of Merkle proofs to verify the user's inclusion in the tree for each pool.
*/
function claimMultiple(
address _user,
uint256[] calldata _pids,
SophonFarmingState.UserInfo[] calldata _userInfos,
bytes32[][] calldata _merkleProofs
) external {
if (msg.sender != _user) revert NotAuthorized();
if (_pids.length != _userInfos.length || _userInfos.length != _merkleProofs.length) revert InvalidInputLengths();

for (uint256 i = 0; i < _pids.length; i++) {
_claim(_user, _user, _pids[i], _userInfos[i], _merkleProofs[i]);
}
}

// TODO add index
function _claim(address _user, address _customReceiver, uint256 _pid, SophonFarmingState.UserInfo memory _userInfo, bytes32[] calldata _merkleProof) internal {
if (hasClaimed[_user][_pid]) revert AlreadyClaimed();

// Verify the Merkle proof.
bytes32 leaf = keccak256(abi.encodePacked(_user, _pid, _userInfo.amount, _userInfo.boostAmount, _userInfo.depositAmount, _userInfo.rewardSettled, _userInfo.rewardDebt));
if (!MerkleProof.verify(_merkleProof, merkleRoot, leaf)) revert InvalidMerkleProof();

// Mark it claimed and transfer the tokens.
hasClaimed[_user][_pid] = true;

_userInfo.rewardSettled = 0;
SF_L2.updateUserInfo(_customReceiver, _pid, _userInfo);
emit Claimed(_user, _pid);
}

/**
* @dev Allows the recovery of any ERC20 tokens sent to the contract by mistake.
* @param token The address of the token to recover.
* @param to The address to send the recovered tokens to.
*/
function rescue(IERC20 token, address to) external onlyRole(ADMIN_ROLE) {
SafeERC20.safeTransfer(token, to, token.balanceOf(address(this)));
}

/**
* @dev Required by UUPSUpgradeable to authorize upgrades.
* @param newImplementation The address of the new implementation.
*/
function _authorizeUpgrade(address newImplementation) internal override onlyRole(ADMIN_ROLE) {}
}
150 changes: 104 additions & 46 deletions contracts/farm/SophonFarming.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "./interfaces/IeETHLiquidityPool.sol";
import "./interfaces/IweETH.sol";
import "../proxies/Upgradeable2Step.sol";
import "./SophonFarmingState.sol";
import 'contracts/interfaces/uniswap/IUniswapV2Router02.sol';

/**
* @title Sophon Farming Contract
Expand Down Expand Up @@ -42,9 +43,6 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
/// @notice Emitted when all pool funds are bridged to Sophon blockchain
event BridgePool(address indexed user, uint256 indexed pid, uint256 amount);

/// @notice Emitted when the admin bridges booster proceeds
event BridgeProceeds(uint256 indexed pid, uint256 proceeds);

/// @notice Emitted when the the revertFailedBridge function is called
event RevertFailedBridge(uint256 indexed pid);

Expand Down Expand Up @@ -85,13 +83,16 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
address public immutable eETH;
address public immutable eETHLiquidityPool;
address public immutable weETH;
uint256 public immutable CHAINID;
uint256 internal constant BEAM_WEHT_PID = 4;
address internal constant PENDLE_EXCEPTION = 0x065347C1Dd7A23Aa043e3844B4D0746ff7715246;

/**
* @notice Construct SophonFarming
* @param tokens_ Immutable token addresses
* @dev 0:dai, 1:sDAI, 2:weth, 3:stETH, 4:wstETH, 5:eETH, 6:eETHLiquidityPool, 7:weETH
*/
constructor(address[8] memory tokens_) {
constructor(address[8] memory tokens_, uint256 _CHAINID) {
dai = tokens_[0];
sDAI = tokens_[1];
weth = tokens_[2];
Expand All @@ -100,6 +101,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
eETH = tokens_[5];
eETHLiquidityPool = tokens_[6];
weETH = tokens_[7];
CHAINID = _CHAINID;
}

/**
Expand Down Expand Up @@ -286,7 +288,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
if (_bridge == address(0)) {
revert ZeroAddress();
}
bridge = BridgeLike(_bridge);
bridge = IBridgehub(_bridge);
}

/**
Expand Down Expand Up @@ -332,7 +334,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
* @notice Set points per block
* @param _pointsPerBlock points per block to set
*/
function setPointsPerBlock(uint256 _pointsPerBlock) public onlyOwner {
function setPointsPerBlock(uint256 _pointsPerBlock) virtual public onlyOwner {
if (isFarmingEnded()) {
revert FarmingIsEnded();
}
Expand All @@ -348,7 +350,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
* @notice Set booster multiplier
* @param _boosterMultiplier booster multiplier to set
*/
function setBoosterMultiplier(uint256 _boosterMultiplier) external onlyOwner {
function setBoosterMultiplier(uint256 _boosterMultiplier) virtual external onlyOwner {
if (_boosterMultiplier < 1e18 || _boosterMultiplier > 10e18) {
revert InvalidBooster();
}
Expand Down Expand Up @@ -808,14 +810,23 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
emit Withdraw(msg.sender, _pid, _withdrawAmount);
}


/**
* @notice Permissionless function to allow anyone to bridge during the correct period
* @param _pid pid to bridge
* @param _l2TxGasLimit l2TxGasLimit for the bridge txn
* @param _l2TxGasPerPubdataByte l2TxGasPerPubdataByte for the bridge txn
* @param _mintValue _mintValue SOPH gas price
*/
function bridgePool(uint256 _pid, uint256 _l2TxGasLimit, uint256 _l2TxGasPerPubdataByte) external payable {
revert Unauthorized(); // NOTE: function not fully implemented, an upgrade will implement this later

function bridgePool(uint256 _pid, uint256 _mintValue, address _sophToken) external payable {
// USDC exception
if (_pid == 7) {
revert Unauthorized();
}

_bridgePool(_pid, _mintValue, _sophToken, bridge);
}

function _bridgePool(uint256 _pid, uint256 _mintValue, address _sophToken, IBridgehub _bridge) internal {

if (!isFarmingEnded() || !isWithdrawPeriodEnded() || isBridged[_pid]) {
revert Unauthorized();
Expand All @@ -824,41 +835,105 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
updatePool(_pid);
PoolInfo storage pool = poolInfo[_pid];

uint256 depositAmount = pool.depositAmount;
if (depositAmount == 0 || address(bridge) == address(0) || pool.l2Farm == address(0)) {
if (pool.depositAmount == 0 || address(bridge) == address(0) || pool.l2Farm == address(0)) {
revert BridgeInvalid();
}
uint256 depositAmount = IERC20(pool.lpToken).balanceOf(address(this));

isBridged[_pid] = true;

IERC20 lpToken = pool.lpToken;
lpToken.approve(address(bridge), depositAmount);
if (_pid == BEAM_WEHT_PID) {
UserInfo storage user = userInfo[BEAM_WEHT_PID][PENDLE_EXCEPTION];
depositAmount -= user.depositAmount - user.boostAmount / boosterMultiplier;
}

L2TransactionRequestTwoBridgesOuter memory _request = L2TransactionRequestTwoBridgesOuter({
chainId: CHAINID,
mintValue: _mintValue,
l2Value: 0,
l2GasLimit: 2000000,
l2GasPerPubdataByteLimit: 800,
refundRecipient: address(this),
secondBridgeAddress: address(bridge.sharedBridge()),
secondBridgeValue: 0,
secondBridgeCalldata: abi.encode(pool.lpToken, depositAmount, pool.l2Farm)
});

if (pool.lpToken.allowance(address(this), _request.secondBridgeAddress) < depositAmount) {
pool.lpToken.safeIncreaseAllowance(_request.secondBridgeAddress, type(uint256).max);
}
IERC20(_sophToken).safeTransferFrom(msg.sender, address(this), _mintValue);
IERC20(_sophToken).safeIncreaseAllowance(_request.secondBridgeAddress, _mintValue);

// Actual values are pending the launch of Sophon testnet
bridge.deposit{value: msg.value}(
pool.l2Farm, // _l2Receiver
address(lpToken), // _l1Token
depositAmount, // _amount
_l2TxGasLimit, // _l2TxGasLimit
_l2TxGasPerPubdataByte, // _l2TxGasPerPubdataByte
owner() // _refundRecipient
);
_bridge.requestL2TransactionTwoBridges(_request);

isBridged[_pid] = true;
emit BridgePool(msg.sender, _pid, depositAmount);
}

// TODO: does this function need to call claimFailedDeposit on the bridge?
// This is pending the launch of Sophon testnet

// bridge USDC
function bridgeUSDC(uint256 _mintValue, address _sophToken, IBridgehub _bridge) external onlyOwner {
uint256 _pid = 7;
if (!isFarmingEnded() || !isWithdrawPeriodEnded() || isBridged[_pid]) {
revert Unauthorized();
}

// IBridgehub _bridge = IBridgehub(address(0));
_bridgePool(_pid, _mintValue, _sophToken, _bridge);

}

/**
* @notice Set L2Farming contract for particular pool
* @param _pid pid to bridge
* @param _l2Farm address of the contract for farming on L2 side
*/
function setL2Farm(uint256 _pid, address _l2Farm) external onlyOwner {
if (_pid >= poolInfo.length) {
revert PoolExists();
}

if (_l2Farm == address(0)) {
revert ZeroAddress();
}

poolInfo[_pid].l2Farm = _l2Farm;
}


/**
* @notice Called by an admin if a bridge process to Sophon fails
* @param _pid pid of the failed bridge to revert
*/
function revertFailedBridge(uint256 _pid) external onlyOwner {
revert Unauthorized(); // NOTE: function not fully implemented, an upgrade will implement this later
function revertFailedBridge(
address _l1SharedBridge,
uint256 _pid,
uint256 _chainId,
address _depositSender,
address _l1Token,
uint256 _amount,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof) external onlyOwner {

if (address(poolInfo[_pid].lpToken) == address(0)) {
revert PoolDoesNotExist();
}

IL1SharedBridge(_l1SharedBridge).claimFailedDeposit(
_chainId,
_depositSender,
_l1Token,
_amount,
_l2TxHash,
_l2BatchNumber,
_l2MessageIndex,
_l2TxNumberInBatch,
_merkleProof
);

isBridged[_pid] = false;
emit RevertFailedBridge(_pid);
}
Expand Down Expand Up @@ -998,23 +1073,6 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
return IsDAI(sDAI).deposit(_amount, address(this));
}

// This is pending the launch of Sophon testnet
/**
* @notice Allows an admin to bridge booster proceeds
* @param _pid pid to bridge proceeds from
* @param _l2TxGasLimit l2TxGasLimit for the bridge txn
* @param _l2TxGasPerPubdataByte l2TxGasPerPubdataByte for the bridge txn
*/
function bridgeProceeds(uint256 _pid, uint256 _l2TxGasLimit, uint256 _l2TxGasPerPubdataByte) external payable onlyOwner {
revert Unauthorized(); // NOTE: function not fully implemented, an upgrade will implement this later

uint256 _proceeds = heldProceeds[_pid];
heldProceeds[_pid] = 0;

// TODO: add bridging logic

emit BridgeProceeds(_pid, _proceeds);
}

/**
* @notice Returns the current block number
Expand Down
Loading