@secondlayer/stacks 3.3.0 → 4.0.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/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
- package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
- package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
- package/dist/shared/{stacks-s361pmzs.cjs → stacks-90jcxs98.js} +84 -2
- package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-90jcxs98.js.map} +6 -4
- package/dist/shared/{stacks-8e5atbps.cjs → stacks-dr5en54r.cjs} +9 -2
- package/dist/shared/{stacks-8e5atbps.cjs.map → stacks-dr5en54r.cjs.map} +2 -2
- package/dist/shared/{stacks-bm49tsh0.js → stacks-fse1f76h.js} +2 -3
- package/dist/shared/{stacks-bm49tsh0.js.map → stacks-fse1f76h.js.map} +1 -1
- package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
- package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
- package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
- package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
- package/dist/shared/{stacks-r1m1r72q.js → stacks-thkhfwz8.js} +35 -5
- package/dist/shared/{stacks-r1m1r72q.js.map → stacks-thkhfwz8.js.map} +4 -3
- package/dist/shared/{stacks-v1hzk599.js → stacks-z3vztaz1.js} +7 -9
- package/dist/shared/{stacks-v1hzk599.js.map → stacks-z3vztaz1.js.map} +2 -2
- package/dist/shared/{stacks-fvnxj77s.cjs → stacks-zwgsbbb2.cjs} +28 -2
- package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-zwgsbbb2.cjs.map} +4 -3
- package/dist/src/actions/index.js +18 -23
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.js +3 -5
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.js +5 -8
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/index.js +19 -25
- package/dist/src/index.js.map +2 -2
- package/dist/src/postconditions/index.js +2 -3
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.js +5 -8
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.js +5 -7
- package/dist/src/pox5/index.js.map +2 -2
- package/dist/src/sbtc/index.cjs +2 -2
- package/dist/src/sbtc/index.cjs.map +3 -3
- package/dist/src/sbtc/index.d.cts +3 -3
- package/dist/src/sbtc/index.d.ts +3 -3
- package/dist/src/sbtc/index.js +5 -7
- package/dist/src/sbtc/index.js.map +3 -3
- package/dist/src/stackingdao/index.js +5 -8
- package/dist/src/stackingdao/index.js.map +2 -2
- package/package.json +1 -6
- package/dist/shared/stacks-1mpmzzyp.js +0 -85
- package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
- package/dist/shared/stacks-44y18a8e.cjs +0 -28
- package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
- package/dist/shared/stacks-8khy9v27.cjs +0 -7
- package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
- package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
- package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
- package/dist/shared/stacks-fh48neva.js +0 -13
- package/dist/shared/stacks-fh48neva.js.map +0 -10
- package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
- package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
- package/dist/shared/stacks-w8tt1fmt.js +0 -44
- package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
- package/dist/shared/stacks-z53fwfcm.js +0 -3
- package/dist/shared/stacks-z53fwfcm.js.map +0 -9
- package/dist/src/x402/index.cjs +0 -65
- package/dist/src/x402/index.cjs.map +0 -11
- package/dist/src/x402/index.d.cts +0 -501
- package/dist/src/x402/index.d.ts +0 -501
- package/dist/src/x402/index.js +0 -90
- package/dist/src/x402/index.js.map +0 -11
- /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"import { getContract } from \"../actions/getContract.ts\";\nimport { SIP010_ABI } from \"../clarity/abi/standards.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { Pc } from \"../postconditions/index.ts\";\nimport {\n\tDATA_CORE_V1_ABI,\n\tDATA_CORE_V3_ABI,\n\tRESERVE_V1_ABI,\n\tSTACKING_DAO_CORE_ABI,\n} from \"./abi.ts\";\nimport { STACKINGDAO_CONTRACTS, TRAIT_CONTRACTS } from \"./constants.ts\";\nimport type {\n\tDepositParams,\n\tExchangeRateInfo,\n\tFeeInfo,\n\tInitWithdrawParams,\n\tWithdrawIdleParams,\n\tWithdrawParams,\n\tWithdrawalInfo,\n} from \"./types.ts\";\n\nfunction assertMainnet(client: Client) {\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\tif (client.chain.network !== \"mainnet\") {\n\t\tthrow new Error(\"StackingDAO is only available on mainnet\");\n\t}\n}\n\nfunction getCoreContract(client: Client) {\n\tassertMainnet(client);\n\tconst c = STACKINGDAO_CONTRACTS.core;\n\treturn getContract({\n\t\tclient,\n\t\taddress: c.address,\n\t\tname: c.name,\n\t\tabi: STACKING_DAO_CORE_ABI,\n\t});\n}\n\nfunction getStstxToken(client: Client) {\n\tassertMainnet(client);\n\tconst c = STACKINGDAO_CONTRACTS.ststxToken;\n\treturn getContract({\n\t\tclient,\n\t\taddress: c.address,\n\t\tname: c.name,\n\t\tabi: SIP010_ABI,\n\t});\n}\n\nfunction getDataCoreV1(client: Client) {\n\tassertMainnet(client);\n\tconst c = STACKINGDAO_CONTRACTS.dataCoreV1;\n\treturn getContract({\n\t\tclient,\n\t\taddress: c.address,\n\t\tname: c.name,\n\t\tabi: DATA_CORE_V1_ABI,\n\t});\n}\n\nfunction getDataCoreV3(client: Client) {\n\tassertMainnet(client);\n\tconst c = STACKINGDAO_CONTRACTS.dataCore;\n\treturn getContract({\n\t\tclient,\n\t\taddress: c.address,\n\t\tname: c.name,\n\t\tabi: DATA_CORE_V3_ABI,\n\t});\n}\n\nfunction getReserveContract(client: Client) {\n\tassertMainnet(client);\n\tconst c = STACKINGDAO_CONTRACTS.reserve;\n\treturn getContract({\n\t\tclient,\n\t\taddress: c.address,\n\t\tname: c.name,\n\t\tabi: RESERVE_V1_ABI,\n\t});\n}\n\nconst traits = {\n\treserve: TRAIT_CONTRACTS.reserve,\n\tcommissionContract: TRAIT_CONTRACTS.commission,\n\tstakingContract: TRAIT_CONTRACTS.staking,\n\tdirectHelpers: TRAIT_CONTRACTS.directHelpers,\n};\n\n// ── User Actions ──\n\nexport async function deposit(\n\tclient: Client,\n\tparams: DepositParams,\n): Promise<string> {\n\tconst core = getCoreContract(client);\n\treturn core.call.deposit(\n\t\t{\n\t\t\t...traits,\n\t\t\tstxAmount: params.amount,\n\t\t\treferrer: params.referrer ?? null,\n\t\t\tpool: params.pool ?? null,\n\t\t},\n\t\t{\n\t\t\tpostConditions: client.account?.address\n\t\t\t\t? [\n\t\t\t\t\t\tPc.principal(client.account.address)\n\t\t\t\t\t\t\t.willSendEq(params.amount)\n\t\t\t\t\t\t\t.ustx(),\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t},\n\t);\n}\n\nexport async function initWithdraw(\n\tclient: Client,\n\tparams: InitWithdrawParams,\n): Promise<string> {\n\tconst core = getCoreContract(client);\n\tconst ststx = STACKINGDAO_CONTRACTS.ststxToken;\n\treturn core.call.initWithdraw(\n\t\t{\n\t\t\treserve: traits.reserve,\n\t\t\tdirectHelpers: traits.directHelpers,\n\t\t\tststxAmount: params.ststxAmount,\n\t\t},\n\t\t{\n\t\t\tpostConditions: client.account?.address\n\t\t\t\t? [\n\t\t\t\t\t\tPc.principal(client.account.address)\n\t\t\t\t\t\t\t.willSendEq(params.ststxAmount)\n\t\t\t\t\t\t\t.ft(`${ststx.address}.${ststx.name}`, \"ststx\"),\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t},\n\t);\n}\n\nexport async function withdraw(\n\tclient: Client,\n\tparams: WithdrawParams,\n): Promise<string> {\n\tconst core = getCoreContract(client);\n\treturn core.call.withdraw({\n\t\treserve: traits.reserve,\n\t\tcommissionContract: traits.commissionContract,\n\t\tstakingContract: traits.stakingContract,\n\t\tnftId: params.nftId,\n\t});\n}\n\nexport async function withdrawIdle(\n\tclient: Client,\n\tparams: WithdrawIdleParams,\n): Promise<string> {\n\tconst core = getCoreContract(client);\n\tconst ststx = STACKINGDAO_CONTRACTS.ststxToken;\n\treturn core.call.withdrawIdle(\n\t\t{\n\t\t\treserve: traits.reserve,\n\t\t\tdirectHelpers: traits.directHelpers,\n\t\t\tcommissionContract: traits.commissionContract,\n\t\t\tstakingContract: traits.stakingContract,\n\t\t\tststxAmount: params.ststxAmount,\n\t\t},\n\t\t{\n\t\t\tpostConditions: client.account?.address\n\t\t\t\t? [\n\t\t\t\t\t\tPc.principal(client.account.address)\n\t\t\t\t\t\t\t.willSendEq(params.ststxAmount)\n\t\t\t\t\t\t\t.ft(`${ststx.address}.${ststx.name}`, \"ststx\"),\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t\t},\n\t);\n}\n\n// ── Read-only Queries ──\n\nexport async function getStSTXBalance(\n\tclient: Client,\n\taddress: string,\n): Promise<bigint> {\n\tconst token = getStstxToken(client);\n\treturn (await token.read.getBalance({ account: address })) as bigint;\n}\n\nexport async function getExchangeRate(\n\tclient: Client,\n): Promise<ExchangeRateInfo> {\n\tconst reserve = getReserveContract(client);\n\tconst dataV3 = getDataCoreV3(client);\n\n\tconst [totalStx, ststxSupply] = await Promise.all([\n\t\treserve.read.getTotalStx({}) as Promise<bigint>,\n\t\tgetTotalSupply(client),\n\t]);\n\n\tconst stxPerStstx = (await dataV3.read.getStxPerStstxHelper({\n\t\tstxAmount: totalStx,\n\t})) as bigint;\n\n\treturn { stxPerStstx, ststxSupply, totalStx };\n}\n\nexport async function getTotalSupply(client: Client): Promise<bigint> {\n\tconst token = getStstxToken(client);\n\treturn (await token.read.getTotalSupply({})) as bigint;\n}\n\nexport async function getWithdrawalInfo(\n\tclient: Client,\n\tnftId: bigint,\n): Promise<WithdrawalInfo> {\n\tconst dataV1 = getDataCoreV1(client);\n\treturn (await dataV1.read.getWithdrawalsByNft({\n\t\tnftId,\n\t})) as WithdrawalInfo;\n}\n\nexport async function getFees(client: Client): Promise<FeeInfo> {\n\tconst core = getCoreContract(client);\n\tconst [stackFee, unstackFee, withdrawIdleFee] = await Promise.all([\n\t\tcore.read.getStackFee({}) as Promise<bigint>,\n\t\tcore.read.getUnstackFee({}) as Promise<bigint>,\n\t\tcore.read.getWithdrawIdleFee({}) as Promise<bigint>,\n\t]);\n\treturn { stackFee, unstackFee, withdrawIdleFee };\n}\n\nexport async function getReserveBalance(client: Client): Promise<bigint> {\n\tconst reserve = getReserveContract(client);\n\treturn (await reserve.read.getTotalStx({})) as bigint;\n}\n\nexport async function getShutdownDeposits(client: Client): Promise<boolean> {\n\tconst core = getCoreContract(client);\n\treturn (await core.read.getShutdownDeposits({})) as boolean;\n}\n",
|
|
8
8
|
"import type { Client } from \"../clients/types.ts\";\nimport {\n\tdeposit,\n\tgetExchangeRate,\n\tgetFees,\n\tgetReserveBalance,\n\tgetShutdownDeposits,\n\tgetStSTXBalance,\n\tgetTotalSupply,\n\tgetWithdrawalInfo,\n\tinitWithdraw,\n\twithdraw,\n\twithdrawIdle,\n} from \"./actions.ts\";\nimport type {\n\tDepositParams,\n\tExchangeRateInfo,\n\tFeeInfo,\n\tInitWithdrawParams,\n\tWithdrawIdleParams,\n\tWithdrawParams,\n\tWithdrawalInfo,\n} from \"./types.ts\";\n\nexport type {\n\tDepositParams,\n\tInitWithdrawParams,\n\tWithdrawParams,\n\tWithdrawIdleParams,\n\tExchangeRateInfo,\n\tWithdrawalInfo,\n\tFeeInfo,\n};\n/** Actions provided by the StackingDAO extension. */\nexport type StackingDaoActions = {\n\tstackingDao: {\n\t\tdeposit: (params: DepositParams) => Promise<string>;\n\t\tinitWithdraw: (params: InitWithdrawParams) => Promise<string>;\n\t\twithdraw: (params: WithdrawParams) => Promise<string>;\n\t\twithdrawIdle: (params: WithdrawIdleParams) => Promise<string>;\n\t\tgetStSTXBalance: (address: string) => Promise<bigint>;\n\t\tgetExchangeRate: () => Promise<ExchangeRateInfo>;\n\t\tgetTotalSupply: () => Promise<bigint>;\n\t\tgetWithdrawalInfo: (nftId: bigint) => Promise<WithdrawalInfo>;\n\t\tgetFees: () => Promise<FeeInfo>;\n\t\tgetReserveBalance: () => Promise<bigint>;\n\t\tgetShutdownDeposits: () => Promise<boolean>;\n\t};\n};\n\nexport { STACKINGDAO_CONTRACTS, TRAIT_CONTRACTS } from \"./constants.ts\";\n\n/**\n * StackingDAO liquid staking extension.\n * Deposit STX → receive stSTX. Auto-compounding stacking rewards.\n *\n * @example\n * import { createWalletClient, http, mainnet } from \"stacks\";\n * import { stackingDao } from \"stacks/stackingdao\";\n *\n * const client = createWalletClient({ ... }).extend(stackingDao());\n *\n * // Deposit STX for stSTX\n * await client.stackingDao.deposit({ amount: 100_000_000_000n });\n *\n * // Check exchange rate\n * const rate = await client.stackingDao.getExchangeRate();\n */\nexport function stackingDao(): (client: Client) => StackingDaoActions {\n\treturn (client: Client) => ({\n\t\tstackingDao: {\n\t\t\t/** Deposit STX, receive stSTX. */\n\t\t\tdeposit: (params: DepositParams) => deposit(client, params),\n\n\t\t\t/** Initiate withdrawal — burns stSTX, mints NFT receipt. */\n\t\t\tinitWithdraw: (params: InitWithdrawParams) =>\n\t\t\t\tinitWithdraw(client, params),\n\n\t\t\t/** Finalize withdrawal — burns NFT, receive STX. */\n\t\t\twithdraw: (params: WithdrawParams) => withdraw(client, params),\n\n\t\t\t/** Withdraw idle STX instantly (burns stSTX). */\n\t\t\twithdrawIdle: (params: WithdrawIdleParams) =>\n\t\t\t\twithdrawIdle(client, params),\n\n\t\t\t/** Get stSTX balance for an address. */\n\t\t\tgetStSTXBalance: (address: string) => getStSTXBalance(client, address),\n\n\t\t\t/** Get current STX/stSTX exchange rate info. */\n\t\t\tgetExchangeRate: () => getExchangeRate(client),\n\n\t\t\t/** Get total stSTX supply. */\n\t\t\tgetTotalSupply: () => getTotalSupply(client),\n\n\t\t\t/** Get withdrawal NFT info by ID. Returns tuple with amounts and unlock height. */\n\t\t\tgetWithdrawalInfo: (nftId: bigint) => getWithdrawalInfo(client, nftId),\n\n\t\t\t/** Get current fee rates. */\n\t\t\tgetFees: () => getFees(client),\n\n\t\t\t/** Get total STX in reserve. */\n\t\t\tgetReserveBalance: () => getReserveBalance(client),\n\n\t\t\t/** Check if deposits are shut down. */\n\t\t\tgetShutdownDeposits: () => getShutdownDeposits(client),\n\t\t},\n\t});\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAEA,IAAM,gBAAgB;AAAA,EACrB,OAAO;AAAA,IACN,EAAE,MAAM,kBAAkB,MAAM,UAAU;AAAA,IAC1C,EAAE,MAAM,mBAAmB,MAAM,UAAU;AAAA,EAC5C;AACD;AAEO,IAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,IAEV;AAAA,MACC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,QACL,EAAE,MAAM,WAAW,MAAM,kBAAkB;AAAA,QAC3C,EAAE,MAAM,uBAAuB,MAAM,kBAAkB;AAAA,QACvD,EAAE,MAAM,oBAAoB,MAAM,kBAAkB;AAAA,QACpD,EAAE,MAAM,kBAAkB,MAAM,kBAAkB;AAAA,QAClD,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,QACtC,EAAE,MAAM,YAAY,MAAM,EAAE,UAAU,YAAY,EAAE;AAAA,QACpD,EAAE,MAAM,QAAQ,MAAM,EAA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MAG5B,iBAAiB,CAAC,YAAoB,gBAAgB,QAAQ,OAAO;AAAA,MAGrE,iBAAiB,MAAM,gBAAgB,MAAM;AAAA,MAG7C,gBAAgB,MAAM,eAAe,MAAM;AAAA,MAG3C,mBAAmB,CAAC,UAAkB,kBAAkB,QAAQ,KAAK;AAAA,MAGrE,SAAS,MAAM,QAAQ,MAAM;AAAA,MAG7B,mBAAmB,MAAM,kBAAkB,MAAM;AAAA,MAGjD,qBAAqB,MAAM,oBAAoB,MAAM;AAAA,IACtD;AAAA,EACD;AAAA;",
|
|
11
|
+
"debugId": "6A1B0C77E43CC85564756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/stacks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -109,11 +109,6 @@
|
|
|
109
109
|
"import": "./dist/src/tools/btc/index.js",
|
|
110
110
|
"require": "./dist/src/tools/btc/index.cjs"
|
|
111
111
|
},
|
|
112
|
-
"./x402": {
|
|
113
|
-
"types": "./dist/src/x402/index.d.ts",
|
|
114
|
-
"import": "./dist/src/x402/index.js",
|
|
115
|
-
"require": "./dist/src/x402/index.cjs"
|
|
116
|
-
},
|
|
117
112
|
"./filters": {
|
|
118
113
|
"types": "./dist/src/filters/index.d.ts",
|
|
119
114
|
"import": "./dist/src/filters/index.js",
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertNoFeeTierForProvider,
|
|
3
|
-
broadcastWithNonceReset,
|
|
4
|
-
isFeeTier,
|
|
5
|
-
isProviderAccount,
|
|
6
|
-
resolveFee,
|
|
7
|
-
resolveNonce,
|
|
8
|
-
setUnsignedFee
|
|
9
|
-
} from "./stacks-9d2d0qjc.js";
|
|
10
|
-
import {
|
|
11
|
-
MalformedResponseError
|
|
12
|
-
} from "./stacks-fh48neva.js";
|
|
13
|
-
import {
|
|
14
|
-
buildContractCall,
|
|
15
|
-
signTransactionWithAccount
|
|
16
|
-
} from "./stacks-jx146qf1.js";
|
|
17
|
-
import {
|
|
18
|
-
deserializeCVBytes,
|
|
19
|
-
serializeCVBytes
|
|
20
|
-
} from "./stacks-ttdk2g2f.js";
|
|
21
|
-
import {
|
|
22
|
-
parseContractId
|
|
23
|
-
} from "./stacks-bfan7ex7.js";
|
|
24
|
-
import {
|
|
25
|
-
bytesToHex,
|
|
26
|
-
with0x
|
|
27
|
-
} from "./stacks-qs5fzts5.js";
|
|
28
|
-
|
|
29
|
-
// src/actions/public/getMapEntry.ts
|
|
30
|
-
async function getMapEntry(client, params) {
|
|
31
|
-
const [address, name] = parseContractId(params.contract);
|
|
32
|
-
const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
|
|
33
|
-
const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
|
|
34
|
-
method: "POST",
|
|
35
|
-
body: serializedKey
|
|
36
|
-
});
|
|
37
|
-
if (typeof data?.data !== "string") {
|
|
38
|
-
throw new MalformedResponseError(`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing "data"`);
|
|
39
|
-
}
|
|
40
|
-
return deserializeCVBytes(data.data);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/actions/wallet/callContract.ts
|
|
44
|
-
async function callContract(client, params) {
|
|
45
|
-
const account = client.account;
|
|
46
|
-
if (!account)
|
|
47
|
-
throw new Error("Account required");
|
|
48
|
-
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
49
|
-
if (isProviderAccount(account)) {
|
|
50
|
-
assertNoFeeTierForProvider(params.fee);
|
|
51
|
-
const result = await account.provider.request("stx_callContract", {
|
|
52
|
-
contract: params.contract,
|
|
53
|
-
functionName: params.functionName,
|
|
54
|
-
functionArgs: params.functionArgs ?? []
|
|
55
|
-
});
|
|
56
|
-
return result.txid;
|
|
57
|
-
}
|
|
58
|
-
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
59
|
-
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
60
|
-
const unsigned = buildContractCall({
|
|
61
|
-
contractAddress,
|
|
62
|
-
contractName,
|
|
63
|
-
functionName: params.functionName,
|
|
64
|
-
functionArgs: params.functionArgs ?? [],
|
|
65
|
-
fee: needsFeeResolution ? 0n : params.fee,
|
|
66
|
-
nonce,
|
|
67
|
-
publicKey: account.publicKey,
|
|
68
|
-
chain: client.chain,
|
|
69
|
-
postConditionMode: params.postConditionMode,
|
|
70
|
-
postConditions: params.postConditions
|
|
71
|
-
});
|
|
72
|
-
if (needsFeeResolution) {
|
|
73
|
-
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
74
|
-
}
|
|
75
|
-
const signed = await signTransactionWithAccount(unsigned, account);
|
|
76
|
-
return broadcastWithNonceReset(client, {
|
|
77
|
-
transaction: signed,
|
|
78
|
-
address: account.address
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { getMapEntry, callContract };
|
|
83
|
-
|
|
84
|
-
//# debugId=FF3F274BBCF0781464756E2164756E21
|
|
85
|
-
//# sourceMappingURL=stacks-1mpmzzyp.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\tif (typeof data?.data !== \"string\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing \"data\"`,\n\t\t);\n\t}\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
|
|
6
|
-
"import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractCall } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,eAAsB,WAAkD,CACvE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,gBAAgB,OAAO,WAAW,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,EAErE,MAAM,OAAO,MAAM,OAAO,QACzB,iBAAiB,WAAW,QAAQ,OAAO,WAC3C;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CACD;AAAA,EAEA,IAAI,OAAO,MAAM,SAAS,UAAU;AAAA,IACn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ClB,CAAC;AAAA;",
|
|
9
|
-
"debugId": "FF3F274BBCF0781464756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/actions/wallet/sponsorTransaction.ts
|
|
2
|
-
async function sponsorTransaction(client, params) {
|
|
3
|
-
const { transaction } = params;
|
|
4
|
-
if (transaction.auth.authType !== AuthType.Sponsored) {
|
|
5
|
-
throw new Error("Transaction must have sponsored authorization");
|
|
6
|
-
}
|
|
7
|
-
const account = client.account;
|
|
8
|
-
if (!account)
|
|
9
|
-
throw new Error("Account required");
|
|
10
|
-
if (isProviderAccount(account)) {
|
|
11
|
-
throw new Error("Provider accounts cannot sponsor transactions");
|
|
12
|
-
}
|
|
13
|
-
const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
|
|
14
|
-
const fee = await resolveFee(client, transaction, params.fee);
|
|
15
|
-
const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
|
|
16
|
-
const auth = transaction.auth;
|
|
17
|
-
const sponsored = {
|
|
18
|
-
...transaction,
|
|
19
|
-
auth: {
|
|
20
|
-
...auth,
|
|
21
|
-
sponsorSpendingCondition: sponsorCondition
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
return signSponsorWithAccount(sponsored, account);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//# debugId=2C7F1B8FDFB94A5364756E2164756E21
|
|
28
|
-
//# sourceMappingURL=stacks-44y18a8e.cjs.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/wallet/sponsorTransaction.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";AAoBA,eAAsB,kBAAkB,CACvC,QACA,QAC6B;AAAA,EAC7B,QAAQ,gBAAgB;AAAA,EAExB,IAAI,YAAY,KAAK,aAAa,SAAS,WAAW;AAAA,IACrD,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAEA,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAChD,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAGA,MAAM,QACL,OAAO,SAAS,OACb,YAAY,OAAO,KAAK,IACxB,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAI9C,MAAM,MAAM,MAAM,WAAW,QAAQ,aAAa,OAAO,GAAG;AAAA,EAG5D,MAAM,mBAAmB,iCACxB,QAAQ,WACR,OACA,GACD;AAAA,EAGA,MAAM,OAAO,YAAY;AAAA,EACzB,MAAM,YAA+B;AAAA,OACjC;AAAA,IACH,MAAM;AAAA,SACF;AAAA,MACH,0BAA0B;AAAA,IAC3B;AAAA,EACD;AAAA,EAGA,OAAO,uBAAuB,WAAW,OAAO;AAAA;",
|
|
8
|
-
"debugId": "2C7F1B8FDFB94A5364756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/errors/response.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";AAGO,MAAM,+BAA+B,UAAU;AAAA,EAC5C,OAAO;AACjB;",
|
|
8
|
-
"debugId": "31C375B5C92A878E64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// src/postconditions/index.ts
|
|
2
|
-
var exports_postconditions = {};
|
|
3
|
-
__export(exports_postconditions, {
|
|
4
|
-
Pc: () => Pc
|
|
5
|
-
});
|
|
6
|
-
module.exports = __toCommonJS(exports_postconditions);
|
|
7
|
-
|
|
8
|
-
//# debugId=826C758A4223AE2664756E2164756E21
|
|
9
|
-
//# sourceMappingURL=stacks-d6pgp4qk.cjs.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseError
|
|
3
|
-
} from "./stacks-709tra19.js";
|
|
4
|
-
|
|
5
|
-
// src/errors/response.ts
|
|
6
|
-
class MalformedResponseError extends BaseError {
|
|
7
|
-
name = "MalformedResponseError";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { MalformedResponseError };
|
|
11
|
-
|
|
12
|
-
//# debugId=93346D5AC0126F7F64756E2164756E21
|
|
13
|
-
//# sourceMappingURL=stacks-fh48neva.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/errors/response.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;AAGO,MAAM,+BAA+B,UAAU;AAAA,EAC5C,OAAO;AACjB;",
|
|
8
|
-
"debugId": "93346D5AC0126F7F64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// src/actions/public/getMapEntry.ts
|
|
2
|
-
async function getMapEntry(client, params) {
|
|
3
|
-
const [address, name] = parseContractId(params.contract);
|
|
4
|
-
const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
|
|
5
|
-
const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
|
|
6
|
-
method: "POST",
|
|
7
|
-
body: serializedKey
|
|
8
|
-
});
|
|
9
|
-
if (typeof data?.data !== "string") {
|
|
10
|
-
throw new MalformedResponseError(`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing "data"`);
|
|
11
|
-
}
|
|
12
|
-
return deserializeCVBytes(data.data);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/actions/wallet/callContract.ts
|
|
16
|
-
async function callContract(client, params) {
|
|
17
|
-
const account = client.account;
|
|
18
|
-
if (!account)
|
|
19
|
-
throw new Error("Account required");
|
|
20
|
-
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
21
|
-
if (isProviderAccount(account)) {
|
|
22
|
-
assertNoFeeTierForProvider(params.fee);
|
|
23
|
-
const result = await account.provider.request("stx_callContract", {
|
|
24
|
-
contract: params.contract,
|
|
25
|
-
functionName: params.functionName,
|
|
26
|
-
functionArgs: params.functionArgs ?? []
|
|
27
|
-
});
|
|
28
|
-
return result.txid;
|
|
29
|
-
}
|
|
30
|
-
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
31
|
-
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
32
|
-
const unsigned = buildContractCall({
|
|
33
|
-
contractAddress,
|
|
34
|
-
contractName,
|
|
35
|
-
functionName: params.functionName,
|
|
36
|
-
functionArgs: params.functionArgs ?? [],
|
|
37
|
-
fee: needsFeeResolution ? 0n : params.fee,
|
|
38
|
-
nonce,
|
|
39
|
-
publicKey: account.publicKey,
|
|
40
|
-
chain: client.chain,
|
|
41
|
-
postConditionMode: params.postConditionMode,
|
|
42
|
-
postConditions: params.postConditions
|
|
43
|
-
});
|
|
44
|
-
if (needsFeeResolution) {
|
|
45
|
-
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
46
|
-
}
|
|
47
|
-
const signed = await signTransactionWithAccount(unsigned, account);
|
|
48
|
-
return broadcastWithNonceReset(client, {
|
|
49
|
-
transaction: signed,
|
|
50
|
-
address: account.address
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//# debugId=B9CB858E212A7D7264756E2164756E21
|
|
55
|
-
//# sourceMappingURL=stacks-fjrpnkt3.cjs.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\tif (typeof data?.data !== \"string\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing \"data\"`,\n\t\t);\n\t}\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
|
|
6
|
-
"import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractCall } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";AAcA,eAAsB,WAAkD,CACvE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,gBAAgB,OAAO,WAAW,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,EAErE,MAAM,OAAO,MAAM,OAAO,QACzB,iBAAiB,WAAW,QAAQ,OAAO,WAC3C;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CACD;AAAA,EAEA,IAAI,OAAO,MAAM,SAAS,UAAU;AAAA,IACnC,MAAM,IAAI,uBACT,8BAA8B,WAAW,QAAQ,OAAO,oCACzD;AAAA,EACD;AAAA,EACA,OAAO,mBAAsB,KAAK,IAAI;AAAA;;;ACNvC,eAAsB,YAAY,CACjC,QACA,QACkB;AAAA,EAClB,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAIhD,OAAO,iBAAiB,gBAAgB,gBAAgB,OAAO,QAAQ;AAAA,EAGvE,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,2BAA2B,OAAO,GAAG;AAAA,IACrC,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,oBAAoB;AAAA,MACjE,UAAU,OAAO;AAAA,MACjB,cAAc,OAAO;AAAA,MACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACvC,CAAC;AAAA,IACD,OAAO,OAAO;AAAA,EACf;AAAA,EAGA,MAAM,QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,qBAAqB,OAAO,QAAQ,aAAa,UAAU,OAAO,GAAG;AAAA,EAE3E,MAAM,WAAW,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,cAAc,OAAO;AAAA,IACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACtC,KAAK,qBAAqB,KAAM,OAAO;AAAA,IACvC;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,oBAAoB;AAAA,IACvB,eAAe,UAAU,MAAM,WAAW,QAAQ,UAAU,OAAO,GAAG,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
9
|
-
"debugId": "B9CB858E212A7D7264756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isProviderAccount,
|
|
3
|
-
resolveFee,
|
|
4
|
-
resolveNonce
|
|
5
|
-
} from "./stacks-9d2d0qjc.js";
|
|
6
|
-
import {
|
|
7
|
-
AuthType,
|
|
8
|
-
createSingleSigSpendingCondition,
|
|
9
|
-
signSponsorWithAccount
|
|
10
|
-
} from "./stacks-jx146qf1.js";
|
|
11
|
-
import {
|
|
12
|
-
intToBigInt
|
|
13
|
-
} from "./stacks-qs5fzts5.js";
|
|
14
|
-
|
|
15
|
-
// src/actions/wallet/sponsorTransaction.ts
|
|
16
|
-
async function sponsorTransaction(client, params) {
|
|
17
|
-
const { transaction } = params;
|
|
18
|
-
if (transaction.auth.authType !== AuthType.Sponsored) {
|
|
19
|
-
throw new Error("Transaction must have sponsored authorization");
|
|
20
|
-
}
|
|
21
|
-
const account = client.account;
|
|
22
|
-
if (!account)
|
|
23
|
-
throw new Error("Account required");
|
|
24
|
-
if (isProviderAccount(account)) {
|
|
25
|
-
throw new Error("Provider accounts cannot sponsor transactions");
|
|
26
|
-
}
|
|
27
|
-
const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
|
|
28
|
-
const fee = await resolveFee(client, transaction, params.fee);
|
|
29
|
-
const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
|
|
30
|
-
const auth = transaction.auth;
|
|
31
|
-
const sponsored = {
|
|
32
|
-
...transaction,
|
|
33
|
-
auth: {
|
|
34
|
-
...auth,
|
|
35
|
-
sponsorSpendingCondition: sponsorCondition
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return signSponsorWithAccount(sponsored, account);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { sponsorTransaction };
|
|
42
|
-
|
|
43
|
-
//# debugId=AD4711CB97F1F3EB64756E2164756E21
|
|
44
|
-
//# sourceMappingURL=stacks-w8tt1fmt.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/wallet/sponsorTransaction.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;AAoBA,eAAsB,kBAAkB,CACvC,QACA,QAC6B;AAAA,EAC7B,QAAQ,gBAAgB;AAAA,EAExB,IAAI,YAAY,KAAK,aAAa,SAAS,WAAW;AAAA,IACrD,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAEA,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAChD,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAGA,MAAM,QACL,OAAO,SAAS,OACb,YAAY,OAAO,KAAK,IACxB,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAI9C,MAAM,MAAM,MAAM,WAAW,QAAQ,aAAa,OAAO,GAAG;AAAA,EAG5D,MAAM,mBAAmB,iCACxB,QAAQ,WACR,OACA,GACD;AAAA,EAGA,MAAM,OAAO,YAAY;AAAA,EACzB,MAAM,YAA+B;AAAA,OACjC;AAAA,IACH,MAAM;AAAA,SACF;AAAA,MACH,0BAA0B;AAAA,IAC3B;AAAA,EACD;AAAA,EAGA,OAAO,uBAAuB,WAAW,OAAO;AAAA;",
|
|
8
|
-
"debugId": "AD4711CB97F1F3EB64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/src/x402/index.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/x402/index.ts
|
|
2
|
-
var exports_x402 = {};
|
|
3
|
-
__export(exports_x402, {
|
|
4
|
-
sponsorAndBroadcast: () => sponsorAndBroadcast,
|
|
5
|
-
buildExactTransfer: () => buildExactTransfer
|
|
6
|
-
});
|
|
7
|
-
module.exports = __toCommonJS(exports_x402);
|
|
8
|
-
|
|
9
|
-
// src/x402/build.ts
|
|
10
|
-
function buildExactTransfer(options) {
|
|
11
|
-
const { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } = options;
|
|
12
|
-
if (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {
|
|
13
|
-
throw new Error(`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`);
|
|
14
|
-
}
|
|
15
|
-
if (asset.kind === "stx") {
|
|
16
|
-
return buildTokenTransfer({
|
|
17
|
-
recipient: payTo,
|
|
18
|
-
amount,
|
|
19
|
-
memo: options.nonce,
|
|
20
|
-
fee: 0,
|
|
21
|
-
nonce: accountNonce,
|
|
22
|
-
publicKey: payerPublicKey,
|
|
23
|
-
chain,
|
|
24
|
-
sponsored: true
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const [contractAddress, contractName] = parseContractId(asset.contractId);
|
|
28
|
-
const postConditions = [
|
|
29
|
-
Pc.principal(payer).willSendEq(amount).ft(asset.contractId, asset.assetName)
|
|
30
|
-
];
|
|
31
|
-
return buildContractCall({
|
|
32
|
-
contractAddress,
|
|
33
|
-
contractName,
|
|
34
|
-
functionName: "transfer",
|
|
35
|
-
functionArgs: [
|
|
36
|
-
Cl.uint(amount),
|
|
37
|
-
Cl.principal(payer),
|
|
38
|
-
Cl.principal(payTo),
|
|
39
|
-
Cl.some(Cl.bufferFromUtf8(options.nonce))
|
|
40
|
-
],
|
|
41
|
-
fee: 0,
|
|
42
|
-
nonce: accountNonce,
|
|
43
|
-
publicKey: payerPublicKey,
|
|
44
|
-
chain,
|
|
45
|
-
postConditionMode: "deny",
|
|
46
|
-
postConditions,
|
|
47
|
-
sponsored: true
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// src/x402/settle.ts
|
|
51
|
-
async function sponsorAndBroadcast(client, signedTxHex, options = {}) {
|
|
52
|
-
const transaction = deserializeTransaction(signedTxHex);
|
|
53
|
-
const sponsored = await sponsorTransaction(client, {
|
|
54
|
-
transaction,
|
|
55
|
-
fee: options.fee,
|
|
56
|
-
nonce: options.nonce
|
|
57
|
-
});
|
|
58
|
-
return sendTransaction(client, {
|
|
59
|
-
transaction: sponsored,
|
|
60
|
-
wait: options.wait
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//# debugId=26F0FC52B71944B464756E2164756E21
|
|
65
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/x402/build.ts", "../src/x402/settle.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { StacksChain } from \"../chains/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { Pc } from \"../postconditions/builder.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport {\n\tbuildContractCall,\n\tbuildTokenTransfer,\n} from \"../transactions/build.ts\";\nimport {\n\tMEMO_MAX_LENGTH_BYTES,\n\ttype StacksTransaction,\n} from \"../transactions/types.ts\";\nimport { parseContractId } from \"../utils/address.ts\";\nimport { type IntegerType, utf8ToBytes } from \"../utils/encoding.ts\";\n\n/**\n * The asset an x402 payment moves. Either native STX or a SIP-010 token,\n * in which case the fully-qualified contract id and the fungible-token asset\n * name (the `::<asset-name>` suffix, e.g. `sbtc-token`) are both required —\n * the asset name is not always equal to the contract name.\n */\nexport type X402Asset =\n\t| { kind: \"stx\" }\n\t| { kind: \"sip010\"; contractId: string; assetName: string };\n\nexport type BuildExactTransferOptions = {\n\t/** The asset and amount to move. */\n\tasset: X402Asset;\n\tamount: IntegerType;\n\t/** Recipient principal (the resource server's `payTo`). */\n\tpayTo: string;\n\t/** Origin/payer principal — pinned by the post-condition. */\n\tpayer: string;\n\t/** Origin compressed public key (the payer signs origin-only). */\n\tpayerPublicKey: string;\n\t/** The payer account's next nonce. */\n\taccountNonce: IntegerType;\n\t/**\n\t * The x402 challenge nonce, carried in the on-chain memo so the facilitator\n\t * can correlate the settled tx with the challenge. Bound to ≤ 34 bytes\n\t * (UTF-8) — both the STX memo and the SIP-010 `(buff 34)` memo arg cap there.\n\t */\n\tnonce: string;\n\tchain?: StacksChain;\n};\n\n/**\n * Build an exact-amount, Deny-mode, post-conditioned, **sponsored** transfer\n * (origin-only, un-broadcast). The origin sets fee `0`; the facilitator's\n * sponsor fills in + pays the fee at settle time. The Deny-mode post-condition\n * asserts EXACTLY `amount` leaves `payer` to `payTo`, so settlement aborts\n * on-chain if anything differs — the \"exact amount\" x402 guarantee is enforced\n * by Clarity, not just by facilitator simulation.\n */\nexport function buildExactTransfer(\n\toptions: BuildExactTransferOptions,\n): StacksTransaction {\n\tconst { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } =\n\t\toptions;\n\n\tif (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {\n\t\tthrow new Error(\n\t\t\t`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`,\n\t\t);\n\t}\n\n\tif (asset.kind === \"stx\") {\n\t\t// A TokenTransfer payload CANNOT carry post-conditions (Stacks consensus\n\t\t// rejects it: \"TokenTransfer transactions do not support post-conditions\").\n\t\t// STX exactness is inherent — the amount + recipient are in the signed\n\t\t// payload, so there is nothing a post-condition would add.\n\t\treturn buildTokenTransfer({\n\t\t\trecipient: payTo,\n\t\t\tamount,\n\t\t\tmemo: options.nonce,\n\t\t\tfee: 0,\n\t\t\tnonce: accountNonce,\n\t\t\tpublicKey: payerPublicKey,\n\t\t\tchain,\n\t\t\tsponsored: true,\n\t\t});\n\t}\n\n\tconst [contractAddress, contractName] = parseContractId(asset.contractId);\n\tconst postConditions: PostCondition[] = [\n\t\tPc.principal(payer)\n\t\t\t.willSendEq(amount)\n\t\t\t.ft(asset.contractId, asset.assetName),\n\t];\n\t// SIP-010: (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))\n\treturn buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: \"transfer\",\n\t\tfunctionArgs: [\n\t\t\tCl.uint(amount),\n\t\t\tCl.principal(payer),\n\t\t\tCl.principal(payTo),\n\t\t\tCl.some(Cl.bufferFromUtf8(options.nonce)),\n\t\t],\n\t\tfee: 0,\n\t\tnonce: accountNonce,\n\t\tpublicKey: payerPublicKey,\n\t\tchain,\n\t\tpostConditionMode: \"deny\",\n\t\tpostConditions,\n\t\tsponsored: true,\n\t});\n}\n",
|
|
6
|
-
"import type { TransactionReceipt } from \"../actions/public/txSources.ts\";\nimport { sendTransaction } from \"../actions/wallet/sendTransaction.ts\";\nimport { sponsorTransaction } from \"../actions/wallet/sponsorTransaction.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { deserializeTransaction } from \"../transactions/wire/deserialize.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\n\nexport type SponsorAndBroadcastOptions = {\n\t/** Override the sponsor fee (µSTX). Defaults to a fee estimate. */\n\tfee?: IntegerType;\n\t/** Override the sponsor account nonce. Defaults to the on-chain nonce. */\n\tnonce?: IntegerType;\n\t/**\n\t * Wait for the payment to be mined before returning (`true` = 1\n\t * confirmation, a number = that many). Settlement rejects if the payment\n\t * aborts or drops, instead of reporting a txid that never lands.\n\t */\n\twait?: boolean | number;\n};\n\nexport type SponsorAndBroadcastResult = {\n\ttxid: string;\n\t/** Present when `wait` was requested. */\n\treceipt?: TransactionReceipt;\n};\n\n/**\n * Take an origin-signed, sponsored transfer (hex) from the payer, sponsor-sign\n * it with `client`'s account (paying the STX fee), and broadcast it.\n *\n * The payer never holds STX: they sign origin-only with fee `0`; this fills in\n * the sponsor spending condition + fee and POSTs to `/v2/transactions`. The\n * sponsor cannot grief the payer — amount/recipient/asset are pinned by the\n * origin signature + Deny-mode post-conditions baked into the tx.\n *\n * @param client a wallet client whose `account` is the funded sponsor signer.\n * @param signedTxHex the payer's origin-signed sponsored tx, hex-serialized.\n */\nexport async function sponsorAndBroadcast(\n\tclient: Client,\n\tsignedTxHex: string,\n\toptions: SponsorAndBroadcastOptions = {},\n): Promise<SponsorAndBroadcastResult> {\n\tconst transaction = deserializeTransaction(signedTxHex);\n\tconst sponsored = await sponsorTransaction(client, {\n\t\ttransaction,\n\t\tfee: options.fee,\n\t\tnonce: options.nonce,\n\t});\n\treturn sendTransaction(client, {\n\t\ttransaction: sponsored,\n\t\twait: options.wait,\n\t});\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";;;;;;;;;AAsDO,SAAS,kBAAkB,CACjC,SACoB;AAAA,EACpB,QAAQ,OAAO,QAAQ,OAAO,OAAO,gBAAgB,cAAc,UAClE;AAAA,EAED,IAAI,YAAY,QAAQ,KAAK,EAAE,aAAa,uBAAuB;AAAA,IAClE,MAAM,IAAI,MACT,0BAA0B,wCAC3B;AAAA,EACD;AAAA,EAEA,IA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