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(core): build constant file for contract addresses #235

Closed
wants to merge 13 commits into from
11 changes: 5 additions & 6 deletions contracts.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"goerli": {},
"sepolia": {},
"testnet": {},
"mainnet": {},
"local": {
"messaging": "0x385ac975687520f0b47f16aa619efb454d16c02388fd01b2fc36c7cb9235dc0",
"executor": "0x72edc1c4893cf4288b1f424b677e7f7c791def1c9826b615864821951875186",
"nftContract": "0x7a0d668105724f2db5197b353538af0454dd059cd0282444c22978493cf2acb",
"dev": {
"nftContract": "0x8305f69a64d04e908b957087411f26658a05ec35acf11afa9f9748b0783825",
"eth": "0x172ca09df59789985a1dfb68e0f3f554121eb313c68cf391bd78f9bf69abcf",
"messaging": "0x7504defaee0ff49d1ac5afa45167da77cce68c4a62295aa9cfa35c83fc11e63",
"executor": "0x7fd31172080d3546c055c490c4b795589104aee02656bc4349573f2ac8cc21f",
"orderbook": "0x3b08fc57e1fc53c8545fa799c7af60bf18b9f43dce739c24bf95f2f118da97"
}
}
2 changes: 1 addition & 1 deletion crates/solis/messaging.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chain": "starknet",
"rpc_url": "http://127.0.0.1:5050",
"contract_address": "0x385ac975687520f0b47f16aa619efb454d16c02388fd01b2fc36c7cb9235dc0",
"contract_address": "0x7504defaee0ff49d1ac5afa45167da77cce68c4a62295aa9cfa35c83fc11e63",
"sender_address": "0x765149d6bc63271df7b0316537888b81aa021523f9516a05306f10fd36914da",
"private_key": "0x1c9053c053edf324aec366a34c6901b1095b07af69495bffec7d7fe21effb1b",
"interval": 2,
Expand Down
5 changes: 1 addition & 4 deletions packages/core/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ STARKNET_ACCOUNT2_ADDRESS=0x5686a647a9cdd63ade617e0baf3b364856b813b508f03903eb58
STARKNET_ACCOUNT2_PRIVATE_KEY=0x33003003001800009900180300d206308b0070db00121318d17b5e6262150b
STARKNET_ACCOUNT2_PUBLIC_KEY=0x4c0f884b8e5b4f00d97a3aad26b2e5de0c0c76a555060c837da2e287403c01d

# Starknet network
STARKNET_NETWORK_ID=local
# Solis network
SOLIS_NETWORK_ID=local
NETWORK=dev
22 changes: 17 additions & 5 deletions packages/core/examples/cancelListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
} from "../src/actions/account/account";
import { cancelOrder, createListing } from "../src/actions/order";
import { getOrderHash, getOrderStatus } from "../src/actions/read";
import { STARKNET_NFT_ADDRESS } from "../src/constants";
import { Network } from "../src/constants";
import { ListingV1 } from "../src/types";
import { getExampleNFTAddress } from "./constants";

// Initialize the RPC provider with the ArkChain node URL
const starknetProvider = new RpcProvider({
Expand All @@ -25,12 +26,18 @@ const arkProvider = new RpcProvider({
nodeUrl: process.env.ARKCHAIN_RPC_URL ?? "http://0.0.0.0:7777"
});

const network = (process.env.NETWORK ?? "dev") as Network;

/**
* Creates a listing on the blockchain using provided order details.
*
* @param {RpcProvider} provider - The RPC provider instance.
*/
(async (arkProvider: RpcProvider, starknetProvider: RpcProvider) => {
(async (
network: Network,
arkProvider: RpcProvider,
starknetProvider: RpcProvider
) => {
// Create a new account using the provider
const { account: arkAccount } = await createAccount(arkProvider);
const starknetAccount = await fetchOrCreateAccount(
Expand All @@ -39,6 +46,8 @@ const arkProvider = new RpcProvider({
process.env.ACCOUNT1_PRIVATE_KEY
);

const STARKNET_NFT_ADDRESS = getExampleNFTAddress(network);

// Define the order details
let order: ListingV1 = {
brokerId: 123, // The broker ID
Expand All @@ -49,7 +58,7 @@ const arkProvider = new RpcProvider({

console.log("Creating listing order...");
// Create the listing on the arkchain using the order details
await createListing(arkProvider, starknetAccount, arkAccount, order);
await createListing(network, arkProvider, starknetAccount, arkAccount, order);

// wait 5 seconds for the transaction to be processed
await new Promise((resolve) => setTimeout(resolve, 5000));
Expand All @@ -58,11 +67,13 @@ const arkProvider = new RpcProvider({
const { orderHash } = await getOrderHash(
order.tokenId,
order.tokenAddress,
network,
arkProvider
);

let { orderStatus: orderStatusBefore } = await getOrderStatus(
orderHash,
network,
arkProvider
);
console.log("orderStatus", shortString.decodeShortString(orderStatusBefore));
Expand All @@ -75,13 +86,14 @@ const arkProvider = new RpcProvider({
};

// Cancel the order
cancelOrder(arkProvider, starknetAccount, arkAccount, cancelInfo);
cancelOrder(network, arkProvider, starknetAccount, arkAccount, cancelInfo);

await new Promise((resolve) => setTimeout(resolve, 2000));

let { orderStatus: orderStatusAfter } = await getOrderStatus(
orderHash,
network,
arkProvider
);
console.log("orderStatus", shortString.decodeShortString(orderStatusAfter));
})(arkProvider, starknetProvider);
})(network, arkProvider, starknetProvider);
5 changes: 5 additions & 0 deletions packages/core/examples/constants/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export const STARKNET_NFT_ADDRESS_MAINNET = "";
export const STARKNET_NFT_ADDRESS_TESTNET = "";
export const STARKNET_NFT_ADDRESS_DEV = "0x8305f69a64d04e908b957087411f26658a05ec35acf11afa9f9748b0783825";

16 changes: 16 additions & 0 deletions packages/core/examples/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Network } from "../../src";
import {
STARKNET_NFT_ADDRESS_DEV,
STARKNET_NFT_ADDRESS_MAINNET,
STARKNET_NFT_ADDRESS_TESTNET
} from "./contracts";

const NETWORK_TO_ADDRESS_MAP = {
mainnet: STARKNET_NFT_ADDRESS_MAINNET,
testnet: STARKNET_NFT_ADDRESS_TESTNET,
dev: STARKNET_NFT_ADDRESS_DEV
};

export function getExampleNFTAddress(network: Network) {
return NETWORK_TO_ADDRESS_MAP[network];
}
34 changes: 14 additions & 20 deletions packages/core/examples/createListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
} from "../src/actions/account/account";
import { createListing } from "../src/actions/order";
import { getOrderHash, getOrderStatus } from "../src/actions/read";
import { STARKNET_NFT_ADDRESS } from "../src/constants";
import { getContractAddresses, Network } from "../src/constants";
import { ListingV1 } from "../src/types";
import { getExampleNFTAddress } from "./constants";

// Initialize the RPC provider with the ArkChain node URL
const starknetProvider = new RpcProvider({
Expand All @@ -25,29 +26,20 @@ const arkProvider = new RpcProvider({
nodeUrl: process.env.ARKCHAIN_RPC_URL ?? "http://0.0.0.0:7777"
});

const katana0 = {
privateKey: "0x1800000000300000180000000000030000000000003006001800006600",
publicKey:
"0x2b191c2f3ecf685a91af7cf72a43e7b90e2e41220175de5c4f7498981b10053",
accountAddress:
"0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
};

const katana1 = {
privateKey:
"0x33003003001800009900180300d206308b0070db00121318d17b5e6262150b",
publicKey:
"0x4c0f884b8e5b4f00d97a3aad26b2e5de0c0c76a555060c837da2e287403c01d",
accountAddress:
"0x5686a647a9cdd63ade617e0baf3b364856b813b508f03903eb58a7e622d5855"
};
const network = (process.env.NETWORK ?? "dev") as Network;

/**
* Creates a listing on the blockchain using provided order details.
*
* @param {RpcProvider} provider - The RPC provider instance.
*/
(async (arkProvider: RpcProvider, starknetProvider: RpcProvider) => {
(async (
network: Network,
arkProvider: RpcProvider,
starknetProvider: RpcProvider
) => {
const STARKNET_NFT_ADDRESS = getExampleNFTAddress(network);

// Create a new account using the provider
const { account: arkAccount } = await createAccount(arkProvider);
const starknetAccount = await fetchOrCreateAccount(
Expand All @@ -64,18 +56,20 @@ const katana1 = {
};

// Create the listing on the blockchain using the order details
await createListing(arkProvider, starknetAccount, arkAccount, order);
await createListing(network, arkProvider, starknetAccount, arkAccount, order);
await new Promise((resolve) => setTimeout(resolve, 2000));
// Get the order hash
const { orderHash } = await getOrderHash(
order.tokenId,
order.tokenAddress,
network,
arkProvider
);

let { orderStatus: orderStatusAfter } = await getOrderStatus(
orderHash,
network,
arkProvider
);
console.log("orderStatus", shortString.decodeShortString(orderStatusAfter));
})(arkProvider, starknetProvider);
})(network, arkProvider, starknetProvider);
13 changes: 10 additions & 3 deletions packages/core/examples/createOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { RpcProvider } from "starknet";

import { Network } from "../src";
import {
createAccount,
fetchOrCreateAccount
Expand All @@ -23,12 +24,18 @@ const arkProvider = new RpcProvider({
nodeUrl: process.env.ARKCHAIN_RPC_URL ?? "http://0.0.0.0:7777"
});

const network = (process.env.NETWORK ?? "dev") as Network;

/**
* Creates a listing on the blockchain using provided order details.
*
* @param {RpcProvider} provider - The RPC provider instance.
*/
(async (arkProvider: RpcProvider, starknetProvider: RpcProvider) => {
(async (
network: Network,
arkProvider: RpcProvider,
starknetProvider: RpcProvider
) => {
// Create a new account using the provider
const { account: arkAccount } = await createAccount(arkProvider);
const starknetAccount = await fetchOrCreateAccount(
Expand All @@ -48,5 +55,5 @@ const arkProvider = new RpcProvider({

// Create the listing on the blockchain using the order details
console.log("Creating listing order...");
await createOffer(arkProvider, starknetAccount, arkAccount, order);
})(arkProvider, starknetProvider);
await createOffer(network, arkProvider, starknetAccount, arkAccount, order);
})(network, arkProvider, starknetProvider);
47 changes: 33 additions & 14 deletions packages/core/examples/fulfillListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import {
import { approveERC20, approveERC721 } from "../src/actions/contract";
import { createListing, fulfillListing } from "../src/actions/order";
import { getOrderHash, getOrderStatus } from "../src/actions/read";
import {
STARKNET_ETH_ADDRESS,
STARKNET_EXECUTOR_ADDRESS,
STARKNET_NFT_ADDRESS
} from "../src/constants";
import { ListingV1 } from "../src/types";
import { getContractAddresses } from "../src/constants";
import { ListingV1, Network } from "../src/types";
import { getExampleNFTAddress } from "./constants";

// Initialize the RPC provider with the ArkChain node URL
const starknetProvider = new RpcProvider({
Expand All @@ -37,13 +34,16 @@ const arkProvider = new RpcProvider({
nodeUrl: process.env.ARKCHAIN_RPC_URL || ""
});

const network = (process.env.NETWORK ?? "dev") as Network;

async function freeMint(
contractAddress: string,
provider: RpcProvider,
starknetAccount: Account,
tokenId: BigNumberish
) {
const mintResult = await starknetAccount.execute({
contractAddress: STARKNET_NFT_ADDRESS,
contractAddress,
entrypoint: "mint",
calldata: CallData.compile({
recipient: starknetAccount.address,
Expand All @@ -58,19 +58,24 @@ async function freeMint(
*
* @param {RpcProvider} provider - The RPC provider instance.
*/
(async (arkProvider: RpcProvider, starknetProvider: RpcProvider) => {
(async (
network: Network,
arkProvider: RpcProvider,
starknetProvider: RpcProvider
) => {
console.log("=> process.env.ARKCHAIN_RPC_URL", process.env.ARKCHAIN_RPC_URL);

// Create a new account for the listing using the provider
const { account: arkAccount } = await createAccount(arkProvider);

console.log("STARKNET_NFT_ADDRESS:", STARKNET_NFT_ADDRESS);
const STARKNET_NFT_ADDRESS = getExampleNFTAddress(network);
const { STARKNET_EXECUTOR_ADDRESS, STARKNET_ETH_ADDRESS } =
getContractAddresses(network);

// Define the order details
let order: ListingV1 = {
brokerId: 123, // The broker ID
tokenAddress: STARKNET_NFT_ADDRESS, // The token address
tokenId: 5, // The ID of the token
tokenId: 16, // The ID of the token
startAmount: 100000000000000000 // The starting amount for the order
};

Expand All @@ -81,7 +86,12 @@ async function freeMint(
);

console.log("Minting token...", STARKNET_NFT_ADDRESS);
await freeMint(starknetProvider, starknetOffererAccount, order.tokenId);
await freeMint(
STARKNET_NFT_ADDRESS,
starknetProvider,
starknetOffererAccount,
order.tokenId
);

console.log(
`Approving token ${order.tokenId} to ${STARKNET_EXECUTOR_ADDRESS}...`
Expand All @@ -96,7 +106,13 @@ async function freeMint(

console.log("Creating listing...");
// Create the listing on the arkchain using the order details
await createListing(arkProvider, starknetOffererAccount, arkAccount, order);
await createListing(
network,
arkProvider,
starknetOffererAccount,
arkAccount,
order
);

// wait 5 seconds for the transaction to be processed
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand All @@ -105,6 +121,7 @@ async function freeMint(
const { orderHash } = await getOrderHash(
order.tokenId,
order.tokenAddress,
network,
arkProvider
);

Expand Down Expand Up @@ -149,6 +166,7 @@ async function freeMint(

// Cancel the order
fulfillListing(
network,
arkProvider,
starknetFulfillerAccount,
arkAccount,
Expand All @@ -158,7 +176,8 @@ async function freeMint(

let { orderStatus: orderStatusAfter } = await getOrderStatus(
orderHash,
network,
arkProvider
);
console.log("orderStatus", shortString.decodeShortString(orderStatusAfter));
})(arkProvider, starknetProvider);
})(network, arkProvider, starknetProvider);
Loading