1+ import { AccountType , BparamsMsgValue } from "@namada/types" ;
12import { defaultAccountAtom } from "atoms/accounts" ;
23import { createOsmosisSwapTxAtom } from "atoms/transfer/atoms" ;
34import BigNumber from "bignumber.js" ;
45import invariant from "invariant" ;
56import { useAtomValue } from "jotai" ;
67import { broadcastTransaction , signTx } from "lib/query" ;
78import { useEffect } from "react" ;
9+ import { getSdkInstance } from "utils/sdk" ;
810
911export const OsmosisSwap : React . FC = ( ) => {
1012 const { mutateAsync : performOsmosisSwap } = useAtomValue (
@@ -29,7 +31,6 @@ export const OsmosisSwap: React.FC = () => {
2931 } ;
3032 const params = {
3133 transfer,
32- // We want to receive TIA
3334 outputDenom : "transfer/channel-14/uatom" ,
3435 recipient : "tnam1qz4u7j7dkxj5wv9xuwy2qemaeeqd450ysgl7pq0r" ,
3536 overflow : "tnam1qz4u7j7dkxj5wv9xuwy2qemaeeqd450ysgl7pq0r" ,
@@ -62,6 +63,69 @@ export const OsmosisSwap: React.FC = () => {
6263
6364 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6465 ( window as any ) . osmosisSwap = handleOsmosisSwap ;
66+
67+ const handleOsmosisShieldedSwap = async ( ) : Promise < void > => {
68+ invariant ( account . data , "No transparent account is found" ) ;
69+ const a = account . data ;
70+
71+ let bparams : BparamsMsgValue [ ] | undefined ;
72+ if ( a . type === AccountType . Ledger ) {
73+ const sdk = await getSdkInstance ( ) ;
74+ const ledger = await sdk . initLedger ( ) ;
75+ bparams = await ledger . getBparams ( ) ;
76+ ledger . closeTransport ( ) ;
77+ }
78+
79+ const transfer = {
80+ amountInBaseDenom : BigNumber ( 100 ) ,
81+ // osmosis channel
82+ channelId : "channel-13" ,
83+ portId : "transfer" ,
84+ token : "tnam1pkxwqwhjkulpd2jmc5hmetj6hkfpf0cdfuzfx70c" ,
85+ source :
86+ "03d5935721000000803fe3d7a9c42c483e5c3840c13eb7dadec2e420f850a769342a2786b58c86215d1fd1ca29f99d94bf033533a30b3461a2dacc4d0f968a080a2a335a085525d18b29f5e59e281a297c35d62299ff82a1525ae327862aca92d01faceebe375af12530bf9eff49e6f90c2eb554db591b1fc30694c716635f0bd2050682d6eeb6a2c5438dd7725495fb866d76db12de4e44ad9be424af57d12c8c19a6dc8664825d8701000000000000000000000000000000000000000000000000000000000000000001f3d7b291d734e35aefd38601bc947778d3adefc9ee2defd8d745fe124e850d0b" ,
87+ gasSpendingKey :
88+ "03d5935721000000803fe3d7a9c42c483e5c3840c13eb7dadec2e420f850a769342a2786b58c86215d1fd1ca29f99d94bf033533a30b3461a2dacc4d0f968a080a2a335a085525d18b29f5e59e281a297c35d62299ff82a1525ae327862aca92d01faceebe375af12530bf9eff49e6f90c2eb554db591b1fc30694c716635f0bd2050682d6eeb6a2c5438dd7725495fb866d76db12de4e44ad9be424af57d12c8c19a6dc8664825d8701000000000000000000000000000000000000000000000000000000000000000001f3d7b291d734e35aefd38601bc947778d3adefc9ee2defd8d745fe124e850d0b" ,
89+ receiver :
90+ "osmo1lrlqeq38ephw8mz0c3uzfdpt4fh3fr0s2atur5n33md90m4wx3mqmz7fq6" ,
91+ bparams,
92+ refundTarget : "tnam1qqshvryx9pngpk7mmzpzkjkm6klelgusuvmkc0uz" ,
93+ } ;
94+ const params = {
95+ transfer,
96+ outputDenom : "transfer/channel-13/uosmo" ,
97+ recipient :
98+ "znam17k7jw0wmvzdzmfm46m8600t9cah5mjl6se75cu9jvwxywk75k3kmxehmxk7wha62l35puzl6srd" ,
99+ overflow : "tnam1qqshvryx9pngpk7mmzpzkjkm6klelgusuvmkc0uz" ,
100+ slippage : { 0 : "1799" } ,
101+ localRecoveryAddr : "osmo18st0wqx84av8y6xdlss9d6m2nepyqwj6n3q7js" ,
102+ osmosisRestRpc : "https://osmosis-rest.publicnode.com" ,
103+ } ;
104+
105+ try {
106+ const encodedTxData = await performOsmosisSwap ( {
107+ signer : {
108+ publicKey : account . data . publicKey ! ,
109+ address : account . data . address ! ,
110+ } ,
111+ account : account . data ,
112+ params : [ params ] ,
113+ gasConfig : {
114+ gasLimit : BigNumber ( 75000 ) ,
115+ gasPriceInMinDenom : BigNumber ( 0.000001 ) ,
116+ gasToken : "tnam1qy440ynh9fwrx8aewjvvmu38zxqgukgc259fzp6h" ,
117+ } ,
118+ } ) ;
119+
120+ const signedTxs = await signTx ( encodedTxData , account . data . address ! ) ;
121+ await broadcastTransaction ( encodedTxData , signedTxs ) ;
122+ } catch ( error ) {
123+ console . error ( "Error performing Osmosis swap:" , error ) ;
124+ }
125+ } ;
126+
127+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128+ ( window as any ) . osmosisShieldedSwap = handleOsmosisShieldedSwap ;
65129 } , [ account . data ] ) ;
66130
67131 return < > </ > ;
0 commit comments