Skip to content

Commit

Permalink
Merge pull request #1354 from DA0-DA0/development
Browse files Browse the repository at this point in the history
Deploy Stargaze mainnet and wallet bug fix
  • Loading branch information
NoahSaso authored Aug 29, 2023
2 parents 3340392 + 78c71dc commit c82a102
Show file tree
Hide file tree
Showing 18 changed files with 1,523 additions and 203 deletions.
748 changes: 748 additions & 0 deletions packages/state/contracts/Sg721Base.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/state/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export {
} from './PolytoneListener'
export { PolytoneNoteClient, PolytoneNoteQueryClient } from './PolytoneNote'
export { PolytoneProxyClient, PolytoneProxyQueryClient } from './PolytoneProxy'
export { Sg721BaseClient, Sg721BaseQueryClient } from './Sg721Base'
export { WyndexFactoryClient, WyndexFactoryQueryClient } from './WyndexFactory'
export {
WyndexMultiHopClient,
Expand Down
237 changes: 237 additions & 0 deletions packages/state/recoil/selectors/contracts/Sg721Base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/**
* This file was automatically generated by @cosmwasm/[email protected].
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { selectorFamily } from 'recoil'

import { WithChainId } from '@dao-dao/types'
import {
AllNftInfoResponse,
AllOperatorsResponse,
AllTokensResponse,
ApprovalResponse,
ApprovalsResponse,
CollectionInfoResponse,
ContractInfoResponse,
MinterResponse,
NftInfoResponse,
NumTokensResponse,
OwnerOfResponse,
TokensResponse,
} from '@dao-dao/types/contracts/Sg721Base'

import {
Sg721BaseClient,
Sg721BaseQueryClient,
} from '../../../contracts/Sg721Base'
import { signingCosmWasmClientAtom } from '../../atoms'
import { cosmWasmClientForChainSelector } from '../chain'

type QueryClientParams = WithChainId<{
contractAddress: string
}>

export const queryClient = selectorFamily<
Sg721BaseQueryClient,
QueryClientParams
>({
key: 'sg721BaseQueryClient',
get:
({ contractAddress, chainId }) =>
({ get }) => {
const client = get(cosmWasmClientForChainSelector(chainId))
return new Sg721BaseQueryClient(client, contractAddress)
},
dangerouslyAllowMutability: true,
})

export type ExecuteClientParams = WithChainId<{
contractAddress: string
sender: string
}>

export const executeClient = selectorFamily<
Sg721BaseClient | undefined,
ExecuteClientParams
>({
key: 'sg721BaseExecuteClient',
get:
({ chainId, contractAddress, sender }) =>
({ get }) => {
const client = get(signingCosmWasmClientAtom({ chainId }))
if (!client) return
return new Sg721BaseClient(client, sender, contractAddress)
},
dangerouslyAllowMutability: true,
})

export const ownerOfSelector = selectorFamily<
OwnerOfResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['ownerOf']>
}
>({
key: 'sg721BaseOwnerOf',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.ownerOf(...params)
},
})
export const approvalSelector = selectorFamily<
ApprovalResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['approval']>
}
>({
key: 'sg721BaseApproval',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.approval(...params)
},
})
export const approvalsSelector = selectorFamily<
ApprovalsResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['approvals']>
}
>({
key: 'sg721BaseApprovals',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.approvals(...params)
},
})
export const allOperatorsSelector = selectorFamily<
AllOperatorsResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['allOperators']>
}
>({
key: 'sg721BaseAllOperators',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.allOperators(...params)
},
})
export const numTokensSelector = selectorFamily<
NumTokensResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['numTokens']>
}
>({
key: 'sg721BaseNumTokens',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.numTokens(...params)
},
})
export const contractInfoSelector = selectorFamily<
ContractInfoResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['contractInfo']>
}
>({
key: 'sg721BaseContractInfo',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.contractInfo(...params)
},
})
export const nftInfoSelector = selectorFamily<
NftInfoResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['nftInfo']>
}
>({
key: 'sg721BaseNftInfo',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.nftInfo(...params)
},
})
export const allNftInfoSelector = selectorFamily<
AllNftInfoResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['allNftInfo']>
}
>({
key: 'sg721BaseAllNftInfo',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.allNftInfo(...params)
},
})
export const tokensSelector = selectorFamily<
TokensResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['tokens']>
}
>({
key: 'sg721BaseTokens',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.tokens(...params)
},
})
export const allTokensSelector = selectorFamily<
AllTokensResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['allTokens']>
}
>({
key: 'sg721BaseAllTokens',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.allTokens(...params)
},
})
export const minterSelector = selectorFamily<
MinterResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['minter']>
}
>({
key: 'sg721BaseMinter',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.minter(...params)
},
})
export const collectionInfoSelector = selectorFamily<
CollectionInfoResponse,
QueryClientParams & {
params: Parameters<Sg721BaseQueryClient['collectionInfo']>
}
>({
key: 'sg721BaseCollectionInfo',
get:
({ params, ...queryClientParams }) =>
async ({ get }) => {
const client = get(queryClient(queryClientParams))
return await client.collectionInfo(...params)
},
})
1 change: 1 addition & 0 deletions packages/state/recoil/selectors/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export * as DaoVotingNativeStakedSelectors from './DaoVotingNativeStaked'
export * as PolytoneListenerSelectors from './PolytoneListener'
export * as PolytoneNoteSelectors from './PolytoneNote'
export * as PolytoneProxySelectors from './PolytoneProxy'
export * as Sg721BaseSelectors from './Sg721Base'
export * as WyndexFactorySelectors from './WyndexFactory'
export * as WyndexMultiHopSelectors from './WyndexMultiHop'
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,28 @@ export const InstantiateNftCollection: ActionComponent = (props) => {

setInstantiating(true)
try {
const { contractAddress } = await signingCosmWasmClient.instantiate(
walletAddress,
codeIds.Cw721Base,
instantiateMsg,
'NFT Collection',
CHAIN_GAS_MULTIPLIER
)
const { contractAddress } = codeIds.Cw721Base
? await signingCosmWasmClient.instantiate(
walletAddress,
codeIds.Cw721Base,
instantiateMsg,
'NFT Collection',
CHAIN_GAS_MULTIPLIER
)
: codeIds.Sg721Base
? await signingCosmWasmClient.instantiate(
walletAddress,
codeIds.Sg721Base,
instantiateMsg,
'NFT Collection',
CHAIN_GAS_MULTIPLIER
)
: { contractAddress: undefined }

// Should never happen.
if (!contractAddress) {
throw new Error(t('error.loadingData'))
}

// Update action form data with address.
setValue(props.fieldNamePrefix + 'collectionAddress', contractAddress, {
Expand All @@ -73,6 +88,8 @@ export const InstantiateNftCollection: ActionComponent = (props) => {
} catch (err) {
console.error(err)
toast.error(processError(err))
} finally {
setInstantiating(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const InstantiateNftCollection: ActionComponent<
<InputErrorMessage error={errors?.instantiateMsg?.symbol} />
</div>

{/* TODO(stargaze): Add Stargaze collection info field on for sg721. */}

<Button
className="self-end"
loading={instantiating}
Expand Down
1 change: 1 addition & 0 deletions packages/stateful/components/PfpkNftSelectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const InnerPfpkNftSelectionModal = ({
const image = watch('image')

const [uploadingImage, setUploadingImage] = useState(false)
// TODO(stargaze): support sg721 or prevent from instantiating on stargaze?
const { ready: instantiateAndExecuteReady, instantiateAndExecute } =
useInstantiateAndExecute(
chain.chain_id,
Expand Down
11 changes: 1 addition & 10 deletions packages/stateful/components/dao/CreateDaoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
useThemeContext,
} from '@dao-dao/stateless'
import {
ChainId,
CreateDaoContext,
CreateDaoCustomValidator,
DaoPageMode,
Expand Down Expand Up @@ -740,15 +739,7 @@ export const InnerCreateDaoForm = ({
<p>{t(CreateDaoSubmitValue.Back)}</p>
</Button>
)}
<Button
disabled={
// TODO(stargaze): remove when mainnet contracts deployed
chainId === ChainId.StargazeMainnet
}
loading={creating}
type="submit"
value={submitValue}
>
<Button loading={creating} type="submit" value={submitValue}>
{submitLabel}
</Button>
</div>
Expand Down
59 changes: 59 additions & 0 deletions packages/stateful/hooks/contracts/Sg721Base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable react-hooks/rules-of-hooks */

import { ExecuteResult } from '@cosmjs/cosmwasm-stargate'
import { useCallback } from 'react'
import { useRecoilValueLoadable } from 'recoil'

import { Sg721BaseClient as ExecuteClient } from '@dao-dao/state/contracts/Sg721Base'
import {
ExecuteClientParams,
executeClient,
} from '@dao-dao/state/recoil/selectors/contracts/Sg721Base'
import { useChain } from '@dao-dao/stateless'
import { FunctionKeyOf } from '@dao-dao/types'

import { useSyncWalletSigner } from '../useSyncWalletSigner'

// This hook wrapper lets us easily make hooks out of all execution functions on
// the contract clients, without having to fetch the `executeClient` selector as
// a loadable and add `useCallback` hooks in all the components.
const wrapExecuteHook =
<T extends FunctionKeyOf<ExecuteClient>>(fn: T) =>
(params: Omit<ExecuteClientParams, 'chainId'>) => {
// Make sure we have the signing client for this chain and wallet.
useSyncWalletSigner()

const { chain_id: chainId } = useChain()
const clientLoadable = useRecoilValueLoadable(
executeClient({
...params,
chainId,
})
)
const client =
clientLoadable.state === 'hasValue' ? clientLoadable.contents : undefined

return useCallback(
(...args: Parameters<ExecuteClient[T]>) => {
if (client)
return (
client[fn] as (
...args: Parameters<ExecuteClient[T]>
) => Promise<ExecuteResult>
)(...args)
throw new Error('Wallet signer not set up.')
},
[client]
)
}

export const useTransferNft = wrapExecuteHook('transferNft')
export const useSendNft = wrapExecuteHook('sendNft')
export const useSendNftMultiple = wrapExecuteHook('sendNftMultiple')
export const useApprove = wrapExecuteHook('approve')
export const useRevoke = wrapExecuteHook('revoke')
export const useApproveAll = wrapExecuteHook('approveAll')
export const useRevokeAll = wrapExecuteHook('revokeAll')
export const useMint = wrapExecuteHook('mint')
export const useBurn = wrapExecuteHook('burn')
export const useUpdateCollectionInfo = wrapExecuteHook('updateCollectionInfo')
Loading

2 comments on commit c82a102

@vercel
Copy link

@vercel vercel bot commented on c82a102 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on c82a102 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.