-
Notifications
You must be signed in to change notification settings - Fork 36
/
liquidation-retract-bid.ts
39 lines (35 loc) · 1.33 KB
/
liquidation-retract-bid.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Dec, Int, MsgExecuteContract } from '@terra-money/terra.js';
import { validateAddress } from '../../utils/validation/address';
import { validateInput } from '../../utils/validate-input';
import { validateIsNumber } from '../../utils/validation/number';
import { validateTrue } from '../../utils/validation/true';
import { AddressProvider } from '../../address-provider/provider';
import { isAmountSet } from '../../utils/validation/amount';
interface Option {
address: string;
collateral_token: string;
amount: string | undefined;
}
export const fabricateLiquidationRetractBid = ({
address,
collateral_token,
amount,
}: Option) => (addressProvider: AddressProvider): MsgExecuteContract[] => {
validateInput([
validateAddress(address),
validateAddress(collateral_token),
amount ? validateIsNumber(amount) : validateTrue,
]);
const mmContractAddress = addressProvider.liquidation();
return [
new MsgExecuteContract(address, mmContractAddress, {
// @see https://github.com/Anchor-Protocol/money-market-contracts/blob/781abf462dc25aaed0ea4953dad14ba9736fa55d/contracts/liquidation/src/bid.rs#L15
retract_bid: {
collateral_token: collateral_token,
amount: isAmountSet(amount)
? new Int(new Dec(amount).mul(1000000)).toString()
: undefined,
},
}),
];
};