Skip to content

Commit

Permalink
Merge pull request #3697 from osmosis-labs/stage
Browse files Browse the repository at this point in the history
Publish Stage
  • Loading branch information
JoseRFelix authored Aug 8, 2024
2 parents 31bebcc + a183638 commit 756fb9f
Show file tree
Hide file tree
Showing 142 changed files with 12,242 additions and 1,604 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
preview-pools-and-select-pair-tests:
timeout-minutes: 10
needs: wait-for-deployment
runs-on: buildjet-4vcpu-ubuntu-2204
runs-on: macos-14
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/monitoring-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
BASE_URL: ${{ matrix.base-url }}
run: |
cd packages/web
npx playwright test -g "Test Select Swap Pair feature"
npx playwright test pools
- name: upload test results
if: failure()
id: e2e-test-results
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/monitoring-geo-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
run: curl -L "https://ipinfo.io" -s
- name: Check out repository
uses: actions/checkout@v4
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -69,6 +71,8 @@ jobs:
run: curl -L "https://ipinfo.io" -s
- name: Check out repository
uses: actions/checkout@v4
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -143,6 +147,8 @@ jobs:
run: curl -L "https://ipinfo.io" -s
- name: Check out repository
uses: actions/checkout@v4
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -186,6 +192,8 @@ jobs:
run: curl -L "https://ipinfo.io" -s
- name: Check out repository
uses: actions/checkout@v4
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prod-frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/server-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,3 @@ jobs:
env:
NEXT_PUBLIC_SIDECAR_BASE_URL: ${{ matrix.server-url }}
NEXT_PUBLIC_TIMESERIES_DATA_URL: ${{ matrix.timeseries-url }}

# Send Slack alert if 'tests' job fails
- name: Send Slack alert if test fails
id: slack
if: failure()
uses: slackapi/[email protected]
with:
payload: |
{
"text": "🚨 Server to SQS E2E Tests Failure Alert 🚨",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Server to SQS E2E Tests Failure"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Environment:* ${{ matrix.env }}\n*Server URL:* ${{ matrix.server-url }}\n*Timeseries URL:* ${{ matrix.timeseries-url }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Click here to view the run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|GitHub Actions Run>"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SERVER_E2E_TESTS_SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
3 changes: 2 additions & 1 deletion packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"long": "^5.2.3",
"lru-cache": "^10.0.1",
"viem": "2.16.4",
"zod": "^3.22.4"
"zod": "^3.22.4",
"base-x": "^5.0.0"
},
"devDependencies": {
"@types/jest-in-case": "^1.0.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/bridge/src/bridge-providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxelarBridgeProvider } from "./axelar";
import { IbcBridgeProvider } from "./ibc";
import { BridgeProviderContext } from "./interface";
import { NitroBridgeProvider } from "./nitro";
import { NomicBridgeProvider } from "./nomic";
import { SkipBridgeProvider } from "./skip";
import { SquidBridgeProvider } from "./squid";
Expand All @@ -17,6 +18,7 @@ export class BridgeProviders {
[IbcBridgeProvider.ID]: IbcBridgeProvider;
[NomicBridgeProvider.ID]: NomicBridgeProvider;
[WormholeBridgeProvider.ID]: WormholeBridgeProvider;
[NitroBridgeProvider.ID]: NitroBridgeProvider;
};

constructor(integratorId: string, commonContext: BridgeProviderContext) {
Expand All @@ -34,6 +36,7 @@ export class BridgeProviders {
[IbcBridgeProvider.ID]: new IbcBridgeProvider(commonContext),
[NomicBridgeProvider.ID]: new NomicBridgeProvider(commonContext),
[WormholeBridgeProvider.ID]: new WormholeBridgeProvider(commonContext),
[NitroBridgeProvider.ID]: new NitroBridgeProvider(commonContext),
};
}
}
19 changes: 16 additions & 3 deletions packages/bridge/src/ibc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,27 @@ export class IbcBridgeProvider implements BridgeProvider {
}

/**
* Gets gas asset from asset list, attempting to match the coinMinimalDenom or counterparty denom.
* Gets gas asset from asset list or chain list, attempting to match the coinMinimalDenom or chainSuggestionDenom.
* @returns gas bridge asset, or undefined if not found.
*/
async getGasAsset(
fromChainId: string,
denom: string
): Promise<BridgeAsset | undefined> {
// check the asset list
// try to get asset list fee asset first, or otherwise the chain fee currency
const assetListAsset = this.ctx.assetLists
.flatMap(({ assets }) => assets)
.find((asset) => asset.coinMinimalDenom);

if (assetListAsset) {
return {
address: assetListAsset.coinMinimalDenom,
denom: assetListAsset.symbol,
decimals: assetListAsset.decimals,
coinGeckoId: assetListAsset.coingeckoId,
};
}

const chains = await this.getChains();
const chain = chains.find((c) => c.chain_id === fromChainId);
const feeCurrency = chain?.feeCurrencies.find(
Expand Down Expand Up @@ -366,7 +379,7 @@ export class IbcBridgeProvider implements BridgeProvider {
fromAsset,
toAsset,
}: GetBridgeExternalUrlParams): Promise<BridgeExternalUrl | undefined> {
if (fromChain?.chainType === "evm" || toChain?.chainType === "evm") {
if (fromChain?.chainType !== "cosmos" || toChain?.chainType !== "cosmos") {
return undefined;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/bridge/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,25 @@ const bitcoinChainSchema = z.object({
chainType: z.literal("bitcoin"),
});

const tronChainSchema = z.object({
/**
* 728126428
*/
chainId: z.number(),
/**
* Optional: The human-readable name of the chain.
*/
chainName: z.string().optional(),

chainType: z.literal("tron"),
});

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

export type BridgeChain = z.infer<typeof bridgeChainSchema>;
Expand Down
142 changes: 142 additions & 0 deletions packages/bridge/src/nitro/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import {
NativeEVMTokenConstantAddress,
TronChainInfo,
} from "@osmosis-labs/utils";
import basex from "base-x";

import {
BridgeAsset,
BridgeChain,
BridgeExternalUrl,
BridgeProvider,
BridgeProviderContext,
BridgeQuote,
BridgeTransactionRequest,
GetBridgeExternalUrlParams,
GetBridgeSupportedAssetsParams,
} from "../interface";

const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
const bs58 = basex(BASE58);

export class NitroBridgeProvider implements BridgeProvider {
static readonly ID = "Nitro";
readonly providerName = NitroBridgeProvider.ID;

constructor(protected readonly ctx: BridgeProviderContext) {}

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

async getSupportedAssets({
asset,
}: GetBridgeSupportedAssetsParams): Promise<(BridgeChain & BridgeAsset)[]> {
try {
// just supports TRX, TRX.rt from Tron

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

if (assetListAsset) {
const variants = assets
.filter((a) => a?.variantGroupKey === assetListAsset.variantGroupKey)
.sort((a) =>
a.coinMinimalDenom === assetListAsset.variantGroupKey ? -1 : 1
);

const tronAsset = variants.length > 1 ? variants[1] : variants[0];

const tronCounterparty = tronAsset.counterparty.find(
(c) => c.chainName === "tron"
);

if (tronCounterparty) {
const isTRC20Token = tronCounterparty.sourceDenom.startsWith("T");
const address = isTRC20Token
? Buffer.from(bs58.decode(tronCounterparty.sourceDenom))
.toString("hex")
// Tron addresses in hexadecimal format always start with '41'.
// This prefix should be replaced with '0x' to convert it to a valid address.
.replace("41", "0x")
.substring(0, 42) // Tron addresses are 21 bytes long, so we need to truncate the last byte.
: undefined;

const resolvedAddress =
tronCounterparty.sourceDenom === "sun"
? NativeEVMTokenConstantAddress // Nitro uses the constant address to reference the native token
: address ?? tronCounterparty.sourceDenom;

return [
{
chainType: "tron",
chainId: TronChainInfo.chainId,
chainName: TronChainInfo.chainName,
denom: tronCounterparty.symbol,
address: resolvedAddress,
decimals: tronCounterparty.decimals,
},
];
}
}

return [];
} catch (e) {
// Avoid returning options if there's an unexpected error, such as the provider being down
if (process.env.NODE_ENV !== "production") {
console.error(
NitroBridgeProvider.ID,
"failed to get supported assets:",
e
);
}
return [];
}
}

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

async getExternalUrl({
fromChain,
toChain,
fromAsset,
toAsset,
}: GetBridgeExternalUrlParams): Promise<BridgeExternalUrl | undefined> {
const url = new URL("https://beta-mainnet.routernitro.com/swap");

if (fromChain) {
url.searchParams.set("fromChain", String(fromChain.chainId));
}

if (toChain) {
url.searchParams.set("toChain", String(toChain.chainId));
}

const setTokenParam = (asset: BridgeAsset, param: string) => {
if (asset.address.includes("alloyed")) {
const assets = this.ctx.assetLists.flatMap(({ assets }) => assets);
const alloy = assets.find((a) => a.coinMinimalDenom === asset.address);
const variant = assets.find(
(a) =>
a.variantGroupKey === alloy?.variantGroupKey &&
a.coinMinimalDenom !== alloy?.coinMinimalDenom
);
if (variant) url.searchParams.set(param, variant.coinMinimalDenom);
} else {
url.searchParams.set(param, asset.address);
}
};

if (fromAsset) setTokenParam(fromAsset, "fromToken");
if (toAsset) setTokenParam(toAsset, "toToken");

return {
urlProviderName: "Nitro",
url,
};
}
}
3 changes: 3 additions & 0 deletions packages/math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"@keplr-wallet/types": "0.10.24-ibc.go.v7.hot.fix",
"@keplr-wallet/unit": "0.10.24-ibc.go.v7.hot.fix",
"big-integer": "^1.6.48"
},
"devDependencies": {
"jest-in-case": "^1.0.2"
}
}
Loading

0 comments on commit 756fb9f

Please sign in to comment.