Skip to content

Commit a97f367

Browse files
committed
feat: apply SecurityToken 3.0 changes
1 parent ce3d86d commit a97f367

File tree

17 files changed

+4260
-1628
lines changed

17 files changed

+4260
-1628
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Context } from '../LowLevel';
2+
import { SecurityToken } from '../SecurityToken';
3+
4+
export default class ContractWrapperFactory {
5+
static packVersion(versions: number[]) {
6+
return versions.join('.');
7+
}
8+
9+
/**
10+
* Given contract's address, this function will return a version agnostic contract wrapper.
11+
*/
12+
static wrapContract = async (contractName: string, address: string, context: Context) => {
13+
// First, wrap this address with a 'stub' wrapper in order to get deployed contract's version.
14+
const stubAbi = (await import(`../${contractName}/stub.abi`)).default;
15+
const stubClass = (await import(`../${contractName}/stub`)).default;
16+
const stubLowLevelContract = new stubClass({ address, abi: stubAbi, context });
17+
18+
const versionArray = await stubLowLevelContract.getVersion();
19+
const packedVersion = ContractWrapperFactory.packVersion(versionArray);
20+
21+
// Now that we know deployed contract version, we'll wrap it with a version specific contract wrapper.
22+
const ContractWrapper = (await import(`../${contractName}/${packedVersion}`)).default;
23+
const wrappedContract = new ContractWrapper({ address, context });
24+
return wrappedContract;
25+
};
26+
27+
static getSecurityToken = async (address: string, context: Context) => {
28+
return (await ContractWrapperFactory.wrapContract(
29+
'SecurityToken',
30+
address,
31+
context
32+
)) as SecurityToken;
33+
};
34+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ContractWrapperFactory from './ContractWrapperFactory';
2+
3+
export default ContractWrapperFactory;

src/LowLevel/DividendCheckpoint.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import {
1616
GetDividendsByCheckpointArgs,
1717
GetDividendArgs,
1818
SetDividendsWalletArgs,
19-
TaxWithholding, DividendModuleTypes } from './types';
19+
TaxWithholding,
20+
DividendModuleTypes,
21+
} from './types';
2022
import { fromUnixTimestamp, fromWei, toWei, fromDivisible, toAscii, getOptions } from './utils';
21-
23+
import ContractWrapperFactory from './ContractWrapperFactory';
2224

2325
interface InternalDividend {
2426
checkpointId: string;
@@ -144,10 +146,7 @@ export abstract class DividendCheckpoint<
144146

145147
public async getDividends() {
146148
const stAddress = await this.securityTokenAddress();
147-
const securityToken = new SecurityToken({
148-
address: stAddress,
149-
context: this.context,
150-
});
149+
const securityToken = await ContractWrapperFactory.getSecurityToken(stAddress, this.context);
151150

152151
const currentCheckpointIndex = await securityToken.currentCheckpointId();
153152
const checkpointIndexes = range(1, currentCheckpointIndex + 1);

0 commit comments

Comments
 (0)