moved lisa-rebase/rebase-1 into lqstx-mint-endpoint

This commit is contained in:
fiftyeightandeight
2024-03-24 11:08:28 +08:00
parent d3028d3b96
commit b048e18781
13 changed files with 56 additions and 48 deletions

View File

@@ -62,7 +62,6 @@ are in the form `(err uint)` and they are unique across all contracts.
| li-stx-burn-nft | err-unauthorised | (err u3000) | |
| li-stx-mint-nft | err-unauthorised | (err u3000) | |
| lisa-rebase | err-unauthorised | (err u3000) | |
| lisa-rebase-v1-02 | err-unauthorised | (err u3000) | |
| lqstx-mint-endpoint-v1-02 | err-unauthorised | (err u3000) | |
| public-pools-strategy-manager | err-unauthorised | (err u3000) | |
| token-lisa | err-unauthorised | (err u3000) | |

View File

@@ -26,7 +26,7 @@
(define-data-var mint-delay uint u432) ;; mint available 3 day after cycle starts
;; __IF_MAINNET__
(define-constant pox-info (unwrap-panic (contract-call? 'ST000000000000000000002AMW42H.pox-3 get-pox-info)))
(define-constant pox-info (unwrap-panic (contract-call? 'SP000000000000000000002Q6VF78.pox-3 get-pox-info)))
(define-constant activation-burn-block (get first-burnchain-block-height pox-info))
(define-constant reward-cycle-length (get reward-cycle-length pox-info))
(define-constant prepare-cycle-length (get prepare-cycle-length pox-info))

View File

@@ -83,14 +83,14 @@
;; @dev used for testing only
(define-read-only (get-reward-cycle (stacks-height uint))
;; (some (contract-call? 'ST000000000000000000002AMW42H.pox-3 current-pox-reward-cycle)))
;; (some (contract-call? 'SP000000000000000000002Q6VF78.pox-3 current-pox-reward-cycle)))
(if (>= stacks-height (var-get activation-block))
(some (/ (- stacks-height (var-get activation-block)) (var-get reward-cycle-length)))
none))
;; @dev used for testing only
(define-read-only (get-first-stacks-block-in-reward-cycle (reward-cycle uint))
;; (contract-call? 'ST000000000000000000002AMW42H.pox-3 reward-cycle-to-burn-height reward-cycle))
;; (contract-call? 'SP000000000000000000002Q6VF78.pox-3 reward-cycle-to-burn-height reward-cycle))
(+ (var-get activation-block) (* (var-get reward-cycle-length) reward-cycle)))
(define-read-only (get-mint-delay)

View File

@@ -29,7 +29,7 @@
;; __IF_MAINNET__
(define-data-var request-cutoff uint u300) ;; request must be made 300 blocks before prepare stage starts
(define-constant pox-info (unwrap-panic (contract-call? 'ST000000000000000000002AMW42H.pox-3 get-pox-info)))
(define-constant pox-info (unwrap-panic (contract-call? 'SP000000000000000000002Q6VF78.pox-3 get-pox-info)))
(define-constant activation-burn-block (get first-burnchain-block-height pox-info))
(define-constant reward-cycle-length (get reward-cycle-length pox-info))
(define-constant prepare-cycle-length (get prepare-cycle-length pox-info))
@@ -123,16 +123,14 @@
(define-public (rebase)
(let (
;; (total-stx (- (+ (stx-get-balance .lqstx-vault) (try! (fold sum-strategy-amounts (list .public-pools-strategy) (ok u0)))) (get-mint-requests-pending-amount))))
(available-stx (stx-get-balance .lqstx-vault))
;; __IF_MAINNET__
(deployed-stx (unwrap-panic (contract-call? .public-pools-strategy get-amount-in-strategy)))
;; (deployed-stx (unwrap-panic (contract-call? .mock-strategy get-amount-in-strategy)))
;; __ENDIF__
(pending-stx (get-mint-requests-pending-amount))
(check-stx (asserts! (>= (+ available-stx deployed-stx) pending-stx) (err deployed-stx)))
(total-stx (- (+ available-stx deployed-stx) pending-stx)))
(as-contract (try! (contract-call? .token-lqstx set-reserve total-stx)))
(try! (contract-call? .token-lqstx set-reserve total-stx))
(ok total-stx)))
;; @dev the requestor stx is held by the contract until mint can be finalized.
@@ -147,7 +145,7 @@
(asserts! (is-whitelisted-or-mint-for-all sender) err-not-whitelisted)
(try! (stx-transfer? amount sender .lqstx-vault))
(try! (contract-call? .lqstx-mint-registry set-mint-requests-pending-amount (+ (get-mint-requests-pending-amount) amount)))
;; (try! (contract-call? .li-stx-mint-nft mint request-id amount sender))
(try! (contract-call? .li-stx-mint-nft mint request-id amount sender))
(try! (rebase))
(print { type: "mint-request", id: request-id, details: request-details })
(ok request-id)))
@@ -163,7 +161,7 @@
(try! (contract-call? .lqstx-vault proxy-call .stx-transfer-proxy (unwrap-panic (to-consensus-buff? { ustx: (get amount request-details), recipient: recipient }))))
(try! (contract-call? .lqstx-mint-registry set-mint-request request-id (merge request-details { status: REVOKED })))
(try! (contract-call? .lqstx-mint-registry set-mint-requests-pending-amount (- (get-mint-requests-pending-amount) (get amount request-details))))
(as-contract (try! (contract-call? .li-stx-mint-nft burn request-id)))
(try! (contract-call? .li-stx-mint-nft burn request-id))
(try! (rebase))
(ok true)))
@@ -179,16 +177,16 @@
(print { type: "burn-request", id: request-id, details: request-details })
(if (>= (stx-get-balance .lqstx-vault) amount)
(begin
(as-contract (try! (contract-call? .token-lqstx dao-burn amount sender)))
(as-contract (try! (contract-call? .lqstx-vault proxy-call .stx-transfer-proxy (unwrap-panic (to-consensus-buff? { ustx: amount, recipient: sender })))))
(as-contract (try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: FINALIZED }))))
(try! (contract-call? .token-lqstx dao-burn amount sender))
(try! (contract-call? .lqstx-vault proxy-call .stx-transfer-proxy (unwrap-panic (to-consensus-buff? { ustx: amount, recipient: sender }))))
(try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: FINALIZED })))
(try! (rebase))
(ok {request-id: request-id, status: FINALIZED })
)
(begin
(try! (contract-call? .token-vlqstx mint amount sender))
(try! (contract-call? .token-vlqstx transfer vlqstx-amount sender .lqstx-mint-registry none))
(as-contract (try! (contract-call? .li-stx-burn-nft mint request-id amount sender)))
(try! (contract-call? .li-stx-burn-nft mint request-id amount sender))
(try! (rebase))
(ok { request-id: request-id, status: PENDING })))))
@@ -201,10 +199,10 @@
(try! (is-not-paused-or-fail))
(asserts! (is-eq PENDING (get status request-details)) err-request-finalized-or-revoked)
(asserts! (is-eq tx-sender recipient) err-unauthorised)
(as-contract (try! (contract-call? .lqstx-mint-registry transfer (get wrapped-amount request-details) recipient .token-vlqstx)))
(try! (contract-call? .lqstx-mint-registry transfer (get wrapped-amount request-details) recipient .token-vlqstx))
(try! (contract-call? .token-vlqstx burn (get wrapped-amount request-details) recipient))
(as-contract (try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: REVOKED }))))
(as-contract (try! (contract-call? .li-stx-burn-nft burn request-id)))
(try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: REVOKED })))
(try! (contract-call? .li-stx-burn-nft burn request-id))
(try! (rebase))
(ok true)))
@@ -215,10 +213,10 @@
(recipient (unwrap! (unwrap-panic (get-owner-mint-nft request-id)) err-request-finalized-or-revoked)))
(try! (validate-mint-request request-id))
(try! (is-not-paused-or-fail))
(as-contract (try! (contract-call? .token-lqstx dao-mint (get amount request-details) recipient)))
(as-contract (try! (contract-call? .lqstx-mint-registry set-mint-request request-id (merge request-details { status: FINALIZED }))))
(as-contract (try! (contract-call? .lqstx-mint-registry set-mint-requests-pending-amount (- (get-mint-requests-pending-amount) (get amount request-details)))))
(as-contract (try! (contract-call? .li-stx-mint-nft burn request-id)))
(try! (contract-call? .token-lqstx dao-mint (get amount request-details) recipient))
(try! (contract-call? .lqstx-mint-registry set-mint-request request-id (merge request-details { status: FINALIZED })))
(try! (contract-call? .lqstx-mint-registry set-mint-requests-pending-amount (- (get-mint-requests-pending-amount) (get amount request-details))))
(try! (contract-call? .li-stx-mint-nft burn request-id))
(try! (rebase))
(ok true)))
@@ -229,15 +227,15 @@
(let (
(rebase-first (try! (rebase)))
(request-details (try! (get-burn-request-or-fail request-id)))
(transfer-vlqstx (as-contract (try! (contract-call? .lqstx-mint-registry transfer (get wrapped-amount request-details) tx-sender .token-vlqstx))))
(transfer-vlqstx (try! (contract-call? .lqstx-mint-registry transfer (get wrapped-amount request-details) (as-contract tx-sender) .token-vlqstx)))
(recipient (unwrap! (unwrap-panic (get-owner-burn-nft request-id)) err-request-finalized-or-revoked))
(validation-data (try! (validate-burn-request request-id))))
(try! (is-not-paused-or-fail))
(as-contract (try! (contract-call? .token-vlqstx burn (get wrapped-amount request-details) tx-sender)))
(as-contract (try! (contract-call? .token-lqstx dao-burn (get vaulted-amount validation-data) tx-sender)))
(as-contract (try! (contract-call? .lqstx-vault proxy-call .stx-transfer-proxy (unwrap-panic (to-consensus-buff? { ustx: (get vaulted-amount validation-data), recipient: recipient })))))
(as-contract (try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: FINALIZED }))))
(as-contract (try! (contract-call? .li-stx-burn-nft burn request-id)))
(try! (contract-call? .token-vlqstx burn (get wrapped-amount request-details) (as-contract tx-sender)))
(try! (contract-call? .token-lqstx dao-burn (get vaulted-amount validation-data) (as-contract tx-sender)))
(try! (contract-call? .lqstx-vault proxy-call .stx-transfer-proxy (unwrap-panic (to-consensus-buff? { ustx: (get vaulted-amount validation-data), recipient: recipient }))))
(try! (contract-call? .lqstx-mint-registry set-burn-request request-id (merge request-details { status: FINALIZED })))
(try! (contract-call? .li-stx-burn-nft burn request-id))
(try! (rebase))
(ok true)))

View File

@@ -24,14 +24,16 @@
)))
(try! (contract-call? .operators set-proposal-threshold 2))
;; Set initial strategy managers, sender is the deployer
(try! (contract-call? .public-pools-strategy-manager set-authorised-manager sender true))
;; Mint max LISA token supply (1bn)
(try! (contract-call? .token-lisa dao-mint-many (list
{ recipient: .treasury, amount: u1000000000000000 }
)))
;; Set initial strategy managers, sender is the deployer
(try! (contract-call? .public-pools-strategy-manager set-authorised-manager sender true))
(try! (contract-call? .public-pools-strategy-manager set-authorised-manager 'ST2QXSK64YQX3CQPC530K79XWQ98XFAM9W3XKEH3N true))
(try! (contract-call? .public-pools-strategy-manager set-authorised-manager 'ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND true))
(try! (contract-call? .lqstx-mint-endpoint-v1-02 set-paused false))
(ok true)
)

View File

@@ -3,7 +3,7 @@
(define-constant err-unauthorised (err u5000))
(as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 allow-contract-caller 'SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.pox-fast-pool-v2 none))
(as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-3 allow-contract-caller 'SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP.pox-fast-pool-v2 none))
(define-read-only (is-strategy-caller)
(ok (asserts! (is-eq contract-caller .public-pools-strategy) err-unauthorised))
@@ -20,7 +20,7 @@
(define-public (revoke-delegate-stx)
(begin
(try! (is-strategy-caller))
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 revoke-delegate-stx))
(match (as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-3 revoke-delegate-stx))
ok-val (ok ok-val)
err-val (err (to-uint err-val))
)

View File

@@ -8,7 +8,7 @@
{ hashbytes: 0x827a04335a9eb22cb46979f180670c8e7ba453b5, version: 0x04 }
)
(as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 allow-contract-caller 'SP001SFSMC2ZY76PD4M68P3WGX154XCH7NE3TYMX.pox-pools-1-cycle-v2 none))
(as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-3 allow-contract-caller 'SP001SFSMC2ZY76PD4M68P3WGX154XCH7NE3TYMX.pox-pools-1-cycle-v2 none))
(define-read-only (is-dao-or-extension)
(ok (asserts! (or (is-eq tx-sender .lisa-dao) (contract-call? .lisa-dao is-extension contract-caller)) err-unauthorised))
@@ -37,7 +37,7 @@
(define-public (revoke-delegate-stx)
(begin
(try! (is-strategy-caller))
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 revoke-delegate-stx))
(match (as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-3 revoke-delegate-stx))
ok-val (ok ok-val)
err-val (err (to-uint err-val))
)

View File

@@ -13,7 +13,7 @@
"multisig-analyse": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/analyse-multisig-deployment-plan.ts",
"get-keys": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/get-secret-pubkeys.ts",
"generate-secret": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/generate-secret.ts",
"error-codes": "node --no-warnings=ExperimentalWarning --loader ts-node/esm --import=./scripts/logErrors.js ./scripts/error-codes.ts",
"error-codes": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/error-codes.ts",
"replace:mainnet": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/replace-mainnet-address.ts",
"replace:testnet": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./scripts/replace-testnet-address.ts",
"setup:clarity": "./scripts/clarinet_manager.sh clean && ./scripts/clarinet_manager.sh install",

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
import { initSimnet } from '@hirosystems/clarinet-sdk';
import { createErrorsTable } from './lib/error-codes.ts';
const manifestFile = './Clarinet.toml';
const simnet = await initSimnet(manifestFile);

View File

@@ -1,6 +1,6 @@
import { tx } from '@hirosystems/clarinet-sdk';
import { IntegerType } from '@stacks/common';
import { BufferCV, Cl, ResponseOkCV, UIntCV } from '@stacks/transactions';
import { Cl, ResponseOkCV, UIntCV } from '@stacks/transactions';
export const createClientMockSetup = () => {
const accounts = simnet.getAccounts();

View File

@@ -4,7 +4,7 @@ import { Cl } from '@stacks/transactions';
import { describe, expect, it } from 'vitest';
import { createClientMockSetup } from './clients/mock-client';
const { contracts, prepareTest, requestMint, requestBurn, goToNextCycle, liSTXBalance, user, bot } =
const { contracts, prepareTest, requestMint, requestBurn, goToNextCycle, liSTXBalance, goToNextRequestCycle, fundStrategy, user, bot } =
createClientMockSetup();
const mintDelay = 14;
@@ -31,15 +31,16 @@ describe('LiSTX NFT', () => {
it('user can transfer nft before finalize mint', () => {
prepareTest().map((e: any) => expect(e.result).toBeOk(Cl.bool(true)));
let response = requestMint(100e6);
console.log(response.events);
expect(response.result).toBeOk(Cl.uint(1));
// transfer nft to bot
response = transferMintNFT(1, bot);
expect(response.result).toBeOk(Cl.bool(true));
// finalize mint
goToNextRequestCycle();
expect(fundStrategy(100e6).result).toBeOk(Cl.uint(100e6));
goToNextCycle();
simnet.mineEmptyBlocks(mintDelay);
simnet.mineEmptyBlocks(mintDelay + 1);
simnet.callPublicFn(contracts.endpoint, 'finalize-mint', [Cl.uint(1)], bot);
// check that bot received liquid stx
@@ -71,8 +72,10 @@ describe('LiSTX NFT', () => {
// request and finalize mint
response = requestMint(100e6);
expect(response.result).toBeOk(Cl.uint(1));
goToNextRequestCycle();
expect(fundStrategy(1e6).result).toBeOk(Cl.uint(1e6));
goToNextCycle();
simnet.mineEmptyBlocks(mintDelay);
simnet.mineEmptyBlocks(mintDelay + 1);
response = simnet.callPublicFn(contracts.endpoint, 'finalize-mint', [Cl.uint(1)], bot);
expect(response.result).toBeOk(Cl.bool(true));
@@ -81,7 +84,7 @@ describe('LiSTX NFT', () => {
expect(response.result).toBeOk(
Cl.tuple({ 'request-id': Cl.uint(1), status: Cl.bufferFromHex('01') })
);
response = requestBurn(40e6);
response = requestBurn(39e6);
expect(response.result).toBeOk(
Cl.tuple({ 'request-id': Cl.uint(2), status: Cl.bufferFromHex('01') })
);
@@ -98,6 +101,6 @@ describe('LiSTX NFT', () => {
// check that bot received stx
expect(simnet.getAssetsMap().get('STX')?.get(bot)).toBe(100000000000000n);
expect(simnet.getAssetsMap().get('STX')?.get(user)).toBe(100000000000000n);
expect(simnet.getAssetsMap().get('STX')?.get(user)).toBe(99999999000000n);
});
});

View File

@@ -11,6 +11,7 @@ const { contracts, user, user2, oracle, bot, manager,
// 1m STX
const mintAmount = 1_000_000e6;
const mintDelay = 432;
describe(contracts.endpoint, () => {
@@ -87,7 +88,7 @@ describe(contracts.endpoint, () => {
simnet.mineEmptyBlocks(mintDelay + 1);
expect(finalizeMint(1).result).toBeOk(Cl.bool(true));
expect(requestBurn(mintAmount).result).toBeOk(
expect(requestBurn(1e6).result).toBeOk(
Cl.tuple({ 'request-id': Cl.uint(1), status: Cl.bufferFromHex('00') })
);

View File

@@ -2,16 +2,20 @@ import { Cl } from '@stacks/transactions';
import { beforeEach, describe, expect } from 'vitest';
import { createClientMockSetup } from './clients/mock-client';
import { sip10Tests } from './clients/sip10-client.ts';
const { goToNextCycle, requestMint, prepareTest, contracts, bot } = createClientMockSetup();
const { goToNextCycle, goToNextRequestCycle, fundStrategy, requestMint, prepareTest, contracts, bot } = createClientMockSetup();
const mintDelay = 14;
describe('lisa token', () => {
beforeEach(() => {
prepareTest().map(r => expect(r.result).toBeOk(Cl.bool(true)));
requestMint(100e6);
let response = requestMint(100e6);
expect(response.result).toBeOk(Cl.uint(1));
goToNextRequestCycle();
expect(fundStrategy(1e6).result).toBeOk(Cl.uint(1e6));
goToNextCycle();
simnet.mineEmptyBlocks(mintDelay);
simnet.callPublicFn(contracts.endpoint, 'finalize-mint', [Cl.uint(1)], bot);
simnet.mineEmptyBlocks(mintDelay + 1);
response = simnet.callPublicFn(contracts.endpoint, 'finalize-mint', [Cl.uint(1)], bot);
expect(response.result).toBeOk(Cl.bool(true));
});
sip10Tests(contracts.lqstx);