From c7eda25f68765d94d858a988ccfb29875bd9f4bb Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Thu, 1 Dec 2022 13:51:59 -0500 Subject: [PATCH] Removing build code. --- .gitignore | 2 + cli/bin/auth.js | 7 -- cli/bin/helpers/pdas.js | 34 ------ cli/bin/helpers/trifle.js | 238 -------------------------------------- cli/bin/helpers/utils.js | 94 --------------- 5 files changed, 2 insertions(+), 373 deletions(-) delete mode 100644 cli/bin/auth.js delete mode 100644 cli/bin/helpers/pdas.js delete mode 100644 cli/bin/helpers/trifle.js delete mode 100644 cli/bin/helpers/utils.js diff --git a/.gitignore b/.gitignore index d9842fd0..d3701347 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ yarn-error.log* !.yarn/versions .vercel +cli/bin/ +cli/node_modules/ \ No newline at end of file diff --git a/cli/bin/auth.js b/cli/bin/auth.js deleted file mode 100644 index 9f287f96..00000000 --- a/cli/bin/auth.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const msgpack_1 = require("@msgpack/msgpack"); -const encoded = (0, msgpack_1.encode)({ foo: 'bar' }); -console.log(encoded); -const decoded = (0, msgpack_1.decode)(encoded); -console.log(decoded); diff --git a/cli/bin/helpers/pdas.js b/cli/bin/helpers/pdas.js deleted file mode 100644 index 8f36aff5..00000000 --- a/cli/bin/helpers/pdas.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.findEscrowPda = exports.findTriflePda = exports.findEscrowConstraintModelPda = void 0; -const web3_js_1 = require("@solana/web3.js"); -const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata"); -const generated_1 = require("../../../js/src/generated"); -const utils_1 = require("./utils"); -const findEscrowConstraintModelPda = async (creator, name) => { - return await web3_js_1.PublicKey.findProgramAddress([Buffer.from("escrow"), creator.toBuffer(), Buffer.from(name)], new web3_js_1.PublicKey(generated_1.PROGRAM_ADDRESS)); -}; -exports.findEscrowConstraintModelPda = findEscrowConstraintModelPda; -const findTriflePda = async (mint, authority) => { - return await web3_js_1.PublicKey.findProgramAddress([Buffer.from("trifle"), mint.toBuffer(), authority.toBuffer()], new web3_js_1.PublicKey(generated_1.PROGRAM_ADDRESS)); -}; -exports.findTriflePda = findTriflePda; -const findEscrowPda = async (mint, authority, creator) => { - const seeds = [ - Buffer.from("metadata"), - new web3_js_1.PublicKey(mpl_token_metadata_1.PROGRAM_ADDRESS).toBuffer(), - mint.toBuffer(), - Uint8Array.from([authority]), - ]; - if (authority == utils_1.EscrowAuthority.Creator) { - if (creator) { - seeds.push(creator.toBuffer()); - } - else { - throw new Error("Creator is required"); - } - } - seeds.push(Buffer.from("escrow")); - return await web3_js_1.PublicKey.findProgramAddress(seeds, new web3_js_1.PublicKey(mpl_token_metadata_1.PROGRAM_ADDRESS)); -}; -exports.findEscrowPda = findEscrowPda; diff --git a/cli/bin/helpers/trifle.js b/cli/bin/helpers/trifle.js deleted file mode 100644 index eb8eccd2..00000000 --- a/cli/bin/helpers/trifle.js +++ /dev/null @@ -1,238 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.showTrifle = exports.showModel = exports.transferOut = exports.transferIn = exports.createTrifle = exports.addTokensConstraint = exports.addCollectionConstraint = exports.addNoneConstraint = exports.createConstraintModel = void 0; -const web3_js_1 = require("@solana/web3.js"); -const generated_1 = require("../../../js/src/generated"); -const pdas_1 = require("./pdas"); -const spl_token_1 = require("@solana/spl-token"); -const js_1 = require("@metaplex-foundation/js"); -const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata"); -const utils_1 = require("./utils"); -const createConstraintModel = async (connection, keypair, name, schema) => { - const escrowConstraintModel = await (0, pdas_1.findEscrowConstraintModelPda)(keypair.publicKey, name); - const createIX = (0, generated_1.createCreateEscrowConstraintModelAccountInstruction)({ - escrowConstraintModel: escrowConstraintModel[0], - payer: keypair.publicKey, - updateAuthority: keypair.publicKey, - }, { - createEscrowConstraintModelAccountArgs: { - name, - schemaUri: schema, - }, - }); - const tx = new web3_js_1.Transaction().add(createIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - const sig = await connection.sendTransaction(tx, [keypair]); - // await connection.sendTransaction(tx, [keypair]); - await connection.confirmTransaction(sig, "finalized"); - return escrowConstraintModel[0]; -}; -exports.createConstraintModel = createConstraintModel; -const addNoneConstraint = async (connection, keypair, name, tokenLimit, transferEffects, model) => { - const addIX = (0, generated_1.createAddNoneConstraintToEscrowConstraintModelInstruction)({ - constraintModel: model, - payer: keypair.publicKey, - updateAuthority: keypair.publicKey, - systemProgram: web3_js_1.SystemProgram.programId, - sysvarInstructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, - }, { - addNoneConstraintToEscrowConstraintModelArgs: { - constraintName: name, - tokenLimit: tokenLimit, - transferEffects, - }, - }); - const tx = new web3_js_1.Transaction().add(addIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - const sig = await connection.sendTransaction(tx, [keypair], { skipPreflight: true }); - await connection.confirmTransaction(sig, "finalized"); -}; -exports.addNoneConstraint = addNoneConstraint; -const addCollectionConstraint = async (connection, keypair, name, tokenLimit, collection, transferEffects, model) => { - const collectionMintMetadata = await (0, js_1.findMetadataPda)(collection); - const addIX = (0, generated_1.createAddCollectionConstraintToEscrowConstraintModelInstruction)({ - constraintModel: model, - payer: keypair.publicKey, - updateAuthority: keypair.publicKey, - collectionMint: collection, - collectionMintMetadata, - sysvarInstructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, - }, { - addCollectionConstraintToEscrowConstraintModelArgs: { - constraintName: name, - tokenLimit: tokenLimit, - transferEffects, - }, - }); - const tx = new web3_js_1.Transaction().add(addIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - const sig = await connection.sendTransaction(tx, [keypair], { - skipPreflight: true, - }); - await connection.confirmTransaction(sig, "finalized"); -}; -exports.addCollectionConstraint = addCollectionConstraint; -const addTokensConstraint = async (connection, keypair, name, tokenLimit, tokens, transferEffects, model) => { - const addIX = (0, generated_1.createAddTokensConstraintToEscrowConstraintModelInstruction)({ - constraintModel: model, - payer: keypair.publicKey, - updateAuthority: keypair.publicKey, - sysvarInstructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, - }, { - addTokensConstraintToEscrowConstraintModelArgs: { - constraintName: name, - tokenLimit: tokenLimit, - tokens, - transferEffects, - }, - }); - const tx = new web3_js_1.Transaction().add(addIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - const sig = await connection.sendTransaction(tx, [keypair], { - skipPreflight: true, - }); - await connection.confirmTransaction(sig, "finalized"); -}; -exports.addTokensConstraint = addTokensConstraint; -const createTrifle = async (connection, nft, keypair, model_name) => { - const escrowConstraintModel = await (0, pdas_1.findEscrowConstraintModelPda)(keypair.publicKey, model_name); - const trifleAddress = await (0, pdas_1.findTriflePda)(nft.mint.address, keypair.publicKey); - const escrowAccountAddress = await (0, pdas_1.findEscrowPda)(nft.mint.address, utils_1.EscrowAuthority.Creator, trifleAddress[0]); - const createIX = (0, generated_1.createCreateTrifleAccountInstruction)({ - escrow: escrowAccountAddress[0], - metadata: nft.metadataAddress, - mint: nft.mint.address, - tokenAccount: nft.token.address, - edition: nft.edition.address, - trifleAccount: trifleAddress[0], - trifleAuthority: keypair.publicKey, - constraintModel: escrowConstraintModel[0], - payer: keypair.publicKey, - tokenMetadataProgram: new web3_js_1.PublicKey(mpl_token_metadata_1.PROGRAM_ADDRESS), - sysvarInstructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, - }); - const tx = new web3_js_1.Transaction().add(createIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - const sig = await connection.sendTransaction(tx, [keypair], { - skipPreflight: false, - }); - await connection.confirmTransaction(sig, "finalized"); - return trifleAddress[0]; -}; -exports.createTrifle = createTrifle; -const transferIn = async (connection, escrowNft, escrowAccountAddress, nft, keypair, slot) => { - const escrowConstraintModel = await (0, pdas_1.findEscrowConstraintModelPda)(keypair.publicKey, "test"); - const trifleAddress = await (0, pdas_1.findTriflePda)(escrowNft.mint.address, keypair.publicKey); - const dst = await (0, spl_token_1.getAssociatedTokenAddress)(nft.mint.address, escrowAccountAddress, true); - // trifle: web3.PublicKey; - // trifleAuthority: web3.PublicKey; - // payer: web3.PublicKey; - // constraintModel: web3.PublicKey; - // escrow: web3.PublicKey; - // escrowMint?: web3.PublicKey; - // escrowToken?: web3.PublicKey; - // escrowEdition?: web3.PublicKey; - // attributeMint?: web3.PublicKey; - // attributeSrcToken?: web3.PublicKey; - // attributeDstToken?: web3.PublicKey; - // attributeMetadata?: web3.PublicKey; - // attributeEdition?: web3.PublicKey; - // attributeCollectionMetadata?: web3.PublicKey; - const transferIX = (0, generated_1.createTransferInInstruction)({ - trifle: trifleAddress[0], - constraintModel: escrowConstraintModel[0], - escrow: escrowAccountAddress, - payer: keypair.publicKey, - trifleAuthority: keypair.publicKey, - attributeMint: nft.mint.address, - attributeSrcToken: nft.token.address, - attributeDstToken: dst, - attributeMetadata: nft.metadataAddress, - escrowMint: escrowNft.mint.address, - escrowToken: escrowNft.token.address, - splToken: new web3_js_1.PublicKey(spl_token_1.TOKEN_PROGRAM_ID), - splAssociatedTokenAccount: new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID), - tokenMetadataProgram: new web3_js_1.PublicKey(mpl_token_metadata_1.PROGRAM_ADDRESS), - }, { - transferInArgs: { amount: 1, slot }, - }); - const tx = new web3_js_1.Transaction().add(transferIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - // console.log(tx); - const sig = await connection.sendTransaction(tx, [keypair], { - skipPreflight: true, - }); - await connection.confirmTransaction(sig, "finalized"); -}; -exports.transferIn = transferIn; -const transferOut = async (connection, escrowNft, escrowAccountAddress, nft, keypair, slot) => { - const escrowConstraintModel = await (0, pdas_1.findEscrowConstraintModelPda)(keypair.publicKey, "test"); - const trifleAddress = await (0, pdas_1.findTriflePda)(escrowNft.mint.address, keypair.publicKey); - const dst = await (0, spl_token_1.getAssociatedTokenAddress)(nft.mint.address, keypair.publicKey, true); - const transferIX = (0, generated_1.createTransferOutInstruction)({ - trifleAccount: trifleAddress[0], - constraintModel: escrowConstraintModel[0], - escrowAccount: escrowAccountAddress, - escrowTokenAccount: escrowNft.token.address, - escrowMint: escrowNft.mint.address, - escrowMetadata: escrowNft.metadataAddress, - payer: keypair.publicKey, - trifleAuthority: keypair.publicKey, - attributeMint: nft.mint.address, - attributeSrcTokenAccount: nft.token.address, - attributeDstTokenAccount: dst, - attributeMetadata: nft.metadataAddress, - splAssociatedTokenAccount: new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID), - splToken: new web3_js_1.PublicKey(spl_token_1.TOKEN_PROGRAM_ID), - tokenMetadataProgram: new web3_js_1.PublicKey(mpl_token_metadata_1.PROGRAM_ADDRESS), - sysvarInstructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, - }, { - transferOutArgs: { amount: 1, slot }, - }); - const tx = new web3_js_1.Transaction().add(transferIX); - const { blockhash } = await connection.getLatestBlockhash(); - tx.recentBlockhash = blockhash; - tx.feePayer = keypair.publicKey; - // console.log(tx); - const sig = await connection.sendTransaction(tx, [keypair], { - skipPreflight: true, - }); - await connection.confirmTransaction(sig, "finalized"); -}; -exports.transferOut = transferOut; -const showModel = async (connection, modelAddress) => { - // console.log("Fetching " + modelAddress.toString()); - const accountInfo = await connection.getAccountInfo(modelAddress); - if (accountInfo) { - const account = generated_1.EscrowConstraintModel.fromAccountInfo(accountInfo)[0]; - console.log(JSON.stringify(account.pretty(), utils_1.map_replacer)); - } - else { - console.log("Unable to fetch account"); - } -}; -exports.showModel = showModel; -const showTrifle = async (connection, trifleAddress) => { - // console.log("Fetching " + trifleAddress.toString()); - const accountInfo = await connection.getAccountInfo(trifleAddress); - if (accountInfo) { - const account = generated_1.Trifle.fromAccountInfo(accountInfo)[0]; - console.log(JSON.stringify(account.pretty(), utils_1.map_replacer)); - } - else { - console.log("Unable to fetch account"); - } -}; -exports.showTrifle = showTrifle; diff --git a/cli/bin/helpers/utils.js b/cli/bin/helpers/utils.js deleted file mode 100644 index e590e8d5..00000000 --- a/cli/bin/helpers/utils.js +++ /dev/null @@ -1,94 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.map_replacer = exports.EscrowAuthority = exports.loadSolanaConfigFile = exports.use_metaplex = void 0; -const os_1 = __importDefault(require("os")); -const yaml_1 = __importDefault(require("yaml")); -const js_1 = require("@metaplex-foundation/js"); -const web3 = __importStar(require("@solana/web3.js")); -const fs = __importStar(require("fs")); -async function use_metaplex(keypair, env, rpc) { - const solanaConfig = (0, exports.loadSolanaConfigFile)(); - let connection; - const selectedRPC = rpc || solanaConfig.json_rpc_url; - const selectedKeypairPath = keypair || solanaConfig.keypair_path; - if (selectedRPC) { - connection = new web3.Connection(selectedRPC, { - confirmTransactionInitialTimeout: 360000, - }); - } - else { - connection = new web3.Connection(web3.clusterApiUrl(env), { - confirmTransactionInitialTimeout: 360000, - }); - } - // Load a local keypair. - const keypairFile = fs.readFileSync(selectedKeypairPath); - const wallet = web3.Keypair.fromSecretKey(Buffer.from(JSON.parse(keypairFile.toString()))); - const metaplex = new js_1.Metaplex(connection); - // Use it in the SDK. - metaplex.use((0, js_1.keypairIdentity)(wallet)); - return metaplex; -} -exports.use_metaplex = use_metaplex; -const loadSolanaConfigFile = () => { - try { - const path = os_1.default.homedir() + '/.config/solana/cli/config.yml'; - const solanaConfigFile = fs.readFileSync(path); - const config = yaml_1.default.parse(solanaConfigFile.toString()); - return config; - } - catch (e) { - return {}; - } -}; -exports.loadSolanaConfigFile = loadSolanaConfigFile; -var EscrowAuthority; -(function (EscrowAuthority) { - EscrowAuthority[EscrowAuthority["TokenOwner"] = 0] = "TokenOwner"; - EscrowAuthority[EscrowAuthority["Creator"] = 1] = "Creator"; -})(EscrowAuthority = exports.EscrowAuthority || (exports.EscrowAuthority = {})); -// Creating a replacer to properly JSON stringify Maps. -function map_replacer(key, value) { - if (value instanceof Map) { - return { - dataType: 'Map', - value: Array.from(value.entries()), // or with spread: value: [...value] - }; - } - else if (value instanceof Set) { - return { - dataType: 'Set', - value: Array.from(value.values()), - }; - } - else { - return value; - } -} -exports.map_replacer = map_replacer;