Skip to content

Commit dd93598

Browse files
committed
deploy-config edit
1 parent 67960c1 commit dd93598

File tree

1 file changed

+57
-42
lines changed

1 file changed

+57
-42
lines changed

projects/coding-assignment/smart_contracts/nft_marketplace/deploy-config.ts

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as algokit from '@algorandfoundation/algokit-utils'
22
import { NftMarketplaceClient } from '../artifacts/nft_marketplace/client'
33
import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account'
4+
import { Config as AlgokitConfig } from '@algorandfoundation/algokit-utils'
45

56
// Below is a showcase of various deployment options you can use in TypeScript Client
67
export async function deploy() {
78
console.log('=== Deploying NftMarketplaceClient ===')
9+
AlgokitConfig.configure({ populateAppCallResources: true })
810

911
// 여러 클라이언트 생성
1012
const algod = algokit.getAlgoClient()
@@ -15,8 +17,7 @@ export async function deploy() {
1517
// 랜덤 계정 생성 후 자금 지급
1618
const deployer = await algorand.account.random()
1719
const buyer = await algorand.account.random()
18-
const lateBuyer = await algorand.account.random()
19-
const accounts = [deployer, buyer, lateBuyer]
20+
const accounts = [deployer, buyer]
2021

2122
const dispenser = await algorand.account.dispenser()
2223
for (let i = 0; i < accounts.length; i++) {
@@ -65,25 +66,29 @@ export async function deploy() {
6566
sender: deployer.addr,
6667
receiver: app.appAddress,
6768
amount: algokit.algos(0.2),
69+
extraFee: algokit.algos(0.001),
6870
})
6971

70-
// 앱이 판매할 준비가 되도록 Bootstrap 메서드를 호출
71-
await appClient.bootstrap(
72-
{ asset: assetId, unitaryPrice: unitaryPrice, mbrPay: mbrPay },
73-
{ sendParams: { fee: algokit.transactionFees(2), populateAppCallResources: true, suppressLog: true } },
74-
)
75-
console.log('2. 앱 부트스트래핑 완료!')
72+
const sendAssetToSell = {
73+
sender: deployer.addr,
74+
receiver: app.appAddress,
75+
assetId: assetId,
76+
amount: 100n,
77+
}
7678

77-
// NftMarketplaceClient 앱에 판매할 NFT 에셋 송금
78-
await algorand.send.assetTransfer(
79-
{
79+
// 앱이 판매할 준비가 되도록 Bootstrap 메서드를 호출, NftMarketplaceClient 앱에 판매할 NFT 에셋 송금
80+
await algorand
81+
.newGroup()
82+
.addMethodCall({
8083
sender: deployer.addr,
81-
receiver: app.appAddress,
82-
assetId: assetId,
83-
amount: 100n,
84-
},
85-
{ suppressLog: true },
86-
)
84+
appId: BigInt(app.appId),
85+
method: appClient.appClient.getABIMethod('bootstrap')!,
86+
args: [assetId, unitaryPrice, mbrPay],
87+
})
88+
.addAssetTransfer(sendAssetToSell)
89+
.execute()
90+
91+
console.log('2. 앱 부트스트래핑 완료!')
8792
console.log('3. IU 티켓 에셋 앱으로 송금 완료!')
8893

8994
// 구매자 앱 클라이언트 생성. 이 앱 클라이언트는 구매자 계정과 연동됨.
@@ -96,15 +101,6 @@ export async function deploy() {
96101
algod,
97102
)
98103

99-
const lateBuyerAppClient = new NftMarketplaceClient(
100-
{
101-
resolveBy: 'id',
102-
sender: lateBuyer,
103-
id: app.appId,
104-
},
105-
algod,
106-
)
107-
108104
// 구매자가 에섯에 옵트인하고 buy 메서드를 호출하는 함수
109105
async function buyAsset(
110106
appClient: NftMarketplaceClient,
@@ -115,42 +111,61 @@ export async function deploy() {
115111
appAddr: string,
116112
unitaryPrice: number,
117113
): Promise<void> {
114+
// NftMarketplaceClient buy 메서드 호출때 구매 비용 지불로 사용할 결제 트랜잭션 생성
115+
const buyNftPay = await algorand.transactions.payment({
116+
sender: buyer.addr,
117+
receiver: appAddr,
118+
amount: algokit.algos((unitaryPrice * buyAmount) / 1_000_000),
119+
})
120+
118121
try {
119122
let assetInfo = await algorand.account.getAssetInformation(buyer, assetId)
120123
console.log(`${buyerName}가 이미 에셋에 옵트인 되어있어요! 현재 보유한 티켓 수: ${assetInfo.balance}개`)
121124
} catch (e) {
122125
console.log(`${buyerName}가 에셋에 옵트인이 안 되어있어요. 옵트인 진행할게요~`)
123-
// 구매자가 NFT에 옵트인
124-
await algorand.send.assetOptIn(
125-
{
126+
127+
// buy메서드 앱 호출 트랜잭션 생성
128+
const buyAppCall = await appClient
129+
.compose()
130+
.buy(
131+
{
132+
buyerTxn: buyNftPay,
133+
quantity: buyAmount,
134+
},
135+
{ sendParams: { fee: algokit.transactionFees(2), suppressLog: true } },
136+
)
137+
.atc()
138+
139+
// 구매자가 NFT에 옵트인, buyNftPay 결제 트랜잭션, NftMarketplaceClient buy 메서드를 어토믹 트랜잭션으로 동시에 호출
140+
await algorand
141+
.newGroup()
142+
.addAssetOptIn({
126143
sender: buyer.addr,
127144
assetId: assetId,
128-
},
129-
{ suppressLog: true },
130-
)
131-
}
145+
})
146+
.addAtc(buyAppCall)
147+
.execute()
132148

133-
// NftMarketplaceClient buy 메서드 호출때 구매 비용 지불로 사용할 결제 트랜잭션 생성
134-
const buyNftPay = await algorand.transactions.payment({
135-
sender: buyer.addr,
136-
receiver: appAddr,
137-
amount: algokit.algos((unitaryPrice * buyAmount) / 1_000_000),
138-
})
149+
const assetInfo = await algorand.account.getAssetInformation(buyer, assetId)
150+
console.log(`${buyerName}가 티켓 ${buyAmount}장을 구매하여 ${assetInfo.balance}개의 티켓을 보유하고 있어요!`)
151+
return
152+
}
139153

140-
// 위 결제 트랜잭션과 NftMarketplaceClient buy 메서드를 어토믹 트랜잭션으로 동시에 호출
154+
// 계정이 이미 구매할 에셋(아이유 콘서트 티켓)에 옵트인 되어 있을 시 buy 메서드만 호출
141155
await appClient.buy(
142156
{
143157
buyerTxn: buyNftPay,
144158
quantity: buyAmount,
145159
},
146-
{ sendParams: { fee: algokit.transactionFees(2), populateAppCallResources: true, suppressLog: true } },
160+
{ sendParams: { fee: algokit.transactionFees(2), suppressLog: true } },
147161
)
148162

149163
const assetInfo = await algorand.account.getAssetInformation(buyer, assetId)
150-
console.log(`${buyerName}가 티켓 1장을 구매하여 ${assetInfo.balance}개의 티켓을 보유하고 있어요!`)
164+
console.log(`${buyerName}가 티켓 ${buyAmount}장을 구매하여 ${assetInfo.balance}개의 티켓을 보유하고 있어요!`)
151165
}
152166

153167
await buyAsset(buyerAppClient, 'buyer', buyer, assetId, 1, app.appAddress, unitaryPrice)
168+
await buyAsset(buyerAppClient, 'buyer', buyer, assetId, 2, app.appAddress, unitaryPrice)
154169

155170
// 판매자가 NftMarketplaceClient 앱을 삭제하며 수익금과 잔여 NFT 에셋을 회수
156171
await appClient.delete.withdrawAndDelete(

0 commit comments

Comments
 (0)