-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtransfer-arguments.ts
103 lines (96 loc) · 3.41 KB
/
transfer-arguments.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Schema } from "effect"
import {
AddressAptosCanonical,
AddressCosmosCanonical,
AddressEvmCanonical
} from "$lib/schema/address"
import { RpcType } from "$lib/schema/chain"
import { EVMWethToken, TokenRawAmount, TokenRawDenom } from "$lib/schema/token"
import { ChannelId } from "$lib/schema/channel"
const CommonTransferFields = {
baseToken: TokenRawDenom.annotations({
message: () => "baseToken must be a non-empty string (e.g., token address or symbol)"
}),
baseAmount: TokenRawAmount.annotations({
message: () => "baseAmount must be a valid bigint string (e.g., '1000000')"
}),
quoteToken: TokenRawDenom.annotations({
message: () => "quoteToken must be a non-empty string (e.g., token address or symbol)"
}),
quoteAmount: TokenRawAmount.annotations({
message: () => "quoteAmount must be a valid bigint string (e.g., '1000000')"
}),
sourceChannelId: ChannelId.annotations({
message: () => "sourceChannelId must be a non-negative integer"
})
}
export class EVMTransfer extends Schema.Class<EVMTransfer>("EVMTransfer")({
type: RpcType.pipe(
Schema.filter(v => v === "evm"),
Schema.annotations({ message: () => "type must be 'evm'" })
),
...CommonTransferFields,
wethToken: EVMWethToken,
receiver: AddressEvmCanonical.pipe(
Schema.annotations({
message: () =>
"receiver must be a valid EVM canonical address (e.g., 0x followed by 40 hex chars)"
})
),
ucs03address: AddressEvmCanonical.pipe(
Schema.annotations({
message: () =>
"ucs03address must be a valid EVM Zkgm address (e.g., 0x followed by 40 hex chars)"
})
)
}) {}
export class CosmosTransfer extends Schema.Class<CosmosTransfer>("CosmosTransfer")({
type: RpcType.pipe(
Schema.filter(v => v === "cosmos"),
Schema.annotations({ message: () => "type must be 'cosmos'" })
),
...CommonTransferFields,
wethToken: Schema.Null,
receiver: AddressCosmosCanonical.pipe(
Schema.annotations({
message: () =>
"receiver must be a valid Cosmos canonical address (e.g., 0x followed by 40 or 64 hex chars)"
})
),
ucs03address: AddressCosmosCanonical.pipe(
// Changed to hex
Schema.annotations({
message: () =>
"ucs03address must be a valid Cosmos Zkgm address in hex (e.g., 0x followed by 40 or 64 hex chars)"
})
)
}) {}
export class AptosTransfer extends Schema.Class<AptosTransfer>("AptosTransfer")({
type: RpcType.pipe(
Schema.filter(v => v === "aptos"),
Schema.annotations({ message: () => "type must be 'aptos'" })
),
...CommonTransferFields,
wethToken: Schema.Null,
receiver: AddressAptosCanonical.pipe(
Schema.annotations({
message: () =>
"receiver must be a valid Aptos canonical address (e.g., 0x followed by 64 hex chars)"
})
),
ucs03address: AddressAptosCanonical.pipe(
Schema.annotations({
message: () =>
"ucs03address must be a valid Aptos Zkgm address (e.g., 0x followed by 64 hex chars)"
})
)
}) {}
export const TransferSchema = Schema.Union(EVMTransfer, CosmosTransfer, AptosTransfer).annotations({
identifier: "Transfer",
title: "Transfer",
description: "transfer arguments"
})
export type Transfer = Schema.Schema.Type<typeof TransferSchema>
export type EVMTransferType = Schema.Schema.Type<typeof EVMTransfer>
export type CosmosTransferType = Schema.Schema.Type<typeof CosmosTransfer>
export type AptosTransferType = Schema.Schema.Type<typeof AptosTransfer>