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

Updated Clarity Maps #848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 26 additions & 5 deletions contracts/contracts/sbtc-registry.clar
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@
;; If status is `none`, the request is pending.
;; Otherwise, the boolean value indicates whether
;; the deposit was accepted.
(define-map withdrawal-status uint bool)
(define-map withdrawal-status uint {
status: bool,
sweep-txid: (optional (buff 32)),
sweep-burn-hash: (optional (buff 32)),
sweep-burn-height: (optional uint),
})

;; Internal data structure to store completed
;; deposit requests & avoid replay attacks.
(define-map completed-deposits {txid: (buff 32), vout-index: uint}
{
amount: uint,
recipient: principal
recipient: principal,
sweep-txid: (buff 32),
sweep-burn-hash: (buff 32),
sweep-burn-height: uint,
}
)

Expand Down Expand Up @@ -177,7 +185,12 @@
(begin
(try! (is-protocol-caller))
;; Mark the withdrawal as completed
(map-insert withdrawal-status request-id true)
(map-insert withdrawal-status request-id {
status: true,
sweep-txid: (some sweep-txid),
sweep-burn-hash: (some burn-hash),
sweep-burn-height: (some burn-height),
})
(print {
topic: "withdrawal-accept",
request-id: request-id,
Expand Down Expand Up @@ -206,7 +219,12 @@
(begin
(try! (is-protocol-caller))
;; Mark the withdrawal as completed
(map-insert withdrawal-status request-id false)
(map-insert withdrawal-status request-id {
status: false,
sweep-txid: none,
sweep-burn-hash: none,
sweep-burn-height: none,
})
(print {
topic: "withdrawal-reject",
request-id: request-id,
Expand Down Expand Up @@ -237,7 +255,10 @@
(try! (is-protocol-caller))
(map-insert completed-deposits {txid: txid, vout-index: vout-index} {
amount: amount,
recipient: recipient
recipient: recipient,
sweep-txid: sweep-txid,
sweep-burn-hash: burn-hash,
sweep-burn-height: burn-height,
})
(print {
topic: "completed-deposit",
Expand Down
67 changes: 63 additions & 4 deletions contracts/tests/clarigen-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ export const contracts = {
tuple: [
{ name: "amount", type: "uint128" },
{ name: "recipient", type: "principal" },
{ name: "sweep-burn-hash", type: { buffer: { length: 32 } } },
{ name: "sweep-burn-height", type: "uint128" },
{ name: "sweep-txid", type: { buffer: { length: 32 } } },
],
},
},
Expand All @@ -893,6 +896,9 @@ export const contracts = {
{
amount: bigint;
recipient: string;
sweepBurnHash: Uint8Array;
sweepBurnHeight: bigint;
sweepTxid: Uint8Array;
} | null
>,
getCurrentAggregatePubkey: {
Expand Down Expand Up @@ -967,7 +973,28 @@ export const contracts = {
},
},
{ name: "sender", type: "principal" },
{ name: "status", type: { optional: "bool" } },
{
name: "status",
type: {
optional: {
tuple: [
{ name: "status", type: "bool" },
{
name: "sweep-burn-hash",
type: { optional: { buffer: { length: 32 } } },
},
{
name: "sweep-burn-height",
type: { optional: "uint128" },
},
{
name: "sweep-txid",
type: { optional: { buffer: { length: 32 } } },
},
],
},
},
},
],
},
},
Expand All @@ -983,7 +1010,12 @@ export const contracts = {
version: Uint8Array;
};
sender: string;
status: boolean | null;
status: {
status: boolean;
sweepBurnHash: Uint8Array | null;
sweepBurnHeight: bigint | null;
sweepTxid: Uint8Array | null;
} | null;
} | null
>,
isProtocolCaller: {
Expand Down Expand Up @@ -1020,6 +1052,9 @@ export const contracts = {
tuple: [
{ name: "amount", type: "uint128" },
{ name: "recipient", type: "principal" },
{ name: "sweep-burn-hash", type: { buffer: { length: 32 } } },
{ name: "sweep-burn-height", type: "uint128" },
{ name: "sweep-txid", type: { buffer: { length: 32 } } },
],
},
} as TypedAbiMap<
Expand All @@ -1030,6 +1065,9 @@ export const contracts = {
{
amount: bigint;
recipient: string;
sweepBurnHash: Uint8Array;
sweepBurnHeight: bigint;
sweepTxid: Uint8Array;
}
>,
multiSigAddress: {
Expand Down Expand Up @@ -1078,8 +1116,29 @@ export const contracts = {
withdrawalStatus: {
name: "withdrawal-status",
key: "uint128",
value: "bool",
} as TypedAbiMap<number | bigint, boolean>,
value: {
tuple: [
{ name: "status", type: "bool" },
{
name: "sweep-burn-hash",
type: { optional: { buffer: { length: 32 } } },
},
{ name: "sweep-burn-height", type: { optional: "uint128" } },
{
name: "sweep-txid",
type: { optional: { buffer: { length: 32 } } },
},
],
},
} as TypedAbiMap<
number | bigint,
{
status: boolean;
sweepBurnHash: Uint8Array | null;
sweepBurnHeight: bigint | null;
sweepTxid: Uint8Array | null;
}
>,
},
variables: {
ERR_AGG_PUBKEY_REPLAY: {
Expand Down
7 changes: 5 additions & 2 deletions contracts/tests/sbtc-deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("sBTC deposit contract", () => {

test("Call get-complete-deposit placeholder", () => {
const { burnHeight, burnHash } = getCurrentBurnInfo();

const sweepTxid = new Uint8Array(32).fill(2);
txOk(
deposit.completeDepositWrapper({
txid: new Uint8Array(32).fill(0),
Expand All @@ -162,7 +162,7 @@ describe("sBTC deposit contract", () => {
recipient: deployer,
burnHash,
burnHeight,
sweepTxid: new Uint8Array(32).fill(2),
sweepTxid: sweepTxid,
}),
deployer
);
Expand All @@ -176,6 +176,9 @@ describe("sBTC deposit contract", () => {
expect(receipt1).toStrictEqual({
amount: 1000n,
recipient: deployer,
sweepTxid: sweepTxid,
sweepBurnHash: burnHash,
sweepBurnHeight: BigInt(burnHeight),
});
});
});
Expand Down
19 changes: 15 additions & 4 deletions contracts/tests/sbtc-withdrawal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ describe("Accepting a withdrawal request", () => {
test("accept withdrawal sets withdrawal-status to true", () => {
// Alice initiates withdrawalrequest
const { burnHeight, burnHash } = getCurrentBurnInfo();
const sweepTxid = new Uint8Array(32).fill(1);
txOk(
deposit.completeDepositWrapper({
txid: new Uint8Array(32).fill(0),
Expand All @@ -535,7 +536,7 @@ describe("Accepting a withdrawal request", () => {
recipient: alice,
burnHash,
burnHeight: BigInt(burnHeight),
sweepTxid: new Uint8Array(32).fill(1),
sweepTxid: sweepTxid,
}),
deployer
);
Expand All @@ -556,7 +557,7 @@ describe("Accepting a withdrawal request", () => {
fee: defaultMaxFee,
burnHash,
burnHeight,
sweepTxid: new Uint8Array(32).fill(1),
sweepTxid: sweepTxid,
}),
deployer
);
Expand All @@ -574,7 +575,12 @@ describe("Accepting a withdrawal request", () => {
amount: defaultAmount,
maxFee: defaultMaxFee,
blockHeight: BigInt(simnet.blockHeight - 3),
status: true,
status: {
status: true,
sweepTxid: sweepTxid,
sweepBurnHash: burnHash,
sweepBurnHeight: BigInt(burnHeight),
},
});
});
test("reject withdrawal sets withdrawal-status to false", () => {
Expand Down Expand Up @@ -647,7 +653,12 @@ describe("Accepting a withdrawal request", () => {
amount: defaultAmount,
maxFee: defaultMaxFee,
blockHeight: BigInt(simnet.blockHeight - 3),
status: false,
status: {
status: false,
sweepTxid: null,
sweepBurnHash: null,
sweepBurnHeight: null,
},
});

// An event is emitted properly
Expand Down
Loading