Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Dec 29, 2024
1 parent c2606f2 commit 7691a88
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -41,7 +42,6 @@ import {
ConsoleSpanExporter,
SimpleSpanProcessor,
} from "@opentelemetry/sdk-trace-base";
import { isAddress } from "viem";

config();

Expand Down Expand Up @@ -123,7 +123,7 @@ const getOptions = async (argv: any, version?: string) => {
)
.option(
"--dispair <address...>",
"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 <string>",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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)],
],
);
}
Expand All @@ -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(
Expand All @@ -57,22 +56,21 @@ export async function getWithdrawEnsureRainlang(
orgOutputBalance: BigNumber,
inputToEthPrice: BigNumber,
outputToEthPrice: BigNumber,
minimumExcepted: BigNumber,
minimumExpected: BigNumber,
sender: string,
): Promise<string> {
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)],
],
Expand Down
17 changes: 9 additions & 8 deletions tasks/ensure-bounty.rain
Original file line number Diff line number Diff line change
@@ -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"
);
33 changes: 18 additions & 15 deletions tasks/withdraw-ensure-bounty.rain
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
);
30 changes: 15 additions & 15 deletions test/e2e/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 26 additions & 23 deletions test/tasks.test.ts → test/task.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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"
);`;
Expand All @@ -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));
Expand All @@ -57,32 +57,35 @@ 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"
);`;
assert.equal(result, expected);
});

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)),
Expand All @@ -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);

Expand Down
9 changes: 2 additions & 7 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit 7691a88

Please sign in to comment.