@shapeshiftoss/unchained-client 10.14.6 → 10.14.7-alpha.1
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/cosmossdk/mayachain/parser/__tests__/mockData/mayachainStreamingSwapOutbound.d.ts +1 -1
- package/dist/cjs/cosmossdk/mayachain/parser/__tests__/mockData/mayachainSwapOutbound.d.ts +1 -1
- package/dist/cjs/cosmossdk/mayachain/parser/__tests__/mockData/mayachainSwapRefund.d.ts +1 -1
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/bnbsmartchain.test.js +32 -32
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep1155.js → erc1155.js} +4 -4
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep20Approve.js → erc20Approve.js} +3 -3
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep721.js → erc721.js} +4 -4
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/tokenSelfSend.js +1 -1
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/tokenStandard.js +1 -1
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeBnbToBusd.js +3 -3
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeBusdToBnb.js +2 -2
- package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeUsdtToBusd.js +4 -4
- package/dist/cjs/evm/bnbsmartchain/parser/index.js +2 -2
- package/dist/cjs/evm/parser/index.js +0 -6
- package/dist/cjs/evm/parser/types.d.ts +1 -2
- package/dist/cjs/generated/arbitrum/apis/V1Api.d.ts +15 -0
- package/dist/cjs/generated/arbitrum/apis/V1Api.js +24 -0
- package/dist/cjs/generated/solana/apis/V1Api.d.ts +3 -3
- package/dist/cjs/generated/solana/apis/V1Api.js +1 -1
- package/dist/cjs/generated/solana/models/Token.d.ts +5 -22
- package/dist/cjs/generated/solana/models/Token.js +7 -15
- package/dist/cjs/generated/solana/models/TokenDetails.d.ts +55 -0
- package/dist/cjs/generated/solana/models/TokenDetails.js +63 -0
- package/dist/cjs/generated/solana/models/index.d.ts +1 -0
- package/dist/cjs/generated/solana/models/index.js +1 -0
- package/dist/cjs/generated/thorchain/apis/ProxyApi.d.ts +8 -0
- package/dist/cjs/generated/thorchain/apis/ProxyApi.js +20 -0
- package/dist/cjs/solana/parser/__tests__/mockData/tokens.d.ts +1 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/cosmossdk/mayachain/parser/__tests__/mockData/mayachainStreamingSwapOutbound.d.ts +1 -1
- package/dist/esm/cosmossdk/mayachain/parser/__tests__/mockData/mayachainSwapOutbound.d.ts +1 -1
- package/dist/esm/cosmossdk/mayachain/parser/__tests__/mockData/mayachainSwapRefund.d.ts +1 -1
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/bnbsmartchain.test.js +32 -32
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep1155.js → erc1155.js} +4 -4
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep20Approve.js → erc20Approve.js} +3 -3
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep721.js → erc721.js} +4 -4
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/tokenSelfSend.js +1 -1
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/tokenStandard.js +1 -1
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeBnbToBusd.js +3 -3
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeBusdToBnb.js +2 -2
- package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/zrxTradeUsdtToBusd.js +4 -4
- package/dist/esm/evm/bnbsmartchain/parser/index.js +2 -2
- package/dist/esm/evm/parser/index.js +0 -6
- package/dist/esm/evm/parser/types.d.ts +1 -2
- package/dist/esm/generated/arbitrum/apis/V1Api.d.ts +15 -0
- package/dist/esm/generated/arbitrum/apis/V1Api.js +24 -0
- package/dist/esm/generated/solana/apis/V1Api.d.ts +3 -3
- package/dist/esm/generated/solana/apis/V1Api.js +2 -2
- package/dist/esm/generated/solana/models/Token.d.ts +5 -22
- package/dist/esm/generated/solana/models/Token.js +7 -15
- package/dist/esm/generated/solana/models/TokenDetails.d.ts +55 -0
- package/dist/esm/generated/solana/models/TokenDetails.js +56 -0
- package/dist/esm/generated/solana/models/index.d.ts +1 -0
- package/dist/esm/generated/solana/models/index.js +1 -0
- package/dist/esm/generated/thorchain/apis/ProxyApi.d.ts +8 -0
- package/dist/esm/generated/thorchain/apis/ProxyApi.js +20 -0
- package/dist/esm/solana/parser/__tests__/mockData/tokens.d.ts +1 -1
- package/package.json +8 -5
- package/dist/cjs/evm/bnbsmartchain/parser/bep20.d.ts +0 -22
- package/dist/cjs/evm/bnbsmartchain/parser/bep20.js +0 -56
- package/dist/esm/evm/bnbsmartchain/parser/bep20.d.ts +0 -22
- package/dist/esm/evm/bnbsmartchain/parser/bep20.js +0 -52
- /package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep1155.d.ts → erc1155.d.ts} +0 -0
- /package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep20Approve.d.ts → erc20Approve.d.ts} +0 -0
- /package/dist/cjs/evm/bnbsmartchain/parser/__tests__/mockData/{bep721.d.ts → erc721.d.ts} +0 -0
- /package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep1155.d.ts → erc1155.d.ts} +0 -0
- /package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep20Approve.d.ts → erc20Approve.d.ts} +0 -0
- /package/dist/esm/evm/bnbsmartchain/parser/__tests__/mockData/{bep721.d.ts → erc721.d.ts} +0 -0
|
@@ -12,16 +12,14 @@
|
|
|
12
12
|
* https://openapi-generator.tech
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
|
+
import { TokenStandardFromJSON, TokenStandardToJSON, } from './TokenStandard.js';
|
|
15
16
|
/**
|
|
16
17
|
* Check if a given object implements the Token interface.
|
|
17
18
|
*/
|
|
18
19
|
export function instanceOfToken(value) {
|
|
19
20
|
let isInstance = true;
|
|
20
|
-
isInstance = isInstance && "
|
|
21
|
-
isInstance = isInstance && "
|
|
22
|
-
isInstance = isInstance && "name" in value;
|
|
23
|
-
isInstance = isInstance && "symbol" in value;
|
|
24
|
-
isInstance = isInstance && "type" in value;
|
|
21
|
+
isInstance = isInstance && "mint" in value;
|
|
22
|
+
isInstance = isInstance && "tokenStandard" in value;
|
|
25
23
|
return isInstance;
|
|
26
24
|
}
|
|
27
25
|
export function TokenFromJSON(json) {
|
|
@@ -32,11 +30,8 @@ export function TokenFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
32
30
|
return json;
|
|
33
31
|
}
|
|
34
32
|
return {
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'name': json['name'],
|
|
38
|
-
'symbol': json['symbol'],
|
|
39
|
-
'type': json['type'],
|
|
33
|
+
'mint': json['mint'],
|
|
34
|
+
'tokenStandard': TokenStandardFromJSON(json['tokenStandard']),
|
|
40
35
|
};
|
|
41
36
|
}
|
|
42
37
|
export function TokenToJSON(value) {
|
|
@@ -47,10 +42,7 @@ export function TokenToJSON(value) {
|
|
|
47
42
|
return null;
|
|
48
43
|
}
|
|
49
44
|
return {
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'name': value.name,
|
|
53
|
-
'symbol': value.symbol,
|
|
54
|
-
'type': value.type,
|
|
45
|
+
'mint': value.mint,
|
|
46
|
+
'tokenStandard': TokenStandardToJSON(value.tokenStandard),
|
|
55
47
|
};
|
|
56
48
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @shapeshiftoss/solana-api
|
|
3
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 10.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Contains info about a token
|
|
14
|
+
* @export
|
|
15
|
+
* @interface TokenDetails
|
|
16
|
+
*/
|
|
17
|
+
export interface TokenDetails {
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @type {string}
|
|
21
|
+
* @memberof TokenDetails
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @type {number}
|
|
27
|
+
* @memberof TokenDetails
|
|
28
|
+
*/
|
|
29
|
+
decimals: number;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @type {string}
|
|
33
|
+
* @memberof TokenDetails
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @type {string}
|
|
39
|
+
* @memberof TokenDetails
|
|
40
|
+
*/
|
|
41
|
+
symbol: string;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @type {string}
|
|
45
|
+
* @memberof TokenDetails
|
|
46
|
+
*/
|
|
47
|
+
type: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a given object implements the TokenDetails interface.
|
|
51
|
+
*/
|
|
52
|
+
export declare function instanceOfTokenDetails(value: object): boolean;
|
|
53
|
+
export declare function TokenDetailsFromJSON(json: any): TokenDetails;
|
|
54
|
+
export declare function TokenDetailsFromJSONTyped(json: any, ignoreDiscriminator: boolean): TokenDetails;
|
|
55
|
+
export declare function TokenDetailsToJSON(value?: TokenDetails | null): any;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* @shapeshiftoss/solana-api
|
|
6
|
+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
7
|
+
*
|
|
8
|
+
* The version of the OpenAPI document: 10.0.0
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
12
|
+
* https://openapi-generator.tech
|
|
13
|
+
* Do not edit the class manually.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Check if a given object implements the TokenDetails interface.
|
|
17
|
+
*/
|
|
18
|
+
export function instanceOfTokenDetails(value) {
|
|
19
|
+
let isInstance = true;
|
|
20
|
+
isInstance = isInstance && "id" in value;
|
|
21
|
+
isInstance = isInstance && "decimals" in value;
|
|
22
|
+
isInstance = isInstance && "name" in value;
|
|
23
|
+
isInstance = isInstance && "symbol" in value;
|
|
24
|
+
isInstance = isInstance && "type" in value;
|
|
25
|
+
return isInstance;
|
|
26
|
+
}
|
|
27
|
+
export function TokenDetailsFromJSON(json) {
|
|
28
|
+
return TokenDetailsFromJSONTyped(json, false);
|
|
29
|
+
}
|
|
30
|
+
export function TokenDetailsFromJSONTyped(json, ignoreDiscriminator) {
|
|
31
|
+
if ((json === undefined) || (json === null)) {
|
|
32
|
+
return json;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
'id': json['id'],
|
|
36
|
+
'decimals': json['decimals'],
|
|
37
|
+
'name': json['name'],
|
|
38
|
+
'symbol': json['symbol'],
|
|
39
|
+
'type': json['type'],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function TokenDetailsToJSON(value) {
|
|
43
|
+
if (value === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (value === null) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
'id': value.id,
|
|
51
|
+
'decimals': value.decimals,
|
|
52
|
+
'name': value.name,
|
|
53
|
+
'symbol': value.symbol,
|
|
54
|
+
'type': value.type,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -36,6 +36,7 @@ export * from './SwapEvent.js';
|
|
|
36
36
|
export * from './Token.js';
|
|
37
37
|
export * from './TokenBalance.js';
|
|
38
38
|
export * from './TokenBalanceChange.js';
|
|
39
|
+
export * from './TokenDetails.js';
|
|
39
40
|
export * from './TokenStandard.js';
|
|
40
41
|
export * from './TokenSwap.js';
|
|
41
42
|
export * from './TokenSwapNativeInput.js';
|
|
@@ -39,6 +39,7 @@ export * from './SwapEvent.js';
|
|
|
39
39
|
export * from './Token.js';
|
|
40
40
|
export * from './TokenBalance.js';
|
|
41
41
|
export * from './TokenBalanceChange.js';
|
|
42
|
+
export * from './TokenDetails.js';
|
|
42
43
|
export * from './TokenStandard.js';
|
|
43
44
|
export * from './TokenSwap.js';
|
|
44
45
|
export * from './TokenSwapNativeInput.js';
|
|
@@ -30,4 +30,12 @@ export declare class ProxyApi extends runtime.BaseAPI {
|
|
|
30
30
|
* Thorchain midgard rest api endpoints.
|
|
31
31
|
*/
|
|
32
32
|
midgard(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Thorchain rpc rest api endpoints.
|
|
35
|
+
*/
|
|
36
|
+
rPCRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;
|
|
37
|
+
/**
|
|
38
|
+
* Thorchain rpc rest api endpoints.
|
|
39
|
+
*/
|
|
40
|
+
rPC(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
|
|
33
41
|
}
|
|
@@ -57,4 +57,24 @@ export class ProxyApi extends runtime.BaseAPI {
|
|
|
57
57
|
async midgard(initOverrides) {
|
|
58
58
|
await this.midgardRaw(initOverrides);
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Thorchain rpc rest api endpoints.
|
|
62
|
+
*/
|
|
63
|
+
async rPCRaw(initOverrides) {
|
|
64
|
+
const queryParameters = {};
|
|
65
|
+
const headerParameters = {};
|
|
66
|
+
const response = await this.request({
|
|
67
|
+
path: `/rpc`,
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: headerParameters,
|
|
70
|
+
query: queryParameters,
|
|
71
|
+
}, initOverrides);
|
|
72
|
+
return new runtime.VoidApiResponse(response);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Thorchain rpc rest api endpoints.
|
|
76
|
+
*/
|
|
77
|
+
async rPC(initOverrides) {
|
|
78
|
+
await this.rPCRaw(initOverrides);
|
|
79
|
+
}
|
|
60
80
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Token as ParserToken } from '../../../../types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TokenDetails as ApiToken } from '../../types.js';
|
|
3
3
|
export declare const usdcApiToken: ApiToken;
|
|
4
4
|
export declare const usdcParserToken: ParserToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/unchained-client",
|
|
3
|
-
"version": "10.14.
|
|
3
|
+
"version": "10.14.7-alpha.1",
|
|
4
4
|
"repository": "https://github.com/shapeshift/web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,12 +30,15 @@
|
|
|
30
30
|
"postbuild:cjs": "echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@shapeshiftoss/caip": "^8.16.
|
|
33
|
+
"@shapeshiftoss/caip": "^8.16.4-alpha.1",
|
|
34
34
|
"@shapeshiftoss/common-api": "^9.3.0",
|
|
35
|
-
"@shapeshiftoss/contracts": "^1.0.
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
35
|
+
"@shapeshiftoss/contracts": "^1.0.3-alpha.1",
|
|
36
|
+
"@shapeshiftoss/utils": "^1.0.3-alpha.1",
|
|
37
|
+
"axios": "^1.13.0",
|
|
38
|
+
"bignumber.js": "^9.3.1",
|
|
39
|
+
"ethers": "6.11.1",
|
|
38
40
|
"isomorphic-ws": "^4.0.1",
|
|
41
|
+
"viem": "^2.10.9",
|
|
39
42
|
"ws": "^8.17.1"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import type { BaseTxMetadata } from '../../../types';
|
|
4
|
-
import type { SubParser, Tx, TxSpecific } from '../../parser/types';
|
|
5
|
-
export interface TxMetadata extends BaseTxMetadata {
|
|
6
|
-
parser: 'bep20';
|
|
7
|
-
assetId: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
}
|
|
10
|
-
interface ParserArgs {
|
|
11
|
-
chainId: ChainId;
|
|
12
|
-
provider: ethers.JsonRpcProvider;
|
|
13
|
-
}
|
|
14
|
-
export declare class Parser<T extends Tx> implements SubParser<T> {
|
|
15
|
-
provider: ethers.JsonRpcProvider;
|
|
16
|
-
readonly chainId: ChainId;
|
|
17
|
-
readonly abiInterface: ethers.Interface;
|
|
18
|
-
private readonly supportedFunctions;
|
|
19
|
-
constructor(args: ParserArgs);
|
|
20
|
-
parse(tx: T): Promise<TxSpecific | undefined>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Parser = void 0;
|
|
4
|
-
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
-
const contracts_1 = require("@shapeshiftoss/contracts");
|
|
6
|
-
const ethers_1 = require("ethers");
|
|
7
|
-
const utils_1 = require("../../parser/utils");
|
|
8
|
-
class Parser {
|
|
9
|
-
provider;
|
|
10
|
-
chainId;
|
|
11
|
-
abiInterface = new ethers_1.ethers.Interface(contracts_1.I_BEP20_ABI);
|
|
12
|
-
supportedFunctions;
|
|
13
|
-
constructor(args) {
|
|
14
|
-
this.provider = args.provider;
|
|
15
|
-
this.chainId = args.chainId;
|
|
16
|
-
const approveSigHash = this.abiInterface.getFunction('approve')?.selector;
|
|
17
|
-
if (!approveSigHash)
|
|
18
|
-
throw new Error('Failed to get function selectors');
|
|
19
|
-
this.supportedFunctions = {
|
|
20
|
-
approveSigHash,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async parse(tx) {
|
|
24
|
-
if (!tx.inputData)
|
|
25
|
-
return;
|
|
26
|
-
const txSigHash = (0, utils_1.getSigHash)(tx.inputData);
|
|
27
|
-
if (!Object.values(this.supportedFunctions).some(hash => hash === txSigHash))
|
|
28
|
-
return;
|
|
29
|
-
const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
|
|
30
|
-
// failed to decode input data
|
|
31
|
-
if (!decoded)
|
|
32
|
-
return;
|
|
33
|
-
const data = {
|
|
34
|
-
assetId: (0, caip_1.toAssetId)({
|
|
35
|
-
chainId: this.chainId,
|
|
36
|
-
assetNamespace: 'bep20',
|
|
37
|
-
assetReference: tx.to,
|
|
38
|
-
}),
|
|
39
|
-
method: decoded.name,
|
|
40
|
-
parser: 'bep20',
|
|
41
|
-
};
|
|
42
|
-
switch (txSigHash) {
|
|
43
|
-
case this.supportedFunctions.approveSigHash: {
|
|
44
|
-
const amount = decoded.args.amount;
|
|
45
|
-
const value = amount.toString();
|
|
46
|
-
if (amount === 0n) {
|
|
47
|
-
return await Promise.resolve({ data: { ...data, method: 'revoke', value } });
|
|
48
|
-
}
|
|
49
|
-
return await Promise.resolve({ data: { ...data, value } });
|
|
50
|
-
}
|
|
51
|
-
default:
|
|
52
|
-
return await Promise.resolve({ data });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.Parser = Parser;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import type { BaseTxMetadata } from '../../../types.js';
|
|
4
|
-
import type { SubParser, Tx, TxSpecific } from '../../parser/types.js';
|
|
5
|
-
export interface TxMetadata extends BaseTxMetadata {
|
|
6
|
-
parser: 'bep20';
|
|
7
|
-
assetId: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
}
|
|
10
|
-
interface ParserArgs {
|
|
11
|
-
chainId: ChainId;
|
|
12
|
-
provider: ethers.JsonRpcProvider;
|
|
13
|
-
}
|
|
14
|
-
export declare class Parser<T extends Tx> implements SubParser<T> {
|
|
15
|
-
provider: ethers.JsonRpcProvider;
|
|
16
|
-
readonly chainId: ChainId;
|
|
17
|
-
readonly abiInterface: ethers.Interface;
|
|
18
|
-
private readonly supportedFunctions;
|
|
19
|
-
constructor(args: ParserArgs);
|
|
20
|
-
parse(tx: T): Promise<TxSpecific | undefined>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { toAssetId } from '@shapeshiftoss/caip';
|
|
2
|
-
import { I_BEP20_ABI } from '@shapeshiftoss/contracts';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
|
-
import { getSigHash } from '../../parser/utils.js';
|
|
5
|
-
export class Parser {
|
|
6
|
-
provider;
|
|
7
|
-
chainId;
|
|
8
|
-
abiInterface = new ethers.Interface(I_BEP20_ABI);
|
|
9
|
-
supportedFunctions;
|
|
10
|
-
constructor(args) {
|
|
11
|
-
this.provider = args.provider;
|
|
12
|
-
this.chainId = args.chainId;
|
|
13
|
-
const approveSigHash = this.abiInterface.getFunction('approve')?.selector;
|
|
14
|
-
if (!approveSigHash)
|
|
15
|
-
throw new Error('Failed to get function selectors');
|
|
16
|
-
this.supportedFunctions = {
|
|
17
|
-
approveSigHash,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
async parse(tx) {
|
|
21
|
-
if (!tx.inputData)
|
|
22
|
-
return;
|
|
23
|
-
const txSigHash = getSigHash(tx.inputData);
|
|
24
|
-
if (!Object.values(this.supportedFunctions).some(hash => hash === txSigHash))
|
|
25
|
-
return;
|
|
26
|
-
const decoded = this.abiInterface.parseTransaction({ data: tx.inputData });
|
|
27
|
-
// failed to decode input data
|
|
28
|
-
if (!decoded)
|
|
29
|
-
return;
|
|
30
|
-
const data = {
|
|
31
|
-
assetId: toAssetId({
|
|
32
|
-
chainId: this.chainId,
|
|
33
|
-
assetNamespace: 'bep20',
|
|
34
|
-
assetReference: tx.to,
|
|
35
|
-
}),
|
|
36
|
-
method: decoded.name,
|
|
37
|
-
parser: 'bep20',
|
|
38
|
-
};
|
|
39
|
-
switch (txSigHash) {
|
|
40
|
-
case this.supportedFunctions.approveSigHash: {
|
|
41
|
-
const amount = decoded.args.amount;
|
|
42
|
-
const value = amount.toString();
|
|
43
|
-
if (amount === 0n) {
|
|
44
|
-
return await Promise.resolve({ data: { ...data, method: 'revoke', value } });
|
|
45
|
-
}
|
|
46
|
-
return await Promise.resolve({ data: { ...data, value } });
|
|
47
|
-
}
|
|
48
|
-
default:
|
|
49
|
-
return await Promise.resolve({ data });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|