Skip to content

Commit

Permalink
Merge pull request #3944 from osmosis-labs/stage
Browse files Browse the repository at this point in the history
Publish Stage
  • Loading branch information
JoseRFelix authored Nov 13, 2024
2 parents 341b8c8 + 498be0c commit 07f0b75
Show file tree
Hide file tree
Showing 41 changed files with 475 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe("SkipBridgeProvider", () => {
revisionNumber: "1",
revisionHeight: "1000",
},
timeoutTimestamp: "0",
timeoutTimestamp: 1718978568036848600,
memo: '{"destination_chain":"Ethereum","destination_address":"0xD397883c12b71ea39e0d9f6755030205f31A1c96","payload":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,120,99,236,5,177,35,136,92,118,9,176,92,53,223,119,127,63,24,2,88],"type":2,"fee":{"amount":"7725420487422623","recipient":"axelar1aythygn6z5thymj6tmzfwekzh05ewg3l7d6y89"}}',
},
},
Expand Down Expand Up @@ -343,11 +343,6 @@ describe("SkipBridgeProvider", () => {

const txRequest = (await provider.createTransaction(
"1",
{
chainId: "osmosis-1",
chainName: "osmosis",
chainType: "cosmos",
},
"0xabc",
messages
)) as EvmBridgeTransactionRequest;
Expand Down
26 changes: 10 additions & 16 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export class SkipBridgeProvider implements BridgeProvider {

const transactionRequest = await this.createTransaction(
fromChain.chainId.toString(),
toChain,
fromAddress as Address,
msgs
);
Expand Down Expand Up @@ -447,7 +446,6 @@ export class SkipBridgeProvider implements BridgeProvider {

async createTransaction(
fromChainId: string,
toChain: BridgeChain,
address: Address,
messages: SkipMsg[]
) {
Expand All @@ -461,16 +459,12 @@ export class SkipBridgeProvider implements BridgeProvider {
}

if ("multi_chain_msg" in message) {
return await this.createCosmosTransaction(
toChain,
message.multi_chain_msg
);
return await this.createCosmosTransaction(message.multi_chain_msg);
}
}
}

async createCosmosTransaction(
toChain: BridgeChain,
message: SkipMultiChainMsg
): Promise<CosmosBridgeTransactionRequest & { fallbackGasLimit?: number }> {
const messageData = JSON.parse(message.msg);
Expand Down Expand Up @@ -503,14 +497,14 @@ export class SkipBridgeProvider implements BridgeProvider {
} else {
// is an ibc transfer

// If toChain is not cosmos, this IBC transfer is an
// intermediary IBC transfer where we need to get the
// timeout from the bech32 prefix of the receiving address
const timeoutHeight = await this.ctx.getTimeoutHeight(
toChain.chainType === "cosmos"
? toChain
: { destinationAddress: messageData.receiver }
);
/**
* Always use the receiver address to get the timeout height.
* For chains with PFM enabled, the destination chain is not the same as
* the toChain. Therefore, we need to derive the immediate next hop height.
*/
const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: messageData.receiver,
});

const { typeUrl, value } = await makeIBCTransferMsg({
sourcePort: messageData.source_port,
Expand All @@ -523,7 +517,7 @@ export class SkipBridgeProvider implements BridgeProvider {
receiver: messageData.receiver,
// @ts-ignore
timeoutHeight,
timeoutTimestamp: "0" as any,
timeoutTimestamp: messageData?.timeout_timestamp ?? BigInt(0),
memo: messageData.memo,
});

Expand Down
92 changes: 55 additions & 37 deletions packages/bridge/src/squid/transfer-status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StatusResponse } from "@0xsquid/sdk";
import { Chain } from "@osmosis-labs/types";
import { apiClient, poll } from "@osmosis-labs/utils";
import { apiClient, ApiClientError, poll } from "@osmosis-labs/utils";

import type {
BridgeEnvironment,
Expand Down Expand Up @@ -33,51 +33,69 @@ export class SquidTransferStatusProvider implements TransferStatusProvider {

/** Request to start polling a new transaction. */
async trackTxStatus(snapshot: TxSnapshot): Promise<void> {
// Will retry every 30 seconds for 3 times before giving up
const maxNotFoundCount = 3;
let notFoundCount = 0;

const {
sendTxHash,
fromChain: { chainId: fromChainId },
toChain: { chainId: toChainId },
} = snapshot;
await poll({
fn: async () => {
const url = new URL(`${this.apiUrl}/v1/status`);
url.searchParams.append("transactionId", sendTxHash);
if (fromChainId) {
url.searchParams.append("fromChainId", fromChainId.toString());
}
if (toChainId) {
url.searchParams.append("toChainId", toChainId.toString());
}

const data = await apiClient<StatusResponse>(url.toString());

if (!data || !data.id || !data.squidTransactionStatus) {
try {
const url = new URL(`${this.apiUrl}/v1/status`);
url.searchParams.append("transactionId", sendTxHash);
if (fromChainId) {
url.searchParams.append("fromChainId", fromChainId.toString());
}
if (toChainId) {
url.searchParams.append("toChainId", toChainId.toString());
}

const data = await apiClient<StatusResponse>(url.toString());

if (!data || !data.id || !data.squidTransactionStatus) {
return;
}

const squidTransactionStatus = data.squidTransactionStatus as
| "success"
| "needs_gas"
| "ongoing"
| "partial_success"
| "not_found";

if (
squidTransactionStatus === "not_found" ||
squidTransactionStatus === "ongoing" ||
squidTransactionStatus === "partial_success"
) {
return;
}

return {
id: sendTxHash,
status: squidTransactionStatus === "success" ? "success" : "failed",
reason:
squidTransactionStatus === "needs_gas"
? "insufficientFee"
: undefined,
} as BridgeTransferStatus;
} catch (e) {
const error = e as Error | ApiClientError;
if (error instanceof ApiClientError && error.status === 404) {
notFoundCount++;
if (notFoundCount >= maxNotFoundCount) {
return {
id: sendTxHash,
status: "failed",
} as BridgeTransferStatus;
}
}
return;
}

const squidTransactionStatus = data.squidTransactionStatus as
| "success"
| "needs_gas"
| "ongoing"
| "partial_success"
| "not_found";

if (
squidTransactionStatus === "not_found" ||
squidTransactionStatus === "ongoing" ||
squidTransactionStatus === "partial_success"
) {
return;
}

return {
id: sendTxHash,
status: squidTransactionStatus === "success" ? "success" : "failed",
reason:
squidTransactionStatus === "needs_gas"
? "insufficientFee"
: undefined,
} as BridgeTransferStatus;
},
validate: (incomingStatus) => incomingStatus !== undefined,
interval: 30_000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function getOrderbookHistoricalOrders({
return cachified({
cache: orderbookHistoricalOrdersCache,
key: `orderbookHistoricalOrders-${userOsmoAddress}`,
ttl: 1000 * 2, // 2 seconds
ttl: 1000 * 5, // 5 seconds
getFreshValue: () =>
queryHistoricalOrders(userOsmoAddress).then(async (data) => {
const orders = data;
Expand Down
7 changes: 5 additions & 2 deletions packages/trpc/src/orderbook-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GetInfiniteLimitOrdersInputSchema = CursorPaginationSchema.merge(
UserOsmoAddressSchema.required()
).merge(
z.object({
filter: z.enum(["open", "filled", "historical"]).optional(),
filter: z.enum(["open", "filled", "historical", "active"]).optional(),
})
);

Expand Down Expand Up @@ -125,7 +125,10 @@ export const orderbookRouter = createTRPCRouter({
const { userOsmoAddress, filter } = input;

const shouldFetchActive =
!filter || filter === "open" || filter === "filled";
!filter ||
filter === "open" ||
filter === "filled" ||
filter === "active";
const shouldFetchHistorical = !filter || filter === "historical";
const promises: Promise<MappedLimitOrder[]>[] = [];
if (shouldFetchActive) {
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/bridge/review-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ const AssetBox: FunctionComponent<{
</div>
<div className="body1 md:caption text-osmoverse-300">
{type === "to" && "~"}{" "}
{formatPretty(coin.inequalitySymbol(false), {
maxDecimals: 10,
{formatPretty(coin, {
maxDecimals: 6,
})}
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/web/components/bridge/use-bridge-quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const useBridgeQuotes = ({
accountStore.getWallet(fromChain.chainId)?.txTypeInProgress
);
} else if (fromChain.chainType === "evm") {
return isEthTxPending;
return isEthTxPending || isBroadcastingTx;
}
return false;
})();
Expand Down Expand Up @@ -546,11 +546,10 @@ export const useBridgeQuotes = ({
hash: approveTxHash,
});

setIsApprovingToken(false);

for (const quoteResult of quoteResults) {
await quoteResult.refetch();
}
setIsApprovingToken(false);
}

const sendTxHash = await sendTransactionAsync({
Expand Down Expand Up @@ -664,6 +663,8 @@ export const useBridgeQuotes = ({

onTransferProp?.();
setTransferInitiated(true);
} else {
setIsBroadcastingTx(false);
}
},
}
Expand Down
2 changes: 0 additions & 2 deletions packages/web/components/complex/all-pools-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const TableControls = () => {

const { filters, setFilters } = useAllPoolsTable();

filters.poolTypesFilter;

const onSearchInput = useCallback(
(data: string) => {
setFilters((state) => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/complex/orders-history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
useWindowSize,
} from "~/hooks";
import {
useOrderbookAllActiveOrders,
useOrderbookClaimableOrders,
useOrderbookOrders,
} from "~/hooks/limit-orders/use-orderbook";
import { useStore } from "~/stores";
import {
Expand Down Expand Up @@ -81,7 +81,7 @@ export const OrderHistory = observer(() => {
hasNextPage,
refetch,
isRefetching,
} = useOrderbookAllActiveOrders({
} = useOrderbookOrders({
userAddress: wallet?.address ?? "",
pageSize: 20,
refetchInterval: featureFlags.sqsActiveOrders ? 10000 : 30000,
Expand Down
11 changes: 4 additions & 7 deletions packages/web/components/complex/portfolio/open-orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { FunctionComponent } from "react";
import { FallbackImg } from "~/components/assets";
import { LinkButton } from "~/components/buttons/link-button";
import { useTranslation } from "~/hooks";
import { useOrderbookAllActiveOrders } from "~/hooks/limit-orders/use-orderbook";
import { useOrderbookOrders } from "~/hooks/limit-orders/use-orderbook";
import { useStore } from "~/stores";
import { formatFiatPrice } from "~/utils/formatter";
import { formatPretty } from "~/utils/formatter";
Expand All @@ -18,15 +18,12 @@ export const OpenOrders: FunctionComponent = () => {
const { accountStore } = useStore();
const wallet = accountStore.getWallet(accountStore.osmosisChainId);

const { orders, isLoading } = useOrderbookAllActiveOrders({
const { orders: openOrders, isLoading } = useOrderbookOrders({
userAddress: wallet?.address ?? "",
pageSize: 100,
pageSize: OPEN_ORDERS_LIMIT,
filter: "open",
});

const openOrders = orders
?.filter((order) => order.status === "open")
.slice(0, OPEN_ORDERS_LIMIT);

const hasOpenOrders = openOrders?.length > 0;

if (isLoading || !hasOpenOrders) return null;
Expand Down
Loading

0 comments on commit 07f0b75

Please sign in to comment.