-
Notifications
You must be signed in to change notification settings - Fork 34
/
ownership.ts
191 lines (149 loc) · 8.26 KB
/
ownership.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import ora from "ora"
import chalk from "chalk"
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"
import { GasPrice } from "@cosmjs/stargate";
import { getChainConfig } from "./lighthouse"
import inquirer from "inquirer"
import { Command } from "commander";
export const command_ownership = (root: Command) => {
root
.command("update-lighthouse-admin")
.description("Change the admin of a collection in Lighthouse Core. Will give the new admin full control over the collections lighthouse configuration.")
.argument("<collection>")
.argument("<new_admin>")
.option("-g --gas-price <gas_price>", "Gas price to use for transaction (default: 0.1)")
.action(async (collection, admin, options) => {
let { wallet, lighthouse, rpc_wasm } = await getChainConfig(true)
const [firstAccount] = await wallet.getAccounts()
const client = await SigningCosmWasmClient.connectWithSigner(rpc_wasm, wallet, {
gasPrice: GasPrice.fromString(options.gasPrice ? options.gasPrice + "usei" : "0.1usei")
})
//confirm
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'Are you sure you want to update the lighthouse admin of collection ' + collection + ' to ' + admin + '?',
default: false
}])
if (!answers.confirm) {
console.log("Exiting")
return
}
let spinner = ora("Updating admin of collection").start()
const Msg = {
update_admin: { collection, admin }
}
const txReceipt = await client.execute(firstAccount.address, lighthouse, Msg, "auto", "",)
spinner.succeed("Admin of collection " + collection + " updated to " + admin)
console.log("Transaction hash: " + chalk.green(txReceipt.transactionHash))
})
root
.command("transfer-cw-ownable-ownership")
.description("Transfer all CW-Ownable rights of a collection to a new address. Transfer proposal will be sent to the new owner. (CW721 and CW404 collections only) Lighthouse Core should be the owner of the collection to execute this command.")
.argument("<collection>")
.argument("<new_owner>")
.option("-g --gas-price <gas_price>", "Gas price to use for transaction (default: 0.1)")
.action(async (collection, admin, options) => {
let { wallet, lighthouse, rpc_wasm } = await getChainConfig(true)
const [firstAccount] = await wallet.getAccounts()
const client = await SigningCosmWasmClient.connectWithSigner(rpc_wasm, wallet, {
gasPrice: GasPrice.fromString(options.gasPrice ? options.gasPrice + "usei" : "0.1usei")
})
const collectionData = await client.queryContractSmart(lighthouse, { get_collection: { collection } })
//confirm
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'Are you sure you want to transfer the owner rights of collection ' + collection + ' to ' + admin + '?',
default: false
}])
if (!answers.confirm) {
console.log("Exiting")
return
}
let spinner = ora("Transferring ownership of collection").start()
const Msg = {
update_nft_contract_owner: { collection, new_admin: admin }
}
const txReceipt = await client.execute(firstAccount.address, lighthouse, Msg, "auto", "",)
if (collectionData.chain === "v2") {
spinner.succeed("Updated Minter role of collection " + collection + " to " + admin)
} else {
spinner.succeed("Ownership proposal sent to " + admin + " for collection " + collection)
}
console.log("Transaction hash: " + chalk.green(txReceipt.transactionHash))
})
root
.command("accept-cw-ownable-ownership")
.description("Accept the CW-Ownable ownership proposal for a collection")
.argument("<collection>")
.option("-g --gas-price <gas_price>", "Gas price to use for transaction (default: 0.1)")
.action(async (collection, options) => {
let { wallet, lighthouse, rpc_wasm } = await getChainConfig(true)
const [firstAccount] = await wallet.getAccounts()
const client = await SigningCosmWasmClient.connectWithSigner(rpc_wasm, wallet, {
gasPrice: GasPrice.fromString(options.gasPrice ? options.gasPrice + "usei" : "0.1usei")
})
const collectionData = await client.queryContractSmart(lighthouse, { get_collection: { collection } })
if (collectionData.chain === "v2") {
console.log("Accept ownership is not available for EVM collections")
return
}
//confirm
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'Are you sure you want to accept the ownership transfer request for collection ' + collection + '?',
default: false
}])
if (!answers.confirm) {
console.log("Exiting")
return
}
let spinner = ora("Accepting ownership transfer request").start()
const Msg = collectionData.collection_type === "404" ? {
accept_ownership: {}
} : {
update_ownership: { accept_ownership: {} }
}
const txReceipt = await client.execute(firstAccount.address, collection, Msg, "auto", "",)
spinner.succeed("Ownership of collection " + collection + " transferred to you")
console.log("Transaction hash: " + chalk.green(txReceipt.transactionHash))
})
root
.command("update-nft-contract-admin")
.description("Transfer contract admin rights of a collection to a new address. New owner can migrate and alter the collection code. For ERC721 collections, Minter role will be transferred to the new owner. Lighthouse Core should be the owner of the collection to execute this command.")
.argument("<collection>")
.argument("<new_owner>")
.option("-g --gas-price <gas_price>", "Gas price to use for transaction (default: 0.1)")
.action(async (collection, admin, options) => {
let { wallet, lighthouse, rpc_wasm } = await getChainConfig(true)
const [firstAccount] = await wallet.getAccounts()
const client = await SigningCosmWasmClient.connectWithSigner(rpc_wasm, wallet, {
gasPrice: GasPrice.fromString(options.gasPrice ? options.gasPrice + "usei" : "0.1usei")
})
const collectionData = await client.queryContractSmart(lighthouse, { get_collection: { collection } })
//confirm
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'Are you sure you want to transfer the admin rights of collection ' + collection + ' to ' + admin + '?',
default: false
}])
if (!answers.confirm) {
console.log("Exiting")
return
}
let spinner = ora("Transferring admin rights of collection").start()
const Msg = {
update_nft_contract_admin: { collection, new_admin: admin }
}
const txReceipt = await client.execute(firstAccount.address, lighthouse, Msg, "auto", "",)
if (collectionData.chain === "v2") {
spinner.succeed("Updated Minter role of collection " + collection + " to " + admin)
} else {
spinner.succeed("Admin of collection " + collection + " transferred to " + admin)
}
console.log("Transaction hash: " + chalk.green(txReceipt.transactionHash))
})
}