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

salt replaced by swap transaction hash and encoding params from salt … #52

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions app/lib/httpCalls/networksHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ module.exports = {

async getAllNetworks() {
try {
// let baseUrl = ((global as any) as any).environment.baseUrlGatewayBackend;
let baseUrl = 'http://localhost:8080/api/v1';
let baseUrl = ((global as any) as any).environment.baseUrlGatewayBackend;
let url = `${baseUrl}/networks/list?isAllowedOnMultiSwap=true&allowFIBERData=${(global as any).environment.apiKeyForGateway}&isPagination=false`;
let res = await axios.get(url);
if(res.data.body && res.data.body.networks && res.data.body.networks.length){
(global as any).networks = await (global as any).commonFunctions.convertIntoFIBERNetworks(res.data.body.networks);
console.log('Refresh netwroks',(global as any).networks.length)
}else {
(global as any).networks = [];
}
return res.data.body.networks;
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions app/lib/httpCalls/receiptsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module.exports = {

async getReceiptBySwapHash(swapHash: any, sourceNetworkId: any) {
try {
// let baseUrl = ((global as any) as any).environment.baseUrlGatewayBackend;
let baseUrl = 'http://localhost:8080/api/v1';
let baseUrl = ((global as any) as any).environment.baseUrlGatewayBackend;
let url = `${baseUrl}/transactions/receipt/by/hash/${swapHash}?sourceNetworkId=${sourceNetworkId}`;
let res = await axios.get(url);
console.log(res.data.body.receipt)
Expand Down
20 changes: 13 additions & 7 deletions app/lib/middlewares/helpers/multiSwapHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,21 @@ module.exports = {

getWithdrawSigned: async function (req: any) {
let log = await this.saveTransactionLog(req);
// await withdrawHelper.getWithdrawReqObject(req);
let query = await withdrawHelper.getWithdrawReqObject(req);
if (!query || !query.sourceWalletAddress || !query.sourceTokenContractAddress || !query.sourceNetworkChainId
|| !query.sourceAmount || !query.destinationTokenContractAddress
|| !query.destinationNetworkChainId) {
throw 'sourceWalletAddress & sourceTokenContractAddress & sourceNetworkChainId & sourceAmount & destinationTokenContractAddress & destinationNetworkChainId are missing';
}
let data: any = {};
data = await fiberEngine.withdraw(
req.query.sourceTokenContractAddress, // goerli ada
req.query.destinationTokenContractAddress, // bsc ada
req.query.sourceNetworkChainId, // source chain id (goerli)
req.query.destinationNetworkChainId, // target chain id (bsc)
req.query.sourceAmount, //source token amount
req.query.destinationWalletAddress // destination wallet address
query.sourceTokenContractAddress,
query.destinationTokenContractAddress,
query.sourceNetworkChainId,
query.destinationNetworkChainId,
query.sourceAmount,
query.destinationWalletAddress
req.query.swapTransactionHash,
);
await this.updateTransactionLog(data, log);
return data;
Expand Down
10 changes: 5 additions & 5 deletions app/lib/middlewares/helpers/withdrawHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const abiDecoder = require('abi-decoder'); // NodeJS
module.exports = {

getWithdrawReqObject: async function (req: any) {
let data: any = {};
try{
let data: any = {};
let sourceNetwork = commonFunctions.getNetworkByChainId(req.query.sourceNetworkChainId);
console.log('sourceNetwork',sourceNetwork.name);
if(sourceNetwork){
if (sourceNetwork) {
console.log('sourceNetwork', sourceNetwork.name);
let receipt = await receiptsHelper.getReceiptBySwapHash(req.query.swapTransactionHash, sourceNetwork._id);
if(receipt){
let web3 = web3ConfigurationHelper.web3(sourceNetwork.rpcUrl).eth;
Expand Down Expand Up @@ -37,11 +37,11 @@ module.exports = {
}
}
}


}catch(e){
console.log('error',e)
}

return data;
},

getValueFromWebTransaction: async function (transaction: any, paramName: any) {
Expand Down
21 changes: 10 additions & 11 deletions scripts/fiberEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ module.exports = {
sourceChainId,
targetChainId,
inputAmount,
destinationWalletAddress
destinationWalletAddress,
salt
) {
const gas = await this.estimateGasForWithdraw(targetChainId, destinationWalletAddress);
console.log('gas==========',gas)
const gas = await estimateGasForWithdraw(targetChainId, destinationWalletAddress);
const sourceNetwork = global.commonFunctions.getNetworkByChainId(sourceChainId).multiswapNetworkFIBERInformation;
const targetNetwork = global.commonFunctions.getNetworkByChainId(targetChainId).multiswapNetworkFIBERInformation;

Expand Down Expand Up @@ -318,7 +318,6 @@ module.exports = {
Math.floor(amountIn)
);
console.log("isTargetTokenFoundry", isTargetTokenFoundry)
const Salt = Web3.utils.randomHex(32);
if (isTargetTokenFoundry === true) {
console.log("TN-1: Target Token is Foundry Asset");
console.log("TN-2: Withdraw Foundry Asset...");
Expand All @@ -328,7 +327,7 @@ module.exports = {
targetTokenAddress,
destinationWalletAddress,
sourceBridgeAmount,
Salt
salt
);
const sigP2 = ecsign(
Buffer.from(hash.replace("0x", ""), "hex"),
Expand All @@ -342,7 +341,7 @@ module.exports = {
targetTokenAddress, //token address on network 2
destinationWalletAddress, //reciver
sourceBridgeAmount, //targetToken amount
Salt,
salt,
sig2,
gas );

Expand Down Expand Up @@ -388,7 +387,7 @@ module.exports = {
path2[0],
targetNetwork.fiberRouter,
sourceBridgeAmount,
Salt
salt
);
const sigP2 = ecsign(
Buffer.from(hash.replace("0x", ""), "hex"),
Expand All @@ -407,7 +406,7 @@ module.exports = {
amountsOut2,
path2,
this.getDeadLine().toString(),
Salt,
salt,
sig2,
gas
);
Expand Down Expand Up @@ -449,10 +448,10 @@ module.exports = {
path2[0],
targetNetwork.fiberRouter,
sourceBridgeAmount,
Salt
salt
);

console.log("targetChainId", targetChainId, "targetNetwork.fundManager", targetNetwork.fundManager, "targetTokenAddress", targetTokenAddress, "=========>path2[0]", path2[0], "targetSigner.address", targetSigner.address, "sourceBridgeAmount", sourceBridgeAmount, "Salt", Salt)
console.log("targetChainId", targetChainId, "targetNetwork.fundManager", targetNetwork.fundManager, "targetTokenAddress", targetTokenAddress, "=========>path2[0]", path2[0], "targetSigner.address", targetSigner.address, "sourceBridgeAmount", sourceBridgeAmount, "salt", salt)
const sigP2 = ecsign(
Buffer.from(hash.replace("0x", ""), "hex"),
Buffer.from(global.environment.SIGNER.replace("0x", ""), "hex")
Expand All @@ -469,7 +468,7 @@ module.exports = {
amountsOut2,
path2,
this.getDeadLine().toString(), //deadline
Salt,
salt,
sig2,
gas
);
Expand Down