Skip to content

Commit

Permalink
feat: thorchain-1 support (#7510)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight authored Sep 9, 2024
1 parent 8f04183 commit 0e7c273
Show file tree
Hide file tree
Showing 38 changed files with 5,563 additions and 4,446 deletions.
1 change: 1 addition & 0 deletions .env.app
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ REACT_APP_UNCHAINED_COSMOS_HTTP_URL=https://api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_COSMOS_WS_URL=wss://api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_V1_HTTP_URL=https://api.thorchain-v1.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://api.ethereum.shapeshift.com/api/v1/jsonrpc
Expand Down
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ REACT_APP_UNCHAINED_COSMOS_HTTP_URL=https://dev-api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_COSMOS_WS_URL=wss://dev-api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_V1_HTTP_URL=https://dev-api.thorchain-v1.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://dev-api.ethereum.shapeshift.com/api/v1/jsonrpc
Expand Down
1 change: 1 addition & 0 deletions .env.develop
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ REACT_APP_UNCHAINED_COSMOS_HTTP_URL=https://dev-api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_COSMOS_WS_URL=wss://dev-api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_V1_HTTP_URL=https://dev-api.thorchain-v1.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://dev-api.ethereum.shapeshift.com/api/v1/jsonrpc
Expand Down
1 change: 1 addition & 0 deletions .env.private
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ REACT_APP_UNCHAINED_COSMOS_HTTP_URL=https://api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_COSMOS_WS_URL=wss://api.cosmos.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_V1_HTTP_URL=https://api.thorchain-v1.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://api.ethereum.shapeshift.com/api/v1/jsonrpc
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@
"@shapeshiftoss/caip": "workspace:^",
"@shapeshiftoss/chain-adapters": "workspace:^",
"@shapeshiftoss/errors": "workspace:^",
"@shapeshiftoss/hdwallet-coinbase": "1.54.2",
"@shapeshiftoss/hdwallet-core": "1.54.2",
"@shapeshiftoss/hdwallet-keepkey": "1.54.2",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.54.2",
"@shapeshiftoss/hdwallet-keplr": "1.54.2",
"@shapeshiftoss/hdwallet-ledger": "1.54.2",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.54.2",
"@shapeshiftoss/hdwallet-metamask": "1.54.2",
"@shapeshiftoss/hdwallet-native": "1.54.2",
"@shapeshiftoss/hdwallet-native-vault": "1.54.2",
"@shapeshiftoss/hdwallet-shapeshift-multichain": "1.54.2",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.54.2",
"@shapeshiftoss/hdwallet-xdefi": "1.54.2",
"@shapeshiftoss/hdwallet-coinbase": "1.55.0",
"@shapeshiftoss/hdwallet-core": "1.55.0",
"@shapeshiftoss/hdwallet-keepkey": "1.55.0",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.55.0",
"@shapeshiftoss/hdwallet-keplr": "1.55.0",
"@shapeshiftoss/hdwallet-ledger": "1.55.0",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.55.0",
"@shapeshiftoss/hdwallet-metamask": "1.55.0",
"@shapeshiftoss/hdwallet-native": "1.55.0",
"@shapeshiftoss/hdwallet-native-vault": "1.55.0",
"@shapeshiftoss/hdwallet-shapeshift-multichain": "1.55.0",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.55.0",
"@shapeshiftoss/hdwallet-xdefi": "1.55.0",
"@shapeshiftoss/swapper": "workspace:^",
"@shapeshiftoss/types": "workspace:^",
"@shapeshiftoss/unchained-client": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cosmos:thorchain-1/slip44:931":"thorchain"}

This file was deleted.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/caip/src/adapters/coincap/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import dogecoin from './bip122_00000000001a91e3dace36e2be3bf030/adapter.json'
import litecoin from './bip122_12a765e31ffd4059bada1e25190f6e98/adapter.json'
import ethereum from './eip155_1/adapter.json'
import cosmos from './cosmos_cosmoshub-4/adapter.json'
import thorchain from './cosmos_thorchain-mainnet-v1/adapter.json'
import thorchain from './cosmos_thorchain-1/adapter.json'

export { bitcoin, bitcoincash, dogecoin, litecoin, ethereum, cosmos, thorchain }
4 changes: 2 additions & 2 deletions packages/caip/src/adapters/coincap/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ describe('adapters:coincap:utils', () => {
'cosmos:cosmoshub-4': {
'cosmos:cosmoshub-4/slip44:118': 'cosmos',
},
'cosmos:thorchain-mainnet-v1': {
'cosmos:thorchain-mainnet-v1/slip44:931': 'thorchain',
'cosmos:thorchain-1': {
'cosmos:thorchain-1/slip44:931': 'thorchain',
},
'eip155:1': {
'eip155:1/slip44:60': 'ethereum',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cosmos:thorchain-1/slip44:931":"thorchain"}

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/caip/src/adapters/coingecko/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import arbitrum from './eip155_42161/adapter.json'
import arbitrumNova from './eip155_42170/adapter.json'
import base from './eip155_8453/adapter.json'
import cosmos from './cosmos_cosmoshub-4/adapter.json'
import thorchain from './cosmos_thorchain-mainnet-v1/adapter.json'
import thorchain from './cosmos_thorchain-1/adapter.json'

export { bitcoin, bitcoincash, dogecoin, litecoin, ethereum, cosmos, avalanche, thorchain, optimism, bnbsmartchain, polygon, gnosis, arbitrum, arbitrumNova, base }
4 changes: 2 additions & 2 deletions packages/caip/src/adapters/coingecko/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe('adapters:coingecko:utils', () => {
'cosmos:cosmoshub-4': {
'cosmos:cosmoshub-4/slip44:118': 'cosmos',
},
'cosmos:thorchain-mainnet-v1': {
'cosmos:thorchain-mainnet-v1/slip44:931': 'thorchain',
'cosmos:thorchain-1': {
'cosmos:thorchain-1/slip44:931': 'thorchain',
},
'eip155:1': {
'eip155:1/slip44:60': 'ethereum',
Expand Down
6 changes: 3 additions & 3 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const foxyAssetId: AssetId = 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95
export const usdtAssetId: AssetId = 'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7'

export const cosmosAssetId: AssetId = 'cosmos:cosmoshub-4/slip44:118'
export const thorchainAssetId: AssetId = 'cosmos:thorchain-mainnet-v1/slip44:931'
export const thorchainAssetId: AssetId = 'cosmos:thorchain-1/slip44:931'
export const binanceAssetId: AssetId = 'cosmos:binance-chain-tigris/slip44:714'

export const btcChainId: ChainId = 'bip122:000000000019d6689c085ae165831e93'
Expand All @@ -47,7 +47,7 @@ export const arbitrumNovaChainId: ChainId = 'eip155:42170'
export const baseChainId: ChainId = 'eip155:8453'

export const cosmosChainId: ChainId = 'cosmos:cosmoshub-4'
export const thorchainChainId: ChainId = 'cosmos:thorchain-mainnet-v1'
export const thorchainChainId: ChainId = 'cosmos:thorchain-1'
export const binanceChainId: ChainId = 'cosmos:binance-chain-tigris'

export const CHAIN_NAMESPACE = {
Expand All @@ -67,7 +67,7 @@ export const CHAIN_REFERENCE = {
DogecoinMainnet: '00000000001a91e3dace36e2be3bf030',
LitecoinMainnet: '12a765e31ffd4059bada1e25190f6e98',
CosmosHubMainnet: 'cosmoshub-4',
ThorchainMainnet: 'thorchain-mainnet-v1',
ThorchainMainnet: 'thorchain-1',
BinanceMainnet: 'binance-chain-tigris', // https://docs.bnbchain.org/docs/wallet_api/#chain-ids
AvalancheCChain: '43114', // https://docs.avax.network/apis/avalanchego/apis/c-chain
OptimismMainnet: '10', //https://community.optimism.io/docs/useful-tools/networks/#optimism-mainnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export abstract class CosmosSdkBaseAdapter<T extends CosmosSdkChainId> implement
}
}

private async parseTx(tx: unchained.cosmossdk.Tx, pubkey: string): Promise<Transaction> {
protected async parseTx(tx: unchained.cosmossdk.Tx, pubkey: string): Promise<Transaction> {
const { address: _, ...parsedTx } = await this.parser.parse(tx, pubkey)

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { BIP44Params } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import { bech32 } from 'bech32'
import PQueue from 'p-queue'

import { ErrorHandler } from '../../error/ErrorHandler'
import type {
Expand All @@ -17,6 +18,8 @@ import type {
GetFeeDataInput,
SignAndBroadcastTransactionInput,
SignTxInput,
TxHistoryInput,
TxHistoryResponse,
ValidAddressResult,
} from '../../types'
import { ChainAdapterDisplayName, CONTRACT_INTERACTION, ValidAddressResultType } from '../../types'
Expand Down Expand Up @@ -44,6 +47,7 @@ const calculateFee = (fee: string): string => {

export interface ChainAdapterArgs extends BaseChainAdapterArgs<unchained.thorchain.V1Api> {
midgardUrl: string
httpV1: unchained.thorchainV1.V1Api
}

export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.ThorchainMainnet> {
Expand All @@ -53,6 +57,8 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.ThorchainMa
accountNumber: 0,
}

protected readonly httpV1: unchained.thorchainV1.V1Api

constructor(args: ChainAdapterArgs) {
super({
assetId: thorchainAssetId,
Expand All @@ -67,6 +73,8 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.ThorchainMa
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
})

this.httpV1 = args.httpV1
}

getDisplayName() {
Expand Down Expand Up @@ -132,6 +140,31 @@ export class ChainAdapter extends CosmosSdkBaseAdapter<KnownChainIds.ThorchainMa
}
}

async getTxHistoryV1(input: TxHistoryInput): Promise<TxHistoryResponse> {
const requestQueue = input.requestQueue ?? new PQueue()
try {
const data = await requestQueue.add(() =>
this.httpV1.getTxHistory({
pubkey: input.pubkey,
pageSize: input.pageSize,
cursor: input.cursor,
}),
)

const txs = await Promise.all(
data.txs.map(tx => requestQueue.add(() => this.parseTx(tx, input.pubkey))),
)

return {
cursor: data.cursor,
pubkey: input.pubkey,
transactions: txs,
}
} catch (err) {
return ErrorHandler(err)
}
}

async signTransaction(signTxInput: SignTxInput<ThorchainSignTx>): Promise<string> {
try {
const { txToSign, wallet } = signTxInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,6 @@
"eip155:43114/erc20:0x420fca0121dc28039145009570975747295f2329",
"eip155:43114/erc20:0x9c9e5fd8bbc25984b178fdce6117defa39d2db39",
"eip155:43114/erc20:0x19860ccb0a68fd4213ab9d8266f7bbf05a8dde98",
"eip155:4/erc20:0xce347e069b68c53a9ed5e7da5952529caf8accd4",
"eip155:4/erc20:0x9ad6c38be94206ca50bb0d90783181662f0cfa10",
"eip155:4/erc20:0xc778417e063141139fce010982780140aa0cd5ab",
"eip155:4/erc20:0x5b8470fbc6b31038aa07abd3010acffca6e36611",
"eip155:43114/erc20:0x6e84a6216ea6dacc71ee8e6b0a5b7322eebc0fdd",
"eip155:43114/erc20:0x60781c2586d68229fde47564546784ab3faca982",
"eip155:43114/erc20:0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"ETH.YFI-0X0BC529C00C6401AEF6D220BE8C6EA1667F6AD93E": "eip155:1/erc20:0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e",
"GAIA.ATOM": "cosmos:cosmoshub-4/slip44:118",
"LTC.LTC": "bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2",
"THOR.RUNE": "cosmos:thorchain-mainnet-v1/slip44:931"
"THOR.RUNE": "cosmos:thorchain-1/slip44:931"
}
2 changes: 1 addition & 1 deletion packages/types/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export enum KnownChainIds {
DogecoinMainnet = 'bip122:00000000001a91e3dace36e2be3bf030',
LitecoinMainnet = 'bip122:12a765e31ffd4059bada1e25190f6e98',
CosmosMainnet = 'cosmos:cosmoshub-4',
ThorchainMainnet = 'cosmos:thorchain-mainnet-v1',
ThorchainMainnet = 'cosmos:thorchain-1',
}

export type EvmChainId =
Expand Down
13 changes: 13 additions & 0 deletions packages/unchained-client/openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@
"supportsES6": "true",
"useSingleRequestParameter": true
}
},
"thorchainV1": {
"inputSpec": "https://raw.githubusercontent.com/shapeshift/unchained/develop/go/coinstacks/thorchain-v1/api/swagger.json",
"generatorName": "typescript-fetch",
"output": "#{cwd}/src/generated/thorchainV1",
"enablePostProcessFile": true,
"reservedWordsMappings": {
"in": "in"
},
"additionalProperties": {
"supportsES6": "true",
"useSingleRequestParameter": true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../../generated/thorchainV1'
1 change: 1 addition & 0 deletions packages/unchained-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * as dogecoin from './utxo/dogecoin'
export * as litecoin from './utxo/litecoin'
export * as cosmos from './cosmossdk/cosmos'
export * as thorchain from './cosmossdk/thorchain'
export * as thorchainV1 from './cosmossdk/thorchainV1'
1 change: 1 addition & 0 deletions react-app-rewired/headers/csps/chains/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const csp: Csp = {
'connect-src': [
process.env.REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL!,
process.env.REACT_APP_UNCHAINED_THORCHAIN_WS_URL!,
process.env.REACT_APP_UNCHAINED_THORCHAIN_V1_HTTP_URL!,
process.env.REACT_APP_THORCHAIN_NODE_URL!,
],
}
Loading

0 comments on commit 0e7c273

Please sign in to comment.