mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
removed getID + code refactored
This commit is contained in:
parent
b74a8e8b8f
commit
5e7916d0f2
|
@ -12,7 +12,25 @@ import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
import "./events.sol";
|
import "./events.sol";
|
||||||
import "./interface.sol";
|
import "./interface.sol";
|
||||||
|
|
||||||
abstract contract SocketConnectorResolver {
|
abstract contract SocketConnectorBridge is Basic {
|
||||||
|
|
||||||
|
address constant registry = 0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev socket API bridge handler
|
||||||
|
* @param _txData - contains data returned from socket build-tx API. Struct defined in interfaces.sol
|
||||||
|
* @param _ethAmt - Eth to bridge for .value()
|
||||||
|
*/
|
||||||
|
function socketBridge(
|
||||||
|
bytes memory _txData,
|
||||||
|
uint _ethAmt
|
||||||
|
) internal returns (bool _success) {
|
||||||
|
(_success, ) = registry.call{value: _ethAmt}(_txData);
|
||||||
|
require(_success, "Socket-swap-failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract contract SocketConnectorResolver is SocketConnectorBridge {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Gets Allowance target from registry.
|
* @dev Gets Allowance target from registry.
|
||||||
|
@ -25,15 +43,7 @@ abstract contract SocketConnectorResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract contract SocketConnector is SocketConnectorResolver, Basic {
|
abstract contract SocketConnector is SocketConnectorResolver {
|
||||||
|
|
||||||
address constant registry = 0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0;
|
|
||||||
|
|
||||||
struct BridgeParams {
|
|
||||||
bytes txData;
|
|
||||||
address token;
|
|
||||||
uint256 amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Bridge Token.
|
* @dev Bridge Token.
|
||||||
|
@ -42,44 +52,40 @@ abstract contract SocketConnector is SocketConnectorResolver, Basic {
|
||||||
* @param _txData tx data for calling
|
* @param _txData tx data for calling
|
||||||
* @param _route route number
|
* @param _route route number
|
||||||
* @param _amount amount to bridge
|
* @param _amount amount to bridge
|
||||||
* @param _getId ID to retrieve amount from last spell.
|
* @param _sourceChain Source chain id
|
||||||
|
* @param _targetChain Source chain id
|
||||||
|
* @param _recipient address of recipient
|
||||||
*/
|
*/
|
||||||
function bridge (
|
function bridge (
|
||||||
address _token,
|
address _token,
|
||||||
bytes memory _txData,
|
bytes memory _txData,
|
||||||
uint256 _route,
|
uint256 _route,
|
||||||
uint256 _amount,
|
uint256 _amount,
|
||||||
uint256 _getId
|
uint256 _sourceChain,
|
||||||
|
uint256 _targetChain,
|
||||||
|
address _recipient
|
||||||
)
|
)
|
||||||
external payable returns (string memory _eventName, bytes memory _eventParam)
|
external payable returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
_amount = getUint(_getId, _amount);
|
uint _ethAmt;
|
||||||
|
|
||||||
if(_token == ethAddr) {
|
if(_token == ethAddr) {
|
||||||
_amount = _amount == uint256(-1)
|
_ethAmt = _amount;
|
||||||
? address(this).balance
|
|
||||||
: _amount;
|
|
||||||
|
|
||||||
(bool success, ) = registry.call{value: _amount}(_txData);
|
|
||||||
require(success, "Socket-swap-failed");
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
TokenInterface _tokenContract = TokenInterface(_token);
|
TokenInterface _tokenContract = TokenInterface(_token);
|
||||||
_amount = _amount == uint256(-1)
|
|
||||||
? _tokenContract.balanceOf(address(this))
|
|
||||||
: _amount;
|
|
||||||
|
|
||||||
_tokenContract.approve(getAllowanceTarget(_route), _amount);
|
_tokenContract.approve(getAllowanceTarget(_route), _amount);
|
||||||
(bool success, ) = registry.call(_txData);
|
|
||||||
require(success, "Socket-swap-failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socketBridge(_txData, _ethAmt);
|
||||||
|
|
||||||
_eventName = "LogSocketBridge(bytes,address,uint256,uint256)";
|
_eventName = "LogSocketBridge(bytes,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
_txData,
|
|
||||||
_token,
|
_token,
|
||||||
_amount,
|
_amount,
|
||||||
_getId
|
_sourceChain,
|
||||||
|
_targetChain,
|
||||||
|
_recipient
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ describe("Socket Connector", function () {
|
||||||
|
|
||||||
const fromChainId = "1"
|
const fromChainId = "1"
|
||||||
const toChainId = "137"
|
const toChainId = "137"
|
||||||
const recipient = "0xD625c7458Da1a0758dA8d3AC7f2c10180Bf0E506"
|
|
||||||
|
|
||||||
const wallets = provider.getWallets();
|
const wallets = provider.getWallets();
|
||||||
const [wallet0, wallet1, wallet2, wallet3] = wallets;
|
const [wallet0, wallet1, wallet2, wallet3] = wallets;
|
||||||
|
@ -172,7 +171,7 @@ describe("Socket Connector", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "bridge",
|
method: "bridge",
|
||||||
args: [DAI_ADDR_ETH, apiReturnData.result.txData, routeToPass, "1000000000000000000", '0']
|
args: [DAI_ADDR_ETH, apiReturnData.result.txData, routeToPass, "1000000000000000000", fromChainId, toChainId, wallet0.address]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -212,7 +211,7 @@ describe("Socket Connector", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "bridge",
|
method: "bridge",
|
||||||
args: [ETHADDR, apiReturnData.result.txData, routeToPass, "1000000000000000000", '0']
|
args: [ETHADDR, apiReturnData.result.txData, routeToPass, "1000000000000000000", fromChainId, toChainId, wallet0.address]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user