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-337): sepolia integration #611

Merged
merged 2 commits into from
Mar 22, 2024
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
31 changes: 7 additions & 24 deletions packages/ethereum/sdk/src/common/check-min-payment-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@ describe("check min payment value fn", function () {
value: toBigNumber("1"),
}

test("checkGreaterThanMinPaymentValue throws error with rari token", async () => {
let err: any
try {
const rariAsset: Asset = {
assetType: {
assetClass: "ERC20",
contract: config.rari as Address,
},
value: toBigNumber("10"),
}
checkGreaterThanMinPaymentValue(rariAsset, config)
} catch (e) {
err = e
}
expect(err?.message.startsWith("Asset value must be greater or equal to")).toBeTruthy()
})

test("checkGreaterThanMinPaymentValue throws error with weth token", async () => {
let err: any
try {
Expand All @@ -58,7 +41,7 @@ describe("check min payment value fn", function () {
},
value: toBigNumber("10"),
}
checkGreaterThanMinPaymentValue(wethAsset, config)
checkGreaterThanMinPaymentValue(wethAsset)
} catch (e) {
err = e
}
Expand All @@ -68,29 +51,29 @@ describe("check min payment value fn", function () {
test("checkGreaterThanMinPaymentValue throws error with ETH", async () => {
let err: any
try {
checkGreaterThanMinPaymentValue(notEnoughEthAsset, config)
checkGreaterThanMinPaymentValue(notEnoughEthAsset)
} catch (e) {
err = e
}
expect(err?.message.startsWith("Asset value must be greater or equal to")).toBeTruthy()
})

test("checkGreaterThanMinPaymentValue returns undefined with 0.0001 ETH", async () => {
checkGreaterThanMinPaymentValue(enoughEthAsset, config)
checkGreaterThanMinPaymentValue(enoughEthAsset)
})

test("checkMinPaymentValue returns undefined if sell order has been passed", async () => {
checkMinPaymentValue({
make: erc721Asset,
take: enoughEthAsset,
} as any, config)
} as any)
})

test("checkMinPaymentValue returns undefined if bid order has been passed", async () => {
checkMinPaymentValue({
make: enoughEthAsset,
take: erc721Asset,
} as any, config)
} as any)
})

test("checkMinPaymentValue throws error if sell order has been passed", async () => {
Expand All @@ -99,7 +82,7 @@ describe("check min payment value fn", function () {
checkMinPaymentValue({
make: erc721Asset,
take: notEnoughEthAsset,
} as any, config)
} as any)
} catch (e) {
err = e
}
Expand All @@ -113,7 +96,7 @@ describe("check min payment value fn", function () {
checkMinPaymentValue({
make: notEnoughEthAsset,
take: erc721Asset,
} as any, config)
} as any)
} catch (e) {
err = e
}
Expand Down
13 changes: 6 additions & 7 deletions packages/ethereum/sdk/src/common/check-min-payment-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import type { Asset } from "@rarible/ethereum-api-client"
import { BigNumber, toBn } from "@rarible/utils"
import type { OrderForm } from "@rarible/ethereum-api-client"
import { Warning } from "@rarible/logger/build"
import { isETH, isRari, isWeth } from "../nft/common"
import type { EthereumConfig } from "../config/type"
import { isErc20, isETH } from "../nft/common"
import { isNft } from "../order/is-nft"
import { ETHER_IN_WEI } from "./index"

export function checkGreaterThanMinPaymentValue({ assetType, value }: Asset, config: EthereumConfig): void {
if ((isETH(assetType) || isWeth(assetType, config) || isRari(assetType, config))
export function checkGreaterThanMinPaymentValue({ assetType, value }: Asset): void {
if ((isETH(assetType) || isErc20(assetType))
&& !toBn(value).gte(MIN_PAYMENT_VALUE)) {
throw new Warning(`Asset value must be greater or equal to ${MIN_PAYMENT_VALUE.div(ETHER_IN_WEI).toFixed()}`)
}
Expand All @@ -18,10 +17,10 @@ export function checkGreaterThanMinPaymentValue({ assetType, value }: Asset, con
export const MIN_PAYMENT_VALUE = new BigNumber(10).pow(14)
export const MIN_PAYMENT_VALUE_DECIMAL = MIN_PAYMENT_VALUE.div(ETHER_IN_WEI)

export function checkMinPaymentValue(checked: OrderForm, config: EthereumConfig): void {
export function checkMinPaymentValue(checked: OrderForm): void {
if (isNft(checked.make.assetType)) {
checkGreaterThanMinPaymentValue(checked.take, config)
checkGreaterThanMinPaymentValue(checked.take)
} else if (isNft(checked.take.assetType)) {
checkGreaterThanMinPaymentValue(checked.make, config)
checkGreaterThanMinPaymentValue(checked.make)
}
}
1 change: 0 additions & 1 deletion packages/ethereum/sdk/src/config/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ export const devEthereumConfig: EthereumConfig = {
pairRouter: toAddress("0x319c4Bd373d3F16697d630153F5a2d526047FD8C"),
},
weth: toAddress("0x3554BA6cb4862C7CB2463f461deF81FA4A8f8E3C"),
rari: ZERO_ADDRESS,
auction: ZERO_ADDRESS,
}
1 change: 0 additions & 1 deletion packages/ethereum/sdk/src/config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const mainnetConfig: EthereumConfig = {
pairRouter: toAddress("0x2b2e8cda09bba9660dca5cb6233787738ad68329"),
},
weth: toAddress("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"),
rari: toAddress("0xfca59cd816ab1ead66534d82bc21e7515ce441cf"),
auction: ZERO_ADDRESS,
looksrareOrderValidatorV2: toAddress("0x2a784a5b5C8AE0bd738FBc67E4C069dB4F4961B7"),
}
31 changes: 15 additions & 16 deletions packages/ethereum/sdk/src/config/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { FEE_CONFIG_URL } from "./common"

export const testnetEthereumConfig: EthereumConfig = {
basePath: "https://testnet-ethereum-api.rarible.org",
chainId: 5,
chainId: 11155111,
environment: "testnet",
exchange: {
v1: ZERO_ADDRESS,
v2: toAddress("0x02afbD43cAD367fcB71305a2dfB9A3928218f0c1"),
v2: toAddress("0x3e52D660b69d1bDacb6C513cE085D924F5Cb9c77"),
openseaV1: ZERO_ADDRESS,
wrapper: toAddress("0x89Ee42D532438BB70a0aF196729aE2B22744c3db"),
looksrare: toAddress("0xD112466471b5438C1ca2D218694200e49d81D047"),
looksrareV2: toAddress("0x35C2215F2FFe8917B06454eEEaba189877F200cf"),
wrapper: toAddress("0x7d47126a2600E22eab9eD6CF0e515678727779A6"),
looksrare: ZERO_ADDRESS,
looksrareV2: toAddress("0x34098cc15a8a48Da9d3f31CC0F63F01f9aa3D9F3"),
x2y2: ZERO_ADDRESS,
},
transferProxies: {
nft: toAddress("0x21B0B84FfAB5A8c48291f5eC9D9FDb9aef574052"),
erc20: toAddress("0x17cEf9a8bf107D58E87c170be1652c06390BD990"),
erc721Lazy: toAddress("0x96102D9472C0338005cbf12Fb7eA829F242C2809"),
erc1155Lazy: toAddress("0x1e1B6E13F0eB4C570628589e3c088BC92aD4dB45"),
nft: toAddress("0xA094E566b61b3c2D88ACf7Cc15e3Dd0FA83F32af"),
erc20: toAddress("0xB8863180CAC2d0Ab665e5968C0De25298A1D8CEe"),
erc721Lazy: toAddress("0xa2eEBb837aEF89369Ad117568d75348e6174520e"),
erc1155Lazy: toAddress("0xC5BBd75789bD007784A0046094d19aCeA1A79eB1"),
openseaV1: ZERO_ADDRESS,
cryptoPunks: ZERO_ADDRESS,
},
Expand All @@ -31,19 +31,18 @@ export const testnetEthereumConfig: EthereumConfig = {
merkleValidator: ZERO_ADDRESS,
},
factories: {
erc721: toAddress("0xf3964B93F0127C9CC2F48752C67dF4b1dB7c9138"),
erc1155: toAddress("0x6E8a327181cE6d83A6cE4A58fe6D07f50B0bc0Af"),
erc721: toAddress("0xB020bA7fcF43DCc59eF0103624BD6FADE66d105E"),
erc1155: toAddress("0x166F6180170f438Ddc38050a2B708d38c0890956"),
},
cryptoPunks: {
marketContract: ZERO_ADDRESS,
wrapperContract: ZERO_ADDRESS,
},
sudoswap: {
pairFactory: toAddress("0xF0202E9267930aE942F0667dC6d805057328F6dC"),
pairRouter: toAddress("0x25b4EfC43c9dCAe134233CD577fFca7CfAd6748F"),
pairFactory: toAddress("0xd96B8cd321176D95C77B2Ba6bfC007659c6CdceB"),
pairRouter: toAddress("0x72d0Ee6B28553b048442a9c8DAD6eA33806e9357"),
},
weth: toAddress("0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"),
rari: toAddress("0xbe6dEA792E5D557d71a4cDEf7d22d6dccA133891"),
weth: toAddress("0x7b79995e5f793a07bc00c21412e50ecae098e7f9"),
auction: ZERO_ADDRESS,
looksrareOrderValidatorV2: toAddress("0x7454Cc9AEB024bcE6A2CDC49ad4733B4D8215fb8"),
looksrareOrderValidatorV2: toAddress("0x0bc129E4c1f8D7b5583eAbAeb1F7468935B6ec0C"),
}
1 change: 0 additions & 1 deletion packages/ethereum/sdk/src/config/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export type EthereumConfig = {
openSea: OpenSeaConfig
factories: FactoriesAddresses
weth: Address
rari?: Address
auction: Address
cryptoPunks: CryptoPunksConfig
sudoswap: SudoswapConfig
Expand Down
4 changes: 0 additions & 4 deletions packages/ethereum/sdk/src/nft/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ export function isErc1155(asset: AssetType): asset is Erc721AssetType {
export function isWeth(asset: AssetType, config: EthereumConfig): boolean {
return isErc20(asset) && asset.contract === config.weth
}

export function isRari(asset: AssetType, config: EthereumConfig): boolean {
return isErc20(asset) && asset.contract === config.rari
}
3 changes: 1 addition & 2 deletions packages/ethereum/sdk/src/order/upsert-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ export class UpsertOrder {

async upsertRequest(checked: OrderForm): Promise<Order> {
const simple = UpsertOrder.orderFormToSimpleOrder(checked)
const config = await this.getConfig()
const apis = await this.getApis()
checkMinPaymentValue(checked, config)
checkMinPaymentValue(checked)
return apis.order.upsertOrder({
orderForm: {
...checked,
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/src/sdk-blockchains/ethereum/cancel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("cancel", () => {
const { itemId } = await suiteDev1.items.mintAndWait(erc721.collectionId)
const orderId = await suiteDev1.orders.sellWithPrepare({
itemId,
price: toBn(1),
price: toBn("2000000000000000000"),
currency: erc20Mintable.assetType,
})

Expand All @@ -39,7 +39,7 @@ describe("cancel", () => {

const orderId = await suiteDev1.orders.sellWithPrepare({
itemId,
price: toBn(1),
price: toBn("2000000000000000000"),
currency: erc20Mintable.assetType,
quantity: 10,
})
Expand All @@ -54,7 +54,7 @@ describe("cancel", () => {

const orderId = await suiteDev2.orders.bid({
itemId,
price: toBn(1),
price: toBn("2000000000000000000"),
currency: erc20Mintable.assetType,
})

Expand All @@ -68,7 +68,7 @@ describe("cancel", () => {

const orderId = await suiteDev2.orders.bid({
itemId,
price: toBn(1),
price: toBn("2000000000000000000"),
quantity: 10,
currency: erc20Mintable.assetType,
})
Expand All @@ -82,7 +82,7 @@ describe("cancel", () => {

const orderId = await suiteDev2.orders.bidByCollection({
collectionId: erc721.collectionId,
price: toBn(1),
price: toBn("2000000000000000000"),
currency: erc20Mintable.assetType,
})

Expand Down
14 changes: 7 additions & 7 deletions packages/sdk/src/sdk-blockchains/ethereum/sale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("sale", () => {
const sellAction = await sdk1.order.sell.prepare({ itemId: result.itemId })
const orderId = await sellAction.submit({
amount: 1,
price: "2",
price: "2000000000000000000",
currency: {
"@type": "ERC20",
contract: erc20ContractAddress,
Expand All @@ -84,7 +84,7 @@ describe("sale", () => {
expect(order.makeStock.toString()).toEqual(nextStock)

const updateAction = await sdk1.order.sellUpdate.prepare({ orderId })
await updateAction.submit({ price: "1" })
await updateAction.submit({ price: "1000000000000000000" })

await sdk1.apis.order.getOrderById({ id: orderId })

Expand Down Expand Up @@ -123,7 +123,7 @@ describe("sale", () => {
const sellAction = await sdk1.order.sell.prepare({ itemId: result.itemId })
const orderId = await sellAction.submit({
amount: 1,
price: "2",
price: "2000000000000000000",
currency: {
"@type": "ERC20",
contract: erc20ContractAddress,
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("sale", () => {
const sellAction = await sdk1.order.sell.prepare({ itemId: result.itemId })
const orderId = await sellAction.submit({
amount: 1,
price: "2",
price: "2000000000000000000",
currency: {
"@type": "ERC20",
contract: erc20ContractAddress,
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("sale", () => {
const sellAction = await sdk1.order.sell.prepare({ itemId: result.itemId })
const orderId = await sellAction.submit({
amount: 1,
price: "2",
price: "2000000000000000000",
currency: {
"@type": "ERC20",
contract: erc20ContractAddress,
Expand Down Expand Up @@ -265,7 +265,7 @@ describe("sale", () => {
const sellAction = await sdk1.order.sell.prepare({ itemId: result.itemId })
const orderId = await sellAction.submit({
amount: 1,
price: "2",
price: "2000000000000000000",
currency: toCurrencyId(erc20ContractAddress),
expirationDate: generateExpirationDate(),
})
Expand Down Expand Up @@ -303,7 +303,7 @@ describe("sale", () => {
const orderId = await sdk1.order.sell({
itemId: result.itemId,
amount: 1,
price: "2",
price: "2000000000000000000",
currency: toCurrencyId(erc20ContractAddress),
expirationDate: generateExpirationDate(),
})
Expand Down