-
Notifications
You must be signed in to change notification settings - Fork 36
/
market-repay-stable.ts
43 lines (38 loc) · 1.47 KB
/
market-repay-stable.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
40
41
42
43
import { Dec, Int, MsgExecuteContract } from '@terra-money/terra.js';
import { validateAddress } from '../../utils/validation/address';
import { validateInput } from '../../utils/validate-input';
import { validateIsGreaterThanZero } from '../../utils/validation/number';
import { AddressProvider } from '../../address-provider/provider';
import { MARKET_DENOMS } from '../../address-provider';
interface Option {
address: string;
market: MARKET_DENOMS;
amount: string;
}
/**
* @param address Client’s Terra address.
* @param market Type of stablecoin money market to repay.
* @param borrower (optional) Terra address of the entity that created the loan position.If null, repays address‘s loan
* @param amount (optional) Amount of stablecoin to repay. Set to null if repay_all is set to true.
*/
export const fabricateMarketRepay = ({ address, market, amount }: Option) => (
addressProvider: AddressProvider,
): MsgExecuteContract[] => {
validateInput([validateAddress(address), validateIsGreaterThanZero(amount)]);
//const nativeTokenDenom = market;
const mmContractAddress = addressProvider.market(market);
return [
new MsgExecuteContract(
address,
mmContractAddress,
{
// @see https://github.com/Anchor-Protocol/money-market-contracts/blob/master/contracts/market/src/msg.rs#L74
repay_stable: {},
},
// sending stablecoin
{
[`${market}`]: new Int(new Dec(amount).mul(1000000)).toString(),
},
),
];
};