Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PLTF-196): support lightlink #584

Merged
merged 20 commits into from
Dec 20, 2023
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
18 changes: 2 additions & 16 deletions packages/connectors/connector-helper/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
import { EthereumWallet } from "@rarible/sdk-wallet"
import { Web3Ethereum } from "@rarible/web3-ethereum"
import Web3 from "web3"
import { Blockchain } from "@rarible/api-client"
import type { EVMBlockchain } from "@rarible/sdk-common"
import { getBlockchainFromChainId } from "@rarible/protocol-ethereum-sdk/src/common"
import type { IWalletAndAddress } from "./wallet-connection"

export function mapEthereumWallet<O>(
Expand All @@ -31,19 +31,5 @@ export function mapEthereumWallet<O>(
}

function getEvmBlockchain(chainId: number): EVMBlockchain {
switch (chainId) {
case 137:
case 80001:
case 300501:
case 200501: return Blockchain.POLYGON
case 5000:
case 5001: return Blockchain.MANTLE
case 42161:
case 421614: return Blockchain.ARBITRUM
case 300:
case 324: return Blockchain.ZKSYNC
case 88882:
case 88888: return Blockchain.CHILIZ
default: return Blockchain.ETHEREUM
}
return getBlockchainFromChainId(chainId)
}
5 changes: 4 additions & 1 deletion packages/ethereum/sdk/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function getBlockchainBySDKNetwork(network: EthereumNetwork): EVMBlockcha
case "chiliz":
case "testnet-chiliz":
return Blockchain.CHILIZ
default: throw new Error("Unrecognized ethereum network")
case "lightlink":
case "testnet-lightlink":
return Blockchain.LIGHTLINK
default: throw new Error(`Unrecognized ethereum network ${network}`)
}
}
1 change: 1 addition & 0 deletions packages/ethereum/sdk/src/common/test/test-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function getAPIKey(env: EthereumNetwork) {
case "arbitrum":
case "zksync":
case "chiliz":
case "lightlink":
return process.env.SDK_API_KEY_PROD
default:
return process.env.SDK_API_KEY_TESTNET
Expand Down
4 changes: 4 additions & 0 deletions packages/ethereum/sdk/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { zkSyncTestnetConfig } from "./testnet-zksync"
import { zkSyncConfig } from "./zksync"
import { chilizConfig } from "./chilliz"
import { chilizTestnetConfig } from "./testnet-chiliz"
import { lightlinkConfig } from "./lightlink"
import { testnetLightlinkConfig } from "./testnet-lightlink"

export const configDictionary: Record<EthereumNetwork, EthereumConfig> = {
mainnet: mainnetConfig,
Expand All @@ -30,6 +32,8 @@ export const configDictionary: Record<EthereumNetwork, EthereumConfig> = {
zksync: zkSyncConfig,
chiliz: chilizConfig,
"testnet-chiliz": chilizTestnetConfig,
lightlink: lightlinkConfig,
"testnet-lightlink": testnetLightlinkConfig,
}

export function getEthereumConfig(env: EthereumNetwork): EthereumConfig {
Expand Down
47 changes: 47 additions & 0 deletions packages/ethereum/sdk/src/config/lightlink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { toAddress, ZERO_ADDRESS } from "@rarible/types"
import { id32 } from "../common/id"
import type { EthereumConfig } from "./type"
import { FEE_CONFIG_URL } from "./common"

export const lightlinkConfig: EthereumConfig = {
basePath: "https://lightlink-api.rarible.org",
chainId: 1890,
exchange: {
v1: ZERO_ADDRESS,
v2: toAddress("0x5faf16A85028BE138A7178B222DeC98092FEEF97"),
openseaV1: ZERO_ADDRESS,
wrapper: toAddress("0x0B7Acd053BC236fc95537e2aDD37C22968b48C1b"),
looksrare: ZERO_ADDRESS,
looksrareV2: ZERO_ADDRESS,
x2y2: ZERO_ADDRESS,
},
transferProxies: {
nft: toAddress("0xF65eF65a95821A16E02973b1C2200FA58898e3c0"),
erc20: toAddress("0x248B46BEB66b3078D771a9E7E5a0a0216d0d07ba"),
erc721Lazy: toAddress("0xce4bf732f53A76C463aE8822be858017b02779c8"),
erc1155Lazy: toAddress("0x1CC22424f2B84791cb99c141A68CD2a44Cf35398"),
openseaV1: ZERO_ADDRESS,
cryptoPunks: ZERO_ADDRESS,
},
feeConfigUrl: FEE_CONFIG_URL,
openSea: {
metadata: id32("RARIBLE"),
proxyRegistry: ZERO_ADDRESS,
merkleValidator: ZERO_ADDRESS,
},
factories: {
erc721: ZERO_ADDRESS,
erc1155: ZERO_ADDRESS,
},
cryptoPunks: {
marketContract: ZERO_ADDRESS,
wrapperContract: ZERO_ADDRESS,
},
sudoswap: {
pairFactory: ZERO_ADDRESS,
pairRouter: ZERO_ADDRESS,
},
weth: toAddress("0x7EbeF2A4b1B09381Ec5B9dF8C5c6f2dBECA59c73"),
auction: ZERO_ADDRESS,
looksrareOrderValidatorV2: ZERO_ADDRESS,
}
47 changes: 47 additions & 0 deletions packages/ethereum/sdk/src/config/testnet-lightlink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { toAddress, ZERO_ADDRESS } from "@rarible/types"
import { id32 } from "../common/id"
import type { EthereumConfig } from "./type"
import { FEE_CONFIG_URL } from "./common"

export const testnetLightlinkConfig: EthereumConfig = {
basePath: "https://testnet-lightlink-api.rarible.org",
chainId: 1891,
exchange: {
v1: ZERO_ADDRESS,
v2: toAddress("0x2E015B0474364757d2cc8e28897DCBCdEE07e340"),
openseaV1: ZERO_ADDRESS,
wrapper: ZERO_ADDRESS,
looksrare: ZERO_ADDRESS,
looksrareV2: ZERO_ADDRESS,
x2y2: ZERO_ADDRESS,
},
transferProxies: {
nft: toAddress("0x166F6180170f438Ddc38050a2B708d38c0890956"),
erc20: toAddress("0x7d47126a2600E22eab9eD6CF0e515678727779A6"),
erc721Lazy: toAddress("0x98C2d878064dCD20489214cf0866f972f91784D0"),
erc1155Lazy: toAddress("0x12B372153249F006F756d0668fCDBD8fbD8b0a15"),
openseaV1: ZERO_ADDRESS,
cryptoPunks: ZERO_ADDRESS,
},
feeConfigUrl: FEE_CONFIG_URL,
openSea: {
metadata: id32("RARIBLE"),
proxyRegistry: ZERO_ADDRESS,
merkleValidator: ZERO_ADDRESS,
},
factories: {
erc721: toAddress("0xfeC0F8d936B9cBa92a332bCB06dC7DF4DdE0c253"),
erc1155: toAddress("0x63e3297a90B4101d0a4Bb8EbEFDF3D47C8d4D4Ac"),
},
cryptoPunks: {
marketContract: ZERO_ADDRESS,
wrapperContract: ZERO_ADDRESS,
},
sudoswap: {
pairFactory: ZERO_ADDRESS,
pairRouter: ZERO_ADDRESS,
},
weth: toAddress("0xF42991f02C07AB66cFEa282E7E482382aEB85461"),
auction: ZERO_ADDRESS,
looksrareOrderValidatorV2: ZERO_ADDRESS,
}
2 changes: 2 additions & 0 deletions packages/ethereum/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type EthereumNetwork =
| "testnet-zksync"
| "chiliz"
| "testnet-chiliz"
| "lightlink"
| "testnet-lightlink"

export enum LogsLevel {
DISABLED = 0,
Expand Down
3 changes: 1 addition & 2 deletions packages/example/src/pages/deploy/deploy-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export function DeployPage() {
label="Blockchain"
>
<MenuItem value={WalletType.ETHEREUM}>
{Blockchain.ETHEREUM} / {Blockchain.POLYGON} / {Blockchain.MANTLE}
/ {Blockchain.ARBITRUM} / {Blockchain.ZKSYNC}
EVM Blockchain
</MenuItem>
<MenuItem value={WalletType.TEZOS}>{WalletType.TEZOS}</MenuItem>
<MenuItem value={Blockchain.SOLANA}>{Blockchain.SOLANA}</MenuItem>
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-common/src/utils/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Blockchain } from "@rarible/api-client/build/models/Blockchain"

export type EVMBlockchain = Blockchain.ETHEREUM | Blockchain.POLYGON | Blockchain.MANTLE
| Blockchain.ARBITRUM | Blockchain.ZKSYNC | Blockchain.CHILIZ
| Blockchain.ARBITRUM | Blockchain.ZKSYNC | Blockchain.CHILIZ | Blockchain.LIGHTLINK
export const EVMBlockchains: EVMBlockchain[] = [
Blockchain.ETHEREUM,
Blockchain.POLYGON,
Blockchain.MANTLE,
Blockchain.ARBITRUM,
Blockchain.ZKSYNC,
Blockchain.CHILIZ,
Blockchain.LIGHTLINK,
]

/**
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/config/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const developmentConfig: RaribleSdkConfig = {
arbitrumNetwork: "testnet-arbitrum",
zksync: "testnet-zksync",
chiliz: "testnet-chiliz",
lightlink: "testnet-lightlink",
}
1 change: 1 addition & 0 deletions packages/sdk/src/config/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type RaribleSdkConfig = {
arbitrumNetwork: EthereumNetwork
zksync: EthereumNetwork
chiliz: EthereumNetwork
lightlink: EthereumNetwork
}
1 change: 1 addition & 0 deletions packages/sdk/src/config/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const prodConfig: RaribleSdkConfig = {
arbitrumNetwork: "arbitrum",
zksync: "zksync",
chiliz: "chiliz",
lightlink: "lightlink",
}
1 change: 1 addition & 0 deletions packages/sdk/src/config/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const testnetConfig: RaribleSdkConfig = {
arbitrumNetwork: "testnet-arbitrum",
zksync: "testnet-zksync",
chiliz: "testnet-chiliz",
lightlink: "testnet-lightlink",
}
7 changes: 7 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export function createRaribleSdk(
blockchainConfig.chiliz,
ethConfig
),
createEthereumSdk(
filterWallet(wallet, WalletType.ETHEREUM),
apis,
Blockchain.LIGHTLINK,
blockchainConfig.lightlink,
ethConfig
),
)

const sdkContext: ISdkContext = {
Expand Down
28 changes: 5 additions & 23 deletions packages/sdk/src/sdk-blockchains/ethereum/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { NftAssetType } from "@rarible/protocol-ethereum-sdk/build/order/ch
import type { EthereumWallet } from "@rarible/sdk-wallet/build"
import type { EVMBlockchain } from "@rarible/sdk-common/build"
import { WalletIsUndefinedError, EVMBlockchains, isEVMBlockchain } from "@rarible/sdk-common/build"
import { getBlockchainBySDKNetwork } from "@rarible/protocol-ethereum-sdk/build/common"
import type { OrderRequest, UnionPart } from "../../../types/order/common"
import type { FillRequest, PrepareFillRequest } from "../../../types/order/fill/domain"
import { OriginFeeSupport, PayoutsSupport } from "../../../types/order/fill/domain"
Expand Down Expand Up @@ -170,30 +171,11 @@ export function getPayoutsSupport(type: "RARIBLE_V1" | "RARIBLE_V2"): PayoutsSup
}

export function getEVMBlockchain(network: EthereumNetwork): EVMBlockchain {
switch (network) {
case "testnet":
case "dev-ethereum":
case "mainnet":
return Blockchain.ETHEREUM
case "dev-polygon":
case "mumbai":
case "polygon":
return Blockchain.POLYGON
case "mantle":
case "testnet-mantle":
return Blockchain.MANTLE
case "arbitrum":
case "testnet-arbitrum":
return Blockchain.ARBITRUM
case "zksync":
case "testnet-zksync":
return Blockchain.ZKSYNC
case "chiliz":
case "testnet-chiliz":
return Blockchain.CHILIZ
default:
throw new Error(`Unsupported network: ${network}`)
const blockchain = getBlockchainBySDKNetwork(network)
if (!isEVMBlockchain(blockchain)) {
throw new Error(`Network ${network} is not EVM compatible`)
}
return blockchain
}

export function getSupportedCurrencies(
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/sdk-blockchains/union/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function createUnionSdk(
mantle: IRaribleInternalSdk,
zksync: IRaribleInternalSdk,
chiliz: IRaribleInternalSdk,
lightlink: IRaribleInternalSdk,
): IRaribleInternalSdk {
return {
balances: new UnionBalanceSdk({
Expand All @@ -78,6 +79,7 @@ export function createUnionSdk(
ARBITRUM: arbitrum.balances,
ZKSYNC: zksync.balances,
CHILIZ: chiliz.balances,
LIGHTLINK: lightlink.balances,
}),
nft: new UnionNftSdk({
ETHEREUM: ethereum.nft,
Expand All @@ -90,6 +92,7 @@ export function createUnionSdk(
ARBITRUM: arbitrum.nft,
ZKSYNC: zksync.nft,
CHILIZ: chiliz.nft,
LIGHTLINK: lightlink.nft,
}),
order: new UnionOrderSdk({
ETHEREUM: ethereum.order,
Expand All @@ -102,6 +105,7 @@ export function createUnionSdk(
ARBITRUM: arbitrum.order,
ZKSYNC: zksync.order,
CHILIZ: chiliz.order,
LIGHTLINK: lightlink.order,
}),
restriction: new UnionRestrictionSdk({
ETHEREUM: ethereum.restriction,
Expand All @@ -114,6 +118,7 @@ export function createUnionSdk(
ARBITRUM: arbitrum.restriction,
ZKSYNC: zksync.restriction,
CHILIZ: chiliz.restriction,
LIGHTLINK: lightlink.restriction,
}),
ethereum: new UnionEthereumSpecificSdk(ethereum.ethereum!),
flow: new UnionFlowSpecificSdk(flow.flow!),
Expand Down
4 changes: 4 additions & 0 deletions packages/transaction/src/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ IBlockchainTransaction<Blockchain, TransactionResult> {
return `https://scan.chiliz.com/tx/${this.hash()}`
case "testnet-chiliz":
return `https://spicy-explorer.chiliz.com/tx/${this.hash()}`
case "lightlink":
return `https://phoenix.lightlink.io/tx/${this.hash()}`
case "testnet-lightlink":
return `https://pegasus.lightlink.io/tx/${this.hash()}`
default:
throw new Error("Unsupported transaction network")
}
Expand Down