@@ -7,7 +7,7 @@ import type { SignerType } from '../enums'
7
7
import { prompt , readConfig , getNetworkConfig , log , defaultLogger } from '../util'
8
8
import { SafeJSONStringify } from '@chorus-one/utils'
9
9
import { newSigner } from '../signer'
10
- import { TonStaker } from '@chorus-one/ton'
10
+ import { TonPoolStaker , TonNominatorPoolStaker , TonSingleNominatorPoolStaker } from '@chorus-one/ton'
11
11
12
12
export interface CLINetworkConfig extends TonNetworkConfig {
13
13
// block explorer URL to display Transaction ID via Web UI. Example:
@@ -29,6 +29,16 @@ function makeTxCommand (): Command {
29
29
. option ( '-b, --broadcast' , 'broadcast generated transaction' , false )
30
30
. option ( '-j, --journal <value>' , "write TX'es to the local journal log" , 'true' )
31
31
32
+ tx . command ( 'delegate-pool' )
33
+ . description ( 'generate a delegate funds to TON pool contract transaction' )
34
+ . argument ( '<amount>' , 'amount of tokens to stake expressed in TON denom e.g 0.1' )
35
+ . action ( getDelegatePoolTx )
36
+
37
+ tx . command ( 'unstake-pool' )
38
+ . description ( 'generate a unstake funds to TON pool contract transaction' )
39
+ . argument ( '<amount>' , 'amount of tokens to unstake expressed in TON denom e.g 0.1' )
40
+ . action ( getUnstakePoolTx )
41
+
32
42
tx . command ( 'delegate-nominator-pool' )
33
43
. description ( 'generate a delegate funds to TON nominator pool contract transaction' )
34
44
. argument ( '<amount>' , 'amount of tokens to stake expressed in TON denom e.g 0.1' )
@@ -70,11 +80,11 @@ async function init (
70
80
71
81
const networkConfig = getNetworkConfig < CLINetworkConfig > ( config )
72
82
const signer = await newSigner ( config , signerType as SignerType , {
73
- addressDerivationFn : TonStaker . getAddressDerivationFn ( {
83
+ addressDerivationFn : TonNominatorPoolStaker . getAddressDerivationFn ( {
74
84
addressDerivationConfig : networkConfig . addressDerivationConfig
75
85
} ) ,
76
- mnemonicToSeedFn : TonStaker . getMnemonicToSeedFn ( ) ,
77
- seedToKeypairFn : TonStaker . getSeedToKeypairFn ( ) ,
86
+ mnemonicToSeedFn : TonNominatorPoolStaker . getMnemonicToSeedFn ( ) ,
87
+ seedToKeypairFn : TonNominatorPoolStaker . getSeedToKeypairFn ( ) ,
78
88
keyType : KeyType . ED25519 ,
79
89
logger : defaultLogger
80
90
} )
@@ -95,9 +105,6 @@ async function runTx (
95
105
const [ config , signer ] = await init ( cmd )
96
106
97
107
const networkConfig = getNetworkConfig < CLINetworkConfig > ( config )
98
- const tonStaker : TonStaker = new TonStaker ( { ...networkConfig } )
99
- await tonStaker . init ( )
100
-
101
108
const logger = defaultLogger
102
109
103
110
logger . info ( 0 , 3 , 'inspect input data' )
@@ -117,11 +124,42 @@ async function runTx (
117
124
118
125
let unsignedTx : UnsignedTx | undefined
119
126
127
+ let tonStaker : TonPoolStaker | TonNominatorPoolStaker | TonSingleNominatorPoolStaker
128
+
120
129
try {
121
130
switch ( msgType ) {
131
+ case 'delegate-pool' : {
132
+ tonStaker = new TonPoolStaker ( { ...networkConfig } )
133
+ await tonStaker . init ( )
134
+
135
+ unsignedTx = (
136
+ await tonStaker . buildStakeTx ( {
137
+ delegatorAddress : config . delegatorAddress ,
138
+ validatorAddress : config . validatorAddress ,
139
+ amount : arg [ 0 ] // amount
140
+ } )
141
+ ) . tx
142
+ break
143
+ }
144
+ case 'unstake-pool' : {
145
+ tonStaker = new TonPoolStaker ( { ...networkConfig } )
146
+ await tonStaker . init ( )
147
+
148
+ unsignedTx = (
149
+ await tonStaker . buildUnstakeTx ( {
150
+ delegatorAddress : config . delegatorAddress ,
151
+ validatorAddress : config . validatorAddress ,
152
+ amount : arg [ 0 ] // amount
153
+ } )
154
+ ) . tx
155
+ break
156
+ }
122
157
case 'delegate-nominator-pool' : {
158
+ tonStaker = new TonNominatorPoolStaker ( { ...networkConfig } )
159
+ await tonStaker . init ( )
160
+
123
161
unsignedTx = (
124
- await tonStaker . buildStakeNominatorPoolTx ( {
162
+ await tonStaker . buildStakeTx ( {
125
163
delegatorAddress : config . delegatorAddress ,
126
164
validatorAddress : config . validatorAddress ,
127
165
amount : arg [ 0 ] // amount
@@ -130,17 +168,23 @@ async function runTx (
130
168
break
131
169
}
132
170
case 'unstake-nominator-pool' : {
171
+ tonStaker = new TonNominatorPoolStaker ( { ...networkConfig } )
172
+ await tonStaker . init ( )
173
+
133
174
unsignedTx = (
134
- await tonStaker . buildUnstakeNominatorPoolTx ( {
175
+ await tonStaker . buildUnstakeTx ( {
135
176
delegatorAddress : config . delegatorAddress ,
136
177
validatorAddress : config . validatorAddress
137
178
} )
138
179
) . tx
139
180
break
140
181
}
141
182
case 'delegate-single-nominator-pool' : {
183
+ tonStaker = new TonSingleNominatorPoolStaker ( { ...networkConfig } )
184
+ await tonStaker . init ( )
185
+
142
186
unsignedTx = (
143
- await tonStaker . buildStakeSingleNominatorPoolTx ( {
187
+ await tonStaker . buildStakeTx ( {
144
188
delegatorAddress : config . delegatorAddress ,
145
189
validatorAddress : config . validatorAddress ,
146
190
amount : arg [ 0 ] // amount
@@ -149,8 +193,11 @@ async function runTx (
149
193
break
150
194
}
151
195
case 'unstake-single-nominator-pool' : {
196
+ tonStaker = new TonSingleNominatorPoolStaker ( { ...networkConfig } )
197
+ await tonStaker . init ( )
198
+
152
199
unsignedTx = (
153
- await tonStaker . buildUnstakeSingleNominatorPoolTx ( {
200
+ await tonStaker . buildUnstakeTx ( {
154
201
delegatorAddress : config . delegatorAddress ,
155
202
validatorAddress : config . validatorAddress ,
156
203
amount : arg [ 0 ] // amount
@@ -159,6 +206,9 @@ async function runTx (
159
206
break
160
207
}
161
208
case 'transfer' : {
209
+ tonStaker = new TonNominatorPoolStaker ( { ...networkConfig } )
210
+ await tonStaker . init ( )
211
+
162
212
unsignedTx = (
163
213
await tonStaker . buildTransferTx ( {
164
214
destinationAddress : config . validatorAddress ,
@@ -168,13 +218,19 @@ async function runTx (
168
218
break
169
219
}
170
220
case 'deploy-wallet' : {
221
+ tonStaker = new TonNominatorPoolStaker ( { ...networkConfig } )
222
+ await tonStaker . init ( )
223
+
171
224
unsignedTx = (
172
225
await tonStaker . buildDeployWalletTx ( {
173
226
address : config . delegatorAddress
174
227
} )
175
228
) . tx
176
229
break
177
230
}
231
+ default : {
232
+ cmd . error ( 'unsupported message type' , { exitCode : 1 , code : `${ msgType } .tx.unsupported` } )
233
+ }
178
234
}
179
235
} catch ( e : any ) {
180
236
cmd . error ( e , { exitCode : 1 , code : msgType + '.tx.sign' } )
@@ -224,6 +280,14 @@ async function runTx (
224
280
}
225
281
}
226
282
283
+ async function getDelegatePoolTx ( amount : string , options : any , cmd : Command < [ string ] > ) : Promise < void > {
284
+ await runTx ( 'delegate-pool' , options , cmd , [ amount ] )
285
+ }
286
+
287
+ async function getUnstakePoolTx ( amount : string , options : any , cmd : Command < [ string ] > ) : Promise < void > {
288
+ await runTx ( 'unstake-pool' , options , cmd , [ amount ] )
289
+ }
290
+
227
291
async function getDelegateNominatorPoolTx ( amount : string , options : any , cmd : Command < [ string ] > ) : Promise < void > {
228
292
await runTx ( 'delegate-nominator-pool' , options , cmd , [ amount ] )
229
293
}
0 commit comments