-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ibc executions #74
Changes from 16 commits
53d9c44
4e57df7
9011d1c
8c77148
91a5d99
93f0c39
2b10228
9e5ac46
9cb0b5d
783b7b0
4d8bf7a
dd15278
ff44076
0de54a8
d4a3b63
ad9464b
a01b01b
c36dcb3
3a67c45
27dfc4c
a947829
6ea3924
ceee727
328ba92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,10 @@ const poppins = Poppins({ | |
weight: ['900', '800', '700'], | ||
variable: '--font-display', | ||
}) | ||
const abstractConfig = createConfig({ provider: cosmosKitProvider }) | ||
const abstractConfig = createConfig({ | ||
provider: cosmosKitProvider, | ||
apiUrl: 'https://api.abstract.money/graphql', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i actually think it makes sense exporting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}) | ||
|
||
export default function RootLayout({ | ||
children, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
'use client' | ||
import { | ||
useAccounts, | ||
useCreateRemoteAccount, | ||
useExecuteOnRemote, | ||
useRemoteAccountIds, | ||
useRemoteHosts, | ||
} from '@abstract-money/react' | ||
import { useChain } from '@cosmos-kit/react' | ||
import { useCallback, useMemo, useState } from 'react' | ||
import { Button } from '../../components/ui/button' | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from '../../components/ui/select' | ||
import { WalletButton } from '../_components/wallet-button' | ||
|
||
const CHAIN_NAME = 'neutron' | ||
export default function RemotePage() { | ||
const { data: remoteHosts, isLoading, refetch } = useRemoteHosts(CHAIN_NAME) | ||
const [chainInput, setChainInput] = useState(remoteHosts?.[0]?.[0]) | ||
|
||
const { address } = useChain(CHAIN_NAME) | ||
|
||
const { data: accounts, status } = useAccounts({ | ||
args: { | ||
chainName: CHAIN_NAME, | ||
owner: address ?? '', | ||
}, | ||
dalechyn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
query: { | ||
enabled: !!address, | ||
}, | ||
}) | ||
|
||
const firstAccount = useMemo(() => accounts?.[0][accounts]) | ||
|
||
const { mutate: createRemoteAccount, isLoading: isCreating } = | ||
useCreateRemoteAccount({ | ||
accountId: firstAccount, | ||
chainName: firstAccount?.chainName, | ||
}) | ||
const { mutate: execRemote, isLoading: isExecuting } = useExecuteOnRemote({ | ||
accountId: firstAccount, | ||
chainName: firstAccount?.chainName, | ||
}) | ||
|
||
const { data: remoteAccountIds } = useRemoteAccountIds({ | ||
args: {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for self in future, in such cases we should default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
accountId: firstAccount, | ||
chainName: firstAccount?.chainName, | ||
}) | ||
|
||
const onCreateClick = useCallback(() => { | ||
if (!chainInput) { | ||
throw new Error('chainInput is undefined') | ||
} | ||
|
||
console.log('creating remote account') | ||
|
||
createRemoteAccount({ | ||
fee: 'auto', | ||
funds: [], | ||
args: { | ||
hostChainName: chainInput, | ||
base_asset: 'juno>juno', | ||
}, | ||
}) | ||
}, [createRemoteAccount, chainInput]) | ||
|
||
const onExecClick = useCallback(() => { | ||
if (!chainInput) { | ||
throw new Error('chainInput is undefined') | ||
} | ||
console.log('executing remote account') | ||
execRemote({ | ||
funds: [], | ||
fee: 'auto', | ||
args: { | ||
hostChainName: chainInput, | ||
managerMsg: { | ||
update_info: { | ||
name: 'test', | ||
}, | ||
}, | ||
}, | ||
}) | ||
}, [execRemote, chainInput]) | ||
|
||
return ( | ||
<> | ||
<h3>Host</h3> | ||
<Select onValueChange={setChainInput} defaultValue={chainInput}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select a host" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{remoteHosts?.map(([chainName]) => { | ||
return ( | ||
<SelectItem key={chainName} value={chainName}> | ||
{chainName} | ||
</SelectItem> | ||
) | ||
})} | ||
</SelectContent> | ||
</Select> | ||
{isLoading && <div>Loading...</div>} | ||
{/*<Input placeholder="chain" value={chainInput} onChange={(e) => setChainInput(e.target.value)} />*/} | ||
<Button onClick={onCreateClick} disabled={!chainInput || isCreating}> | ||
Creat{isCreating ? 'ing' : 'e'} Remote Account {isCreating && '...'} | ||
</Button> | ||
<Button onClick={onExecClick} disabled={!chainInput || isExecuting}> | ||
Updat{isExecuting ? 'ing' : 'e'} Remote Account {isExecuting && '...'} | ||
</Button> | ||
adairrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<WalletButton /> | ||
<h3>Remote Accounts</h3> | ||
<div> | ||
<pre>{JSON.stringify(remoteAccountIds, null, 2)}</pre> | ||
</div> | ||
<Button onClick={() => refetch()}>Refresh</Button> | ||
</> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { IbcClientTypes } from '../../../codegen/abstract' | ||
import { WithCosmWasmSignOptions } from '../../../types/parameters' | ||
import { executeIbcAction } from './execute-ibc-action' | ||
import { BaseWalletParameters } from './types' | ||
|
||
export type CreateRemoteAccountParameters = Omit< | ||
WithCosmWasmSignOptions< | ||
BaseWalletParameters & | ||
Omit< | ||
Extract<IbcClientTypes.ExecuteMsg, { register: unknown }>['register'], | ||
'host_chain' | 'install_modules' | ||
> & { | ||
hostChainName: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to stick with the names that we have in the contract to avoid confusion. we can provide this one as an alias maybe. |
||
// for some reason we cannot use the `install_modules` type from the IbcClientTypes | ||
installModules?: IbcClientTypes.ModuleInstallConfig[] | ||
} | ||
>, | ||
'funds' | ||
> | ||
|
||
/** | ||
* Create a remote account. | ||
* @param accountId | ||
* @param signingCosmWasmClient | ||
* @param apiUrl | ||
* @param sender | ||
* @param hostChainName | ||
* @param registerMsgParams | ||
* @param fee | ||
* @param memo | ||
*/ | ||
export async function createRemoteAccount({ | ||
accountId, | ||
signingCosmWasmClient, | ||
apiUrl, | ||
sender, | ||
hostChainName, | ||
installModules, | ||
fee, | ||
memo, | ||
...registerMsgParams | ||
}: CreateRemoteAccountParameters) { | ||
const registerMsg: IbcClientTypes.ExecuteMsg = { | ||
register: { | ||
host_chain: hostChainName, | ||
install_modules: installModules ?? [], | ||
...registerMsgParams, | ||
}, | ||
} | ||
|
||
return executeIbcAction({ | ||
accountId, | ||
signingCosmWasmClient, | ||
apiUrl, | ||
sender, | ||
msgs: registerMsg, | ||
fee, | ||
memo, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that looks odd, why do we have to do that?