@tcswap/helpers 4.5.15
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.
- package/dist/api/index.cjs +4 -0
- package/dist/api/index.cjs.map +16 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +16 -0
- package/dist/chunk-pfmeq01a.js +5 -0
- package/dist/chunk-pfmeq01a.js.map +9 -0
- package/dist/chunk-vb4wtm2w.js +4 -0
- package/dist/chunk-vb4wtm2w.js.map +9 -0
- package/dist/contracts.cjs +4 -0
- package/dist/contracts.cjs.map +10 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +10 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +30 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +30 -0
- package/dist/tokens.cjs +4 -0
- package/dist/tokens.cjs.map +10 -0
- package/dist/tokens.js +4 -0
- package/dist/tokens.js.map +10 -0
- package/dist/types/api/index.d.ts +502 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/memoless/endpoints.d.ts +56 -0
- package/dist/types/api/memoless/endpoints.d.ts.map +1 -0
- package/dist/types/api/memoless/types.d.ts +85 -0
- package/dist/types/api/memoless/types.d.ts.map +1 -0
- package/dist/types/api/midgard/endpoints.d.ts +80 -0
- package/dist/types/api/midgard/endpoints.d.ts.map +1 -0
- package/dist/types/api/midgard/types.d.ts +543 -0
- package/dist/types/api/midgard/types.d.ts.map +1 -0
- package/dist/types/api/thornode/endpoints.d.ts +34 -0
- package/dist/types/api/thornode/endpoints.d.ts.map +1 -0
- package/dist/types/api/thornode/types.d.ts +264 -0
- package/dist/types/api/thornode/types.d.ts.map +1 -0
- package/dist/types/api/uswap/endpoints.d.ts +372 -0
- package/dist/types/api/uswap/endpoints.d.ts.map +1 -0
- package/dist/types/api/uswap/types.d.ts +1487 -0
- package/dist/types/api/uswap/types.d.ts.map +1 -0
- package/dist/types/contracts.d.ts +2 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/assetValue.d.ts +82 -0
- package/dist/types/modules/assetValue.d.ts.map +1 -0
- package/dist/types/modules/bigIntArithmetics.d.ts +60 -0
- package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -0
- package/dist/types/modules/feeMultiplier.d.ts +48 -0
- package/dist/types/modules/feeMultiplier.d.ts.map +1 -0
- package/dist/types/modules/requestClient.d.ts +33 -0
- package/dist/types/modules/requestClient.d.ts.map +1 -0
- package/dist/types/modules/uSwapConfig.d.ts +249 -0
- package/dist/types/modules/uSwapConfig.d.ts.map +1 -0
- package/dist/types/modules/uSwapError.d.ts +879 -0
- package/dist/types/modules/uSwapError.d.ts.map +1 -0
- package/dist/types/modules/uSwapNumber.d.ts +10 -0
- package/dist/types/modules/uSwapNumber.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +2 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/types/types/commonTypes.d.ts +16 -0
- package/dist/types/types/commonTypes.d.ts.map +1 -0
- package/dist/types/types/derivationPath.d.ts +4 -0
- package/dist/types/types/derivationPath.d.ts.map +1 -0
- package/dist/types/types/errors/apiV1.d.ts +2 -0
- package/dist/types/types/errors/apiV1.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/quotes.d.ts +180 -0
- package/dist/types/types/quotes.d.ts.map +1 -0
- package/dist/types/types/sdk.d.ts +35 -0
- package/dist/types/types/sdk.d.ts.map +1 -0
- package/dist/types/types/wallet.d.ts +130 -0
- package/dist/types/types/wallet.d.ts.map +1 -0
- package/dist/types/utils/asset.d.ts +37 -0
- package/dist/types/utils/asset.d.ts.map +1 -0
- package/dist/types/utils/chains.d.ts +13 -0
- package/dist/types/utils/chains.d.ts.map +1 -0
- package/dist/types/utils/derivationPath.d.ts +21 -0
- package/dist/types/utils/derivationPath.d.ts.map +1 -0
- package/dist/types/utils/explorerUrls.d.ts +10 -0
- package/dist/types/utils/explorerUrls.d.ts.map +1 -0
- package/dist/types/utils/liquidity.d.ts +62 -0
- package/dist/types/utils/liquidity.d.ts.map +1 -0
- package/dist/types/utils/memo.d.ts +65 -0
- package/dist/types/utils/memo.d.ts.map +1 -0
- package/dist/types/utils/others.d.ts +15 -0
- package/dist/types/utils/others.d.ts.map +1 -0
- package/dist/types/utils/validators.d.ts +6 -0
- package/dist/types/utils/validators.d.ts.map +1 -0
- package/dist/types/utils/wallets.d.ts +36 -0
- package/dist/types/utils/wallets.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/api/index.ts +15 -0
- package/src/api/memoless/endpoints.ts +62 -0
- package/src/api/memoless/types.ts +83 -0
- package/src/api/midgard/endpoints.ts +352 -0
- package/src/api/midgard/types.ts +515 -0
- package/src/api/thornode/endpoints.ts +109 -0
- package/src/api/thornode/types.ts +247 -0
- package/src/api/uswap/endpoints.ts +252 -0
- package/src/api/uswap/types.ts +626 -0
- package/src/contracts.ts +1 -0
- package/src/index.ts +32 -0
- package/src/modules/__tests__/assetValue.test.ts +2452 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +410 -0
- package/src/modules/__tests__/feeMultiplier.test.ts +131 -0
- package/src/modules/__tests__/uSwapConfig.test.ts +429 -0
- package/src/modules/__tests__/uSwapNumber.test.ts +439 -0
- package/src/modules/assetValue.ts +536 -0
- package/src/modules/bigIntArithmetics.ts +366 -0
- package/src/modules/feeMultiplier.ts +84 -0
- package/src/modules/requestClient.ts +116 -0
- package/src/modules/uSwapConfig.ts +189 -0
- package/src/modules/uSwapError.ts +474 -0
- package/src/modules/uSwapNumber.ts +17 -0
- package/src/tokens.ts +1 -0
- package/src/types/commonTypes.ts +10 -0
- package/src/types/derivationPath.ts +11 -0
- package/src/types/errors/apiV1.ts +0 -0
- package/src/types/index.ts +5 -0
- package/src/types/quotes.ts +182 -0
- package/src/types/sdk.ts +38 -0
- package/src/types/wallet.ts +124 -0
- package/src/utils/__tests__/asset.test.ts +186 -0
- package/src/utils/__tests__/derivationPath.test.ts +142 -0
- package/src/utils/__tests__/explorerUrls.test.ts +59 -0
- package/src/utils/__tests__/liquidity.test.ts +302 -0
- package/src/utils/__tests__/memo.test.ts +99 -0
- package/src/utils/__tests__/others.test.ts +169 -0
- package/src/utils/__tests__/validators.test.ts +84 -0
- package/src/utils/__tests__/wallets.test.ts +625 -0
- package/src/utils/asset.ts +399 -0
- package/src/utils/chains.ts +104 -0
- package/src/utils/derivationPath.ts +101 -0
- package/src/utils/explorerUrls.ts +32 -0
- package/src/utils/liquidity.ts +154 -0
- package/src/utils/memo.ts +102 -0
- package/src/utils/others.ts +64 -0
- package/src/utils/validators.ts +36 -0
- package/src/utils/wallets.ts +238 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../../src/utils/asset.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAwD,MAAM,eAAe,CAAC;AAE5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;AAE5E,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC;AAEnH,eAAO,MAAM,kBAAkB,kGAQrB,CAAC;AAyIX,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;;;GAwHnF;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,WAe7E;AAED,eAAO,MAAM,kBAAkB,GAAI,aAAa,iBAAiB;;;CA8ChE,CAAC;AAEF,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,wCAiB/E;AAED,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM;;;;;CAYlD,CAAC;AAEF,wBAAsB,WAAW,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,UAAU,EAAE,GAAG,KAAK,IAAI,MAAM,EAAE,CAAA;CAAE,gv2QAsBlH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
import { Chain, type StagenetChain } from "@tcswap/types";
|
|
5
|
+
export declare function getRPCUrl(chain: Chain | StagenetChain): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
* RPC URLs are now managed dynamically via USwapConfig.
|
|
9
|
+
* Please use static { rpcUrls, fallbackRpcUrls } USwap init config or dynamic USwapConfig.setRpcUrl/setFallbackRpcUrl to configure RPC endpoints.
|
|
10
|
+
* This function is obsolete and will be removed in a future release.
|
|
11
|
+
*/
|
|
12
|
+
export declare function initializeRPCUrlsWithFallback(_chains: never): void;
|
|
13
|
+
//# sourceMappingURL=chains.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../src/utils/chains.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAA2B,KAAK,aAAa,EAA8B,MAAM,eAAe,CAAC;AAiD/G,wBAAsB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,mBAmC3D;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,KAAK,QAO3D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Chain } from "@tcswap/types";
|
|
2
|
+
import { type DerivationPathArray } from "../types";
|
|
3
|
+
type Params = {
|
|
4
|
+
chain: Chain;
|
|
5
|
+
index: number;
|
|
6
|
+
addressIndex?: number;
|
|
7
|
+
type?: "legacy" | "ledgerLive" | "nativeSegwitMiddleAccount" | "segwit" | "account";
|
|
8
|
+
};
|
|
9
|
+
export declare function updateDerivationPath(path: DerivationPathArray, params: {
|
|
10
|
+
index: number;
|
|
11
|
+
} | {
|
|
12
|
+
account: number;
|
|
13
|
+
} | {
|
|
14
|
+
change: number;
|
|
15
|
+
}): [44, 118, 0, 0, 0] | [44, 931, 0, 0, 0] | [number, number, number, number, number] | [44, 397, 0, 0, 0] | [0, 0, 0, 0, 0] | [44, 144, 0, 0, 0] | [44, 501, 0, 0, 0] | [44, 607, 0, 0, 0] | [44, 195, 0, 0, 0] | [44, 784, 0, 0, 0] | [1852, 1815, 0, 0, 0] | [number, number, number, number, (number | undefined)?] | [44, 145, 0, 0, 0] | [84, 2, 0, 0, 0] | [44, 3, 0, 0, 0] | [44, 5, 0, 0, 0] | [44, 133, 0, 0, 0];
|
|
16
|
+
export declare function derivationPathToString([network, chainId, account, change, index]: [number, number, number, number?, number?] | [number, number, number, number, number?] | DerivationPathArray): string;
|
|
17
|
+
export declare function getDerivationPathFor({ chain, index, addressIndex, type }: Params): [number, number, number, number, (number | undefined)?] | number[];
|
|
18
|
+
export declare function getWalletFormatFor(path: string): "legacy" | "p2sh" | "bech32";
|
|
19
|
+
export declare const DerivationPath: Record<Chain, string>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=derivationPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivationPath.d.ts","sourceRoot":"","sources":["../../../src/utils/derivationPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAA4B,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,KAAK,mBAAmB,EAAyB,MAAM,UAAU,CAAC;AAE3E,KAAK,MAAM,GAAG;IACZ,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,2BAA2B,GAAG,QAAQ,GAAG,SAAS,CAAC;CACrF,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,mBAAmB,EACzB,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,2ZAkBrE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAC7E,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC1C,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,GACzC,mBAAmB,UAStB;AAGD,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,YAAgB,EAAE,IAAI,EAAE,EAAE,MAAM,sEA8BpF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,gCAa9C;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAMhD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Chain } from "@tcswap/types";
|
|
2
|
+
export declare function getExplorerTxUrl({ chain, txHash }: {
|
|
3
|
+
txHash: string;
|
|
4
|
+
chain: Chain;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function getExplorerAddressUrl({ chain, address }: {
|
|
7
|
+
address: string;
|
|
8
|
+
chain: Chain;
|
|
9
|
+
}): string;
|
|
10
|
+
//# sourceMappingURL=explorerUrls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explorerUrls.d.ts","sourceRoot":"","sources":["../../../src/utils/explorerUrls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAwE,MAAM,eAAe,CAAC;AAG5G,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,UAoBnF;AAED,wBAAgB,qBAAqB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,UAM1F"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
import { USwapNumber } from "../modules/uSwapNumber";
|
|
5
|
+
type ShareParams<T extends {}> = T & {
|
|
6
|
+
liquidityUnits: string;
|
|
7
|
+
poolUnits: string;
|
|
8
|
+
};
|
|
9
|
+
type PoolParams = {
|
|
10
|
+
runeAmount: string;
|
|
11
|
+
assetAmount: string;
|
|
12
|
+
runeDepth: string;
|
|
13
|
+
assetDepth: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Ref: https://gitlab.com/thorchain/thornode/-/issues/657
|
|
17
|
+
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
18
|
+
* s = stakeUnits for member (after factoring in withdrawBasisPoints)
|
|
19
|
+
* T = totalPoolUnits for pool
|
|
20
|
+
* A = assetDepth to be withdrawn
|
|
21
|
+
*
|
|
22
|
+
* Formula:
|
|
23
|
+
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
24
|
+
* (part1 * (part2 - part3 + part4)) / part5
|
|
25
|
+
*/
|
|
26
|
+
export declare function getAsymmetricRuneShare({ liquidityUnits, poolUnits, runeDepth }: ShareParams<{
|
|
27
|
+
runeDepth: string;
|
|
28
|
+
}>): USwapNumber;
|
|
29
|
+
export declare function getAsymmetricAssetShare({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
|
|
30
|
+
assetDepth: string;
|
|
31
|
+
}>): USwapNumber;
|
|
32
|
+
export declare function getAsymmetricRuneWithdrawAmount({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
|
|
33
|
+
percent: number;
|
|
34
|
+
runeDepth: string;
|
|
35
|
+
}>): USwapNumber;
|
|
36
|
+
export declare function getAsymmetricAssetWithdrawAmount({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
|
|
37
|
+
percent: number;
|
|
38
|
+
assetDepth: string;
|
|
39
|
+
}>): USwapNumber;
|
|
40
|
+
export declare function getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
|
|
41
|
+
runeDepth: string;
|
|
42
|
+
assetDepth: string;
|
|
43
|
+
}>): {
|
|
44
|
+
assetAmount: USwapNumber;
|
|
45
|
+
runeAmount: USwapNumber;
|
|
46
|
+
};
|
|
47
|
+
export declare function getSymmetricWithdraw({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
|
|
48
|
+
runeDepth: string;
|
|
49
|
+
assetDepth: string;
|
|
50
|
+
percent: number;
|
|
51
|
+
}>): {
|
|
52
|
+
[k: string]: USwapNumber;
|
|
53
|
+
};
|
|
54
|
+
export declare function getEstimatedPoolShare({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
|
|
55
|
+
runeAmount: string;
|
|
56
|
+
assetAmount: string;
|
|
57
|
+
runeDepth: string;
|
|
58
|
+
assetDepth: string;
|
|
59
|
+
}>): number;
|
|
60
|
+
export declare function getLiquiditySlippage({ runeAmount, assetAmount, runeDepth, assetDepth }: PoolParams): number;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=liquidity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidity.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidity.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,KAAK,WAAW,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,KAAK,UAAU,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAErG;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,WAAW,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,eAclH;AAED,wBAAgB,uBAAuB,CAAC,EACtC,cAAc,EACd,SAAS,EACT,UAAU,GACX,EAAE,WAAW,CAAC;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,eAarC;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,OAAO,EACP,SAAS,EACT,cAAc,EACd,SAAS,GACV,EAAE,WAAW,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,eAErD;AAED,wBAAgB,gCAAgC,CAAC,EAC/C,OAAO,EACP,UAAU,EACV,cAAc,EACd,SAAS,GACV,EAAE,WAAW,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,eAEtD;AAMD,wBAAgB,qBAAqB,CAAC,EACpC,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,GACX,EAAE,WAAW,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;;;EAKxD;AAED,wBAAgB,oBAAoB,CAAC,EACnC,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,OAAO,GACR,EAAE,WAAW,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;;EAOzE;AAED,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EACT,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,GACZ,EAAE,WAAW,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,UAyBjG;AAED,wBAAgB,oBAAoB,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,UAAU,UAalG"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Chain } from "@tcswap/types";
|
|
2
|
+
import { MemoType } from "../types/sdk";
|
|
3
|
+
export declare function getMemoForLeaveAndBond({ type, address }: BondOrLeaveParams): string;
|
|
4
|
+
export declare function getMemoForUnbond({ address, unbondAmount }: UnbondParams): string;
|
|
5
|
+
/**
|
|
6
|
+
* Deposit
|
|
7
|
+
*/
|
|
8
|
+
export declare function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>): string;
|
|
9
|
+
export declare function getMemoForDeposit({ chain, symbol, address, ...affiliate }: WithAffiliate<{
|
|
10
|
+
chain: Chain;
|
|
11
|
+
symbol: string;
|
|
12
|
+
address?: string;
|
|
13
|
+
}>): string;
|
|
14
|
+
/**
|
|
15
|
+
* Withdraw
|
|
16
|
+
*/
|
|
17
|
+
export declare function getMemoForWithdraw({ chain, symbol, ticker, basisPoints, targetAsset }: WithdrawParams): string;
|
|
18
|
+
export declare function getMemoForRunePoolWithdraw({ basisPoints, ...affiliate }: WithAffiliate<{
|
|
19
|
+
basisPoints: number;
|
|
20
|
+
}>): string;
|
|
21
|
+
/**
|
|
22
|
+
* TNS
|
|
23
|
+
*/
|
|
24
|
+
export declare function getMemoForNameRegister({ name, chain, address, owner }: NameRegisterParams): string;
|
|
25
|
+
export declare function getMemoForNamePreferredAssetRegister({ name, chain, asset, payout, owner, }: PreferredAssetRegisterParams): string;
|
|
26
|
+
export declare function getMemoForTcyClaim(memoType: MemoType.CLAIM_TCY, { address }: WithAffiliate<{
|
|
27
|
+
address: string;
|
|
28
|
+
}>): string;
|
|
29
|
+
export declare function getMemoForTcyStake(memoType: MemoType.STAKE_TCY | MemoType.UNSTAKE_TCY, { unstakeBps, ...affiliate }: WithAffiliate<{
|
|
30
|
+
unstakeBps?: number;
|
|
31
|
+
}>): string;
|
|
32
|
+
type WithAffiliate<T extends {}> = T & {
|
|
33
|
+
affiliateAddress?: string;
|
|
34
|
+
affiliateBasisPoints?: number;
|
|
35
|
+
};
|
|
36
|
+
type BondOrLeaveParams = {
|
|
37
|
+
type: MemoType.BOND | MemoType.LEAVE;
|
|
38
|
+
address: string;
|
|
39
|
+
};
|
|
40
|
+
type UnbondParams = {
|
|
41
|
+
address: string;
|
|
42
|
+
unbondAmount: number;
|
|
43
|
+
};
|
|
44
|
+
type NameRegisterParams = {
|
|
45
|
+
name: string;
|
|
46
|
+
chain: string;
|
|
47
|
+
address: string;
|
|
48
|
+
owner?: string;
|
|
49
|
+
};
|
|
50
|
+
type PreferredAssetRegisterParams = {
|
|
51
|
+
name: string;
|
|
52
|
+
chain: Chain;
|
|
53
|
+
asset: string;
|
|
54
|
+
payout: string;
|
|
55
|
+
owner: string;
|
|
56
|
+
};
|
|
57
|
+
type WithdrawParams = {
|
|
58
|
+
chain: Chain;
|
|
59
|
+
symbol: string;
|
|
60
|
+
ticker: string;
|
|
61
|
+
basisPoints: number;
|
|
62
|
+
targetAsset?: string;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../../src/utils/memo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,wBAAgB,sBAAsB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,iBAAiB,UAE1E;AAED,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,YAAY,UAEvE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,UAEtE;AAED,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,MAAM,EACN,OAAO,EACP,GAAG,SAAS,EACb,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,UAKnE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,cAAc,UAKrG;AAED,wBAAgB,0BAA0B,CAAC,EAAE,WAAW,EAAE,GAAG,SAAS,EAAE,EAAE,aAAa,CAAC;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,UAE/G;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,kBAAkB,UAKzF;AAED,wBAAgB,oCAAoC,CAAC,EACnD,IAAI,EACJ,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,GACN,EAAE,4BAA4B,UAE9B;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,UAE/G;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,WAAW,EACnD,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,EAAE,aAAa,CAAC;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,UAMrE;AAkBD,KAAK,aAAa,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpG,KAAK,iBAAiB,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AACnF,KAAK,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3F,KAAK,4BAA4B,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACjH,KAAK,cAAc,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
import { Chain } from "@tcswap/types";
|
|
5
|
+
import { type ErrorKeys } from "../modules/uSwapError";
|
|
6
|
+
export declare function getTHORNameCost(numberOfYears: number): number;
|
|
7
|
+
export declare function getMAYANameCost(numberOfYears: number): number;
|
|
8
|
+
export declare function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys): T | undefined;
|
|
9
|
+
export declare function getChainIdentifier<T extends Chain>(chain: T): string;
|
|
10
|
+
export declare function warnOnce({ condition, id, warning }: {
|
|
11
|
+
condition: boolean;
|
|
12
|
+
id: string;
|
|
13
|
+
warning: string;
|
|
14
|
+
}): void;
|
|
15
|
+
//# sourceMappingURL=others.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"others.d.ts","sourceRoot":"","sources":["../../../src/utils/others.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,uBAAuB,CAAC;AAInE,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,UAGpD;AAID,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,UAIpD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,iBAUjE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,UAc3D;AAGD,wBAAgB,QAAQ,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,QAYvG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/utils/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,wBAAgB,kBAAkB,CAAC,UAAU,SAAK,WAgBjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,WAMvC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
import { type Chain } from "@tcswap/types";
|
|
5
|
+
import type { BrowserProvider, JsonRpcProvider } from "ethers";
|
|
6
|
+
import { type EIP6963Provider, type NetworkParams, WalletOption } from "../types";
|
|
7
|
+
export declare function isWeb3Detected(): boolean;
|
|
8
|
+
export declare function isDetected(walletOption: WalletOption): boolean;
|
|
9
|
+
export declare function listWeb3EVMWallets(): WalletOption[];
|
|
10
|
+
export declare function switchEVMWalletNetwork(provider: BrowserProvider, chain: Chain, networkParams?: NetworkParams): Promise<void>;
|
|
11
|
+
export declare function filterSupportedChains<T extends string[]>({ chains, supportedChains, walletType, }: {
|
|
12
|
+
chains: Chain[];
|
|
13
|
+
supportedChains: T;
|
|
14
|
+
walletType?: WalletOption;
|
|
15
|
+
}): T;
|
|
16
|
+
export declare function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(func: T, provider: BrowserProvider, chain: Chain): T;
|
|
17
|
+
export declare function prepareNetworkSwitch<T extends Record<string, unknown>, M extends keyof T>({ toolbox, chain, provider, methodNames, }: {
|
|
18
|
+
toolbox: T;
|
|
19
|
+
chain: Chain;
|
|
20
|
+
provider?: BrowserProvider | JsonRpcProvider;
|
|
21
|
+
methodNames?: M[];
|
|
22
|
+
}): T & {};
|
|
23
|
+
export declare function addEVMWalletNetwork(provider: BrowserProvider, networkParams: NetworkParams): Promise<any>;
|
|
24
|
+
export declare function addAccountsChangedCallback(callback: () => void): void;
|
|
25
|
+
export declare function getETHDefaultWallet(): WalletOption.BRAVE | WalletOption.COINBASE_WEB | WalletOption.CTRL | WalletOption.METAMASK | WalletOption.ONEKEY | WalletOption.TRUSTWALLET_WEB;
|
|
26
|
+
export declare function getEIP6963Wallets(): {
|
|
27
|
+
providers: EIP6963Provider[];
|
|
28
|
+
removeEIP6963EventListener: () => void;
|
|
29
|
+
};
|
|
30
|
+
export declare function okxMobileEnabled(): boolean;
|
|
31
|
+
export declare function providerRequest({ provider, params, method, }: {
|
|
32
|
+
provider?: BrowserProvider;
|
|
33
|
+
params?: any;
|
|
34
|
+
method: "wallet_addEthereumChain" | "wallet_switchEthereumChain" | "eth_requestAccounts" | "eth_sendTransaction" | "eth_signTransaction";
|
|
35
|
+
}): Promise<any>;
|
|
36
|
+
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../../src/utils/wallets.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE/D,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,aAAa,EAClB,YAAY,EACb,MAAM,UAAU,CAAC;AAclB,wBAAgB,cAAc,YAE7B;AAED,wBAAgB,UAAU,CAAC,YAAY,EAAE,YAAY,WAEpD;AAED,wBAAgB,kBAAkB,mBAwBjC;AAED,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,aAAa,iBAelH;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EACxD,MAAM,EACN,eAAe,EACf,UAAU,GACX,EAAE;IACD,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,eAAe,EAAE,CAAC,CAAC;IACnB,UAAU,CAAC,EAAE,YAAY,CAAC;CAC3B,GAiBqB,CAAC,CACtB;AAED,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3E,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,KAAK,GAaK,CAAC,CACnB;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,EACzF,OAAO,EACP,KAAK,EACL,QAA0B,EAC1B,WAAgB,GACjB,EAAE;IACD,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,eAAe,GAAG,eAAe,CAAC;IAC7C,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC;CACnB,UAiCA;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,gBAE1F;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,IAAI,QAG9D;AAED,wBAAgB,mBAAmB,oJAQlC;AAED,wBAAgB,iBAAiB;;;EAgBhC;AAED,wBAAgB,gBAAgB,YAQ/B;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,MAAM,GACP,EAAE;IACD,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,EACF,yBAAyB,GACzB,4BAA4B,GAC5B,qBAAqB,GACrB,qBAAqB,GACrB,qBAAqB,CAAC;CAC3B,gBAOA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "swapkit-oss",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@near-js/providers": "~2.5.0",
|
|
5
|
+
"@tcswap/contracts": "4.0.5",
|
|
6
|
+
"@tcswap/tokens": "4.1.5",
|
|
7
|
+
"@tcswap/types": "0.4.1",
|
|
8
|
+
"ethers": "^6.14.0",
|
|
9
|
+
"ts-pattern": "5.9.0",
|
|
10
|
+
"zod": "3.25.74",
|
|
11
|
+
"zustand": "5.0.8"
|
|
12
|
+
},
|
|
13
|
+
"description": "USwap - Helpers",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@near-js/providers": "2.5.0",
|
|
16
|
+
"@tcswap/toolboxes": "4.3.15",
|
|
17
|
+
"ethers": "6.15.0",
|
|
18
|
+
"tronweb": "6.1.0"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"bun": "./src/index.ts",
|
|
23
|
+
"default": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/types/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./api": {
|
|
28
|
+
"bun": "./src/api/index.ts",
|
|
29
|
+
"default": "./dist/api/index.js",
|
|
30
|
+
"require": "./dist/api/index.cjs",
|
|
31
|
+
"types": "./dist/types/api/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./contracts": {
|
|
34
|
+
"bun": "./src/contracts.ts",
|
|
35
|
+
"default": "./dist/contracts.js",
|
|
36
|
+
"require": "./dist/contracts.cjs",
|
|
37
|
+
"types": "./dist/types/contracts.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./tokens": {
|
|
40
|
+
"bun": "./src/tokens.ts",
|
|
41
|
+
"default": "./dist/tokens.js",
|
|
42
|
+
"require": "./dist/tokens.cjs",
|
|
43
|
+
"types": "./dist/types/tokens.d.ts"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": ["dist/", "src/"],
|
|
47
|
+
"homepage": "https://github.com/thorchain/TCSwap",
|
|
48
|
+
"license": "Apache-2.0",
|
|
49
|
+
"name": "@tcswap/helpers",
|
|
50
|
+
"repository": {
|
|
51
|
+
"directory": "packages/helpers",
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/thorchain/TCSwap.git"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "bun run ./build.ts",
|
|
57
|
+
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
58
|
+
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
59
|
+
"generate-tokens": "bun --bun ./fetchTokenLists.ts",
|
|
60
|
+
"test": "bun test",
|
|
61
|
+
"test:ci": "bun test --coverage",
|
|
62
|
+
"type-check": "bun tsc --noEmit",
|
|
63
|
+
"type-check:go": "tsgo"
|
|
64
|
+
},
|
|
65
|
+
"type": "module",
|
|
66
|
+
"version": "4.5.15"
|
|
67
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as memoless from "./memoless/endpoints";
|
|
6
|
+
import { mayachainMidgard, thorchainMidgard } from "./midgard/endpoints";
|
|
7
|
+
import * as thornode from "./thornode/endpoints";
|
|
8
|
+
import * as uswap from "./uswap/endpoints";
|
|
9
|
+
|
|
10
|
+
export * from "./memoless/types";
|
|
11
|
+
export * from "./midgard/types";
|
|
12
|
+
export * from "./thornode/types";
|
|
13
|
+
export * from "./uswap/types";
|
|
14
|
+
|
|
15
|
+
export const USwapApi = { ...uswap, ...memoless, mayachainMidgard, thorchainMidgard, thornode };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { RequestClient, type RequestOptions, USwapConfig, USwapError } from "@tcswap/helpers";
|
|
6
|
+
import {
|
|
7
|
+
type MemolessAssetsResponse,
|
|
8
|
+
type PreflightRequest,
|
|
9
|
+
type PreflightResult,
|
|
10
|
+
PreflightResultSchema,
|
|
11
|
+
type RegistrationRequest,
|
|
12
|
+
type RegistrationResponse,
|
|
13
|
+
RegistrationResponseSchema,
|
|
14
|
+
} from "./types";
|
|
15
|
+
|
|
16
|
+
const USwapRequestClient = RequestClient.extend({
|
|
17
|
+
dynamicHeader: () => {
|
|
18
|
+
const { memoless } = USwapConfig.get("apiKeys");
|
|
19
|
+
return memoless ? { "x-api-key": memoless } : {};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export function getMemolessAssets(options?: RequestOptions) {
|
|
24
|
+
return USwapRequestClient.get<MemolessAssetsResponse>(getApiUrl("/assets"), { ...options });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function registerMemoless(json: RegistrationRequest, options?: RequestOptions) {
|
|
28
|
+
const apiUrl = getApiUrl("/register");
|
|
29
|
+
const response = await USwapRequestClient.post<RegistrationResponse>(apiUrl, { json, ...options });
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const parsedResponse = RegistrationResponseSchema.safeParse(response);
|
|
33
|
+
if (!parsedResponse.success) {
|
|
34
|
+
throw new USwapError("api_v2_invalid_response", parsedResponse.error);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return parsedResponse.data;
|
|
38
|
+
} catch (_error) {
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function preflightMemoless(json: PreflightRequest, options?: RequestOptions) {
|
|
44
|
+
const apiUrl = getApiUrl("/preflight");
|
|
45
|
+
const response = await USwapRequestClient.post<PreflightResult>(apiUrl, { json, ...options });
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const parsedResponse = PreflightResultSchema.safeParse(response);
|
|
49
|
+
if (!parsedResponse.success) {
|
|
50
|
+
throw new USwapError("api_v2_invalid_response", parsedResponse.error);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return parsedResponse.data;
|
|
54
|
+
} catch (_error) {
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getApiUrl(path?: `/${string}`) {
|
|
60
|
+
const { memolessApiUrl } = USwapConfig.get("envs");
|
|
61
|
+
return `${memolessApiUrl}${path}`;
|
|
62
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { array, coerce, object, optional, z } from "zod/v4";
|
|
6
|
+
|
|
7
|
+
export const MemolessAssetItem = z.object({
|
|
8
|
+
asset: z.string(),
|
|
9
|
+
balanceRune: z.number(),
|
|
10
|
+
decimals: coerce.number(),
|
|
11
|
+
isToken: z.boolean(),
|
|
12
|
+
priceUSD: z.number(),
|
|
13
|
+
status: z.string(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const MemolessAssetsSchema = z.object({
|
|
17
|
+
assets: array(MemolessAssetItem),
|
|
18
|
+
error: optional(object({ code: z.string(), details: z.string(), message: z.string() })),
|
|
19
|
+
success: z.boolean(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type MemolessAsset = z.infer<typeof MemolessAssetItem>;
|
|
23
|
+
export type MemolessAssetsResponse = z.infer<typeof MemolessAssetsSchema>;
|
|
24
|
+
|
|
25
|
+
export const RegistrationRequestSchema = z.object({
|
|
26
|
+
asset: z.string(),
|
|
27
|
+
memo: z.string(),
|
|
28
|
+
requested_in_asset_amount: z.optional(z.string()).or(z.number()),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type RegistrationRequest = z.infer<typeof RegistrationRequestSchema>;
|
|
32
|
+
|
|
33
|
+
export const RegistrationResponseSchema = z.object({
|
|
34
|
+
asset: z.string(),
|
|
35
|
+
decimals: z.number(),
|
|
36
|
+
height: z.string(),
|
|
37
|
+
internal_api_id: z.string(),
|
|
38
|
+
memo: z.string(),
|
|
39
|
+
minimum_amount_to_send: z.string(),
|
|
40
|
+
reference: z.string(),
|
|
41
|
+
reference_length: z.number(),
|
|
42
|
+
registered_by: z.string(),
|
|
43
|
+
registration_hash: z.string(),
|
|
44
|
+
success: z.boolean(),
|
|
45
|
+
suggested_in_asset_amount: z.optional(z.string()),
|
|
46
|
+
txHash: z.string(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export type RegistrationResponse = z.infer<typeof RegistrationResponseSchema>;
|
|
50
|
+
|
|
51
|
+
export enum PreflightInputType {
|
|
52
|
+
asset = "asset",
|
|
53
|
+
usd = "usd",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const PreflightRequestSchema = z.object({
|
|
57
|
+
amount: z.string(),
|
|
58
|
+
asset: optional(z.string()),
|
|
59
|
+
inputType: optional(z.enum(PreflightInputType)),
|
|
60
|
+
internal_api_id: optional(z.string()),
|
|
61
|
+
reference: optional(z.string()),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export type PreflightRequest = z.infer<typeof PreflightRequestSchema>;
|
|
65
|
+
|
|
66
|
+
export const PreflightResultSchema = z.object({
|
|
67
|
+
data: z.object({
|
|
68
|
+
blocks_remaining: z.number(),
|
|
69
|
+
current_uses: z.number(),
|
|
70
|
+
inbound_address: optional(z.string()),
|
|
71
|
+
max_uses: z.number(),
|
|
72
|
+
memo: optional(z.string()),
|
|
73
|
+
qr_code: optional(z.string()),
|
|
74
|
+
qr_code_data_url: optional(z.string()),
|
|
75
|
+
seconds_remaining: z.number(),
|
|
76
|
+
time_remaining: z.string(),
|
|
77
|
+
}),
|
|
78
|
+
error: optional(z.object({ code: z.string(), message: z.string() })),
|
|
79
|
+
message: z.string(),
|
|
80
|
+
success: z.boolean(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export type PreflightResult = z.infer<typeof PreflightResultSchema>;
|