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 136 commits into
base: v2.2-branch
Choose a base branch
from
Open

Multichain #105

wants to merge 136 commits into from

Conversation

xvi10
Copy link
Contributor

@xvi10 xvi10 commented Jan 27, 2025

No description provided.

# Conflicts:
#	contracts/error/Errors.sol
@xvi10 xvi10 changed the base branch from main to v2.2-branch January 27, 2025 07:43
@dmax10 dmax10 changed the base branch from v2.2-branch to gasless January 28, 2025 16:42
@dmax10 dmax10 changed the base branch from gasless to v2.2-branch January 28, 2025 16:42
@dmax10 dmax10 force-pushed the multichain branch 2 times, most recently from 70dba6c to 6f03e4f Compare January 29, 2025 20:48
// TODO: confirm virtual account is used correctly
address virtualAccount = MultichainUtils.getVirtualAccount(account, sourceChainId);

return _createDeposit(relayParams.tokenPermits, relayParams.fee, params, virtualAccount);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use _createDeposit(..., account, chainId) here instead of virtualAccount

the GM tokens should be sent to MultichainVault and the account's multichain GM balance should be increased

so would need a deposit.chainId as well

in execute deposit, if the deposit.chainId is "0" this means that the deposit would be a normal deposit, so the GM tokens would be sent directly to the user, if the deposit.chainId is not zero, then the user's multichain GM balance should be increased

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Named it srcChainId though.

eventEmitter: eventEmitter,
// TODO: confirm Contracts struct can be modified --> replace `OrderVault orderVault;` field with `StrictBank vault;`
// otherwise, should probably overridde _handleRelay
orderVault: OrderVault(payable(multichainVault))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdev8317 is it ok for Max to change Contracts { OrderVault orderVault } into Contracts { StrictBank bank }?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it.


// TODO: confirm where funds are bridged. Are they sent to this contract, to MultichainProvider, or directly to MultichainVault?
// if funds are sent directly to MultichainVault, _sendTokens would not be needed, but then where is the relay fee being paid from?
_sendTokens(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funds should be bridged to MultichainVault directly

if funds are sent directly to MultichainVault, _sendTokens would not be needed

I don't quite understand this, to create a deposit, the tokens would still need to be sent from MultichainVault to DepositVault?

then where is the relay fee being paid from?

relay fee should be sent from MultichainVault, from the user's multichain balance

residual fees should be sent to the deposit vault

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this, to create a deposit, the tokens would still need to be sent from MultichainVault to DepositVault?

I thought so. DepositUtils.createDeposit does a recordTransferIn, which assumes tokens have already been transferred to DepositVault

@@ -7,6 +7,6 @@ pragma solidity ^0.8.0;
*/
library MultichainUtils {
function getVirtualAccount(address account, uint256 sourceChainId) internal pure returns (address) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove this function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

import "./MultichainUtils.sol";

contract MultichainRouter is GelatoRelayRouter {
struct GaslessCreateDepositParams {
Copy link
Collaborator

@gdev8317 gdev8317 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would suggest to call it MulticallCreateDepositParams (and use multichain instead of gasless in otehr names) because GelatoRelayRouter is also gasless

Copy link
Collaborator

@gdev8317 gdev8317 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe chainId, longTokenAmount and shortTokenAmount can be passed as a separate arguments and remove the extra nesting? just thinking, at first glance it could simplify the contract interface

Copy link
Collaborator

@dmax10 dmax10 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to:

struct MultichainCreateDepositParams {
        uint256 desChainId;
        uint256 longTokenAmount;
        uint256 shortTokenAmount;
        DepositUtils.CreateDepositParams createDepositParams;
    }

and replaced gasless with multichain as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't change the nesting yet, but could do that as well if needed.

tokenPermits,
fee,
account,
NonceUtils.getKey(contracts.dataStore, NonceUtils.getCurrentNonce(dataStore) + 1), // calculate next key without incrementing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be the same as NonceUtils.getNextKey(dataStore)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, same logic, the difference is that getNextKey also writes the incremented value (it is named "get" but it does "set" as well).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, not ideal naming, would be good to change it sometime

function getVirtualAccount(address account, uint256 sourceChainId) internal pure returns (address) {
return address(uint160(uint256(keccak256(abi.encode("GMX Multichain", account, sourceChainId)))));
function increaseBalance(DataStore dataStore, uint256 chainId, address account, address token, uint256 amount) internal {
dataStore.decrementUint(Keys.multichainBalanceKey(chainId, account, token), amount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it should be incrementUint instead of decrementUint

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it.

Contracts memory contracts = Contracts({
dataStore: dataStore,
eventEmitter: eventEmitter,
// TODO: confirm Contracts struct can be modified --> replace `OrderVault orderVault;` field with `StrictBank vault;`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's okay to change type to StrictBank, yes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it.

Solar and others added 30 commits February 21, 2025 13:32
It was removed as a temporary fix to reduce the contract size and it's not needed anymore. Different refactoring was implemented
…onality

It's actually inherited into BaseGelatoRelayRouter instead of MultichainTransferRouter due to inheritance structure.
Since SubaccountGelatoRelayRouter was getting too big, some of it's logic is moved into a new external lib SubaccountRelayUtils
…al was used to pay the execution fee, small refactor to solve stack too deep error in OrderUtils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants