mirror of
https://github.com/innopals/ts-clarity.git
synced 2026-01-12 22:27:15 +08:00
@@ -1,2 +1,2 @@
|
||||
nodejs 20.13.1
|
||||
pnpm 9.1.2
|
||||
nodejs 22.11.0
|
||||
pnpm 9.12.3
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
@@ -16,7 +16,7 @@
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "single",
|
||||
"trailingComma": "all",
|
||||
"trailingCommas": "all",
|
||||
"semicolons": "always"
|
||||
}
|
||||
},
|
||||
|
||||
20
package.json
20
package.json
@@ -9,7 +9,7 @@
|
||||
"deps": "pnpx taze -r",
|
||||
"format": "biome format . --write",
|
||||
"lint": "biome check .",
|
||||
"lint:fix": "pnpm lint --apply",
|
||||
"lint:fix": "pnpm lint --write",
|
||||
"lint:unused": "pnpm clean && knip",
|
||||
"prepare": "npx simple-git-hooks",
|
||||
"prepublishOnly": "tsc && node build/formatPackageJson.js",
|
||||
@@ -22,17 +22,17 @@
|
||||
"typecheck:propertyTypes": "pnpm run --r --parallel typecheck --exactOptionalPropertyTypes false && tsc --noEmit --exactOptionalPropertyTypes false"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.7.3",
|
||||
"@types/node": "^20.12.12",
|
||||
"@vitest/coverage-v8": "^1.6.0",
|
||||
"knip": "^5.16.0",
|
||||
"publint": "^0.2.8",
|
||||
"rimraf": "^5.0.7",
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@types/node": "^22.8.5",
|
||||
"@vitest/coverage-v8": "^2.1.4",
|
||||
"knip": "^5.34.4",
|
||||
"publint": "^0.2.12",
|
||||
"rimraf": "^6.0.1",
|
||||
"simple-git-hooks": "^2.11.1",
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^1.6.0"
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^2.1.4"
|
||||
},
|
||||
"packageManager": "pnpm@9.1.2",
|
||||
"packageManager": "pnpm@9.12.3",
|
||||
"simple-git-hooks": {
|
||||
"pre-commit": "pnpm run lint"
|
||||
},
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stacks/stacks-blockchain-api-types": "^7.10.0",
|
||||
"@stacks/transactions": "^6.15.0",
|
||||
"@stacks/stacks-blockchain-api-types": "^7.14.1",
|
||||
"@stacks/transactions": "^6.17.0",
|
||||
"clarity-abi": "^0.0.20",
|
||||
"cross-fetch": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"contributors": ["bestmike007 <bestmike007@gmail.com>"],
|
||||
"keywords": ["abi", "clarity", "stacks", "typescript", "sdk", "web3"]
|
||||
|
||||
@@ -7,7 +7,7 @@ test('call readonly without args', async () => {
|
||||
const rs = await callReadonly({
|
||||
abi: SIP010TraitABI.functions,
|
||||
functionName: 'get-total-supply',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
||||
});
|
||||
console.log(rs);
|
||||
assert(rs.type === 'success');
|
||||
@@ -18,9 +18,9 @@ test('call readonly with args', async () => {
|
||||
const rs = await callReadonly({
|
||||
abi: SIP010TraitABI.functions,
|
||||
functionName: 'get-balance',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
||||
args: {
|
||||
who: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9',
|
||||
who: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
||||
},
|
||||
});
|
||||
console.log(rs);
|
||||
@@ -37,7 +37,7 @@ test('call readonly with unknown ABI', async () => {
|
||||
const rs = await callReadonly({
|
||||
abi: abi.functions,
|
||||
functionName: 'get-total-supply',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
||||
});
|
||||
console.log(rs);
|
||||
});
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
import type { ClarityAbi } from 'clarity-abi';
|
||||
import { assert, test } from 'vitest';
|
||||
import ammSwapPoolV11 from '../../../test/abis/amm-swap-pool-v1-1.js';
|
||||
import AmmVault from '../../../test/abis/amm-vault-v2-01.js';
|
||||
import { readMap } from './read-map.js';
|
||||
|
||||
test('read map', async () => {
|
||||
const rs = await readMap({
|
||||
abi: ammSwapPoolV11.maps,
|
||||
mapName: 'pools-id-map',
|
||||
key: 1n,
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.amm-swap-pool-v1-1',
|
||||
abi: AmmVault.maps,
|
||||
mapName: 'approved-tokens',
|
||||
key: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
||||
});
|
||||
console.log(rs);
|
||||
assert(rs != null);
|
||||
assert(rs.factor > 0n);
|
||||
assert(rs != null && rs === true);
|
||||
});
|
||||
|
||||
test('read map with unknown abi', async () => {
|
||||
const abi: ClarityAbi = ammSwapPoolV11 as unknown as ClarityAbi;
|
||||
const abi: ClarityAbi = AmmVault as unknown as ClarityAbi;
|
||||
let rs = await readMap({
|
||||
abi: abi.maps,
|
||||
mapName: 'pools-id-map',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.amm-swap-pool-v1-1',
|
||||
key: 1n,
|
||||
mapName: 'reserve',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
||||
key: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex',
|
||||
});
|
||||
console.log(rs);
|
||||
rs = {};
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import type { ClarityAbi } from 'clarity-abi';
|
||||
import { assert, test } from 'vitest';
|
||||
import ammSwapPoolV11 from '../../../test/abis/amm-swap-pool-v1-1.js';
|
||||
import AmmVault from '../../../test/abis/amm-vault-v2-01.js';
|
||||
import { readVariable } from './read-variable.js';
|
||||
|
||||
test('read variable', async () => {
|
||||
const rs = await readVariable({
|
||||
abi: ammSwapPoolV11.variables,
|
||||
variableName: 'contract-owner',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.amm-swap-pool-v1-1',
|
||||
abi: AmmVault.variables,
|
||||
variableName: 'paused',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
||||
});
|
||||
assert(String(rs) === 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9');
|
||||
assert(rs === false);
|
||||
});
|
||||
|
||||
test('read variable with unknown ABI', async () => {
|
||||
const abi: ClarityAbi = ammSwapPoolV11 as unknown as ClarityAbi;
|
||||
const abi: ClarityAbi = AmmVault as unknown as ClarityAbi;
|
||||
const rs = await readVariable({
|
||||
abi: abi.variables,
|
||||
variableName: 'contract-owner',
|
||||
contract: 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.amm-swap-pool-v1-1',
|
||||
variableName: 'paused',
|
||||
contract: 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01',
|
||||
});
|
||||
assert(String(rs) === 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9');
|
||||
assert(rs === false);
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
203
packages/ts-clarity/test/abis/amm-vault-v2-01.ts
Normal file
203
packages/ts-clarity/test/abis/amm-vault-v2-01.ts
Normal file
@@ -0,0 +1,203 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
maps: [
|
||||
{ key: 'principal', name: 'approved-flash-loan-users', value: 'bool' },
|
||||
{ key: 'principal', name: 'approved-tokens', value: 'bool' },
|
||||
{ key: 'principal', name: 'reserve', value: 'uint128' },
|
||||
],
|
||||
epoch: 'Epoch25',
|
||||
functions: [
|
||||
{
|
||||
args: [{ name: 'flash-loan-user-trait', type: 'principal' }],
|
||||
name: 'check-is-approved-flash-loan-user',
|
||||
access: 'private',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [{ name: 'flash-loan-token', type: 'principal' }],
|
||||
name: 'check-is-approved-token',
|
||||
access: 'private',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'a', type: 'uint128' },
|
||||
{ name: 'b', type: 'uint128' },
|
||||
],
|
||||
name: 'mul-down',
|
||||
access: 'private',
|
||||
outputs: { type: 'uint128' },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'a', type: 'uint128' },
|
||||
{ name: 'b', type: 'uint128' },
|
||||
],
|
||||
name: 'mul-up',
|
||||
access: 'private',
|
||||
outputs: { type: 'uint128' },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-trait', type: 'principal' },
|
||||
{ name: 'amount', type: 'uint128' },
|
||||
],
|
||||
name: 'add-to-reserve',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'flash-loan-user-trait', type: 'trait_reference' },
|
||||
{ name: 'token-trait', type: 'trait_reference' },
|
||||
{ name: 'amount', type: 'uint128' },
|
||||
{ name: 'memo', type: { optional: { buffer: { length: 16 } } } },
|
||||
],
|
||||
name: 'flash-loan',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'uint128', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [{ name: 'new-paused', type: 'bool' }],
|
||||
name: 'pause',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-trait', type: 'principal' },
|
||||
{ name: 'amount', type: 'uint128' },
|
||||
],
|
||||
name: 'remove-from-reserve',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'flash-loan-user-trait', type: 'principal' },
|
||||
{ name: 'approved', type: 'bool' },
|
||||
],
|
||||
name: 'set-approved-flash-loan-user',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-trait', type: 'principal' },
|
||||
{ name: 'approved', type: 'bool' },
|
||||
],
|
||||
name: 'set-approved-token',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [{ name: 'enabled', type: 'bool' }],
|
||||
name: 'set-flash-loan-enabled',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [{ name: 'fee', type: 'uint128' }],
|
||||
name: 'set-flash-loan-fee-rate',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-trait', type: 'trait_reference' },
|
||||
{ name: 'amount', type: 'uint128' },
|
||||
{ name: 'recipient', type: 'principal' },
|
||||
],
|
||||
name: 'transfer-ft',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-x-trait', type: 'trait_reference' },
|
||||
{ name: 'dx', type: 'uint128' },
|
||||
{ name: 'token-y-trait', type: 'trait_reference' },
|
||||
{ name: 'dy', type: 'uint128' },
|
||||
{ name: 'recipient', type: 'principal' },
|
||||
],
|
||||
name: 'transfer-ft-two',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [
|
||||
{ name: 'token-trait', type: 'trait_reference' },
|
||||
{ name: 'token-id', type: 'uint128' },
|
||||
{ name: 'amount', type: 'uint128' },
|
||||
{ name: 'recipient', type: 'principal' },
|
||||
],
|
||||
name: 'transfer-sft',
|
||||
access: 'public',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [],
|
||||
name: 'get-flash-loan-enabled',
|
||||
access: 'read_only',
|
||||
outputs: { type: 'bool' },
|
||||
},
|
||||
{
|
||||
args: [],
|
||||
name: 'get-flash-loan-fee-rate',
|
||||
access: 'read_only',
|
||||
outputs: { type: 'uint128' },
|
||||
},
|
||||
{
|
||||
args: [{ name: 'token-trait', type: 'principal' }],
|
||||
name: 'get-reserve',
|
||||
access: 'read_only',
|
||||
outputs: { type: 'uint128' },
|
||||
},
|
||||
{
|
||||
args: [],
|
||||
name: 'is-dao-or-extension',
|
||||
access: 'read_only',
|
||||
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
|
||||
},
|
||||
{
|
||||
args: [],
|
||||
name: 'is-paused',
|
||||
access: 'read_only',
|
||||
outputs: { type: 'bool' },
|
||||
},
|
||||
],
|
||||
variables: [
|
||||
{
|
||||
name: 'ERR-AMOUNT-EXCEED-RESERVE',
|
||||
type: { response: { ok: 'none', error: 'uint128' } },
|
||||
access: 'constant',
|
||||
},
|
||||
{
|
||||
name: 'ERR-INVALID-BALANCE',
|
||||
type: { response: { ok: 'none', error: 'uint128' } },
|
||||
access: 'constant',
|
||||
},
|
||||
{
|
||||
name: 'ERR-INVALID-TOKEN',
|
||||
type: { response: { ok: 'none', error: 'uint128' } },
|
||||
access: 'constant',
|
||||
},
|
||||
{
|
||||
name: 'ERR-NOT-AUTHORIZED',
|
||||
type: { response: { ok: 'none', error: 'uint128' } },
|
||||
access: 'constant',
|
||||
},
|
||||
{
|
||||
name: 'ERR-PAUSED',
|
||||
type: { response: { ok: 'none', error: 'uint128' } },
|
||||
access: 'constant',
|
||||
},
|
||||
{ name: 'ONE_8', type: 'uint128', access: 'constant' },
|
||||
{ name: 'flash-loan-enabled', type: 'bool', access: 'variable' },
|
||||
{ name: 'flash-loan-fee-rate', type: 'uint128', access: 'variable' },
|
||||
{ name: 'paused', type: 'bool', access: 'variable' },
|
||||
],
|
||||
clarity_version: 'Clarity2',
|
||||
fungible_tokens: [],
|
||||
non_fungible_tokens: [],
|
||||
} as const;
|
||||
1649
pnpm-lock.yaml
generated
1649
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user