Skip to content

Commit

Permalink
feat: update cep78 & marketplace scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bufo24 committed Aug 22, 2023
1 parent 83c8ee0 commit 68d30e5
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 46 deletions.
Binary file modified .DS_Store
Binary file not shown.
23 changes: 17 additions & 6 deletions scripts/cep78/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Keys,
CLString,
CLU64,
CLKey,
CLByteArray,
} from "casper-js-sdk";
import { stringToKey } from "./utils";
import dotenv from "dotenv";
Expand All @@ -14,9 +16,9 @@ dotenv.config();
let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIIVATE_KEY) {
if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIIVATE_KEY;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}
Expand All @@ -25,23 +27,32 @@ const casperClient = new CasperClient(rpcUri);

const privateKeyPath = "/Users/bufo/Downloads/BitHotel_secret_key.pem";

// 0165e406c81af68793a4f56b60f646f9eeba2fad1bd16f06cd1c42f6f8d88cc5fb
const key = Keys.Ed25519.loadKeyPairFromPrivateFile(privateKeyPath);

// 013cafb1912c0ca0dc6e0251905f29ebe01176371c298e513a24c0f2d9b2bbff28
const key2 = Keys.getKeysFromHexPrivKey(
privateKey,
Keys.SignatureAlgorithm.Ed25519
);

const contractClient = new Contracts.Contract();
contractClient.setContractHash(
"hash-0b659298a70a7bfcde35aceb49a0d7b4a34aed5e0a7e946db135d598edd411b9"
"hash-59a13d7a9c89d989a13b9b15e183eb0ab695b95c98fd98a082b171efacd1c3ca"
);

const runtimeArgs = RuntimeArgs.fromMap({
operator: stringToKey(
"cc8d74f5cdd36bf926ebb47f57f6d6f2317846c852623fcee72bb5f756d99857"
operator: new CLKey(
new CLByteArray(
Uint8Array.from(
Buffer.from(
"411f0c5ae537b18beabfe43601d3e2d238bd7b89e1566ff78fff66a07826a0db",
"hex"
)
)
)
),
token_id: new CLU64(2),
token_id: new CLU64(9),
});

const preparedDeploy = contractClient.callEntrypoint(
Expand Down
37 changes: 16 additions & 21 deletions scripts/cep78/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ dotenv.config();
let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIIVATE_KEY) {
if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIIVATE_KEY;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}
Expand All @@ -28,41 +28,36 @@ const casperClient = new CasperClient(rpcUri);

const privateKeyPath = "/Users/bufo/Downloads/BitHotel_secret_key.pem";

// 0165e406c81af68793a4f56b60f646f9eeba2fad1bd16f06cd1c42f6f8d88cc5fb
const key = Keys.Ed25519.loadKeyPairFromPrivateFile(privateKeyPath);

// 013cafb1912c0ca0dc6e0251905f29ebe01176371c298e513a24c0f2d9b2bbff28
const recipientKey = Keys.getKeysFromHexPrivKey(
privateKey,
Keys.SignatureAlgorithm.Ed25519
);

const contractClient = new Contracts.Contract();
contractClient.setContractHash(
"hash-0b659298a70a7bfcde35aceb49a0d7b4a34aed5e0a7e946db135d598edd411b9"
"hash-59a13d7a9c89d989a13b9b15e183eb0ab695b95c98fd98a082b171efacd1c3ca"
);

const metadata = {
name: "Casper punk",
description: "This is a Casper Punk!",
name: "CasperPunk Hotel Guest",
description:
"The original and limited edition CasperPunk hotel guest that is only available on the Casper blockchain. This scary character is in high demand among hotel guests.",
image:
"https://apigateway.bithotel.io/metadata/QmWN9Gb4A1gT1j7DQj34gn3Mta3jQcsLmddjaU7JabcHuG",
external_link: "https://bithotel.io/#/",
"https://apigateway.bithotel.io/metadata/QmSFjb5DtAg5Zyf6fvferRCGijUfLUmMV1jTYCX7k1uTRG",
external_link: "https://www.bithotel.io/#/",
attributes: [
{
trait_type: "Rarity",
value: "Epic",
},
{
trait_type: "Replicas",
value: "10",
},
{
trait_type: "Drop",
value: "Season 2",
},
{ trait_type: "Rarity", value: "Uncommon" },
{ trait_type: "Replicas", value: "3000" },
{ trait_type: "Drop", value: "Season 2" },
],
};

const runtimeArgs = RuntimeArgs.fromMap({
token_owner: new CLKey(recipientKey.publicKey),
token_owner: new CLKey(key.publicKey),
token_meta_data: new CLString(JSON.stringify(metadata)),
});

Expand All @@ -71,7 +66,7 @@ const preparedDeploy = contractClient.callEntrypoint(
runtimeArgs,
key.publicKey,
"casper-test",
"20000000000",
"5000000000",
[key]
);

Expand Down
26 changes: 15 additions & 11 deletions scripts/marketplace/add-listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ dotenv.config();
let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIIVATE_KEY) {
if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIIVATE_KEY;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}
Expand All @@ -26,30 +26,34 @@ const key = Keys.getKeysFromHexPrivKey(
privateKey,
Keys.SignatureAlgorithm.Ed25519
);
const privateKeyPath = "/Users/bufo/Downloads/BitHotel_secret_key.pem";

const key2 = Keys.Ed25519.loadKeyPairFromPrivateFile(privateKeyPath);

// b590bbf67fb2f60bdb54a7295bbb602f63008e4d8bb49fefe093ec805283b82f
// cc8d74f5cdd36bf926ebb47f57f6d6f2317846c852623fcee72bb5f756d99857
const contractClient = new Contracts.Contract();
contractClient.setContractHash(
"hash-cc8d74f5cdd36bf926ebb47f57f6d6f2317846c852623fcee72bb5f756d99857"
"hash-411f0c5ae537b18beabfe43601d3e2d238bd7b89e1566ff78fff66a07826a0db"
);

console.log({ hash: contractClient.contractHash });
const price = 75;

const runtimeArgs = RuntimeArgs.fromMap({
collection: CasperHelpers.stringToKey(
"0b659298a70a7bfcde35aceb49a0d7b4a34aed5e0a7e946db135d598edd411b9"
"59a13d7a9c89d989a13b9b15e183eb0ab695b95c98fd98a082b171efacd1c3ca"
),
token_id: new CLU64(2),
price: new CLU256(50),
token_id: new CLU64(9),
price: new CLU256(price * 1_000_000_000),
});

const preparedDeploy = contractClient.callEntrypoint(
"add_listing",
runtimeArgs,
key.publicKey,
key2.publicKey,
"casper-test",
"35000000000",
[key]
"10000000000",
[key2]
);

// casperClient.putDeploy(preparedDeploy).then(console.log).catch(console.error);
casperClient.putDeploy(preparedDeploy).then(console.log).catch(console.error);
8 changes: 4 additions & 4 deletions scripts/marketplace/cancel-listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ dotenv.config();
let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIIVATE_KEY) {
if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIIVATE_KEY;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}
Expand All @@ -28,11 +28,11 @@ const key = Keys.getKeysFromHexPrivKey(

const contractClient = new Contracts.Contract();
contractClient.setContractHash(
"hash-b590bbf67fb2f60bdb54a7295bbb602f63008e4d8bb49fefe093ec805283b82f"
"hash-411f0c5ae537b18beabfe43601d3e2d238bd7b89e1566ff78fff66a07826a0db"
);

const runtimeArgs = RuntimeArgs.fromMap({
listing_id: new CLU64(3),
listing_id: new CLU64(4),
});

const preparedDeploy = contractClient.callEntrypoint(
Expand Down
56 changes: 56 additions & 0 deletions scripts/marketplace/execute-listing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
CasperClient,
Contracts,
RuntimeArgs,
Keys,
CLU64,
CLU512,
} from "casper-js-sdk";
import dotenv from "dotenv";
import { readFileSync } from "fs";
import { CasperHelpers } from "./helpers";

dotenv.config();

let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}

const casperClient = new CasperClient(rpcUri);

const privateKeyPath = "/Users/bufo/Downloads/BitHotel_secret_key.pem";

const key = Keys.Ed25519.loadKeyPairFromPrivateFile(privateKeyPath);

const executeListingFile = readFileSync("./execute_listing_call.wasm");

const wasm = Uint8Array.from(executeListingFile);

const contractClient = new Contracts.Contract();

const price = 27;

const runtimeArgs = RuntimeArgs.fromMap({
marketplace_contract_hash: CasperHelpers.stringToKey(
"411f0c5ae537b18beabfe43601d3e2d238bd7b89e1566ff78fff66a07826a0db"
),
listing_id: new CLU64(16),
amount: new CLU512(price * 1_000_000_000),
});

const preparedDeploy = contractClient.install(
wasm,
runtimeArgs,
"15000000000",
key.publicKey,
"casper-test",
[key]
);

casperClient.putDeploy(preparedDeploy).then(console.log).catch(console.error);
Binary file added scripts/marketplace/execute_listing_call.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions scripts/marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"dependencies": {
"casper-js-sdk": "^2.12.1",
"dotenv": "^16.0.3"
},
"devDependencies": {
"fs": "^0.0.1-security"
}
}
8 changes: 4 additions & 4 deletions scripts/marketplace/whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ dotenv.config();
let rpcUri: string;
let privateKey: string;

if (process.env.RPC_URI && process.env.PRIIVATE_KEY) {
if (process.env.RPC_URI && process.env.PRIVATE_KEY) {
rpcUri = process.env.RPC_URI;
privateKey = process.env.PRIIVATE_KEY;
privateKey = process.env.PRIVATE_KEY;
} else {
throw new Error(`No rpcUri or privateKey found`);
}
Expand All @@ -30,12 +30,12 @@ const key = Keys.Ed25519.loadKeyPairFromPrivateFile(privateKeyPath);

const contractClient = new Contracts.Contract();
contractClient.setContractHash(
"hash-cc8d74f5cdd36bf926ebb47f57f6d6f2317846c852623fcee72bb5f756d99857"
"hash-411f0c5ae537b18beabfe43601d3e2d238bd7b89e1566ff78fff66a07826a0db"
);

const runtimeArgs = RuntimeArgs.fromMap({
collection: CasperHelpers.stringToKey(
"0b659298a70a7bfcde35aceb49a0d7b4a34aed5e0a7e946db135d598edd411b9"
"59a13d7a9c89d989a13b9b15e183eb0ab695b95c98fd98a082b171efacd1c3ca"
),
});

Expand Down
5 changes: 5 additions & 0 deletions scripts/marketplace/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ file-uri-to-path@1.0.0:
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==

fs@^0.0.1-security:
version "0.0.1-security"
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==

hash-base@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.1.0.tgz#55c381d9e06e1d2997a883b4a3fddfe7f0d3af33"
Expand Down

0 comments on commit 68d30e5

Please sign in to comment.