@lifi/sdk 3.6.1 → 3.6.2-beta.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/package.json +3 -3
- package/src/_cjs/core/BaseStepExecutor.js +13 -38
- package/src/_cjs/core/BaseStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +329 -359
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +18 -9
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/checkPermitSupport.js +2 -2
- package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signPermit2Message.js +27 -26
- package/src/_cjs/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/typeguards.js +5 -2
- package/src/_cjs/core/EVM/typeguards.js.map +1 -1
- package/src/_cjs/core/EVM/types.js.map +1 -1
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js +8 -33
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +97 -112
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/StatusManager.js +100 -135
- package/src/_cjs/core/StatusManager.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js +136 -151
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_cjs/core/prepareRestart.js +7 -1
- package/src/_cjs/core/prepareRestart.js.map +1 -1
- package/src/_cjs/errors/SDKError.js +5 -30
- package/src/_cjs/errors/SDKError.js.map +1 -1
- package/src/_cjs/errors/baseError.js +2 -12
- package/src/_cjs/errors/baseError.js.map +1 -1
- package/src/_cjs/errors/httpError.js +6 -36
- package/src/_cjs/errors/httpError.js.map +1 -1
- package/src/_cjs/index.js +3 -2
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +2 -4
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/utils/withDedupe.js +1 -6
- package/src/_cjs/utils/withDedupe.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/core/BaseStepExecutor.js +13 -38
- package/src/_esm/core/BaseStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +367 -397
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +18 -9
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/checkPermitSupport.js +2 -2
- package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_esm/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_esm/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_esm/core/EVM/permits/signPermit2Message.js +29 -28
- package/src/_esm/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_esm/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_esm/core/EVM/typeguards.js +4 -2
- package/src/_esm/core/EVM/typeguards.js.map +1 -1
- package/src/_esm/core/EVM/types.js.map +1 -1
- package/src/_esm/core/Solana/KeypairWalletAdapter.js +12 -37
- package/src/_esm/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +105 -120
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/StatusManager.js +129 -164
- package/src/_esm/core/StatusManager.js.map +1 -1
- package/src/_esm/core/UTXO/UTXOStepExecutor.js +144 -159
- package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_esm/core/prepareRestart.js +10 -1
- package/src/_esm/core/prepareRestart.js.map +1 -1
- package/src/_esm/errors/SDKError.js +5 -30
- package/src/_esm/errors/SDKError.js.map +1 -1
- package/src/_esm/errors/baseError.js +2 -12
- package/src/_esm/errors/baseError.js.map +1 -1
- package/src/_esm/errors/httpError.js +6 -36
- package/src/_esm/errors/httpError.js.map +1 -1
- package/src/_esm/index.js +1 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +2 -4
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/utils/withDedupe.js +1 -6
- package/src/_esm/utils/withDedupe.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/checkAllowance.d.ts +2 -3
- package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts +4 -4
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/getNativePermit.d.ts +1 -2
- package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts +2 -11
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts +2 -2
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/types.d.ts +3 -9
- package/src/_types/core/EVM/permits/types.d.ts.map +1 -1
- package/src/_types/core/EVM/typeguards.d.ts +6 -2
- package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
- package/src/_types/core/EVM/types.d.ts +2 -5
- package/src/_types/core/EVM/types.d.ts.map +1 -1
- package/src/_types/core/prepareRestart.d.ts.map +1 -1
- package/src/_types/index.d.ts +1 -1
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +2 -2
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +39 -44
- package/src/core/EVM/checkAllowance.ts +28 -19
- package/src/core/EVM/checkPermitSupport.ts +14 -2
- package/src/core/EVM/permits/allowanceTransfer.ts +14 -10
- package/src/core/EVM/permits/getNativePermit.ts +13 -11
- package/src/core/EVM/permits/signPermit2Message.ts +43 -63
- package/src/core/EVM/permits/signatureTransfer.ts +10 -10
- package/src/core/EVM/permits/types.ts +3 -16
- package/src/core/EVM/typeguards.ts +14 -4
- package/src/core/EVM/types.ts +2 -6
- package/src/core/prepareRestart.ts +14 -2
- package/src/index.ts +1 -1
- package/src/services/api.ts +3 -6
- package/src/version.ts +1 -1
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js +0 -20
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_cjs/core/EVM/permits/utils.js +0 -31
- package/src/_cjs/core/EVM/permits/utils.js.map +0 -1
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js +0 -16
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_esm/core/EVM/permits/utils.js +0 -26
- package/src/_esm/core/EVM/permits/utils.js.map +0 -1
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts +0 -4
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts.map +0 -1
- package/src/_types/core/EVM/permits/utils.d.ts +0 -6
- package/src/_types/core/EVM/permits/utils.d.ts.map +0 -1
- package/src/core/EVM/permits/signNativePermitMessage.ts +0 -27
- package/src/core/EVM/permits/utils.ts +0 -40
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import type { ExtendedChain, LiFiStep } from '@lifi/types'
|
|
1
|
+
import type { ExtendedChain, LiFiStep, SignedTypedData } from '@lifi/types'
|
|
2
2
|
import type { Address, Client, Hash } from 'viem'
|
|
3
|
+
import { signTypedData } from 'viem/actions'
|
|
4
|
+
import { getAction } from 'viem/utils'
|
|
3
5
|
import { MaxUint256 } from '../../constants.js'
|
|
4
6
|
import type { StatusManager } from '../StatusManager.js'
|
|
5
7
|
import type { ExecutionOptions, Process, ProcessType } from '../types.js'
|
|
6
8
|
import { getAllowance } from './getAllowance.js'
|
|
7
9
|
import { parseEVMErrors } from './parseEVMErrors.js'
|
|
8
10
|
import { getNativePermit } from './permits/getNativePermit.js'
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
NativePermitData,
|
|
12
|
-
NativePermitSignature,
|
|
13
|
-
} from './permits/types.js'
|
|
14
|
-
import { prettifyNativePermitData } from './permits/utils.js'
|
|
11
|
+
import type { NativePermitData } from './permits/types.js'
|
|
15
12
|
import { setAllowance } from './setAllowance.js'
|
|
16
13
|
import { isRelayerStep } from './typeguards.js'
|
|
17
14
|
import type { Call } from './types.js'
|
|
@@ -38,7 +35,7 @@ export type AllowanceResult =
|
|
|
38
35
|
}
|
|
39
36
|
| {
|
|
40
37
|
status: 'NATIVE_PERMIT'
|
|
41
|
-
data:
|
|
38
|
+
data: SignedTypedData
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
export const checkAllowance = async ({
|
|
@@ -78,6 +75,7 @@ export const checkAllowance = async ({
|
|
|
78
75
|
const spenderAddress = permit2Supported
|
|
79
76
|
? chain.permit2
|
|
80
77
|
: step.estimate.approvalAddress
|
|
78
|
+
|
|
81
79
|
const fromAmount = BigInt(step.action.fromAmount)
|
|
82
80
|
|
|
83
81
|
const approved = await getAllowance(
|
|
@@ -97,17 +95,15 @@ export const checkAllowance = async ({
|
|
|
97
95
|
|
|
98
96
|
let nativePermitData: NativePermitData | undefined
|
|
99
97
|
if (isRelayerTransaction) {
|
|
100
|
-
|
|
101
|
-
(p) => p.
|
|
102
|
-
)
|
|
103
|
-
if (permitData) {
|
|
104
|
-
nativePermitData = prettifyNativePermitData(permitData)
|
|
105
|
-
}
|
|
98
|
+
nativePermitData = step.typedData.find(
|
|
99
|
+
(p) => p.primaryType === 'Permit'
|
|
100
|
+
) as NativePermitData
|
|
106
101
|
} else {
|
|
107
102
|
nativePermitData = await getNativePermit(
|
|
108
103
|
client,
|
|
109
|
-
chain,
|
|
104
|
+
chain.id,
|
|
110
105
|
step.action.fromToken.address as Address,
|
|
106
|
+
chain.permit2Proxy as Address,
|
|
111
107
|
fromAmount
|
|
112
108
|
)
|
|
113
109
|
}
|
|
@@ -123,12 +119,25 @@ export const checkAllowance = async ({
|
|
|
123
119
|
!!nativePermitData && !!chain.permit2Proxy && !batchingSupported
|
|
124
120
|
|
|
125
121
|
if (nativePermitSupported && nativePermitData) {
|
|
126
|
-
const
|
|
122
|
+
const signature = await getAction(
|
|
127
123
|
client,
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
signTypedData,
|
|
125
|
+
'signTypedData'
|
|
126
|
+
)({
|
|
127
|
+
account: client.account!,
|
|
128
|
+
domain: nativePermitData.domain,
|
|
129
|
+
types: nativePermitData.types,
|
|
130
|
+
primaryType: 'Permit',
|
|
131
|
+
message: nativePermitData.message,
|
|
132
|
+
})
|
|
130
133
|
statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
|
|
131
|
-
return {
|
|
134
|
+
return {
|
|
135
|
+
status: 'NATIVE_PERMIT',
|
|
136
|
+
data: {
|
|
137
|
+
...nativePermitData,
|
|
138
|
+
signature,
|
|
139
|
+
},
|
|
140
|
+
}
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
// Set new allowance
|
|
@@ -49,10 +49,22 @@ export const checkPermitSupport = async ({
|
|
|
49
49
|
let nativePermit: NativePermitData | undefined
|
|
50
50
|
// Try with wallet client first, fallback to public client
|
|
51
51
|
try {
|
|
52
|
-
nativePermit = await getNativePermit(
|
|
52
|
+
nativePermit = await getNativePermit(
|
|
53
|
+
client,
|
|
54
|
+
chain.id,
|
|
55
|
+
tokenAddress,
|
|
56
|
+
chain.permit2Proxy as Address,
|
|
57
|
+
amount
|
|
58
|
+
)
|
|
53
59
|
} catch {
|
|
54
60
|
client = await getPublicClient(chain.id)
|
|
55
|
-
nativePermit = await getNativePermit(
|
|
61
|
+
nativePermit = await getNativePermit(
|
|
62
|
+
client,
|
|
63
|
+
chain.id,
|
|
64
|
+
tokenAddress,
|
|
65
|
+
chain.permit2Proxy as Address,
|
|
66
|
+
amount
|
|
67
|
+
)
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
let permit2Allowance: bigint | undefined
|
|
@@ -35,13 +35,13 @@ export interface PermitBatch {
|
|
|
35
35
|
export type PermitSingleData = {
|
|
36
36
|
domain: TypedDataDomain
|
|
37
37
|
types: TypedData
|
|
38
|
-
|
|
38
|
+
message: PermitSingle
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export type PermitBatchData = {
|
|
42
42
|
domain: TypedDataDomain
|
|
43
43
|
types: TypedData
|
|
44
|
-
|
|
44
|
+
message: PermitBatch
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const PERMIT_DETAILS = [
|
|
@@ -85,7 +85,7 @@ export function getPermitSingleData(
|
|
|
85
85
|
|
|
86
86
|
return {
|
|
87
87
|
domain,
|
|
88
|
-
|
|
88
|
+
message: permit,
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -101,7 +101,7 @@ export function getPermitBatchData(
|
|
|
101
101
|
|
|
102
102
|
return {
|
|
103
103
|
domain,
|
|
104
|
-
|
|
104
|
+
message: permit,
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -118,14 +118,14 @@ export function getPermitData(
|
|
|
118
118
|
return {
|
|
119
119
|
domain,
|
|
120
120
|
types: PERMIT_TYPES,
|
|
121
|
-
|
|
121
|
+
message: permit,
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
permit.details.forEach(validatePermitDetails)
|
|
125
125
|
return {
|
|
126
126
|
domain,
|
|
127
127
|
types: PERMIT_BATCH_TYPES,
|
|
128
|
-
|
|
128
|
+
message: permit,
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -135,7 +135,7 @@ export function hash(
|
|
|
135
135
|
chainId: number
|
|
136
136
|
): string {
|
|
137
137
|
if (isPermit(permit)) {
|
|
138
|
-
const { domain,
|
|
138
|
+
const { domain, message } = getPermitSingleData(
|
|
139
139
|
permit,
|
|
140
140
|
permit2Address,
|
|
141
141
|
chainId
|
|
@@ -145,16 +145,20 @@ export function hash(
|
|
|
145
145
|
domain,
|
|
146
146
|
types: PERMIT_TYPES,
|
|
147
147
|
primaryType: 'PermitSingle',
|
|
148
|
-
message:
|
|
148
|
+
message: message,
|
|
149
149
|
})
|
|
150
150
|
}
|
|
151
|
-
const { domain,
|
|
151
|
+
const { domain, message } = getPermitBatchData(
|
|
152
|
+
permit,
|
|
153
|
+
permit2Address,
|
|
154
|
+
chainId
|
|
155
|
+
)
|
|
152
156
|
|
|
153
157
|
return hashTypedData({
|
|
154
158
|
domain,
|
|
155
159
|
types: PERMIT_BATCH_TYPES,
|
|
156
160
|
primaryType: 'PermitBatch',
|
|
157
|
-
message:
|
|
161
|
+
message: message,
|
|
158
162
|
})
|
|
159
163
|
}
|
|
160
164
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ExtendedChain } from '@lifi/types'
|
|
2
1
|
import {
|
|
3
2
|
encodeAbiParameters,
|
|
4
3
|
keccak256,
|
|
@@ -145,12 +144,13 @@ function validateDomainSeparator({
|
|
|
145
144
|
*/
|
|
146
145
|
export const getNativePermit = async (
|
|
147
146
|
client: Client,
|
|
148
|
-
|
|
147
|
+
chainId: number,
|
|
149
148
|
tokenAddress: Address,
|
|
149
|
+
spenderAddress: Address,
|
|
150
150
|
amount: bigint
|
|
151
151
|
): Promise<NativePermitData | undefined> => {
|
|
152
152
|
try {
|
|
153
|
-
const multicallAddress = await getMulticallAddress(
|
|
153
|
+
const multicallAddress = await getMulticallAddress(chainId)
|
|
154
154
|
|
|
155
155
|
const contractCalls = [
|
|
156
156
|
{
|
|
@@ -197,7 +197,7 @@ export const getNativePermit = async (
|
|
|
197
197
|
const { isValid, domain } = validateDomainSeparator({
|
|
198
198
|
name: nameResult.result,
|
|
199
199
|
version: versionResult.result ?? '1',
|
|
200
|
-
chainId: BigInt(
|
|
200
|
+
chainId: BigInt(chainId),
|
|
201
201
|
verifyingContract: tokenAddress,
|
|
202
202
|
domainSeparator: domainSeparatorResult.result,
|
|
203
203
|
})
|
|
@@ -206,18 +206,19 @@ export const getNativePermit = async (
|
|
|
206
206
|
return undefined
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
const
|
|
209
|
+
const message = {
|
|
210
210
|
owner: client.account!.address,
|
|
211
|
-
spender:
|
|
211
|
+
spender: spenderAddress,
|
|
212
212
|
value: amount,
|
|
213
213
|
nonce: noncesResult.result,
|
|
214
214
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 30 * 60), // 30 minutes
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
return {
|
|
218
|
+
primaryType: 'Permit',
|
|
218
219
|
domain,
|
|
219
220
|
types: eip2612Types,
|
|
220
|
-
|
|
221
|
+
message,
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
|
|
@@ -245,7 +246,7 @@ export const getNativePermit = async (
|
|
|
245
246
|
const { isValid, domain } = validateDomainSeparator({
|
|
246
247
|
name,
|
|
247
248
|
version,
|
|
248
|
-
chainId: BigInt(
|
|
249
|
+
chainId: BigInt(chainId),
|
|
249
250
|
verifyingContract: tokenAddress,
|
|
250
251
|
domainSeparator: domainSeparatorResult.value,
|
|
251
252
|
})
|
|
@@ -254,18 +255,19 @@ export const getNativePermit = async (
|
|
|
254
255
|
return undefined
|
|
255
256
|
}
|
|
256
257
|
|
|
257
|
-
const
|
|
258
|
+
const message = {
|
|
258
259
|
owner: client.account!.address,
|
|
259
|
-
spender:
|
|
260
|
+
spender: spenderAddress,
|
|
260
261
|
value: amount,
|
|
261
262
|
nonce: noncesResult.value,
|
|
262
263
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 30 * 60), // 30 minutes
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
return {
|
|
267
|
+
primaryType: 'Permit',
|
|
266
268
|
domain,
|
|
267
269
|
types: eip2612Types,
|
|
268
|
-
|
|
270
|
+
message,
|
|
269
271
|
}
|
|
270
272
|
} catch {
|
|
271
273
|
return undefined
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import type { ExtendedChain } from '@lifi/types'
|
|
1
|
+
import type { ExtendedChain, SignedTypedData } from '@lifi/types'
|
|
2
2
|
import type { Address, Client, Hex } from 'viem'
|
|
3
3
|
import { keccak256 } from 'viem'
|
|
4
4
|
import { signTypedData } from 'viem/actions'
|
|
5
5
|
import { getAction } from 'viem/utils'
|
|
6
6
|
import { getPermitTransferFromValues } from './getPermitTransferFromValues.js'
|
|
7
|
-
import {
|
|
8
|
-
type PermitBatchTransferFrom,
|
|
9
|
-
type PermitBatchTransferFromData,
|
|
10
|
-
type PermitTransferFrom,
|
|
11
|
-
type PermitTransferFromData,
|
|
12
|
-
getPermitData,
|
|
13
|
-
} from './signatureTransfer.js'
|
|
14
|
-
import type { Permit2Signature } from './types.js'
|
|
7
|
+
import { getPermitData } from './signatureTransfer.js'
|
|
15
8
|
|
|
16
9
|
export interface SignPermit2MessageParams {
|
|
17
10
|
client: Client
|
|
@@ -22,59 +15,45 @@ export interface SignPermit2MessageParams {
|
|
|
22
15
|
witness?: boolean
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
export interface SignPermit2SingleParams extends SignPermit2MessageParams {
|
|
26
|
-
permitData?: PermitTransferFromData
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SignPermit2BatchParams extends SignPermit2MessageParams {
|
|
30
|
-
permitData?: PermitBatchTransferFromData
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function signPermit2Message(
|
|
34
|
-
params: SignPermit2SingleParams
|
|
35
|
-
): Promise<Permit2Signature<PermitTransferFrom>>
|
|
36
|
-
export function signPermit2Message(
|
|
37
|
-
params: SignPermit2BatchParams
|
|
38
|
-
): Promise<Permit2Signature<PermitBatchTransferFrom>>
|
|
39
18
|
export async function signPermit2Message(
|
|
40
|
-
params:
|
|
41
|
-
): Promise<
|
|
42
|
-
const { client, chain, tokenAddress, amount, data,
|
|
43
|
-
params
|
|
19
|
+
params: SignPermit2MessageParams
|
|
20
|
+
): Promise<SignedTypedData> {
|
|
21
|
+
const { client, chain, tokenAddress, amount, data, witness } = params
|
|
44
22
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
amount
|
|
52
|
-
)
|
|
23
|
+
const permitTransferFrom = await getPermitTransferFromValues(
|
|
24
|
+
client,
|
|
25
|
+
chain,
|
|
26
|
+
tokenAddress,
|
|
27
|
+
amount
|
|
28
|
+
)
|
|
53
29
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
// Create witness data for the LI.FI call
|
|
31
|
+
const _witness = witness
|
|
32
|
+
? {
|
|
33
|
+
witness: {
|
|
34
|
+
diamondAddress: chain.diamondAddress as Address,
|
|
35
|
+
diamondCalldataHash: keccak256(data),
|
|
36
|
+
},
|
|
37
|
+
witnessTypeName: 'LiFiCall',
|
|
38
|
+
witnessType: {
|
|
39
|
+
LiFiCall: [
|
|
40
|
+
{ name: 'diamondAddress', type: 'address' },
|
|
41
|
+
{ name: 'diamondCalldataHash', type: 'bytes32' },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
: undefined
|
|
70
46
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
47
|
+
const permitData = getPermitData(
|
|
48
|
+
permitTransferFrom,
|
|
49
|
+
chain.permit2 as Address,
|
|
50
|
+
chain.id,
|
|
51
|
+
_witness
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const primaryType = witness
|
|
55
|
+
? 'PermitWitnessTransferFrom'
|
|
56
|
+
: 'PermitTransferFrom'
|
|
78
57
|
|
|
79
58
|
const signature = await getAction(
|
|
80
59
|
client,
|
|
@@ -82,14 +61,15 @@ export async function signPermit2Message(
|
|
|
82
61
|
'signTypedData'
|
|
83
62
|
)({
|
|
84
63
|
account: client.account!,
|
|
85
|
-
primaryType
|
|
86
|
-
domain:
|
|
87
|
-
types:
|
|
88
|
-
message:
|
|
64
|
+
primaryType,
|
|
65
|
+
domain: permitData.domain,
|
|
66
|
+
types: permitData.types,
|
|
67
|
+
message: permitData.message,
|
|
89
68
|
})
|
|
90
69
|
|
|
91
70
|
return {
|
|
71
|
+
...permitData,
|
|
72
|
+
primaryType,
|
|
92
73
|
signature,
|
|
93
|
-
values: _permitData.values,
|
|
94
74
|
}
|
|
95
75
|
}
|
|
@@ -36,13 +36,13 @@ export type PermitBatchTransferFrom = {
|
|
|
36
36
|
export type PermitTransferFromData = {
|
|
37
37
|
domain: TypedDataDomain
|
|
38
38
|
types: TypedData
|
|
39
|
-
|
|
39
|
+
message: PermitTransferFrom
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export type PermitBatchTransferFromData = {
|
|
43
43
|
domain: TypedDataDomain
|
|
44
44
|
types: TypedData
|
|
45
|
-
|
|
45
|
+
message: PermitBatchTransferFrom
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const TOKEN_PERMISSIONS = [
|
|
@@ -103,14 +103,14 @@ export function getPermitTransferData(
|
|
|
103
103
|
} as const)
|
|
104
104
|
: PERMIT_TRANSFER_FROM_TYPES
|
|
105
105
|
|
|
106
|
-
const
|
|
106
|
+
const message = witness
|
|
107
107
|
? Object.assign(permit, { witness: witness.witness })
|
|
108
108
|
: permit
|
|
109
109
|
|
|
110
110
|
return {
|
|
111
111
|
domain,
|
|
112
112
|
types,
|
|
113
|
-
|
|
113
|
+
message,
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -141,14 +141,14 @@ export function getPermitBatchTransferData(
|
|
|
141
141
|
}
|
|
142
142
|
: PERMIT_BATCH_TRANSFER_FROM_TYPES
|
|
143
143
|
|
|
144
|
-
const
|
|
144
|
+
const message = witness
|
|
145
145
|
? Object.assign(permit, { witness: witness.witness })
|
|
146
146
|
: permit
|
|
147
147
|
|
|
148
148
|
return {
|
|
149
149
|
domain,
|
|
150
150
|
types,
|
|
151
|
-
|
|
151
|
+
message,
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -185,7 +185,7 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
185
185
|
witness?: Witness
|
|
186
186
|
) {
|
|
187
187
|
if (isPermitTransferFrom(permit)) {
|
|
188
|
-
const { domain, types,
|
|
188
|
+
const { domain, types, message } = getPermitTransferData(
|
|
189
189
|
permit,
|
|
190
190
|
permit2Address,
|
|
191
191
|
chainId,
|
|
@@ -197,11 +197,11 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
197
197
|
types,
|
|
198
198
|
primaryType: witness ? 'PermitWitnessTransferFrom' : 'PermitTransferFrom',
|
|
199
199
|
message: {
|
|
200
|
-
...
|
|
200
|
+
...message,
|
|
201
201
|
},
|
|
202
202
|
})
|
|
203
203
|
}
|
|
204
|
-
const { domain, types,
|
|
204
|
+
const { domain, types, message } = getPermitBatchTransferData(
|
|
205
205
|
permit,
|
|
206
206
|
permit2Address,
|
|
207
207
|
chainId,
|
|
@@ -214,7 +214,7 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
214
214
|
primaryType: witness
|
|
215
215
|
? 'PermitBatchWitnessTransferFrom'
|
|
216
216
|
: 'PermitBatchTransferFrom',
|
|
217
|
-
message: { ...
|
|
217
|
+
message: { ...message },
|
|
218
218
|
})
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { Address, Hash, TypedData, TypedDataDomain } from 'viem'
|
|
2
|
-
import type {
|
|
3
|
-
PermitBatchTransferFrom,
|
|
4
|
-
PermitTransferFrom,
|
|
5
|
-
} from './signatureTransfer.js'
|
|
6
2
|
|
|
7
3
|
export type PermitSignature = {
|
|
8
4
|
signature: Hash
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
export type
|
|
7
|
+
export type NativePermitMessage = {
|
|
12
8
|
owner: Address
|
|
13
9
|
spender: Address
|
|
14
10
|
nonce: bigint
|
|
@@ -17,17 +13,8 @@ export type NativePermitValues = {
|
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
export type NativePermitData = {
|
|
16
|
+
primaryType: 'Permit'
|
|
20
17
|
domain: TypedDataDomain
|
|
21
18
|
types: TypedData
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type NativePermitSignature = PermitSignature & {
|
|
26
|
-
values: NativePermitValues
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type Permit2Signature<
|
|
30
|
-
T extends PermitTransferFrom | PermitBatchTransferFrom,
|
|
31
|
-
> = PermitSignature & {
|
|
32
|
-
values: T
|
|
19
|
+
message: NativePermitMessage
|
|
33
20
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import type { LiFiStep } from '@lifi/types'
|
|
2
2
|
import type { LiFiStepExtended } from '../types.js'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
type RelayerStep = (LiFiStepExtended | LiFiStep) & {
|
|
5
|
+
typedData: NonNullable<(LiFiStepExtended | LiFiStep)['typedData']>
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
export function isRelayerStep(
|
|
6
9
|
step: LiFiStepExtended | LiFiStep
|
|
7
|
-
): step is
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
): step is RelayerStep {
|
|
11
|
+
return !!step.typedData && step.typedData.length > 0
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isGaslessStep(
|
|
15
|
+
step: LiFiStepExtended | LiFiStep
|
|
16
|
+
): step is RelayerStep {
|
|
17
|
+
return !!step.typedData?.find(
|
|
18
|
+
(p) => p.primaryType === 'PermitWitnessTransferFrom'
|
|
19
|
+
)
|
|
10
20
|
}
|
package/src/core/EVM/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type BaseToken, ChainType
|
|
1
|
+
import { type BaseToken, ChainType } from '@lifi/types'
|
|
2
2
|
import type { Address, Client, FallbackTransportConfig, Hex } from 'viem'
|
|
3
|
-
import type {
|
|
3
|
+
import type { SwitchChainHook } from '../types.js'
|
|
4
4
|
import type { SDKProvider } from '../types.js'
|
|
5
5
|
|
|
6
6
|
export interface EVMProviderOptions {
|
|
@@ -52,10 +52,6 @@ export interface RevokeApprovalRequest {
|
|
|
52
52
|
spenderAddress: string
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export interface EVMPermitStep extends LiFiStepExtended {
|
|
56
|
-
permits: Permit[]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
55
|
export type Call = {
|
|
60
56
|
to: Address
|
|
61
57
|
data?: Hex
|
|
@@ -4,9 +4,21 @@ export const prepareRestart = async (route: RouteExtended) => {
|
|
|
4
4
|
for (let index = 0; index < route.steps.length; index++) {
|
|
5
5
|
const step = route.steps[index]
|
|
6
6
|
if (step.execution) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// Find the index of the last process that has tx hash
|
|
8
|
+
const lastValidIndex = step.execution.process.findLastIndex(
|
|
9
|
+
(process) => !!process.txHash
|
|
9
10
|
)
|
|
11
|
+
|
|
12
|
+
// Keep all processes up to the one with tx hash
|
|
13
|
+
if (lastValidIndex >= 0) {
|
|
14
|
+
step.execution.process = step.execution.process.slice(
|
|
15
|
+
0,
|
|
16
|
+
lastValidIndex + 1
|
|
17
|
+
)
|
|
18
|
+
} else {
|
|
19
|
+
// If no tx hash exists, reset the process array
|
|
20
|
+
step.execution.process = []
|
|
21
|
+
}
|
|
10
22
|
}
|
|
11
23
|
step.transactionRequest = undefined
|
|
12
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ export {
|
|
|
14
14
|
export { isEVM } from './core/EVM/types.js'
|
|
15
15
|
export { isBatchingSupported } from './core/EVM/isBatchingSupported.js'
|
|
16
16
|
export { isExtendedChain, convertExtendedChain } from './core/EVM/utils.js'
|
|
17
|
-
export { isRelayerStep } from './core/EVM/typeguards.js'
|
|
17
|
+
export { isRelayerStep, isGaslessStep } from './core/EVM/typeguards.js'
|
|
18
18
|
export type {
|
|
19
19
|
EVMProvider,
|
|
20
20
|
EVMProviderOptions,
|
package/src/services/api.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
type RelayStatusResponse,
|
|
20
20
|
type RelayStatusResponseData,
|
|
21
21
|
type RelayerQuoteResponse,
|
|
22
|
-
type RelayerQuoteResponseData,
|
|
23
22
|
type RequestOptions,
|
|
24
23
|
type RoutesRequest,
|
|
25
24
|
type RoutesResponse,
|
|
@@ -262,7 +261,7 @@ export const getStatus = async (
|
|
|
262
261
|
export const getRelayerQuote = async (
|
|
263
262
|
params: QuoteRequest,
|
|
264
263
|
options?: RequestOptions
|
|
265
|
-
): Promise<
|
|
264
|
+
): Promise<LiFiStep> => {
|
|
266
265
|
const requiredParameters: Array<keyof QuoteRequest> = [
|
|
267
266
|
'fromChain',
|
|
268
267
|
'fromToken',
|
|
@@ -332,10 +331,8 @@ export const relayTransaction = async (
|
|
|
332
331
|
options?: RequestOptions
|
|
333
332
|
): Promise<RelayResponseData> => {
|
|
334
333
|
const requiredParameters: Array<keyof RelayRequest> = [
|
|
335
|
-
'
|
|
336
|
-
'
|
|
337
|
-
'permits',
|
|
338
|
-
'callData',
|
|
334
|
+
'typedData',
|
|
335
|
+
'transactionRequest',
|
|
339
336
|
]
|
|
340
337
|
|
|
341
338
|
for (const requiredParameter of requiredParameters) {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '3.6.
|
|
2
|
+
export const version = '3.6.2-beta.0'
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signNativePermitMessage = void 0;
|
|
4
|
-
const actions_1 = require("viem/actions");
|
|
5
|
-
const utils_1 = require("viem/utils");
|
|
6
|
-
const signNativePermitMessage = async (client, permitData) => {
|
|
7
|
-
const signature = await (0, utils_1.getAction)(client, actions_1.signTypedData, 'signTypedData')({
|
|
8
|
-
account: client.account,
|
|
9
|
-
domain: permitData.domain,
|
|
10
|
-
types: permitData.types,
|
|
11
|
-
primaryType: 'Permit',
|
|
12
|
-
message: permitData.values,
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
signature,
|
|
16
|
-
values: permitData.values,
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
exports.signNativePermitMessage = signNativePermitMessage;
|
|
20
|
-
//# sourceMappingURL=signNativePermitMessage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signNativePermitMessage.js","sourceRoot":"","sources":["../../../../core/EVM/permits/signNativePermitMessage.ts"],"names":[],"mappings":";;;AAEA,0CAA4C;AAC5C,sCAAsC;AAG/B,MAAM,uBAAuB,GAAG,KAAK,EAC1C,MAAc,EACd,UAA4B,EACI,EAAE;IAClC,MAAM,SAAS,GAAG,MAAM,IAAA,iBAAS,EAC/B,MAAM,EACN,uBAAa,EACb,eAAe,CAChB,CAAC;QACA,OAAO,EAAE,MAAM,CAAC,OAAQ;QACxB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,WAAW,EAAE,QAAQ;QACrB,OAAO,EAAE,UAAU,CAAC,MAAM;KAC3B,CAAC,CAAA;IAEF,OAAO;QACL,SAAS;QACT,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAA;AACH,CAAC,CAAA;AApBY,QAAA,uBAAuB,2BAoBnC"}
|