-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(sdk-coin-bera): add bera token support
- Loading branch information
Showing
11 changed files
with
243 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import { coins, EthLikeTokenConfig } from '@bitgo/statics'; | ||
import { BitGoBase, CoinConstructor, common, NamedCoinConstructor } from '@bitgo/sdk-core'; | ||
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth'; | ||
|
||
import { TransactionBuilder } from './lib'; | ||
|
||
export { EthLikeTokenConfig }; | ||
|
||
export class BeraToken extends EthLikeToken { | ||
public readonly tokenConfig: EthLikeTokenConfig; | ||
static coinNames: CoinNames = { | ||
Mainnet: 'bera', | ||
Testnet: 'tbera', | ||
}; | ||
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) { | ||
super(bitgo, tokenConfig, BeraToken.coinNames); | ||
} | ||
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor { | ||
return super.createTokenConstructor(config, BeraToken.coinNames); | ||
} | ||
|
||
static createTokenConstructors(): NamedCoinConstructor[] { | ||
return super.createTokenConstructors(BeraToken.coinNames); | ||
} | ||
|
||
protected getTransactionBuilder(): TransactionBuilder { | ||
return new TransactionBuilder(coins.get(this.getBaseChain())); | ||
} | ||
|
||
/** | ||
* Make a query to Berachain explorer for information such as balance, token balance, solidity calls | ||
* @param {Object} query key-value pairs of parameters to append after /api | ||
* @returns {Promise<Object>} response Berachain explorer | ||
*/ | ||
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> { | ||
const apiToken = common.Environments[this.bitgo.getEnv()].beraExplorerApiToken; | ||
const explorerUrl = common.Environments[this.bitgo.getEnv()].beraExplorerBaseUrl; | ||
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken); | ||
} | ||
|
||
getFullName(): string { | ||
return 'Bera Token'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './bera'; | ||
export * from './tbera'; | ||
export * from './beraToken'; | ||
export * from './lib'; | ||
export * from './register'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { BitGoBase } from '@bitgo/sdk-core'; | ||
import { Bera } from './bera'; | ||
import { Tbera } from './tbera'; | ||
import { BeraToken } from './beraToken'; | ||
|
||
export const register = (sdk: BitGoBase): void => { | ||
sdk.register('bera', Bera.createInstance); | ||
sdk.register('tbera', Tbera.createInstance); | ||
BeraToken.createTokenConstructors().forEach(({ name, coinConstructor }) => { | ||
sdk.register(name, coinConstructor); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { BeraToken } from '../../src'; | ||
|
||
describe('Bera Token:', function () { | ||
let bitgo: TestBitGoAPI; | ||
let bgtTokenCoin; | ||
const tokenName = 'tbera:bgt'; | ||
|
||
before(function () { | ||
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' }); | ||
BeraToken.createTokenConstructors().forEach(({ name, coinConstructor }) => { | ||
bitgo.safeRegister(name, coinConstructor); | ||
}); | ||
bitgo.initializeTestVars(); | ||
bgtTokenCoin = bitgo.coin(tokenName); | ||
}); | ||
|
||
it('should return constants', function () { | ||
bgtTokenCoin.getChain().should.equal('tbera:bgt'); | ||
bgtTokenCoin.getBaseChain().should.equal('tbera'); | ||
bgtTokenCoin.getFullName().should.equal('Bera Token'); | ||
bgtTokenCoin.getBaseFactor().should.equal(1e18); | ||
bgtTokenCoin.type.should.equal(tokenName); | ||
bgtTokenCoin.name.should.equal('Bera Testnet BGT'); | ||
bgtTokenCoin.coin.should.equal('tbera'); | ||
bgtTokenCoin.network.should.equal('Testnet'); | ||
bgtTokenCoin.decimalPlaces.should.equal(18); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters