Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/constants/module-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const CLAMM_MODULE_ADDRESSES = [
"0x6b41bf295bc31cd9bef75a9a5a67e5a8d6749b34a7ab3105808251fa2697823d" // testnet
] as const;

export const SKIP_ENTRY_POINT_MODULE_ADDRESSES = [
"0xd921c61c7e7d2eead33bdff4c5c2941e66d488f0a15fe7fbc432565dc04b3710" // mainnet
] as const;

export const CLAMM_FARMING_MODULE_ADDRESSES = [
"0xcb2999c70a9b8db7cb473255bb01f956f0726087f08b04ece50844a6d8167351", // mainnet
"0xf8ef0cb7c73607b7658524565015ce2aadc45ccf7164e5351959a4d7a1c37753" // testnet
Expand Down
1 change: 1 addition & 0 deletions src/decoder-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const cosmosMoveMessageDecoders: MessageDecoder[] = [
Decoders.redelegateDecoder,
Decoders.redelegateLockedDecoder,
Decoders.sendDecoder,
Decoders.skipSwapDecoder,
Decoders.stableswapDecoder,
Decoders.undelegateDecoder,
Decoders.undelegateLockedDecoder,
Expand Down
1 change: 1 addition & 0 deletions src/decoders/cosmos/move/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./liquidity";
export * from "./minitswap";
export * from "./nft";
export * from "./object-transfer";
export * from "./skip";
export * from "./stableswap";
export * from "./staking";
export * from "./usernames";
Expand Down
70 changes: 70 additions & 0 deletions src/decoders/cosmos/move/skip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ApiClient } from "@/api";
import { DecodedMessage, MessageDecoder } from "@/interfaces";
import { Log, Message, TxResponse, zMsgSkipSwapAndAction } from "@/schema";
import { zSkipSwapEvent } from "@/schema";
import { findAllMoveEvents } from "@/utils";

// swap_and_action routes through 0x1 AMMs, so amounts come from their swap
// events: offer of the first hop, return of the last hop.
const SWAP_EVENT_TAGS = [
"0x1::dex::SwapEvent",
"0x1::minitswap::SwapEvent",
"0x1::stableswap::SwapEvent"
];

export const skipSwapDecoder: MessageDecoder = {
check: (message: Message, _log: Log) =>
zMsgSkipSwapAndAction.safeParse(message).success,
decode: async (
message: Message,
log: Log,
apiClient: ApiClient,
_txResponse: TxResponse
) => {
const parsed = zMsgSkipSwapAndAction.parse(message);
const { sender } = parsed;

const swapEvents = findAllMoveEvents(
log.events,
SWAP_EVENT_TAGS,
zSkipSwapEvent
);
const firstSwapEvent = swapEvents[0];
const lastSwapEvent = swapEvents[swapEvents.length - 1];
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (!firstSwapEvent || !lastSwapEvent) {
throw new Error("Skip swap event not found");
}

const [denomIn, denomOut] = await Promise.all([
apiClient.findDenomFromMetadataAddr(firstSwapEvent.offer_coin),
apiClient.findDenomFromMetadataAddr(lastSwapEvent.return_coin)
]);

if (!denomIn) {
throw new Error(
`Denom in not found for offer coin ${firstSwapEvent.offer_coin}`
);
}

if (!denomOut) {
throw new Error(
`Denom out not found for return coin ${lastSwapEvent.return_coin}`
);
}

const decodedMessage: DecodedMessage = {
action: "swap",
data: {
amountIn: firstSwapEvent.offer_amount,
amountOut: lastSwapEvent.return_amount,
denomIn,
denomOut,
from: sender
},
isIbc: false,
isOp: false
};

return decodedMessage;
}
};
11 changes: 11 additions & 0 deletions src/schema/cosmos/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ export const zSwapEvent = zJsonString.pipe(
})
);

// Shared shape of 0x1::{dex,stableswap,minitswap}::SwapEvent — minitswap lacks
// fee_amount/liquidity_token, so only the common fields are required here.
export const zSkipSwapEvent = zJsonString.pipe(
z.object({
offer_amount: z.string(),
offer_coin: z.string(),
return_amount: z.string(),
return_coin: z.string()
})
);

export const zCreateEvent = zJsonString.pipe(
z.object({
object: z.string(),
Expand Down
8 changes: 8 additions & 0 deletions src/schema/cosmos/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CLAMM_MODULE_ADDRESSES,
DEX_UTILS_MODULE_ADDRESSES,
INITIA_VAULT_MODULE_ADDRESSES,
SKIP_ENTRY_POINT_MODULE_ADDRESSES,
USERNAME_MODULE_ADDRESSES
} from "@/constants";

Expand Down Expand Up @@ -88,6 +89,13 @@ export const zMsgMoveStableSwap = zMsgMoveExecute.extend({
module_name: z.literal("stableswap")
});

// Skip entry_point related Move messages
export const zMsgSkipSwapAndAction = zMsgMoveExecute.extend({
function_name: z.enum(["swap_and_action", "swap_and_action_with_recover"]),
module_address: z.enum(SKIP_ENTRY_POINT_MODULE_ADDRESSES),
module_name: z.literal("entry_point")
});

// NFT related Move messages
const zMsgMoveSimpleMint = zMsgMoveExecute.extend({
function_name: z.literal("mint"),
Expand Down
Loading
Loading