Skip to content

Commit e88fa1d

Browse files
Merge pull request #6 from SteerProtocol/update/interface
Update/interface
2 parents 7b3390f + af03954 commit e88fa1d

14 files changed

Lines changed: 4413 additions & 12755 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

.github/workflows/nodejs.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ jobs:
2929
- name: Perform tests
3030
run: yarn test
3131

32-
- name: Create the docs directory locally in CI
33-
run: yarn docs
32+
# - name: Create the docs directory locally in CI
33+
# run: yarn docs
3434

3535
- name: Release
3636
run: npx semantic-release
3737
env:
3838
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3939

40-
- name: Deploy 🚀
41-
uses: JamesIves/github-pages-deploy-action@4.1.4
42-
with:
43-
branch: gh-pages
44-
folder: docs
40+
# - name: Deploy 🚀
41+
# uses: JamesIves/github-pages-deploy-action@4.1.4
42+
# with:
43+
# branch: gh-pages
44+
# folder: docs

CHANGELOG.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

asconfig.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
{
22
"targets": {
33
"debug": {
4-
"binaryFile": "build/untouched.wasm",
5-
"textFile": "build/untouched.wat",
4+
"outFile": "build/debug.wasm",
5+
"textFile": "build/debug.wat",
66
"sourceMap": true,
77
"debug": true
88
},
99
"release": {
10-
"binaryFile": "build/optimized.wasm",
11-
"textFile": "build/optimized.wat",
10+
"outFile": "build/release.wasm",
11+
"textFile": "build/release.wat",
1212
"sourceMap": true,
1313
"optimizeLevel": 3,
1414
"shrinkLevel": 0,
1515
"converge": false,
1616
"noAssert": false
1717
}
1818
},
19-
"options": {}
19+
"options": {
20+
"bindings": "esm",
21+
"transform": ["json-as/transform"]
22+
}
2023
}

assembly/index.ts

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,83 @@
1-
import { JSON } from "assemblyscript-json";
2-
import {Position, parsePrices, getTickFromPrice, trailingStop, renderULMResult, getTickSpacing} from "@steerprotocol/strategy-utils";
1+
import { getTickFromPrice, getTickSpacing, renderULMResult } from "@steerprotocol/concentrated-liquidity-strategy/assembly";
2+
import { parseCandles, Position, console, trailingStop } from "@steerprotocol/strategy-utils/assembly";
3+
import { JSON } from "json-as/assembly";
34

4-
5-
let width: i32 = 600;
65
let percent: f32 = 0;
76
let poolFee: i32 = 0;
87

8+
@serializable
9+
class Config {
10+
poolFee: f32 = 0;
11+
percent: i32 = 0;
12+
}
13+
914
export function initialize(config: string): void {
1015
// Parse the config object
11-
const configJson = <JSON.Obj>JSON.parse(config);
12-
// Get our config variables
13-
const _width = configJson.getInteger("binWidth");
14-
const _poolFee = configJson.getInteger("poolFee");
15-
const _percent = configJson.getValue("percent");
16+
const configJson: Config = JSON.parse<Config>(config);
17+
1618
// Handle null case
17-
if (_width == null || _percent == null || _poolFee == null) {
19+
if (
20+
configJson.percent == 0 ||
21+
configJson.poolFee == 0
22+
) {
1823
throw new Error("Invalid configuration");
1924
}
2025

21-
// Handle percents presented as integers
22-
if (_percent.isFloat) {
23-
const f_percent = <JSON.Num>_percent
24-
percent = f32(f_percent._num);
25-
}
26-
if (_percent.isInteger) {
27-
const i_percent = <JSON.Integer>_percent
28-
percent = f32(i_percent._num);
29-
}
3026
// Assign values to memory
31-
width = i32(_width._num);
32-
poolFee = i32(_poolFee._num);
27+
percent = f32(configJson.percent);
28+
poolFee = i32(configJson.poolFee);
29+
}
30+
31+
function closestDivisibleNumber(num: number, divisor: number, floor: boolean): number {
32+
if (floor) return Math.floor(num / divisor) * divisor;
33+
return Math.ceil(num / divisor) * divisor;
3334
}
3435

3536
export function execute(_prices: string): string {
3637
// _prices will have the results of the dc, which is only candles here
37-
const prices = parsePrices(_prices, 0);
38+
const prices = parseCandles(_prices);
3839
// If we have no candles, skip action
39-
if (prices.length == 0) {return `continue`}
40-
// Get Trailing stop price
41-
const trailingLimit = trailingStop(percent, prices)
42-
// Calculate position
43-
const positions = calculateBin(trailingLimit);
44-
// Format and return result
45-
return renderULMResult(positions);
46-
}
47-
48-
49-
function calculateBin(upper: f32): Position[] {
50-
51-
// Calculate the upper tick based on the start of the stop
52-
const upperTick: i32 = i32(Math.round(getTickFromPrice(upper)));
53-
54-
// Get the spacing
55-
const tickSpacing = getTickSpacing(poolFee);
56-
57-
// Step down ticks until we reach an initializable tick
58-
let _startTick: i32 = upperTick;
59-
while (_startTick % tickSpacing !== 0) {
60-
_startTick--;
40+
if (prices.length == 0) {
41+
return `continue`;
6142
}
6243

63-
const positions: Array<Position> = [];
64-
const position = new Position(_startTick - width, _startTick, 1);
65-
positions.push(position);
44+
const lowerLimit = trailingStop(percent, prices);
45+
const upperLimit = prices[prices.length - 1].close;
46+
47+
const upperTick = closestDivisibleNumber(i32(Math.round(getTickFromPrice(f32(upperLimit)))), getTickSpacing(poolFee), false);
48+
const lowerTick = closestDivisibleNumber(i32(Math.round(getTickFromPrice(f32(lowerLimit)))), getTickSpacing(poolFee), true);
49+
50+
// Calculate position
51+
52+
53+
const positions = [new Position(i32(lowerTick), i32(upperTick), 100)];
6654

67-
return positions
55+
// Format and return result
56+
return renderULMResult(positions, 10000);
6857
}
6958

70-
export function config(): string{
59+
export function config(): string {
7160
return `{
7261
"$schema": "http://json-schema.org/draft-07/schema#",
7362
"title": "Strategy Config",
7463
"type": "object",
64+
"parameters": ["OHLC"],
7565
"properties": {
7666
"percent": {
77-
"type": "number",
78-
"description": "Percent for trailing stop order",
79-
"default": 5.0
80-
},
67+
"type": "number",
68+
"description": "Percent for trailing stop order (must be greater than pool fee)",
69+
"default": 5.0
70+
},
8171
"poolFee": {
8272
"description": "Pool fee percent for desired Uniswapv3 pool",
8373
"enum" : [10000, 3000, 500, 100],
8474
"enumNames": ["1%", "0.3%", "0.05%", "0.01%"]
85-
},
86-
"binWidth": {
87-
"type": "number",
88-
"description": "Width for liquidity position, must be a multiple of pool tick spacing",
89-
"default": 600
9075
}
9176
},
92-
"required": ["percent", "binWidth", "poolFee"]
77+
"required": ["percent", "poolFee"]
9378
}`;
9479
}
9580

9681
export function version(): i32 {
9782
return 1;
9883
}
99-

0 commit comments

Comments
 (0)