Skip to content

Commit

Permalink
feat: nft support tx history (shapeshift#4439)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight authored May 11, 2023
1 parent 2287f6e commit 79deaaa
Show file tree
Hide file tree
Showing 57 changed files with 3,042 additions and 1,040 deletions.
1 change: 1 addition & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ REACT_APP_FEATURE_WHEREVER=true
REACT_APP_FEATURE_YAT=true
REACT_APP_FEATURE_YEARN=false
REACT_APP_FEATURE_FOX_BOND_CTA=true
REACT_APP_FEATURE_NFT_METADATA=false

# Fetch UNI-V2 assets from Zapper
REACT_APP_FEATURE_DYNAMIC_LP_ASSETS=true
Expand Down
9 changes: 5 additions & 4 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# feature flags
REACT_APP_FEATURE_NFT_METADATA=true

# logging
REACT_APP_REDUX_WINDOW=false
Expand All @@ -15,8 +16,8 @@ REACT_APP_UNCHAINED_OPTIMISM_HTTP_URL=https://dev-api.optimism.shapeshift.com
REACT_APP_UNCHAINED_OPTIMISM_WS_URL=wss://dev-api.optimism.shapeshift.com
REACT_APP_UNCHAINED_BNBSMARTCHAIN_HTTP_URL=https://dev-api.bnbsmartchain.shapeshift.com
REACT_APP_UNCHAINED_BNBSMARTCHAIN_WS_URL=wss://dev-api.bnbsmartchain.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_HTTP_URL=https://api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_WS_URL=wss://api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_HTTP_URL=https://dev-api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_WS_URL=wss://dev-api.polygon.shapeshift.com
REACT_APP_UNCHAINED_BITCOIN_HTTP_URL=https://dev-api.bitcoin.shapeshift.com
REACT_APP_UNCHAINED_BITCOIN_WS_URL=wss://dev-api.bitcoin.shapeshift.com
REACT_APP_UNCHAINED_DOGECOIN_WS_URL=wss://dev-api.dogecoin.shapeshift.com
Expand All @@ -33,12 +34,12 @@ REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://dev-api.thorchain.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://daemon.ethereum.shapeshift.com
REACT_APP_ETHEREUM_NODE_URL=https://dev-daemon.ethereum.shapeshift.com
REACT_APP_ETHEREUM_INFURA_URL=https://mainnet.infura.io/v3/fb05c87983c4431baafd4600fd33de7e
REACT_APP_AVALANCHE_NODE_URL=https://dev-daemon.avalanche.shapeshift.com/ext/bc/C/rpc
REACT_APP_OPTIMISM_NODE_URL=https://dev-daemon.optimism.shapeshift.com
REACT_APP_BNBSMARTCHAIN_NODE_URL=https://dev-daemon.bnbsmartchain.shapeshift.com
REACT_APP_POLYGON_NODE_URL=https://daemon.polygon.shapeshift.com
REACT_APP_POLYGON_NODE_URL=https://dev-daemon.polygon.shapeshift.com
REACT_APP_COSMOS_NODE_URL=https://dev-daemon.cosmos.shapeshift.com
REACT_APP_OSMOSIS_NODE_URL=https://dev-daemon.osmosis.shapeshift.com
REACT_APP_THORCHAIN_NODE_URL=https://dev-daemon.thorchain.shapeshift.com
Expand Down
9 changes: 5 additions & 4 deletions .env.develop
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# feature flags
REACT_APP_FEATURE_NFT_METADATA=true

# mixpanel
REACT_APP_MIXPANEL_TOKEN=1c1369f6ea23a6404bac41b42817cc4b
Expand All @@ -12,8 +13,8 @@ REACT_APP_UNCHAINED_OPTIMISM_HTTP_URL=https://dev-api.optimism.shapeshift.com
REACT_APP_UNCHAINED_OPTIMISM_WS_URL=wss://dev-api.optimism.shapeshift.com
REACT_APP_UNCHAINED_BNBSMARTCHAIN_HTTP_URL=https://dev-api.bnbsmartchain.shapeshift.com
REACT_APP_UNCHAINED_BNBSMARTCHAIN_WS_URL=wss://dev-api.bnbsmartchain.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_HTTP_URL=https://api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_WS_URL=wss://api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_HTTP_URL=https://dev-api.polygon.shapeshift.com
REACT_APP_UNCHAINED_POLYGON_WS_URL=wss://dev-api.polygon.shapeshift.com
REACT_APP_UNCHAINED_BITCOIN_HTTP_URL=https://dev-api.bitcoin.shapeshift.com
REACT_APP_UNCHAINED_BITCOIN_WS_URL=wss://dev-api.bitcoin.shapeshift.com
REACT_APP_UNCHAINED_DOGECOIN_WS_URL=wss://dev-api.dogecoin.shapeshift.com
Expand All @@ -30,12 +31,12 @@ REACT_APP_UNCHAINED_THORCHAIN_HTTP_URL=https://dev-api.thorchain.shapeshift.com
REACT_APP_UNCHAINED_THORCHAIN_WS_URL=wss://dev-api.thorchain.shapeshift.com

# nodes
REACT_APP_ETHEREUM_NODE_URL=https://daemon.ethereum.shapeshift.com
REACT_APP_ETHEREUM_NODE_URL=https://dev-daemon.ethereum.shapeshift.com
REACT_APP_ETHEREUM_INFURA_URL=https://mainnet.infura.io/v3/d28923bef53e4b26b21a094ae38d32b3
REACT_APP_AVALANCHE_NODE_URL=https://dev-daemon.avalanche.shapeshift.com/ext/bc/C/rpc
REACT_APP_OPTIMISM_NODE_URL=https://dev-daemon.optimism.shapeshift.com
REACT_APP_BNBSMARTCHAIN_NODE_URL=https://dev-daemon.bnbsmartchain.shapeshift.com
REACT_APP_POLYGON_NODE_URL=https://daemon.polygon.shapeshift.com
REACT_APP_POLYGON_NODE_URL=https://dev-daemon.polygon.shapeshift.com
REACT_APP_COSMOS_NODE_URL=https://dev-daemon.cosmos.shapeshift.com
REACT_APP_OSMOSIS_NODE_URL=https://dev-daemon.osmosis.shapeshift.com
REACT_APP_THORCHAIN_NODE_URL=https://dev-daemon.thorchain.shapeshift.com
Expand Down
11 changes: 8 additions & 3 deletions packages/caip/src/assetId/assetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ export const toAssetId: ToAssetId = (args: ToAssetIdArgs): AssetId => {
}
})()

const isContractAddress = Array<AssetNamespace>('erc20', 'erc721', 'bep20', 'bep721').includes(
assetNamespace,
)
const isContractAddress = Array<AssetNamespace>(
'erc20',
'erc721',
'erc1155',
'bep20',
'bep721',
'bep1155',
).includes(assetNamespace)

assertIsChainNamespace(chainNamespace)
assertIsChainReference(chainReference)
Expand Down
4 changes: 4 additions & 0 deletions packages/caip/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export const ASSET_NAMESPACE = {
cw721: 'cw721',
erc20: 'erc20',
erc721: 'erc721',
erc1155: 'erc1155',
bep20: 'bep20',
bep721: 'bep721',
bep1155: 'bep1155',
slip44: 'slip44',
native: 'native',
ibc: 'ibc',
Expand Down Expand Up @@ -153,8 +155,10 @@ export const VALID_ASSET_NAMESPACE: ValidAssetNamespace = Object.freeze({
ASSET_NAMESPACE.slip44,
ASSET_NAMESPACE.erc20,
ASSET_NAMESPACE.erc721,
ASSET_NAMESPACE.erc1155,
ASSET_NAMESPACE.bep20,
ASSET_NAMESPACE.bep721,
ASSET_NAMESPACE.bep1155,
],
[CHAIN_NAMESPACE.CosmosSdk]: [
ASSET_NAMESPACE.cw20,
Expand Down
15 changes: 6 additions & 9 deletions packages/chain-adapters/src/evm/EvmBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ export const isEvmChainId = (
return evmChainIds.includes(maybeEvmChainId as EvmChainId)
}

type EvmApi =
| unchained.ethereum.V1Api
| unchained.avalanche.V1Api
| unchained.optimism.V1Api
| unchained.bnbsmartchain.V1Api
| unchained.polygon.V1Api

export interface ChainAdapterArgs<T = EvmApi> {
export interface ChainAdapterArgs<T = unchained.evm.Api> {
chainId?: EvmChainId
providers: {
http: T
Expand All @@ -92,7 +85,7 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap
protected readonly defaultBIP44Params: BIP44Params
protected readonly supportedChainIds: ChainId[]
protected readonly providers: {
http: EvmApi
http: unchained.evm.Api
ws: unchained.ws.Client<unchained.evm.types.Tx>
}

Expand Down Expand Up @@ -370,6 +363,8 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap
to: transfer.to,
type: transfer.type,
value: transfer.totalValue,
id: transfer.id,
token: transfer.token,
})),
data: parsedTx.data,
}
Expand Down Expand Up @@ -493,6 +488,8 @@ export abstract class EvmBaseAdapter<T extends EvmChainId> implements IChainAdap
to: transfer.to,
type: transfer.type,
value: transfer.totalValue,
id: transfer.id,
token: transfer.token,
})),
txid: tx.txid,
data: tx.data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.AvalancheMainnet>
assetId: avalancheAssetId,
chainId: args.chainId ?? DEFAULT_CHAIN_ID,
rpcUrl: args.rpcUrl,
api: args.providers.http,
}),
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.BnbSmartChainMain
assetId: bscAssetId,
chainId: args.chainId ?? DEFAULT_CHAIN_ID,
rpcUrl: args.rpcUrl,
api: args.providers.http,
}),
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.EthereumMainnet>
assetId: ethAssetId,
chainId: args.chainId ?? DEFAULT_CHAIN_ID,
rpcUrl: args.rpcUrl,
api: args.providers.http,
}),
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.OptimismMainnet>
assetId: optimismAssetId,
chainId: args.chainId ?? DEFAULT_CHAIN_ID,
rpcUrl: args.rpcUrl,
api: args.providers.http,
}),
supportedChainIds: SUPPORTED_CHAIN_IDS,
...args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ChainAdapter extends EvmBaseAdapter<KnownChainIds.PolygonMainnet> {
assetId: polygonAssetId,
chainId: args.chainId ?? DEFAULT_CHAIN_ID,
rpcUrl: args.rpcUrl,
api: args.providers.http,
}),
...args,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-adapters/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export type Transaction = Omit<unchained.StandardTx, 'transfers'> & {
data?: TxMetadata
}

export type TxTransfer = Omit<unchained.Transfer, 'components' | 'totalValue' | 'token'> & {
export type TxTransfer = Omit<unchained.Transfer, 'components' | 'totalValue'> & {
value: string
}

Expand Down
2 changes: 1 addition & 1 deletion packages/unchained-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@shapeshiftoss/caip": "workspace:^",
"@shapeshiftoss/common-api": "^8.3.0",
"@shapeshiftoss/common-api": "^9.2.0",
"@shapeshiftoss/logger": "workspace:^",
"@shapeshiftoss/types": "workspace:^",
"@yfi/sdk": "^1.2.0",
Expand Down
20 changes: 10 additions & 10 deletions packages/unchained-client/src/cosmossdk/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ export class BaseTransactionParser<T extends Tx> {
const amount = new BigNumber(value?.amount ?? 0)

if (from === address && amount.gt(0)) {
parsedTx.transfers = aggregateTransfer(
parsedTx.transfers,
TransferType.Send,
parsedTx.transfers = aggregateTransfer({
assetId,
from,
to,
amount.toString(10),
)
transfers: parsedTx.transfers,
type: TransferType.Send,
value: amount.toString(10),
})
}

if (to === address && amount.gt(0)) {
parsedTx.transfers = aggregateTransfer(
parsedTx.transfers,
TransferType.Receive,
parsedTx.transfers = aggregateTransfer({
assetId,
from,
to,
amount.toString(10),
)
transfers: parsedTx.transfers,
type: TransferType.Receive,
value: amount.toString(10),
})
}
})

Expand Down
Loading

0 comments on commit 79deaaa

Please sign in to comment.