|
|
@ -1,16 +1,16 @@ |
|
|
|
import BN from "bn.js"; |
|
|
|
import BN from "bn.js"; |
|
|
|
import { Cell, beginCell, Address } from "ton"; |
|
|
|
import {Cell, beginCell, Address} from "ton"; |
|
|
|
import { C7Config, SmartContract } from "ton-contract-executor"; |
|
|
|
import {C7Config, SmartContract} from "ton-contract-executor"; |
|
|
|
import {encodeOffChainContent, makeSnakeCell} from "./utils"; |
|
|
|
import {encodeOffChainContent, makeSnakeCell} from "./utils"; |
|
|
|
import { randomBytes } from "crypto"; |
|
|
|
import {randomBytes} from "crypto"; |
|
|
|
import { keyPairFromSeed, KeyPair, sign } from "ton-crypto"; |
|
|
|
import {keyPairFromSeed, KeyPair, sign} from "ton-crypto"; |
|
|
|
import { ExpansionPanelActions } from "@material-ui/core"; |
|
|
|
import {ExpansionPanelActions} from "@material-ui/core"; |
|
|
|
|
|
|
|
|
|
|
|
// encode contract storage according to save_data() contract method
|
|
|
|
// encode contract storage according to save_data() contract method
|
|
|
|
|
|
|
|
|
|
|
|
export function genKeyPair(): KeyPair { |
|
|
|
export function genKeyPair(): KeyPair { |
|
|
|
let seed = randomBytes(32); |
|
|
|
let seed = randomBytes(32); |
|
|
|
return keyPairFromSeed(seed); |
|
|
|
return keyPairFromSeed(seed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// nft_item_code:^Cell
|
|
|
|
// nft_item_code:^Cell
|
|
|
@ -22,89 +22,100 @@ export function genKeyPair(): KeyPair { |
|
|
|
// cell auction - auction info
|
|
|
|
// cell auction - auction info
|
|
|
|
// int64 last_fill_up_time
|
|
|
|
// int64 last_fill_up_time
|
|
|
|
export function data(params: { ownerAddress: Address; collectionAddress: Address, code: Cell, domain: String, publicKey: Buffer }): Cell { |
|
|
|
export function data(params: { ownerAddress: Address; collectionAddress: Address, code: Cell, domain: String, publicKey: Buffer }): Cell { |
|
|
|
let data_cell = beginCell() |
|
|
|
let data_cell = beginCell() |
|
|
|
// For code: https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-auction/build.sh
|
|
|
|
// For code: https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-auction/build.sh
|
|
|
|
.storeRef(params.code) |
|
|
|
.storeRef(params.code) |
|
|
|
.storeUint(0, 256) |
|
|
|
.storeUint(0, 256) |
|
|
|
.storeAddress(params.collectionAddress) |
|
|
|
.storeAddress(params.collectionAddress) |
|
|
|
.storeAddress(params.ownerAddress) |
|
|
|
.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://agorata.io/collection.json")) // https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md
|
|
|
|
.storeRef(makeSnakeCell(Buffer.from(params.domain))) |
|
|
|
.storeRef(makeSnakeCell(Buffer.from(params.domain))) |
|
|
|
.storeDict(null) |
|
|
|
.storeDict(null) |
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
|
|
|
|
|
|
|
|
return beginCell().storeRef(data_cell).storeBuffer(params.publicKey).endCell(); |
|
|
|
return beginCell().storeRef(data_cell).storeBuffer(params.publicKey).endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function collectionData(params: { code: Cell, ownerAddress: Address, ownerKey: number }): Cell { |
|
|
|
export function collectionData(params: { |
|
|
|
|
|
|
|
code: Cell, ownerAddress: Address, ownerKey: number, |
|
|
|
|
|
|
|
price_multiplier?: number, price_steepness?: number |
|
|
|
|
|
|
|
}): Cell { |
|
|
|
|
|
|
|
if (params.price_multiplier == undefined) { |
|
|
|
|
|
|
|
params.price_multiplier = 10; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (params.price_steepness == undefined) { |
|
|
|
|
|
|
|
params.price_steepness = 5; |
|
|
|
|
|
|
|
} |
|
|
|
return beginCell() |
|
|
|
return beginCell() |
|
|
|
.storeRef(encodeOffChainContent("https://agorata.io/collection.json")) |
|
|
|
.storeRef(encodeOffChainContent("https://agorata.io/collection.json")) |
|
|
|
.storeRef(params.code) |
|
|
|
.storeRef(params.code) |
|
|
|
.storeRef(beginCell().endCell()) |
|
|
|
.storeRef(beginCell().storeUint(params.price_multiplier, 8).storeUint(params.price_steepness, 4).endCell()) |
|
|
|
.storeUint(params.ownerKey, 256) |
|
|
|
.storeUint(params.ownerKey, 256) |
|
|
|
.storeAddress(params.ownerAddress) |
|
|
|
.storeAddress(params.ownerAddress) |
|
|
|
.endCell(); |
|
|
|
.endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function auctionWithWinner(winnerAddress: Address) { |
|
|
|
export function auctionWithWinner(winnerAddress: Address) { |
|
|
|
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) |
|
|
|
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function setContractBalance(contract: SmartContract, balance: number) { |
|
|
|
export function setContractBalance(contract: SmartContract, balance: number) { |
|
|
|
contract.setC7Config({balance: balance}); |
|
|
|
contract.setC7Config({balance: balance}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function TON(): number { return 1000000000; } |
|
|
|
export function TON(): number { |
|
|
|
|
|
|
|
return 1000000000; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// message encoders for all ops (see contracts/imports/constants.fc for consts)
|
|
|
|
// message encoders for all ops (see contracts/imports/constants.fc for consts)
|
|
|
|
|
|
|
|
|
|
|
|
export function transferOwnership(params: { newOwnerAddress: Address }): Cell { |
|
|
|
export function transferOwnership(params: { newOwnerAddress: Address }): Cell { |
|
|
|
return beginCell().storeUint(0x5fcc3d14, 32).storeUint(0, 64).storeAddress(params.newOwnerAddress).storeAddress(null).storeInt(0, 1).storeCoins(1 * TON()).endCell(); |
|
|
|
return beginCell().storeUint(0x5fcc3d14, 32).storeUint(0, 64).storeAddress(params.newOwnerAddress).storeAddress(null).storeInt(0, 1).storeCoins(1 * TON()).endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function createItem(params: { domain: String }): Cell { |
|
|
|
export function createItem(params: { domain: String }): Cell { |
|
|
|
let signature = '000'; |
|
|
|
let signature = '000'; |
|
|
|
return beginCell() |
|
|
|
return beginCell() |
|
|
|
.storeUint(0, 32) |
|
|
|
.storeUint(0, 32) |
|
|
|
.storeRef(makeSnakeCell(Buffer.from(params.domain + ';' + signature))) |
|
|
|
.storeRef(makeSnakeCell(Buffer.from(params.domain + ';' + signature))) |
|
|
|
.endCell(); |
|
|
|
.endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function instantBuySignature(receiverAddress: Address, issuedCollectionAddr: Address, amount: number, domain: Cell, privateKey: Buffer): Buffer { |
|
|
|
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 messageToSign = beginCell().storeAddress(receiverAddress).storeAddress(issuedCollectionAddr).storeUint(amount, 256).storeRef(domain).endCell(); |
|
|
|
let hash = messageToSign.hash(); |
|
|
|
let hash = messageToSign.hash(); |
|
|
|
// console.log(hash.toString("hex"));
|
|
|
|
// console.log(hash.toString("hex"));
|
|
|
|
// console.log((new BN(hash)).toString(10))
|
|
|
|
// console.log((new BN(hash)).toString(10))
|
|
|
|
// return sign(hash, privateKey);
|
|
|
|
// return sign(hash, privateKey);
|
|
|
|
let althash = new BN("FF11841721E4DAD5AE679A1A338B2EBFC5AAF7529C200B4EF9D71831B1DCB969", "hex"); |
|
|
|
let althash = new BN("FF11841721E4DAD5AE679A1A338B2EBFC5AAF7529C200B4EF9D71831B1DCB969", "hex"); |
|
|
|
return sign(althash.toBuffer(), privateKey); |
|
|
|
return sign(althash.toBuffer(), privateKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function instantBuyMessage(params: { receiverAddress: Address, issuedCollectionAddr: Address, price: number, domain: String, privateKey: Buffer}): Cell { |
|
|
|
export function instantBuyMessage(params: { receiverAddress: Address, issuedCollectionAddr: Address, price: number, domain: String, privateKey: Buffer }): Cell { |
|
|
|
let domainSnakeCell = makeSnakeCell(Buffer.from(params.domain)); |
|
|
|
let domainSnakeCell = makeSnakeCell(Buffer.from(params.domain)); |
|
|
|
let signature = instantBuySignature(params.receiverAddress, params.issuedCollectionAddr, params.price, domainSnakeCell, params.privateKey); |
|
|
|
let signature = instantBuySignature(params.receiverAddress, params.issuedCollectionAddr, params.price, domainSnakeCell, params.privateKey); |
|
|
|
console.log(signature.toString("hex").toUpperCase()); |
|
|
|
console.log(signature.toString("hex").toUpperCase()); |
|
|
|
let cell = beginCell() |
|
|
|
let cell = beginCell() |
|
|
|
.storeUint(0x16c7d435, 32) // opcode
|
|
|
|
.storeUint(0x16c7d435, 32) // opcode
|
|
|
|
.storeUint(0, 64) // query id
|
|
|
|
.storeUint(0, 64) // query id
|
|
|
|
.storeBuffer(signature) // body
|
|
|
|
.storeBuffer(signature) // body
|
|
|
|
.storeUint(params.price, 256) |
|
|
|
.storeUint(params.price, 256) |
|
|
|
.storeRef(domainSnakeCell).endCell(); |
|
|
|
.storeRef(domainSnakeCell).endCell(); |
|
|
|
return cell; |
|
|
|
return cell; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function currentState(contract: SmartContract) { |
|
|
|
export function currentState(contract: SmartContract) { |
|
|
|
let c4 = contract.dataCell.beginParse(); |
|
|
|
let c4 = contract.dataCell.beginParse(); |
|
|
|
let reader = c4.readRef(); |
|
|
|
let reader = c4.readRef(); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
nft_item_code: reader.readRef(), |
|
|
|
nft_item_code: reader.readRef(), |
|
|
|
index: reader.readUint(256), |
|
|
|
index: reader.readUint(256), |
|
|
|
collectionAddress: reader.readAddress(), |
|
|
|
collectionAddress: reader.readAddress(), |
|
|
|
ownerAddress: reader.readAddress(), |
|
|
|
ownerAddress: reader.readAddress(), |
|
|
|
collectionContent: reader.readRef(), |
|
|
|
collectionContent: reader.readRef(), |
|
|
|
domain: reader.readRef(), |
|
|
|
domain: reader.readRef(), |
|
|
|
// auction: reader.readCell(), – TODO: still havent's figured out to load auction here
|
|
|
|
// auction: reader.readCell(), – TODO: still havent's figured out to load auction here
|
|
|
|
// lastFillUpTime: reader.readInt(64)
|
|
|
|
// lastFillUpTime: reader.readInt(64)
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|