Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add-initial-regtest-prototype #19

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ lib-cov
*.seed
*.log
*.csv
*.tsv
*.dat
*.out
*.pid
*.gz
*.swp
*.bak

pids
logs
Expand Down
5,288 changes: 3,853 additions & 1,435 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
},
"dependencies": {
"@hirosystems/api-toolkit": "^1.3.3",
"@scure/btc-signer": "^1.2.1",
"@sinclair/typebox": "^0.32.12",
"@stacks/blockchain-api-client": "^7.8.1",
"@stacks/network": "^6.10.0",
"@stacks/transactions": "^6.11.2",
"@stacks/common": "^6.13.0",
"@stacks/network": "^6.13.0",
"@stacks/stacking": "^6.13.0",
"@stacks/transactions": "^6.13.0",
"@stacks/wallet-sdk": "^6.13.0",
"@types/node": "^20.11.5",
"env-schema": "^5.2.1"
}
Expand Down
96 changes: 96 additions & 0 deletions src/contracts/pox-4-wrapper.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
(define-public (disallow-contract-caller (caller principal))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 disallow-contract-caller caller))

(define-public (allow-contract-caller (caller principal) (until-burn-ht (optional uint)))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 allow-contract-caller caller until-burn-ht))

(define-public (stack-stx (amount-ustx uint)
(pox-addr (tuple (version (buff 1)) (hashbytes (buff 32))))
(start-burn-ht uint)
(lock-period uint)
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-stx amount-ustx pox-addr start-burn-ht lock-period signer-sig signer-key max-amount auth-id))

(define-public (revoke-delegate-stx)
(contract-call? 'ST000000000000000000002AMW42H.pox-4 revoke-delegate-stx))

(define-public (delegate-stx (amount-ustx uint)
(delegate-to principal)
(until-burn-ht (optional uint))
(pox-addr (optional { version: (buff 1), hashbytes: (buff 32) })))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 delegate-stx amount-ustx delegate-to until-burn-ht pox-addr))


(define-public (stack-aggregation-commit (pox-addr { version: (buff 1), hashbytes: (buff 32) })
(reward-cycle uint)
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-aggregation-commit pox-addr reward-cycle signer-sig signer-key max-amount auth-id))

(define-public (stack-aggregation-commit-indexed (pox-addr { version: (buff 1), hashbytes: (buff 32) })
(reward-cycle uint)
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-aggregation-commit-indexed pox-addr reward-cycle signer-sig signer-key max-amount auth-id))

(define-public (stack-aggregation-increase (pox-addr { version: (buff 1), hashbytes: (buff 32) })
(reward-cycle uint)
(reward-cycle-index uint)
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-aggregation-increase pox-addr reward-cycle reward-cycle-index signer-sig signer-key max-amount auth-id))

(define-public (delegate-stack-stx (stacker principal)
(amount-ustx uint)
(pox-addr { version: (buff 1), hashbytes: (buff 32) })
(start-burn-ht uint)
(lock-period uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 delegate-stack-stx stacker amount-ustx pox-addr start-burn-ht lock-period))

(define-public (stack-increase
(increase-by uint)
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-increase increase-by signer-sig signer-key max-amount auth-id))

(define-public (stack-extend (extend-count uint)
(pox-addr { version: (buff 1), hashbytes: (buff 32) })
(signer-sig (optional (buff 65)))
(signer-key (buff 33))
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 stack-extend extend-count pox-addr signer-sig signer-key max-amount auth-id))

(define-public (delegate-stack-increase
(stacker principal)
(pox-addr { version: (buff 1), hashbytes: (buff 32) })
(increase-by uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 delegate-stack-increase stacker pox-addr increase-by))

(define-public (delegate-stack-extend
(stacker principal)
(pox-addr { version: (buff 1), hashbytes: (buff 32) })
(extend-count uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 delegate-stack-extend stacker pox-addr extend-count))


(define-public (set-signer-key-authorization (pox-addr { version: (buff 1), hashbytes: (buff 32)})
(period uint)
(reward-cycle uint)
(topic (string-ascii 14))
(signer-key (buff 33))
(allowed bool)
(max-amount uint)
(auth-id uint))
(contract-call? 'ST000000000000000000002AMW42H.pox-4 set-signer-key-authorization pox-addr period reward-cycle topic signer-key allowed max-amount auth-id))
60 changes: 48 additions & 12 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,61 @@ import envSchema from 'env-schema';

const schema = Type.Object({
STACKS_CHAIN: Type.Enum({ mainnet: 'mainnet', testnet: 'testnet' }),
/* STX address of the issuer of all transactions we will be testing */
/** STX address of the issuer of all transactions we will be testing */
SENDER_STX_ADDRESS: Type.String(),
/* `SENDER_STX_ADDRESS`'s hex private key */
/** `SENDER_STX_ADDRESS`'s hex private key */
SENDER_KEY: Type.String(),
/* STX address of the receiver of any sent tokens */
/** STX address of the receiver of any sent tokens */
RECEIVER_STX_ADDRESS: Type.String(),

/* Stacks Blockchain API host */
STACKS_API_HOST: Type.String(),
/* Stacks Blockchain API port */
STACKS_API_PORT: Type.Integer(),
/* Stacks node host */
STACKS_NODE_HOST: Type.String(),
/* Stacks node port */
STACKS_NODE_PORT: Type.Integer(),
/** Stacks Blockchain API host */
STACKS_API: Type.String(),

/** Stacks node host */
STACKS_NODE: Type.String(),

STACKS_TX_TIMEOUT: Type.Integer({ default: 15_000 }),

POLL_INTERVAL: Type.Integer({ default: 1000 }),
RETRY_INTERVAL: Type.Integer({ default: 500 }),

/** List of pre-funded STX addresses on regtest-env */
REGTEST_KEYS: Type.Array(Type.String(), {
default: [
// taken from regtest-env `stacks-kryton-miner.toml`
'cb3df38053d132895220b9ce471f6b676db5b9bf0b4adefb55f2118ece2478df01',
'21d43d2ae0da1d9d04cfcaac7d397a33733881081f0b2cd038062cf0ccbb752601',
'5b8303150239eceaba43892af7cdd1fa7fc26eda5182ebaaa568e3341d54a4d001',
],
}),
/**
* Signer private key for generating signatures.
* On regtest-env, this should be the private key of a participating signer.
*/
SIGNER_KEY: Type.String({
default: '7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01',
}),

/**
* Command to run to start regtest-env.
* e.g. this could `cd` into the regtest-env directory and run `docker compose up -d`
*/
REGTEST_UP_CMD: Type.String({ default: "echo 'no-op'" }),
/**
* Command to run to stop regtest-env.
* e.g. this could `cd` into the regtest-env directory and run `docker compose down`
*/
REGTEST_DOWN_CMD: Type.String({ default: "echo 'no-op'" }),

/**
* If true, doesn't wait for unlock and verifying rewards in regtest tests.
* Useful for speeding up tests when running many long-running regtest-env tests
*/
REGTEST_SKIP_UNLOCK: Type.Boolean({ default: false }),
});
type Env = Static<typeof schema>;

export const ENV = envSchema<Env>({
schema: schema,
dotenv: true,
schema,
});
Loading