Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ryder Mint V2 on Stacks #16

Merged
merged 12 commits into from
Jan 9, 2023
4 changes: 4 additions & 0 deletions backend-stacks/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ contract_id = 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait'
path = 'contracts/external/commission-free.clar'
clarity_version = 1

[contracts.ryder-buy]
path = 'contracts/ryder-buy.clar'
clarity_version = 1

[contracts.ryder-mint]
path = 'contracts/ryder-mint.clar'
clarity_version = 1
Expand Down
84 changes: 84 additions & 0 deletions backend-stacks/contracts/ryder-buy.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(define-constant contract-principal (as-contract tx-sender))

(define-constant err-unauthorized (err u403))
(define-constant err-not-allowed (err u508))
(define-constant err-mint-not-live (err u600))
(define-constant err-sold-out (err u601))
(define-constant err-failed (err u602))
(define-constant err-no-price (err u603))
(define-constant err-insufficient-balance (err u604))

(define-data-var buy-enabled bool false)
(define-data-var payment-recipient principal 'SP1YZSSPWJ5D3S1G48ZPW8NGXVG0K2TZJJXDM6N0Q)

(define-map tier-prices uint uint)
;; don't set tier u0
(map-set tier-prices u1 u1130000000)
(map-set tier-prices u2 u1130000000)
(map-set tier-prices u3 u1130000000)
(map-set tier-prices u4 u1130000000)
(map-set tier-prices u5 u1130000000)
(map-set tier-prices u6 u1130000000)
(map-set tier-prices u7 u1130000000)

(define-map admins principal bool)
(map-set admins tx-sender true)

(define-map token-mapping uint uint)

(define-private (mint-self-iter (c (buff 1)) (p (response bool uint)))
(contract-call? .ryder-nft mint contract-principal))

(define-public (mint-self (iterations (buff 200)))
MarvinJanssen marked this conversation as resolved.
Show resolved Hide resolved
(fold mint-self-iter iterations (ok true)))

(define-read-only (get-tier-price (tier-id uint))
(map-get? tier-prices tier-id))

(define-read-only (get-token-price (token-id uint))
(map-get? tier-prices (contract-call? .ryder-nft get-tier-by-token-id token-id)))

(define-read-only (is-for-sale (token-id uint))
(is-eq (contract-call? .ryder-nft get-owner token-id) (ok (some contract-principal))))

(define-public (buy (token-id uint))
MarvinJanssen marked this conversation as resolved.
Show resolved Hide resolved
(let ((price (unwrap! (get-token-price token-id) err-no-price)))
(unwrap! (stx-transfer? price tx-sender (var-get payment-recipient)) err-insufficient-balance)
(asserts! (var-get buy-enabled) err-mint-not-live)
(contract-call? .ryder-nft transfer token-id contract-principal tx-sender)))
MarvinJanssen marked this conversation as resolved.
Show resolved Hide resolved

;; admin function
(define-read-only (check-is-admin)
(ok (asserts! (default-to false (map-get? admins contract-caller)) err-unauthorized)))

(define-public (set-buy-enabled (enabled bool))
(begin
(try! (check-is-admin))
(ok (var-set buy-enabled enabled))))

(define-public (set-admin (new-admin principal) (value bool))
(begin
(try! (check-is-admin))
(asserts! (not (is-eq tx-sender new-admin)) err-not-allowed)
(ok (map-set admins new-admin value))))

(define-private (burn-iter (token-id uint) (previous (response bool uint)))
(begin
(try! previous)
(as-contract (contract-call? .ryder-nft burn token-id))))

(define-public (burn (token-ids (list 200 uint)))
MarvinJanssen marked this conversation as resolved.
Show resolved Hide resolved
(begin
(try! (check-is-admin))
(fold burn-iter token-ids (ok true))))

(define-public (set-payment-recipient (recipient principal))
(begin
(try! (check-is-admin))
(ok (var-set payment-recipient recipient))))

;; don't set u0
(define-public (set-price-in-ustx (tier-id uint) (price uint))
(begin
(try! (check-is-admin))
(ok (map-set tier-prices tier-id price))))
25 changes: 15 additions & 10 deletions backend-stacks/deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ plan:
batches:
- id: 0
transactions:
- emulated-contract-publish:
contract-name: commission-trait
emulated-sender: SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C
path: ".cache/requirements/SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.commission-trait.clar"
clarity-version: 1
- emulated-contract-publish:
contract-name: nft-trait
emulated-sender: SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9
path: ".cache/requirements/SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.clar"
clarity-version: 1
- emulated-contract-publish:
contract-name: commission-trait
emulated-sender: SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C
path: ".cache/requirements/SP2KAF9RF86PVX3NEE27DFV1CQX0T4WGR41X3S45C.commission-trait.clar"
contract-name: commission-free
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/external/commission-free.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: ryder-nft
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/ryder-nft.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: ryder-mint-free
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/external/ryder-mint-free.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: ryder-mint
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
Expand All @@ -77,9 +77,14 @@ plan:
path: contracts/ryder-nft-allow-list.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: commission-free
contract-name: ryder-buy
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/external/commission-free.clar
path: contracts/ryder-buy.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: ryder-mint-free
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/external/ryder-mint-free.clar
clarity-version: 1
- emulated-contract-publish:
contract-name: ryder-mint-v2
Expand Down
26 changes: 26 additions & 0 deletions backend-stacks/tests/ryder-buy_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import { Clarinet, Tx, Chain, Account, types } from 'https://deno.land/x/[email protected]/index.ts';
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts';

Clarinet.test({
name: "Ensure that <...>",
async fn(chain: Chain, accounts: Map<string, Account>) {
let block = chain.mineBlock([
/*
* Add transactions with:
* Tx.contractCall(...)
*/
]);
assertEquals(block.receipts.length, 0);
assertEquals(block.height, 2);

block = chain.mineBlock([
/*
* Add transactions with:
* Tx.contractCall(...)
*/
]);
assertEquals(block.receipts.length, 0);
assertEquals(block.height, 3);
},
});