> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-Exchange Script Trigger Reference

Reference for event triggers that call extended scripts



## Trigger

### exchange

Exchange

**Related methods:**
exchange - Perform exchange


#### Synchronous Execution Script

The script is executed synchronously before the exchange process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [RateModel](../sdk/#ratemodel) | Exchange Rate Model |
| userId | string | User ID performing the exchange |
| count | int | Exchange quantity |
| config | [Config[]](../sdk/#config) | Configuration values applied to transaction variables |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow exchange |
| rateMode | string | ✓ | "float" |  | Rate mode |
| rate | float |  | 1.0 | 0 ~ 1000 | Reward quantity multiplier |
| logRate | [LogRate](../sdk/#lograte) |  |  |  | Logarithmic reward correction |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Business logic:
local permit = true
local rateMode = ""
local rate = 1.0
local logRate = nil

-- Result
result = {
  permit=permit,
  rateMode=rateMode,
  rate=rate,
  logRate=logRate
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the exchange process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [RateModel](../sdk/#ratemodel) | Exchange Rate Model |
| userId | string | User ID performing the exchange |
| count | int | Exchange quantity |
| config | [Config[]](../sdk/#config) | Configuration values applied to transaction variables |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  
### incrementalExchange

Exchange

**Related methods:**
incrementalExchange - Perform incremental cost exchange


#### Synchronous Execution Script

The script is executed synchronously before the exchange process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [IncrementalRateModel](../sdk/#incrementalratemodel) | Exchange rate model |
| userId | string | User ID performing the exchange |
| count | int | Exchange quantity |
| config | [Config[]](../sdk/#config) | Configuration values applied to transaction variables |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow exchange |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the exchange process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [IncrementalRateModel](../sdk/#incrementalratemodel) | Exchange rate model |
| userId | string | User ID performing the exchange |
| count | int | Exchange quantity |
| config | [Config[]](../sdk/#config) | Configuration values applied to transaction variables |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local userId = args.userId
local count = args.count
local config = args.config

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  
### calculateCost

Cost calculation for Incremental Cost Exchange

**Related methods:**
incrementalExchange - Perform incremental cost exchange
incrementalExchangeByUserId - Perform incremental cost exchange by User ID


#### Synchronous Execution Script

The script is executed synchronously before the cost calculation for incremental cost exchange process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| incrementalRateModel | [IncrementalRateModel](../sdk/#incrementalratemodel) | Incremental Cost Exchange Rate Model |
| userId | string | User ID |
| currentExchangeCount | int | Current number of exchange counts |
| quantity | int | Exchange Quantity |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| costMode | string | ✓ | "num" |  | Cost calculation method |
| cost | long |  |  | 0 ~ 9223372036854775805 | Cost |
| logCost | [LogCost](../sdk/#logcost) |  |  |  | Cost calculation result using logarithm |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local incrementalRateModel = args.incrementalRateModel
local userId = args.userId
local currentExchangeCount = args.currentExchangeCount
local quantity = args.quantity

-- Business logic:
local costMode = ""
local cost = 0
local logCost = nil

-- Result
result = {
  costMode=costMode,
  cost=cost,
  logCost=logCost
}
```


---
  
### acquireAwait

Exchange Await

**Related methods:**
acquire - Receive rewards for Exchange Await
acquireByUserId - Receive rewards for Exchange Await by User ID
acquireForceByUserId - Receive rewards for Exchange Await without waiting for the lock time


#### Synchronous Execution Script

The script is executed synchronously before the exchange await process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [RateModel](../sdk/#ratemodel) | Exchange Rate Model |
| awaitModel | [Await](../sdk/#await) | Exchange Await |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow awaiting exchange |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local awaitModel = args.awaitModel

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the exchange await process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| rateModel | [RateModel](../sdk/#ratemodel) | Exchange Rate Model |
| awaitModel | [Await](../sdk/#await) | Exchange Await |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local rateModel = args.rateModel
local awaitModel = args.awaitModel

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  



