-
Notifications
You must be signed in to change notification settings - Fork 36
/
provide-liquidity-bluna.ts
84 lines (79 loc) · 2.17 KB
/
provide-liquidity-bluna.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
Coin,
Dec,
Coins,
Int,
MsgExecuteContract,
} from '@terra-money/terra.js';
import { validateInput } from '../../utils/validate-input';
import { validateAddress } from '../../utils/validation/address';
import { AddressProvider } from '../../address-provider/provider';
import { validateIsGreaterThanZero } from '../../utils/validation/number';
/* eslint-disable */
type Expire = { at_height: number } | { at_time: number } | { never: {} };
interface Option {
address: string;
token_amount: string;
native_amount: string;
quote: string;
slippage_tolerance?: string;
expires: Expire;
}
export const fabricateTerraswapProvideLiquiditybLuna = ({
address,
slippage_tolerance,
token_amount,
native_amount,
quote,
expires,
}: Option) => (addressProvider: AddressProvider): MsgExecuteContract[] => {
validateInput([
validateAddress(address),
validateIsGreaterThanZero(token_amount),
validateIsGreaterThanZero(native_amount),
]);
const pairAddress = addressProvider.terraswapblunaLunaPair();
const tokenAddress = addressProvider.bLunaToken();
const coins = new Coins([
new Coin(quote, new Int(new Dec(native_amount).mul(1000000)).toString()),
]);
return [
new MsgExecuteContract(address, tokenAddress, {
increase_allowance: {
spender: pairAddress,
amount: new Int(new Dec(token_amount).mul(1000000)).toString(),
expires: expires || { never: {} },
},
}),
new MsgExecuteContract(
address,
pairAddress,
{
provide_liquidity: {
assets: [
{
info: {
token: {
contract_addr: tokenAddress,
},
},
amount: new Int(new Dec(token_amount).mul(1000000)).toString(),
},
{
info: {
native_token: {
denom: quote,
},
},
amount: new Int(new Dec(native_amount).mul(1000000)).toString(),
},
],
slippage_tolerance: slippage_tolerance
? slippage_tolerance
: undefined,
},
},
coins,
),
];
};