Skip to content

Commit

Permalink
Feat: added getTxData
Browse files Browse the repository at this point in the history
  • Loading branch information
sk1122 committed Aug 24, 2022
1 parent 8ea85bf commit f846a26
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
50 changes: 49 additions & 1 deletion src/services/contract/evm/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,52 @@ export const executeRoute = (
reject(e);
}
});
}
}

export const getTxData = (receiver: string, route: Routes) => {
return new Promise(async (resolve, reject) => {
try {
const bridgeAddress =
wagpayBridge[Number(route.route.fromChain)];

const contract = new ethers.utils.Interface(abi);

const params = constructExtraParams(route)
const routeDataArr = [
receiver,
BigNumber.from(config.wagpayBridgeId[route.name]),
BigNumber.from(Number(route.route.toChain)),
route.route.fromToken.address,
BigNumber.from(route.route.amount),
params,
route.uniswapData ? true : false,
[
route.uniswapData.dex,
BigNumber.from(route.route.amount),
BigNumber.from(
ethers.utils
.parseUnits(
route.uniswapData.amountToGet.toFixed(2),
route.uniswapData.toToken.decimals
)
.toString()
),
BigNumber.from(Number(3000)),
BigNumber.from(Number(route.uniswapData.chainId)),
route.uniswapData.fromToken.address,
route.uniswapData.toToken.address,
bridgeAddress,
],
];

console.log(routeDataArr)

const transaction = await contract.encodeFunctionData('transfer', [routeDataArr]);

resolve(transaction)
} catch (e) {
console.log(e);
reject(e);
}
});
}
Empty file added src/solana/index.ts
Empty file.
15 changes: 8 additions & 7 deletions test/route.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainId, CoinKey, RouteData, Routes } from "@wagpay/types"
import { assert, expect } from "chai"
import { ethers } from "ethers"
import { getRoutes, executeRoute } from "../src"
import { getRoutes, executeRoute, getTxData } from "../src"
import { ReturnData } from "../src/types"

describe("Routes", () => {
Expand Down Expand Up @@ -36,12 +36,13 @@ describe("Routes", () => {
signer = signer.connect(provider)
console.log(signer.address)
try {
const data = await executeRoute(signer.address, route, signer) as ReturnData
expect(data.fromChain).to.eq(route.route.fromChain)
expect(data.toChain).to.eq(route.route.toChain)
expect(data.fromToken.address).to.eq(route.route.fromToken.address)
expect(data.amount).to.eq(route.route.amount)
expect(data.bridge).to.eq(route.name)
const data = await getTxData(signer.address, route)
console.log(data)
// expect(data.fromChain).to.eq(route.route.fromChain)
// expect(data.toChain).to.eq(route.route.toChain)
// expect(data.fromToken.address).to.eq(route.route.fromToken.address)
// expect(data.amount).to.eq(route.route.amount)
// expect(data.bridge).to.eq(route.name)
} catch (e) { console.log(e); assert.fail('Transaction Unsuccessful') }
})
})

0 comments on commit f846a26

Please sign in to comment.