Skip to content

Commit

Permalink
Merge pull request #300 from rainlanguage/2025-01-20-cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
rouzwelt authored Feb 19, 2025
2 parents ffdffb2 + 8befd39 commit c7f447b
Show file tree
Hide file tree
Showing 31 changed files with 872 additions and 1,596 deletions.
25 changes: 8 additions & 17 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"@opentelemetry/resources": "^1.22.0",
"@opentelemetry/sdk-trace-base": "^1.22.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"@rainlanguage/dotrain": "^6.0.1-alpha.21",
"@rainlanguage/orderbook": "^0.0.1-alpha.6",
"@rainlanguage/dotrain": "^6.0.1-alpha.24",
"axios": "^1.3.4",
"commander": "^11.0.0",
"dotenv": "^16.0.3",
Expand Down
98 changes: 98 additions & 0 deletions scripts/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { PublicClient } from "viem";
import { Token } from "sushi/currency";
import { ChainId, Router } from "sushi";
import { BigNumber, ethers } from "ethers";
import { getDataFetcher } from "../src/config";

/**
* Gets the route for tokens
* @param chainId - The network chain id
* @param rpcs - The rpcs
* @param sellAmount - The sell amount, should be in onchain token value
* @param fromTokenAddress - The from token address
* @param fromTokenDecimals - The from token decimals
* @param toTokenAddress - The to token address
* @param toTokenDecimals - The to token decimals
* @param receiverAddress - The address of the receiver
* @param routeProcessorAddress - The address of the RouteProcessor contract
* @param abiencoded - If the result should be abi encoded or not
*/
export const getRouteForTokens = async (
chainId: number,
rpcs: string[],
sellAmount: BigNumber,
fromTokenAddress: string,
fromTokenDecimals: number,
toTokenAddress: string,
toTokenDecimals: number,
receiverAddress: string,
routeProcessorAddress: string,
abiEncoded = false,
) => {
const amountIn = sellAmount.toBigInt();
const fromToken = new Token({
chainId: chainId,
decimals: fromTokenDecimals,
address: fromTokenAddress,
});
const toToken = new Token({
chainId: chainId,
decimals: toTokenDecimals,
address: toTokenAddress,
});
const dataFetcher = await getDataFetcher({
chain: { id: chainId },
rpc: rpcs,
} as any as PublicClient);
await dataFetcher.fetchPoolsForToken(fromToken, toToken);
const pcMap = dataFetcher.getCurrentPoolCodeMap(fromToken, toToken);
const route = Router.findBestRoute(
pcMap,
chainId as ChainId,
fromToken,
amountIn,
toToken,
Number(await dataFetcher.web3Client.getGasPrice()),
// providers,
// poolFilter
);
if (route.status == "NoWay") throw "NoWay";
else {
let routeText = "";
route.legs.forEach((v, i) => {
if (i === 0)
routeText =
routeText +
v.tokenTo.symbol +
"/" +
v.tokenFrom.symbol +
"(" +
(v as any).poolName +
")";
else
routeText =
routeText +
" + " +
v.tokenTo.symbol +
"/" +
v.tokenFrom.symbol +
"(" +
(v as any).poolName +
")";
});
// eslint-disable-next-line no-console
console.log("Route portions: ", routeText, "\n");
const rpParams = Router.routeProcessor4Params(
pcMap,
route,
fromToken,
toToken,
receiverAddress as `0x${string}`,
routeProcessorAddress as `0x${string}`,
// permits
// "0.005"
);
if (abiEncoded) return ethers.utils.defaultAbiCoder.encode(["bytes"], [rpParams.routeCode]);
else return rpParams.routeCode;
}
};
8 changes: 4 additions & 4 deletions scripts/sweep.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-console */
import { ChainId } from "sushi";
import { ethers } from "ethers";
import { PublicClient } from "viem";
import { TokenDetails } from "../src/types";
import { errorSnapshot } from "../src/error";
import { PublicClient, erc20Abi } from "viem";
import { routeProcessor3Abi } from "../src/abis";
import { setWatchedTokens } from "../src/account";
import { Native, Token, WNATIVE } from "sushi/currency";
import { ROUTE_PROCESSOR_4_ADDRESS } from "sushi/config";
import { erc20Abi, routeProcessor3Abi } from "../src/abis";
import { createViemClient, getDataFetcher } from "../src/config";
import { getRpSwap, PoolBlackList, processLps, sleep } from "../src/utils";
import { getRpSwap, PoolBlackList, sleep } from "../src/utils";
import { createViemClient, getDataFetcher, processLps } from "../src/config";
import { HDAccount, mnemonicToAccount, PrivateKeyAccount } from "viem/accounts";

/**
Expand Down
16 changes: 4 additions & 12 deletions src/abis.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { parseAbi } from "viem";

/**
* Minimal ABI for ERC20 contract only including Transfer event
*/
export const erc20Abi = [
"event Transfer(address indexed from, address indexed to, uint256 value)",
"function symbol() public view returns (string memory)",
"function transfer(address to, uint256 amount) external returns (bool)",
"function balanceOf(address account) external view returns (uint256)",
"function approve(address spender, uint256 amount) external returns (bool)",
"function allowance(address owner, address spender) external view returns (uint256)",
] as const;

// structs used in the orderbook and arb abis
export const IO = "(address token, uint8 decimals, uint256 vaultId)" as const;
export const EvaluableV3 = "(address interpreter, address store, bytes bytecode)" as const;
Expand Down Expand Up @@ -108,6 +96,10 @@ export const DefaultArbEvaluable = {

export const TakeOrderV2EventAbi = parseAbi([orderbookAbi[13]]);
export const OrderbookQuoteAbi = parseAbi([orderbookAbi[14]]);
export const VaultBalanceAbi = parseAbi([orderbookAbi[3]]);
export const AfterClearAbi = parseAbi([orderbookAbi[2]]);
export const DeployerAbi = parseAbi(deployerAbi);
export const MulticallAbi = parseAbi(multicall3Abi);

/**
* Arbitrum node interface address, used to get L1 gas limit.
Expand Down
Loading

0 comments on commit c7f447b

Please sign in to comment.