0xtrails 0.7.0 → 0.8.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/{ccip-fConRNoG.js → ccip-uMWNlvmJ.js} +34 -34
- package/dist/fees.d.ts.map +1 -1
- package/dist/{index-BbajxCG_.js → index-BiPwqVkZ.js} +31527 -28874
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +478 -456
- package/dist/intents.d.ts +10 -4
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +2 -2
- package/dist/prices.d.ts.map +1 -1
- package/dist/refund.d.ts +116 -0
- package/dist/refund.d.ts.map +1 -0
- package/dist/tokenBalances.d.ts +1 -1
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +4 -3
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +3 -3
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +1 -2
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +3 -3
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +5 -4
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactions.d.ts +4 -0
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +2 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +2 -1
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorDisplay.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +2 -1
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +2 -1
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +2 -1
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts +1 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -1
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useGetIntent.d.ts +18 -0
- package/dist/widget/hooks/useGetIntent.d.ts.map +1 -0
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +10 -7
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +3 -2
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -1
- package/dist/widget/index.js +3 -3
- package/dist/widget/widget.d.ts +2 -1
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +5 -12
- package/src/fees.ts +8 -2
- package/src/index.ts +33 -1
- package/src/intents.ts +34 -7
- package/src/prepareSend.ts +6 -4
- package/src/prices.ts +6 -6
- package/src/refund.ts +914 -0
- package/src/tokenBalances.ts +4 -14
- package/src/transactionIntent/handlers/crossChain.ts +21 -10
- package/src/transactionIntent/handlers/sameChainSameToken.ts +12 -8
- package/src/transactionIntent/quote/normalizeQuote.ts +29 -27
- package/src/transactionIntent/quote/quoteHelpers.ts +5 -9
- package/src/transactionIntent/types.ts +5 -3
- package/src/transactions.ts +5 -0
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +197 -5
- package/src/widget/components/ClassicSwap.tsx +6 -3
- package/src/widget/components/Earn.tsx +6 -3
- package/src/widget/components/ErrorDisplay.tsx +6 -4
- package/src/widget/components/Fund.tsx +6 -3
- package/src/widget/components/FundSwap.tsx +2 -1
- package/src/widget/components/Pay.tsx +15 -7
- package/src/widget/components/PoolDeposit.tsx +6 -3
- package/src/widget/components/QuoteDetails.tsx +34 -38
- package/src/widget/components/Swap.tsx +2 -1
- package/src/widget/components/TokenImage.tsx +3 -1
- package/src/widget/components/TransactionDetails.tsx +108 -0
- package/src/widget/hooks/useAmountUsd.ts +0 -3
- package/src/widget/hooks/useDefaultTokenSelection.tsx +0 -3
- package/src/widget/hooks/useGetIntent.ts +53 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +85 -3
- package/src/widget/hooks/useQuote.ts +16 -10
- package/src/widget/hooks/useSendForm.ts +30 -15
- package/src/widget/hooks/useTokenList.ts +2 -4
- package/src/widget/hooks/useTrailsSendTransaction.ts +2 -1
- package/src/widget/widget.tsx +12 -6
- package/dist/sequenceWallet.d.ts +0 -67
- package/dist/sequenceWallet.d.ts.map +0 -1
- package/src/sequenceWallet.ts +0 -532
package/dist/sequenceWallet.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Account } from '@0xsequence/account';
|
|
2
|
-
import { commons } from '@0xsequence/core';
|
|
3
|
-
import { trackers } from '@0xsequence/sessions';
|
|
4
|
-
import { signers } from '@0xsequence/signhub';
|
|
5
|
-
import { Chain, PublicClient, WalletClient } from 'viem';
|
|
6
|
-
export type FlatTransaction = {
|
|
7
|
-
to: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
data?: string;
|
|
10
|
-
gasLimit?: string;
|
|
11
|
-
delegateCall?: boolean;
|
|
12
|
-
revertOnError?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type TransactionsEntry = {
|
|
15
|
-
subdigest?: string;
|
|
16
|
-
wallet: string;
|
|
17
|
-
space: string;
|
|
18
|
-
nonce: string;
|
|
19
|
-
chainId: string;
|
|
20
|
-
transactions: FlatTransaction[];
|
|
21
|
-
};
|
|
22
|
-
export declare const TRACKER: trackers.remote.RemoteConfigTracker;
|
|
23
|
-
export declare function createSequenceWallet(threshold: number, signers: {
|
|
24
|
-
address: string;
|
|
25
|
-
weight: number;
|
|
26
|
-
}[]): Promise<Account>;
|
|
27
|
-
export declare function toSequenceTransactions(txs: FlatTransaction[]): commons.transaction.Transaction[];
|
|
28
|
-
export declare function toSequenceTransaction(tx: FlatTransaction): commons.transaction.Transaction;
|
|
29
|
-
export declare function accountFor(args: {
|
|
30
|
-
address: string;
|
|
31
|
-
signatures?: {
|
|
32
|
-
signer: string;
|
|
33
|
-
signature: string;
|
|
34
|
-
}[];
|
|
35
|
-
sequenceProjectAccessKey: string;
|
|
36
|
-
}): Account;
|
|
37
|
-
export declare function digestOf(tx: TransactionsEntry): string;
|
|
38
|
-
export declare function subdigestOf(tx: TransactionsEntry): string;
|
|
39
|
-
export declare function fromSequenceTransactions(wallet: string, txs: commons.transaction.Transactionish): FlatTransaction[];
|
|
40
|
-
export declare function recoverSigner(signatures: string[], subdigest: string): {
|
|
41
|
-
signer: string;
|
|
42
|
-
signature: string;
|
|
43
|
-
}[];
|
|
44
|
-
export declare function simpleCreateSequenceWallet(account: Account): Promise<`0x${string}`>;
|
|
45
|
-
export declare function getIsWalletDeployed(wallet: `0x${string}`, publicClient: PublicClient): Promise<boolean>;
|
|
46
|
-
export declare function waitForWalletDeployment(wallet: `0x${string}`, publicClient: PublicClient): Promise<void>;
|
|
47
|
-
export declare function sequenceSendTransaction(sequenceWalletAddress: string, accountClient: WalletClient, publicClient: PublicClient, calls: any[], chain: Chain, sequenceProjectAccessKey: string): Promise<string | null>;
|
|
48
|
-
type TransactionBundle = commons.transaction.TransactionBundle;
|
|
49
|
-
type SignedTransactionBundle = commons.transaction.SignedTransactionBundle;
|
|
50
|
-
type IntendedTransactionBundle = commons.transaction.IntendedTransactionBundle;
|
|
51
|
-
type BytesLike = `0x${string}` | Uint8Array;
|
|
52
|
-
export declare class StaticSigner implements signers.SapientSigner {
|
|
53
|
-
private readonly address;
|
|
54
|
-
readonly _signature: string;
|
|
55
|
-
private readonly signatureBytes;
|
|
56
|
-
private readonly savedSuffix;
|
|
57
|
-
constructor(address: string, _signature: string);
|
|
58
|
-
buildDeployTransaction(): Promise<TransactionBundle | undefined>;
|
|
59
|
-
predecorateSignedTransactions(): Promise<SignedTransactionBundle[]>;
|
|
60
|
-
decorateTransactions(og: IntendedTransactionBundle): Promise<IntendedTransactionBundle>;
|
|
61
|
-
sign(): Promise<BytesLike>;
|
|
62
|
-
notifyStatusChange(): void;
|
|
63
|
-
suffix(): BytesLike;
|
|
64
|
-
getAddress(): Promise<string>;
|
|
65
|
-
}
|
|
66
|
-
export {};
|
|
67
|
-
//# sourceMappingURL=sequenceWallet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sequenceWallet.d.ts","sourceRoot":"","sources":["../src/sequenceWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAEhE,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,YAAY,EAEjB,KAAK,YAAY,EAClB,MAAM,MAAM,CAAA;AAGb,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,I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EAAE,MAAM,EACvB,UAAU,EAAE,MAAM;IASvB,sBAAsB,IAAI,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAIhE,6BAA6B,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAInE,oBAAoB,CACxB,EAAE,EAAE,yBAAyB,GAC5B,OAAO,CAAC,yBAAyB,CAAC;IAI/B,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC;IAIhC,kBAAkB,IAAI,IAAI;IAE1B,MAAM,IAAI,SAAS;IAIb,UAAU;CAGjB"}
|
package/src/sequenceWallet.ts
DELETED
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
import { Account } from "@0xsequence/account"
|
|
2
|
-
import { commons } from "@0xsequence/core"
|
|
3
|
-
import { allNetworks } from "@0xsequence/network"
|
|
4
|
-
import { trackers } from "@0xsequence/sessions"
|
|
5
|
-
import { Orchestrator, type signers } from "@0xsequence/signhub"
|
|
6
|
-
import { Abi, AbiFunction } from "ox"
|
|
7
|
-
import {
|
|
8
|
-
bytesToHex,
|
|
9
|
-
type Chain,
|
|
10
|
-
hexToBytes,
|
|
11
|
-
type PublicClient,
|
|
12
|
-
toHex,
|
|
13
|
-
type WalletClient,
|
|
14
|
-
} from "viem"
|
|
15
|
-
import { logger } from "./logger.js"
|
|
16
|
-
|
|
17
|
-
export type FlatTransaction = {
|
|
18
|
-
to: string
|
|
19
|
-
value?: string
|
|
20
|
-
data?: string
|
|
21
|
-
gasLimit?: string
|
|
22
|
-
delegateCall?: boolean
|
|
23
|
-
revertOnError?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type TransactionsEntry = {
|
|
27
|
-
subdigest?: string
|
|
28
|
-
wallet: string
|
|
29
|
-
space: string
|
|
30
|
-
nonce: string
|
|
31
|
-
chainId: string
|
|
32
|
-
transactions: FlatTransaction[]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const TRACKER = new trackers.remote.RemoteConfigTracker(
|
|
36
|
-
"https://sessions.sequence.app",
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
export async function createSequenceWallet(
|
|
40
|
-
threshold: number,
|
|
41
|
-
signers: { address: string; weight: number }[],
|
|
42
|
-
): Promise<Account> {
|
|
43
|
-
const account = await Account.new({
|
|
44
|
-
config: {
|
|
45
|
-
threshold,
|
|
46
|
-
// By default a random checkpoint is generated every second
|
|
47
|
-
checkpoint: Math.floor(Date.now() / 1000),
|
|
48
|
-
signers: signers,
|
|
49
|
-
},
|
|
50
|
-
tracker: TRACKER,
|
|
51
|
-
contexts: commons.context.defaultContexts,
|
|
52
|
-
orchestrator: new Orchestrator([]),
|
|
53
|
-
networks: allNetworks,
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Try to fetch the config from the tracker
|
|
57
|
-
const reverse1 = await TRACKER.imageHashOfCounterfactualWallet({
|
|
58
|
-
wallet: account.address,
|
|
59
|
-
})
|
|
60
|
-
if (!reverse1) {
|
|
61
|
-
throw new Error("Failed to fetch imageHash from the tracker")
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Try to fetch the imageHash from the tracker
|
|
65
|
-
const reverse2 = await TRACKER.configOfImageHash({
|
|
66
|
-
imageHash: reverse1.imageHash,
|
|
67
|
-
})
|
|
68
|
-
if (!reverse2) {
|
|
69
|
-
throw new Error("Failed to fetch config from the tracker")
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return account
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function toSequenceTransactions(
|
|
76
|
-
txs: FlatTransaction[],
|
|
77
|
-
): commons.transaction.Transaction[] {
|
|
78
|
-
return txs.map(toSequenceTransaction)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function toSequenceTransaction(
|
|
82
|
-
tx: FlatTransaction,
|
|
83
|
-
): commons.transaction.Transaction {
|
|
84
|
-
return {
|
|
85
|
-
to: tx.to,
|
|
86
|
-
value: tx.value ? BigInt(tx.value) : 0n,
|
|
87
|
-
data: tx.data,
|
|
88
|
-
gasLimit: tx.gasLimit ? BigInt(tx.gasLimit) : 100000n,
|
|
89
|
-
delegateCall: tx.delegateCall || false,
|
|
90
|
-
revertOnError: tx.revertOnError || false,
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function accountFor(args: {
|
|
95
|
-
address: string
|
|
96
|
-
signatures?: { signer: string; signature: string }[]
|
|
97
|
-
sequenceProjectAccessKey: string
|
|
98
|
-
}): Account {
|
|
99
|
-
const signers: signers.SapientSigner[] = []
|
|
100
|
-
|
|
101
|
-
if (args.signatures) {
|
|
102
|
-
for (const { signer, signature } of args.signatures) {
|
|
103
|
-
// Some ECDSA libraries may return the signature with `v` as 0x00 or 0x01
|
|
104
|
-
// but the Sequence protocol expects it to be 0x1b or 0x1c. We need to
|
|
105
|
-
// adjust the signature to match the protocol.
|
|
106
|
-
const signatureArr = hexToBytes(signature as `0x${string}`)
|
|
107
|
-
if (
|
|
108
|
-
signatureArr.length === 66 &&
|
|
109
|
-
(signatureArr[64] === 0 || signatureArr[64] === 1)
|
|
110
|
-
) {
|
|
111
|
-
signatureArr[64] = signatureArr[64] + 27
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
signers.push(new StaticSigner(signer, bytesToHex(signatureArr)))
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
logger.console.log("[trails-sdk] signers", signers)
|
|
119
|
-
|
|
120
|
-
return new Account({
|
|
121
|
-
address: args.address,
|
|
122
|
-
tracker: TRACKER,
|
|
123
|
-
contexts: commons.context.defaultContexts,
|
|
124
|
-
orchestrator: new Orchestrator(signers),
|
|
125
|
-
networks: allNetworks,
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function digestOf(tx: TransactionsEntry): string {
|
|
130
|
-
return commons.transaction.digestOfTransactions(
|
|
131
|
-
commons.transaction.encodeNonce(tx.space, tx.nonce),
|
|
132
|
-
toSequenceTransactions(tx.transactions),
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function subdigestOf(tx: TransactionsEntry): string {
|
|
137
|
-
const digest = digestOf(tx)
|
|
138
|
-
|
|
139
|
-
return commons.signature.subdigestOf({
|
|
140
|
-
digest,
|
|
141
|
-
chainId: tx.chainId,
|
|
142
|
-
address: tx.wallet,
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function fromSequenceTransactions(
|
|
147
|
-
wallet: string,
|
|
148
|
-
txs: commons.transaction.Transactionish,
|
|
149
|
-
): FlatTransaction[] {
|
|
150
|
-
const sequenceTxs = commons.transaction.fromTransactionish(wallet, txs)
|
|
151
|
-
return sequenceTxs.map((stx: any) => ({
|
|
152
|
-
to: stx.to,
|
|
153
|
-
value: stx.value?.toString(),
|
|
154
|
-
data: stx.data?.toString(),
|
|
155
|
-
gasLimit: stx.gasLimit?.toString(),
|
|
156
|
-
delegateCall: stx.delegateCall,
|
|
157
|
-
revertOnError: stx.revertOnError,
|
|
158
|
-
}))
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function recoverSigner(
|
|
162
|
-
signatures: string[],
|
|
163
|
-
subdigest: string,
|
|
164
|
-
): { signer: string; signature: string }[] {
|
|
165
|
-
const res: { signer: string; signature: string }[] = []
|
|
166
|
-
|
|
167
|
-
for (const signature of signatures) {
|
|
168
|
-
try {
|
|
169
|
-
const r = commons.signer.recoverSigner(subdigest, signature)
|
|
170
|
-
res.push({ signer: r, signature: signature })
|
|
171
|
-
} catch (e) {
|
|
172
|
-
logger.console.error("[trails-sdk] Failed to recover signature", e)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return res
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export async function simpleCreateSequenceWallet(
|
|
180
|
-
account: Account,
|
|
181
|
-
): Promise<`0x${string}`> {
|
|
182
|
-
const signer = account.address
|
|
183
|
-
const threshold = 1
|
|
184
|
-
const weight = 1
|
|
185
|
-
const wallet = await createSequenceWallet(threshold, [
|
|
186
|
-
{ address: signer, weight: weight },
|
|
187
|
-
])
|
|
188
|
-
|
|
189
|
-
return wallet.address as `0x${string}`
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export async function getIsWalletDeployed(
|
|
193
|
-
wallet: `0x${string}`,
|
|
194
|
-
publicClient: PublicClient,
|
|
195
|
-
): Promise<boolean> {
|
|
196
|
-
const hasCode = await publicClient?.getCode({
|
|
197
|
-
address: wallet as `0x${string}`,
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
const isDeployed = hasCode !== undefined && hasCode !== "0x"
|
|
201
|
-
return isDeployed
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function waitForWalletDeployment(
|
|
205
|
-
wallet: `0x${string}`,
|
|
206
|
-
publicClient: PublicClient,
|
|
207
|
-
): Promise<void> {
|
|
208
|
-
while (true) {
|
|
209
|
-
const isDeployed = await getIsWalletDeployed(wallet, publicClient)
|
|
210
|
-
if (isDeployed) {
|
|
211
|
-
break
|
|
212
|
-
}
|
|
213
|
-
logger.console.log("[trails-sdk] waiting for wallet deployment")
|
|
214
|
-
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
export async function sequenceSendTransaction(
|
|
218
|
-
sequenceWalletAddress: string,
|
|
219
|
-
accountClient: WalletClient,
|
|
220
|
-
publicClient: PublicClient,
|
|
221
|
-
calls: any[],
|
|
222
|
-
chain: Chain,
|
|
223
|
-
sequenceProjectAccessKey: string,
|
|
224
|
-
): Promise<string | null> {
|
|
225
|
-
const chainId = chain.id
|
|
226
|
-
if (!accountClient?.account?.address || !sequenceWalletAddress) {
|
|
227
|
-
throw new Error("Signer or sequence wallet address not available")
|
|
228
|
-
}
|
|
229
|
-
const txsToExecute = calls.map((call: any) => {
|
|
230
|
-
return {
|
|
231
|
-
to: call.to,
|
|
232
|
-
data: call.data,
|
|
233
|
-
value: call.value || "0",
|
|
234
|
-
revertOnError: true,
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
const txe: TransactionsEntry = {
|
|
239
|
-
wallet: sequenceWalletAddress as `0x${string}`,
|
|
240
|
-
space: Math.floor(Date.now()).toString(),
|
|
241
|
-
nonce: "0",
|
|
242
|
-
chainId: chainId.toString(),
|
|
243
|
-
transactions: txsToExecute,
|
|
244
|
-
}
|
|
245
|
-
// Calculate the tx subdigest
|
|
246
|
-
const subdigest = subdigestOf(txe)
|
|
247
|
-
const digestBytes = hexToBytes(subdigest as `0x${string}`)
|
|
248
|
-
// Sign the tx subdigest
|
|
249
|
-
const signature = await accountClient.signMessage({
|
|
250
|
-
account: accountClient.account,
|
|
251
|
-
message: { raw: digestBytes },
|
|
252
|
-
})
|
|
253
|
-
const suffixed = `${signature}02`
|
|
254
|
-
// Get the account for the Sequence Wallet with signatures
|
|
255
|
-
const sequenceAccount = accountFor({
|
|
256
|
-
address: sequenceWalletAddress as `0x${string}`,
|
|
257
|
-
signatures: [
|
|
258
|
-
{
|
|
259
|
-
signer: accountClient.account?.address as `0x${string}`,
|
|
260
|
-
signature: suffixed,
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
sequenceProjectAccessKey,
|
|
264
|
-
})
|
|
265
|
-
const sequenceTxs = toSequenceTransactions(txsToExecute)
|
|
266
|
-
const status = await sequenceAccount.status(chainId)
|
|
267
|
-
const wallet = sequenceAccount.walletForStatus(chainId, status)
|
|
268
|
-
|
|
269
|
-
logger.console.log("[trails-sdk] sequence wallet", wallet)
|
|
270
|
-
|
|
271
|
-
const isDeployed = await getIsWalletDeployed(
|
|
272
|
-
wallet.address as `0x${string}`,
|
|
273
|
-
publicClient,
|
|
274
|
-
)
|
|
275
|
-
if (!isDeployed) {
|
|
276
|
-
logger.console.log("[trails-sdk] deploying sequence wallet")
|
|
277
|
-
|
|
278
|
-
const deployTx = await wallet.buildDeployTransaction()
|
|
279
|
-
if (!wallet.relayer) throw new Error("Wallet deploy requires a relayer")
|
|
280
|
-
logger.console.log("[trails-sdk] deploy Tx", deployTx)
|
|
281
|
-
logger.console.log(
|
|
282
|
-
"[trails-sdk] deployTx entrypoint:",
|
|
283
|
-
deployTx!.entrypoint,
|
|
284
|
-
)
|
|
285
|
-
logger.console.log(
|
|
286
|
-
"[trails-sdk] deployTx transactions:",
|
|
287
|
-
deployTx!.transactions,
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
logger.console.log("[trails-sdk] getting fee options 0")
|
|
291
|
-
const feeOptions = await wallet.relayer.getFeeOptions(
|
|
292
|
-
wallet.address as `0x${string}`,
|
|
293
|
-
...deployTx!.transactions,
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
const quote = feeOptions?.quote
|
|
297
|
-
logger.console.log("[trails-sdk] feeOptions", feeOptions)
|
|
298
|
-
|
|
299
|
-
// Check if deployment is whitelisted (no fees required)
|
|
300
|
-
if (feeOptions?.options.length === 0) {
|
|
301
|
-
logger.console.log(
|
|
302
|
-
"[trails-sdk] Deployment is whitelisted - no fees required",
|
|
303
|
-
)
|
|
304
|
-
|
|
305
|
-
const bytes = new Uint8Array(32)
|
|
306
|
-
crypto.getRandomValues(bytes)
|
|
307
|
-
|
|
308
|
-
wallet.relayer.relay(
|
|
309
|
-
{
|
|
310
|
-
entrypoint: deployTx!.entrypoint as `0x${string}`,
|
|
311
|
-
transactions: deployTx!.transactions,
|
|
312
|
-
chainId: wallet.chainId,
|
|
313
|
-
intent: {
|
|
314
|
-
id: toHex(bytes),
|
|
315
|
-
wallet: wallet.address,
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
quote,
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
logger.console.log("[trails-sdk] Deployment relayed")
|
|
322
|
-
|
|
323
|
-
await waitForWalletDeployment(
|
|
324
|
-
wallet.address as `0x${string}`,
|
|
325
|
-
publicClient,
|
|
326
|
-
)
|
|
327
|
-
logger.console.log("[trails-sdk] sequence wallet deployed")
|
|
328
|
-
} else {
|
|
329
|
-
const option = feeOptions?.options[0]
|
|
330
|
-
if (!option) {
|
|
331
|
-
throw new Error("fee option not found")
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
logger.console.log("[trails-sdk] option", option)
|
|
335
|
-
|
|
336
|
-
if (option) {
|
|
337
|
-
logger.console.log("[trails-sdk] Using native token for deployment fee")
|
|
338
|
-
|
|
339
|
-
// Use encodeGasRefundTransaction to create the fee transaction
|
|
340
|
-
const feeTransactions = encodeGasRefundTransaction(option)
|
|
341
|
-
logger.console.log("[trails-sdk] Fee transactions:", feeTransactions)
|
|
342
|
-
|
|
343
|
-
// Include both deployment and fee transactions
|
|
344
|
-
const allTransactions = [...deployTx!.transactions]
|
|
345
|
-
logger.console.log(
|
|
346
|
-
"[trails-sdk] All transactions (deployment + fees):",
|
|
347
|
-
allTransactions,
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
const predecorated = await sequenceAccount.predecorateTransactions(
|
|
351
|
-
allTransactions,
|
|
352
|
-
status,
|
|
353
|
-
chainId,
|
|
354
|
-
)
|
|
355
|
-
const signed = await sequenceAccount.signTransactions(
|
|
356
|
-
predecorated,
|
|
357
|
-
chainId,
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
logger.console.log(
|
|
361
|
-
"[trails-sdk] signed transactions with fees:",
|
|
362
|
-
signed.transactions,
|
|
363
|
-
)
|
|
364
|
-
logger.console.log(
|
|
365
|
-
"[trails-sdk] signed entrypoint with fees:",
|
|
366
|
-
signed.entrypoint,
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
const bytes = new Uint8Array(32)
|
|
370
|
-
crypto.getRandomValues(bytes)
|
|
371
|
-
|
|
372
|
-
wallet.relayer.relay(
|
|
373
|
-
{
|
|
374
|
-
entrypoint: deployTx!.entrypoint as `0x${string}`,
|
|
375
|
-
transactions: deployTx!.transactions,
|
|
376
|
-
chainId: wallet.chainId,
|
|
377
|
-
intent: {
|
|
378
|
-
id: toHex(bytes),
|
|
379
|
-
wallet: wallet.address,
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
quote,
|
|
383
|
-
)
|
|
384
|
-
|
|
385
|
-
logger.console.log("[trails-sdk] relayed deployment")
|
|
386
|
-
|
|
387
|
-
await waitForWalletDeployment(
|
|
388
|
-
wallet.address as `0x${string}`,
|
|
389
|
-
publicClient,
|
|
390
|
-
)
|
|
391
|
-
logger.console.log("[trails-sdk] sequence wallet deployed")
|
|
392
|
-
} else {
|
|
393
|
-
throw new Error(
|
|
394
|
-
"ERC20 fee payment for deployment is not supported yet. Please use native token or a relayer with free wallet deployments.",
|
|
395
|
-
)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
logger.console.log("[trails-sdk] sequenceTxs", sequenceTxs)
|
|
401
|
-
logger.console.log("[trails-sdk] getting fee options 1")
|
|
402
|
-
const feeOptions = await wallet.relayer!.getFeeOptions(
|
|
403
|
-
wallet.address as `0x${string}`,
|
|
404
|
-
...sequenceTxs,
|
|
405
|
-
)
|
|
406
|
-
|
|
407
|
-
logger.console.log("[trails-sdk] feeOptions 1", feeOptions)
|
|
408
|
-
|
|
409
|
-
// Find the USDC option for fee payment
|
|
410
|
-
const option = feeOptions?.options.find(
|
|
411
|
-
(option) => option.token.symbol === "USDC",
|
|
412
|
-
)
|
|
413
|
-
|
|
414
|
-
const quote = feeOptions?.quote
|
|
415
|
-
|
|
416
|
-
// Use encodeGasRefundTransaction to create the fee transaction
|
|
417
|
-
const feeTransactions = encodeGasRefundTransaction(option)
|
|
418
|
-
logger.console.log("[trails-sdk] Fee transactions:", feeTransactions)
|
|
419
|
-
|
|
420
|
-
// Sign the txs with the Sequence Wallet
|
|
421
|
-
const signed = await wallet.signTransactions(
|
|
422
|
-
[...feeTransactions, ...sequenceTxs],
|
|
423
|
-
commons.transaction.encodeNonce(txe.space, txe.nonce),
|
|
424
|
-
)
|
|
425
|
-
// Relay the txs to sponsor them
|
|
426
|
-
const relayer = sequenceAccount.relayer(chainId)
|
|
427
|
-
const relayed = await relayer.relay(signed, quote)
|
|
428
|
-
return relayed?.hash || null
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
type TransactionBundle = commons.transaction.TransactionBundle
|
|
432
|
-
type SignedTransactionBundle = commons.transaction.SignedTransactionBundle
|
|
433
|
-
type IntendedTransactionBundle = commons.transaction.IntendedTransactionBundle
|
|
434
|
-
type BytesLike = `0x${string}` | Uint8Array
|
|
435
|
-
|
|
436
|
-
export class StaticSigner implements signers.SapientSigner {
|
|
437
|
-
private readonly signatureBytes: Uint8Array
|
|
438
|
-
private readonly savedSuffix: Uint8Array
|
|
439
|
-
|
|
440
|
-
constructor(
|
|
441
|
-
private readonly address: string,
|
|
442
|
-
readonly _signature: string,
|
|
443
|
-
) {
|
|
444
|
-
const raw = hexToBytes(this._signature as `0x${string}`)
|
|
445
|
-
|
|
446
|
-
// Separate last byte as suffix
|
|
447
|
-
this.savedSuffix = raw.slice(-1)
|
|
448
|
-
this.signatureBytes = raw.slice(0, -1)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
async buildDeployTransaction(): Promise<TransactionBundle | undefined> {
|
|
452
|
-
return undefined
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
async predecorateSignedTransactions(): Promise<SignedTransactionBundle[]> {
|
|
456
|
-
return []
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
async decorateTransactions(
|
|
460
|
-
og: IntendedTransactionBundle,
|
|
461
|
-
): Promise<IntendedTransactionBundle> {
|
|
462
|
-
return og
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
async sign(): Promise<BytesLike> {
|
|
466
|
-
return this.signatureBytes
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
notifyStatusChange(): void {}
|
|
470
|
-
|
|
471
|
-
suffix(): BytesLike {
|
|
472
|
-
return this.savedSuffix
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
async getAddress() {
|
|
476
|
-
return this.address
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Import the encodeGasRefundTransaction function
|
|
481
|
-
function encodeGasRefundTransaction(option?: any): FlatTransaction[] {
|
|
482
|
-
if (!option) return []
|
|
483
|
-
|
|
484
|
-
const value = BigInt(option.value)
|
|
485
|
-
|
|
486
|
-
switch (option.token.type) {
|
|
487
|
-
case "UNKNOWN":
|
|
488
|
-
return [
|
|
489
|
-
{
|
|
490
|
-
delegateCall: false,
|
|
491
|
-
revertOnError: true,
|
|
492
|
-
gasLimit: option.gasLimit,
|
|
493
|
-
to: option.to,
|
|
494
|
-
value: value.toString(),
|
|
495
|
-
data: "0x",
|
|
496
|
-
},
|
|
497
|
-
]
|
|
498
|
-
|
|
499
|
-
case "ERC20_TOKEN": {
|
|
500
|
-
if (!option.token.contractAddress) {
|
|
501
|
-
throw new Error(`No contract address for ERC-20 fee option`)
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
const [transfer] = Abi.from([
|
|
505
|
-
{
|
|
506
|
-
inputs: [{ type: "address" }, { type: "uint256" }],
|
|
507
|
-
name: "transfer",
|
|
508
|
-
outputs: [{ type: "bool" }],
|
|
509
|
-
stateMutability: "nonpayable",
|
|
510
|
-
type: "function",
|
|
511
|
-
},
|
|
512
|
-
])
|
|
513
|
-
|
|
514
|
-
return [
|
|
515
|
-
{
|
|
516
|
-
delegateCall: false,
|
|
517
|
-
revertOnError: true,
|
|
518
|
-
gasLimit: option.gasLimit,
|
|
519
|
-
to: option.token.contractAddress,
|
|
520
|
-
value: "0",
|
|
521
|
-
data: AbiFunction.encodeData(transfer, [
|
|
522
|
-
option.to as `0x${string}`,
|
|
523
|
-
value,
|
|
524
|
-
]),
|
|
525
|
-
},
|
|
526
|
-
]
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
default:
|
|
530
|
-
throw new Error(`Unhandled fee token type ${option.token.type}`)
|
|
531
|
-
}
|
|
532
|
-
}
|