Bladeren bron

feat: layer zero stargate

Wren 1 jaar geleden
bovenliggende
commit
1b0c693087

+ 47 - 0
js-runtime/src/script/layerzero/stargate/contract/router.js

@@ -0,0 +1,47 @@
+export default [{
+    "inputs": [{"internalType": "address", "name": "_stargateEthVault", "type": "address"}, {
+        "internalType": "address",
+        "name": "_stargateRouter",
+        "type": "address"
+    }, {"internalType": "uint16", "name": "_poolId", "type": "uint16"}],
+    "stateMutability": "nonpayable",
+    "type": "constructor"
+}, {
+    "inputs": [],
+    "name": "addLiquidityETH",
+    "outputs": [],
+    "stateMutability": "payable",
+    "type": "function"
+}, {
+    "inputs": [],
+    "name": "poolId",
+    "outputs": [{"internalType": "uint16", "name": "", "type": "uint16"}],
+    "stateMutability": "view",
+    "type": "function"
+}, {
+    "inputs": [],
+    "name": "stargateEthVault",
+    "outputs": [{"internalType": "address", "name": "", "type": "address"}],
+    "stateMutability": "view",
+    "type": "function"
+}, {
+    "inputs": [],
+    "name": "stargateRouter",
+    "outputs": [{"internalType": "contract IStargateRouter", "name": "", "type": "address"}],
+    "stateMutability": "view",
+    "type": "function"
+}, {
+    "inputs": [{"internalType": "uint16", "name": "_dstChainId", "type": "uint16"}, {
+        "internalType": "address payable",
+        "name": "_refundAddress",
+        "type": "address"
+    }, {"internalType": "bytes", "name": "_toAddress", "type": "bytes"}, {
+        "internalType": "uint256",
+        "name": "_amountLD",
+        "type": "uint256"
+    }, {"internalType": "uint256", "name": "_minAmountLD", "type": "uint256"}],
+    "name": "swapETH",
+    "outputs": [],
+    "stateMutability": "payable",
+    "type": "function"
+}, {"stateMutability": "payable", "type": "receive"}]

+ 21 - 0
js-runtime/src/script/layerzero/stargate/swapEthForArb.js

@@ -0,0 +1,21 @@
+import express from "express";
+import CommonUtil from "../../utils/commonUtil.js";
+import {Contract} from "ethers";
+import RouterAbi from "./contract/router.js"
+
+const router = express.Router();
+const distChainId = 110;
+const wrapperEth = "0x0000"
+
+router.post("/", async (req, res) => {
+    let {wallet, params} = CommonUtil.getParamsAndWallet(req);
+    const router = new Contract("0x150f94B44927F078737562f0fcF3C95c01Cc2376", RouterAbi, wallet);
+    const quoteData = router.queryLayerZeroFee(distChainId, 1, wrapperEth, "0x", ({
+        dstGasForCall: 0,       // extra gas, if calling smart contract,
+        dstNativeAmount: 0,     // amount of dust dropped in destination wallet
+        dstNativeAddr: "0x" // destination wallet for dust
+    }))
+    let feeWei = quoteData[0]
+    await router.swap(distChainId,
+
+});

+ 8 - 0
js-runtime/src/script/utils/commonUtil.js

@@ -0,0 +1,8 @@
+export default {
+    getParamsAndWallet: (req) => {
+        let params = req.body.params;
+        let wallet = params.wallet;
+        delete params.wallet;
+        return {params, wallet};
+    }
+}