@btc-vision/btc-runtime 1.11.1 → 1.11.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/btc-runtime",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.3",
|
|
4
4
|
"description": "Bitcoin L1 Smart Contract Runtime for OP_NET. Build decentralized applications on Bitcoin using AssemblyScript and WebAssembly. Fully audited.",
|
|
5
5
|
"main": "btc/index.ts",
|
|
6
6
|
"types": "btc/index.ts",
|
|
@@ -64,18 +64,19 @@
|
|
|
64
64
|
"@btc-vision/assemblyscript": "^0.29.3",
|
|
65
65
|
"@btc-vision/opnet-transform": "^1.2.2",
|
|
66
66
|
"@eslint/js": "^10.0.1",
|
|
67
|
-
"eslint": "^10.0
|
|
67
|
+
"eslint": "^10.3.0",
|
|
68
68
|
"gulplog": "^2.2.0",
|
|
69
69
|
"ts-node": "^10.9.2",
|
|
70
|
-
"typescript": "^
|
|
71
|
-
"typescript-eslint": "^8.
|
|
70
|
+
"typescript": "^6.0.3",
|
|
71
|
+
"typescript-eslint": "^8.59.2"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@btc-vision/as-covers-assembly": "^0.4.
|
|
75
|
-
"@btc-vision/as-covers-transform": "^0.4.
|
|
76
|
-
"@btc-vision/as-pect-assembly": "^8.
|
|
77
|
-
"@btc-vision/as-pect-cli": "^8.
|
|
78
|
-
"@btc-vision/as-pect-transform": "^8.
|
|
79
|
-
"@types/node": "^25.
|
|
74
|
+
"@btc-vision/as-covers-assembly": "^0.4.5",
|
|
75
|
+
"@btc-vision/as-covers-transform": "^0.4.5",
|
|
76
|
+
"@btc-vision/as-pect-assembly": "^8.3.0",
|
|
77
|
+
"@btc-vision/as-pect-cli": "^8.3.0",
|
|
78
|
+
"@btc-vision/as-pect-transform": "^8.3.0",
|
|
79
|
+
"@types/node": "^25.6.2",
|
|
80
|
+
"yaml": "^2.8.4"
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from '../constants/Exports';
|
|
22
22
|
import { Blockchain } from '../env';
|
|
23
23
|
import { sha256, sha256String } from '../env/global';
|
|
24
|
-
import { OP20ApprovedEvent, OP20BurnedEvent, OP20MintedEvent, OP20TransferredEvent } from '../events/predefined';
|
|
24
|
+
import { OP20ApprovedEvent, OP20BurnedEvent, OP20MintedEvent, OP20TransferredEvent, } from '../events/predefined';
|
|
25
25
|
import { Selector } from '../math/abi';
|
|
26
26
|
import { EMPTY_POINTER } from '../math/bytes';
|
|
27
27
|
import { AddressMemoryMap } from '../memory/AddressMemoryMap';
|
|
@@ -476,74 +476,6 @@ export abstract class OP20 extends ReentrancyGuard implements IOP20 {
|
|
|
476
476
|
return new BytesWriter(0);
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
-
/**
|
|
480
|
-
* Increases allowance using an EIP-712 typed signature (gasless approval).
|
|
481
|
-
*
|
|
482
|
-
* @param calldata - Contains owner, spender, amount, deadline, and signature
|
|
483
|
-
* @emits Approved event
|
|
484
|
-
*
|
|
485
|
-
* @throws {Revert} If signature is invalid or expired
|
|
486
|
-
*
|
|
487
|
-
* @remarks
|
|
488
|
-
* Enables gasless approvals where a third party can submit the transaction.
|
|
489
|
-
* Uses Schnorr signatures now, will support ML-DSA after quantum transition.
|
|
490
|
-
*/
|
|
491
|
-
@method(
|
|
492
|
-
{ name: 'owner', type: ABIDataTypes.BYTES32 },
|
|
493
|
-
{ name: 'ownerTweakedPublicKey', type: ABIDataTypes.BYTES32 },
|
|
494
|
-
{ name: 'spender', type: ABIDataTypes.ADDRESS },
|
|
495
|
-
{ name: 'amount', type: ABIDataTypes.UINT256 },
|
|
496
|
-
{ name: 'deadline', type: ABIDataTypes.UINT64 },
|
|
497
|
-
{ name: 'signature', type: ABIDataTypes.BYTES },
|
|
498
|
-
)
|
|
499
|
-
@emit('Approved')
|
|
500
|
-
public increaseAllowanceBySignature(calldata: Calldata): BytesWriter {
|
|
501
|
-
const ownerAddress = calldata.readBytesArray(ADDRESS_BYTE_LENGTH);
|
|
502
|
-
const ownerTweakedPublicKey = calldata.readBytesArray(ADDRESS_BYTE_LENGTH);
|
|
503
|
-
|
|
504
|
-
const owner = new ExtendedAddress(ownerTweakedPublicKey, ownerAddress);
|
|
505
|
-
|
|
506
|
-
const spender: Address = calldata.readAddress();
|
|
507
|
-
const amount: u256 = calldata.readU256();
|
|
508
|
-
const deadline: u64 = calldata.readU64();
|
|
509
|
-
const signature = calldata.readBytesWithLength();
|
|
510
|
-
|
|
511
|
-
this._increaseAllowanceBySignature(owner, spender, amount, deadline, signature);
|
|
512
|
-
return new BytesWriter(0);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Decreases allowance using an EIP-712 typed signature.
|
|
517
|
-
*
|
|
518
|
-
* @param calldata - Contains owner, spender, amount, deadline, and signature
|
|
519
|
-
* @emits Approved event
|
|
520
|
-
*
|
|
521
|
-
* @throws {Revert} If signature is invalid or expired
|
|
522
|
-
*/
|
|
523
|
-
@method(
|
|
524
|
-
{ name: 'owner', type: ABIDataTypes.BYTES32 },
|
|
525
|
-
{ name: 'ownerTweakedPublicKey', type: ABIDataTypes.BYTES32 },
|
|
526
|
-
{ name: 'spender', type: ABIDataTypes.ADDRESS },
|
|
527
|
-
{ name: 'amount', type: ABIDataTypes.UINT256 },
|
|
528
|
-
{ name: 'deadline', type: ABIDataTypes.UINT64 },
|
|
529
|
-
{ name: 'signature', type: ABIDataTypes.BYTES },
|
|
530
|
-
)
|
|
531
|
-
@emit('Approved')
|
|
532
|
-
public decreaseAllowanceBySignature(calldata: Calldata): BytesWriter {
|
|
533
|
-
const ownerAddress = calldata.readBytesArray(ADDRESS_BYTE_LENGTH);
|
|
534
|
-
const ownerTweakedPublicKey = calldata.readBytesArray(ADDRESS_BYTE_LENGTH);
|
|
535
|
-
|
|
536
|
-
const owner = new ExtendedAddress(ownerTweakedPublicKey, ownerAddress);
|
|
537
|
-
|
|
538
|
-
const spender: Address = calldata.readAddress();
|
|
539
|
-
const amount: u256 = calldata.readU256();
|
|
540
|
-
const deadline: u64 = calldata.readU64();
|
|
541
|
-
const signature = calldata.readBytesWithLength();
|
|
542
|
-
|
|
543
|
-
this._decreaseAllowanceBySignature(owner, spender, amount, deadline, signature);
|
|
544
|
-
return new BytesWriter(0);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
479
|
/**
|
|
548
480
|
* Burns tokens from the sender's balance.
|
|
549
481
|
*
|
|
@@ -861,6 +793,7 @@ export abstract class OP20 extends ReentrancyGuard implements IOP20 {
|
|
|
861
793
|
if (owner === Address.zero()) {
|
|
862
794
|
throw new Revert('Invalid approver');
|
|
863
795
|
}
|
|
796
|
+
|
|
864
797
|
if (spender === Address.zero()) {
|
|
865
798
|
throw new Revert('Invalid spender');
|
|
866
799
|
}
|
|
@@ -19,6 +19,4 @@ export interface IOP20 {
|
|
|
19
19
|
burn(callData: Calldata): BytesWriter;
|
|
20
20
|
increaseAllowance(callData: Calldata): BytesWriter;
|
|
21
21
|
decreaseAllowance(callData: Calldata): BytesWriter;
|
|
22
|
-
increaseAllowanceBySignature(callData: Calldata): BytesWriter;
|
|
23
|
-
decreaseAllowanceBySignature(callData: Calldata): BytesWriter;
|
|
24
22
|
}
|
|
@@ -14,19 +14,9 @@ export const transferSignature = 'transfer(address,uint256)';
|
|
|
14
14
|
export const transferFromSignature = 'transferFrom(address,address,uint256)';
|
|
15
15
|
export const SafeTransferSignature = 'safeTransfer(address,uint256,bytes)';
|
|
16
16
|
export const SafeTransferFromSignature = 'safeTransferFrom(address,address,uint256,bytes)';
|
|
17
|
-
export const IncreaseAllowanceSignature = 'increaseAllowance(address,uint256)';
|
|
18
|
-
export const DecreaseAllowanceSignature = 'decreaseAllowance(address,uint256)';
|
|
19
17
|
export const BurnSignature = 'burn(uint256)';
|
|
20
18
|
|
|
21
19
|
export class TransferHelper {
|
|
22
|
-
public static get INCREASE_ALLOWANCE_SELECTOR(): Selector {
|
|
23
|
-
return encodeSelector(IncreaseAllowanceSignature);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public static get DECREASE_ALLOWANCE_SELECTOR(): Selector {
|
|
27
|
-
return encodeSelector(DecreaseAllowanceSignature);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
public static get TRANSFER_SELECTOR(): Selector {
|
|
31
21
|
return encodeSelector(transferSignature);
|
|
32
22
|
}
|
|
@@ -43,28 +33,6 @@ export class TransferHelper {
|
|
|
43
33
|
return encodeSelector(SafeTransferFromSignature);
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
public static increaseAllowance(token: Address, spender: Address, amount: u256): void {
|
|
47
|
-
const calldata = new BytesWriter(
|
|
48
|
-
SELECTOR_BYTE_LENGTH + ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH,
|
|
49
|
-
);
|
|
50
|
-
calldata.writeSelector(this.INCREASE_ALLOWANCE_SELECTOR);
|
|
51
|
-
calldata.writeAddress(spender);
|
|
52
|
-
calldata.writeU256(amount);
|
|
53
|
-
|
|
54
|
-
Blockchain.call(token, calldata);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static decreaseAllowance(token: Address, spender: Address, amount: u256): void {
|
|
58
|
-
const calldata = new BytesWriter(
|
|
59
|
-
SELECTOR_BYTE_LENGTH + ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH,
|
|
60
|
-
);
|
|
61
|
-
calldata.writeSelector(this.DECREASE_ALLOWANCE_SELECTOR);
|
|
62
|
-
calldata.writeAddress(spender);
|
|
63
|
-
calldata.writeU256(amount);
|
|
64
|
-
|
|
65
|
-
Blockchain.call(token, calldata);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
36
|
public static transfer(token: Address, to: Address, amount: u256): void {
|
|
69
37
|
const calldata = new BytesWriter(
|
|
70
38
|
SELECTOR_BYTE_LENGTH + ADDRESS_BYTE_LENGTH + U256_BYTE_LENGTH,
|