-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3697 from osmosis-labs/stage
Publish Stage
- Loading branch information
Showing
142 changed files
with
12,242 additions
and
1,604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.