@allbridge/bridge-core-sdk 3.27.0-alpha.14 → 3.27.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/browser/index.js +2 -2
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +2 -2
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/client/core-api/api-client.js +1 -0
  8. package/dist/src/client/core-api/api-client.js.map +1 -1
  9. package/dist/src/client/core-api/core-api-mapper.js +29 -0
  10. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  11. package/dist/src/client/core-api/core-api.model.d.ts +13 -2
  12. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  13. package/dist/src/models/index.d.ts +12 -4
  14. package/dist/src/models/index.js +4 -0
  15. package/dist/src/models/index.js.map +1 -1
  16. package/dist/src/services/bridge/alg/index.js +52 -43
  17. package/dist/src/services/bridge/alg/index.js.map +1 -1
  18. package/dist/src/services/bridge/evm/index.d.ts +1 -0
  19. package/dist/src/services/bridge/evm/index.js +108 -33
  20. package/dist/src/services/bridge/evm/index.js.map +1 -1
  21. package/dist/src/services/bridge/index.d.ts +2 -2
  22. package/dist/src/services/bridge/index.js +10 -4
  23. package/dist/src/services/bridge/index.js.map +1 -1
  24. package/dist/src/services/bridge/models/bridge.model.d.ts +9 -2
  25. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  26. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
  27. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  28. package/dist/src/services/bridge/srb/index.js +36 -28
  29. package/dist/src/services/bridge/srb/index.js.map +1 -1
  30. package/dist/src/services/bridge/stx/index.js +23 -14
  31. package/dist/src/services/bridge/stx/index.js.map +1 -1
  32. package/dist/src/services/bridge/sui/index.js +166 -138
  33. package/dist/src/services/bridge/sui/index.js.map +1 -1
  34. package/dist/src/services/bridge/trx/index.js +98 -70
  35. package/dist/src/services/bridge/trx/index.js.map +1 -1
  36. package/dist/src/services/bridge/utils.js +63 -8
  37. package/dist/src/services/bridge/utils.js.map +1 -1
  38. package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
  39. package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
  40. package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
  41. package/dist/src/services/token/models/token.model.d.ts +4 -4
  42. package/dist/src/services/token/models/token.model.js.map +1 -1
  43. package/dist/src/tokens-info/tokens-info.model.d.ts +17 -0
  44. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  45. package/dist/src/utils/utils.d.ts +1 -0
  46. package/dist/src/utils/utils.js +5 -0
  47. package/dist/src/utils/utils.js.map +1 -1
  48. package/dist/src/version.d.ts +1 -1
  49. package/dist/src/version.js +1 -1
  50. package/dist/src/version.js.map +1 -1
  51. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;AAKA,gDAQC;AAED,oDAIC;AAED,sDAIC;AAED,wDAQC;AAED,gDAOC;AAED,oEAgBC;AAMD,wDAwDC;AA5HD,mCAAwC;AAExC,8CAA+F;AAGxF,KAAK,UAAU,kBAAkB,CACtC,GAAgC,EAChC,gBAAuC;IAEvC,OAAO,MAAM,GAAG,CAAC,gBAAgB,CAAC;QAChC,WAAW,EAAE,gBAAgB,CAAC,WAAW;QACzC,WAAW,EAAE,gBAAgB,CAAC,WAAW;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAiB;IACpD,IAAI,IAAA,YAAG,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,+BAAkB,CAAC,kCAAkC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,SAAg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AAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtD,sBAAsB;QACtB,QAAQ,GAAG,QAAQ,GAAG,iBAAiB,CAAC;QACxC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC;YAC1D,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAClC,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,IAAI,CAAC,0CAA0C,QAAQ,IAAI,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;QACD,aAAa,GAAG,QAAQ,GAAG,aAAa,CAAC;QACzC,YAAY;QACZ,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC;QAC1C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3B,IAAI,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1C,OAAO,CAAC,IAAI,CACV,GAAG,KAAK,YAAY,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,gCAAgC,IAAI,CAAC,SAAS,CAC3F,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,EAC7B,IAAI,EACJ,CAAC,CACF,EAAE,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { Big, BigSource } from \"big.js\";\nimport { AllbridgeCoreClientPoolsExt } from \"../client/core-api/core-client-pool-info-caching\";\nimport { ArgumentInvalidDecimalsError, InvalidAmountError, TimeoutError } from \"../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../tokens-info\";\n\nexport async function getPoolInfoByToken(\n api: AllbridgeCoreClientPoolsExt,\n sourceChainToken: TokenWithChainDetails\n): Promise<PoolInfo> {\n return await api.getPoolInfoByKey({\n chainSymbol: sourceChainToken.chainSymbol,\n poolAddress: sourceChainToken.poolAddress,\n });\n}\n\nexport function validateAmountGtZero(amount: BigSource) {\n if (Big(amount).lte(0)) {\n throw new InvalidAmountError(\"Amount must be greater than zero\");\n }\n}\n\nexport function validateAmountGteZero(amount: BigSource) {\n if (Big(amount).lt(0)) {\n throw new InvalidAmountError(\"Amount must be greater or equal than zero\");\n }\n}\n\nexport function validateAmountDecimals(argName: string, amountFloat: number | string | Big, decimalRequired: number) {\n const amount = Big(amountFloat).toFixed();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [integerPart, fractionalPart] = amount.split(\".\");\n\n if (fractionalPart && fractionalPart.length > decimalRequired) {\n throw new ArgumentInvalidDecimalsError(argName, fractionalPart.length, decimalRequired);\n }\n}\n\nexport async function promiseWithTimeout<T>(promise: Promise<T>, msg: string, timeoutMs: number): Promise<T> {\n return (await Promise.race([\n promise,\n new Promise((resolve, reject) => {\n setTimeout(() => reject(new TimeoutError(msg)), timeoutMs);\n }),\n ])) as any as T;\n}\n\nexport async function promiseWithTimeoutAndRetries<T>(\n toTry: () => Promise<T>,\n msg: string,\n maxRetries: number,\n timeoutMs: number\n): Promise<T> {\n if (maxRetries < 1)\n throw new Error(`Bad argument: 'maxRetries' must be greater than 0, but ${maxRetries} was received.`);\n let attemptCount = 0;\n while (true) {\n try {\n return await promiseWithTimeout(toTry(), msg, timeoutMs);\n } catch (ignoreError) {\n if (++attemptCount >= maxRetries) throw new TimeoutError(msg);\n }\n }\n}\n\n/**\n * Keep calling a `fn` for `secondsToWait` seconds, if `keepWaitingIf` is true.\n * Returns an array of all attempts to call the function.\n */\nexport async function withExponentialBackoff<T>(\n fn: (previousFailure?: T) => Promise<T>,\n keepWaitingIf: (result: T) => boolean,\n secondsToWait: number,\n exponentialFactor = 1.5,\n verbose = false\n): Promise<T[]> {\n const attempts: T[] = [];\n\n let count = 0;\n const initialAttempt = await fn();\n attempts.push(initialAttempt);\n if (!keepWaitingIf(initialAttempt)) return attempts;\n\n const waitUntil = new Date(Date.now() + secondsToWait * 1000).valueOf();\n let waitTime = 1000;\n let totalWaitTime = waitTime;\n\n while (Date.now() < waitUntil) {\n const lastAttempt = attempts[attempts.length - 1];\n if (lastAttempt === undefined || !keepWaitingIf(lastAttempt)) break;\n\n count++;\n // Wait a beat\n if (verbose) {\n console.info(\n `Waiting ${waitTime}ms before trying again (bringing the total wait time to ${totalWaitTime}ms so far, of total ${\n secondsToWait * 1000\n }ms)`\n );\n }\n await new Promise((res) => setTimeout(res, waitTime));\n // Exponential backoff\n waitTime = waitTime * exponentialFactor;\n if (new Date(Date.now() + waitTime).valueOf() > waitUntil) {\n waitTime = waitUntil - Date.now();\n if (verbose) {\n console.info(`was gonna wait too long; new waitTime: ${waitTime}ms`);\n }\n }\n totalWaitTime = waitTime + totalWaitTime;\n // Try again\n const nextAttempt = await fn(lastAttempt);\n attempts.push(nextAttempt);\n if (verbose && keepWaitingIf(nextAttempt)) {\n console.info(\n `${count}. Called ${fn.name}; ${attempts.length} prev attempts. Most recent: ${JSON.stringify(\n attempts[attempts.length - 1],\n null,\n 2\n )}`\n );\n }\n }\n\n return attempts;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;AAKA,kCAGC;AAED,gDAQC;AAED,oDAIC;AAED,sDAIC;AAED,wDAQC;AAED,gDAOC;AAED,oEAgBC;AAMD,wDAwDC;AAjID,mCAAwC;AAExC,8CAA+F;AAG/F,SAAgB,WAAW,CAAC,CAAQ,EAAE,OAAgB;IACpD,4EAA4E;IAC5E,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;AACvD,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,GAAgC,EAChC,gBAAuC;IAEvC,OAAO,MAAM,GAAG,CAAC,gBAAgB,CAAC;QAChC,WAAW,EAAE,gBAAgB,CAAC,WAAW;QACzC,WAAW,EAAE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CoreClientPoolsExt } from \"../client/core-api/core-client-pool-info-caching\";\nimport { ArgumentInvalidDecimalsError, InvalidAmountError, TimeoutError } from \"../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../tokens-info\";\n\nexport function assertNever(x: never, message?: string): never {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(message ?? `Unexpected value: ${x}`);\n}\n\nexport async function getPoolInfoByToken(\n api: AllbridgeCoreClientPoolsExt,\n sourceChainToken: TokenWithChainDetails\n): Promise<PoolInfo> {\n return await api.getPoolInfoByKey({\n chainSymbol: sourceChainToken.chainSymbol,\n poolAddress: sourceChainToken.poolAddress,\n });\n}\n\nexport function validateAmountGtZero(amount: BigSource) {\n if (Big(amount).lte(0)) {\n throw new InvalidAmountError(\"Amount must be greater than zero\");\n }\n}\n\nexport function validateAmountGteZero(amount: BigSource) {\n if (Big(amount).lt(0)) {\n throw new InvalidAmountError(\"Amount must be greater or equal than zero\");\n }\n}\n\nexport function validateAmountDecimals(argName: string, amountFloat: number | string | Big, decimalRequired: number) {\n const amount = Big(amountFloat).toFixed();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [integerPart, fractionalPart] = amount.split(\".\");\n\n if (fractionalPart && fractionalPart.length > decimalRequired) {\n throw new ArgumentInvalidDecimalsError(argName, fractionalPart.length, decimalRequired);\n }\n}\n\nexport async function promiseWithTimeout<T>(promise: Promise<T>, msg: string, timeoutMs: number): Promise<T> {\n return (await Promise.race([\n promise,\n new Promise((resolve, reject) => {\n setTimeout(() => reject(new TimeoutError(msg)), timeoutMs);\n }),\n ])) as any as T;\n}\n\nexport async function promiseWithTimeoutAndRetries<T>(\n toTry: () => Promise<T>,\n msg: string,\n maxRetries: number,\n timeoutMs: number\n): Promise<T> {\n if (maxRetries < 1)\n throw new Error(`Bad argument: 'maxRetries' must be greater than 0, but ${maxRetries} was received.`);\n let attemptCount = 0;\n while (true) {\n try {\n return await promiseWithTimeout(toTry(), msg, timeoutMs);\n } catch (ignoreError) {\n if (++attemptCount >= maxRetries) throw new TimeoutError(msg);\n }\n }\n}\n\n/**\n * Keep calling a `fn` for `secondsToWait` seconds, if `keepWaitingIf` is true.\n * Returns an array of all attempts to call the function.\n */\nexport async function withExponentialBackoff<T>(\n fn: (previousFailure?: T) => Promise<T>,\n keepWaitingIf: (result: T) => boolean,\n secondsToWait: number,\n exponentialFactor = 1.5,\n verbose = false\n): Promise<T[]> {\n const attempts: T[] = [];\n\n let count = 0;\n const initialAttempt = await fn();\n attempts.push(initialAttempt);\n if (!keepWaitingIf(initialAttempt)) return attempts;\n\n const waitUntil = new Date(Date.now() + secondsToWait * 1000).valueOf();\n let waitTime = 1000;\n let totalWaitTime = waitTime;\n\n while (Date.now() < waitUntil) {\n const lastAttempt = attempts[attempts.length - 1];\n if (lastAttempt === undefined || !keepWaitingIf(lastAttempt)) break;\n\n count++;\n // Wait a beat\n if (verbose) {\n console.info(\n `Waiting ${waitTime}ms before trying again (bringing the total wait time to ${totalWaitTime}ms so far, of total ${\n secondsToWait * 1000\n }ms)`\n );\n }\n await new Promise((res) => setTimeout(res, waitTime));\n // Exponential backoff\n waitTime = waitTime * exponentialFactor;\n if (new Date(Date.now() + waitTime).valueOf() > waitUntil) {\n waitTime = waitUntil - Date.now();\n if (verbose) {\n console.info(`was gonna wait too long; new waitTime: ${waitTime}ms`);\n }\n }\n totalWaitTime = waitTime + totalWaitTime;\n // Try again\n const nextAttempt = await fn(lastAttempt);\n attempts.push(nextAttempt);\n if (verbose && keepWaitingIf(nextAttempt)) {\n console.info(\n `${count}. Called ${fn.name}; ${attempts.length} prev attempts. Most recent: ${JSON.stringify(\n attempts[attempts.length - 1],\n null,\n 2\n )}`\n );\n }\n }\n\n return attempts;\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "3.27.0-alpha.14";
1
+ export declare const VERSION = "3.27.0-alpha.16";
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "3.27.0-alpha.14";
4
+ exports.VERSION = "3.27.0-alpha.16";
5
5
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,iBAAiB,CAAC","sourcesContent":["export const VERSION = \"3.27.0-alpha.14\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,iBAAiB,CAAC","sourcesContent":["export const VERSION = \"3.27.0-alpha.16\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbridge/bridge-core-sdk",
3
- "version": "3.27.0-alpha.14",
3
+ "version": "3.27.0-alpha.16",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/src/index.d.ts",