Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@dappio-wonderland/gateway",
"version": "0.2.25",
"version": "0.2.25-test-7c3e268b",
"description": "Dappio Gateway: The Framework that Empowers the Composability of Solana Programs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"@dappio-wonderland/gateway-idls": "^0.2.8",
"@dappio-wonderland/gateway-idls": "^0.2.9",
"@dappio-wonderland/navigator": "^0.2.26",
"@dappio-wonderland/utils": "^0.2.0",
"@jup-ag/core": "1.0.0-beta.26",
"@jup-ag/core": "4.0.0-beta.4",
"@project-serum/anchor": "^0.24.2",
"@project-serum/borsh": "^0.2.5",
"@project-serum/serum": "^0.13.61",
Expand Down Expand Up @@ -47,6 +47,7 @@
"testAdapterNftFinance": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterNftFinance.ts",
"testAdapterFrancium": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterFrancium.ts",
"testAdapterKatana": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterKatana.ts",
"testAdapterFriktion": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterFriktion.ts"
"testAdapterFriktion": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterFriktion.ts",
"testAdapterJupiter": "ANCHOR_WALLET=~/.config/solana/gateway.json ts-mocha -p ./tsconfig.json -t 1000000 tests/testAdapterJupiter.ts"
}
}
65 changes: 44 additions & 21 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IProtocolNFTFarm,
IProtocolNFTPool,
IProtocolPool,
IProtocolSwap,
IProtocolVault,
LockNFTParams,
PoolDirection,
Expand Down Expand Up @@ -106,6 +107,9 @@ export class GatewayBuilder {
poolDirection: PoolDirection.Obverse,
swapMinOutAmount: new anchor.BN(0),
farmType: [],
swapIndex: 0,
swapAmountConfig: [] as Uint8Array[],
swapRouteConfig: [] as Uint8Array[],
};

this._metadata = {
Expand All @@ -128,18 +132,29 @@ export class GatewayBuilder {
// IProtocolSwap
async swap(swapParams: SwapParams): Promise<GatewayBuilder> {
// NOTE: No need to push protocol / action to queue since Jupiter apapter is not implemented yet
this.params.actionQueue.push(ActionType.Swap);
this.params.protocolQueue.push(swapParams.protocol);
this.params.versionQueue.push(1);
this._metadata.fromTokenMint = swapParams.fromTokenMint;
this._metadata.toTokenMint = swapParams.toTokenMint;

this._adjustParams();

let protocol: IProtocolSwap;

// TODO: Move the logic into protocols
switch (swapParams.protocol) {
case SupportedProtocols.Jupiter:
const protocol = new ProtocolJupiter(this._provider.connection, {
...swapParams,
userKey: this._provider.wallet.publicKey,
});
protocol = new ProtocolJupiter(
this._provider.connection,
this._program,
await this.getGatewayStateKey(),
this.params,
{
...swapParams,
userKey: this._provider.wallet.publicKey,
}
);

// Jupiter only
await protocol.build();
Expand All @@ -148,14 +163,21 @@ export class GatewayBuilder {
this._metadata.routes = Boolean(this._metadata.routes)
? [...this._metadata.routes, await protocol.getRoute()]
: [await protocol.getRoute()];

this._transactions = [...this._transactions, ...(await protocol.swap())];

this._metadata.addressLookupTables = protocol.getAddressLookupTables().map((a) => a.key);
break;
default:
throw new Error("Unsupported Protocol");
}

const { txs, input } = await protocol.swap();

// Push input payload
(this.params.payloadQueue as Uint8Array[]).push(input);
// TODO: Extract the logic of index dispatch to a config file
this.params.inputIndexQueue.push(0);

this._transactions = [...this._transactions, ...txs];

return this;
}

Expand Down Expand Up @@ -1666,20 +1688,20 @@ export class GatewayBuilder {
}

// ZapIn only: Update poolTokenAInAmount if swapOutAmount has value
if (this.params?.swapMinOutAmount?.toNumber() > 0) {
const indexAddLiquidity = this.params.actionQueue.indexOf(ActionType.AddLiquidity);
// Note: ZapIn only
if (indexAddLiquidity > 0) {
switch (this.params.poolDirection) {
case PoolDirection.Obverse:
this.params.payloadQueue[indexAddLiquidity] = new anchor.BN(this.params.swapMinOutAmount.toNumber());
break;
case PoolDirection.Reverse:
this.params.payloadQueue[indexAddLiquidity] = new anchor.BN(this.params.swapMinOutAmount.toNumber());
break;
}
}
}
// if (this.params?.swapMinOutAmount?.toNumber() > 0) {
// const indexAddLiquidity = this.params.actionQueue.indexOf(ActionType.AddLiquidity);
// // Note: ZapIn only
// if (indexAddLiquidity > 0) {
// switch (this.params.poolDirection) {
// case PoolDirection.Obverse:
// this.params.payloadQueue[indexAddLiquidity] = new anchor.BN(this.params.swapMinOutAmount.toNumber());
// break;
// case PoolDirection.Reverse:
// this.params.payloadQueue[indexAddLiquidity] = new anchor.BN(this.params.swapMinOutAmount.toNumber());
// break;
// }
// }
// }
}

async finalize(): Promise<GatewayBuilder> {
Expand Down Expand Up @@ -1718,6 +1740,7 @@ export class GatewayBuilder {
async v0Transactions(addressLookupTable: anchor.web3.PublicKey[] = []): Promise<anchor.web3.VersionedTransaction[]> {
return compressV0(this._transactions, this._provider.wallet.publicKey, this._provider.connection, [
...ADDRESS_LOOKUP_TABLES,
...this._metadata.addressLookupTables,
...addressLookupTable,
]);
}
Expand Down
6 changes: 6 additions & 0 deletions src/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const SOLEND_ADAPTER_PROGRAM_ID = new PublicKey("ADPTCXAFfJFVqcw73B4PWRZQ

export const NFT_FINANCE_ADAPTER_PROGRAM_ID = new PublicKey("ADPTyBr92sBCE1hdYBRvXbMpF4hKs17xyDjFPxopcsrh");

export const JUPITER_ADAPTER_PROGRAM_ID = new PublicKey("ADPT8iF4A7BSUWQ8AsVwmcod2suFzA4bpYpJj7kUWK3E");

export const SERUM_PROGRAM_ID = new PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin");

export const JUPITER_PROGRAM_ID = new PublicKey("JUP4Fb2cqiRUcaTHdrPC8h2gNsA2ETXiPDD33WcGuJB");

export const NATIVE_SOL = new PublicKey("11111111111111111111111111111111");

export const WSOL = new PublicKey("So11111111111111111111111111111111111111112");
Expand Down
Loading