Skip to content

Commit

Permalink
add code demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
iskysun96 committed May 31, 2024
1 parent ea4bab6 commit 2b1f08c
Show file tree
Hide file tree
Showing 45 changed files with 3,841 additions and 27 deletions.
5 changes: 4 additions & 1 deletion orakle-nft-marketplace-app.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"path": "./",
"name": "ROOT"
},
{
"path": "./projects/code-demo"
},
{
"path": "./projects/orakle-nft-marketplace-app-contracts"
},
Expand Down Expand Up @@ -93,4 +96,4 @@
}
]
}
}
}
38 changes: 38 additions & 0 deletions projects/code-demo/.algokit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[algokit]
min_version = "v2.0.0"

[generate.smart_contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[project]
type = 'contract'
name = 'code-demo'
artifacts = 'smart_contracts/artifacts'

[project.deploy]
command = "npm run deploy:ci"
environment_secrets = [
"DEPLOYER_MNEMONIC",
]

[project.deploy.localnet]
environment_secrets = []

[project.run]
# Commands intented for use locally and in CI
build = { commands = [
'poetry run python -m smart_contracts build',
], description = 'Build all smart contracts in the project' }
lint = { commands = [
], description = 'Perform linting' }
audit-teal = { commands = [
# 🚨 IMPORTANT 🚨: For strict TEAL validation, remove --exclude statements. The default starter contract is not for production. Ensure thorough testing and adherence to best practices in smart contract development. This is not a replacement for a professional audit.
'algokit task analyze smart_contracts/artifacts --recursive --force --exclude rekey-to --exclude is-updatable --exclude missing-fee-check --exclude is-deletable --exclude can-close-asset --exclude can-close-account --exclude unprotected-deletable --exclude unprotected-updatable',
], description = 'Audit TEAL files' }

# Commands intented for CI only, prefixed with `ci-` by convention
ci-teal-diff = { commands = [
'git add -N ./smart_contracts/artifacts',
'git diff --exit-code --minimal ./smart_contracts/artifacts',
], description = 'Check TEAL files for differences' }
10 changes: 10 additions & 0 deletions projects/code-demo/.algokit/generators/create_contract/copier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_tasks:
- "echo '==== Successfully initialized new smart contract 🚀 ===='"

contract_name:
type: str
help: Name of your new contract.
placeholder: "my-new-contract"
default: "my-new-contract"

_templates_suffix: ".j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pyright: reportMissingModuleSource=false
from algopy import ARC4Contract, arc4


class {{ contract_name.split('_')|map('capitalize')|join }}(ARC4Contract):
@arc4.abimethod()
def hello(self, name: arc4.String) -> arc4.String:
return "Hello, " + name
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as algokit from '@algorandfoundation/algokit-utils'
import { NftMarketplaceClient } from '../artifacts/nft_marketplace/client'

// Below is a showcase of various deployment options you can use in TypeScript Client
export async function deploy() {
console.log('=== Deploying NftMarketplace ===')

const algod = algokit.getAlgoClient()
const indexer = algokit.getAlgoIndexerClient()
const deployer = await algokit.mnemonicAccountFromEnvironment({ name: 'DEPLOYER', fundWith: algokit.algos(3) }, algod)
await algokit.ensureFunded(
{
accountToFund: deployer,
minSpendingBalance: algokit.algos(2),
minFundingIncrement: algokit.algos(2),
},
algod,
)
const appClient = new NftMarketplaceClient(
{
resolveBy: 'creatorAndName',
findExistingUsing: indexer,
sender: deployer,
creatorAddress: deployer.addr,
},
algod,
)

const app = await appClient.deploy({
onSchemaBreak: 'append',
onUpdate: 'append',
})


// If app was just created fund the app account
if (['create', 'replace'].includes(app.operationPerformed)) {
algokit.transferAlgos(
{
amount: algokit.algos(1),
from: deployer,
to: app.appAddress,
},
algod,
)
}

const method = 'hello'
const response = await appClient.hello({ name: 'world' })
console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`)
}
9 changes: 9 additions & 0 deletions projects/code-demo/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 1.0.7
_src_path: gh:algorandfoundation/algokit-python-template
author_email: iskysun96@gmail.com
author_name: iskysun96
contract_name: nft_marketplace
deployment_language: typescript
preset_name: starter
project_name: code-demo
10 changes: 10 additions & 0 deletions projects/code-demo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root=true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true

[*.py]
indent_size = 4
7 changes: 7 additions & 0 deletions projects/code-demo/.env.localnet.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this file should contain environment variables specific to algokit localnet
ALGOD_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ALGOD_SERVER=http://localhost
ALGOD_PORT=4001
INDEXER_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
INDEXER_SERVER=http://localhost
INDEXER_PORT=8980
1 change: 1 addition & 0 deletions projects/code-demo/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this file should contain environment variables common to all environments/networks
3 changes: 3 additions & 0 deletions projects/code-demo/.env.testnet.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_SERVER=https://testnet-api.algonode.cloud
INDEXER_SERVER=https://testnet-idx.algonode.cloud
1 change: 1 addition & 0 deletions projects/code-demo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
180 changes: 180 additions & 0 deletions projects/code-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
coverage/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
.env.*
!.env.*.template
!.env.template
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Ruff (linter)
.ruff_cache/

# Cython debug symbols
cython_debug/

# PyCharm
.idea
!.idea/
.idea/*
!.idea/runConfigurations/

# macOS
.DS_Store

# Received approval test files
*.received.*

# NPM
node_modules

# AlgoKit
debug_traces/

.algokit/static-analysis/tealer/
1 change: 1 addition & 0 deletions projects/code-demo/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict = true
12 changes: 12 additions & 0 deletions projects/code-demo/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# don't ever format node_modules
node_modules
# don't lint format output (make sure it's set to your correct build folder name)
dist
build
# don't format nyc coverage output
coverage
# don't format generated types
**/generated/types.d.ts
**/generated/types.ts
# don't format ide files
.idea
10 changes: 10 additions & 0 deletions projects/code-demo/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
singleQuote: true,
jsxSingleQuote: false,
semi: false,
tabWidth: 2,
trailingComma: 'all',
printWidth: 120,
endOfLine: 'lf',
arrowParens: 'always',
}
Loading

0 comments on commit 2b1f08c

Please sign in to comment.