@@ -9,7 +9,17 @@ import { Effect, Logger } from "effect"
9
9
import { getFullnodeUrl } from "@mysten/sui/client"
10
10
import { PublicClient , WalletClient , writeContract , readCoinMetadata , readCoinBalances , sendInstruction } from "../src/Sui.js"
11
11
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
12
+ import * as ZkgmClientRequest from "@unionlabs/sdk/ZkgmClientRequest"
13
+ import * as ZkgmClientResponse from "@unionlabs/sdk/ZkgmClientResponse"
14
+ import { ChannelId } from "@unionlabs/sdk/schema/channel"
15
+ import * as ZkgmIncomingMessage from "@unionlabs/sdk/ZkgmIncomingMessage"
16
+ import * as ZkgmClient from "@unionlabs/sdk/ZkgmClient"
17
+ import { layerWithoutWallet } from "../src/SuiZkgmClient.js"
18
+
12
19
import { Transaction } from "@mysten/sui/transactions"
20
+ import * as TokenOrder from "@unionlabs/sdk/TokenOrder"
21
+ import { UniversalChainId } from "@unionlabs/sdk/schema/chain"
22
+ import { ChainRegistry } from "@unionlabs/sdk/ChainRegistry"
13
23
14
24
const MNEMONIC = process . env . MNEMONIC ?? "fix auto gallery heart practice drip joke nice decline lift attend bread"
15
25
const RECIPIENT = process . env . RECIPIENT ?? "0x03ff9dd9e093387bdd4432c6a3eb6a1bd5a8f39a530042ac7efe576f18d3232b"
@@ -18,38 +28,65 @@ const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
18
28
19
29
20
30
const program = Effect . gen ( function * ( ) {
31
+ const source = yield * ChainRegistry . byUniversalId (
32
+ UniversalChainId . make ( "ethereum.17000" ) ,
33
+ )
34
+
35
+ console . log ( "source" , source )
36
+ const destination = yield * ChainRegistry . byUniversalId (
37
+ UniversalChainId . make ( "ethereum.11155111" ) ,
38
+ )
21
39
const { client } = yield * PublicClient
22
- yield * Effect . log ( "Sui public client initialized" , client . network )
23
- const meta = yield * readCoinMetadata ( "0x2::sui::SUI" as any )
24
- yield * Effect . log ( "SUI metadata" , meta )
25
-
26
- yield * Effect . log ( "keypair.getPublicKey().toSuiAddress()" , keypair . getPublicKey ( ) . toSuiAddress ( ) )
27
- const balances = yield * readCoinBalances ( "0x2::sui::SUI" as any , keypair . getPublicKey ( ) . toSuiAddress ( ) as any )
28
- yield * Effect . log ( "SUI balances" , balances )
29
-
30
-
31
- const wallet = yield * WalletClient
32
- const amountMist = 10_000_000n // 0.01 SUI
33
-
34
- const tx = new Transaction ( )
35
- const coin = tx . splitCoins ( tx . gas , [ tx . pure . u64 ( amountMist ) ] )
36
- const recipient = tx . pure . address ( RECIPIENT )
37
-
38
- const res = yield * writeContract (
39
- client ,
40
- keypair ,
41
- "0x2" , // packageId: Sui framework
42
- "transfer" , // module: sui::transfer
43
- "public_transfer" , // function
44
- [ "0x2::coin::Coin<0x2::sui::SUI>" ] , // type arg T
45
- [ coin , recipient ] , // (obj: T, recipient: address)
46
- tx ,
40
+
41
+ const tokenOrder = yield * TokenOrder . make ( {
42
+ source,
43
+ destination,
44
+ sender : "0x06627714f3F17a701f7074a12C02847a5D2Ca487" ,
45
+ receiver : "0x50A22f95bcB21E7bFb63c7A8544AC0683dCeA302" ,
46
+ // LINK on Holesky
47
+ baseToken : "0x685ce6742351ae9b618f383883d6d1e0c5a31b4b" ,
48
+ baseAmount : 10n ,
49
+ // Holesky LINK on Sepolia
50
+ quoteToken : "0x80fdbf104ec58a527ec40f7b03f88c404ef4ba63" ,
51
+ quoteAmount : 10n ,
52
+ kind : "escrow" ,
53
+ metadata : undefined ,
54
+ version : 2 ,
55
+ } )
56
+
57
+ yield * Effect . log ( "Token Order V2" , tokenOrder )
58
+
59
+ const request = ZkgmClientRequest . make ( {
60
+ source,
61
+ destination,
62
+ channelId : ChannelId . make ( 2 ) ,
63
+ ucs03Address : "0x5fbe74a283f7954f10aa04c2edf55578811aeb03" ,
64
+ kind : "simulateAndExecute" ,
65
+ instruction : tokenOrder ,
66
+ } )
67
+
68
+ const zkgmClient = yield * ZkgmClient . ZkgmClient
69
+
70
+ // NOTE: 1. switch chain is assumed
71
+ // NOTE: 2. write in progress
72
+
73
+ const response : ZkgmClientResponse . ZkgmClientResponse = yield * zkgmClient . execute ( request )
74
+
75
+ // NOTE: 3. write complete (with tx hash)
76
+
77
+ yield * Effect . log ( "Submission Hash" , response . txHash )
78
+
79
+ const completion = yield * response . waitFor (
80
+ ZkgmIncomingMessage . LifecycleEvent . $is ( "EvmTransactionReceiptComplete" ) ,
47
81
)
48
82
49
- yield * Effect . log ( "Transfer submitted" , res )
83
+ // NOTE: 4. tx complete
84
+
85
+ yield * Effect . log ( "Completion" , completion )
50
86
51
87
52
88
} ) . pipe (
89
+ Effect . provide ( layerWithoutWallet ) ,
53
90
Effect . provide ( PublicClient . Live ( { url : getFullnodeUrl ( "testnet" ) } ) ) ,
54
91
Effect . provide (
55
92
WalletClient . Live ( {
@@ -59,6 +96,7 @@ const program = Effect.gen(function* () {
59
96
} ) ,
60
97
) ,
61
98
99
+ Effect . provide ( ChainRegistry . Default ) ,
62
100
Effect . provide ( Logger . replace ( Logger . defaultLogger , Logger . prettyLoggerDefault ) ) ,
63
101
)
64
102
0 commit comments