Skip to content
Merged
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
2 changes: 2 additions & 0 deletions config.env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ contracts:
sushiArbAddress: $ARB_ADDRESS
genericArbAddress: $GENERIC_ARB_ADDRESS
balancerArbAddress: $BALANCER_ARB_ADDRESS
stabullArbAddress: $STABULL_ARB_ADDRESS
dispair: $DISPAIR
v5:
sushiArbAddress: $ARB_ADDRESS_V5
genericArbAddress: $GENERIC_ARB_ADDRESS_V5
balancerArbAddress: $BALANCER_ARB_ADDRESS_V5
stabullArbAddress: $STABULL_ARB_ADDRESS_V5
dispair: $DISPAIR_V5
liquidityProviders: $LIQUIDITY_PROVIDERS
route: $ROUTE
Expand Down
4 changes: 4 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ contracts:
genericArbAddress: "0x1234...5678"
# Balancer arb v4 contract address
balancerArbAddress: "0x1234...5678"
# Stabull arb v4 contract address
stabullArbAddress: "0x1234...5678"
# Dispair v4 contract address
dispair: "0x1234...5678"
v5:
Expand All @@ -55,6 +57,8 @@ contracts:
genericArbAddress: "0x1234...5678"
# Balancer arb v5 contract address
balancerArbAddress: "0x1234...5678"
# Stabull arb v5 contract address
stabullArbAddress: "0x1234...5678"
# Dispair v5 contract address
dispair: "0x1234...5678"

Expand Down
2 changes: 2 additions & 0 deletions src/common/abis/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { StabullAbi } from "./stabull";
import { RouteProcessorAbi } from "./rp";
import { DeployerAbi } from "./deployer";
import { OrderbookAbi } from "./orderbook";
Expand All @@ -8,6 +9,7 @@ import { ArbitrumNodeInterfaceAbi } from "./arbitrum";

/** Keeps all necesdsary ABIs for rain solver app */
export namespace ABI {
export import Stabull = StabullAbi;
export import Deployer = DeployerAbi;
export import Orderbook = OrderbookAbi;
export import Multicall3 = Multicall3Abi;
Expand Down
54 changes: 54 additions & 0 deletions src/common/abis/stabull.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** Keeps Stabull protocol related ABIs */
export namespace StabullAbi {
/** Stabull primary contracts */
export namespace Primary {
/** Stabull Router contract ABI */
export const Router = [
{
inputs: [],
name: "factory",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "_quoteCurrency", type: "address" },
{ internalType: "address", name: "_origin", type: "address" },
{ internalType: "address", name: "_target", type: "address" },
{ internalType: "uint256", name: "_originAmount", type: "uint256" },
{ internalType: "uint256", name: "_minTargetAmount", type: "uint256" },
{ internalType: "uint256", name: "_deadline", type: "uint256" },
],
name: "originSwap",
outputs: [{ internalType: "uint256", name: "targetAmount_", type: "uint256" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "_quoteCurrency", type: "address" },
{ internalType: "address", name: "_origin", type: "address" },
{ internalType: "address", name: "_target", type: "address" },
{ internalType: "uint256", name: "_originAmount", type: "uint256" },
],
name: "viewOriginSwap",
outputs: [{ internalType: "uint256", name: "targetAmount_", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "_quoteCurrency", type: "address" },
{ internalType: "address", name: "_origin", type: "address" },
{ internalType: "address", name: "_target", type: "address" },
{ internalType: "uint256", name: "_targetAmount", type: "uint256" },
],
name: "viewTargetSwap",
outputs: [{ internalType: "uint256", name: "originAmount_", type: "uint256" }],
stateMutability: "view",
type: "function",
},
] as const;
}
}
28 changes: 26 additions & 2 deletions src/config/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ export namespace Validator {
"balancerArbAddress v4",
true,
);
const stabullArbAddressV4 = resolveAddress(
input?.contracts?.v4?.stabullArbAddress,
"stabullArbAddress v4",
true,
);
const dispairV5 = resolveAddress(input?.contracts?.v5?.dispair, "dispair v5", true);
const sushiArbAddressV5 = resolveAddress(
input?.contracts?.v5?.sushiArbAddress,
Expand All @@ -502,21 +507,40 @@ export namespace Validator {
"balancerArbAddress v5",
true,
);
const stabullArbAddressV5 = resolveAddress(
input?.contracts?.v5?.stabullArbAddress,
"stabullArbAddress v5",
true,
);
const contracts: AppOptionsContracts = {};
if (dispairV4 || sushiArbAddressV4 || genericArbAddressV4 || balancerArbAddressV4) {
if (
dispairV4 ||
sushiArbAddressV4 ||
genericArbAddressV4 ||
balancerArbAddressV4 ||
stabullArbAddressV4
) {
contracts.v4 = {
sushiArb: sushiArbAddressV4 as `0x${string}` | undefined,
dispair: dispairV4 as `0x${string}` | undefined,
genericArb: genericArbAddressV4 as `0x${string}` | undefined,
balancerArb: balancerArbAddressV4 as `0x${string}` | undefined,
stabullArb: stabullArbAddressV4 as `0x${string}` | undefined,
};
}
if (dispairV5 || sushiArbAddressV5 || genericArbAddressV5 || balancerArbAddressV5) {
if (
dispairV5 ||
sushiArbAddressV5 ||
genericArbAddressV5 ||
balancerArbAddressV5 ||
stabullArbAddressV5
) {
contracts.v5 = {
sushiArb: sushiArbAddressV5 as `0x${string}` | undefined,
dispair: dispairV5 as `0x${string}` | undefined,
genericArb: genericArbAddressV5 as `0x${string}` | undefined,
balancerArb: balancerArbAddressV5 as `0x${string}` | undefined,
stabullArb: stabullArbAddressV5 as `0x${string}` | undefined,
};
}
return contracts;
Expand Down
2 changes: 2 additions & 0 deletions src/config/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contracts:
sushiArbAddress: "0x1111111111111111111111111111111111111111"
balancerArbAddress: "0x3333333333333333333333333333333333333333"
dispair: "0x2222222222222222222222222222222222222222"
stabullArbAddress: "0x4444444444444444444444444444444444444444"
liquidityProviders:
- lp1
- lp2
Expand Down Expand Up @@ -90,6 +91,7 @@ orderbookTradeTypes:
balancerArb: "0x3333333333333333333333333333333333333333",
dispair: "0x2222222222222222222222222222222222222222",
genericArb: undefined,
stabullArb: "0x4444444444444444444444444444444444444444",
},
},
liquidityProviders: ["lp1", "lp2"],
Expand Down
2 changes: 2 additions & 0 deletions src/config/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ export type AppOptionsContracts = {
dispair?: `0x${string}`;
genericArb?: `0x${string}`;
balancerArb?: `0x${string}`;
stabullArb?: `0x${string}`;
};
v5?: {
sushiArb?: `0x${string}`;
dispair?: `0x${string}`;
genericArb?: `0x${string}`;
balancerArb?: `0x${string}`;
stabullArb?: `0x${string}`;
};
};

Expand Down
24 changes: 15 additions & 9 deletions src/core/modes/router/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type SimulateRouterTradeArgs = {

/** Arguments for preparing router trade type parameters required for simulation and building tx object */
export type RouterTradePreparedParams = {
type: TradeType.Router | TradeType.Balancer | TradeType.RouteProcessor;
type: TradeType.Router | TradeType.Balancer | TradeType.RouteProcessor | TradeType.Stabull;
rawtx: RawTransaction;
price: bigint;
minimumExpected: bigint;
Expand Down Expand Up @@ -118,15 +118,21 @@ export class RouterTradeSimulator extends TradeSimulatorBase {
takeOrdersConfigStruct,
} = tradeParamsResult.value;

// determine trade type based on router type
// determine trade type based on route type
let type = TradeType.Router;
if (routeType === RouterType.Sushi) {
type = TradeType.RouteProcessor;
} else if (routeType === RouterType.Balancer) {
type = TradeType.Balancer;
} else {
// unreachable path
type = TradeType.Router;
switch (routeType) {
case RouterType.Sushi: {
type = TradeType.RouteProcessor;
break;
}
case RouterType.Balancer: {
type = TradeType.Balancer;
break;
}
case RouterType.Stabull: {
type = TradeType.Stabull;
break;
}
}

this.spanAttributes["amountOut"] = formatUnits(quote.amountOut, toToken.decimals);
Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum TradeType {
InterOrderbook = "interOrderbook",
Balancer = "balancer",
Router = "router",
Stabull = "stabull",
}

/** Base type for process order results containing shared fields */
Expand Down
11 changes: 10 additions & 1 deletion src/router/error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { RainSolverBaseError } from "../error";
import { SushiRouterError } from "./sushi/error";
import { BalancerRouterError } from "./balancer/error";
import { StabullRouterError } from "./stabull/error";

// re-export all error types from sushi and balancer
// re-export all error types from sushi, balancer and stabull
export * from "./sushi/error";
export * from "./stabull/error";
export * from "./balancer/error";

/** Enumerates the possible error types that can occur within the RainSolverRouter functionalities */
Expand All @@ -28,11 +30,14 @@ export class RainSolverRouterError extends RainSolverBaseError {
typ?: RainSolverRouterErrorType;
sushiError?: SushiRouterError;
balancerError?: BalancerRouterError;
stabullError?: StabullRouterError;

constructor(
message: string,
type: RainSolverRouterErrorType,
sushiError?: SushiRouterError,
balancerError?: BalancerRouterError,
stabullError?: StabullRouterError,
) {
const msgs = [message];
if (sushiError) {
Expand All @@ -41,10 +46,14 @@ export class RainSolverRouterError extends RainSolverBaseError {
if (balancerError) {
msgs.push(`BalancerRouterError: ${balancerError.message}`);
}
if (stabullError) {
msgs.push(`StabullRouterError: ${stabullError.message}`);
}
super(msgs.join("\n"));
this.typ = type;
this.sushiError = sushiError;
this.balancerError = balancerError;
this.stabullError = stabullError;
this.name = "RainSolverRouterError";
}
}
Loading