Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support go fast operation type #452

Merged
merged 5 commits into from
Nov 11, 2024
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
5 changes: 5 additions & 0 deletions .changeset/afraid-tools-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/client': patch
---

skip validation gas on noble-1 on multi tx route
5 changes: 5 additions & 0 deletions .changeset/olive-mice-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/widget': patch
---

support go fast operation type
23 changes: 19 additions & 4 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ export class SkipClient {
}

if (isOfflineDirectSigner(signer)) {
rawTx = await this.signCosmosMessageDirect({ ...commonRawTxBody, signer});
rawTx = await this.signCosmosMessageDirect({ ...commonRawTxBody, signer });
} else {
rawTx = await this.signCosmosMessageAmino({ ...commonRawTxBody, signer});
rawTx = await this.signCosmosMessageAmino({ ...commonRawTxBody, signer });
}

const txBytes = TxRaw.encode(rawTx).finish();
Expand Down Expand Up @@ -1646,7 +1646,7 @@ export class SkipClient {
const validateResult = await Promise.all(
txs.map(async (tx, i) => {
if (!tx) {
raise(` invalid tx at index ${i}`);
raise(`invalid tx at index ${i}`);
}
if ('cosmosTx' in tx) {
if (!tx.cosmosTx.msgs) {
Expand Down Expand Up @@ -1682,6 +1682,7 @@ export class SkipClient {
client,
messages: tx.cosmosTx.msgs,
getFallbackGasAmount,
txIndex: i
});
return res;
} catch (e) {
Expand All @@ -1695,7 +1696,9 @@ export class SkipClient {
}
})
);
const txError = validateResult.find((res) => res?.error !== null);
const txError = validateResult.find(
(res) => res && res?.error !== null
);
if (txError) {
onValidateGasBalance?.({
status: 'error',
Expand All @@ -1719,12 +1722,14 @@ export class SkipClient {
client,
messages,
getFallbackGasAmount,
txIndex
}: {
chainID: string;
signerAddress: string;
client: SigningStargateClient;
messages?: types.CosmosMsg[];
getFallbackGasAmount?: clientTypes.GetFallbackGasAmount;
txIndex?: number;
}) {
const mainnetChains = await this.chains();
const testnetChains = await this.chains({ onlyTestnets: true });
Expand Down Expand Up @@ -1809,6 +1814,16 @@ export class SkipClient {
asset,
};
}

// Skip fee validation for noble-1 in multi tx route
if (txIndex !== 0 && chainID === 'noble-1') {
return {
error: null,
asset,
fee,
}
}

const balance = feeBalance.chains[chainID]?.denoms[asset.denom];
if (!balance) {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/constants/skipClientDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const endpointOptions = {
},
};

export const prodApiUrl = `${appUrl}/api/widget/skip`;
export const prodApiUrl = `${appUrl}/api/skip`;
3 changes: 3 additions & 0 deletions packages/widget/src/devMode/loadWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const DevMode = () => {
settings={{
slippage: 5,
}}
routeConfig={{
goFast: true,
}}
/>
<Column gap={5}>
<ShowWidget />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const operationTypeToIcon: operationTypeToIcon = {
[OperationType.cctpTransfer]: <SwapExecutionBridgeIcon width={34} />,
[OperationType.hyperlaneTransfer]: <SwapExecutionBridgeIcon width={34} />,
[OperationType.opInitTransfer]: <SwapExecutionBridgeIcon width={34} />,
[OperationType.goFastTransfer]: <SwapExecutionBridgeIcon width={34} />,
// send icon
[OperationType.bankSend]: <SwapExecutionSendIcon width={34} />,
};
Expand All @@ -41,6 +42,7 @@ const operationTypeToSimpleOperationType = {
hyperlaneTransfer: "Bridged",
opInitTransfer: "Bridged",
bankSend: "Sent",
goFastTransfer: "Bridged",
};

type tooltipMap = Record<number, boolean>;
Expand Down
7 changes: 5 additions & 2 deletions packages/widget/src/state/skipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import { defaultTheme, Theme } from "@/widget/theme";
type ArgumentTypes<F extends Function> = F extends (...args: infer A) => unknown ? A : never;

export const defaultSkipClientConfig = {
apiURL: prodApiUrl,
apiUrl: prodApiUrl,
endpointOptions,
};

export const skipClientConfigAtom = atom<SkipClientOptions>(defaultSkipClientConfig);
export const skipClientConfigAtom = atom<SkipClientOptions>({
apiURL: defaultSkipClientConfig.apiUrl,
endpointOptions: defaultSkipClientConfig.endpointOptions,
});

export const themeAtom = atom<Theme>(defaultTheme);

Expand Down
29 changes: 25 additions & 4 deletions packages/widget/src/utils/clientType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
CCTPTransferInfo,
CCTPTransferState,
EvmSwap,
GoFastTransfer,
GoFastTransferInfo,
GoFastTransferState,
HyperlaneTransfer,
HyperlaneTransferInfo,
HyperlaneTransferState,
Expand Down Expand Up @@ -35,6 +38,7 @@ export enum OperationType {
hyperlaneTransfer = "hyperlaneTransfer",
opInitTransfer = "opInitTransfer",
bankSend = "bankSend",
goFastTransfer = "goFastTransfer",
}

type CombinedOperation = {
Expand All @@ -49,6 +53,7 @@ type CombinedOperation = {
hyperlaneTransfer?: HyperlaneTransfer;
evmSwap?: EvmSwap;
opInitTransfer?: OPInitTransfer;
goFastTransfer?: GoFastTransfer;
};

type OperationDetails = CombineObjectTypes<
Expand All @@ -59,7 +64,8 @@ type OperationDetails = CombineObjectTypes<
CCTPTransfer &
HyperlaneTransfer &
EvmSwap &
OPInitTransfer
OPInitTransfer &
GoFastTransfer
> & {
swapIn?: {
swapVenue: SwapVenue;
Expand Down Expand Up @@ -101,8 +107,8 @@ type KeysNotPresentInAll<T> = keyof T extends infer Key
type CombineObjectTypes<T> = {
[K in KeysPresentInAll<T>]: T[K];
} & {
[K in KeysNotPresentInAll<T>]?: T[K];
};
[K in KeysNotPresentInAll<T>]?: T[K];
};

function getOperationDetailsAndType(operation: SkipClientOperation) {
const combinedOperation = operation as CombinedOperation;
Expand Down Expand Up @@ -206,6 +212,7 @@ function getClientTransferEvent(transferEvent: TransferEvent) {
combinedTransferEvent?.hyperlaneTransfer as HyperlaneTransferInfo;
const opInitTransfer =
combinedTransferEvent?.opInitTransfer as OPInitTransferInfo;
const goFastTransfer = combinedTransferEvent?.goFastTransfer as GoFastTransferInfo;

let transferType = "" as TransferType;
if (axelarTransfer) {
Expand All @@ -218,6 +225,8 @@ function getClientTransferEvent(transferEvent: TransferEvent) {
transferType = TransferType.hyperlaneTransfer;
} else if (opInitTransfer) {
transferType = TransferType.opInitTransfer;
} else if (goFastTransfer) {
transferType = TransferType.goFastTransfer;
}

const getExplorerLink = (type: "send" | "receive") => {
Expand All @@ -227,6 +236,11 @@ function getClientTransferEvent(transferEvent: TransferEvent) {
return ibcTransfer.packetTXs.sendTx?.explorerLink;
}
return ibcTransfer.packetTXs.receiveTx?.explorerLink;
case TransferType.goFastTransfer:
if (type === "send") {
return goFastTransfer.txs.orderSubmittedTx?.explorerLink;
}
return goFastTransfer.txs.orderFilledTx?.explorerLink;
case TransferType.axelarTransfer:
return axelarTransfer.axelarScanLink;
default:
Expand All @@ -248,6 +262,7 @@ function getClientTransferEvent(transferEvent: TransferEvent) {
...cctpTransfer,
...hyperlaneTransfer,
...opInitTransfer,
...goFastTransfer,
fromExplorerLink: getExplorerLink("send"),
toExplorerLink: getExplorerLink("receive"),
} as ClientTransferEvent;
Expand Down Expand Up @@ -291,6 +306,7 @@ export function getSimpleStatus(
| CCTPTransferState
| HyperlaneTransferState
| OPInitTransferState
| GoFastTransferState
): SimpleStatus {
switch (state) {
case "TRANSFER_PENDING":
Expand All @@ -302,12 +318,14 @@ export function getSimpleStatus(
case "CCTP_TRANSFER_CONFIRMED":
case "HYPERLANE_TRANSFER_SENT":
case "OPINIT_TRANSFER_SENT":
case "GO_FAST_TRANSFER_SENT":
return "pending";
case "TRANSFER_SUCCESS":
case "AXELAR_TRANSFER_SUCCESS":
case "CCTP_TRANSFER_RECEIVED":
case "HYPERLANE_TRANSFER_RECEIVED":
case "OPINIT_TRANSFER_RECEIVED":
case "GO_FAST_TRANSFER_FILLED":
return "completed";
default:
return "failed";
Expand All @@ -320,6 +338,7 @@ type CombinedTransferEvent = {
[TransferType.cctpTransfer]: CCTPTransferInfo;
[TransferType.hyperlaneTransfer]: HyperlaneTransferInfo;
[TransferType.opInitTransfer]: OPInitTransferInfo;
[TransferType.goFastTransfer]: GoFastTransferInfo;
};

export enum TransferType {
Expand All @@ -328,6 +347,7 @@ export enum TransferType {
cctpTransfer = "cctpTransfer",
hyperlaneTransfer = "hyperlaneTransfer",
opInitTransfer = "opInitTransfer",
goFastTransfer = "goFastTransfer",
}

export type SimpleStatus =
Expand All @@ -345,7 +365,8 @@ export type ClientTransferEvent = {
| AxelarTransferState
| CCTPTransferState
| HyperlaneTransferState
| OPInitTransferState;
| OPInitTransferState
| GoFastTransferState;
status?: SimpleStatus;
fromExplorerLink?: string;
toExplorerLink?: string;
Expand Down
26 changes: 18 additions & 8 deletions packages/widget/src/widget/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type WidgetProps = {
};
routeConfig?: WidgetRouteConfig;
filter?: ChainFilter;
} & NewSkipClientOptions;
} & Pick<NewSkipClientOptions, "apiUrl" | "chainIdsToAffiliates" | "endpointOptions">;

type NewSwapVenueRequest = {
name: string;
Expand Down Expand Up @@ -81,14 +81,20 @@ const WidgetWithoutNiceModalProvider = (props: WidgetProps) => {
const setChainFilter = useSetAtom(chainFilterAtom);
const setOnlyTestnets = useSetAtom(onlyTestnetsAtom);

const mergedSkipClientConfig = useMemo(() => {
const { theme, apiUrl, chainIdsToAffiliates, ...skipClientConfig } = props;
const mergedSkipClientConfig: SkipClientOptions = useMemo(() => {
const { apiUrl, chainIdsToAffiliates, endpointOptions } = props;
const fromWidgetProps = {
apiUrl,
chainIdsToAffiliates,
endpointOptions,
}

// merge if not undefined

return {
...defaultSkipClientConfig,
...skipClientConfig,
apiURL: apiUrl,
chainIDsToAffiliates: chainIdsToAffiliates,
apiURL: fromWidgetProps.apiUrl ?? defaultSkipClientConfig.apiUrl,
endpointOptions: fromWidgetProps.endpointOptions ?? defaultSkipClientConfig.endpointOptions,
chainIDsToAffiliates: fromWidgetProps.chainIdsToAffiliates ?? {},
};
}, [props]);

Expand All @@ -106,7 +112,11 @@ const WidgetWithoutNiceModalProvider = (props: WidgetProps) => {
}, [props.brandColor, props.theme]);

useLayoutEffect(() => {
setSkipClientConfig(mergedSkipClientConfig);
setSkipClientConfig({
apiURL: mergedSkipClientConfig.apiURL,
endpointOptions: mergedSkipClientConfig.endpointOptions,
chainIDsToAffiliates: mergedSkipClientConfig.chainIDsToAffiliates,
});
setTheme(mergedTheme);
registerModals();
}, [setSkipClientConfig, mergedSkipClientConfig, setTheme, mergedTheme]);
Expand Down
Loading