diff --git a/modules/sdk-coin-apt/test/unit/apt.ts b/modules/sdk-coin-apt/test/unit/apt.ts index ffbbab4796..41453780c8 100644 --- a/modules/sdk-coin-apt/test/unit/apt.ts +++ b/modules/sdk-coin-apt/test/unit/apt.ts @@ -18,7 +18,7 @@ import { Network, } from '@aptos-labs/ts-sdk'; import utils from '../../src/lib/utils'; -import { coins } from '@bitgo/statics'; +import { coins, GasTankAccountCoin } from '@bitgo/statics'; describe('APT:', function () { let bitgo: TestBitGoAPI; @@ -52,6 +52,8 @@ describe('APT:', function () { it('should return the right info', function () { const apt = bitgo.coin('apt'); const tapt = bitgo.coin('tapt'); + const aptStatics = coins.get('apt') as GasTankAccountCoin; + const taptStatics = coins.get('tapt') as GasTankAccountCoin; apt.getChain().should.equal('apt'); apt.getFamily().should.equal('apt'); @@ -62,6 +64,11 @@ describe('APT:', function () { tapt.getFamily().should.equal('apt'); tapt.getFullName().should.equal('Testnet Aptos'); tapt.getBaseFactor().should.equal(1e8); + + aptStatics.gasTankLowBalanceAlertFactor.should.equal(400); + taptStatics.gasTankLowBalanceAlertFactor.should.equal(400); + aptStatics.gasTankMinBalanceRecommendationFactor.should.equal(1000); + taptStatics.gasTankMinBalanceRecommendationFactor.should.equal(1000); }); it('is valid pub', function () { diff --git a/modules/statics/src/account.ts b/modules/statics/src/account.ts index 23cfe84014..796f3aa33f 100644 --- a/modules/statics/src/account.ts +++ b/modules/statics/src/account.ts @@ -66,6 +66,13 @@ export class AccountCoin extends BaseCoin { } } +export interface GasTankAccountConstructorOptions extends AccountConstructorOptions { + // low gas tank balance alert threshold is calculated as (feeEstimate x gasTankLowBalanceAlertFactor) + gasTankLowBalanceAlertFactor: number; + // min gas tank balance recommendation is calculated as (feeEstimate x gasTankMinBalanceRecommendationFactor) + gasTankMinBalanceRecommendationFactor: number; +} + export interface Erc20ConstructorOptions extends AccountConstructorOptions { contractAddress: string; } @@ -134,6 +141,18 @@ export class AccountCoinToken extends AccountCoin { } } +export class GasTankAccountCoin extends AccountCoin { + public gasTankLowBalanceAlertFactor: number; + public gasTankMinBalanceRecommendationFactor: number; + constructor(options: GasTankAccountConstructorOptions) { + super({ + ...options, + }); + this.gasTankLowBalanceAlertFactor = options.gasTankLowBalanceAlertFactor; + this.gasTankMinBalanceRecommendationFactor = options.gasTankMinBalanceRecommendationFactor; + } +} + /** * Some blockchains support tokens which are defined by an address at which they have a smart contract deployed. * Examples are ERC20 tokens, and the equivalent on other chains. @@ -547,6 +566,60 @@ export function account( ); } +/** + * Factory function for gas tank account coin instances. + * + * @param id uuid v4 + * @param name unique identifier of the coin + * @param fullName Complete human-readable name of the coin + * @param network Network object for this coin + * @param decimalPlaces Number of decimal places this coin supports (divisibility exponent) + * @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin. + * @param baseUnit + * @param features Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin` + * @param primaryKeyCurve The elliptic curve for this chain/token + * @param gasTankLowBalanceAlertFactor Low gas tank balance alert threshold = (feeEstimate x gasTankLowBalanceAlertFactor) + * @param gasTankMinBalanceRecommendationFactor Min gas tank balance recommendation = (feeEstimate x gasTankMinBalanceRecommendationFactor) + * @param prefix Optional coin prefix. Defaults to empty string + * @param suffix Optional coin suffix. Defaults to coin name. + * @param isToken Whether or not this account coin is a token of another coin + */ +export function gasTankAccount( + id: string, + name: string, + fullName: string, + network: AccountNetwork, + decimalPlaces: number, + asset: UnderlyingAsset, + baseUnit: BaseUnit, + features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES, + primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1, + gasTankLowBalanceAlertFactor = 2, + gasTankMinBalanceRecommendationFactor = 10, + prefix = '', + suffix: string = name.toUpperCase(), + isToken = false +) { + return Object.freeze( + new GasTankAccountCoin({ + id, + name, + fullName, + network, + prefix, + suffix, + baseUnit, + features, + decimalPlaces, + isToken, + asset, + primaryKeyCurve, + gasTankLowBalanceAlertFactor, + gasTankMinBalanceRecommendationFactor, + }) + ); +} + /** * Factory function for erc20 token instances. * diff --git a/modules/statics/src/coins.ts b/modules/statics/src/coins.ts index a460261cf1..939dcd6bea 100644 --- a/modules/statics/src/coins.ts +++ b/modules/statics/src/coins.ts @@ -12,6 +12,7 @@ import { erc20CompatibleAccountCoin, erc721, fiat, + gasTankAccount, hederaCoin, hederaToken, nonstandardToken, @@ -1156,7 +1157,7 @@ export const coins = CoinMap.fromCoins([ BaseUnit.ETH, EVM_FEATURES ), - account( + gasTankAccount( '75a71e9c-e3a0-4852-8e4b-9613ffed2a4c', 'apt', 'Aptos', @@ -1165,9 +1166,11 @@ export const coins = CoinMap.fromCoins([ UnderlyingAsset.APT, BaseUnit.APT, APT_FEATURES, - KeyCurve.Ed25519 + KeyCurve.Ed25519, + 400, + 1000 ), - account( + gasTankAccount( '7aca10bf-79dd-428b-aeb6-54f03f9aec0f', 'tapt', 'Testnet Aptos', @@ -1176,7 +1179,9 @@ export const coins = CoinMap.fromCoins([ UnderlyingAsset.APT, BaseUnit.APT, APT_FEATURES, - KeyCurve.Ed25519 + KeyCurve.Ed25519, + 400, + 1000 ), account( 'a08453f0-a3be-4875-b82b-6b0c9bfa53e6', diff --git a/modules/statics/src/index.ts b/modules/statics/src/index.ts index fc586f1431..b64cb35196 100644 --- a/modules/statics/src/index.ts +++ b/modules/statics/src/index.ts @@ -8,6 +8,7 @@ export { UtxoCoin } from './utxo'; export { LightningCoin } from './lightning'; export { AccountCoin, + GasTankAccountCoin, CeloCoin, ContractAddressDefinedToken, Erc20Coin,