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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ lbp = []
stableswap = []
liquidity-mining = []
omnipool = []
ema = []
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ build-web-release:
wasm-pack build --release --target web --out-dir ./build/stableswap/web -- --features stableswap
wasm-pack build --release --target web --out-dir ./build/liquidity-mining/web -- --features liquidity-mining
wasm-pack build --release --target web --out-dir ./build/omnipool/web -- --features omnipool
rm ./build/xyk/web/.gitignore ./build/lbp/web/.gitignore ./build/stableswap/web/.gitignore ./build/liquidity-mining/web/.gitignore ./build/omnipool/web/.gitignore
rm ./build/xyk/web/LICENSE ./build/lbp/web/LICENSE ./build/stableswap/web/LICENSE ./build/liquidity-mining/web/LICENSE ./build/omnipool/web/LICENSE
rm ./build/xyk/web/README.md ./build/lbp/web/README.md ./build/stableswap/web/README.md ./build/liquidity-mining/web/README.md ./build/omnipool/web/README.md
wasm-pack build --release --target web --out-dir ./build/ema/web -- --features ema
rm ./build/xyk/web/.gitignore ./build/lbp/web/.gitignore ./build/stableswap/web/.gitignore ./build/liquidity-mining/web/.gitignore ./build/omnipool/web/.gitignore ./build/ema/web/.gitignore
rm ./build/xyk/web/LICENSE ./build/lbp/web/LICENSE ./build/stableswap/web/LICENSE ./build/liquidity-mining/web/LICENSE ./build/omnipool/web/LICENSE ./build/ema/web/LICENSE
rm ./build/xyk/web/README.md ./build/lbp/web/README.md ./build/stableswap/web/README.md ./build/liquidity-mining/web/README.md ./build/omnipool/web/README.md ./build/ema/web/README.md

.PHONY: build-nodejs-release
build-nodejs-release:
Expand All @@ -19,9 +20,10 @@ build-nodejs-release:
wasm-pack build --release --target nodejs --out-dir ./build/stableswap/nodejs -- --features stableswap
wasm-pack build --release --target nodejs --out-dir ./build/liquidity-mining/nodejs -- --features liquidity-mining
wasm-pack build --release --target nodejs --out-dir ./build/omnipool/nodejs -- --features omnipool
rm ./build/xyk/nodejs/.gitignore ./build/lbp/nodejs/.gitignore ./build/stableswap/nodejs/.gitignore ./build/liquidity-mining/nodejs/.gitignore ./build/omnipool/nodejs/.gitignore
rm ./build/xyk/nodejs/LICENSE ./build/lbp/nodejs/LICENSE ./build/stableswap/nodejs/LICENSE ./build/liquidity-mining/nodejs/LICENSE ./build/omnipool/nodejs/LICENSE
rm ./build/xyk/nodejs/README.md ./build/lbp/nodejs/README.md ./build/stableswap/nodejs/README.md ./build/liquidity-mining/nodejs/README.md ./build/omnipool/nodejs/README.md
wasm-pack build --release --target nodejs --out-dir ./build/ema/nodejs -- --features ema
rm ./build/xyk/nodejs/.gitignore ./build/lbp/nodejs/.gitignore ./build/stableswap/nodejs/.gitignore ./build/liquidity-mining/nodejs/.gitignore ./build/omnipool/nodejs/.gitignore ./build/ema/nodejs/.gitignore
rm ./build/xyk/nodejs/LICENSE ./build/lbp/nodejs/LICENSE ./build/stableswap/nodejs/LICENSE ./build/liquidity-mining/nodejs/LICENSE ./build/omnipool/nodejs/LICENSE ./build/ema/nodejs/LICENSE
rm ./build/xyk/nodejs/README.md ./build/lbp/nodejs/README.md ./build/stableswap/nodejs/README.md ./build/liquidity-mining/nodejs/README.md ./build/omnipool/nodejs/README.md ./build/ema/nodejs/README.md

.PHONY: build-bundler-release
build-bundler-release:
Expand All @@ -30,9 +32,10 @@ build-bundler-release:
wasm-pack build --release --target bundler --out-dir ./build/stableswap/bundler -- --features stableswap
wasm-pack build --release --target bundler --out-dir ./build/liquidity-mining/bundler -- --features liquidity-mining
wasm-pack build --release --target bundler --out-dir ./build/omnipool/bundler -- --features omnipool
rm ./build/xyk/bundler/.gitignore ./build/lbp/bundler/.gitignore ./build/stableswap/bundler/.gitignore ./build/liquidity-mining/bundler/.gitignore ./build/omnipool/bundler/.gitignore
rm ./build/xyk/bundler/LICENSE ./build/lbp/bundler/LICENSE ./build/stableswap/bundler/LICENSE ./build/liquidity-mining/bundler/LICENSE ./build/omnipool/bundler/LICENSE
rm ./build/xyk/bundler/README.md ./build/lbp/bundler/README.md ./build/stableswap/bundler/README.md ./build/liquidity-mining/bundler/README.md ./build/omnipool/bundler/README.md
wasm-pack build --release --target bundler --out-dir ./build/ema/bundler -- --features ema
rm ./build/xyk/bundler/.gitignore ./build/lbp/bundler/.gitignore ./build/stableswap/bundler/.gitignore ./build/liquidity-mining/bundler/.gitignore ./build/omnipool/bundler/.gitignore ./build/ema/bundler/.gitignore
rm ./build/xyk/bundler/LICENSE ./build/lbp/bundler/LICENSE ./build/stableswap/bundler/LICENSE ./build/liquidity-mining/bundler/LICENSE ./build/omnipool/bundler/LICENSE ./build/ema/bundler/LICENSE
rm ./build/xyk/bundler/README.md ./build/lbp/bundler/README.md ./build/stableswap/bundler/README.md ./build/liquidity-mining/bundler/README.md ./build/omnipool/bundler/README.md ./build/ema/bundler/README.md


.PHONY: build-package
Expand All @@ -42,6 +45,7 @@ build-package:
bash ./build-package.sh stableswap
bash ./build-package.sh liquidity-mining
bash ./build-package.sh omnipool
bash ./build-package.sh ema

.PHONY: clean-package
clean-package:
Expand All @@ -50,6 +54,7 @@ clean-package:
bash ./clean-package.sh stableswap
bash ./clean-package.sh liquidity-mining
bash ./clean-package.sh omnipool
bash ./clean-package.sh ema

.PHONY: test
test:
Expand Down
43 changes: 43 additions & 0 deletions build/ema/bundler/hydra_dx_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* tslint:disable */
/* eslint-disable */
/**
* Calculate the iterated exponential moving average for the given prices.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev_n` and `prev_d` are the previous oracle value, `incoming_n` and `incoming_d` are the new value to
* integrate (expected to be serialized `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `FixedU128` (lower precision than the input).
* @param {string} iterations
* @param {string} prev_n
* @param {string} prev_d
* @param {string} incoming_n
* @param {string} incoming_d
* @param {string} smoothing
* @returns {string}
*/
export function low_precision_iterated_price_ema(iterations: string, prev_n: string, prev_d: string, incoming_n: string, incoming_d: string, smoothing: string): string;
/**
* Calculate the iterated exponential moving average for the given balances.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev` is the previous oracle value, `incoming` is the new value to integrate (expected to be serialized
* `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `u128`.
* @param {string} iterations
* @param {string} prev
* @param {string} incoming
* @param {string} smoothing
* @returns {string}
*/
export function iterated_balance_ema(iterations: string, prev: string, incoming: string, smoothing: string): string;
/**
* @param {string} a
* @param {number} fee_numerator
* @param {number} fee_denominator
* @returns {string}
*/
export function calculate_pool_trade_fee(a: string, fee_numerator: number, fee_denominator: number): string;
4 changes: 4 additions & 0 deletions build/ema/bundler/hydra_dx_wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as wasm from "./hydra_dx_wasm_bg.wasm";
import { __wbg_set_wasm } from "./hydra_dx_wasm_bg.js";
__wbg_set_wasm(wasm);
export * from "./hydra_dx_wasm_bg.js";
189 changes: 189 additions & 0 deletions build/ema/bundler/hydra_dx_wasm_bg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
let wasm;
export function __wbg_set_wasm(val) {
wasm = val;
}


let WASM_VECTOR_LEN = 0;

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;

let cachedTextEncoder = new lTextEncoder('utf-8');

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});

function passStringToWasm0(arg, malloc, realloc) {

if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length);
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}

let len = arg.length;
let ptr = malloc(len);

const mem = getUint8Memory0();

let offset = 0;

for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}

if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3);
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);

offset += ret.written;
}

WASM_VECTOR_LEN = offset;
return ptr;
}

let cachedInt32Memory0 = null;

function getInt32Memory0() {
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachedInt32Memory0;
}

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
/**
* Calculate the iterated exponential moving average for the given prices.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev_n` and `prev_d` are the previous oracle value, `incoming_n` and `incoming_d` are the new value to
* integrate (expected to be serialized `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `FixedU128` (lower precision than the input).
* @param {string} iterations
* @param {string} prev_n
* @param {string} prev_d
* @param {string} incoming_n
* @param {string} incoming_d
* @param {string} smoothing
* @returns {string}
*/
export function low_precision_iterated_price_ema(iterations, prev_n, prev_d, incoming_n, incoming_d, smoothing) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(iterations, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(prev_n, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passStringToWasm0(prev_d, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len2 = WASM_VECTOR_LEN;
const ptr3 = passStringToWasm0(incoming_n, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len3 = WASM_VECTOR_LEN;
const ptr4 = passStringToWasm0(incoming_d, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len4 = WASM_VECTOR_LEN;
const ptr5 = passStringToWasm0(smoothing, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len5 = WASM_VECTOR_LEN;
wasm.low_precision_iterated_price_ema(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}

/**
* Calculate the iterated exponential moving average for the given balances.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev` is the previous oracle value, `incoming` is the new value to integrate (expected to be serialized
* `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `u128`.
* @param {string} iterations
* @param {string} prev
* @param {string} incoming
* @param {string} smoothing
* @returns {string}
*/
export function iterated_balance_ema(iterations, prev, incoming, smoothing) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(iterations, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(prev, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passStringToWasm0(incoming, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len2 = WASM_VECTOR_LEN;
const ptr3 = passStringToWasm0(smoothing, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len3 = WASM_VECTOR_LEN;
wasm.iterated_balance_ema(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}

/**
* @param {string} a
* @param {number} fee_numerator
* @param {number} fee_denominator
* @returns {string}
*/
export function calculate_pool_trade_fee(a, fee_numerator, fee_denominator) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.calculate_pool_trade_fee(retptr, ptr0, len0, fee_numerator, fee_denominator);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(r0, r1);
}
}

Binary file added build/ema/bundler/hydra_dx_wasm_bg.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions build/ema/bundler/hydra_dx_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function low_precision_iterated_price_ema(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number): void;
export function iterated_balance_ema(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void;
export function calculate_pool_trade_fee(a: number, b: number, c: number, d: number, e: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export function __wbindgen_free(a: number, b: number): void;
24 changes: 24 additions & 0 deletions build/ema/bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "hydra-dx-wasm",
"collaborators": [
"GalacticCouncil"
],
"version": "4.0.0",
"license": "Apache 2.0",
"repository": {
"type": "git",
"url": "https://github.com/galacticcouncil/hydradx-wasm"
},
"files": [
"hydra_dx_wasm_bg.wasm",
"hydra_dx_wasm.js",
"hydra_dx_wasm_bg.js",
"hydra_dx_wasm.d.ts"
],
"module": "hydra_dx_wasm.js",
"types": "hydra_dx_wasm.d.ts",
"sideEffects": [
"./hydra_dx_wasm.js",
"./snippets/*"
]
}
43 changes: 43 additions & 0 deletions build/ema/nodejs/hydra_dx_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* tslint:disable */
/* eslint-disable */
/**
* Calculate the iterated exponential moving average for the given prices.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev_n` and `prev_d` are the previous oracle value, `incoming_n` and `incoming_d` are the new value to
* integrate (expected to be serialized `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `FixedU128` (lower precision than the input).
* @param {string} iterations
* @param {string} prev_n
* @param {string} prev_d
* @param {string} incoming_n
* @param {string} incoming_d
* @param {string} smoothing
* @returns {string}
*/
export function low_precision_iterated_price_ema(iterations: string, prev_n: string, prev_d: string, incoming_n: string, incoming_d: string, smoothing: string): string;
/**
* Calculate the iterated exponential moving average for the given balances.
* + `iterations` is the number of iterations of the EMA to calculate (expected to be a serialized `u32`).
* + `prev` is the previous oracle value, `incoming` is the new value to integrate (expected to be serialized
* `u128` values).
* + `smoothing` is the smoothing factor of the EMA (expected to be a serialized `u128` that gets interpreted as a
* `Fraction`).
*
* Returns the new oracle value as a serialized `u128`.
* @param {string} iterations
* @param {string} prev
* @param {string} incoming
* @param {string} smoothing
* @returns {string}
*/
export function iterated_balance_ema(iterations: string, prev: string, incoming: string, smoothing: string): string;
/**
* @param {string} a
* @param {number} fee_numerator
* @param {number} fee_denominator
* @returns {string}
*/
export function calculate_pool_trade_fee(a: string, fee_numerator: number, fee_denominator: number): string;
Loading