|
2 | 2 | pragma solidity ^0.8.13; |
3 | 3 |
|
4 | 4 | import "socket-protocol/contracts/base/AppGatewayBase.sol"; |
| 5 | +import "socket-protocol/contracts/interfaces/IForwarder.sol"; |
5 | 6 | import "solady/auth/Ownable.sol"; |
6 | 7 | import {ISuperToken} from "./ISuperToken.sol"; |
7 | 8 |
|
@@ -34,8 +35,10 @@ contract SuperTokenApp is AppGatewayBase, Ownable { |
34 | 35 | address srcToken; |
35 | 36 | /// @notice Destination token contract address |
36 | 37 | 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; |
39 | 42 | /// @notice Amount of tokens to be bridged from source chain |
40 | 43 | uint256 srcAmount; |
41 | 44 | /// @notice Deadline for the bridge transaction |
@@ -102,16 +105,41 @@ contract SuperTokenApp is AppGatewayBase, Ownable { |
102 | 105 | ) external async returns (bytes32 asyncId) { |
103 | 106 | UserOrder memory order = abi.decode(_order, (UserOrder)); |
104 | 107 | 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 | + } |
115 | 143 |
|
116 | 144 | emit Bridged(asyncId); |
117 | 145 | } |
|
0 commit comments