From 3ed9b878ef104db4ec941cad3165bf5a1d870983 Mon Sep 17 00:00:00 2001 From: MrDeadCe11 Date: Sun, 9 Jun 2024 18:42:48 -0500 Subject: [PATCH] working on using the seaport sdk --- .env.example | 4 +- script/DeploySIP15Zone.s.sol | 4 +- script/createListing.ts | 77 +++++++++++++++++++++++++----------- script/utils/constants.ts | 19 +++------ 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/.env.example b/.env.example index 2a7f770..f9c9710 100644 --- a/.env.example +++ b/.env.example @@ -9,7 +9,7 @@ DEFAULT_KEY_PUBLIC_ADDRESS= ANVIL_ONE=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 ANVIL_RPC=http://127.0.0.1:8545 -VAULT712_SEPOLIA_ADDRESS=0x05AC7e3ac152012B980407dEff2655c209667E4c +VAULT721_SEPOLIA_ADDRESS=0x05AC7e3ac152012B980407dEff2655c209667E4c VAULT712_MAINNET_ADDRESS=0x0005AFE00fF7E7FF83667bFe4F2996720BAf0B36 OPENSEA_API_KEY= @@ -18,4 +18,4 @@ WALLET_PRIV_KEY= SIP15_ZONE_SEPOLIA_ADDRESS= SIP15_ZONE_MAINNET_ADDRESS= VAULT712_MAINNET_ADAPATER_ADDRESS= -VAULT712_SEPOLIA_ADAPATER_ADDRESS= \ No newline at end of file +VAULT721_SEPOLIA_ADAPATER_ADDRESS= \ No newline at end of file diff --git a/script/DeploySIP15Zone.s.sol b/script/DeploySIP15Zone.s.sol index 6650262..424f559 100644 --- a/script/DeploySIP15Zone.s.sol +++ b/script/DeploySIP15Zone.s.sol @@ -42,7 +42,7 @@ contract DeploySIP15ZoneWithENV is Script { if (block.chainid == 421_614) { _privateKey = vm.envUint('ARB_SEPOLIA_PK'); deployer = vm.addr(_privateKey); - vault721 = vm.envAddress('VAULT712_SEPOLIA_ADDRESS'); // SepoliaContracts.Vault721_Address; + vault721 = vm.envAddress('VAULT721_SEPOLIA_ADDRESS'); // SepoliaContracts.Vault721_Address; } else if (block.chainid == 42_161) { _privateKey = vm.envUint('ARB_MAINNET_PK'); deployer = vm.addr(_privateKey); @@ -80,7 +80,7 @@ contract DeploySIP15ZoneWithCastWallet is Script { function _loadAddresseses() internal { if (block.chainid == 421_614) { - vault721 = vm.envAddress('VAULT712_SEPOLIA_ADDRESS'); // SepoliaContracts.Vault721_Address; + vault721 = vm.envAddress('VAULT721_SEPOLIA_ADDRESS'); // SepoliaContracts.Vault721_Address; } else if (block.chainid == 42_161) { vault721 = vm.envAddress('VAULT712_MAINNET_ADDRESS'); // MainnetContracts.Vault721_Address; } else { diff --git a/script/createListing.ts b/script/createListing.ts index b4325ed..ce1f0f3 100644 --- a/script/createListing.ts +++ b/script/createListing.ts @@ -1,21 +1,21 @@ -import { BytesLike, keccak256, ethers } from 'ethers'; -import { WALLET_ADDRESS, VAULT712_ADDRESS, VAULT712_ADAPATER_ADDRESS, sdk } from './utils/constants'; - +import { BytesLike, ethers } from 'ethers'; +import { + WALLET_ADDRESS, + VAULT721_SEPOLIA_ADDRESS, + VAULT721_SEPOLIA_ADAPATER_ADDRESS, + SIP15_ZONE_SEPOLIA_ADDRESS, + seaport, + wallet +} from './utils/constants'; +import { Vault721Adapter } from '../out/Vault721Adapter.sol/Vault721Adapter.json'; +import { ItemType } from "@opensea/seaport-js/src/constants.ts"; const createSIP15ZoneListing = async () => { // TODO: Fill in the token address and token ID of the NFT you want to sell, as well as the price - let tokenAddress: string = ""; - let tokenId: string = ""; + let considerationTokenAddress: string = ""; + let vaultId: string = ""; let listingAmount: string = ""; - const listing = { - accountAddress: WALLET_ADDRESS, - startAmount: listingAmount, - asset: { - tokenAddress: tokenAddress, - tokenId: tokenId, - }, - }; /** * struct Substandard5Comparison { uint8[] comparisonEnums; @@ -26,29 +26,58 @@ const createSIP15ZoneListing = async () => { bytes32[] traitKeys; } */ - const _comparisonEnums: number[] = [4,5]; - const _traitKeys: BytesLike[] = [keccak256('DEBT'), keccak256('COLLATERAL')]; - const _traitValues: BytesLike[] = await getValues(tokenId, _traitKeys); + const substandard5ComparisonTypeString = + 'Substandard5Comparison(uint8[] comparisonEnums,address token,address traits,uint256 identifier,bytes32[] traitValues,bytes32[] traitKeys)' + + const _comparisonEnums: number[] = [4, 5]; + const _traitKeys: BytesLike[] = [ethers.keccak256('DEBT'), ethers.keccak256('COLLATERAL')]; + const _traitValues: BytesLike[] = await getValues(vaultId, _traitKeys); const substandard5data = { - comparisonEnums:_comparisonEnums, - token: VAULT712_ADDRESS, - traits: VAULT712_ADAPATER_ADDRESS, - identifier: tokenId, + comparisonEnums: _comparisonEnums, + token: VAULT721_SEPOLIA_ADDRESS, + traits: VAULT721_SEPOLIA_ADAPATER_ADDRESS, + identifier: vaultId, traitValues: _traitValues, traitKeys: _traitKeys + } + //encode data with struct fragment as type + const encodedStruct = ethers.solidityPacked([substandard5ComparisonTypeString], [substandard5data]); + //encode extraData with substandard + const extraData = ethers.solidityPacked(['uint8', 'bytes'], [ethers.toBeHex('0x05'), encodedStruct]); + // get zone hash by hashing extraData + const zoneHash = ethers.keccak256(extraData); + const listing = { + offer: [ + { + itemType: ItemType.ERC721, + token: VAULT721_SEPOLIA_ADDRESS, + identifier: vaultId + }, + ], + consideration: [ + { + itemType: ItemType.ERC20, + token: considerationTokenAddress, + amount: ethers.parseEther(listingAmount).toString(), + recipient: WALLET_ADDRESS + }, + ], + zoneHash: zoneHash, + extraData: extraData } try { - const response = await sdk.createListing(listing); - console.log("Successfully created a listing with orderHash:", response.orderHash); + const { executeAllActions } = await seaport.createOrder(listing, wallet.address); + const order = await executeAllActions(); + console.log("Successfully created a listing with orderHash:", order.parameters); } catch (error) { console.error("Error in createListing:", error); } } -async function getValues(tokenId: string, _traitKeys: BytesLike[]): Promise{ - // import sip15 library +async function getValues(tokenId: string, _traitKeys: BytesLike[]): Promise { + const vault712Adapter = new // create adaptor contract //get values from adaptor //return values array diff --git a/script/utils/constants.ts b/script/utils/constants.ts index 0d96af0..6a8a4e2 100644 --- a/script/utils/constants.ts +++ b/script/utils/constants.ts @@ -1,12 +1,12 @@ -import { Chain, OpenSeaSDK } from "opensea-js"; +import { ItemType, Seaport } from "@opensea/seaport-js"; import { JsonRpcProvider, ethers } from "ethers"; export const OPENSEA_API_KEY = process.env.OPENSEA_API_KEY; -export const WALLET_PRIV_KEY = process.env.WALLET_PRIV_KEY; +export const WALLET_PRIV_KEY = process.env.ARB_SEPOLIA_PK; export const ARB_SEPOLIA_RPC = process.env.ARB_SEPOLIA_RPC; -export const SIP15_ZONE_ADDRESS = process.env.SIP15_ZONE_ADDRESS; -export const VAULT712_ADAPATER_ADDRESS = process.env.VAULT712_ADAPATER_ADDRESS; -export const VAULT712_ADDRESS = process.env.VAULT712_ADDRESS; +export const SIP15_ZONE_SEPOLIA_ADDRESS = process.env.SIP15_ZONE_SEPOLIA_ADDRESS; +export const VAULT721_SEPOLIA_ADAPATER_ADDRESS = process.env.VAULT721_SEPOLIA_ADAPATER_ADDRESS; +export const VAULT721_SEPOLIA_ADDRESS = process.env.VAULT721_SEPOLIA_ADDRESS; let provider = new JsonRpcProvider(ARB_SEPOLIA_RPC); @@ -17,11 +17,4 @@ export const wallet = new ethers.Wallet( export const WALLET_ADDRESS = wallet.address; -export const sdk = new OpenSeaSDK( - wallet, - { - chain: Chain.ArbitrumSepolia, - apiKey: OPENSEA_API_KEY, - }, - (line) => console.info(`MAINNET: ${line}`), -); \ No newline at end of file +export const seaport = new Seaport(wallet); \ No newline at end of file