@vultisig/core-mpc 3.0.1 → 3.2.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/CHANGELOG.md +55 -0
- package/dist/keysign/chainSpecific/resolvers/evm.d.ts.map +1 -1
- package/dist/keysign/chainSpecific/resolvers/evm.js +0 -16
- package/dist/keysign/chainSpecific/resolvers/evm.js.map +1 -1
- package/dist/keysign/fee/resolvers/evm/getEvmFeeQuote.d.ts +5 -0
- package/dist/keysign/fee/resolvers/evm/getEvmFeeQuote.d.ts.map +1 -1
- package/dist/keysign/fee/resolvers/evm/getEvmFeeQuote.js +68 -32
- package/dist/keysign/fee/resolvers/evm/getEvmFeeQuote.js.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/index.d.ts.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/index.js +22 -2
- package/dist/keysign/signingInputs/resolvers/ton/index.js.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/jetton.d.ts +3 -1
- package/dist/keysign/signingInputs/resolvers/ton/jetton.d.ts.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/jetton.js +3 -3
- package/dist/keysign/signingInputs/resolvers/ton/jetton.js.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/native.d.ts +17 -2
- package/dist/keysign/signingInputs/resolvers/ton/native.d.ts.map +1 -1
- package/dist/keysign/signingInputs/resolvers/ton/native.js +20 -4
- package/dist/keysign/signingInputs/resolvers/ton/native.js.map +1 -1
- package/dist/keysign/swap/KeysignSwapPayload.d.ts +1 -1
- package/dist/keysign/swap/KeysignSwapPayload.d.ts.map +1 -1
- package/dist/keysign/swap/build.d.ts +0 -11
- package/dist/keysign/swap/build.d.ts.map +1 -1
- package/dist/keysign/swap/build.js +23 -10
- package/dist/keysign/swap/build.js.map +1 -1
- package/dist/keysign/swap/buildLimitSwapKeysignPayload.d.ts +4 -5
- package/dist/keysign/swap/buildLimitSwapKeysignPayload.d.ts.map +1 -1
- package/dist/keysign/swap/buildLimitSwapKeysignPayload.js +4 -5
- package/dist/keysign/swap/buildLimitSwapKeysignPayload.js.map +1 -1
- package/dist/keysign/swap/getKeysignSwapFeeFields.d.ts +23 -0
- package/dist/keysign/swap/getKeysignSwapFeeFields.d.ts.map +1 -0
- package/dist/keysign/swap/getKeysignSwapFeeFields.js +10 -0
- package/dist/keysign/swap/getKeysignSwapFeeFields.js.map +1 -0
- package/dist/keysign/swap/getKeysignSwapProviderName.d.ts +9 -0
- package/dist/keysign/swap/getKeysignSwapProviderName.d.ts.map +1 -1
- package/dist/keysign/swap/getKeysignSwapProviderName.js +13 -1
- package/dist/keysign/swap/getKeysignSwapProviderName.js.map +1 -1
- package/dist/swap/native/utils/nativeSwapQuoteToSwapPayload.d.ts.map +1 -1
- package/dist/swap/native/utils/nativeSwapQuoteToSwapPayload.js +3 -0
- package/dist/swap/native/utils/nativeSwapQuoteToSwapPayload.js.map +1 -1
- package/dist/types/vultisig/keysign/v1/1inch_swap_payload_pb.d.ts +19 -6
- package/dist/types/vultisig/keysign/v1/1inch_swap_payload_pb.d.ts.map +1 -1
- package/dist/types/vultisig/keysign/v1/1inch_swap_payload_pb.js +14 -6
- package/dist/types/vultisig/keysign/v1/1inch_swap_payload_pb.js.map +1 -1
- package/dist/types/vultisig/keysign/v1/swapkit_swap_payload_pb.d.ts +36 -4
- package/dist/types/vultisig/keysign/v1/swapkit_swap_payload_pb.d.ts.map +1 -1
- package/dist/types/vultisig/keysign/v1/swapkit_swap_payload_pb.js +8 -4
- package/dist/types/vultisig/keysign/v1/swapkit_swap_payload_pb.js.map +1 -1
- package/dist/types/vultisig/keysign/v1/thorchain_swap_payload_pb.d.ts +15 -0
- package/dist/types/vultisig/keysign/v1/thorchain_swap_payload_pb.d.ts.map +1 -1
- package/dist/types/vultisig/keysign/v1/thorchain_swap_payload_pb.js +1 -1
- package/dist/types/vultisig/keysign/v1/thorchain_swap_payload_pb.js.map +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @vultisig/core-mpc
|
|
2
2
|
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2328](https://github.com/vultisig/vultisig-sdk/pull/2328) [`741272f`](https://github.com/vultisig/vultisig-sdk/commit/741272f8d3872afdf12d9487d2121dee04c2f363) Thanks [@Ehsan-saradar](https://github.com/Ehsan-saradar)! - Carry a native swap's price impact in the keysign payload, so a co-signer can show it.
|
|
8
|
+
|
|
9
|
+
A device joining a keysign renders its swap verify screen entirely from the `KeysignPayload` — it holds no quote. Price impact was never on the wire, so the initiator showed a `Price Impact` row and the joining device showed nothing, on the screen whose purpose is for both parties to confirm they are approving the same swap.
|
|
10
|
+
|
|
11
|
+
`THORChainSwapPayload` gains `optional uint32 slippage_bps = 14` (vultisig/commondata#104), and `nativeSwapQuoteToSwapPayload` populates it from `quote.fees.slippage_bps`. MayaChain shares the message, so one field covers both native swap chains.
|
|
12
|
+
|
|
13
|
+
The value is carried rather than re-derived on the joiner. A joining device has enough in the payload to rebuild the quote request, but pools move between initiating and joining, so a fresh quote returns a different figure — price impact would become the only term on that screen where the two devices legitimately disagree.
|
|
14
|
+
|
|
15
|
+
The field is optional and left unset when the provider reports no slippage. Payloads from senders that predate it round-trip unchanged, and receivers are expected to hide the row rather than read an absent figure as zero.
|
|
16
|
+
|
|
17
|
+
- [#2325](https://github.com/vultisig/vultisig-sdk/pull/2325) [`7c95286`](https://github.com/vultisig/vultisig-sdk/commit/7c9528622702a1e6f10cd5ff72017779d25e509a) Thanks [@Ehsan-saradar](https://github.com/Ehsan-saradar)! - EVM fee quotes now size the gas reserve from the transaction itself instead of a flat 600k floor. An aggregator swap is signed with the larger of the route's own gas and 1.5x its simulation (1.5x the 600k default when it cannot be simulated, e.g. a token route quoted before its allowance exists); a THORChain or Maya swap deposit (any transaction carrying the native swap payload) takes a fixed 120k; a plain transfer, including a memo-carrying vault deposit that carries no swap payload, takes its simulation raised to a per-chain floor with no inflation (when it cannot be simulated, that floor plus the intrinsic cost of its memo calldata); a dApp or other contract call keeps 1.5x headroom over its simulation. Base-fee headroom drops from 50% to 20% (32% for swaps), legacy-priced chains (BSC) are priced from `eth_gasPrice` with no tip, and the tip is the highest recent 5th-percentile reward from `eth_feeHistory`, capped at the gas price, with per-chain floors (1 gwei on tip-auction chains, 30 gwei on Polygon, 20 wei on OP-stack rollups) and a zero tip on Arbitrum, Mantle and Robinhood.
|
|
18
|
+
|
|
19
|
+
`getEvmFeeQuote`'s `minimumGasLimit` now only raises the value that stands in for a failed simulation and never a successful estimate. `getEvmTransferGasLimit`, `getEvmContractCallGasLimit` and `evmRouterDepositGasLimit` are exported from `@vultisig/core-chain/tx/fee/evm/evmGasLimit`, and `getEvmGasPrice` from `@vultisig/core-chain/tx/fee/evm/gasPrice`.
|
|
20
|
+
|
|
21
|
+
- [#2331](https://github.com/vultisig/vultisig-sdk/pull/2331) [`982d464`](https://github.com/vultisig/vultisig-sdk/commit/982d4645467272f32e33a2df20883c1a7171a7ee) Thanks [@Ehsan-saradar](https://github.com/Ehsan-saradar)! - Publish the SwapKit swap-fee work to the core packages that hold it. [#2315](https://github.com/vultisig/vultisig-sdk/issues/2315) landed
|
|
22
|
+
`swap_fee` on `SwapKitSwapPayload`, the `getKeysignSwapFeeFields` reader, and the
|
|
23
|
+
`sub_provider` route tag in `@vultisig/core-mpc`, plus the transfer-route fee
|
|
24
|
+
resolution in `@vultisig/core-chain` — but its changeset named only
|
|
25
|
+
`@vultisig/sdk`, so neither core package was versioned and the release skipped
|
|
26
|
+
both. Clients that consume `@vultisig/core-mpc` directly, rather than through
|
|
27
|
+
`@vultisig/sdk`, cannot reach the new fee group or its reader until these are
|
|
28
|
+
republished.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`7c95286`](https://github.com/vultisig/vultisig-sdk/commit/7c9528622702a1e6f10cd5ff72017779d25e509a), [`2e1ed70`](https://github.com/vultisig/vultisig-sdk/commit/2e1ed704ccd0a360eaf760f1258c7cd8a4401e22), [`741272f`](https://github.com/vultisig/vultisig-sdk/commit/741272f8d3872afdf12d9487d2121dee04c2f363), [`982d464`](https://github.com/vultisig/vultisig-sdk/commit/982d4645467272f32e33a2df20883c1a7171a7ee), [`95cf397`](https://github.com/vultisig/vultisig-sdk/commit/95cf39722b8a4d3e197b26bcef9983ecef6c3703)]:
|
|
33
|
+
- @vultisig/core-chain@5.3.0
|
|
34
|
+
|
|
35
|
+
## 3.1.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- [#2299](https://github.com/vultisig/vultisig-sdk/pull/2299) [`bcca32c`](https://github.com/vultisig/vultisig-sdk/commit/bcca32c885066e2bf224aa37d6666c68a3684956) Thanks [@Ehsan-saradar](https://github.com/Ehsan-saradar)! - feat(ton): W5 (wallet v5r1) support as an explicit per-account opt-in
|
|
40
|
+
|
|
41
|
+
Every Vultisig TON account has been hard-pinned to the V4R2 wallet contract. W5 is the default for new wallets in Tonkeeper and Telegram Wallet and is the gateway to what users now expect from TON — up to 255 messages per request instead of 4, lower fees, and relayer-paid ("gasless") transactions. WalletCore has supported it for a while; nothing here used it.
|
|
42
|
+
|
|
43
|
+
A W5 wallet is a _different address_ for the same key, with its own balance, so this is not a switch: V4R2 stays the default everywhere and W5 is selected per account.
|
|
44
|
+
|
|
45
|
+
- `@vultisig/core-chain/chains/ton/wallet` (new): `TonWalletVersion` (`'v4r2' | 'v5r1'`), `deriveTonAddress` for either contract, `resolveTonWalletVersion` to tell which contract an address is for a key, the W5 mainnet wallet id, and the per-contract message limits.
|
|
46
|
+
- `vault.setTonWalletVersion('v5r1')` selects which of the key's two TON accounts the vault acts on: `send`, balances, swaps, fee estimation and every other address lookup follow it, so one selected account is used consistently. `vault.address(chain, { tonWalletVersion })` — like `deriveAddress` / `getChainAddress` / `deriveAddressFromKeys` — names a contract for a single lookup without changing the selection, so a client can show both accounts side by side for a migration flow.
|
|
47
|
+
- Balance cache keys name a chain and an asset, not an account, so switching between the two accounts drops the balance scope and any fetch already in flight for the old account is neither cached nor announced: it still answers its own caller, but `balanceUpdated` carries no account identity, so emitting it after a switch would credit the old account's balance to the new one.
|
|
48
|
+
- The keysign signing-input resolver derives the contract from the sender address — the payload has no wallet-version field, and every co-signer reaches the same answer from the shared vault key — and refuses an address that is neither of the key's wallets rather than assuming V4R2. W5 requests carry `IGNORE_ACTION_PHASE_ERRORS`, which the W5 code requires of every external action (its replay protection) and WalletCore enforces; the TON status resolver's action-phase check covers the blindness that flag would otherwise cause. Message counts are capped per contract.
|
|
49
|
+
- The RN-safe builders (`buildTonSendTx`, `buildTonJettonTransferTx`, `buildTonTxFromSigningPayload`, `deriveTonAddress`, `prepareJettonTransferTxFromKeys`) take `walletVersion`; W5 uses the `signed_external` request layout with the signature appended, byte-identical to WalletCore. New `buildV5R1Wallet` / `TON_V5R1_WALLET_ID` alongside the V4R2 helpers.
|
|
50
|
+
|
|
51
|
+
Golden vectors (`testdata/cross-encoder-golden/ton-w5-*.json`) pin the W5 pre-images and are verified against real WalletCore, including the full signed external message. Client-side migration UI (show both accounts, move funds, reconnect dApps) is separate work per platform.
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [[`a5def09`](https://github.com/vultisig/vultisig-sdk/commit/a5def098e06cf7269174eb6840dc516d78ec55f9), [`bcca32c`](https://github.com/vultisig/vultisig-sdk/commit/bcca32c885066e2bf224aa37d6666c68a3684956)]:
|
|
56
|
+
- @vultisig/core-chain@5.2.0
|
|
57
|
+
|
|
3
58
|
## 3.0.1
|
|
4
59
|
|
|
5
60
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/mpc/keysign/chainSpecific/resolvers/evm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/mpc/keysign/chainSpecific/resolvers/evm.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAEtD,eAAO,MAAM,mBAAmB,EAAE,wBAAwB,CAAC,kBAAkB,CAsC5E,CAAA"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { create } from '@bufbuild/protobuf';
|
|
2
2
|
import { getEvmClient } from '@vultisig/core-chain/chains/evm/client';
|
|
3
|
-
import { deriveEvmGasLimit } from '@vultisig/core-chain/tx/fee/evm/evmGasLimit';
|
|
4
3
|
import { getEvmFeeQuote } from '@vultisig/core-mpc/keysign/fee/resolvers/evm/getEvmFeeQuote';
|
|
5
4
|
import { EthereumSpecificSchema } from '@vultisig/core-mpc/types/vultisig/keysign/v1/blockchain_specific_pb';
|
|
6
|
-
import { getKeysignSwapPayload } from '../../swap/getKeysignSwapPayload.js';
|
|
7
5
|
import { getKeysignCoin } from '../../utils/getKeysignCoin.js';
|
|
8
6
|
export const getEvmChainSpecific = async ({ keysignPayload, feeSettings, thirdPartyGasLimitEstimation, }) => {
|
|
9
7
|
const coin = getKeysignCoin(keysignPayload);
|
|
@@ -24,24 +22,10 @@ export const getEvmChainSpecific = async ({ keysignPayload, feeSettings, thirdPa
|
|
|
24
22
|
}
|
|
25
23
|
};
|
|
26
24
|
const nonce = BigInt(await getNonce());
|
|
27
|
-
const getData = () => {
|
|
28
|
-
const swapPayload = getKeysignSwapPayload(keysignPayload);
|
|
29
|
-
if (swapPayload && 'general' in swapPayload) {
|
|
30
|
-
const value = swapPayload.general.quote?.tx?.data;
|
|
31
|
-
if (value) {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return keysignPayload.memo;
|
|
36
|
-
};
|
|
37
25
|
const { gasLimit, baseFeePerGas, maxPriorityFeePerGas } = await getEvmFeeQuote({
|
|
38
26
|
keysignPayload,
|
|
39
27
|
feeSettings,
|
|
40
28
|
thirdPartyGasLimitEstimation,
|
|
41
|
-
minimumGasLimit: deriveEvmGasLimit({
|
|
42
|
-
coin,
|
|
43
|
-
data: getData(),
|
|
44
|
-
}),
|
|
45
29
|
});
|
|
46
30
|
const maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
|
|
47
31
|
return create(EthereumSpecificSchema, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.js","sourceRoot":"","sources":["../../../../../../../packages/core/mpc/keysign/chainSpecific/resolvers/evm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"evm.js","sourceRoot":"","sources":["../../../../../../../packages/core/mpc/keysign/chainSpecific/resolvers/evm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6DAA6D,CAAA;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,qEAAqE,CAAA;AAE5G,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAG3D,MAAM,CAAC,MAAM,mBAAmB,GAAiD,KAAK,EAAE,EACtF,cAAc,EACd,WAAW,EACX,4BAA4B,GAC7B,EAAE,EAAE;IACH,MAAM,IAAI,GAAG,cAAc,CAAW,cAAc,CAAC,CAAA;IACrD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/B,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IAElC,wEAAwE;IACxE,kEAAkE;IAClE,wEAAwE;IACxE,wEAAwE;IACxE,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,OAAwB,EAAE,CAAA;QACpD,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAA;QAC7E,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,mBAAmB,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;QACtE,CAAC;IACH,CAAC,CAAA;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAA;IAEtC,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,oBAAoB,EAAE,GAAG,MAAM,cAAc,CAAC;QAC7E,cAAc;QACd,WAAW;QACX,4BAA4B;KAC7B,CAAC,CAAA;IAEF,MAAM,YAAY,GAAG,aAAa,GAAG,oBAAoB,CAAA;IAEzD,OAAO,MAAM,CAAC,sBAAsB,EAAE;QACpC,KAAK;QACL,eAAe,EAAE,YAAY,CAAC,QAAQ,EAAE;QACxC,WAAW,EAAE,oBAAoB,CAAC,QAAQ,EAAE;QAC5C,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;KAC9B,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -8,7 +8,12 @@ type EvmFeeQuote = {
|
|
|
8
8
|
type GetEvmFeeQuoteInput = {
|
|
9
9
|
keysignPayload: KeysignPayload;
|
|
10
10
|
feeSettings?: FeeSettings<'evm'>;
|
|
11
|
+
/** Gas limit the transaction's author (a dApp, an aggregator route) asks for. */
|
|
11
12
|
thirdPartyGasLimitEstimation?: bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Extra floor on the value that stands in for a failed simulation. Never
|
|
15
|
+
* raises a successful estimate.
|
|
16
|
+
*/
|
|
12
17
|
minimumGasLimit?: bigint;
|
|
13
18
|
};
|
|
14
19
|
export declare const getEvmFeeQuote: ({ keysignPayload, feeSettings, thirdPartyGasLimitEstimation, minimumGasLimit, }: GetEvmFeeQuoteInput) => Promise<EvmFeeQuote>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEvmFeeQuote.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/fee/resolvers/evm/getEvmFeeQuote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEvmFeeQuote.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/fee/resolvers/evm/getEvmFeeQuote.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAMlF,OAAO,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAA;AAehG,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IAChC,iFAAiF;IACjF,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAsBD,eAAO,MAAM,cAAc,GAAU,iFAKlC,mBAAmB,KAAG,OAAO,CAAC,WAAW,CAmM3C,CAAA"}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
import { Chain
|
|
1
|
+
import { Chain } from '@vultisig/core-chain/Chain';
|
|
2
2
|
import { evmChainInfo } from '@vultisig/core-chain/chains/evm/chainInfo';
|
|
3
3
|
import { getEvmClient } from '@vultisig/core-chain/chains/evm/client';
|
|
4
|
+
import { evmChainTxFeeFormat } from '@vultisig/core-chain/chains/evm/tx/fee';
|
|
4
5
|
import { getEvmBaseFee } from '@vultisig/core-chain/tx/fee/evm/baseFee';
|
|
5
|
-
import { clampEvmPriorityFee } from '@vultisig/core-chain/tx/fee/evm/clampEvmPriorityFee';
|
|
6
|
+
import { clampEvmPriorityFee, isZeroPriorityFeeChain } from '@vultisig/core-chain/tx/fee/evm/clampEvmPriorityFee';
|
|
7
|
+
import { evmRouterDepositGasLimit, getEvmCalldataGas, getEvmContractCallGasLimit, getEvmTransferGasLimit, } from '@vultisig/core-chain/tx/fee/evm/evmGasLimit';
|
|
8
|
+
import { getEvmGasPrice } from '@vultisig/core-chain/tx/fee/evm/gasPrice';
|
|
6
9
|
import { getEvmMaxPriorityFeePerGas } from '@vultisig/core-chain/tx/fee/evm/maxPriorityFeePerGas';
|
|
7
10
|
import { getKeysignSwapPayload } from '@vultisig/core-mpc/keysign/swap/getKeysignSwapPayload';
|
|
8
11
|
import { getIsGenericContractCall } from '@vultisig/core-mpc/keysign/utils/getIsGenericContractCall';
|
|
9
12
|
import { getKeysignAmount } from '@vultisig/core-mpc/keysign/utils/getKeysignAmount';
|
|
10
13
|
import { getKeysignCoin } from '@vultisig/core-mpc/keysign/utils/getKeysignCoin';
|
|
11
|
-
import { without } from '@vultisig/lib-utils/array/without';
|
|
12
14
|
import { attempt, withFallback } from '@vultisig/lib-utils/attempt';
|
|
13
15
|
import { bigIntMax } from '@vultisig/lib-utils/bigint/bigIntMax';
|
|
14
16
|
import { formatDataToHex } from '@vultisig/lib-utils/formatDataToHex';
|
|
17
|
+
import { match } from '@vultisig/lib-utils/match';
|
|
15
18
|
import { matchRecordUnion } from '@vultisig/lib-utils/matchRecordUnion';
|
|
16
|
-
import { encodeFunctionData, erc20Abi } from 'viem';
|
|
19
|
+
import { encodeFunctionData, erc20Abi, isHex } from 'viem';
|
|
17
20
|
import { publicActionsL2 } from 'viem/zksync';
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
21
|
+
const percentOf = (value, percent) => (value * percent) / 100n;
|
|
22
|
+
// Half again on top of a simulated contract call: a route that turns out to need
|
|
23
|
+
// slightly more gas than its simulation would otherwise revert and forfeit the gas.
|
|
24
|
+
const inflateGasLimit = (value) => value + value / 2n;
|
|
25
|
+
const getEvmTxKind = (keysignPayload, swapPayload) => {
|
|
26
|
+
if (swapPayload) {
|
|
27
|
+
return 'general' in swapPayload ? 'swap' : 'routerDeposit';
|
|
28
|
+
}
|
|
29
|
+
const { memo } = keysignPayload;
|
|
30
|
+
if (getIsGenericContractCall(keysignPayload) || (memo && isHex(memo))) {
|
|
31
|
+
return 'contractCall';
|
|
32
|
+
}
|
|
33
|
+
return 'transfer';
|
|
34
|
+
};
|
|
22
35
|
export const getEvmFeeQuote = async ({ keysignPayload, feeSettings, thirdPartyGasLimitEstimation, minimumGasLimit, }) => {
|
|
23
36
|
const coin = getKeysignCoin(keysignPayload);
|
|
24
37
|
const { chain, address } = coin;
|
|
@@ -27,30 +40,55 @@ export const getEvmFeeQuote = async ({ keysignPayload, feeSettings, thirdPartyGa
|
|
|
27
40
|
const receiver = keysignPayload.toAddress;
|
|
28
41
|
const data = keysignPayload.memo ? formatDataToHex(keysignPayload.memo) : undefined;
|
|
29
42
|
const swapPayload = getKeysignSwapPayload(keysignPayload);
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const kind = getEvmTxKind(keysignPayload, swapPayload);
|
|
44
|
+
const kindGasLimit = match(kind, {
|
|
45
|
+
transfer: () => getEvmTransferGasLimit(coin),
|
|
46
|
+
contractCall: () => getEvmContractCallGasLimit(chain),
|
|
47
|
+
swap: () => getEvmContractCallGasLimit(chain),
|
|
48
|
+
routerDeposit: () => evmRouterDepositGasLimit,
|
|
49
|
+
});
|
|
50
|
+
// A fee-coin transfer that could not be simulated still has to cover the
|
|
51
|
+
// calldata its memo becomes, which the per-chain floor leaves out; a node
|
|
52
|
+
// refuses a limit below that intrinsic cost outright.
|
|
53
|
+
const unsimulatedGasLimit = kind === 'transfer' && !coin.id && data ? kindGasLimit + getEvmCalldataGas(data) : kindGasLimit;
|
|
54
|
+
// Stands in for a simulation that failed. A caller minimum only ever raises
|
|
55
|
+
// this stand-in, never a real estimate.
|
|
56
|
+
const fallbackGasLimit = bigIntMax(unsimulatedGasLimit, minimumGasLimit ?? 0n);
|
|
57
|
+
const requestedGasLimit = thirdPartyGasLimitEstimation ?? 0n;
|
|
58
|
+
const resolveGasLimit = (estimatedGasLimit) => match(kind, {
|
|
59
|
+
// A transfer costs what its simulation says, raised to the per-chain floor.
|
|
60
|
+
transfer: () => bigIntMax(estimatedGasLimit ?? fallbackGasLimit, kindGasLimit, requestedGasLimit),
|
|
61
|
+
// A contract call gets headroom over its simulation (or the fallback), and
|
|
62
|
+
// never less than what its author asked for.
|
|
63
|
+
contractCall: () => inflateGasLimit(bigIntMax(estimatedGasLimit ?? fallbackGasLimit, requestedGasLimit)),
|
|
64
|
+
// A swap is signed with the larger of the route's own gas and the inflated
|
|
65
|
+
// simulation; a route that carries no gas figure counts as the swap default.
|
|
66
|
+
swap: () => bigIntMax(requestedGasLimit > 0n ? requestedGasLimit : kindGasLimit, inflateGasLimit(estimatedGasLimit ?? fallbackGasLimit)),
|
|
67
|
+
// A router deposit is never simulated, so its fixed limit is the stand-in
|
|
68
|
+
// a caller minimum may raise.
|
|
69
|
+
routerDeposit: () => bigIntMax(fallbackGasLimit, requestedGasLimit),
|
|
70
|
+
});
|
|
71
|
+
const isLegacyPriced = evmChainTxFeeFormat[chain] === 'legacy';
|
|
72
|
+
// Headroom against the base fee rising while the keysign runs: 20% on
|
|
73
|
+
// everything, plus 10% on aggregator swaps, whose quotes go stale fastest
|
|
74
|
+
// and whose reverts cost the most.
|
|
75
|
+
const withBaseFeeHeadroom = (baseFee) => kind === 'swap' ? percentOf(percentOf(baseFee, 110n), 120n) : percentOf(baseFee, 120n);
|
|
76
|
+
// A legacy-priced chain has a single gas price; a swap gets 10% on top of it.
|
|
77
|
+
const withGasPriceHeadroom = (gasPrice) => (kind === 'swap' ? percentOf(gasPrice, 110n) : gasPrice);
|
|
78
|
+
const getBaseFeePerGas = async () => isLegacyPriced ? withGasPriceHeadroom(await getEvmGasPrice(chain)) : withBaseFeeHeadroom(await getEvmBaseFee(chain));
|
|
79
|
+
// A legacy-priced chain carries no tip, and a chain that pins it to zero
|
|
80
|
+
// needs no network suggestion to discard.
|
|
81
|
+
const getMaxPriorityFeePerGas = async () => isLegacyPriced || isZeroPriorityFeeChain(chain)
|
|
82
|
+
? 0n
|
|
83
|
+
: clampEvmPriorityFee(chain, await getEvmMaxPriorityFeePerGas(chain));
|
|
48
84
|
const getEstimateGasParams = async () => {
|
|
49
85
|
if (swapPayload) {
|
|
50
86
|
return matchRecordUnion(swapPayload, {
|
|
51
87
|
native: () => null,
|
|
52
88
|
general: ({ quote }) => {
|
|
53
|
-
|
|
89
|
+
// A token route cannot be simulated until its allowance exists, so it
|
|
90
|
+
// is sized from the route's own gas and the swap fallback instead.
|
|
91
|
+
if (coin.id || !quote?.tx) {
|
|
54
92
|
return null;
|
|
55
93
|
}
|
|
56
94
|
const { to, data, value } = quote.tx;
|
|
@@ -95,7 +133,7 @@ export const getEvmFeeQuote = async ({ keysignPayload, feeSettings, thirdPartyGa
|
|
|
95
133
|
if (feeSettings) {
|
|
96
134
|
return {
|
|
97
135
|
gasLimit: feeSettings.gasLimit,
|
|
98
|
-
baseFeePerGas: await
|
|
136
|
+
baseFeePerGas: await getBaseFeePerGas(),
|
|
99
137
|
maxPriorityFeePerGas: feeSettings.maxPriorityFeePerGas,
|
|
100
138
|
};
|
|
101
139
|
}
|
|
@@ -136,11 +174,9 @@ export const getEvmFeeQuote = async ({ keysignPayload, feeSettings, thirdPartyGa
|
|
|
136
174
|
data: estimateGasParams.data,
|
|
137
175
|
})), undefined)
|
|
138
176
|
: undefined;
|
|
139
|
-
const
|
|
140
|
-
const baseFeePerGas = baseFeeMultiplier(await getEvmBaseFee(chain));
|
|
141
|
-
const maxPriorityFeePerGas = clampEvmPriorityFee(chain, await getEvmMaxPriorityFeePerGas(chain));
|
|
177
|
+
const [baseFeePerGas, maxPriorityFeePerGas] = await Promise.all([getBaseFeePerGas(), getMaxPriorityFeePerGas()]);
|
|
142
178
|
return {
|
|
143
|
-
gasLimit,
|
|
179
|
+
gasLimit: resolveGasLimit(estimatedGasLimit),
|
|
144
180
|
baseFeePerGas,
|
|
145
181
|
maxPriorityFeePerGas,
|
|
146
182
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEvmFeeQuote.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/fee/resolvers/evm/getEvmFeeQuote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"getEvmFeeQuote.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/fee/resolvers/evm/getEvmFeeQuote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAA;AACjH,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAA;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,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CAAC,CAAC,CAAA;QAEhH,OAAO;YACL,QAAQ,EAAE,eAAe,CAAC,iBAAiB,CAAC;YAC5C,aAAa;YACb,oBAAoB;SACrB,CAAA;IACH,CAAC,CAAA;IAED,OAAO,MAAM,UAAU,EAAE,CAAA;AAC3B,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAItD,eAAO,MAAM,mBAAmB,EAAE,qBAAqB,CAAC,KAAK,CA2E5D,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getTonMessageBounceable } from '@vultisig/core-chain/chains/ton/messageBounce';
|
|
2
2
|
import { isTonStakingComment } from '@vultisig/core-chain/chains/ton/staking';
|
|
3
|
+
import { resolveTonWalletVersion, tonMaxMessagesPerRequest } from '@vultisig/core-chain/chains/ton/wallet';
|
|
3
4
|
import { isFeeCoin } from '@vultisig/core-chain/coin/utils/isFeeCoin';
|
|
5
|
+
import { match } from '@vultisig/lib-utils/match';
|
|
4
6
|
import { TW } from '@trustwallet/wallet-core';
|
|
5
7
|
import { getBlockchainSpecificValue } from '../../../chainSpecific/KeysignChainSpecific.js';
|
|
6
8
|
import { getKeysignTwPublicKey } from '../../../tw/getKeysignTwPublicKey.js';
|
|
@@ -9,6 +11,14 @@ import { buildJettonTransfer } from './jetton.js';
|
|
|
9
11
|
import { buildNativeTonTransfer, buildNativeTonTransferFromMessage } from './native.js';
|
|
10
12
|
export const getTonSigningInputs = ({ keysignPayload, walletCore }) => {
|
|
11
13
|
const coin = getKeysignCoin(keysignPayload);
|
|
14
|
+
const publicKeyBytes = getKeysignTwPublicKey(keysignPayload);
|
|
15
|
+
// The payload does not say which wallet contract the sender is; its address
|
|
16
|
+
// does. Every co-signer derives the same answer from the shared vault key.
|
|
17
|
+
const walletVersion = resolveTonWalletVersion({
|
|
18
|
+
address: coin.address,
|
|
19
|
+
publicKey: walletCore.PublicKey.createWithData(publicKeyBytes, walletCore.PublicKeyType.ed25519),
|
|
20
|
+
walletCore,
|
|
21
|
+
});
|
|
12
22
|
// `sendMaxAmount` is deliberately not read here. A MAX send is the displayed
|
|
13
23
|
// `balance - fee` carried in `toAmount` like any other amount, so the signed bytes
|
|
14
24
|
// are identical either way and the flag stays descriptive metadata.
|
|
@@ -25,26 +35,36 @@ export const getTonSigningInputs = ({ keysignPayload, walletCore }) => {
|
|
|
25
35
|
// tag. The wallet-level flag describes only `toAddress` — the first message —
|
|
26
36
|
// and applying it to the whole batch signs the wrong bit on the others.
|
|
27
37
|
bounceable: getTonMessageBounceable(msg.to, !!msg.stateInit),
|
|
38
|
+
walletVersion,
|
|
28
39
|
}))
|
|
29
40
|
: [
|
|
30
41
|
isFeeCoin(coin)
|
|
31
42
|
? buildNativeTonTransfer({
|
|
32
43
|
keysignPayload,
|
|
33
44
|
bounceable: isStakeOp ? true : !!bounceable,
|
|
45
|
+
walletVersion,
|
|
34
46
|
})
|
|
35
47
|
: buildJettonTransfer({
|
|
36
48
|
keysignPayload,
|
|
37
49
|
walletCore,
|
|
38
50
|
jettonAddress,
|
|
39
51
|
isActiveDestination,
|
|
52
|
+
walletVersion,
|
|
40
53
|
}),
|
|
41
54
|
];
|
|
55
|
+
const maxMessages = tonMaxMessagesPerRequest[walletVersion];
|
|
56
|
+
if (messages.length > maxMessages) {
|
|
57
|
+
throw new Error(`A ${walletVersion} TON wallet can send at most ${maxMessages} messages per request, got ${messages.length}`);
|
|
58
|
+
}
|
|
42
59
|
const input = TW.TheOpenNetwork.Proto.SigningInput.create({
|
|
43
|
-
walletVersion:
|
|
60
|
+
walletVersion: match(walletVersion, {
|
|
61
|
+
v4r2: () => TW.TheOpenNetwork.Proto.WalletVersion.WALLET_V4_R2,
|
|
62
|
+
v5r1: () => TW.TheOpenNetwork.Proto.WalletVersion.WALLET_V5_R1,
|
|
63
|
+
}),
|
|
44
64
|
expireAt: Number(expireAt.toString()),
|
|
45
65
|
sequenceNumber: Number(sequenceNumber.toString()),
|
|
46
66
|
messages,
|
|
47
|
-
publicKey:
|
|
67
|
+
publicKey: publicKeyBytes,
|
|
48
68
|
});
|
|
49
69
|
return [input];
|
|
50
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AACrE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAA;AAE7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAA;AAEpF,MAAM,CAAC,MAAM,mBAAmB,GAAiC,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE;IAClG,MAAM,IAAI,GAAG,cAAc,CAAC,cAAc,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,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AAC;IAED,MAAM,KAAK,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;QACxD,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE;YAClC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY;YAC9D,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY;SAC/D,CAAC;QACF,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACrC,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QACjD,QAAQ;QACR,SAAS,EAAE,cAAc;KAC1B,CAAC,CAAA;IAEF,OAAO,CAAC,KAAK,CAAC,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TonWalletVersion } from '@vultisig/core-chain/chains/ton/wallet';
|
|
1
2
|
import { KeysignPayload } from '@vultisig/core-mpc/types/vultisig/keysign/v1/keysign_message_pb';
|
|
2
3
|
import { TW } from '@trustwallet/wallet-core';
|
|
3
4
|
import { WalletCore } from '@trustwallet/wallet-core';
|
|
@@ -6,6 +7,7 @@ type BuildJettonTransferInput = {
|
|
|
6
7
|
walletCore: WalletCore;
|
|
7
8
|
jettonAddress: string;
|
|
8
9
|
isActiveDestination: boolean;
|
|
10
|
+
walletVersion: TonWalletVersion;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* Builds the transfer that carries a Jetton send: a fixed TON amount to the
|
|
@@ -13,6 +15,6 @@ type BuildJettonTransferInput = {
|
|
|
13
15
|
* nanoton only when the destination is already active, so an inactive recipient
|
|
14
16
|
* isn't charged for a notification it cannot receive.
|
|
15
17
|
*/
|
|
16
|
-
export declare const buildJettonTransfer: ({ keysignPayload, walletCore, jettonAddress, isActiveDestination, }: BuildJettonTransferInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
18
|
+
export declare const buildJettonTransfer: ({ keysignPayload, walletCore, jettonAddress, isActiveDestination, walletVersion, }: BuildJettonTransferInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
17
19
|
export {};
|
|
18
20
|
//# sourceMappingURL=jetton.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jetton.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/jetton.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAA;AAEhG,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAMrD,KAAK,wBAAwB,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"jetton.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/jetton.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAA;AAEhG,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAMrD,KAAK,wBAAwB,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,aAAa,EAAE,gBAAgB,CAAA;CAChC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,oFAMjC,wBAAwB,KAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,QAsCrD,CAAA"}
|
|
@@ -4,14 +4,14 @@ import { shouldBePresent } from '@vultisig/lib-utils/assert/shouldBePresent';
|
|
|
4
4
|
import { TW } from '@trustwallet/wallet-core';
|
|
5
5
|
import { getKeysignAmount } from '../../../utils/getKeysignAmount.js';
|
|
6
6
|
import { getKeysignCoin } from '../../../utils/getKeysignCoin.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getTonSendMode, tonAmountToBytes } from './native.js';
|
|
8
8
|
/**
|
|
9
9
|
* Builds the transfer that carries a Jetton send: a fixed TON amount to the
|
|
10
10
|
* sender's own Jetton wallet, wrapping the Jetton payload. `forwardAmount` is 1
|
|
11
11
|
* nanoton only when the destination is already active, so an inactive recipient
|
|
12
12
|
* isn't charged for a notification it cannot receive.
|
|
13
13
|
*/
|
|
14
|
-
export const buildJettonTransfer = ({ keysignPayload, walletCore, jettonAddress, isActiveDestination, }) => {
|
|
14
|
+
export const buildJettonTransfer = ({ keysignPayload, walletCore, jettonAddress, isActiveDestination, walletVersion, }) => {
|
|
15
15
|
// `TonSpecific.jettonAddress` is a plain proto string that defaults to '' when the
|
|
16
16
|
// sender's jetton wallet could not be resolved, and '' survives every null/undefined
|
|
17
17
|
// check on the way here. Signing that would broadcast a transfer to no destination,
|
|
@@ -40,7 +40,7 @@ export const buildJettonTransfer = ({ keysignPayload, walletCore, jettonAddress,
|
|
|
40
40
|
amount: tonAmountToBytes(tonConfig.jettonAmount),
|
|
41
41
|
bounceable: true,
|
|
42
42
|
comment: keysignPayload.memo ?? '',
|
|
43
|
-
mode:
|
|
43
|
+
mode: getTonSendMode(walletVersion),
|
|
44
44
|
jettonTransfer,
|
|
45
45
|
});
|
|
46
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jetton.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/jetton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;
|
|
1
|
+
{"version":3,"file":"jetton.js","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/jetton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAA;AAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAA;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAU3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,cAAc,EACd,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,GACY,EAAoC,EAAE;IAC/D,mFAAmF;IACnF,qFAAqF;IACrF,oFAAoF;IACpF,qEAAqE;IACrE,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAA;IACpG,CAAC;IAED,MAAM,IAAI,GAAG,cAAc,CAAC,cAAc,CAAC,CAAA;IAE3C,MAAM,kBAAkB,GAAG,UAAU,CAAC,mBAAmB,CAAC,cAAc,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAE/G,MAAM,MAAM,GAAG,eAAe,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAA;IAChE,MAAM,aAAa,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnD,4EAA4E;IAC5E,2EAA2E;IAC3E,6EAA6E;IAC7E,8EAA8E;IAC9E,4CAA4C;IAC5C,kBAAkB,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAAE,CAAC,CAAA;IAEhG,MAAM,cAAc,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC;QACnE,YAAY,EAAE,gBAAgB,CAAC,MAAM,CAAC;QACtC,OAAO,EAAE,kBAAkB;QAC3B,eAAe,EAAE,IAAI,CAAC,OAAO;QAC7B,aAAa,EAAE,gBAAgB,CAAC,aAAa,CAAC;KAC/C,CAAC,CAAA;IAEF,OAAO,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC7C,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,YAAY,CAAC;QAChD,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,cAAc,CAAC,IAAI,IAAI,EAAE;QAClC,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC;QACnC,cAAc;KACf,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
+
import { TonWalletVersion } from '@vultisig/core-chain/chains/ton/wallet';
|
|
2
3
|
import { KeysignPayload } from '@vultisig/core-mpc/types/vultisig/keysign/v1/keysign_message_pb';
|
|
3
4
|
import { TW } from '@trustwallet/wallet-core';
|
|
4
5
|
type BuildNativeTonTransferFromMessageInput = {
|
|
@@ -7,10 +8,12 @@ type BuildNativeTonTransferFromMessageInput = {
|
|
|
7
8
|
payload?: string;
|
|
8
9
|
stateInit?: string;
|
|
9
10
|
bounceable: boolean;
|
|
11
|
+
walletVersion: TonWalletVersion;
|
|
10
12
|
};
|
|
11
13
|
type BuildNativeTonTransferInput = {
|
|
12
14
|
keysignPayload: KeysignPayload;
|
|
13
15
|
bounceable: boolean;
|
|
16
|
+
walletVersion: TonWalletVersion;
|
|
14
17
|
};
|
|
15
18
|
export declare const tonAmountToBytes: (amount: string | bigint) => Buffer;
|
|
16
19
|
/**
|
|
@@ -29,6 +32,18 @@ export declare const tonAmountToBytes: (amount: string | bigint) => Buffer;
|
|
|
29
32
|
* this payload, so changing it here breaks keysign with any client that has not changed too.
|
|
30
33
|
*/
|
|
31
34
|
export declare const tonSendMode = TW.TheOpenNetwork.Proto.SendMode.PAY_FEES_SEPARATELY;
|
|
35
|
+
/**
|
|
36
|
+
* The send mode for a given wallet contract.
|
|
37
|
+
*
|
|
38
|
+
* W5 is the exception to the rule above: its code refuses an external request
|
|
39
|
+
* unless every action carries `IGNORE_ACTION_PHASE_ERRORS`, because that is
|
|
40
|
+
* how it guarantees the seqno advances even when an action fails — the
|
|
41
|
+
* contract's own replay protection. WalletCore enforces the same check before
|
|
42
|
+
* it will build the message. The blindness the flag causes is covered on the
|
|
43
|
+
* other side: the status resolver reads the action phase, so a W5 send whose
|
|
44
|
+
* transfer was skipped reports as failed instead of confirmed.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getTonSendMode: (walletVersion: TonWalletVersion) => number;
|
|
32
47
|
/**
|
|
33
48
|
* Builds the single WalletCore transfer for an app-initiated native TON send.
|
|
34
49
|
*
|
|
@@ -39,11 +54,11 @@ export declare const tonSendMode = TW.TheOpenNetwork.Proto.SendMode.PAY_FEES_SEP
|
|
|
39
54
|
* send is just `balance - fee` as an ordinary amount, and that fee is the reserve the
|
|
40
55
|
* send mode then draws on.
|
|
41
56
|
*/
|
|
42
|
-
export declare const buildNativeTonTransfer: ({ keysignPayload, bounceable, }: BuildNativeTonTransferInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
57
|
+
export declare const buildNativeTonTransfer: ({ keysignPayload, bounceable, walletVersion, }: BuildNativeTonTransferInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
43
58
|
/**
|
|
44
59
|
* Builds a transfer for one message of a dApp-supplied `signTon` request. The
|
|
45
60
|
* message carries its own payload/stateInit, so no comment is attached here.
|
|
46
61
|
*/
|
|
47
|
-
export declare const buildNativeTonTransferFromMessage: ({ to, amount, payload, stateInit, bounceable, }: BuildNativeTonTransferFromMessageInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
62
|
+
export declare const buildNativeTonTransferFromMessage: ({ to, amount, payload, stateInit, bounceable, walletVersion, }: BuildNativeTonTransferFromMessageInput) => TW.TheOpenNetwork.Proto.Transfer;
|
|
48
63
|
export {};
|
|
49
64
|
//# sourceMappingURL=native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAA;
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/mpc/keysign/signingInputs/resolvers/ton/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,iEAAiE,CAAA;AAGhG,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAA;AAE7C,KAAK,sCAAsC,GAAG;IAC5C,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,EAAE,gBAAgB,CAAA;CAChC,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,EAAE,gBAAgB,CAAA;CAChC,CAAA;AAMD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,GAAG,MAAM,KAAG,MAuB1D,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,uDAAuD,CAAA;AAE/E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,eAAe,gBAAgB,KAAG,MAI7D,CAAA;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAAI,gDAIpC,2BAA2B,KAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,QAWxD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iCAAiC,GAAI,gEAO/C,sCAAsC,KAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,QAUnE,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { validateTonComment } from '@vultisig/core-chain/chains/ton/comment';
|
|
3
3
|
import { numberToEvenHex } from '@vultisig/lib-utils/hex/numberToHex';
|
|
4
|
+
import { match } from '@vultisig/lib-utils/match';
|
|
4
5
|
import { TW } from '@trustwallet/wallet-core';
|
|
5
6
|
const tonUnsignedDecimalRegex = /^\d+$/;
|
|
6
7
|
const tonMaxAmount = (1n << 120n) - 1n;
|
|
@@ -40,6 +41,21 @@ export const tonAmountToBytes = (amount) => {
|
|
|
40
41
|
* this payload, so changing it here breaks keysign with any client that has not changed too.
|
|
41
42
|
*/
|
|
42
43
|
export const tonSendMode = TW.TheOpenNetwork.Proto.SendMode.PAY_FEES_SEPARATELY;
|
|
44
|
+
/**
|
|
45
|
+
* The send mode for a given wallet contract.
|
|
46
|
+
*
|
|
47
|
+
* W5 is the exception to the rule above: its code refuses an external request
|
|
48
|
+
* unless every action carries `IGNORE_ACTION_PHASE_ERRORS`, because that is
|
|
49
|
+
* how it guarantees the seqno advances even when an action fails — the
|
|
50
|
+
* contract's own replay protection. WalletCore enforces the same check before
|
|
51
|
+
* it will build the message. The blindness the flag causes is covered on the
|
|
52
|
+
* other side: the status resolver reads the action phase, so a W5 send whose
|
|
53
|
+
* transfer was skipped reports as failed instead of confirmed.
|
|
54
|
+
*/
|
|
55
|
+
export const getTonSendMode = (walletVersion) => match(walletVersion, {
|
|
56
|
+
v4r2: () => tonSendMode,
|
|
57
|
+
v5r1: () => tonSendMode | TW.TheOpenNetwork.Proto.SendMode.IGNORE_ACTION_PHASE_ERRORS,
|
|
58
|
+
});
|
|
43
59
|
/**
|
|
44
60
|
* Builds the single WalletCore transfer for an app-initiated native TON send.
|
|
45
61
|
*
|
|
@@ -50,7 +66,7 @@ export const tonSendMode = TW.TheOpenNetwork.Proto.SendMode.PAY_FEES_SEPARATELY;
|
|
|
50
66
|
* send is just `balance - fee` as an ordinary amount, and that fee is the reserve the
|
|
51
67
|
* send mode then draws on.
|
|
52
68
|
*/
|
|
53
|
-
export const buildNativeTonTransfer = ({ keysignPayload, bounceable, }) => {
|
|
69
|
+
export const buildNativeTonTransfer = ({ keysignPayload, bounceable, walletVersion, }) => {
|
|
54
70
|
const comment = keysignPayload.memo || '';
|
|
55
71
|
validateTonComment({ memo: comment });
|
|
56
72
|
return TW.TheOpenNetwork.Proto.Transfer.create({
|
|
@@ -58,14 +74,14 @@ export const buildNativeTonTransfer = ({ keysignPayload, bounceable, }) => {
|
|
|
58
74
|
amount: tonAmountToBytes(keysignPayload.toAmount),
|
|
59
75
|
bounceable,
|
|
60
76
|
comment,
|
|
61
|
-
mode:
|
|
77
|
+
mode: getTonSendMode(walletVersion),
|
|
62
78
|
});
|
|
63
79
|
};
|
|
64
80
|
/**
|
|
65
81
|
* Builds a transfer for one message of a dApp-supplied `signTon` request. The
|
|
66
82
|
* message carries its own payload/stateInit, so no comment is attached here.
|
|
67
83
|
*/
|
|
68
|
-
export const buildNativeTonTransferFromMessage = ({ to, amount, payload = '', stateInit, bounceable, }) => {
|
|
84
|
+
export const buildNativeTonTransferFromMessage = ({ to, amount, payload = '', stateInit, bounceable, walletVersion, }) => {
|
|
69
85
|
return TW.TheOpenNetwork.Proto.Transfer.create({
|
|
70
86
|
dest: to,
|
|
71
87
|
amount: tonAmountToBytes(amount),
|
|
@@ -73,7 +89,7 @@ export const buildNativeTonTransferFromMessage = ({ to, amount, payload = '', st
|
|
|
73
89
|
comment: '',
|
|
74
90
|
customPayload: payload || undefined,
|
|
75
91
|
stateInit: stateInit || undefined,
|
|
76
|
-
mode:
|
|
92
|
+
mode: getTonSendMode(walletVersion),
|
|
77
93
|
});
|
|
78
94
|
};
|
|
79
95
|
//# sourceMappingURL=native.js.map
|