igor
2 years ago
6 changed files with 96 additions and 86 deletions
@ -0,0 +1,3 @@
|
||||
[submodule "contracts/dns-contract"] |
||||
path = contracts/dns-contract |
||||
url = https://github.com/ton-blockchain/dns-contract.git |
@ -1,32 +1,57 @@
|
||||
import BN from "bn.js"; |
||||
import { Cell, beginCell, Address } from "ton"; |
||||
import { C7Config, SmartContract } from "ton-contract-executor"; |
||||
import {encodeOffChainContent, makeSnakeCell} from "./utils"; |
||||
|
||||
// encode contract storage according to save_data() contract method
|
||||
|
||||
// collection_content:^Cell
|
||||
// nft_item_code:^Cell
|
||||
// uint256 index
|
||||
// MsgAddressInt collection_address
|
||||
// MsgAddressInt owner_address
|
||||
// collection_content:^Cell
|
||||
// cell domain - e.g contains "alice" (without ending \0) for "alice.ton" domain
|
||||
// cell auction - auction info
|
||||
// int last_fill_up_time
|
||||
// int64 last_fill_up_time
|
||||
export function data(params: { ownerAddress: Address; collectionAddress: Address, code: Cell, domain: String }): Cell { |
||||
return beginCell() |
||||
.storeRef(encodeOffChainContent("https://agorata.io/collection.json")) // https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md
|
||||
// For code: https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-auction/build.sh
|
||||
.storeRef(params.code) |
||||
.storeUint8(0) |
||||
.storeAddress(params.collectionAddress) |
||||
.storeAddress(params.ownerAddress) |
||||
.storeRef(makeSnakeCell(Buffer.from(params.domain))) |
||||
.storeRef(beginCell().endCell()) |
||||
.storeUint(0, 64).endCell(); |
||||
// For code: https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-auction/build.sh
|
||||
.storeRef(params.code) |
||||
.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(makeSnakeCell(Buffer.from(params.domain))) |
||||
.storeDict(null) |
||||
.storeUint(0, 64).endCell(); |
||||
} |
||||
|
||||
export function auctionWithWinner(winnerAddress: Address) { |
||||
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) |
||||
} |
||||
|
||||
export function setContractBalance(contract: SmartContract, balance: number) { |
||||
contract.setC7Config({balance: balance}); |
||||
} |
||||
|
||||
export function TON(): number { return 1000000000; } |
||||
|
||||
// message encoders for all ops (see contracts/imports/constants.fc for consts)
|
||||
|
||||
export function transferOwnership(params: { newOwnerAddress: Address }): Cell { |
||||
return beginCell().storeUint(0x2da38aaf, 32).storeUint(0, 64).storeAddress(params.newOwnerAddress).endCell(); |
||||
return beginCell().storeUint(0x5fcc3d14, 32).storeUint(0, 64).storeAddress(params.newOwnerAddress).storeAddress(null).storeInt(0, 1).storeCoins(1 * TON()).endCell(); |
||||
} |
||||
|
||||
export function currentState(contract: SmartContract) { |
||||
let reader = contract.dataCell.beginParse(); |
||||
return { |
||||
nft_item_code: reader.readRef(), |
||||
index: reader.readUint(256), |
||||
collectionAddress: reader.readAddress(), |
||||
ownerAddress: reader.readAddress(), |
||||
collectionContent: reader.readRef(), |
||||
domain: reader.readRef(), |
||||
// auction: reader.readCell(), – TODO: still havent's figured out to load auction here
|
||||
// lastFillUpTime: reader.readInt(64)
|
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue