Skip to content

Commit

Permalink
Merge pull request #5615 from BitGo/coin-3185-fee-estimate-multiplyin…
Browse files Browse the repository at this point in the history
…g-factor

feat(statics): add GasTankAccountCoin
  • Loading branch information
bhavidhingra authored Feb 23, 2025
2 parents a94bd33 + b031d23 commit b33bf73
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
9 changes: 8 additions & 1 deletion modules/sdk-coin-apt/test/unit/apt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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 () {
Expand Down
73 changes: 73 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
13 changes: 9 additions & 4 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
erc20CompatibleAccountCoin,
erc721,
fiat,
gasTankAccount,
hederaCoin,
hederaToken,
nonstandardToken,
Expand Down Expand Up @@ -1156,7 +1157,7 @@ export const coins = CoinMap.fromCoins([
BaseUnit.ETH,
EVM_FEATURES
),
account(
gasTankAccount(
'75a71e9c-e3a0-4852-8e4b-9613ffed2a4c',
'apt',
'Aptos',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions modules/statics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { UtxoCoin } from './utxo';
export { LightningCoin } from './lightning';
export {
AccountCoin,
GasTankAccountCoin,
CeloCoin,
ContractAddressDefinedToken,
Erc20Coin,
Expand Down

0 comments on commit b33bf73

Please sign in to comment.