Skip to content

Commit

Permalink
fix: amino signing for withdraw position message
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddyMc committed Sep 21, 2024
1 parent 6db052a commit 365ab0a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,11 @@ export const MsgWithdrawPosition = {
if (message.sender !== "") {
writer.uint32(18).string(message.sender);
}
// NOTE: Withdraw postion will break if we regenerate protos
// if you see this line being removed in a PR, flag it!
// TODO: Abstract to an override function.
if (message.liquidityAmount !== "") {
writer
.uint32(26)
.string(Decimal.fromUserInput(message.liquidityAmount, 18).atomics);
writer.uint32(26).string(message.liquidityAmount.replace(".", ""));
}
return writer;
},
Expand Down
43 changes: 43 additions & 0 deletions packages/stores/src/account/amino-converters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { AminoMsgTransfer } from "@cosmjs/stargate";
import type {
MsgWithdrawPosition,
MsgWithdrawPositionAmino,
} from "@osmosis-labs/proto-codecs/build/codegen/osmosis/concentratedliquidity/v1beta1/tx";
import type { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import Long from "long";

Expand Down Expand Up @@ -46,6 +50,45 @@ export async function getAminoConverters() {
: undefined,
}),
},
"/osmosis.concentratedliquidity.v1beta1.MsgWithdrawPosition": {
...originalOsmosisAminoConverters[
"/osmosis.concentratedliquidity.v1beta1.MsgWithdrawPosition"
],
aminoType: "osmosis/cl-withdraw-position",
fromAmino(object: MsgWithdrawPositionAmino): MsgWithdrawPosition {
const message = {
positionId: BigInt(0),
sender: "",
liquidityAmount: "",
};
if (object.position_id !== undefined && object.position_id !== null) {
message.positionId = BigInt(object.position_id);
}
if (object.sender !== undefined && object.sender !== null) {
message.sender = object.sender;
}
if (
object.liquidity_amount !== undefined &&
object.liquidity_amount !== null
) {
message.liquidityAmount = object.liquidity_amount.replace(".", "");
}
return message;
},
toAmino(message: MsgWithdrawPosition): MsgWithdrawPositionAmino {
const obj: any = {};
obj.position_id =
message.positionId !== BigInt(0)
? message.positionId.toString()
: undefined;
obj.sender = message.sender === "" ? undefined : message.sender;
obj.liquidity_amount =
message.liquidityAmount === ""
? undefined
: message.liquidityAmount.replace(".", "");
return obj;
},
},
};

const ibcAminoConverters: Record<
Expand Down
9 changes: 3 additions & 6 deletions packages/stores/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,12 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
return typeUrl;
};

// TODO - update proto codec
// @osmosis-labs/proto-codec has been updated for "/osmosis.concentratedliquidity.v1beta1.MsgWithdrawPosition"
// TODO: Copy what's been done there for this message below
const doesTxNeedDirectSigning = messages.some(
(message) =>
message.typeUrl ===
getTypeUrl(
"/osmosis.concentratedliquidity.v1beta1.MsgWithdrawPosition"
) ||
message.typeUrl ===
getTypeUrl("/osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference")
getTypeUrl("/osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference")
);

const forceSignDirect = doesTxNeedDirectSigning;
Expand Down

0 comments on commit 365ab0a

Please sign in to comment.