From 7691a883189b80fc90c346c149f99028716988e1 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Sun, 29 Dec 2024 21:54:46 +0000 Subject: [PATCH] update --- README.md | 2 +- src/abis.ts | 5 ++- src/cli.ts | 4 +-- src/config.ts | 2 +- src/task.ts | 22 ++++++------- tasks/ensure-bounty.rain | 17 +++++----- tasks/withdraw-ensure-bounty.rain | 33 ++++++++++--------- test/e2e/e2e.test.js | 30 ++++++++--------- test/{tasks.test.ts => task.test.ts} | 49 +++++++++++++++------------- test/utils.js | 9 ++--- 10 files changed, 88 insertions(+), 85 deletions(-) rename test/{tasks.test.ts => task.test.ts} (74%) diff --git a/README.md b/README.md index e8ecc659..82ceb7b0 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ The app requires these arguments (all arguments can be set in env variables alte - `--arb-address`, Address of the deployed arb contract, Will override the 'ARB_ADDRESS' in env variables - `--bot-min-balance` The minimum gas token balance the bot wallet must have. Will override the 'BOT_MIN_BALANCE' in env variables - `-s` or `--subgraph`, Subgraph URL(s) to read orders details from, can be used in combination with --orders, Will override the 'SUBGRAPH' in env variables -- `--dispair`, Addresses of dispair to use for tasks, in order of [interpreter, store, deployer], Will override the 'DISPAIR' in env variables" +- `--dispair`, Addresses of dispair to use for tasks, in order of interpreter, store, deployer, Will override the 'DISPAIR' in env variables Other optional arguments are: - `--generic-arb-address`, Address of the deployed generic arb contract to perform inter-orderbook clears, Will override the 'GENERIC_ARB_ADDRESS' in env variables diff --git a/src/abis.ts b/src/abis.ts index 86aac631..0893de0e 100644 --- a/src/abis.ts +++ b/src/abis.ts @@ -70,8 +70,11 @@ export const routeProcessor3Abi = [ `function processRoute(address tokenIn, uint256 amountIn, address tokenOut, uint256 amountOutMin ,address to, bytes memory route) external payable returns (uint256 amountOut)`, ] as const; +/** + * ExpressionDeployerNPE2 minimal ABI + */ export const deployerAbi = [ - "function parse2(bytes data) external view returns (bytes bytecode)", + "function parse2(bytes memory data) external view returns (bytes memory bytecode)", ] as const; /** diff --git a/src/cli.ts b/src/cli.ts index e61f2f26..366f6c86 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,4 +1,5 @@ import { config } from "dotenv"; +import { isAddress } from "viem"; import { Command } from "commander"; import { getMetaInfo } from "./config"; import { BigNumber, ethers } from "ethers"; @@ -41,7 +42,6 @@ import { ConsoleSpanExporter, SimpleSpanProcessor, } from "@opentelemetry/sdk-trace-base"; -import { isAddress } from "viem"; config(); @@ -123,7 +123,7 @@ const getOptions = async (argv: any, version?: string) => { ) .option( "--dispair ", - "Addresses of dispair to use for tasks, in order of [interpreter, store, deployer], Will override the 'DISPAIR' in env variables", + "Addresses of dispair to use for tasks, in order of interpreter, store, deployer, Will override the 'DISPAIR' in env variables", ) .option( "-l, --lps ", diff --git a/src/config.ts b/src/config.ts index e722e956..4c5744de 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,5 @@ import { getSgOrderbooks } from "./sg"; +import { sendTransaction } from "./tx"; import { WNATIVE } from "sushi/currency"; import { ChainId, ChainKey } from "sushi/chain"; import { DataFetcher, LiquidityProviders } from "sushi/router"; @@ -29,7 +30,6 @@ import { ROUTE_PROCESSOR_3_1_ADDRESS, ROUTE_PROCESSOR_3_2_ADDRESS, } from "sushi/config"; -import { sendTransaction } from "./tx"; /** * Get the chain config for a given chain id diff --git a/src/task.ts b/src/task.ts index 00b4be90..5df3191b 100644 --- a/src/task.ts +++ b/src/task.ts @@ -14,25 +14,24 @@ export const WithdrawEnsureBountyDotrainPath = "./tasks/withdraw-ensure-bounty.r * Get the bounty check ensure task rainlang * @param inputToEthPrice - Input token to Eth price * @param outputToEthPrice - Output token to Eth price - * @param minimumExcepted - Minimum expected amount + * @param minimumExpected - Minimum expected amount * @param sender - The msg sender */ export async function getBountyEnsureRainlang( inputToEthPrice: BigNumber, outputToEthPrice: BigNumber, - minimumExcepted: BigNumber, + minimumExpected: BigNumber, sender: string, ): Promise { - const text = fs.readFileSync(EnsureBountyDotrainPath, { encoding: "utf8" }); return await RainDocument.composeText( - text, + fs.readFileSync(EnsureBountyDotrainPath, { encoding: "utf8" }), TaskEntryPoint as any as string[], new MetaStore(), [ ["sender", sender], ["input-to-eth-price", utils.formatUnits(inputToEthPrice)], ["output-to-eth-price", utils.formatUnits(outputToEthPrice)], - ["minimum-excepted", utils.formatUnits(minimumExcepted)], + ["minimum-expected", utils.formatUnits(minimumExpected)], ], ); } @@ -46,7 +45,7 @@ export async function getBountyEnsureRainlang( * @param orgOutputBalance - Output token original balance * @param inputToEthPrice - Input token to Eth price * @param outputToEthPrice - Output token to Eth price - * @param minimumExcepted - Minimum expected amount + * @param minimumExpected - Minimum expected amount * @param sender - The msg sender */ export async function getWithdrawEnsureRainlang( @@ -57,22 +56,21 @@ export async function getWithdrawEnsureRainlang( orgOutputBalance: BigNumber, inputToEthPrice: BigNumber, outputToEthPrice: BigNumber, - minimumExcepted: BigNumber, + minimumExpected: BigNumber, sender: string, ): Promise { - const text = fs.readFileSync(WithdrawEnsureBountyDotrainPath, { encoding: "utf8" }); return await RainDocument.composeText( - text, + fs.readFileSync(WithdrawEnsureBountyDotrainPath, { encoding: "utf8" }), TaskEntryPoint as any as string[], new MetaStore(), [ ["sender", sender], - ["input-to-eth-price", utils.formatUnits(inputToEthPrice)], - ["output-to-eth-price", utils.formatUnits(outputToEthPrice)], - ["minimum-excepted", utils.formatUnits(minimumExcepted)], ["bot-address", botAddress], ["input-token", inputToken], ["output-token", outputToken], + ["minimum-expected", utils.formatUnits(minimumExpected)], + ["input-to-eth-price", utils.formatUnits(inputToEthPrice)], + ["output-to-eth-price", utils.formatUnits(outputToEthPrice)], ["original-input-balance", utils.formatUnits(orgInputBalance)], ["original-output-balance", utils.formatUnits(orgOutputBalance)], ], diff --git a/tasks/ensure-bounty.rain b/tasks/ensure-bounty.rain index faa12599..85d34540 100644 --- a/tasks/ensure-bounty.rain +++ b/tasks/ensure-bounty.rain @@ -1,18 +1,19 @@ --- #sender ! msg sender -#input-to-eth-price ! set input token to eth price -#output-to-eth-price ! set output token to eth price -#minimum-excepted ! minimum expected bounty +#input-to-eth-price ! input token to eth price +#output-to-eth-price ! output token to eth price +#minimum-expected ! minimum expected bounty #main :ensure(equal-to(sender context<0 0>()) "unknown sender"), +total-bounty-eth: add( + mul(input-to-eth-price context<1 0>()) + mul(output-to-eth-price context<1 1>()) +), :ensure( greater-than-or-equal-to( - add( - mul(input-to-eth-price context<1 0>()) - mul(output-to-eth-price context<1 1>()) - ) - minimum-excepted + total-bounty-eth + minimum-expected ) "minimum sender output" ); diff --git a/tasks/withdraw-ensure-bounty.rain b/tasks/withdraw-ensure-bounty.rain index 1a98a2c6..46ecb0a4 100644 --- a/tasks/withdraw-ensure-bounty.rain +++ b/tasks/withdraw-ensure-bounty.rain @@ -3,27 +3,30 @@ #bot-address ! bot wallet adddress as bounty vault owner #input-token ! input token address #output-token ! input token address -#input-to-eth-price ! set input token to eth price -#output-to-eth-price ! set output token to eth price +#input-to-eth-price ! input token to eth price +#output-to-eth-price ! output token to eth price #original-input-balance ! original balance of the bot input token bounty vault before clear #original-output-balance ! original balance of the bot output token bounty vault before clear -#minimum-excepted ! minimum expected bounty +#minimum-expected ! minimum expected bounty #main :ensure(equal-to(sender context<0 0>()) "unknown sender"), +input-bounty: sub( + erc20-balance-of(input-token bot-address) + original-input-balance +), +output-bounty: sub( + erc20-balance-of(output-token bot-address) + original-output-balance +), +total-bounty-eth: add( + mul(input-bounty input-to-eth-price) + mul(output-bounty output-to-eth-price) +), :ensure( greater-than-or-equal-to( - add( - mul( - sub(erc20-balance-of(input-token bot-address) original-input-balance) - input-to-eth-price - ) - mul( - sub(erc20-balance-of(output-token bot-address) original-output-balance) - output-to-eth-price - ) - ) - minimum-excepted + total-bounty-eth + minimum-expected ) "minimum sender output" -); \ No newline at end of file +); diff --git a/test/e2e/e2e.test.js b/test/e2e/e2e.test.js index 4144cb65..8ba4d799 100644 --- a/test/e2e/e2e.test.js +++ b/test/e2e/e2e.test.js @@ -119,11 +119,11 @@ for (let i = 0; i < testData.length; i++) { const interpreter = await rainterpreterNPE2Deploy(); const store = await rainterpreterStoreNPE2Deploy(); const parser = await rainterpreterParserNPE2Deploy(); - const deployer = await rainterpreterExpressionDeployerNPE2Deploy( - interpreter.address, - store.address, - parser.address, - ); + const deployer = await rainterpreterExpressionDeployerNPE2Deploy({ + interpreter: interpreter.address, + store: store.address, + parser: parser.address, + }); const orderbook = !orderbookAddress ? await deployOrderBookNPE2() : await ethers.getContractAt(orderbookAbi, orderbookAddress); @@ -394,11 +394,11 @@ for (let i = 0; i < testData.length; i++) { const interpreter = await rainterpreterNPE2Deploy(); const store = await rainterpreterStoreNPE2Deploy(); const parser = await rainterpreterParserNPE2Deploy(); - const deployer = await rainterpreterExpressionDeployerNPE2Deploy( - interpreter.address, - store.address, - parser.address, - ); + const deployer = await rainterpreterExpressionDeployerNPE2Deploy({ + interpreter: interpreter.address, + store: store.address, + parser: parser.address, + }); const orderbook1 = !orderbookAddress ? await deployOrderBookNPE2() : await ethers.getContractAt(orderbookAbi, orderbookAddress); @@ -756,11 +756,11 @@ for (let i = 0; i < testData.length; i++) { const interpreter = await rainterpreterNPE2Deploy(); const store = await rainterpreterStoreNPE2Deploy(); const parser = await rainterpreterParserNPE2Deploy(); - const deployer = await rainterpreterExpressionDeployerNPE2Deploy( - interpreter.address, - store.address, - parser.address, - ); + const deployer = await rainterpreterExpressionDeployerNPE2Deploy({ + interpreter: interpreter.address, + store: store.address, + parser: parser.address, + }); const orderbook = !orderbookAddress ? await deployOrderBookNPE2() : await ethers.getContractAt(orderbookAbi, orderbookAddress); diff --git a/test/tasks.test.ts b/test/task.test.ts similarity index 74% rename from test/tasks.test.ts rename to test/task.test.ts index e63d1640..837700a0 100644 --- a/test/tasks.test.ts +++ b/test/task.test.ts @@ -1,5 +1,4 @@ import { assert } from "chai"; -import { ChainId } from "sushi"; import { getLocal } from "mockttp"; import { BigNumber, utils } from "ethers"; import { encodeAbiParameters } from "viem"; @@ -14,24 +13,25 @@ describe("Test task", async function () { it("should get ensure bounty rainlang", async function () { const inputToEthPrice = BigNumber.from(10); const outputToEthPrice = BigNumber.from(20); - const minimumExcepted = BigNumber.from(15); + const minimumExpected = BigNumber.from(15); const sender = utils.hexlify(utils.randomBytes(20)); const result = await getBountyEnsureRainlang( inputToEthPrice, outputToEthPrice, - minimumExcepted, + minimumExpected, sender, ); const expected = `/* 0. main */ :ensure(equal-to(${sender} context<0 0>()) "unknown sender"), +total-bounty-eth: add( + mul(${utils.formatUnits(inputToEthPrice)} context<1 0>()) + mul(${utils.formatUnits(outputToEthPrice)} context<1 1>()) +), :ensure( greater-than-or-equal-to( - add( - mul(${utils.formatUnits(inputToEthPrice)} context<1 0>()) - mul(${utils.formatUnits(outputToEthPrice)} context<1 1>()) - ) - ${utils.formatUnits(minimumExcepted)} + total-bounty-eth + ${utils.formatUnits(minimumExpected)} ) "minimum sender output" );`; @@ -41,7 +41,7 @@ describe("Test task", async function () { it("should get withdraw ensure bounty rainlang", async function () { const inputToEthPrice = BigNumber.from(10); const outputToEthPrice = BigNumber.from(20); - const minimumExcepted = BigNumber.from(15); + const minimumExpected = BigNumber.from(15); const sender = utils.hexlify(utils.randomBytes(20)); const botAddress = utils.hexlify(utils.randomBytes(20)); const inputToken = utils.hexlify(utils.randomBytes(20)); @@ -57,24 +57,27 @@ describe("Test task", async function () { orgOutputBalance, inputToEthPrice, outputToEthPrice, - minimumExcepted, + minimumExpected, sender, ); const expected = `/* 0. main */ :ensure(equal-to(${sender} context<0 0>()) "unknown sender"), +input-bounty: sub( + erc20-balance-of(${inputToken} ${botAddress}) + ${utils.formatUnits(orgInputBalance)} +), +output-bounty: sub( + erc20-balance-of(${outputToken} ${botAddress}) + ${utils.formatUnits(orgOutputBalance)} +), +total-bounty-eth: add( + mul(input-bounty ${utils.formatUnits(inputToEthPrice)}) + mul(output-bounty ${utils.formatUnits(outputToEthPrice)}) +), :ensure( greater-than-or-equal-to( - add( - mul( - sub(erc20-balance-of(${inputToken} ${botAddress}) ${utils.formatUnits(orgInputBalance)}) - ${utils.formatUnits(inputToEthPrice)} - ) - mul( - sub(erc20-balance-of(${outputToken} ${botAddress}) ${utils.formatUnits(orgOutputBalance)}) - ${utils.formatUnits(outputToEthPrice)} - ) - ) - ${utils.formatUnits(minimumExcepted)} + total-bounty-eth + ${utils.formatUnits(minimumExpected)} ) "minimum sender output" );`; @@ -82,7 +85,7 @@ describe("Test task", async function () { }); it("should parse rainlang to bytecode", async function () { - const viemClient = await createViemClient(ChainId.POLYGON, [mockServer.url + "/rpc"]); + const viemClient = await createViemClient(1, [mockServer.url + "/rpc"]); const rainlang = "some-rainlang"; const dispair = { interpreter: utils.hexlify(utils.randomBytes(20)), @@ -96,7 +99,7 @@ describe("Test task", async function () { // mock call await mockServer .forPost("/rpc") - .withBodyIncluding("0xa3869e14") + .withBodyIncluding("0xa3869e14") // parse2() selector .thenSendJsonRpcResult(callResult); const result = await parseRainlang(rainlang, viemClient, dispair); diff --git a/test/utils.js b/test/utils.js index 7aa0f0a6..c64e4d70 100644 --- a/test/utils.js +++ b/test/utils.js @@ -62,13 +62,8 @@ exports.rainterpreterParserNPE2Deploy = async () => { return await this.basicDeploy(RainterpreterParserNPE2Artifact); }; -exports.rainterpreterExpressionDeployerNPE2Deploy = async (interpreter, store, parser) => { - // eslint-disable-next-line prettier/prettier - return await this.basicDeploy( - RainterpreterExpressionDeployerNPE2Artifact, - // eslint-disable-next-line prettier/prettier - { interpreter, store, parser }, - ); +exports.rainterpreterExpressionDeployerNPE2Deploy = async (deployConfig) => { + return await this.basicDeploy(RainterpreterExpressionDeployerNPE2Artifact, deployConfig); }; /**