Skip to content

Commit cadb381

Browse files
committed
feat: authz helpers, instantiate2 acc address prediction
1 parent 217de4d commit cadb381

11 files changed

+88
-7
lines changed

.changeset/spicy-shoes-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@abstract-money/core": patch
3+
---
4+
5+
Added authz utils and util to retrieve account address before creation.

packages/core/abstract.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ import { registry, vanilla } from '@abstract-money/cli/plugins'
44
const contractsConfig = [
55
{
66
name: 'manager',
7-
version: '0.19.2',
7+
version: '0.20.0',
88
},
99
{
1010
name: 'proxy',
11-
version: '0.19',
11+
version: '0.20.0',
1212
},
1313
{
1414
name: 'module-factory',
15-
version: '0.19',
15+
version: '0.20.0',
1616
},
1717
{
1818
name: 'version-control',
19-
version: '0.19',
19+
version: '0.20.0',
2020
},
2121
{
2222
name: 'ans-host',
23-
version: '0.19',
23+
version: '0.20.0',
2424
},
2525
{
2626
name: 'account-factory',
27-
version: '0.19',
27+
version: '0.20.0',
2828
},
2929
{
3030
name: 'ibc-client',

packages/core/src/actions/wallet/create-account.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function createAccount({
2828
namespace,
2929
governance,
3030
link,
31+
accountId,
3132
},
3233
fee,
3334
memo,
@@ -53,6 +54,7 @@ export async function createAccount({
5354
namespace,
5455
governance,
5556
link,
57+
accountId,
5658
},
5759
fee,
5860
memo,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { instantiate2Address } from '@cosmjs/cosmwasm-stargate'
2+
import { bech32 } from 'bech32'
3+
import { AccountId, accountIdToString } from '../account-id'
4+
5+
async function getSalt(accountId: AccountId) {
6+
const hash = await crypto.subtle.digest(
7+
'sha256',
8+
new TextEncoder().encode(accountIdToString(accountId)),
9+
)
10+
return new Uint8Array(hash)
11+
}
12+
13+
export async function getInstantiate2AccountAddress(
14+
address: string,
15+
accountFactoryAddress: string,
16+
checksum: Uint8Array,
17+
accountId: AccountId,
18+
) {
19+
const prefix = bech32.decode(address).prefix
20+
21+
return instantiate2Address(
22+
checksum,
23+
accountFactoryAddress,
24+
await getSalt(accountId),
25+
prefix,
26+
)
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './parse-create-account-execute-result'
2+
export * from './get-instantiate2-account-address'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum AuthzTransactionTypeUrl {
2+
AuthZMsgExec = '/cosmos.authz.v1beta1.MsgExec',
3+
AuthZMsgGrant = '/cosmos.authz.v1beta1.MsgGrant',
4+
GenericAuthorization = '/cosmos.authz.v1beta1.GenericAuthorization',
5+
SendAuthorization = '/cosmos.bank.v1beta1.SendAuthorization',
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum BankTransactionTypeUrl {
2+
Send = '/cosmos.bank.v1beta1.MsgSend',
3+
MultiSend = '/cosmos.bank.v1beta1.MsgMultiSend',
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { GenericAuthorization } from 'cosmjs-types/cosmos/authz/v1beta1/authz'
2+
import { AuthzTransactionTypeUrl } from './auth-transactions-types-url'
3+
import { BankTransactionTypeUrl } from './bank-transaction-types-url'
4+
5+
export function encodeAuthzGenericAuthorizationMsg(
6+
permission: `${BankTransactionTypeUrl}`,
7+
) {
8+
return {
9+
typeUrl: AuthzTransactionTypeUrl.GenericAuthorization,
10+
value: GenericAuthorization.encode(
11+
GenericAuthorization.fromPartial({
12+
msg: permission,
13+
}),
14+
).finish(),
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SendAuthorization } from 'cosmjs-types/cosmos/bank/v1beta1/authz'
2+
import { AuthzTransactionTypeUrl } from './auth-transactions-types-url'
3+
4+
export function encodeAuthzSendAuthorizationMsg(
5+
options: Parameters<typeof SendAuthorization.fromPartial>[0],
6+
) {
7+
return {
8+
typeUrl: AuthzTransactionTypeUrl.SendAuthorization,
9+
value: SendAuthorization.encode(
10+
SendAuthorization.fromPartial(options),
11+
).finish(),
12+
}
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './auth-transactions-types-url'
2+
export * from './bank-transaction-types-url'
3+
export * from './encode-authz-send-authorization-msg'
4+
export * from './encode-authz-generic-authorization-msg'

0 commit comments

Comments
 (0)