Skip to content

Commit

Permalink
Merge pull request #447 from BitGo/bsc-polygon-tss
Browse files Browse the repository at this point in the history
feat: add support for bsc and polygon mpcv2
  • Loading branch information
dpkjnr authored Jun 3, 2024
2 parents 966ce65 + abf5e51 commit d16dc0d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 69 deletions.
6 changes: 6 additions & 0 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { Txlm, Xlm } from '@bitgo/sdk-coin-xlm';
import { Txrp, Xrp } from '@bitgo/sdk-coin-xrp';
import { Zec } from '@bitgo/sdk-coin-zec';
import { Zeta, Tzeta } from '@bitgo/sdk-coin-zeta';
import { Bsc, Tbsc } from '@bitgo/sdk-coin-bsc';
import { BaseCoin } from '@bitgo/sdk-core';
import assert from 'assert';
import BIP32Factory from 'bip32';
Expand Down Expand Up @@ -108,6 +109,8 @@ sdk.register('sol', Sol.createInstance);
sdk.register('tsol', Tsol.createInstance);
sdk.register('polygon', Polygon.createInstance);
sdk.register('tpolygon', Tpolygon.createInstance);
sdk.register('bsc', Bsc.createInstance);
sdk.register('tbsc', Tbsc.createInstance);
sdk.register('doge', Doge.createInstance);
sdk.register('tdoge', Tdoge.createInstance);
sdk.register('ada', Ada.createInstance);
Expand Down Expand Up @@ -275,6 +278,9 @@ async function createWindow() {
case 'tpolygonToken':
sdk = new BitGoAPI({ env: environment, polygonscanApiToken: apiKey });
break;
case 'bsc':
case 'tbsc':
sdk = new BitGoAPI({ env: environment, bscscanApiToken: apiKey });
default:
sdk = new BitGoAPI({ env: environment });
}
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@bitgo/sdk-coin-bch": "2.0.16",
"@bitgo/sdk-coin-bcha": "2.1.0",
"@bitgo/sdk-coin-bld": "2.0.16",
"@bitgo/sdk-coin-bsc": "22.1.0",
"@bitgo/sdk-coin-bsv": "2.0.16",
"@bitgo/sdk-coin-btc": "2.0.16",
"@bitgo/sdk-coin-btg": "2.0.16",
Expand Down
1 change: 1 addition & 0 deletions scripts/build-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const coins = [
'opeth',
'hbar',
'algo',
'bsc',
];

const paths = fs
Expand Down
22 changes: 22 additions & 0 deletions src/components/CryptocurrencyIcon/CryptocurrencyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CryptocurrencyIconProps {
| 'avax'
| 'bch'
| 'bld'
| 'bsc'
| 'bsv'
| 'btc'
| 'btg'
Expand Down Expand Up @@ -246,6 +247,27 @@ export function CryptocurrencyIcon({
</g>
</svg>
);
case 'bsc':
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
className={clsx('tw-inline-flex tw-fill-current', {
'tw-w-4 tw-h-4': Size === 'small',
'tw-w-6 tw-h-6': Size === 'medium',
'tw-w-8 tw-h-8': Size === 'large',
})}
{...hostProps}
>
<g fill="none">
<circle cx="16" cy="16" r="16" fill="#F3BA2F" />
<path
fill="#FFF"
d="M12.116 14.404L16 10.52l3.886 3.886 2.26-2.26L16 6l-6.144 6.144 2.26 2.26zM6 16l2.26-2.26L10.52 16l-2.26 2.26L6 16zm6.116 1.596L16 21.48l3.886-3.886 2.26 2.259L16 26l-6.144-6.144-.003-.003 2.263-2.257zM21.48 16l2.26-2.26L26 16l-2.26 2.26L21.48 16zm-3.188-.002h.002V16L16 18.294l-2.291-2.29-.004-.004.004-.003.401-.402.195-.195L16 13.706l2.293 2.293z"
/>
</g>
</svg>
);
case 'bsv':
return (
<svg
Expand Down
71 changes: 4 additions & 67 deletions src/containers/NonBitGoRecoveryCoin/NonBitGoRecoveryCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { EthereumForm } from './EthLikeForm';
import { EthereumWForm } from './EthereumWForm';
import { LitecoinForm } from './LitecoinForm';
import { PolkadotForm } from './PolkadotForm';
import { PolygonForm } from './PolygonForm';
import { RippleForm } from './RippleForm';
import { SolanaForm } from './SolanaForm';
import { SolanaTokenForm } from './SolanaTokenForm';
Expand Down Expand Up @@ -337,6 +336,10 @@ function Form() {
case 'tarbeth':
case 'opeth':
case 'topeth':
case 'polygon':
case 'tpolygon':
case 'bsc':
case 'tbsc':
return (
<EthereumForm
key={coin}
Expand Down Expand Up @@ -993,72 +996,6 @@ function Form() {
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/non-bitgo-recovery/${coin}/success`
);
} catch (err) {
if (err instanceof Error) {
setAlert(err.message);
} else {
console.error(err);
}
setSubmitting(false);
}
}}
/>
);
case 'polygon':
case 'tpolygon':
return (
<PolygonForm
key={coin}
onSubmit={async (values, { setSubmitting }) => {
setAlert(undefined);
setSubmitting(true);
try {
await window.commands.setBitGoEnvironment(
bitGoEnvironment,
coin,
values.apiKey
);
const chainData = await window.queries.getChain(coin);

const { maxFeePerGas, maxPriorityFeePerGas, ...rest } = values;

const recoverData = await window.commands.recover(coin, {
...rest,
eip1559: {
maxFeePerGas: toWei(maxFeePerGas),
maxPriorityFeePerGas: toWei(maxPriorityFeePerGas),
},
bitgoKey: '',
ignoreAddressTypes: [],
});
assert(
isRecoveryTransaction(recoverData),
'Fully-signed recovery transaction not detected.'
);

const showSaveDialogData = await window.commands.showSaveDialog({
filters: [
{
name: 'Custom File Type',
extensions: ['json'],
},
],
defaultPath: `~/${chainData}-recovery-${Date.now()}.json`,
});

if (!showSaveDialogData.filePath) {
throw new Error('No file path selected');
}

await window.commands.writeFile(
showSaveDialogData.filePath,
JSON.stringify(recoverData, null, 2),
{ encoding: 'utf-8' }
);

navigate(
`/${bitGoEnvironment}/non-bitgo-recovery/${coin}/success`
);
Expand Down
23 changes: 22 additions & 1 deletion src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export const allCoinMetas: Record<string, CoinMetadata> = {
Description: 'POLYGON Chain',
Icon: 'polygon',
value: 'polygon',
isTssSupported: true,
},
bsc: {
Title: 'BSC',
Description: 'BNB Smart Chain',
Icon: 'bsc',
value: 'bsc',
isTssSupported: true,
},
polygonToken: {
Title: 'POLYGON TOKEN',
Expand Down Expand Up @@ -439,13 +447,22 @@ export const allCoinMetas: Record<string, CoinMetadata> = {
Description: 'Polygon Mumbai Testnet',
Icon: 'polygon',
value: 'tpolygon',
isTssSupported: true,
ApiKeyProvider: 'api-amoy.polygonscan.com',
},
tbsc: {
Title: 'TBSC',
Description: 'BNB Smart Chain Testnet',
Icon: 'bsc',
value: 'tbsc',
isTssSupported: true,
},
tpolygonToken: {
Title: 'TPOLYGON TOKEN',
Description: 'Testnet Polygon Token',
Icon: 'polygon',
value: 'tpolygonToken',
ApiKeyProvider: 'polygonscan.com',
ApiKeyProvider: 'api-amoy.polygonscan.com',
minGasLimit: '30,000',
defaultGasLimit: '500,000',
defaultGasLimitNum: 500000,
Expand Down Expand Up @@ -577,6 +594,7 @@ export const buildUnsignedSweepCoins: Record<
allCoinMetas.opethToken,
allCoinMetas.polygon,
allCoinMetas.polygonToken,
allCoinMetas.bsc,
allCoinMetas.bcha,
allCoinMetas.doge,
allCoinMetas.sol,
Expand Down Expand Up @@ -610,6 +628,7 @@ export const buildUnsignedSweepCoins: Record<
allCoinMetas.tdot,
allCoinMetas.thbar,
allCoinMetas.talgo,
allCoinMetas.tbsc,
] as const,
};

Expand Down Expand Up @@ -642,6 +661,7 @@ export const nonBitgoRecoveryCoins: Record<BitgoEnv, readonly CoinMetadata[]> =
allCoinMetas.solToken,
allCoinMetas.polygon,
allCoinMetas.polygonToken,
allCoinMetas.bsc,
allCoinMetas.bcha,
allCoinMetas.doge,
allCoinMetas.ada,
Expand Down Expand Up @@ -678,6 +698,7 @@ export const nonBitgoRecoveryCoins: Record<BitgoEnv, readonly CoinMetadata[]> =
allCoinMetas.tsolToken,
allCoinMetas.tpolygon,
allCoinMetas.tpolygonToken,
allCoinMetas.tbsc,
allCoinMetas.tdoge,
allCoinMetas.tada,
allCoinMetas.tatom,
Expand Down
9 changes: 8 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
BackupKeyRecoveryTransansaction,
FormattedOfflineVaultTxInfo,
} from '@bitgo/abstract-utxo';
import { coins, EthereumNetwork } from '@bitgo/statics'

const GWEI = 10 ** 9;

Expand Down Expand Up @@ -41,7 +42,13 @@ export function getEthLikeRecoveryChainId(
coinName: string,
bitGoEnvironment: string
) {
return coinName === 'ethw' ? 10001 : bitGoEnvironment === 'prod' ? 1 : 17000;
const chainId = (coins.get(coinName)?.network as EthereumNetwork)?.chainId;
if (chainId) {
return chainId;
}

// default to eth
return bitGoEnvironment === 'prod' ? 1 : 17000;
}

export type BitgoEnv = 'prod' | 'test';
Expand Down

0 comments on commit d16dc0d

Please sign in to comment.