mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
code refactor
This commit is contained in:
parent
8a3fdde853
commit
32429d2b05
|
@ -2,13 +2,12 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogSwap(
|
||||
event LogSwapAggregator(
|
||||
string _connector,
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ pragma abicoder v2;
|
|||
|
||||
import { InstaConnectors } from "../../common/interfaces.sol";
|
||||
|
||||
abstract contract Helper {
|
||||
contract SwapHelpers {
|
||||
/**
|
||||
* @dev Instadapp Connectors Registry
|
||||
*/
|
||||
|
@ -19,9 +19,7 @@ abstract contract Helper {
|
|||
bytes[] callDatas;
|
||||
uint256 setId;
|
||||
}
|
||||
}
|
||||
|
||||
contract SwapHelpers is Helper {
|
||||
/**
|
||||
*@dev Swap using the dex aggregators.
|
||||
*@param _connectors name of the connectors in preference order.
|
||||
|
@ -35,25 +33,27 @@ contract SwapHelpers is Helper {
|
|||
string memory _connector
|
||||
)
|
||||
{
|
||||
require(_connectors.length > 0, "zero-length-not-allowed");
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
require(
|
||||
_inputData.unitAmts.length == _connectors.length,
|
||||
_inputData.unitAmts.length == _length,
|
||||
"unitAmts-length-invalid"
|
||||
);
|
||||
require(
|
||||
_inputData.callDatas.length == _connectors.length,
|
||||
_inputData.callDatas.length == _length,
|
||||
"callDatas-length-invalid"
|
||||
);
|
||||
|
||||
// require _connectors[i] == "1INCH-A" || "ZEROX-A" || "PARASWAP-A" || similar connectors
|
||||
|
||||
for (uint256 i = 0; i < _connectors.length; i++) {
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
bytes4 swapData = bytes4(
|
||||
keccak256("swap(address,address,uint256,uint256,bytes,uint256)")
|
||||
);
|
||||
|
||||
string memory _1INCH = "1INCH-A";
|
||||
if (keccak256(bytes(_connectors[i])) == keccak256(bytes(_1INCH))) {
|
||||
if (
|
||||
keccak256(bytes(_connectors[i])) == keccak256(bytes("1INCH-A"))
|
||||
) {
|
||||
swapData = bytes4(
|
||||
keccak256(
|
||||
"sell(address,address,uint256,uint256,bytes,uint256)"
|
||||
|
|
|
@ -60,14 +60,13 @@ abstract contract Swap is SwapHelpers, Events {
|
|||
(_buyAmt, _sellAmt) = decodeEvents(_connector, returnData);
|
||||
}
|
||||
|
||||
_eventName = "LogSwap(string,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventName = "LogSwapAggregator(string,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_connector,
|
||||
buyAddr,
|
||||
sellAddr,
|
||||
_buyAmt,
|
||||
_sellAmt,
|
||||
0,
|
||||
setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogSwap(
|
||||
event LogSwapAggregator(
|
||||
string _connector,
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ pragma abicoder v2;
|
|||
|
||||
import { InstaConnectors } from "../../common/interfaces.sol";
|
||||
|
||||
abstract contract Helper {
|
||||
contract SwapHelpers {
|
||||
/**
|
||||
* @dev Instadapp Connectors Registry
|
||||
*/
|
||||
|
@ -19,9 +19,6 @@ abstract contract Helper {
|
|||
bytes[] callDatas;
|
||||
uint256 setId;
|
||||
}
|
||||
}
|
||||
|
||||
contract SwapHelpers is Helper {
|
||||
/**
|
||||
*@dev Swap using the dex aggregators.
|
||||
*@param _connectors name of the connectors in preference order.
|
||||
|
@ -35,25 +32,25 @@ contract SwapHelpers is Helper {
|
|||
string memory _connector
|
||||
)
|
||||
{
|
||||
require(_connectors.length > 0, "zero-length-not-allowed");
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
require(
|
||||
_inputData.unitAmts.length == _connectors.length,
|
||||
_inputData.unitAmts.length == _length,
|
||||
"unitAmts-length-invalid"
|
||||
);
|
||||
require(
|
||||
_inputData.callDatas.length == _connectors.length,
|
||||
_inputData.callDatas.length == _length,
|
||||
"callDatas-length-invalid"
|
||||
);
|
||||
|
||||
// require _connectors[i] == "1INCH-A" || "ZEROX-A" || "PARASWAP-A" || similar connectors
|
||||
|
||||
for (uint256 i = 0; i < _connectors.length; i++) {
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
bytes4 swapData = bytes4(
|
||||
keccak256("swap(address,address,uint256,uint256,bytes,uint256)")
|
||||
);
|
||||
|
||||
string memory _1INCH = "1INCH-A";
|
||||
if (keccak256(bytes(_connectors[i])) == keccak256(bytes(_1INCH))) {
|
||||
if (keccak256(bytes(_connectors[i])) == keccak256(bytes("1INCH-A"))) {
|
||||
swapData = bytes4(
|
||||
keccak256(
|
||||
"sell(address,address,uint256,uint256,bytes,uint256)"
|
||||
|
|
|
@ -60,14 +60,13 @@ abstract contract Swap is SwapHelpers, Events {
|
|||
(_buyAmt, _sellAmt) = decodeEvents(_connector, returnData);
|
||||
}
|
||||
|
||||
_eventName = "LogSwap(string,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventName = "LogSwapAggregator(string,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_connector,
|
||||
buyAddr,
|
||||
sellAddr,
|
||||
_buyAmt,
|
||||
_sellAmt,
|
||||
0,
|
||||
setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogSwap(
|
||||
event LogSwapAggregator(
|
||||
string _connector,
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ pragma abicoder v2;
|
|||
|
||||
import { InstaConnectors } from "../../common/interfaces.sol";
|
||||
|
||||
abstract contract Helper {
|
||||
contract SwapHelpers {
|
||||
/**
|
||||
* @dev Instadapp Connectors Registry
|
||||
*/
|
||||
|
@ -19,9 +19,7 @@ abstract contract Helper {
|
|||
bytes[] callDatas;
|
||||
uint256 setId;
|
||||
}
|
||||
}
|
||||
|
||||
contract SwapHelpers is Helper {
|
||||
/**
|
||||
*@dev Swap using the dex aggregators.
|
||||
*@param _connectors name of the connectors in preference order.
|
||||
|
@ -35,25 +33,25 @@ contract SwapHelpers is Helper {
|
|||
string memory _connector
|
||||
)
|
||||
{
|
||||
require(_connectors.length > 0, "zero-length-not-allowed");
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
require(
|
||||
_inputData.unitAmts.length == _connectors.length,
|
||||
_inputData.unitAmts.length == _length,
|
||||
"unitAmts-length-invalid"
|
||||
);
|
||||
require(
|
||||
_inputData.callDatas.length == _connectors.length,
|
||||
_inputData.callDatas.length == _length,
|
||||
"callDatas-length-invalid"
|
||||
);
|
||||
|
||||
// require _connectors[i] == "1INCH-A" || "ZEROX-A" || "PARASWAP-A" || similar connectors
|
||||
|
||||
for (uint256 i = 0; i < _connectors.length; i++) {
|
||||
for (uint256 i = 0; i < _length; i++) {
|
||||
bytes4 swapData = bytes4(
|
||||
keccak256("swap(address,address,uint256,uint256,bytes,uint256)")
|
||||
);
|
||||
|
||||
string memory _1INCH = "1INCH-A";
|
||||
if (keccak256(bytes(_connectors[i])) == keccak256(bytes(_1INCH))) {
|
||||
if (keccak256(bytes(_connectors[i])) == keccak256(bytes("1INCH-A"))) {
|
||||
swapData = bytes4(
|
||||
keccak256(
|
||||
"sell(address,address,uint256,uint256,bytes,uint256)"
|
||||
|
|
|
@ -60,14 +60,13 @@ abstract contract Swap is SwapHelpers, Events {
|
|||
(_buyAmt, _sellAmt) = decodeEvents(_connector, returnData);
|
||||
}
|
||||
|
||||
_eventName = "LogSwap(string,address,address,uint256,uint256,uint256,uint256)";
|
||||
_eventName = "LogSwapAggregator(string,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
_connector,
|
||||
buyAddr,
|
||||
sellAddr,
|
||||
_buyAmt,
|
||||
_sellAmt,
|
||||
0,
|
||||
setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
|||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||
import { addresses } from "../../../scripts/tests/avalanche/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import { ConnectV2SwapAvalanche__factory } from "../../../typechain";
|
||||
import { ConnectV2SwapAggregatorAvalanche__factory } from "../../../typechain";
|
||||
import er20abi from "../../../scripts/constant/abi/basics/erc20.json";
|
||||
import type { Signer, Contract } from "ethers";
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe("Swap | Avalanche", function () {
|
|||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: ConnectV2SwapAvalanche__factory,
|
||||
contractArtifact: ConnectV2SwapAggregatorAvalanche__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
|||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import { ConnectV2Swap__factory } from "../../../typechain";
|
||||
import { ConnectV2SwapAggregator__factory } from "../../../typechain";
|
||||
import er20abi from "../../../scripts/constant/abi/basics/erc20.json";
|
||||
import type { Signer, Contract } from "ethers";
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe("Swap | Mainnet", function () {
|
|||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: ConnectV2Swap__factory,
|
||||
contractArtifact: ConnectV2SwapAggregator__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
|||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||
import { addresses } from "../../../scripts/tests/polygon/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import { ConnectV2SwapPolygon__factory } from "../../../typechain";
|
||||
import { ConnectV2SwapAggregatorPolygon__factory } from "../../../typechain";
|
||||
import er20abi from "../../../scripts/constant/abi/basics/erc20.json";
|
||||
import type { Signer, Contract } from "ethers";
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe("Swap", function () {
|
|||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: ConnectV2SwapPolygon__factory,
|
||||
contractArtifact: ConnectV2SwapAggregatorPolygon__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user