Skip to content

Commit

Permalink
got scripts compiling and running, erroring.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Jun 11, 2024
1 parent 3ed9b87 commit 878f660
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 183 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"scripts": {
"build": "tsc && forge build",
"coverage": "forge coverage",
"createListing": "ts-node script/createListing.ts",
"createListing": "tsx script/createListing.ts",
"lint:check": "yarn lint:sol && forge fmt --check",
"lint:fix": "sort-package-json && forge fmt && yarn lint:sol --fix",
"lint:sol": "cross-env solhint 'src/**/*.sol' 'test/**/*.sol'",
Expand All @@ -33,15 +33,17 @@
"@opendollar/contracts": "^0.0.0-c2beba2",
"@openzeppelin/contracts": "^4.9.6",
"@types/node": "^20.11.5",
"abitype": "^1.0.2",
"dotenv": "^16.4.5",
"ethers": "^6.10.0",
"opensea-js": "^7.0.7",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"devDependencies": {
"cross-env": "^7.0.3",
"solhint": "^4.5.2",
"solhint-plugin-defi-wonderland": "^1.1.3",
"sort-package-json": "^2.8.0"
"sort-package-json": "^2.8.0",
"tsx": "^4.15.2"
}
}
82 changes: 53 additions & 29 deletions script/createListing.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
import { BytesLike, ethers } from 'ethers';
import {
WALLET_ADDRESS,
VAULT721_SEPOLIA_ADDRESS,
VAULT721_SEPOLIA_ADAPATER_ADDRESS,
SIP15_ZONE_SEPOLIA_ADDRESS,
seaport,
wallet
ANVIL_ONE,
ANVIL_RPC,
ARB_SEPOLIA_RPC,
WALLET_PRIV_KEY
} from './utils/constants';
import { Vault721Adapter } from '../out/Vault721Adapter.sol/Vault721Adapter.json';
import { ItemType } from "@opensea/seaport-js/src/constants.ts";
const createSIP15ZoneListing = async () => {
import {Abi, narrow} from 'abitype';
const vault721AdapterABI = require('../out/Vault721Adapter.sol/Vault721Adapter.json');
const sip15ZoneABI = require('../out/SIP15Zone.sol/SIP15Zone.json');
import { ItemType } from "@opensea/seaport-js/src/constants";
import { CreateOrderInput } from '@opensea/seaport-js/lib/types';
import { Seaport } from "@opensea/seaport-js";
import { Wallet, Provider } from 'ethers';

const createSIP15ZoneListing = async (chain: string) => {
let provider: Provider;
let wallet: Wallet;
let seaport: Seaport;
if(chain == 'anvil'){
provider = new ethers.JsonRpcProvider(ANVIL_RPC);
wallet = new ethers.Wallet(
ANVIL_ONE as string,
provider
);
seaport = new Seaport(wallet);
} else if (chain == 'sepolia'){
provider = new ethers.JsonRpcProvider(ARB_SEPOLIA_RPC);
wallet = new ethers.Wallet(
WALLET_PRIV_KEY as string,
provider
);
seaport = new Seaport(wallet);
} else {
throw new Error('unsupported chain');
}

// TODO: Fill in the token address and token ID of the NFT you want to sell, as well as the price
let considerationTokenAddress: string = "";
let vaultId: string = "";
let listingAmount: string = "";
const vault721Adapter = new ethers.Contract(VAULT721_SEPOLIA_ADAPATER_ADDRESS!, vault721AdapterABI.abi);
const sip15Zone = new ethers.Contract(SIP15_ZONE_SEPOLIA_ADDRESS!, sip15ZoneABI.abi);

/**
* struct Substandard5Comparison {
uint8[] comparisonEnums;
address token;
address traits;
uint256 identifier;
bytes32[] traitValues;
bytes32[] traitKeys;
uint8[] comparisonEnums;
address token;
address traits;
uint256 identifier;
bytes32[] traitValues;
bytes32[] 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 _traitValues: BytesLike[] = await vault721Adapter.getTraits(vaultId, _traitKeys);

const substandard5data = {
comparisonEnums: _comparisonEnums,
token: VAULT721_SEPOLIA_ADDRESS,
Expand All @@ -46,48 +76,42 @@ const createSIP15ZoneListing = async () => {
const extraData = ethers.solidityPacked(['uint8', 'bytes'], [ethers.toBeHex('0x05'), encodedStruct]);
// get zone hash by hashing extraData
const zoneHash = ethers.keccak256(extraData);
const timeStamp = (await provider.getBlock('latest'))!.timestamp;

const listing = {
const createOrderInput: CreateOrderInput = {
offer: [
{
itemType: ItemType.ERC721,
token: VAULT721_SEPOLIA_ADDRESS,
token: VAULT721_SEPOLIA_ADDRESS!,
identifier: vaultId
},
],
consideration: [
{
itemType: ItemType.ERC20,
token: considerationTokenAddress,
amount: ethers.parseEther(listingAmount).toString(),
recipient: WALLET_ADDRESS
amount: ethers.parseEther(listingAmount).toString()
},
],
startTime: timeStamp,
endTime: 10,
zoneHash: zoneHash,
extraData: extraData
zone: SIP15_ZONE_SEPOLIA_ADDRESS,
restrictedByZone: true,
}

try {
const { executeAllActions } = await seaport.createOrder(listing, wallet.address);
const { executeAllActions } = await seaport.createOrder(createOrderInput, 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[]> {
const vault712Adapter = new
// create adaptor contract
//get values from adaptor
//return values array
return _traitKeys;
}

// Check if the module is the main entry point
if (require.main === module) {
// If yes, run the createOffer function
createSIP15ZoneListing().catch((error) => {
createSIP15ZoneListing('anvil').catch((error) => {
console.error("Error in createListing:", error);
});
}
Expand Down
13 changes: 7 additions & 6 deletions script/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { ItemType, Seaport } from "@opensea/seaport-js";
import { JsonRpcProvider, ethers } from "ethers";
require('dotenv').config();

export const OPENSEA_API_KEY = process.env.OPENSEA_API_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_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;
export const ANVIL_ONE = process.env.ANVIL_ONE;
export const ANVIL_RPC = process.env.ANVIL_RPC;

let provider = new JsonRpcProvider(ARB_SEPOLIA_RPC);
export const sepoliaProvider = new JsonRpcProvider(ARB_SEPOLIA_RPC);

export const wallet = new ethers.Wallet(
export const sepoliaWallet = new ethers.Wallet(
WALLET_PRIV_KEY as string,
provider
sepoliaProvider
);

export const WALLET_ADDRESS = wallet.address;
export const SEPOLIA_WALLET_ADDRESS = sepoliaWallet.address;

export const seaport = new Seaport(wallet);
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"module": "CommonJS",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
"outDir": "./dist",
"moduleResolution":"Node",
"types": []
},
"include": ["src/**/*.ts"],
"include": ["script/**/*.ts"],
"exclude": ["node_modules"]
}

Loading

0 comments on commit 878f660

Please sign in to comment.