-
Notifications
You must be signed in to change notification settings - Fork 36
/
basset-send.ts
47 lines (43 loc) · 1.32 KB
/
basset-send.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
import { Dec, Int, MsgExecuteContract } from '@terra-money/terra.js';
import { validateInput } from '../../utils/validate-input';
import { validateAddress } from '../../utils/validation/address';
import {
validateIsGreaterThanZero,
validateIsNumber,
} from '../../utils/validation/number';
import { AddressProvider } from '../../address-provider/provider';
/* eslint-disable */
interface Option {
address: string;
amount: string;
contract: string;
msg?: object;
}
export const fabricatebAssetSend = ({
address,
amount,
contract,
msg,
}: Option) => (addressProvider: AddressProvider): MsgExecuteContract[] => {
validateInput([
validateAddress(address),
validateIsNumber(+amount),
validateIsGreaterThanZero(+amount),
validateAddress(contract),
]);
const bAssetTokenAddress = addressProvider.bLunaToken();
let message = undefined;
if (msg) {
message = Buffer.from(JSON.stringify(msg)).toString('base64');
}
return [
new MsgExecuteContract(address, bAssetTokenAddress, {
// @see https://github.com/Anchor-Protocol/anchor-bAsset-contracts/blob/cce41e707c67ee2852c4929e17fb1472dbd2aa35/contracts/anchor_basset_token/src/handler.rs#L17
send: {
contract: contract,
amount: new Int(new Dec(amount).mul(1000000)).toString(),
msg: message,
},
}),
];
};