Skip to content
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
6 changes: 6 additions & 0 deletions config.env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ contracts:
balancerArbAddress: $BALANCER_ARB_ADDRESS_V5
stabullArbAddress: $STABULL_ARB_ADDRESS_V5
dispair: $DISPAIR_V5
v6:
sushiArbAddress: $ARB_ADDRESS_V6
genericArbAddress: $GENERIC_ARB_ADDRESS_V6
balancerArbAddress: $BALANCER_ARB_ADDRESS_V6
stabullArbAddress: $STABULL_ARB_ADDRESS_V6
dispair: $DISPAIR_V6
liquidityProviders: $LIQUIDITY_PROVIDERS
route: $ROUTE
sleep: $SLEEP
Expand Down
11 changes: 11 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ contracts:
stabullArbAddress: "0x1234...5678"
# Dispair v5 contract address
dispair: "0x1234...5678"
v6:
# Sushi RP arb v6 contract address
sushiArbAddress: "0x1234...5678"
# Generic arb v6 contract address
genericArbAddress: "0x1234...5678"
# Balancer arb v6 contract address
balancerArbAddress: "0x1234...5678"
# Stabull arb v6 contract address
stabullArbAddress: "0x1234...5678"
# Dispair v6 contract address
dispair: "0x1234...5678"

# list of liquidity providers
# if provided through an env var, they should be separated by a comma
Expand Down
99 changes: 99 additions & 0 deletions src/common/abis/orderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,59 @@ export namespace _v5 {
] as const;
}

export namespace _v6 {
// structs
export const Float = "bytes32" as const;
export const IOV2 = `(address token, bytes32 vaultId)` as const;
export const EvaluableV4 = `(address interpreter, address store, bytes bytecode)` as const;
export const SignedContextV1 = "(address signer, bytes32[] context, bytes signature)" as const;
export const TaskV2 = `(${EvaluableV4} evaluable, ${SignedContextV1}[] signedContext)` as const;
export const ClearStateChangeV2 =
`(${Float} aliceOutput, ${Float} bobOutput, ${Float} aliceInput, ${Float} bobInput)` as const;
export const OrderV4 =
`(address owner, ${EvaluableV4} evaluable, ${IOV2}[] validInputs, ${IOV2}[] validOutputs, bytes32 nonce)` as const;
export const TakeOrderConfigV4 =
`(${OrderV4} order, uint256 inputIOIndex, uint256 outputIOIndex, ${SignedContextV1}[] signedContext)` as const;
export const QuoteV2 =
`(${OrderV4} order, uint256 inputIOIndex, uint256 outputIOIndex, ${SignedContextV1}[] signedContext)` as const;
export const TakeOrdersConfigV5 =
`(${Float} minimumInput, ${Float} maximumInput, ${Float} maximumIORatio, ${TakeOrderConfigV4}[] orders, bytes data)` as const;
export const OrderConfigV4 =
`(${EvaluableV4} evaluable, ${IOV2}[] validInputs, ${IOV2}[] validOutputs, bytes32 nonce, bytes32 secret, bytes meta)` as const;
export const ClearConfigV2 =
"(uint256 aliceInputIOIndex, uint256 aliceOutputIOIndex, uint256 bobInputIOIndex, uint256 bobOutputIOIndex, bytes32 aliceBountyVaultId, bytes32 bobBountyVaultId)" as const;

// signatures
export const Orderbook = [
`event OrderNotFound(address sender, address owner, bytes32 orderHash)` as const,
`event AddOrderV3(address sender, bytes32 orderHash, ${OrderV4} order)` as const,
`event OrderZeroAmount(address sender, address owner, bytes32 orderHash)` as const,
`event RemoveOrderV3(address sender, bytes32 orderHash, ${OrderV4} order)` as const,
`event AfterClearV2(address sender, ${ClearStateChangeV2} clearStateChange)` as const,
`event OrderExceedsMaxRatio(address sender, address owner, bytes32 orderHash)` as const,
`event DepositV2(address sender, address token, bytes32 vaultId, uint256 depositAmountUint256)` as const,
`event ClearV3(address sender, ${OrderV4} alice, ${OrderV4} bob, ${ClearConfigV2} clearConfig)` as const,
`event TakeOrderV3(address sender, ${TakeOrderConfigV4} config, ${Float} input, ${Float} output)` as const,
`event WithdrawV2(address sender, address token, bytes32 vaultId, ${Float} targetAmount, ${Float} withdrawAmount, uint256 withdrawAmountUint256)` as const,
`function entask2(${TaskV2}[] calldata tasks) external` as const,
`function orderExists(bytes32 orderHash) external view returns (bool exists)` as const,
`function vaultBalance2(address owner, address token, bytes32 vaultId) external view returns (${Float} balance)` as const,
`function deposit3(address token, bytes32 vaultId, ${Float} depositAmount, ${TaskV2}[] calldata tasks) external` as const,
`function withdraw3(address token, bytes32 vaultId, ${Float} targetAmount, ${TaskV2}[] calldata tasks) external` as const,
`function removeOrder3(${OrderV4} calldata order, ${TaskV2}[] calldata tasks) external returns (bool stateChanged)` as const,
`function addOrder4(${OrderConfigV4} calldata config, ${TaskV2}[] calldata tasks) external returns (bool stateChanged)` as const,
`function quote2(${QuoteV2} calldata quoteConfig) external view returns (bool exists, ${Float} outputMax, ${Float} ioRatio)` as const,
`function takeOrders4(${TakeOrdersConfigV5} calldata config) external returns (${Float} totalTakerInput, ${Float} totalTakerOutput)` as const,
`function clear3(${OrderV4} memory alice, ${OrderV4} memory bob, ${ClearConfigV2} calldata clearConfig, ${SignedContextV1}[] memory aliceSignedContext, ${SignedContextV1}[] memory bobSignedContext) external` as const,
"function multicall(bytes[] calldata data) external returns (bytes[] memory results)",
] as const;
export const Arb = [
"function iRouteProcessor() external view returns (address)",
`function arb5(address orderBook, ${TakeOrdersConfigV5} calldata takeOrders, ${TaskV2} calldata task) external payable`,
// `function arb4(address orderBook, ${TakeOrdersConfigV5} calldata startTakeOrders, ${TakeOrdersConfigV5} calldata endTakeOrders, bytes calldata exchangeData, ${TaskV2} calldata task) external payable`,
] as const;
}
Comment on lines +103 to +154
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for Solidity sources and ABI files related to V6 orderbook/arb
find . -type f \( -name "*.sol" -o -name "*.json" \) | head -30

Repository: rainlanguage/rain.solver

Length of output: 1021


🏁 Script executed:

# Search for V6-related content in Solidity and ABI files
rg -l "addOrder4|takeOrders4|arb5" -g "*.sol" -g "*.json" -g "*.ts" | head -20

Repository: rainlanguage/rain.solver

Length of output: 240


🏁 Script executed:

# Look for OrderBook contract definitions
rg -l "contract.*OrderBook|contract.*Orderbook" -g "*.sol" | head -10

Repository: rainlanguage/rain.solver

Length of output: 50


🏁 Script executed:

# Search for specific function definitions in the codebase
rg "function\s+(addOrder4|takeOrders4|arb5)" -A 3 -g "*.sol"

Repository: rainlanguage/rain.solver

Length of output: 50


🏁 Script executed:

# Search for V6 usage throughout the codebase
rg "_v6" -n

Repository: rainlanguage/rain.solver

Length of output: 1617


🏁 Script executed:

# Check the OrderbookAbi definition and its exports
rg "OrderbookAbi" -A 10 -B 2 -n | head -50

Repository: rainlanguage/rain.solver

Length of output: 2123


🏁 Script executed:

# Look at the complete orderbook.ts file structure
cat -n src/common/abis/orderbook.ts | grep -E "^[[:space:]]*[0-9]+(.*namespace|.*export const|.*V[0-9])" | head -40

Repository: rainlanguage/rain.solver

Length of output: 3707


🏁 Script executed:

# Search for any reference to addOrder4 or takeOrders4 outside orderbook.ts
rg "addOrder4|takeOrders4" -n --type ts --type tsx

Repository: rainlanguage/rain.solver

Length of output: 95


🏁 Script executed:

# Search for addOrder4 and takeOrders4 in TypeScript files only
rg "addOrder4|takeOrders4" -n --type ts

Repository: rainlanguage/rain.solver

Length of output: 674


🏁 Script executed:

# Check if V6 is actually being used in the codebase
rg "OrderbookAbi\.V6" -n --type ts

Repository: rainlanguage/rain.solver

Length of output: 50


🏁 Script executed:

# Look for test files that might reference V6
find . -type f -name "*.test.ts" | xargs grep -l "V6\|_v6" 2>/dev/null

Repository: rainlanguage/rain.solver

Length of output: 230


🏁 Script executed:

# Get the full _v6 namespace definition to inspect the signatures
sed -n '103,154p' src/common/abis/orderbook.ts

Repository: rainlanguage/rain.solver

Length of output: 4704


🏁 Script executed:

# Check the V6 ABI export section in detail
sed -n '249,293p' src/common/abis/orderbook.ts

Repository: rainlanguage/rain.solver

Length of output: 1868


🏁 Script executed:

# Check which Orderbook ABI version is being used in simulate.ts
sed -n '500,530p' src/core/modes/inter/simulate.ts

Repository: rainlanguage/rain.solver

Length of output: 1262


🏁 Script executed:

# Check the full context of takeOrders4 usage in simulate.ts
sed -n '500,550p' src/core/modes/inter/simulate.ts | cat -n

Repository: rainlanguage/rain.solver

Length of output: 2432


🏁 Script executed:

# Check for any imports or version selection logic in simulate.ts
head -100 src/core/modes/inter/simulate.ts | grep -E "import|OrderbookAbi|version"

Repository: rainlanguage/rain.solver

Length of output: 718


🏁 Script executed:

# Look for where the Orderbook version is determined/set
rg "OrderbookAbi\." src/core/modes/inter/simulate.ts -A 2 -B 2 | head -40

Repository: rainlanguage/rain.solver

Length of output: 50


🏁 Script executed:

# Check if V6 is actually exported from orderbook.ts
rg "export.*V6" src/common/abis/orderbook.ts

Repository: rainlanguage/rain.solver

Length of output: 93


🏁 Script executed:

# Look at the exact TakeOrdersConfigV5 struct definition and compare with usage
sed -n '115,120p' src/common/abis/orderbook.ts

Repository: rainlanguage/rain.solver

Length of output: 540


🏁 Script executed:

# Check the actual args structure being passed in simulate.ts more carefully
sed -n '505,530p' src/core/modes/inter/simulate.ts

Repository: rainlanguage/rain.solver

Length of output: 1036


🏁 Script executed:

# Search for any type definitions related to TakeOrdersConfigV5 in the codebase
rg "TakeOrdersConfigV5|TakeOrdersConfigType" -A 5 -B 2 --type ts | head -80

Repository: rainlanguage/rain.solver

Length of output: 4612


🏁 Script executed:

# Check if there's a mapping or transformation of field names somewhere
rg "minimumIO|maximumIO|IOIsInput" -B 3 -A 3 --type ts | head -60

Repository: rainlanguage/rain.solver

Length of output: 3707


🏁 Script executed:

# Look for TakeOrdersConfigTypeV5 type definition
rg "interface TakeOrdersConfigTypeV5|type TakeOrdersConfigTypeV5" -A 10 --type ts

Repository: rainlanguage/rain.solver

Length of output: 592


🏁 Script executed:

# Check if there's a mismatch between ABI definition and actual struct usage
sed -n '115,120p' src/common/abis/orderbook.ts && echo "---ABI Definition Above---" && rg "TakeOrdersConfigTypeV5 = " -A 7 src/router/types.ts

Repository: rainlanguage/rain.solver

Length of output: 885


🏁 Script executed:

# Get the complete TakeOrdersConfigTypeV5 type definition from order/index.ts or where it's defined
rg -l "TakeOrdersConfigTypeV5" --type ts | xargs cat | grep -A 15 "type TakeOrdersConfigTypeV5\|interface TakeOrdersConfigTypeV5"

Repository: rainlanguage/rain.solver

Length of output: 467


🏁 Script executed:

# Check the order/index.ts file for type definitions
find . -path "./src/order/*" -name "*.ts" | head -10

Repository: rainlanguage/rain.solver

Length of output: 312


🏁 Script executed:

# Verify the exact ABI string definition once more to be absolutely sure
sed -n '103,154p' src/common/abis/orderbook.ts | grep -A 1 "TakeOrdersConfigV5"

Repository: rainlanguage/rain.solver

Length of output: 980


🏁 Script executed:

# Check how encodeFunctionData is being called with the mismatched struct
sed -n '510,530p' src/core/modes/inter/simulate.ts

Repository: rainlanguage/rain.solver

Length of output: 852


🏁 Script executed:

# Look for any other V5/V6 structs that might have similar field name mismatches
rg "minimumInput|maximumInput" src/order/types/ --type ts

Repository: rainlanguage/rain.solver

Length of output: 388


🏁 Script executed:

# Check if the ABI definitions for V4 and V5 have the correct field names for comparison
sed -n '1,102p' src/common/abis/orderbook.ts | tail -30

Repository: rainlanguage/rain.solver

Length of output: 3030


🏁 Script executed:

# Double-check the V5 namespace to see the pattern for comparison
sed -n '50,102p' src/common/abis/orderbook.ts | grep -E "export const (TakeOrdersConfigV4|TaskV2|OrderV4)" -A 2

Repository: rainlanguage/rain.solver

Length of output: 706


🏁 Script executed:

# Verify if the struct encoding works at runtime by checking test files
rg "takeOrders4" src/core/modes/inter/simulate.test.ts -B 5 -A 10 | head -40

Repository: rainlanguage/rain.solver

Length of output: 1538


Fix V6 ABI struct field names to match TypeScript type definitions.

The TakeOrdersConfigV5 struct in the V6 namespace has a critical mismatch: the ABI string defines fields as minimumInput and maximumInput, but the TypeScript type (TakeOrdersConfigTypeV5 in src/order/types/v4.ts) uses minimumIO, maximumIO, and includes an IOIsInput boolean field. When encodeFunctionData attempts to encode the struct for takeOrders4() and arb5() calls, it will fail to match ABI field names to the provided arguments, breaking calldata encoding at runtime.

Update line 119 to:

export const TakeOrdersConfigV5 = 
  `(${Float} minimumIO, ${Float} maximumIO, ${Float} maximumIORatio, bool IOIsInput, ${TakeOrderConfigV4}[] orders, bytes data)` as const;
🤖 Prompt for AI Agents
In `@src/common/abis/orderbook.ts` around lines 103 - 154, The TakeOrdersConfigV5
ABI struct fields in namespace _v6 (symbol TakeOrdersConfigV5) don't match the
TypeScript type (TakeOrdersConfigTypeV5) — update the ABI string for
TakeOrdersConfigV5 to use minimumIO, maximumIO, maximumIORatio, add the bool
IOIsInput field, then orders and data (i.e. `(${Float} minimumIO, ${Float}
maximumIO, ${Float} maximumIORatio, bool IOIsInput, ${TakeOrderConfigV4}[]
orders, bytes data)`) so calldata encoding for takeOrders4 and arb5 will align
with the TypeScript types.


/** Keeps Orderbook v4 and v5 related ABIs */
export namespace OrderbookAbi {
export namespace V4 {
Expand Down Expand Up @@ -192,4 +245,50 @@ export namespace OrderbookAbi {
bytecode: "0x",
} as const;
}

export namespace V6 {
/** Orderbook and Arb contracts primary parsed ABIs */
export namespace Primary {
/** Arb contract ABI */
export const Arb = parseAbi(_v6.Arb);

/** Orderbook v4 contract ABI */
export const Orderbook = parseAbi(_v6.Orderbook);

/** Order v4 struct ABI */
export const OrderStructAbi = parseAbiParameters(_v6.OrderV4);
}

/** Orderbook v4 structs */
export namespace Structs {
export const Float = _v6.Float;
export const IO = _v6.IOV2;
export const Evaluable = _v6.EvaluableV4;
export const SignedContext = _v6.SignedContextV1;
export const Task = _v6.TaskV2;
export const ClearStateChange = _v6.ClearStateChangeV2;
export const Order = _v6.OrderV4;
export const TakeOrderConfig = _v6.TakeOrderConfigV4;
export const OrderConfig = _v6.OrderConfigV4;
export const TakeOrdersConfig = _v6.TakeOrdersConfigV5;
export const ClearConfig = _v6.ClearConfigV2;
export const Quote = _v6.QuoteV2;
}

/** Signature ABI for Orderbook v4 and Arb contracts */
export namespace Signatures {
/** Signature ABI for Orderbook contract only including vaultBalance() function */
export const Orderbook = _v6.Orderbook;

/** Signature ABI for Arb contract */
export const Arb = _v6.Arb;
}

// an empty evaluable mainly used as default evaluable for arb contracts
export const DefaultArbEvaluable = {
interpreter: "0x" + "0".repeat(40),
store: "0x" + "0".repeat(40),
bytecode: "0x",
} as const;
}
}
36 changes: 36 additions & 0 deletions src/config/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,27 @@ export namespace Validator {
"stabullArbAddress v5",
true,
);
const dispairV6 = resolveAddress(input?.contracts?.v6?.dispair, "dispair v6", true);
const sushiArbAddressV6 = resolveAddress(
input?.contracts?.v6?.sushiArbAddress,
"sushiArbAddress v6",
true,
);
const genericArbAddressV6 = resolveAddress(
input?.contracts?.v6?.genericArbAddress,
"genericArbAddress v6",
true,
);
const balancerArbAddressV6 = resolveAddress(
input?.contracts?.v6?.balancerArbAddress,
"balancerArbAddress v6",
true,
);
const stabullArbAddressV6 = resolveAddress(
input?.contracts?.v6?.stabullArbAddress,
"stabullArbAddress v6",
true,
);
const contracts: AppOptionsContracts = {};
if (
dispairV4 ||
Expand Down Expand Up @@ -543,6 +564,21 @@ export namespace Validator {
stabullArb: stabullArbAddressV5 as `0x${string}` | undefined,
};
}
if (
dispairV6 ||
sushiArbAddressV6 ||
genericArbAddressV6 ||
balancerArbAddressV6 ||
stabullArbAddressV6
) {
contracts.v6 = {
sushiArb: sushiArbAddressV6 as `0x${string}` | undefined,
dispair: dispairV6 as `0x${string}` | undefined,
genericArb: genericArbAddressV6 as `0x${string}` | undefined,
balancerArb: balancerArbAddressV6 as `0x${string}` | undefined,
stabullArb: stabullArbAddressV6 as `0x${string}` | undefined,
};
}
return contracts;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/config/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export type AppOptionsContracts = {
balancerArb?: `0x${string}`;
stabullArb?: `0x${string}`;
};
v6?: {
sushiArb?: `0x${string}`;
dispair?: `0x${string}`;
genericArb?: `0x${string}`;
balancerArb?: `0x${string}`;
stabullArb?: `0x${string}`;
};
};

/** Rain Solver app yaml configurations */
Expand Down
Loading
Loading