Skip to content

Commit 5368682

Browse files
authored
added metadata for fee option token (#815)
* added metadata for fee option token * check token address + removed unused imports
1 parent 7eecab8 commit 5368682

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

packages/wallet/core/src/relayer/relayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Payload, Precondition } from '@0xsequence/wallet-primitives'
22
import { Address, Hex } from 'ox'
3-
import { GetMetaTxnReceiptReturn } from './standard/rpc/index.js'
3+
import { FeeToken, GetMetaTxnReceiptReturn } from './standard/rpc/index.js'
44

55
export interface FeeOption {
6-
token: Address.Address
6+
token: FeeToken
77
to: string
88
value: string
99
gasLimit: number

packages/wallet/core/src/relayer/standard/rpc/index.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ import {
44
MetaTxn as RpcMetaTxn,
55
FeeTokenType,
66
IntentPrecondition,
7-
GetMetaTxnReceiptReturn,
87
} from './relayer.gen.js'
98
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../../relayer.js'
109
import { Address, Hex, Bytes, AbiFunction } from 'ox'
11-
import { Constants, Payload, Precondition as PrimitivePrecondition } from '@0xsequence/wallet-primitives'
12-
import {
13-
IntentPrecondition as RpcIntentPrecondition,
14-
ETHTxnStatus,
15-
FeeOption as RpcFeeOption,
16-
FeeToken as RpcFeeToken,
17-
} from './relayer.gen.js'
10+
import { Constants, Payload } from '@0xsequence/wallet-primitives'
11+
import { ETHTxnStatus, FeeToken as RpcFeeToken } from './relayer.gen.js'
1812
import { decodePrecondition } from '../../../preconditions/index.js'
1913
import {
2014
erc20BalanceOf,
@@ -87,8 +81,16 @@ export class RpcRelayer implements Relayer {
8781
data: Bytes.toHex(data),
8882
})
8983

90-
const options = result.options.map((feeOption) => this.mapRpcFeeOptionToFeeOption(feeOption))
9184
const quote = result.quote ? ({ _tag: 'FeeQuote', _quote: result.quote } as FeeQuote) : undefined
85+
const options = result.options.map((option) => ({
86+
token: {
87+
...option.token,
88+
contractAddress: this.mapRpcFeeTokenToAddress(option.token),
89+
},
90+
to: option.to,
91+
value: option.value,
92+
gasLimit: option.gasLimit,
93+
}))
9294

9395
return { options, quote }
9496
} catch (e) {
@@ -364,15 +366,6 @@ export class RpcRelayer implements Relayer {
364366
}
365367
}
366368

367-
private mapRpcFeeOptionToFeeOption(rpcOption: RpcFeeOption): FeeOption {
368-
return {
369-
token: this.mapRpcFeeTokenToAddress(rpcOption.token),
370-
to: rpcOption.to,
371-
value: rpcOption.value,
372-
gasLimit: rpcOption.gasLimit,
373-
}
374-
}
375-
376369
private mapRpcFeeTokenToAddress(rpcToken: RpcFeeToken): Address.Address {
377370
if (rpcToken.type === FeeTokenType.ERC20_TOKEN && rpcToken.contractAddress) {
378371
return Address.from(rpcToken.contractAddress)

packages/wallet/core/src/relayer/standard/sequence.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ETHTxnStatus, IntentPrecondition, Relayer as Service } from '@0xsequence/relayer'
2-
import { Constants, Payload } from '@0xsequence/wallet-primitives'
2+
import { Payload } from '@0xsequence/wallet-primitives'
33
import { AbiFunction, Address, Bytes, Hex } from 'ox'
44
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../relayer.js'
55

@@ -32,17 +32,7 @@ export class SequenceRelayer implements Relayer {
3232
const { options, quote } = await this.service.feeOptions({ wallet, to, data })
3333

3434
return {
35-
options: options.map(({ token: { contractAddress }, to, value, gasLimit }) => {
36-
let token: Address.Address
37-
if (contractAddress) {
38-
Address.assert(contractAddress)
39-
token = contractAddress
40-
} else {
41-
token = Constants.ZeroAddress
42-
}
43-
44-
return { token, to, value, gasLimit }
45-
}),
35+
options,
4636
quote: quote ? { _tag: 'FeeQuote', _quote: quote } : undefined,
4737
}
4838
}

packages/wallet/wdk/src/sequence/transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export class Transactions implements TransactionsInterface {
434434

435435
Address.assert(to)
436436

437-
if (token === Constants.ZeroAddress) {
437+
if (token.contractAddress === Constants.ZeroAddress) {
438438
tx.envelope.payload.calls.unshift({
439439
to,
440440
value: BigInt(value),
@@ -448,7 +448,7 @@ export class Transactions implements TransactionsInterface {
448448
const [transfer] = Abi.from(['function transfer(address to, uint256 amount) returns (bool)'])
449449

450450
tx.envelope.payload.calls.unshift({
451-
to: token,
451+
to: token.contractAddress as Address.Address,
452452
value: 0n,
453453
data: AbiFunction.encodeData(transfer, [to, BigInt(value)]),
454454
gasLimit: BigInt(gasLimit),

0 commit comments

Comments
 (0)