From 0e7f467bbf46359417f6537f088fcec2ab1a9328 Mon Sep 17 00:00:00 2001 From: afsardo Date: Tue, 26 Mar 2024 03:03:21 +0000 Subject: [PATCH] feat: add osmosis MsgBeginUnlocking and fix MsgLockTokens --- packages/core/src/externals/binary.ts | 1014 +++++++++ packages/core/src/externals/osmosis.ts | 716 ------- packages/core/src/externals/osmosis/binary.ts | 491 +++++ packages/core/src/externals/osmosis/coin.ts | 418 ++++ .../core/src/externals/osmosis/duration.ts | 282 +++ .../core/src/externals/osmosis/helpers.ts | 222 ++ packages/core/src/externals/osmosis/lockup.ts | 1899 +++++++++++++++++ .../core/src/externals/osmosis/timestamp.ts | 350 +++ packages/core/src/externals/osmosis/utf8.ts | 119 ++ packages/core/src/externals/osmosis/varint.ts | 454 ++++ packages/core/src/internals/registry.ts | 3 + .../messages/MsgBeginUnlocking.ts | 34 + .../transactions/messages/MsgLockTokens.ts | 21 +- .../internals/transactions/messages/index.ts | 1 + 14 files changed, 5303 insertions(+), 721 deletions(-) create mode 100644 packages/core/src/externals/binary.ts delete mode 100644 packages/core/src/externals/osmosis.ts create mode 100644 packages/core/src/externals/osmosis/binary.ts create mode 100644 packages/core/src/externals/osmosis/coin.ts create mode 100644 packages/core/src/externals/osmosis/duration.ts create mode 100644 packages/core/src/externals/osmosis/helpers.ts create mode 100644 packages/core/src/externals/osmosis/lockup.ts create mode 100644 packages/core/src/externals/osmosis/timestamp.ts create mode 100644 packages/core/src/externals/osmosis/utf8.ts create mode 100644 packages/core/src/externals/osmosis/varint.ts create mode 100644 packages/core/src/internals/transactions/messages/MsgBeginUnlocking.ts diff --git a/packages/core/src/externals/binary.ts b/packages/core/src/externals/binary.ts new file mode 100644 index 0000000..3f7cd12 --- /dev/null +++ b/packages/core/src/externals/binary.ts @@ -0,0 +1,1014 @@ +"use strict"; + +export enum WireType { + Varint = 0, + + Fixed64 = 1, + + Bytes = 2, + + Fixed32 = 5, +} + +// Reader +export interface IBinaryReader { + buf: Uint8Array; + pos: number; + type: number; + len: number; + tag(): [number, WireType, number]; + skip(length?: number): this; + skipType(wireType: number): this; + uint32(): number; + int32(): number; + sint32(): number; + fixed32(): number; + sfixed32(): number; + int64(): bigint; + uint64(): bigint; + sint64(): bigint; + fixed64(): bigint; + sfixed64(): bigint; + float(): number; + double(): number; + bool(): boolean; + bytes(): Uint8Array; + string(): string; +} + +export class BinaryReader implements IBinaryReader { + buf: Uint8Array; + pos: number; + type: number; + len: number; + + assertBounds(): void { + if (this.pos > this.len) throw new RangeError("premature EOF"); + } + + constructor(buf?: ArrayLike) { + this.buf = buf ? new Uint8Array(buf) : new Uint8Array(0); + this.pos = 0; + this.type = 0; + this.len = this.buf.length; + } + + tag(): [number, WireType, number] { + const tag = this.uint32(), + fieldNo = tag >>> 3, + wireType = tag & 7; + if (fieldNo <= 0 || wireType < 0 || wireType > 5) + throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType); + return [fieldNo, wireType, tag]; + } + + skip(length?: number) { + if (typeof length === "number") { + if (this.pos + length > this.len) throw indexOutOfRange(this, length); + this.pos += length; + } else { + do { + if (this.pos >= this.len) throw indexOutOfRange(this); + } while (this.buf[this.pos++] & 128); + } + return this; + } + + skipType(wireType: number) { + switch (wireType) { + case WireType.Varint: + this.skip(); + break; + case WireType.Fixed64: + this.skip(8); + break; + case WireType.Bytes: + this.skip(this.uint32()); + break; + case 3: + while ((wireType = this.uint32() & 7) !== 4) { + this.skipType(wireType); + } + break; + case WireType.Fixed32: + this.skip(4); + break; + + /* istanbul ignore next */ + default: + throw Error("invalid wire type " + wireType + " at offset " + this.pos); + } + return this; + } + + uint32(): number { + return varint32read.bind(this)(); + } + + int32(): number { + return this.uint32() | 0; + } + + sint32(): number { + const num = this.uint32(); + return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding + } + + fixed32(): number { + const val = readUInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + sfixed32(): number { + const val = readInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + int64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(int64ToString(lo, hi)); + } + + uint64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(uInt64ToString(lo, hi)); + } + + sint64(): bigint { + let [lo, hi] = varint64read.bind(this)(); + // zig zag + [lo, hi] = zzDecode(lo, hi); + return BigInt(int64ToString(lo, hi)); + } + + fixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(uInt64ToString(lo, hi)); + } + sfixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(int64ToString(lo, hi)); + } + + float(): number { + throw new Error("float not supported"); + } + + double(): number { + throw new Error("double not supported"); + } + + bool(): boolean { + const [lo, hi] = varint64read.bind(this)(); + return lo !== 0 || hi !== 0; + } + + bytes(): Uint8Array { + const len = this.uint32(), + start = this.pos; + this.pos += len; + this.assertBounds(); + return this.buf.subarray(start, start + len); + } + + string(): string { + const bytes = this.bytes(); + return utf8Read(bytes, 0, bytes.length); + } +} + +// Writer +export interface IBinaryWriter { + len: number; + head: IOp; + tail: IOp; + states: State | null; + finish(): Uint8Array; + fork(): IBinaryWriter; + reset(): IBinaryWriter; + ldelim(): IBinaryWriter; + tag(fieldNo: number, type: WireType): IBinaryWriter; + uint32(value: number): IBinaryWriter; + int32(value: number): IBinaryWriter; + sint32(value: number): IBinaryWriter; + int64(value: string | number | bigint): IBinaryWriter; + uint64: (value: string | number | bigint) => IBinaryWriter; + sint64(value: string | number | bigint): IBinaryWriter; + fixed64(value: string | number | bigint): IBinaryWriter; + sfixed64: (value: string | number | bigint) => IBinaryWriter; + bool(value: boolean): IBinaryWriter; + fixed32(value: number): IBinaryWriter; + sfixed32: (value: number) => IBinaryWriter; + float(value: number): IBinaryWriter; + double(value: number): IBinaryWriter; + bytes(value: Uint8Array): IBinaryWriter; + string(value: string): IBinaryWriter; +} + +interface IOp { + len: number; + next?: IOp; + proceed(buf: Uint8Array | number[], pos: number): void; +} + +class Op implements IOp { + fn?: ((val: T, buf: Uint8Array | number[], pos: number) => void) | null; + len: number; + val: T; + next?: IOp; + + constructor( + fn: ((val: T, buf: Uint8Array | number[], pos: number) => void | undefined | null) | null, + len: number, + val: T, + ) { + this.fn = fn; + this.len = len; + this.val = val; + } + + proceed(buf: Uint8Array | number[], pos: number) { + if (this.fn) { + this.fn(this.val, buf, pos); + } + } +} + +class State { + head: IOp; + tail: IOp; + len: number; + next: State | null; + + constructor(writer: BinaryWriter) { + this.head = writer.head; + this.tail = writer.tail; + this.len = writer.len; + this.next = writer.states; + } +} + +export class BinaryWriter implements IBinaryWriter { + len = 0; + head: IOp; + tail: IOp; + states: State | null; + + constructor() { + this.head = new Op(null, 0, 0); + this.tail = this.head; + this.states = null; + } + + static create() { + return new BinaryWriter(); + } + + static alloc(size: number): Uint8Array | number[] { + if (typeof Uint8Array !== "undefined") { + return pool((size) => new Uint8Array(size), Uint8Array.prototype.subarray)(size); + } else { + return new Array(size); + } + } + + private _push(fn: (val: T, buf: Uint8Array | number[], pos: number) => void, len: number, val: T) { + this.tail = this.tail.next = new Op(fn, len, val); + this.len += len; + return this; + } + + finish(): Uint8Array { + let head = this.head.next, + pos = 0; + const buf = BinaryWriter.alloc(this.len); + while (head) { + head.proceed(buf, pos); + pos += head.len; + head = head.next; + } + return buf as Uint8Array; + } + + fork(): BinaryWriter { + this.states = new State(this); + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + return this; + } + + reset(): BinaryWriter { + if (this.states) { + this.head = this.states.head; + this.tail = this.states.tail; + this.len = this.states.len; + this.states = this.states.next; + } else { + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + } + return this; + } + + ldelim(): BinaryWriter { + const head = this.head, + tail = this.tail, + len = this.len; + this.reset().uint32(len); + if (len) { + this.tail.next = head.next; // skip noop + this.tail = tail; + this.len += len; + } + return this; + } + + tag(fieldNo: number, type: WireType): BinaryWriter { + return this.uint32(((fieldNo << 3) | type) >>> 0); + } + + uint32(value: number): BinaryWriter { + this.len += (this.tail = this.tail.next = + new Op( + writeVarint32, + (value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, + value, + )).len; + return this; + } + + int32(value: number): BinaryWriter { + return value < 0 + ? this._push(writeVarint64, 10, int64FromString(value.toString())) // 10 bytes per spec + : this.uint32(value); + } + + sint32(value: number): BinaryWriter { + return this.uint32(((value << 1) ^ (value >> 31)) >>> 0); + } + + int64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + // uint64 is the same with int64 + uint64 = BinaryWriter.prototype.int64; + + sint64(value: string | number | bigint): BinaryWriter { + let { lo, hi } = int64FromString(value.toString()); + // zig zag + [lo, hi] = zzEncode(lo, hi); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + fixed64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeFixed32, 4, lo)._push(writeFixed32, 4, hi); + } + + // sfixed64 is the same with fixed64 + sfixed64 = BinaryWriter.prototype.fixed64; + + bool(value: boolean): BinaryWriter { + return this._push(writeByte, 1, value ? 1 : 0); + } + + fixed32(value: number): BinaryWriter { + return this._push(writeFixed32, 4, value >>> 0); + } + + // sfixed32 is the same with fixed32 + sfixed32 = BinaryWriter.prototype.fixed32; + + float(value: number): BinaryWriter { + throw new Error("float not supported" + value); + } + + double(value: number): BinaryWriter { + throw new Error("double not supported" + value); + } + + bytes(value: Uint8Array): BinaryWriter { + const len = value.length >>> 0; + if (!len) return this._push(writeByte, 1, 0); + return this.uint32(len)._push(writeBytes, len, value); + } + + string(value: string): BinaryWriter { + const len = utf8Length(value); + return len ? this.uint32(len)._push(utf8Write, len, value) : this._push(writeByte, 1, 0); + } +} + +function writeBytes(val: Uint8Array | number[], buf: Uint8Array | number[], pos: number) { + if (typeof Uint8Array !== "undefined") { + (buf as Uint8Array).set(val, pos); + } else { + for (let i = 0; i < val.length; ++i) buf[pos + i] = val[i]; + } +} + +function pool( + alloc: (size: number) => Uint8Array, + slice: (begin?: number, end?: number) => Uint8Array, + size?: number, +): (size: number) => Uint8Array { + const SIZE = size || 8192; + const MAX = SIZE >>> 1; + let slab: Uint8Array | null = null; + let offset = SIZE; + return function pool_alloc(size): Uint8Array { + if (size < 1 || size > MAX) return alloc(size); + if (offset + size > SIZE) { + slab = alloc(SIZE); + offset = 0; + } + const buf: Uint8Array = slice.call(slab, offset, (offset += size)); + if (offset & 7) + // align to 32 bit + offset = (offset | 7) + 1; + return buf; + }; +} + +function indexOutOfRange(reader: BinaryReader, writeLength?: number) { + return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len); +} + +// Copyright 2008 Google Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Code generated by the Protocol Buffer compiler is owned by the owner +// of the input file used when generating it. This code is not +// standalone and requires a support library to be linked with it. This +// support library is itself covered by the above license. + +/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */ + +/** + * Read a 64 bit varint as two JS numbers. + * + * Returns tuple: + * [0]: low bits + * [1]: high bits + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175 + */ +export function varint64read(this: ReaderLike): [number, number] { + let lowBits = 0; + let highBits = 0; + + for (let shift = 0; shift < 28; shift += 7) { + let b = this.buf[this.pos++]; + lowBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + let middleByte = this.buf[this.pos++]; + + // last four bits of the first 32 bit number + lowBits |= (middleByte & 0x0f) << 28; + + // 3 upper bits are part of the next 32 bit number + highBits = (middleByte & 0x70) >> 4; + + if ((middleByte & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + + for (let shift = 3; shift <= 31; shift += 7) { + let b = this.buf[this.pos++]; + highBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + throw new Error("invalid varint"); +} + +/** + * Write a 64 bit varint, given as two JS numbers, to the given bytes array. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344 + */ +export function varint64write(lo: number, hi: number, bytes: number[]): void { + for (let i = 0; i < 28; i = i + 7) { + const shift = lo >>> i; + const hasNext = !(shift >>> 7 == 0 && hi == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4); + const hasMoreBits = !(hi >> 3 == 0); + bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff); + + if (!hasMoreBits) { + return; + } + + for (let i = 3; i < 31; i = i + 7) { + const shift = hi >>> i; + const hasNext = !(shift >>> 7 == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + bytes.push((hi >>> 31) & 0x01); +} + +// constants for binary math +const TWO_PWR_32_DBL = 0x100000000; + +/** + * Parse decimal string of 64 bit integer value as two JS numbers. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64FromString(dec: string): { lo: number; hi: number } { + // Check for minus sign. + const minus = dec[0] === "-"; + if (minus) { + dec = dec.slice(1); + } + + // Work 6 decimal digits at a time, acting like we're converting base 1e6 + // digits to binary. This is safe to do with floating point math because + // Number.isSafeInteger(ALL_32_BITS * 1e6) == true. + const base = 1e6; + let lowBits = 0; + let highBits = 0; + + function add1e6digit(begin: number, end?: number) { + // Note: Number('') is 0. + const digit1e6 = Number(dec.slice(begin, end)); + highBits *= base; + lowBits = lowBits * base + digit1e6; + // Carry bits from lowBits to + if (lowBits >= TWO_PWR_32_DBL) { + highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0); + lowBits = lowBits % TWO_PWR_32_DBL; + } + } + + add1e6digit(-24, -18); + add1e6digit(-18, -12); + add1e6digit(-12, -6); + add1e6digit(-6); + return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits); +} + +/** + * Losslessly converts a 64-bit signed integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64ToString(lo: number, hi: number): string { + let bits = newBits(lo, hi); + // If we're treating the input as a signed value and the high bit is set, do + // a manual two's complement conversion before the decimal conversion. + const negative = bits.hi & 0x80000000; + if (negative) { + bits = negate(bits.lo, bits.hi); + } + const result = uInt64ToString(bits.lo, bits.hi); + return negative ? "-" + result : result; +} + +/** + * Losslessly converts a 64-bit unsigned integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function uInt64ToString(lo: number, hi: number): string { + ({ lo, hi } = toUnsigned(lo, hi)); + // Skip the expensive conversion if the number is small enough to use the + // built-in conversions. + // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with + // highBits <= 0x1FFFFF can be safely expressed with a double and retain + // integer precision. + // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true. + if (hi <= 0x1fffff) { + return String(TWO_PWR_32_DBL * hi + lo); + } + + // What this code is doing is essentially converting the input number from + // base-2 to base-1e7, which allows us to represent the 64-bit range with + // only 3 (very large) digits. Those digits are then trivial to convert to + // a base-10 string. + + // The magic numbers used here are - + // 2^24 = 16777216 = (1,6777216) in base-1e7. + // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7. + + // Split 32:32 representation into 16:24:24 representation so our + // intermediate digits don't overflow. + const low = lo & 0xffffff; + const mid = ((lo >>> 24) | (hi << 8)) & 0xffffff; + const high = (hi >> 16) & 0xffff; + + // Assemble our three base-1e7 digits, ignoring carries. The maximum + // value in a digit at this step is representable as a 48-bit integer, which + // can be stored in a 64-bit floating point number. + let digitA = low + mid * 6777216 + high * 6710656; + let digitB = mid + high * 8147497; + let digitC = high * 2; + + // Apply carries from A to B and from B to C. + const base = 10000000; + if (digitA >= base) { + digitB += Math.floor(digitA / base); + digitA %= base; + } + + if (digitB >= base) { + digitC += Math.floor(digitB / base); + digitB %= base; + } + + // If digitC is 0, then we should have returned in the trivial code path + // at the top for non-safe integers. Given this, we can assume both digitB + // and digitA need leading zeros. + return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) + decimalFrom1e7WithLeadingZeros(digitA); +} + +function toUnsigned(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo >>> 0, hi: hi >>> 0 }; +} + +function newBits(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo | 0, hi: hi | 0 }; +} + +/** + * Returns two's compliment negation of input. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers + */ +function negate(lowBits: number, highBits: number) { + highBits = ~highBits; + if (lowBits) { + lowBits = ~lowBits + 1; + } else { + // If lowBits is 0, then bitwise-not is 0xFFFFFFFF, + // adding 1 to that, results in 0x100000000, which leaves + // the low bits 0x0 and simply adds one to the high bits. + highBits += 1; + } + return newBits(lowBits, highBits); +} + +/** + * Returns decimal representation of digit1e7 with leading zeros. + */ +const decimalFrom1e7WithLeadingZeros = (digit1e7: number) => { + const partial = String(digit1e7); + return "0000000".slice(partial.length) + partial; +}; + +/** + * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)` + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144 + */ +export function varint32write(value: number, bytes: number[]): void { + if (value >= 0) { + // write value as varint 32 + while (value > 0x7f) { + bytes.push((value & 0x7f) | 0x80); + value = value >>> 7; + } + bytes.push(value); + } else { + for (let i = 0; i < 9; i++) { + bytes.push((value & 127) | 128); + value = value >> 7; + } + bytes.push(1); + } +} + +/** + * Read an unsigned 32 bit varint. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220 + */ +export function varint32read(this: ReaderLike): number { + let b = this.buf[this.pos++]; + let result = b & 0x7f; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 7; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 14; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 21; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + // Extract only last 4 bits + b = this.buf[this.pos++]; + result |= (b & 0x0f) << 28; + + for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++) b = this.buf[this.pos++]; + + if ((b & 0x80) != 0) throw new Error("invalid varint"); + + this.assertBounds(); + + // Result can have 32 bits, convert it to unsigned + return result >>> 0; +} + +type ReaderLike = { + buf: Uint8Array; + pos: number; + len: number; + assertBounds(): void; +}; + +/** + * encode zig zag + */ +export function zzEncode(lo: number, hi: number) { + let mask = hi >> 31; + hi = (((hi << 1) | (lo >>> 31)) ^ mask) >>> 0; + lo = ((lo << 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * decode zig zag + */ +export function zzDecode(lo: number, hi: number) { + let mask = -(lo & 1); + lo = (((lo >>> 1) | (hi << 31)) ^ mask) >>> 0; + hi = ((hi >>> 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * unsigned int32 without moving pos. + */ +export function readUInt32(buf: Uint8Array, pos: number) { + return (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + buf[pos + 3] * 0x1000000; +} + +/** + * signed int32 without moving pos. + */ +export function readInt32(buf: Uint8Array, pos: number) { + return (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + (buf[pos + 3] << 24); +} + +/** + * writing varint32 to pos + */ +export function writeVarint32(val: number, buf: Uint8Array | number[], pos: number) { + while (val > 127) { + buf[pos++] = (val & 127) | 128; + val >>>= 7; + } + buf[pos] = val; +} + +/** + * writing varint64 to pos + */ +export function writeVarint64(val: { lo: number; hi: number }, buf: Uint8Array | number[], pos: number) { + while (val.hi) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = ((val.lo >>> 7) | (val.hi << 25)) >>> 0; + val.hi >>>= 7; + } + while (val.lo > 127) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = val.lo >>> 7; + } + buf[pos++] = val.lo; +} + +export function int64Length(lo: number, hi: number) { + let part0 = lo, + part1 = ((lo >>> 28) | (hi << 4)) >>> 0, + part2 = hi >>> 24; + return part2 === 0 + ? part1 === 0 + ? part0 < 16384 + ? part0 < 128 + ? 1 + : 2 + : part0 < 2097152 + ? 3 + : 4 + : part1 < 16384 + ? part1 < 128 + ? 5 + : 6 + : part1 < 2097152 + ? 7 + : 8 + : part2 < 128 + ? 9 + : 10; +} + +export function writeFixed32(val: number, buf: Uint8Array | number[], pos: number) { + buf[pos] = val & 255; + buf[pos + 1] = (val >>> 8) & 255; + buf[pos + 2] = (val >>> 16) & 255; + buf[pos + 3] = val >>> 24; +} + +export function writeByte(val: number, buf: Uint8Array | number[], pos: number) { + buf[pos] = val & 255; +} + +// Copyright (c) 2016, Daniel Wirtz All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: + +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of its author, nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * Calculates the UTF8 byte length of a string. + * @param {string} string String + * @returns {number} Byte length + */ +export function utf8Length(str: string) { + let len = 0, + c = 0; + for (let i = 0; i < str.length; ++i) { + c = str.charCodeAt(i); + if (c < 128) len += 1; + else if (c < 2048) len += 2; + else if ((c & 0xfc00) === 0xd800 && (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00) { + ++i; + len += 4; + } else len += 3; + } + return len; +} + +/** + * Reads UTF8 bytes as a string. + * @param {Uint8Array} buffer Source buffer + * @param {number} start Source start + * @param {number} end Source end + * @returns {string} String read + */ +export function utf8Read(buffer: ArrayLike, start: number, end: number) { + const len = end - start; + if (len < 1) return ""; + const chunk = []; + let parts: string[] = [], + i = 0, // char offset + t; // temporary + while (start < end) { + t = buffer[start++]; + if (t < 128) chunk[i++] = t; + else if (t > 191 && t < 224) chunk[i++] = ((t & 31) << 6) | (buffer[start++] & 63); + else if (t > 239 && t < 365) { + t = + (((t & 7) << 18) | ((buffer[start++] & 63) << 12) | ((buffer[start++] & 63) << 6) | (buffer[start++] & 63)) - + 0x10000; + chunk[i++] = 0xd800 + (t >> 10); + chunk[i++] = 0xdc00 + (t & 1023); + } else chunk[i++] = ((t & 15) << 12) | ((buffer[start++] & 63) << 6) | (buffer[start++] & 63); + if (i > 8191) { + (parts || (parts = [])).push(String.fromCharCode(...chunk)); + i = 0; + } + } + if (parts) { + if (i) parts.push(String.fromCharCode(...chunk.slice(0, i))); + return parts.join(""); + } + return String.fromCharCode(...chunk.slice(0, i)); +} + +/** + * Writes a string as UTF8 bytes. + * @param {string} string Source string + * @param {Uint8Array} buffer Destination buffer + * @param {number} offset Destination offset + * @returns {number} Bytes written + */ +export function utf8Write(str: string, buffer: Uint8Array | Array, offset: number) { + const start = offset; + let c1, // character 1 + c2; // character 2 + for (let i = 0; i < str.length; ++i) { + c1 = str.charCodeAt(i); + if (c1 < 128) { + buffer[offset++] = c1; + } else if (c1 < 2048) { + buffer[offset++] = (c1 >> 6) | 192; + buffer[offset++] = (c1 & 63) | 128; + } else if ((c1 & 0xfc00) === 0xd800 && ((c2 = str.charCodeAt(i + 1)) & 0xfc00) === 0xdc00) { + c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff); + ++i; + buffer[offset++] = (c1 >> 18) | 240; + buffer[offset++] = ((c1 >> 12) & 63) | 128; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } else { + buffer[offset++] = (c1 >> 12) | 224; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } + } + return offset - start; +} diff --git a/packages/core/src/externals/osmosis.ts b/packages/core/src/externals/osmosis.ts deleted file mode 100644 index 1a23a9a..0000000 --- a/packages/core/src/externals/osmosis.ts +++ /dev/null @@ -1,716 +0,0 @@ -// @generated by protoc-gen-es v1.2.0 with parameter "target=ts" -// @generated from file osmosis/lockup/tx.proto (package osmosis.lockup, syntax proto3) -/* eslint-disable */ - -import type { - BinaryReadOptions, - FieldList, - JsonReadOptions, - JsonValue, - PartialMessage, - PlainMessage, -} from "@bufbuild/protobuf"; -import { Duration, Message, proto3, protoInt64, Timestamp } from "@bufbuild/protobuf"; - -/** - * @generated from message osmosis.lockup.MsgLockTokens - */ -export class MsgLockTokens extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - /** - * @generated from field: google.protobuf.Duration duration = 2; - */ - duration?: Duration; - - /** - * @generated from field: repeated cosmos.base.v1beta1.Coin coins = 3; - */ - coins: Coin[] = []; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgLockTokens"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "duration", kind: "message", T: Duration }, - { no: 3, name: "coins", kind: "message", T: Coin, repeated: true }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgLockTokens { - return new MsgLockTokens().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgLockTokens { - return new MsgLockTokens().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgLockTokens { - return new MsgLockTokens().fromJsonString(jsonString, options); - } - - static equals( - a: MsgLockTokens | PlainMessage | undefined, - b: MsgLockTokens | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgLockTokens, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgLockTokensResponse - */ -export class MsgLockTokensResponse extends Message { - /** - * @generated from field: uint64 ID = 1; - */ - ID = protoInt64.zero; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgLockTokensResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "ID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgLockTokensResponse { - return new MsgLockTokensResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgLockTokensResponse { - return new MsgLockTokensResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgLockTokensResponse { - return new MsgLockTokensResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgLockTokensResponse | PlainMessage | undefined, - b: MsgLockTokensResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgLockTokensResponse, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgBeginUnlockingAll - */ -export class MsgBeginUnlockingAll extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgBeginUnlockingAll"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgBeginUnlockingAll { - return new MsgBeginUnlockingAll().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgBeginUnlockingAll { - return new MsgBeginUnlockingAll().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgBeginUnlockingAll { - return new MsgBeginUnlockingAll().fromJsonString(jsonString, options); - } - - static equals( - a: MsgBeginUnlockingAll | PlainMessage | undefined, - b: MsgBeginUnlockingAll | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgBeginUnlockingAll, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgBeginUnlockingAllResponse - */ -export class MsgBeginUnlockingAllResponse extends Message { - /** - * @generated from field: repeated osmosis.lockup.PeriodLock unlocks = 1; - */ - unlocks: PeriodLock[] = []; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgBeginUnlockingAllResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "unlocks", kind: "message", T: PeriodLock, repeated: true }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgBeginUnlockingAllResponse { - return new MsgBeginUnlockingAllResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgBeginUnlockingAllResponse { - return new MsgBeginUnlockingAllResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgBeginUnlockingAllResponse { - return new MsgBeginUnlockingAllResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgBeginUnlockingAllResponse | PlainMessage | undefined, - b: MsgBeginUnlockingAllResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgBeginUnlockingAllResponse, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgBeginUnlocking - */ -export class MsgBeginUnlocking extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - /** - * @generated from field: uint64 ID = 2; - */ - ID = protoInt64.zero; - - /** - * Amount of unlocking coins. Unlock all if not set. - * - * @generated from field: repeated cosmos.base.v1beta1.Coin coins = 3; - */ - coins: Coin[] = []; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgBeginUnlocking"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "ID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 3, name: "coins", kind: "message", T: Coin, repeated: true }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgBeginUnlocking { - return new MsgBeginUnlocking().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgBeginUnlocking { - return new MsgBeginUnlocking().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgBeginUnlocking { - return new MsgBeginUnlocking().fromJsonString(jsonString, options); - } - - static equals( - a: MsgBeginUnlocking | PlainMessage | undefined, - b: MsgBeginUnlocking | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgBeginUnlocking, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgBeginUnlockingResponse - */ -export class MsgBeginUnlockingResponse extends Message { - /** - * @generated from field: bool success = 1; - */ - success = false; - - /** - * @generated from field: uint64 unlockingLockID = 2; - */ - unlockingLockID = protoInt64.zero; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgBeginUnlockingResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "success", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - { no: 2, name: "unlockingLockID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgBeginUnlockingResponse { - return new MsgBeginUnlockingResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgBeginUnlockingResponse { - return new MsgBeginUnlockingResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgBeginUnlockingResponse { - return new MsgBeginUnlockingResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgBeginUnlockingResponse | PlainMessage | undefined, - b: MsgBeginUnlockingResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgBeginUnlockingResponse, a, b); - } -} - -/** - * MsgExtendLockup extends the existing lockup's duration. - * The new duration is longer than the original. - * - * @generated from message osmosis.lockup.MsgExtendLockup - */ -export class MsgExtendLockup extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - /** - * @generated from field: uint64 ID = 2; - */ - ID = protoInt64.zero; - - /** - * duration to be set. fails if lower than the current duration, or is - * unlocking - * - * @generated from field: google.protobuf.Duration duration = 3; - */ - duration?: Duration; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgExtendLockup"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "ID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 3, name: "duration", kind: "message", T: Duration }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgExtendLockup { - return new MsgExtendLockup().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgExtendLockup { - return new MsgExtendLockup().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgExtendLockup { - return new MsgExtendLockup().fromJsonString(jsonString, options); - } - - static equals( - a: MsgExtendLockup | PlainMessage | undefined, - b: MsgExtendLockup | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgExtendLockup, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgExtendLockupResponse - */ -export class MsgExtendLockupResponse extends Message { - /** - * @generated from field: bool success = 1; - */ - success = false; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgExtendLockupResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "success", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgExtendLockupResponse { - return new MsgExtendLockupResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgExtendLockupResponse { - return new MsgExtendLockupResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgExtendLockupResponse { - return new MsgExtendLockupResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgExtendLockupResponse | PlainMessage | undefined, - b: MsgExtendLockupResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgExtendLockupResponse, a, b); - } -} - -/** - * MsgForceUnlock unlocks locks immediately for - * addresses registered via governance. - * - * @generated from message osmosis.lockup.MsgForceUnlock - */ -export class MsgForceUnlock extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - /** - * @generated from field: uint64 ID = 2; - */ - ID = protoInt64.zero; - - /** - * Amount of unlocking coins. Unlock all if not set. - * - * @generated from field: repeated cosmos.base.v1beta1.Coin coins = 3; - */ - coins: Coin[] = []; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgForceUnlock"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "ID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 3, name: "coins", kind: "message", T: Coin, repeated: true }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgForceUnlock { - return new MsgForceUnlock().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgForceUnlock { - return new MsgForceUnlock().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgForceUnlock { - return new MsgForceUnlock().fromJsonString(jsonString, options); - } - - static equals( - a: MsgForceUnlock | PlainMessage | undefined, - b: MsgForceUnlock | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgForceUnlock, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgForceUnlockResponse - */ -export class MsgForceUnlockResponse extends Message { - /** - * @generated from field: bool success = 1; - */ - success = false; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgForceUnlockResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "success", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgForceUnlockResponse { - return new MsgForceUnlockResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgForceUnlockResponse { - return new MsgForceUnlockResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgForceUnlockResponse { - return new MsgForceUnlockResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgForceUnlockResponse | PlainMessage | undefined, - b: MsgForceUnlockResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgForceUnlockResponse, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgSetRewardReceiverAddress - */ -export class MsgSetRewardReceiverAddress extends Message { - /** - * @generated from field: string owner = 1; - */ - owner = ""; - - /** - * @generated from field: uint64 lockID = 2; - */ - lockID = protoInt64.zero; - - /** - * @generated from field: string reward_receiver = 3; - */ - rewardReceiver = ""; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgSetRewardReceiverAddress"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "lockID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 3, name: "reward_receiver", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgSetRewardReceiverAddress { - return new MsgSetRewardReceiverAddress().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgSetRewardReceiverAddress { - return new MsgSetRewardReceiverAddress().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgSetRewardReceiverAddress { - return new MsgSetRewardReceiverAddress().fromJsonString(jsonString, options); - } - - static equals( - a: MsgSetRewardReceiverAddress | PlainMessage | undefined, - b: MsgSetRewardReceiverAddress | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgSetRewardReceiverAddress, a, b); - } -} - -/** - * @generated from message osmosis.lockup.MsgSetRewardReceiverAddressResponse - */ -export class MsgSetRewardReceiverAddressResponse extends Message { - /** - * @generated from field: bool success = 1; - */ - success = false; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.MsgSetRewardReceiverAddressResponse"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "success", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): MsgSetRewardReceiverAddressResponse { - return new MsgSetRewardReceiverAddressResponse().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): MsgSetRewardReceiverAddressResponse { - return new MsgSetRewardReceiverAddressResponse().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): MsgSetRewardReceiverAddressResponse { - return new MsgSetRewardReceiverAddressResponse().fromJsonString(jsonString, options); - } - - static equals( - a: MsgSetRewardReceiverAddressResponse | PlainMessage | undefined, - b: MsgSetRewardReceiverAddressResponse | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(MsgSetRewardReceiverAddressResponse, a, b); - } -} - -/** - * PeriodLock is a single lock unit by period defined by the x/lockup module. - * It's a record of a locked coin at a specific time. It stores owner, duration, - * unlock time and the number of coins locked. A state of a period lock is - * created upon lock creation, and deleted once the lock has been matured after - * the `duration` has passed since unbonding started. - * - * @generated from message osmosis.lockup.PeriodLock - */ -export class PeriodLock extends Message { - /** - * ID is the unique id of the lock. - * The ID of the lock is decided upon lock creation, incrementing by 1 for - * every lock. - * - * @generated from field: uint64 ID = 1; - */ - ID = protoInt64.zero; - - /** - * Owner is the account address of the lock owner. - * Only the owner can modify the state of the lock. - * - * @generated from field: string owner = 2; - */ - owner = ""; - - /** - * Duration is the time needed for a lock to mature after unlocking has - * started. - * - * @generated from field: google.protobuf.Duration duration = 3; - */ - duration?: Duration; - - /** - * EndTime refers to the time at which the lock would mature and get deleted. - * This value is first initialized when an unlock has started for the lock, - * end time being block time + duration. - * - * @generated from field: google.protobuf.Timestamp end_time = 4; - */ - endTime?: Timestamp; - - /** - * Coins are the tokens locked within the lock, kept in the module account. - * - * @generated from field: repeated cosmos.base.v1beta1.Coin coins = 5; - */ - coins: Coin[] = []; - - /** - * Reward Receiver Address is the address that would be receiving rewards for - * the incentives for the lock. This is set to owner by default and can be - * changed via separate msg. - * - * @generated from field: string reward_receiver_address = 6; - */ - rewardReceiverAddress = ""; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "osmosis.lockup.PeriodLock"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "ID", kind: "scalar", T: 4 /* ScalarType.UINT64 */ }, - { no: 2, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "duration", kind: "message", T: Duration }, - { no: 4, name: "end_time", kind: "message", T: Timestamp }, - { no: 5, name: "coins", kind: "message", T: Coin, repeated: true }, - { no: 6, name: "reward_receiver_address", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): PeriodLock { - return new PeriodLock().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): PeriodLock { - return new PeriodLock().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): PeriodLock { - return new PeriodLock().fromJsonString(jsonString, options); - } - - static equals( - a: PeriodLock | PlainMessage | undefined, - b: PeriodLock | PlainMessage | undefined, - ): boolean { - return proto3.util.equals(PeriodLock, a, b); - } -} - -/** - * Coin defines a token with a denomination and an amount. - * - * NOTE: The amount field is an Int which implements the custom method - * signatures required by gogoproto. - * - * @generated from message cosmos.base.v1beta1.Coin - */ -export class Coin extends Message { - /** - * @generated from field: string denom = 1; - */ - denom = ""; - - /** - * @generated from field: string amount = 2; - */ - amount = ""; - - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } - - static readonly runtime: typeof proto3 = proto3; - static readonly typeName = "cosmos.base.v1beta1.Coin"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "denom", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "amount", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): Coin { - return new Coin().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): Coin { - return new Coin().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): Coin { - return new Coin().fromJsonString(jsonString, options); - } - - static equals(a: Coin | PlainMessage | undefined, b: Coin | PlainMessage | undefined): boolean { - return proto3.util.equals(Coin, a, b); - } -} diff --git a/packages/core/src/externals/osmosis/binary.ts b/packages/core/src/externals/osmosis/binary.ts new file mode 100644 index 0000000..cc0f6a0 --- /dev/null +++ b/packages/core/src/externals/osmosis/binary.ts @@ -0,0 +1,491 @@ +// Copyright (c) 2016, Daniel Wirtz All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: + +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of its author, nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- + +// Code generated by the command line utilities is owned by the owner +// of the input file used when generating it. This code is not +// standalone and requires a support library to be linked with it. This +// support library is itself covered by the above license. + +import { utf8Length, utf8Read, utf8Write } from "./utf8"; +import { + int64FromString, + int64Length, + int64ToString, + readInt32, + readUInt32, + uInt64ToString, + varint32read, + varint64read, + writeByte, + writeFixed32, + writeVarint32, + writeVarint64, + zzDecode, + zzEncode, +} from "./varint"; + +export enum WireType { + Varint = 0, + + Fixed64 = 1, + + Bytes = 2, + + Fixed32 = 5, +} + +// Reader +export interface IBinaryReader { + buf: Uint8Array; + pos: number; + type: number; + len: number; + tag(): [number, WireType, number]; + skip(length?: number): this; + skipType(wireType: number): this; + uint32(): number; + int32(): number; + sint32(): number; + fixed32(): number; + sfixed32(): number; + int64(): bigint; + uint64(): bigint; + sint64(): bigint; + fixed64(): bigint; + sfixed64(): bigint; + float(): number; + double(): number; + bool(): boolean; + bytes(): Uint8Array; + string(): string; +} + +export class BinaryReader implements IBinaryReader { + buf: Uint8Array; + pos: number; + type: number; + len: number; + + assertBounds(): void { + if (this.pos > this.len) throw new RangeError("premature EOF"); + } + + constructor(buf?: ArrayLike) { + this.buf = buf ? new Uint8Array(buf) : new Uint8Array(0); + this.pos = 0; + this.type = 0; + this.len = this.buf.length; + } + + tag(): [number, WireType, number] { + const tag = this.uint32(), + fieldNo = tag >>> 3, + wireType = tag & 7; + if (fieldNo <= 0 || wireType < 0 || wireType > 5) + throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType); + return [fieldNo, wireType, tag]; + } + + skip(length?: number) { + if (typeof length === "number") { + if (this.pos + length > this.len) throw indexOutOfRange(this, length); + this.pos += length; + } else { + do { + if (this.pos >= this.len) throw indexOutOfRange(this); + } while (this.buf[this.pos++] & 128); + } + return this; + } + + skipType(wireType: number) { + switch (wireType) { + case WireType.Varint: + this.skip(); + break; + case WireType.Fixed64: + this.skip(8); + break; + case WireType.Bytes: + this.skip(this.uint32()); + break; + case 3: + while ((wireType = this.uint32() & 7) !== 4) { + this.skipType(wireType); + } + break; + case WireType.Fixed32: + this.skip(4); + break; + + /* istanbul ignore next */ + default: + throw Error("invalid wire type " + wireType + " at offset " + this.pos); + } + return this; + } + + uint32(): number { + return varint32read.bind(this)(); + } + + int32(): number { + return this.uint32() | 0; + } + + sint32(): number { + const num = this.uint32(); + return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding + } + + fixed32(): number { + const val = readUInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + sfixed32(): number { + const val = readInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + int64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(int64ToString(lo, hi)); + } + + uint64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(uInt64ToString(lo, hi)); + } + + sint64(): bigint { + let [lo, hi] = varint64read.bind(this)(); + // zig zag + [lo, hi] = zzDecode(lo, hi); + return BigInt(int64ToString(lo, hi)); + } + + fixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(uInt64ToString(lo, hi)); + } + sfixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(int64ToString(lo, hi)); + } + + float(): number { + throw new Error("float not supported"); + } + + double(): number { + throw new Error("double not supported"); + } + + bool(): boolean { + const [lo, hi] = varint64read.bind(this)(); + return lo !== 0 || hi !== 0; + } + + bytes(): Uint8Array { + const len = this.uint32(), + start = this.pos; + this.pos += len; + this.assertBounds(); + return this.buf.subarray(start, start + len); + } + + string(): string { + const bytes = this.bytes(); + return utf8Read(bytes, 0, bytes.length); + } +} + +// Writer +export interface IBinaryWriter { + len: number; + head: IOp; + tail: IOp; + states: State | null; + finish(): Uint8Array; + fork(): IBinaryWriter; + reset(): IBinaryWriter; + ldelim(): IBinaryWriter; + tag(fieldNo: number, type: WireType): IBinaryWriter; + uint32(value: number): IBinaryWriter; + int32(value: number): IBinaryWriter; + sint32(value: number): IBinaryWriter; + int64(value: string | number | bigint): IBinaryWriter; + uint64: (value: string | number | bigint) => IBinaryWriter; + sint64(value: string | number | bigint): IBinaryWriter; + fixed64(value: string | number | bigint): IBinaryWriter; + sfixed64: (value: string | number | bigint) => IBinaryWriter; + bool(value: boolean): IBinaryWriter; + fixed32(value: number): IBinaryWriter; + sfixed32: (value: number) => IBinaryWriter; + float(value: number): IBinaryWriter; + double(value: number): IBinaryWriter; + bytes(value: Uint8Array): IBinaryWriter; + string(value: string): IBinaryWriter; +} + +interface IOp { + len: number; + next?: IOp; + proceed(buf: Uint8Array | number[], pos: number): void; +} + +class Op implements IOp { + fn?: ((val: T, buf: Uint8Array | number[], pos: number) => void) | null; + len: number; + val: T; + next?: IOp; + + constructor( + fn: ((val: T, buf: Uint8Array | number[], pos: number) => void | undefined | null) | null, + len: number, + val: T, + ) { + this.fn = fn; + this.len = len; + this.val = val; + } + + proceed(buf: Uint8Array | number[], pos: number) { + if (this.fn) { + this.fn(this.val, buf, pos); + } + } +} + +class State { + head: IOp; + tail: IOp; + len: number; + next: State | null; + + constructor(writer: BinaryWriter) { + this.head = writer.head; + this.tail = writer.tail; + this.len = writer.len; + this.next = writer.states; + } +} + +export class BinaryWriter implements IBinaryWriter { + len = 0; + head: IOp; + tail: IOp; + states: State | null; + + constructor() { + this.head = new Op(null, 0, 0); + this.tail = this.head; + this.states = null; + } + + static create() { + return new BinaryWriter(); + } + + static alloc(size: number): Uint8Array | number[] { + if (typeof Uint8Array !== "undefined") { + return pool((size) => new Uint8Array(size), Uint8Array.prototype.subarray)(size); + } else { + return new Array(size); + } + } + + private _push(fn: (val: T, buf: Uint8Array | number[], pos: number) => void, len: number, val: T) { + this.tail = this.tail.next = new Op(fn, len, val); + this.len += len; + return this; + } + + finish(): Uint8Array { + let head = this.head.next, + pos = 0; + const buf = BinaryWriter.alloc(this.len); + while (head) { + head.proceed(buf, pos); + pos += head.len; + head = head.next; + } + return buf as Uint8Array; + } + + fork(): BinaryWriter { + this.states = new State(this); + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + return this; + } + + reset(): BinaryWriter { + if (this.states) { + this.head = this.states.head; + this.tail = this.states.tail; + this.len = this.states.len; + this.states = this.states.next; + } else { + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + } + return this; + } + + ldelim(): BinaryWriter { + const head = this.head, + tail = this.tail, + len = this.len; + this.reset().uint32(len); + if (len) { + this.tail.next = head.next; // skip noop + this.tail = tail; + this.len += len; + } + return this; + } + + tag(fieldNo: number, type: WireType): BinaryWriter { + return this.uint32(((fieldNo << 3) | type) >>> 0); + } + + uint32(value: number): BinaryWriter { + this.len += (this.tail = this.tail.next = + new Op( + writeVarint32, + (value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, + value, + )).len; + return this; + } + + int32(value: number): BinaryWriter { + return value < 0 + ? this._push(writeVarint64, 10, int64FromString(value.toString())) // 10 bytes per spec + : this.uint32(value); + } + + sint32(value: number): BinaryWriter { + return this.uint32(((value << 1) ^ (value >> 31)) >>> 0); + } + + int64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + // uint64 is the same with int64 + uint64 = BinaryWriter.prototype.int64; + + sint64(value: string | number | bigint): BinaryWriter { + let { lo, hi } = int64FromString(value.toString()); + // zig zag + [lo, hi] = zzEncode(lo, hi); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + fixed64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeFixed32, 4, lo)._push(writeFixed32, 4, hi); + } + + // sfixed64 is the same with fixed64 + sfixed64 = BinaryWriter.prototype.fixed64; + + bool(value: boolean): BinaryWriter { + return this._push(writeByte, 1, value ? 1 : 0); + } + + fixed32(value: number): BinaryWriter { + return this._push(writeFixed32, 4, value >>> 0); + } + + // sfixed32 is the same with fixed32 + sfixed32 = BinaryWriter.prototype.fixed32; + + float(value: number): BinaryWriter { + throw new Error("float not supported" + value); + } + + double(value: number): BinaryWriter { + throw new Error("double not supported" + value); + } + + bytes(value: Uint8Array): BinaryWriter { + const len = value.length >>> 0; + if (!len) return this._push(writeByte, 1, 0); + return this.uint32(len)._push(writeBytes, len, value); + } + + string(value: string): BinaryWriter { + const len = utf8Length(value); + return len ? this.uint32(len)._push(utf8Write, len, value) : this._push(writeByte, 1, 0); + } +} + +function writeBytes(val: Uint8Array | number[], buf: Uint8Array | number[], pos: number) { + if (typeof Uint8Array !== "undefined") { + (buf as Uint8Array).set(val, pos); + } else { + for (let i = 0; i < val.length; ++i) buf[pos + i] = val[i]; + } +} + +function pool( + alloc: (size: number) => Uint8Array, + slice: (begin?: number, end?: number) => Uint8Array, + size?: number, +): (size: number) => Uint8Array { + const SIZE = size || 8192; + const MAX = SIZE >>> 1; + let slab: Uint8Array | null = null; + let offset = SIZE; + return function pool_alloc(size): Uint8Array { + if (size < 1 || size > MAX) return alloc(size); + if (offset + size > SIZE) { + slab = alloc(SIZE); + offset = 0; + } + const buf: Uint8Array = slice.call(slab, offset, (offset += size)); + if (offset & 7) + // align to 32 bit + offset = (offset | 7) + 1; + return buf; + }; +} + +function indexOutOfRange(reader: BinaryReader, writeLength?: number) { + return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len); +} diff --git a/packages/core/src/externals/osmosis/coin.ts b/packages/core/src/externals/osmosis/coin.ts new file mode 100644 index 0000000..cfe3f2f --- /dev/null +++ b/packages/core/src/externals/osmosis/coin.ts @@ -0,0 +1,418 @@ +import { BinaryReader, BinaryWriter } from "./binary"; + +/** + * Coin defines a token with a denomination and an amount. + * + * NOTE: The amount field is an Int which implements the custom method + * signatures required by gogoproto. + */ +export interface Coin { + denom: string; + amount: string; +} +export interface CoinProtoMsg { + typeUrl: "/cosmos.base.v1beta1.Coin"; + value: Uint8Array; +} +/** + * Coin defines a token with a denomination and an amount. + * + * NOTE: The amount field is an Int which implements the custom method + * signatures required by gogoproto. + */ +export interface CoinAmino { + denom?: string; + amount?: string; +} +export interface CoinAminoMsg { + type: "cosmos-sdk/Coin"; + value: CoinAmino; +} +/** + * Coin defines a token with a denomination and an amount. + * + * NOTE: The amount field is an Int which implements the custom method + * signatures required by gogoproto. + */ +export interface CoinSDKType { + denom: string; + amount: string; +} +/** + * DecCoin defines a token with a denomination and a decimal amount. + * + * NOTE: The amount field is an Dec which implements the custom method + * signatures required by gogoproto. + */ +export interface DecCoin { + denom: string; + amount: string; +} +export interface DecCoinProtoMsg { + typeUrl: "/cosmos.base.v1beta1.DecCoin"; + value: Uint8Array; +} +/** + * DecCoin defines a token with a denomination and a decimal amount. + * + * NOTE: The amount field is an Dec which implements the custom method + * signatures required by gogoproto. + */ +export interface DecCoinAmino { + denom?: string; + amount?: string; +} +export interface DecCoinAminoMsg { + type: "cosmos-sdk/DecCoin"; + value: DecCoinAmino; +} +/** + * DecCoin defines a token with a denomination and a decimal amount. + * + * NOTE: The amount field is an Dec which implements the custom method + * signatures required by gogoproto. + */ +export interface DecCoinSDKType { + denom: string; + amount: string; +} +/** IntProto defines a Protobuf wrapper around an Int object. */ +export interface IntProto { + int: string; +} +export interface IntProtoProtoMsg { + typeUrl: "/cosmos.base.v1beta1.IntProto"; + value: Uint8Array; +} +/** IntProto defines a Protobuf wrapper around an Int object. */ +export interface IntProtoAmino { + int?: string; +} +export interface IntProtoAminoMsg { + type: "cosmos-sdk/IntProto"; + value: IntProtoAmino; +} +/** IntProto defines a Protobuf wrapper around an Int object. */ +export interface IntProtoSDKType { + int: string; +} +/** DecProto defines a Protobuf wrapper around a Dec object. */ +export interface DecProto { + dec: string; +} +export interface DecProtoProtoMsg { + typeUrl: "/cosmos.base.v1beta1.DecProto"; + value: Uint8Array; +} +/** DecProto defines a Protobuf wrapper around a Dec object. */ +export interface DecProtoAmino { + dec?: string; +} +export interface DecProtoAminoMsg { + type: "cosmos-sdk/DecProto"; + value: DecProtoAmino; +} +/** DecProto defines a Protobuf wrapper around a Dec object. */ +export interface DecProtoSDKType { + dec: string; +} +function createBaseCoin(): Coin { + return { + denom: "", + amount: "", + }; +} +export const Coin = { + typeUrl: "/cosmos.base.v1beta1.Coin", + encode(message: Coin, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.denom !== "") { + writer.uint32(10).string(message.denom); + } + if (message.amount !== "") { + writer.uint32(18).string(message.amount); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): Coin { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCoin(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.amount = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): Coin { + const message = createBaseCoin(); + message.denom = object.denom ?? ""; + message.amount = object.amount ?? ""; + return message; + }, + fromAmino(object: CoinAmino): Coin { + const message = createBaseCoin(); + if (object.denom !== undefined && object.denom !== null) { + message.denom = object.denom; + } + if (object.amount !== undefined && object.amount !== null) { + message.amount = object.amount; + } + return message; + }, + toAmino(message: Coin): CoinAmino { + const obj: any = {}; + obj.denom = message.denom === "" ? undefined : message.denom; + obj.amount = message.amount === "" ? undefined : message.amount; + return obj; + }, + fromAminoMsg(object: CoinAminoMsg): Coin { + return Coin.fromAmino(object.value); + }, + toAminoMsg(message: Coin): CoinAminoMsg { + return { + type: "cosmos-sdk/Coin", + value: Coin.toAmino(message), + }; + }, + fromProtoMsg(message: CoinProtoMsg): Coin { + return Coin.decode(message.value); + }, + toProto(message: Coin): Uint8Array { + return Coin.encode(message).finish(); + }, + toProtoMsg(message: Coin): CoinProtoMsg { + return { + typeUrl: "/cosmos.base.v1beta1.Coin", + value: Coin.encode(message).finish(), + }; + }, +}; +function createBaseDecCoin(): DecCoin { + return { + denom: "", + amount: "", + }; +} +export const DecCoin = { + typeUrl: "/cosmos.base.v1beta1.DecCoin", + encode(message: DecCoin, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.denom !== "") { + writer.uint32(10).string(message.denom); + } + if (message.amount !== "") { + writer.uint32(18).string(message.amount); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): DecCoin { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDecCoin(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.amount = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): DecCoin { + const message = createBaseDecCoin(); + message.denom = object.denom ?? ""; + message.amount = object.amount ?? ""; + return message; + }, + fromAmino(object: DecCoinAmino): DecCoin { + const message = createBaseDecCoin(); + if (object.denom !== undefined && object.denom !== null) { + message.denom = object.denom; + } + if (object.amount !== undefined && object.amount !== null) { + message.amount = object.amount; + } + return message; + }, + toAmino(message: DecCoin): DecCoinAmino { + const obj: any = {}; + obj.denom = message.denom === "" ? undefined : message.denom; + obj.amount = message.amount === "" ? undefined : message.amount; + return obj; + }, + fromAminoMsg(object: DecCoinAminoMsg): DecCoin { + return DecCoin.fromAmino(object.value); + }, + toAminoMsg(message: DecCoin): DecCoinAminoMsg { + return { + type: "cosmos-sdk/DecCoin", + value: DecCoin.toAmino(message), + }; + }, + fromProtoMsg(message: DecCoinProtoMsg): DecCoin { + return DecCoin.decode(message.value); + }, + toProto(message: DecCoin): Uint8Array { + return DecCoin.encode(message).finish(); + }, + toProtoMsg(message: DecCoin): DecCoinProtoMsg { + return { + typeUrl: "/cosmos.base.v1beta1.DecCoin", + value: DecCoin.encode(message).finish(), + }; + }, +}; +function createBaseIntProto(): IntProto { + return { + int: "", + }; +} +export const IntProto = { + typeUrl: "/cosmos.base.v1beta1.IntProto", + encode(message: IntProto, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.int !== "") { + writer.uint32(10).string(message.int); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): IntProto { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseIntProto(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.int = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): IntProto { + const message = createBaseIntProto(); + message.int = object.int ?? ""; + return message; + }, + fromAmino(object: IntProtoAmino): IntProto { + const message = createBaseIntProto(); + if (object.int !== undefined && object.int !== null) { + message.int = object.int; + } + return message; + }, + toAmino(message: IntProto): IntProtoAmino { + const obj: any = {}; + obj.int = message.int === "" ? undefined : message.int; + return obj; + }, + fromAminoMsg(object: IntProtoAminoMsg): IntProto { + return IntProto.fromAmino(object.value); + }, + toAminoMsg(message: IntProto): IntProtoAminoMsg { + return { + type: "cosmos-sdk/IntProto", + value: IntProto.toAmino(message), + }; + }, + fromProtoMsg(message: IntProtoProtoMsg): IntProto { + return IntProto.decode(message.value); + }, + toProto(message: IntProto): Uint8Array { + return IntProto.encode(message).finish(); + }, + toProtoMsg(message: IntProto): IntProtoProtoMsg { + return { + typeUrl: "/cosmos.base.v1beta1.IntProto", + value: IntProto.encode(message).finish(), + }; + }, +}; +function createBaseDecProto(): DecProto { + return { + dec: "", + }; +} +export const DecProto = { + typeUrl: "/cosmos.base.v1beta1.DecProto", + encode(message: DecProto, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.dec !== "") { + writer.uint32(10).string(message.dec); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): DecProto { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDecProto(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dec = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): DecProto { + const message = createBaseDecProto(); + message.dec = object.dec ?? ""; + return message; + }, + fromAmino(object: DecProtoAmino): DecProto { + const message = createBaseDecProto(); + if (object.dec !== undefined && object.dec !== null) { + message.dec = object.dec; + } + return message; + }, + toAmino(message: DecProto): DecProtoAmino { + const obj: any = {}; + obj.dec = message.dec === "" ? undefined : message.dec; + return obj; + }, + fromAminoMsg(object: DecProtoAminoMsg): DecProto { + return DecProto.fromAmino(object.value); + }, + toAminoMsg(message: DecProto): DecProtoAminoMsg { + return { + type: "cosmos-sdk/DecProto", + value: DecProto.toAmino(message), + }; + }, + fromProtoMsg(message: DecProtoProtoMsg): DecProto { + return DecProto.decode(message.value); + }, + toProto(message: DecProto): Uint8Array { + return DecProto.encode(message).finish(); + }, + toProtoMsg(message: DecProto): DecProtoProtoMsg { + return { + typeUrl: "/cosmos.base.v1beta1.DecProto", + value: DecProto.encode(message).finish(), + }; + }, +}; diff --git a/packages/core/src/externals/osmosis/duration.ts b/packages/core/src/externals/osmosis/duration.ts new file mode 100644 index 0000000..149b9d3 --- /dev/null +++ b/packages/core/src/externals/osmosis/duration.ts @@ -0,0 +1,282 @@ +import { BinaryReader, BinaryWriter } from "./binary"; + +/** + * A Duration represents a signed, fixed-length span of time represented + * as a count of seconds and fractions of seconds at nanosecond + * resolution. It is independent of any calendar and concepts like "day" + * or "month". It is related to Timestamp in that the difference between + * two Timestamp values is a Duration and it can be added or subtracted + * from a Timestamp. Range is approximately +-10,000 years. + * + * # Examples + * + * Example 1: Compute Duration from two Timestamps in pseudo code. + * + * Timestamp start = ...; + * Timestamp end = ...; + * Duration duration = ...; + * + * duration.seconds = end.seconds - start.seconds; + * duration.nanos = end.nanos - start.nanos; + * + * if (duration.seconds < 0 && duration.nanos > 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.seconds > 0 && duration.nanos < 0) { + * duration.seconds -= 1; + * duration.nanos += 1000000000; + * } + * + * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + * + * Timestamp start = ...; + * Duration duration = ...; + * Timestamp end = ...; + * + * end.seconds = start.seconds + duration.seconds; + * end.nanos = start.nanos + duration.nanos; + * + * if (end.nanos < 0) { + * end.seconds -= 1; + * end.nanos += 1000000000; + * } else if (end.nanos >= 1000000000) { + * end.seconds += 1; + * end.nanos -= 1000000000; + * } + * + * Example 3: Compute Duration from datetime.timedelta in Python. + * + * td = datetime.timedelta(days=3, minutes=10) + * duration = Duration() + * duration.FromTimedelta(td) + * + * # JSON Mapping + * + * In JSON format, the Duration type is encoded as a string rather than an + * object, where the string ends in the suffix "s" (indicating seconds) and + * is preceded by the number of seconds, with nanoseconds expressed as + * fractional seconds. For example, 3 seconds with 0 nanoseconds should be + * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + * microsecond should be expressed in JSON format as "3.000001s". + */ +export interface Duration { + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + */ + seconds: bigint; + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + */ + nanos: number; +} +export interface DurationProtoMsg { + typeUrl: "/google.protobuf.Duration"; + value: Uint8Array; +} +/** + * A Duration represents a signed, fixed-length span of time represented + * as a count of seconds and fractions of seconds at nanosecond + * resolution. It is independent of any calendar and concepts like "day" + * or "month". It is related to Timestamp in that the difference between + * two Timestamp values is a Duration and it can be added or subtracted + * from a Timestamp. Range is approximately +-10,000 years. + * + * # Examples + * + * Example 1: Compute Duration from two Timestamps in pseudo code. + * + * Timestamp start = ...; + * Timestamp end = ...; + * Duration duration = ...; + * + * duration.seconds = end.seconds - start.seconds; + * duration.nanos = end.nanos - start.nanos; + * + * if (duration.seconds < 0 && duration.nanos > 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.seconds > 0 && duration.nanos < 0) { + * duration.seconds -= 1; + * duration.nanos += 1000000000; + * } + * + * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + * + * Timestamp start = ...; + * Duration duration = ...; + * Timestamp end = ...; + * + * end.seconds = start.seconds + duration.seconds; + * end.nanos = start.nanos + duration.nanos; + * + * if (end.nanos < 0) { + * end.seconds -= 1; + * end.nanos += 1000000000; + * } else if (end.nanos >= 1000000000) { + * end.seconds += 1; + * end.nanos -= 1000000000; + * } + * + * Example 3: Compute Duration from datetime.timedelta in Python. + * + * td = datetime.timedelta(days=3, minutes=10) + * duration = Duration() + * duration.FromTimedelta(td) + * + * # JSON Mapping + * + * In JSON format, the Duration type is encoded as a string rather than an + * object, where the string ends in the suffix "s" (indicating seconds) and + * is preceded by the number of seconds, with nanoseconds expressed as + * fractional seconds. For example, 3 seconds with 0 nanoseconds should be + * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + * microsecond should be expressed in JSON format as "3.000001s". + */ +export type DurationAmino = string; +export interface DurationAminoMsg { + type: "/google.protobuf.Duration"; + value: DurationAmino; +} +/** + * A Duration represents a signed, fixed-length span of time represented + * as a count of seconds and fractions of seconds at nanosecond + * resolution. It is independent of any calendar and concepts like "day" + * or "month". It is related to Timestamp in that the difference between + * two Timestamp values is a Duration and it can be added or subtracted + * from a Timestamp. Range is approximately +-10,000 years. + * + * # Examples + * + * Example 1: Compute Duration from two Timestamps in pseudo code. + * + * Timestamp start = ...; + * Timestamp end = ...; + * Duration duration = ...; + * + * duration.seconds = end.seconds - start.seconds; + * duration.nanos = end.nanos - start.nanos; + * + * if (duration.seconds < 0 && duration.nanos > 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.seconds > 0 && duration.nanos < 0) { + * duration.seconds -= 1; + * duration.nanos += 1000000000; + * } + * + * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + * + * Timestamp start = ...; + * Duration duration = ...; + * Timestamp end = ...; + * + * end.seconds = start.seconds + duration.seconds; + * end.nanos = start.nanos + duration.nanos; + * + * if (end.nanos < 0) { + * end.seconds -= 1; + * end.nanos += 1000000000; + * } else if (end.nanos >= 1000000000) { + * end.seconds += 1; + * end.nanos -= 1000000000; + * } + * + * Example 3: Compute Duration from datetime.timedelta in Python. + * + * td = datetime.timedelta(days=3, minutes=10) + * duration = Duration() + * duration.FromTimedelta(td) + * + * # JSON Mapping + * + * In JSON format, the Duration type is encoded as a string rather than an + * object, where the string ends in the suffix "s" (indicating seconds) and + * is preceded by the number of seconds, with nanoseconds expressed as + * fractional seconds. For example, 3 seconds with 0 nanoseconds should be + * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + * microsecond should be expressed in JSON format as "3.000001s". + */ +export interface DurationSDKType { + seconds: bigint; + nanos: number; +} +function createBaseDuration(): Duration { + return { + seconds: BigInt(0), + nanos: 0, + }; +} +export const Duration = { + typeUrl: "/google.protobuf.Duration", + encode(message: Duration, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.seconds !== BigInt(0)) { + writer.uint32(8).int64(message.seconds); + } + if (message.nanos !== 0) { + writer.uint32(16).int32(message.nanos); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): Duration { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDuration(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.seconds = reader.int64(); + break; + case 2: + message.nanos = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): Duration { + const message = createBaseDuration(); + message.seconds = + object.seconds !== undefined && object.seconds !== null ? BigInt(object.seconds.toString()) : BigInt(0); + message.nanos = object.nanos ?? 0; + return message; + }, + fromAmino(object: DurationAmino): Duration { + const value = BigInt(object); + return { + seconds: value / BigInt("1000000000"), + nanos: Number(value % BigInt("1000000000")), + }; + }, + toAmino(message: Duration): DurationAmino { + return (message.seconds * BigInt("1000000000") + BigInt(message.nanos)).toString(); + }, + fromAminoMsg(object: DurationAminoMsg): Duration { + return Duration.fromAmino(object.value); + }, + fromProtoMsg(message: DurationProtoMsg): Duration { + return Duration.decode(message.value); + }, + toProto(message: Duration): Uint8Array { + return Duration.encode(message).finish(); + }, + toProtoMsg(message: Duration): DurationProtoMsg { + return { + typeUrl: "/google.protobuf.Duration", + value: Duration.encode(message).finish(), + }; + }, +}; diff --git a/packages/core/src/externals/osmosis/helpers.ts b/packages/core/src/externals/osmosis/helpers.ts new file mode 100644 index 0000000..21e1460 --- /dev/null +++ b/packages/core/src/externals/osmosis/helpers.ts @@ -0,0 +1,222 @@ +/* eslint-disable @typescript-eslint/ban-types */ +/* eslint-disable no-var */ +// @ts-nocheck + +declare let self: any | undefined; +declare let window: any | undefined; +declare let global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); + +export function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); + +export function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return btoa(bin.join("")); +} + +export interface AminoHeight { + readonly revision_number?: string; + readonly revision_height?: string; +} + +export function omitDefault(input: T): T | undefined { + if (typeof input === "string") { + return input === "" ? undefined : input; + } + + if (typeof input === "number") { + return input === 0 ? undefined : input; + } + + if (typeof input === "boolean") { + return input === false ? undefined : input; + } + + if (typeof input === "bigint") { + return input === BigInt(0) ? undefined : input; + } + + throw new Error(`Got unsupported type ${typeof input}`); +} + +interface Duration { + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + */ + seconds: bigint; + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + */ + + nanos: number; +} + +export function toDuration(duration: string): Duration { + return { + seconds: BigInt(Math.floor(parseInt(duration) / 1000000000)), + nanos: parseInt(duration) % 1000000000, + }; +} + +export function fromDuration(duration: Duration): string { + return (parseInt(duration.seconds.toString()) * 1000000000 + duration.nanos).toString(); +} + +export function isSet(value: any): boolean { + return value !== null && value !== undefined; +} + +export function isObject(value: any): boolean { + return typeof value === "object" && value !== null; +} + +export interface PageRequest { + key: Uint8Array; + offset: bigint; + limit: bigint; + countTotal: boolean; + reverse: boolean; +} + +export interface PageRequestParams { + "pagination.key"?: string; + "pagination.offset"?: string; + "pagination.limit"?: string; + "pagination.count_total"?: boolean; + "pagination.reverse"?: boolean; +} + +export interface Params { + params: PageRequestParams; +} + +export const setPaginationParams = (options: Params, pagination?: PageRequest) => { + if (!pagination) { + return options; + } + + if (typeof pagination?.countTotal !== "undefined") { + options.params["pagination.count_total"] = pagination.countTotal; + } + if (typeof pagination?.key !== "undefined") { + // String to Uint8Array + // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); + + // Uint8Array to String + options.params["pagination.key"] = Buffer.from(pagination.key).toString("base64"); + } + if (typeof pagination?.limit !== "undefined") { + options.params["pagination.limit"] = pagination.limit.toString(); + } + if (typeof pagination?.offset !== "undefined") { + options.params["pagination.offset"] = pagination.offset.toString(); + } + if (typeof pagination?.reverse !== "undefined") { + options.params["pagination.reverse"] = pagination.reverse; + } + + return options; +}; + +type Builtin = Date | Function | Uint8Array | string | number | bigint | boolean | undefined; + +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + +export interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + */ + seconds: bigint; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + */ + + nanos: number; +} + +export function toTimestamp(date: Date): Timestamp { + const seconds = numberToLong(date.getTime() / 1_000); + const nanos = (date.getTime() % 1000) * 1000000; + return { + seconds, + nanos, + }; +} + +export function fromTimestamp(t: Timestamp): Date { + let millis = Number(t.seconds) * 1000; + millis += t.nanos / 1000000; + return new Date(millis); +} + +const timestampFromJSON = (object: any): Timestamp => { + return { + seconds: isSet(object.seconds) ? BigInt(object.seconds.toString()) : BigInt(0), + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; +}; + +export function fromJsonTimestamp(o: any): Timestamp { + if (o instanceof Date) { + return toTimestamp(o); + } else if (typeof o === "string") { + return toTimestamp(new Date(o)); + } else { + return timestampFromJSON(o); + } +} + +function numberToLong(number: number) { + return BigInt(Math.trunc(number)); +} diff --git a/packages/core/src/externals/osmosis/lockup.ts b/packages/core/src/externals/osmosis/lockup.ts new file mode 100644 index 0000000..b1d0a51 --- /dev/null +++ b/packages/core/src/externals/osmosis/lockup.ts @@ -0,0 +1,1899 @@ +import { BinaryReader, BinaryWriter } from "./binary"; +import { Coin, CoinAmino, CoinSDKType } from "./coin"; +import { Duration, DurationAmino, DurationSDKType } from "./duration"; +import { Timestamp } from "./timestamp"; +import { fromTimestamp, toTimestamp } from "./helpers"; + +/** + * LockQueryType defines the type of the lock query that can + * either be by duration or start time of the lock. + */ +export enum LockQueryType { + ByDuration = 0, + ByTime = 1, + NoLock = 2, + ByGroup = 3, + UNRECOGNIZED = -1, +} +export const LockQueryTypeSDKType = LockQueryType; +export const LockQueryTypeAmino = LockQueryType; +export function lockQueryTypeFromJSON(object: any): LockQueryType { + switch (object) { + case 0: + case "ByDuration": + return LockQueryType.ByDuration; + case 1: + case "ByTime": + return LockQueryType.ByTime; + case 2: + case "NoLock": + return LockQueryType.NoLock; + case 3: + case "ByGroup": + return LockQueryType.ByGroup; + case -1: + case "UNRECOGNIZED": + default: + return LockQueryType.UNRECOGNIZED; + } +} +export function lockQueryTypeToJSON(object: LockQueryType): string { + switch (object) { + case LockQueryType.ByDuration: + return "ByDuration"; + case LockQueryType.ByTime: + return "ByTime"; + case LockQueryType.NoLock: + return "NoLock"; + case LockQueryType.ByGroup: + return "ByGroup"; + case LockQueryType.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} +/** + * PeriodLock is a single lock unit by period defined by the x/lockup module. + * It's a record of a locked coin at a specific time. It stores owner, duration, + * unlock time and the number of coins locked. A state of a period lock is + * created upon lock creation, and deleted once the lock has been matured after + * the `duration` has passed since unbonding started. + */ +export interface PeriodLock { + /** + * ID is the unique id of the lock. + * The ID of the lock is decided upon lock creation, incrementing by 1 for + * every lock. + */ + ID: bigint; + /** + * Owner is the account address of the lock owner. + * Only the owner can modify the state of the lock. + */ + owner: string; + /** + * Duration is the time needed for a lock to mature after unlocking has + * started. + */ + duration: Duration; + /** + * EndTime refers to the time at which the lock would mature and get deleted. + * This value is first initialized when an unlock has started for the lock, + * end time being block time + duration. + */ + endTime: Date; + /** Coins are the tokens locked within the lock, kept in the module account. */ + coins: Coin[]; + /** + * Reward Receiver Address is the address that would be receiving rewards for + * the incentives for the lock. This is set to owner by default and can be + * changed via separate msg. + */ + rewardReceiverAddress: string; +} +export interface PeriodLockProtoMsg { + typeUrl: "/osmosis.lockup.PeriodLock"; + value: Uint8Array; +} +/** + * PeriodLock is a single lock unit by period defined by the x/lockup module. + * It's a record of a locked coin at a specific time. It stores owner, duration, + * unlock time and the number of coins locked. A state of a period lock is + * created upon lock creation, and deleted once the lock has been matured after + * the `duration` has passed since unbonding started. + */ +export interface PeriodLockAmino { + /** + * ID is the unique id of the lock. + * The ID of the lock is decided upon lock creation, incrementing by 1 for + * every lock. + */ + ID?: string; + /** + * Owner is the account address of the lock owner. + * Only the owner can modify the state of the lock. + */ + owner?: string; + /** + * Duration is the time needed for a lock to mature after unlocking has + * started. + */ + duration?: DurationAmino; + /** + * EndTime refers to the time at which the lock would mature and get deleted. + * This value is first initialized when an unlock has started for the lock, + * end time being block time + duration. + */ + end_time?: string; + /** Coins are the tokens locked within the lock, kept in the module account. */ + coins?: CoinAmino[]; + /** + * Reward Receiver Address is the address that would be receiving rewards for + * the incentives for the lock. This is set to owner by default and can be + * changed via separate msg. + */ + reward_receiver_address?: string; +} +export interface PeriodLockAminoMsg { + type: "osmosis/lockup/period-lock"; + value: PeriodLockAmino; +} +/** + * PeriodLock is a single lock unit by period defined by the x/lockup module. + * It's a record of a locked coin at a specific time. It stores owner, duration, + * unlock time and the number of coins locked. A state of a period lock is + * created upon lock creation, and deleted once the lock has been matured after + * the `duration` has passed since unbonding started. + */ +export interface PeriodLockSDKType { + ID: bigint; + owner: string; + duration: DurationSDKType; + end_time: Date; + coins: CoinSDKType[]; + reward_receiver_address: string; +} +/** + * QueryCondition is a struct used for querying locks upon different conditions. + * Duration field and timestamp fields could be optional, depending on the + * LockQueryType. + */ +export interface QueryCondition { + /** LockQueryType is a type of lock query, ByLockDuration | ByLockTime */ + lockQueryType: LockQueryType; + /** Denom represents the token denomination we are looking to lock up */ + denom: string; + /** + * Duration is used to query locks with longer duration than the specified + * duration. Duration field must not be nil when the lock query type is + * `ByLockDuration`. + */ + duration: Duration; + /** + * Timestamp is used by locks started before the specified duration. + * Timestamp field must not be nil when the lock query type is `ByLockTime`. + * Querying locks with timestamp is currently not implemented. + */ + timestamp: Date; +} +export interface QueryConditionProtoMsg { + typeUrl: "/osmosis.lockup.QueryCondition"; + value: Uint8Array; +} +/** + * QueryCondition is a struct used for querying locks upon different conditions. + * Duration field and timestamp fields could be optional, depending on the + * LockQueryType. + */ +export interface QueryConditionAmino { + /** LockQueryType is a type of lock query, ByLockDuration | ByLockTime */ + lock_query_type?: LockQueryType; + /** Denom represents the token denomination we are looking to lock up */ + denom?: string; + /** + * Duration is used to query locks with longer duration than the specified + * duration. Duration field must not be nil when the lock query type is + * `ByLockDuration`. + */ + duration?: DurationAmino; + /** + * Timestamp is used by locks started before the specified duration. + * Timestamp field must not be nil when the lock query type is `ByLockTime`. + * Querying locks with timestamp is currently not implemented. + */ + timestamp?: string; +} +export interface QueryConditionAminoMsg { + type: "osmosis/lockup/query-condition"; + value: QueryConditionAmino; +} +/** + * QueryCondition is a struct used for querying locks upon different conditions. + * Duration field and timestamp fields could be optional, depending on the + * LockQueryType. + */ +export interface QueryConditionSDKType { + lock_query_type: LockQueryType; + denom: string; + duration: DurationSDKType; + timestamp: Date; +} +/** + * SyntheticLock is creating virtual lockup where new denom is combination of + * original denom and synthetic suffix. At the time of synthetic lockup creation + * and deletion, accumulation store is also being updated and on querier side, + * they can query as freely as native lockup. + */ +export interface SyntheticLock { + /** + * Underlying Lock ID is the underlying native lock's id for this synthetic + * lockup. A synthetic lock MUST have an underlying lock. + */ + underlyingLockId: bigint; + /** + * SynthDenom is the synthetic denom that is a combination of + * gamm share + bonding status + validator address. + */ + synthDenom: string; + /** + * used for unbonding synthetic lockups, for active synthetic lockups, this + * value is set to uninitialized value + */ + endTime: Date; + /** + * Duration is the duration for a synthetic lock to mature + * at the point of unbonding has started. + */ + duration: Duration; +} +export interface SyntheticLockProtoMsg { + typeUrl: "/osmosis.lockup.SyntheticLock"; + value: Uint8Array; +} +/** + * SyntheticLock is creating virtual lockup where new denom is combination of + * original denom and synthetic suffix. At the time of synthetic lockup creation + * and deletion, accumulation store is also being updated and on querier side, + * they can query as freely as native lockup. + */ +export interface SyntheticLockAmino { + /** + * Underlying Lock ID is the underlying native lock's id for this synthetic + * lockup. A synthetic lock MUST have an underlying lock. + */ + underlying_lock_id?: string; + /** + * SynthDenom is the synthetic denom that is a combination of + * gamm share + bonding status + validator address. + */ + synth_denom?: string; + /** + * used for unbonding synthetic lockups, for active synthetic lockups, this + * value is set to uninitialized value + */ + end_time?: string; + /** + * Duration is the duration for a synthetic lock to mature + * at the point of unbonding has started. + */ + duration?: DurationAmino; +} +export interface SyntheticLockAminoMsg { + type: "osmosis/lockup/synthetic-lock"; + value: SyntheticLockAmino; +} +/** + * SyntheticLock is creating virtual lockup where new denom is combination of + * original denom and synthetic suffix. At the time of synthetic lockup creation + * and deletion, accumulation store is also being updated and on querier side, + * they can query as freely as native lockup. + */ +export interface SyntheticLockSDKType { + underlying_lock_id: bigint; + synth_denom: string; + end_time: Date; + duration: DurationSDKType; +} +function createBasePeriodLock(): PeriodLock { + return { + ID: BigInt(0), + owner: "", + duration: Duration.fromPartial({}), + endTime: new Date(), + coins: [], + rewardReceiverAddress: "", + }; +} +export const PeriodLock = { + typeUrl: "/osmosis.lockup.PeriodLock", + encode(message: PeriodLock, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.ID !== BigInt(0)) { + writer.uint32(8).uint64(message.ID); + } + if (message.owner !== "") { + writer.uint32(18).string(message.owner); + } + if (message.duration !== undefined) { + Duration.encode(message.duration, writer.uint32(26).fork()).ldelim(); + } + if (message.endTime !== undefined) { + Timestamp.encode(toTimestamp(message.endTime), writer.uint32(34).fork()).ldelim(); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(42).fork()).ldelim(); + } + if (message.rewardReceiverAddress !== "") { + writer.uint32(50).string(message.rewardReceiverAddress); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): PeriodLock { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBasePeriodLock(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.ID = reader.uint64(); + break; + case 2: + message.owner = reader.string(); + break; + case 3: + message.duration = Duration.decode(reader, reader.uint32()); + break; + case 4: + message.endTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + case 5: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + case 6: + message.rewardReceiverAddress = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): PeriodLock { + const message = createBasePeriodLock(); + message.ID = object.ID !== undefined && object.ID !== null ? BigInt(object.ID.toString()) : BigInt(0); + message.owner = object.owner ?? ""; + // @ts-ignore + message.duration = + object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + // @ts-ignore + message.endTime = object.endTime ?? undefined; + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + message.rewardReceiverAddress = object.rewardReceiverAddress ?? ""; + return message; + }, + fromAmino(object: PeriodLockAmino): PeriodLock { + const message = createBasePeriodLock(); + if (object.ID !== undefined && object.ID !== null) { + message.ID = BigInt(object.ID); + } + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.duration !== undefined && object.duration !== null) { + message.duration = Duration.fromAmino(object.duration); + } + if (object.end_time !== undefined && object.end_time !== null) { + message.endTime = fromTimestamp(Timestamp.fromAmino(object.end_time)); + } + message.coins = object.coins?.map((e) => Coin.fromAmino(e)) || []; + if (object.reward_receiver_address !== undefined && object.reward_receiver_address !== null) { + message.rewardReceiverAddress = object.reward_receiver_address; + } + return message; + }, + toAmino(message: PeriodLock): PeriodLockAmino { + const obj: any = {}; + obj.ID = message.ID !== BigInt(0) ? message.ID.toString() : undefined; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.duration = message.duration ? Duration.toAmino(message.duration) : undefined; + obj.end_time = message.endTime ? Timestamp.toAmino(toTimestamp(message.endTime)) : undefined; + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toAmino(e) : undefined)); + } else { + obj.coins = message.coins; + } + obj.reward_receiver_address = message.rewardReceiverAddress === "" ? undefined : message.rewardReceiverAddress; + return obj; + }, + fromAminoMsg(object: PeriodLockAminoMsg): PeriodLock { + return PeriodLock.fromAmino(object.value); + }, + toAminoMsg(message: PeriodLock): PeriodLockAminoMsg { + return { + type: "osmosis/lockup/period-lock", + value: PeriodLock.toAmino(message), + }; + }, + fromProtoMsg(message: PeriodLockProtoMsg): PeriodLock { + return PeriodLock.decode(message.value); + }, + toProto(message: PeriodLock): Uint8Array { + return PeriodLock.encode(message).finish(); + }, + toProtoMsg(message: PeriodLock): PeriodLockProtoMsg { + return { + typeUrl: "/osmosis.lockup.PeriodLock", + value: PeriodLock.encode(message).finish(), + }; + }, +}; +function createBaseQueryCondition(): QueryCondition { + return { + lockQueryType: 0, + denom: "", + duration: Duration.fromPartial({}), + timestamp: new Date(), + }; +} +export const QueryCondition = { + typeUrl: "/osmosis.lockup.QueryCondition", + encode(message: QueryCondition, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.lockQueryType !== 0) { + writer.uint32(8).int32(message.lockQueryType); + } + if (message.denom !== "") { + writer.uint32(18).string(message.denom); + } + if (message.duration !== undefined) { + Duration.encode(message.duration, writer.uint32(26).fork()).ldelim(); + } + if (message.timestamp !== undefined) { + Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(34).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): QueryCondition { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryCondition(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.lockQueryType = reader.int32() as any; + break; + case 2: + message.denom = reader.string(); + break; + case 3: + message.duration = Duration.decode(reader, reader.uint32()); + break; + case 4: + message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): QueryCondition { + const message = createBaseQueryCondition(); + message.lockQueryType = object.lockQueryType ?? 0; + message.denom = object.denom ?? ""; + // @ts-ignore + message.duration = + object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + // @ts-ignore + message.timestamp = object.timestamp ?? undefined; + return message; + }, + fromAmino(object: QueryConditionAmino): QueryCondition { + const message = createBaseQueryCondition(); + if (object.lock_query_type !== undefined && object.lock_query_type !== null) { + message.lockQueryType = object.lock_query_type; + } + if (object.denom !== undefined && object.denom !== null) { + message.denom = object.denom; + } + if (object.duration !== undefined && object.duration !== null) { + message.duration = Duration.fromAmino(object.duration); + } + if (object.timestamp !== undefined && object.timestamp !== null) { + message.timestamp = fromTimestamp(Timestamp.fromAmino(object.timestamp)); + } + return message; + }, + toAmino(message: QueryCondition): QueryConditionAmino { + const obj: any = {}; + obj.lock_query_type = message.lockQueryType === 0 ? undefined : message.lockQueryType; + obj.denom = message.denom === "" ? undefined : message.denom; + obj.duration = message.duration ? Duration.toAmino(message.duration) : undefined; + obj.timestamp = message.timestamp ? Timestamp.toAmino(toTimestamp(message.timestamp)) : undefined; + return obj; + }, + fromAminoMsg(object: QueryConditionAminoMsg): QueryCondition { + return QueryCondition.fromAmino(object.value); + }, + toAminoMsg(message: QueryCondition): QueryConditionAminoMsg { + return { + type: "osmosis/lockup/query-condition", + value: QueryCondition.toAmino(message), + }; + }, + fromProtoMsg(message: QueryConditionProtoMsg): QueryCondition { + return QueryCondition.decode(message.value); + }, + toProto(message: QueryCondition): Uint8Array { + return QueryCondition.encode(message).finish(); + }, + toProtoMsg(message: QueryCondition): QueryConditionProtoMsg { + return { + typeUrl: "/osmosis.lockup.QueryCondition", + value: QueryCondition.encode(message).finish(), + }; + }, +}; +function createBaseSyntheticLock(): SyntheticLock { + return { + underlyingLockId: BigInt(0), + synthDenom: "", + endTime: new Date(), + duration: Duration.fromPartial({}), + }; +} +export const SyntheticLock = { + typeUrl: "/osmosis.lockup.SyntheticLock", + encode(message: SyntheticLock, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.underlyingLockId !== BigInt(0)) { + writer.uint32(8).uint64(message.underlyingLockId); + } + if (message.synthDenom !== "") { + writer.uint32(18).string(message.synthDenom); + } + if (message.endTime !== undefined) { + Timestamp.encode(toTimestamp(message.endTime), writer.uint32(26).fork()).ldelim(); + } + if (message.duration !== undefined) { + Duration.encode(message.duration, writer.uint32(34).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): SyntheticLock { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseSyntheticLock(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.underlyingLockId = reader.uint64(); + break; + case 2: + message.synthDenom = reader.string(); + break; + case 3: + message.endTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + case 4: + message.duration = Duration.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): SyntheticLock { + const message = createBaseSyntheticLock(); + message.underlyingLockId = + object.underlyingLockId !== undefined && object.underlyingLockId !== null + ? BigInt(object.underlyingLockId.toString()) + : BigInt(0); + message.synthDenom = object.synthDenom ?? ""; + // @ts-ignore + message.endTime = object.endTime ?? undefined; + // @ts-ignore + message.duration = + object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + return message; + }, + fromAmino(object: SyntheticLockAmino): SyntheticLock { + const message = createBaseSyntheticLock(); + if (object.underlying_lock_id !== undefined && object.underlying_lock_id !== null) { + message.underlyingLockId = BigInt(object.underlying_lock_id); + } + if (object.synth_denom !== undefined && object.synth_denom !== null) { + message.synthDenom = object.synth_denom; + } + if (object.end_time !== undefined && object.end_time !== null) { + message.endTime = fromTimestamp(Timestamp.fromAmino(object.end_time)); + } + if (object.duration !== undefined && object.duration !== null) { + message.duration = Duration.fromAmino(object.duration); + } + return message; + }, + toAmino(message: SyntheticLock): SyntheticLockAmino { + const obj: any = {}; + obj.underlying_lock_id = message.underlyingLockId !== BigInt(0) ? message.underlyingLockId.toString() : undefined; + obj.synth_denom = message.synthDenom === "" ? undefined : message.synthDenom; + obj.end_time = message.endTime ? Timestamp.toAmino(toTimestamp(message.endTime)) : undefined; + obj.duration = message.duration ? Duration.toAmino(message.duration) : undefined; + return obj; + }, + fromAminoMsg(object: SyntheticLockAminoMsg): SyntheticLock { + return SyntheticLock.fromAmino(object.value); + }, + toAminoMsg(message: SyntheticLock): SyntheticLockAminoMsg { + return { + type: "osmosis/lockup/synthetic-lock", + value: SyntheticLock.toAmino(message), + }; + }, + fromProtoMsg(message: SyntheticLockProtoMsg): SyntheticLock { + return SyntheticLock.decode(message.value); + }, + toProto(message: SyntheticLock): Uint8Array { + return SyntheticLock.encode(message).finish(); + }, + toProtoMsg(message: SyntheticLock): SyntheticLockProtoMsg { + return { + typeUrl: "/osmosis.lockup.SyntheticLock", + value: SyntheticLock.encode(message).finish(), + }; + }, +}; + +export interface MsgLockTokens { + owner: string; + duration: Duration; + coins: Coin[]; +} +export interface MsgLockTokensProtoMsg { + typeUrl: "/osmosis.lockup.MsgLockTokens"; + value: Uint8Array; +} +export interface MsgLockTokensAmino { + owner?: string; + duration?: DurationAmino; + coins?: CoinAmino[]; +} +export interface MsgLockTokensAminoMsg { + type: "osmosis/lockup/lock-tokens"; + value: MsgLockTokensAmino; +} +export interface MsgLockTokensSDKType { + owner: string; + duration: DurationSDKType; + coins: CoinSDKType[]; +} +export interface MsgLockTokensResponse { + ID: bigint; +} +export interface MsgLockTokensResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgLockTokensResponse"; + value: Uint8Array; +} +export interface MsgLockTokensResponseAmino { + ID?: string; +} +export interface MsgLockTokensResponseAminoMsg { + type: "osmosis/lockup/lock-tokens-response"; + value: MsgLockTokensResponseAmino; +} +export interface MsgLockTokensResponseSDKType { + ID: bigint; +} +export interface MsgBeginUnlockingAll { + owner: string; +} +export interface MsgBeginUnlockingAllProtoMsg { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAll"; + value: Uint8Array; +} +export interface MsgBeginUnlockingAllAmino { + owner?: string; +} +export interface MsgBeginUnlockingAllAminoMsg { + type: "osmosis/lockup/begin-unlock-tokens"; + value: MsgBeginUnlockingAllAmino; +} +export interface MsgBeginUnlockingAllSDKType { + owner: string; +} +export interface MsgBeginUnlockingAllResponse { + unlocks: PeriodLock[]; +} +export interface MsgBeginUnlockingAllResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAllResponse"; + value: Uint8Array; +} +export interface MsgBeginUnlockingAllResponseAmino { + unlocks?: PeriodLockAmino[]; +} +export interface MsgBeginUnlockingAllResponseAminoMsg { + type: "osmosis/lockup/begin-unlocking-all-response"; + value: MsgBeginUnlockingAllResponseAmino; +} +export interface MsgBeginUnlockingAllResponseSDKType { + unlocks: PeriodLockSDKType[]; +} +export interface MsgBeginUnlocking { + owner: string; + ID: bigint; + /** Amount of unlocking coins. Unlock all if not set. */ + coins: Coin[]; +} +export interface MsgBeginUnlockingProtoMsg { + typeUrl: "/osmosis.lockup.MsgBeginUnlocking"; + value: Uint8Array; +} +export interface MsgBeginUnlockingAmino { + owner?: string; + ID?: string; + /** Amount of unlocking coins. Unlock all if not set. */ + coins?: CoinAmino[]; +} +export interface MsgBeginUnlockingAminoMsg { + type: "osmosis/lockup/begin-unlock-period-lock"; + value: MsgBeginUnlockingAmino; +} +export interface MsgBeginUnlockingSDKType { + owner: string; + ID: bigint; + coins: CoinSDKType[]; +} +export interface MsgBeginUnlockingResponse { + success: boolean; + unlockingLockID: bigint; +} +export interface MsgBeginUnlockingResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingResponse"; + value: Uint8Array; +} +export interface MsgBeginUnlockingResponseAmino { + success?: boolean; + unlockingLockID?: string; +} +export interface MsgBeginUnlockingResponseAminoMsg { + type: "osmosis/lockup/begin-unlocking-response"; + value: MsgBeginUnlockingResponseAmino; +} +export interface MsgBeginUnlockingResponseSDKType { + success: boolean; + unlockingLockID: bigint; +} +/** + * MsgExtendLockup extends the existing lockup's duration. + * The new duration is longer than the original. + */ +export interface MsgExtendLockup { + owner: string; + ID: bigint; + /** + * duration to be set. fails if lower than the current duration, or is + * unlocking + */ + duration: Duration; +} +export interface MsgExtendLockupProtoMsg { + typeUrl: "/osmosis.lockup.MsgExtendLockup"; + value: Uint8Array; +} +/** + * MsgExtendLockup extends the existing lockup's duration. + * The new duration is longer than the original. + */ +export interface MsgExtendLockupAmino { + owner?: string; + ID?: string; + /** + * duration to be set. fails if lower than the current duration, or is + * unlocking + */ + duration?: DurationAmino; +} +export interface MsgExtendLockupAminoMsg { + type: "osmosis/lockup/extend-lockup"; + value: MsgExtendLockupAmino; +} +/** + * MsgExtendLockup extends the existing lockup's duration. + * The new duration is longer than the original. + */ +export interface MsgExtendLockupSDKType { + owner: string; + ID: bigint; + duration: DurationSDKType; +} +export interface MsgExtendLockupResponse { + success: boolean; +} +export interface MsgExtendLockupResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgExtendLockupResponse"; + value: Uint8Array; +} +export interface MsgExtendLockupResponseAmino { + success?: boolean; +} +export interface MsgExtendLockupResponseAminoMsg { + type: "osmosis/lockup/extend-lockup-response"; + value: MsgExtendLockupResponseAmino; +} +export interface MsgExtendLockupResponseSDKType { + success: boolean; +} +/** + * MsgForceUnlock unlocks locks immediately for + * addresses registered via governance. + */ +export interface MsgForceUnlock { + owner: string; + ID: bigint; + /** Amount of unlocking coins. Unlock all if not set. */ + coins: Coin[]; +} +export interface MsgForceUnlockProtoMsg { + typeUrl: "/osmosis.lockup.MsgForceUnlock"; + value: Uint8Array; +} +/** + * MsgForceUnlock unlocks locks immediately for + * addresses registered via governance. + */ +export interface MsgForceUnlockAmino { + owner?: string; + ID?: string; + /** Amount of unlocking coins. Unlock all if not set. */ + coins?: CoinAmino[]; +} +export interface MsgForceUnlockAminoMsg { + type: "osmosis/lockup/force-unlock-tokens"; + value: MsgForceUnlockAmino; +} +/** + * MsgForceUnlock unlocks locks immediately for + * addresses registered via governance. + */ +export interface MsgForceUnlockSDKType { + owner: string; + ID: bigint; + coins: CoinSDKType[]; +} +export interface MsgForceUnlockResponse { + success: boolean; +} +export interface MsgForceUnlockResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgForceUnlockResponse"; + value: Uint8Array; +} +export interface MsgForceUnlockResponseAmino { + success?: boolean; +} +export interface MsgForceUnlockResponseAminoMsg { + type: "osmosis/lockup/force-unlock-response"; + value: MsgForceUnlockResponseAmino; +} +export interface MsgForceUnlockResponseSDKType { + success: boolean; +} +export interface MsgSetRewardReceiverAddress { + owner: string; + lockID: bigint; + rewardReceiver: string; +} +export interface MsgSetRewardReceiverAddressProtoMsg { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddress"; + value: Uint8Array; +} +export interface MsgSetRewardReceiverAddressAmino { + owner?: string; + lockID?: string; + reward_receiver?: string; +} +export interface MsgSetRewardReceiverAddressAminoMsg { + type: "osmosis/lockup/set-reward-receiver-address"; + value: MsgSetRewardReceiverAddressAmino; +} +export interface MsgSetRewardReceiverAddressSDKType { + owner: string; + lockID: bigint; + reward_receiver: string; +} +export interface MsgSetRewardReceiverAddressResponse { + success: boolean; +} +export interface MsgSetRewardReceiverAddressResponseProtoMsg { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddressResponse"; + value: Uint8Array; +} +export interface MsgSetRewardReceiverAddressResponseAmino { + success?: boolean; +} +export interface MsgSetRewardReceiverAddressResponseAminoMsg { + type: "osmosis/lockup/set-reward-receiver-address-response"; + value: MsgSetRewardReceiverAddressResponseAmino; +} +export interface MsgSetRewardReceiverAddressResponseSDKType { + success: boolean; +} +function createBaseMsgLockTokens(): MsgLockTokens { + return { + owner: "", + duration: Duration.fromPartial({}), + coins: [], + }; +} +export const MsgLockTokens = { + typeUrl: "/osmosis.lockup.MsgLockTokens", + encode(message: MsgLockTokens, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + if (message.duration !== undefined) { + Duration.encode(message.duration, writer.uint32(18).fork()).ldelim(); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgLockTokens { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgLockTokens(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + case 2: + message.duration = Duration.decode(reader, reader.uint32()); + break; + case 3: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgLockTokens { + const message = createBaseMsgLockTokens(); + message.owner = object.owner ?? ""; + // @ts-ignore + message.duration = + object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, + fromAmino(object: MsgLockTokensAmino): MsgLockTokens { + const message = createBaseMsgLockTokens(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.duration !== undefined && object.duration !== null) { + message.duration = Duration.fromAmino(object.duration); + } + message.coins = object.coins?.map((e) => Coin.fromAmino(e)) || []; + return message; + }, + toAmino(message: MsgLockTokens): MsgLockTokensAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.duration = message.duration ? Duration.toAmino(message.duration) : undefined; + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toAmino(e) : undefined)); + } else { + obj.coins = message.coins; + } + return obj; + }, + fromAminoMsg(object: MsgLockTokensAminoMsg): MsgLockTokens { + return MsgLockTokens.fromAmino(object.value); + }, + toAminoMsg(message: MsgLockTokens): MsgLockTokensAminoMsg { + return { + type: "osmosis/lockup/lock-tokens", + value: MsgLockTokens.toAmino(message), + }; + }, + fromProtoMsg(message: MsgLockTokensProtoMsg): MsgLockTokens { + return MsgLockTokens.decode(message.value); + }, + toProto(message: MsgLockTokens): Uint8Array { + return MsgLockTokens.encode(message).finish(); + }, + toProtoMsg(message: MsgLockTokens): MsgLockTokensProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgLockTokens", + value: MsgLockTokens.encode(message).finish(), + }; + }, +}; +function createBaseMsgLockTokensResponse(): MsgLockTokensResponse { + return { + ID: BigInt(0), + }; +} +export const MsgLockTokensResponse = { + typeUrl: "/osmosis.lockup.MsgLockTokensResponse", + encode(message: MsgLockTokensResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.ID !== BigInt(0)) { + writer.uint32(8).uint64(message.ID); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgLockTokensResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgLockTokensResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.ID = reader.uint64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgLockTokensResponse { + const message = createBaseMsgLockTokensResponse(); + message.ID = object.ID !== undefined && object.ID !== null ? BigInt(object.ID.toString()) : BigInt(0); + return message; + }, + fromAmino(object: MsgLockTokensResponseAmino): MsgLockTokensResponse { + const message = createBaseMsgLockTokensResponse(); + if (object.ID !== undefined && object.ID !== null) { + message.ID = BigInt(object.ID); + } + return message; + }, + toAmino(message: MsgLockTokensResponse): MsgLockTokensResponseAmino { + const obj: any = {}; + obj.ID = message.ID !== BigInt(0) ? message.ID.toString() : undefined; + return obj; + }, + fromAminoMsg(object: MsgLockTokensResponseAminoMsg): MsgLockTokensResponse { + return MsgLockTokensResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgLockTokensResponse): MsgLockTokensResponseAminoMsg { + return { + type: "osmosis/lockup/lock-tokens-response", + value: MsgLockTokensResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgLockTokensResponseProtoMsg): MsgLockTokensResponse { + return MsgLockTokensResponse.decode(message.value); + }, + toProto(message: MsgLockTokensResponse): Uint8Array { + return MsgLockTokensResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgLockTokensResponse): MsgLockTokensResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgLockTokensResponse", + value: MsgLockTokensResponse.encode(message).finish(), + }; + }, +}; +function createBaseMsgBeginUnlockingAll(): MsgBeginUnlockingAll { + return { + owner: "", + }; +} +export const MsgBeginUnlockingAll = { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAll", + encode(message: MsgBeginUnlockingAll, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgBeginUnlockingAll { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgBeginUnlockingAll(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgBeginUnlockingAll { + const message = createBaseMsgBeginUnlockingAll(); + message.owner = object.owner ?? ""; + return message; + }, + fromAmino(object: MsgBeginUnlockingAllAmino): MsgBeginUnlockingAll { + const message = createBaseMsgBeginUnlockingAll(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + return message; + }, + toAmino(message: MsgBeginUnlockingAll): MsgBeginUnlockingAllAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + return obj; + }, + fromAminoMsg(object: MsgBeginUnlockingAllAminoMsg): MsgBeginUnlockingAll { + return MsgBeginUnlockingAll.fromAmino(object.value); + }, + toAminoMsg(message: MsgBeginUnlockingAll): MsgBeginUnlockingAllAminoMsg { + return { + type: "osmosis/lockup/begin-unlock-tokens", + value: MsgBeginUnlockingAll.toAmino(message), + }; + }, + fromProtoMsg(message: MsgBeginUnlockingAllProtoMsg): MsgBeginUnlockingAll { + return MsgBeginUnlockingAll.decode(message.value); + }, + toProto(message: MsgBeginUnlockingAll): Uint8Array { + return MsgBeginUnlockingAll.encode(message).finish(); + }, + toProtoMsg(message: MsgBeginUnlockingAll): MsgBeginUnlockingAllProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAll", + value: MsgBeginUnlockingAll.encode(message).finish(), + }; + }, +}; +function createBaseMsgBeginUnlockingAllResponse(): MsgBeginUnlockingAllResponse { + return { + unlocks: [], + }; +} +export const MsgBeginUnlockingAllResponse = { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAllResponse", + encode(message: MsgBeginUnlockingAllResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + for (const v of message.unlocks) { + PeriodLock.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgBeginUnlockingAllResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgBeginUnlockingAllResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.unlocks.push(PeriodLock.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgBeginUnlockingAllResponse { + const message = createBaseMsgBeginUnlockingAllResponse(); + message.unlocks = object.unlocks?.map((e) => PeriodLock.fromPartial(e)) || []; + return message; + }, + fromAmino(object: MsgBeginUnlockingAllResponseAmino): MsgBeginUnlockingAllResponse { + const message = createBaseMsgBeginUnlockingAllResponse(); + message.unlocks = object.unlocks?.map((e) => PeriodLock.fromAmino(e)) || []; + return message; + }, + toAmino(message: MsgBeginUnlockingAllResponse): MsgBeginUnlockingAllResponseAmino { + const obj: any = {}; + if (message.unlocks) { + obj.unlocks = message.unlocks.map((e) => (e ? PeriodLock.toAmino(e) : undefined)); + } else { + obj.unlocks = message.unlocks; + } + return obj; + }, + fromAminoMsg(object: MsgBeginUnlockingAllResponseAminoMsg): MsgBeginUnlockingAllResponse { + return MsgBeginUnlockingAllResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgBeginUnlockingAllResponse): MsgBeginUnlockingAllResponseAminoMsg { + return { + type: "osmosis/lockup/begin-unlocking-all-response", + value: MsgBeginUnlockingAllResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgBeginUnlockingAllResponseProtoMsg): MsgBeginUnlockingAllResponse { + return MsgBeginUnlockingAllResponse.decode(message.value); + }, + toProto(message: MsgBeginUnlockingAllResponse): Uint8Array { + return MsgBeginUnlockingAllResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgBeginUnlockingAllResponse): MsgBeginUnlockingAllResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingAllResponse", + value: MsgBeginUnlockingAllResponse.encode(message).finish(), + }; + }, +}; +function createBaseMsgBeginUnlocking(): MsgBeginUnlocking { + return { + owner: "", + ID: BigInt(0), + coins: [], + }; +} +export const MsgBeginUnlocking = { + typeUrl: "/osmosis.lockup.MsgBeginUnlocking", + encode(message: MsgBeginUnlocking, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + if (message.ID !== BigInt(0)) { + writer.uint32(16).uint64(message.ID); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgBeginUnlocking { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgBeginUnlocking(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + case 2: + message.ID = reader.uint64(); + break; + case 3: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgBeginUnlocking { + const message = createBaseMsgBeginUnlocking(); + message.owner = object.owner ?? ""; + message.ID = object.ID !== undefined && object.ID !== null ? BigInt(object.ID.toString()) : BigInt(0); + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, + fromAmino(object: MsgBeginUnlockingAmino): MsgBeginUnlocking { + const message = createBaseMsgBeginUnlocking(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.ID !== undefined && object.ID !== null) { + message.ID = BigInt(object.ID); + } + message.coins = object.coins?.map((e) => Coin.fromAmino(e)) || []; + return message; + }, + toAmino(message: MsgBeginUnlocking): MsgBeginUnlockingAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.ID = message.ID !== BigInt(0) ? message.ID.toString() : undefined; + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toAmino(e) : undefined)); + } else { + obj.coins = message.coins; + } + return obj; + }, + fromAminoMsg(object: MsgBeginUnlockingAminoMsg): MsgBeginUnlocking { + return MsgBeginUnlocking.fromAmino(object.value); + }, + toAminoMsg(message: MsgBeginUnlocking): MsgBeginUnlockingAminoMsg { + return { + type: "osmosis/lockup/begin-unlock-period-lock", + value: MsgBeginUnlocking.toAmino(message), + }; + }, + fromProtoMsg(message: MsgBeginUnlockingProtoMsg): MsgBeginUnlocking { + return MsgBeginUnlocking.decode(message.value); + }, + toProto(message: MsgBeginUnlocking): Uint8Array { + return MsgBeginUnlocking.encode(message).finish(); + }, + toProtoMsg(message: MsgBeginUnlocking): MsgBeginUnlockingProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgBeginUnlocking", + value: MsgBeginUnlocking.encode(message).finish(), + }; + }, +}; +function createBaseMsgBeginUnlockingResponse(): MsgBeginUnlockingResponse { + return { + success: false, + unlockingLockID: BigInt(0), + }; +} +export const MsgBeginUnlockingResponse = { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingResponse", + encode(message: MsgBeginUnlockingResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.success === true) { + writer.uint32(8).bool(message.success); + } + if (message.unlockingLockID !== BigInt(0)) { + writer.uint32(16).uint64(message.unlockingLockID); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgBeginUnlockingResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgBeginUnlockingResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.success = reader.bool(); + break; + case 2: + message.unlockingLockID = reader.uint64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgBeginUnlockingResponse { + const message = createBaseMsgBeginUnlockingResponse(); + message.success = object.success ?? false; + message.unlockingLockID = + object.unlockingLockID !== undefined && object.unlockingLockID !== null + ? BigInt(object.unlockingLockID.toString()) + : BigInt(0); + return message; + }, + fromAmino(object: MsgBeginUnlockingResponseAmino): MsgBeginUnlockingResponse { + const message = createBaseMsgBeginUnlockingResponse(); + if (object.success !== undefined && object.success !== null) { + message.success = object.success; + } + if (object.unlockingLockID !== undefined && object.unlockingLockID !== null) { + message.unlockingLockID = BigInt(object.unlockingLockID); + } + return message; + }, + toAmino(message: MsgBeginUnlockingResponse): MsgBeginUnlockingResponseAmino { + const obj: any = {}; + obj.success = message.success === false ? undefined : message.success; + obj.unlockingLockID = message.unlockingLockID !== BigInt(0) ? message.unlockingLockID.toString() : undefined; + return obj; + }, + fromAminoMsg(object: MsgBeginUnlockingResponseAminoMsg): MsgBeginUnlockingResponse { + return MsgBeginUnlockingResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgBeginUnlockingResponse): MsgBeginUnlockingResponseAminoMsg { + return { + type: "osmosis/lockup/begin-unlocking-response", + value: MsgBeginUnlockingResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgBeginUnlockingResponseProtoMsg): MsgBeginUnlockingResponse { + return MsgBeginUnlockingResponse.decode(message.value); + }, + toProto(message: MsgBeginUnlockingResponse): Uint8Array { + return MsgBeginUnlockingResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgBeginUnlockingResponse): MsgBeginUnlockingResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgBeginUnlockingResponse", + value: MsgBeginUnlockingResponse.encode(message).finish(), + }; + }, +}; +function createBaseMsgExtendLockup(): MsgExtendLockup { + return { + owner: "", + ID: BigInt(0), + duration: Duration.fromPartial({}), + }; +} +export const MsgExtendLockup = { + typeUrl: "/osmosis.lockup.MsgExtendLockup", + encode(message: MsgExtendLockup, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + if (message.ID !== BigInt(0)) { + writer.uint32(16).uint64(message.ID); + } + if (message.duration !== undefined) { + Duration.encode(message.duration, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgExtendLockup { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgExtendLockup(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + case 2: + message.ID = reader.uint64(); + break; + case 3: + message.duration = Duration.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgExtendLockup { + const message = createBaseMsgExtendLockup(); + message.owner = object.owner ?? ""; + message.ID = object.ID !== undefined && object.ID !== null ? BigInt(object.ID.toString()) : BigInt(0); + // @ts-ignore + message.duration = + object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + return message; + }, + fromAmino(object: MsgExtendLockupAmino): MsgExtendLockup { + const message = createBaseMsgExtendLockup(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.ID !== undefined && object.ID !== null) { + message.ID = BigInt(object.ID); + } + if (object.duration !== undefined && object.duration !== null) { + message.duration = Duration.fromAmino(object.duration); + } + return message; + }, + toAmino(message: MsgExtendLockup): MsgExtendLockupAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.ID = message.ID !== BigInt(0) ? message.ID.toString() : undefined; + obj.duration = message.duration ? Duration.toAmino(message.duration) : undefined; + return obj; + }, + fromAminoMsg(object: MsgExtendLockupAminoMsg): MsgExtendLockup { + return MsgExtendLockup.fromAmino(object.value); + }, + toAminoMsg(message: MsgExtendLockup): MsgExtendLockupAminoMsg { + return { + type: "osmosis/lockup/extend-lockup", + value: MsgExtendLockup.toAmino(message), + }; + }, + fromProtoMsg(message: MsgExtendLockupProtoMsg): MsgExtendLockup { + return MsgExtendLockup.decode(message.value); + }, + toProto(message: MsgExtendLockup): Uint8Array { + return MsgExtendLockup.encode(message).finish(); + }, + toProtoMsg(message: MsgExtendLockup): MsgExtendLockupProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgExtendLockup", + value: MsgExtendLockup.encode(message).finish(), + }; + }, +}; +function createBaseMsgExtendLockupResponse(): MsgExtendLockupResponse { + return { + success: false, + }; +} +export const MsgExtendLockupResponse = { + typeUrl: "/osmosis.lockup.MsgExtendLockupResponse", + encode(message: MsgExtendLockupResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.success === true) { + writer.uint32(8).bool(message.success); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgExtendLockupResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgExtendLockupResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.success = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgExtendLockupResponse { + const message = createBaseMsgExtendLockupResponse(); + message.success = object.success ?? false; + return message; + }, + fromAmino(object: MsgExtendLockupResponseAmino): MsgExtendLockupResponse { + const message = createBaseMsgExtendLockupResponse(); + if (object.success !== undefined && object.success !== null) { + message.success = object.success; + } + return message; + }, + toAmino(message: MsgExtendLockupResponse): MsgExtendLockupResponseAmino { + const obj: any = {}; + obj.success = message.success === false ? undefined : message.success; + return obj; + }, + fromAminoMsg(object: MsgExtendLockupResponseAminoMsg): MsgExtendLockupResponse { + return MsgExtendLockupResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgExtendLockupResponse): MsgExtendLockupResponseAminoMsg { + return { + type: "osmosis/lockup/extend-lockup-response", + value: MsgExtendLockupResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgExtendLockupResponseProtoMsg): MsgExtendLockupResponse { + return MsgExtendLockupResponse.decode(message.value); + }, + toProto(message: MsgExtendLockupResponse): Uint8Array { + return MsgExtendLockupResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgExtendLockupResponse): MsgExtendLockupResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgExtendLockupResponse", + value: MsgExtendLockupResponse.encode(message).finish(), + }; + }, +}; +function createBaseMsgForceUnlock(): MsgForceUnlock { + return { + owner: "", + ID: BigInt(0), + coins: [], + }; +} +export const MsgForceUnlock = { + typeUrl: "/osmosis.lockup.MsgForceUnlock", + encode(message: MsgForceUnlock, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + if (message.ID !== BigInt(0)) { + writer.uint32(16).uint64(message.ID); + } + for (const v of message.coins) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgForceUnlock { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgForceUnlock(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + case 2: + message.ID = reader.uint64(); + break; + case 3: + message.coins.push(Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgForceUnlock { + const message = createBaseMsgForceUnlock(); + message.owner = object.owner ?? ""; + message.ID = object.ID !== undefined && object.ID !== null ? BigInt(object.ID.toString()) : BigInt(0); + message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || []; + return message; + }, + fromAmino(object: MsgForceUnlockAmino): MsgForceUnlock { + const message = createBaseMsgForceUnlock(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.ID !== undefined && object.ID !== null) { + message.ID = BigInt(object.ID); + } + message.coins = object.coins?.map((e) => Coin.fromAmino(e)) || []; + return message; + }, + toAmino(message: MsgForceUnlock): MsgForceUnlockAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.ID = message.ID !== BigInt(0) ? message.ID.toString() : undefined; + if (message.coins) { + obj.coins = message.coins.map((e) => (e ? Coin.toAmino(e) : undefined)); + } else { + obj.coins = message.coins; + } + return obj; + }, + fromAminoMsg(object: MsgForceUnlockAminoMsg): MsgForceUnlock { + return MsgForceUnlock.fromAmino(object.value); + }, + toAminoMsg(message: MsgForceUnlock): MsgForceUnlockAminoMsg { + return { + type: "osmosis/lockup/force-unlock-tokens", + value: MsgForceUnlock.toAmino(message), + }; + }, + fromProtoMsg(message: MsgForceUnlockProtoMsg): MsgForceUnlock { + return MsgForceUnlock.decode(message.value); + }, + toProto(message: MsgForceUnlock): Uint8Array { + return MsgForceUnlock.encode(message).finish(); + }, + toProtoMsg(message: MsgForceUnlock): MsgForceUnlockProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgForceUnlock", + value: MsgForceUnlock.encode(message).finish(), + }; + }, +}; +function createBaseMsgForceUnlockResponse(): MsgForceUnlockResponse { + return { + success: false, + }; +} +export const MsgForceUnlockResponse = { + typeUrl: "/osmosis.lockup.MsgForceUnlockResponse", + encode(message: MsgForceUnlockResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.success === true) { + writer.uint32(8).bool(message.success); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgForceUnlockResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgForceUnlockResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.success = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgForceUnlockResponse { + const message = createBaseMsgForceUnlockResponse(); + message.success = object.success ?? false; + return message; + }, + fromAmino(object: MsgForceUnlockResponseAmino): MsgForceUnlockResponse { + const message = createBaseMsgForceUnlockResponse(); + if (object.success !== undefined && object.success !== null) { + message.success = object.success; + } + return message; + }, + toAmino(message: MsgForceUnlockResponse): MsgForceUnlockResponseAmino { + const obj: any = {}; + obj.success = message.success === false ? undefined : message.success; + return obj; + }, + fromAminoMsg(object: MsgForceUnlockResponseAminoMsg): MsgForceUnlockResponse { + return MsgForceUnlockResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgForceUnlockResponse): MsgForceUnlockResponseAminoMsg { + return { + type: "osmosis/lockup/force-unlock-response", + value: MsgForceUnlockResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgForceUnlockResponseProtoMsg): MsgForceUnlockResponse { + return MsgForceUnlockResponse.decode(message.value); + }, + toProto(message: MsgForceUnlockResponse): Uint8Array { + return MsgForceUnlockResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgForceUnlockResponse): MsgForceUnlockResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgForceUnlockResponse", + value: MsgForceUnlockResponse.encode(message).finish(), + }; + }, +}; +function createBaseMsgSetRewardReceiverAddress(): MsgSetRewardReceiverAddress { + return { + owner: "", + lockID: BigInt(0), + rewardReceiver: "", + }; +} +export const MsgSetRewardReceiverAddress = { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddress", + encode(message: MsgSetRewardReceiverAddress, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.owner !== "") { + writer.uint32(10).string(message.owner); + } + if (message.lockID !== BigInt(0)) { + writer.uint32(16).uint64(message.lockID); + } + if (message.rewardReceiver !== "") { + writer.uint32(26).string(message.rewardReceiver); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgSetRewardReceiverAddress { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSetRewardReceiverAddress(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.owner = reader.string(); + break; + case 2: + message.lockID = reader.uint64(); + break; + case 3: + message.rewardReceiver = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgSetRewardReceiverAddress { + const message = createBaseMsgSetRewardReceiverAddress(); + message.owner = object.owner ?? ""; + message.lockID = + object.lockID !== undefined && object.lockID !== null ? BigInt(object.lockID.toString()) : BigInt(0); + message.rewardReceiver = object.rewardReceiver ?? ""; + return message; + }, + fromAmino(object: MsgSetRewardReceiverAddressAmino): MsgSetRewardReceiverAddress { + const message = createBaseMsgSetRewardReceiverAddress(); + if (object.owner !== undefined && object.owner !== null) { + message.owner = object.owner; + } + if (object.lockID !== undefined && object.lockID !== null) { + message.lockID = BigInt(object.lockID); + } + if (object.reward_receiver !== undefined && object.reward_receiver !== null) { + message.rewardReceiver = object.reward_receiver; + } + return message; + }, + toAmino(message: MsgSetRewardReceiverAddress): MsgSetRewardReceiverAddressAmino { + const obj: any = {}; + obj.owner = message.owner === "" ? undefined : message.owner; + obj.lockID = message.lockID !== BigInt(0) ? message.lockID.toString() : undefined; + obj.reward_receiver = message.rewardReceiver === "" ? undefined : message.rewardReceiver; + return obj; + }, + fromAminoMsg(object: MsgSetRewardReceiverAddressAminoMsg): MsgSetRewardReceiverAddress { + return MsgSetRewardReceiverAddress.fromAmino(object.value); + }, + toAminoMsg(message: MsgSetRewardReceiverAddress): MsgSetRewardReceiverAddressAminoMsg { + return { + type: "osmosis/lockup/set-reward-receiver-address", + value: MsgSetRewardReceiverAddress.toAmino(message), + }; + }, + fromProtoMsg(message: MsgSetRewardReceiverAddressProtoMsg): MsgSetRewardReceiverAddress { + return MsgSetRewardReceiverAddress.decode(message.value); + }, + toProto(message: MsgSetRewardReceiverAddress): Uint8Array { + return MsgSetRewardReceiverAddress.encode(message).finish(); + }, + toProtoMsg(message: MsgSetRewardReceiverAddress): MsgSetRewardReceiverAddressProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddress", + value: MsgSetRewardReceiverAddress.encode(message).finish(), + }; + }, +}; +function createBaseMsgSetRewardReceiverAddressResponse(): MsgSetRewardReceiverAddressResponse { + return { + success: false, + }; +} +export const MsgSetRewardReceiverAddressResponse = { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddressResponse", + encode(message: MsgSetRewardReceiverAddressResponse, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.success === true) { + writer.uint32(8).bool(message.success); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): MsgSetRewardReceiverAddressResponse { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgSetRewardReceiverAddressResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.success = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): MsgSetRewardReceiverAddressResponse { + const message = createBaseMsgSetRewardReceiverAddressResponse(); + message.success = object.success ?? false; + return message; + }, + fromAmino(object: MsgSetRewardReceiverAddressResponseAmino): MsgSetRewardReceiverAddressResponse { + const message = createBaseMsgSetRewardReceiverAddressResponse(); + if (object.success !== undefined && object.success !== null) { + message.success = object.success; + } + return message; + }, + toAmino(message: MsgSetRewardReceiverAddressResponse): MsgSetRewardReceiverAddressResponseAmino { + const obj: any = {}; + obj.success = message.success === false ? undefined : message.success; + return obj; + }, + fromAminoMsg(object: MsgSetRewardReceiverAddressResponseAminoMsg): MsgSetRewardReceiverAddressResponse { + return MsgSetRewardReceiverAddressResponse.fromAmino(object.value); + }, + toAminoMsg(message: MsgSetRewardReceiverAddressResponse): MsgSetRewardReceiverAddressResponseAminoMsg { + return { + type: "osmosis/lockup/set-reward-receiver-address-response", + value: MsgSetRewardReceiverAddressResponse.toAmino(message), + }; + }, + fromProtoMsg(message: MsgSetRewardReceiverAddressResponseProtoMsg): MsgSetRewardReceiverAddressResponse { + return MsgSetRewardReceiverAddressResponse.decode(message.value); + }, + toProto(message: MsgSetRewardReceiverAddressResponse): Uint8Array { + return MsgSetRewardReceiverAddressResponse.encode(message).finish(); + }, + toProtoMsg(message: MsgSetRewardReceiverAddressResponse): MsgSetRewardReceiverAddressResponseProtoMsg { + return { + typeUrl: "/osmosis.lockup.MsgSetRewardReceiverAddressResponse", + value: MsgSetRewardReceiverAddressResponse.encode(message).finish(), + }; + }, +}; diff --git a/packages/core/src/externals/osmosis/timestamp.ts b/packages/core/src/externals/osmosis/timestamp.ts new file mode 100644 index 0000000..ff6521a --- /dev/null +++ b/packages/core/src/externals/osmosis/timestamp.ts @@ -0,0 +1,350 @@ +import { BinaryReader, BinaryWriter } from "./binary"; +import { fromJsonTimestamp, fromTimestamp } from "./helpers"; +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * + * Example 5: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + */ +export interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + */ + seconds: bigint; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + */ + nanos: number; +} +export interface TimestampProtoMsg { + typeUrl: "/google.protobuf.Timestamp"; + value: Uint8Array; +} +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * + * Example 5: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + */ +export type TimestampAmino = string; +export interface TimestampAminoMsg { + type: "/google.protobuf.Timestamp"; + value: TimestampAmino; +} +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * + * Example 5: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + */ +export interface TimestampSDKType { + seconds: bigint; + nanos: number; +} +function createBaseTimestamp(): Timestamp { + return { + seconds: BigInt(0), + nanos: 0, + }; +} +export const Timestamp = { + typeUrl: "/google.protobuf.Timestamp", + encode(message: Timestamp, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.seconds !== BigInt(0)) { + writer.uint32(8).int64(message.seconds); + } + if (message.nanos !== 0) { + writer.uint32(16).int32(message.nanos); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): Timestamp { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTimestamp(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.seconds = reader.int64(); + break; + case 2: + message.nanos = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromPartial(object: Partial): Timestamp { + const message = createBaseTimestamp(); + message.seconds = + object.seconds !== undefined && object.seconds !== null ? BigInt(object.seconds.toString()) : BigInt(0); + message.nanos = object.nanos ?? 0; + return message; + }, + fromAmino(object: TimestampAmino): Timestamp { + return fromJsonTimestamp(object); + }, + toAmino(message: Timestamp): TimestampAmino { + return fromTimestamp(message) + .toISOString() + .replace(/\.\d+Z$/, "Z"); + }, + fromAminoMsg(object: TimestampAminoMsg): Timestamp { + return Timestamp.fromAmino(object.value); + }, + fromProtoMsg(message: TimestampProtoMsg): Timestamp { + return Timestamp.decode(message.value); + }, + toProto(message: Timestamp): Uint8Array { + return Timestamp.encode(message).finish(); + }, + toProtoMsg(message: Timestamp): TimestampProtoMsg { + return { + typeUrl: "/google.protobuf.Timestamp", + value: Timestamp.encode(message).finish(), + }; + }, +}; diff --git a/packages/core/src/externals/osmosis/utf8.ts b/packages/core/src/externals/osmosis/utf8.ts new file mode 100644 index 0000000..b6a3438 --- /dev/null +++ b/packages/core/src/externals/osmosis/utf8.ts @@ -0,0 +1,119 @@ +// Copyright (c) 2016, Daniel Wirtz All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: + +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of its author, nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"use strict"; + +/** + * Calculates the UTF8 byte length of a string. + * @param {string} string String + * @returns {number} Byte length + */ +export function utf8Length(str: string) { + let len = 0, + c = 0; + for (let i = 0; i < str.length; ++i) { + c = str.charCodeAt(i); + if (c < 128) len += 1; + else if (c < 2048) len += 2; + else if ((c & 0xfc00) === 0xd800 && (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00) { + ++i; + len += 4; + } else len += 3; + } + return len; +} + +/** + * Reads UTF8 bytes as a string. + * @param {Uint8Array} buffer Source buffer + * @param {number} start Source start + * @param {number} end Source end + * @returns {string} String read + */ +export function utf8Read(buffer: ArrayLike, start: number, end: number) { + const len = end - start; + if (len < 1) return ""; + const chunk = []; + let parts: string[] = [], + i = 0, // char offset + t; // temporary + while (start < end) { + t = buffer[start++]; + if (t < 128) chunk[i++] = t; + else if (t > 191 && t < 224) chunk[i++] = ((t & 31) << 6) | (buffer[start++] & 63); + else if (t > 239 && t < 365) { + t = + (((t & 7) << 18) | ((buffer[start++] & 63) << 12) | ((buffer[start++] & 63) << 6) | (buffer[start++] & 63)) - + 0x10000; + chunk[i++] = 0xd800 + (t >> 10); + chunk[i++] = 0xdc00 + (t & 1023); + } else chunk[i++] = ((t & 15) << 12) | ((buffer[start++] & 63) << 6) | (buffer[start++] & 63); + if (i > 8191) { + (parts || (parts = [])).push(String.fromCharCode(...chunk)); + i = 0; + } + } + if (parts) { + if (i) parts.push(String.fromCharCode(...chunk.slice(0, i))); + return parts.join(""); + } + return String.fromCharCode(...chunk.slice(0, i)); +} + +/** + * Writes a string as UTF8 bytes. + * @param {string} string Source string + * @param {Uint8Array} buffer Destination buffer + * @param {number} offset Destination offset + * @returns {number} Bytes written + */ +export function utf8Write(str: string, buffer: Uint8Array | Array, offset: number) { + const start = offset; + let c1, // character 1 + c2; // character 2 + for (let i = 0; i < str.length; ++i) { + c1 = str.charCodeAt(i); + if (c1 < 128) { + buffer[offset++] = c1; + } else if (c1 < 2048) { + buffer[offset++] = (c1 >> 6) | 192; + buffer[offset++] = (c1 & 63) | 128; + } else if ((c1 & 0xfc00) === 0xd800 && ((c2 = str.charCodeAt(i + 1)) & 0xfc00) === 0xdc00) { + c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff); + ++i; + buffer[offset++] = (c1 >> 18) | 240; + buffer[offset++] = ((c1 >> 12) & 63) | 128; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } else { + buffer[offset++] = (c1 >> 12) | 224; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } + } + return offset - start; +} diff --git a/packages/core/src/externals/osmosis/varint.ts b/packages/core/src/externals/osmosis/varint.ts new file mode 100644 index 0000000..8059152 --- /dev/null +++ b/packages/core/src/externals/osmosis/varint.ts @@ -0,0 +1,454 @@ +// Copyright 2008 Google Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Code generated by the Protocol Buffer compiler is owned by the owner +// of the input file used when generating it. This code is not +// standalone and requires a support library to be linked with it. This +// support library is itself covered by the above license. + +/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */ + +/** + * Read a 64 bit varint as two JS numbers. + * + * Returns tuple: + * [0]: low bits + * [1]: high bits + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175 + */ +export function varint64read(this: ReaderLike): [number, number] { + let lowBits = 0; + let highBits = 0; + + for (let shift = 0; shift < 28; shift += 7) { + let b = this.buf[this.pos++]; + lowBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + let middleByte = this.buf[this.pos++]; + + // last four bits of the first 32 bit number + lowBits |= (middleByte & 0x0f) << 28; + + // 3 upper bits are part of the next 32 bit number + highBits = (middleByte & 0x70) >> 4; + + if ((middleByte & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + + for (let shift = 3; shift <= 31; shift += 7) { + let b = this.buf[this.pos++]; + highBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + throw new Error("invalid varint"); +} + +/** + * Write a 64 bit varint, given as two JS numbers, to the given bytes array. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344 + */ +export function varint64write(lo: number, hi: number, bytes: number[]): void { + for (let i = 0; i < 28; i = i + 7) { + const shift = lo >>> i; + const hasNext = !(shift >>> 7 == 0 && hi == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4); + const hasMoreBits = !(hi >> 3 == 0); + bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff); + + if (!hasMoreBits) { + return; + } + + for (let i = 3; i < 31; i = i + 7) { + const shift = hi >>> i; + const hasNext = !(shift >>> 7 == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + bytes.push((hi >>> 31) & 0x01); +} + +// constants for binary math +const TWO_PWR_32_DBL = 0x100000000; + +/** + * Parse decimal string of 64 bit integer value as two JS numbers. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64FromString(dec: string): { lo: number; hi: number } { + // Check for minus sign. + const minus = dec[0] === "-"; + if (minus) { + dec = dec.slice(1); + } + + // Work 6 decimal digits at a time, acting like we're converting base 1e6 + // digits to binary. This is safe to do with floating point math because + // Number.isSafeInteger(ALL_32_BITS * 1e6) == true. + const base = 1e6; + let lowBits = 0; + let highBits = 0; + + function add1e6digit(begin: number, end?: number) { + // Note: Number('') is 0. + const digit1e6 = Number(dec.slice(begin, end)); + highBits *= base; + lowBits = lowBits * base + digit1e6; + // Carry bits from lowBits to + if (lowBits >= TWO_PWR_32_DBL) { + highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0); + lowBits = lowBits % TWO_PWR_32_DBL; + } + } + + add1e6digit(-24, -18); + add1e6digit(-18, -12); + add1e6digit(-12, -6); + add1e6digit(-6); + return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits); +} + +/** + * Losslessly converts a 64-bit signed integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64ToString(lo: number, hi: number): string { + let bits = newBits(lo, hi); + // If we're treating the input as a signed value and the high bit is set, do + // a manual two's complement conversion before the decimal conversion. + const negative = bits.hi & 0x80000000; + if (negative) { + bits = negate(bits.lo, bits.hi); + } + const result = uInt64ToString(bits.lo, bits.hi); + return negative ? "-" + result : result; +} + +/** + * Losslessly converts a 64-bit unsigned integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function uInt64ToString(lo: number, hi: number): string { + ({ lo, hi } = toUnsigned(lo, hi)); + // Skip the expensive conversion if the number is small enough to use the + // built-in conversions. + // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with + // highBits <= 0x1FFFFF can be safely expressed with a double and retain + // integer precision. + // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true. + if (hi <= 0x1fffff) { + return String(TWO_PWR_32_DBL * hi + lo); + } + + // What this code is doing is essentially converting the input number from + // base-2 to base-1e7, which allows us to represent the 64-bit range with + // only 3 (very large) digits. Those digits are then trivial to convert to + // a base-10 string. + + // The magic numbers used here are - + // 2^24 = 16777216 = (1,6777216) in base-1e7. + // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7. + + // Split 32:32 representation into 16:24:24 representation so our + // intermediate digits don't overflow. + const low = lo & 0xffffff; + const mid = ((lo >>> 24) | (hi << 8)) & 0xffffff; + const high = (hi >> 16) & 0xffff; + + // Assemble our three base-1e7 digits, ignoring carries. The maximum + // value in a digit at this step is representable as a 48-bit integer, which + // can be stored in a 64-bit floating point number. + let digitA = low + mid * 6777216 + high * 6710656; + let digitB = mid + high * 8147497; + let digitC = high * 2; + + // Apply carries from A to B and from B to C. + const base = 10000000; + if (digitA >= base) { + digitB += Math.floor(digitA / base); + digitA %= base; + } + + if (digitB >= base) { + digitC += Math.floor(digitB / base); + digitB %= base; + } + + // If digitC is 0, then we should have returned in the trivial code path + // at the top for non-safe integers. Given this, we can assume both digitB + // and digitA need leading zeros. + return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) + decimalFrom1e7WithLeadingZeros(digitA); +} + +function toUnsigned(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo >>> 0, hi: hi >>> 0 }; +} + +function newBits(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo | 0, hi: hi | 0 }; +} + +/** + * Returns two's compliment negation of input. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers + */ +function negate(lowBits: number, highBits: number) { + highBits = ~highBits; + if (lowBits) { + lowBits = ~lowBits + 1; + } else { + // If lowBits is 0, then bitwise-not is 0xFFFFFFFF, + // adding 1 to that, results in 0x100000000, which leaves + // the low bits 0x0 and simply adds one to the high bits. + highBits += 1; + } + return newBits(lowBits, highBits); +} + +/** + * Returns decimal representation of digit1e7 with leading zeros. + */ +const decimalFrom1e7WithLeadingZeros = (digit1e7: number) => { + const partial = String(digit1e7); + return "0000000".slice(partial.length) + partial; +}; + +/** + * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)` + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144 + */ +export function varint32write(value: number, bytes: number[]): void { + if (value >= 0) { + // write value as varint 32 + while (value > 0x7f) { + bytes.push((value & 0x7f) | 0x80); + value = value >>> 7; + } + bytes.push(value); + } else { + for (let i = 0; i < 9; i++) { + bytes.push((value & 127) | 128); + value = value >> 7; + } + bytes.push(1); + } +} + +/** + * Read an unsigned 32 bit varint. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220 + */ +export function varint32read(this: ReaderLike): number { + let b = this.buf[this.pos++]; + let result = b & 0x7f; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 7; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 14; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 21; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + // Extract only last 4 bits + b = this.buf[this.pos++]; + result |= (b & 0x0f) << 28; + + for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++) b = this.buf[this.pos++]; + + if ((b & 0x80) != 0) throw new Error("invalid varint"); + + this.assertBounds(); + + // Result can have 32 bits, convert it to unsigned + return result >>> 0; +} + +type ReaderLike = { + buf: Uint8Array; + pos: number; + len: number; + assertBounds(): void; +}; + +/** + * encode zig zag + */ +export function zzEncode(lo: number, hi: number) { + let mask = hi >> 31; + hi = (((hi << 1) | (lo >>> 31)) ^ mask) >>> 0; + lo = ((lo << 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * decode zig zag + */ +export function zzDecode(lo: number, hi: number) { + let mask = -(lo & 1); + lo = (((lo >>> 1) | (hi << 31)) ^ mask) >>> 0; + hi = ((hi >>> 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * unsigned int32 without moving pos. + */ +export function readUInt32(buf: Uint8Array, pos: number) { + return (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + buf[pos + 3] * 0x1000000; +} + +/** + * signed int32 without moving pos. + */ +export function readInt32(buf: Uint8Array, pos: number) { + return (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + (buf[pos + 3] << 24); +} + +/** + * writing varint32 to pos + */ +export function writeVarint32(val: number, buf: Uint8Array | number[], pos: number) { + while (val > 127) { + buf[pos++] = (val & 127) | 128; + val >>>= 7; + } + buf[pos] = val; +} + +/** + * writing varint64 to pos + */ +export function writeVarint64(val: { lo: number; hi: number }, buf: Uint8Array | number[], pos: number) { + while (val.hi) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = ((val.lo >>> 7) | (val.hi << 25)) >>> 0; + val.hi >>>= 7; + } + while (val.lo > 127) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = val.lo >>> 7; + } + buf[pos++] = val.lo; +} + +export function int64Length(lo: number, hi: number) { + let part0 = lo, + part1 = ((lo >>> 28) | (hi << 4)) >>> 0, + part2 = hi >>> 24; + return part2 === 0 + ? part1 === 0 + ? part0 < 16384 + ? part0 < 128 + ? 1 + : 2 + : part0 < 2097152 + ? 3 + : 4 + : part1 < 16384 + ? part1 < 128 + ? 5 + : 6 + : part1 < 2097152 + ? 7 + : 8 + : part2 < 128 + ? 9 + : 10; +} + +export function writeFixed32(val: number, buf: Uint8Array | number[], pos: number) { + buf[pos] = val & 255; + buf[pos + 1] = (val >>> 8) & 255; + buf[pos + 2] = (val >>> 16) & 255; + buf[pos + 3] = val >>> 24; +} + +export function writeByte(val: number, buf: Uint8Array | number[], pos: number) { + buf[pos] = val & 255; +} diff --git a/packages/core/src/internals/registry.ts b/packages/core/src/internals/registry.ts index 6d982db..828ab87 100644 --- a/packages/core/src/internals/registry.ts +++ b/packages/core/src/internals/registry.ts @@ -1,7 +1,10 @@ import { GeneratedType } from "@cosmjs/proto-signing"; import { MsgDepositForBurn } from "../externals/cctp"; +import { MsgLockTokens, MsgBeginUnlocking } from "../externals/osmosis/lockup"; export const extendedRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ["/circle.cctp.v1.MsgDepositForBurn", MsgDepositForBurn], + ["/osmosis.lockup.MsgLockTokens", MsgLockTokens as GeneratedType], + ["/osmosis.lockup.MsgBeginUnlocking", MsgBeginUnlocking as GeneratedType], ]; diff --git a/packages/core/src/internals/transactions/messages/MsgBeginUnlocking.ts b/packages/core/src/internals/transactions/messages/MsgBeginUnlocking.ts new file mode 100644 index 0000000..8b2908b --- /dev/null +++ b/packages/core/src/internals/transactions/messages/MsgBeginUnlocking.ts @@ -0,0 +1,34 @@ +import { Coin } from "@cosmjs/amino"; +import Long from "long"; + +import { MsgBeginUnlocking as OsmosisMsgBeginUnlocking } from "../../../externals/osmosis/lockup"; +import TransactionMsg, { ProtoMsg } from "./TransactionMsg"; + +export type MsgBeginUnlockingValue = { + owner: string; + ID: Long; + coins?: Coin[]; +}; + +export class MsgBeginUnlocking extends TransactionMsg { + static override TYPE = "/osmosis.lockup.MsgBeginUnlocking"; + static override AMINO_TYPE = "osmosis/lockup/begin-unlock-period-lock"; + + constructor({ owner, ID, coins }: MsgBeginUnlockingValue) { + super(MsgBeginUnlocking.TYPE, MsgBeginUnlocking.AMINO_TYPE, { + owner, + ID, + coins, + }); + } + + override toProtoMsg(): ProtoMsg { + const cosmosMsg = this.toCosmosMsg(); + return { + typeUrl: this.typeUrl, + value: OsmosisMsgBeginUnlocking.encode(OsmosisMsgBeginUnlocking.fromPartial(cosmosMsg.value)).finish(), + }; + } +} + +export default MsgBeginUnlocking; diff --git a/packages/core/src/internals/transactions/messages/MsgLockTokens.ts b/packages/core/src/internals/transactions/messages/MsgLockTokens.ts index ef51a45..c4d9184 100644 --- a/packages/core/src/internals/transactions/messages/MsgLockTokens.ts +++ b/packages/core/src/internals/transactions/messages/MsgLockTokens.ts @@ -1,11 +1,12 @@ import { Coin } from "@cosmjs/amino"; -import { MsgLockTokens as OsmosisMsgLockTokens } from "../../../externals/osmosis"; -import TransactionMsg, { ProtoMsg } from "./TransactionMsg"; +import { MsgLockTokens as OsmosisMsgLockTokens } from "../../../externals/osmosis/lockup"; +import TransactionMsg, { AminoMsg, ProtoMsg } from "./TransactionMsg"; +import { Duration } from "../../../externals/osmosis/duration"; export type MsgLockTokensValue = { owner: string; - duration: string; + duration: Duration; coins: Coin[]; }; @@ -16,16 +17,26 @@ export class MsgLockTokens extends TransactionMsg { constructor({ owner, duration, coins }: MsgLockTokensValue) { super(MsgLockTokens.TYPE, MsgLockTokens.AMINO_TYPE, { owner, - duration: (Number(duration) * 1_000_000_000).toString(), + duration, coins, }); } + override toAminoMsg(): AminoMsg { + return { + type: this.aminoTypeUrl, + value: { + ...this.value, + duration: Number(this.value.duration.seconds.toString()) * 1_000_000_000, + }, + }; + } + override toProtoMsg(): ProtoMsg { const cosmosMsg = this.toCosmosMsg(); return { typeUrl: this.typeUrl, - value: new OsmosisMsgLockTokens(OsmosisMsgLockTokens.fromJson(cosmosMsg.value)).toBinary(), + value: OsmosisMsgLockTokens.encode(OsmosisMsgLockTokens.fromPartial(cosmosMsg.value)).finish(), }; } } diff --git a/packages/core/src/internals/transactions/messages/index.ts b/packages/core/src/internals/transactions/messages/index.ts index 00c80b9..5946270 100644 --- a/packages/core/src/internals/transactions/messages/index.ts +++ b/packages/core/src/internals/transactions/messages/index.ts @@ -12,3 +12,4 @@ export * from "./MsgCreateSpoTLimitOrder"; export * from "./MsgCancelSpotOrder"; export * from "./MsgDepositForBurn"; export * from "./MsgLockTokens"; +export * from "./MsgBeginUnlocking";