Skip to content

Commit e444866

Browse files
authored
Merge pull request #93 from SetProtocol/slippageissuanceapi/will
Add SlippageIssuanceAPI class for clients to consume
2 parents 22661f0 + 8b7fe5b commit e444866

File tree

3 files changed

+467
-16
lines changed

3 files changed

+467
-16
lines changed

src/api/SlippageIssuanceAPI.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ import { ADDRESS_ZERO } from '@setprotocol/set-protocol-v2/dist/utils/constants'
2323
import { TransactionOverrides } from '@setprotocol/set-protocol-v2/dist/typechain';
2424
import { BigNumber } from 'ethers/lib/ethers';
2525

26-
import DebtIssuanceModuleV2Wrapper from '../wrappers/set-protocol-v2/DebtIssuanceModuleV2Wrapper';
26+
import SlippageIssuanceModuleWrapper from '../wrappers/set-protocol-v2/SlippageIssuanceModuleWrapper';
2727
import Assertions from '../assertions';
2828

2929
/**
30-
* @title DebtIssuanceV2API
30+
* @title SlippageIssuanceAPI
3131
* @author Set Protocol
3232
*
33-
* The DebtIssuanceModuleV2API exposes issue and redeem functionality for Sets that contain poitions that accrue
33+
* The SlippageIssuanceModuleAPI exposes issue and redeem functionality for Sets that contain poitions that accrue
3434
* interest per block. The getter function syncs the position balance to the current block, so subsequent blocks
3535
* will cause the position value to be slightly out of sync (a buffer is needed). This API is primarily used for Sets
3636
* that rely on the ALM contracts to manage debt. The manager can define arbitrary issuance logic
3737
* in the manager hook, as well as specify issue and redeem fees.
3838
*
3939
*/
40-
export default class DebtIssuanceV2API {
41-
private debtIssuanceModuleV2Wrapper: DebtIssuanceModuleV2Wrapper;
40+
export default class SlippageIssuanceAPI {
41+
private slippageIssuanceModuleWrapper: SlippageIssuanceModuleWrapper;
4242
private assert: Assertions;
4343

44-
public constructor(provider: Provider, debtIssuanceModuleV2Address: Address, assertions?: Assertions) {
45-
this.debtIssuanceModuleV2Wrapper = new DebtIssuanceModuleV2Wrapper(provider, debtIssuanceModuleV2Address);
44+
public constructor(provider: Provider, slippageIssuanceModuleAddress: Address, assertions?: Assertions) {
45+
this.slippageIssuanceModuleWrapper = new SlippageIssuanceModuleWrapper(provider, slippageIssuanceModuleAddress);
4646
this.assert = assertions || new Assertions();
4747
}
4848

4949
/**
50-
* Initializes the DebtIssuanceModuleV2 to the SetToken. Only callable by the SetToken's manager.
50+
* Initializes the SlippageIssuanceModule to the SetToken. Only callable by the SetToken's manager.
5151
*
5252
* @param setTokenAddress Address of the SetToken to initialize
5353
* @param maxManagerFee Maximum fee that can be charged on issue and redeem
@@ -73,7 +73,7 @@ export default class DebtIssuanceV2API {
7373
this.assert.schema.isValidAddress('feeRecipient', feeRecipient);
7474
this.assert.schema.isValidAddress('managerIssuanceHook', managerIssuanceHook);
7575

76-
return await this.debtIssuanceModuleV2Wrapper.initialize(
76+
return await this.slippageIssuanceModuleWrapper.initialize(
7777
setTokenAddress,
7878
maxManagerFee,
7979
managerIssueFee,
@@ -90,23 +90,34 @@ export default class DebtIssuanceV2API {
9090
*
9191
* @param setTokenAddress Address of the SetToken contract to issue
9292
* @param quantity Quantity to issue
93+
* @param checkedComponents Array of components to be checked to verify required collateral doesn't
94+
* exceed defined max. Each entry must be unique.
95+
* @param maxTokenAmountsIn Max amount of component willing to transfer in to collateralize quantity
96+
* amount of setToken.
9397
* @param setTokenRecipientAddress Address of the recipient of the issued SetToken
9498
* @param callerAddress Address of caller (optional)
9599
* @return Transaction hash of the issuance transaction
96100
*/
97-
public async issueAsync(
101+
public async issueWithSlippageAsync(
98102
setTokenAddress: Address,
99103
quantity: BigNumber,
104+
checkedComponents: Address[],
105+
maxTokenAmountsIn: BigNumber[],
100106
setTokenRecipientAddress: Address,
101107
callerAddress: Address = undefined,
102108
txOpts: TransactionOverrides = {}
103109
): Promise<ContractTransaction> {
104110
this.assert.schema.isValidAddress('setAddress', setTokenAddress);
105111
this.assert.schema.isValidAddress('setTokenRecipientAddress', setTokenRecipientAddress);
112+
this.assert.common.isUniqueList(checkedComponents, 'checkedComponents List needs to be unique');
113+
this.assert.common.isEqualLength(checkedComponents, maxTokenAmountsIn,
114+
'checkedComponents and maxTokenAmountsIn need to be equal length');
106115

107-
return await this.debtIssuanceModuleV2Wrapper.issue(
116+
return await this.slippageIssuanceModuleWrapper.issueWithSlippage(
108117
setTokenAddress,
109118
quantity,
119+
checkedComponents,
120+
maxTokenAmountsIn,
110121
setTokenRecipientAddress,
111122
callerAddress,
112123
txOpts
@@ -118,23 +129,34 @@ export default class DebtIssuanceV2API {
118129
*
119130
* @param setTokenAddress Address of the SetToken contract
120131
* @param quantity Quantity to redeem
132+
* @param checkedComponents Array of components to be checked to verify required collateral doesn't
133+
* exceed defined max. Each entry must be unique.
134+
* @param minTokenAmountsOut Min amount of component willing to receive to redeem quantity
135+
* amount of setToken.
121136
* @param setTokenRecipientAddress Address of recipient of component tokens from redemption
122137
* @param callerAddress Address of caller (optional)
123138
* @return Transaction hash of the redemption transaction
124139
*/
125-
public async redeemAsync(
140+
public async redeemWithSlippageAsync(
126141
setTokenAddress: Address,
127142
quantity: BigNumber,
143+
checkedComponents: Address[],
144+
minTokenAmountsOut: BigNumber[],
128145
setTokenRecipientAddress: Address,
129146
callerAddress: Address = undefined,
130147
txOpts: TransactionOverrides = {}
131148
): Promise<ContractTransaction> {
132149
this.assert.schema.isValidAddress('setAddress', setTokenAddress);
133150
this.assert.schema.isValidAddress('setTokenRecipientAddress', setTokenRecipientAddress);
151+
this.assert.common.isUniqueList(checkedComponents, 'checkedComponents List needs to be unique');
152+
this.assert.common.isEqualLength(checkedComponents, minTokenAmountsOut,
153+
'checkedComponents and minTokenAmountsOut need to be equal length');
134154

135-
return await this.debtIssuanceModuleV2Wrapper.redeem(
155+
return await this.slippageIssuanceModuleWrapper.redeemWithSlippage(
136156
setTokenAddress,
137157
quantity,
158+
checkedComponents,
159+
minTokenAmountsOut,
138160
setTokenRecipientAddress,
139161
callerAddress,
140162
txOpts
@@ -163,7 +185,7 @@ export default class DebtIssuanceV2API {
163185
): Promise<(Address|BigNumber)[][]> {
164186
this.assert.schema.isValidAddress('setAddress', setTokenAddress);
165187

166-
return await this.debtIssuanceModuleV2Wrapper.getRequiredComponentIssuanceUnits(
188+
return await this.slippageIssuanceModuleWrapper.getRequiredComponentIssuanceUnits(
167189
setTokenAddress,
168190
quantity,
169191
callerAddress,
@@ -191,7 +213,7 @@ export default class DebtIssuanceV2API {
191213
): Promise<(Address|BigNumber)[][]> {
192214
this.assert.schema.isValidAddress('setAddress', setTokenAddress);
193215

194-
return await this.debtIssuanceModuleV2Wrapper.getRequiredComponentRedemptionUnits(
216+
return await this.slippageIssuanceModuleWrapper.getRequiredComponentRedemptionUnits(
195217
setTokenAddress,
196218
quantity,
197219
callerAddress,
@@ -228,7 +250,7 @@ export default class DebtIssuanceV2API {
228250
this.assert.schema.isValidAddress('setAddress', setTokenAddress);
229251
this.assert.common.isNotUndefined(isIssue, 'isIssue arg must be a boolean.');
230252

231-
return await this.debtIssuanceModuleV2Wrapper.calculateTotalFees(
253+
return await this.slippageIssuanceModuleWrapper.calculateTotalFees(
232254
setTokenAddress,
233255
quantity,
234256
isIssue,

src/assertions/CommonAssertions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export class CommonAssertions {
3838
}
3939
}
4040

41+
public isUniqueList(array: any[], errorMessage: string) {
42+
if ((new Set(array)).size !== array.length) {
43+
throw new Error(errorMessage);
44+
}
45+
}
46+
4147
public isGreaterThan(quantity1: BigNumber, quantity2: BigNumber, errorMessage: string) {
4248
if (quantity1.lte(quantity2)) {
4349
throw new Error(errorMessage);

0 commit comments

Comments
 (0)