npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@duelo/core

v0.1.26

Published

sdk for Duelo Tournaments

Downloads

4

Readme

Duelo program library

Install the Typescript package

yarn add @duelo/core

Setup the package in your app

Setup Duelo to work with the connected wallet:

import { useAnchorWallet, useConnection } from "@solana/wallet-adapter-react";
import { DueloCore } from "@duelo/core";
import { DueloCore, DUELO_PROGRAM_ID, IDL } from "@duelo/core";

const anchorWallet = useAnchorWallet() as Wallet;
const { connection } = useConnection();

const duelo = new DueloCore(connection, anchorWallet, IDL, DUELO_PROGRAM_ID);

(async () => await duelo.fetchTournamentAcc(LUCHA_MANIA_TOURNAMENT_ID))();

Methods available on duelo/core

Fetch tournament account:

async fetchTournamentAcc(tournamentKey: PublicKey): Promise<TournamentAccount>

Create tournament account:

/!\ this will be handled by a script in mainnet

// This can be any NFT
const collectionNft = await createNft(provider, provider.publicKey);

const startTimestamp = Number((new Date().getTime() / 1000).toFixed(0));

// Change this to start the tournament whenever you need it to start
const inSevenDays = 86400 * 7;

// Tournament starts in 7 days
const { tournamentAccountKey } = await duelo.createTournament(
  collectionNft.mintKey,
  new BN(startTimestamp + inSevenDays)
);

await duelo.fetchTournamentAcc(tournamentAccountKey);

Mint a new Duelo NFT:

async mintDueloNft(
  tournamentAccountId: PublicKey,
  collectionMint: PublicKey
): Promise<{ mintId: PublicKey }>

Fetch a Luchador skills:

async fetchSkillsAcc(
  tournamentKey: PublicKey,
  mintKey: PublicKey
): Promise<NftSkillsAccount>

Example response:

{
    "health": 100,
    "defense": 100,
    "speed": 100,
    "attack": 100,
    "availablePoints": 200,
    "nftMint": "<nft_mint_address>",
    "owner": "<owner_wallet_address>",
    "bump": 254
}

Update a Luchador skills:

type UpdateAttributesArgs = {
  attack: number;
  health: number;
  speed: number;
  defense: numbe;
}

async updateDueloNftSkills(
  tournamentAccountId: PublicKey,
  nftMint: PublicKey,
  updateSkillzArgs: UpdateAttributesArgs
): Promise<{ mintId: PublicKey }>

Create a bracket:

/!\ this will be handled by a script in mainnet

const { bracketKey, instructions, signers, gamesKey } = await duelo.createBracket(
  tournamentAccountKey,
  // Data from fetchTournament, this is the index of the bracket to be created (make sure to have fresh data)
  tournamentAccountData.nextBracket,
  // Max number of games based on number of NFTs minted
  maxGames, 
  // Similar to the timestamp used to create the tournament
  endTimestamp 
);

await provider.sendAndConfirm(
  new Transaction().add(...instructions.map(ix => (ix))),
  signers,
  { skipPreflight: true }
);

Add two matches to a bracket:

/!\ this will be handled by a script in mainnet

await duelo.createMatch(tournamentAccountKey, bracketKey, gamesKey, [dueloNft1, dueloNft2]);
await duelo.createMatch(tournamentAccountKey, bracketKey, gamesKey, [dueloNft3, dueloNft4]);

Fetch a bracket matches:

async fetchCurrentBracketGames(
  tournamentKey: PublicKey
): Promise<GamesAccount>

This method will return a list of all the games of the current bracket.

If you want to get the games of a previous bracket, set the selectBracket param to this bracket (between 0 and tournament.currentBracket).

The data format is as follows:

{
  total: 2,
  max: 2,
  games: [
    {
      game: PublicKey,
      nftLeft: PublicKey,
      nftRight: PublicKey,
    },
    {
      game: PublicKey,
      nftLeft: PublicKey,
      nftRight: PublicKey,
    }
  ]
}

You then need to fetch the games accounts data:

async fetchGameAcc(
  gameKey: PublicKey
): Promise<GameAccount>

Fetch my current matches:

async fetchMyCurrentBracketGames(
  tournamentKey: PublicKey,
  nfts: PublicKey[],
  selectBracket?: number
): Promise<GamesAccount>

This method will return a list of all the games from the current bracket that contain the nfts passed as parameters.

If you want to get the games of a previous bracket, set the selectBracket param to this bracket (between 0 and tournament.currentBracket).

The format is the same as the previous method's.

Full example

import { Wallet } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { useAnchorWallet, useWallet, useConnection } from "@solana/wallet-adapter-react";
import { DUELO_PROGRAM_ID, DueloCore, IDL } from "@duelo/core";
import { WalletDisconnectButton, WalletMultiButton } from "@solana/wallet-adapter-react-ui";


const MintDueloNFT = () => {
  const anchorWallet = useAnchorWallet() as Wallet;
  const { connection } = useConnection();
  const duelo = new DueloCore(connection, anchorWallet, IDL, DUELO_PROGRAM_ID);

  async function click() {
    const tournamentKey = new PublicKey("<LUCHA_MANIA_TOURNAMENT_ID>");
    const tournament = await duelo.fetchTournamentAcc(tournamentKey);

    const { mintId } = await duelo.mintDueloNft(tournamentKey, tournament.collectionMint);

    const originalSkills = await duelo.fetchAttributesAcc(tournamentKey, mintId);
    console.log('skills: ', originalSkills);
    // Response
    // ----
    // {
    //   "health": 100,
    //   "defense": 100,
    //   "speed": 100,
    //   "attack": 100,
    //   "availablePoints": 200,
    //   "nftMint": "11111111111111111111111111111111",
    //   "owner": "11111111111111111111111111111111",
    //   "bump": 254
    // }

    await duelo.updateDueloNftSkills(tournamentKey, mintId, {
      "health": 120,
      "defense": 150,
      "speed": 110,
      "attack": 120,
    });

    const skillsAfterUpdate = await duelo.fetchAttributesAcc(tournamentKey, mintId);
    console.log('skills after update: ', skillsAfterUpdate);
    // Response
    // ----
    // {
    //   "health": 120,
    //   "defense": 150,
    //   "speed": 110,
    //   "attack": 120,
    //   "availablePoints": 100,
    //   "nftMint": "11111111111111111111111111111111",
    //   "owner": "11111111111111111111111111111111",
    //   "bump": 254
    // }
  }

  return <>
    <div>
      {!anchorWallet && <WalletMultiButton />}
      {anchorWallet &&
        <>
          <WalletDisconnectButton />
          <button onClick={click}>
            CLICK ME
          </button>
        </>}
    </div>
  </>
}

export default MintDueloNFT;

Fetch all assets

You can also fetch all the assets from the tournament with this method on the duelo class:

async fetchMyTournamentAssets(
  collectionMint: PublicKey, 
  owner?: PublicKey, 
  page?: number, 
  limit?: number
): Promise<any>

The result, containing all the NFTs from this collection, will look like this:

{
  "jsonrpc": "2.0",
  "result": {
    "total": 12,
    "limit": 1000,
    "page": 1,
    "items": [
      {}, {},
      {}, {},
      {}, {},
      {}, {},
      {}, {},
      {}, {}
    ]
  },
  "id": "duelo-assets-search"
}

You can also fetch assets belonging to just one wallet by adding the owner param to the function call, as described in the function signature.

Run tests (local dev, for Rust programmers)

Start your local validator (from .anchor dir)

solana-test-validator -r \
  --mint 4YonHNa8dXeDSFpfpoLoGU3cB4YCtk8Q5hHDxL3Y3GFx \
  --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ../tests/mainnet-programs/metadata.so \
  --bpf-program auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg ../tests/mainnet-programs/mpl-auth.so

Run the Duelo tests (from root dir)

anchor test --provider.cluster localnet --skip-local-validator

Check your transactions on explorer.solana.com (turn on custom endpoint to localnet address).