-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathfetch-recommended-channels-legacy.ts
99 lines (84 loc) · 2.59 KB
/
fetch-recommended-channels-legacy.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
import { parseArgs } from "node:util"
import { consola } from "scripts/logger"
import {
getChannelInfo,
getQuoteToken,
getRecommendedChannels
} from "#query/offchain/ucs03-channels"
const { values } = parseArgs({
args: process.argv.slice(2),
options: {
"private-key": { type: "string" },
"estimate-gas": { type: "boolean", default: false }
}
})
const PRIVATE_KEY = values["private-key"]
// const evmAccount = privateKeyToAccount(`0x${PRIVATE_KEY}`)
// const sepoliaClient = createUnionClient({
// chainId: "11155111",
// account: evmAccount,
// transport: fallback([
// http("https://rpc.11155111.sepolia.chain.kitchen"),
// http(holesky?.rpcUrls.default.http.at(0))
// ])
// })
let channels = await getRecommendedChannels()
const LINK_CONTRACT_ADDRESS = "0x685cE6742351ae9b618F383883D6d1e0c5A31B4B"
const LINK_CONTRACT_ADDRESS_SEPOLIA = "0x44799296211290262fd6b22a07a0fa13414caddc"
let channel = getChannelInfo("11155111", "17000", channels)
if (channel === null) {
consola.info("no channel found")
process.exit(1)
}
consola.info({ channel })
let quoteToken = await getQuoteToken("11155111", LINK_CONTRACT_ADDRESS_SEPOLIA, channel)
if (quoteToken.isErr()) {
consola.info("could not get quote token")
process.exit(1)
}
if (quoteToken.value.type === "NO_QUOTE_AVAILABLE") {
consola.info("no quote token available")
process.exit(1)
}
console.log(JSON.stringify(quoteToken.value))
let channel2 = getChannelInfo("17000", "11155111", channels)
if (channel2 === null) {
consola.info("no channel found")
process.exit(1)
}
consola.info({ channel })
let quoteToken2 = await getQuoteToken("17000", LINK_CONTRACT_ADDRESS, channel2)
if (quoteToken2.isErr()) {
consola.info("could not get quote token")
process.exit(1)
}
if (quoteToken2.value.type === "NO_QUOTE_AVAILABLE") {
consola.info("no quote token available")
process.exit(1)
}
console.log(JSON.stringify(quoteToken2.value))
/**
const approveResponse = await evmApproveTransferAsset(client, {
amount: 1n,
denomAddress: LINK_CONTRACT_ADDRESS,
receiver: `0x${channel.source_port_id}`
})
if (approveResponse.isErr()) {
consola.error(approveResponse)
}
consola.info("approval", approveResponse.value)
const transfer = await client.transferAssetNew({
baseToken: LINK_CONTRACT_ADDRESS,
baseAmount: 1n,
quoteToken: LINK_CONTRACT_ADDRESS, //wrong!
quoteAmount: 1n,
receiver: "0x153919669Edc8A5D0c8D1E4507c9CE60435A1177",
sourceChannelId: channel.source_channel_id,
ucs03address: `0x${channel.source_port_id}`
})
if (transfer.isErr()) {
console.error(transfer.error)
process.exit(1)
}
consola.info(transfer.value)
*/