@dfinity/ckbtc 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -9
- package/dist/candid/minter.certified.idl.js +68 -0
- package/dist/candid/minter.d.ts +62 -2
- package/dist/candid/minter.did +87 -9
- package/dist/candid/minter.idl.js +68 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/index.cjs.js.map +3 -3
- package/dist/esm/chunk-XGTBIGYK.js +2 -0
- package/dist/esm/chunk-XGTBIGYK.js.map +7 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/minter.canister.js +1 -1
- package/dist/types/enums/btc.enums.d.ts +3 -1
- package/dist/types/errors/minter.errors.d.ts +4 -1
- package/dist/types/minter.canister.d.ts +24 -1
- package/dist/types/types/minter.responses.d.ts +6 -1
- package/package.json +1 -1
- package/dist/esm/chunk-WPJD44WU.js +0 -2
- package/dist/esm/chunk-WPJD44WU.js.map +0 -7
package/README.md
CHANGED
|
@@ -74,11 +74,11 @@ Parameters:
|
|
|
74
74
|
- `params`: The Bitcoin address and network to parse
|
|
75
75
|
- `params.network`: Optional. Default BtcNetwork is Mainnet
|
|
76
76
|
|
|
77
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/utils/btc.utils.ts#
|
|
77
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/utils/btc.utils.ts#L195)
|
|
78
78
|
|
|
79
79
|
### :factory: CkBTCMinterCanister
|
|
80
80
|
|
|
81
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
81
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L35)
|
|
82
82
|
|
|
83
83
|
#### Methods
|
|
84
84
|
|
|
@@ -87,6 +87,7 @@ Parameters:
|
|
|
87
87
|
- [updateBalance](#gear-updatebalance)
|
|
88
88
|
- [getWithdrawalAccount](#gear-getwithdrawalaccount)
|
|
89
89
|
- [retrieveBtc](#gear-retrievebtc)
|
|
90
|
+
- [retrieveBtcWithApproval](#gear-retrievebtcwithapproval)
|
|
90
91
|
- [estimateWithdrawalFee](#gear-estimatewithdrawalfee)
|
|
91
92
|
- [getMinterInfo](#gear-getminterinfo)
|
|
92
93
|
|
|
@@ -96,7 +97,7 @@ Parameters:
|
|
|
96
97
|
| -------- | ------------------------------------------------------------------------ |
|
|
97
98
|
| `create` | `(options: CkBTCMinterCanisterOptions<_SERVICE>) => CkBTCMinterCanister` |
|
|
98
99
|
|
|
99
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
100
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L36)
|
|
100
101
|
|
|
101
102
|
##### :gear: getBtcAddress
|
|
102
103
|
|
|
@@ -114,7 +115,7 @@ Parameters:
|
|
|
114
115
|
- `params.owner`: The owner for which the BTC address should be generated. If not provided, the `caller` will be use instead.
|
|
115
116
|
- `params.subaccount`: An optional subaccount to compute the address.
|
|
116
117
|
|
|
117
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
118
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L57)
|
|
118
119
|
|
|
119
120
|
##### :gear: updateBalance
|
|
120
121
|
|
|
@@ -132,7 +133,7 @@ Parameters:
|
|
|
132
133
|
- `params.owner`: The owner of the address. If not provided, the `caller` will be use instead.
|
|
133
134
|
- `params.subaccount`: An optional subaccount of the address.
|
|
134
135
|
|
|
135
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
136
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L76)
|
|
136
137
|
|
|
137
138
|
##### :gear: getWithdrawalAccount
|
|
138
139
|
|
|
@@ -142,7 +143,7 @@ Returns the account to which the caller should deposit ckBTC before withdrawing
|
|
|
142
143
|
| ---------------------- | ------------------------ |
|
|
143
144
|
| `getWithdrawalAccount` | `() => Promise<Account>` |
|
|
144
145
|
|
|
145
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
146
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L99)
|
|
146
147
|
|
|
147
148
|
##### :gear: retrieveBtc
|
|
148
149
|
|
|
@@ -166,7 +167,33 @@ Parameters:
|
|
|
166
167
|
- `params.address`: The bitcoin address.
|
|
167
168
|
- `params.amount`: The ckBTC amount.
|
|
168
169
|
|
|
169
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
170
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L118)
|
|
171
|
+
|
|
172
|
+
##### :gear: retrieveBtcWithApproval
|
|
173
|
+
|
|
174
|
+
Submits a request to convert ckBTC to BTC after making an ICRC-2 approval.
|
|
175
|
+
|
|
176
|
+
# Note
|
|
177
|
+
|
|
178
|
+
The BTC retrieval process is slow. Instead of synchronously waiting for a BTC transaction to settle, this method returns a request ([block_index]) that the caller can use to query the request status.
|
|
179
|
+
|
|
180
|
+
# Preconditions
|
|
181
|
+
|
|
182
|
+
The caller allowed the minter's principal to spend its funds using
|
|
183
|
+
[icrc2_approve] on the ckBTC ledger.
|
|
184
|
+
|
|
185
|
+
| Method | Type |
|
|
186
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `retrieveBtcWithApproval` | `({ address, amount, fromSubaccount, }: { address: string; amount: bigint; fromSubaccount?: Uint8Array; }) => Promise<RetrieveBtcOk>` |
|
|
188
|
+
|
|
189
|
+
Parameters:
|
|
190
|
+
|
|
191
|
+
- `params.address`: The bitcoin address.
|
|
192
|
+
- `params.amount`: The ckBTC amount.
|
|
193
|
+
- `params.fromSubaccount`: An optional subaccount from which
|
|
194
|
+
the ckBTC should be transferred.
|
|
195
|
+
|
|
196
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L148)
|
|
170
197
|
|
|
171
198
|
##### :gear: estimateWithdrawalFee
|
|
172
199
|
|
|
@@ -182,7 +209,7 @@ Parameters:
|
|
|
182
209
|
- `params.certified`: query or update call
|
|
183
210
|
- `params.amount`: The optional amount for which the fee should be estimated.
|
|
184
211
|
|
|
185
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
212
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L179)
|
|
186
213
|
|
|
187
214
|
##### :gear: getMinterInfo
|
|
188
215
|
|
|
@@ -197,7 +224,7 @@ Parameters:
|
|
|
197
224
|
- `params`: The parameters to get the deposit fee.
|
|
198
225
|
- `params.certified`: query or update call
|
|
199
226
|
|
|
200
|
-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#
|
|
227
|
+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc/src/minter.canister.ts#L193)
|
|
201
228
|
|
|
202
229
|
<!-- TSDOC_END -->
|
|
203
230
|
|
|
@@ -34,6 +34,25 @@ export const idlFactory = ({ IDL }) => {
|
|
|
34
34
|
'Upgrade' : IDL.Opt(UpgradeArgs),
|
|
35
35
|
'Init' : InitArgs,
|
|
36
36
|
});
|
|
37
|
+
const CanisterStatusType = IDL.Variant({
|
|
38
|
+
'stopped' : IDL.Null,
|
|
39
|
+
'stopping' : IDL.Null,
|
|
40
|
+
'running' : IDL.Null,
|
|
41
|
+
});
|
|
42
|
+
const DefiniteCanisterSettings = IDL.Record({
|
|
43
|
+
'freezing_threshold' : IDL.Nat,
|
|
44
|
+
'controllers' : IDL.Vec(IDL.Principal),
|
|
45
|
+
'memory_allocation' : IDL.Nat,
|
|
46
|
+
'compute_allocation' : IDL.Nat,
|
|
47
|
+
});
|
|
48
|
+
const CanisterStatusResponse = IDL.Record({
|
|
49
|
+
'status' : CanisterStatusType,
|
|
50
|
+
'memory_size' : IDL.Nat,
|
|
51
|
+
'cycles' : IDL.Nat,
|
|
52
|
+
'settings' : DefiniteCanisterSettings,
|
|
53
|
+
'idle_cycles_burned_per_day' : IDL.Nat,
|
|
54
|
+
'module_hash' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
55
|
+
});
|
|
37
56
|
const Account = IDL.Record({
|
|
38
57
|
'owner' : IDL.Principal,
|
|
39
58
|
'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
@@ -43,7 +62,16 @@ export const idlFactory = ({ IDL }) => {
|
|
|
43
62
|
'value' : IDL.Nat64,
|
|
44
63
|
'outpoint' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8), 'vout' : IDL.Nat32 }),
|
|
45
64
|
});
|
|
65
|
+
const ReimbursementReason = IDL.Variant({
|
|
66
|
+
'CallFailed' : IDL.Null,
|
|
67
|
+
'TaintedDestination' : IDL.Record({
|
|
68
|
+
'kyt_fee' : IDL.Nat64,
|
|
69
|
+
'kyt_provider' : IDL.Principal,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
46
72
|
const BitcoinAddress = IDL.Variant({
|
|
73
|
+
'p2wsh_v0' : IDL.Vec(IDL.Nat8),
|
|
74
|
+
'p2tr_v1' : IDL.Vec(IDL.Nat8),
|
|
47
75
|
'p2sh' : IDL.Vec(IDL.Nat8),
|
|
48
76
|
'p2wpkh_v0' : IDL.Vec(IDL.Nat8),
|
|
49
77
|
'p2pkh' : IDL.Vec(IDL.Nat8),
|
|
@@ -51,8 +79,15 @@ export const idlFactory = ({ IDL }) => {
|
|
|
51
79
|
const Event = IDL.Variant({
|
|
52
80
|
'received_utxos' : IDL.Record({
|
|
53
81
|
'to_account' : Account,
|
|
82
|
+
'mint_txid' : IDL.Opt(IDL.Nat64),
|
|
54
83
|
'utxos' : IDL.Vec(Utxo),
|
|
55
84
|
}),
|
|
85
|
+
'schedule_deposit_reimbursement' : IDL.Record({
|
|
86
|
+
'burn_block_index' : IDL.Nat64,
|
|
87
|
+
'account' : Account,
|
|
88
|
+
'amount' : IDL.Nat64,
|
|
89
|
+
'reason' : ReimbursementReason,
|
|
90
|
+
}),
|
|
56
91
|
'sent_transaction' : IDL.Record({
|
|
57
92
|
'fee' : IDL.Opt(IDL.Nat64),
|
|
58
93
|
'change_output' : IDL.Opt(
|
|
@@ -72,6 +107,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
72
107
|
'upgrade' : UpgradeArgs,
|
|
73
108
|
'retrieve_btc_kyt_failed' : IDL.Record({
|
|
74
109
|
'block_index' : IDL.Nat64,
|
|
110
|
+
'owner' : IDL.Principal,
|
|
75
111
|
'uuid' : IDL.Text,
|
|
76
112
|
'address' : IDL.Text,
|
|
77
113
|
'amount' : IDL.Nat64,
|
|
@@ -100,6 +136,10 @@ export const idlFactory = ({ IDL }) => {
|
|
|
100
136
|
'submitted_at' : IDL.Nat64,
|
|
101
137
|
}),
|
|
102
138
|
'ignored_utxo' : IDL.Record({ 'utxo' : Utxo }),
|
|
139
|
+
'reimbursed_failed_deposit' : IDL.Record({
|
|
140
|
+
'burn_block_index' : IDL.Nat64,
|
|
141
|
+
'mint_block_index' : IDL.Nat64,
|
|
142
|
+
}),
|
|
103
143
|
});
|
|
104
144
|
const MinterInfo = IDL.Record({
|
|
105
145
|
'retrieve_btc_min_amount' : IDL.Nat64,
|
|
@@ -131,6 +171,23 @@ export const idlFactory = ({ IDL }) => {
|
|
|
131
171
|
'Submitted' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
|
|
132
172
|
'Pending' : IDL.Null,
|
|
133
173
|
});
|
|
174
|
+
const RetrieveBtcWithApprovalArgs = IDL.Record({
|
|
175
|
+
'from_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
176
|
+
'address' : IDL.Text,
|
|
177
|
+
'amount' : IDL.Nat64,
|
|
178
|
+
});
|
|
179
|
+
const RetrieveBtcWithApprovalError = IDL.Variant({
|
|
180
|
+
'MalformedAddress' : IDL.Text,
|
|
181
|
+
'GenericError' : IDL.Record({
|
|
182
|
+
'error_message' : IDL.Text,
|
|
183
|
+
'error_code' : IDL.Nat64,
|
|
184
|
+
}),
|
|
185
|
+
'TemporarilyUnavailable' : IDL.Text,
|
|
186
|
+
'InsufficientAllowance' : IDL.Record({ 'allowance' : IDL.Nat64 }),
|
|
187
|
+
'AlreadyProcessing' : IDL.Null,
|
|
188
|
+
'AmountTooLow' : IDL.Nat64,
|
|
189
|
+
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat64 }),
|
|
190
|
+
});
|
|
134
191
|
const UtxoStatus = IDL.Variant({
|
|
135
192
|
'ValueTooSmall' : Utxo,
|
|
136
193
|
'Tainted' : Utxo,
|
|
@@ -169,6 +226,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
169
226
|
[IDL.Text],
|
|
170
227
|
[],
|
|
171
228
|
),
|
|
229
|
+
'get_canister_status' : IDL.Func([], [CanisterStatusResponse], []),
|
|
172
230
|
'get_deposit_fee' : IDL.Func([], [IDL.Nat64], []),
|
|
173
231
|
'get_events' : IDL.Func(
|
|
174
232
|
[IDL.Record({ 'start' : IDL.Nat64, 'length' : IDL.Nat64 })],
|
|
@@ -187,6 +245,16 @@ export const idlFactory = ({ IDL }) => {
|
|
|
187
245
|
[RetrieveBtcStatus],
|
|
188
246
|
[],
|
|
189
247
|
),
|
|
248
|
+
'retrieve_btc_with_approval' : IDL.Func(
|
|
249
|
+
[RetrieveBtcWithApprovalArgs],
|
|
250
|
+
[
|
|
251
|
+
IDL.Variant({
|
|
252
|
+
'Ok' : RetrieveBtcOk,
|
|
253
|
+
'Err' : RetrieveBtcWithApprovalError,
|
|
254
|
+
}),
|
|
255
|
+
],
|
|
256
|
+
[],
|
|
257
|
+
),
|
|
190
258
|
'update_balance' : IDL.Func(
|
|
191
259
|
[
|
|
192
260
|
IDL.Record({
|
package/dist/candid/minter.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface Account {
|
|
|
6
6
|
subaccount: [] | [Uint8Array];
|
|
7
7
|
}
|
|
8
8
|
export type BitcoinAddress =
|
|
9
|
+
| { p2wsh_v0: Uint8Array }
|
|
10
|
+
| { p2tr_v1: Uint8Array }
|
|
9
11
|
| { p2sh: Uint8Array }
|
|
10
12
|
| { p2wpkh_v0: Uint8Array }
|
|
11
13
|
| { p2pkh: Uint8Array };
|
|
@@ -13,9 +15,39 @@ export type BtcNetwork =
|
|
|
13
15
|
| { Mainnet: null }
|
|
14
16
|
| { Regtest: null }
|
|
15
17
|
| { Testnet: null };
|
|
18
|
+
export interface CanisterStatusResponse {
|
|
19
|
+
status: CanisterStatusType;
|
|
20
|
+
memory_size: bigint;
|
|
21
|
+
cycles: bigint;
|
|
22
|
+
settings: DefiniteCanisterSettings;
|
|
23
|
+
idle_cycles_burned_per_day: bigint;
|
|
24
|
+
module_hash: [] | [Uint8Array];
|
|
25
|
+
}
|
|
26
|
+
export type CanisterStatusType =
|
|
27
|
+
| { stopped: null }
|
|
28
|
+
| { stopping: null }
|
|
29
|
+
| { running: null };
|
|
30
|
+
export interface DefiniteCanisterSettings {
|
|
31
|
+
freezing_threshold: bigint;
|
|
32
|
+
controllers: Array<Principal>;
|
|
33
|
+
memory_allocation: bigint;
|
|
34
|
+
compute_allocation: bigint;
|
|
35
|
+
}
|
|
16
36
|
export type Event =
|
|
17
37
|
| {
|
|
18
|
-
received_utxos: {
|
|
38
|
+
received_utxos: {
|
|
39
|
+
to_account: Account;
|
|
40
|
+
mint_txid: [] | [bigint];
|
|
41
|
+
utxos: Array<Utxo>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
schedule_deposit_reimbursement: {
|
|
46
|
+
burn_block_index: bigint;
|
|
47
|
+
account: Account;
|
|
48
|
+
amount: bigint;
|
|
49
|
+
reason: ReimbursementReason;
|
|
50
|
+
};
|
|
19
51
|
}
|
|
20
52
|
| {
|
|
21
53
|
sent_transaction: {
|
|
@@ -39,6 +71,7 @@ export type Event =
|
|
|
39
71
|
| {
|
|
40
72
|
retrieve_btc_kyt_failed: {
|
|
41
73
|
block_index: bigint;
|
|
74
|
+
owner: Principal;
|
|
42
75
|
uuid: string;
|
|
43
76
|
address: string;
|
|
44
77
|
amount: bigint;
|
|
@@ -73,7 +106,13 @@ export type Event =
|
|
|
73
106
|
submitted_at: bigint;
|
|
74
107
|
};
|
|
75
108
|
}
|
|
76
|
-
| { ignored_utxo: { utxo: Utxo } }
|
|
109
|
+
| { ignored_utxo: { utxo: Utxo } }
|
|
110
|
+
| {
|
|
111
|
+
reimbursed_failed_deposit: {
|
|
112
|
+
burn_block_index: bigint;
|
|
113
|
+
mint_block_index: bigint;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
77
116
|
export interface InitArgs {
|
|
78
117
|
kyt_principal: [] | [Principal];
|
|
79
118
|
ecdsa_key_name: string;
|
|
@@ -96,6 +135,9 @@ export type Mode =
|
|
|
96
135
|
| { DepositsRestrictedTo: Array<Principal> }
|
|
97
136
|
| { ReadOnly: null }
|
|
98
137
|
| { GeneralAvailability: null };
|
|
138
|
+
export type ReimbursementReason =
|
|
139
|
+
| { CallFailed: null }
|
|
140
|
+
| { TaintedDestination: { kyt_fee: bigint; kyt_provider: Principal } };
|
|
99
141
|
export interface RetrieveBtcArgs {
|
|
100
142
|
address: string;
|
|
101
143
|
amount: bigint;
|
|
@@ -118,6 +160,19 @@ export type RetrieveBtcStatus =
|
|
|
118
160
|
| { Unknown: null }
|
|
119
161
|
| { Submitted: { txid: Uint8Array } }
|
|
120
162
|
| { Pending: null };
|
|
163
|
+
export interface RetrieveBtcWithApprovalArgs {
|
|
164
|
+
from_subaccount: [] | [Uint8Array];
|
|
165
|
+
address: string;
|
|
166
|
+
amount: bigint;
|
|
167
|
+
}
|
|
168
|
+
export type RetrieveBtcWithApprovalError =
|
|
169
|
+
| { MalformedAddress: string }
|
|
170
|
+
| { GenericError: { error_message: string; error_code: bigint } }
|
|
171
|
+
| { TemporarilyUnavailable: string }
|
|
172
|
+
| { InsufficientAllowance: { allowance: bigint } }
|
|
173
|
+
| { AlreadyProcessing: null }
|
|
174
|
+
| { AmountTooLow: bigint }
|
|
175
|
+
| { InsufficientFunds: { balance: bigint } };
|
|
121
176
|
export type UpdateBalanceError =
|
|
122
177
|
| {
|
|
123
178
|
GenericError: { error_message: string; error_code: bigint };
|
|
@@ -163,6 +218,7 @@ export interface _SERVICE {
|
|
|
163
218
|
[{ owner: [] | [Principal]; subaccount: [] | [Uint8Array] }],
|
|
164
219
|
string
|
|
165
220
|
>;
|
|
221
|
+
get_canister_status: ActorMethod<[], CanisterStatusResponse>;
|
|
166
222
|
get_deposit_fee: ActorMethod<[], bigint>;
|
|
167
223
|
get_events: ActorMethod<[{ start: bigint; length: bigint }], Array<Event>>;
|
|
168
224
|
get_minter_info: ActorMethod<[], MinterInfo>;
|
|
@@ -175,6 +231,10 @@ export interface _SERVICE {
|
|
|
175
231
|
[{ block_index: bigint }],
|
|
176
232
|
RetrieveBtcStatus
|
|
177
233
|
>;
|
|
234
|
+
retrieve_btc_with_approval: ActorMethod<
|
|
235
|
+
[RetrieveBtcWithApprovalArgs],
|
|
236
|
+
{ Ok: RetrieveBtcOk } | { Err: RetrieveBtcWithApprovalError }
|
|
237
|
+
>;
|
|
178
238
|
update_balance: ActorMethod<
|
|
179
239
|
[{ owner: [] | [Principal]; subaccount: [] | [Uint8Array] }],
|
|
180
240
|
{ Ok: Array<UtxoStatus> } | { Err: UpdateBalanceError }
|
package/dist/candid/minter.did
CHANGED
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
// Generated from IC repo commit
|
|
1
|
+
// Generated from IC repo commit 8be68bc88db7332dd39a26509ddf62c564ca3415 'rs/bitcoin/ckbtc/minter/ckbtc_minter.did' by import-candid
|
|
2
2
|
// Represents an account on the ckBTC ledger.
|
|
3
3
|
type Account = record { owner : principal; subaccount : opt blob };
|
|
4
4
|
|
|
5
|
+
type CanisterStatusResponse = record {
|
|
6
|
+
status : CanisterStatusType;
|
|
7
|
+
memory_size : nat;
|
|
8
|
+
cycles : nat;
|
|
9
|
+
settings : DefiniteCanisterSettings;
|
|
10
|
+
idle_cycles_burned_per_day : nat;
|
|
11
|
+
module_hash : opt vec nat8;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type CanisterStatusType = variant { stopped; stopping; running };
|
|
15
|
+
|
|
16
|
+
type DefiniteCanisterSettings = record {
|
|
17
|
+
freezing_threshold : nat;
|
|
18
|
+
controllers : vec principal;
|
|
19
|
+
memory_allocation : nat;
|
|
20
|
+
compute_allocation : nat;
|
|
21
|
+
};
|
|
22
|
+
|
|
5
23
|
type RetrieveBtcArgs = record {
|
|
6
24
|
// The address to which the ckBTC minter should deposit BTC.
|
|
7
|
-
// Currently, the minter understands only the following types of addresses:
|
|
8
|
-
// * P2WPKH addresses (they start with the "bc1q" prefix on the Bitcoin mainnet).
|
|
9
|
-
// * P2PKH addresses (they start with the "1" prefix on the Bitcoin mainnet).
|
|
10
|
-
// * P2SH addresses (they start with the "3" prefix on the Bitcoin mainnet).
|
|
11
25
|
address : text;
|
|
12
26
|
// The amount of BTC in Satoshis that the client wants to withdraw.
|
|
13
27
|
amount : nat64;
|
|
14
28
|
};
|
|
15
29
|
|
|
30
|
+
type RetrieveBtcWithApprovalArgs = record {
|
|
31
|
+
// The address to which the ckBTC minter should deposit BTC.
|
|
32
|
+
address : text;
|
|
33
|
+
// The amount of BTC in Satoshis that the client wants to withdraw.
|
|
34
|
+
amount : nat64;
|
|
35
|
+
// The subaccount to burn ckBTC from.
|
|
36
|
+
from_subaccount : opt blob;
|
|
37
|
+
};
|
|
38
|
+
|
|
16
39
|
type RetrieveBtcError = variant {
|
|
17
40
|
// The minter failed to parse the destination address.
|
|
18
41
|
MalformedAddress : text;
|
|
@@ -31,6 +54,26 @@ type RetrieveBtcError = variant {
|
|
|
31
54
|
GenericError : record { error_message : text; error_code : nat64 };
|
|
32
55
|
};
|
|
33
56
|
|
|
57
|
+
type RetrieveBtcWithApprovalError = variant {
|
|
58
|
+
// The minter failed to parse the destination address.
|
|
59
|
+
MalformedAddress : text;
|
|
60
|
+
// The minter is already processing another retrieval request for the same
|
|
61
|
+
// principal.
|
|
62
|
+
AlreadyProcessing;
|
|
63
|
+
// The withdrawal amount is too low.
|
|
64
|
+
// The payload contains the minimal withdrawal amount.
|
|
65
|
+
AmountTooLow : nat64;
|
|
66
|
+
// The ckBTC balance of the withdrawal account is too low.
|
|
67
|
+
InsufficientFunds : record { balance : nat64 };
|
|
68
|
+
// The allowance given to the minter is too low.
|
|
69
|
+
InsufficientAllowance : record { allowance : nat64 };
|
|
70
|
+
// The minter is overloaded, retry the request.
|
|
71
|
+
// The payload contains a human-readable message explaining what caused the unavailability.
|
|
72
|
+
TemporarilyUnavailable : text;
|
|
73
|
+
// A generic error reserved for future extensions.
|
|
74
|
+
GenericError : record { error_message : text; error_code : nat64 };
|
|
75
|
+
};
|
|
76
|
+
|
|
34
77
|
type RetrieveBtcOk = record {
|
|
35
78
|
// Returns the burn transaction index corresponding to the withdrawal.
|
|
36
79
|
// You can use this index to query the withdrawal status.
|
|
@@ -43,7 +86,7 @@ type UtxoStatus = variant {
|
|
|
43
86
|
// the KYT fees. This state is final, retrying [update_balance] call will
|
|
44
87
|
// have no effect on this UTXO.
|
|
45
88
|
ValueTooSmall : Utxo;
|
|
46
|
-
// The KYT provider considered this UTXO to be
|
|
89
|
+
// The KYT provider considered this UTXO to be tainted. This UTXO state is
|
|
47
90
|
// final, retrying [update_balance] call will have no effect on this UTXO.
|
|
48
91
|
Tainted : Utxo;
|
|
49
92
|
// The UTXO passed the KYT check, but the minter failed to mint ckBTC
|
|
@@ -121,7 +164,7 @@ type InitArgs = record {
|
|
|
121
164
|
/// The minter's operation mode.
|
|
122
165
|
mode : Mode;
|
|
123
166
|
|
|
124
|
-
/// The fee paid per check by the KYT
|
|
167
|
+
/// The fee paid per check by the KYT canister.
|
|
125
168
|
kyt_fee : opt nat64;
|
|
126
169
|
|
|
127
170
|
/// The canister id of the KYT canister.
|
|
@@ -144,7 +187,7 @@ type UpgradeArgs = record {
|
|
|
144
187
|
/// If set, overrides the current minter's operation mode.
|
|
145
188
|
mode : opt Mode;
|
|
146
189
|
|
|
147
|
-
/// The fee per check by the KYT
|
|
190
|
+
/// The fee per check by the KYT canister.
|
|
148
191
|
kyt_fee : opt nat64;
|
|
149
192
|
|
|
150
193
|
/// The principal of the KYT canister.
|
|
@@ -190,6 +233,8 @@ type Utxo = record {
|
|
|
190
233
|
|
|
191
234
|
type BitcoinAddress = variant {
|
|
192
235
|
p2wpkh_v0 : blob;
|
|
236
|
+
p2wsh_v0 : blob;
|
|
237
|
+
p2tr_v1 : blob;
|
|
193
238
|
p2pkh : blob;
|
|
194
239
|
p2sh : blob;
|
|
195
240
|
};
|
|
@@ -200,10 +245,18 @@ type MinterInfo = record {
|
|
|
200
245
|
kyt_fee : nat64;
|
|
201
246
|
};
|
|
202
247
|
|
|
248
|
+
type ReimbursementReason = variant {
|
|
249
|
+
CallFailed;
|
|
250
|
+
TaintedDestination : record {
|
|
251
|
+
kyt_fee : nat64;
|
|
252
|
+
kyt_provider: principal;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
203
256
|
type Event = variant {
|
|
204
257
|
init : InitArgs;
|
|
205
258
|
upgrade : UpgradeArgs;
|
|
206
|
-
received_utxos : record { to_account : Account; utxos : vec Utxo };
|
|
259
|
+
received_utxos : record { to_account : Account; mint_txid : opt nat64; utxos : vec Utxo };
|
|
207
260
|
accepted_retrieve_btc_request : record {
|
|
208
261
|
amount : nat64;
|
|
209
262
|
address : BitcoinAddress;
|
|
@@ -243,10 +296,18 @@ type Event = variant {
|
|
|
243
296
|
retrieve_btc_kyt_failed : record {
|
|
244
297
|
address : text;
|
|
245
298
|
amount : nat64;
|
|
299
|
+
owner : principal;
|
|
246
300
|
kyt_provider : principal;
|
|
247
301
|
uuid : text;
|
|
248
302
|
block_index : nat64;
|
|
249
303
|
};
|
|
304
|
+
schedule_deposit_reimbursement : record {
|
|
305
|
+
account : Account;
|
|
306
|
+
burn_block_index : nat64;
|
|
307
|
+
amount : nat64;
|
|
308
|
+
reason : ReimbursementReason;
|
|
309
|
+
};
|
|
310
|
+
reimbursed_failed_deposit : record { burn_block_index : nat64; mint_block_index : nat64 };
|
|
250
311
|
};
|
|
251
312
|
|
|
252
313
|
type MinterArg = variant {
|
|
@@ -305,6 +366,21 @@ service : (minter_arg : MinterArg) -> {
|
|
|
305
366
|
// that the [get_withdrawal_account] endpoint returns.
|
|
306
367
|
retrieve_btc : (RetrieveBtcArgs) -> (variant { Ok : RetrieveBtcOk; Err : RetrieveBtcError });
|
|
307
368
|
|
|
369
|
+
// Submits a request to convert ckBTC to BTC.
|
|
370
|
+
//
|
|
371
|
+
// # Note
|
|
372
|
+
//
|
|
373
|
+
// The BTC retrieval process is slow. Instead of
|
|
374
|
+
// synchronously waiting for a BTC transaction to settle, this
|
|
375
|
+
// method returns a request ([block_index]) that the caller can use
|
|
376
|
+
// to query the request status.
|
|
377
|
+
//
|
|
378
|
+
// # Preconditions
|
|
379
|
+
//
|
|
380
|
+
// * The caller allowed the minter's principal to spend its funds
|
|
381
|
+
// using [icrc2_approve] on the ckBTC ledger.
|
|
382
|
+
retrieve_btc_with_approval : (RetrieveBtcWithApprovalArgs) -> (variant { Ok : RetrieveBtcOk; Err : RetrieveBtcWithApprovalError });
|
|
383
|
+
|
|
308
384
|
/// Returns the status of a [retrieve_btc] request.
|
|
309
385
|
retrieve_btc_status : (record { block_index : nat64 }) -> (RetrieveBtcStatus) query;
|
|
310
386
|
|
|
@@ -313,6 +389,8 @@ service : (minter_arg : MinterArg) -> {
|
|
|
313
389
|
// Section "Minter Information" {{{
|
|
314
390
|
// Returns internal minter parameters.
|
|
315
391
|
get_minter_info : () -> (MinterInfo) query;
|
|
392
|
+
|
|
393
|
+
get_canister_status : () -> (CanisterStatusResponse);
|
|
316
394
|
// }}}
|
|
317
395
|
|
|
318
396
|
// Section "Event log" {{{
|
|
@@ -34,6 +34,25 @@ export const idlFactory = ({ IDL }) => {
|
|
|
34
34
|
'Upgrade' : IDL.Opt(UpgradeArgs),
|
|
35
35
|
'Init' : InitArgs,
|
|
36
36
|
});
|
|
37
|
+
const CanisterStatusType = IDL.Variant({
|
|
38
|
+
'stopped' : IDL.Null,
|
|
39
|
+
'stopping' : IDL.Null,
|
|
40
|
+
'running' : IDL.Null,
|
|
41
|
+
});
|
|
42
|
+
const DefiniteCanisterSettings = IDL.Record({
|
|
43
|
+
'freezing_threshold' : IDL.Nat,
|
|
44
|
+
'controllers' : IDL.Vec(IDL.Principal),
|
|
45
|
+
'memory_allocation' : IDL.Nat,
|
|
46
|
+
'compute_allocation' : IDL.Nat,
|
|
47
|
+
});
|
|
48
|
+
const CanisterStatusResponse = IDL.Record({
|
|
49
|
+
'status' : CanisterStatusType,
|
|
50
|
+
'memory_size' : IDL.Nat,
|
|
51
|
+
'cycles' : IDL.Nat,
|
|
52
|
+
'settings' : DefiniteCanisterSettings,
|
|
53
|
+
'idle_cycles_burned_per_day' : IDL.Nat,
|
|
54
|
+
'module_hash' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
55
|
+
});
|
|
37
56
|
const Account = IDL.Record({
|
|
38
57
|
'owner' : IDL.Principal,
|
|
39
58
|
'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
@@ -43,7 +62,16 @@ export const idlFactory = ({ IDL }) => {
|
|
|
43
62
|
'value' : IDL.Nat64,
|
|
44
63
|
'outpoint' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8), 'vout' : IDL.Nat32 }),
|
|
45
64
|
});
|
|
65
|
+
const ReimbursementReason = IDL.Variant({
|
|
66
|
+
'CallFailed' : IDL.Null,
|
|
67
|
+
'TaintedDestination' : IDL.Record({
|
|
68
|
+
'kyt_fee' : IDL.Nat64,
|
|
69
|
+
'kyt_provider' : IDL.Principal,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
46
72
|
const BitcoinAddress = IDL.Variant({
|
|
73
|
+
'p2wsh_v0' : IDL.Vec(IDL.Nat8),
|
|
74
|
+
'p2tr_v1' : IDL.Vec(IDL.Nat8),
|
|
47
75
|
'p2sh' : IDL.Vec(IDL.Nat8),
|
|
48
76
|
'p2wpkh_v0' : IDL.Vec(IDL.Nat8),
|
|
49
77
|
'p2pkh' : IDL.Vec(IDL.Nat8),
|
|
@@ -51,8 +79,15 @@ export const idlFactory = ({ IDL }) => {
|
|
|
51
79
|
const Event = IDL.Variant({
|
|
52
80
|
'received_utxos' : IDL.Record({
|
|
53
81
|
'to_account' : Account,
|
|
82
|
+
'mint_txid' : IDL.Opt(IDL.Nat64),
|
|
54
83
|
'utxos' : IDL.Vec(Utxo),
|
|
55
84
|
}),
|
|
85
|
+
'schedule_deposit_reimbursement' : IDL.Record({
|
|
86
|
+
'burn_block_index' : IDL.Nat64,
|
|
87
|
+
'account' : Account,
|
|
88
|
+
'amount' : IDL.Nat64,
|
|
89
|
+
'reason' : ReimbursementReason,
|
|
90
|
+
}),
|
|
56
91
|
'sent_transaction' : IDL.Record({
|
|
57
92
|
'fee' : IDL.Opt(IDL.Nat64),
|
|
58
93
|
'change_output' : IDL.Opt(
|
|
@@ -72,6 +107,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
72
107
|
'upgrade' : UpgradeArgs,
|
|
73
108
|
'retrieve_btc_kyt_failed' : IDL.Record({
|
|
74
109
|
'block_index' : IDL.Nat64,
|
|
110
|
+
'owner' : IDL.Principal,
|
|
75
111
|
'uuid' : IDL.Text,
|
|
76
112
|
'address' : IDL.Text,
|
|
77
113
|
'amount' : IDL.Nat64,
|
|
@@ -100,6 +136,10 @@ export const idlFactory = ({ IDL }) => {
|
|
|
100
136
|
'submitted_at' : IDL.Nat64,
|
|
101
137
|
}),
|
|
102
138
|
'ignored_utxo' : IDL.Record({ 'utxo' : Utxo }),
|
|
139
|
+
'reimbursed_failed_deposit' : IDL.Record({
|
|
140
|
+
'burn_block_index' : IDL.Nat64,
|
|
141
|
+
'mint_block_index' : IDL.Nat64,
|
|
142
|
+
}),
|
|
103
143
|
});
|
|
104
144
|
const MinterInfo = IDL.Record({
|
|
105
145
|
'retrieve_btc_min_amount' : IDL.Nat64,
|
|
@@ -131,6 +171,23 @@ export const idlFactory = ({ IDL }) => {
|
|
|
131
171
|
'Submitted' : IDL.Record({ 'txid' : IDL.Vec(IDL.Nat8) }),
|
|
132
172
|
'Pending' : IDL.Null,
|
|
133
173
|
});
|
|
174
|
+
const RetrieveBtcWithApprovalArgs = IDL.Record({
|
|
175
|
+
'from_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)),
|
|
176
|
+
'address' : IDL.Text,
|
|
177
|
+
'amount' : IDL.Nat64,
|
|
178
|
+
});
|
|
179
|
+
const RetrieveBtcWithApprovalError = IDL.Variant({
|
|
180
|
+
'MalformedAddress' : IDL.Text,
|
|
181
|
+
'GenericError' : IDL.Record({
|
|
182
|
+
'error_message' : IDL.Text,
|
|
183
|
+
'error_code' : IDL.Nat64,
|
|
184
|
+
}),
|
|
185
|
+
'TemporarilyUnavailable' : IDL.Text,
|
|
186
|
+
'InsufficientAllowance' : IDL.Record({ 'allowance' : IDL.Nat64 }),
|
|
187
|
+
'AlreadyProcessing' : IDL.Null,
|
|
188
|
+
'AmountTooLow' : IDL.Nat64,
|
|
189
|
+
'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat64 }),
|
|
190
|
+
});
|
|
134
191
|
const UtxoStatus = IDL.Variant({
|
|
135
192
|
'ValueTooSmall' : Utxo,
|
|
136
193
|
'Tainted' : Utxo,
|
|
@@ -169,6 +226,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
169
226
|
[IDL.Text],
|
|
170
227
|
[],
|
|
171
228
|
),
|
|
229
|
+
'get_canister_status' : IDL.Func([], [CanisterStatusResponse], []),
|
|
172
230
|
'get_deposit_fee' : IDL.Func([], [IDL.Nat64], ['query']),
|
|
173
231
|
'get_events' : IDL.Func(
|
|
174
232
|
[IDL.Record({ 'start' : IDL.Nat64, 'length' : IDL.Nat64 })],
|
|
@@ -187,6 +245,16 @@ export const idlFactory = ({ IDL }) => {
|
|
|
187
245
|
[RetrieveBtcStatus],
|
|
188
246
|
['query'],
|
|
189
247
|
),
|
|
248
|
+
'retrieve_btc_with_approval' : IDL.Func(
|
|
249
|
+
[RetrieveBtcWithApprovalArgs],
|
|
250
|
+
[
|
|
251
|
+
IDL.Variant({
|
|
252
|
+
'Ok' : RetrieveBtcOk,
|
|
253
|
+
'Err' : RetrieveBtcWithApprovalError,
|
|
254
|
+
}),
|
|
255
|
+
],
|
|
256
|
+
[],
|
|
257
|
+
),
|
|
190
258
|
'update_balance' : IDL.Func(
|
|
191
259
|
[
|
|
192
260
|
IDL.Record({
|