Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 0 deletions config.env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contracts:
genericArbAddress: $GENERIC_ARB_ADDRESS_V6
balancerArbAddress: $BALANCER_ARB_ADDRESS_V6
stabullArbAddress: $STABULL_ARB_ADDRESS_V6
raindexArbAddress: $RAINDEX_ARB_ADDRESS_V6
dispair: $DISPAIR_V6
liquidityProviders: $LIQUIDITY_PROVIDERS
route: $ROUTE
Expand Down Expand Up @@ -51,3 +52,4 @@ orderbookTradeTypes:
router: $ROUTER_ENABLED_ORDERBOOKS
interOrderbook: $INTER_ENABLED_ORDERBOOKS
intraOrderbook: $INTRA_ENABLED_ORDERBOOKS
raindexRouter: $RAINDEX_ENABLED_ORDERBOOKS
6 changes: 6 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ contracts:
balancerArbAddress: "0x1234...5678"
# Stabull arb v6 contract address
stabullArbAddress: "0x1234...5678"
# Raindex Router arb v6 contract address
raindexArbAddress: "0x1234...5678"
# Dispair v6 contract address
dispair: "0x1234...5678"

Expand Down Expand Up @@ -192,3 +194,7 @@ orderbookTradeTypes:
intraOrderbook:
- "0xabcd..."
- "0x1234..."
# Enable raindex router trades for the given orderbooks
raindexRouter:
- "0xabcd..."
- "0x1234..."
6 changes: 5 additions & 1 deletion src/common/abis/orderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export namespace _v6 {
`(${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;
export const RouteLeg = `(uint8 routeLegType, address destination, bytes data)[]`;
Comment thread
rouzwelt marked this conversation as resolved.

// signatures
export const Orderbook = [
Expand Down Expand Up @@ -149,7 +150,7 @@ export namespace _v6 {
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`,
`function arb4(address orderBook, ${TakeOrdersConfigV5}[] calldata startTakeOrders, bytes calldata exchangeData, ${TaskV2} calldata task) external payable`,
] as const;
Comment thread
rouzwelt marked this conversation as resolved.
}

Expand Down Expand Up @@ -257,6 +258,8 @@ export namespace OrderbookAbi {

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

export const RouteLeg = parseAbiParameters(_v6.RouteLeg);
}

/** Orderbook v4 structs */
Expand All @@ -273,6 +276,7 @@ export namespace OrderbookAbi {
export const TakeOrdersConfig = _v6.TakeOrdersConfigV5;
export const ClearConfig = _v6.ClearConfigV2;
export const Quote = _v6.QuoteV2;
export const RouteLeg = _v6.RouteLeg;
}

/** Signature ABI for Orderbook v4 and Arb contracts */
Expand Down
311 changes: 311 additions & 0 deletions src/config/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,317 @@ describe("Test yaml Validator methods", async function () {
"unexpected error",
);
});

it("test Validator resolveContracts", async function () {
const sushiArbV4 = `0x${"1".repeat(40)}`;
const dispairV4 = `0x${"2".repeat(40)}`;
const genericArbV4 = `0x${"3".repeat(40)}`;
const balancerArbV4 = `0x${"4".repeat(40)}`;
const stabullArbV4 = `0x${"5".repeat(40)}`;

const sushiArbV5 = `0x${"6".repeat(40)}`;
const dispairV5 = `0x${"7".repeat(40)}`;
const genericArbV5 = `0x${"8".repeat(40)}`;
const balancerArbV5 = `0x${"9".repeat(40)}`;
const stabullArbV5 = `0x${"a".repeat(40)}`;

const sushiArbV6 = `0x${"b".repeat(40)}`;
const dispairV6 = `0x${"c".repeat(40)}`;
const genericArbV6 = `0x${"d".repeat(40)}`;
const balancerArbV6 = `0x${"e".repeat(40)}`;
const stabullArbV6 = `0x${"f".repeat(40)}`;
const raindexArbV6 = `0x${"1".repeat(39)}1`;

// happy path: all v4 contracts provided
let input: any = {
contracts: {
v4: {
sushiArbAddress: sushiArbV4,
dispair: dispairV4,
genericArbAddress: genericArbV4,
balancerArbAddress: balancerArbV4,
stabullArbAddress: stabullArbV4,
},
},
};
let result = Validator.resolveContracts(input);
let expected: any = {
v4: {
sushiArb: sushiArbV4 as `0x${string}`,
dispair: dispairV4 as `0x${string}`,
genericArb: genericArbV4 as `0x${string}`,
balancerArb: balancerArbV4 as `0x${string}`,
stabullArb: stabullArbV4 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// happy path: all v5 contracts provided
input = {
contracts: {
v5: {
sushiArbAddress: sushiArbV5,
dispair: dispairV5,
genericArbAddress: genericArbV5,
balancerArbAddress: balancerArbV5,
stabullArbAddress: stabullArbV5,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v5: {
sushiArb: sushiArbV5 as `0x${string}`,
dispair: dispairV5 as `0x${string}`,
genericArb: genericArbV5 as `0x${string}`,
balancerArb: balancerArbV5 as `0x${string}`,
stabullArb: stabullArbV5 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// happy path: all v6 contracts provided including raindex
input = {
contracts: {
v6: {
sushiArbAddress: sushiArbV6,
dispair: dispairV6,
genericArbAddress: genericArbV6,
balancerArbAddress: balancerArbV6,
stabullArbAddress: stabullArbV6,
raindexArbAddress: raindexArbV6,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v6: {
sushiArb: sushiArbV6 as `0x${string}`,
dispair: dispairV6 as `0x${string}`,
genericArb: genericArbV6 as `0x${string}`,
balancerArb: balancerArbV6 as `0x${string}`,
stabullArb: stabullArbV6 as `0x${string}`,
raindexArb: raindexArbV6 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// happy path: mix of v4, v5, and v6 contracts
input = {
contracts: {
v4: {
sushiArbAddress: sushiArbV4,
dispair: dispairV4,
},
v5: {
genericArbAddress: genericArbV5,
},
v6: {
balancerArbAddress: balancerArbV6,
raindexArbAddress: raindexArbV6,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v4: {
sushiArb: sushiArbV4 as `0x${string}`,
dispair: dispairV4 as `0x${string}`,
genericArb: undefined,
balancerArb: undefined,
stabullArb: undefined,
},
v5: {
sushiArb: undefined,
dispair: undefined,
genericArb: genericArbV5 as `0x${string}`,
balancerArb: undefined,
stabullArb: undefined,
},
v6: {
sushiArb: undefined,
dispair: undefined,
genericArb: undefined,
balancerArb: balancerArbV6 as `0x${string}`,
stabullArb: undefined,
raindexArb: raindexArbV6 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// happy path: partial v4 contracts
input = {
contracts: {
v4: {
sushiArbAddress: sushiArbV4,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v4: {
sushiArb: sushiArbV4 as `0x${string}`,
dispair: undefined,
genericArb: undefined,
balancerArb: undefined,
stabullArb: undefined,
},
};
assert.deepEqual(result, expected);

// happy path: partial v5 contracts
input = {
contracts: {
v5: {
dispair: dispairV5,
balancerArbAddress: balancerArbV5,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v5: {
sushiArb: undefined,
dispair: dispairV5 as `0x${string}`,
genericArb: undefined,
balancerArb: balancerArbV5 as `0x${string}`,
stabullArb: undefined,
},
};
assert.deepEqual(result, expected);

// happy path: partial v6 contracts
input = {
contracts: {
v6: {
raindexArbAddress: raindexArbV6,
},
},
};
result = Validator.resolveContracts(input);
expected = {
v6: {
sushiArb: undefined,
dispair: undefined,
genericArb: undefined,
balancerArb: undefined,
stabullArb: undefined,
raindexArb: raindexArbV6 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// happy path: no contracts provided (empty object returned)
input = {};
result = Validator.resolveContracts(input);
expected = {};
assert.deepEqual(result, expected);

// happy path: contracts object exists but no versions provided
input = { contracts: {} };
result = Validator.resolveContracts(input);
expected = {};
assert.deepEqual(result, expected);

// happy path: using env variables for v4
process.env.SUSHI_ARB_V4 = sushiArbV4;
process.env.DISPAIR_V4 = dispairV4;
input = {
contracts: {
v4: {
sushiArbAddress: "$SUSHI_ARB_V4",
dispair: "$DISPAIR_V4",
},
},
};
result = Validator.resolveContracts(input);
expected = {
v4: {
sushiArb: sushiArbV4 as `0x${string}`,
dispair: dispairV4 as `0x${string}`,
genericArb: undefined,
balancerArb: undefined,
stabullArb: undefined,
},
};
assert.deepEqual(result, expected);

// happy path: using env variables for v6 including raindex
process.env.RAINDEX_ARB_V6 = raindexArbV6;
process.env.BALANCER_ARB_V6 = balancerArbV6;
input = {
contracts: {
v6: {
raindexArbAddress: "$RAINDEX_ARB_V6",
balancerArbAddress: "$BALANCER_ARB_V6",
},
},
};
result = Validator.resolveContracts(input);
expected = {
v6: {
sushiArb: undefined,
dispair: undefined,
genericArb: undefined,
balancerArb: balancerArbV6 as `0x${string}`,
stabullArb: undefined,
raindexArb: raindexArbV6 as `0x${string}`,
},
};
assert.deepEqual(result, expected);

// unhappy: invalid address format for v4 sushiArbAddress
input = {
contracts: {
v4: {
sushiArbAddress: "invalid_address",
},
},
};
assert.throws(
() => Validator.resolveContracts(input),
"expected valid sushiArbAddress v4 contract address",
);

// unhappy: invalid address format for v5 dispair
input = {
contracts: {
v5: {
dispair: "0x123", // too short
},
},
};
assert.throws(
() => Validator.resolveContracts(input),
"expected valid dispair v5 contract address",
);

// unhappy: invalid address format for v6 raindexArbAddress
input = {
contracts: {
v6: {
raindexArbAddress: "not_an_address",
},
},
};
assert.throws(
() => Validator.resolveContracts(input),
"expected valid raindexArbAddress v6 contract address",
);

// unhappy: undefined env variable
delete process.env.UNDEFINED_CONTRACT;
input = {
contracts: {
v4: {
sushiArbAddress: "$UNDEFINED_CONTRACT",
},
},
};
result = Validator.resolveContracts(input);
expected = {};
assert.deepEqual(result, expected);
});
});

describe("Test yaml Validator helpers", async function () {
Expand Down
Loading
Loading