@funkit/fun-relay 2.2.0-next.5 → 2.2.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -833,7 +833,7 @@ import {
833
833
  encodeFunctionData as encodeFunctionData2,
834
834
  toFunctionSelector
835
835
  } from "viem";
836
- import { mainnet as mainnet2 } from "viem/chains";
836
+ import { mainnet as mainnet3 } from "viem/chains";
837
837
 
838
838
  // src/dynamicRoutes/abi.ts
839
839
  var UNWRAP_AND_CALL_ABI = [
@@ -1276,7 +1276,7 @@ var ASSET_LOGO_SRCS = {
1276
1276
  IMX: "https://sdk-cdn.fun.xyz/images/imx.svg",
1277
1277
  INJ: "https://sdk-cdn.fun.xyz/images/inj.svg",
1278
1278
  LDO: "https://sdk-cdn.fun.xyz/images/ldo.svg",
1279
- LINK: "https://sdk-cdn.fun.xyz/images/link.svg",
1279
+ LINK: "https://sdk-cdn.fun.xyz/images/link.png",
1280
1280
  LUCK: "https://sdk-cdn.fun.xyz/images/luck.png",
1281
1281
  MATIC: "https://sdk-cdn.fun.xyz/images/matic.svg",
1282
1282
  MFER: "https://sdk-cdn.fun.xyz/images/mfer.png",
@@ -1294,7 +1294,7 @@ var ASSET_LOGO_SRCS = {
1294
1294
  SOL: "https://sdk-cdn.fun.xyz/images/sol.svg",
1295
1295
  SUSDS: "https://sdk-cdn.fun.xyz/images/susds.svg",
1296
1296
  TYBG: "https://sdk-cdn.fun.xyz/images/tybg.png",
1297
- UNI: "https://sdk-cdn.fun.xyz/images/uni.svg",
1297
+ UNI: "https://sdk-cdn.fun.xyz/images/uni.png",
1298
1298
  USDC: "https://sdk-cdn.fun.xyz/images/usdc.svg",
1299
1299
  "USDC.E": "https://sdk-cdn.fun.xyz/images/usdc.svg",
1300
1300
  USDE: "https://sdk-cdn.fun.xyz/images/usde.svg",
@@ -1335,7 +1335,8 @@ var ASSET_LOGO_SRCS = {
1335
1335
  MON: "https://sdk-cdn.fun.xyz/images/monad.svg",
1336
1336
  WMON: "https://sdk-cdn.fun.xyz/images/wmon.svg",
1337
1337
  AUSD: "https://sdk-cdn.fun.xyz/images/ausd.svg",
1338
- SUSHI: "https://sdk-cdn.fun.xyz/images/sushi.svg"
1338
+ SUSHI: "https://sdk-cdn.fun.xyz/images/sushi.svg",
1339
+ SKY: "https://sdk-cdn.fun.xyz/images/sky.svg"
1339
1340
  };
1340
1341
 
1341
1342
  // src/dynamicRoutes/consts.ts
@@ -1349,6 +1350,25 @@ var tokenAddresses = {
1349
1350
  },
1350
1351
  USDC: {
1351
1352
  [mainnet.id]: getAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
1353
+ },
1354
+ // LIT is currently unused
1355
+ LIT: {
1356
+ [mainnet.id]: getAddress("0x232CE3bd40fCd6f80f3d55A522d03f25Df784Ee2")
1357
+ },
1358
+ LINK: {
1359
+ [mainnet.id]: getAddress("0x514910771AF9Ca656af840dff83E8264EcF986CA")
1360
+ },
1361
+ UNI: {
1362
+ [mainnet.id]: getAddress("0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984")
1363
+ },
1364
+ AAVE: {
1365
+ [mainnet.id]: getAddress("0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9")
1366
+ },
1367
+ SKY: {
1368
+ [mainnet.id]: getAddress("0x56072C95FAA701256059aa122697B133aDEd9279")
1369
+ },
1370
+ LDO: {
1371
+ [mainnet.id]: getAddress("0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32")
1352
1372
  }
1353
1373
  };
1354
1374
  var UNWRAP_AND_CALL_ADDRESS = {
@@ -1363,6 +1383,8 @@ var LIGHTER_DEPOSIT_ADDRESS = getAddress(
1363
1383
  var MATCH_ALL_CONDITION = "*";
1364
1384
 
1365
1385
  // src/dynamicRoutes/utils.ts
1386
+ import { erc20Abi as ERC20_ABI } from "viem";
1387
+ import { mainnet as mainnet2 } from "viem/chains";
1366
1388
  var createPath = (config) => {
1367
1389
  return config;
1368
1390
  };
@@ -1445,6 +1467,35 @@ var initDynamicRouting = (dynamicRoutes, dynamicRoutingConfig) => {
1445
1467
  );
1446
1468
  return indexedDynamicRoutingConfig;
1447
1469
  };
1470
+ var MAX_APPROVAL = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
1471
+ var getApprovalCalldata = ({
1472
+ tokenAddress,
1473
+ spenderAddress,
1474
+ amount
1475
+ }) => {
1476
+ return {
1477
+ contractAbi: ERC20_ABI,
1478
+ contractAddress: tokenAddress,
1479
+ functionName: "approve",
1480
+ functionArgs: [spenderAddress, amount]
1481
+ };
1482
+ };
1483
+ var getResetApprovalCalldata = ({
1484
+ tokenAddress,
1485
+ spenderAddress
1486
+ }) => {
1487
+ return getApprovalCalldata({
1488
+ tokenAddress,
1489
+ spenderAddress,
1490
+ amount: "0"
1491
+ });
1492
+ };
1493
+ var RESET_APPROVAL_TOKENS = [tokenAddresses.LDO[mainnet2.id]].map(
1494
+ (address) => address.toLowerCase()
1495
+ );
1496
+ var shouldResetApproval = (tokenAddress) => {
1497
+ return RESET_APPROVAL_TOKENS.includes(tokenAddress.toLowerCase());
1498
+ };
1448
1499
 
1449
1500
  // src/dynamicRoutes/lighter.ts
1450
1501
  var NATIVE_TOKEN = FUNKIT_NATIVE_TOKEN;
@@ -1453,14 +1504,31 @@ var RELAY_LIGHTER_ETH_SPOT_ADDRESS = "0x0000000000000000000000000000000000000001
1453
1504
  var RELAY_LIGHTER_USDC_PERPS_ADDRESS = "0x0000000000000000000000000000000000000000";
1454
1505
  var TICK_SIZE_FOR_ASSET_INDEX = {
1455
1506
  [3 /* USDC */]: BigInt(1),
1456
- [1 /* ETH */]: BigInt(10 ** 10)
1507
+ [1 /* ETH */]: BigInt(10 ** 10),
1508
+ [2 /* LIT */]: BigInt(10 ** 10),
1509
+ [5 /* LINK */]: BigInt(10 ** 10),
1510
+ [6 /* UNI */]: BigInt(10 ** 10),
1511
+ [7 /* AAVE */]: BigInt(10 ** 10),
1512
+ [8 /* SKY */]: BigInt(10 ** 10),
1513
+ [9 /* LDO */]: BigInt(10 ** 10)
1457
1514
  };
1458
1515
  var DEPOSIT_TOKEN_FOR_ASSET_INDEX = {
1459
- [3 /* USDC */]: tokenAddresses.USDC[mainnet2.id],
1460
- [1 /* ETH */]: NATIVE_TOKEN
1516
+ [3 /* USDC */]: tokenAddresses.USDC[mainnet3.id],
1517
+ [1 /* ETH */]: NATIVE_TOKEN,
1518
+ [2 /* LIT */]: tokenAddresses.LIT[mainnet3.id],
1519
+ [5 /* LINK */]: tokenAddresses.LINK[mainnet3.id],
1520
+ [6 /* UNI */]: tokenAddresses.UNI[mainnet3.id],
1521
+ [7 /* AAVE */]: tokenAddresses.AAVE[mainnet3.id],
1522
+ [8 /* SKY */]: tokenAddresses.SKY[mainnet3.id],
1523
+ [9 /* LDO */]: tokenAddresses.LDO[mainnet3.id]
1461
1524
  };
1462
1525
  var USDC_PERPS_SYMBOL = "USDC (Perps)";
1463
1526
  var ETH_SPOT_SYMBOL = "ETH (Spot)";
1527
+ var LINK_SPOT_SYMBOL = "LINK (Spot)";
1528
+ var UNI_SPOT_SYMBOL = "UNI (Spot)";
1529
+ var AAVE_SPOT_SYMBOL = "AAVE (Spot)";
1530
+ var SKY_SPOT_SYMBOL = "SKY (Spot)";
1531
+ var LDO_SPOT_SYMBOL = "LDO (Spot)";
1464
1532
  var generateLighterMainnetDepositActions = ({
1465
1533
  address,
1466
1534
  assetIndex,
@@ -1503,22 +1571,18 @@ var generateLighterMainnetDepositActions = ({
1503
1571
  });
1504
1572
  return [
1505
1573
  // Step 1: Approve WETH to UnwrapWETHAndCall
1506
- {
1507
- contractAbi: erc20Abi,
1508
- contractAddress: tokenAddresses.WETH[mainnet2.id],
1509
- functionName: "approve",
1510
- functionArgs: [
1511
- UNWRAP_AND_CALL_ADDRESS[mainnet2.id],
1512
- "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1513
- ]
1514
- },
1574
+ getApprovalCalldata({
1575
+ tokenAddress: tokenAddresses.WETH[mainnet3.id],
1576
+ spenderAddress: UNWRAP_AND_CALL_ADDRESS[mainnet3.id],
1577
+ amount: MAX_APPROVAL
1578
+ }),
1515
1579
  // Step 2: UnwrapWETHAndCall pulls WETH, unwraps to ETH, sends to VaultWrapper, calls deposit
1516
1580
  {
1517
1581
  contractAbi: UNWRAP_AND_CALL_ABI,
1518
- contractAddress: UNWRAP_AND_CALL_ADDRESS[mainnet2.id],
1582
+ contractAddress: UNWRAP_AND_CALL_ADDRESS[mainnet3.id],
1519
1583
  functionName: "unwrapAndCall",
1520
1584
  functionArgs: [
1521
- VAULT_DEPOSITOR_ADDRESS[mainnet2.id],
1585
+ VAULT_DEPOSITOR_ADDRESS[mainnet3.id],
1522
1586
  // target (VaultWrapper)
1523
1587
  vaultWrapperCalldata
1524
1588
  // VaultWrapper.deposit() calldata
@@ -1526,52 +1590,53 @@ var generateLighterMainnetDepositActions = ({
1526
1590
  }
1527
1591
  ];
1528
1592
  }
1529
- if (depositToken === tokenAddresses.USDC[mainnet2.id]) {
1530
- return [
1531
- // Step 1: Approve USDC to VaultDepositor
1532
- {
1533
- contractAbi: erc20Abi,
1534
- contractAddress: tokenAddresses.USDC[mainnet2.id],
1535
- functionName: "approve",
1536
- functionArgs: [
1537
- VAULT_DEPOSITOR_ADDRESS[mainnet2.id],
1538
- "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1539
- // Max approval
1540
- ]
1541
- },
1542
- // Step 2: VaultDepositor pulls USDC and calls Lighter deposit
1543
- {
1544
- contractAbi: VAULT_DEPOSITOR_ABI,
1545
- contractAddress: VAULT_DEPOSITOR_ADDRESS[mainnet2.id],
1546
- functionName: "depositWithTick",
1547
- functionArgs: [
1548
- tokenAddresses.USDC[mainnet2.id],
1549
- // token (USDC)
1550
- LIGHTER_DEPOSIT_ADDRESS,
1551
- // vault (Lighter deposit contract)
1552
- lighterDepositCalldata,
1553
- // callData
1554
- 0n,
1555
- // minAmountOut
1556
- tickSize,
1557
- // tickSize
1558
- dustRecipient
1559
- // dustRecipient
1560
- ]
1561
- }
1562
- ];
1563
- }
1593
+ const resetApprovalNeeded = shouldResetApproval(depositToken);
1594
+ return [
1595
+ // Special handling of LDO token as it requires approval reset before approval can be set to a new value due to non-standard implementation of the approve function.
1596
+ ...resetApprovalNeeded ? [
1597
+ getResetApprovalCalldata({
1598
+ tokenAddress: depositToken,
1599
+ spenderAddress: VAULT_DEPOSITOR_ADDRESS[mainnet3.id]
1600
+ })
1601
+ ] : [],
1602
+ // Step 1: Approve deposit token to VaultDepositor
1603
+ getApprovalCalldata({
1604
+ tokenAddress: depositToken,
1605
+ spenderAddress: VAULT_DEPOSITOR_ADDRESS[mainnet3.id],
1606
+ amount: MAX_APPROVAL
1607
+ }),
1608
+ // Step 2: VaultDepositor pulls deposit token and calls Lighter deposit
1609
+ {
1610
+ contractAbi: VAULT_DEPOSITOR_ABI,
1611
+ contractAddress: VAULT_DEPOSITOR_ADDRESS[mainnet3.id],
1612
+ functionName: "depositWithTick",
1613
+ functionArgs: [
1614
+ depositToken,
1615
+ // token (deposit token)
1616
+ LIGHTER_DEPOSIT_ADDRESS,
1617
+ // vault (Lighter deposit contract)
1618
+ lighterDepositCalldata,
1619
+ // callData
1620
+ 0n,
1621
+ // minAmountOut
1622
+ tickSize,
1623
+ // tickSize
1624
+ dustRecipient
1625
+ // dustRecipient
1626
+ ]
1627
+ }
1628
+ ];
1564
1629
  };
1565
1630
  var LIGHTER_USDC_PERPS_FUN_MAINNET_DEPOSIT = createPath({
1566
- targetChain: mainnet2.id.toString(),
1567
- targetAsset: tokenAddresses.USDC[mainnet2.id],
1631
+ targetChain: mainnet3.id.toString(),
1632
+ targetAsset: tokenAddresses.USDC[mainnet3.id],
1568
1633
  targetAssetTicker: USDC_PERPS_SYMBOL,
1569
1634
  iconSrc: ASSET_LOGO_SRCS.USDC,
1570
1635
  generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1571
1636
  if (!outputConfig) {
1572
1637
  return [];
1573
1638
  }
1574
- if (outputConfig.targetChain !== mainnet2.id.toString()) {
1639
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1575
1640
  return [];
1576
1641
  }
1577
1642
  return generateLighterMainnetDepositActions({
@@ -1582,15 +1647,15 @@ var LIGHTER_USDC_PERPS_FUN_MAINNET_DEPOSIT = createPath({
1582
1647
  }
1583
1648
  });
1584
1649
  var LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1585
- targetChain: mainnet2.id.toString(),
1586
- targetAsset: tokenAddresses.WETH[mainnet2.id],
1650
+ targetChain: mainnet3.id.toString(),
1651
+ targetAsset: tokenAddresses.WETH[mainnet3.id],
1587
1652
  targetAssetTicker: ETH_SPOT_SYMBOL,
1588
1653
  iconSrc: ASSET_LOGO_SRCS.ETH,
1589
1654
  generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1590
1655
  if (!outputConfig) {
1591
1656
  return [];
1592
1657
  }
1593
- if (outputConfig.targetChain !== mainnet2.id.toString()) {
1658
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1594
1659
  return [];
1595
1660
  }
1596
1661
  return generateLighterMainnetDepositActions({
@@ -1600,6 +1665,101 @@ var LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1600
1665
  });
1601
1666
  }
1602
1667
  });
1668
+ var LIGHTER_LINK_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1669
+ targetChain: mainnet3.id.toString(),
1670
+ targetAsset: tokenAddresses.LINK[mainnet3.id],
1671
+ targetAssetTicker: LINK_SPOT_SYMBOL,
1672
+ iconSrc: ASSET_LOGO_SRCS.LINK,
1673
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1674
+ if (!outputConfig) {
1675
+ return [];
1676
+ }
1677
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1678
+ return [];
1679
+ }
1680
+ return generateLighterMainnetDepositActions({
1681
+ address,
1682
+ assetIndex: 5 /* LINK */,
1683
+ routeType: 1 /* Spot */
1684
+ });
1685
+ }
1686
+ });
1687
+ var LIGHTER_SKY_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1688
+ targetChain: mainnet3.id.toString(),
1689
+ targetAsset: tokenAddresses.SKY[mainnet3.id],
1690
+ targetAssetTicker: SKY_SPOT_SYMBOL,
1691
+ iconSrc: ASSET_LOGO_SRCS.SKY,
1692
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1693
+ if (!outputConfig) {
1694
+ return [];
1695
+ }
1696
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1697
+ return [];
1698
+ }
1699
+ return generateLighterMainnetDepositActions({
1700
+ address,
1701
+ assetIndex: 8 /* SKY */,
1702
+ routeType: 1 /* Spot */
1703
+ });
1704
+ }
1705
+ });
1706
+ var LIGHTER_UNI_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1707
+ targetChain: mainnet3.id.toString(),
1708
+ targetAsset: tokenAddresses.UNI[mainnet3.id],
1709
+ targetAssetTicker: UNI_SPOT_SYMBOL,
1710
+ iconSrc: ASSET_LOGO_SRCS.UNI,
1711
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1712
+ if (!outputConfig) {
1713
+ return [];
1714
+ }
1715
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1716
+ return [];
1717
+ }
1718
+ return generateLighterMainnetDepositActions({
1719
+ address,
1720
+ assetIndex: 6 /* UNI */,
1721
+ routeType: 1 /* Spot */
1722
+ });
1723
+ }
1724
+ });
1725
+ var LIGHTER_AAVE_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1726
+ targetChain: mainnet3.id.toString(),
1727
+ targetAsset: tokenAddresses.AAVE[mainnet3.id],
1728
+ targetAssetTicker: AAVE_SPOT_SYMBOL,
1729
+ iconSrc: ASSET_LOGO_SRCS.AAVE,
1730
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1731
+ if (!outputConfig) {
1732
+ return [];
1733
+ }
1734
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1735
+ return [];
1736
+ }
1737
+ return generateLighterMainnetDepositActions({
1738
+ address,
1739
+ assetIndex: 7 /* AAVE */,
1740
+ routeType: 1 /* Spot */
1741
+ });
1742
+ }
1743
+ });
1744
+ var LIGHTER_LDO_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1745
+ targetChain: mainnet3.id.toString(),
1746
+ targetAsset: tokenAddresses.LDO[mainnet3.id],
1747
+ targetAssetTicker: LDO_SPOT_SYMBOL,
1748
+ iconSrc: ASSET_LOGO_SRCS.LDO,
1749
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1750
+ if (!outputConfig) {
1751
+ return [];
1752
+ }
1753
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1754
+ return [];
1755
+ }
1756
+ return generateLighterMainnetDepositActions({
1757
+ address,
1758
+ assetIndex: 9 /* LDO */,
1759
+ routeType: 1 /* Spot */
1760
+ });
1761
+ }
1762
+ });
1603
1763
  var LIGHTER_DYNAMIC_ROUTES = [
1604
1764
  createRoute({
1605
1765
  id: "LIGHTER_ETH_SPOT",
@@ -1642,6 +1802,37 @@ var LIGHTER_DYNAMIC_ROUTES = [
1642
1802
  paths: {
1643
1803
  FUN_MAINNET_DEPOSIT: LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT
1644
1804
  }
1805
+ }),
1806
+ // LINK, UNI, AAVE, SKY, LDO tokens
1807
+ createRoute({
1808
+ id: "LIGHTER_LINK_SPOT_NEW_USER",
1809
+ paths: {
1810
+ FUN_MAINNET_DEPOSIT: LIGHTER_LINK_SPOT_FUN_MAINNET_DEPOSIT
1811
+ }
1812
+ }),
1813
+ createRoute({
1814
+ id: "LIGHTER_SKY_SPOT_NEW_USER",
1815
+ paths: {
1816
+ FUN_MAINNET_DEPOSIT: LIGHTER_SKY_SPOT_FUN_MAINNET_DEPOSIT
1817
+ }
1818
+ }),
1819
+ createRoute({
1820
+ id: "LIGHTER_UNI_SPOT_NEW_USER",
1821
+ paths: {
1822
+ FUN_MAINNET_DEPOSIT: LIGHTER_UNI_SPOT_FUN_MAINNET_DEPOSIT
1823
+ }
1824
+ }),
1825
+ createRoute({
1826
+ id: "LIGHTER_AAVE_SPOT_NEW_USER",
1827
+ paths: {
1828
+ FUN_MAINNET_DEPOSIT: LIGHTER_AAVE_SPOT_FUN_MAINNET_DEPOSIT
1829
+ }
1830
+ }),
1831
+ createRoute({
1832
+ id: "LIGHTER_LDO_SPOT_NEW_USER",
1833
+ paths: {
1834
+ FUN_MAINNET_DEPOSIT: LIGHTER_LDO_SPOT_FUN_MAINNET_DEPOSIT
1835
+ }
1645
1836
  })
1646
1837
  ];
1647
1838
 
@@ -1679,6 +1870,7 @@ export {
1679
1870
  initDynamicRouting,
1680
1871
  initializeRelayClient,
1681
1872
  isRelayExecutionTerminalStatus,
1682
- parseRelayFees
1873
+ parseRelayFees,
1874
+ shouldResetApproval
1683
1875
  };
1684
1876
  //# sourceMappingURL=index.mjs.map