Skip to content

Commit 0de3c54

Browse files
Merge pull request #6630 from BitGo/SC-2516/fix-unsteth
fix(statics): fix unstETH support
2 parents 05827d5 + 0e57013 commit 0de3c54

File tree

8 files changed

+498
-12
lines changed

8 files changed

+498
-12
lines changed

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
Eos,
7676
EosToken,
7777
Erc20Token,
78+
Erc721Token,
7879
Etc,
7980
Eth,
8081
Ethw,
@@ -399,6 +400,12 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
399400
}
400401
);
401402

403+
Erc721Token.createTokenConstructors([...tokens.bitcoin.eth.nfts, ...tokens.testnet.eth.nfts]).forEach(
404+
({ name, coinConstructor }) => {
405+
coinFactory.register(name, coinConstructor);
406+
}
407+
);
408+
402409
StellarToken.createTokenConstructors([...tokens.bitcoin.xlm.tokens, ...tokens.testnet.xlm.tokens]).forEach(
403410
({ name, coinConstructor }) => {
404411
coinFactory.register(name, coinConstructor);
@@ -862,7 +869,11 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
862869
switch (tokenConfig.coin) {
863870
case 'eth':
864871
case 'hteth':
865-
return Erc20Token.createTokenConstructor(tokenConfig as Erc20TokenConfig);
872+
if (tokenConfig.type.includes('erc721')) {
873+
return Erc721Token.createTokenConstructor(tokenConfig as EthLikeTokenConfig);
874+
} else {
875+
return Erc20Token.createTokenConstructor(tokenConfig as Erc20TokenConfig);
876+
}
866877
case 'xlm':
867878
case 'txlm':
868879
return StellarToken.createTokenConstructor(tokenConfig as StellarTokenConfig);

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { Doge, Tdoge } from '@bitgo/sdk-coin-doge';
3030
import { Dot, Tdot } from '@bitgo/sdk-coin-dot';
3131
import { Eos, EosToken, Teos } from '@bitgo/sdk-coin-eos';
3232
import { Etc, Tetc } from '@bitgo/sdk-coin-etc';
33-
import { Erc20Token, Eth, Gteth, Hteth, Teth } from '@bitgo/sdk-coin-eth';
33+
import { Erc20Token, Erc721Token, Eth, Gteth, Hteth, Teth } from '@bitgo/sdk-coin-eth';
3434
import { EvmCoin } from '@bitgo/sdk-coin-evm';
3535
import { Flr, Tflr } from '@bitgo/sdk-coin-flr';
3636
import { Ethw } from '@bitgo/sdk-coin-ethw';
@@ -104,7 +104,7 @@ export { Doge, Tdoge };
104104
export { Dot, Tdot };
105105
export { Bcha, Tbcha };
106106
export { Eos, EosToken, Teos };
107-
export { Erc20Token, Eth, Gteth, Hteth, Teth };
107+
export { Erc20Token, Erc721Token, Eth, Gteth, Hteth, Teth };
108108
export { Ethw };
109109
export { EthLikeCoin, TethLikeCoin };
110110
export { Etc, Tetc };

modules/bitgo/test/browser/browser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Coins', () => {
1515
AbstractUtxoCoin: 1,
1616
AbstractLightningCoin: 1,
1717
Erc20Token: 1,
18+
Erc721Token: 1,
1819
EthLikeCoin: 1,
1920
TethLikeCoin: 1,
2021
OfcToken: 1,

modules/bitgo/test/v2/resources/amsTokenConfig.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@ export const reducedAmsTokenConfig = {
2121
contractAddress: '0x89a959b9184b4f8c8633646d5dfd049d2ebc983a',
2222
},
2323
],
24+
'terc721:unsteth': [
25+
{
26+
id: '49ff49ea-3355-4717-bbb0-5e8f5cae2201',
27+
fullName: 'Test Lido: stETH Withdrawal NFT',
28+
name: 'terc721:unsteth',
29+
prefix: '',
30+
suffix: '',
31+
baseUnit: 'wei',
32+
kind: 'crypto',
33+
family: 'eth',
34+
isToken: true,
35+
additionalFeatures: [],
36+
excludedFeatures: [],
37+
decimalPlaces: 0,
38+
asset: 'terc721:unsteth',
39+
network: {
40+
name: 'Hoodi',
41+
},
42+
contractAddress: '0xfe56573178f1bcdf53f01a6e9977670dcbbd9186',
43+
},
44+
],
2445
};

modules/bitgo/test/v2/unit/ams/ams.ts

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ describe('Asset metadata service', () => {
2525
});
2626

2727
it('should not fetch coin from custom coin factory when useAms is false', async () => {
28-
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: false } as any);
29-
bitgo.initializeTestVars();
30-
bitgo.initCoinFactory(reducedAmsTokenConfig);
28+
const bitgoNoAms = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: false } as any);
29+
bitgoNoAms.initializeTestVars();
30+
bitgoNoAms.initCoinFactory(reducedAmsTokenConfig);
3131
(() => {
32-
bitgo.coin('hteth:faketoken');
32+
bitgoNoAms.coin('hteth:faketoken');
3333
}).should.throw(
3434
'Coin or token type hteth:faketoken not supported or not compiled. Please be sure that you are using the latest version of BitGoJS. If using @bitgo/sdk-api, please confirm you have registered hteth:faketoken first.'
3535
);
3636
});
3737

3838
it('should be able to register a token in the coin factory', () => {
3939
const tokenName = 'hteth:faketoken';
40-
const amsToken = reducedAmsTokenConfig[tokenName][0];
41-
bitgo.registerToken(amsToken);
40+
bitgo.registerToken(tokenName);
4241
const coin = bitgo.coin(tokenName);
4342
should.exist(coin);
4443
coin.type.should.equal(tokenName);
@@ -47,6 +46,53 @@ describe('Asset metadata service', () => {
4746
coin.tokenContractAddress.should.equal('0x89a959b9184b4f8c8633646d5dfd049d2ebc983a');
4847
});
4948

49+
describe('ERC721 NFTs', () => {
50+
it('should create a custom coin factory from ams response', async () => {
51+
bitgo.initCoinFactory(reducedAmsTokenConfig);
52+
const coin = bitgo.coin('erc721:unsteth');
53+
should.exist(coin);
54+
coin.type.should.equal('erc721:unsteth');
55+
coin.name.should.equal('Lido: stETH Withdrawal NFT');
56+
coin.decimalPlaces.should.equal(0);
57+
coin.tokenContractAddress.should.equal('0x889edc2edab5f40e902b864ad4d7ade8e412f9b1');
58+
});
59+
60+
it('should be able to register an nft in the coin factory', () => {
61+
const nftName = 'terc721:unsteth';
62+
bitgo.registerToken(nftName);
63+
const coin = bitgo.coin(nftName);
64+
should.exist(coin);
65+
coin.type.should.equal(nftName);
66+
coin.name.should.equal('Test Lido: stETH Withdrawal NFT');
67+
coin.decimalPlaces.should.equal(0);
68+
coin.tokenContractAddress.should.equal('0xfe56573178f1bcdf53f01a6e9977670dcbbd9186');
69+
});
70+
71+
it('should fetch all assets from AMS and initialize the coin factory', async () => {
72+
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: true } as BitGoOptions);
73+
bitgo.initializeTestVars();
74+
75+
// Setup nocks
76+
nock(microservicesUri).get('/api/v1/assets/list/testnet').reply(200, reducedAmsTokenConfig);
77+
78+
await bitgo.registerAllTokens();
79+
const coin = bitgo.coin('terc721:unsteth');
80+
should.exist(coin);
81+
});
82+
83+
it('should fetch nft from default coin factory when useAms is false', () => {
84+
const bitgoNoAms = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: false } as BitGoOptions);
85+
bitgoNoAms.initializeTestVars();
86+
bitgoNoAms.initCoinFactory(reducedAmsTokenConfig);
87+
const coin: any = bitgoNoAms.coin('erc721:unsteth');
88+
should.exist(coin);
89+
coin.type.should.equal('erc721:unsteth');
90+
coin.name.should.equal('Lido: stETH Withdrawal NFT');
91+
coin.decimalPlaces.should.equal(0);
92+
coin.tokenContractAddress.should.equal('0x889edc2edab5f40e902b864ad4d7ade8e412f9b1');
93+
});
94+
});
95+
5096
it('should fetch all assets from AMS and initialize the coin factory', async () => {
5197
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: true } as BitGoOptions);
5298
bitgo.initializeTestVars();
@@ -61,10 +107,10 @@ describe('Asset metadata service', () => {
61107

62108
describe('registerToken', () => {
63109
it('should throw an error when useAms is false', async () => {
64-
const bitgo = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: false } as BitGoOptions);
65-
bitgo.initializeTestVars();
110+
const bitgoNoAms = TestBitGo.decorate(BitGo, { env: 'mock', microservicesUri, useAms: false } as BitGoOptions);
111+
bitgoNoAms.initializeTestVars();
66112

67-
await bitgo
113+
await bitgoNoAms
68114
.registerToken('hteth:faketoken')
69115
.should.be.rejectedWith('registerToken is only supported when useAms is set to true');
70116
});

0 commit comments

Comments
 (0)