Skip to content

Commit

Permalink
Merge pull request #230 from skip-mev/ws/evm_swap
Browse files Browse the repository at this point in the history
[API-2947] Add EVM swap operation types
  • Loading branch information
wllmshao authored Jun 17, 2024
2 parents 7d59e68 + 336e3b8 commit bd45294
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-jeans-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skip-router/core": minor
---

Add evm swap operation
50 changes: 48 additions & 2 deletions packages/core/src/types/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ import {
SmartSwapExactCoinIn,
SmartSwapExactCoinInJSON,
SwapJSON,
EvmSwap,
EvmSwapJSON,
SwapOperation,
SwapOperationJSON,
SwapRoute,
Expand Down Expand Up @@ -810,6 +812,32 @@ export function swapToJSON(swap: Swap): SwapJSON {
};
}

export function evmSwapFromJSON(evmSwapJSON: EvmSwapJSON): EvmSwap {
return {
inputToken: evmSwapJSON.input_token,
amountIn: evmSwapJSON.amount_in,
swapCalldata: evmSwapJSON.swap_calldata,
amountOut: evmSwapJSON.amount_out,
fromChainID: evmSwapJSON.from_chain_id,
denomIn: evmSwapJSON.denom_in,
denomOut: evmSwapJSON.denom_out,
swapVenues: evmSwapJSON.swap_venues.map(swapVenueFromJSON),
};
}

export function evmSwapToJSON(evmSwap: EvmSwap): EvmSwapJSON {
return {
input_token: evmSwap.inputToken,
amount_in: evmSwap.amountIn,
swap_calldata: evmSwap.swapCalldata,
amount_out: evmSwap.amountOut,
from_chain_id: evmSwap.fromChainID,
denom_in: evmSwap.denomIn,
denom_out: evmSwap.denomOut,
swap_venues: evmSwap.swapVenues.map(swapVenueToJSON),
};
}

export function operationFromJSON(operationJSON: OperationJSON): Operation {
if ("transfer" in operationJSON) {
return {
Expand Down Expand Up @@ -858,8 +886,17 @@ export function operationFromJSON(operationJSON: OperationJSON): Operation {
};
}

if ("swap" in operationJSON) {
return {
swap: swapFromJSON(operationJSON.swap),
txIndex: operationJSON.tx_index,
amountIn: operationJSON.amount_in,
amountOut: operationJSON.amount_out,
};
}

return {
swap: swapFromJSON(operationJSON.swap),
evmSwap: evmSwapFromJSON(operationJSON.evm_swap),
txIndex: operationJSON.tx_index,
amountIn: operationJSON.amount_in,
amountOut: operationJSON.amount_out,
Expand Down Expand Up @@ -912,8 +949,17 @@ export function operationToJSON(operation: Operation): OperationJSON {
};
}

if ("swap" in operation) {
return {
swap: swapToJSON(operation.swap),
tx_index: operation.txIndex,
amount_in: operation.amountIn,
amount_out: operation.amountOut,
};
}

return {
swap: swapToJSON(operation.swap),
evm_swap: evmSwapToJSON(operation.evmSwap),
tx_index: operation.txIndex,
amount_in: operation.amountIn,
amount_out: operation.amountOut,
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,28 @@ export type Swap = (
swapVenues: SwapVenue[];
};

export type EvmSwapJSON = {
input_token: string;
amount_in: string;
swap_calldata: string;
amount_out: string;
from_chain_id: string;
denom_in: string;
denom_out: string;
swap_venues: SwapVenueJSON[];
}

export type EvmSwap = {
inputToken: string;
amountIn: string;
swapCalldata: string;
amountOut: string;
fromChainID: string;
denomIn: string;
denomOut: string;
swapVenues: SwapVenue[];
}

export type AffiliateJSON = {
basis_points_fee: string;
address: string;
Expand Down
94 changes: 54 additions & 40 deletions packages/core/src/types/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
PostHandler,
PostHandlerJSON,
Reason,
EvmSwap,
EvmSwapJSON,
Swap,
SwapJSON,
SwapVenue,
Expand Down Expand Up @@ -231,59 +233,71 @@ export type EstimatedFeeJSON = {

export type OperationJSON =
| {
transfer: TransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
transfer: TransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
| {
bank_send: BankSendJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
bank_send: BankSendJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
| { swap: SwapJSON; tx_index: number; amount_in: string; amount_out: string }
| {
axelar_transfer: AxelarTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
axelar_transfer: AxelarTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
| {
cctp_transfer: CCTPTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
cctp_transfer: CCTPTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
| {
hyperlane_transfer: HyperlaneTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
};
hyperlane_transfer: HyperlaneTransferJSON;
tx_index: number;
amount_in: string;
amount_out: string;
}
| {
evm_swap: EvmSwapJSON;
tx_index: number;
amount_in: string;
amount_out: string;
};

export type Operation =
| { transfer: Transfer; txIndex: number; amountIn: string; amountOut: string }
| { bankSend: BankSend; txIndex: number; amountIn: string; amountOut: string }
| { swap: Swap; txIndex: number; amountIn: string; amountOut: string }
| {
axelarTransfer: AxelarTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
}
axelarTransfer: AxelarTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
}
| {
cctpTransfer: CCTPTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
}
cctpTransfer: CCTPTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
}
| {
hyperlaneTransfer: HyperlaneTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
};
hyperlaneTransfer: HyperlaneTransfer;
txIndex: number;
amountIn: string;
amountOut: string;
}
| {
evmSwap: EvmSwap;
txIndex: number;
amountIn: string;
amountOut: string;
};

export type RouteResponseJSON = {
source_asset_denom: string;
Expand Down

0 comments on commit bd45294

Please sign in to comment.