From acd32aa823fb3c324344e60d7bb1100aeb83b0ad Mon Sep 17 00:00:00 2001 From: Jeremias Diaz Date: Mon, 13 Jan 2020 13:19:05 -0300 Subject: [PATCH 1/5] fix: refine Launch Tiered STO types Also throw an error when not supplying stable coin addresses in a SC fundraise --- .../SecurityToken/Issuance/Offerings.ts | 76 +++++++++++++++---- src/procedures/LaunchTieredSto.ts | 32 +++++++- src/types/index.ts | 4 +- 3 files changed, 94 insertions(+), 18 deletions(-) diff --git a/src/entities/SecurityToken/Issuance/Offerings.ts b/src/entities/SecurityToken/Issuance/Offerings.ts index aeb62c4..a228c22 100644 --- a/src/entities/SecurityToken/Issuance/Offerings.ts +++ b/src/entities/SecurityToken/Issuance/Offerings.ts @@ -24,22 +24,19 @@ interface LaunchTieredStoParams { currencies: Currency[]; raisedFundsWallet: string; unsoldTokensWallet: string; - stableCoinAddresses: string[]; + stableCoinAddresses?: string[]; customCurrency?: Partial; allowPreIssuance?: boolean; } -type OnlyEth = - | [Currency.ETH] - | [Currency.StableCoin, Currency.ETH] - | [Currency.ETH, Currency.StableCoin]; -type OnlyPoly = - | [Currency.POLY] +type OnlyEth = [Currency.ETH]; +type EthAndStableCoin = [Currency.StableCoin, Currency.ETH] | [Currency.ETH, Currency.StableCoin]; +type OnlyPoly = [Currency.POLY]; +type PolyAndStableCoin = | [Currency.StableCoin, Currency.POLY] | [Currency.POLY, Currency.StableCoin]; -type EthAndPoly = - | [Currency.ETH, Currency.POLY] - | [Currency.POLY, Currency.ETH] +type EthAndPoly = [Currency.ETH, Currency.POLY] | [Currency.POLY, Currency.ETH]; +type AllCurrencies = | [Currency.StableCoin, Currency.ETH, Currency.POLY] | [Currency.ETH, Currency.StableCoin, Currency.POLY] | [Currency.ETH, Currency.POLY, Currency.StableCoin] @@ -47,12 +44,28 @@ type EthAndPoly = | [Currency.POLY, Currency.StableCoin, Currency.ETH] | [Currency.POLY, Currency.ETH, Currency.StableCoin]; +interface LaunchTieredStoNoCustomCurrencyNoStableCoinParams + extends Omit, 'stableCoinAddresses'> { + currencies: OnlyEth | OnlyPoly | EthAndPoly; +} + interface LaunchTieredStoNoCustomCurrencyParams extends Omit { - currencies: OnlyEth | OnlyPoly | EthAndPoly; + currencies: EthAndStableCoin | PolyAndStableCoin | AllCurrencies; + stableCoinAddresses: string[]; } interface LaunchTieredStoCustomCurrencyEthParams extends LaunchTieredStoParams { + currencies: OnlyEth | EthAndStableCoin; + customCurrency: { + currencySymbol?: string; + ethOracleAddress: string; + }; + stableCoinAddresses: string[]; +} + +interface LaunchTieredStoCustomCurrencyEthNoStableCoinParams + extends Omit { currencies: OnlyEth; customCurrency: { currencySymbol?: string; @@ -61,6 +74,16 @@ interface LaunchTieredStoCustomCurrencyEthParams extends LaunchTieredStoParams { } interface LaunchTieredStoCustomCurrencyPolyParams extends LaunchTieredStoParams { + currencies: OnlyPoly | PolyAndStableCoin; + customCurrency: { + currencySymbol?: string; + polyOracleAddress: string; + }; + stableCoinAddresses: string[]; +} + +interface LaunchTieredStoCustomCurrencyPolyNoStableCoinParams + extends Omit { currencies: OnlyPoly; customCurrency: { currencySymbol?: string; @@ -69,6 +92,17 @@ interface LaunchTieredStoCustomCurrencyPolyParams extends LaunchTieredStoParams } interface LaunchTieredStoCustomCurrencyBothParams extends LaunchTieredStoParams { + currencies: AllCurrencies; + customCurrency: { + currencySymbol?: string; + ethOracleAddress: string; + polyOracleAddress: string; + }; + stableCoinAddresses: string[]; +} + +interface LaunchTieredStoCustomCurrencyBothNoStableCoinParams + extends Omit { currencies: EthAndPoly; customCurrency: { currencySymbol?: string; @@ -79,16 +113,28 @@ interface LaunchTieredStoCustomCurrencyBothParams extends LaunchTieredStoParams interface LaunchTieredStoMethod { (args: LaunchTieredStoNoCustomCurrencyParams): Promise< - TransactionQueue + TransactionQueue + >; + (args: LaunchTieredStoNoCustomCurrencyNoStableCoinParams): Promise< + TransactionQueue >; (args: LaunchTieredStoCustomCurrencyEthParams): Promise< - TransactionQueue + TransactionQueue + >; + (args: LaunchTieredStoCustomCurrencyEthNoStableCoinParams): Promise< + TransactionQueue >; (args: LaunchTieredStoCustomCurrencyPolyParams): Promise< - TransactionQueue + TransactionQueue + >; + (args: LaunchTieredStoCustomCurrencyPolyNoStableCoinParams): Promise< + TransactionQueue >; (args: LaunchTieredStoCustomCurrencyBothParams): Promise< - TransactionQueue + TransactionQueue + >; + (args: LaunchTieredStoCustomCurrencyBothNoStableCoinParams): Promise< + TransactionQueue >; } diff --git a/src/procedures/LaunchTieredSto.ts b/src/procedures/LaunchTieredSto.ts index 877d1ff..2741ff9 100644 --- a/src/procedures/LaunchTieredSto.ts +++ b/src/procedures/LaunchTieredSto.ts @@ -35,7 +35,7 @@ export class LaunchTieredSto extends Procedure; allowPreIssuing?: boolean; } @@ -743,7 +743,7 @@ export enum TransferStatusCode { * @param T - type to exclude from * @param K - name of the property that will be excluded */ -export type Omit = { [key in Exclude]: T[key] }; +export type Omit = Pick>; /** * Transaction method from the contract-wrappers package From 47e08ccd8ed30a3803443fa2c9b14fe79adbfb3e Mon Sep 17 00:00:00 2001 From: Jeremias Diaz Date: Mon, 13 Jan 2020 19:19:10 -0300 Subject: [PATCH 2/5] fix: only transfer POLY to ST if the current balance is insufficient --- src/procedures/LaunchTieredSto.ts | 37 +++++++++---------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/procedures/LaunchTieredSto.ts b/src/procedures/LaunchTieredSto.ts index 2741ff9..e0f99e0 100644 --- a/src/procedures/LaunchTieredSto.ts +++ b/src/procedures/LaunchTieredSto.ts @@ -123,10 +123,16 @@ export class LaunchTieredSto extends Procedure Date: Mon, 13 Jan 2020 19:36:58 -0300 Subject: [PATCH 3/5] test: test conditional transfer --- src/procedures/__tests__/LaunchTieredSto.ts | 32 +++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/procedures/__tests__/LaunchTieredSto.ts b/src/procedures/__tests__/LaunchTieredSto.ts index 65170d7..2117073 100644 --- a/src/procedures/__tests__/LaunchTieredSto.ts +++ b/src/procedures/__tests__/LaunchTieredSto.ts @@ -136,10 +136,35 @@ describe('LaunchTieredSto', () => { }); describe('LaunchTieredSto', () => { - test('should add the transaction to the queue to launch usd tiered sto and add a procedure to transfer erc20 token', async () => { + test('should add the transaction to the queue to launch usd tiered sto', async () => { + const addTransactionSpy = spy(target, 'addTransaction'); + securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); + + // Real call + await target.prepareTransactions(); + + // Verifications + expect( + addTransactionSpy + .getCall(0) + .calledWith(securityTokenMock.getMockInstance().addModuleWithLabel) + ).toEqual(true); + expect(addTransactionSpy.getCall(0).lastArg.fees).toEqual({ + usd: costIn, + poly: costInPoly, + }); + expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableTieredSto); + expect(addTransactionSpy.callCount).toEqual(1); + }); + + test("should transfer POLY to the security token if the token's balance doesn't cover the launch fee", async () => { const addProcedureSpy = spy(target, 'addProcedure'); const addTransactionSpy = spy(target, 'addTransaction'); securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); + polyTokenMock + .mock('balanceOf', Promise.resolve(new BigNumber(20))) + .withArgs({ owner: securityTokenAddress }) + .returns(Promise.resolve(new BigNumber(1))); // Real call await target.prepareTransactions(); @@ -156,12 +181,11 @@ describe('LaunchTieredSto', () => { }); expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableTieredSto); expect(addTransactionSpy.callCount).toEqual(1); - expect(addProcedureSpy.getCall(0).calledWithExactly(TransferErc20)).toEqual(true); + expect(addProcedureSpy.getCall(0).calledWith(TransferErc20)); expect(addProcedureSpy.callCount).toEqual(1); }); test('should add the transaction to the queue to launch usd tiered sto with cost in poly', async () => { - const addProcedureSpy = spy(target, 'addProcedure'); const addTransactionSpy = spy(target, 'addTransaction'); securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); moduleFactoryMock.mock('isCostInPoly', Promise.resolve(true)); @@ -181,8 +205,6 @@ describe('LaunchTieredSto', () => { }); expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableTieredSto); expect(addTransactionSpy.callCount).toEqual(1); - expect(addProcedureSpy.getCall(0).calledWithExactly(TransferErc20)).toEqual(true); - expect(addProcedureSpy.callCount).toEqual(1); }); test('should throw if corresponding usd tiered sto event is not fired', async () => { From 3cf8dbd8515a3e92a07a4aecc6aa8ae8400d64b1 Mon Sep 17 00:00:00 2001 From: Jeremias Diaz Date: Tue, 14 Jan 2020 11:41:19 -0300 Subject: [PATCH 4/5] feat: only transfer POLY to the ST if missing --- src/procedures/LaunchSimpleSto.ts | 14 +++++++--- src/procedures/__tests__/LaunchSimpleSto.ts | 30 ++++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/procedures/LaunchSimpleSto.ts b/src/procedures/LaunchSimpleSto.ts index b9b37ab..0917afc 100644 --- a/src/procedures/LaunchSimpleSto.ts +++ b/src/procedures/LaunchSimpleSto.ts @@ -74,10 +74,16 @@ export class LaunchSimpleSto extends Procedure { describe('LaunchSimpleSto', () => { test('should add a transaction to the queue to launch a capped sto with cost in usd', async () => { + const addTransactionSpy = spy(target, 'addTransaction'); + securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); + + // Real call + await target.prepareTransactions(); + + // Verifications + expect( + addTransactionSpy + .getCall(0) + .calledWith(securityTokenMock.getMockInstance().addModuleWithLabel) + ).toEqual(true); + expect(addTransactionSpy.getCall(0).lastArg.fees).toEqual({ + usd: costInUsd, + poly: costInPoly, + }); + expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableCappedSto); + expect(addTransactionSpy.callCount).toEqual(1); + }); + + test("should transfer POLY to the security token if the token's balance doesn't cover the launch fee", async () => { const addProcedureSpy = spy(target, 'addProcedure'); const addTransactionSpy = spy(target, 'addTransaction'); securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); + polyTokenMock + .mock('balanceOf', Promise.resolve(new BigNumber(20))) + .withArgs({ owner: securityTokenAddress }) + .returns(Promise.resolve(new BigNumber(1))); // Real call await target.prepareTransactions(); @@ -143,12 +168,11 @@ describe('LaunchSimpleSto', () => { }); expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableCappedSto); expect(addTransactionSpy.callCount).toEqual(1); - expect(addProcedureSpy.getCall(0).calledWithExactly(TransferErc20)).toEqual(true); + expect(addProcedureSpy.getCall(0).calledWith(TransferErc20)); expect(addProcedureSpy.callCount).toEqual(1); }); test('should add a transaction to the queue to launch a capped sto with cost in poly', async () => { - const addProcedureSpy = spy(target, 'addProcedure'); const addTransactionSpy = spy(target, 'addTransaction'); moduleFactoryMock.mock('isCostInPoly', Promise.resolve(true)); @@ -169,8 +193,6 @@ describe('LaunchSimpleSto', () => { }); expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.EnableCappedSto); expect(addTransactionSpy.callCount).toEqual(1); - expect(addProcedureSpy.getCall(0).calledWithExactly(TransferErc20)).toEqual(true); - expect(addProcedureSpy.callCount).toEqual(1); }); test('should throw if corresponding capped sto event is not fired', async () => { From 87ec5c33d57a6520ef352b56572ef13ff1e4730c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 14 Jan 2020 15:02:58 +0000 Subject: [PATCH 5/5] chore(release): 2.0.1-beta.93 [skip ci] ## [2.0.1-beta.93](https://github.com/PolymathNetwork/polymath-sdk/compare/v2.0.1-beta.92@beta...v2.0.1-beta.93@beta) (2020-01-14) ### Bug Fixes * only transfer POLY to ST if the current balance is insufficient ([47e08cc](https://github.com/PolymathNetwork/polymath-sdk/commit/47e08cc)) * refine Launch Tiered STO types ([acd32aa](https://github.com/PolymathNetwork/polymath-sdk/commit/acd32aa)) ### Features * only transfer POLY to the ST if missing ([3cf8dbd](https://github.com/PolymathNetwork/polymath-sdk/commit/3cf8dbd)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 57ee395..54cd8a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@polymathnetwork/sdk", - "version": "2.0.1-beta.92", + "version": "2.0.1-beta.93", "description": "A Javascript SDK for interacting with the Polymath network for the browser and Node.js", "bugs": { "url": "https://github.com/PolymathNetwork/polymath-sdk/issues"