Skip to content

Commit a4fae42

Browse files
authored
Fix whitelist (#5085)
2 parents cbeda96 + fedf8d9 commit a4fae42

File tree

17 files changed

+672
-67
lines changed

17 files changed

+672
-67
lines changed

app2/examples/bond.ts

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/**
2+
* ETH -> UNION
3+
*
4+
* Execute from CLI with `KEY="0xprivatekey" pnpm dlx vite-node ./path/to/bond.ts`
5+
*/
6+
// @ts-ignore
7+
if (typeof BigInt.prototype.toJSON !== "function") {
8+
// @ts-ignore
9+
BigInt.prototype.toJSON = function() {
10+
return this.toString()
11+
}
12+
}
13+
import {
14+
Batch,
15+
Call,
16+
Token,
17+
TokenOrder,
18+
Ucs03,
19+
Ucs05,
20+
Utils,
21+
ZkgmClient,
22+
ZkgmClientRequest,
23+
ZkgmIncomingMessage,
24+
} from "@unionlabs/sdk"
25+
import { Evm, EvmZkgmClient } from "@unionlabs/sdk-evm"
26+
import { ChainRegistry } from "@unionlabs/sdk/ChainRegistry"
27+
import {
28+
EU_ERC20,
29+
EU_FROM_UNION_SOLVER_METADATA,
30+
EU_LST,
31+
ON_ZKGM_CALL_PROXY,
32+
U_BANK,
33+
U_ERC20,
34+
U_TO_UNION_SOLVER_METADATA,
35+
} from "@unionlabs/sdk/Constants"
36+
import { UniversalChainId } from "@unionlabs/sdk/schema/chain"
37+
import { ChannelId } from "@unionlabs/sdk/schema/channel"
38+
import { HexFromJson } from "@unionlabs/sdk/schema/hex"
39+
import { Effect, Logger, pipe, Schema } from "effect"
40+
import { http } from "viem"
41+
import { privateKeyToAccount } from "viem/accounts"
42+
import { holesky } from "viem/chains"
43+
44+
const JsonFromBase64 = Schema.compose(
45+
Schema.StringFromBase64,
46+
Schema.parseJson(),
47+
)
48+
49+
const ETHEREUM_CHAIN_ID = UniversalChainId.make("ethereum.17000")
50+
const UNION_CHAIN_ID = UniversalChainId.make("union.union-testnet-10")
51+
const SOURCE_CHANNEL_ID = ChannelId.make(1) // FIXME
52+
const UCS03_MINTER = Ucs05.EvmDisplay.make({
53+
address: "0x5fbe74a283f7954f10aa04c2edf55578811aeb03",
54+
})
55+
const MIN_MINT_AMOUNT = 1n
56+
const VIEM_CHAIN = holesky
57+
const RPC_URL = "https://rpc.17000.ethereum.chain.kitchen"
58+
const SENDER = Ucs05.EvmDisplay.make({
59+
address: "0x06627714f3F17a701f7074a12C02847a5D2Ca487",
60+
})
61+
const EU_STAKING_HUB = Ucs05.CosmosDisplay.make({
62+
address: "union1eueueueu9var4yhdruyzkjcsh74xzeug6ckyy60hs0vcqnzql2hq0lxc2f", // FIXME
63+
})
64+
65+
const VIEM_ACCOUNT = privateKeyToAccount(
66+
process.env.KEY as any,
67+
)
68+
69+
const sendBond = Effect.gen(function*() {
70+
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
71+
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
72+
73+
const eu_staking_hub = yield* Ucs05.anyDisplayToZkgm(EU_STAKING_HUB)
74+
const on_zkgm_call_proxy = yield* Ucs05.anyDisplayToZkgm(ON_ZKGM_CALL_PROXY)
75+
const ucs03_minter = yield* Ucs05.anyDisplayToZkgm(UCS03_MINTER)
76+
const eu_lst = yield* Ucs05.anyDisplayToZkgm(EU_LST)
77+
78+
const tokenOrder = yield* TokenOrder.make({
79+
source: ethereumChain,
80+
destination: unionChain,
81+
sender: SENDER,
82+
receiver: ON_ZKGM_CALL_PROXY,
83+
baseToken: U_ERC20,
84+
baseAmount: 1n,
85+
quoteToken: U_BANK,
86+
quoteAmount: 1n,
87+
kind: "solve",
88+
metadata: U_TO_UNION_SOLVER_METADATA,
89+
version: 2,
90+
})
91+
92+
const bondCall = yield* pipe(
93+
{
94+
mint_to: on_zkgm_call_proxy,
95+
min_mint_amount: MIN_MINT_AMOUNT,
96+
} as const,
97+
Schema.encode(JsonFromBase64),
98+
Effect.map((msg) => ({
99+
contract: eu_staking_hub,
100+
msg,
101+
funds: [{
102+
denom: tokenOrder.quoteToken.address,
103+
amount: tokenOrder.quoteAmount,
104+
}],
105+
call_action: "call_proxy",
106+
} as const)),
107+
Effect.flatMap(Schema.decode(HexFromJson)),
108+
Effect.map((contractCalldata) =>
109+
Call.make({
110+
sender: SENDER,
111+
eureka: false,
112+
contractAddress: ON_ZKGM_CALL_PROXY,
113+
contractCalldata,
114+
})
115+
),
116+
)
117+
118+
const increaseAllowanceCall = yield* pipe(
119+
{
120+
spender: ucs03_minter,
121+
amount: MIN_MINT_AMOUNT,
122+
} as const,
123+
Schema.encode(JsonFromBase64),
124+
Effect.map((msg) => ({
125+
contract: eu_lst,
126+
msg,
127+
funds: [],
128+
call_action: "direct",
129+
} as const)),
130+
Effect.flatMap(Schema.decode(HexFromJson)),
131+
Effect.map((contractCalldata) =>
132+
Call.make({
133+
sender: SENDER,
134+
eureka: false,
135+
contractAddress: ON_ZKGM_CALL_PROXY,
136+
contractCalldata,
137+
})
138+
),
139+
)
140+
141+
const salt = yield* Utils.generateSalt("cosmos")
142+
143+
const sendCall = yield* pipe(
144+
TokenOrder.make({
145+
source: unionChain,
146+
destination: ethereumChain,
147+
sender: ON_ZKGM_CALL_PROXY, // FIXME: foundation multisig
148+
receiver: SENDER,
149+
baseToken: Token.Cw20.make({ address: EU_LST.address }),
150+
baseAmount: MIN_MINT_AMOUNT,
151+
quoteToken: EU_ERC20,
152+
quoteAmount: MIN_MINT_AMOUNT,
153+
kind: "solve",
154+
metadata: EU_FROM_UNION_SOLVER_METADATA,
155+
version: 2,
156+
}),
157+
Effect.flatMap(TokenOrder.encodeV2),
158+
Effect.flatMap(Schema.encode(Ucs03.Ucs03WithInstructionFromHex)),
159+
Effect.tap((instr) => Effect.log("instr:", instr)),
160+
Effect.map((instruction) => ({
161+
path: 0n,
162+
channel_id: 19,
163+
salt,
164+
instruction,
165+
} as const)),
166+
Effect.flatMap(Schema.encode(JsonFromBase64)),
167+
Effect.map((msg) => ({
168+
contract: ucs03_minter,
169+
msg,
170+
funds: [],
171+
call_action: "direct",
172+
} as const)),
173+
Effect.flatMap(Schema.decode(HexFromJson)),
174+
Effect.map((contractCalldata) =>
175+
Call.make({
176+
sender: SENDER,
177+
eureka: false,
178+
contractAddress: ON_ZKGM_CALL_PROXY,
179+
contractCalldata,
180+
})
181+
),
182+
)
183+
184+
const batch = Batch.make([
185+
tokenOrder,
186+
bondCall,
187+
increaseAllowanceCall,
188+
sendCall,
189+
])
190+
191+
const request = ZkgmClientRequest.make({
192+
source: ethereumChain,
193+
destination: unionChain,
194+
channelId: SOURCE_CHANNEL_ID,
195+
ucs03Address: UCS03_MINTER.address,
196+
instruction: batch,
197+
})
198+
199+
const client = yield* ZkgmClient.ZkgmClient
200+
201+
const response = yield* client.execute(request)
202+
yield* Effect.log("Submission TX Hash:", response.txHash)
203+
204+
const receipt = yield* response.waitFor(
205+
ZkgmIncomingMessage.LifecycleEvent.$is("EvmTransactionReceiptComplete"),
206+
)
207+
208+
yield* Effect.log("Receipt:", receipt)
209+
}).pipe(
210+
Effect.provide(EvmZkgmClient.layerWithoutWallet),
211+
Effect.provide(Evm.WalletClient.Live({
212+
account: VIEM_ACCOUNT,
213+
chain: VIEM_CHAIN,
214+
transport: http(RPC_URL),
215+
})),
216+
Effect.provide(Evm.PublicClient.Live({
217+
chain: VIEM_CHAIN,
218+
transport: http(RPC_URL),
219+
})),
220+
Effect.provide(ChainRegistry.Default),
221+
Effect.provide(Logger.replace(
222+
Logger.defaultLogger,
223+
Logger.prettyLogger({
224+
stderr: true,
225+
colors: true,
226+
mode: "tty",
227+
}),
228+
)),
229+
)
230+
231+
Effect.runPromise(sendBond)
232+
.then(console.log)
233+
.catch(console.error)

app2/examples/unbond.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* ETH -> UNION
3+
*
4+
* Execute from CLI with `KEY="0xprivatekey" pnpm dlx vite-node ./path/to/bond.ts`
5+
*/
6+
// @ts-ignore
7+
if (typeof BigInt.prototype.toJSON !== "function") {
8+
// @ts-ignore
9+
BigInt.prototype.toJSON = function() {
10+
return this.toString()
11+
}
12+
}
13+
import {
14+
Batch,
15+
Call,
16+
TokenOrder,
17+
Ucs05,
18+
ZkgmClient,
19+
ZkgmClientRequest,
20+
ZkgmIncomingMessage,
21+
} from "@unionlabs/sdk"
22+
import { Evm, EvmZkgmClient } from "@unionlabs/sdk-evm"
23+
import { ChainRegistry } from "@unionlabs/sdk/ChainRegistry"
24+
import {
25+
ON_ZKGM_CALL_PROXY,
26+
U_BANK,
27+
U_ERC20,
28+
U_TO_UNION_SOLVER_METADATA,
29+
} from "@unionlabs/sdk/Constants"
30+
import { UniversalChainId } from "@unionlabs/sdk/schema/chain"
31+
import { ChannelId } from "@unionlabs/sdk/schema/channel"
32+
import { HexFromJson } from "@unionlabs/sdk/schema/hex"
33+
import { Effect, Logger, pipe, Schema } from "effect"
34+
import { http } from "viem"
35+
import { privateKeyToAccount } from "viem/accounts"
36+
import { holesky } from "viem/chains"
37+
38+
const JsonFromBase64 = Schema.compose(
39+
Schema.StringFromBase64,
40+
Schema.parseJson(),
41+
)
42+
43+
const AMOUNT = 1n
44+
const ETHEREUM_CHAIN_ID = UniversalChainId.make("ethereum.17000")
45+
const UNION_CHAIN_ID = UniversalChainId.make("union.union-testnet-10")
46+
const SOURCE_CHANNEL_ID = ChannelId.make(1) // FIXME
47+
const UCS03_MINTER = Ucs05.EvmDisplay.make({
48+
address: "0x5fbe74a283f7954f10aa04c2edf55578811aeb03",
49+
})
50+
const VIEM_CHAIN = holesky
51+
const RPC_URL = "https://rpc.17000.ethereum.chain.kitchen"
52+
const SENDER = Ucs05.EvmDisplay.make({
53+
address: "0x06627714f3F17a701f7074a12C02847a5D2Ca487",
54+
})
55+
const EU_STAKING_HUB = Ucs05.CosmosDisplay.make({
56+
address: "union1eueueueu9var4yhdruyzkjcsh74xzeug6ckyy60hs0vcqnzql2hq0lxc2f", // FIXME
57+
})
58+
59+
const VIEM_ACCOUNT = privateKeyToAccount(
60+
process.env.KEY as any,
61+
)
62+
63+
const sendUnbond = Effect.gen(function*() {
64+
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
65+
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
66+
67+
const eu_staking_hub = yield* Ucs05.anyDisplayToZkgm(EU_STAKING_HUB)
68+
69+
const tokenOrder = yield* TokenOrder.make({
70+
source: ethereumChain,
71+
destination: unionChain,
72+
sender: SENDER,
73+
receiver: ON_ZKGM_CALL_PROXY,
74+
baseToken: U_ERC20,
75+
baseAmount: AMOUNT,
76+
quoteToken: U_BANK,
77+
quoteAmount: AMOUNT,
78+
kind: "solve",
79+
metadata: U_TO_UNION_SOLVER_METADATA,
80+
version: 2,
81+
})
82+
83+
const unbondCall = yield* pipe(
84+
{ amount: tokenOrder.quoteAmount } as const,
85+
Schema.encode(JsonFromBase64),
86+
Effect.map((msg) => ({
87+
contract: eu_staking_hub,
88+
msg,
89+
funds: [],
90+
call_action: "call_proxy",
91+
} as const)),
92+
Effect.flatMap(Schema.decode(HexFromJson)),
93+
Effect.map((contractCalldata) =>
94+
Call.make({
95+
sender: SENDER,
96+
eureka: false,
97+
contractAddress: ON_ZKGM_CALL_PROXY,
98+
contractCalldata,
99+
})
100+
),
101+
)
102+
103+
const batch = Batch.make([
104+
tokenOrder,
105+
unbondCall,
106+
])
107+
108+
const request = ZkgmClientRequest.make({
109+
source: ethereumChain,
110+
destination: unionChain,
111+
channelId: SOURCE_CHANNEL_ID,
112+
ucs03Address: UCS03_MINTER.address,
113+
instruction: batch,
114+
})
115+
116+
const client = yield* ZkgmClient.ZkgmClient
117+
118+
const response = yield* client.execute(request)
119+
yield* Effect.log("Submission TX Hash:", response.txHash)
120+
121+
const receipt = yield* response.waitFor(
122+
ZkgmIncomingMessage.LifecycleEvent.$is("EvmTransactionReceiptComplete"),
123+
)
124+
125+
yield* Effect.log("Receipt:", receipt)
126+
}).pipe(
127+
Effect.provide(EvmZkgmClient.layerWithoutWallet),
128+
Effect.provide(Evm.WalletClient.Live({
129+
account: VIEM_ACCOUNT,
130+
chain: VIEM_CHAIN,
131+
transport: http(RPC_URL),
132+
})),
133+
Effect.provide(Evm.PublicClient.Live({
134+
chain: VIEM_CHAIN,
135+
transport: http(RPC_URL),
136+
})),
137+
Effect.provide(ChainRegistry.Default),
138+
Effect.provide(Logger.replace(
139+
Logger.defaultLogger,
140+
Logger.prettyLogger({
141+
stderr: true,
142+
colors: true,
143+
mode: "tty",
144+
}),
145+
)),
146+
)
147+
148+
Effect.runPromise(sendUnbond)
149+
.then(console.log)
150+
.catch(console.error)

0 commit comments

Comments
 (0)