-
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.
Merge pull request #142 from AbstractSDK/adair/fix-init-2
Clarify instantiate2 address prediction methods
- Loading branch information
Showing
20 changed files
with
259 additions
and
222 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,7 @@ | ||
--- | ||
"@abstract-money/core": minor | ||
"@abstract-money/react": minor | ||
"wagemos-graz-nextjs": patch | ||
--- | ||
|
||
Rename instantiate2 methods to predict and remove 'base' from AccountAddress retrieval |
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
54 changes: 0 additions & 54 deletions
54
packages/core/src/actions/account/public/get-account-instantiate2-address-from-api.ts
This file was deleted.
Oops, something went wrong.
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
78 changes: 78 additions & 0 deletions
78
packages/core/src/actions/public/get-account-instantiate2-address-from-api.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,78 @@ | ||
import { | ||
abstractModuleId, | ||
chainIdToName, | ||
getInstantiate2Address, | ||
getInstantiate2AddressWithAccountId, | ||
} from '@abstract-money/core' | ||
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' | ||
import { P, match } from 'ts-pattern' | ||
import { RegistryTypes } from '../../codegen/abstract' | ||
import { getRegistryAddressFromApi } from '../get-registry-address-from-api' | ||
import { getAppModuleCodeIdFromRegistry } from './get-app-module-code-id-from-registry' | ||
import { CommonModuleNames } from './types' | ||
|
||
export type GetAccountInstantiate2AddressFromApi = { | ||
cosmWasmClient: CosmWasmClient | ||
apiUrl: string | ||
creator: string | ||
salt: | ||
| { | ||
accountId: RegistryTypes.AccountId | ||
} | ||
| { | ||
custom: string | Uint8Array | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve the calculated manager init2 address from the api. | ||
* @param accountId | ||
* @param cosmWasmClient | ||
* @param apiUrl | ||
* @param creator - the creator address | ||
* @param salt - the (optional) salt to use for the address calculation. If not provided, will use the accountId salt. | ||
*/ | ||
export async function getAccountInstantiate2AddressFromApi({ | ||
cosmWasmClient, | ||
apiUrl, | ||
creator, | ||
salt, | ||
}: GetAccountInstantiate2AddressFromApi): Promise<string> { | ||
const chainId = await cosmWasmClient.getChainId() | ||
const chainName = chainIdToName(chainId) | ||
|
||
const registryAddress = await getRegistryAddressFromApi({ | ||
apiUrl, | ||
chainName, | ||
}) | ||
|
||
const accountCodeId = await getAppModuleCodeIdFromRegistry({ | ||
moduleId: abstractModuleId(CommonModuleNames.ACCOUNT), | ||
version: 'latest', | ||
cosmWasmClient, | ||
registryAddress, | ||
}) | ||
|
||
const moduleCodeDetails = await cosmWasmClient.getCodeDetails(accountCodeId) | ||
|
||
return await match(salt) | ||
.with( | ||
{ accountId: P.select() }, | ||
async (accountId) => | ||
await getInstantiate2AddressWithAccountId( | ||
creator, | ||
moduleCodeDetails.checksum, | ||
accountId, | ||
), | ||
) | ||
.with( | ||
{ custom: P.select() }, | ||
async (customSalt) => | ||
await getInstantiate2Address( | ||
creator, | ||
moduleCodeDetails.checksum, | ||
customSalt, | ||
), | ||
) | ||
.exhaustive() | ||
} |
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
21 changes: 8 additions & 13 deletions
21
packages/core/src/utils/account-factory/parse-create-account-execute-result.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
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
Oops, something went wrong.