-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (context-module) [DSDK-325]: Add uniswap loader (#675)
- Loading branch information
Showing
21 changed files
with
1,789 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-management-kit": patch | ||
--- | ||
|
||
Use unknown type for HexaString typeguard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/context-module": minor | ||
--- | ||
|
||
Add uniswap loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/signer/context-module/src/uniswap/constants/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const UNISWAP_PLUGIN_SIGNATURE = | ||
"0x3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"; | ||
export const UNISWAP_PLUGIN_NAME = "Uniswap"; |
46 changes: 46 additions & 0 deletions
46
packages/signer/context-module/src/uniswap/constants/uniswap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { type HexaString } from "@ledgerhq/device-management-kit"; | ||
|
||
export const UNISWAP_EXECUTE_ABI = [ | ||
"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable", | ||
]; | ||
|
||
export const UNISWAP_UNIVERSAL_ROUTER_ADDRESS = | ||
"0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad"; | ||
export const UNISWAP_EXECUTE_SELECTOR = "0x3593564c"; | ||
|
||
export enum UniswapSupportedCommand { | ||
V2_SWAP_EXACT_IN = "V2_SWAP_EXACT_IN", | ||
V2_SWAP_EXACT_OUT = "V2_SWAP_EXACT_OUT", | ||
V3_SWAP_EXACT_IN = "V3_SWAP_EXACT_IN", | ||
V3_SWAP_EXACT_OUT = "V3_SWAP_EXACT_OUT", | ||
WRAP_ETH = "WRAP_ETH", | ||
UNWRAP_ETH = "UNWRAP_ETH", | ||
PERMIT2_PERMIT = "PERMIT2_PERMIT", | ||
PERMIT2_TRANSFER_FROM = "PERMIT2_TRANSFER_FROM", | ||
PERMIT2_PERMIT_BATCH = "PERMIT2_PERMIT_BATCH", | ||
PERMIT2_TRANSFER_FROM_BATCH = "PERMIT2_TRANSFER_FROM_BATCH", | ||
PAY_PORTION = "PAY_PORTION", | ||
SWEEP = "SWEEP", | ||
} | ||
|
||
export const UNISWAP_COMMANDS: Record<HexaString, UniswapSupportedCommand> = { | ||
"0x08": UniswapSupportedCommand.V2_SWAP_EXACT_IN, | ||
"0x09": UniswapSupportedCommand.V2_SWAP_EXACT_OUT, | ||
"0x00": UniswapSupportedCommand.V3_SWAP_EXACT_IN, | ||
"0x01": UniswapSupportedCommand.V3_SWAP_EXACT_OUT, | ||
"0x0b": UniswapSupportedCommand.WRAP_ETH, | ||
"0x0c": UniswapSupportedCommand.UNWRAP_ETH, | ||
"0x0a": UniswapSupportedCommand.PERMIT2_PERMIT, | ||
"0x0d": UniswapSupportedCommand.PERMIT2_TRANSFER_FROM, | ||
"0x02": UniswapSupportedCommand.PERMIT2_PERMIT_BATCH, | ||
"0x03": UniswapSupportedCommand.PERMIT2_TRANSFER_FROM_BATCH, | ||
"0x06": UniswapSupportedCommand.PAY_PORTION, | ||
"0x04": UniswapSupportedCommand.SWEEP, | ||
}; | ||
|
||
export const UNISWAP_SWAP_COMMANDS: UniswapSupportedCommand[] = [ | ||
UniswapSupportedCommand.V2_SWAP_EXACT_IN, | ||
UniswapSupportedCommand.V2_SWAP_EXACT_OUT, | ||
UniswapSupportedCommand.V3_SWAP_EXACT_IN, | ||
UniswapSupportedCommand.V3_SWAP_EXACT_OUT, | ||
]; |
50 changes: 50 additions & 0 deletions
50
packages/signer/context-module/src/uniswap/constants/weth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { type HexaString } from "@ledgerhq/device-management-kit"; | ||
|
||
export enum WETHSupportedChainIds { | ||
ETHEREUM_MAINNET = 1, | ||
ETHEREUM_GOERLI = 5, | ||
ETHEREUM_SEPOLIA = 11155111, | ||
ARBITRUM_ONE = 42161, | ||
ARBITRUM_GOERLI = 421613, | ||
AVALANCHE_C_CHAIN = 43114, | ||
BSC = 56, | ||
BASE = 8453, | ||
BASE_GOERLI = 84531, | ||
BLAST = 23888, | ||
OPTIMISM = 10, | ||
OPTIMISM_GOERLI = 420, | ||
POLYGON = 137, | ||
POLYGON_MUMBAI = 80001, | ||
} | ||
|
||
export type WETHSupportedChainId = keyof typeof WETH_ADDRESS_BY_CHAIN_ID; | ||
|
||
export const WETH_ADDRESS_BY_CHAIN_ID: Record< | ||
WETHSupportedChainIds, | ||
HexaString | ||
> = { | ||
[WETHSupportedChainIds.ETHEREUM_MAINNET]: | ||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", | ||
[WETHSupportedChainIds.ETHEREUM_GOERLI]: | ||
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", | ||
[WETHSupportedChainIds.ETHEREUM_SEPOLIA]: | ||
"0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", | ||
[WETHSupportedChainIds.ARBITRUM_ONE]: | ||
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", | ||
[WETHSupportedChainIds.ARBITRUM_GOERLI]: | ||
"0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3", | ||
[WETHSupportedChainIds.AVALANCHE_C_CHAIN]: | ||
"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", | ||
[WETHSupportedChainIds.BSC]: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", | ||
[WETHSupportedChainIds.BASE]: "0x4200000000000000000000000000000000000006", | ||
[WETHSupportedChainIds.BASE_GOERLI]: | ||
"0x44D627f900da8AdaC7561bD73aA745F132450798", | ||
[WETHSupportedChainIds.BLAST]: "0x4300000000000000000000000000000000000004", | ||
[WETHSupportedChainIds.OPTIMISM]: | ||
"0x4200000000000000000000000000000000000006", | ||
[WETHSupportedChainIds.OPTIMISM_GOERLI]: | ||
"0x4200000000000000000000000000000000000006", | ||
[WETHSupportedChainIds.POLYGON]: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", | ||
[WETHSupportedChainIds.POLYGON_MUMBAI]: | ||
"0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889", | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/signer/context-module/src/uniswap/data/AbiDecoderDataSource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type HexaString } from "@ledgerhq/device-management-kit"; | ||
|
||
export interface AbiDecoderDataSource { | ||
decode(types: string[], data: HexaString): unknown[]; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/signer/context-module/src/uniswap/data/CommandDecoderDataSource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { type HexaString } from "@ledgerhq/device-management-kit"; | ||
|
||
import { type UniswapSupportedCommand } from "@/uniswap/constants/uniswap"; | ||
|
||
export interface CommandDecoderDataSource { | ||
decode( | ||
command: UniswapSupportedCommand, | ||
input: HexaString, | ||
chainId: number, | ||
): HexaString[]; | ||
} |
Oops, something went wrong.