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

Added 'send-many' Function To sBTC Token #969

Merged
merged 10 commits into from
Dec 10, 2024
Merged
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
13 changes: 9 additions & 4 deletions contracts/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ path = 'contracts/sbtc-registry.clar'
clarity_version = 3
epoch = 3.0

[contracts.sbtc-withdrawal]
path = 'contracts/sbtc-withdrawal.clar'
[contracts.sbtc-token]
path = 'contracts/sbtc-token.clar'
clarity_version = 3
epoch = 3.0

[contracts.sbtc-token]
path = 'contracts/sbtc-token.clar'
[contracts.sbtc-token-test]
path = 'contracts/sbtc-token-test.clar'
clarity_version = 3
epoch = 3.0

[contracts.sbtc-withdrawal]
path = 'contracts/sbtc-withdrawal.clar'
clarity_version = 3
epoch = 3.0
[repl.analysis]
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/sbtc-bootstrap-signers.clar
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f
0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f
0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f
0x30 0x31 0x33 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c 0x4d 0x4e 0x4f
0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f
0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f
Expand Down
11 changes: 10 additions & 1 deletion contracts/contracts/sbtc-deposit.clar
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@
(match helper-response
index
(begin
(unwrap! (complete-deposit-wrapper (get txid deposit) (get vout-index deposit) (get amount deposit) (get recipient deposit) (get burn-hash deposit) (get burn-height deposit) (get sweep-txid deposit)) (err (+ ERR_DEPOSIT_INDEX_PREFIX (+ u10 index))))
(unwrap!
(complete-deposit-wrapper
(get txid deposit)
(get vout-index deposit)
(get amount deposit)
(get recipient deposit)
(get burn-hash deposit)
(get burn-height deposit)
(get sweep-txid deposit))
(err (+ ERR_DEPOSIT_INDEX_PREFIX (+ u10 index))))
(ok (+ index u1))
)
err-response
Expand Down
22 changes: 22 additions & 0 deletions contracts/contracts/sbtc-token-test.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;; send many sbtc tokens
(define-public (send-many-sbtc-tokens (recipients (list 10 principal)))
(as-contract (contract-call? .sbtc-token transfer-many (list
{
amount: u100,
sender: tx-sender,
to: (unwrap-panic (element-at? recipients u0)),
memo: none
}
{
amount: u100,
sender: tx-sender,
to: (unwrap-panic (element-at? recipients u1)),
memo: none
}
{
amount: u100,
sender: tx-sender,
to: (unwrap-panic (element-at? recipients u2)),
memo: none
})))
)
34 changes: 34 additions & 0 deletions contracts/contracts/sbtc-token.clar
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(define-constant ERR_NOT_OWNER (err u4)) ;; `tx-sender` or `contract-caller` tried to move a token it does not own.
(define-constant ERR_NOT_AUTH (err u5)) ;; `tx-sender` or `contract-caller` is not the protocol caller
(define-constant ERR_TRANSFER_INDEX_PREFIX (unwrap-err! ERR_TRANSFER (err true)))
(define-constant ERR_TRANSFER (err u6))

(define-fungible-token sbtc-token)
(define-fungible-token sbtc-token-locked)
Expand Down Expand Up @@ -99,6 +101,38 @@
)

;; --- Public functions
(define-public (transfer-many
(recipients (list 200 {
amount: uint,
sender: principal,
to: principal,
memo: (optional (buff 34)) })))
(fold complete-individual-transfer recipients (ok u0))
)

(define-private (complete-individual-transfer
(individual-transfer {
amount: uint,
sender: principal,
to: principal,
memo: (optional (buff 34)) })
(helper-response (response uint uint)))
(match helper-response
index
(begin
(unwrap!
(transfer
(get amount individual-transfer)
(get sender individual-transfer)
(get to individual-transfer)
(get memo individual-transfer))
(err (+ ERR_TRANSFER_INDEX_PREFIX index)))
(ok (+ index u1))
)
err-response
(err err-response)
)
)

;; sip-010-trait

Expand Down
5 changes: 5 additions & 0 deletions contracts/deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ plan:
emulated-sender: ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039
path: contracts/sbtc-deposit.clar
clarity-version: 3
- emulated-contract-publish:
contract-name: sbtc-token-test
emulated-sender: ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039
path: contracts/sbtc-token-test.clar
clarity-version: 3
- emulated-contract-publish:
contract-name: sbtc-withdrawal
emulated-sender: ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039
Expand Down
2 changes: 1 addition & 1 deletion contracts/docs/sbtc-bootstrap-signers.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ equal to 100% of the total number of signer keys.
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f
0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f
0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f
0x30 0x31 0x33 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c 0x4d 0x4e 0x4f
0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f
0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f
Expand Down
5 changes: 3 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@clarigen/cli": "2.1.2",
"@clarigen/core": "2.1.2",
"@clarigen/test": "2.1.2",
"@hirosystems/clarinet-sdk": "^2.11.2",
"@hirosystems/clarinet-sdk": "2.11.2",
"@hirosystems/clarinet-sdk-wasm": "2.11.2",
"@noble/secp256k1": "^2.1.0",
"@scure/base": "^1.1.6",
"@scure/btc-signer": "^1.3.1",
Expand All @@ -30,7 +31,7 @@
"chokidar-cli": "^3.0.0",
"vite": "^5.1.4",
"vitest": "^1.3.1",
"vitest-environment-clarinet": "^2.0.0"
"vitest-environment-clarinet": "2.1.0"
},
"devDependencies": {
"@eslint/js": "^8.56.0",
Expand Down
136 changes: 135 additions & 1 deletion contracts/tests/clarigen-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const contracts = {
Uint8Array.from([47]),
Uint8Array.from([48]),
Uint8Array.from([49]),
Uint8Array.from([51]),
Uint8Array.from([50]),
Uint8Array.from([51]),
Uint8Array.from([52]),
Uint8Array.from([53]),
Expand Down Expand Up @@ -1264,6 +1264,48 @@ export const contracts = {
},
sbtcToken: {
functions: {
completeIndividualTransfer: {
name: "complete-individual-transfer",
access: "private",
args: [
{
name: "individual-transfer",
type: {
tuple: [
{ name: "amount", type: "uint128" },
{
name: "memo",
type: { optional: { buffer: { length: 34 } } },
},
{ name: "sender", type: "principal" },
{ name: "to", type: "principal" },
],
},
},
{
name: "helper-response",
type: { response: { ok: "uint128", error: "uint128" } },
},
],
outputs: { type: { response: { ok: "uint128", error: "uint128" } } },
} as TypedAbiFunction<
[
individualTransfer: TypedAbiArg<
{
amount: number | bigint;
memo: Uint8Array | null;
sender: string;
to: string;
},
"individualTransfer"
>,
helperResponse: TypedAbiArg<
Response<number | bigint, number | bigint>,
"helperResponse"
>,
],
Response<bigint, bigint>
>,
protocolMintManyIter: {
name: "protocol-mint-many-iter",
access: "private",
Expand Down Expand Up @@ -1480,6 +1522,45 @@ export const contracts = {
],
Response<boolean, bigint>
>,
transferMany: {
name: "transfer-many",
access: "public",
args: [
{
name: "recipients",
type: {
list: {
type: {
tuple: [
{ name: "amount", type: "uint128" },
{
name: "memo",
type: { optional: { buffer: { length: 34 } } },
},
{ name: "sender", type: "principal" },
{ name: "to", type: "principal" },
],
},
length: 200,
},
},
},
],
outputs: { type: { response: { ok: "uint128", error: "uint128" } } },
} as TypedAbiFunction<
[
recipients: TypedAbiArg<
{
amount: number | bigint;
memo: Uint8Array | null;
sender: string;
to: string;
}[],
"recipients"
>,
],
Response<bigint, bigint>
>,
getBalance: {
name: "get-balance",
access: "read_only",
Expand Down Expand Up @@ -1575,6 +1656,21 @@ export const contracts = {
},
access: "constant",
} as TypedAbiVariable<Response<null, bigint>>,
ERR_TRANSFER: {
name: "ERR_TRANSFER",
type: {
response: {
ok: "none",
error: "uint128",
},
},
access: "constant",
} as TypedAbiVariable<Response<null, bigint>>,
ERR_TRANSFER_INDEX_PREFIX: {
name: "ERR_TRANSFER_INDEX_PREFIX",
type: "uint128",
access: "constant",
} as TypedAbiVariable<bigint>,
tokenDecimals: {
name: "token-decimals",
type: "uint128",
Expand Down Expand Up @@ -1619,6 +1715,11 @@ export const contracts = {
isOk: false,
value: 4n,
},
ERR_TRANSFER: {
isOk: false,
value: 6n,
},
ERR_TRANSFER_INDEX_PREFIX: 6n,
tokenDecimals: 8n,
tokenName: "sBTC",
tokenSymbol: "sBTC",
Expand All @@ -1630,6 +1731,32 @@ export const contracts = {
clarity_version: "Clarity3",
contractName: "sbtc-token",
},
sbtcTokenTest: {
functions: {
sendManySbtcTokens: {
name: "send-many-sbtc-tokens",
access: "public",
args: [
{
name: "recipients",
type: { list: { type: "principal", length: 10 } },
},
],
outputs: { type: { response: { ok: "uint128", error: "uint128" } } },
} as TypedAbiFunction<
[recipients: TypedAbiArg<string[], "recipients">],
Response<bigint, bigint>
>,
},
maps: {},
variables: {},
constants: {},
non_fungible_tokens: [],
fungible_tokens: [],
epoch: "Epoch30",
clarity_version: "Clarity3",
contractName: "sbtc-token-test",
},
sbtcWithdrawal: {
functions: {
completeIndividualWithdrawalHelper: {
Expand Down Expand Up @@ -2047,6 +2174,7 @@ export const identifiers = {
sbtcDeposit: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-deposit",
sbtcRegistry: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-registry",
sbtcToken: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-token",
sbtcTokenTest: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-token-test",
sbtcWithdrawal: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-withdrawal",
} as const;

Expand Down Expand Up @@ -2081,6 +2209,12 @@ export const deployments = {
testnet: null,
mainnet: null,
},
sbtcTokenTest: {
devnet: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-token-test",
simnet: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-token-test",
testnet: null,
mainnet: null,
},
sbtcWithdrawal: {
devnet: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-withdrawal",
simnet: "ST2SBXRBJJTH7GV5J93HJ62W2NRRQ46XYBK92Y039.sbtc-withdrawal",
Expand Down
1 change: 1 addition & 0 deletions contracts/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const deposit = contracts.sbtcDeposit;
export const signers = contracts.sbtcBootstrapSigners;
export const withdrawal = contracts.sbtcWithdrawal;
export const token = contracts.sbtcToken;
export const tokenTest = contracts.sbtcTokenTest;

export const controllerId = `${accounts.deployer.address}.controller`;

Expand Down
Loading
Loading