Correctly parse tokenID in SDK
Change-Id: I902b8fc3a8092ef1f7c38ba8eb3235e3d40543a8
This commit is contained in:
parent
3968b6eb7f
commit
4c9bf1162c
|
@ -40,7 +40,10 @@ export async function getOriginalAssetEth(
|
||||||
return {
|
return {
|
||||||
isWrapped: true,
|
isWrapped: true,
|
||||||
chainId,
|
chainId,
|
||||||
assetAddress: chainId === CHAIN_ID_SOLANA ? arrayify(BigNumber.from(tokenId)) : arrayify(assetAddress),
|
assetAddress:
|
||||||
|
chainId === CHAIN_ID_SOLANA
|
||||||
|
? arrayify(BigNumber.from(tokenId))
|
||||||
|
: arrayify(assetAddress),
|
||||||
tokenId, // tokenIds are maintained across EVM chains
|
tokenId, // tokenIds are maintained across EVM chains
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -80,7 +83,11 @@ export async function getOriginalAssetSol(
|
||||||
if (wrappedMetaAccountInfo) {
|
if (wrappedMetaAccountInfo) {
|
||||||
const parsed = parse_wrapped_meta(wrappedMetaAccountInfo.data);
|
const parsed = parse_wrapped_meta(wrappedMetaAccountInfo.data);
|
||||||
const token_id_arr = parsed.token_id as BigUint64Array;
|
const token_id_arr = parsed.token_id as BigUint64Array;
|
||||||
const token_id = BigNumber.from(token_id_arr.reverse()).toString();
|
const token_id_bytes = [];
|
||||||
|
for (let elem of token_id_arr.reverse()) {
|
||||||
|
token_id_bytes.push(...bigToUint8Array(elem));
|
||||||
|
}
|
||||||
|
const token_id = BigNumber.from(token_id_bytes).toString();
|
||||||
return {
|
return {
|
||||||
isWrapped: true,
|
isWrapped: true,
|
||||||
chainId: parsed.chain,
|
chainId: parsed.chain,
|
||||||
|
@ -102,3 +109,33 @@ export async function getOriginalAssetSol(
|
||||||
assetAddress: new Uint8Array(32),
|
assetAddress: new Uint8Array(32),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Derived from https://www.jackieli.dev/posts/bigint-to-uint8array/
|
||||||
|
const big0 = BigInt(0);
|
||||||
|
const big1 = BigInt(1);
|
||||||
|
const big8 = BigInt(8);
|
||||||
|
|
||||||
|
function bigToUint8Array(big: bigint) {
|
||||||
|
if (big < big0) {
|
||||||
|
const bits: bigint = (BigInt(big.toString(2).length) / big8 + big1) * big8;
|
||||||
|
const prefix1: bigint = big1 << bits;
|
||||||
|
big += prefix1;
|
||||||
|
}
|
||||||
|
let hex = big.toString(16);
|
||||||
|
if (hex.length % 2) {
|
||||||
|
hex = "0" + hex;
|
||||||
|
} else if (hex[0] === "8") {
|
||||||
|
// maximum positive need to prepend 0 otherwise resuts in negative number
|
||||||
|
hex = "00" + hex;
|
||||||
|
}
|
||||||
|
const len = hex.length / 2;
|
||||||
|
const u8 = new Uint8Array(len);
|
||||||
|
var i = 0;
|
||||||
|
var j = 0;
|
||||||
|
while (i < len) {
|
||||||
|
u8[i] = parseInt(hex.slice(j, j + 2), 16);
|
||||||
|
i += 1;
|
||||||
|
j += 2;
|
||||||
|
}
|
||||||
|
return u8;
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"downlevelIteration": true,
|
"downlevelIteration": true,
|
||||||
"allowJs": true
|
"allowJs": true,
|
||||||
|
"lib": ["dom", "es5", "scripthost", "es2020.bigint"]
|
||||||
},
|
},
|
||||||
"include": ["src", "types"],
|
"include": ["src", "types"],
|
||||||
"exclude": ["node_modules", "**/__tests__/*"]
|
"exclude": ["node_modules", "**/__tests__/*"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"extends": ["tslint:recommended", "tslint-config-prettier"],
|
"extends": ["tslint:recommended", "tslint-config-prettier"],
|
||||||
"linterOptions": {
|
"linterOptions": {
|
||||||
"exclude": [
|
"exclude": ["src/proto/**"]
|
||||||
"src/proto/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue