-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@abstract-money/core": minor | ||
"@abstract-money/react": minor | ||
--- | ||
|
||
Update remote execution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/core/src/actions/account/wallet/execute-remote.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
ManagerTypes, | ||
ProxyExecuteMsgBuilder, | ||
ProxyTypes, | ||
} from '../../../codegen/abstract' | ||
import { ModuleType } from '../../../codegen/gql/graphql' | ||
import { WithCosmWasmSignOptions } from '../../../types/parameters' | ||
import { MaybeArray } from '../../../types/utils' | ||
import { abstractModuleId } from '../../../utils/modules/abstract-module-id' | ||
import { encodeModuleMsg } from '../../../utils/modules/encode-module-msg' | ||
import { CommonModuleNames } from '../../public/types' | ||
import { executeOnRemoteManager } from './execute-on-remote-manager' | ||
import { executeOnRemoteModule } from './execute-on-remote-module' | ||
import { BaseWalletParameters } from './types' | ||
|
||
export type ExecuteOnRemoteParameters = Omit< | ||
WithCosmWasmSignOptions< | ||
BaseWalletParameters & { | ||
hostChainName: string | ||
msgs: MaybeArray<ProxyTypes.CosmosMsgForEmpty> | ||
} | ||
>, | ||
'funds' | ||
> | ||
|
||
/** | ||
* Execute a message on a remote account as the admin of the Account. Must be called by the owner. | ||
* This message will execute on the proxy of the account. | ||
* @param accountId | ||
* @param signingCosmWasmClient | ||
* @param apiUrl | ||
* @param sender | ||
* @param hostChainName | ||
* @param msgs | ||
* @param fee | ||
* @param memo | ||
*/ | ||
export async function executeRemote({ | ||
accountId, | ||
signingCosmWasmClient, | ||
apiUrl, | ||
sender, | ||
msgs, | ||
hostChainName, | ||
fee, | ||
memo, | ||
}: ExecuteOnRemoteParameters) { | ||
const proxyMsg: ProxyTypes.ExecuteMsg = ProxyExecuteMsgBuilder.moduleAction({ | ||
msgs: Array.isArray(msgs) ? msgs : [msgs], | ||
}) | ||
|
||
return executeOnRemoteModule({ | ||
accountId, | ||
signingCosmWasmClient, | ||
apiUrl, | ||
sender, | ||
moduleId: abstractModuleId(CommonModuleNames.PROXY), | ||
moduleType: ModuleType.AccountBase, | ||
moduleMsg: proxyMsg, | ||
hostChainName, | ||
fee, | ||
memo, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
export * from './use-deposit' | ||
export * from './use-create-sub-account' | ||
export * from './use-execute-on-remote' | ||
export * from './use-execute-on-remote-module' | ||
export * from './use-create-remote-account' | ||
export * from './use-create-sub-account' | ||
export * from './use-deposit' | ||
export * from './use-execute' | ||
export * from './use-execute-on-remote-manager' | ||
export * from './use-execute-on-remote-module' | ||
export * from './use-execute-remote' | ||
export * from './use-send-funds-to-remote' | ||
export * from './use-update-settings' | ||
export * from './use-upgrade-module' | ||
export * from './use-withdraw' | ||
export * from './use-update-settings' | ||
export * from './use-send-funds-to-remote' |
39 changes: 39 additions & 0 deletions
39
packages/react/src/hooks/account/wallet/use-execute-on-remote-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { AccountId, AccountWalletClient } from '@abstract-money/core' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { useConfig } from '../../../contexts' | ||
import { ExtractArgsFromParameters } from '../../../types/args' | ||
import { UseMutationParameters } from '../../../types/queries' | ||
|
||
type ExecuteOnRemoteManagerutation = ExtractArgsFromParameters< | ||
Parameters<AccountWalletClient['executeOnRemoteManager']>[0] | ||
> | ||
|
||
export type UseExecuteOnRemoteManagerParameters = { | ||
accountId: AccountId | undefined | ||
chainName: string | undefined | ||
mutation?: UseMutationParameters< | ||
Awaited<ReturnType<AccountWalletClient['executeOnRemoteManager']>>, | ||
unknown, | ||
ExecuteOnRemoteManagerutation | ||
> | ||
} | ||
|
||
export function useExecuteOnRemoteManager({ | ||
accountId, | ||
chainName, | ||
mutation, | ||
}: UseExecuteOnRemoteManagerParameters) { | ||
const config = useConfig() | ||
const walletClient = config.useAccountWalletClient({ | ||
accountId, | ||
chainName: chainName, | ||
}) | ||
|
||
return useMutation(({ args, ...cosmWasmSignOptions }) => { | ||
if (!walletClient) throw new Error('walletClient is not defined') | ||
return walletClient.executeOnRemoteManager({ | ||
...cosmWasmSignOptions, | ||
...args, | ||
}) | ||
}, mutation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters