Skip to content

Commit 3029d89

Browse files
committed
Add referrer field for TON staking tx
1 parent 523c634 commit 3029d89

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

book/build-your-staking-dapp/ton/ton-pool/methods.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Staking tokens supports the network's operations and earns rewards for the deleg
1818

1919
### How to Use
2020

21-
To build a staking transaction, you need to provide the validator address pair, the staking amount (in TON), and optionally, a Unix timestamp indicating when the transaction expires.
21+
To build a staking transaction, you need to provide the validator address pair, and the staking amount (in TON). Optionally, you can also specify a referrer address for tracking purposes, and a Unix timestamp indicating when the transaction expires.
2222

2323
### Example
2424

@@ -29,7 +29,8 @@ const { tx } = await staker.buildStakeTx({
2929
'kQCltujow9Sq3ZVPPU6CYGfqwDxYwjlmFGZ1Wt0bAYebio4o'
3030
],
3131
amount: '2', // 2 TON
32-
validUntil: Math.floor(Date.now() / 1000) + 3600 // Optional, expires in 1 hour
32+
validUntil: Math.floor(Date.now() / 1000) + 3600, // Optional, expires in 1 hour
33+
referrer: 'Telegram' // Optional, unique referrer string for tracking
3334
})
3435
```
3536

book/docs/classes/ton_src.TonPoolStaker.md

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ to stake to automatically.
178178
| `params` | `Object` | Parameters for building the transaction |
179179
| `params.validatorAddressPair` | [`string`, `string`] | The validator address pair to stake to |
180180
| `params.amount` | `string` | The amount to stake, specified in `TON` |
181+
| `params.referrer?` | `string` | (Optional) The address of the referrer. This is used to track the origin of transactions, providing insights into which sources or campaigns are driving activity. This can be useful for analytics and optimizing user acquisition strategies |
181182
| `params.validUntil?` | `number` | (Optional) The Unix timestamp when the transaction expires |
182183

183184
### Returns

packages/ton/src/TonPoolStaker.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ export class TonPoolStaker extends TonBaseStaker {
1010
* @param params - Parameters for building the transaction
1111
* @param params.validatorAddressPair - The validator address pair to stake to
1212
* @param params.amount - The amount to stake, specified in `TON`
13+
* @param params.referrer - (Optional) The address of the referrer. This is used to track the origin of transactions,
14+
* providing insights into which sources or campaigns are driving activity. This can be useful for analytics and
15+
* optimizing user acquisition strategies
1316
* @param params.validUntil - (Optional) The Unix timestamp when the transaction expires
1417
*
1518
* @returns Returns a promise that resolves to a TON nominator pool staking transaction.
1619
*/
1720
async buildStakeTx (params: {
1821
validatorAddressPair: [string, string]
1922
amount: string
23+
referrer?: string
2024
validUntil?: number
2125
}): Promise<{ tx: UnsignedTx }> {
22-
const { validatorAddressPair, amount, validUntil } = params
26+
const { validatorAddressPair, amount, validUntil, referrer } = params
2327
const validatorAddress = await this.getPoolAddressForStake({ validatorAddressPair })
2428

2529
// ensure the address is for the right network
@@ -35,11 +39,16 @@ export class TonPoolStaker extends TonBaseStaker {
3539
}
3640

3741
// https://github.com/tonwhales/ton-nominators/blob/0553e1b6ddfc5c0b60505957505ce58d01bec3e7/compiled/nominators.fc#L18
38-
const payload = beginCell()
42+
let basePayload = beginCell()
3943
.storeUint(2077040623, 32) // stake_deposit method const
4044
.storeUint(getRandomQueryId(), 64) // Query ID
4145
.storeCoins(getDefaultGas()) // Gas
42-
.endCell()
46+
47+
if (referrer) {
48+
basePayload = basePayload.storeStringTail(referrer)
49+
}
50+
51+
const payload = basePayload.endCell()
4352

4453
const tx = {
4554
validUntil: defaultValidUntil(validUntil),

0 commit comments

Comments
 (0)