Project initialised with AlgoKit CLI using template: https://github.com/algorandfoundation/algokit-fullstack-template.git
This commit is contained in:
56
projects/TokenizeRWATemplate-contracts/.algokit.toml
Normal file
56
projects/TokenizeRWATemplate-contracts/.algokit.toml
Normal file
@ -0,0 +1,56 @@
|
||||
[algokit]
|
||||
min_version = "v2.6.0"
|
||||
|
||||
[generate.smart-contract]
|
||||
description = "Generate a new smart contract for existing project"
|
||||
path = ".algokit/generators/create_contract"
|
||||
|
||||
[generate.env-file]
|
||||
description = "Generate a new generic or Algorand network specific .env file"
|
||||
path = ".algokit/generators/create_env_file"
|
||||
|
||||
[project]
|
||||
type = 'contract'
|
||||
name = 'TokenizeRWATemplate-contracts'
|
||||
artifacts = 'smart_contracts/artifacts'
|
||||
|
||||
[project.deploy]
|
||||
command = "npm run deploy:ci"
|
||||
|
||||
[project.deploy.testnet]
|
||||
environment_secrets = [
|
||||
"DEPLOYER_MNEMONIC",
|
||||
"DISPENSER_MNEMONIC",
|
||||
]
|
||||
|
||||
[project.deploy.mainnet]
|
||||
environment_secrets = [
|
||||
"DEPLOYER_MNEMONIC",
|
||||
"DISPENSER_MNEMONIC",
|
||||
]
|
||||
|
||||
[project.run]
|
||||
# Commands intended for use locally and in CI
|
||||
build = { commands = [
|
||||
'npm run build',
|
||||
], description = 'Build all smart contracts in the project' }
|
||||
test = { commands = [
|
||||
'npm run test',
|
||||
], description = 'Run smart contract tests using vitest' }
|
||||
audit = { commands = [
|
||||
'npm run audit',
|
||||
], description = 'Audit with better-npm-audit' }
|
||||
lint = { commands = [
|
||||
'npm run lint',
|
||||
'npm run format',
|
||||
], 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' }
|
||||
@ -0,0 +1,9 @@
|
||||
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
|
||||
_commit: 0.3.7
|
||||
_src_path: gh:algorandfoundation/algokit-typescript-template
|
||||
author_email: sarajanedeveloper@gmail.com
|
||||
author_name: SaraJane
|
||||
contract_name: hello_world
|
||||
preset_name: production
|
||||
project_name: TokenizeRWATemplate-contracts
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
_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"
|
||||
|
||||
include_tests:
|
||||
type: bool
|
||||
help: Should we include testing files?
|
||||
default: 'yes'
|
||||
|
||||
_templates_suffix: ".j2"
|
||||
@ -0,0 +1,7 @@
|
||||
import { Contract } from '@algorandfoundation/algorand-typescript'
|
||||
|
||||
export class {{ contract_name.split('_')|map('capitalize')|join }} extends Contract {
|
||||
{% if preset_name != 'starter' %}public {% endif %}hello(name: string): string {
|
||||
return `Hello, ${name}`
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
||||
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
|
||||
|
||||
// Below is a showcase of various deployment options you can use in TypeScript Client
|
||||
export async function deploy() {
|
||||
console.log('=== Deploying {{ contract_name.split('_')|map('capitalize')|join }} ===')
|
||||
|
||||
const algorand = AlgorandClient.fromEnvironment()
|
||||
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
||||
|
||||
const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
|
||||
defaultSender: deployer.addr,
|
||||
})
|
||||
|
||||
const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })
|
||||
|
||||
// If app was just created fund the app account
|
||||
if (['create', 'replace'].includes(result.operationPerformed)) {
|
||||
await algorand.send.payment({
|
||||
amount: (1).algo(),
|
||||
sender: deployer.addr,
|
||||
receiver: appClient.appAddress,
|
||||
})
|
||||
}
|
||||
|
||||
const method = 'hello'
|
||||
const response = await appClient.send.hello({
|
||||
args: { name: 'world' },
|
||||
})
|
||||
console.log(
|
||||
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
import { Config } from '@algorandfoundation/algokit-utils'
|
||||
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
|
||||
import { Address } from 'algosdk'
|
||||
import { beforeAll, beforeEach, describe, expect, test } from 'vitest'
|
||||
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
|
||||
|
||||
describe('{{ contract_name.split('_')|map('capitalize')|join }} contract', () => {
|
||||
const localnet = algorandFixture()
|
||||
beforeAll(() => {
|
||||
Config.configure({
|
||||
debug: true,
|
||||
// traceAll: true,
|
||||
})
|
||||
})
|
||||
beforeEach(localnet.newScope)
|
||||
|
||||
const deploy = async (account: Address) => {
|
||||
const factory = localnet.algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
|
||||
defaultSender: account,
|
||||
})
|
||||
|
||||
const { appClient } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })
|
||||
return { client: appClient }
|
||||
}
|
||||
|
||||
test('says hello', async () => {
|
||||
const { testAccount } = localnet.context
|
||||
const { client } = await deploy(testAccount)
|
||||
|
||||
const result = await client.send.hello({ args: { name: 'World' } })
|
||||
|
||||
expect(result.return).toBe('Hello World')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { {{ contract_name.split('_')|map('capitalize')|join }} } from './contract.algo'
|
||||
|
||||
describe('{{ contract_name.split('_')|map('capitalize')|join }} contract', () => {
|
||||
const ctx = new TestExecutionContext()
|
||||
it('Logs the returned value when sayHello is called', () => {
|
||||
const contract = ctx.contract.create({{ contract_name.split('_')|map('capitalize')|join }})
|
||||
|
||||
const result = contract.hello('Sally')
|
||||
|
||||
expect(result).toBe('Hello Sally')
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,49 @@
|
||||
_tasks:
|
||||
- "echo '==== Successfully generated new .env file 🚀 ===='"
|
||||
|
||||
target_network:
|
||||
type: str
|
||||
help: Name of your target network.
|
||||
choices:
|
||||
- mainnet
|
||||
- testnet
|
||||
- localnet
|
||||
- custom
|
||||
default: "localnet"
|
||||
when: "{{ not use_generic_env }}"
|
||||
|
||||
custom_network_name:
|
||||
type: str
|
||||
help: Name of your custom Algorand network.
|
||||
placeholder: "custom"
|
||||
when: "{{ not use_generic_env and target_network == 'custom' }}"
|
||||
|
||||
is_localnet:
|
||||
type: bool
|
||||
help: Whether to deploy on localnet.
|
||||
placeholder: "true"
|
||||
default: "{{ target_network == 'localnet' and not use_generic_env }}"
|
||||
when: 'false'
|
||||
|
||||
is_testnet:
|
||||
type: bool
|
||||
help: Whether to deploy on testnet.
|
||||
placeholder: "true"
|
||||
default: "{{ target_network == 'testnet' and not use_generic_env }}"
|
||||
when: 'false'
|
||||
|
||||
is_mainnet:
|
||||
type: bool
|
||||
help: Whether to deploy on mainnet.
|
||||
placeholder: "true"
|
||||
default: "{{ target_network == 'mainnet' and not use_generic_env }}"
|
||||
when: 'false'
|
||||
|
||||
is_customnet:
|
||||
type: bool
|
||||
help: Whether to deploy on custom network.
|
||||
placeholder: "true"
|
||||
default: "{{ target_network == 'custom' and not use_generic_env }}"
|
||||
when: 'false'
|
||||
|
||||
_templates_suffix: ".j2"
|
||||
@ -0,0 +1,7 @@
|
||||
# this file contains algorand network settings for interacting with testnet via algonode
|
||||
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
|
||||
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
|
||||
ALGOD_PORT={YOUR_ALGOD_PORT}
|
||||
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
|
||||
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
|
||||
INDEXER_PORT={YOUR_INDEXER_PORT}
|
||||
@ -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
|
||||
@ -0,0 +1,3 @@
|
||||
# this file contains algorand network settings for interacting with testnet via algonode
|
||||
ALGOD_SERVER=https://mainnet-api.algonode.cloud
|
||||
INDEXER_SERVER=https://mainnet-idx.algonode.cloud
|
||||
@ -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
|
||||
7
projects/TokenizeRWATemplate-contracts/.editorconfig
Normal file
7
projects/TokenizeRWATemplate-contracts/.editorconfig
Normal file
@ -0,0 +1,7 @@
|
||||
root=true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
62
projects/TokenizeRWATemplate-contracts/.gitignore
vendored
Normal file
62
projects/TokenizeRWATemplate-contracts/.gitignore
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# Editor/OS directories and files
|
||||
.DS_Store
|
||||
*.suo
|
||||
|
||||
# IntelliJ family
|
||||
.idea
|
||||
!.idea/
|
||||
.idea/*
|
||||
!.idea/runConfigurations/
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# Compiled code
|
||||
dist/
|
||||
build/
|
||||
|
||||
# Coverage report
|
||||
coverage
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# Received approval test files
|
||||
*.received.*
|
||||
|
||||
# AlgoKit
|
||||
debug_traces/
|
||||
.algokit/static-analysis/ # Replace with .algokit/static-analysis/tealer/ to enable snapshot checks in CI
|
||||
.algokit/sources
|
||||
1
projects/TokenizeRWATemplate-contracts/.npmrc
Normal file
1
projects/TokenizeRWATemplate-contracts/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
engine-strict = true
|
||||
13
projects/TokenizeRWATemplate-contracts/.prettierignore
Normal file
13
projects/TokenizeRWATemplate-contracts/.prettierignore
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
||||
smart_contracts/artifacts
|
||||
10
projects/TokenizeRWATemplate-contracts/.prettierrc.js
Normal file
10
projects/TokenizeRWATemplate-contracts/.prettierrc.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
singleQuote: true,
|
||||
jsxSingleQuote: false,
|
||||
semi: false,
|
||||
tabWidth: 2,
|
||||
trailingComma: 'all',
|
||||
printWidth: 120,
|
||||
endOfLine: 'lf',
|
||||
arrowParens: 'always',
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
{
|
||||
"$schema": "https://aka.ms/codetour-schema",
|
||||
"title": "Getting Started with Your AlgoKit Project",
|
||||
"steps": [
|
||||
{
|
||||
"file": "README.md",
|
||||
"description": "Welcome to your brand new AlgoKit template-based project. In this tour, we will guide you through the main features and capabilities included in the template.",
|
||||
"line": 3
|
||||
},
|
||||
{
|
||||
"file": "README.md",
|
||||
"description": "Start by ensuring you have followed the setup of pre-requisites.",
|
||||
"line": 9
|
||||
},
|
||||
{
|
||||
"file": ".algokit.toml",
|
||||
"description": "This is the main configuration file used by algokit-cli to manage the project. The default template includes a starter 'Hello World' contract that is deployed via the `algokit-utils` package. To create a new smart contract, you can use the [`algokit generate`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) command and invoke a pre-bundled generator template by running `algokit generate smart-contract` (see how it is defined in the `.algokit.toml`, you can create your own generators if needed). This action will create a new folder in the `smart_contracts` directory, named after your project. Each folder contains a `contract.algo.ts` file, which is the entry point for your contract implementation, and `deployConfig.ts` file, that perform the deployment of the contract. Additionally you can define custom commands to run (similar to `npm` scripts), see definitions under `[project]` section in `.algokit.toml`.",
|
||||
"line": 1
|
||||
},
|
||||
{
|
||||
"file": "smart_contracts/hello_world/deploy-config.ts",
|
||||
"description": "The default deployment scripts invoke a sample method on the starter contract that demonstrates how to interact with your deployed Algorand on-chain applications using the [`AlgoKit Typed Clients`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients) feature. The invocation if deploy is aliased in `.algokit.toml` file, allowing simple deployments via `algokit project deploy` command.",
|
||||
"line": 32
|
||||
},
|
||||
{
|
||||
"file": "smart_contracts/hello_world/contact.spec.ts",
|
||||
"description": "The default tests provided demonstrate an example of setting up in-memory fast unit tests with the Algorand TypeScript testing library that mocks AVM functionality.",
|
||||
"line": 5
|
||||
},
|
||||
{
|
||||
"file": "smart_contracts/hello_world/contact.e2e.spec.ts",
|
||||
"description": "The default tests provided demonstrate an example of setting up an end-to-end test with fixtures, and testing smart contract calls against a LocalNet network via an AlgoKit typed client.",
|
||||
"line": 7
|
||||
},
|
||||
{
|
||||
"file": ".env.localnet.template",
|
||||
"description": "Environment files are a crucial mechanism that allows you to set up the [`algokit deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/deploy.md) feature to simplify deploying your contracts in CI/CD environments (please note we still recommend careful evaluation when it comes to deployment to MainNet). Clone the file and remove the `.template` suffix to apply the changes to deployment scripts and launch configurations. The network prefix `localnet|testnet|mainnet` is primarily optimized for `algokit deploy`. The order of loading the variables is `.env.{network}` < `.env`.",
|
||||
"line": 2
|
||||
},
|
||||
{
|
||||
"file": ".vscode/launch.json",
|
||||
"description": "Refer to the pre-bundled Visual Studio launch configurations, offering various options on how to execute the build and deployment of your smart contracts. Alternatively execute `algokit project run` to see list of available custom commands.",
|
||||
"line": 5
|
||||
},
|
||||
{
|
||||
"file": ".vscode/extensions.json",
|
||||
"description": "We highly recommend installing the recommended extensions to get the most out of this template starter project in your VSCode IDE.",
|
||||
"line": 3
|
||||
},
|
||||
{
|
||||
"file": "smart_contracts/index.ts",
|
||||
"description": "Uncomment the following line to enable artifacts required for the [AlgoKit AVM Debugger](https://github.com/algorandfoundation/algokit-avm-vscode-debugger) that run for every single call rather than just failures. This VSCode plugin is available on the [VSCode Extension Marketplace](https://marketplace.visualstudio.com/items?itemName=algorandfoundation.algokit-avm-vscode-debugger) for every call. A new folder will be automatically created in the `.algokit` directory with source maps of all TEAL contracts in this workspace, as well as traces that will appear in a folder at the root of the workspace. You can then use the traces as entry points to trigger the debug extension. Make sure to have the `.algokit.toml` file available at the root of the workspace.",
|
||||
"line": 13
|
||||
}
|
||||
]
|
||||
}
|
||||
10
projects/TokenizeRWATemplate-contracts/.vscode/extensions.json
vendored
Normal file
10
projects/TokenizeRWATemplate-contracts/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"vitest.explorer",
|
||||
"editorconfig.editorconfig",
|
||||
"vsls-contrib.codetour",
|
||||
"algorandfoundation.algokit-avm-vscode-debugger"
|
||||
]
|
||||
}
|
||||
58
projects/TokenizeRWATemplate-contracts/.vscode/launch.json
vendored
Normal file
58
projects/TokenizeRWATemplate-contracts/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Build & Deploy contracts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": ["run", "deploy"],
|
||||
"cwd": "${workspaceFolder}/smart_contracts",
|
||||
"console": "integratedTerminal",
|
||||
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
||||
"preLaunchTask": "Build contracts (+ LocalNet)",
|
||||
"env": {
|
||||
"ALGOD_TOKEN": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"ALGOD_SERVER": "http://localhost",
|
||||
"ALGOD_PORT": "4001",
|
||||
"INDEXER_TOKEN": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"INDEXER_SERVER": "http://localhost",
|
||||
"INDEXER_PORT": "8980"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Deploy contracts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": ["run", "deploy"],
|
||||
"cwd": "${workspaceFolder}/smart_contracts",
|
||||
"console": "integratedTerminal",
|
||||
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
||||
"env": {
|
||||
"ALGOD_TOKEN": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"ALGOD_SERVER": "http://localhost",
|
||||
"ALGOD_PORT": "4001",
|
||||
"INDEXER_TOKEN": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"INDEXER_SERVER": "http://localhost",
|
||||
"INDEXER_PORT": "8980"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Build contracts",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": ["run", "build"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
"skipFiles": ["<node_internals>/**", "node_modules/**"],
|
||||
},
|
||||
{
|
||||
"type": "avm",
|
||||
"request": "launch",
|
||||
"name": "Debug AVM executions",
|
||||
"simulateTraceFile": "${workspaceFolder}/${command:PickSimulateTraceFile}",
|
||||
"stopOnEntry": true
|
||||
}
|
||||
]
|
||||
}
|
||||
19
projects/TokenizeRWATemplate-contracts/.vscode/settings.json
vendored
Normal file
19
projects/TokenizeRWATemplate-contracts/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"algorandTypeScript.languageServer.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.organizeImports": "explicit"
|
||||
},
|
||||
"jest.enable": false,
|
||||
"files.associations": {
|
||||
".github/**/*.yml": "github-actions-workflow"
|
||||
},
|
||||
"eslint.enable": true,
|
||||
"eslint.validate": ["typescript"],
|
||||
"eslint.options": {
|
||||
"extensions": [".ts"]
|
||||
},
|
||||
"eslint.workingDirectories": ["./smart_contracts"]
|
||||
}
|
||||
69
projects/TokenizeRWATemplate-contracts/.vscode/tasks.json
vendored
Normal file
69
projects/TokenizeRWATemplate-contracts/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build contracts",
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"path": "${workspaceFolder}",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build contracts (+ LocalNet)",
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"path": "${workspaceFolder}",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"dependsOn": "Start AlgoKit LocalNet",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Start AlgoKit LocalNet",
|
||||
"command": "algokit",
|
||||
"args": ["localnet", "start"],
|
||||
"type": "shell",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Stop AlgoKit LocalNet",
|
||||
"command": "algokit",
|
||||
"args": ["localnet", "stop"],
|
||||
"type": "shell",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Reset AlgoKit LocalNet",
|
||||
"command": "algokit",
|
||||
"args": ["localnet", "reset"],
|
||||
"type": "shell",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Analyze TEAL contracts with AlgoKit Tealer integration",
|
||||
"command": "algokit",
|
||||
"args": ["task", "analyze", "${workspaceFolder}/.algokit", "--recursive", "--force"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
157
projects/TokenizeRWATemplate-contracts/README.md
Normal file
157
projects/TokenizeRWATemplate-contracts/README.md
Normal file
@ -0,0 +1,157 @@
|
||||
# TokenizeRWATemplate-contracts
|
||||
|
||||
This project has been generated using AlgoKit. See below for default getting started instructions.
|
||||
|
||||
# Setup
|
||||
|
||||
### Pre-requisites
|
||||
|
||||
- [Nodejs 22](https://nodejs.org/en/download) or later
|
||||
- [AlgoKit CLI 2.5](https://github.com/algorandfoundation/algokit-cli?tab=readme-ov-file#install) or later
|
||||
- [Docker](https://www.docker.com/) (only required for LocalNet)
|
||||
- [Puya Compiler 4.4.4](https://pypi.org/project/puyapy/) or later
|
||||
|
||||
> For interactive tour over the codebase, download [vsls-contrib.codetour](https://marketplace.visualstudio.com/items?itemName=vsls-contrib.codetour) extension for VS Code, then open the [`.codetour.json`](./.tours/getting-started-with-your-algokit-project.tour) file in code tour extension.
|
||||
|
||||
### Initial Setup
|
||||
|
||||
#### 1. Clone the Repository
|
||||
Start by cloning this repository to your local machine.
|
||||
|
||||
#### 2. Install Pre-requisites
|
||||
Ensure the following pre-requisites are installed and properly configured:
|
||||
|
||||
- **Docker**: Required for running a local Algorand network.
|
||||
- **AlgoKit CLI**: Essential for project setup and operations. Verify installation with `algokit --version`, expecting `2.6.0` or later.
|
||||
|
||||
#### 3. Bootstrap Your Local Environment
|
||||
Run the following commands within the project folder:
|
||||
|
||||
- **Setup Project**: Execute `algokit project bootstrap all` to install dependencies and setup npm dependencies.
|
||||
- **Configure environment**: Execute `algokit generate env-file -a target_network localnet` to create a `.env.localnet` file with default configuration for `localnet`.
|
||||
- **Start LocalNet**: Use `algokit localnet start` to initiate a local Algorand network.
|
||||
|
||||
### Development Workflow
|
||||
|
||||
#### Terminal
|
||||
Directly manage and interact with your project using AlgoKit commands:
|
||||
|
||||
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
|
||||
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
|
||||
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
|
||||
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
|
||||
|
||||
#### VS Code
|
||||
For a seamless experience with breakpoint debugging and other features:
|
||||
|
||||
1. **Open Project**: In VS Code, open the repository root.
|
||||
2. **Install Extensions**: Follow prompts to install recommended extensions.
|
||||
3. **Debugging**:
|
||||
- Use `F5` to start debugging.
|
||||
|
||||
#### JetBrains IDEs
|
||||
While primarily optimized for VS Code, JetBrains IDEs are supported:
|
||||
|
||||
1. **Open Project**: In your JetBrains IDE, open the repository root.
|
||||
2. **Automatic Setup**: The IDE should configure the Node.js environment.
|
||||
3. **Debugging**: Use `Shift+F10` or `Ctrl+R` to start debugging. Note: Windows users may encounter issues with pre-launch tasks due to a known bug. See [JetBrains forums](https://youtrack.jetbrains.com/issue/IDEA-277486/Shell-script-configuration-cannot-run-as-before-launch-task) for workarounds.
|
||||
|
||||
## AlgoKit Workspaces and Project Management
|
||||
This project supports both standalone and monorepo setups through AlgoKit workspaces. Leverage [`algokit project run`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/run.md) commands for efficient monorepo project orchestration and management across multiple projects within a workspace.
|
||||
|
||||
## AlgoKit Generators
|
||||
|
||||
This template provides a set of [algokit generators](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) that allow you to further modify the project instantiated from the template to fit your needs, as well as giving you a base to build your own extensions to invoke via the `algokit generate` command.
|
||||
|
||||
### Generate Smart Contract
|
||||
|
||||
By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:
|
||||
|
||||
1. From the root of the project (`../`) execute `algokit generate smart-contract`. This will create a new starter smart contract and deployment configuration file under `{your_contract_name}` subfolder in the `smart_contracts` directory.
|
||||
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy-config.ts` file.
|
||||
3. Technically, you need to reference your contract deployment logic in the `index.ts` file. However, by default, `index.ts` will auto import all TypeScript deployment files under `smart_contracts` directory. If you want to manually import specific contracts, modify the default code provided by the template in `index.ts` file.
|
||||
|
||||
> Please note, above is just a suggested convention tailored for the base configuration and structure of this template. The default code supplied by the template in the `index.ts` file is tailored for the suggested convention. You are free to modify the structure and naming conventions as you see fit.
|
||||
|
||||
### Generate '.env' files
|
||||
|
||||
By default the template instance does not contain any env files to deploy to different networks. Using [`algokit project deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/deploy.md) against `localnet` | `testnet` | `mainnet` will use default values for `algod` and `indexer` unless overwritten via `.env` or `.env.{target_network}`.
|
||||
|
||||
To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`
|
||||
|
||||
### Debugging Smart Contracts
|
||||
|
||||
This project is optimized to work with AlgoKit AVM Debugger extension. To activate it:
|
||||
|
||||
Refer to the commented header in the `index.ts` file in the `smart_contracts` folder.Since you have opted in to include VSCode launch configurations in your project, you can also use the `Debug TEAL via AlgoKit AVM Debugger` launch configuration to interactively select an available trace file and launch the debug session for your smart contract.
|
||||
|
||||
|
||||
For information on using and setting up the `AlgoKit AVM Debugger` VSCode extension refer [here](https://github.com/algorandfoundation/algokit-avm-vscode-debugger). To install the extension from the VSCode Marketplace, use the following link: [AlgoKit AVM Debugger extension](https://marketplace.visualstudio.com/items?itemName=algorandfoundation.algokit-avm-vscode-debugger).### Continuous Integration / Continuous Deployment (CI/CD)
|
||||
|
||||
This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [.github/workflows](`../../.github/workflows`) folder.
|
||||
|
||||
> Please note, if you instantiated the project with --workspace flag in `algokit init` it will automatically attempt to move the contents of the `.github` folder to the root of the workspace.
|
||||
|
||||
### AlgoKit Workspaces
|
||||
|
||||
To define custom `algokit project run` commands refer to [documentation](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/run.md). This allows orchestration of commands spanning across multiple projects within an algokit workspace based project (monorepo).
|
||||
|
||||
#### Setting up GitHub for CI/CD workflow and TestNet deployment
|
||||
|
||||
1. Every time you have a change to your smart contract, and when you first initialize the project you need to [build the contract](#initial-setup) and then commit the `smart_contracts/artifacts` folder so the [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md) tests pass
|
||||
2. Decide what values you want to use for the `allowUpdate` and `allowDelete` parameters specified in [`deploy-config.ts`](./smart_contracts/hello_world/deploy-config.ts).
|
||||
When deploying to LocalNet these values are both set to `true` for convenience. But for non-LocalNet networks
|
||||
they are more conservative and use `false`
|
||||
These default values will allow the smart contract to be deployed initially, but will not allow the app to be updated or deleted if is changed and the build will instead fail.
|
||||
To help you decide it may be helpful to read the [AlgoKit Utils app deployment documentation](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/docs/capabilities/app-deploy.md) or the [AlgoKit smart contract deployment architecture](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md#upgradeable-and-deletable-contracts).
|
||||
3. Create a [Github Environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#creating-an-environment) named `Test`.
|
||||
Note: If you have a private repository and don't have GitHub Enterprise then Environments won't work and you'll need to convert the GitHub Action to use a different approach. Ignore this step if you picked `Starter` preset.
|
||||
4. Create or obtain a mnemonic for an Algorand account for use on TestNet to deploy apps, referred to as the `DEPLOYER` account.
|
||||
5. Store the mnemonic as a [secret](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#environment-secrets) `DEPLOYER_MNEMONIC`
|
||||
in the Test environment created in step 3.
|
||||
6. The account used to deploy the smart contract will require enough funds to create the app, and also fund it. There are two approaches available here:
|
||||
* Either, ensure the account is funded outside of CI/CD.
|
||||
In Testnet, funds can be obtained by using the [Algorand TestNet dispenser](https://bank.testnet.algorand.network/) and we recommend provisioning 50 ALGOs.
|
||||
* Or, fund the account as part of the CI/CD process by using a `DISPENSER_MNEMONIC` GitHub Environment secret to point to a separate `DISPENSER` account that you maintain ALGOs in (similarly, you need to provision ALGOs into this account using the [TestNet dispenser](https://bank.testnet.algorand.network/)).
|
||||
|
||||
#### Continuous Integration
|
||||
|
||||
For pull requests and pushes to `main` branch against this repository the following checks are automatically performed by GitHub Actions:
|
||||
- NPM dependencies are audited using [better-npm-audit](https://github.com/jeemok/better-npm-audit#readme)
|
||||
- Code formatting is performed using [Prettier](https://prettier.io/)
|
||||
- Linting is checked using [ESLint](https://eslint.org/)
|
||||
- The base framework for testing is [vitest](https://vitest.dev/), and the project includes two separate kinds of tests:
|
||||
- - `Algorand TypeScript` smart contract unit tests, that are run using [`algorand-typescript-testing`](https://github.com/algorandfoundation/algorand-typescript-testing), which are executed in a Node.js intepreter emulating major AVM behaviour
|
||||
- - End-to-end (e2e) `AppClient` tests that are run against `algokit localnet` and test the behaviour in a real network environment
|
||||
- Smart contract artifacts are built
|
||||
- Smart contract artifacts are checked for [output stability](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/articles/output_stability.md).
|
||||
- Smart contract is deployed to a AlgoKit LocalNet instance
|
||||
|
||||
> NOTE: By default smart contract artifacts are compiled with `--debug-level` set to 0, to change this, modify the compiler invocation under the `build` script in `package.json`
|
||||
|
||||
#### Continuous Deployment
|
||||
|
||||
For pushes to `main` branch, after the above checks pass, the following deployment actions are performed:
|
||||
- The smart contract(s) are deployed to TestNet using [AlgoNode](https://algonode.io).
|
||||
|
||||
> Please note deployment is also performed via `algokit deploy` command which can be invoked both via CI as seen on this project, or locally. For more information on how to use `algokit deploy` please see [AlgoKit documentation](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/deploy.md).
|
||||
|
||||
# Tools
|
||||
|
||||
This project makes use of Algorand TypeScript to build Algorand smart contracts. The following tools are in use:
|
||||
|
||||
- [Algorand](https://www.algorand.com/) - Layer 1 Blockchain; [Developer portal](https://dev.algorand.co/), [Why Algorand?](https://dev.algorand.co/getting-started/why-algorand/)
|
||||
- [AlgoKit](https://github.com/algorandfoundation/algokit-cli) - One-stop shop tool for developers building on the Algorand network; [docs](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/algokit.md), [intro tutorial](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/tutorials/intro.md)
|
||||
- [Algorand TypeScript](https://github.com/algorandfoundation/puya-ts/) - A semantically and syntactically compatible, typed TypeScript language that works with standard TypeScript tooling and allows you to express smart contracts (apps) and smart signatures (logic signatures) for deployment on the Algorand Virtual Machine (AVM); [docs](https://github.com/algorandfoundation/puya-ts/), [examples](https://github.com/algorandfoundation/puya-ts/tree/main/examples)
|
||||
- [AlgoKit Utils](https://github.com/algorandfoundation/algokit-utils-ts) - A set of core Algorand utilities that make it easier to build solutions on Algorand.
|
||||
- [NPM](https://www.npmjs.com/): TypeScript packaging and dependency management.
|
||||
- [TypeScript](https://www.typescriptlang.org/): Strongly typed programming language that builds on JavaScript
|
||||
- [ts-node-dev](https://github.com/wclr/ts-node-dev): TypeScript development execution environment- [Prettier](https://prettier.io/): A code formatter.- [ESLint](https://eslint.org/): A JavaScript / TypeScript linter.
|
||||
- [vitest](https://vitest.dev/): Automated testing.
|
||||
- [better-npm-audit](https://github.com/jeemok/better-npm-audit#readme): Tool for scanning JavaScript / TypeScript environments for packages with known vulnerabilities.
|
||||
|
||||
|
||||
It has also been configured to have a productive dev experience out of the box in [VS Code](https://code.visualstudio.com/), see the [.vscode](./.vscode) folder.
|
||||
|
||||
|
||||
|
||||
18
projects/TokenizeRWATemplate-contracts/eslint.config.mjs
Normal file
18
projects/TokenizeRWATemplate-contracts/eslint.config.mjs
Normal file
@ -0,0 +1,18 @@
|
||||
import eslint from '@eslint/js'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import globals from 'globals'
|
||||
|
||||
export default tseslint.config(
|
||||
eslint.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-member-accessibility': 'warn',
|
||||
},
|
||||
},
|
||||
);
|
||||
5161
projects/TokenizeRWATemplate-contracts/package-lock.json
generated
Normal file
5161
projects/TokenizeRWATemplate-contracts/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
projects/TokenizeRWATemplate-contracts/package.json
Normal file
48
projects/TokenizeRWATemplate-contracts/package.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "smart_contracts",
|
||||
"version": "1.0.0",
|
||||
"description": "Smart contract deployer",
|
||||
"main": "smart_contracts/index.ts",
|
||||
"scripts": {
|
||||
"build": "algokit compile ts smart_contracts --output-source-map --out-dir artifacts && algokit generate client smart_contracts/artifacts --output {app_spec_dir}/{contract_name}Client.ts",
|
||||
"deploy": "ts-node-dev --transpile-only --watch .env -r dotenv/config smart_contracts/index.ts",
|
||||
"deploy:ci": "ts-node --transpile-only -r dotenv/config smart_contracts/index.ts",
|
||||
"lint": "eslint smart_contracts",
|
||||
"lint:fix": "eslint smart_contracts --fix",
|
||||
"audit": "better-npm-audit audit",
|
||||
"format": "prettier --write .",
|
||||
"test": "vitest run --coverage",
|
||||
"test:watch": "vitest watch",
|
||||
"check-types": "tsc --noEmit"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.0",
|
||||
"npm": ">=9.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@algorandfoundation/algorand-typescript": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@algorandfoundation/algokit-client-generator": "^6.0.0",
|
||||
"@algorandfoundation/algokit-utils": "^9.0.0",
|
||||
"@algorandfoundation/algokit-utils-debug": "^1.0.4",
|
||||
"@algorandfoundation/puya-ts": "^1.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@tsconfig/node22": "^22.0.0",
|
||||
"algosdk": "^3.0.0",
|
||||
"better-npm-audit": "^3.11.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"eslint": "^9.18.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"typescript-eslint": "^8.19.1",
|
||||
"prettier": "^3.4.2",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"@algorandfoundation/algorand-typescript-testing": "^1.0.1",
|
||||
"vitest": "^2.1.8",
|
||||
"@vitest/coverage-v8": "^2.1.8",
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"overrides": {
|
||||
"esbuild": "0.25.0"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { HelloWorld } from './contract.algo'
|
||||
|
||||
describe('HelloWorld contract', () => {
|
||||
const ctx = new TestExecutionContext()
|
||||
it('Logs the returned value when sayHello is called', () => {
|
||||
const contract = ctx.contract.create(HelloWorld)
|
||||
|
||||
const result = contract.hello('Sally')
|
||||
|
||||
expect(result).toBe('Hello, Sally')
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,7 @@
|
||||
import { Contract } from '@algorandfoundation/algorand-typescript'
|
||||
|
||||
export class HelloWorld extends Contract {
|
||||
public hello(name: string): string {
|
||||
return `Hello, ${name}`
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
import { Config } from '@algorandfoundation/algokit-utils'
|
||||
import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug'
|
||||
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
|
||||
import { Address } from 'algosdk'
|
||||
import { beforeAll, beforeEach, describe, expect, test } from 'vitest'
|
||||
import { HelloWorldFactory } from '../artifacts/hello_world/HelloWorldClient'
|
||||
|
||||
describe('HelloWorld contract', () => {
|
||||
const localnet = algorandFixture()
|
||||
beforeAll(() => {
|
||||
Config.configure({
|
||||
debug: true,
|
||||
// traceAll: true,
|
||||
})
|
||||
registerDebugEventHandlers()
|
||||
})
|
||||
beforeEach(localnet.newScope)
|
||||
|
||||
const deploy = async (account: Address) => {
|
||||
const factory = localnet.algorand.client.getTypedAppFactory(HelloWorldFactory, {
|
||||
defaultSender: account,
|
||||
})
|
||||
|
||||
const { appClient } = await factory.deploy({
|
||||
onUpdate: 'append',
|
||||
onSchemaBreak: 'append',
|
||||
})
|
||||
return { client: appClient }
|
||||
}
|
||||
|
||||
test('says hello', async () => {
|
||||
const { testAccount } = localnet.context
|
||||
const { client } = await deploy(testAccount)
|
||||
|
||||
const result = await client.send.hello({ args: { name: 'World' } })
|
||||
|
||||
expect(result.return).toBe('Hello, World')
|
||||
})
|
||||
|
||||
test('simulate says hello with correct budget consumed', async () => {
|
||||
const { testAccount } = localnet.context
|
||||
const { client } = await deploy(testAccount)
|
||||
const result = await client
|
||||
.newGroup()
|
||||
.hello({ args: { name: 'World' } })
|
||||
.hello({ args: { name: 'Jane' } })
|
||||
.simulate()
|
||||
|
||||
expect(result.returns[0]).toBe('Hello, World')
|
||||
expect(result.returns[1]).toBe('Hello, Jane')
|
||||
expect(result.simulateResponse.txnGroups[0].appBudgetConsumed).toBeLessThan(100)
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,33 @@
|
||||
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
||||
import { HelloWorldFactory } from '../artifacts/hello_world/HelloWorldClient'
|
||||
|
||||
// Below is a showcase of various deployment options you can use in TypeScript Client
|
||||
export async function deploy() {
|
||||
console.log('=== Deploying HelloWorld ===')
|
||||
|
||||
const algorand = AlgorandClient.fromEnvironment()
|
||||
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
||||
|
||||
const factory = algorand.client.getTypedAppFactory(HelloWorldFactory, {
|
||||
defaultSender: deployer.addr,
|
||||
})
|
||||
|
||||
const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })
|
||||
|
||||
// If app was just created fund the app account
|
||||
if (['create', 'replace'].includes(result.operationPerformed)) {
|
||||
await algorand.send.payment({
|
||||
amount: (1).algo(),
|
||||
sender: deployer.addr,
|
||||
receiver: appClient.appAddress,
|
||||
})
|
||||
}
|
||||
|
||||
const method = 'hello'
|
||||
const response = await appClient.send.hello({
|
||||
args: { name: 'world' },
|
||||
})
|
||||
console.log(
|
||||
`Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`,
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
import { Config } from '@algorandfoundation/algokit-utils'
|
||||
import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug'
|
||||
import { consoleLogger } from '@algorandfoundation/algokit-utils/types/logging'
|
||||
import * as fs from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
|
||||
// Uncomment the traceAll option to enable auto generation of AVM Debugger compliant sourceMap and simulation trace file for all AVM calls.
|
||||
// Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-Debugger
|
||||
|
||||
Config.configure({
|
||||
logger: consoleLogger,
|
||||
debug: true,
|
||||
// traceAll: true,
|
||||
})
|
||||
registerDebugEventHandlers()
|
||||
|
||||
// base directory
|
||||
const baseDir = path.resolve(__dirname)
|
||||
|
||||
// function to validate and dynamically import a module
|
||||
async function importDeployerIfExists(dir: string) {
|
||||
const deployerPath = path.resolve(dir, 'deploy-config')
|
||||
if (fs.existsSync(deployerPath + '.ts') || fs.existsSync(deployerPath + '.js')) {
|
||||
const deployer = await import(deployerPath)
|
||||
return { ...deployer, name: path.basename(dir) }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// get a list of all deployers from the subdirectories
|
||||
async function getDeployers() {
|
||||
const directories = fs
|
||||
.readdirSync(baseDir, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map((dirent) => path.resolve(baseDir, dirent.name))
|
||||
|
||||
const deployers = await Promise.all(directories.map(importDeployerIfExists))
|
||||
return deployers.filter((deployer) => deployer !== null) // Filter out null values
|
||||
}
|
||||
|
||||
// execute all the deployers
|
||||
(async () => {
|
||||
const contractName = process.argv.length > 2 ? process.argv[2] : undefined
|
||||
const contractDeployers = await getDeployers()
|
||||
|
||||
const filteredDeployers = contractName
|
||||
? contractDeployers.filter(deployer => deployer.name === contractName)
|
||||
: contractDeployers
|
||||
|
||||
if (contractName && filteredDeployers.length === 0) {
|
||||
console.warn(`No deployer found for contract name: ${contractName}`)
|
||||
return
|
||||
}
|
||||
|
||||
for (const deployer of filteredDeployers) {
|
||||
try {
|
||||
await deployer.deploy()
|
||||
} catch (e) {
|
||||
console.error(`Error deploying ${deployer.name}:`, e)
|
||||
}
|
||||
}
|
||||
})()
|
||||
26
projects/TokenizeRWATemplate-contracts/tsconfig.json
Normal file
26
projects/TokenizeRWATemplate-contracts/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
},
|
||||
"include": ["smart_contracts/**/*.ts"],
|
||||
"exclude": ["node_modules", "dist", "coverage"]
|
||||
}
|
||||
14
projects/TokenizeRWATemplate-contracts/tsconfig.test.json
Normal file
14
projects/TokenizeRWATemplate-contracts/tsconfig.test.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "@tsconfig/node22/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"target": "ES2023",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2023"],
|
||||
"moduleResolution": "Bundler",
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.mts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
21
projects/TokenizeRWATemplate-contracts/vitest.config.mts
Normal file
21
projects/TokenizeRWATemplate-contracts/vitest.config.mts
Normal file
@ -0,0 +1,21 @@
|
||||
import { puyaTsTransformer } from '@algorandfoundation/algorand-typescript-testing/vitest-transformer'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
esbuild: {},
|
||||
test: {
|
||||
testTimeout: 10000,
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
typescript({
|
||||
tsconfig: './tsconfig.test.json',
|
||||
transformers: {
|
||||
before: [puyaTsTransformer],
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
Reference in New Issue
Block a user