Skip to content

Gradient strategy support#337

Open
zavelevsky wants to merge 22 commits into
mainfrom
gradient-support
Open

Gradient strategy support#337
zavelevsky wants to merge 22 commits into
mainfrom
gradient-support

Conversation

@zavelevsky

@zavelevsky zavelevsky commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

missing: trading through gradient strategies, and using batcher to trade through both types of strategies

const EXP_ONE_DIV_RR = EXP_ONE / RR; // = 2 ^ 31
const EXP_ONE_DIV_MM = EXP_ONE / MM; // = 2 ^ 79

enum GradientType {

@GrandSchtroumpf GrandSchtroumpf Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +31 to +32
LINEAR_INCREASE,
LINEAR_DECREASE,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couldn't Linear_Increase and Linear_Decrease be derived from startPrice and endPrice ? So we would only have LINEAR, LINEAR_INV or EXPONENTIAL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this simply reflects the contracts API

if (new Decimal(budget).isNegative()) {
throw new Error('budgets cannot be negative');
}
if (endTime <= startTime) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't endTime === 0 && startTime === 0 a valid value (empty order) ?

token0,
token1,
strategies.map(encodedStrategyStrToBN),
(parsedCache.gradientStrategiesByPair[key] ?? []).map(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we make the field gradientStrategiesByPair optional ? It would prevent app with existing cache to break

@GrandSchtroumpf

Copy link
Copy Markdown
Collaborator

When trying to create a strategy I get this error:

SyntaxError: Cannot convert NaN to a BigInt

Logs:
"[SDK][Toolkit.ts]: createBuySellGradientStrategy called"

{
    "0": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
    "1": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "2": "0",
    "3": "0",
    "4": "0",
    "5": 1,
    "6": 0,
    "7": 1000000000,
    "8": "2540.121098406958",
    "9": "2332.2930085372978",
    "10": "1",
    "11": 1,
    "12": 1776729600,
    "13": 1778457600
}

for the value 7, I set a date bigger than 0 to avoid the error where endTime is equal to stateTime

@barakman

Copy link
Copy Markdown
Collaborator
    "2": "0",
    "3": "0",
    "4": "0",

When the rates of an order are all but zero (typically in a strategy where only the other order is valid), you should avoid encoding it

@zavelevsky

Copy link
Copy Markdown
Contributor Author

add gradientTradingFeePPMByPair as gradient pairs can have their own fees

@zavelevsky

Copy link
Copy Markdown
Contributor Author

Wrong handling the startTime/endTime terminology - it should be translated to startTime and expiry, where expiry is calculated from end - start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants