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

chore(deps): bump minimist from 1.2.0 to 1.2.8 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 30 additions & 8 deletions src/main/scripts/do-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import {
} from "../utils/common";
import {
ExchangeApi,
AccountApi,
StatusApi,
GetRoutesRequest,
Route,
RoutesResponse,
GetTokenApprovalRequest,
} from "@blockdaemon/blockdaemon-defi-api-typescript-fetch";
import { ethers } from "ethers";

const logger = log.getLogger("do-swap");

async function main() {
const api = new ExchangeApi(apiConfig);
const exchangeAPI = new ExchangeApi(apiConfig);
const accountAPI = new AccountApi(apiConfig);
const statusAPI = new StatusApi(apiConfig);

const routeParameters: GetRoutesRequest = {
fromChain: "10", // Optimism
Expand All @@ -33,16 +38,32 @@ async function main() {
};

try {
// const routes: RoutesResponse = await api.getRoutes(routeParameters);
// logger.info("Got routes");
const routes: RoutesResponse = await exchangeAPI.getRoutes(routeParameters);
logger.info("Got routes");

const selectedRoute: Route = routes.routes[0];
logger.info("Selected route:");
const approvalAddress = selectedRoute.steps[0].estimate.approvalAddress;

const approvalRequest: GetTokenApprovalRequest = {
chainID: routeParameters.fromChain,
accountAddress: routeParameters.fromAddress,
tokenAddress: routeParameters.toToken,
spenderAddress: approvalAddress,
}

const approval = await accountAPI.getTokenApproval(approvalRequest);
logger.info("Got approval");
logger.info(JSON.stringify(approval, null, 2));

// set timeout 10 seconds, await the approval to propagate
await new Promise(resolve => setTimeout(resolve, 10000));

logger.info("Sending transaction...");

// const selectedRoute: Route = routes.routes[0];
// logger.info("Selected route:");
// const approvalAddress = selectedRoute.steps[0].estimate.approvalAddress;

const destination = RECEIVER_ADDRESS;
const txPayload =
"0x0b4cb5d80000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000038d34169c6b532200000000000000000000000000000000000000000000000009497c1a68fe583400000000000000000000000000000000000000000000000000000000669a767900000000000000000000000000000000000000000000000009497c1a68fe583400000000000000000000000000000000000000000000000000000000669a7679000000000000000000000000b3c68a491608952cb1257fc9909a537a0173b63b0000000000000000000000009298dfd8a0384da62643c2e98f437e820029e75e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b017ed3df2acd34e91f651533afaa9e9c4cfcd499a3ca0cf327c00c8e8cfbe90000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1000000000000000000000000f271aafc62634e6dc9a276ac0f6145c4fdbe2ced0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000089000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003686f7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
const txPayload = selectedRoute.transactionRequest.data;
const signedPayload = await signMessage(txPayload);
const broadcastResult = await transact(signedPayload, destination);

Expand All @@ -54,6 +75,7 @@ async function main() {
"Check transaction at: https://optimistic.etherscan.io/tx/" +
broadcastResult.hash,
);
logger.info("Transaction done with success. Please check your balances.");
} else {
throw new Error("Failed to broadcast signed message");
}
Expand Down