@rozoai/intent-common 0.1.2 → 0.1.4
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/package.json +5 -1
- package/src/api/base.ts +0 -261
- package/src/api/fee.ts +0 -95
- package/src/api/payment.ts +0 -483
- package/src/assert.ts +0 -29
- package/src/bridge-utils.ts +0 -382
- package/src/chain.ts +0 -257
- package/src/debug.ts +0 -14
- package/src/format.ts +0 -65
- package/src/index.ts +0 -14
- package/src/primitiveTypes.ts +0 -29
- package/src/retryBackoff.ts +0 -30
- package/src/rozoPay.ts +0 -638
- package/src/token.ts +0 -1226
- package/src/try.ts +0 -25
- package/src/validation.ts +0 -54
- package/test/bridge.test.ts +0 -396
- package/tsconfig.json +0 -12
package/src/format.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { getChainName } from "./chain";
|
|
2
|
-
import { getKnownToken } from "./token";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Contract an Ethereum address to a shorter string.
|
|
6
|
-
*
|
|
7
|
-
* Example:
|
|
8
|
-
* 0x1234567890123456789012345678901234567890
|
|
9
|
-
* becomes
|
|
10
|
-
* 0x1234…7890
|
|
11
|
-
*/
|
|
12
|
-
export function getAddressContraction(address: string, length = 4): string {
|
|
13
|
-
return address.slice(0, 2 + length) + "…" + address.slice(-length);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Convert a JS Date object to a UNIX timestamp. */
|
|
17
|
-
export function dateToUnix(d: Date): number {
|
|
18
|
-
return Math.floor(d.getTime() / 1000);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Convert a UNIX timestamp to a JS Date object. */
|
|
22
|
-
export function unixToDate(unix: number): Date {
|
|
23
|
-
return new Date(unix * 1000);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function generateEVMDeepLink({
|
|
27
|
-
amountUnits,
|
|
28
|
-
chainId,
|
|
29
|
-
recipientAddress,
|
|
30
|
-
tokenAddress,
|
|
31
|
-
}: {
|
|
32
|
-
tokenAddress: string;
|
|
33
|
-
chainId: number;
|
|
34
|
-
recipientAddress: string;
|
|
35
|
-
amountUnits: string;
|
|
36
|
-
}): string {
|
|
37
|
-
return `ethereum:${tokenAddress}@${chainId}/transfer?address=${recipientAddress}&uint256=${amountUnits}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function generateIntentTitle({
|
|
41
|
-
toChainId,
|
|
42
|
-
toTokenAddress,
|
|
43
|
-
preferredChainId,
|
|
44
|
-
preferredTokenAddress,
|
|
45
|
-
}: {
|
|
46
|
-
toChainId: number;
|
|
47
|
-
toTokenAddress: string;
|
|
48
|
-
preferredChainId: number;
|
|
49
|
-
preferredTokenAddress: string;
|
|
50
|
-
}): string {
|
|
51
|
-
const toChainName = getChainName(toChainId);
|
|
52
|
-
const preferredChainName = getChainName(preferredChainId);
|
|
53
|
-
const toToken = getKnownToken(toChainId, toTokenAddress);
|
|
54
|
-
const preferredToken = getKnownToken(preferredChainId, preferredTokenAddress);
|
|
55
|
-
|
|
56
|
-
if (!toToken || !preferredToken) {
|
|
57
|
-
return "Pay";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (toToken.chainId === preferredToken.chainId) {
|
|
61
|
-
return `Pay with ${preferredToken.symbol} (${preferredChainName})`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return `Pay with ${preferredToken.symbol} (${preferredChainName}) to ${toToken.symbol} (${toChainName})`;
|
|
65
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { setApiConfig, type ApiVersion } from "./api/base";
|
|
2
|
-
export * from "./api/fee";
|
|
3
|
-
export * from "./api/payment";
|
|
4
|
-
export * from "./assert";
|
|
5
|
-
export * from "./bridge-utils";
|
|
6
|
-
export * from "./chain";
|
|
7
|
-
export * from "./debug";
|
|
8
|
-
export * from "./format";
|
|
9
|
-
export * from "./primitiveTypes";
|
|
10
|
-
export * from "./retryBackoff";
|
|
11
|
-
export * from "./rozoPay";
|
|
12
|
-
export * from "./token";
|
|
13
|
-
export * from "./try";
|
|
14
|
-
export * from "./validation";
|
package/src/primitiveTypes.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const zBigIntStr = z
|
|
5
|
-
.string()
|
|
6
|
-
.regex(/^[0-9]+$/i)
|
|
7
|
-
.refine((s): s is BigIntStr => true);
|
|
8
|
-
|
|
9
|
-
export type BigIntStr = `${bigint}`;
|
|
10
|
-
|
|
11
|
-
export const zAddress = z
|
|
12
|
-
.string()
|
|
13
|
-
.regex(/^0x[0-9a-f]{40}$/i)
|
|
14
|
-
.refine((s): s is Address => true);
|
|
15
|
-
|
|
16
|
-
export const zHex = z
|
|
17
|
-
.string()
|
|
18
|
-
.regex(/^0x[0-9a-f]*$/i)
|
|
19
|
-
.refine((s): s is Hex => true);
|
|
20
|
-
|
|
21
|
-
export const zSolanaPublicKey = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
22
|
-
|
|
23
|
-
export type SolanaPublicKey = z.infer<typeof zSolanaPublicKey>;
|
|
24
|
-
|
|
25
|
-
export const zStellarPublicKey = z.string();
|
|
26
|
-
|
|
27
|
-
export type StellarPublicKey = z.infer<typeof zStellarPublicKey>;
|
|
28
|
-
|
|
29
|
-
export type PlatformType = "ios" | "android" | "other";
|
package/src/retryBackoff.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retries a function up to a maximum number of times, with exponential backoff.
|
|
3
|
-
* Current settings, max total wait time is ~10 seconds.
|
|
4
|
-
*/
|
|
5
|
-
export async function retryBackoff<T>(
|
|
6
|
-
name: string,
|
|
7
|
-
fn: () => Promise<T>,
|
|
8
|
-
maxRetries = 5,
|
|
9
|
-
backoffFn: (i: number) => number = (i) => Math.min(2000, 250 * 2 ** i),
|
|
10
|
-
): Promise<T> {
|
|
11
|
-
for (let i = 1; ; i++) {
|
|
12
|
-
try {
|
|
13
|
-
return await fn();
|
|
14
|
-
} catch (e) {
|
|
15
|
-
if (i <= maxRetries) {
|
|
16
|
-
const sleepMs = backoffFn(i);
|
|
17
|
-
console.error(
|
|
18
|
-
`[RETRY] ${name} sleeping ${sleepMs}ms after try ${i}, error:`,
|
|
19
|
-
e,
|
|
20
|
-
);
|
|
21
|
-
await new Promise((r) => setTimeout(r, sleepMs));
|
|
22
|
-
} else {
|
|
23
|
-
console.warn(`[RETRY] ${name} QUITTING after try ${i}, error: ${e}`);
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// TODO: add performance logging
|
|
29
|
-
throw new Error(`too many retries: ${name}`);
|
|
30
|
-
}
|