@nemoprotocol/points-sdk
Version:
## Table of Contents
1,774 lines (1,772 loc) • 243 kB
JavaScript
import na, { Decimal as ee } from "decimal.js";
import "@cetusprotocol/vaults-sdk";
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
function sa(r) {
return r instanceof Uint8Array || ArrayBuffer.isView(r) && r.constructor.name === "Uint8Array";
}
function En(r, e) {
return Array.isArray(e) ? e.length === 0 ? !0 : r ? e.every((t) => typeof t == "string") : e.every((t) => Number.isSafeInteger(t)) : !1;
}
function or(r, e) {
if (typeof e != "string")
throw new Error(`${r}: string expected`);
return !0;
}
function On(r) {
if (!Number.isSafeInteger(r))
throw new Error(`invalid integer: ${r}`);
}
function cr(r) {
if (!Array.isArray(r))
throw new Error("array expected");
}
function Cn(r, e) {
if (!En(!0, e))
throw new Error(`${r}: array of strings expected`);
}
function aa(r, e) {
if (!En(!1, e))
throw new Error(`${r}: array of numbers expected`);
}
// @__NO_SIDE_EFFECTS__
function ia(...r) {
const e = (a) => a, t = (a, i) => (o) => a(i(o)), n = r.map((a) => a.encode).reduceRight(t, e), s = r.map((a) => a.decode).reduce(t, e);
return { encode: n, decode: s };
}
// @__NO_SIDE_EFFECTS__
function oa(r) {
const e = typeof r == "string" ? r.split("") : r, t = e.length;
Cn("alphabet", e);
const n = new Map(e.map((s, a) => [s, a]));
return {
encode: (s) => (cr(s), s.map((a) => {
if (!Number.isSafeInteger(a) || a < 0 || a >= t)
throw new Error(`alphabet.encode: digit index outside alphabet "${a}". Allowed: ${r}`);
return e[a];
})),
decode: (s) => (cr(s), s.map((a) => {
or("alphabet.decode", a);
const i = n.get(a);
if (i === void 0)
throw new Error(`Unknown letter: "${a}". Allowed: ${r}`);
return i;
}))
};
}
// @__NO_SIDE_EFFECTS__
function ca(r = "") {
return or("join", r), {
encode: (e) => (Cn("join.decode", e), e.join(r)),
decode: (e) => (or("join.decode", e), e.split(r))
};
}
function Lr(r, e, t) {
if (e < 2)
throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);
if (t < 2)
throw new Error(`convertRadix: invalid to=${t}, base cannot be less than 2`);
if (cr(r), !r.length)
return [];
let n = 0;
const s = [], a = Array.from(r, (o) => {
if (On(o), o < 0 || o >= e)
throw new Error(`invalid integer: ${o}`);
return o;
}), i = a.length;
for (; ; ) {
let o = 0, u = !0;
for (let d = n; d < i; d++) {
const l = a[d], f = e * o, p = f + l;
if (!Number.isSafeInteger(p) || f / e !== o || p - l !== f)
throw new Error("convertRadix: carry overflow");
const v = p / t;
o = p % t;
const y = Math.floor(v);
if (a[d] = y, !Number.isSafeInteger(y) || y * t + o !== p)
throw new Error("convertRadix: carry overflow");
if (u)
y ? u = !1 : n = d;
else continue;
}
if (s.push(o), u)
break;
}
for (let o = 0; o < r.length - 1 && r[o] === 0; o++)
s.push(0);
return s.reverse();
}
// @__NO_SIDE_EFFECTS__
function ua(r) {
On(r);
const e = 2 ** 8;
return {
encode: (t) => {
if (!sa(t))
throw new Error("radix.encode input should be Uint8Array");
return Lr(Array.from(t), e, r);
},
decode: (t) => (aa("radix.decode", t), Uint8Array.from(Lr(t, r, e)))
};
}
const la = /* @__NO_SIDE_EFFECTS__ */ (r) => /* @__PURE__ */ ia(/* @__PURE__ */ ua(58), /* @__PURE__ */ oa(r), /* @__PURE__ */ ca("")), jn = /* @__PURE__ */ la("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"), zt = (r) => jn.encode(r), dt = (r) => jn.decode(r);
function Q(r) {
return Uint8Array.from(atob(r), (e) => e.charCodeAt(0));
}
const Jt = 8192;
function F(r) {
if (r.length < Jt)
return btoa(String.fromCharCode(...r));
let e = "";
for (var t = 0; t < r.length; t += Jt) {
const n = r.slice(t, t + Jt);
e += String.fromCharCode(...n);
}
return btoa(e);
}
function xn(r) {
const e = r.startsWith("0x") ? r.slice(2) : r, t = e.length % 2 === 0 ? e : `0${e}`, n = t.match(/[0-9a-fA-F]{2}/g)?.map((s) => parseInt(s, 16)) ?? [];
if (n.length !== t.length / 2)
throw new Error(`Invalid hex string ${r}`);
return Uint8Array.from(n);
}
function Ze(r) {
return r.reduce((e, t) => e + t.toString(16).padStart(2, "0"), "");
}
function Wt(r, e) {
return Array.from({ length: Math.ceil(r.length / e) }, (t, n) => r.slice(n * e, (n + 1) * e));
}
class Mn {
constructor(e, t) {
if (typeof e != "function")
throw new TypeError(
`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: ${e}.`
);
this._batchLoadFn = e, this._maxBatchSize = ha(t), this._batchScheduleFn = ba(t), this._cacheKeyFn = ma(t), this._cacheMap = ya(t), this._batch = null, this.name = ga(t);
}
/**
* Loads a key, returning a `Promise` for the value represented by that key.
*/
load(e) {
if (e == null)
throw new TypeError(
`The loader.load() function must be called with a value, but got: ${String(e)}.`
);
const t = fa(this), n = this._cacheMap;
let s;
if (n) {
s = this._cacheKeyFn(e);
const i = n.get(s);
if (i) {
const o = t.cacheHits || (t.cacheHits = []);
return new Promise((u) => {
o.push(() => {
u(i);
});
});
}
}
t.keys.push(e);
const a = new Promise((i, o) => {
t.callbacks.push({ resolve: i, reject: o });
});
return n && n.set(s, a), a;
}
/**
* Loads multiple keys, promising an array of values:
*
* var [ a, b ] = await myLoader.loadMany([ 'a', 'b' ]);
*
* This is similar to the more verbose:
*
* var [ a, b ] = await Promise.all([
* myLoader.load('a'),
* myLoader.load('b')
* ]);
*
* However it is different in the case where any load fails. Where
* Promise.all() would reject, loadMany() always resolves, however each result
* is either a value or an Error instance.
*
* var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);
* // c instanceof Error
*
*/
loadMany(e) {
if (!$n(e))
throw new TypeError(
`The loader.loadMany() function must be called with Array<key>, but got: ${e}.`
);
const t = [];
for (let n = 0; n < e.length; n++)
t.push(this.load(e[n]).catch((s) => s));
return Promise.all(t);
}
/**
* Clears the value at `key` from the cache, if it exists. Returns itself for
* method chaining.
*/
clear(e) {
const t = this._cacheMap;
if (t) {
const n = this._cacheKeyFn(e);
t.delete(n);
}
return this;
}
/**
* Clears the entire cache. To be used when some event results in unknown
* invalidations across this particular `DataLoader`. Returns itself for
* method chaining.
*/
clearAll() {
const e = this._cacheMap;
return e && e.clear(), this;
}
/**
* Adds the provided key and value to the cache. If the key already
* exists, no change is made. Returns itself for method chaining.
*
* To prime the cache with an error at a key, provide an Error instance.
*/
prime(e, t) {
const n = this._cacheMap;
if (n) {
const s = this._cacheKeyFn(e);
if (n.get(s) === void 0) {
let a;
t instanceof Error ? (a = Promise.reject(t), a.catch(() => {
})) : a = Promise.resolve(t), n.set(s, a);
}
}
return this;
}
}
const da = (
/** @ts-ignore */
typeof process == "object" && typeof process.nextTick == "function" ? function(r) {
Yt || (Yt = Promise.resolve()), Yt.then(() => {
process.nextTick(r);
});
} : (
// @ts-ignore
typeof setImmediate == "function" ? function(r) {
setImmediate(r);
} : function(r) {
setTimeout(r);
}
)
);
let Yt;
function fa(r) {
const e = r._batch;
if (e !== null && !e.hasDispatched && e.keys.length < r._maxBatchSize)
return e;
const t = { hasDispatched: !1, keys: [], callbacks: [] };
return r._batch = t, r._batchScheduleFn(() => {
pa(r, t);
}), t;
}
function pa(r, e) {
if (e.hasDispatched = !0, e.keys.length === 0) {
ur(e);
return;
}
let t;
try {
t = r._batchLoadFn(e.keys);
} catch (n) {
return Qt(
r,
e,
new TypeError(
`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: ${String(n)}.`
)
);
}
if (!t || typeof t.then != "function")
return Qt(
r,
e,
new TypeError(
`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: ${String(t)}.`
)
);
Promise.resolve(t).then((n) => {
if (!$n(n))
throw new TypeError(
`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array: ${String(n)}.`
);
if (n.length !== e.keys.length)
throw new TypeError(
`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.
Keys:
${String(e.keys)}
Values:
${String(n)}`
);
ur(e);
for (let s = 0; s < e.callbacks.length; s++) {
const a = n[s];
a instanceof Error ? e.callbacks[s].reject(a) : e.callbacks[s].resolve(a);
}
}).catch((n) => {
Qt(r, e, n);
});
}
function Qt(r, e, t) {
ur(e);
for (let n = 0; n < e.keys.length; n++)
r.clear(e.keys[n]), e.callbacks[n].reject(t);
}
function ur(r) {
if (r.cacheHits)
for (let e = 0; e < r.cacheHits.length; e++)
r.cacheHits[e]();
}
function ha(r) {
if (!(!r || r.batch !== !1))
return 1;
const t = r && r.maxBatchSize;
if (t === void 0)
return 1 / 0;
if (typeof t != "number" || t < 1)
throw new TypeError(`maxBatchSize must be a positive number: ${t}`);
return t;
}
function ba(r) {
const e = r && r.batchScheduleFn;
if (e === void 0)
return da;
if (typeof e != "function")
throw new TypeError(`batchScheduleFn must be a function: ${e}`);
return e;
}
function ma(r) {
const e = r && r.cacheKeyFn;
if (e === void 0)
return (t) => t;
if (typeof e != "function")
throw new TypeError(`cacheKeyFn must be a function: ${e}`);
return e;
}
function ya(r) {
if (!(!r || r.cache !== !1))
return null;
const t = r && r.cacheMap;
if (t === void 0)
return /* @__PURE__ */ new Map();
if (t !== null) {
const s = ["get", "set", "delete", "clear"].filter(
(a) => t && typeof t[a] != "function"
);
if (s.length !== 0)
throw new TypeError("Custom cacheMap missing methods: " + s.join(", "));
}
return t;
}
function ga(r) {
return r && r.name ? r.name : null;
}
function $n(r) {
return typeof r == "object" && r !== null && "length" in r && typeof r.length == "number" && (r.length === 0 || r.length > 0 && Object.prototype.hasOwnProperty.call(r, r.length - 1));
}
function $t(r) {
const e = [];
let t = 0;
if (r === 0)
return [0];
for (; r > 0; )
e[t] = r & 127, (r >>= 7) && (e[t] |= 128), t += 1;
return e;
}
function va(r) {
let e = 0, t = 0, n = 0;
for (; ; ) {
const s = r[n];
if (n += 1, e |= (s & 127) << t, (s & 128) === 0)
break;
t += 7;
}
return {
value: e,
length: n
};
}
class wa {
/**
* @param {Uint8Array} data Data to use as a buffer.
*/
constructor(e) {
this.bytePosition = 0, this.dataView = new DataView(e.buffer, e.byteOffset, e.byteLength);
}
/**
* Shift current cursor position by `bytes`.
*
* @param {Number} bytes Number of bytes to
* @returns {this} Self for possible chaining.
*/
shift(e) {
return this.bytePosition += e, this;
}
/**
* Read U8 value from the buffer and shift cursor by 1.
* @returns
*/
read8() {
const e = this.dataView.getUint8(this.bytePosition);
return this.shift(1), e;
}
/**
* Read U16 value from the buffer and shift cursor by 2.
* @returns
*/
read16() {
const e = this.dataView.getUint16(this.bytePosition, !0);
return this.shift(2), e;
}
/**
* Read U32 value from the buffer and shift cursor by 4.
* @returns
*/
read32() {
const e = this.dataView.getUint32(this.bytePosition, !0);
return this.shift(4), e;
}
/**
* Read U64 value from the buffer and shift cursor by 8.
* @returns
*/
read64() {
const e = this.read32(), n = this.read32().toString(16) + e.toString(16).padStart(8, "0");
return BigInt("0x" + n).toString(10);
}
/**
* Read U128 value from the buffer and shift cursor by 16.
*/
read128() {
const e = BigInt(this.read64()), n = BigInt(this.read64()).toString(16) + e.toString(16).padStart(16, "0");
return BigInt("0x" + n).toString(10);
}
/**
* Read U128 value from the buffer and shift cursor by 32.
* @returns
*/
read256() {
const e = BigInt(this.read128()), n = BigInt(this.read128()).toString(16) + e.toString(16).padStart(32, "0");
return BigInt("0x" + n).toString(10);
}
/**
* Read `num` number of bytes from the buffer and shift cursor by `num`.
* @param num Number of bytes to read.
*/
readBytes(e) {
const t = this.bytePosition + this.dataView.byteOffset, n = new Uint8Array(this.dataView.buffer, t, e);
return this.shift(e), n;
}
/**
* Read ULEB value - an integer of varying size. Used for enum indexes and
* vector lengths.
* @returns {Number} The ULEB value.
*/
readULEB() {
const e = this.bytePosition + this.dataView.byteOffset, t = new Uint8Array(this.dataView.buffer, e), { value: n, length: s } = va(t);
return this.shift(s), n;
}
/**
* Read a BCS vector: read a length and then apply function `cb` X times
* where X is the length of the vector, defined as ULEB in BCS bytes.
* @param cb Callback to process elements of vector.
* @returns {Array<Any>} Array of the resulting values, returned by callback.
*/
readVec(e) {
const t = this.readULEB(), n = [];
for (let s = 0; s < t; s++)
n.push(e(this, s, t));
return n;
}
}
function _a(r, e) {
switch (e) {
case "base58":
return zt(r);
case "base64":
return F(r);
case "hex":
return Ze(r);
default:
throw new Error("Unsupported encoding, supported values are: base64, hex");
}
}
function Pn(r, e = ["<", ">"]) {
const [t, n] = e, s = [];
let a = "", i = 0;
for (let o = 0; o < r.length; o++) {
const u = r[o];
if (u === t && i++, u === n && i--, i === 0 && u === ",") {
s.push(a.trim()), a = "";
continue;
}
a += u;
}
return s.push(a.trim()), s;
}
class Ta {
constructor({
initialSize: e = 1024,
maxSize: t = 1 / 0,
allocateSize: n = 1024
} = {}) {
this.bytePosition = 0, this.size = e, this.maxSize = t, this.allocateSize = n, this.dataView = new DataView(new ArrayBuffer(e));
}
ensureSizeOrGrow(e) {
const t = this.bytePosition + e;
if (t > this.size) {
const n = Math.min(this.maxSize, this.size + this.allocateSize);
if (t > n)
throw new Error(
`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${t}`
);
this.size = n;
const s = new ArrayBuffer(this.size);
new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)), this.dataView = new DataView(s);
}
}
/**
* Shift current cursor position by `bytes`.
*
* @param {Number} bytes Number of bytes to
* @returns {this} Self for possible chaining.
*/
shift(e) {
return this.bytePosition += e, this;
}
/**
* Write a U8 value into a buffer and shift cursor position by 1.
* @param {Number} value Value to write.
* @returns {this}
*/
write8(e) {
return this.ensureSizeOrGrow(1), this.dataView.setUint8(this.bytePosition, Number(e)), this.shift(1);
}
/**
* Write a U16 value into a buffer and shift cursor position by 2.
* @param {Number} value Value to write.
* @returns {this}
*/
write16(e) {
return this.ensureSizeOrGrow(2), this.dataView.setUint16(this.bytePosition, Number(e), !0), this.shift(2);
}
/**
* Write a U32 value into a buffer and shift cursor position by 4.
* @param {Number} value Value to write.
* @returns {this}
*/
write32(e) {
return this.ensureSizeOrGrow(4), this.dataView.setUint32(this.bytePosition, Number(e), !0), this.shift(4);
}
/**
* Write a U64 value into a buffer and shift cursor position by 8.
* @param {bigint} value Value to write.
* @returns {this}
*/
write64(e) {
return Xt(BigInt(e), 8).forEach((t) => this.write8(t)), this;
}
/**
* Write a U128 value into a buffer and shift cursor position by 16.
*
* @param {bigint} value Value to write.
* @returns {this}
*/
write128(e) {
return Xt(BigInt(e), 16).forEach((t) => this.write8(t)), this;
}
/**
* Write a U256 value into a buffer and shift cursor position by 16.
*
* @param {bigint} value Value to write.
* @returns {this}
*/
write256(e) {
return Xt(BigInt(e), 32).forEach((t) => this.write8(t)), this;
}
/**
* Write a ULEB value into a buffer and shift cursor position by number of bytes
* written.
* @param {Number} value Value to write.
* @returns {this}
*/
writeULEB(e) {
return $t(e).forEach((t) => this.write8(t)), this;
}
/**
* Write a vector into a buffer by first writing the vector length and then calling
* a callback on each passed value.
*
* @param {Array<Any>} vector Array of elements to write.
* @param {WriteVecCb} cb Callback to call on each element of the vector.
* @returns {this}
*/
writeVec(e, t) {
return this.writeULEB(e.length), Array.from(e).forEach((n, s) => t(this, n, s, e.length)), this;
}
/**
* Adds support for iterations over the object.
* @returns {Uint8Array}
*/
*[Symbol.iterator]() {
for (let e = 0; e < this.bytePosition; e++)
yield this.dataView.getUint8(e);
return this.toBytes();
}
/**
* Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
* @returns {Uint8Array} Resulting bcs.
*/
toBytes() {
return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
}
/**
* Represent data as 'hex' or 'base64'
* @param encoding Encoding to use: 'base64' or 'hex'
*/
toString(e) {
return _a(this.toBytes(), e);
}
}
function Xt(r, e) {
const t = new Uint8Array(e);
let n = 0;
for (; r > 0; )
t[n] = Number(r % BigInt(256)), r = r / BigInt(256), n += 1;
return t;
}
var Un = (r) => {
throw TypeError(r);
}, Rn = (r, e, t) => e.has(r) || Un("Cannot " + t), ie = (r, e, t) => (Rn(r, e, "read from private field"), t ? t.call(r) : e.get(r)), Pt = (r, e, t) => e.has(r) ? Un("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), Ut = (r, e, t, n) => (Rn(r, e, "write to private field"), e.set(r, t), t), Ye, st, Et, Ce;
const Sa = class Nn {
constructor(e) {
Pt(this, Ye), Pt(this, st), this.name = e.name, this.read = e.read, this.serializedSize = e.serializedSize ?? (() => null), Ut(this, Ye, e.write), Ut(this, st, e.serialize ?? ((t, n) => {
const s = new Ta({
initialSize: this.serializedSize(t) ?? void 0,
...n
});
return ie(this, Ye).call(this, t, s), s.toBytes();
})), this.validate = e.validate ?? (() => {
});
}
write(e, t) {
this.validate(e), ie(this, Ye).call(this, e, t);
}
serialize(e, t) {
return this.validate(e), new ka(this, ie(this, st).call(this, e, t));
}
parse(e) {
const t = new wa(e);
return this.read(t);
}
fromHex(e) {
return this.parse(xn(e));
}
fromBase58(e) {
return this.parse(dt(e));
}
fromBase64(e) {
return this.parse(Q(e));
}
transform({
name: e,
input: t,
output: n,
validate: s
}) {
return new Nn({
name: e ?? this.name,
read: (a) => n ? n(this.read(a)) : this.read(a),
write: (a, i) => ie(this, Ye).call(this, t ? t(a) : a, i),
serializedSize: (a) => this.serializedSize(t ? t(a) : a),
serialize: (a, i) => ie(this, st).call(this, t ? t(a) : a, i),
validate: (a) => {
s?.(a), this.validate(t ? t(a) : a);
}
});
}
};
Ye = /* @__PURE__ */ new WeakMap();
st = /* @__PURE__ */ new WeakMap();
let he = Sa;
const Bn = Symbol.for("@mysten/serialized-bcs");
function kr(r) {
return !!r && typeof r == "object" && r[Bn] === !0;
}
class ka {
constructor(e, t) {
Pt(this, Et), Pt(this, Ce), Ut(this, Et, e), Ut(this, Ce, t);
}
// Used to brand SerializedBcs so that they can be identified, even between multiple copies
// of the @mysten/bcs package are installed
get [Bn]() {
return !0;
}
toBytes() {
return ie(this, Ce);
}
toHex() {
return Ze(ie(this, Ce));
}
toBase64() {
return F(ie(this, Ce));
}
toBase58() {
return zt(ie(this, Ce));
}
parse() {
return ie(this, Et).parse(ie(this, Ce));
}
}
Et = /* @__PURE__ */ new WeakMap();
Ce = /* @__PURE__ */ new WeakMap();
function Rt({
size: r,
...e
}) {
return new he({
...e,
serializedSize: () => r
});
}
function Zt({
readMethod: r,
writeMethod: e,
...t
}) {
return Rt({
...t,
read: (n) => n[r](),
write: (n, s) => s[e](n),
validate: (n) => {
if (n < 0 || n > t.maxValue)
throw new TypeError(
`Invalid ${t.name} value: ${n}. Expected value in range 0-${t.maxValue}`
);
t.validate?.(n);
}
});
}
function er({
readMethod: r,
writeMethod: e,
...t
}) {
return Rt({
...t,
read: (n) => n[r](),
write: (n, s) => s[e](BigInt(n)),
validate: (n) => {
const s = BigInt(n);
if (s < 0 || s > t.maxValue)
throw new TypeError(
`Invalid ${t.name} value: ${s}. Expected value in range 0-${t.maxValue}`
);
t.validate?.(s);
}
});
}
function Aa({
serialize: r,
...e
}) {
const t = new he({
...e,
serialize: r,
write: (n, s) => {
for (const a of t.serialize(n).toBytes())
s.write8(a);
}
});
return t;
}
function Ia({
toBytes: r,
fromBytes: e,
...t
}) {
return new he({
...t,
read: (n) => {
const s = n.readULEB(), a = n.readBytes(s);
return e(a);
},
write: (n, s) => {
const a = r(n);
s.writeULEB(a.length);
for (let i = 0; i < a.length; i++)
s.write8(a[i]);
},
serialize: (n) => {
const s = r(n), a = $t(s.length), i = new Uint8Array(a.length + s.length);
return i.set(a, 0), i.set(s, a.length), i;
},
validate: (n) => {
if (typeof n != "string")
throw new TypeError(`Invalid ${t.name} value: ${n}. Expected string`);
t.validate?.(n);
}
});
}
function Ea(r) {
let e = null;
function t() {
return e || (e = r()), e;
}
return new he({
name: "lazy",
read: (n) => t().read(n),
serializedSize: (n) => t().serializedSize(n),
write: (n, s) => t().write(n, s),
serialize: (n, s) => t().serialize(n, s).toBytes()
});
}
const c = {
/**
* Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
* @example
* bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
*/
u8(r) {
return Zt({
name: "u8",
readMethod: "read8",
writeMethod: "write8",
size: 1,
maxValue: 2 ** 8 - 1,
...r
});
},
/**
* Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
* @example
* bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
*/
u16(r) {
return Zt({
name: "u16",
readMethod: "read16",
writeMethod: "write16",
size: 2,
maxValue: 2 ** 16 - 1,
...r
});
},
/**
* Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
* @example
* bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
*/
u32(r) {
return Zt({
name: "u32",
readMethod: "read32",
writeMethod: "write32",
size: 4,
maxValue: 2 ** 32 - 1,
...r
});
},
/**
* Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
* @example
* bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
*/
u64(r) {
return er({
name: "u64",
readMethod: "read64",
writeMethod: "write64",
size: 8,
maxValue: 2n ** 64n - 1n,
...r
});
},
/**
* Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
* @example
* bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
*/
u128(r) {
return er({
name: "u128",
readMethod: "read128",
writeMethod: "write128",
size: 16,
maxValue: 2n ** 128n - 1n,
...r
});
},
/**
* Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
* @example
* bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
*/
u256(r) {
return er({
name: "u256",
readMethod: "read256",
writeMethod: "write256",
size: 32,
maxValue: 2n ** 256n - 1n,
...r
});
},
/**
* Creates a BcsType that can be used to read and write boolean values.
* @example
* bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
*/
bool(r) {
return Rt({
name: "bool",
size: 1,
read: (e) => e.read8() === 1,
write: (e, t) => t.write8(e ? 1 : 0),
...r,
validate: (e) => {
if (r?.validate?.(e), typeof e != "boolean")
throw new TypeError(`Expected boolean, found ${typeof e}`);
}
});
},
/**
* Creates a BcsType that can be used to read and write unsigned LEB encoded integers
* @example
*
*/
uleb128(r) {
return Aa({
name: "uleb128",
read: (e) => e.readULEB(),
serialize: (e) => Uint8Array.from($t(e)),
...r
});
},
/**
* Creates a BcsType representing a fixed length byte array
* @param size The number of bytes this types represents
* @example
* bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
*/
bytes(r, e) {
return Rt({
name: `bytes[${r}]`,
size: r,
read: (t) => t.readBytes(r),
write: (t, n) => {
const s = new Uint8Array(t);
for (let a = 0; a < r; a++)
n.write8(s[a] ?? 0);
},
...e,
validate: (t) => {
if (e?.validate?.(t), !t || typeof t != "object" || !("length" in t))
throw new TypeError(`Expected array, found ${typeof t}`);
if (t.length !== r)
throw new TypeError(`Expected array of length ${r}, found ${t.length}`);
}
});
},
/**
* Creates a BcsType representing a variable length byte array
*
* @example
* bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
*/
byteVector(r) {
return new he({
name: "bytesVector",
read: (e) => {
const t = e.readULEB();
return e.readBytes(t);
},
write: (e, t) => {
const n = new Uint8Array(e);
t.writeULEB(n.length);
for (let s = 0; s < n.length; s++)
t.write8(n[s] ?? 0);
},
...r,
serializedSize: (e) => {
const t = "length" in e ? e.length : null;
return t == null ? null : $t(t).length + t;
},
validate: (e) => {
if (r?.validate?.(e), !e || typeof e != "object" || !("length" in e))
throw new TypeError(`Expected array, found ${typeof e}`);
}
});
},
/**
* Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
* @example
* bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
*/
string(r) {
return Ia({
name: "string",
toBytes: (e) => new TextEncoder().encode(e),
fromBytes: (e) => new TextDecoder().decode(e),
...r
});
},
/**
* Creates a BcsType that represents a fixed length array of a given type
* @param size The number of elements in the array
* @param type The BcsType of each element in the array
* @example
* bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
*/
fixedArray(r, e, t) {
return new he({
name: `${e.name}[${r}]`,
read: (n) => {
const s = new Array(r);
for (let a = 0; a < r; a++)
s[a] = e.read(n);
return s;
},
write: (n, s) => {
for (const a of n)
e.write(a, s);
},
...t,
validate: (n) => {
if (t?.validate?.(n), !n || typeof n != "object" || !("length" in n))
throw new TypeError(`Expected array, found ${typeof n}`);
if (n.length !== r)
throw new TypeError(`Expected array of length ${r}, found ${n.length}`);
}
});
},
/**
* Creates a BcsType representing an optional value
* @param type The BcsType of the optional value
* @example
* bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
* bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
*/
option(r) {
return c.enum(`Option<${r.name}>`, {
None: null,
Some: r
}).transform({
input: (e) => e == null ? { None: !0 } : { Some: e },
output: (e) => e.$kind === "Some" ? e.Some : null
});
},
/**
* Creates a BcsType representing a variable length vector of a given type
* @param type The BcsType of each element in the vector
*
* @example
* bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
*/
vector(r, e) {
return new he({
name: `vector<${r.name}>`,
read: (t) => {
const n = t.readULEB(), s = new Array(n);
for (let a = 0; a < n; a++)
s[a] = r.read(t);
return s;
},
write: (t, n) => {
n.writeULEB(t.length);
for (const s of t)
r.write(s, n);
},
...e,
validate: (t) => {
if (e?.validate?.(t), !t || typeof t != "object" || !("length" in t))
throw new TypeError(`Expected array, found ${typeof t}`);
}
});
},
/**
* Creates a BcsType representing a tuple of a given set of types
* @param types The BcsTypes for each element in the tuple
*
* @example
* const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
* tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
*/
tuple(r, e) {
return new he({
name: `(${r.map((t) => t.name).join(", ")})`,
serializedSize: (t) => {
let n = 0;
for (let s = 0; s < r.length; s++) {
const a = r[s].serializedSize(t[s]);
if (a == null)
return null;
n += a;
}
return n;
},
read: (t) => {
const n = [];
for (const s of r)
n.push(s.read(t));
return n;
},
write: (t, n) => {
for (let s = 0; s < r.length; s++)
r[s].write(t[s], n);
},
...e,
validate: (t) => {
if (e?.validate?.(t), !Array.isArray(t))
throw new TypeError(`Expected array, found ${typeof t}`);
if (t.length !== r.length)
throw new TypeError(`Expected array of length ${r.length}, found ${t.length}`);
}
});
},
/**
* Creates a BcsType representing a struct of a given set of fields
* @param name The name of the struct
* @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
*
* @example
* const struct = bcs.struct('MyStruct', {
* a: bcs.u8(),
* b: bcs.string(),
* })
* struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
*/
struct(r, e, t) {
const n = Object.entries(e);
return new he({
name: r,
serializedSize: (s) => {
let a = 0;
for (const [i, o] of n) {
const u = o.serializedSize(s[i]);
if (u == null)
return null;
a += u;
}
return a;
},
read: (s) => {
const a = {};
for (const [i, o] of n)
a[i] = o.read(s);
return a;
},
write: (s, a) => {
for (const [i, o] of n)
o.write(s[i], a);
},
...t,
validate: (s) => {
if (t?.validate?.(s), typeof s != "object" || s == null)
throw new TypeError(`Expected object, found ${typeof s}`);
}
});
},
/**
* Creates a BcsType representing an enum of a given set of options
* @param name The name of the enum
* @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
* null can be used to represent a variant with no data.
*
* @example
* const enum = bcs.enum('MyEnum', {
* A: bcs.u8(),
* B: bcs.string(),
* C: null,
* })
* enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
* enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
* enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
*/
enum(r, e, t) {
const n = Object.entries(e);
return new he({
name: r,
read: (s) => {
const a = s.readULEB(), i = n[a];
if (!i)
throw new TypeError(`Unknown value ${a} for enum ${r}`);
const [o, u] = i;
return {
[o]: u?.read(s) ?? !0,
$kind: o
};
},
write: (s, a) => {
const [i, o] = Object.entries(s).filter(
([u]) => Object.hasOwn(e, u)
)[0];
for (let u = 0; u < n.length; u++) {
const [d, l] = n[u];
if (d === i) {
a.writeULEB(u), l?.write(o, a);
return;
}
}
},
...t,
validate: (s) => {
if (t?.validate?.(s), typeof s != "object" || s == null)
throw new TypeError(`Expected object, found ${typeof s}`);
const a = Object.keys(s).filter(
(o) => s[o] !== void 0 && Object.hasOwn(e, o)
);
if (a.length !== 1)
throw new TypeError(
`Expected object with one key, but found ${a.length} for type ${r}}`
);
const [i] = a;
if (!Object.hasOwn(e, i))
throw new TypeError(`Invalid enum variant ${i}`);
}
});
},
/**
* Creates a BcsType representing a map of a given key and value type
* @param keyType The BcsType of the key
* @param valueType The BcsType of the value
* @example
* const map = bcs.map(bcs.u8(), bcs.string())
* map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
*/
map(r, e) {
return c.vector(c.tuple([r, e])).transform({
name: `Map<${r.name}, ${e.name}>`,
input: (t) => [...t.entries()],
output: (t) => {
const n = /* @__PURE__ */ new Map();
for (const [s, a] of t)
n.set(s, a);
return n;
}
});
},
/**
* Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
* @param cb A callback that returns the BcsType
*/
lazy(r) {
return Ea(r);
}
}, Ln = /^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i, Vn = /^(?!.*(^|[-.])($|[-.]))(?:[a-z0-9-]{0,63}\.)+sui$/i, Oa = 235;
function Ca(r) {
return r.length > Oa ? !1 : r.includes("@") ? Ln.test(r) : Vn.test(r);
}
function ja(r, e = "at") {
const t = r.toLowerCase();
let n;
if (t.includes("@")) {
if (!Ln.test(t))
throw new Error(`Invalid SuiNS name ${r}`);
const [s, a] = t.split("@");
n = [...s ? s.split(".") : [], a];
} else {
if (!Vn.test(t))
throw new Error(`Invalid SuiNS name ${r}`);
n = t.split(".").slice(0, -1);
}
return e === "dot" ? `${n.join(".")}.sui` : `${n.slice(0, -1).join(".")}@${n[n.length - 1]}`;
}
const xa = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/, Ma = /^\d+$/, $a = 64, Dn = "/", Y = (r) => {
const e = r.split(Dn);
if (e.length < 2 || e.length > 3) return !1;
const [t, n, s] = e;
return s !== void 0 && !Ma.test(s) || !Ca(t) ? !1 : xa.test(n) && n.length < $a;
}, Pa = (r) => {
const e = r.split(/::|<|>|,/);
for (const t of e)
if (t.includes(Dn) && !Y(t)) return !1;
return !0;
}, Ua = 32;
function Vr(r) {
try {
return dt(r).length === Ua;
} catch {
return !1;
}
}
const Ft = 32;
function oe(r) {
return Na(r) && Ba(r) === Ft;
}
function wt(r) {
return oe(r);
}
function Ra(r) {
return r.includes("::") ? We(r) : r;
}
function We(r) {
const [e, t] = r.split("::"), n = Y(e), s = r.slice(e.length + t.length + 4), a = s.includes("<") ? s.slice(0, s.indexOf("<")) : s, i = s.includes("<") ? Pn(s.slice(s.indexOf("<") + 1, s.lastIndexOf(">"))).map(
(o) => Ra(o.trim())
) : [];
return {
address: n ? e : I(e),
module: t,
name: a,
typeParams: i
};
}
function Nt(r) {
const { address: e, module: t, name: n, typeParams: s } = typeof r == "string" ? We(r) : r, a = s?.length > 0 ? `<${s.map(
(i) => typeof i == "string" ? i : Nt(i)
).join(",")}>` : "";
return `${e}::${t}::${n}${a}`;
}
function I(r, e = !1) {
let t = r.toLowerCase();
return !e && t.startsWith("0x") && (t = t.slice(2)), `0x${t.padStart(Ft * 2, "0")}`;
}
function Se(r, e = !1) {
return I(r, e);
}
function Na(r) {
return /^(0x|0X)?[a-fA-F0-9]+$/.test(r) && r.length % 2 === 0;
}
function Ba(r) {
return /^(0x|0X)/.test(r) ? (r.length - 2) / 2 : r.length / 2;
}
const La = /^vector<(.+)>$/, Va = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
class ue {
static parseFromStr(e, t = !1) {
if (e === "address")
return { address: null };
if (e === "bool")
return { bool: null };
if (e === "u8")
return { u8: null };
if (e === "u16")
return { u16: null };
if (e === "u32")
return { u32: null };
if (e === "u64")
return { u64: null };
if (e === "u128")
return { u128: null };
if (e === "u256")
return { u256: null };
if (e === "signer")
return { signer: null };
const n = e.match(La);
if (n)
return {
vector: ue.parseFromStr(n[1], t)
};
const s = e.match(Va);
if (s)
return {
struct: {
address: t ? I(s[1]) : s[1],
module: s[2],
name: s[3],
typeParams: s[5] === void 0 ? [] : ue.parseStructTypeArgs(s[5], t)
}
};
throw new Error(`Encountered unexpected token when parsing type args for ${e}`);
}
static parseStructTypeArgs(e, t = !1) {
return Pn(e).map(
(n) => ue.parseFromStr(n, t)
);
}
static tagToString(e) {
if ("bool" in e)
return "bool";
if ("u8" in e)
return "u8";
if ("u16" in e)
return "u16";
if ("u32" in e)
return "u32";
if ("u64" in e)
return "u64";
if ("u128" in e)
return "u128";
if ("u256" in e)
return "u256";
if ("address" in e)
return "address";
if ("signer" in e)
return "signer";
if ("vector" in e)
return `vector<${ue.tagToString(e.vector)}>`;
if ("struct" in e) {
const t = e.struct, n = t.typeParams.map(ue.tagToString).join(", ");
return `${t.address}::${t.module}::${t.name}${n ? `<${n}>` : ""}`;
}
throw new Error("Invalid TypeTag");
}
}
function Da(r) {
return c.u64({
name: "unsafe_u64",
...r
}).transform({
input: (e) => e,
output: (e) => Number(e)
});
}
function za(r) {
return c.enum("Option", {
None: null,
Some: r
});
}
const C = c.bytes(Ft).transform({
validate: (r) => {
const e = typeof r == "string" ? r : Ze(r);
if (!e || !oe(I(e)))
throw new Error(`Invalid Sui address ${e}`);
},
input: (r) => typeof r == "string" ? xn(I(r)) : r,
output: (r) => I(Ze(r))
}), de = c.vector(c.u8()).transform({
name: "ObjectDigest",
input: (r) => dt(r),
output: (r) => zt(new Uint8Array(r)),
validate: (r) => {
if (dt(r).length !== 32)
throw new Error("ObjectDigest must be 32 bytes");
}
}), te = c.struct("SuiObjectRef", {
objectId: C,
version: c.u64(),
digest: de
}), zn = c.struct("SharedObjectRef", {
objectId: C,
initialSharedVersion: c.u64(),
mutable: c.bool()
}), Wn = c.enum("ObjectArg", {
ImmOrOwnedObject: te,
SharedObject: zn,
Receiving: te
}), Be = c.enum("Owner", {
AddressOwner: C,
ObjectOwner: C,
Shared: c.struct("Shared", {
initialSharedVersion: c.u64()
}),
Immutable: null,
ConsensusAddressOwner: c.struct("ConsensusAddressOwner", {
owner: C,
startVersion: c.u64()
})
}), Fn = c.enum("CallArg", {
Pure: c.struct("Pure", {
bytes: c.vector(c.u8()).transform({
input: (r) => typeof r == "string" ? Q(r) : r,
output: (r) => F(new Uint8Array(r))
})
}),
Object: Wn
}), Ar = c.enum("TypeTag", {
bool: null,
u8: null,
u64: null,
u128: null,
address: null,
signer: null,
vector: c.lazy(() => Ar),
struct: c.lazy(() => Yn),
u16: null,
u32: null,
u256: null
}), Ir = Ar.transform({
input: (r) => typeof r == "string" ? ue.parseFromStr(r, !0) : r,
output: (r) => ue.tagToString(r)
}), pe = c.enum("Argument", {
GasCoin: null,
Input: c.u16(),
Result: c.u16(),
NestedResult: c.tuple([c.u16(), c.u16()])
}), Gn = c.struct("ProgrammableMoveCall", {
package: C,
module: c.string(),
function: c.string(),
typeArguments: c.vector(Ir),
arguments: c.vector(pe)
}), qn = c.enum("Command", {
/**
* A Move Call - any public Move function can be called via
* this transaction. The results can be used that instant to pass
* into the next transaction.
*/
MoveCall: Gn,
/**
* Transfer vector of objects to a receiver.
*/
TransferObjects: c.struct("TransferObjects", {
objects: c.vector(pe),
address: pe
}),
// /**
// * Split `amount` from a `coin`.
// */
SplitCoins: c.struct("SplitCoins", {
coin: pe,
amounts: c.vector(pe)
}),
// /**
// * Merge Vector of Coins (`sources`) into a `destination`.
// */
MergeCoins: c.struct("MergeCoins", {
destination: pe,
sources: c.vector(pe)
}),
// /**
// * Publish a Move module.
// */
Publish: c.struct("Publish", {
modules: c.vector(
c.vector(c.u8()).transform({
input: (r) => typeof r == "string" ? Q(r) : r,
output: (r) => F(new Uint8Array(r))
})
),
dependencies: c.vector(C)
}),
// /**
// * Build a vector of objects using the input arguments.
// * It is impossible to export construct a `vector<T: key>` otherwise,
// * so this call serves a utility function.
// */
MakeMoveVec: c.struct("MakeMoveVec", {
type: za(Ir).transform({
input: (r) => r === null ? {
None: !0
} : {
Some: r
},
output: (r) => r.Some ?? null
}),
elements: c.vector(pe)
}),
Upgrade: c.struct("Upgrade", {
modules: c.vector(
c.vector(c.u8()).transform({
input: (r) => typeof r == "string" ? Q(r) : r,
output: (r) => F(new Uint8Array(r))
})
),
dependencies: c.vector(C),
package: C,
ticket: pe
})
}), Kn = c.struct("ProgrammableTransaction", {
inputs: c.vector(Fn),
commands: c.vector(qn)
}), Hn = c.enum("TransactionKind", {
ProgrammableTransaction: Kn,
ChangeEpoch: null,
Genesis: null,
ConsensusCommitPrologue: null
}), Jn = c.enum("TransactionExpiration", {
None: null,
Epoch: Da()
}), Yn = c.struct("StructTag", {
address: C,
module: c.string(),
name: c.string(),
typeParams: c.vector(Ar)
}), Qn = c.struct("GasData", {
payment: c.vector(te),
owner: C,
price: c.u64(),
budget: c.u64()
}), Xn = c.struct("TransactionDataV1", {
kind: Hn,
sender: C,
gasData: Qn,
expiration: Jn
}), Zn = c.enum("TransactionData", {
V1: Xn
}), es = c.enum("IntentScope", {
TransactionData: null,
TransactionEffects: null,
CheckpointSummary: null,
PersonalMessage: null
}), ts = c.enum("IntentVersion", {
V0: null
}), rs = c.enum("AppId", {
Sui: null
}), ns = c.struct("Intent", {
scope: es,
version: ts,
appId: rs
});
function ss(r) {
return c.struct(`IntentMessage<${r.name}>`, {
intent: ns,
value: r
});
}
const as = c.enum("CompressedSignature", {
ED25519: c.fixedArray(64, c.u8()),
Secp256k1: c.fixedArray(64, c.u8()),
Secp256r1: c.fixedArray(64, c.u8()),
ZkLogin: c.vector(c.u8())
}), is = c.enum("PublicKey", {
ED25519: c.fixedArray(32, c.u8()),
Secp256k1: c.fixedArray(33, c.u8()),
Secp256r1: c.fixedArray(33, c.u8()),
ZkLogin: c.vector(c.u8())
}), os = c.struct("MultiSigPkMap", {
pubKey: is,
weight: c.u8()
}), cs = c.struct("MultiSigPublicKey", {
pk_map: c.vector(os),
threshold: c.u16()
}), Wa = c.struct("MultiSig", {
sigs: c.vector(as),
bitmap: c.u16(),
multisig_pk: cs
}), Fa = c.vector(c.u8()).transform({
input: (r) => typeof r == "string" ? Q(r) : r,
output: (r) => F(new Uint8Array(r))
}), us = c.struct("SenderSignedTransaction", {
intentMessage: ss(Zn),
txSignatures: c.vector(Fa)
}), Ga = c.vector(us, {
name: "SenderSignedData"
}), qa = c.struct("PasskeyAuthenticator", {
authenticatorData: c.vector(c.u8()),
clientDataJson: c.string(),
userSignature: c.vector(c.u8())
}), Ka = c.enum("PackageUpgradeError", {
UnableToFetchPackage: c.struct("UnableToFetchPackage", { packageId: C }),
NotAPackage: c.struct("NotAPackage", { objectId: C }),
IncompatibleUpgrade: null,
DigestDoesNotMatch: c.struct("DigestDoesNotMatch", { digest: c.vector(c.u8()) }),
UnknownUpgradePolicy: c.struct("UnknownUpgradePolicy", { policy: c.u8() }),
PackageIDDoesNotMatch: c.struct("PackageIDDoesNotMatch", {
packageId: C,
ticketId: C
})
}), Ha = c.struct("ModuleId", {
address: C,
name: c.string()
}), Dr = c.struct("MoveLocation", {
module: Ha,
function: c.u16(),
instruction: c.u16(),
functionName: c.option(c.string())
}), Ja = c.enum("CommandArgumentError", {
TypeMismatch: null,
InvalidBCSBytes: null,
InvalidUsageOfPureArg: null,
InvalidArgumentToPrivateEntryFunction: null,
IndexOutOfBounds: c.struct("IndexOutOfBounds", { idx: c.u16() }),
SecondaryIndexOutOfBounds: c.struct("SecondaryIndexOutOfBounds", {
resultIdx: c.u16(),
secondaryIdx: c.u16()
}),
InvalidResultArity: c.struct("InvalidResultArity", { resultIdx: c.u16() }),
InvalidGasCoinUsage: null,
InvalidValueUsage: null,
InvalidObjectByValue: null,
InvalidObjectByMutRef: null,
SharedObjectOperationNotAllowed: null
}), Ya = c.enum("TypeArgumentError", {
TypeNotFound: null,
ConstraintNotSatisfied: null
}), Qa = c.enum("ExecutionFailureStatus", {
InsufficientGas: null,
InvalidGasObject: null,
InvariantViolation: null,
FeatureNotYetSupported: null,
MoveObjectTooBig: c.struct("MoveObjectTooBig", {
objectSize: c.u64(),
maxObjectSize: c.u64()
}),
MovePackageTooBig: c.struct("MovePackageTooBig", {
objectSize: c.u64(),
maxObjectSize: c.u64()
}),
CircularObjectOwnership: c.struct("CircularObjectOwnership", { object: C }),
InsufficientCoinBalance: null,
CoinBalanceOverflow: null,
PublishErrorNonZeroAddress: null,
SuiMoveVerificationError: null,
MovePrimitiveRuntimeError: c.option(Dr),
MoveAbort: c.tuple([Dr, c.u64()]),
VMVerificationOrDeserializationError: null,
VMInvariantViolation: null,
FunctionNotFound: null,
ArityMismatch: null,
TypeArityMismatch: null,
NonEntryFunctionInvoked: null,
CommandArgumentError: c.struct("CommandArgumentError", {
argIdx: c.u16(),
kind: Ja
}),
TypeArgumentError: c.struct("TypeArgumentError", {
argumentIdx: c.u16(),
kind: Ya
}),
UnusedValueWithoutDrop: c.struct("UnusedValueWithoutDrop", {
resultIdx: c.u16(),
secondaryIdx: c.u16()
}),
InvalidPublicFunctionReturnType: c.struct("InvalidPublicFunctionReturnType", {
idx: c.u16()
}),
InvalidTransferObject: null,
EffectsTooLarge: c.struct("EffectsTooLarge", { currentSize: c.u64(), maxSize: c.u64() }),
PublishUpgradeMissingDependency: null,
PublishUpgradeDependencyDowngrade: null,
PackageUpgradeError: c.struct("PackageUpgradeError", { upgradeError: Ka }),
WrittenObjectsTooLarge: c.struct("WrittenObjectsTooLarge", {
currentSize: c.u64(),
maxSize: c.u64()
}),
CertificateDenied: null,
SuiMoveVerificationTimedout: null,
SharedObjectOperationNotAllowed: null,
InputObjectDeleted: null,
ExecutionCancelledDueToSharedObjectCongestion: c.struct(
"ExecutionCancelledDueToSharedObjectCongestion",
{
congestedObjects: c.vector(C)
}
),
AddressDeniedForCoin: c.struct("AddressDeniedForCoin", {
address: C,
coinType: c.string()
}),
CoinTypeGlobalPause: c.struct("CoinTypeGlobalPause", { coinType: c.string() }),
ExecutionCancelledDueToRandomnessUnavailable: null
}), ls = c.enum("ExecutionStatus", {
Success: null,
Failed: c.struct("ExecutionFailed", {
error: Qa,
command: c.option(c.u64())
})
}), ds = c.struct("GasCostSummary", {
computationCost: c.u64(),
storageCost: c.u64(),
storageRebate: c.u64(),
nonRefundableStorageFee: c.u64()
}), Xa = c.struct("TransactionEffectsV1", {
status: ls,
executedEpoch: c.u64(),
gasUsed: ds,
modifiedAtVersions: c.vector(c.tuple([C, c.u64()])),
sharedObjects: c.vector(te),
transactionDigest: de,
created: c.vector(c.tuple([te, Be])),
mutated: c.vector(c.tuple([te, Be])),
unwrapped: c.vector(c.tuple([te, Be])),
deleted: c.vector(te),
unwrappedThenDeleted: c.vector(te),
wrapped: c.vector(te),
gasObject: c.tuple([