Skip to content

Commit

Permalink
Merge pull request #4170 from BitGo/WIN-1421-zksync-statics
Browse files Browse the repository at this point in the history
feat(sdk-coin-zketh): add zketh token support
  • Loading branch information
ajays97 authored Dec 26, 2023
2 parents 2c3a9ca + 086b86c commit 44bb681
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# All other coins
/modules/sdk-coin-ada/ @BitGo/ethalt-team
/modules/sdk-coin-algo/ @BitGo/ethalt-team
/modules/sdk-coin-arbeth/ @BitGo/ethalt-team
/modules/sdk-coin-atom/ @BitGo/ethalt-team
/modules/sdk-coin-avaxc/ @BitGo/ethalt-team
/modules/sdk-coin-avaxp/ @BitGo/ethalt-team
Expand All @@ -49,6 +50,7 @@
/modules/sdk-coin-eos/ @BitGo/ethalt-team
/modules/sdk-coin-hbar/ @BitGo/ethalt-team
/modules/sdk-coin-near/ @BitGo/ethalt-team
/modules/sdk-coin-opeth/ @BitGo/ethalt-team
/modules/sdk-coin-polygon/ @BitGo/ethalt-team
/modules/sdk-coin-sol/ @BitGo/ethalt-team
/modules/sdk-coin-stx/ @BitGo/ethalt-team
Expand All @@ -58,6 +60,7 @@
/modules/sdk-coin-xlm/ @BitGo/ethalt-team
/modules/sdk-coin-xrp/ @BitGo/ethalt-team
/modules/sdk-coin-xtz/ @BitGo/ethalt-team
/modules/sdk-coin-zketh/ @BitGo/ethalt-team

# Trade
/modules/sdk-core/src/bitgo/address-book/ @BitGo/prime
Expand Down
5 changes: 5 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import {
Zec,
Zeta,
Zketh,
ZkethToken,
} from './coins';

function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
Expand Down Expand Up @@ -276,6 +277,10 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register(name, coinConstructor);
});

ZkethToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
globalCoinFactory.register(name, coinConstructor);
});

SolToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
globalCoinFactory.register(name, coinConstructor);
});
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { Txrp, Xrp } from '@bitgo/sdk-coin-xrp';
import { Txtz, Xtz } from '@bitgo/sdk-coin-xtz';
import { Tzec, Zec } from '@bitgo/sdk-coin-zec';
import { Tzeta, Zeta } from '@bitgo/sdk-coin-zeta';
import { Zketh, Tzketh } from '@bitgo/sdk-coin-zketh';
import { Zketh, Tzketh, ZkethToken } from '@bitgo/sdk-coin-zketh';

export { AbstractUtxoCoin };
export { Algo, AlgoToken, Talgo };
Expand Down Expand Up @@ -94,7 +94,7 @@ export { Txrp, Xrp };
export { Txtz, Xtz };
export { Tzec, Zec };
export { Tzeta, Zeta };
export { Zketh, Tzketh };
export { Zketh, Tzketh, ZkethToken };

import { coins } from '@bitgo/sdk-core';
const { Ofc, OfcToken, Susd, FiatUsd, FiatEur, FiatGBP, Tsusd, TfiatUsd, TfiatEur, TfiatGBP } = coins;
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Coins', () => {
BscToken: 1,
ArbethToken: 1,
OpethToken: 1,
ZkethToken: 1,
};
Object.keys(BitGoJS.Coin)
.filter((coinName) => !excludedKeys[coinName])
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-zketh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"coverage": "nyc -- npm run unit-test",
"unit-test": "mocha"
},
"author": "Ajay Srinivas <ajsrinivas@bitgo.com>",
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=16 <21"
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-zketh/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './lib';
export * from './zketh';
export * from './tzketh';
export * from './zkethToken';
export * from './register';
12 changes: 1 addition & 11 deletions modules/sdk-coin-zketh/src/zketh.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @prettier
*/
import { BaseCoin, BitGoBase, MPCAlgorithm } from '@bitgo/sdk-core';
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
import { AbstractEthLikeNewCoins, TransactionBuilder as EthLikeTransactionBuilder } from '@bitgo/abstract-eth';
import { TransactionBuilder } from './lib';
Expand All @@ -18,14 +18,4 @@ export class Zketh extends AbstractEthLikeNewCoins {
protected getTransactionBuilder(): EthLikeTransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

/** @inheritDoc */
supportsTss(): boolean {
return false;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
}
35 changes: 35 additions & 0 deletions modules/sdk-coin-zketh/src/zkethToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @prettier
*/
import { EthLikeTokenConfig, coins } from '@bitgo/statics';
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
import { CoinNames, EthLikeToken } from '@bitgo/abstract-eth';
import { TransactionBuilder } from './lib';

export { EthLikeTokenConfig };

export class ZkethToken extends EthLikeToken {
public readonly tokenConfig: EthLikeTokenConfig;
static coinNames: CoinNames = {
Mainnet: 'zketh',
Testnet: 'tzketh',
};
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
super(bitgo, tokenConfig, ZkethToken.coinNames);
}
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
return super.createTokenConstructor(config, ZkethToken.coinNames);
}

static createTokenConstructors(): NamedCoinConstructor[] {
return super.createTokenConstructors(ZkethToken.coinNames);
}

protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

getFullName(): string {
return 'Zketh Token';
}
}
32 changes: 32 additions & 0 deletions modules/sdk-coin-zketh/test/unit/zkethToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'should';

import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { ZkethToken } from '../../src';
import { BitGoAPI } from '@bitgo/sdk-api';

describe('Zketh Token:', function () {
let bitgo: TestBitGoAPI;
let zkethTokenCoin;
const tokenName = 'tzketh:link';

before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
ZkethToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
bitgo.safeRegister(name, coinConstructor);
});
bitgo.initializeTestVars();
zkethTokenCoin = bitgo.coin(tokenName);
});

it('should return constants', function () {
zkethTokenCoin.getChain().should.equal('tzketh:link');
zkethTokenCoin.getBaseChain().should.equal('tzketh');
zkethTokenCoin.getFullName().should.equal('Zketh Token');
zkethTokenCoin.getBaseFactor().should.equal(1e18);
zkethTokenCoin.type.should.equal(tokenName);
zkethTokenCoin.name.should.equal('zkSync Test LINK');
zkethTokenCoin.coin.should.equal('tzketh');
zkethTokenCoin.network.should.equal('Testnet');
zkethTokenCoin.decimalPlaces.should.equal(18);
});
});
6 changes: 6 additions & 0 deletions modules/sdk-core/src/bitgo/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ interface EnvironmentTemplate {
arbiscanApiToken?: string;
optimisticEtherscanBaseUrl?: string;
optimisticEtherscanApiToken?: string;
zksyncExplorerBaseUrl?: string;
zksyncExplorerApiToken?: string;
stellarFederationServerUrl?: string;
eosNodeUrls: string[];
nearNodeUrls: string[];
Expand Down Expand Up @@ -108,6 +110,8 @@ const mainnetBase: EnvironmentTemplate = {
arbiscanApiToken: process.env.ARBISCAN_API_TOKEN,
optimisticEtherscanBaseUrl: 'https://api-optimistic.etherscan.io',
optimisticEtherscanApiToken: process.env.OPTIMISTIC_ETHERSCAN_API_TOKEN,
zksyncExplorerBaseUrl: 'https://block-explorer-api.mainnet.zksync.io',
zksyncExplorerApiToken: process.env.ZKSYNC_EXPLORER_API_TOKEN,
eosNodeUrls: ['https://bp.cryptolions.io', 'https://api.eosnewyork.io', 'https://api.eosdetroit.io'],
nearNodeUrls: ['https://rpc.mainnet.near.org'],
solNodeUrl: 'https://api.mainnet-beta.solana.com',
Expand Down Expand Up @@ -148,6 +152,8 @@ const testnetBase: EnvironmentTemplate = {
arbiscanApiToken: process.env.ARBISCAN_API_TOKEN,
optimisticEtherscanBaseUrl: 'https://api-sepolia-optimistic.etherscan.io',
optimisticEtherscanApiToken: process.env.OPTIMISTIC_ETHERSCAN_API_TOKEN,
zksyncExplorerBaseUrl: 'https://block-explorer-api.sepolia.zksync.dev',
zksyncExplorerApiToken: process.env.ZKSYNC_EXPLORER_API_TOKEN,
// kylin eos endpoints found here
// https://github.com/cryptokylin/CryptoKylin-Testnet#http-api-list
// https://docs.liquidapps.io/liquidapps-documentation/eosio-guides/testnet-creation-guides/creating-cryptokylin-account#setup
Expand Down
100 changes: 100 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ export class OpethERC20Token extends ContractAddressDefinedToken {
}
}

/**
* The zkSync network support tokens
* zkSync Tokens are ERC20 tokens
*/
export class ZkethERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}

/**
* The Xrp network supports tokens
* Xrp tokens are identified by their issuer address
Expand Down Expand Up @@ -1876,6 +1886,96 @@ export function topethErc20(
);
}

/**
* Factory function for zkethErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to zkSync mainnet network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function zkethErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.zkSync,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new ZkethERC20Token({
id,
name,
fullName,
network,
contractAddress,
prefix,
suffix,
features,
decimalPlaces,
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.ETH,
})
);
}

/**
* Factory function for zkSync Sepolia testnet zkethErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to the zkSync sepolia test network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function tzkethErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.test.zkSync,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return zkethErc20(
id,
name,
fullName,
decimalPlaces,
contractAddress,
asset,
features,
prefix,
suffix,
network,
primaryKeyCurve
);
}

/**
* Factory function for xrp token instances.
*
Expand Down
6 changes: 6 additions & 0 deletions modules/statics/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,12 @@ export enum UnderlyingAsset {
// Optimism testnet tokens
'topeth:terc18dp' = 'topeth:terc18dp',

// zkSync mainnet tokens
'zketh:link' = 'zketh:link',

// zkSync testnet tokens
'tzketh:link' = 'tzketh:link',

ERC721 = 'erc721',
ERC1155 = 'erc1155',
NONSTANDARD = 'nonstandard',
Expand Down
18 changes: 18 additions & 0 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
tstellarToken,
ttronToken,
txrpToken,
tzkethErc20,
zkethErc20,
} from './account';
import { ada } from './ada';
import { avaxp } from './avaxp';
Expand Down Expand Up @@ -14082,6 +14084,22 @@ export const coins = CoinMap.fromCoins([
'0xe9df68a54bba438c8a6192e95f0f2c53ac93d997',
UnderlyingAsset['topeth:terc18dp']
),
zkethErc20(
'53f0e845-f415-44d3-8517-7565dc346390',
'zketh:link',
'Chainlink Token',
18,
'0x082fade8b84b18c441d506e1d3a43a387cc59d20',
UnderlyingAsset['zketh:link']
),
tzkethErc20(
'ef49b6d1-b7a7-4c5c-8c53-43d22c15cc17',
'tzketh:link',
'zkSync Test LINK',
18,
'0xcccb29bac5ad81290383643c6fb38130cda9d881',
UnderlyingAsset['tzketh:link']
),
txrpToken(
'8ef16158-1015-4a67-b6fe-db669c18ab2b',
'txrp:tst-rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
Expand Down
Loading

0 comments on commit 44bb681

Please sign in to comment.