Skip to content

Commit

Permalink
working on using the seaport sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Jun 9, 2024
1 parent b56e647 commit 3ed9b87
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -18,4 +18,4 @@ WALLET_PRIV_KEY=
SIP15_ZONE_SEPOLIA_ADDRESS=
SIP15_ZONE_MAINNET_ADDRESS=
VAULT712_MAINNET_ADAPATER_ADDRESS=
VAULT712_SEPOLIA_ADAPATER_ADDRESS=
VAULT721_SEPOLIA_ADAPATER_ADDRESS=
4 changes: 2 additions & 2 deletions script/DeploySIP15Zone.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
77 changes: 53 additions & 24 deletions script/createListing.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BytesLike[]>{
// import sip15 library
async function getValues(tokenId: string, _traitKeys: BytesLike[]): Promise<BytesLike[]> {
const vault712Adapter = new
// create adaptor contract
//get values from adaptor
//return values array
Expand Down
19 changes: 6 additions & 13 deletions script/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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}`),
);
export const seaport = new Seaport(wallet);

0 comments on commit 3ed9b87

Please sign in to comment.