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

Add Mayan Shuttle protocol and update all protocol limits #3247

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
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
88 changes: 80 additions & 8 deletions wormhole-connect/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wormhole-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@ledgerhq/hw-transport": "6.27.1",
"@ledgerhq/hw-transport-webhid": "6.27.1",
"@ledgerhq/logs": "6.12.0",
"@mayanfinance/wormhole-sdk-route": "1.1.0",
"@mayanfinance/wormhole-sdk-route": "1.3.0",
"@metaplex-foundation/mpl-token-metadata": "^3.3.0",
"@metaplex-foundation/umi": "^0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
Expand Down
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 @@
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 @@
/* @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 @@ -145,7 +148,7 @@
}
};

useEffect(emitCustomConfig, []);

Check warning on line 151 in wormhole-connect/src/components/DemoApp/index.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'customConfigInput', 'customConfigNonce', and 'isLoadingCustomConfig'. Either include them or remove the dependency array. You can also do a functional update 'setCustomConfigNonce(c => ...)' if you only need 'customConfigNonce' in the 'setCustomConfigNonce' call

return (
<>
Expand Down Expand Up @@ -227,6 +230,10 @@
<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: 1_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
2 changes: 2 additions & 0 deletions wormhole-connect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MayanRouteWH,
MayanRouteMCTP,
MayanRouteSWIFT,
MayanRouteSHUTTLE,
} from '@mayanfinance/wormhole-sdk-route';
import {
nttAutomaticRoute,
Expand Down Expand Up @@ -63,6 +64,7 @@ export {
MayanRouteWH,
MayanRouteMCTP,
MayanRouteSWIFT,
MayanRouteSHUTTLE,

// Utility function for CDN-hosted version of Connect
wormholeConnectHosted,
Expand Down
Loading