mirror of
https://github.com/stxer/stxer-sdk.git
synced 2026-01-12 15:34:01 +08:00
feat: update stx sdk to @stacks/ v7
This commit is contained in:
@@ -53,12 +53,13 @@
|
||||
"husky": "^9.1.6",
|
||||
"size-limit": "^11.1.5",
|
||||
"tslib": "^2.7.0",
|
||||
"typescript": "^5.6.2"
|
||||
"typescript": "^5.6.2",
|
||||
"tsx": "^4.19.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stacks/network": "^6.16.0",
|
||||
"@stacks/network": "^7.0.0",
|
||||
"@stacks/stacks-blockchain-api-types": "^7.14.1",
|
||||
"@stacks/transactions": "^6.16.1",
|
||||
"@stacks/transactions": "^7.0.0",
|
||||
"c32check": "^2.0.0",
|
||||
"ts-clarity": "^0.0.26"
|
||||
}
|
||||
|
||||
64
pnpm-lock.yaml
generated
64
pnpm-lock.yaml
generated
@@ -9,14 +9,14 @@ importers:
|
||||
.:
|
||||
dependencies:
|
||||
'@stacks/network':
|
||||
specifier: ^6.16.0
|
||||
version: 6.16.0
|
||||
specifier: ^7.0.0
|
||||
version: 7.0.0
|
||||
'@stacks/stacks-blockchain-api-types':
|
||||
specifier: ^7.14.1
|
||||
version: 7.14.1
|
||||
'@stacks/transactions':
|
||||
specifier: ^6.16.1
|
||||
version: 6.16.1
|
||||
specifier: ^7.0.0
|
||||
version: 7.0.0
|
||||
c32check:
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0
|
||||
@@ -42,6 +42,9 @@ importers:
|
||||
tslib:
|
||||
specifier: ^2.7.0
|
||||
version: 2.7.0
|
||||
tsx:
|
||||
specifier: ^4.19.2
|
||||
version: 4.19.2
|
||||
typescript:
|
||||
specifier: ^5.6.2
|
||||
version: 5.6.2
|
||||
@@ -1065,15 +1068,24 @@ packages:
|
||||
'@stacks/common@6.16.0':
|
||||
resolution: {integrity: sha512-PnzvhrdGRMVZvxTulitlYafSK4l02gPCBBoI9QEoTqgSnv62oaOXhYAUUkTMFKxdHW1seVEwZsrahuXiZPIAwg==}
|
||||
|
||||
'@stacks/common@7.0.0':
|
||||
resolution: {integrity: sha512-/BKBK9S9GEuGjbnc2fBAwsG21f8cfNekG/9mXLSMwBqnh4qaQY2hxK+6wRI2YXJgpkXrpZilpZy2sdPGlVUdQA==}
|
||||
|
||||
'@stacks/network@6.16.0':
|
||||
resolution: {integrity: sha512-uqz9Nb6uf+SeyCKENJN+idt51HAfEeggQKrOMfGjpAeFgZV2CR66soB/ci9+OVQR/SURvasncAz2ScI1blfS8A==}
|
||||
|
||||
'@stacks/network@7.0.0':
|
||||
resolution: {integrity: sha512-4diddT0ii85BQ4PW6ww3l4cS7Oo0a5VIsJ7umBcCPAArIc4Sm/MIOEXIg9joKK8fVHLnWyh1p4D+febJQFfa+Q==}
|
||||
|
||||
'@stacks/stacks-blockchain-api-types@7.14.1':
|
||||
resolution: {integrity: sha512-65hvhXxC+EUqHJAQsqlBCqXB+zwfxZICSKYJugdg6BCp9I9qniyfz5XyQeC4RMVo0tgEoRdS/b5ZCFo5kLWmxA==}
|
||||
|
||||
'@stacks/transactions@6.16.1':
|
||||
resolution: {integrity: sha512-yCtUM+8IN0QJbnnlFhY1wBW7Q30Cxje3Zmy8DgqdBoM/EPPWadez/8wNWFANVAMyUZeQ9V/FY+8MAw4E+pCReA==}
|
||||
|
||||
'@stacks/transactions@7.0.0':
|
||||
resolution: {integrity: sha512-9kGTnJLwRQPugLzbdJ8MmFED+eRhlJKIXpz2mshyy238hvBc4T0jynsoJMi4qGqvJYzsiRYCLDPJVkkUde85vA==}
|
||||
|
||||
'@tootallnate/once@2.0.0':
|
||||
resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==}
|
||||
engines: {node: '>= 10'}
|
||||
@@ -2136,6 +2148,9 @@ packages:
|
||||
resolution: {integrity: sha512-g0QYk1dZBxGwk+Ngc+ltRH2IBp2f7zBkBMBJZCDerh6EhlhSR6+9irMCuT/09zD6qkarHUSn529sK/yL4S27mg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
get-tsconfig@4.8.1:
|
||||
resolution: {integrity: sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==}
|
||||
|
||||
git-hooks-list@1.0.3:
|
||||
resolution: {integrity: sha512-Y7wLWcrLUXwk2noSka166byGCvhMtDRpgHdzCno1UQv/n/Hegp++a2xBWJL1lJarnKD3SWaljD+0z1ztqxuKyQ==}
|
||||
|
||||
@@ -3135,6 +3150,9 @@ packages:
|
||||
resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
resolve-pkg-maps@1.0.0:
|
||||
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
|
||||
|
||||
resolve.exports@2.0.2:
|
||||
resolution: {integrity: sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -3491,6 +3509,11 @@ packages:
|
||||
peerDependencies:
|
||||
typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta'
|
||||
|
||||
tsx@4.19.2:
|
||||
resolution: {integrity: sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==}
|
||||
engines: {node: '>=18.0.0'}
|
||||
hasBin: true
|
||||
|
||||
type-check@0.4.0:
|
||||
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
@@ -4940,6 +4963,8 @@ snapshots:
|
||||
'@types/bn.js': 5.1.6
|
||||
'@types/node': 18.19.50
|
||||
|
||||
'@stacks/common@7.0.0': {}
|
||||
|
||||
'@stacks/network@6.16.0':
|
||||
dependencies:
|
||||
'@stacks/common': 6.16.0
|
||||
@@ -4947,6 +4972,13 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@stacks/network@7.0.0':
|
||||
dependencies:
|
||||
'@stacks/common': 7.0.0
|
||||
cross-fetch: 3.1.8
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@stacks/stacks-blockchain-api-types@7.14.1': {}
|
||||
|
||||
'@stacks/transactions@6.16.1':
|
||||
@@ -4960,6 +4992,17 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@stacks/transactions@7.0.0':
|
||||
dependencies:
|
||||
'@noble/hashes': 1.1.5
|
||||
'@noble/secp256k1': 1.7.1
|
||||
'@stacks/common': 7.0.0
|
||||
'@stacks/network': 7.0.0
|
||||
c32check: 2.0.0
|
||||
lodash.clonedeep: 4.5.0
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@tootallnate/once@2.0.0': {}
|
||||
|
||||
'@tsconfig/node10@1.0.11': {}
|
||||
@@ -6362,6 +6405,10 @@ snapshots:
|
||||
es-errors: 1.3.0
|
||||
get-intrinsic: 1.2.4
|
||||
|
||||
get-tsconfig@4.8.1:
|
||||
dependencies:
|
||||
resolve-pkg-maps: 1.0.0
|
||||
|
||||
git-hooks-list@1.0.3: {}
|
||||
|
||||
glob-parent@5.1.2:
|
||||
@@ -7555,6 +7602,8 @@ snapshots:
|
||||
|
||||
resolve-from@5.0.0: {}
|
||||
|
||||
resolve-pkg-maps@1.0.0: {}
|
||||
|
||||
resolve.exports@2.0.2: {}
|
||||
|
||||
resolve@1.22.8:
|
||||
@@ -7955,6 +8004,13 @@ snapshots:
|
||||
tslib: 1.14.1
|
||||
typescript: 5.6.2
|
||||
|
||||
tsx@4.19.2:
|
||||
dependencies:
|
||||
esbuild: 0.23.1
|
||||
get-tsconfig: 4.8.1
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
|
||||
type-check@0.4.0:
|
||||
dependencies:
|
||||
prelude-ls: 1.2.1
|
||||
|
||||
25
src/index.ts
25
src/index.ts
@@ -1,17 +1,18 @@
|
||||
import { type AccountDataResponse, getNodeInfo, richFetch } from 'ts-clarity';
|
||||
import type { Block } from '@stacks/stacks-blockchain-api-types';
|
||||
import { StacksMainnet } from '@stacks/network';
|
||||
import { STACKS_MAINNET } from '@stacks/network';
|
||||
import {
|
||||
AnchorMode,
|
||||
type ClarityValue,
|
||||
PostConditionMode,
|
||||
type StacksTransaction,
|
||||
type StacksTransactionWire,
|
||||
bufferCV,
|
||||
contractPrincipalCV,
|
||||
makeUnsignedContractCall,
|
||||
makeUnsignedContractDeploy,
|
||||
makeUnsignedSTXTokenTransfer,
|
||||
serializeCV,
|
||||
serializeCVBytes,
|
||||
stringAsciiCV,
|
||||
tupleCV,
|
||||
uintCV,
|
||||
@@ -21,9 +22,9 @@ import { c32addressDecode } from 'c32check';
|
||||
// current beta api endpoint
|
||||
const SIMULATION_API_ENDPOINT = 'https://api.stxer.xyz/simulations';
|
||||
|
||||
function runTx(tx: StacksTransaction) {
|
||||
function runTx(tx: StacksTransactionWire) {
|
||||
// type 0: run transaction
|
||||
return tupleCV({ type: uintCV(0), data: bufferCV(tx.serialize()) });
|
||||
return tupleCV({ type: uintCV(0), data: bufferCV(tx.serializeBytes()) });
|
||||
}
|
||||
|
||||
export interface SimulationEval {
|
||||
@@ -37,7 +38,7 @@ export function runEval({ contract_id, code }: SimulationEval) {
|
||||
return tupleCV({
|
||||
type: uintCV(1),
|
||||
data: bufferCV(
|
||||
serializeCV(
|
||||
serializeCVBytes(
|
||||
tupleCV({
|
||||
contract: contractPrincipalCV(contract_address, contract_name),
|
||||
code: stringAsciiCV(code),
|
||||
@@ -50,7 +51,7 @@ export function runEval({ contract_id, code }: SimulationEval) {
|
||||
export async function runSimulation(
|
||||
block_hash: string,
|
||||
block_height: number,
|
||||
txs: (StacksTransaction | SimulationEval)[]
|
||||
txs: (StacksTransactionWire | SimulationEval)[]
|
||||
) {
|
||||
const body = Buffer.concat([
|
||||
Buffer.from('sim-v1'),
|
||||
@@ -63,7 +64,7 @@ export async function runSimulation(
|
||||
.map((t) => {
|
||||
return 'contract_id' in t && 'code' in t ? runEval(t) : runTx(t);
|
||||
})
|
||||
.map((t) => serializeCV(t)),
|
||||
.map((t) => serializeCVBytes(t)),
|
||||
]);
|
||||
body.writeBigUInt64BE(BigInt(block_height), 6);
|
||||
const rs = await fetch(SIMULATION_API_ENDPOINT, {
|
||||
@@ -265,10 +266,9 @@ To get in touch: contact@stxer.xyz
|
||||
functionName: step.function_name,
|
||||
functionArgs: step.function_args ?? [],
|
||||
nonce,
|
||||
network: new StacksMainnet(),
|
||||
network: STACKS_MAINNET,
|
||||
publicKey: '',
|
||||
postConditionMode: PostConditionMode.Allow,
|
||||
anchorMode: AnchorMode.Any,
|
||||
fee: step.fee,
|
||||
});
|
||||
tx.auth.spendingCondition.signer = c32addressDecode(step.sender)[1];
|
||||
@@ -279,9 +279,8 @@ To get in touch: contact@stxer.xyz
|
||||
recipient: step.recipient,
|
||||
amount: step.amount,
|
||||
nonce,
|
||||
network: new StacksMainnet(),
|
||||
network: STACKS_MAINNET,
|
||||
publicKey: '',
|
||||
anchorMode: AnchorMode.Any,
|
||||
fee: step.fee,
|
||||
});
|
||||
tx.auth.spendingCondition.signer = c32addressDecode(step.sender)[1];
|
||||
@@ -292,10 +291,9 @@ To get in touch: contact@stxer.xyz
|
||||
contractName: step.contract_name,
|
||||
codeBody: step.source_code,
|
||||
nonce,
|
||||
network: new StacksMainnet(),
|
||||
network: STACKS_MAINNET,
|
||||
publicKey: '',
|
||||
postConditionMode: PostConditionMode.Allow,
|
||||
anchorMode: AnchorMode.Any,
|
||||
fee: step.fee,
|
||||
});
|
||||
tx.auth.spendingCondition.signer = c32addressDecode(step.deployer)[1];
|
||||
@@ -303,6 +301,7 @@ To get in touch: contact@stxer.xyz
|
||||
} else if ('code' in step) {
|
||||
txs.push(step);
|
||||
} else {
|
||||
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
|
||||
console.log(`Invalid simulation step:`, step);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user