stackswap-front-api-test-02 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/506.index.umd.js +1 -0
- package/dist/esm/index.d.ts +77 -0
- package/dist/esm/index.js +110 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/stackswap/config.d.ts +84 -0
- package/dist/esm/stackswap/config.js +123 -0
- package/dist/esm/stackswap/config.js.map +1 -0
- package/dist/esm/stackswap/main.d.ts +1 -0
- package/dist/esm/stackswap/main.js +5 -0
- package/dist/esm/stackswap/main.js.map +1 -0
- package/dist/esm/stackswap/manager/farm.manager.d.ts +37 -0
- package/dist/esm/stackswap/manager/farm.manager.js +220 -0
- package/dist/esm/stackswap/manager/farm.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/farm2.manager.d.ts +37 -0
- package/dist/esm/stackswap/manager/farm2.manager.js +294 -0
- package/dist/esm/stackswap/manager/farm2.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/governance.manager.d.ts +9 -0
- package/dist/esm/stackswap/manager/governance.manager.js +54 -0
- package/dist/esm/stackswap/manager/governance.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/launchpad.manager.d.ts +13 -0
- package/dist/esm/stackswap/manager/launchpad.manager.js +148 -0
- package/dist/esm/stackswap/manager/launchpad.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/lbtc.manager.d.ts +31 -0
- package/dist/esm/stackswap/manager/lbtc.manager.js +327 -0
- package/dist/esm/stackswap/manager/lbtc.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/multisig.manager.d.ts +11 -0
- package/dist/esm/stackswap/manager/multisig.manager.js +52 -0
- package/dist/esm/stackswap/manager/multisig.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/nft.manager.d.ts +52 -0
- package/dist/esm/stackswap/manager/nft.manager.js +244 -0
- package/dist/esm/stackswap/manager/nft.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/operator.manager.d.ts +17 -0
- package/dist/esm/stackswap/manager/operator.manager.js +86 -0
- package/dist/esm/stackswap/manager/operator.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/other.manager.d.ts +9 -0
- package/dist/esm/stackswap/manager/other.manager.js +48 -0
- package/dist/esm/stackswap/manager/other.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/pool.manager.d.ts +33 -0
- package/dist/esm/stackswap/manager/pool.manager.js +160 -0
- package/dist/esm/stackswap/manager/pool.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/poxl.manager.d.ts +16 -0
- package/dist/esm/stackswap/manager/poxl.manager.js +72 -0
- package/dist/esm/stackswap/manager/poxl.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/staking.manager.d.ts +25 -0
- package/dist/esm/stackswap/manager/staking.manager.js +234 -0
- package/dist/esm/stackswap/manager/staking.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/swap.manager.d.ts +35 -0
- package/dist/esm/stackswap/manager/swap.manager.js +291 -0
- package/dist/esm/stackswap/manager/swap.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/token.manager.d.ts +31 -0
- package/dist/esm/stackswap/manager/token.manager.js +126 -0
- package/dist/esm/stackswap/manager/token.manager.js.map +1 -0
- package/dist/esm/stackswap/util.d.ts +37 -0
- package/dist/esm/stackswap/util.js +240 -0
- package/dist/esm/stackswap/util.js.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.LICENSE.txt +10 -0
- package/dist/stackswap/config.d.ts +84 -0
- package/dist/stackswap/config.js +127 -0
- package/dist/stackswap/config.js.map +1 -0
- package/dist/stackswap/main.d.ts +1 -0
- package/dist/stackswap/main.js +7 -0
- package/dist/stackswap/main.js.map +1 -0
- package/dist/stackswap/manager/farm.manager.d.ts +37 -0
- package/dist/stackswap/manager/farm.manager.js +228 -0
- package/dist/stackswap/manager/farm.manager.js.map +1 -0
- package/dist/stackswap/manager/farm2.manager.d.ts +37 -0
- package/dist/stackswap/manager/farm2.manager.js +301 -0
- package/dist/stackswap/manager/farm2.manager.js.map +1 -0
- package/dist/stackswap/manager/governance.manager.d.ts +9 -0
- package/dist/stackswap/manager/governance.manager.js +61 -0
- package/dist/stackswap/manager/governance.manager.js.map +1 -0
- package/dist/stackswap/manager/launchpad.manager.d.ts +13 -0
- package/dist/stackswap/manager/launchpad.manager.js +152 -0
- package/dist/stackswap/manager/launchpad.manager.js.map +1 -0
- package/dist/stackswap/manager/lbtc.manager.d.ts +31 -0
- package/dist/stackswap/manager/lbtc.manager.js +334 -0
- package/dist/stackswap/manager/lbtc.manager.js.map +1 -0
- package/dist/stackswap/manager/multisig.manager.d.ts +11 -0
- package/dist/stackswap/manager/multisig.manager.js +56 -0
- package/dist/stackswap/manager/multisig.manager.js.map +1 -0
- package/dist/stackswap/manager/nft.manager.d.ts +52 -0
- package/dist/stackswap/manager/nft.manager.js +251 -0
- package/dist/stackswap/manager/nft.manager.js.map +1 -0
- package/dist/stackswap/manager/operator.manager.d.ts +17 -0
- package/dist/stackswap/manager/operator.manager.js +93 -0
- package/dist/stackswap/manager/operator.manager.js.map +1 -0
- package/dist/stackswap/manager/other.manager.d.ts +9 -0
- package/dist/stackswap/manager/other.manager.js +55 -0
- package/dist/stackswap/manager/other.manager.js.map +1 -0
- package/dist/stackswap/manager/pool.manager.d.ts +33 -0
- package/dist/stackswap/manager/pool.manager.js +168 -0
- package/dist/stackswap/manager/pool.manager.js.map +1 -0
- package/dist/stackswap/manager/poxl.manager.d.ts +16 -0
- package/dist/stackswap/manager/poxl.manager.js +79 -0
- package/dist/stackswap/manager/poxl.manager.js.map +1 -0
- package/dist/stackswap/manager/staking.manager.d.ts +25 -0
- package/dist/stackswap/manager/staking.manager.js +241 -0
- package/dist/stackswap/manager/staking.manager.js.map +1 -0
- package/dist/stackswap/manager/swap.manager.d.ts +35 -0
- package/dist/stackswap/manager/swap.manager.js +298 -0
- package/dist/stackswap/manager/swap.manager.js.map +1 -0
- package/dist/stackswap/manager/token.manager.d.ts +31 -0
- package/dist/stackswap/manager/token.manager.js +134 -0
- package/dist/stackswap/manager/token.manager.js.map +1 -0
- package/dist/stackswap/util.d.ts +37 -0
- package/dist/stackswap/util.js +259 -0
- package/dist/stackswap/util.js.map +1 -0
- package/package.json +43 -0
- package/src/index.ts +165 -0
- package/src/stackswap/config.ts +202 -0
- package/src/stackswap/main.ts +6 -0
- package/src/stackswap/manager/farm.manager.ts +310 -0
- package/src/stackswap/manager/farm2.manager.ts +407 -0
- package/src/stackswap/manager/governance.manager.ts +95 -0
- package/src/stackswap/manager/launchpad.manager.ts +190 -0
- package/src/stackswap/manager/lbtc.manager.ts +566 -0
- package/src/stackswap/manager/multisig.manager.ts +87 -0
- package/src/stackswap/manager/nft.manager.ts +311 -0
- package/src/stackswap/manager/operator.manager.ts +123 -0
- package/src/stackswap/manager/other.manager.ts +71 -0
- package/src/stackswap/manager/pool.manager.ts +188 -0
- package/src/stackswap/manager/poxl.manager.ts +99 -0
- package/src/stackswap/manager/staking.manager.ts +321 -0
- package/src/stackswap/manager/swap.manager.ts +351 -0
- package/src/stackswap/manager/token.manager.ts +156 -0
- package/src/stackswap/util.ts +269 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import {
|
|
4
|
+
callReadOnlyFunction,
|
|
5
|
+
contractPrincipalCV, cvToValue, falseCV,
|
|
6
|
+
FungibleConditionCode,
|
|
7
|
+
standardPrincipalCV,
|
|
8
|
+
stringAsciiCV, trueCV, uintCV
|
|
9
|
+
} from "@stacks/transactions";
|
|
10
|
+
import {openContractCall} from "@stacks/connect";
|
|
11
|
+
import {StackswapAPI} from "../../index";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export class LbtcManager {
|
|
15
|
+
stackswap: StackswapAPI;
|
|
16
|
+
|
|
17
|
+
constructor(stackswap: StackswapAPI) {
|
|
18
|
+
this.stackswap = stackswap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getPoxInfo() {
|
|
22
|
+
const function_option = getReadOptions(
|
|
23
|
+
this.stackswap,
|
|
24
|
+
this.stackswap.config.CONTRACT_NAME_POX()+'pox',
|
|
25
|
+
'get-pox-info',
|
|
26
|
+
[]
|
|
27
|
+
);
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
30
|
+
return cvToValue(result_raw);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getVaultTypeInfo(coll_type: string) {
|
|
34
|
+
|
|
35
|
+
const function_option = getReadOptions(this.stackswap,
|
|
36
|
+
this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES(),
|
|
37
|
+
'get-collateral-type-by-name',
|
|
38
|
+
[stringAsciiCV(coll_type)]
|
|
39
|
+
);
|
|
40
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
41
|
+
return cvToValue(result_raw);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async getVaultIDFromUser() {
|
|
45
|
+
|
|
46
|
+
const function_option = getReadOptions(this.stackswap,
|
|
47
|
+
this.stackswap.config.CONTRACT_NAME_VAULT_DATA(),
|
|
48
|
+
'get-vaults',
|
|
49
|
+
[standardPrincipalCV(this.stackswap.getSenderAddress())]
|
|
50
|
+
);
|
|
51
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
52
|
+
return cvToValue(result_raw);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async getVaultInfoFromID(vault_id: string) {
|
|
56
|
+
|
|
57
|
+
const function_option = getReadOptions(this.stackswap,
|
|
58
|
+
this.stackswap.config.CONTRACT_NAME_VAULT_DATA(),
|
|
59
|
+
'get-vault-by-id',
|
|
60
|
+
[uintCV(vault_id)]
|
|
61
|
+
);
|
|
62
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
63
|
+
return cvToValue(result_raw);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getVaultIDFromUser2() {
|
|
67
|
+
const function_option = getReadOptions(this.stackswap,
|
|
68
|
+
this.stackswap.config.CONTRACT_NAME_VAULT_DATA(),
|
|
69
|
+
'get-vault-entries',
|
|
70
|
+
[standardPrincipalCV(this.stackswap.getSenderAddress())]
|
|
71
|
+
);
|
|
72
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
73
|
+
// console.log('getVaultIDFromUser2', cvToValue(result_raw))
|
|
74
|
+
return cvToValue(result_raw);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
78
|
+
|
|
79
|
+
async txCreateVaultWithSTX(coll_amt: BigNumber, debt_amt: BigNumber, coll_type: string, isStack: boolean, callback: any = null) {
|
|
80
|
+
let IsStack = trueCV;
|
|
81
|
+
if (isStack) {
|
|
82
|
+
IsStack = trueCV;
|
|
83
|
+
} else {
|
|
84
|
+
IsStack = falseCV;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const post_condition = [];
|
|
88
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
89
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_MORTGAGER(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.LessEqual));
|
|
90
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10**6).toString(), FungibleConditionCode.Equal));
|
|
91
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10**8).toString(), FungibleConditionCode.LessEqual));
|
|
92
|
+
|
|
93
|
+
const function_option = getWriteOptions(
|
|
94
|
+
this.stackswap,
|
|
95
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
96
|
+
'collateralize-and-mint',
|
|
97
|
+
[
|
|
98
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
99
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
100
|
+
IsStack(),
|
|
101
|
+
stringAsciiCV(coll_type),
|
|
102
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_STX_RESERVE()),
|
|
103
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
104
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
105
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
106
|
+
],
|
|
107
|
+
post_condition, callback
|
|
108
|
+
);
|
|
109
|
+
openContractCall(function_option);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async txCreateVaultWithSTSW(coll_amt: BigNumber, debt_amt: BigNumber, coll_type: string, callback: any = null) {
|
|
113
|
+
// let IsStack = trueCV;
|
|
114
|
+
// if (isStack) {
|
|
115
|
+
// IsStack = trueCV;
|
|
116
|
+
// } else {
|
|
117
|
+
// IsStack = falseCV;
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
const post_condition = [];
|
|
121
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
122
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_MORTGAGER(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.LessEqual));
|
|
123
|
+
|
|
124
|
+
const function_option = getWriteOptions(
|
|
125
|
+
this.stackswap,
|
|
126
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
127
|
+
'collateralize-and-mint',
|
|
128
|
+
[
|
|
129
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
130
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
131
|
+
falseCV(),
|
|
132
|
+
stringAsciiCV(coll_type),
|
|
133
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE()),
|
|
134
|
+
contractPrincipalCV(this.stackswap.config.BASE_STSW_DATA().addr.split('.')[0], this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
135
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
136
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
137
|
+
],
|
|
138
|
+
post_condition, callback
|
|
139
|
+
);
|
|
140
|
+
openContractCall(function_option);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
async txDepositCollateral(vault_id: number, coll_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
145
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
146
|
+
// console.log(coll_token,coll_token === 'STX' )
|
|
147
|
+
if (coll_token === 'STX') {
|
|
148
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const post_condition = [];
|
|
152
|
+
if (coll_token === 'STX') {
|
|
153
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
154
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
155
|
+
|
|
156
|
+
} else if (coll_token === 'STSW') {
|
|
157
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
158
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const function_option = getWriteOptions(
|
|
162
|
+
this.stackswap,
|
|
163
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
164
|
+
'deposit',
|
|
165
|
+
[
|
|
166
|
+
uintCV(vault_id.toString()),
|
|
167
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
168
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
169
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
170
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES())
|
|
171
|
+
],
|
|
172
|
+
post_condition, callback
|
|
173
|
+
);
|
|
174
|
+
openContractCall(function_option);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async txToggleStacking(vault_id: number, callback: any = null) {
|
|
178
|
+
const post_condition: any = [];
|
|
179
|
+
|
|
180
|
+
const function_option = getWriteOptions(
|
|
181
|
+
this.stackswap,
|
|
182
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
183
|
+
'toggle-stacking',
|
|
184
|
+
[
|
|
185
|
+
uintCV(vault_id.toString()),
|
|
186
|
+
],
|
|
187
|
+
post_condition, callback
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
openContractCall(function_option);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async txStackCollateral(vault_id: number, callback: any = null) {
|
|
194
|
+
const post_condition: any = [];
|
|
195
|
+
|
|
196
|
+
const function_option = getWriteOptions(
|
|
197
|
+
this.stackswap,
|
|
198
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
199
|
+
'stack-collateral',
|
|
200
|
+
[
|
|
201
|
+
uintCV(vault_id.toString()),
|
|
202
|
+
],
|
|
203
|
+
post_condition, callback
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
openContractCall(function_option);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
resolveStacker(stacker_name: string) {
|
|
210
|
+
switch (stacker_name) {
|
|
211
|
+
case 'stacker':
|
|
212
|
+
return this.stackswap.config.CONTRACT_NAME_STACKER1();
|
|
213
|
+
case 'stacker-2':
|
|
214
|
+
return this.stackswap.config.CONTRACT_NAME_STACKER2();
|
|
215
|
+
case 'stacker-3':
|
|
216
|
+
return this.stackswap.config.CONTRACT_NAME_STACKER3();
|
|
217
|
+
case 'stacker-4':
|
|
218
|
+
return this.stackswap.config.CONTRACT_NAME_STACKER4();
|
|
219
|
+
default:
|
|
220
|
+
return this.stackswap.config.CONTRACT_NAME_STACKER1();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async txEnableWithdraw(vault_id: number, stacker_name: string, callback: any = null) {
|
|
225
|
+
const post_condition: any = [];
|
|
226
|
+
|
|
227
|
+
const function_option = getWriteOptions(
|
|
228
|
+
this.stackswap,
|
|
229
|
+
this.resolveStacker(stacker_name),
|
|
230
|
+
'enable-vault-withdrawals',
|
|
231
|
+
[
|
|
232
|
+
uintCV(vault_id.toString()),
|
|
233
|
+
],
|
|
234
|
+
post_condition, callback
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
openContractCall(function_option);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async txWithdrawCollateral(vault_id: number, coll_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
241
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
242
|
+
if (coll_token === 'STX') {
|
|
243
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const post_condition: any = [];
|
|
247
|
+
if (coll_token === 'STX') {
|
|
248
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
249
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + reserve, this.stackswap.config.BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
250
|
+
} else if (coll_token === 'STSW') {
|
|
251
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
252
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + reserve, this.stackswap.config.BASE_STSW_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const function_option = getWriteOptions(
|
|
256
|
+
this.stackswap,
|
|
257
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
258
|
+
'withdraw',
|
|
259
|
+
[
|
|
260
|
+
uintCV(vault_id.toString()),
|
|
261
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
262
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
263
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
264
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
265
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
266
|
+
],
|
|
267
|
+
post_condition, callback
|
|
268
|
+
);
|
|
269
|
+
openContractCall(function_option);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async txMintDebt(vault_id: number, debt_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
273
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
274
|
+
if (coll_token === 'STX') {
|
|
275
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const post_condition = [];
|
|
279
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
280
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + reserve, this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.LessEqual));
|
|
281
|
+
|
|
282
|
+
const function_option = getWriteOptions(
|
|
283
|
+
this.stackswap,
|
|
284
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
285
|
+
'mint',
|
|
286
|
+
[
|
|
287
|
+
uintCV(vault_id.toString()),
|
|
288
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
289
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
290
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
291
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
292
|
+
],
|
|
293
|
+
post_condition, callback
|
|
294
|
+
);
|
|
295
|
+
openContractCall(function_option);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async txBurnDebt(vault_id: number, debt_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
299
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
300
|
+
if (coll_token === 'STX') {
|
|
301
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const post_condition = [];
|
|
305
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
306
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.GreaterEqual));
|
|
307
|
+
|
|
308
|
+
const function_option = getWriteOptions(
|
|
309
|
+
this.stackswap,
|
|
310
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
311
|
+
'burn',
|
|
312
|
+
[
|
|
313
|
+
uintCV(vault_id.toString()),
|
|
314
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
315
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
316
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
317
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES())
|
|
318
|
+
],
|
|
319
|
+
post_condition, callback
|
|
320
|
+
);
|
|
321
|
+
openContractCall(function_option);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async txCloseVault(vault_id: number, coll_token: string, coll_amount: string, debt_amount: string, callback: any = null) {
|
|
325
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
326
|
+
|
|
327
|
+
// console.log(coll_token, debt_amount);
|
|
328
|
+
const post_condition: any = [];
|
|
329
|
+
|
|
330
|
+
if (coll_token === 'STX') {
|
|
331
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
332
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STX_RESERVE(), this.stackswap.config.BASE_WSTX_DATA().addr, coll_amount, FungibleConditionCode.Equal));
|
|
333
|
+
} else {
|
|
334
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE(), this.stackswap.config.BASE_STSW_DATA().addr, coll_amount, FungibleConditionCode.Equal));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, new BigNumber(debt_amount).multipliedBy(10 ** 8).multipliedBy(1.001).toFixed(0), FungibleConditionCode.LessEqual));
|
|
338
|
+
|
|
339
|
+
const function_option = getWriteOptions(
|
|
340
|
+
this.stackswap,
|
|
341
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
342
|
+
'close-vault',
|
|
343
|
+
[
|
|
344
|
+
uintCV(vault_id.toString()),
|
|
345
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
346
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
347
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES())
|
|
348
|
+
],
|
|
349
|
+
post_condition, callback
|
|
350
|
+
);
|
|
351
|
+
openContractCall(function_option);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
355
|
+
|
|
356
|
+
async txFinalLiquidation(vault_id: number, callback: any = null) {
|
|
357
|
+
|
|
358
|
+
const post_condition: any = [];
|
|
359
|
+
|
|
360
|
+
const function_option = getWriteOptions(
|
|
361
|
+
this.stackswap,
|
|
362
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
363
|
+
'finalize-liquidation',
|
|
364
|
+
[
|
|
365
|
+
uintCV(vault_id.toString()),
|
|
366
|
+
],
|
|
367
|
+
post_condition, callback
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
openContractCall(function_option);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async txUnliquidationDeposit(vault_id: number, coll_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
374
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
375
|
+
if (coll_token === 'STX') {
|
|
376
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const post_condition = [];
|
|
380
|
+
if (coll_token === 'STX') {
|
|
381
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
382
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
383
|
+
} else if (coll_token === 'STSW') {
|
|
384
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
385
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, coll_amt.multipliedBy(10 ** 6).toString(), FungibleConditionCode.Equal));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const function_option = getWriteOptions(
|
|
389
|
+
this.stackswap,
|
|
390
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
391
|
+
'deposit-to-unliquidate',
|
|
392
|
+
[
|
|
393
|
+
uintCV(vault_id.toString()),
|
|
394
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
395
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
396
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
397
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
398
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
399
|
+
],
|
|
400
|
+
post_condition, callback
|
|
401
|
+
);
|
|
402
|
+
openContractCall(function_option);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async txUnliquidationBurn(vault_id: number, debt_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
406
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
407
|
+
if (coll_token === 'STX') {
|
|
408
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const post_condition = [];
|
|
412
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
413
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.GreaterEqual));
|
|
414
|
+
|
|
415
|
+
const function_option = getWriteOptions(
|
|
416
|
+
this.stackswap,
|
|
417
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
418
|
+
'burn-to-unliquidate',
|
|
419
|
+
[
|
|
420
|
+
uintCV(vault_id.toString()),
|
|
421
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
422
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
423
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
424
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
425
|
+
],
|
|
426
|
+
post_condition, callback
|
|
427
|
+
);
|
|
428
|
+
openContractCall(function_option);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async txLiquidationWithdraw(vault_id: number, coll_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
432
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
433
|
+
if (coll_token === 'STX') {
|
|
434
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const post_condition = [];
|
|
438
|
+
if (coll_token === 'STX') {
|
|
439
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
440
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_WSTX_DATA().addr, coll_amt.multipliedBy(10**6).toString(), FungibleConditionCode.LessEqual));
|
|
441
|
+
|
|
442
|
+
} else if (coll_token === 'STSW') {
|
|
443
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
444
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), BASE_STSW_DATA().addr, coll_amt.multipliedBy(10**6).toString(), FungibleConditionCode.LessEqual));
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const function_option = getWriteOptions(
|
|
449
|
+
this.stackswap,
|
|
450
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
451
|
+
'withdraw-liquidated',
|
|
452
|
+
[
|
|
453
|
+
uintCV(vault_id.toString()),
|
|
454
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toString()),
|
|
455
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
456
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
457
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES())
|
|
458
|
+
],
|
|
459
|
+
post_condition, callback
|
|
460
|
+
);
|
|
461
|
+
openContractCall(function_option);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async txLiquidationBurn(vault_id: number, debt_amt: BigNumber, coll_token: string, callback: any = null) {
|
|
465
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
466
|
+
if (coll_token === 'STX') {
|
|
467
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const post_condition = [];
|
|
471
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
472
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, debt_amt.multipliedBy(10 ** 8).toString(), FungibleConditionCode.LessEqual));
|
|
473
|
+
|
|
474
|
+
const function_option = getWriteOptions(
|
|
475
|
+
this.stackswap,
|
|
476
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
477
|
+
'burn-liquidated',
|
|
478
|
+
[
|
|
479
|
+
uintCV(vault_id.toString()),
|
|
480
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toString()),
|
|
481
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
482
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
483
|
+
],
|
|
484
|
+
post_condition, callback
|
|
485
|
+
);
|
|
486
|
+
openContractCall(function_option);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
async txCloseVaultLiquidated(vault_id: number, coll_token: string, callback: any = null) {
|
|
490
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
491
|
+
if (coll_token === 'STX') {
|
|
492
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const post_condition: any = [];
|
|
496
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap.getSenderAddress(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
497
|
+
|
|
498
|
+
const function_option = getWriteOptions(
|
|
499
|
+
this.stackswap,
|
|
500
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
501
|
+
'close-vault-liquidated',
|
|
502
|
+
[
|
|
503
|
+
uintCV(vault_id.toString()),
|
|
504
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), reserve),
|
|
505
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.BASE_STSW_DATA().addr.split('.')[1]),
|
|
506
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES())
|
|
507
|
+
],
|
|
508
|
+
post_condition, callback
|
|
509
|
+
);
|
|
510
|
+
openContractCall(function_option);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
514
|
+
|
|
515
|
+
async getDebtRatio(coll_amt: BigNumber, debt_amt: BigNumber, coll_token: string) {
|
|
516
|
+
let reserve = this.stackswap.config.CONTRACT_NAME_SIP10_RESERVE();
|
|
517
|
+
if (coll_token === 'STX') {
|
|
518
|
+
reserve = this.stackswap.config.CONTRACT_NAME_STX_RESERVE();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const function_option = getReadOptions(this.stackswap,
|
|
522
|
+
reserve,
|
|
523
|
+
'calculate-current-collateral-to-debt-ratio',
|
|
524
|
+
[
|
|
525
|
+
stringAsciiCV(coll_token),
|
|
526
|
+
uintCV(debt_amt.multipliedBy(10 ** 8).toFixed(0)),
|
|
527
|
+
uintCV(coll_amt.multipliedBy(10 ** 6).toFixed(0)),
|
|
528
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
529
|
+
]
|
|
530
|
+
);
|
|
531
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
532
|
+
return cvToValue(result_raw);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
536
|
+
|
|
537
|
+
async getPrice(token: string) {
|
|
538
|
+
|
|
539
|
+
const function_option = getReadOptions(this.stackswap,
|
|
540
|
+
this.stackswap.config.CONTRACT_NAME_ORACLE(),
|
|
541
|
+
'get-price',
|
|
542
|
+
[
|
|
543
|
+
stringAsciiCV(token)
|
|
544
|
+
]
|
|
545
|
+
);
|
|
546
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
547
|
+
// console.log(cvToValue(result_raw))
|
|
548
|
+
return cvToValue(result_raw);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
async getStabilityFee(vault_id: string) {
|
|
552
|
+
|
|
553
|
+
const function_option = getReadOptions(this.stackswap,
|
|
554
|
+
this.stackswap.config.CONTRACT_NAME_MORTGAGER(),
|
|
555
|
+
'get-stability-fee-for-vault',
|
|
556
|
+
[
|
|
557
|
+
uintCV(vault_id),
|
|
558
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_COLLATERAL_TYPES()),
|
|
559
|
+
]
|
|
560
|
+
);
|
|
561
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
562
|
+
// console.log(cvToValue(result_raw))
|
|
563
|
+
return cvToValue(result_raw);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {openContractCall} from "@stacks/connect";
|
|
2
|
+
import {
|
|
3
|
+
callReadOnlyFunction,
|
|
4
|
+
cvToValue,
|
|
5
|
+
falseCV,
|
|
6
|
+
FungibleConditionCode,
|
|
7
|
+
trueCV,
|
|
8
|
+
uintCV
|
|
9
|
+
} from "@stacks/transactions";
|
|
10
|
+
import {StackswapAPI} from "../../index";
|
|
11
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions, parseAddressToCV} from "../util";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export class MultisigManager {
|
|
15
|
+
stackswap: StackswapAPI;
|
|
16
|
+
|
|
17
|
+
constructor(stackswap: StackswapAPI) {
|
|
18
|
+
this.stackswap = stackswap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async deposit_vote_multisig(vote: boolean){
|
|
22
|
+
|
|
23
|
+
// console.log({amount});
|
|
24
|
+
const function_option : any = getWriteOptions(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', 'deposit-vote', [
|
|
25
|
+
vote? trueCV() : falseCV()
|
|
26
|
+
], []);
|
|
27
|
+
await openContractCall(function_option);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async withdraw_vote_multisig(vote: boolean){
|
|
31
|
+
|
|
32
|
+
// console.log({amount});
|
|
33
|
+
const function_option : any = getWriteOptions(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', 'withdraw-vote', [
|
|
34
|
+
vote? trueCV() : falseCV()
|
|
35
|
+
], []);
|
|
36
|
+
await openContractCall(function_option);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async deposit_multisig(amount: string){
|
|
40
|
+
|
|
41
|
+
// console.log({amount});
|
|
42
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, amount, FungibleConditionCode.Equal)];
|
|
43
|
+
const function_option : any = getWriteOptions(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', 'deposit', [
|
|
44
|
+
uintCV(amount)
|
|
45
|
+
], post_condition);
|
|
46
|
+
await openContractCall(function_option);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async withdraw_multisig(addr: string, amount: string){
|
|
50
|
+
|
|
51
|
+
// console.log({amount});
|
|
52
|
+
const post_condition = [await getPostConditionFromAsset(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', this.stackswap.config.BASE_STSW_DATA().addr, amount, FungibleConditionCode.Equal)];
|
|
53
|
+
|
|
54
|
+
const function_option: any = getWriteOptions(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', 'withdraw', [
|
|
55
|
+
parseAddressToCV(addr), uintCV(amount)
|
|
56
|
+
], post_condition);
|
|
57
|
+
await openContractCall(function_option);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async getMultisigSTSWAmount() {
|
|
61
|
+
// console.log('getStakingSTSWBalance');
|
|
62
|
+
const pair_details_options : any = getReadOptions(this.stackswap, this.stackswap.config.BASE_STSW_DATA().addr, 'get-balance',
|
|
63
|
+
[parseAddressToCV('SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01')]);
|
|
64
|
+
try {
|
|
65
|
+
const result = await callReadOnlyFunction(pair_details_options);
|
|
66
|
+
console.log('get-balance', cvToValue(result));
|
|
67
|
+
return cvToValue(result).value;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// console.log(e);
|
|
70
|
+
return '0';
|
|
71
|
+
}
|
|
72
|
+
// console.log(pair_details_result)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getMultisigResult(functionName: string) {
|
|
76
|
+
const pair_details_options : any = getReadOptions(this.stackswap, 'SPVRC3RHFD58B2PY1HZD2V71THPW7G445WBRCQYW.octopus_v01', functionName,
|
|
77
|
+
[]);
|
|
78
|
+
const result = await callReadOnlyFunction(pair_details_options);
|
|
79
|
+
console.log(functionName, cvToValue(result));
|
|
80
|
+
return cvToValue(result);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|