|
|
|
@ -4,6 +4,7 @@ import {SmartContract} from "ton-contract-executor";
|
|
|
|
|
import {encodeOffChainContent, makeSnakeCell} from "./utils"; |
|
|
|
|
import {randomBytes} from "crypto"; |
|
|
|
|
import {keyPairFromSeed, KeyPair, sign, keyPairFromSecretKey} from "ton-crypto"; |
|
|
|
|
import { hex as item_code } from "../build/nft-item.compiled.json"; |
|
|
|
|
import {randomAddress} from "../test/helpers"; |
|
|
|
|
import {hashCell} from "ton/dist/boc/boc"; |
|
|
|
|
|
|
|
|
@ -29,7 +30,7 @@ export function data(params: { ownerAddress: Address; collectionAddress: Address
|
|
|
|
|
.storeUint(0, 256) |
|
|
|
|
.storeAddress(params.collectionAddress) |
|
|
|
|
.storeAddress(params.ownerAddress) |
|
|
|
|
.storeRef(encodeOffChainContent("https://agorata.io/collection.json")) // https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md
|
|
|
|
|
.storeRef(encodeOffChainContent(`https://api.agorata.io/collection/${params.domain}.json`)) // https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md
|
|
|
|
|
.storeRef(makeSnakeCell(Buffer.from(params.domain))) |
|
|
|
|
.storeDict(null) |
|
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
@ -39,16 +40,19 @@ export function data(params: { ownerAddress: Address; collectionAddress: Address
|
|
|
|
|
|
|
|
|
|
export function collectionData(params: { |
|
|
|
|
code: Cell, ownerAddress: Address, ownerKey: BN, |
|
|
|
|
price_multiplier?: number, price_steepness?: number |
|
|
|
|
price_multiplier?: number, price_steepness?: number, zone?: string |
|
|
|
|
}): Cell { |
|
|
|
|
if (params.price_multiplier == undefined) { |
|
|
|
|
params.price_multiplier = 10; |
|
|
|
|
params.price_multiplier = 1; |
|
|
|
|
} |
|
|
|
|
if (params.price_steepness == undefined) { |
|
|
|
|
params.price_steepness = 5; |
|
|
|
|
params.price_steepness = 1; |
|
|
|
|
} |
|
|
|
|
if (params.zone == undefined) { |
|
|
|
|
params.zone = "example"; |
|
|
|
|
} |
|
|
|
|
return beginCell() |
|
|
|
|
.storeRef(encodeOffChainContent("https://agorata.io/collection.json")) |
|
|
|
|
.storeRef(encodeOffChainContent(`https://api.agorata.io/data/${params.zone}.json`)) // https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md
|
|
|
|
|
.storeRef(params.code) |
|
|
|
|
.storeRef(beginCell().storeUint(params.price_multiplier, 8).storeUint(params.price_steepness, 4).endCell()) |
|
|
|
|
.storeUint(params.ownerKey, 256) |
|
|
|
@ -99,6 +103,17 @@ export function signBuy(domain: string, collectionAddress: Address, buyerAddress
|
|
|
|
|
return asciiEncode(signature); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getItemAddr(collectionAddress: Address, domain: string, workchain: number): Address { |
|
|
|
|
let item_data_init = beginCell() |
|
|
|
|
.storeUint(new BN(hashCell(beginCell().storeBuffer(Buffer.from(domain)).endCell())), 256) |
|
|
|
|
.storeAddress(collectionAddress).endCell(); |
|
|
|
|
let item_state_init = beginCell().storeUint(0, 2) |
|
|
|
|
.storeDict(Cell.fromBoc(item_code)[0]) |
|
|
|
|
.storeDict(item_data_init) |
|
|
|
|
.storeUint(0, 1).endCell(); |
|
|
|
|
return new Address(workchain, hashCell(item_state_init)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function TON(): number { |
|
|
|
|
return 1000000000; |
|
|
|
|
} |
|
|
|
@ -119,6 +134,13 @@ export function createItem(params: { domain: String, signature?: String }): Cell
|
|
|
|
|
.endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function setContent(params: { domain: string, zone: string }) { |
|
|
|
|
return beginCell() |
|
|
|
|
.storeUint(0x1a0b9d51 , 32) |
|
|
|
|
.storeRef(encodeOffChainContent(`https://api.agorata.io/data/${params.zone}/${params.domain}.json`)) |
|
|
|
|
.endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function instantBuySignature(receiverAddress: Address, issuedCollectionAddr: Address, amount: number, domain: Cell, privateKey: Buffer): Buffer { |
|
|
|
|
let messageToSign = beginCell().storeAddress(receiverAddress).storeAddress(issuedCollectionAddr).storeUint(amount, 256).storeRef(domain).endCell(); |
|
|
|
|
let hash = messageToSign.hash(); |
|
|
|
|