Skip to content

Commit

Permalink
Add Mayan Shuttle protocol and update all protocol limits
Browse files Browse the repository at this point in the history
Signed-off-by: Emre Bogazliyanlioglu <[email protected]>
  • Loading branch information
emreboga committed Feb 3, 2025
1 parent f753b14 commit cdf8687
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
7 changes: 7 additions & 0 deletions wormhole-connect/src/components/DemoApp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
MayanRouteWH,
MayanRouteMCTP,
MayanRouteSWIFT,
MayanRouteSHUTTLE,
} from '@mayanfinance/wormhole-sdk-route';
import { NTT_TEST_CONFIG_TESTNET, NTT_TEST_CONFIG_MAINNET } from './consts';
import { DEFAULT_ROUTES, nttRoutes } from 'routes/operator';
Expand Down Expand Up @@ -70,6 +71,8 @@ const parseConfig = (config: string): WormholeConnectConfig => {
/* @ts-ignore */
window.MayanRouteSWIFT = MayanRouteSWIFT;
/* @ts-ignore */
window.MayanRouteSHUTTLE = MayanRouteSHUTTLE;
/* @ts-ignore */
window.testNttRoutesTestnet = () => nttRoutes(NTT_TEST_CONFIG_TESTNET);
/* @ts-ignore */
window.testNttRoutesMainnet = () => nttRoutes(NTT_TEST_CONFIG_MAINNET);
Expand Down Expand Up @@ -227,6 +230,10 @@ function DemoApp() {
<pre>MayanRouteSWIFT</pre>
<i>{'RouteConstructor'}</i>
</li>
<li>
<pre>MayanRouteSHUTTLE</pre>
<i>{'RouteConstructor'}</i>
</li>
<li>
<pre>nttRoutes</pre>{' '}
<i>{'(NttRoute.Config) -> RouteConstructor[]'}</i>
Expand Down
8 changes: 8 additions & 0 deletions wormhole-connect/src/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,12 @@ export const RoutesConfig: Record<string, RouteData> = {
icon: XLabsIcon,
pendingMessage: 'Waiting for Wormhole network consensus . . .',
},
MayanSwapSHUTTLE: {
name: 'MayanSwapSHUTTLE',
displayName: 'Mayan Swap Shuttle',
providedBy: 'Mayan Shuttle',
link: 'https://mayan.finance/',
icon: XLabsIcon,
pendingMessage: 'Waiting for Wormhole network consensus . . .',
},
};
30 changes: 16 additions & 14 deletions wormhole-connect/src/hooks/useRoutesQuotesBulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type HookReturn = {
};

const QUOTE_REFRESH_INTERVAL = 20_000;

const MAYAN_BETA_LIMIT = 10_000; // USD
const MAYAN_BETA_PROTOCOLS = ['MCTP', 'SWIFT'];
const MAYAN_BETA_PROTOCOL_LIMITS = {
MCTP: 10_000,
SHUTTLE: 5_000,
};

const useRoutesQuotesBulk = (routes: string[], params: Params): HookReturn => {
const [nonce, setNonce] = useState(new Date().valueOf());
Expand Down Expand Up @@ -171,27 +172,28 @@ const useRoutesQuotesBulk = (routes: string[], params: Params): HookReturn => {
if (name.startsWith('MayanSwap')) {
const mayanQuote = quotesMap[name];

if (
mayanQuote !== undefined &&
mayanQuote.success &&
MAYAN_BETA_PROTOCOLS.includes(mayanQuote.details?.type.toUpperCase())
) {
if (mayanQuote !== undefined && mayanQuote.success) {
// There are two special cases here for Mayan Swift transfers
//
// 1) Disallow transfers >$10,000 (temporary, while in beta)
// 1) Apply limits for the specified protocols, see MAYAN_BETA_PROTOCOL_LIMITS (temporary, while in beta).
// 2) For transfers <=$10,000, calculate network costs manually, because Mayan API doesn't
// expose relayer fee info for Swift quotes.
//
// TODO all of the code here is horrible and would ideally not exist

if (usdValue !== undefined && usdValue > MAYAN_BETA_LIMIT) {
// Temporarily disallow Swift quotes above $10,000
const protocolLimit =
MAYAN_BETA_PROTOCOL_LIMITS[mayanQuote.details?.type.toUpperCase()];

if (
protocolLimit &&
usdValue !== undefined &&
usdValue > protocolLimit
) {
// Temporarily disallow quotes above the limit
// TODO revisit this
quotesMap[name] = {
success: false,
error: new Error(
`Amount exceeds limit of $${MAYAN_BETA_LIMIT} USD`,
),
error: new Error(`Amount exceeds limit of $${protocolLimit} USD`),
};
} else {
const approxInputUsdValue = calculateUSDPriceRaw(
Expand Down

0 comments on commit cdf8687

Please sign in to comment.