Skip to content

Commit 98a6a1b

Browse files
committed
[WIP] Add bridge logic
1 parent 71dddb9 commit 98a6a1b

1 file changed

Lines changed: 40 additions & 12 deletions

File tree

src/superToken/SuperTokenAppGateway.sol

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import "socket-protocol/contracts/base/AppGatewayBase.sol";
5+
import "socket-protocol/contracts/interfaces/IForwarder.sol";
56
import "solady/auth/Ownable.sol";
67
import {ISuperToken} from "./ISuperToken.sol";
78

@@ -34,8 +35,10 @@ contract SuperTokenApp is AppGatewayBase, Ownable {
3435
address srcToken;
3536
/// @notice Destination token contract address
3637
address dstToken;
37-
/// @notice User initiating the bridge transaction
38-
address user;
38+
/// @notice User initiating the transaction
39+
address srcUser;
40+
/// @notice User receiving the funds
41+
address dstUser;
3942
/// @notice Amount of tokens to be bridged from source chain
4043
uint256 srcAmount;
4144
/// @notice Deadline for the bridge transaction
@@ -102,16 +105,41 @@ contract SuperTokenApp is AppGatewayBase, Ownable {
102105
) external async returns (bytes32 asyncId) {
103106
UserOrder memory order = abi.decode(_order, (UserOrder));
104107
asyncId = _getCurrentAsyncId();
105-
/* TODO:
106-
1. Check user balance on src chain
107-
2. Check if it was a already deployed contract
108-
if original contract,
109-
transferFrom user to Vault
110-
mint to user on dst chain
111-
if supertoken,
112-
burn from user
113-
transferFrom Vault to user
114-
*/
108+
// Check user balance on src chain
109+
_readCallOn();
110+
// Request to forwarder and deploys immutable promise contract and stores it
111+
ISuperToken(order.srcToken).balanceOf(order.srcUser);
112+
IPromise(order.srcToken).then(
113+
this.checkBalance.selector,
114+
abi.encode(order, asyncId)
115+
);
116+
117+
_readCallOff();
118+
119+
// if same-chain transfer
120+
if (order.srcToken == order.dstToken) {
121+
ISuperToken(order.srcToken).transferFrom(
122+
order.srcUser,
123+
order.dstUser,
124+
order.srcAmount
125+
);
126+
} else {
127+
// | src \ dst | baseChain | other |
128+
// |------------|------------|------------|
129+
// | baseChain | transfer | Vault/mint |
130+
// | other | burn/Vault | burn/mint |
131+
if (IForwarder(order.srcToken).getChainSlug() == baseChainSlug) {
132+
// Vault and mint
133+
// TODO: Figure out how to get the Vault address
134+
} else if (
135+
IForwarder(order.dstToken).getChainSlug() == baseChainSlug
136+
) {
137+
// burn and Vault
138+
// TODO: Figure out how to get the Vault address
139+
} else {
140+
// burn and mint
141+
}
142+
}
115143

116144
emit Bridged(asyncId);
117145
}

0 commit comments

Comments
 (0)