Skip to content

Commit 6e92993

Browse files
committed
refactor: check if v4 factory is defined
TICKET: WP-6461
1 parent 3292e9d commit 6e92993

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,16 +2732,18 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27322732
return {};
27332733
}
27342734

2735-
getFactoryAndImplContractAddresses(walletVersion: number | undefined): {
2735+
getForwarderFactoryAndImplContractAddresses(walletVersion: number | undefined): {
27362736
forwarderFactoryAddress: string;
27372737
forwarderImplementationAddress: string;
27382738
} {
27392739
const ethNetwork = this.getNetwork();
27402740
if (walletVersion && (walletVersion === 5 || walletVersion === 4)) {
2741-
return {
2742-
forwarderFactoryAddress: ethNetwork?.walletV4ForwarderFactoryAddress as string,
2743-
forwarderImplementationAddress: ethNetwork?.walletV4ForwarderImplementationAddress as string,
2744-
};
2741+
if (ethNetwork?.walletV4ForwarderFactoryAddress && ethNetwork?.walletV4ForwarderImplementationAddress) {
2742+
return {
2743+
forwarderFactoryAddress: ethNetwork?.walletV4ForwarderFactoryAddress as string,
2744+
forwarderImplementationAddress: ethNetwork?.walletV4ForwarderImplementationAddress as string,
2745+
};
2746+
}
27452747
}
27462748
return {
27472749
forwarderFactoryAddress: ethNetwork?.forwarderFactoryAddress as string,
@@ -2795,9 +2797,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27952797
);
27962798
}
27972799

2798-
const { forwarderFactoryAddress, forwarderImplementationAddress } = this.getFactoryAndImplContractAddresses(
2799-
params.walletVersion
2800-
);
2800+
const { forwarderFactoryAddress, forwarderImplementationAddress } =
2801+
this.getForwarderFactoryAndImplContractAddresses(params.walletVersion);
28012802
const initcode = getProxyInitcode(forwarderImplementationAddress);
28022803
const saltBuffer = ethUtil.setLengthLeft(
28032804
Buffer.from(ethUtil.padToEven(ethUtil.stripHexPrefix(coinSpecific.salt || '')), 'hex'),

modules/sdk-coin-polygon/test/unit/polygon.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,4 +1315,49 @@ describe('Polygon', function () {
13151315
);
13161316
});
13171317
});
1318+
1319+
describe('Test isWalletAddress', function () {
1320+
it('verify address for tpolygon', async function () {
1321+
const keychains = [
1322+
{
1323+
id: '6920c05e0b195abd8ed0bb0a5df32cdc',
1324+
source: 'user',
1325+
type: 'tss',
1326+
commonKeychain:
1327+
'02f929f92c25eaccb0e3ebaa0f5ed900c5ad30ba94f8444dc89c94e12f01aa5371522d810b8918ecc9e41eb901352df1c7977420fbaf9b8617f61b780b32b2ccad',
1328+
},
1329+
{
1330+
id: '6920c05e93c3b1c9e5006bf00a3cf016',
1331+
source: 'backup',
1332+
type: 'tss',
1333+
commonKeychain:
1334+
'02f929f92c25eaccb0e3ebaa0f5ed900c5ad30ba94f8444dc89c94e12f01aa5371522d810b8918ecc9e41eb901352df1c7977420fbaf9b8617f61b780b32b2ccad',
1335+
},
1336+
{
1337+
id: '6920c05d9ebee0100ec4a8aa7e300c02',
1338+
source: 'bitgo',
1339+
type: 'tss',
1340+
commonKeychain:
1341+
'02f929f92c25eaccb0e3ebaa0f5ed900c5ad30ba94f8444dc89c94e12f01aa5371522d810b8918ecc9e41eb901352df1c7977420fbaf9b8617f61b780b32b2ccad',
1342+
},
1343+
];
1344+
1345+
const params = {
1346+
address: '0x4e9fc44697f4135455157396485f6fe8f909752f',
1347+
baseAddress: '0x8cf5ebd51585d159c4a1ca36178f9ad0fd7a594c',
1348+
coinSpecific: {
1349+
salt: '0xd',
1350+
forwarderVersion: 4,
1351+
feeAddress: '0x44dcb3504e323a3d70142036a99e2d4bba3f2270',
1352+
},
1353+
keychains,
1354+
index: 13,
1355+
walletVersion: 5,
1356+
};
1357+
1358+
const coin = bitgo.coin('tpolygon');
1359+
const isWalletAddr = await coin.isWalletAddress(params);
1360+
isWalletAddr.should.equal(true);
1361+
});
1362+
});
13181363
});

modules/statics/src/networks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,8 @@ class Polygon extends Mainnet implements EthereumNetwork {
11861186
batcherContractAddress = '0x3e1e5d78e44f15593b3b61ed278f12c27f0ff33e';
11871187
nativeCoinOperationHashPrefix = 'POLYGON';
11881188
tokenOperationHashPrefix = 'POLYGON-ERC20';
1189+
walletV4ForwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a';
1190+
walletV4ForwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
11891191
}
11901192

11911193
class PolygonTestnet extends Testnet implements EthereumNetwork {
@@ -1201,6 +1203,8 @@ class PolygonTestnet extends Testnet implements EthereumNetwork {
12011203
batcherContractAddress = '0x3e1e5d78e44f15593b3b61ed278f12c27f0ff33e';
12021204
nativeCoinOperationHashPrefix = 'POLYGON';
12031205
tokenOperationHashPrefix = 'POLYGON-ERC20';
1206+
walletV4ForwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a';
1207+
walletV4ForwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12041208
}
12051209

12061210
class Optimism extends Mainnet implements EthereumNetwork {
@@ -1215,6 +1219,8 @@ class Optimism extends Mainnet implements EthereumNetwork {
12151219
forwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12161220
walletFactoryAddress = '0x809ee567e413543af1caebcdb247f6a67eafc8dd';
12171221
walletImplementationAddress = '0x944fef03af368414f29dc31a72061b8d64f568d2';
1222+
walletV4ForwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a';
1223+
walletV4ForwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12181224
batcherContractAddress = '0xebe27913fcc7510eadf10643a8f86bf5492a9541';
12191225
}
12201226

@@ -1230,6 +1236,8 @@ class OptimismTestnet extends Testnet implements EthereumNetwork {
12301236
forwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12311237
walletFactoryAddress = '0x809ee567e413543af1caebcdb247f6a67eafc8dd';
12321238
walletImplementationAddress = '0x944fef03af368414f29dc31a72061b8d64f568d2';
1239+
walletV4ForwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a';
1240+
walletV4ForwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12331241
batcherContractAddress = '0xebe27913fcc7510eadf10643a8f86bf5492a9541';
12341242
}
12351243

@@ -1253,6 +1261,8 @@ class ZkSyncTestnet extends Testnet implements EthereumNetwork {
12531261
tokenOperationHashPrefix = '300-ERC20';
12541262
forwarderFactoryAddress = '0xdd498702f44c4da08eb9e08d3f015eefe5cb71fc';
12551263
forwarderImplementationAddress = '0xbe69cae311191fb45e648ed20847f06fad2dbab4';
1264+
walletV4ForwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a';
1265+
walletV4ForwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b';
12561266
walletFactoryAddress = '0x4550e1e7616d3364877fc6c9324938dab678621a';
12571267
walletImplementationAddress = '0x92db2759d1dca129a0d9d46877f361be819184c4';
12581268
}

0 commit comments

Comments
 (0)