@0xsequence/relayer 2.3.35 → 3.0.0-beta.2
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +3862 -0
- package/LICENSE +0 -17
- package/README.md +1 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/preconditions/codec.d.ts +12 -0
- package/dist/preconditions/codec.d.ts.map +1 -0
- package/dist/preconditions/codec.js +125 -0
- package/dist/preconditions/index.d.ts +4 -0
- package/dist/preconditions/index.d.ts.map +1 -0
- package/dist/preconditions/index.js +3 -0
- package/dist/preconditions/selectors.d.ts +7 -0
- package/dist/preconditions/selectors.d.ts.map +1 -0
- package/dist/preconditions/selectors.js +27 -0
- package/dist/preconditions/types.d.ts +70 -0
- package/dist/preconditions/types.d.ts.map +1 -0
- package/dist/preconditions/types.js +203 -0
- package/dist/relayer/index.d.ts +45 -0
- package/dist/relayer/index.d.ts.map +1 -0
- package/dist/relayer/index.js +3 -0
- package/dist/relayer/relayer.d.ts +26 -0
- package/dist/relayer/relayer.d.ts.map +1 -0
- package/dist/relayer/relayer.js +7 -0
- package/dist/relayer/rpc-relayer/index.d.ts +38 -0
- package/dist/relayer/rpc-relayer/index.d.ts.map +1 -0
- package/dist/relayer/rpc-relayer/index.js +375 -0
- package/dist/{declarations/src → relayer}/rpc-relayer/relayer.gen.d.ts +218 -178
- package/dist/relayer/rpc-relayer/relayer.gen.d.ts.map +1 -0
- package/dist/relayer/rpc-relayer/relayer.gen.js +1246 -0
- package/dist/relayer/standard/abi.d.ts +73 -0
- package/dist/relayer/standard/abi.d.ts.map +1 -0
- package/dist/relayer/standard/abi.js +10 -0
- package/dist/relayer/standard/eip6963.d.ts +31 -0
- package/dist/relayer/standard/eip6963.d.ts.map +1 -0
- package/dist/relayer/standard/eip6963.js +51 -0
- package/dist/relayer/standard/index.d.ts +5 -0
- package/dist/relayer/standard/index.d.ts.map +1 -0
- package/dist/relayer/standard/index.js +4 -0
- package/dist/relayer/standard/local.d.ts +60 -0
- package/dist/relayer/standard/local.d.ts.map +1 -0
- package/dist/relayer/standard/local.js +285 -0
- package/dist/relayer/standard/pk-relayer.d.ts +28 -0
- package/dist/relayer/standard/pk-relayer.d.ts.map +1 -0
- package/dist/relayer/standard/pk-relayer.js +112 -0
- package/dist/relayer/standard/sequence.d.ts +27 -0
- package/dist/relayer/standard/sequence.d.ts.map +1 -0
- package/dist/relayer/standard/sequence.js +84 -0
- package/package.json +28 -25
- package/src/index.ts +3 -111
- package/src/preconditions/codec.ts +190 -0
- package/src/preconditions/index.ts +3 -0
- package/src/preconditions/selectors.ts +38 -0
- package/src/preconditions/types.ts +201 -0
- package/src/relayer/index.ts +60 -0
- package/src/relayer/relayer.ts +37 -0
- package/src/relayer/rpc-relayer/index.ts +449 -0
- package/src/relayer/rpc-relayer/relayer.gen.ts +2268 -0
- package/src/relayer/standard/abi.ts +13 -0
- package/src/relayer/standard/eip6963.ts +74 -0
- package/src/relayer/standard/index.ts +4 -0
- package/src/relayer/standard/local.ts +353 -0
- package/src/relayer/standard/pk-relayer.ts +138 -0
- package/src/relayer/standard/sequence.ts +110 -0
- package/test/preconditions/codec.test.ts +531 -0
- package/test/preconditions/preconditions.test.ts +283 -0
- package/test/preconditions/selectors.test.ts +415 -0
- package/test/preconditions/types.test.ts +443 -0
- package/test/relayer/relayer.test.ts +355 -0
- package/tsconfig.json +10 -0
- package/dist/0xsequence-relayer.cjs.d.ts +0 -2
- package/dist/0xsequence-relayer.cjs.dev.js +0 -1626
- package/dist/0xsequence-relayer.cjs.js +0 -7
- package/dist/0xsequence-relayer.cjs.prod.js +0 -1626
- package/dist/0xsequence-relayer.esm.js +0 -1613
- package/dist/declarations/src/index.d.ts +0 -42
- package/dist/declarations/src/local-relayer.d.ts +0 -35
- package/dist/declarations/src/provider-relayer.d.ts +0 -47
- package/dist/declarations/src/rpc-relayer/index.d.ts +0 -72
- package/src/local-relayer.ts +0 -125
- package/src/provider-relayer.ts +0 -284
- package/src/rpc-relayer/index.ts +0 -380
- package/src/rpc-relayer/relayer.gen.ts +0 -1900
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const erc20BalanceOf: {
|
|
2
|
+
readonly name: "balanceOf";
|
|
3
|
+
readonly type: "function";
|
|
4
|
+
readonly stateMutability: "nonpayable";
|
|
5
|
+
readonly inputs: readonly [{
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}];
|
|
8
|
+
readonly outputs: readonly [{
|
|
9
|
+
readonly type: "uint256";
|
|
10
|
+
}];
|
|
11
|
+
};
|
|
12
|
+
export declare const erc20Allowance: {
|
|
13
|
+
readonly name: "allowance";
|
|
14
|
+
readonly type: "function";
|
|
15
|
+
readonly stateMutability: "nonpayable";
|
|
16
|
+
readonly inputs: readonly [{
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}, {
|
|
19
|
+
readonly type: "address";
|
|
20
|
+
}];
|
|
21
|
+
readonly outputs: readonly [{
|
|
22
|
+
readonly type: "uint256";
|
|
23
|
+
}];
|
|
24
|
+
};
|
|
25
|
+
export declare const erc721OwnerOf: {
|
|
26
|
+
readonly name: "ownerOf";
|
|
27
|
+
readonly type: "function";
|
|
28
|
+
readonly stateMutability: "nonpayable";
|
|
29
|
+
readonly inputs: readonly [{
|
|
30
|
+
readonly type: "uint256";
|
|
31
|
+
}];
|
|
32
|
+
readonly outputs: readonly [{
|
|
33
|
+
readonly type: "address";
|
|
34
|
+
}];
|
|
35
|
+
};
|
|
36
|
+
export declare const erc721GetApproved: {
|
|
37
|
+
readonly name: "getApproved";
|
|
38
|
+
readonly type: "function";
|
|
39
|
+
readonly stateMutability: "nonpayable";
|
|
40
|
+
readonly inputs: readonly [{
|
|
41
|
+
readonly type: "uint256";
|
|
42
|
+
}];
|
|
43
|
+
readonly outputs: readonly [{
|
|
44
|
+
readonly type: "address";
|
|
45
|
+
}];
|
|
46
|
+
};
|
|
47
|
+
export declare const erc1155BalanceOf: {
|
|
48
|
+
readonly name: "balanceOf";
|
|
49
|
+
readonly type: "function";
|
|
50
|
+
readonly stateMutability: "nonpayable";
|
|
51
|
+
readonly inputs: readonly [{
|
|
52
|
+
readonly type: "address";
|
|
53
|
+
}, {
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
}];
|
|
56
|
+
readonly outputs: readonly [{
|
|
57
|
+
readonly type: "uint256";
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
export declare const erc1155IsApprovedForAll: {
|
|
61
|
+
readonly name: "isApprovedForAll";
|
|
62
|
+
readonly type: "function";
|
|
63
|
+
readonly stateMutability: "nonpayable";
|
|
64
|
+
readonly inputs: readonly [{
|
|
65
|
+
readonly type: "address";
|
|
66
|
+
}, {
|
|
67
|
+
readonly type: "address";
|
|
68
|
+
}];
|
|
69
|
+
readonly outputs: readonly [{
|
|
70
|
+
readonly type: "bool";
|
|
71
|
+
}];
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=abi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../../src/relayer/standard/abi.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc;;;;;;;;;;CAAoE,CAAA;AAC/F,eAAO,MAAM,cAAc;;;;;;;;;;;;CAA4E,CAAA;AAGvG,eAAO,MAAM,aAAa;;;;;;;;;;CAAkE,CAAA;AAC5F,eAAO,MAAM,iBAAiB;;;;;;;;;;CAAsE,CAAA;AAGpG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;CAA4E,CAAA;AACzG,eAAO,MAAM,uBAAuB;;;;;;;;;;;;CAAgF,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AbiFunction } from 'ox';
|
|
2
|
+
// ERC20 ABI functions
|
|
3
|
+
export const erc20BalanceOf = AbiFunction.from('function balanceOf(address) returns (uint256)');
|
|
4
|
+
export const erc20Allowance = AbiFunction.from('function allowance(address,address) returns (uint256)');
|
|
5
|
+
// ERC721 ABI functions
|
|
6
|
+
export const erc721OwnerOf = AbiFunction.from('function ownerOf(uint256) returns (address)');
|
|
7
|
+
export const erc721GetApproved = AbiFunction.from('function getApproved(uint256) returns (address)');
|
|
8
|
+
// ERC1155 ABI functions
|
|
9
|
+
export const erc1155BalanceOf = AbiFunction.from('function balanceOf(address,uint256) returns (uint256)');
|
|
10
|
+
export const erc1155IsApprovedForAll = AbiFunction.from('function isApprovedForAll(address,address) returns (bool)');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EIP6963ProviderInfo, EIP6963ProviderDetail } from 'mipd';
|
|
2
|
+
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../index.js';
|
|
3
|
+
import { Address, Hex } from 'ox';
|
|
4
|
+
import { Payload } from '@0xsequence/wallet-primitives';
|
|
5
|
+
import { FeeToken, TransactionPrecondition } from '../rpc-relayer/relayer.gen.js';
|
|
6
|
+
export declare class EIP6963Relayer implements Relayer {
|
|
7
|
+
readonly kind: 'relayer';
|
|
8
|
+
readonly type = "eip6963";
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly info: EIP6963ProviderInfo;
|
|
11
|
+
private readonly relayer;
|
|
12
|
+
constructor(detail: EIP6963ProviderDetail);
|
|
13
|
+
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean>;
|
|
14
|
+
feeTokens(): Promise<{
|
|
15
|
+
isFeeRequired: boolean;
|
|
16
|
+
tokens?: FeeToken[];
|
|
17
|
+
paymentAddress?: Address.Address;
|
|
18
|
+
}>;
|
|
19
|
+
feeOptions(wallet: Address.Address, chainId: number, calls: Payload.Call[]): Promise<{
|
|
20
|
+
options: FeeOption[];
|
|
21
|
+
quote?: FeeQuote;
|
|
22
|
+
}>;
|
|
23
|
+
relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{
|
|
24
|
+
opHash: Hex.Hex;
|
|
25
|
+
}>;
|
|
26
|
+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>;
|
|
27
|
+
checkPrecondition(precondition: TransactionPrecondition): Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
export declare function getEIP6963Store(): import("mipd").Store;
|
|
30
|
+
export declare function getRelayers(): EIP6963Relayer[];
|
|
31
|
+
//# sourceMappingURL=eip6963.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip6963.d.ts","sourceRoot":"","sources":["../../../src/relayer/standard/eip6963.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAA;AAE9E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAEjF,qBAAa,cAAe,YAAW,OAAO;IAC5C,SAAgB,IAAI,EAAE,SAAS,CAAY;IAC3C,SAAgB,IAAI,aAAY;IAChC,SAAgB,EAAE,EAAE,MAAM,CAAA;IAC1B,SAAgB,IAAI,EAAE,mBAAmB,CAAA;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;gBAE1B,MAAM,EAAE,qBAAqB;IAOzC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvE,SAAS,IAAI,OAAO,CAAC;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAC,OAAO,CAAA;KAAE,CAAC;IAIvG,UAAU,CACR,MAAM,EAAE,OAAO,CAAC,OAAO,EACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,GACpB,OAAO,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC;IAIhD,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAA;KAAE,CAAC;IAI5G,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAI5D,iBAAiB,CAAC,YAAY,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;CAGjF;AAKD,wBAAgB,eAAe,yBAK9B;AAID,wBAAgB,WAAW,IAAI,cAAc,EAAE,CAW9C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createStore } from 'mipd';
|
|
2
|
+
import { EIP1193ProviderAdapter, LocalRelayer } from './local.js';
|
|
3
|
+
export class EIP6963Relayer {
|
|
4
|
+
kind = 'relayer';
|
|
5
|
+
type = 'eip6963';
|
|
6
|
+
id;
|
|
7
|
+
info;
|
|
8
|
+
relayer;
|
|
9
|
+
constructor(detail) {
|
|
10
|
+
this.info = detail.info;
|
|
11
|
+
this.id = detail.info.uuid;
|
|
12
|
+
this.relayer = new LocalRelayer(new EIP1193ProviderAdapter(detail.provider));
|
|
13
|
+
}
|
|
14
|
+
isAvailable(wallet, chainId) {
|
|
15
|
+
return this.relayer.isAvailable(wallet, chainId);
|
|
16
|
+
}
|
|
17
|
+
feeTokens() {
|
|
18
|
+
return this.relayer.feeTokens();
|
|
19
|
+
}
|
|
20
|
+
feeOptions(wallet, chainId, calls) {
|
|
21
|
+
return this.relayer.feeOptions(wallet, chainId, calls);
|
|
22
|
+
}
|
|
23
|
+
async relay(to, data, chainId, _) {
|
|
24
|
+
return this.relayer.relay(to, data, chainId);
|
|
25
|
+
}
|
|
26
|
+
status(opHash, chainId) {
|
|
27
|
+
return this.relayer.status(opHash, chainId);
|
|
28
|
+
}
|
|
29
|
+
async checkPrecondition(precondition) {
|
|
30
|
+
return this.relayer.checkPrecondition(precondition);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Global store instance
|
|
34
|
+
let store;
|
|
35
|
+
export function getEIP6963Store() {
|
|
36
|
+
if (!store) {
|
|
37
|
+
store = createStore();
|
|
38
|
+
}
|
|
39
|
+
return store;
|
|
40
|
+
}
|
|
41
|
+
let relayers = new Map();
|
|
42
|
+
export function getRelayers() {
|
|
43
|
+
const store = getEIP6963Store();
|
|
44
|
+
const providers = store.getProviders();
|
|
45
|
+
for (const detail of providers) {
|
|
46
|
+
if (!relayers.has(detail.info.uuid)) {
|
|
47
|
+
relayers.set(detail.info.uuid, new EIP6963Relayer(detail));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return Array.from(relayers.values());
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relayer/standard/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Payload } from '@0xsequence/wallet-primitives';
|
|
2
|
+
import { EIP1193Provider } from 'mipd';
|
|
3
|
+
import { Address, Hex } from 'ox';
|
|
4
|
+
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../index.js';
|
|
5
|
+
import { FeeToken, TransactionPrecondition } from '../rpc-relayer/relayer.gen.js';
|
|
6
|
+
type GenericProviderTransactionReceipt = 'success' | 'failed' | 'unknown';
|
|
7
|
+
export interface GenericProvider {
|
|
8
|
+
sendTransaction(args: {
|
|
9
|
+
to: Address.Address;
|
|
10
|
+
data: Hex.Hex;
|
|
11
|
+
}, chainId: number): Promise<string | undefined>;
|
|
12
|
+
getBalance(address: Address.Address): Promise<bigint>;
|
|
13
|
+
call(args: {
|
|
14
|
+
to: Address.Address;
|
|
15
|
+
data: Hex.Hex;
|
|
16
|
+
}): Promise<string>;
|
|
17
|
+
getTransactionReceipt(txHash: Hex.Hex, chainId: number): Promise<GenericProviderTransactionReceipt>;
|
|
18
|
+
}
|
|
19
|
+
export declare class LocalRelayer implements Relayer {
|
|
20
|
+
readonly provider: GenericProvider;
|
|
21
|
+
readonly kind: 'relayer';
|
|
22
|
+
readonly type = "local";
|
|
23
|
+
readonly id = "local";
|
|
24
|
+
constructor(provider: GenericProvider);
|
|
25
|
+
isAvailable(_wallet: Address.Address, _chainId: number): Promise<boolean>;
|
|
26
|
+
static createFromWindow(window: Window): LocalRelayer | undefined;
|
|
27
|
+
static createFromProvider(provider: EIP1193Provider): LocalRelayer;
|
|
28
|
+
feeTokens(): Promise<{
|
|
29
|
+
isFeeRequired: boolean;
|
|
30
|
+
tokens?: FeeToken[];
|
|
31
|
+
paymentAddress?: Address.Address;
|
|
32
|
+
}>;
|
|
33
|
+
feeOptions(wallet: Address.Address, chainId: number, calls: Payload.Call[]): Promise<{
|
|
34
|
+
options: FeeOption[];
|
|
35
|
+
quote?: FeeQuote;
|
|
36
|
+
}>;
|
|
37
|
+
private decodeCalls;
|
|
38
|
+
relay(to: Address.Address, data: Hex.Hex, chainId: number, quote?: FeeQuote, preconditions?: TransactionPrecondition[], checkInterval?: number): Promise<{
|
|
39
|
+
opHash: Hex.Hex;
|
|
40
|
+
}>;
|
|
41
|
+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>;
|
|
42
|
+
checkPrecondition(precondition: TransactionPrecondition): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
export declare class EIP1193ProviderAdapter implements GenericProvider {
|
|
45
|
+
private readonly provider;
|
|
46
|
+
constructor(provider: EIP1193Provider);
|
|
47
|
+
private trySwitchChain;
|
|
48
|
+
sendTransaction(args: {
|
|
49
|
+
to: Address.Address;
|
|
50
|
+
data: Hex.Hex;
|
|
51
|
+
}, chainId: number): Promise<`0x${string}` | undefined>;
|
|
52
|
+
getBalance(address: Address.Address): Promise<bigint>;
|
|
53
|
+
call(args: {
|
|
54
|
+
to: Address.Address;
|
|
55
|
+
data: Hex.Hex;
|
|
56
|
+
}): Promise<`0x${string}`>;
|
|
57
|
+
getTransactionReceipt(txHash: Hex.Hex, chainId: number): Promise<"success" | "unknown" | "failed">;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/relayer/standard/local.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Constants, Payload } from '@0xsequence/wallet-primitives';
|
|
2
|
+
import { AbiFunction, Bytes, TransactionReceipt } from 'ox';
|
|
3
|
+
import { decodePrecondition } from '../../preconditions/index.js';
|
|
4
|
+
import { erc20BalanceOf, erc20Allowance, erc721OwnerOf, erc721GetApproved, erc1155BalanceOf, erc1155IsApprovedForAll, } from './abi.js';
|
|
5
|
+
export class LocalRelayer {
|
|
6
|
+
provider;
|
|
7
|
+
kind = 'relayer';
|
|
8
|
+
type = 'local';
|
|
9
|
+
id = 'local';
|
|
10
|
+
constructor(provider) {
|
|
11
|
+
this.provider = provider;
|
|
12
|
+
}
|
|
13
|
+
isAvailable(_wallet, _chainId) {
|
|
14
|
+
return Promise.resolve(true);
|
|
15
|
+
}
|
|
16
|
+
static createFromWindow(window) {
|
|
17
|
+
const eth = window.ethereum;
|
|
18
|
+
if (!eth) {
|
|
19
|
+
console.warn('Window.ethereum not found, skipping local relayer');
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return new LocalRelayer(new EIP1193ProviderAdapter(eth));
|
|
23
|
+
}
|
|
24
|
+
static createFromProvider(provider) {
|
|
25
|
+
return new LocalRelayer(new EIP1193ProviderAdapter(provider));
|
|
26
|
+
}
|
|
27
|
+
feeTokens() {
|
|
28
|
+
return Promise.resolve({
|
|
29
|
+
isFeeRequired: false,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
feeOptions(wallet, chainId, calls) {
|
|
33
|
+
return Promise.resolve({ options: [] });
|
|
34
|
+
}
|
|
35
|
+
decodeCalls(data) {
|
|
36
|
+
const executeSelector = AbiFunction.getSelector(Constants.EXECUTE);
|
|
37
|
+
let packedPayload;
|
|
38
|
+
if (data.startsWith(executeSelector)) {
|
|
39
|
+
const decode = AbiFunction.decodeData(Constants.EXECUTE, data);
|
|
40
|
+
packedPayload = decode[0];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
packedPayload = data;
|
|
44
|
+
}
|
|
45
|
+
return Payload.decode(Bytes.fromHex(packedPayload));
|
|
46
|
+
}
|
|
47
|
+
async relay(to, data, chainId, quote, preconditions, checkInterval = 5000) {
|
|
48
|
+
// Helper function to check all preconditions
|
|
49
|
+
const checkAllPreconditions = async () => {
|
|
50
|
+
if (!preconditions || preconditions.length === 0) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
for (const precondition of preconditions) {
|
|
54
|
+
const isValid = await this.checkPrecondition(precondition);
|
|
55
|
+
if (!isValid) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
// Check preconditions immediately
|
|
62
|
+
if (await checkAllPreconditions()) {
|
|
63
|
+
// If all preconditions are met, relay the transaction
|
|
64
|
+
const txHash = await this.provider.sendTransaction({
|
|
65
|
+
to,
|
|
66
|
+
data,
|
|
67
|
+
}, chainId);
|
|
68
|
+
// TODO: Return the opHash instead, but solve the `status` function
|
|
69
|
+
// to properly fetch the receipt from an opHash instead of a txHash
|
|
70
|
+
return { opHash: txHash };
|
|
71
|
+
}
|
|
72
|
+
// If not all preconditions are met, set up event listeners and polling
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
let timeoutId;
|
|
75
|
+
let isResolved = false;
|
|
76
|
+
// Function to check and relay
|
|
77
|
+
const checkAndRelay = async () => {
|
|
78
|
+
try {
|
|
79
|
+
if (isResolved)
|
|
80
|
+
return;
|
|
81
|
+
if (await checkAllPreconditions()) {
|
|
82
|
+
isResolved = true;
|
|
83
|
+
clearTimeout(timeoutId);
|
|
84
|
+
const txHash = await this.provider.sendTransaction({
|
|
85
|
+
to,
|
|
86
|
+
data,
|
|
87
|
+
}, chainId);
|
|
88
|
+
resolve({ opHash: txHash });
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Schedule next check
|
|
92
|
+
timeoutId = setTimeout(checkAndRelay, checkInterval);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
isResolved = true;
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
reject(error);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Start checking
|
|
102
|
+
timeoutId = setTimeout(checkAndRelay, checkInterval);
|
|
103
|
+
// Cleanup function
|
|
104
|
+
return () => {
|
|
105
|
+
isResolved = true;
|
|
106
|
+
clearTimeout(timeoutId);
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async status(opHash, chainId) {
|
|
111
|
+
const receipt = await this.provider.getTransactionReceipt(opHash, chainId);
|
|
112
|
+
if (receipt === 'unknown') {
|
|
113
|
+
// Could be pending but we don't know
|
|
114
|
+
return { status: 'unknown' };
|
|
115
|
+
}
|
|
116
|
+
return receipt === 'success'
|
|
117
|
+
? { status: 'confirmed', transactionHash: opHash }
|
|
118
|
+
: { status: 'failed', reason: 'failed' };
|
|
119
|
+
}
|
|
120
|
+
async checkPrecondition(precondition) {
|
|
121
|
+
const decoded = decodePrecondition(precondition);
|
|
122
|
+
if (!decoded) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
switch (decoded.type()) {
|
|
126
|
+
case 'native-balance': {
|
|
127
|
+
const native = decoded;
|
|
128
|
+
const balance = await this.provider.getBalance(native.address.toString());
|
|
129
|
+
if (native.min !== undefined && balance < native.min) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (native.max !== undefined && balance > native.max) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
case 'erc20-balance': {
|
|
138
|
+
const erc20 = decoded;
|
|
139
|
+
const data = AbiFunction.encodeData(erc20BalanceOf, [erc20.address.toString()]);
|
|
140
|
+
const result = await this.provider.call({
|
|
141
|
+
to: erc20.token.toString(),
|
|
142
|
+
data,
|
|
143
|
+
});
|
|
144
|
+
const balance = BigInt(result);
|
|
145
|
+
if (erc20.min !== undefined && balance < erc20.min) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (erc20.max !== undefined && balance > erc20.max) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
case 'erc20-approval': {
|
|
154
|
+
const erc20 = decoded;
|
|
155
|
+
const data = AbiFunction.encodeData(erc20Allowance, [erc20.address.toString(), erc20.operator.toString()]);
|
|
156
|
+
const result = await this.provider.call({
|
|
157
|
+
to: erc20.token.toString(),
|
|
158
|
+
data,
|
|
159
|
+
});
|
|
160
|
+
const allowance = BigInt(result);
|
|
161
|
+
return allowance >= erc20.min;
|
|
162
|
+
}
|
|
163
|
+
case 'erc721-ownership': {
|
|
164
|
+
const erc721 = decoded;
|
|
165
|
+
const data = AbiFunction.encodeData(erc721OwnerOf, [erc721.tokenId]);
|
|
166
|
+
const result = await this.provider.call({
|
|
167
|
+
to: erc721.token.toString(),
|
|
168
|
+
data,
|
|
169
|
+
});
|
|
170
|
+
const owner = '0x' + result.slice(26);
|
|
171
|
+
const isOwner = owner.toLowerCase() === erc721.address.toString().toLowerCase();
|
|
172
|
+
return erc721.owned === undefined ? isOwner : erc721.owned === isOwner;
|
|
173
|
+
}
|
|
174
|
+
case 'erc721-approval': {
|
|
175
|
+
const erc721 = decoded;
|
|
176
|
+
const data = AbiFunction.encodeData(erc721GetApproved, [erc721.tokenId]);
|
|
177
|
+
const result = await this.provider.call({
|
|
178
|
+
to: erc721.token.toString(),
|
|
179
|
+
data,
|
|
180
|
+
});
|
|
181
|
+
const approved = '0x' + result.slice(26);
|
|
182
|
+
return approved.toLowerCase() === erc721.operator.toString().toLowerCase();
|
|
183
|
+
}
|
|
184
|
+
case 'erc1155-balance': {
|
|
185
|
+
const erc1155 = decoded;
|
|
186
|
+
const data = AbiFunction.encodeData(erc1155BalanceOf, [erc1155.address.toString(), erc1155.tokenId]);
|
|
187
|
+
const result = await this.provider.call({
|
|
188
|
+
to: erc1155.token.toString(),
|
|
189
|
+
data,
|
|
190
|
+
});
|
|
191
|
+
const balance = BigInt(result);
|
|
192
|
+
if (erc1155.min !== undefined && balance < erc1155.min) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (erc1155.max !== undefined && balance > erc1155.max) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
case 'erc1155-approval': {
|
|
201
|
+
const erc1155 = decoded;
|
|
202
|
+
const data = AbiFunction.encodeData(erc1155IsApprovedForAll, [
|
|
203
|
+
erc1155.address.toString(),
|
|
204
|
+
erc1155.operator.toString(),
|
|
205
|
+
]);
|
|
206
|
+
const result = await this.provider.call({
|
|
207
|
+
to: erc1155.token.toString(),
|
|
208
|
+
data,
|
|
209
|
+
});
|
|
210
|
+
return BigInt(result) === 1n;
|
|
211
|
+
}
|
|
212
|
+
default:
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export class EIP1193ProviderAdapter {
|
|
218
|
+
provider;
|
|
219
|
+
constructor(provider) {
|
|
220
|
+
this.provider = provider;
|
|
221
|
+
}
|
|
222
|
+
async trySwitchChain(chainId) {
|
|
223
|
+
try {
|
|
224
|
+
await this.provider.request({
|
|
225
|
+
method: 'wallet_switchEthereumChain',
|
|
226
|
+
params: [
|
|
227
|
+
{
|
|
228
|
+
chainId: `0x${chainId.toString(16)}`,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
// Log and continue
|
|
235
|
+
console.error('Error switching chain', error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async sendTransaction(args, chainId) {
|
|
239
|
+
const accounts = await this.provider.request({ method: 'eth_requestAccounts' });
|
|
240
|
+
const from = accounts[0];
|
|
241
|
+
if (!from) {
|
|
242
|
+
console.warn('No account selected, skipping local relayer');
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
await this.trySwitchChain(chainId);
|
|
246
|
+
const tx = await this.provider.request({
|
|
247
|
+
method: 'eth_sendTransaction',
|
|
248
|
+
params: [
|
|
249
|
+
{
|
|
250
|
+
from,
|
|
251
|
+
to: args.to,
|
|
252
|
+
data: args.data,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
return tx;
|
|
257
|
+
}
|
|
258
|
+
async getBalance(address) {
|
|
259
|
+
const balance = await this.provider.request({
|
|
260
|
+
method: 'eth_getBalance',
|
|
261
|
+
params: [address, 'latest'],
|
|
262
|
+
});
|
|
263
|
+
return BigInt(balance);
|
|
264
|
+
}
|
|
265
|
+
async call(args) {
|
|
266
|
+
return await this.provider.request({
|
|
267
|
+
method: 'eth_call',
|
|
268
|
+
params: [args, 'latest'],
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async getTransactionReceipt(txHash, chainId) {
|
|
272
|
+
await this.trySwitchChain(chainId);
|
|
273
|
+
const rpcReceipt = await this.provider.request({ method: 'eth_getTransactionReceipt', params: [txHash] });
|
|
274
|
+
if (rpcReceipt) {
|
|
275
|
+
const receipt = TransactionReceipt.fromRpc(rpcReceipt);
|
|
276
|
+
if (receipt?.status === 'success') {
|
|
277
|
+
return 'success';
|
|
278
|
+
}
|
|
279
|
+
else if (receipt?.status === 'reverted') {
|
|
280
|
+
return 'failed';
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return 'unknown';
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Payload, Precondition } from '@0xsequence/wallet-primitives';
|
|
2
|
+
import { Address, Hex, Provider } from 'ox';
|
|
3
|
+
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../index.js';
|
|
4
|
+
import { FeeToken } from '../rpc-relayer/relayer.gen.js';
|
|
5
|
+
export declare class PkRelayer implements Relayer {
|
|
6
|
+
private readonly provider;
|
|
7
|
+
readonly kind: 'relayer';
|
|
8
|
+
readonly type = "pk";
|
|
9
|
+
readonly id = "pk";
|
|
10
|
+
private readonly relayer;
|
|
11
|
+
constructor(privateKey: Hex.Hex, provider: Provider.Provider);
|
|
12
|
+
isAvailable(_wallet: Address.Address, chainId: number): Promise<boolean>;
|
|
13
|
+
feeTokens(): Promise<{
|
|
14
|
+
isFeeRequired: boolean;
|
|
15
|
+
tokens?: FeeToken[];
|
|
16
|
+
paymentAddress?: Address.Address;
|
|
17
|
+
}>;
|
|
18
|
+
feeOptions(wallet: Address.Address, chainId: number, calls: Payload.Call[]): Promise<{
|
|
19
|
+
options: FeeOption[];
|
|
20
|
+
quote?: FeeQuote;
|
|
21
|
+
}>;
|
|
22
|
+
relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{
|
|
23
|
+
opHash: Hex.Hex;
|
|
24
|
+
}>;
|
|
25
|
+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>;
|
|
26
|
+
checkPrecondition(precondition: Precondition.Precondition): Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=pk-relayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pk-relayer.d.ts","sourceRoot":"","sources":["../../../src/relayer/standard/pk-relayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAA6D,MAAM,IAAI,CAAA;AAEtG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAExD,qBAAa,SAAU,YAAW,OAAO;IAQrC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAP3B,SAAgB,IAAI,EAAE,SAAS,CAAY;IAC3C,SAAgB,IAAI,QAAO;IAC3B,SAAgB,EAAE,QAAO;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;gBAGpC,UAAU,EAAE,GAAG,CAAC,GAAG,EACF,QAAQ,EAAE,QAAQ,CAAC,QAAQ;IA0FxC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK9E,SAAS,IAAI,OAAO,CAAC;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAC,OAAO,CAAA;KAAE,CAAC;IAIvG,UAAU,CACR,MAAM,EAAE,OAAO,CAAC,OAAO,EACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,GACpB,OAAO,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC;IAIhD,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAA;KAAE,CAAC;IAQ5G,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAI5D,iBAAiB,CAAC,YAAY,EAAE,YAAY,CAAC,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAInF"}
|