Skip to content

Commit

Permalink
fix standalone simulate call by appropriately transforming message an…
Browse files Browse the repository at this point in the history
…d signerAddress
  • Loading branch information
BurntVal committed Dec 12, 2024
1 parent f8d6fb8 commit 26f48fd
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions packages/abstraxion-core/src/GranteeSignerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,41 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
return customAccountFromAny(account);
}

private transformForMsgExec(
signerAddress: string,
messages: readonly EncodeObject[],
): { signerAddress: string; messages: readonly EncodeObject[] } {
if (signerAddress === this.granterAddress) {
signerAddress = this.granteeAddress;

messages = [
{
typeUrl: "/cosmos.authz.v1beta1.MsgExec",
value: MsgExec.fromPartial({
grantee: this.granteeAddress,
msgs: messages.map((msg) => this.registry.encodeAsAny(msg)),
}),
},
];
}

return { signerAddress, messages };
}

public async simulate(
signerAddress: string,
messages: readonly EncodeObject[],
memo: string | undefined,
feeGranter?: string,
): Promise<number> {
const { sequence } = await this.getSequence(signerAddress);
const {
signerAddress: transformedSignerAddress,
messages: transformedMessages,
} = this.transformForMsgExec(signerAddress, messages);

const { sequence } = await this.getSequence(transformedSignerAddress);
const accountFromSigner = (await this._signer.getAccounts()).find(
(account) => account.address === signerAddress,
(account) => account.address === transformedSignerAddress,
);

if (!accountFromSigner) {
Expand Down Expand Up @@ -157,7 +183,7 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
const txBodyEncodeObject = {
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: messages,
messages: transformedMessages,
memo: memo,
},
};
Expand Down Expand Up @@ -188,20 +214,10 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
// Figure out if the signerAddress is a granter
if (signerAddress === this.granterAddress) {
signerAddress = this.granteeAddress;
// Wrap the signerAddress in a MsgExec
messages = [
{
typeUrl: "/cosmos.authz.v1beta1.MsgExec",
value: MsgExec.fromPartial({
grantee: this.granteeAddress,
msgs: messages.map((msg) => this.registry.encodeAsAny(msg)),
}),
},
];
}
const {
signerAddress: transformedSignerAddress,
messages: transformedMessages,
} = this.transformForMsgExec(signerAddress, messages);

let usedFee: StdFee;

Expand All @@ -214,8 +230,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
);
}
const gasEstimation = await this.simulate(
signerAddress,
messages,
transformedSignerAddress,
transformedMessages,
memo,
granter,
);
Expand All @@ -235,8 +251,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
}

const txRaw = await this.sign(
signerAddress,
messages,
transformedSignerAddress,
transformedMessages,
usedFee,
memo,
undefined,
Expand Down

0 comments on commit 26f48fd

Please sign in to comment.