-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex5-dvp-if-registro-vendedor.ts
More file actions
125 lines (105 loc) · 3.73 KB
/
ex5-dvp-if-registro-vendedor.ts
File metadata and controls
125 lines (105 loc) · 3.73 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { ethers } from "hardhat";
import {
getBalanceTPFTSync,
getPLInformation,
TimeoutExecution
} from "../utils/utils";
import IendpointContractABI from "../abi/IEndpoint.json";
import TpftContractABI from "../abi/TPFt.json";
import tpftOpContractABI from "../abi/TPFToperation.json";
async function example5() {
const {
chainId,
endpointContractAddr,
tpftResourceId,
tpftOpResourceId
} = await getPLInformation();
const [deployerSigner] = await ethers.getSigners();
const chainIdDestination = process.env.DEST_CHAINID ?? 0;
const destinationWd = process.env.DEST_RESERVES_ACC ?? "";
const tpftOperationAmount = BigInt(100);
const tpftOperationPrice = BigInt(500);
const tpftDvpData = {
acronym: '<acrônimo do título público>',
code: '<código do título público>',
maturityDate: <data de validade do título público>
};
const opData = {
operationId: '<ID da operação>',
chainIdSeller: <Chain ID da PL vendedora>,
chainIdBuyer: <Chain ID da PL compradora>,
accountSeller: '<conta vendedora>',
accountBuyer: '<conta compradora>',
tpftData: <TPFt data>,
tpftAmount: <Quantidade de TPFt da operação>,
price: <Preço a ser pago por TPFt>,
status: <Estado da operação (p/ vendedor: 1)>,
isBetweenClients: <True, apenas quando for operação entre clientes. False, caso contrário.>
};
const endpointContract = await ethers.getContractAt(
IendpointContractABI,
endpointContractAddr,
deployerSigner
);
const tpftOpAddress = await endpointContract
.resourceIdToContractAddress(
tpftOpResourceId
);
const tpftOpContract = await ethers.getContractAt(
tpftOpContractABI,
tpftOpAddress,
deployerSigner
);
const op = await tpftOpContract.operations(opData.operationId);
const prevStatus = op.status;
console.log("[DEBUG] prevStatus:", prevStatus);
const balanceBefore = await getBalanceTPFTSync(
endpointContract,
tpftResourceId,
deployerSigner,
deployerSigner.address,
opData.tpftData
);
console.log("[DEBUG] balanceBefore:", balanceBefore);
const tpftContractAddr = await endpointContract
.resourceIdToContractAddress(
tpftResourceId
);
const tpftContract = await ethers.getContractAt(
TpftContractABI,
tpftContractAddr,
deployerSigner
);
console.log("[DEBUG] Approving TPFt amount for TPFToperation contract address...");
const txApprove = await tpftContract.setApprovalForAll(
tpftOpAddress,
true
);
txApprove.wait();
console.log("[DEBUG] Registering operation as seller...");
let txOpReg = await tpftOpContract.callRegisterOperation(opData);
await txOpReg.wait();
console.time("Waiting register response from DVP contract");
const newStatus = await TimeoutExecution(async (retry) => {
const _op = await tpftOpContract.operations(opData.operationId);
if (_op.status > prevStatus) {
return [true, _op.status];
} else return [false, false];
});
console.timeEnd("Waiting register response from DVP contract");
console.log("[DEBUG] newStatus:", newStatus);
const balanceAfter = await getBalanceTPFTSync(
endpointContract,
tpftResourceId,
deployerSigner,
deployerSigner.address,
opData.tpftData
);
console.log("[DEBUG] balanceAfter", balanceAfter);
}
example5()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});