{"_id":"@anastasia-labs/direct-offer-offchain","_rev":"1-42a88f366fe0c9a7cd9c648a2dd52fa3","name":"@anastasia-labs/direct-offer-offchain","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@anastasia-labs/direct-offer-offchain","version":"0.1.0","keywords":[],"author":"","license":"ISC","_id":"@anastasia-labs/direct-offer-offchain@0.1.0","maintainers":[{"name":"anastasia-labs","email":"info@anastasialabs.com"}],"dist":{"shasum":"cba20cd897651ad9ff993857d143019972189d6b","tarball":"https://registry.npmjs.org/@anastasia-labs/direct-offer-offchain/-/direct-offer-offchain-0.1.0.tgz","fileCount":5,"integrity":"sha512-ZElZlrM0wX7ADubnSfigK7kPL6XeoKUohApK4RgM5VyrkMsC9erNXtnnUudG+8ZOC+KXpSpYs7LKw+ZXFdqehw==","signatures":[{"sig":"MEUCIA5olc++sWFmP9YTJRFaGXknKTnrg0cXmyxplLUO000dAiEA35vKbCbE4/ioOM7R93zF5Z+0/w5Rn5Y6o0SNqL1Sjoc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33391},"main":"./dist/index.js","type":"module","_from":"file:anastasia-labs-direct-offer-offchain-0.1.0.tgz","types":"./dist/index.d.ts","scripts":{"lint":"eslint","test":"export NODE_ENV='emulator' && vitest run","build":"tsup src/index.ts --minify --format esm,cjs --dts --clean","repack":"pnpm run build  && pnpm pack","ts-node":"ts-node"},"_npmUser":{"name":"anastasia-labs","email":"info@anastasialabs.com"},"_resolved":"/tmp/29fd890cec6f23d1f6a26ab23fa22f79/anastasia-labs-direct-offer-offchain-0.1.0.tgz","_integrity":"sha512-ZElZlrM0wX7ADubnSfigK7kPL6XeoKUohApK4RgM5VyrkMsC9erNXtnnUudG+8ZOC+KXpSpYs7LKw+ZXFdqehw==","_npmVersion":"10.2.3","description":"https://docs.github.com/en/packages/quickstart","directories":{"test":"test"},"_nodeVersion":"18.19.0","dependencies":{"@anastasia-labs/lucid-cardano-fork":"^0.10.8-rc.2"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^6.7.0","eslint":"^8.39.0","vitest":"0.34.6","ts-node":"^10.9.1","typescript":"^5.1.3","@types/node":"^20.4.9","@sinclair/typebox":"^0.25.13","eslint-config-prettier":"^8.8.0","@typescript-eslint/parser":"^5.59.1","@typescript-eslint/eslint-plugin":"^5.59.1"},"_npmOperationalInternal":{"tmp":"tmp/direct-offer-offchain_0.1.0_1704980841154_0.6037891125723893","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@anastasia-labs/direct-offer-offchain","version":"0.2.0","description":"https://docs.github.com/en/packages/quickstart","main":"./dist/index.js","types":"./dist/index.d.ts","type":"module","keywords":[],"author":"","license":"ISC","devDependencies":{"@sinclair/typebox":"^0.25.13","@types/node":"^20.4.9","@typescript-eslint/eslint-plugin":"^5.59.1","@typescript-eslint/parser":"^5.59.1","eslint":"^8.39.0","eslint-config-prettier":"^8.8.0","ts-node":"^10.9.1","tsup":"^6.7.0","typescript":"^5.1.3","vitest":"0.34.6"},"directories":{"test":"test"},"dependencies":{"@lucid-evolution/lucid":"^0.3.18"},"packageManager":"pnpm@9.7.1+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247","scripts":{"test":"export NODE_ENV='emulator' && vitest run","build":"tsup src/index.ts --minify --format esm,cjs --dts --clean","lint":"eslint","repack":"pnpm run build  && pnpm pack","ts-node":"ts-node"},"_id":"@anastasia-labs/direct-offer-offchain@0.2.0","_integrity":"sha512-HDtyD6y3PiIWTrZy8f6tjr4w0qifkWo6fYEOskXI2O+xE3gez7nc/zZFKysZY703FNUjhE9WFyKHzhdajT3+Ig==","_resolved":"/tmp/2d952a97700dbef82800ed4c33bc6127/anastasia-labs-direct-offer-offchain-0.2.0.tgz","_from":"file:anastasia-labs-direct-offer-offchain-0.2.0.tgz","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-HDtyD6y3PiIWTrZy8f6tjr4w0qifkWo6fYEOskXI2O+xE3gez7nc/zZFKysZY703FNUjhE9WFyKHzhdajT3+Ig==","shasum":"908b24a074172c1d8a692e6529478381295124b6","tarball":"https://registry.npmjs.org/@anastasia-labs/direct-offer-offchain/-/direct-offer-offchain-0.2.0.tgz","fileCount":6,"unpackedSize":36504,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD3VK2XW2YmDXecgbv5thYpENqtkAjrdhV5UEdO1GdKYAIhAKnLCrn0NjAEVgy8/KhxwZh7m6sExymN2XB5G8k0+DMB"}]},"_npmUser":{"name":"anastasia-labs","email":"info@anastasialabs.com"},"maintainers":[{"name":"anastasia-labs","email":"info@anastasialabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/direct-offer-offchain_0.2.0_1725038884327_0.39551068516972454"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-11T13:47:21.062Z","modified":"2024-08-30T17:28:04.831Z","0.1.0":"2024-01-11T13:47:21.312Z","0.2.0":"2024-08-30T17:28:04.640Z"},"license":"ISC","keywords":[],"description":"https://docs.github.com/en/packages/quickstart","maintainers":[{"name":"anastasia-labs","email":"info@anastasialabs.com"}],"readme":"# Table of Contents\n\n- [Direct Offer Offchain](#direct-offer-offchain)\n  - [Introduction](#introduction)\n  - [Documentation](#documentation)\n    - [What is P2P trading?](#what-is-peer-to-peer-p2p-trading)\n    - [How can this project facilitate P2P trading?](#how-can-this-project-facilitate-p2p-trading)\n  - [Usage Example](#usage-example)\n    - [Setup](#setup-lucid--offer-scripts)\n    - [Make Offer](#make-offer)\n    - [Fetch Offer](#fetch-offer)\n    - [Accept Offer](#accept-offer)\n  - [Local Build](#local-build)\n  - [Test Framework](#test-framework)\n  - [Running Tests](#running-tests)\n\n# Direct Offer Offchain\n\n## Introduction\n\nThe Direct Offer Offchain project provides a typescript based SDK to convenietly interact with Plutarch-based implementation of a smart contract enabling peer-to-peer trading, in a trustless manner, for the Cardano blockchain. Without the need for a trusted third party or a Decentralized Exchange (DEX), a user can put up any Cardano native asset(s) for sale in exchange for any user-specified native asset(s).\n\nThis project is funded by the Cardano Treasury in [Catalyst Fund 10](https://projectcatalyst.io/funds/10/f10-developer-ecosystem-the-evolution/plug-and-play-smart-contract-api-a-game-changing-platform-to-deploy-open-source-contracts-instantly)\n\n## Documentation\n\n### What is Peer-to-Peer (P2P) trading?\n\nP2P trading in the context of this project refers to the direct buying and selling of Cardano Native Tokens (both Fungible & Non-Fungible Tokens) among users, without a third party or an intermediary. This is unlike buying and selling digital assets using a Centralized Exchange (CEX), where you cannot transact directly with counterparties or a DEX where you trade against a fixed Liquidity Pool.\n\nTrading on a CEX requires you to give custody of your tokens to them, so they can execute the trades you enter based on their charts and market order aggregators. A CEX provides access to their order book and facilitates trades and takes fees in exchange.\n\nDepending on the type of order you use, effects such as slippage may mean you don’t get the exact price you want. P2P trading, on the other hand, gives you full control over pricing, settlement time, and whom you choose to sell to and buy from. What is even better you don't need to give custody of your assets to a centralized entity, they are locked in a contract from which you can reclaim them up until the point they are bought.\n\n### How can this project facilitate P2P trading?\n\nThis project fulfills the cornerstone requirement of a trusted Escrow, over seeing the trade in the form of a smart contract. It locks the seller's assets in the contract until a buyer provides the required ask price or the seller wishes to cancel the offer and claim the funds back.\n\n## Usage Example\n\n### Install package\n\n```sh\nnpm install @anastasia-labs/direct-offer-offchain\n```\n\nor\n\n```sh\npnpm install @anastasia-labs/direct-offer-offchain\n```\n\n### Setup Lucid & Offer Scripts\n\n```ts\n// You can get the compiled scripts here: https://github.com/Anastasia-Labs/direct-offer/tree/master/compiled\nimport spendingValidator from \"../directOfferSpending.json\" assert { type : \"json\" };\nimport stakingValidator from \"../directOfferStaking.json\" assert { type : \"json\" };\n\nexport const lucid = await Lucid.new(\n  new Maestro({\n    network : \"Preprod\",\n    apiKey: \"your maestro api key\",\n  }),\n  \"Preprod\"\n);\n\nlucid.selectWalletFromPrivateKey(\n  \"your secret key here e.g. ed25519_...\",\n);\n\nconst offerScripts = {\n  spending: spendingValidator.cborHex,\n  staking: stakingValidator.cborHex\n};\n```\n\n### Make Offer\n\n```ts\nimport {\n  MakeOfferConfig,\n  makeOffer\n} from \"@anastasia-labs/direct-offer-offchain\";\n\nconst makeOfferConfig: MakeOfferConfig = {\n  offer: {\n    [\"lovelace\"]: 10_000_000n\n  },\n  toBuy: {\n    [toUnit(\"e16c2dc8ae937e8d3790c7fd7168d7b994621ba14ca11415f39fed72\",\n    \"4d494e\")]: 10_000n,\n  },\n  scripts: offerScripts,\n};\n\nconst makeOfferUnSigned = await makeOffer(lucid, makeOfferConfig);\n\nif (makeOfferUnSigned.type == \"ok\") {\n  const makeOfferSigned = await makeOfferUnSigned.data.sign().complete();\n  const makeOfferHash = await makeOfferSigned.submit();\n  await lucid.awaitTx(makeOfferHash);\n  console.log(`Made offer: ${makeOfferHash}`)\n}\n```\n\n### Fetch Offer\n\n```ts\nimport {\n  FetchOfferConfig,\n  getOfferUTxOs\n} from \"@anastasia-labs/direct-offer-offchain\";\n\nconst offerConfig: FetchOfferConfig = {\n  scripts: offerScripts\n};\n\nconst offers = await getOfferUTxOs(lucid, offerConfig);\nconsole.log(\"Available Offers\", offers);\n```\n\n### Accept Offer\n\n```ts\nimport {\n  AcceptOfferConfig,\n  acceptOffer\n} from \"@anastasia-labs/direct-offer-offchain\";\n\nconst acceptOfferConfig: AcceptOfferConfig = {\n  offerOutRef: offers[0].outRef,\n  scripts: offerScripts\n};\n\nconst acceptOfferUnsigned = await acceptOffer(lucid, acceptOfferConfig);\n\nif (acceptOfferUnsigned.type == \"ok\"){\n  const acceptOfferSigned = await acceptOfferUnsigned.data\n  .sign()\n  .complete();\n  const acceptOfferSignedHash = await acceptOfferSigned.submit();\n  await lucid.awaitTx(acceptOfferSignedHash);\n  console.log(`Accepted offer: ${acceptOfferSignedHash}`)\n}\n```\n\n## Local Build\n\nIn the main directory\n\n```\npnpm run build\n```\n## Test framework\n\nhttps://github.com/vitest-dev/vitest\n\n\n## Running Tests\n\n```sh\npnpm test\n```\n\n![direct-offer-offchain](/assets/gifs/direct-offer-offchain.gif)","readmeFilename":"README.md"}