Skip to content

Commit

Permalink
Merge branch 'main' into feat/lp
Browse files Browse the repository at this point in the history
Peixer authored Jan 17, 2024
2 parents 85577b3 + 12387c7 commit bfc463f
Showing 21 changed files with 2,028 additions and 576 deletions.
2 changes: 1 addition & 1 deletion contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]

resolver = "1"
members = ["src/greeter"]
members = ["src/zkdex"]
2 changes: 0 additions & 2 deletions contracts/deployments/greeter/alephzero-testnet.ts

This file was deleted.

2 changes: 0 additions & 2 deletions contracts/deployments/greeter/alephzero.ts

This file was deleted.

1 change: 0 additions & 1 deletion contracts/deployments/greeter/greeter.contract

This file was deleted.

468 changes: 0 additions & 468 deletions contracts/deployments/greeter/greeter.json

This file was deleted.

Binary file removed contracts/deployments/greeter/greeter.wasm
Binary file not shown.
2 changes: 0 additions & 2 deletions contracts/deployments/greeter/rococo.ts

This file was deleted.

2 changes: 0 additions & 2 deletions contracts/deployments/greeter/shibuya.ts

This file was deleted.

2 changes: 2 additions & 0 deletions contracts/deployments/zkdex/alephzero-testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const address = '5HoA2DXwfuuJHWmbyXjosuzPyMVsiPPxAVEx6nKD5mKUcq7i'
export const blockNumber = 52091772
1 change: 1 addition & 0 deletions contracts/deployments/zkdex/zkdex.contract

Large diffs are not rendered by default.

1,295 changes: 1,295 additions & 0 deletions contracts/deployments/zkdex/zkdex.json

Large diffs are not rendered by default.

Binary file added contracts/deployments/zkdex/zkdex.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions contracts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ set -eu
# This is kind of a hack to prevent a nasty Next.js error when running the frontend
# for the first time after deploying to a local node which forces to clear `frontend/.next`.

if [[ ! -e deployments/greeter/development.ts ]]; then
if [[ ! -e deployments/zkdex/development.ts ]]; then
echo "Creating empty 'development.ts'…"
if command -v touch &> /dev/null; then
touch deployments/greeter/development.ts
touch deployments/zkdex/development.ts
else
copy /b deployments/greeter/development.ts +,,
copy /b deployments/zkdex/development.ts +,,
fi
else
echo "Great, 'development.ts' already exists! Skipping…"
10 changes: 5 additions & 5 deletions contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { writeContractAddresses } from '@/utils/writeContractAddresses'
import { deployContract } from '@scio-labs/use-inkathon/helpers'

/**
* Script that deploys the greeter contract and writes its address to a file.
* Script that deploys the zkdex contract and writes its address to a file.
*
* Parameters:
* - `DIR`: Directory to read contract build artifacts & write addresses to (optional, defaults to `./deployments`)
@@ -18,13 +18,13 @@ const main = async () => {
const initParams = await initPolkadotJs()
const { api, chain, account } = initParams

// Deploy greeter contract
const { abi, wasm } = await getDeploymentData('greeter')
const greeter = await deployContract(api, account, abi, wasm, 'default', [])
// Deploy zkdex contract
const { abi, wasm } = await getDeploymentData('zkdex')
const zkdex = await deployContract(api, account, abi, wasm, 'default', [])

// Write contract addresses to `{contract}/{network}.ts` file(s)
await writeContractAddresses(chain.network, {
greeter,
zkdex,
})
}

6 changes: 3 additions & 3 deletions contracts/scripts/script.template.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
} from '@scio-labs/use-inkathon/helpers'

/**
* Example script that updates & reads a message from a greeter contract.
* Example script that updates & reads a message from a zkdex contract.
* Can be used as a template for other scripts.
*
* Parameters:
@@ -23,8 +23,8 @@ import {
const main = async () => {
const { api, account } = await initPolkadotJs()

// Deploy greeter contract
const { abi, wasm } = await getDeploymentData('greeter')
// Deploy zkdex contract
const { abi, wasm } = await getDeploymentData('zkdex')
const { address } = await deployContract(api, account, abi, wasm, 'default', [])
const contract = new ContractPromise(api, abi, address)

81 changes: 0 additions & 81 deletions contracts/src/greeter/lib.rs

This file was deleted.

10 changes: 6 additions & 4 deletions contracts/src/greeter/Cargo.toml → contracts/src/zkdex/Cargo.toml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[package]
name = "greeter"
name = "zkdex"
version = "0.0.1"
authors = ["Scio Labs <hello@scio.xyz>"]
authors = ["AE Studio<hello@scio.xyz>"]
edition = "2021"

[dependencies]
ink = { version = "4.3.0", default-features = false }
ink_prelude = { version = "4.3.0", default-features = false }
openbrush = { version = "4.0.0-beta", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

[lib]
path = "lib.rs"
path = "zkdex.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
std = ["ink/std", "scale/std", "scale-info/std", "openbrush/std", "ink_prelude/std"]
ink-as-dependency = []
590 changes: 590 additions & 0 deletions contracts/src/zkdex/zkdex.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { toast } from 'react-hot-toast'

import { ChainInfo } from '@/components/web3/chain-info'
import { ConnectButton } from '@/components/web3/connect-button'
import { GreeterContractInteractions } from '@/components/web3/greeter-contract-interactions'
import { ZKDexContractInteractions } from '@/components/web3/zkdex-contract-interactions'

import { Button } from '../components/ui/button'
import { Background } from './components/background'
@@ -51,6 +51,7 @@ export default function HomePage() {
</Button>
</div>
<HeroHexagons />
<ZKDexContractInteractions />
</main>
</div>
<Background />
118 changes: 118 additions & 0 deletions frontend/src/components/web3/zkdex-contract-interactions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
'use client'

import { FC } from 'react'

import { ContractIds } from '@/deployments/deployments'
import {
contractQuery,
decodeOutput,
useInkathon,
useRegisteredContract,
} from '@scio-labs/use-inkathon'
import toast from 'react-hot-toast'

import { contractTxWithToast } from '@/utils/contract-tx-with-toast'

export const ZKDexContractInteractions: FC = () => {
const { api, activeAccount, activeSigner } = useInkathon()
const { contract, address: contractAddress } = useRegisteredContract(ContractIds.zkdex)

const fetchAllOrders = async () => {
if (!contract || !api) return

const result = await contractQuery(api, '', contract, 'get_all_orders')
const { output, isError, decodedOutput } = decodeOutput(result, contract, 'get_all_orders')
if (isError) throw new Error(decodedOutput)
console.log('Get All Orders')
console.log(decodedOutput)
}

const fetchAllClaimOrders = async () => {
if (!contract || !api) return

const result = await contractQuery(api, '', contract, 'get_all_orders_claim')
const { output, isError, decodedOutput } = decodeOutput(
result,
contract,
'get_all_orders_claim',
)
if (isError) throw new Error(decodedOutput)
console.log('Get All Claim Orders')
console.log(decodedOutput)
}

const fetchOrder = async () => {
if (!activeAccount || !contract || !api) return

const result = await contractQuery(api, activeAccount.address, contract, 'get_order', {}, [0])
const { output, isError, decodedOutput } = decodeOutput(result, contract, 'get_order')
if (isError) throw new Error(decodedOutput)
console.log('Get Order')
console.log(decodedOutput)
}

const createOrder = async () => {
if (!activeAccount || !contract || !activeSigner || !api) {
toast.error('Wallet not connected. Try again…')
return
}

await contractTxWithToast(
api,
activeAccount.address,
contract,
'create_order',
{
value: 11,
},
[1, 'test', 'test', 1],
)
}

const createClaimOrder = async () => {
if (!activeAccount || !contract || !activeSigner || !api) {
toast.error('Wallet not connected. Try again…')
return
}

await contractTxWithToast(
api,
activeAccount.address,
contract,
'claim_order',
{},
[0, 1705475714000],
)
}

if (!api) return null

return (
<>
<div className="flex max-w-[22rem] grow flex-col gap-4">
<h2 className="text-center font-mono text-gray-400">ZKDex Smart Contract</h2>

<button className="w-sm rounded bg-slate-800" onClick={fetchAllOrders}>
Get All Orders
</button>
<button className="w-sm rounded bg-slate-800" onClick={fetchAllClaimOrders}>
Get All Claim Orders
</button>
<button className="w-sm rounded bg-slate-800" onClick={fetchOrder}>
Get Order
</button>
<button className="w-sm rounded bg-slate-800" onClick={createOrder}>
Create Liquidity Pool
</button>
<button className="w-sm rounded bg-slate-800" onClick={createClaimOrder}>
Claim Liquidity Pool
</button>

{/* Contract Address */}
<p className="text-center font-mono text-xs text-gray-600">
{contract ? contractAddress : 'Loading…'}
</p>
</div>
</>
)
}
3 changes: 2 additions & 1 deletion frontend/src/deployments/deployments.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@ import { env } from '@/config/environment'
* DOCS: https://github.com/scio-labs/inkathon#2-custom-contracts
*/
export enum ContractIds {
Greeter = 'greeter',
zkdex = 'zkdex',
// Greeter = 'greeter',
}

export const getDeployments = async (): Promise<SubstrateDeployment[]> => {

0 comments on commit bfc463f

Please sign in to comment.