Skip to content

Commit

Permalink
chore(app2): pre commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Mar 3, 2025
1 parent 2dc0dc1 commit ce2da72
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 102 deletions.
68 changes: 34 additions & 34 deletions app2/src/lib/examples/transfer-arguments.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
type EVMTransferInput = {
type: "evm";
baseToken: string;
baseAmount: string;
quoteToken: string;
quoteAmount: string;
sourceChannelId: number;
wethToken: string;
receiver: string;
ucs03address: string;
};
type: "evm"
baseToken: string
baseAmount: string
quoteToken: string
quoteAmount: string
sourceChannelId: number
wethToken: string
receiver: string
ucs03address: string
}

type CosmosTransferInput = {
type: "cosmos";
baseToken: string;
baseAmount: string;
quoteToken: string;
quoteAmount: string;
sourceChannelId: number;
wethToken: null;
receiver: string;
ucs03address: string;
};
type: "cosmos"
baseToken: string
baseAmount: string
quoteToken: string
quoteAmount: string
sourceChannelId: number
wethToken: null
receiver: string
ucs03address: string
}

type AptosTransferInput = {
type: "aptos";
baseToken: string;
baseAmount: string;
quoteToken: string;
quoteAmount: string;
sourceChannelId: number;
wethToken: null;
receiver: string;
ucs03address: string;
};
type: "aptos"
baseToken: string
baseAmount: string
quoteToken: string
quoteAmount: string
sourceChannelId: number
wethToken: null
receiver: string
ucs03address: string
}

export const examples: {
evm: EVMTransferInput;
cosmos: CosmosTransferInput;
aptos: AptosTransferInput;
evm: EVMTransferInput
cosmos: CosmosTransferInput
aptos: AptosTransferInput
} = {
evm: {
type: "evm",
Expand Down Expand Up @@ -72,4 +72,4 @@ export const examples: {
ucs03address: "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
wethToken: null
}
};
}
2 changes: 1 addition & 1 deletion app2/src/lib/schema/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const RpcType = Schema.Union(
Schema.Literal("evm"),
Schema.Literal("cosmos"),
Schema.Literal("aptos")
).annotations({ message: () => "type must be 'evm', 'cosmos', or 'aptos'" });
).annotations({ message: () => "type must be 'evm', 'cosmos', or 'aptos'" })

export class ChainFeatures extends Schema.Class<ChainFeatures>("ChainFeatures")({
channel_list: Schema.Boolean,
Expand Down
2 changes: 1 addition & 1 deletion app2/src/lib/schema/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { Schema } from "effect"
export const ChannelId = Schema.Int.pipe(
Schema.nonNegative({ message: () => "sourceChannelId must be non-negative" }),
Schema.brand("ChannelId")
)
)
9 changes: 6 additions & 3 deletions app2/src/lib/schema/token.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Schema } from "effect"
import { Hex } from "$lib/schema/hex"
import {AddressEvmCanonical} from "$lib/schema/address";
import { AddressEvmCanonical } from "$lib/schema/address"

export const TokenRawDenom = Hex.pipe(Schema.brand("TokenRawDenom"))
export const TokenRawAmount = Schema.BigInt.pipe(Schema.brand("TokenRawAmount"))
export const EVMWethToken = AddressEvmCanonical.pipe(
Schema.annotations({ message: () => "WETH token must be a valid EVM canonical address (e.g., 0x followed by 40 hex chars)" })
);
Schema.annotations({
message: () =>
"WETH token must be a valid EVM canonical address (e.g., 0x followed by 40 hex chars)"
})
)
59 changes: 33 additions & 26 deletions app2/src/lib/schema/transfer-arguments.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
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";
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({
Expand All @@ -20,77 +24,80 @@ const CommonTransferFields = {
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.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)"
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)"
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.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)"
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
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)"
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.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)"
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)"
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({
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 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>;
export type EVMTransferType = Schema.Schema.Type<typeof EVMTransfer>
export type CosmosTransferType = Schema.Schema.Type<typeof CosmosTransfer>
export type AptosTransferType = Schema.Schema.Type<typeof AptosTransfer>
74 changes: 37 additions & 37 deletions app2/src/routes/transfer/validate/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
<!-- src/routes/+page.svelte -->
<script lang="ts">
import {Effect, Schema} from "effect";
import type { RpcType } from "$lib/schema/chain";
import {
AptosTransfer,
CosmosTransfer,
EVMTransfer,
type Transfer
} from "$lib/schema/transfer-arguments";
import {examples} from "$lib/examples/transfer-arguments";
import { Effect, Schema } from "effect"
import type { RpcType } from "$lib/schema/chain"
import {
AptosTransfer,
CosmosTransfer,
EVMTransfer,
type Transfer
} from "$lib/schema/transfer-arguments"
import { examples } from "$lib/examples/transfer-arguments"
type RpcTypeValue = Schema.Schema.Type<typeof RpcType>;
type RpcTypeValue = Schema.Schema.Type<typeof RpcType>
let results: { type: string; data?: Transfer | undefined; error?: string | undefined }[] = [];
let results: Array<{ type: string; data?: Transfer | undefined; error?: string | undefined }> = []
function handleResult(type: RpcTypeValue, parsed: Transfer | undefined, error: unknown) {
if (parsed) {
console.log(`${type} example:`, parsed);
results = [...results, { type, data: parsed, error: undefined }];
} else {
console.error(`${type} example failed:`, error);
results = [...results, { type, error: String(error), data: undefined }];
}
function handleResult(type: RpcTypeValue, parsed: Transfer | undefined, error: unknown) {
if (parsed) {
console.log(`${type} example:`, parsed)
results = [...results, { type, data: parsed, error: undefined }]
} else {
console.error(`${type} example failed:`, error)
results = [...results, { type, error: String(error), data: undefined }]
}
}
function validateEvm() {
const effect = Schema.decode(EVMTransfer)(examples.evm);
Effect.runPromise(effect)
.then((parsed) => handleResult("evm", parsed, undefined))
.catch((error) => handleResult("evm", undefined, error));
}
function validateEvm() {
const effect = Schema.decode(EVMTransfer)(examples.evm)
Effect.runPromise(effect)
.then(parsed => handleResult("evm", parsed, undefined))
.catch(error => handleResult("evm", undefined, error))
}
function validateCosmos() {
const effect = Schema.decode(CosmosTransfer)(examples.cosmos);
Effect.runPromise(effect)
.then((parsed) => handleResult("cosmos", parsed, undefined))
.catch((error) => handleResult("cosmos", undefined, error));
}
function validateCosmos() {
const effect = Schema.decode(CosmosTransfer)(examples.cosmos)
Effect.runPromise(effect)
.then(parsed => handleResult("cosmos", parsed, undefined))
.catch(error => handleResult("cosmos", undefined, error))
}
function validateAptos() {
const effect = Schema.decode(AptosTransfer)(examples.aptos);
Effect.runPromise(effect)
.then((parsed) => handleResult("aptos", parsed, undefined))
.catch((error) => handleResult("aptos", undefined, error));
}
function validateAptos() {
const effect = Schema.decode(AptosTransfer)(examples.aptos)
Effect.runPromise(effect)
.then(parsed => handleResult("aptos", parsed, undefined))
.catch(error => handleResult("aptos", undefined, error))
}
</script>

<main class="p-8 max-w-5xl mx-auto bg-zinc-950 min-h-screen">
Expand Down

0 comments on commit ce2da72

Please sign in to comment.