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

Multichain #105

Open
wants to merge 228 commits into
base: v2.2-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
31cdecd
Merge branch 'gasless' into multichain
xdev10 Jan 27, 2025
122e703
Merge branch 'v2.2-branch' into multichain
xdev10 Jan 27, 2025
233f187
update yarn
xdev10 Jan 27, 2025
48ee48c
WIP multichain
dmax10 Jan 27, 2025
4da6f6c
Merge branch 'gasless' into multichain
dmax10 Jan 31, 2025
7413467
Merge branch 'v2.2-branch' into multichain
dmax10 Jan 31, 2025
00dd7d1
Make BaseGelatoRelayRouter._sendTokens virtual to be able to override…
dmax10 Feb 1, 2025
1200a1a
fix compile errors
dmax10 Feb 1, 2025
6cb97f8
Rename MultichainHandler in MultichainVaultHandler
dmax10 Feb 1, 2025
21e9c14
Add GaslessCreateDepositParams
dmax10 Feb 1, 2025
1129853
Add chainId to Deposit.Props
dmax10 Feb 1, 2025
908b2bd
Update multichain createDeposit logic
dmax10 Feb 1, 2025
572d0b7
Emit dataList for createDeposit, createWithdrawal, createOrder, updat…
dmax10 Feb 2, 2025
70f486e
Rename sourceChain* to multichain*
dmax10 Feb 3, 2025
774b598
Add multichain increase and decrease utils methods
dmax10 Feb 3, 2025
9111ef4
Add chainId to Withdrawal, Shift, GlvDeposit, GlvWithdrawal
dmax10 Feb 3, 2025
6c490c1
Fix increaseBalance: incrementUint instead of decrementUint
dmax10 Feb 4, 2025
5994001
Set chainId for Deposit on executeShift, remove position chainId rela…
dmax10 Feb 4, 2025
6bd246b
WIP multichain deposits and gm logic
dmax10 Feb 4, 2025
68c06ce
Update multichain logic for fee payment
dmax10 Feb 5, 2025
48c9a91
Remove chainId from multichain balance
dmax10 Feb 5, 2025
370d42a
Rename chainId to srcChainId
dmax10 Feb 5, 2025
0c1ff1a
Move srcChainId into RelayParams
dmax10 Feb 5, 2025
76dfadd
Emit srcChainId for createWithdrawal, createShift, createGlvDeposit, …
dmax10 Feb 6, 2025
c7b4ca2
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 6, 2025
df9ac70
Fix tests after merging gasless branch
dmax10 Feb 6, 2025
8064ea1
Use srcChainId instead of block.chainid to _validateCall
dmax10 Feb 6, 2025
b9cc9be
Use block.chainid as the desChainId to genearte gaslessCreateDepositP…
dmax10 Feb 6, 2025
96f8609
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 6, 2025
e471ec8
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 6, 2025
1ba3477
Add in and out multichain transfers methods to MultichainUtils lib. R…
dmax10 Feb 7, 2025
97625ad
Add multichainVault address to contracts and stucts
dmax10 Feb 7, 2025
3d3477d
Validate desChainId provided is block.chainid, rename gasless to mult…
dmax10 Feb 7, 2025
3d783dd
Add srcChainId to _sendTokens
dmax10 Feb 7, 2025
d78d5ca
Change Contracts { OrderVault orderVault } into Contracts { StrictBan…
dmax10 Feb 7, 2025
65168e6
Split CreateDepositParams into subgroups
dmax10 Feb 8, 2025
c174957
Add srcChainId to orders
dmax10 Feb 9, 2025
e6c2dad
Add srcChainId to _sendTokens
dmax10 Feb 9, 2025
674dddb
Rename multichainId to srcChainId, remove second topic log
dmax10 Feb 10, 2025
7269653
reorder method params
dmax10 Feb 10, 2025
b27ba9e
Record residualFee under user's multichain balance when the residualF…
dmax10 Feb 10, 2025
756fba7
Add srcChiainId field to CreateOrderParams struct
dmax10 Feb 10, 2025
abacb21
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 10, 2025
06afc34
gasless merge fixes
dmax10 Feb 10, 2025
4f0fe26
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 10, 2025
6f0199b
Implement multichain createWithdrawal
dmax10 Feb 10, 2025
6b08605
Use multichainVault as withdrawal receiver for GM/GLV for source chai…
dmax10 Feb 11, 2025
7afe63d
Implement multichain createGlvDeposit
dmax10 Feb 11, 2025
c891d25
Use MultichainUtils as external lib to avoid increasing the size of t…
dmax10 Feb 11, 2025
4e958e7
Implement multichain createGlvWithdrawal
dmax10 Feb 11, 2025
eb5ad00
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 11, 2025
ec51450
Fix function params order
dmax10 Feb 12, 2025
c2af843
Implement multichain createShift
dmax10 Feb 12, 2025
6882c2c
Fix refund fee receiver for multichain actions
dmax10 Feb 12, 2025
a9b3017
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 12, 2025
5d3822f
Refactor BaseGelatoRelayRouter, GelatoRelayRouter, MultichainRouter t…
dmax10 Feb 13, 2025
967b56c
Refactor MultichainRouter by spliting it's logic into MultichainGmRou…
dmax10 Feb 13, 2025
8b7a0f2
Add TransferRequest[] param to create* multichain actions and _sendTo…
dmax10 Feb 13, 2025
ce8c971
Refactor GlvDepositUtils to move the "execute" part into ExecuteGlvDe…
dmax10 Feb 13, 2025
01738f2
Uncomment relay fee refund logic after solving the contract size error
dmax10 Feb 13, 2025
78f619d
Refactor to add addresses subgroup to CreateGlvDepositParams to fix t…
dmax10 Feb 13, 2025
9170014
Refactor to add addresses subgroup to CreateGlvWithdrawalParams to fi…
dmax10 Feb 13, 2025
6e3cf10
Remove "immutable" from state variables to reduce contract size bello…
dmax10 Feb 13, 2025
7aa648c
Remove srcChainId from RelayParams struct
dmax10 Feb 14, 2025
9447228
Remove outdated contracts
dmax10 Feb 14, 2025
576c3ca
Remove srcChainId from RelayParams struct (continued)
dmax10 Feb 14, 2025
dc952cb
Move desChainId from multichain structs into RelayParams struct, remo…
dmax10 Feb 14, 2025
c43d5dd
Add srcChainId to depositHandler.createDeposit, small DepositUtils re…
dmax10 Feb 14, 2025
059a726
Add srcChainId to withdrawalHandler.createWithdrawal, small Withdrawa…
dmax10 Feb 14, 2025
2a02ee7
Add srcChainId to shiftHandler.createShift
dmax10 Feb 14, 2025
0aadaaf
Add srcChainId to glvHandler (createGlvDeposit, createGlvWithdrawal),…
dmax10 Feb 15, 2025
d72a86a
Add srcChainId to orderHandler.createOrder, small OrderUtils refactor…
dmax10 Feb 15, 2025
f3777d0
Remove srcChainId from non-multichain orders
dmax10 Feb 16, 2025
c148831
Add MultichainGmRouter: createOrder, updateOrder, cancelOrder
dmax10 Feb 16, 2025
2801fbc
Rename contract, remove comment, add modifier
dmax10 Feb 16, 2025
764f855
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 16, 2025
1d60d13
gassless merge fix
dmax10 Feb 16, 2025
149cb5c
Refactor: add function to validate destination chain
dmax10 Feb 16, 2025
2d9f8ad
Add bridgeOut function, validate multichain provider is whitelisted, …
dmax10 Feb 16, 2025
5ae76a0
wip provider bridgeOut
dmax10 Feb 16, 2025
8a7f026
Merge branch 'gasless' into multichain
dmax10 Feb 17, 2025
07e6c96
Fix gasless merge
dmax10 Feb 17, 2025
fb303a0
Add dataList field to relay create order params
dmax10 Feb 17, 2025
b848483
Fix signatures and missing fields for gasless tests
dmax10 Feb 17, 2025
6553e81
Include desChainId into relay signature
dmax10 Feb 17, 2025
0f4dca5
Validate desChainId against block.chainid (for same chain actions, ch…
dmax10 Feb 17, 2025
749a413
Include dataList into relay signature, remove srcChainId from multich…
dmax10 Feb 17, 2025
2b9883b
Add deploy script for MultichainGmRouter
dmax10 Feb 18, 2025
a7c8e43
Fix 'from' param for transferOut
dmax10 Feb 18, 2025
afca6e5
Fix multichain createDeposit typehash (without transferRequests)
dmax10 Feb 18, 2025
fdaa752
WIP test multichain createDeposit flow
dmax10 Feb 18, 2025
76260fe
change token permit nonce and srcChainId
dmax10 Feb 18, 2025
b4fd7ae
Add provider specific function param on bridgeOut
dmax10 Feb 19, 2025
957a63b
Fix multichain transferOut logic
dmax10 Feb 19, 2025
170376a
Remove double validation for desChainId
dmax10 Feb 19, 2025
15b0f4c
Change transferRequests structure, update typehashes
dmax10 Feb 19, 2025
81baa9f
Test multichain deposit
dmax10 Feb 19, 2025
c7d699d
Fix ETH deposit and fee payment
dmax10 Feb 20, 2025
3447978
Split CreateWithdrawalParams into subgroups to solve relay typehash e…
dmax10 Feb 20, 2025
082d847
Add error params
dmax10 Feb 20, 2025
b252c9f
WIP test multichain withdrawal
dmax10 Feb 20, 2025
0e839d0
squash - refactor callbacks to eventdata
Feb 21, 2025
45b28d4
Merge pull request #115 from gmx-io/refactor-callbacks-to-event-structs
xvi10 Feb 21, 2025
9b51da4
squash - refactor callbacks to eventdata
Feb 21, 2025
5bd23ed
Merge branch 'refactor-callbacks-to-event-structs' of github.com:gmx-…
Feb 21, 2025
d52370b
fix tests
Feb 21, 2025
6a7a5f9
Merge branch 'refactor-callbacks-to-event-structs' into multichain
Feb 21, 2025
4523ce7
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 22, 2025
583cbab
Fix tests after gasless merge
dmax10 Feb 22, 2025
9a7ca9f
test multichain withdrawal
dmax10 Feb 23, 2025
655b38f
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 24, 2025
f1645a5
Revert "immutable" to state variable.
dmax10 Feb 24, 2025
2434cac
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 24, 2025
f85b9f0
Split CreateShiftParams into subgroups to solve relay typehash error
dmax10 Feb 24, 2025
11d29f0
Add bridgeIn and move bridgeOut from MultichainOrderRouter into Multi…
dmax10 Feb 24, 2025
380d97d
Test multichain withdrawal (wip)
dmax10 Feb 24, 2025
b0405e5
Test multichain glv deposit, fix typehases, add deploy script
dmax10 Feb 24, 2025
cf9ca85
Add multichain handler contract
dmax10 Dec 4, 2024
700e926
Add multichain withdrawal
dmax10 Dec 5, 2024
ba123a0
Add multichain provider interface, multichain provider signature cont…
dmax10 Dec 8, 2024
4109821
Add multichain errors, small refactor
dmax10 Dec 8, 2024
7cd83bc
Simplify LayerZeroProvider contract (keep only lzCompose for now)
dmax10 Dec 9, 2024
8967503
Fix compilers error, add source chain balance key under the allowed b…
dmax10 Dec 10, 2024
d9c0ec1
Remove multichain controller role, use controller role for provider c…
dmax10 Dec 11, 2024
c7668c4
Add deploy scripts
dmax10 Dec 11, 2024
8dcc72a
Add multichain utils
dmax10 Dec 11, 2024
d6c1e3e
Store open position price impact on position open instead of charging…
dmax10 Dec 16, 2024
7fb2488
Keep the original event key since it is used for e.g. analytics
dmax10 Dec 17, 2024
f0a0c58
Remove comments
dmax10 Dec 17, 2024
1656a77
Track impact pending amount using a hash from account and market.
dmax10 Dec 17, 2024
2bf9d81
Remove combined key logic for storing the pending impact
dmax10 Dec 18, 2024
f523941
Use position store instead of the data store for storing/retrieving p…
dmax10 Dec 18, 2024
ece6a48
Remove blank lines
dmax10 Dec 20, 2024
eb4c624
Use balanceWasImproved instead of priceImpactUsd > 0 as forPositiveIm…
dmax10 Jan 12, 2025
f5b6e63
Use balanceWasImproved for crossover rebalance
dmax10 Jan 13, 2025
11fe64b
Update affiliate reward tests when balance was improved
dmax10 Jan 14, 2025
76d9e81
Update comments
dmax10 Jan 14, 2025
7af0f75
Add token address to OracleTimestampsAreSmallerThanRequired error
dmax10 Jan 13, 2025
92bcbb9
Revert "Add token address to OracleTimestampsAreSmallerThanRequired e…
dmax10 Jan 16, 2025
cdb6a71
Order.market should be validated for swap orders
dmax10 Jan 16, 2025
255da58
Revert "Order.market should be validated for swap orders"
dmax10 Jan 17, 2025
2101d4e
Add ConfigUtils lib and move logic from the Config to reduce the cont…
dmax10 Jan 22, 2025
57e8abc
Remove IConfigUtils interface and import ConfigUtils directly.
dmax10 Jan 23, 2025
3258480
Remove contructor param from Config
dmax10 Jan 23, 2025
d0b570a
WIP multichain
dmax10 Jan 27, 2025
14de976
Add support for bytes type in DataStore (bytesValues, getBytes, setBy…
dmax10 Jan 21, 2025
62bfd6a
WIP add data field for deposits, orders, withdrawals, shifts etc
dmax10 Jan 21, 2025
1e5ef9f
Revert changes for the DataStore
dmax10 Jan 22, 2025
11e0d03
Replace bytes data field with bytes32[] dataList
dmax10 Jan 22, 2025
4c60ef7
Fix tests: default dataList to empty array
dmax10 Jan 22, 2025
6a45be0
Fix tests: increase expectedPropsLength by one for the structs where …
dmax10 Jan 22, 2025
7e7f483
Add data length validation
dmax10 Jan 23, 2025
84a58cb
Add dataList to Orders
dmax10 Jan 23, 2025
e178969
Revert "Refactor ExchangeRouter to reduce it's size"
dmax10 Jan 23, 2025
6d53986
Comments update
dmax10 Jan 24, 2025
099931c
Revert dataList for GlvShift
dmax10 Jan 24, 2025
d3237b5
Remove dataList from ADL orders
dmax10 Jan 27, 2025
ff05d57
WIP Allow setting a CLAIMABLE_COLLATERAL_REDUCTION_FACTOR for (accoun…
dmax10 Jan 22, 2025
34b0631
Move claimable reduction method from ConfigSyncer to Config
dmax10 Jan 22, 2025
fd6411c
Move setClaimableCollateralReductionFactorForAccount logic from Confi…
dmax10 Jan 23, 2025
9b4ba55
Refactor GlvDepositUtils to reduce bytecode size
dmax10 Jan 28, 2025
ed2082a
Rename glv deposit utility lib
dmax10 Jan 31, 2025
782aaae
Rename deploy script
dmax10 Jan 31, 2025
fbd41c6
Rename MultichainHandler in MultichainVaultHandler
dmax10 Feb 1, 2025
59e9489
Add chainId to Deposit.Props
dmax10 Feb 1, 2025
a3006f2
Update multichain createDeposit logic
dmax10 Feb 1, 2025
81be37c
Emit dataList for createDeposit, createWithdrawal, createOrder, updat…
dmax10 Feb 2, 2025
ee08b27
Rename sourceChain* to multichain*
dmax10 Feb 3, 2025
b6ff3e4
Add multichain increase and decrease utils methods
dmax10 Feb 3, 2025
0bd9d83
Set chainId for Deposit on executeShift, remove position chainId rela…
dmax10 Feb 4, 2025
81699fd
WIP multichain deposits and gm logic
dmax10 Feb 4, 2025
57a8b3e
Update multichain logic for fee payment
dmax10 Feb 5, 2025
c0ed26a
Remove chainId from multichain balance
dmax10 Feb 5, 2025
f2f927c
Add in and out multichain transfers methods to MultichainUtils lib. R…
dmax10 Feb 7, 2025
f811669
Split CreateDepositParams into subgroups
dmax10 Feb 8, 2025
39c146e
Add srcChainId to orders
dmax10 Feb 9, 2025
b1bcadd
Rename multichainId to srcChainId, remove second topic log
dmax10 Feb 10, 2025
b701ce8
Add srcChiainId field to CreateOrderParams struct
dmax10 Feb 10, 2025
f85d942
Add TransferRequest[] param to create* multichain actions and _sendTo…
dmax10 Feb 13, 2025
b2e457d
Remove outdated contracts
dmax10 Feb 14, 2025
4748b13
Add srcChainId to depositHandler.createDeposit, small DepositUtils re…
dmax10 Feb 14, 2025
5b6dc11
Add srcChainId to withdrawalHandler.createWithdrawal, small Withdrawa…
dmax10 Feb 14, 2025
edd7333
Add srcChainId to shiftHandler.createShift
dmax10 Feb 14, 2025
830f300
Add srcChainId to orderHandler.createOrder, small OrderUtils refactor…
dmax10 Feb 15, 2025
9362087
Rename contract, remove comment, add modifier
dmax10 Feb 16, 2025
deaac54
Refactor: add function to validate destination chain
dmax10 Feb 16, 2025
20bd13c
Fix gasless merge
dmax10 Feb 17, 2025
dea3c67
Validate desChainId against block.chainid (for same chain actions, ch…
dmax10 Feb 17, 2025
eb03f91
Remove double validation for desChainId
dmax10 Feb 19, 2025
22768d8
Change transferRequests structure, update typehashes
dmax10 Feb 19, 2025
b4bde60
Fix ETH deposit and fee payment
dmax10 Feb 20, 2025
3c3bd58
squash - refactor callbacks to eventdata
Feb 21, 2025
d2aa689
add timelockconfigcontroller
Feb 21, 2025
1c9031c
timelock controller
Feb 24, 2025
305759f
pr fix
Feb 11, 2025
ae79681
pr fix
Feb 11, 2025
1d0362f
set default maxPnlFactorForTraders for VIRTUAL and PENGU markets
gmxer Feb 13, 2025
0f21eda
upd maxPnlFactorForTraders for new markets
gmxer Feb 13, 2025
f321509
rebase
Feb 25, 2025
6c510fe
Test multichain glv withdrawal
dmax10 Feb 25, 2025
4cfccce
Fix refund fee. Skip updating user's multichain balance if the refund…
dmax10 Feb 25, 2025
6bc996e
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 26, 2025
fdfb6b7
Fix params order for gasless _createOrder
dmax10 Feb 26, 2025
4e3652b
Merge branch 'v2.2-branch' into multichain
dmax10 Feb 26, 2025
f6aa776
Add multichain support to orders
dmax10 Feb 26, 2025
4509a69
Add script to deployMultichainOrderRouter
dmax10 Feb 27, 2025
5d7e6d4
Fix fee refund error to non initialised multichain vault
dmax10 Feb 27, 2025
a6300af
Test create multichain order
dmax10 Feb 27, 2025
64e4683
Test update multichain order
dmax10 Feb 27, 2025
c86c297
Test cancel multichain order
dmax10 Feb 27, 2025
fe4ed43
Add back "immutable" which was temporarily added to reduce contract s…
dmax10 Feb 27, 2025
b64484e
fix tests
Feb 28, 2025
5a345db
Inherit BaseGelatoRelayRouter instead of GelatoRelayRouter into Multi…
dmax10 Feb 28, 2025
12c7f76
Handle partial fee payment for multichain update/cancel orders
dmax10 Feb 28, 2025
0759a69
Inherit BaseRouter into MultichainTransferRouter for multicall functi…
dmax10 Feb 28, 2025
dc6ed96
Set HOLDING_ADDRESS as the refundReceiverAddress if position collater…
dmax10 Mar 1, 2025
dcc577d
Emit PositionCollateralUsedForExecutionFee event
dmax10 Mar 1, 2025
ba591f0
Update multichain events, validate gasless feature for all multichain…
dmax10 Mar 1, 2025
c6f0225
Check keeper fee on multichain deposit
dmax10 Mar 2, 2025
0ef8f0b
Install @stargatefinance/stg-evm-v2
dmax10 Mar 2, 2025
90d5370
Enable multichain bridging out, add deploy script and test setup, oth…
dmax10 Mar 2, 2025
9318680
Rename multichain test file
dmax10 Mar 2, 2025
5aedb23
auto format
dmax10 Mar 2, 2025
651555c
update scripts
Mar 2, 2025
945575e
Merge branch 'multichain' into timelock-refactor
Mar 3, 2025
67afac2
update CI node version
Mar 3, 2025
fb9e5e0
Merge pull request #117 from gmx-io/timelock-refactor
xvi10 Mar 3, 2025
64b62e5
Fix multichain shift (the withdawal part should go into the shiftVaul…
dmax10 Mar 3, 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
5 changes: 4 additions & 1 deletion contracts/config/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ contract Config is ReentrancyGuard, RoleModule, BasicMulticall {

allowedBaseKeys[Keys.DATA_STREAM_SPREAD_REDUCTION_FACTOR] = true;

allowedBaseKeys[Keys.SOURCE_CHAIN_BALANCE] = true;
allowedBaseKeys[Keys.MULTICHAIN_BALANCE] = true;

allowedBaseKeys[Keys.MAX_DATA_LENGTH] = true;

Expand All @@ -540,6 +540,9 @@ contract Config is ReentrancyGuard, RoleModule, BasicMulticall {
allowedLimitedBaseKeys[Keys.MAX_POOL_USD_FOR_DEPOSIT] = true;
allowedLimitedBaseKeys[Keys.MAX_OPEN_INTEREST] = true;

allowedLimitedBaseKeys[Keys.GLV_MAX_MARKET_TOKEN_BALANCE_USD] = true;
allowedLimitedBaseKeys[Keys.GLV_MAX_MARKET_TOKEN_BALANCE_AMOUNT] = true;

allowedLimitedBaseKeys[Keys.PRO_TRADER_TIER] = true;
}

Expand Down
28 changes: 20 additions & 8 deletions contracts/data/Keys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ library Keys {
bytes32 public constant AFFILIATE_REWARD = keccak256(abi.encode("AFFILIATE_REWARD"));
// @dev key for max allowed subaccount action count
bytes32 public constant MAX_ALLOWED_SUBACCOUNT_ACTION_COUNT = keccak256(abi.encode("MAX_ALLOWED_SUBACCOUNT_ACTION_COUNT"));
bytes32 public constant SUBACCOUNT_EXPIRES_AT = keccak256(abi.encode("SUBACCOUNT_EXPIRES_AT"));
// @dev key for subaccount action count
bytes32 public constant SUBACCOUNT_ACTION_COUNT = keccak256(abi.encode("SUBACCOUNT_ACTION_COUNT"));
// @dev key for subaccount auto top up amount
Expand Down Expand Up @@ -470,8 +471,8 @@ library Keys {
// @dev key for the buyback withdrawable fees
bytes32 public constant WITHDRAWABLE_BUYBACK_TOKEN_AMOUNT = keccak256(abi.encode("WITHDRAWABLE_BUYBACK_TOKEN_AMOUNT"));

// @dev key for user's balance for a source chain, recorded under the user's virtual account
bytes32 public constant SOURCE_CHAIN_BALANCE = keccak256(abi.encode("SOURCE_CHAIN_BALANCE"));
// @dev key for user's multichain balance
bytes32 public constant MULTICHAIN_BALANCE = keccak256(abi.encode("MULTICHAIN_BALANCE"));

// @dev key for the maximum length for data list array of bytes32
bytes32 public constant MAX_DATA_LENGTH = keccak256(abi.encode("MAX_DATA_LENGTH"));
Expand Down Expand Up @@ -1779,6 +1780,15 @@ library Keys {
));
}

function subaccountExpiresAtKey(address account, address subaccount, bytes32 actionType) internal pure returns (bytes32) {
return keccak256(abi.encode(
SUBACCOUNT_EXPIRES_AT,
account,
subaccount,
actionType
));
}

function subaccountActionCountKey(address account, address subaccount, bytes32 actionType) internal pure returns (bytes32) {
return keccak256(abi.encode(
SUBACCOUNT_ACTION_COUNT,
Expand Down Expand Up @@ -2110,14 +2120,16 @@ library Keys {
));
}

// @dev key for user's balance for a source chain, recorded under the user's virtual account
// @param virtualAccount the virtual account for which to retreive the user balance key
// @dev key for user's multichain balance
// @param chainId the chain id for the destination chain
// @param account the account for which to retreive the user balance key
// @param token the token for which to retreive the user balance key
// @return key for a source chain balance for a given user and token
function sourceChainBalanceKey(address virtualAccount, address token) internal pure returns (bytes32) {
// @return key for multichain balance for a given user and token
function multichainBalanceKey(uint256 chainId, address account, address token) internal pure returns (bytes32) {
return keccak256(abi.encode(
SOURCE_CHAIN_BALANCE,
virtualAccount,
MULTICHAIN_BALANCE,
chainId,
account,
token
));
}
Expand Down
9 changes: 9 additions & 0 deletions contracts/deposit/Deposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ library Deposit {
uint256 updatedAtTime;
uint256 executionFee;
uint256 callbackGasLimit;
uint256 chainId;
}

// @param shouldUnwrapNativeToken whether to unwrap the native token when
Expand Down Expand Up @@ -181,6 +182,14 @@ library Deposit {
props.numbers.callbackGasLimit = value;
}

function chainId(Props memory props) internal pure returns (uint256) {
return props.numbers.chainId;
}

function setChainId(Props memory props, uint256 value) internal pure {
props.numbers.chainId = value;
}

function shouldUnwrapNativeToken(Props memory props) internal pure returns (bool) {
return props.flags.shouldUnwrapNativeToken;
}
Expand Down
7 changes: 6 additions & 1 deletion contracts/deposit/DepositEventUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,25 @@ library DepositEventUtils {
eventData.addressItems.setItem(0, "longTokenSwapPath", deposit.longTokenSwapPath());
eventData.addressItems.setItem(1, "shortTokenSwapPath", deposit.shortTokenSwapPath());

eventData.uintItems.initItems(7);
eventData.uintItems.initItems(8);
eventData.uintItems.setItem(0, "initialLongTokenAmount", deposit.initialLongTokenAmount());
eventData.uintItems.setItem(1, "initialShortTokenAmount", deposit.initialShortTokenAmount());
eventData.uintItems.setItem(2, "minMarketTokens", deposit.minMarketTokens());
eventData.uintItems.setItem(3, "updatedAtTime", deposit.updatedAtTime());
eventData.uintItems.setItem(4, "executionFee", deposit.executionFee());
eventData.uintItems.setItem(5, "callbackGasLimit", deposit.callbackGasLimit());
eventData.uintItems.setItem(6, "depositType", uint256(depositType));
eventData.uintItems.setItem(7, "chainId", deposit.chainId());

eventData.boolItems.initItems(1);
eventData.boolItems.setItem(0, "shouldUnwrapNativeToken", deposit.shouldUnwrapNativeToken());

eventData.bytes32Items.initItems(1);
eventData.bytes32Items.setItem(0, "key", key);

eventData.bytes32Items.initArrayItems(1);
eventData.bytes32Items.setItem(0, "dataList", deposit.dataList());

eventEmitter.emitEventLog2(
"DepositCreated",
key,
Expand All @@ -67,6 +71,7 @@ library DepositEventUtils {
function emitDepositExecuted(
EventEmitter eventEmitter,
bytes32 key,
// uint256 chainId, TODO: should chainId be added as param? Is it ok to change the event signature (for e.g. analytics)
address account,
uint256 longTokenAmount,
uint256 shortTokenAmount,
Expand Down
14 changes: 14 additions & 0 deletions contracts/deposit/DepositStoreUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library DepositStoreUtils {
bytes32 public constant UPDATED_AT_TIME = keccak256(abi.encode("UPDATED_AT_TIME"));
bytes32 public constant EXECUTION_FEE = keccak256(abi.encode("EXECUTION_FEE"));
bytes32 public constant CALLBACK_GAS_LIMIT = keccak256(abi.encode("CALLBACK_GAS_LIMIT"));
bytes32 public constant CHAIN_ID = keccak256(abi.encode("CHAIN_ID"));

bytes32 public constant SHOULD_UNWRAP_NATIVE_TOKEN = keccak256(abi.encode("SHOULD_UNWRAP_NATIVE_TOKEN"));

Expand Down Expand Up @@ -101,6 +102,10 @@ library DepositStoreUtils {
keccak256(abi.encode(key, CALLBACK_GAS_LIMIT))
));

deposit.setChainId(dataStore.getUint(
keccak256(abi.encode(key, CHAIN_ID))
));

deposit.setShouldUnwrapNativeToken(dataStore.getBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN))
));
Expand Down Expand Up @@ -198,6 +203,11 @@ library DepositStoreUtils {
deposit.callbackGasLimit()
);

dataStore.setUint(
keccak256(abi.encode(key, CHAIN_ID)),
deposit.chainId()
);

dataStore.setBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN)),
deposit.shouldUnwrapNativeToken()
Expand Down Expand Up @@ -284,6 +294,10 @@ library DepositStoreUtils {
keccak256(abi.encode(key, CALLBACK_GAS_LIMIT))
);

dataStore.removeUint(
keccak256(abi.encode(key, CHAIN_ID))
);

dataStore.removeBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN))
);
Expand Down
4 changes: 3 additions & 1 deletion contracts/deposit/DepositUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ library DepositUtils {
bool shouldUnwrapNativeToken;
uint256 executionFee;
uint256 callbackGasLimit;
uint256 chainId;
bytes32[] dataList;
}

Expand Down Expand Up @@ -117,7 +118,8 @@ library DepositUtils {
params.minMarketTokens,
Chain.currentTimestamp(), // updatedAtTime
params.executionFee,
params.callbackGasLimit
params.callbackGasLimit,
params.chainId
),
Deposit.Flags(
params.shouldUnwrapNativeToken
Expand Down
23 changes: 22 additions & 1 deletion contracts/error/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ library Errors {
// Oracle errors
error SequencerDown();
error SequencerGraceDurationNotYetPassed(uint256 timeSinceUp, uint256 sequencerGraceDuration);
error EmptyValidatedPrices();
error EmptyValidatedPrices(); // not used, kept for compatibility
error InvalidOracleProvider(address provider);
error InvalidOracleProviderForToken(address provider, address expectedProvider);
error GmEmptySigner(uint256 signerIndex);
Expand Down Expand Up @@ -358,10 +358,12 @@ library Errors {

// SubaccountRouter errors
error InvalidReceiverForSubaccountOrder(address receiver, address expectedReceiver);
error InvalidCancellationReceiverForSubaccountOrder(address cancellationReceiver, address expectedCancellationReceiver);

// SubaccountUtils errors
error SubaccountNotAuthorized(address account, address subaccount);
error MaxSubaccountActionCountExceeded(address account, address subaccount, uint256 count, uint256 maxCount);
error SubaccountApprovalExpired(address account, address subaccount, uint256 deadline, uint256 currentTimestamp);

// TokenUtils errors
error TokenTransferError(address token, address receiver, uint256 amount);
Expand Down Expand Up @@ -433,4 +435,23 @@ library Errors {
error InvalidMultichainProviderSignature();
error InvalidStargatePool();
error InvalidLzEndpoint();

enum SignatureType {
Call,
SubaccountApproval
}

// Gelato relay errors
error InvalidSignature(string signatureType);
// User sent incorrect fee token or incorrect swap path
error UnexpectedRelayFeeTokenAfterSwap(address feeToken, address expectedFeeToken);
// Contract received unsupported fee token from Gelato relay
error UnsupportedRelayFeeToken(address feeToken, address expectedFeeToken);
error InvalidPermitSpender(address spender, address expectedSpender);
error InvalidUserNonce(uint256 storedUserNonce, uint256 userNonce);
error SubaccountApprovalDeadlinePassed(uint256 currentTimestamp, uint256 deadline);
error InvalidSubaccountApprovalNonce(uint256 storedNonce, uint256 nonce);
error DeadlinePassed(uint256 currentTimestamp, uint256 deadline);
error InsufficientRelayFee(uint256 requiredRelayFee, uint256 feeAmount);
error InvalidSubaccountApprovalSubaccount();
}
3 changes: 2 additions & 1 deletion contracts/exchange/DepositHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ contract DepositHandler is IDepositHandler, BaseHandler {
keeper,
startingGas,
ISwapPricingUtils.SwapPricingType.Deposit,
true // includeVirtualInventoryImpact
true, // includeVirtualInventoryImpact
deposit.chainId()
);

ExecuteDepositUtils.executeDeposit(params, deposit);
Expand Down
9 changes: 9 additions & 0 deletions contracts/glv/glvDeposit/GlvDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ library GlvDeposit {
uint256 updatedAtTime;
uint256 executionFee;
uint256 callbackGasLimit;
uint256 chainId;
}

// @param shouldUnwrapNativeToken whether to unwrap the native token when
Expand Down Expand Up @@ -198,6 +199,14 @@ library GlvDeposit {
props.numbers.callbackGasLimit = value;
}

function chainId(Props memory props) internal pure returns (uint256) {
return props.numbers.chainId;
}

function setChainId(Props memory props, uint256 value) internal pure {
props.numbers.chainId = value;
}

function shouldUnwrapNativeToken(Props memory props) internal pure returns (bool) {
return props.flags.shouldUnwrapNativeToken;
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/glv/glvDeposit/GlvDepositEventUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ library GlvDepositEventUtils {
eventData.bytes32Items.initItems(1);
eventData.bytes32Items.setItem(0, "key", key);

eventData.bytes32Items.initArrayItems(1);
eventData.bytes32Items.setItem(0, "dataList", glvDeposit.dataList());

eventEmitter.emitEventLog2(
"GlvDepositCreated",
key,
Expand Down
15 changes: 15 additions & 0 deletions contracts/glv/glvDeposit/GlvDepositStoreUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ library GlvDepositStoreUtils {

bytes32 public constant DATA_LIST = keccak256(abi.encode("DATA_LIST"));

bytes32 public constant CHAIN_ID = keccak256(abi.encode("CHAIN_ID"));

function get(DataStore dataStore, bytes32 key) external view returns (GlvDeposit.Props memory) {
GlvDeposit.Props memory glvDeposit;
if (!dataStore.containsBytes32(Keys.GLV_DEPOSIT_LIST, key)) {
Expand Down Expand Up @@ -112,6 +114,10 @@ library GlvDepositStoreUtils {
keccak256(abi.encode(key, CALLBACK_GAS_LIMIT))
));

glvDeposit.setChainId(dataStore.getUint(
keccak256(abi.encode(key, CHAIN_ID))
));

glvDeposit.setShouldUnwrapNativeToken(dataStore.getBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN))
));
Expand Down Expand Up @@ -223,6 +229,11 @@ library GlvDepositStoreUtils {
glvDeposit.callbackGasLimit()
);

dataStore.setUint(
keccak256(abi.encode(key, CHAIN_ID)),
glvDeposit.chainId()
);

dataStore.setBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN)),
glvDeposit.shouldUnwrapNativeToken()
Expand Down Expand Up @@ -322,6 +333,10 @@ library GlvDepositStoreUtils {
keccak256(abi.encode(key, CALLBACK_GAS_LIMIT))
);

dataStore.removeUint(
keccak256(abi.encode(key, CHAIN_ID))
);

dataStore.removeBool(
keccak256(abi.encode(key, SHOULD_UNWRAP_NATIVE_TOKEN))
);
Expand Down
10 changes: 7 additions & 3 deletions contracts/glv/glvDeposit/GlvDepositUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ library GlvDepositUtils {
uint256 minGlvTokens;
uint256 executionFee;
uint256 callbackGasLimit;
uint256 chainId;
bool shouldUnwrapNativeToken;
bool isMarketTokenDeposit;
bytes32[] dataList;
Expand Down Expand Up @@ -177,7 +178,8 @@ library GlvDepositUtils {
minGlvTokens: params.minGlvTokens,
updatedAtTime: Chain.currentTimestamp(),
executionFee: params.executionFee,
callbackGasLimit: params.callbackGasLimit
callbackGasLimit: params.callbackGasLimit,
chainId: params.chainId
}),
GlvDeposit.Flags({
shouldUnwrapNativeToken: params.shouldUnwrapNativeToken,
Expand Down Expand Up @@ -354,7 +356,8 @@ library GlvDepositUtils {
minMarketTokens: 0,
updatedAtTime: glvDeposit.updatedAtTime(),
executionFee: 0,
callbackGasLimit: 0
callbackGasLimit: 0,
chainId: 0
}),
Deposit.Flags({shouldUnwrapNativeToken: false}),
new bytes32[](0) // dataList
Expand All @@ -373,7 +376,8 @@ library GlvDepositUtils {
params.keeper,
params.startingGas,
ISwapPricingUtils.SwapPricingType.Deposit,
true // includeVirtualInventoryImpact
true, // includeVirtualInventoryImpact
glvDeposit.chainId()
);

uint256 receivedMarketTokens = ExecuteDepositUtils.executeDeposit(executeDepositParams, deposit);
Expand Down
3 changes: 2 additions & 1 deletion contracts/glv/glvShift/GlvShiftUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ library GlvShiftUtils {
marketTokenAmount: glvShift.marketTokenAmount(),
updatedAtTime: glvShift.updatedAtTime(),
executionFee: 0,
callbackGasLimit: 0
callbackGasLimit: 0,
chainId: 0 // TODO: should glvShift have the chainId as well?
}),
new bytes32[](0)
);
Expand Down
9 changes: 9 additions & 0 deletions contracts/glv/glvWithdrawal/GlvWithdrawal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ library GlvWithdrawal {
uint256 updatedAtTime;
uint256 executionFee;
uint256 callbackGasLimit;
uint256 chainId;
}

// @param shouldUnwrapNativeToken whether to unwrap the native token when
Expand Down Expand Up @@ -168,6 +169,14 @@ library GlvWithdrawal {
props.numbers.callbackGasLimit = value;
}

function chainId(Props memory props) internal pure returns (uint256) {
return props.numbers.chainId;
}

function setChainId(Props memory props, uint256 value) internal pure {
props.numbers.chainId = value;
}

function shouldUnwrapNativeToken(Props memory props) internal pure returns (bool) {
return props.flags.shouldUnwrapNativeToken;
}
Expand Down
Loading