Skip to content
Merged
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
12 changes: 4 additions & 8 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ VITE_ARBITRUM_NOVA_NODE_URL=https://api.arbitrum-nova.shapeshift.com/api/v1/json
VITE_BASE_NODE_URL=https://api.base.shapeshift.com/api/v1/jsonrpc
VITE_MONAD_NODE_URL=https://rpc.monad.xyz
VITE_PLASMA_NODE_URL=https://rpc.plasma.to
# VITE_THORCHAIN_NODE_URL=https://api.thorchain.shapeshift.com/lcd
VITE_THORCHAIN_NODE_URL=https://thornode.ninerealms.com
# VITE_MAYACHAIN_NODE_URL=https://api.mayachain.shapeshift.com/lcd
VITE_MAYACHAIN_NODE_URL=https://mayanode.mayachain.info
VITE_THORCHAIN_NODE_URL=https://api.thorchain.shapeshift.com/lcd
VITE_MAYACHAIN_NODE_URL=https://api.mayachain.shapeshift.com/lcd
VITE_SOLANA_NODE_URL=https://api.solana.shapeshift.com/api/v1/jsonrpc
VITE_STARKNET_NODE_URL=https://rpc.starknet.lava.build
VITE_TRON_NODE_URL=https://api.trongrid.io
Expand All @@ -170,10 +168,8 @@ VITE_FASTNEAR_API_URL=https://api.fastnear.com
VITE_ALCHEMY_POLYGON_URL=https://polygon-mainnet.g.alchemy.com/v2/anoTMcIc2hbPUxri37h4DeuUwg2p5_xZ

# midgard
# VITE_THORCHAIN_MIDGARD_URL=https://api.thorchain.shapeshift.com/midgard/v2
VITE_THORCHAIN_MIDGARD_URL=https://midgard.ninerealms.com/v2
# VITE_MAYACHAIN_MIDGARD_URL=https://api.mayachain.shapeshift.com/midgard/v2
VITE_MAYACHAIN_MIDGARD_URL=https://midgard.mayachain.info/v2
VITE_THORCHAIN_MIDGARD_URL=https://api.thorchain.shapeshift.com/midgard/v2
VITE_MAYACHAIN_MIDGARD_URL=https://api.mayachain.shapeshift.com/midgard/v2

# foxy apr
VITE_TOKEMAK_STATS_URL=https://stats.tokemaklabs.com/
Expand Down
15 changes: 6 additions & 9 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,17 @@ VITE_BASE_NODE_URL=https://dev-api.base.shapeshift.com/api/v1/jsonrpc
VITE_MONAD_NODE_URL=https://rpc.monad.xyz
VITE_PLASMA_NODE_URL=https://rpc.plasma.to
VITE_HYPEREVM_NODE_URL=https://rpc.hyperliquid.xyz/evm
# Swap me back to SS as-needed
# VITE_THORCHAIN_NODE_URL=https://dev-api.thorchain.shapeshift.com/lcd
VITE_THORCHAIN_NODE_URL=https://thornode.ninerealms.com
# VITE_MAYACHAIN_NODE_URL=https://dev-api.mayachain.shapeshift.com/lcd
VITE_MAYACHAIN_NODE_URL=https://mayanode.mayachain.info
# Swap me back to 9R as-needed
# VITE_THORCHAIN_NODE_URL=https://thornode.ninerealms.com
VITE_THORCHAIN_NODE_URL=https://dev-api.thorchain.shapeshift.com/lcd
VITE_MAYACHAIN_NODE_URL=https://dev-api.mayachain.shapeshift.com/lcd
VITE_SOLANA_NODE_URL=https://dev-api.solana.shapeshift.com/api/v1/jsonrpc
VITE_STARKNET_NODE_URL=https://rpc.starknet.lava.build
VITE_TRON_NODE_URL=https://api.trongrid.io

# midgard
# VITE_THORCHAIN_MIDGARD_URL=https://dev-api.thorchain.shapeshift.com/midgard/v2
VITE_THORCHAIN_MIDGARD_URL=https://midgard.ninerealms.com/v2
# VITE_MAYACHAIN_MIDGARD_URL=https://dev-api.mayachain.shapeshift.com/midgard/v2
VITE_MAYACHAIN_MIDGARD_URL=https://midgard.mayachain.info/v2
VITE_THORCHAIN_MIDGARD_URL=https://dev-api.thorchain.shapeshift.com/midgard/v2
VITE_MAYACHAIN_MIDGARD_URL=https://dev-api.mayachain.shapeshift.com/midgard/v2

NODE_ENV=development

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { AssetId } from '@shapeshiftoss/caip'
import {
ASSET_REFERENCE,
generateAssetIdFromCosmosSdkDenom,
mayachainAssetId,
} from '@shapeshiftoss/caip'
import { ASSET_REFERENCE, mayachainAssetId } from '@shapeshiftoss/caip'
import type { HDWallet, MayachainSignTx, MayachainWallet } from '@shapeshiftoss/hdwallet-core'
import { supportsMayachain } from '@shapeshiftoss/hdwallet-core'
import type { RootBip44Params } from '@shapeshiftoss/types'
Expand All @@ -12,8 +8,6 @@ import * as unchained from '@shapeshiftoss/unchained-client'

import { ChainAdapterError, ErrorHandler } from '../../error/ErrorHandler'
import type {
Account,
BroadcastTransactionInput,
BuildDepositTxInput,
BuildSendApiTxInput,
BuildSendTxInput,
Expand All @@ -40,7 +34,6 @@ const DEFAULT_CHAIN_ID = KnownChainIds.MayachainMainnet

export interface ChainAdapterArgs extends BaseChainAdapterArgs<unchained.mayachain.V1Api> {
midgardUrl: string
nodeUrl: string
}

export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.MayachainMainnet> {
Expand All @@ -50,8 +43,6 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.MayachainMa
accountNumber: 0,
}

protected readonly nodeUrl: string

constructor(args: ChainAdapterArgs) {
super({
assetId: mayachainAssetId,
Expand All @@ -66,8 +57,6 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.MayachainMa
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
})

this.nodeUrl = args.nodeUrl
}

private assertSupportsChain(wallet: HDWallet): asserts wallet is MayachainWallet {
Expand Down Expand Up @@ -261,101 +250,4 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.MayachainMa
})
}
}

async getAccount(pubkey: string): Promise<Account<KnownChainIds.MayachainMainnet>> {
try {
const [authRes, balanceRes] = await Promise.all([
fetch(`${this.nodeUrl}/cosmos/auth/v1beta1/accounts/${pubkey}`),
fetch(`${this.nodeUrl}/cosmos/bank/v1beta1/balances/${pubkey}`),
])

if (!authRes.ok) {
throw new Error(`Failed to fetch account: ${authRes.status} ${authRes.statusText}`)
}
if (!balanceRes.ok) {
throw new Error(`Failed to fetch balances: ${balanceRes.status} ${balanceRes.statusText}`)
}

const authData = (await authRes.json()) as {
account: { account_number: string; sequence: string; pub_key?: { key: string } }
}
const balanceData = (await balanceRes.json()) as {
balances: { denom: string; amount: string }[]
}

const assets = balanceData.balances.reduce<{ amount: string; assetId: AssetId }[]>(
(acc, b) => {
if (b.denom === this.denom) return acc
try {
acc.push({
amount: b.amount,
assetId: generateAssetIdFromCosmosSdkDenom(b.denom),
})
} catch {}
return acc
},
[],
)

const nativeBalance = balanceData.balances.find(b => b.denom === this.denom)?.amount ?? '0'

return {
balance: nativeBalance,
pubkey,
chainId: this.chainId,
assetId: this.assetId,
chain: this.getType(),
chainSpecific: {
accountNumber: authData.account.account_number,
sequence: authData.account.sequence,
assets,
delegations: [],
redelegations: [],
undelegations: [],
rewards: [],
},
} as Account<KnownChainIds.MayachainMainnet>
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.getAccount',
options: { pubkey },
})
}
}

async broadcastTransaction({
senderAddress,
receiverAddress,
hex,
}: BroadcastTransactionInput): Promise<string> {
try {
await Promise.all([
assertAddressNotSanctioned(senderAddress),
receiverAddress !== CONTRACT_INTERACTION && assertAddressNotSanctioned(receiverAddress),
])

const response = await fetch(`${this.nodeUrl}/cosmos/tx/v1beta1/txs`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tx_bytes: hex,
mode: 'BROADCAST_MODE_SYNC',
}),
})

const data = (await response.json()) as {
tx_response?: { code: number; txhash: string; raw_log?: string }
}

if (data.tx_response?.code !== 0) {
throw new Error(data.tx_response?.raw_log || 'Broadcast failed')
}

return data.tx_response.txhash
} catch (err) {
return ErrorHandler(err, {
translation: 'chainAdapters.errors.broadcastTransaction',
})
}
}
}
Loading