Skip to content

Commit

Permalink
feat: update prod deployments for l1 contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Oct 26, 2023
1 parent 2c01c65 commit d347241
Show file tree
Hide file tree
Showing 11 changed files with 891 additions and 11 deletions.
5 changes: 5 additions & 0 deletions contracts/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ path = 'contracts/l1/bridge-v1.clar'
clarity_version = 2
epoch = 2.1

[contracts.community-handles-v2]
path = 'contracts/external/community-handles-v2.clar'
clarity_version = 2
epoch = 2.1

[repl.analysis]
passes = ['check_checker']

Expand Down
134 changes: 134 additions & 0 deletions contracts/contracts/external/community-handles-v2.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
;; @contract Community Handles
;; @version 2

(define-constant err-not-authorized (err u403))
(define-constant internal-price-high u999999999999999999999999999999)
(define-constant name-salt 0x00)
(define-fungible-token danger-zone-token)

(define-map namespace-controller (buff 20) principal)

;; variables for iteration functions
(define-data-var ctx-bulk-registration-namespace (buff 20) 0x00)

;; @desc preorder the namespace on-chain
;; @param hashed-salted-namespace; ripdem160 hash of namespace concat with salt
;; @param stx-to-burn; namespace price in ustx
(define-public (namespace-preorder (hashed-salted-namespace (buff 20)) (stx-to-burn uint))
(contract-call? 'SP000000000000000000002Q6VF78.bns
namespace-preorder hashed-salted-namespace stx-to-burn))

;; @desc reveal the namespace
;; @param namespace; namespace to register
;; @param salt; salt used during preorder
;; @param lifetime; number of blocks until a name expires
;; @param controller; optional principal set as the first namespace controller
;; defaults to contract-caller
(define-public (namespace-reveal (namespace (buff 20)) (salt (buff 20)) (lifetime uint) (controller (optional principal)))
(begin
(map-set namespace-controller namespace (default-to contract-caller controller))
(try! (contract-call? 'SP000000000000000000002Q6VF78.bns
namespace-reveal
namespace
salt
internal-price-high u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1
lifetime
(as-contract tx-sender)))
(try! (as-contract (contract-call? 'SP000000000000000000002Q6VF78.bns
namespace-ready namespace)))
(ok true)))

;; @desc register name for 1 ustx by namespace controller only
;; @param namespace; controlled namespace
;; @param name; name in the controlled namespace
;; @param zonefile-hash; hash of the attachment/zonefile for the name
;; @param owner; principal owning the name after registration
(define-public (name-register (namespace (buff 20))
(name (buff 48))
(owner principal)
(zonefile-hash (buff 20)))
(let ((hash (hash160 (concat (concat (concat name 0x2e) namespace) name-salt))))
(try! (is-contract-caller-namespace-controller namespace))
(try! (to-uint-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-preorder hash u1)))
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u1 u1))))
(try! (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-register namespace name name-salt zonefile-hash)))
(try! (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-transfer namespace name owner (some zonefile-hash))))
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace internal-price-high u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1))))
(ok true)))

;; @desc renew a name for 1 ustx by namespace controller only
;; @param namespace; controlled namespace
;; @param name; name in the controlled namespace
;; @param new-owner; optional new owner of name after renewal
;; @param zonefile-hash; optional new zonefile hash after renewal
(define-public (name-renewal (namespace (buff 20))
(name (buff 48))
(new-owner (optional principal))
(zonefile-hash (optional (buff 20))))
(let ((original-owner tx-sender))
(try! (is-contract-caller-namespace-controller namespace))
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u1 u1))))
(try! (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-renewal namespace name u1 new-owner zonefile-hash)))
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace internal-price-high u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1))))
(ok true)))


;; iterator for bulk-name-register
(define-private (bulk-name-register-iter (entry {name: (buff 48), owner: principal, zonefile-hash: (buff 20)}) (prev (response bool uint)))
(let ((namespace (var-get ctx-bulk-registration-namespace))
(name (get name entry))
(hash (hash160 (concat (concat (concat name 0x2e) namespace) name-salt))))
(try! prev)
(try! (to-uint-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-preorder hash u1)))
(try! (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-register namespace name name-salt (get zonefile-hash entry))))
(try! (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns name-transfer namespace name (get owner entry) (some (get zonefile-hash entry)))))
(ok true)))

;; @desc register multiple namens for 1 ustx by namespace controller only
;; @param namespace; controlled namespace
;; @param names; list of names with owner and hash of the attachment/zonefile for the name
(define-public (bulk-name-register (namespace (buff 20)) (names (list 1000 {name: (buff 48), owner: principal, zonefile-hash: (buff 20)})))
(begin
(try! (is-contract-caller-namespace-controller namespace))
(var-set ctx-bulk-registration-namespace namespace)
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u1 u1))))
(try! (fold bulk-name-register-iter names (ok true)))
(var-set ctx-bulk-registration-namespace 0x00)
(try! (as-contract (to-bool-response (contract-call? 'SP000000000000000000002Q6VF78.bns namespace-update-function-price namespace internal-price-high u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1 u1))))
(ok true)))

;; convert response to standard uint response with uint error
;; (response uint int) (response uint uint)
(define-private (to-uint-response (value (response uint int)))
(match value
success (ok success)
error (err (to-uint error))))

;; convert response to standard bool response with uint error
;; (response bool int) (response bool uint)
(define-private (to-bool-response (value (response bool int)))
(match value
success (ok success)
error (err (to-uint error))))

(define-private (is-contract-caller-namespace-controller (namespace (buff 20)))
(ok (asserts! (is-eq (map-get? namespace-controller namespace) (some contract-caller)) err-not-authorized)))

(define-read-only (get-namespace-controller (namespace (buff 20)))
(map-get? namespace-controller namespace))

;; @desc set new namespace controller, by current namespace owner only
;;
;; It is the responsibility of the namespace controller to
;; ensure that the new controller can manage the namespace.
;; Otherwise, it might happen that new names can NOT be registered anymore.
;;
;; @param namespace; controlled namespace by contract caller
;; @param new-controller; new namespace controller
(define-public (set-namespace-controller (namespace (buff 20)) (new-controller principal))
(begin
(try! (is-contract-caller-namespace-controller namespace))
(try! (ft-mint? danger-zone-token u1 tx-sender))
(try! (ft-burn? danger-zone-token u1 tx-sender))
(map-set namespace-controller namespace new-controller)
(ok true)))
3 changes: 0 additions & 3 deletions contracts/contracts/proposals/proposal-migrator-v2.clar
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
(try! (contract-call? .bnsx-extensions set-extensions
(list
{ extension: .wrapper-migrator-v2, enabled: true }
;; { extension: DEPLOYER, enabled: false }
;; { extension: .test-utils, enabled: false }
;; { extension: .fake-multisafe, enabled: true }
)
))

Expand Down
28 changes: 28 additions & 0 deletions contracts/deployments/default.mainnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,32 @@ plan:
anchor_block_only: false
parameters:
- "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.proposal-bootstrap"
- contract-publish:
contract-name: wrapper-migrator-v2
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 83190
path: contracts/testnet/wrapper-migrator-v2.clar
anchor-block-only: true
clarity-version: 2
- contract-publish:
contract-name: proposal-migrator-v2
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 13970
path: contracts/proposals/proposal-migrator-v2.clar
anchor-block-only: true
clarity-version: 2
- contract-publish:
contract-name: l1-registry
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 83190
path: contracts/l1/registry.clar
anchor-block-only: true
clarity-version: 2
- contract-publish:
contract-name: l1-bridge-v1
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 83190
path: contracts/l1/bridge-v1.clar
anchor-block-only: true
clarity-version: 2
epoch: "2.0"
27 changes: 27 additions & 0 deletions contracts/deployments/l1-migration.mainnet-plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
id: 0
name: Register helper - mainnet
network: mainnet
stacks-node: "https://stacks-node-api.mainnet.stacks.co"
bitcoin-node: "http://blockstack:[email protected]:8332"
plan:
batches:
- id: 0
transactions:
- contract-call:
contract-id: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.bnsx-extensions
method: execute
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 100000
anchor_block_only: false
parameters:
- "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.proposal-migrator-v2"
- "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60"
- contract-call:
contract-id: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.wrapper-migrator-v2
method: execute
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 100000
anchor_block_only: false
parameters:
- "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60"
47 changes: 47 additions & 0 deletions contracts/deployments/l1.mainnet-plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
id: 0
name: Register helper - mainnet
network: mainnet
stacks-node: "https://stacks-node-api.mainnet.stacks.co"
bitcoin-node: "http://blockstack:[email protected]:8332"
plan:
batches:
- id: 0
transactions:
- contract-publish:
contract-name: wrapper-migrator-v2
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 200000
path: contracts/wrapper-migrator-v2.clar
anchor-block-only: false
clarity-version: 2
# - contract-publish:
# contract-name: proposal-migrator-v2
# expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
# cost: 200000
# path: contracts/proposals/proposal-migrator-v2.clar
# anchor-block-only: true
# clarity-version: 2
# - contract-publish:
# contract-name: l1-registry
# expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
# cost: 200000
# path: contracts/l1/registry.clar
# anchor-block-only: true
# clarity-version: 2
- contract-publish:
contract-name: l1-bridge-v1
expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
cost: 200000
path: contracts/l1/bridge-v1.clar
anchor-block-only: false
clarity-version: 2
# - contract-call:
# contract-id: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.bnsx-extensions
# method: execute
# expected-sender: SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60
# cost: 100000
# anchor_block_only: false
# parameters:
# - "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60.proposal-migrator-v2"
# - "'SP1JTCR202ECC6333N7ZXD7MK7E3ZTEEE1MJ73C60"
84 changes: 84 additions & 0 deletions contracts/scripts/l1-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'cross-fetch/polyfill';
import { config } from 'dotenv';
import {
AnchorMode,
broadcastTransaction,
PostConditionMode,
makeContractCall,
} from 'micro-stacks/transactions';
import { c32addressDecode } from 'micro-stacks/crypto';
import {
contracts,
deployer,
getControllerAddress,
getNonce,
network,
networkKey,
} from './script-utils';
import { bytesToHex, hexToBytes } from 'micro-stacks/common';

const migrator = contracts.wrapperMigrator;

config();

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const privateKey = process.env.DEPLOYER_KEY!;

const [signer] = process.argv.slice(2);

async function run() {
console.log('Network:', networkKey);
console.log('Signer:', signer);
console.log('Migrator:', migrator.identifier);
const controller = getControllerAddress(privateKey);
console.log('Controller:', controller);
console.log('Deployer:', deployer);

const nonce = await getNonce();

const proposalTx = await makeContractCall({
...contracts.bnsxExtensions.execute(contracts.proposalMigratorV2.identifier, controller),
nonce,
fee: 100000,
network,
senderKey: privateKey,
anchorMode: AnchorMode.Any,
});

const migratorTx = await makeContractCall({
...contracts.wrapperMigratorV2.setSigners([
{
signer,
enabled: true,
},
]),
nonce: nonce + 1,
fee: 100000,
network,
senderKey: privateKey,
anchorMode: AnchorMode.Any,
});

const bridgeTx = await makeContractCall({
...contracts.l1BridgeV1.updateSigner(signer),
nonce: nonce + 2,
fee: 100000,
network,
senderKey: privateKey,
anchorMode: AnchorMode.Any,
});

if (networkKey !== 'devnet') {
throw 'Safe exit';
}

console.log(await broadcastTransaction(proposalTx, network));
console.log(await broadcastTransaction(migratorTx, network));
console.log(await broadcastTransaction(bridgeTx, network));
}

run()
.catch(console.error)
.finally(() => {
process.exit();
});
12 changes: 12 additions & 0 deletions contracts/scripts/script-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'cross-fetch/polyfill';
import { config } from 'dotenv';
config();
import { project, contracts as _contracts } from '@bns-x/core';
import { projectFactory, contractFactory } from '@clarigen/core';
import type { StacksNetwork } from 'micro-stacks/network';
import { StacksMainnet, StacksMocknet, StacksTestnet } from 'micro-stacks/network';
import { privateKeyToStxAddress, StacksNetworkVersion } from 'micro-stacks/crypto';
import { fetchAccountNonces } from 'micro-stacks/api';

export let networkKey: 'devnet' | 'testnet' | 'mainnet' = 'devnet';
export let network: StacksNetwork = new StacksMocknet({
Expand Down Expand Up @@ -44,3 +47,12 @@ export function getControllerAddress(privateKey: string) {
}
return privateKeyToStxAddress(privateKey, version, false);
}

export async function getNonce() {
const nonces = await fetchAccountNonces({
url: network.getCoreApiUrl(),
// principal: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
principal: deployer,
});
return nonces.possible_next_nonce;
}
Loading

0 comments on commit d347241

Please sign in to comment.