diff --git a/.eslintignore b/.eslintignore index 1420622..111858e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,5 @@ dist/ dts.config.js -rollup.config.js \ No newline at end of file +rollup.config.js +src/managers/coin/create-coin/utils/move-bytecode-template.js +src/managers/coin/create-coin/utils/template.ts \ No newline at end of file diff --git a/examples/coin/coin-address-validation.ts b/examples/coin/coin-address-validation.ts index 06a69fd..b6fd901 100644 --- a/examples/coin/coin-address-validation.ts +++ b/examples/coin/coin-address-validation.ts @@ -1,5 +1,5 @@ import { isValidTokenAddress } from "../../src/providers/utils/isValidTokenAddress"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/examples/coin/coin.ts b/examples/coin/coin.ts index 881f303..e3b7d4a 100644 --- a/examples/coin/coin.ts +++ b/examples/coin/coin.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/examples/coin/find-duplicates-by-coin-address.ts b/examples/coin/find-duplicates-by-coin-address.ts index 29d70a3..3260ccf 100644 --- a/examples/coin/find-duplicates-by-coin-address.ts +++ b/examples/coin/find-duplicates-by-coin-address.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/examples/coin/find-min-max-decimals-across-all-coins.ts b/examples/coin/find-min-max-decimals-across-all-coins.ts index a91e047..b09b2cf 100644 --- a/examples/coin/find-min-max-decimals-across-all-coins.ts +++ b/examples/coin/find-min-max-decimals-across-all-coins.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/examples/create-coin/create-coin.ts b/examples/create-coin/create-coin.ts index 05e7f05..bbc7a1f 100644 --- a/examples/create-coin/create-coin.ts +++ b/examples/create-coin/create-coin.ts @@ -1,5 +1,5 @@ import { keypair, provider, user } from "../common"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { CreateCoinTransactionParams } from "../../src"; // yarn ts-node examples/create-coin/create-coin.ts diff --git a/examples/create-pool/create-pool.ts b/examples/create-pool/create-pool.ts index c94428b..861f3ce 100644 --- a/examples/create-pool/create-pool.ts +++ b/examples/create-pool/create-pool.ts @@ -1,7 +1,7 @@ /* eslint-disable require-jsdoc */ import BigNumber from "bignumber.js"; import { createClient } from "redis"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { getLpCoinDecimals } from "../../src/providers/aftermath/create-pool-utils"; diff --git a/examples/router/multiple-use.ts b/examples/router/multiple-use.ts index bfa4d17..bb7665e 100644 --- a/examples/router/multiple-use.ts +++ b/examples/router/multiple-use.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { RouteManager } from "../../src/managers/RouteManager"; import { SHORT_SUI_COIN_TYPE } from "../../src/providers/common"; import { USDC_COIN_TYPE } from "../coin-types"; diff --git a/examples/router/router-dca.ts b/examples/router/router-dca.ts index 4acd2f0..bf0d1c1 100644 --- a/examples/router/router-dca.ts +++ b/examples/router/router-dca.ts @@ -1,5 +1,5 @@ import { DCAManagerSingleton, TurbosSingleton } from "../../src"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { RouteManager } from "../../src/managers/RouteManager"; import { LONG_SUI_COIN_TYPE } from "../../src/providers/common"; import { USDC_COIN_TYPE } from "../coin-types"; diff --git a/examples/router/router.ts b/examples/router/router.ts index c55f29f..10def1d 100644 --- a/examples/router/router.ts +++ b/examples/router/router.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { RouteManager } from "../../src/managers/RouteManager"; import { SHORT_SUI_COIN_TYPE } from "../../src/providers/common"; import { USDC_COIN_TYPE } from "../coin-types"; diff --git a/examples/wallet/wallet.ts b/examples/wallet/wallet.ts index 9fc830d..48828d7 100644 --- a/examples/wallet/wallet.ts +++ b/examples/wallet/wallet.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; import { clmmMainnet } from "../../src/providers/cetus/config"; diff --git a/examples/wallet/withdrawal.ts b/examples/wallet/withdrawal.ts index 7d0a0e2..fed172f 100644 --- a/examples/wallet/withdrawal.ts +++ b/examples/wallet/withdrawal.ts @@ -1,4 +1,4 @@ -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; import { clmmMainnet } from "../../src/providers/cetus/config"; diff --git a/package.json b/package.json index 1406437..33c6562 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "dependencies": { "@cetusprotocol/cetus-sui-clmm-sdk": "^3.17.8", "@flowx-pkg/ts-sdk": "^0.0.11", - "@mysten/sui.js": "^0.42.0", + "@mysten/sui.js": "yarn:@mysten/sui.js@^0.42.0", + "@mysten/sui.js-0.51.2": "yarn:@mysten/sui.js@^0.51.2", "@types/redis": "^4.0.11", "aftermath-ts-sdk": "^1.1.32", "bech32": "^2.0.0", diff --git a/src/index.ts b/src/index.ts index 030dfb9..924b7bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ // Managers -export * from "./managers/CoinManager"; +export * from "./managers/coin/CoinManager"; export * from "./managers/RouteManager"; export * from "./managers/WalletManager"; export * from "./managers/types"; diff --git a/src/managers/RouteManager.ts b/src/managers/RouteManager.ts index d73e501..c494e05 100644 --- a/src/managers/RouteManager.ts +++ b/src/managers/RouteManager.ts @@ -5,7 +5,7 @@ import { NoRoutesError } from "../errors/NoRoutesError"; import { CetusSingleton } from "../providers/cetus/cetus"; import { SUI_DENOMINATOR, SWAP_GAS_BUDGET } from "../providers/common"; import { isSuiCoinType } from "../providers/utils/isSuiCoinType"; -import { CoinManagerSingleton } from "./CoinManager"; +import { CoinManagerSingleton } from "./coin/CoinManager"; import { BestRouteData, IRouteManager, Provider, Providers, ProvidersToRouteDataMap } from "./types"; import { getFiltredProviders, getRouterMaps, tokenFromIsTokenTo } from "./utils"; import { TryCatchWrapperResult } from "../providers/types"; diff --git a/src/managers/WalletManager.ts b/src/managers/WalletManager.ts index d882717..109f7ce 100644 --- a/src/managers/WalletManager.ts +++ b/src/managers/WalletManager.ts @@ -11,7 +11,7 @@ import { TransactionBlock } from "@mysten/sui.js/transactions"; import { SUI_DECIMALS } from "@mysten/sui.js/utils"; import BigNumber from "bignumber.js"; import { SUI_DENOMINATOR, SWAP_GAS_BUDGET } from "../providers/common"; -import { CoinManagerSingleton } from "./CoinManager"; +import { CoinManagerSingleton } from "./coin/CoinManager"; import { CoinAssetData, IWalletManager } from "./types"; import { getCoinsAssetsFromCoinObjects, normalizeMnemonic } from "./utils"; import { bech32 } from "bech32"; diff --git a/src/managers/CoinManager.ts b/src/managers/coin/CoinManager.ts similarity index 81% rename from src/managers/CoinManager.ts rename to src/managers/coin/CoinManager.ts index 1576cfa..c2396da 100644 --- a/src/managers/CoinManager.ts +++ b/src/managers/coin/CoinManager.ts @@ -1,16 +1,10 @@ import { CoinMetadata, SuiClient } from "@mysten/sui.js/client"; -import { LONG_SUI_COIN_TYPE, SHORT_SUI_COIN_TYPE } from "../providers/common"; -import { - CommonCoinData, - CreateCoinExternalApiResType, - CreateCoinTransactionParams, - ICoinManager, - Providers, - UpdatedCoinsCache, -} from "./types"; import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { isValidResForCreateCoin } from "./utils"; -import BigNumber from "bignumber.js"; +import { normalizeSuiAddress } from "@mysten/sui.js/utils"; +import { LONG_SUI_COIN_TYPE, SHORT_SUI_COIN_TYPE } from "../../providers/common"; +import { CommonCoinData, CreateCoinTransactionParams, ICoinManager, Providers, UpdatedCoinsCache } from "../types"; +import initMoveByteCodeTemplate from "./create-coin/utils/move-bytecode-template"; +import { getBytecode } from "./create-coin/utils/template"; /** * @class CoinManagerSingleton @@ -22,13 +16,7 @@ export class CoinManagerSingleton implements ICoinManager { private allCoinsCache: Map = new Map(); private coinsByProviderNameCache: Map> = new Map(); private provider: SuiClient; - private static COIN_CREATION_API_URL = "https://www.api.interestprotocol.com/api/v1/token/makeToken"; - private static COIN_CREATION_HEADERS = { - "Content-Type": "application/json", - Host: "www.api.interestprotocol.com", - Origin: "https://www.suicoins.com", - Referer: "https://www.suicoins.com/", - }; + private static COIN_CREATION_BYTECODE_TEMPLATE_URL = "https://www.suicoins.com/move_bytecode_template_bg.wasm"; /** * Constructs a new instance of the SuiProvider class with the provided SUI provider URL. @@ -245,47 +233,34 @@ export class CoinManagerSingleton implements ICoinManager { transaction, }: CreateCoinTransactionParams): Promise { const tx = transaction ?? new TransactionBlock(); - let txData: CreateCoinExternalApiResType; - - // convert mint amount to string respecting provided decimals - const mintAmountRespectingDecimals = new BigNumber(mintAmount) - .multipliedBy(new BigNumber(10).pow(decimals)) - .toString(); try { - const result = await fetch(this.COIN_CREATION_API_URL, { - method: "POST", - headers: this.COIN_CREATION_HEADERS, - body: JSON.stringify({ - name, - symbol, - decimals, - fixedSupply, - mintAmount: mintAmountRespectingDecimals, - url, - description, - }), + await initMoveByteCodeTemplate(CoinManagerSingleton.COIN_CREATION_BYTECODE_TEMPLATE_URL); + + const [upgradeCap] = tx.publish({ + modules: [ + [ + ...getBytecode({ + name, + symbol, + totalSupply: mintAmount, + description, + fixedSupply, + decimals: +decimals, + imageUrl: url, + recipient: signerAddress, + }), + ], + ], + dependencies: [normalizeSuiAddress("0x1"), normalizeSuiAddress("0x2")], }); - if (!result.ok) { - throw new Error(`[CoinManager.getCreateCoinTransaction] API request failed with status: ${result.status}`); - } - - const data: CreateCoinExternalApiResType = await result.json(); + tx.transferObjects([upgradeCap], tx.pure(signerAddress)); - if (isValidResForCreateCoin(data)) { - txData = data; - } else { - throw new Error("[CoinManager.getCreateCoinTransaction] Invalid API response structure"); - } + return tx; } catch (error) { console.error("[CoinManager.getCreateCoinTransaction] error: ", error); throw error; } - - const [upgradeCap] = tx.publish({ modules: txData.modules, dependencies: txData.dependencies }); - tx.transferObjects([upgradeCap], tx.pure(signerAddress)); - - return tx; } } diff --git a/src/managers/coin/create-coin/utils/create-token.types.ts b/src/managers/coin/create-coin/utils/create-token.types.ts new file mode 100644 index 0000000..25f3714 --- /dev/null +++ b/src/managers/coin/create-coin/utils/create-token.types.ts @@ -0,0 +1,11 @@ +// This file is partially copied from https://github.com/interest-protocol/sui-coins. + +export interface ICreateTokenForm { + name: string; + symbol: string; + totalSupply: string; + decimals?: number | undefined; + imageUrl?: string | undefined; + description: string; + fixedSupply: NonNullable; +} diff --git a/src/managers/coin/create-coin/utils/move-bytecode-template.js b/src/managers/coin/create-coin/utils/move-bytecode-template.js new file mode 100644 index 0000000..10d8abb --- /dev/null +++ b/src/managers/coin/create-coin/utils/move-bytecode-template.js @@ -0,0 +1,755 @@ +// This file is totally copied from https://github.com/interest-protocol/sui-coins. + +let wasm; + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { + return heap[idx]; +} + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +let WASM_VECTOR_LEN = 0; + +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +const cachedTextEncoder = + typeof TextEncoder !== "undefined" + ? new TextEncoder("utf-8") + : { + encode: () => { + throw Error("TextEncoder not available"); + }, + }; + +const encodeString = + typeof cachedTextEncoder.encodeInto === "function" + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); + } + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length, + }; + }; + +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0() + .subarray(ptr, ptr + buf.length) + .set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7f) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +const cachedTextDecoder = + typeof TextDecoder !== "undefined" + ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) + : { + decode: () => { + throw Error("TextDecoder not available"); + }, + }; + +if (typeof TextDecoder !== "undefined") { + cachedTextDecoder.decode(); +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +let cachedFloat64Memory0 = null; + +function getFloat64Memory0() { + if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { + cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); + } + return cachedFloat64Memory0; +} + +let cachedBigInt64Memory0 = null; + +function getBigInt64Memory0() { + if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) { + cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer); + } + return cachedBigInt64Memory0; +} + +function debugString(val) { + // primitive types + const type = typeof val; + if (type == "number" || type == "boolean" || val == null) { + return `${val}`; + } + if (type == "string") { + return `"${val}"`; + } + if (type == "symbol") { + const description = val.description; + if (description == null) { + return "Symbol"; + } else { + return `Symbol(${description})`; + } + } + if (type == "function") { + const name = val.name; + if (typeof name == "string" && name.length > 0) { + return `Function(${name})`; + } else { + return "Function"; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = "["; + if (length > 0) { + debug += debugString(val[0]); + } + for (let i = 1; i < length; i++) { + debug += ", " + debugString(val[i]); + } + debug += "]"; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + // Failed to match the standard '[object ClassName]' + return toString.call(val); + } + if (className == "Object") { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return "Object(" + JSON.stringify(val) + ")"; + } catch (_) { + return "Object"; + } + } + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; + } + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; +} +/** + * Get the version of the crate (useful for testing the package). + * @returns {string} + */ +export function version() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.version(retptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8Memory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** + * Deserialize the `Uint8Array`` bytecode into a JSON object. + * + * ```javascript + * import * as template from '@mysten/move-binary-template'; + * + * const json = template.deserialize( binary ); + * console.log( json, json.identifiers ); + * ``` + * @param {Uint8Array} binary + * @returns {any} + */ +export function deserialize(binary) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(binary, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.deserialize(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); +} +/** + * Update the identifiers in the module bytecode, given a map of old -> new identifiers. + * Returns the updated bytecode. + * + * ```javascript + * import * as template from '@mysten/move-binary-template'; + * + * const updated = template.update_identifiers( binary, { + * 'TEMPLATE': 'NEW_VALUE', + * 'template': 'new_value', + * 'Name': 'NewName' + * }); + * ``` + * @param {Uint8Array} binary + * @param {any} map + * @returns {Uint8Array} + */ +export function update_identifiers(binary, map) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(binary, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.update_identifiers(retptr, ptr0, len0, addHeapObject(map)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v2 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1); + return v2; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * Updates a constant in the constant pool. Because constants don't have names, + * the only way to identify them is by their type and value. + * + * The value of a constant is BCS-encoded and the type is a string representation + * of the `SignatureToken` enum. String identifier for `SignatureToken` is a + * capitalized version of the type: U8, Address, Vector(Bool), Vector(U8), etc. + * + * ```javascript + * import * as template from '@mysten/move-binary-template'; + * import { bcs } from '@mysten/bcs'; + * + * let binary = template.update_constants( + * binary, // Uint8Array + * bcs.u64().serialize(0).toBytes(), // new value + * bcs.u64().serialize(100000).toBytes(), // old value + * 'U64' // type + * ); + * ``` + * @param {Uint8Array} binary + * @param {Uint8Array} new_value + * @param {Uint8Array} expected_value + * @param {string} expected_type + * @returns {Uint8Array} + */ +export function update_constants(binary, new_value, expected_value, expected_type) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(binary, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passArray8ToWasm0(new_value, wasm.__wbindgen_malloc); + const len1 = WASM_VECTOR_LEN; + const ptr2 = passArray8ToWasm0(expected_value, wasm.__wbindgen_malloc); + const len2 = WASM_VECTOR_LEN; + const ptr3 = passStringToWasm0(expected_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len3 = WASM_VECTOR_LEN; + wasm.update_constants(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v5 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1); + return v5; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * Convenience method to analyze the constant pool; returns all constants in order + * with their type and BCS value. + * + * ```javascript + * import * as template from '@mysten/move-binary-template'; + * + * let consts = template.get_constants(binary); + * ``` + * @param {Uint8Array} binary + * @returns {any} + */ +export function get_constants(binary) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(binary, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.get_constants(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** + * Serialize the JSON module into a `Uint8Array` (bytecode). + * @param {any} json_module + * @returns {Uint8Array} + */ +export function serialize(json_module) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.serialize(retptr, addHeapObject(json_module)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } +} +/** + * A transformed constant from the constant pool. + */ +export class Constant { + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_constant_free(ptr); + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === "function" && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === "function") { + try { + return await WebAssembly.instantiateStreaming(module, imports); + } catch (e) { + if (module.headers.get("Content-Type") != "application/wasm") { + console.warn( + "`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", + e, + ); + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_object_drop_ref = function (arg0) { + takeObject(arg0); + }; + imports.wbg.__wbindgen_string_get = function (arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "string" ? obj : undefined; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbindgen_is_bigint = function (arg0) { + const ret = typeof getObject(arg0) === "bigint"; + return ret; + }; + imports.wbg.__wbindgen_bigint_from_u64 = function (arg0) { + const ret = BigInt.asUintN(64, arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_jsval_eq = function (arg0, arg1) { + const ret = getObject(arg0) === getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_error_new = function (arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_boolean_get = function (arg0) { + const v = getObject(arg0); + const ret = typeof v === "boolean" ? (v ? 1 : 0) : 2; + return ret; + }; + imports.wbg.__wbindgen_is_string = function (arg0) { + const ret = typeof getObject(arg0) === "string"; + return ret; + }; + imports.wbg.__wbindgen_is_object = function (arg0) { + const val = getObject(arg0); + const ret = typeof val === "object" && val !== null; + return ret; + }; + imports.wbg.__wbindgen_is_undefined = function (arg0) { + const ret = getObject(arg0) === undefined; + return ret; + }; + imports.wbg.__wbindgen_in = function (arg0, arg1) { + const ret = getObject(arg0) in getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_shr = function (arg0, arg1) { + const ret = getObject(arg0) >> getObject(arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_object_clone_ref = function (arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_jsval_loose_eq = function (arg0, arg1) { + const ret = getObject(arg0) == getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_number_get = function (arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "number" ? obj : undefined; + getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; + getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); + }; + imports.wbg.__wbg_String_88810dfeb4021902 = function (arg0, arg1) { + const ret = String(getObject(arg1)); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbindgen_number_new = function (arg0) { + const ret = arg0; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_bigint_from_u128 = function (arg0, arg1) { + const ret = (BigInt.asUintN(64, arg0) << BigInt(64)) | BigInt.asUintN(64, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_string_new = function (arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getwithrefkey_5e6d9547403deab8 = function (arg0, arg1) { + const ret = getObject(arg0)[getObject(arg1)]; + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_841ac57cff3d672b = function (arg0, arg1, arg2) { + getObject(arg0)[takeObject(arg1)] = takeObject(arg2); + }; + imports.wbg.__wbindgen_is_function = function (arg0) { + const ret = typeof getObject(arg0) === "function"; + return ret; + }; + imports.wbg.__wbg_get_44be0491f933a435 = function (arg0, arg1) { + const ret = getObject(arg0)[arg1 >>> 0]; + return addHeapObject(ret); + }; + imports.wbg.__wbg_length_fff51ee6522a1a18 = function (arg0) { + const ret = getObject(arg0).length; + return ret; + }; + imports.wbg.__wbg_new_898a68150f225f2e = function () { + const ret = new Array(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_next_526fc47e980da008 = function (arg0) { + const ret = getObject(arg0).next; + return addHeapObject(ret); + }; + imports.wbg.__wbg_next_ddb3312ca1c4e32a = function () { + return handleError(function (arg0) { + const ret = getObject(arg0).next(); + return addHeapObject(ret); + }, arguments); + }; + imports.wbg.__wbg_done_5c1f01fb660d73b5 = function (arg0) { + const ret = getObject(arg0).done; + return ret; + }; + imports.wbg.__wbg_value_1695675138684bd5 = function (arg0) { + const ret = getObject(arg0).value; + return addHeapObject(ret); + }; + imports.wbg.__wbg_iterator_97f0c81209c6c35a = function () { + const ret = Symbol.iterator; + return addHeapObject(ret); + }; + imports.wbg.__wbg_get_97b561fb56f034b5 = function () { + return handleError(function (arg0, arg1) { + const ret = Reflect.get(getObject(arg0), getObject(arg1)); + return addHeapObject(ret); + }, arguments); + }; + imports.wbg.__wbg_call_cb65541d95d71282 = function () { + return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments); + }; + imports.wbg.__wbg_new_b51585de1b234aff = function () { + const ret = new Object(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_502d29070ea18557 = function (arg0, arg1, arg2) { + getObject(arg0)[arg1 >>> 0] = takeObject(arg2); + }; + imports.wbg.__wbg_isArray_4c24b343cb13cfb1 = function (arg0) { + const ret = Array.isArray(getObject(arg0)); + return ret; + }; + imports.wbg.__wbg_instanceof_ArrayBuffer_39ac22089b74fddb = function (arg0) { + let result; + try { + result = getObject(arg0) instanceof ArrayBuffer; + } catch { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_isSafeInteger_bb8e18dd21c97288 = function (arg0) { + const ret = Number.isSafeInteger(getObject(arg0)); + return ret; + }; + imports.wbg.__wbg_entries_e51f29c7bba0c054 = function (arg0) { + const ret = Object.entries(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_buffer_085ec1f694018c4f = function (arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_8125e318e6245eed = function (arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_5cf90238115182c3 = function (arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbg_length_72e2208bbc0efc61 = function (arg0) { + const ret = getObject(arg0).length; + return ret; + }; + imports.wbg.__wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4 = function (arg0) { + let result; + try { + result = getObject(arg0) instanceof Uint8Array; + } catch { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbindgen_bigint_get_as_i64 = function (arg0, arg1) { + const v = getObject(arg1); + const ret = typeof v === "bigint" ? v : undefined; + getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret; + getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); + }; + imports.wbg.__wbindgen_debug_string = function (arg0, arg1) { + const ret = debugString(getObject(arg1)); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbindgen_throw = function (arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_memory = function () { + const ret = wasm.memory; + return addHeapObject(ret); + }; + + return imports; +} + +function __wbg_init_memory(imports, maybe_memory) {} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedBigInt64Memory0 = null; + cachedFloat64Memory0 = null; + cachedInt32Memory0 = null; + cachedUint8Memory0 = null; + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(input) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + if ( + typeof input === "string" || + (typeof Request === "function" && input instanceof Request) || + (typeof URL === "function" && input instanceof URL) + ) { + input = fetch(input); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await input, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync }; +export default __wbg_init; diff --git a/src/managers/coin/create-coin/utils/template.ts b/src/managers/coin/create-coin/utils/template.ts new file mode 100644 index 0000000..368c0b6 --- /dev/null +++ b/src/managers/coin/create-coin/utils/template.ts @@ -0,0 +1,111 @@ +// This file is totally copied from https://github.com/interest-protocol/sui-coins. + +import { bcs } from "@mysten/sui.js-0.51.2/bcs"; +import { fromHEX, normalizeSuiAddress, toHEX } from "@mysten/sui.js-0.51.2/utils"; +import BigNumber from "bignumber.js"; + +import { ICreateTokenForm } from "./create-token.types"; + +import * as template from "./move-bytecode-template"; + +const getCoinTemplateByteCode = () => + "a11ceb0b060000000a01000c020c1e032a2d04570a05616307c401e70108ab0360068b04570ae204050ce704360007010d02060212021302140000020001020701000002010c01000102030c0100010404020005050700000a000100011105060100020808090102020b0c010100030e0501010c030f0e01010c04100a0b00050c030400010402070307050d040f02080007080400020b020108000b03010800010a02010805010900010b01010900010800070900020a020a020a020b01010805070804020b030109000b0201090001060804010504070b030109000305070804010b0301080002090005010b020108000d434f494e5f54454d504c4154450c436f696e4d65746164617461064f7074696f6e0b5472656173757279436170095478436f6e746578740355726c04636f696e0d636f696e5f74656d706c6174650f6372656174655f63757272656e63790b64756d6d795f6669656c6404696e6974116d696e745f616e645f7472616e73666572156e65775f756e736166655f66726f6d5f6279746573066f7074696f6e137075626c69635f73686172655f6f626a6563740f7075626c69635f7472616e736665720673656e64657204736f6d65087472616e736665720a74785f636f6e746578740375726c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020201090a02070653594d424f4c0a0205044e414d450a020c0b4445534352495054494f4e0a02040375726c030800000000000000000520000000000000000000000000000000000000000000000000000000000000000000020109010000000002190b0007000701070207030704110738000a0138010c020c030d0307050a012e11060b0138020b03070638030b0238040200"; + +const getCoinTemplateSameNameAndSymbolByteCode = () => + "a11ceb0b060000000a01000c020c1e032a2d04570a05616307c401e70108ab0360068b044f0ada04050cdf04360007010d02060212021302140000020001020701000002010c01000102030c0100010404020005050700000a000100011105060100020808090102020b0c010100030e0501010c030f0e01010c04100a0b00050c030400010402070307050d040f02080007080400020b020108000b03010800010a02010805010900010b01010900010800070900020a020a020a020b01010805070804020b030109000b0201090001060804010504070b030109000305070804010b0301080002090005010b020108000d434f494e5f54454d504c4154450c436f696e4d65746164617461064f7074696f6e0b5472656173757279436170095478436f6e746578740355726c04636f696e0d636f696e5f74656d706c6174650f6372656174655f63757272656e63790b64756d6d795f6669656c6404696e6974116d696e745f616e645f7472616e73666572156e65775f756e736166655f66726f6d5f6279746573066f7074696f6e137075626c69635f73686172655f6f626a6563740f7075626c69635f7472616e736665720673656e64657204736f6d65087472616e736665720a74785f636f6e746578740375726c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020201090a02070653594d424f4c0a020c0b4445534352495054494f4e0a02040375726c030800000000000000000520000000000000000000000000000000000000000000000000000000000000000000020109010000000002190b0007000701070107020703110738000a0138010c020c030d0307040a012e11060b0138020b03070538030b0238040200"; + +const Address = bcs.bytes(32).transform({ + // To change the input type, you need to provide a type definition for the input + input: (val: string) => fromHEX(val), + output: (val) => toHEX(val), +}); + +const updateDecimals = (modifiedByteCode: Uint8Array, decimals: number = 9) => + template.update_constants( + modifiedByteCode, + bcs.u8().serialize(decimals).toBytes(), + bcs.u8().serialize(9).toBytes(), + "U8", + ); + +const updateSymbol = (modifiedByteCode: Uint8Array, symbol: string) => + template.update_constants( + modifiedByteCode, + bcs.string().serialize(symbol.trim()).toBytes(), + bcs.string().serialize("SYMBOL").toBytes(), + "Vector(U8)", + ); + +const updateName = (modifiedByteCode: Uint8Array, name: string) => { + return template.update_constants( + modifiedByteCode, + bcs.string().serialize(name.trim()).toBytes(), + bcs.string().serialize("NAME").toBytes(), + "Vector(U8)", + ); +}; + +const updateDescription = (modifiedByteCode: Uint8Array, description: string) => + template.update_constants( + modifiedByteCode, + bcs.string().serialize(description.trim()).toBytes(), + bcs.string().serialize("DESCRIPTION").toBytes(), + "Vector(U8)", + ); + +const updateUrl = (modifiedByteCode: Uint8Array, url: string) => + template.update_constants( + modifiedByteCode, + bcs.string().serialize(url).toBytes(), + bcs.string().serialize("url").toBytes(), + "Vector(U8)", + ); + +const updateMintAmount = (modifiedByteCode: Uint8Array, supply: BigNumber) => + template.update_constants( + modifiedByteCode, + bcs.u64().serialize(supply.toString()).toBytes(), + bcs.u64().serialize(0).toBytes(), + "U64", + ); + +const updateTreasuryCapRecipient = (modifiedByteCode: Uint8Array, recipient: string) => + template.update_constants( + modifiedByteCode, + Address.serialize(recipient).toBytes(), + Address.serialize(normalizeSuiAddress("0x0")).toBytes(), + "Address", + ); + +export const getBytecode = (info: ICreateTokenForm & { recipient: string }) => { + const isSameNameAndSymbol = info.symbol === info.name; + const templateByteCode = fromHEX( + isSameNameAndSymbol ? getCoinTemplateSameNameAndSymbolByteCode() : getCoinTemplateByteCode(), + ); + + const modifiedByteCode = template.update_identifiers(templateByteCode, { + COIN_TEMPLATE: info.symbol.toUpperCase().replaceAll(" ", "_"), + coin_template: info.symbol.toLowerCase().replaceAll(" ", "_"), + }); + + let updated = updateDecimals(modifiedByteCode, info.decimals); + if (isSameNameAndSymbol) { + updated = updateSymbol(updated, info.symbol); + } else { + updated = updateSymbol(updated, info.symbol); + updated = updateName(updated, info.name); + } + + updated = updateSymbol(updated, info.symbol); + updated = updateName(updated, info.name); + + updated = updateDescription(updated, info.description ?? ""); + updated = updateUrl(updated, info.imageUrl ?? ""); + + const supply = BigNumber(info.totalSupply).times(BigNumber(10).pow(info.decimals || 9)); + + updated = updateMintAmount(updated, supply); + updated = updateTreasuryCapRecipient(updated, info.fixedSupply ? normalizeSuiAddress("0x0") : info.recipient); + + return updated; +}; diff --git a/src/managers/utils.ts b/src/managers/utils.ts index bda1b92..31bfe7d 100644 --- a/src/managers/utils.ts +++ b/src/managers/utils.ts @@ -13,7 +13,7 @@ import { LONG_SUI_COIN_TYPE, SHORT_SUI_COIN_TYPE } from "../providers/common"; import { CommonPoolData } from "../providers/types"; import { hasPath } from "../providers/utils/hasPath"; import { tryCatchWrapper } from "../providers/utils/tryCatchWrapper"; -import { CoinManagerSingleton } from "./CoinManager"; +import { CoinManagerSingleton } from "./coin/CoinManager"; import { WalletManagerSingleton } from "./WalletManager"; export const getFiltredProviders = ({ diff --git a/src/providers/aftermath/aftermath.ts b/src/providers/aftermath/aftermath.ts index 542af45..54c8b20 100644 --- a/src/providers/aftermath/aftermath.ts +++ b/src/providers/aftermath/aftermath.ts @@ -4,7 +4,7 @@ import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Aftermath, CoinMetadaWithInfo, Pool, RouterCompleteTradeRoute } from "aftermath-ts-sdk"; import BigNumber from "bignumber.js"; import { EventEmitter } from "../../emitters/EventEmitter"; -import { CoinManagerSingleton } from "../../managers/CoinManager"; +import { CoinManagerSingleton } from "../../managers/coin/CoinManager"; import { CoinAssetData, CommonCoinData, UpdatedCoinsCache } from "../../managers/types"; import { InMemoryStorageSingleton } from "../../storages/InMemoryStorage"; import { Storage } from "../../storages/types"; diff --git a/src/providers/aftermath/utils.ts b/src/providers/aftermath/utils.ts index c63d9b7..98a910f 100644 --- a/src/providers/aftermath/utils.ts +++ b/src/providers/aftermath/utils.ts @@ -3,7 +3,7 @@ import { CoinMetadata } from "@mysten/sui.js/client"; import { CoinMetadaWithInfo, Pool, PoolCoin, PoolCoins, PoolObject, PoolStats, SuiNetwork } from "aftermath-ts-sdk"; import BigNumber from "bignumber.js"; -import { CoinManagerSingleton } from "../../managers/CoinManager"; +import { CoinManagerSingleton } from "../../managers/coin/CoinManager"; import { CommonPoolData } from "../types"; import { OwnedPoolCoinInfo, OwnedPoolInfo } from "./types"; diff --git a/src/providers/cetus/cetus.ts b/src/providers/cetus/cetus.ts index d08e8e7..fdc519c 100644 --- a/src/providers/cetus/cetus.ts +++ b/src/providers/cetus/cetus.ts @@ -17,7 +17,7 @@ import BigNumber from "bignumber.js"; import BN from "bn.js"; import { EventEmitter } from "../../emitters/EventEmitter"; import { NoRoutesError } from "../../errors/NoRoutesError"; -import { CoinManagerSingleton } from "../../managers/CoinManager"; +import { CoinManagerSingleton } from "../../managers/coin/CoinManager"; import { CommonCoinData, ProvidersToRouteDataMap, UpdatedCoinsCache } from "../../managers/types"; import { InMemoryStorageSingleton } from "../../storages/InMemoryStorage"; import { Storage } from "../../storages/types"; diff --git a/src/providers/turbos/turbos.ts b/src/providers/turbos/turbos.ts index ac5597d..abb2e1e 100644 --- a/src/providers/turbos/turbos.ts +++ b/src/providers/turbos/turbos.ts @@ -3,7 +3,7 @@ import { TransactionBlock } from "@mysten/sui.js/transactions"; import BigNumber from "bignumber.js"; import { Contract, Network, TurbosSdk } from "turbos-clmm-sdk"; import { EventEmitter } from "../../emitters/EventEmitter"; -import { CoinManagerSingleton } from "../../managers/CoinManager"; +import { CoinManagerSingleton } from "../../managers/coin/CoinManager"; import { swapDoctored } from "../../managers/dca/adapterUtils/turbosUtils"; import { buildDcaTxBlock } from "../../managers/dca/adapters/turbosAdapter"; import { CommonCoinData, UpdatedCoinsCache } from "../../managers/types"; diff --git a/src/providers/turbos/utils.ts b/src/providers/turbos/utils.ts index 50b74c1..129519b 100644 --- a/src/providers/turbos/utils.ts +++ b/src/providers/turbos/utils.ts @@ -1,5 +1,5 @@ import BigNumber from "bignumber.js"; -import { CoinManagerSingleton } from "../../managers/CoinManager"; +import { CoinManagerSingleton } from "../../managers/coin/CoinManager"; import { CommonCoinData } from "../../managers/types"; import { LONG_SUI_COIN_TYPE, SHORT_SUI_COIN_TYPE } from "../common"; import { CoinsCache, CommonPoolData, PathsCache } from "../types"; diff --git a/tests/managers/coinLazyLoading.test.ts b/tests/managers/coinLazyLoading.test.ts index 6555d6b..af7a97f 100644 --- a/tests/managers/coinLazyLoading.test.ts +++ b/tests/managers/coinLazyLoading.test.ts @@ -1,5 +1,5 @@ import { cacheOptions, suiProviderUrl } from "../constants"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Provider, Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/tests/managers/coinNoLazyLoading.test.ts b/tests/managers/coinNoLazyLoading.test.ts index faa9c81..be4f295 100644 --- a/tests/managers/coinNoLazyLoading.test.ts +++ b/tests/managers/coinNoLazyLoading.test.ts @@ -1,5 +1,5 @@ import { cacheOptions, suiProviderUrl } from "../constants"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Provider, Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/tests/managers/routeManager.test.ts b/tests/managers/routeManager.test.ts index d0ad97a..1e3b2ed 100644 --- a/tests/managers/routeManager.test.ts +++ b/tests/managers/routeManager.test.ts @@ -1,7 +1,7 @@ import { TransactionBlock } from "@mysten/sui.js/transactions"; import { cacheOptions, suiProviderUrl, publicKey } from "../constants"; import { RouteManager } from "../../src/managers/RouteManager"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; import { CetusSingleton } from "../../src/providers/cetus/cetus"; diff --git a/tests/managers/walletManager.test.ts b/tests/managers/walletManager.test.ts index a6c0173..0bcb53a 100644 --- a/tests/managers/walletManager.test.ts +++ b/tests/managers/walletManager.test.ts @@ -2,7 +2,7 @@ import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; import { TransactionBlock } from "@mysten/sui.js/transactions"; import { cacheOptions, provider, suiProviderUrl, publicKey } from "../constants"; import { isValidTokenAddress } from "../../src"; -import { CoinManagerSingleton } from "../../src/managers/CoinManager"; +import { CoinManagerSingleton } from "../../src/managers/coin/CoinManager"; import { WalletManagerSingleton } from "../../src/managers/WalletManager"; import { CoinAssetData, Providers } from "../../src/managers/types"; import { AftermathSingleton } from "../../src/providers/aftermath/aftermath"; diff --git a/tsconfig.json b/tsconfig.json index 1d10117..94d07ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,11 +6,12 @@ "sourceMap": true, "removeComments": false, "strict": true, - "target": "ES2020", + "target": "ES2021", "esModuleInterop": true, "skipLibCheck": true, "moduleResolution": "Bundler", "resolveJsonModule": true, + "allowJs": true, }, "compileOnSave": true, "include": ["src", ".eslintrc.js", "examples", "tests", "jest.config.js"], diff --git a/yarn.lock b/yarn.lock index 6e0a0f5..da91811 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,20 @@ # yarn lockfile v1 +"@0no-co/graphql.web@^1.0.5": + version "1.0.7" + resolved "https://registry.yarnpkg.com/@0no-co/graphql.web/-/graphql.web-1.0.7.tgz#c7a762c887b3482a79ffa68f63de5e96059a62e4" + integrity sha512-E3Qku4mTzdrlwVWGPxklDnME5ANrEGetvYw4i2GCRlppWXXE4QD66j7pwb8HelZwS6LnqEChhrSOGCXpbiu6MQ== + +"@0no-co/graphqlsp@^1.10.0": + version "1.10.1" + resolved "https://registry.yarnpkg.com/@0no-co/graphqlsp/-/graphqlsp-1.10.1.tgz#4c9f9b927434c0b1b027d2e6e881ac26d6efe40e" + integrity sha512-IFRxxCHIFW8erFDoXYGUnNvI4okn4c7i4AAW0LEDRyrVQb9IhuxxW1kmBKMhXenuPP9aGroNDYgYJzeuR0wEYg== + dependencies: + "@gql.tada/internal" "^0.1.2" + graphql "^16.8.1" + node-fetch "^2.0.0" + "@aashutoshrathi/word-wrap@^1.2.3": version "1.2.6" resolved "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" @@ -508,6 +522,30 @@ resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6" integrity sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw== +"@gql.tada/cli-utils@1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@gql.tada/cli-utils/-/cli-utils-1.0.3.tgz#e29d2ff2389ab068da48e5a0619a4f09cab7000f" + integrity sha512-oB93rsOK4xWu46jpUpZ9Q7AR5VDYWIYtNFGM+drtUQiRzD/wPhmnMLZI1eQWC1vamJDjOSj16taPJEL2m0qLeg== + dependencies: + "@0no-co/graphqlsp" "^1.10.0" + "@gql.tada/internal" "0.2.1" + graphql "^16.8.1" + ts-morph "~22.0.0" + +"@gql.tada/internal@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@gql.tada/internal/-/internal-0.2.1.tgz#24dfec6a327ae6d51a82c6da6ead96dbf6fd7a24" + integrity sha512-Nn+vcvIOUliUFaQwl+URNvqBnWd1MuDjvQo63Hy8+DkV3rbRSa0OCVXIR55EQRpIT7ZmPMzYyMQ2Bmj9Mk37vQ== + dependencies: + "@0no-co/graphql.web" "^1.0.5" + +"@gql.tada/internal@^0.1.2": + version "0.1.3" + resolved "https://registry.yarnpkg.com/@gql.tada/internal/-/internal-0.1.3.tgz#c39a124c18c7d4213c29751edcb89cbbbfb7e521" + integrity sha512-wIvykBId7O0gaizmSl5n5AhbQsgJVLTUsFBm3RsfQ9dVfpmT+Fhy2yHX+yNgiVECg2EimXMhs4ltcE4EuZ2WOA== + dependencies: + "@0no-co/graphql.web" "^1.0.5" + "@graphql-typed-document-node/core@^3.2.0": version "3.2.0" resolved "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861" @@ -805,6 +843,13 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@mysten/bcs@0.11.1": + version "0.11.1" + resolved "https://registry.yarnpkg.com/@mysten/bcs/-/bcs-0.11.1.tgz#0cc0b0f5960f60cfe5cf6a8c229affa59cd09b1b" + integrity sha512-xP85isNSYUCHd3O/g+TmZYmg4wK6cU8q/n/MebkIGP4CYVJZz2wU/G24xIZ3wI+0iTop4dfgA5kYrg/DQKCUzA== + dependencies: + bs58 "^5.0.0" + "@mysten/bcs@0.7.3": version "0.7.3" resolved "https://registry.npmjs.org/@mysten/bcs/-/bcs-0.7.3.tgz#b2e4558a8feb9fd3a0dc2ff4e94c37e1f8a7c7e5" @@ -826,6 +871,24 @@ dependencies: bs58 "^5.0.0" +"@mysten/sui.js-0.51.2@yarn:@mysten/sui.js@^0.51.2": + version "0.51.2" + resolved "https://registry.yarnpkg.com/@mysten/sui.js/-/sui.js-0.51.2.tgz#40c54bf1df57fdeaf27ad11efddeaa20ff5e6a7b" + integrity sha512-RRG/VHhVvkQlWqodFZagRxVDo3SbXh4e3xTBplhPNNyybugbWj/V+wGrNv5/KtxfVxHBw6jTCoB798ijqPBq7g== + dependencies: + "@graphql-typed-document-node/core" "^3.2.0" + "@mysten/bcs" "0.11.1" + "@noble/curves" "^1.1.0" + "@noble/hashes" "^1.3.1" + "@scure/bip32" "^1.3.1" + "@scure/bip39" "^1.2.1" + "@suchipi/femver" "^1.0.0" + bech32 "^2.0.0" + gql.tada "^1.4.1" + graphql "^16.8.1" + superstruct "^1.0.3" + tweetnacl "^1.0.3" + "@mysten/sui.js@0.41.2", "@mysten/sui.js@^0.35.1": version "0.41.2" resolved "https://registry.npmjs.org/@mysten/sui.js/-/sui.js-0.41.2.tgz#0ef09ce8777f254c1a25f4108fb55c4755a60943" @@ -842,7 +905,7 @@ superstruct "^1.0.3" tweetnacl "^1.0.3" -"@mysten/sui.js@0.42.0", "@mysten/sui.js@^0.42.0", "@mysten/sui.js@^0.45.1": +"@mysten/sui.js@0.42.0", "@mysten/sui.js@^0.45.1": version "0.42.0" resolved "https://registry.npmjs.org/@mysten/sui.js/-/sui.js-0.42.0.tgz#db57ad931aa7683fe1526cb4b308425234e1eecf" integrity sha512-khYpfrWTRNk7WTuDWJx/KCbleqY1B40gVRt1DttqlNkD2lvg134xZn7F/r94jxgnUETbK+hVoQvBY7F36MsfRw== @@ -904,6 +967,22 @@ superstruct "^1.0.3" tweetnacl "^1.0.3" +"@mysten/sui.js@yarn:@mysten/sui.js@^0.42.0": + version "0.42.0" + resolved "https://registry.yarnpkg.com/@mysten/sui.js/-/sui.js-0.42.0.tgz#db57ad931aa7683fe1526cb4b308425234e1eecf" + integrity sha512-khYpfrWTRNk7WTuDWJx/KCbleqY1B40gVRt1DttqlNkD2lvg134xZn7F/r94jxgnUETbK+hVoQvBY7F36MsfRw== + dependencies: + "@mysten/bcs" "0.7.4" + "@noble/curves" "^1.1.0" + "@noble/hashes" "^1.3.1" + "@open-rpc/client-js" "^1.8.1" + "@scure/bip32" "^1.3.1" + "@scure/bip39" "^1.2.1" + "@suchipi/femver" "^1.0.0" + events "^3.3.0" + superstruct "^1.0.3" + tweetnacl "^1.0.3" + "@noble/curves@^1.0.0", "@noble/curves@^1.1.0", "@noble/curves@^1.2.0", "@noble/curves@~1.3.0": version "1.3.0" resolved "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz#01be46da4fd195822dab821e72f71bf4aeec635e" @@ -1377,6 +1456,16 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A== +"@ts-morph/common@~0.23.0": + version "0.23.0" + resolved "https://registry.yarnpkg.com/@ts-morph/common/-/common-0.23.0.tgz#bd4ddbd3f484f29476c8bd985491592ae5fc147e" + integrity sha512-m7Lllj9n/S6sOkCkRftpM7L24uvmfXQFedlW/4hENcuJH1HHm9u5EgxZb9uVjQSCGrbBWBkOGgcTxNg36r6ywA== + dependencies: + fast-glob "^3.3.2" + minimatch "^9.0.3" + mkdirp "^3.0.1" + path-browserify "^1.0.1" + "@tsconfig/node10@^1.0.7": version "1.0.9" resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" @@ -2293,6 +2382,11 @@ co@^4.6.0: resolved "https://registry.npmjs.org/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" integrity sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ== +code-block-writer@^13.0.1: + version "13.0.1" + resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-13.0.1.tgz#52ac60ca6076d8700b88a45bd71e06a577158405" + integrity sha512-c5or4P6erEA69TxaxTNcHUNcIn+oyxSRTOWV+pSYF+z4epXqNvwvJ70XPGjPNgue83oAFAPBRQYwpAJ/Hpe/Sg== + collect-v8-coverage@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz#c0b29bcd33bcd0779a1344c2136051e6afd3d9e9" @@ -2923,9 +3017,9 @@ fast-diff@^1.1.2: resolved "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz#ece407fa550a64d638536cd727e129c61616e0f0" integrity sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw== -fast-glob@^3.2.9: +fast-glob@^3.2.9, fast-glob@^3.3.2: version "3.3.2" - resolved "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129" integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow== dependencies: "@nodelib/fs.stat" "^2.0.2" @@ -3252,6 +3346,15 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" +gql.tada@^1.4.1: + version "1.5.3" + resolved "https://registry.yarnpkg.com/gql.tada/-/gql.tada-1.5.3.tgz#daea90febabed9dd4cedeb5ebd9f5811440c7169" + integrity sha512-PBLxypMVAs/mD8HRTTdu++RYkB+PyKjNbKugg80Zr9AKi6CMkTv6sgkiUowjwQsmEDNgVneQWz86tEvKSsFqAw== + dependencies: + "@0no-co/graphql.web" "^1.0.5" + "@gql.tada/cli-utils" "1.0.3" + "@gql.tada/internal" "0.2.1" + graceful-fs@^4.2.11, graceful-fs@^4.2.6, graceful-fs@^4.2.9: version "4.2.11" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" @@ -4667,6 +4770,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4: resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== +mkdirp@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50" + integrity sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg== + ms@2.1.2: version "2.1.2" resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -4711,7 +4819,7 @@ node-domexception@^1.0.0: resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== -node-fetch@^2.6.1, node-fetch@^2.6.12: +node-fetch@^2.0.0, node-fetch@^2.6.1, node-fetch@^2.6.12: version "2.7.0" resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== @@ -5140,6 +5248,11 @@ parse-json@^5.2.0: json-parse-even-better-errors "^2.3.0" lines-and-columns "^1.1.6" +path-browserify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" + integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g== + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" @@ -5985,6 +6098,14 @@ ts-log@^2.2.4: resolved "https://registry.yarnpkg.com/ts-log/-/ts-log-2.2.5.tgz#aef3252f1143d11047e2cb6f7cfaac7408d96623" integrity sha512-PGcnJoTBnVGy6yYNFxWVNkdcAuAMstvutN9MgDJIV6L0oG8fB+ZNNy1T+wJzah8RPGor1mZuPQkVfXNDpy9eHA== +ts-morph@~22.0.0: + version "22.0.0" + resolved "https://registry.yarnpkg.com/ts-morph/-/ts-morph-22.0.0.tgz#5532c592fb6dddae08846f12c9ab0fc590b1d42e" + integrity sha512-M9MqFGZREyeb5fTl6gNHKZLqBQA0TjA1lea+CR48R8EBTDuWrNqW6ccC5QvjNR4s6wDumD3LTCjOFSp9iwlzaw== + dependencies: + "@ts-morph/common" "~0.23.0" + code-block-writer "^13.0.1" + ts-node@^10.9.1: version "10.9.2" resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f"