diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 8d8767c..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust/.devcontainer/base.Dockerfile - -# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye -ARG VARIANT -FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} - -# Install additional packages -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends protobuf-compiler libprotobuf-dev - -RUN rustup toolchain install nightly-2022-11-03 \ - && rustup default nightly-2022-11-03 && rustup component add clippy diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index def086a..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,54 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust -{ - "name": "Rust", - "build": { - "dockerfile": "Dockerfile", - "args": { - // Use the VARIANT arg to pick a Debian OS version: buster, bullseye - // Use bullseye when on local on arm64/Apple Silicon. - "VARIANT": "bullseye" - } - }, - "runArgs": [ - "--cap-add=SYS_PTRACE", - "--security-opt", - "seccomp=unconfined" - ], - // Configure tool-specific properties. - "customizations": { - // Configure properties specific to VS Code. - "vscode": { - // Set *default* container specific settings.json values on container create. - "settings": { - "lldb.executable": "/usr/bin/lldb", - // VS Code don't watch files under ./target - "files.watcherExclude": { - "**/target/**": true - }, - "rust-analyzer.checkOnSave.command": "clippy" - }, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "vadimcn.vscode-lldb", - "mutantdino.resourcemonitor", - "rust-lang.rust-analyzer", - "tamasfe.even-better-toml", - "serayuzgur.crates" - ] - } - }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "rustc --version", - // "postCreateCommand": ". scripts/startup.sh", - // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - // "remoteUser": "vscode", - "features": { - "node": "18" - }, - "remoteEnv": { - "PATH": "${containerEnv:PATH}:/workspace/dojo/target/release" - } -} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a1c4509..8021341 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,4 +12,4 @@ jobs: - uses: software-mansion/setup-scarb@v1 with: scarb-version: "0.7.0" - - run: scarb test + - run: cd contracts && scarb test diff --git a/.gitignore b/.gitignore index d06cbdc..a5bcd10 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ target .idea/ .spr.yml node_modules -.DS_Store \ No newline at end of file +.DS_Store + +.sdk/node_modules \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index f4d0797..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "cairo"] - path = cairo - url = https://github.com/starkware-libs/cairo diff --git a/README.md b/README.md index 949ca25..cc57979 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,3 @@ -# InstaSwap +## InstaSwap -What is InstaSwap? - -InstaSwap is a decentralized token swap protocol for ERC-1155 tokens on Starknet. In other words, InstaSwap is Uniswap for ERC-1155 tokens.Users can trade up to `n` amount of ERC1155 tokens in one transaction with a ERC20 token! - -*Greatly inspired by Uniswap and Niftyswap,thanks for the work done by the Uniswap team and Niftyswap team* - - -# Contribute - -Contribution are welcome! Please check the good first issues for a list of issues that are good for new contributors. - -# Development - -## Installing dependencies - -### Step 1: Install Cairo 1.0 (guide by [Abdel](https://github.com/abdelhamidbakhta)) - -If you are on an x86 Linux system and able to use the release binary, -you can download Cairo here https://github.com/starkware-libs/cairo/releases. - -For everyone, else, we recommend compiling Cairo from source like so: - -```bash -# Install stable Rust -$ rustup override set stable && rustup update - -# Clone the Cairo compiler in $HOME/Bin -$ cd ~/Bin && git clone git@github.com:starkware-libs/cairo.git && cd cairo - -# Generate release binaries -$ cargo build --all --release -``` - -**NOTE: Keeping Cairo up to date** - -Now that your Cairo compiler is in a cloned repository, all you will need to do -is pull the latest changes and rebuild as follows: - -```bash -$ cd ~/Bin/cairo && git fetch && git pull && cargo build --all --release -``` - -### Step 2: Add Cairo 1.0 executables to your path - -```bash -export PATH="$HOME/Bin/cairo/target/release:$PATH" -``` - -**NOTE: If installing from a Linux binary, adapt the destination path accordingly.** - -This will make available several binaries. The one we use is called `cairo-test`. - -### Step 3: Install the Cairo package manager Scarb - -Follow the installation guide in [Scarb's Repository](https://github.com/software-mansion/scarb). - -### Step 4: Setup Language Server - -#### VS Code Extension - -- Disable previous Cairo 0.x extension -- Install the Cairo 1 extension for proper syntax highlighting and code navigation. -Just follow the steps indicated [here](https://github.com/starkware-libs/cairo/blob/main/vscode-cairo/README.md). - -#### Cairo Language Server - -From [Step 1](#step-1-install-cairo-10-guide-by-abdel), the `cairo-language-server` binary should be built and executing this command will copy its path into your clipboard. - -```bash -$ which cairo-language-server | pbcopy -``` - -Update the `languageServerPath` of the Cairo 1.0 extension by pasting the path. - -### Build - -Build the contracts. - -```bash -$ make build -``` - -### Test - -Run the tests in `src/test`: - -```bash -$ make test -``` - -### Format - -Format the Cairo source code (using Scarb): - -```bash -$ make fmt -``` - -### Sierra (advanced) - -View the compiled Sierra output of your Cairo code: - -```bash -$ make sierra -``` \ No newline at end of file +## \ No newline at end of file diff --git a/LICENSE b/contracts/LICENSE similarity index 96% rename from LICENSE rename to contracts/LICENSE index 6db4652..aaebdfc 100644 --- a/LICENSE +++ b/contracts/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Auditless Limited +Copyright (c) 2023 Bibliotheca Limited Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Scarb.toml b/contracts/Scarb.toml similarity index 100% rename from Scarb.toml rename to contracts/Scarb.toml diff --git a/cairo_project.toml b/contracts/cairo_project.toml similarity index 100% rename from cairo_project.toml rename to contracts/cairo_project.toml diff --git a/deploy/starknet-devnet.md b/contracts/deploy/starknet-devnet.md similarity index 100% rename from deploy/starknet-devnet.md rename to contracts/deploy/starknet-devnet.md diff --git a/src/erc1155.cairo b/contracts/src/erc1155.cairo similarity index 100% rename from src/erc1155.cairo rename to contracts/src/erc1155.cairo diff --git a/src/lib.cairo b/contracts/src/lib.cairo similarity index 100% rename from src/lib.cairo rename to contracts/src/lib.cairo diff --git a/src/tests.cairo b/contracts/src/tests.cairo similarity index 100% rename from src/tests.cairo rename to contracts/src/tests.cairo diff --git a/src/werc20_from_erc1155.cairo b/contracts/src/werc20_from_erc1155.cairo similarity index 100% rename from src/werc20_from_erc1155.cairo rename to contracts/src/werc20_from_erc1155.cairo diff --git a/src/wrap_factory.cairo b/contracts/src/wrap_factory.cairo similarity index 100% rename from src/wrap_factory.cairo rename to contracts/src/wrap_factory.cairo diff --git a/examples/vanilla/.gitignore b/examples/vanilla/.gitignore new file mode 100644 index 0000000..3d75225 --- /dev/null +++ b/examples/vanilla/.gitignore @@ -0,0 +1,172 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +\*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +\*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +\*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +\*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp +.cache + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.\* + +# IntelliJ based IDEs +.idea diff --git a/examples/vanilla/README.md b/examples/vanilla/README.md new file mode 100644 index 0000000..dade42f --- /dev/null +++ b/examples/vanilla/README.md @@ -0,0 +1,15 @@ +# vanilla + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.1. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/examples/vanilla/bun.lockb b/examples/vanilla/bun.lockb new file mode 100755 index 0000000..02c8dbc Binary files /dev/null and b/examples/vanilla/bun.lockb differ diff --git a/examples/vanilla/index.ts b/examples/vanilla/index.ts new file mode 100644 index 0000000..6aba5fd --- /dev/null +++ b/examples/vanilla/index.ts @@ -0,0 +1 @@ +import { Wrap } from '@bibliothecadao/instaswap-core' \ No newline at end of file diff --git a/examples/vanilla/package.json b/examples/vanilla/package.json new file mode 100644 index 0000000..8137fed --- /dev/null +++ b/examples/vanilla/package.json @@ -0,0 +1,14 @@ +{ + "name": "vanilla", + "module": "index.ts", + "type": "module", + "devDependencies": { + "bun-types": "latest" + }, + "dependencies": { + "@bibliothecadao/instaswap-core": "link:instaswap/packages/instaswap-core" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} \ No newline at end of file diff --git a/examples/vanilla/tsconfig.json b/examples/vanilla/tsconfig.json new file mode 100644 index 0000000..1449bc3 --- /dev/null +++ b/examples/vanilla/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "allowImportingTsExtensions": true, + "noEmit": true, + "composite": true, + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "jsx": "preserve", + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "types": [ + "bun-types" // add Bun global + ] + } +} diff --git a/sdk/bun.lockb b/sdk/bun.lockb new file mode 100755 index 0000000..5acccd8 Binary files /dev/null and b/sdk/bun.lockb differ diff --git a/sdk/package.json b/sdk/package.json new file mode 100644 index 0000000..fc1f5b5 --- /dev/null +++ b/sdk/package.json @@ -0,0 +1,7 @@ +{ + "name": "instaswap", + "version": "0.1.0", + "workspaces": [ + "packages/instaswap-core" + ] +} \ No newline at end of file diff --git a/sdk/packages/instaswap-core/.gitignore b/sdk/packages/instaswap-core/.gitignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/sdk/packages/instaswap-core/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/sdk/packages/instaswap-core/.npmignore b/sdk/packages/instaswap-core/.npmignore new file mode 100644 index 0000000..e30ed30 --- /dev/null +++ b/sdk/packages/instaswap-core/.npmignore @@ -0,0 +1,6 @@ +* + +!dist/** +!package.json +!readme.md +!changelog.md \ No newline at end of file diff --git a/sdk/packages/instaswap-core/bun.lockb b/sdk/packages/instaswap-core/bun.lockb new file mode 100755 index 0000000..32556d3 Binary files /dev/null and b/sdk/packages/instaswap-core/bun.lockb differ diff --git a/sdk/packages/instaswap-core/changelog.md b/sdk/packages/instaswap-core/changelog.md new file mode 100644 index 0000000..e69de29 diff --git a/sdk/packages/instaswap-core/global.d.ts b/sdk/packages/instaswap-core/global.d.ts new file mode 100644 index 0000000..a0f27c3 --- /dev/null +++ b/sdk/packages/instaswap-core/global.d.ts @@ -0,0 +1 @@ +import '@types/jest'; \ No newline at end of file diff --git a/sdk/packages/instaswap-core/jest.config.js b/sdk/packages/instaswap-core/jest.config.js new file mode 100644 index 0000000..05ca416 --- /dev/null +++ b/sdk/packages/instaswap-core/jest.config.js @@ -0,0 +1,5 @@ +// jest.config.js +module.exports = { + preset: "ts-jest", + testEnvironment: "node", + }; \ No newline at end of file diff --git a/sdk/packages/instaswap-core/package.json b/sdk/packages/instaswap-core/package.json new file mode 100644 index 0000000..b8a5707 --- /dev/null +++ b/sdk/packages/instaswap-core/package.json @@ -0,0 +1,26 @@ +{ + "name": "@bibliothecadao/instaswap-core", + "version": "0.0.1", + "description": "Instaswap core", + "scripts": { + "build": "tsc", + "test": "jest" + }, + "author": "Loaf", + "license": "MIT", + "main": "dist/index.js", + "devDependencies": { + "@types/elliptic": "^6.4.14", + "@types/jest": "^29.5.0", + "@types/mocha": "^10.0.1", + "bun-types": "^1.0.1", + "fetch-mock": "^9.11.0", + "jest": "^29.5.0", + "starknet": "^5.19.5", + "ts-jest": "^29.1.0", + "typescript": "^5.0.3" + }, + "bin": { + "create-components": "./dist/bin/generateComponents.cjs" + } +} \ No newline at end of file diff --git a/sdk/packages/instaswap-core/readme.md b/sdk/packages/instaswap-core/readme.md new file mode 100644 index 0000000..217ed3a --- /dev/null +++ b/sdk/packages/instaswap-core/readme.md @@ -0,0 +1 @@ +## Instaswap Core \ No newline at end of file diff --git a/sdk/packages/instaswap-core/src/abi/erc1155-abi.json b/sdk/packages/instaswap-core/src/abi/erc1155-abi.json new file mode 100644 index 0000000..f472490 --- /dev/null +++ b/sdk/packages/instaswap-core/src/abi/erc1155-abi.json @@ -0,0 +1,587 @@ +[ + { + "name": "IERC1155Impl", + "type": "impl", + "interface_name": "rules_erc1155::erc1155::interface::IERC1155" + }, + { + "name": "core::integer::u256", + "type": "struct", + "members": [ + { + "name": "low", + "type": "core::integer::u128" + }, + { + "name": "high", + "type": "core::integer::u128" + } + ] + }, + { + "name": "core::array::Span::", + "type": "struct", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "name": "core::array::Span::", + "type": "struct", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "name": "core::bool", + "type": "enum", + "variants": [ + { + "name": "False", + "type": "()" + }, + { + "name": "True", + "type": "()" + } + ] + }, + { + "name": "core::array::Span::", + "type": "struct", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "name": "rules_erc1155::erc1155::interface::IERC1155", + "type": "interface", + "items": [ + { + "name": "balance_of", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "id", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "balance_of_batch", + "type": "function", + "inputs": [ + { + "name": "accounts", + "type": "core::array::Span::" + }, + { + "name": "ids", + "type": "core::array::Span::" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "name": "is_approved_for_all", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "name": "set_approval_for_all", + "type": "function", + "inputs": [ + { + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "approved", + "type": "core::bool" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "safe_transfer_from", + "type": "function", + "inputs": [ + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "id", + "type": "core::integer::u256" + }, + { + "name": "amount", + "type": "core::integer::u256" + }, + { + "name": "data", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "safe_batch_transfer_from", + "type": "function", + "inputs": [ + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "ids", + "type": "core::array::Span::" + }, + { + "name": "amounts", + "type": "core::array::Span::" + }, + { + "name": "data", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "name": "IERC1155CamelOnlyImpl", + "type": "impl", + "interface_name": "rules_erc1155::erc1155::interface::IERC1155CamelOnly" + }, + { + "name": "rules_erc1155::erc1155::interface::IERC1155CamelOnly", + "type": "interface", + "items": [ + { + "name": "balanceOf", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "id", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "balanceOfBatch", + "type": "function", + "inputs": [ + { + "name": "accounts", + "type": "core::array::Span::" + }, + { + "name": "ids", + "type": "core::array::Span::" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "name": "isApprovedForAll", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "name": "setApprovalForAll", + "type": "function", + "inputs": [ + { + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "approved", + "type": "core::bool" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "safeTransferFrom", + "type": "function", + "inputs": [ + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "id", + "type": "core::integer::u256" + }, + { + "name": "amount", + "type": "core::integer::u256" + }, + { + "name": "data", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "safeBatchTransferFrom", + "type": "function", + "inputs": [ + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "ids", + "type": "core::array::Span::" + }, + { + "name": "amounts", + "type": "core::array::Span::" + }, + { + "name": "data", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "name": "IERC1155MetadataImpl", + "type": "impl", + "interface_name": "rules_erc1155::erc1155::interface::IERC1155Metadata" + }, + { + "name": "rules_erc1155::erc1155::interface::IERC1155Metadata", + "type": "interface", + "items": [ + { + "name": "uri", + "type": "function", + "inputs": [ + { + "name": "token_id", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + } + ] + }, + { + "name": "ISRC5Impl", + "type": "impl", + "interface_name": "rules_utils::introspection::interface::ISRC5" + }, + { + "name": "rules_utils::introspection::interface::ISRC5", + "type": "interface", + "items": [ + { + "name": "supports_interface", + "type": "function", + "inputs": [ + { + "name": "interface_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + } + ] + }, + { + "name": "ISRC5CamelImpl", + "type": "impl", + "interface_name": "rules_utils::introspection::interface::ISRC5Camel" + }, + { + "name": "rules_utils::introspection::interface::ISRC5Camel", + "type": "interface", + "items": [ + { + "name": "supportsInterface", + "type": "function", + "inputs": [ + { + "name": "interfaceId", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + } + ] + }, + { + "name": "constructor", + "type": "constructor", + "inputs": [ + { + "name": "uri_", + "type": "core::array::Span::" + } + ] + }, + { + "name": "mint", + "type": "function", + "inputs": [ + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "id", + "type": "core::integer::u256" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "kind": "struct", + "name": "instaswap::erc1155::erc1155::ERC1155::TransferSingle", + "type": "event", + "members": [ + { + "kind": "data", + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "id", + "type": "core::integer::u256" + }, + { + "kind": "data", + "name": "value", + "type": "core::integer::u256" + } + ] + }, + { + "kind": "struct", + "name": "instaswap::erc1155::erc1155::ERC1155::TransferBatch", + "type": "event", + "members": [ + { + "kind": "data", + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "from", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "to", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "ids", + "type": "core::array::Span::" + }, + { + "kind": "data", + "name": "values", + "type": "core::array::Span::" + } + ] + }, + { + "kind": "struct", + "name": "instaswap::erc1155::erc1155::ERC1155::ApprovalForAll", + "type": "event", + "members": [ + { + "kind": "data", + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "operator", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "approved", + "type": "core::bool" + } + ] + }, + { + "kind": "struct", + "name": "instaswap::erc1155::erc1155::ERC1155::URI", + "type": "event", + "members": [ + { + "kind": "data", + "name": "value", + "type": "core::array::Span::" + }, + { + "kind": "data", + "name": "id", + "type": "core::integer::u256" + } + ] + }, + { + "kind": "enum", + "name": "instaswap::erc1155::erc1155::ERC1155::Event", + "type": "event", + "variants": [ + { + "kind": "nested", + "name": "TransferSingle", + "type": "instaswap::erc1155::erc1155::ERC1155::TransferSingle" + }, + { + "kind": "nested", + "name": "TransferBatch", + "type": "instaswap::erc1155::erc1155::ERC1155::TransferBatch" + }, + { + "kind": "nested", + "name": "ApprovalForAll", + "type": "instaswap::erc1155::erc1155::ERC1155::ApprovalForAll" + }, + { + "kind": "nested", + "name": "URI", + "type": "instaswap::erc1155::erc1155::ERC1155::URI" + } + ] + } +] diff --git a/sdk/packages/instaswap-core/src/abi/werc20-abi.json b/sdk/packages/instaswap-core/src/abi/werc20-abi.json new file mode 100644 index 0000000..b7e710e --- /dev/null +++ b/sdk/packages/instaswap-core/src/abi/werc20-abi.json @@ -0,0 +1,368 @@ +[ + { + "name": "core::integer::u256", + "type": "struct", + "members": [ + { + "name": "low", + "type": "core::integer::u128" + }, + { + "name": "high", + "type": "core::integer::u128" + } + ] + }, + { + "name": "deposit", + "type": "function", + "inputs": [ + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "withdraw", + "type": "function", + "inputs": [ + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "ERC20Impl", + "type": "impl", + "interface_name": "openzeppelin::token::erc20::interface::IERC20" + }, + { + "name": "core::bool", + "type": "enum", + "variants": [ + { + "name": "False", + "type": "()" + }, + { + "name": "True", + "type": "()" + } + ] + }, + { + "name": "openzeppelin::token::erc20::interface::IERC20", + "type": "interface", + "items": [ + { + "name": "name", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "name": "symbol", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "name": "decimals", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "total_supply", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "balance_of", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "allowance", + "type": "function", + "inputs": [ + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "transfer", + "type": "function", + "inputs": [ + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "transfer_from", + "type": "function", + "inputs": [ + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "approve", + "type": "function", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ontractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + } + ] + }, + { + "name": "totalSupply", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "balanceOf", + "type": "function", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "name": "transferFrom", + "type": "function", + "inputs": [ + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "constructor", + "type": "constructor", + "inputs": [ + { + "name": "erc1155_address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "token_id", + "type": "core::integer::u256" + }, + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "symbol", + "type": "core::felt252" + } + ] + }, + { + "name": "increase_allowance", + "type": "function", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "added_value", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "increaseAllowance", + "type": "function", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "addedValue", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "decrease_allowance", + "type": "function", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "subtracted_value", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "name": "decreaseAllowance", + "type": "function", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "subtractedValue", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "kind": "enum", + "name": "instaswap::werc20_from_erc1155::WERC20FromERC1155::Event", + "type": "event", + "variants": [] + } +] diff --git a/sdk/packages/instaswap-core/src/index.ts b/sdk/packages/instaswap-core/src/index.ts new file mode 100644 index 0000000..deeec51 --- /dev/null +++ b/sdk/packages/instaswap-core/src/index.ts @@ -0,0 +1 @@ +export * from './wrap'; diff --git a/sdk/packages/instaswap-core/src/wrap.ts b/sdk/packages/instaswap-core/src/wrap.ts new file mode 100644 index 0000000..cac4f81 --- /dev/null +++ b/sdk/packages/instaswap-core/src/wrap.ts @@ -0,0 +1,22 @@ +import { Contract } from "starknet"; + +import ERC1155 from "./abi/erc1155-abi.json"; +import WERC20 from "./abi/werc20-abi.json"; + +export abstract class Wrap { + public static ERC1155Contract: Contract; + public static WERC20Contract: Contract; + + constructor(ERC1155Address: string, WERC20Address: string) { + Wrap.ERC1155Contract = new Contract(ERC1155, ERC1155Address); + Wrap.WERC20Contract = new Contract(WERC20, WERC20Address); + } + + public deposit = async (amount: bigint) => { + // TODO: implement + } + + public withdraw = async (amount: bigint) => { + // + } +} \ No newline at end of file diff --git a/sdk/packages/instaswap-core/tsconfig.json b/sdk/packages/instaswap-core/tsconfig.json new file mode 100644 index 0000000..4545129 --- /dev/null +++ b/sdk/packages/instaswap-core/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "ESNext", + "declaration": true, + "outDir": "./dist", + "sourceMap": true, + "noImplicitAny": true, + "noUnusedLocals": true, + "moduleResolution": "bundler", + // "noUnusedParameters": true, + // "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "strictNullChecks": true, + "types": [ + "jest", + "bun-types", + ], + "esModuleInterop": true + }, + "include": [ + "src/**/*.ts" + ], + "skipLibCheck": true, + "exclude": [ + "node_modules", + "dist", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/sdk/readme.md b/sdk/readme.md new file mode 100644 index 0000000..70b89a4 --- /dev/null +++ b/sdk/readme.md @@ -0,0 +1,19 @@ +## SDK + +This is the SDK to interact with the InstaSwap protocol. + +It is a Vanilla JS implementation. + +### To Develop + +Install bun.sh + +Install dependencies: +``` +bun install +``` + +Build watch: +``` +bun run build --watch +``` \ No newline at end of file