Skip to content

Commit

Permalink
(Deposit/Withdraw) Fix Penumbra Issue (#3966)
Browse files Browse the repository at this point in the history
* feat: add penumbra bridge provider

* fix: build

* fix: build
  • Loading branch information
JoseRFelix authored Nov 23, 2024
1 parent 8419dea commit 8179a7f
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/bridge/src/bridge-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IbcBridgeProvider } from "./ibc";
import { BridgeProviderContext } from "./interface";
import { NitroBridgeProvider } from "./nitro";
import { NomicBridgeProvider } from "./nomic";
import { PenumbraBridgeProvider } from "./penumbra";
import { PicassoBridgeProvider } from "./picasso";
import { SkipBridgeProvider } from "./skip";
import { SquidBridgeProvider } from "./squid";
Expand All @@ -21,6 +22,7 @@ export class BridgeProviders {
[WormholeBridgeProvider.ID]: WormholeBridgeProvider;
[NitroBridgeProvider.ID]: NitroBridgeProvider;
[PicassoBridgeProvider.ID]: PicassoBridgeProvider;
[PenumbraBridgeProvider.ID]: PenumbraBridgeProvider;
};

constructor(integratorId: string, commonContext: BridgeProviderContext) {
Expand All @@ -40,6 +42,7 @@ export class BridgeProviders {
[WormholeBridgeProvider.ID]: new WormholeBridgeProvider(commonContext),
[NitroBridgeProvider.ID]: new NitroBridgeProvider(commonContext),
[PicassoBridgeProvider.ID]: new PicassoBridgeProvider(commonContext),
[PenumbraBridgeProvider.ID]: new PenumbraBridgeProvider(commonContext),
};
}
}
7 changes: 7 additions & 0 deletions packages/bridge/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,19 @@ const tronChainSchema = z.object({
chainType: z.literal("tron"),
});

const penumbraChainSchema = z.object({
chainId: z.string(),
chainName: z.string(),
chainType: z.literal("penumbra"),
});

export const bridgeChainSchema = z.discriminatedUnion("chainType", [
cosmosChainSchema,
evmChainSchema,
solanaChainSchema,
bitcoinChainSchema,
tronChainSchema,
penumbraChainSchema,
]);

export type BridgeChain = z.infer<typeof bridgeChainSchema>;
Expand Down
65 changes: 65 additions & 0 deletions packages/bridge/src/penumbra/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
BridgeChain,
BridgeExternalUrl,
BridgeProvider,
BridgeProviderContext,
BridgeQuote,
BridgeSupportedAsset,
BridgeTransactionRequest,
GetBridgeSupportedAssetsParams,
} from "../interface";

export class PenumbraBridgeProvider implements BridgeProvider {
static readonly ID = "Penumbra";
readonly providerName = PenumbraBridgeProvider.ID;

constructor(protected readonly ctx: BridgeProviderContext) {}

async getQuote(): Promise<BridgeQuote> {
throw new Error("Penumbra quotes are currently not supported.");
}

async getSupportedAssets({
asset,
}: GetBridgeSupportedAssetsParams): Promise<
(BridgeChain & BridgeSupportedAsset)[]
> {
// just supports SOL via Penumbra

const assetListAsset = this.ctx.assetLists
.flatMap(({ assets }) => assets)
.find(
(a) => a.coinMinimalDenom.toLowerCase() === asset.address.toLowerCase()
);

if (assetListAsset) {
const penumbraCounterparty = assetListAsset.counterparty.find(
(c) => c.chainName === "penumbra"
);

if (penumbraCounterparty) {
return [
{
transferTypes: ["external-url"],
chainId: "penumbra",
chainName: "Penumbra",
chainType: "penumbra",
denom: penumbraCounterparty.symbol,
address: penumbraCounterparty.sourceDenom,
decimals: penumbraCounterparty.decimals,
},
];
}
}

return [];
}

async getTransactionData(): Promise<BridgeTransactionRequest> {
throw new Error("Penumbra transactions are currently not supported.");
}

async getExternalUrl(): Promise<BridgeExternalUrl | undefined> {
throw new Error("Penumbra external urls are currently not supported.");
}
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from "./gas-utils";
export * from "./ibc-utils";
export * from "./math";
export * from "./object";
export * from "./penumbra";
export * from "./poll";
export * from "./solana";
export * from "./sort";
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/src/penumbra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const PenumbraChainInfo = {
prettyName: "Penumbra",
chainId: "penumbra",
chainName: "Penumbra",
color: "#ff902f",
};
8 changes: 8 additions & 0 deletions packages/web/components/bridge/amount-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ export const AmountScreen = observer(
type: fromChain.chainType,
assets: assets as Extract<SupportedAsset, { chainType: "tron" }>[],
};
case "penumbra":
return {
type: fromChain.chainType,
assets: assets as Extract<
SupportedAsset,
{ chainType: "penumbra" }
>[],
};
default:
return {
type: fromChain.chainType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ const supportedAssetsBridges: Bridge[] = [
"Squid",
"Axelar",
"IBC",
// include nomic, nitro and wormhole for suggesting BTC + SOL + TRX assets and chains
// include nomic, nitro, wormhole, and penumbra for suggesting BTC + SOL + TRX assets and chains
// as external URL transfer options, even though they are not supported by the bridge providers natively yet.
// Once bridging is natively supported, we can add these to the `useBridgeQuotes` provider list.
"Nomic",
"Wormhole",
"Nitro",
"Picasso",
"Penumbra",
];

export type SupportedAsset = ReturnType<
Expand Down
40 changes: 40 additions & 0 deletions packages/web/public/networks/penumbra.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/web/server/api/routers/bridge-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EthereumChainInfo,
isNil,
isSameVariant,
PenumbraChainInfo,
SolanaChainInfo,
timeout,
TronChainInfo,
Expand All @@ -41,6 +42,7 @@ export type BridgeChainWithDisplayInfo = (
| Extract<BridgeChain, { chainType: "evm" }>
| Extract<BridgeChain, { chainType: "bitcoin" }>
| Extract<BridgeChain, { chainType: "solana" }>
| Extract<BridgeChain, { chainType: "penumbra" }>
| (Extract<BridgeChain, { chainType: "cosmos" }> & { bech32Prefix: string })
| Extract<BridgeChain, { chainType: "tron" }>
) & {
Expand Down Expand Up @@ -419,6 +421,12 @@ export const bridgeTransferRouter = createTRPCRouter({
chainType,
logoUri: "/networks/tron.svg",
};
} else if (chainType === "penumbra") {
return {
...PenumbraChainInfo,
chainType,
logoUri: "/networks/penumbra.svg",
};
}

return undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/web/server/api/routers/local-bridge-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const localBridgeTransferRouter = createTRPCRouter({
createAssetObject("bitcoin", z.object({})),
createAssetObject("solana", z.object({})),
createAssetObject("tron", z.object({})),
createAssetObject("penumbra", z.object({})),
]),
})
)
Expand Down Expand Up @@ -236,7 +237,7 @@ export const localBridgeTransferRouter = createTRPCRouter({

return assetsWithBalance;
} else {
// For Bitcoin, Tron or Solana, return 0 assets as it's not supported for now
// For Bitcoin, Tron, Penumbra or Solana, return 0 assets as it's not supported for now
// TODO: add 2 more else statements and send balance queries to Bitcoin, Tron or Solana as needed

return input.source.assets.map((asset) => ({
Expand Down
2 changes: 2 additions & 0 deletions packages/web/utils/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const BridgeLogoUrls: Record<Bridge, string> = {
Wormhole: "/bridges/wormhole.svg",
Nitro: "/bridges/nitro.svg",
Picasso: "/bridges/picasso.svg",
Penumbra: "/networks/penumbra.svg",
};

export const ExternalBridgeLogoUrls: Record<Bridge | "Generic", string> = {
Expand All @@ -21,4 +22,5 @@ export const ExternalBridgeLogoUrls: Record<Bridge | "Generic", string> = {
Generic: "/external-bridges/generic.svg",
Nitro: "/bridges/nitro.svg",
Picasso: "/bridges/picasso.svg",
Penumbra: "/networks/penumbra.svg",
};

0 comments on commit 8179a7f

Please sign in to comment.