stxer 0.4.5 → 0.7.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.
@@ -1,42 +0,0 @@
1
- import { uintCV } from '@stacks/transactions';
2
- import { SimulationBuilder } from '..';
3
-
4
- const sender = 'SP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER';
5
-
6
- const test = () =>
7
- SimulationBuilder.new()
8
- .withSender(sender)
9
- .addContractDeploy({
10
- contract_name: 'test-simulation',
11
- source_code: `
12
- ;; counter example
13
- (define-data-var counter uint u0)
14
-
15
- (define-public (increment (delta uint))
16
- (begin
17
- (var-set counter (+ (var-get counter) delta))
18
- (ok (var-get counter))))
19
-
20
- (define-public (decrement)
21
- (begin
22
- (var-set counter (- (var-get counter) u1))
23
- (ok (var-get counter))))
24
-
25
- (define-read-only (get-counter)
26
- (ok (var-get counter)))
27
- `,
28
- })
29
- .addEvalCode(`${sender}.test-simulation`, '(get-counter)')
30
- .addContractCall({
31
- contract_id: `${sender}.test-simulation`,
32
- function_name: 'increment',
33
- function_args: [uintCV(10)],
34
- })
35
- .addEvalCode(`${sender}.test-simulation`, '(get-counter)')
36
- .run();
37
-
38
- if (require.main === module) {
39
- (async () => {
40
- await test();
41
- })().catch(console.error);
42
- }
@@ -1,139 +0,0 @@
1
- import {
2
- contractPrincipalCV,
3
- principalCV,
4
- tupleCV,
5
- uintCV,
6
- } from '@stacks/transactions';
7
- import { SIP010TraitABI } from 'clarity-abi/abis';
8
- import { unwrapResponse } from 'ts-clarity';
9
- import { batchRead } from '../BatchAPI';
10
- import { BatchProcessor } from '../BatchProcessor';
11
- import { callReadonly, readMap, readVariable } from '../clarity-api';
12
-
13
- async function batchReadsExample() {
14
- const rs = await batchRead({
15
- // index_block_hash:
16
- // 'ce04817b9c6d90814ff9c06228d3a07d64335b1d9b01a233456fc304e34f7c0e', // block 373499
17
- variables: [
18
- {
19
- contract: contractPrincipalCV(
20
- 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275',
21
- 'liquidity-token-v5kbe3oqvac',
22
- ),
23
- variableName: 'balance-x',
24
- },
25
- {
26
- contract: contractPrincipalCV(
27
- 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275',
28
- 'liquidity-token-v5kbe3oqvac',
29
- ),
30
- variableName: 'balance-y',
31
- },
32
- {
33
- contract: contractPrincipalCV(
34
- 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275',
35
- 'liquidity-token-v5kbe3oqvac',
36
- ),
37
- variableName: 'something-not-exists',
38
- },
39
- ],
40
- maps: [
41
- {
42
- contract: contractPrincipalCV(
43
- 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM',
44
- 'amm-registry-v2-01',
45
- ),
46
- mapName: 'pools-data-map',
47
- mapKey: tupleCV({
48
- 'token-x': principalCV(
49
- 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-wstx-v2',
50
- ),
51
- 'token-y': principalCV(
52
- 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
53
- ),
54
- factor: uintCV(1e8),
55
- }),
56
- },
57
- {
58
- contract: contractPrincipalCV(
59
- 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1',
60
- 'univ2-core',
61
- ),
62
- mapName: 'pools',
63
- mapKey: uintCV(1),
64
- },
65
- {
66
- contract: contractPrincipalCV(
67
- 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1',
68
- 'contract-not-exists',
69
- ),
70
- mapName: 'pools',
71
- mapKey: uintCV(1),
72
- },
73
- ],
74
- });
75
- console.log(rs);
76
- }
77
-
78
- async function batchQueueProcessorExample() {
79
- const processor = new BatchProcessor({
80
- stxerAPIEndpoint: 'https://api.stxer.xyz',
81
- batchDelayMs: 1000,
82
- });
83
-
84
- const promiseA = processor.read({
85
- mode: 'variable',
86
- contractAddress: 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275',
87
- contractName: 'liquidity-token-v5kbe3oqvac',
88
- variableName: 'balance-x',
89
- });
90
-
91
- const promiseB = processor.read({
92
- mode: 'variable',
93
- contractAddress: 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275',
94
- contractName: 'liquidity-token-v5kbe3oqvac',
95
- variableName: 'balance-y',
96
- });
97
-
98
- const result = await Promise.all([promiseA, promiseB]);
99
- console.log(result);
100
- }
101
-
102
- async function batchSip010Example() {
103
- const supply = callReadonly({
104
- abi: SIP010TraitABI.functions,
105
- functionName: 'get-total-supply',
106
- contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
107
- }).then(unwrapResponse);
108
- const balance = callReadonly({
109
- abi: SIP010TraitABI.functions,
110
- functionName: 'get-balance',
111
- contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
112
- args: {
113
- who: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
114
- },
115
- }).then(unwrapResponse);
116
- const paused = readVariable({
117
- abi: [{ name: 'paused', type: 'bool', access: 'variable' }],
118
- variableName: 'paused',
119
- contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
120
- });
121
- const approved = readMap({
122
- abi: [{ key: 'principal', name: 'approved-tokens', value: 'bool' }],
123
- mapName: 'approved-tokens',
124
- key: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
125
- contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
126
- });
127
- const result = await Promise.all([supply, balance, paused, approved]);
128
- console.log(result);
129
- }
130
-
131
- async function main() {
132
- await batchReadsExample();
133
- await batchQueueProcessorExample();
134
- await batchSip010Example();
135
- }
136
-
137
- if (require.main === module) {
138
- main().catch(console.error);
139
- }