Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
EthLikeCoin,
EvmCoin,
Flr,
FlrToken,
HashToken,
TethLikeCoin,
FiatAED,
Expand Down Expand Up @@ -531,6 +532,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register(name, coinConstructor)
);

FlrToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
coinFactory.register(name, coinConstructor);
});

// Generic ERC20 token registration for coins with SUPPORTS_ERC20 feature
coins
.filter((coin) => coin.features.includes(CoinFeature.SUPPORTS_ERC20) && !coin.isToken)
Expand Down Expand Up @@ -963,6 +968,9 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
case 'hash':
case 'thash':
return HashToken.createTokenConstructor(tokenConfig as CosmosTokenConfig);
case 'flr':
case 'tflr':
return FlrToken.createTokenConstructor(tokenConfig as EthLikeTokenConfig);
default:
return undefined;
}
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 @@ -31,7 +31,7 @@ import { Eos, EosToken, Teos } from '@bitgo/sdk-coin-eos';
import { Etc, Tetc } from '@bitgo/sdk-coin-etc';
import { Erc20Token, Erc721Token, Eth, Gteth, Hteth, Teth } from '@bitgo/sdk-coin-eth';
import { EvmCoin, EthLikeErc20Token } from '@bitgo/sdk-coin-evm';
import { Flr, Tflr } from '@bitgo/sdk-coin-flr';
import { Flr, Tflr, FlrToken } from '@bitgo/sdk-coin-flr';
import { Ethw } from '@bitgo/sdk-coin-ethw';
import { EthLikeCoin, TethLikeCoin } from '@bitgo/sdk-coin-ethlike';
import { Hash, Thash, HashToken } from '@bitgo/sdk-coin-hash';
Expand Down Expand Up @@ -107,7 +107,7 @@ export { Ethw };
export { EthLikeCoin, TethLikeCoin };
export { Etc, Tetc };
export { EvmCoin, EthLikeErc20Token };
export { Flr, Tflr };
export { Flr, Tflr, FlrToken };
export { Hash, Thash, HashToken };
export { Hbar, Thbar };
export { Icp, Ticp };
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 @@ -56,6 +56,7 @@ describe('Coins', () => {
VetToken: 1,
EthLikeErc20Token: 1,
HashToken: 1,
FlrToken: 1,
};
Object.keys(BitGoJS.Coin)
.filter((coinName) => !excludedKeys[coinName])
Expand Down
58 changes: 58 additions & 0 deletions modules/sdk-coin-flr/src/flrToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { coins, EthLikeTokenConfig } from '@bitgo/statics';
import { BitGoBase, CoinConstructor, common, MPCAlgorithm, NamedCoinConstructor } from '@bitgo/sdk-core';
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';

import { TransactionBuilder } from './lib';

export { EthLikeTokenConfig };

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

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

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

/** @inheritDoc **/
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}

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

/**
* Make a query to Flare explorer for information such as balance, token balance, solidity calls
* @param {Object} query key-value pairs of parameters to append after /api
* @param {string} apiKey optional API key to use instead of the one from the environment
* @returns {Promise<Object>} response from Flare explorer
*/
async recoveryBlockchainExplorerQuery(
query: Record<string, string>,
apiKey?: string
): Promise<Record<string, unknown>> {
const apiToken = apiKey || common.Environments[this.bitgo.getEnv()].flrExplorerApiToken;
const explorerUrl = common.Environments[this.bitgo.getEnv()].flrExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
}

getFullName(): string {
return 'Flare Token';
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-flr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './lib';
export * from './flr';
export * from './tflr';
export * from './register';
export * from './flrToken';
4 changes: 4 additions & 0 deletions modules/sdk-coin-flr/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Flr } from './flr';
import { Tflr } from './tflr';
import { FlrToken } from './flrToken';

export const register = (sdk: BitGoBase): void => {
sdk.register('flr', Flr.createInstance);
sdk.register('tflr', Tflr.createInstance);
FlrToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
});
};
31 changes: 31 additions & 0 deletions modules/sdk-coin-flr/test/unit/flrToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';

import { FlrToken } from '../../src/flrToken';

describe('Flare Token:', function () {
let bitgo: TestBitGoAPI;
let flrTokenCoin;
const tokenName = 'tflr:wflr';

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

it('should return constants', function () {
flrTokenCoin.getChain().should.equal('tflr:wflr');
flrTokenCoin.getBaseChain().should.equal('tflr');
flrTokenCoin.getFullName().should.equal('Flare Token');
flrTokenCoin.getBaseFactor().should.equal(1e18);
flrTokenCoin.type.should.equal(tokenName);
flrTokenCoin.name.should.equal('Wrapped Flare Testnet');
flrTokenCoin.coin.should.equal('tflr');
flrTokenCoin.network.should.equal('Testnet');
flrTokenCoin.decimalPlaces.should.equal(18);
});
});
100 changes: 100 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ export class WorldERC20Token extends ContractAddressDefinedToken {
}
}

/**
* The Flr Chain network supports tokens
* Flr Chain Tokens are ERC20 tokens
*/
export class FlrERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}

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

/**
* Factory function for FlrErc20 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 Flr Chain 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 flrErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.flr,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new FlrERC20Token({
id,
name,
fullName,
network,
contractAddress,
prefix,
suffix,
features,
decimalPlaces,
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.ETH,
})
);
}

/**
* Factory function for Flr testnet FlrErc20 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 Flr Chain 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 tflrErc20(
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.flr,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return flrErc20(
id,
name,
fullName,
decimalPlaces,
contractAddress,
asset,
features,
prefix,
suffix,
network,
primaryKeyCurve
);
}

/**
* Factory function for xrp token instances.
*
Expand Down
20 changes: 20 additions & 0 deletions modules/statics/src/allCoinsAndTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
erc20CompatibleAccountCoin,
erc721,
fiat,
flrErc20,
gasTankAccount,
hederaCoin,
hederaToken,
Expand All @@ -30,6 +31,7 @@ import {
teosToken,
terc1155,
terc721,
tflrErc20,
topethErc20,
tpolyxToken,
tronToken,
Expand Down Expand Up @@ -3952,6 +3954,24 @@ export const allCoinsAndTokens = [
UnderlyingAsset['tworld:usdc'],
[...AccountCoin.DEFAULT_FEATURES, CoinFeature.STABLECOIN]
),
flrErc20(
'1a38ab45-a789-4810-8d1d-2970af380753',
'flr:wflr',
'Wrapped Flare',
18,
'0x1d80c49bbbcd1c0911346656b529df9e5c2f783d',
UnderlyingAsset['flr:wflr'],
[...AccountCoin.DEFAULT_FEATURES, CoinFeature.STABLECOIN]
),
tflrErc20(
'ff4dd56d-8fa0-4e92-b764-88c56ea48549',
'tflr:wflr',
'Wrapped Flare Testnet',
18,
'0xab6fad89389b73dbc887d31206a26fd88d719d1f',
UnderlyingAsset['tflr:wflr'],
[...AccountCoin.DEFAULT_FEATURES, CoinFeature.STABLECOIN]
),
txrpToken(
'8ef16158-1015-4a67-b6fe-db669c18ab2b',
'txrp:tst-rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
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 @@ -2814,6 +2814,12 @@ export enum UnderlyingAsset {
'tworld:wld' = 'tworld:wld',
'tworld:usdc' = 'tworld:usdc',

// Flr mainnet tokens
'flr:wflr' = 'flr:wflr',

// Flr testnet tokens
'tflr:wflr' = 'tflr:wflr',

ERC721 = 'erc721',
ERC1155 = 'erc1155',
NONSTANDARD = 'nonstandard',
Expand Down
Loading