Skip to content

Commit

Permalink
Attempt using fetch_account + publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
adairrr committed Nov 1, 2024
1 parent 5968660 commit e221e39
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 30 deletions.
7 changes: 4 additions & 3 deletions contracts/{{adapter_name}}/src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
let abstract_client: AbstractClient<Daemon> = AbstractClient::new(chain.clone())?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = abstract_client
.publisher_builder(adapter_namespace)
.build()?;
let publisher_acc = abstract_client.fetch_account(adapter_namespace)?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = Publisher::new(&publisher_acc)?;

if publisher.account().owner()? != chain.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
Expand Down
5 changes: 4 additions & 1 deletion contracts/{{app_name}}/src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
let abstract_client: AbstractClient<Daemon> = AbstractClient::new(chain.clone())?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = abstract_client.publisher_builder(app_namespace).build()?;
let publisher_acc = abstract_client.fetch_account(app_namespace)?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = Publisher::new(&publisher_acc)?;

if publisher.account().owner()? != chain.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
Expand Down
7 changes: 4 additions & 3 deletions contracts/{{standalone_name}}/src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
let abstract_client: AbstractClient<Daemon> = AbstractClient::new(chain.clone())?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = abstract_client
.publisher_builder(standalone_namespace)
.build()?;
let publisher_acc = abstract_client.fetch_account(standalone_namespace)?;

// Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace
let publisher: Publisher<_> = Publisher::new(&publisher_acc)?;

if publisher.account().owner()? != chain.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
Expand Down
15 changes: 9 additions & 6 deletions frontend/app/_components/codegen-contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { Card, CardContent, CardHeader, CardTitle } from "../../components/card"
import { Alert, AlertDescription, AlertTitle } from "../../components/alert"
import { AlertCircle } from "lucide-react"

const EXAMPLE_NEUTRONTESTNET_CW20 = "neutron1sj7exsjqgy460zky8t0u0cvjutu09fswqfq3trssq9z935dryl3snjeekf"


export const CodegenContract: React.FC = () => {
const contractAddress = "juno1ju8k8sqwsqu5k6umrypmtyqu2wqcpnrkf4w4mntvl0javt4nma7s8lzgss"
const chainId = appChain.chainId

const { data: cosmosAccount } = useAccount({ chainId })
Expand All @@ -24,11 +26,12 @@ export const CodegenContract: React.FC = () => {
},
})
const { data: accountsMetadata } = useAccountsMetadataGraphQLQuery({ accountIds: accounts })
const { data: balance, isLoading } = cw20Base.queries.useBalance({
contractAddress,

const { data: exampleCw20Balance, isLoading } = cw20Base.queries.useBalance({
contractAddress: EXAMPLE_NEUTRONTESTNET_CW20,
chainName: appChain.chainName,
args: { address: accountsMetadata?.[0]?.address ?? "" },
options: { enabled: !!accountsMetadata?.[0]?.address && !!contractAddress },
options: { enabled: !!accountsMetadata?.[0]?.address && !!EXAMPLE_NEUTRONTESTNET_CW20 },
})

return (
Expand All @@ -39,11 +42,11 @@ export const CodegenContract: React.FC = () => {
<CardContent>
{isLoading ? (
<p>Loading balance...</p>
) : balance ? (
) : exampleCw20Balance ? (
<div className="bg-gray-100 p-3 rounded-md">
<h3 className="font-semibold mb-2">Balance for address: {accountsMetadata?.[0]?.address ?? ""}</h3>
<p>
<strong>Balance:</strong> {balance.balance}
<strong>Balance:</strong> {exampleCw20Balance.balance}
</p>
</div>
) : (
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/_generated/generated-graphql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
* Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
*/
const documents = {
"\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n": types.AccountsMetadataDocument,
"\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n": types.AccountsMetadataDocument,
};

/**
Expand All @@ -34,7 +34,7 @@ export function gql(source: string): unknown;
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n"): (typeof documents)["\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n }\n }\n"];
export function gql(source: "\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n"): (typeof documents)["\n query AccountsMetadata($ids: [AccountIdWithChain!]!) {\n accountsByIds(ids: $ids) {\n id\n info { name chainId description link }\n address\n owner\n balances {\n amount\n denom\n }\n }\n }\n"];

export function gql(source: string) {
return (documents as any)[source] ?? {};
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/_generated/generated-graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export type AccountsMetadataQueryVariables = Exact<{
}>;


export type AccountsMetadataQuery = { __typename?: 'Query', accountsByIds: Array<{ __typename?: 'AbstractAccount', id: string, address: string, owner?: string | null, info: { __typename?: 'AccountInfo', name?: string | null, chainId: string, description?: string | null, link?: string | null } }> };
export type AccountsMetadataQuery = { __typename?: 'Query', accountsByIds: Array<{ __typename?: 'AbstractAccount', id: string, address: string, owner?: string | null, info: { __typename?: 'AccountInfo', name?: string | null, chainId: string, description?: string | null, link?: string | null }, balances: Array<{ __typename?: 'Balance', amount: string, denom: string }> }> };


export const AccountsMetadataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AccountsMetadata"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"ids"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AccountIdWithChain"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountsByIds"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"ids"},"value":{"kind":"Variable","name":{"kind":"Name","value":"ids"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"info"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}},{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"owner"}}]}}]}}]} as unknown as DocumentNode<AccountsMetadataQuery, AccountsMetadataQueryVariables>;
export const AccountsMetadataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AccountsMetadata"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"ids"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AccountIdWithChain"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"accountsByIds"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"ids"},"value":{"kind":"Variable","name":{"kind":"Name","value":"ids"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"info"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}},{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"owner"}},{"kind":"Field","name":{"kind":"Name","value":"balances"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"denom"}}]}}]}}]}}]} as unknown as DocumentNode<AccountsMetadataQuery, AccountsMetadataQueryVariables>;
10 changes: 5 additions & 5 deletions frontend/app/_hooks/useQueryAccountsById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const ACCOUNTS_METADATA_QUERY = gql(/* GraphQL */ `
info { name chainId description link }
address
owner
balances {
amount
denom
}
}
}
`)
Expand All @@ -18,12 +22,8 @@ export type UseAccountsMetadataArgs = {
accountIds: AccountId[] | undefined
}

export function useAccountsMetadataGraphQLRequest() {
return useGraphQLRequest(ACCOUNTS_METADATA_QUERY)
}

export const useAccountsMetadataGraphQLQuery = ({ accountIds }: UseAccountsMetadataArgs) => {
const request = useAccountsMetadataGraphQLRequest()
const request = useGraphQLRequest(ACCOUNTS_METADATA_QUERY)
return useQuery({
queryFn: () => {
if (!accountIds) throw new Error('Missing `accountIds`')
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "next start",
"lint": "next lint",
"generate": "npm run generate:graz && npm run generate:gql && npm run generate:abstract",
"generate:graz": "graz generate -g -M juno,osmosis -T junotestnet,osmosistestnet",
"generate:graz": "graz generate -g -M neutron,osmosis -T neutrontestnet,osmosistestnet",
"generate:gql": "gql-gen --config codegen.yml",
"generate:abstract": "abstract generate"
},
Expand Down
15 changes: 8 additions & 7 deletions frontend/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { ChainInfo } from '@keplr-wallet/types'
import { mainnetChains } from "graz/chains";
import { testnetChains } from 'graz/chains'

const ABSTRACT_CORS_PROXY_BASE_URL = 'https://rpc-proxy.abstract-os.workers.dev/'

const proxiedUrl = (chainId: string, path: 'rpc' | 'api') =>
`${ABSTRACT_CORS_PROXY_BASE_URL}${chainId}/${path}`
const chainNameToPolachuUrl = (chainName: string, urlType: 'api' | 'rpc') => {
const hyphenatedChainName = chainName.replace('testnet', '-testnet')
return `https://${hyphenatedChainName}-${urlType}.polkachu.com/`
}

export const proxyChainEndpoints = (chain: ChainInfo): ChainInfo =>
({
...chain,
rpc: proxiedUrl(chain.chainId, 'rpc'),
rest: proxiedUrl(chain.chainId, 'api'),
rpc: chainNameToPolachuUrl(chain.chainName, 'rpc'),
rest: chainNameToPolachuUrl(chain.chainName, 'api'),
}) as const

export const appChain = proxyChainEndpoints(mainnetChains.juno)
export const appChain = proxyChainEndpoints(testnetChains.neutrontestnet)

0 comments on commit e221e39

Please sign in to comment.